Mercurial > hg > Members > kono > os9 > sbc09
annotate src/v09.c @ 191:d0f5894e9b3a default tip
some how load: confilicts in gmake
author | kono |
---|---|
date | Thu, 07 Dec 2023 09:37:15 +0900 |
parents | b93996f54090 |
children |
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> | |
184 | 32 |
0 | 33 #include <strings.h> |
34 #include <sys/stat.h> | |
184 | 35 |
151 | 36 #include <string.h> |
0 | 37 |
38 #define engine extern | |
39 | |
40 #include "v09.h" | |
41 | |
190 | 42 extern FILE *tracefile; |
0 | 43 |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
44 extern FILE *disk[]; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
45 extern FILE *fp; // for disasm |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
46 extern char *prog; // for disasm |
0 | 47 extern void disasm(int,int); |
16 | 48 extern void do_mmu(Word,Byte); |
20 | 49 extern void init_term(void) ; |
64 | 50 #ifdef USE_VDISK |
51 extern int setVdisk(int drv,char *name) ; | |
52 #endif | |
53 | |
20 | 54 |
0 | 55 |
56 void do_trace(FILE *tracefile) | |
57 { | |
58 Word pc=pcreg; | |
59 Byte ir; | |
60 // fprintf(tracefile,"pc=%04x ",pc); | |
61 // ir=mem[pc++]; | |
62 // fprintf(tracefile,"i=%02x ",ir); if((ir&0xfe)==0x10) fprintf(tracefile,"%02x ",mem[pc]);else | |
63 // fprintf(tracefile," "); | |
85 | 64 fprintf(tracefile,"x=%04x y=%04x u=%04x s=%04x a=%02x b=%02x cc=%02x dp=%02x pc=", |
65 xreg,yreg,ureg,sreg,*areg,*breg,ccreg,dpreg); | |
0 | 66 fp = tracefile; |
67 disasm(pc,pc); | |
68 } | |
69 | |
70 char *romfile = "v09.rom"; | |
9 | 71 long romstart = 0x8000; |
0 | 72 |
73 long | |
74 filesize(FILE *image) | |
75 { | |
76 struct stat buf; | |
77 fstat(fileno(image),&buf); | |
78 return buf.st_size; | |
79 } | |
80 | |
81 | |
184 | 82 void read_image() |
0 | 83 { |
84 FILE *image; | |
85 if((image=fopen(romfile,"rb"))==NULL) | |
86 if((image=fopen("../v09.rom","rb"))==NULL) | |
87 if((image=fopen("..\\v09.rom","rb"))==NULL) { | |
88 perror("v09, image file"); | |
89 exit(2); | |
90 } | |
91 long len = filesize(image); | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
92 /* |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
93 * |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
94 * 0x0000-0xdfff normal mem |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
95 * 0xxxxx-0xdfff rom |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
96 * 0xe000-0xe100 i/o |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
97 * 0xe000-0xffff rom |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
98 * |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
99 * discless boot |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
100 * rom image will be copyied from 0xed00-0x1xxxx |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
101 * boot copies 0x10000-0x1xxxx to os9's boot memory |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
102 */ |
16 | 103 #ifdef USE_MMU |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
104 /* |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
105 * In case of Coco, there is no ROM (switched out after boot ) |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
106 * 0x00000-0x0fdff normal mem |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
107 * 0x0fe00-0x0ffff ram fixed address ram including io |
84 | 108 * 0x10000-0x1fffff ram (2MB memory ) |
109 * >0x200000 lapround | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
110 * |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
111 * discless boot |
84 | 112 * rom image will be copyied from 0x7eed00-0x7fxxxx (all ram) |
113 * boot copies 0x800000-0x8xxxx to os9's boot memory (ususally done by rel.asm ) | |
114 * (original system copies it from fd or hd) | |
115 * after that 0x800000-0x8xxxx will be all free | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
116 */ |
84 | 117 phymem = malloc(memsize ); |
118 rommemsize = memsize ; | |
119 mem = phymem + 0x38*0x2000; | |
24 | 120 mmu = &mem[0xffa0]; |
16 | 121 prog = (char*)mem; |
9 | 122 if (romstart==0x8000) { |
33 | 123 romstart = memsize ; // full 512kb mem |
16 | 124 } |
84 | 125 fread(mem+ 0xe000,len,1,image); |
126 mem[0xff90] = 0; | |
33 | 127 mem[0xffa7] = 0x3f; |
9 | 128 #else |
16 | 129 if (romstart==0x8000) { |
9 | 130 romstart = 0x10000 - len; |
16 | 131 } |
29
3c14d647bb51
assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
132 fread(mem+(romstart&0xffff),len,1,image); |
9 | 133 #endif |
0 | 134 fclose(image); |
135 } | |
136 | |
137 void usage(void) | |
138 { | |
9 | 139 fprintf(stderr,"Usage: v09 [-rom rom-image] [-l romstart] [-t tracefile [-tl addr] [-nt]" |
64 | 140 "[-[01] disk-image ] " |
141 #ifdef USE_VDISK | |
142 "[v vdisk-base-dir ] " | |
143 #endif | |
0 | 144 "[-th addr] ]\n[-e escchar] \n"); |
145 exit(1); | |
146 } | |
147 | |
148 | |
149 #define CHECKARG if(i==argc)usage();else i++; | |
150 | |
184 | 151 int main(int argc,char *argv[]) |
0 | 152 { |
153 char *imagename=0; | |
154 int i; | |
155 int setterm = 1; | |
55 | 156 timerirq = 2; // use FIRQ default |
158 | 157 #ifdef USE_MMU |
84 | 158 memsize = 512*1024*4; // full 2 mbute |
158 | 159 #else |
160 memsize = 1024*64; // 64k | |
161 #endif | |
0 | 162 escchar='\x1d'; |
163 tracelo=0;tracehi=0xffff; | |
164 for(i=1;i<argc;i++) { | |
165 if (strcmp(argv[i],"-t")==0) { | |
166 i++; | |
167 if((tracefile=fopen(argv[i],"w"))==NULL) { | |
168 perror("v09, tracefile"); | |
169 exit(2); | |
170 } | |
171 tracing=1;attention=1; | |
172 } else if (strcmp(argv[i],"-rom")==0) { | |
173 i++; | |
61 | 174 timer = 3; // non standard rom image, don't start timer, and timder start call enabled |
55 | 175 timerirq = 1 ; // os9 cannot handle FIRQ |
0 | 176 romfile = argv[i]; |
9 | 177 |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
178 } 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
|
179 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
180 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
|
181 } 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
|
182 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
183 disk[1] = fopen(argv[i],"r+"); |
64 | 184 #ifdef USE_VDISK |
185 } else if (strcmp(argv[i],"-v")==0) { | |
186 i++; | |
187 setVdisk(0,argv[i]); | |
188 #endif | |
0 | 189 } else if (strcmp(argv[i],"-tl")==0) { |
190 i++; | |
191 tracelo=strtol(argv[i],(char**)0,0); | |
192 } else if (strcmp(argv[i],"-th")==0) { | |
193 i++; | |
194 tracehi=strtol(argv[i],(char**)0,0); | |
195 } else if (strcmp(argv[i],"-e")==0) { | |
196 i++; | |
197 escchar=strtol(argv[i],(char**)0,0); | |
198 } else if (strcmp(argv[i],"-l")==0) { | |
199 i++; | |
200 romstart=strtol(argv[i],(char**)0,0); | |
1 | 201 } else if (strcmp(argv[i],"-nt")==0) { // start debugger at the start |
0 | 202 attention = escape = 1; |
61 | 203 timer = 1; // desable default timer interrupt and don't start timer on timer start IO |
4 | 204 } else if (strcmp(argv[i],"-m")==0) { |
205 i++; | |
206 memsize=strtol(argv[i],(char**)0,0) & ~0xffff; | |
158 | 207 #ifdef USE_MMU |
4 | 208 if (memsize < 512*1024) memsize = 512*1024; |
158 | 209 #endif |
0 | 210 } else usage(); |
211 } | |
212 #ifdef MSDOS | |
213 if((mem=farmalloc(65535))==0) { | |
214 fprintf(stderr,"Not enough memory\n"); | |
215 exit(2); | |
216 } | |
217 #endif | |
218 read_image(); | |
20 | 219 init_term(); |
0 | 220 if (setterm) set_term(escchar); |
221 pcreg=(mem[0xfffe]<<8)+mem[0xffff]; | |
16 | 222 prog = (char*)mem; // for disasm |
0 | 223 interpr(); |
224 return 0; | |
225 } | |
226 |