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