Mercurial > hg > Members > kono > os9 > sbc09
annotate v09.c @ 24:7104ad38bed3
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 10 Jul 2018 10:49:07 +0900 (2018-07-10) |
parents | 49fac9474858 |
children | d34482fd6945 |
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); | |
16 | 86 #ifdef USE_MMU |
87 phymem = malloc(memsize + len - 0x2000); | |
88 rommemsize = memsize + len - 0x2000; | |
89 mem = phymem + memsize - 0x10000 ; | |
24 | 90 mmu = &mem[0xffa0]; |
16 | 91 prog = (char*)mem; |
9 | 92 if (romstart==0x8000) { |
11 | 93 romstart = memsize - 0x2000; |
16 | 94 } |
9 | 95 #else |
16 | 96 if (romstart==0x8000) { |
9 | 97 romstart = 0x10000 - len; |
16 | 98 } |
9 | 99 #endif |
100 fread(mem+(romstart&0xffff),len,1,image); | |
0 | 101 fclose(image); |
102 } | |
103 | |
104 void usage(void) | |
105 { | |
9 | 106 fprintf(stderr,"Usage: v09 [-rom rom-image] [-l romstart] [-t tracefile [-tl addr] [-nt]" |
0 | 107 "[-th addr] ]\n[-e escchar] \n"); |
108 exit(1); | |
109 } | |
110 | |
111 | |
112 #define CHECKARG if(i==argc)usage();else i++; | |
113 | |
114 int | |
115 main(int argc,char *argv[]) | |
116 { | |
117 char *imagename=0; | |
118 int i; | |
119 int setterm = 1; | |
4 | 120 memsize = 512*1024; |
0 | 121 escchar='\x1d'; |
122 tracelo=0;tracehi=0xffff; | |
123 for(i=1;i<argc;i++) { | |
124 if (strcmp(argv[i],"-t")==0) { | |
125 i++; | |
126 if((tracefile=fopen(argv[i],"w"))==NULL) { | |
127 perror("v09, tracefile"); | |
128 exit(2); | |
129 } | |
130 tracing=1;attention=1; | |
131 } else if (strcmp(argv[i],"-rom")==0) { | |
132 i++; | |
1 | 133 timer = 0; // non standard rom image, don't start timer |
0 | 134 romfile = argv[i]; |
9 | 135 |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
136 } 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
|
137 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
138 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
|
139 } 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
|
140 i++; |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
141 disk[1] = fopen(argv[i],"r+"); |
0 | 142 } else if (strcmp(argv[i],"-tl")==0) { |
143 i++; | |
144 tracelo=strtol(argv[i],(char**)0,0); | |
145 } else if (strcmp(argv[i],"-th")==0) { | |
146 i++; | |
147 tracehi=strtol(argv[i],(char**)0,0); | |
148 } else if (strcmp(argv[i],"-e")==0) { | |
149 i++; | |
150 escchar=strtol(argv[i],(char**)0,0); | |
151 } else if (strcmp(argv[i],"-l")==0) { | |
152 i++; | |
153 romstart=strtol(argv[i],(char**)0,0); | |
1 | 154 } else if (strcmp(argv[i],"-nt")==0) { // start debugger at the start |
0 | 155 attention = escape = 1; |
1 | 156 timer = 0; // no timer |
4 | 157 } else if (strcmp(argv[i],"-m")==0) { |
158 i++; | |
159 memsize=strtol(argv[i],(char**)0,0) & ~0xffff; | |
160 if (memsize < 512*1024) memsize = 512*1024; | |
0 | 161 } else usage(); |
162 } | |
163 #ifdef MSDOS | |
164 if((mem=farmalloc(65535))==0) { | |
165 fprintf(stderr,"Not enough memory\n"); | |
166 exit(2); | |
167 } | |
168 #endif | |
169 read_image(); | |
20 | 170 init_term(); |
0 | 171 if (setterm) set_term(escchar); |
172 pcreg=(mem[0xfffe]<<8)+mem[0xffff]; | |
16 | 173 prog = (char*)mem; // for disasm |
0 | 174 interpr(); |
175 return 0; | |
176 } | |
177 |