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