Mercurial > hg > Members > kono > os9 > sbc09
annotate v09.c @ 55:8d151f303bee
FIRQ does not worked
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Jul 2018 08:35:25 +0900 |
parents | 51b437557f42 |
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> | |
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); |
16 | 45 extern void do_mmu(Word,Byte); |
20 | 46 extern void init_term(void) ; |
47 | |
0 | 48 |
49 void do_trace(FILE *tracefile) | |
50 { | |
51 Word pc=pcreg; | |
52 Byte ir; | |
53 // fprintf(tracefile,"pc=%04x ",pc); | |
54 // ir=mem[pc++]; | |
55 // fprintf(tracefile,"i=%02x ",ir); if((ir&0xfe)==0x10) fprintf(tracefile,"%02x ",mem[pc]);else | |
56 // fprintf(tracefile," "); | |
57 fprintf(tracefile,"x=%04x y=%04x u=%04x s=%04x a=%02x b=%02x cc=%02x pc=", | |
58 xreg,yreg,ureg,sreg,*areg,*breg,ccreg); | |
59 fp = tracefile; | |
60 disasm(pc,pc); | |
61 } | |
62 | |
63 char *romfile = "v09.rom"; | |
9 | 64 long romstart = 0x8000; |
0 | 65 |
66 long | |
67 filesize(FILE *image) | |
68 { | |
69 struct stat buf; | |
70 fstat(fileno(image),&buf); | |
71 return buf.st_size; | |
72 } | |
73 | |
74 | |
75 void | |
76 read_image() | |
77 { | |
78 FILE *image; | |
79 if((image=fopen(romfile,"rb"))==NULL) | |
80 if((image=fopen("../v09.rom","rb"))==NULL) | |
81 if((image=fopen("..\\v09.rom","rb"))==NULL) { | |
82 perror("v09, image file"); | |
83 exit(2); | |
84 } | |
85 long len = filesize(image); | |
52
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
86 /* |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
87 * |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
88 * 0x0000-0xdfff normal mem |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
89 * 0xxxxx-0xdfff rom |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
90 * 0xe000-0xe100 i/o |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
91 * 0xe000-0xffff rom |
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 * discless boot |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
94 * 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
|
95 * 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
|
96 */ |
16 | 97 #ifdef USE_MMU |
52
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 * 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
|
100 * 0x00000-0x0fdff normal mem |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
101 * 0x0fe00-0x0ffff ram fixed address ram including io |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
102 * 0x10000-0x7ffff ram (512Kb memory current implementation) |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
103 * it should have 2MB memory |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
104 * 0x10000-0xfffff ram |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
105 * >0x100000 lapround |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
106 * |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
107 * discless boot |
51b437557f42
boot without disk image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
108 * 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
|
109 * 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
|
110 */ |
16 | 111 phymem = malloc(memsize + len - 0x2000); |
112 rommemsize = memsize + len - 0x2000; | |
113 mem = phymem + memsize - 0x10000 ; | |
24 | 114 mmu = &mem[0xffa0]; |
16 | 115 prog = (char*)mem; |
9 | 116 if (romstart==0x8000) { |
33 | 117 // romstart = memsize - 0x10000 + 0xed00 ; |
118 romstart = memsize ; // full 512kb mem | |
16 | 119 } |
29
3c14d647bb51
assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
120 fread(mem+ 0xe000,len,1,image); |
33 | 121 mem[0xffa7] = 0x3f; |
9 | 122 #else |
16 | 123 if (romstart==0x8000) { |
9 | 124 romstart = 0x10000 - len; |
16 | 125 } |
29
3c14d647bb51
assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
126 fread(mem+(romstart&0xffff),len,1,image); |
9 | 127 #endif |
0 | 128 fclose(image); |
129 } | |
130 | |
131 void usage(void) | |
132 { | |
9 | 133 fprintf(stderr,"Usage: v09 [-rom rom-image] [-l romstart] [-t tracefile [-tl addr] [-nt]" |
0 | 134 "[-th addr] ]\n[-e escchar] \n"); |
135 exit(1); | |
136 } | |
137 | |
138 | |
139 #define CHECKARG if(i==argc)usage();else i++; | |
140 | |
141 int | |
142 main(int argc,char *argv[]) | |
143 { | |
144 char *imagename=0; | |
145 int i; | |
146 int setterm = 1; | |
55 | 147 timerirq = 2; // use FIRQ default |
4 | 148 memsize = 512*1024; |
0 | 149 escchar='\x1d'; |
150 tracelo=0;tracehi=0xffff; | |
151 for(i=1;i<argc;i++) { | |
152 if (strcmp(argv[i],"-t")==0) { | |
153 i++; | |
154 if((tracefile=fopen(argv[i],"w"))==NULL) { | |
155 perror("v09, tracefile"); | |
156 exit(2); | |
157 } | |
158 tracing=1;attention=1; | |
159 } else if (strcmp(argv[i],"-rom")==0) { | |
160 i++; | |
55 | 161 timer = 0; // non standard rom image, don't start timer |
162 timerirq = 1 ; // os9 cannot handle FIRQ | |
0 | 163 romfile = argv[i]; |
9 | 164 |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
165 } 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
|
166 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
167 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
|
168 } 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
|
169 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
170 disk[1] = fopen(argv[i],"r+"); |
0 | 171 } else if (strcmp(argv[i],"-tl")==0) { |
172 i++; | |
173 tracelo=strtol(argv[i],(char**)0,0); | |
174 } else if (strcmp(argv[i],"-th")==0) { | |
175 i++; | |
176 tracehi=strtol(argv[i],(char**)0,0); | |
177 } else if (strcmp(argv[i],"-e")==0) { | |
178 i++; | |
179 escchar=strtol(argv[i],(char**)0,0); | |
180 } else if (strcmp(argv[i],"-l")==0) { | |
181 i++; | |
182 romstart=strtol(argv[i],(char**)0,0); | |
1 | 183 } else if (strcmp(argv[i],"-nt")==0) { // start debugger at the start |
0 | 184 attention = escape = 1; |
1 | 185 timer = 0; // no timer |
4 | 186 } else if (strcmp(argv[i],"-m")==0) { |
187 i++; | |
188 memsize=strtol(argv[i],(char**)0,0) & ~0xffff; | |
189 if (memsize < 512*1024) memsize = 512*1024; | |
0 | 190 } else usage(); |
191 } | |
192 #ifdef MSDOS | |
193 if((mem=farmalloc(65535))==0) { | |
194 fprintf(stderr,"Not enough memory\n"); | |
195 exit(2); | |
196 } | |
197 #endif | |
198 read_image(); | |
20 | 199 init_term(); |
0 | 200 if (setterm) set_term(escchar); |
201 pcreg=(mem[0xfffe]<<8)+mem[0xffff]; | |
16 | 202 prog = (char*)mem; // for disasm |
0 | 203 interpr(); |
204 return 0; | |
205 } | |
206 |