Mercurial > hg > Members > kono > os9 > sbc09
annotate v09.c @ 2:31d96e2b364e
add virtual hd option to v09
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 Jul 2018 21:39:55 +0900 |
parents | 3c736a81b886 |
children | 831ac057ea86 |
rev | line source |
---|---|
0 | 1 /* 6809 Simulator V09. |
2 | |
3 Copyright 1994, L.C. Benschop, Eidnhoven The Netherlands. | |
4 This version of the program is distributed under the terms and conditions | |
5 of the GNU General Public License version 2. See the file COPYING. | |
6 THERE IS NO WARRANTY ON THIS PROGRAM!!! | |
7 | |
8 This program simulates a 6809 processor. | |
9 | |
10 System dependencies: short must be 16 bits. | |
11 char must be 8 bits. | |
12 long must be more than 16 bits. | |
13 arrays up to 65536 bytes must be supported. | |
14 machine must be twos complement. | |
15 Most Unix machines will work. For MSODS you need long pointers | |
16 and you may have to malloc() the mem array of 65536 bytes. | |
17 | |
18 Define BIG_ENDIAN if you have a big-endian machine (680x0 etc) | |
19 | |
20 Special instructions: | |
21 SWI2 writes char to stdout from register B. | |
22 SWI3 reads char from stdout to register B, sets carry at EOF. | |
23 (or when no key available when using term control). | |
24 SWI retains its normal function. | |
25 CWAI and SYNC stop simulator. | |
26 | |
27 */ | |
28 | |
29 | |
30 #include <stdio.h> | |
31 #include <stdlib.h> | |
32 #include <strings.h> | |
33 #include <sys/stat.h> | |
34 | |
35 #define engine extern | |
36 | |
37 #include "v09.h" | |
38 | |
39 FILE *tracefile; | |
40 | |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
41 extern FILE *disk[]; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
42 extern FILE *fp; // for disasm |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
43 extern char *prog; // for disasm |
0 | 44 extern void disasm(int,int); |
45 | |
46 void do_trace(FILE *tracefile) | |
47 { | |
48 Word pc=pcreg; | |
49 Byte ir; | |
50 // fprintf(tracefile,"pc=%04x ",pc); | |
51 // ir=mem[pc++]; | |
52 // fprintf(tracefile,"i=%02x ",ir); if((ir&0xfe)==0x10) fprintf(tracefile,"%02x ",mem[pc]);else | |
53 // fprintf(tracefile," "); | |
54 fprintf(tracefile,"x=%04x y=%04x u=%04x s=%04x a=%02x b=%02x cc=%02x pc=", | |
55 xreg,yreg,ureg,sreg,*areg,*breg,ccreg); | |
56 fp = tracefile; | |
57 prog = (char*)mem; | |
58 disasm(pc,pc); | |
59 } | |
60 | |
61 char *romfile = "v09.rom"; | |
62 int romstart = 0x8000; | |
63 | |
64 long | |
65 filesize(FILE *image) | |
66 { | |
67 struct stat buf; | |
68 fstat(fileno(image),&buf); | |
69 return buf.st_size; | |
70 } | |
71 | |
72 | |
73 void | |
74 read_image() | |
75 { | |
76 FILE *image; | |
77 if((image=fopen(romfile,"rb"))==NULL) | |
78 if((image=fopen("../v09.rom","rb"))==NULL) | |
79 if((image=fopen("..\\v09.rom","rb"))==NULL) { | |
80 perror("v09, image file"); | |
81 exit(2); | |
82 } | |
83 long len = filesize(image); | |
84 fread(mem+romstart,len,1,image); | |
85 fclose(image); | |
86 } | |
87 | |
88 void usage(void) | |
89 { | |
90 fprintf(stderr,"Usage: v09 [-l romstart] [-rom rom-image] [-t tracefile [-tl addr] [-nt]" | |
91 "[-th addr] ]\n[-e escchar] \n"); | |
92 exit(1); | |
93 } | |
94 | |
95 | |
96 #define CHECKARG if(i==argc)usage();else i++; | |
97 | |
98 int | |
99 main(int argc,char *argv[]) | |
100 { | |
101 Word loadaddr=0x100; | |
102 char *imagename=0; | |
103 int i; | |
104 int setterm = 1; | |
105 escchar='\x1d'; | |
106 tracelo=0;tracehi=0xffff; | |
107 for(i=1;i<argc;i++) { | |
108 if (strcmp(argv[i],"-t")==0) { | |
109 i++; | |
110 if((tracefile=fopen(argv[i],"w"))==NULL) { | |
111 perror("v09, tracefile"); | |
112 exit(2); | |
113 } | |
114 tracing=1;attention=1; | |
115 } else if (strcmp(argv[i],"-rom")==0) { | |
116 i++; | |
1 | 117 timer = 0; // non standard rom image, don't start timer |
0 | 118 romfile = argv[i]; |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
119 } else if (strcmp(argv[i],"-0")==0) { |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
120 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
121 disk[0] = fopen(argv[i],"r+"); |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
122 } else if (strcmp(argv[i],"-1")==0) { |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
123 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
124 disk[1] = fopen(argv[i],"r+"); |
0 | 125 } else if (strcmp(argv[i],"-tl")==0) { |
126 i++; | |
127 tracelo=strtol(argv[i],(char**)0,0); | |
128 } else if (strcmp(argv[i],"-th")==0) { | |
129 i++; | |
130 tracehi=strtol(argv[i],(char**)0,0); | |
131 } else if (strcmp(argv[i],"-e")==0) { | |
132 i++; | |
133 escchar=strtol(argv[i],(char**)0,0); | |
134 } else if (strcmp(argv[i],"-l")==0) { | |
135 i++; | |
136 romstart=strtol(argv[i],(char**)0,0); | |
1 | 137 } else if (strcmp(argv[i],"-nt")==0) { // start debugger at the start |
0 | 138 attention = escape = 1; |
1 | 139 timer = 0; // no timer |
0 | 140 } else usage(); |
141 } | |
142 #ifdef MSDOS | |
143 if((mem=farmalloc(65535))==0) { | |
144 fprintf(stderr,"Not enough memory\n"); | |
145 exit(2); | |
146 } | |
147 #endif | |
148 read_image(); | |
149 if (setterm) set_term(escchar); | |
150 pcreg=(mem[0xfffe]<<8)+mem[0xffff]; | |
151 interpr(); | |
152 return 0; | |
153 } | |
154 |