-
Notifications
You must be signed in to change notification settings - Fork 22
/
quickload.c
109 lines (97 loc) · 2.98 KB
/
quickload.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Copyright 2015 by Joseph Forgione
This file is part of VCC (Virtual Color Computer).
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#include <stdio.h>
#include "defines.h"
#include "pakinterface.h"
#include "Vcc.h"
#include "coco3.h"
#include "tcc1014mmu.h"
#include "fileops.h"
static unsigned char FileType=0;
static unsigned short FileLenth=0;
static short StartAddress=0;
static unsigned short XferAddress=0;
static unsigned char *MemImage=NULL;
FILE *BinImage=NULL;
HANDLE hr;
static unsigned char Flag=1;
static int temp=255;
static char Extension[MAX_PATH]="";
unsigned char QuickLoad(char *BinFileName)
{
unsigned int MemIndex=0;
hr=CreateFile(BinFileName,NULL,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hr==INVALID_HANDLE_VALUE)
return(1); //File Not Found
CloseHandle(hr);
BinImage=fopen(BinFileName,"rb");
if (BinImage==NULL)
return(2); //Can't Open File
MemImage=(unsigned char *)malloc(65535);
if (MemImage==NULL)
{
MessageBox(NULL,"Can't alocate ram","Error",0);
return(3); //Not enough memory
}
strcpy(Extension,PathFindExtension(BinFileName));
_strlwr(Extension);
if ( (strcmp(Extension,".rom")==0) | (strcmp(Extension,".ccc")==0) | (strcmp(Extension,"*.pak")==0))
{
InsertModule (BinFileName);
return(0);
}
if ( strcmp(Extension,".bin")==0)
{
while (true)
{
temp=fread(MemImage,sizeof(char),5,BinImage);
FileType=MemImage[0];
FileLenth=(MemImage[1]<<8) + MemImage[2];
StartAddress=(MemImage[3]<<8)+MemImage[4];
switch (FileType)
{
case 0:
temp=fread(&MemImage[0],sizeof(char),FileLenth,BinImage);
for (MemIndex=0;MemIndex<FileLenth;MemIndex++) //Kluge!!!
MemWrite8(MemImage[MemIndex],StartAddress++);
break;
case 255:
XferAddress=StartAddress;
if ( (XferAddress==0) | (XferAddress >32767) |(FileLenth != 0) )
{
MessageBox(NULL,".Bin file is corrupt or invalid Transfer Address","Error",0);
return(3);
}
fclose(BinImage);
free(MemImage);
CPUForcePC(XferAddress);
return(0);
break;
default:
MessageBox(NULL,".Bin file is corrupt or invalid","Error",0);
fclose(BinImage);
free(MemImage);
return(3);
break;
} //End Switch
} //End While
} // End if
return(255); //Invalid File type
} //End Proc
unsigned short GetXferAddr(void)
{
return(XferAddress);
}