Mercurial > hg > Members > kono > os9 > sbc09
annotate io.c @ 11:ce7323f9b937
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 06 Jul 2018 18:31:38 +0900 |
parents | 2a1338b218bf |
children | 111e5defb8ab |
rev | line source |
---|---|
9 | 1 /* 6808 Simulator V092 |
2 created 1993,1994 by L.C. Benschop. copyleft (c) 1994-2014 | |
3 by the sbc09 team, see AUTHORS for more details. license: | |
4 GNU General Public License version 2, see LICENSE for more | |
5 details. | |
0 | 6 |
7 This program simulates a 6809 processor. | |
8 | |
9 System dependencies: short must be 16 bits. | |
10 char must be 8 bits. | |
11 long must be more than 16 bits. | |
12 arrays up to 65536 bytes must be supported. | |
13 machine must be twos complement. | |
14 Most Unix machines will work. For MSODS you need long pointers | |
15 and you may have to malloc() the mem array of 65536 bytes. | |
16 | |
17 Define BIG_ENDIAN if you have a big-endian machine (680x0 etc) | |
18 | |
19 Special instructions: | |
20 SWI2 writes char to stdout from register B. | |
21 SWI3 reads char from stdout to register B, sets carry at EOF. | |
22 (or when no key available when using term control). | |
23 SWI retains its normal function. | |
24 CWAI and SYNC stop simulator. | |
25 | |
26 */ | |
27 | |
28 #include<stdio.h> | |
29 #include<stdlib.h> | |
30 #include<ctype.h> | |
31 #include<signal.h> | |
32 #include<sys/time.h> | |
33 | |
34 #include <unistd.h> | |
35 #include <fcntl.h> | |
36 #include <string.h> | |
1 | 37 #include <time.h> |
0 | 38 |
39 #ifdef USE_TERMIOS | |
40 #include <termios.h> | |
41 #endif | |
42 | |
43 #define engine extern | |
44 #include "v09.h" | |
45 | |
1 | 46 /* |
3 | 47 * IO Map ( can be overrupped by ROM ) |
48 * | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
49 * IOPAGE ~ IOPAGE+0x7f |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
50 * for OS9 level2 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
51 * IOPAGE 0xff80 means ioport beging 0xff80 but IOPAGE itself starts 0xff00 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
52 * 0xff00-0xff7f, 0xffe0-0xffff can be used as ROM in fixed area |
1 | 53 * |
3 | 54 * IOPAGE + 0x00 ACIA control |
55 * IOPAGE + 0x01 ACIA data | |
1 | 56 * |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
57 * IOPAGE + 0x11 MMU Taskreg 0 system map, 1 user map |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
58 * IOPAGE + 0x20-0x27 MMU reg system map |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
59 * IOPAGE + 0x28-0x2f MMU reg user map |
3 | 60 * |
61 * on reset tr==0 and only IOPAGE is valid | |
62 * translatation occur only on non-IOPAGE | |
63 * mem == phymem + 0x70000 | |
64 * phy addr = phymem[ ( mmu[ adr >> 13 ] <<13 ) + (adr & 0x1fff ) ] | |
65 * tr=0 mmu=IOPAGE+0xa0 | |
66 * tr=1 mmu=IOPAGE+0xa8 | |
1 | 67 * |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
68 * IOPAGE + 0x30 Timer control 0x8f start timer/0x80 stop timer/0x04 update date |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
69 * IOPAGE + 0x31- YY/MM/DD/HH/MM/SS |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
70 * |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
71 * IOPAGE + 0x40 Disk control 0x81 read/0x55 write 0 ... ok / 0xff .. error |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
72 * IOPAGE + 0x41 drive no |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
73 * IOPAGE + 0x42 LSN2 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
74 * IOPAGE + 0x43 LSN1 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
75 * IOPAGE + 0x44 LSN0 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
76 * IOPAGE + 0x45 ADR2 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
77 * IOPAGE + 0x46 ADR1 |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
78 * |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
79 * |
1 | 80 */ |
81 | |
82 #define SECSIZE 256 | |
83 | |
0 | 84 int tflags; |
85 int timer = 1; | |
86 struct termios termsetting; | |
87 | |
88 int xmstat; /* 0= no XMODEM transfer, 1=send, 2=receiver */ | |
89 unsigned char xmbuf[132]; | |
90 int xidx; | |
91 int acknak; | |
92 int rcvdnak; | |
93 int blocknum; | |
94 | |
95 FILE *logfile; | |
96 FILE *infile; | |
97 FILE *xfile; | |
1 | 98 FILE *disk[] = {0,0}; |
0 | 99 |
100 extern void hexadump( unsigned char *b, int l, int loc, int w); | |
101 extern void disasm(int,int); | |
9 | 102 #ifdef USE_MMU |
103 extern char *prog ; // for disass | |
11 | 104 extern Byte * mem0(Byte *iphymem, Word adr, Byte *immu) ; |
9 | 105 #endif |
106 | |
0 | 107 |
1 | 108 void do_timer(int,int); |
109 void do_disk(int,int); | |
4 | 110 void do_mmu(int,int); |
0 | 111 |
112 int char_input(void) { | |
113 int c, w, sum; | |
114 if (!xmstat) { | |
115 if (infile) { | |
116 c = getc(infile); | |
117 if (c == EOF) { | |
118 fclose(infile); | |
119 infile = 0; | |
120 return char_input(); | |
121 } | |
122 if (c == '\n') | |
123 c = '\r'; | |
124 return c; | |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
125 } else { |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
126 usleep(100); |
0 | 127 return getchar(); |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
128 } |
0 | 129 } else if (xmstat == 1) { |
130 if (xidx) { | |
131 c = xmbuf[xidx++]; | |
132 if (xidx == 132) { | |
133 xidx = 0; | |
134 rcvdnak = EOF; | |
135 acknak = 6; | |
136 } | |
137 } else { | |
138 if ((acknak == 21 && rcvdnak == 21) || (acknak == 6 && rcvdnak == 6)) { | |
139 rcvdnak = 0; | |
140 memset(xmbuf, 0, 132); | |
141 w = fread(xmbuf + 3, 1, 128, xfile); | |
142 if (w) { | |
143 printf("Block %3d transmitted, ", blocknum); | |
144 xmbuf[0] = 1; | |
145 xmbuf[1] = blocknum; | |
146 xmbuf[2] = 255 - blocknum; | |
147 blocknum = (blocknum + 1) & 255; | |
148 sum = 0; | |
149 for (w = 3; w < 131; w++) | |
150 sum = (sum + xmbuf[w]) & 255; | |
151 xmbuf[131] = sum; | |
152 acknak = 6; | |
153 c = 1; | |
154 xidx = 1; | |
155 } else { | |
156 printf("EOT transmitted, "); | |
157 acknak = 4; | |
158 c = 4; | |
159 } | |
160 } else if (rcvdnak == 21) { | |
161 rcvdnak = 0; | |
162 printf("Block %3d retransmitted, ", xmbuf[1]); | |
163 c = xmbuf[xidx++]; /*retransmit the same block */ | |
164 } else | |
165 c = EOF; | |
166 } | |
167 return c; | |
168 } else { | |
169 if (acknak == 4) { | |
170 c = 6; | |
171 acknak = 0; | |
172 fclose(xfile); | |
173 xfile = 0; | |
174 xmstat = 0; | |
175 } else if (acknak) { | |
176 c = acknak; | |
177 acknak = 0; | |
178 } else | |
179 c = EOF; | |
180 if (c == 6) | |
181 printf("ACK\n"); | |
182 if (c == 21) | |
183 printf("NAK\n"); | |
184 return c; | |
185 } | |
186 } | |
187 | |
9 | 188 int do_input(int a) { |
0 | 189 static int c, f = EOF; |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
190 if (a == 0+(IOPAGE&0xff)) { |
0 | 191 if (f == EOF) |
192 f = char_input(); | |
193 if (f != EOF) | |
194 c = f; | |
195 return 2 + (f != EOF); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
196 } else if (a == 1+(IOPAGE&0xff)) { /*data port*/ |
0 | 197 if (f == EOF) |
198 f = char_input(); | |
199 if (f != EOF) { | |
200 c = f; | |
201 f = EOF; | |
202 } | |
203 return c; | |
204 } | |
9 | 205 return mem[(IOPAGE&0xff00) + a]; |
0 | 206 } |
207 | |
208 void do_output(int a, int c) { | |
209 int i, sum; | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
210 if (a == 1+(IOPAGE&0xff)) { /* ACIA data port,ignore address */ |
0 | 211 if (!xmstat) { |
212 if (logfile && c != 127 && (c >= ' ' || c == '\n')) | |
213 putc(c, logfile); | |
214 putchar(c); | |
215 fflush(stdout); | |
216 } else if (xmstat == 1) { | |
217 rcvdnak = c; | |
218 if (c == 6 && acknak == 4) { | |
219 fclose(xfile); | |
220 xfile = 0; | |
221 xmstat = 0; | |
222 } | |
223 if (c == 6) | |
224 printf("ACK\n"); | |
225 if (c == 21) | |
226 printf("NAK\n"); | |
227 if (c == 24) { | |
228 printf("CAN\n"); | |
229 fclose(xfile); | |
230 xmstat = 0; | |
231 xfile = 0; | |
232 } | |
233 } else { | |
234 if (xidx == 0 && c == 4) { | |
235 acknak = 4; | |
236 printf("EOT received, "); | |
237 } | |
238 xmbuf[xidx++] = c; | |
239 if (xidx == 132) { | |
240 sum = 0; | |
241 for (i = 3; i < 131; i++) | |
242 sum = (sum + xmbuf[i]) & 255; | |
243 if (xmbuf[0] == 1 && xmbuf[1] == 255 - xmbuf[2] | |
244 && sum == xmbuf[131]) | |
245 acknak = 6; | |
246 else | |
247 acknak = 21; | |
248 printf("Block %3d received, ", xmbuf[1]); | |
249 if (blocknum == xmbuf[1]) { | |
250 blocknum = (blocknum + 1) & 255; | |
251 fwrite(xmbuf + 3, 1, 128, xfile); | |
252 } | |
253 xidx = 0; | |
254 } | |
255 } | |
11 | 256 } else if (a >= 0x40+(IOPAGE&0xff)) { /* disk */ |
257 do_disk(a,c); | |
258 } else if (a >= 0x30+(IOPAGE&0xff)) { /* timer */ | |
259 do_timer(a,c); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
260 } else if (a >= 0x10+(IOPAGE&0xff)) { /* mmu */ |
4 | 261 do_mmu(a,c); |
0 | 262 } |
263 } | |
264 | |
265 void restore_term(void) { | |
266 tcsetattr(0, TCSAFLUSH, &termsetting); | |
267 fcntl(0, F_SETFL, tflags); | |
268 signal(SIGALRM, SIG_IGN); | |
269 } | |
270 | |
271 void do_exit(void) { | |
272 restore_term(); | |
273 exit(0); | |
274 } | |
275 | |
1 | 276 void do_timer(int a, int c) { |
277 struct itimerval timercontrol; | |
9 | 278 if (a==0x30+(IOPAGE&0xff) && c==0x8f) { |
1 | 279 timercontrol.it_interval.tv_sec = 0; |
280 timercontrol.it_interval.tv_usec = 20000; | |
281 timercontrol.it_value.tv_sec = 0; | |
282 timercontrol.it_value.tv_usec = 20000; | |
283 setitimer(ITIMER_REAL, &timercontrol, NULL); | |
9 | 284 } else if (a==0x30+(IOPAGE&0xff) && c==0x80) { |
1 | 285 timercontrol.it_interval.tv_sec = 0; |
286 timercontrol.it_interval.tv_usec = 0; | |
287 setitimer(ITIMER_REAL, &timercontrol, NULL); | |
9 | 288 } else if (a==0x30+(IOPAGE&0xff) && c==0x04) { |
1 | 289 time_t tm = time(0); |
290 struct tm *t = localtime(&tm); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
291 mem[IOPAGE+0x31] = t->tm_year; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
292 mem[IOPAGE+0x32] = t->tm_mon; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
293 mem[IOPAGE+0x33] = t->tm_mday; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
294 mem[IOPAGE+0x34] = t->tm_hour; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
295 mem[IOPAGE+0x35] = t->tm_min; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
296 mem[IOPAGE+0x36] = t->tm_sec; |
1 | 297 } else { |
9 | 298 mem[(IOPAGE&0xff00)+a]=c; |
1 | 299 } |
300 } | |
301 | |
302 void do_disk(int a, int c) { | |
9 | 303 if (a!=0x40+(IOPAGE&0xff)) { |
304 mem[(IOPAGE&0xff00)+a]=c; | |
1 | 305 return; |
306 } | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
307 int drv = mem[IOPAGE+0x41]; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
308 int lsn = (mem[IOPAGE+0x42]<<16) + (mem[IOPAGE+0x43]<<8) + mem[IOPAGE+0x44]; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
309 int buf = (mem[IOPAGE+0x45]<<8) + mem[IOPAGE+0x46]; |
1 | 310 if (drv > 1 || disk[drv]==0) goto error; |
311 if (c==0x81) { | |
312 if (lseek(fileno(disk[drv]),lsn*SECSIZE,SEEK_SET)==-1) goto error; | |
313 if (read(fileno(disk[drv]),&mem[buf],SECSIZE)==-1) goto error; | |
314 } else if (c==0x55) { | |
315 if (lseek(fileno(disk[drv]),lsn*SECSIZE,SEEK_SET)==-1) goto error; | |
316 if (write(fileno(disk[drv]),&mem[buf],SECSIZE)==-1) goto error; | |
317 } | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
318 mem[IOPAGE+0x40] = 0; |
1 | 319 return; |
320 error : | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
321 mem[IOPAGE+0x40] = 0xff; |
1 | 322 } |
323 | |
4 | 324 void do_mmu(int a, int c) |
325 { | |
326 #ifdef USE_MMU | |
327 | |
9 | 328 if (a==0x11+(IOPAGE&0xff)) { |
4 | 329 if (c&0) { |
330 mmu = phymem+memsize-0x10000+0xffa0; | |
331 } else { | |
332 mmu = phymem+memsize-0x10000+0xffa8; | |
333 } | |
334 } | |
11 | 335 mem[(IOPAGE&0xff00)+a] = c; // other register such as 0xffa0-0xffaf |
4 | 336 #endif |
337 } | |
338 | |
0 | 339 typedef struct bp { |
340 int address; | |
341 int count; | |
342 struct bp *next; | |
343 } BP, *BPTR; | |
344 | |
345 BPTR breakpoint = 0; | |
346 int bpskip = 0; | |
347 int trskip = 0; | |
348 int stkskip = 0; | |
349 | |
350 int getarg(char *buf, char** next) { | |
351 return strtol(buf,(char**)next,0); | |
352 } | |
353 | |
354 void printhelp(void) | |
355 { | |
356 printf( | |
357 " s [count] one step trace\n" | |
358 " n step over\n" | |
359 " f finish this call (until stack pop)\n" | |
360 " b [adr] set break point\n" | |
361 " l break point list\n" | |
362 " d [n] delte break point list\n" | |
363 " c [count] continue;\n" | |
364 " x [adr] dump\n" | |
9 | 365 #ifdef USE_MMU |
366 " xp [adr] dump physical memory\n" | |
367 #endif | |
0 | 368 " xi [adr] disassemble\n" |
1 | 369 " 0 file disk drive 0 image\n" |
370 " 1 file disk drive 1 image\n" | |
0 | 371 " L file start log to file\n" |
372 " S file set input file\n" | |
373 " X exit\n" | |
374 " q exit\n" | |
375 " U file upload from srecord file \n" | |
376 " D file download to srecord file \n" | |
377 " R do reset\n" | |
378 " h,? print this\n" | |
379 ); | |
380 } | |
381 | |
382 void do_escape(void) { | |
383 char s[80]; | |
384 int adr,skip; | |
385 if (bpskip) { // skip unbreak instruction | |
386 bpskip--; | |
387 for(BPTR b = breakpoint; b ; b=b->next) { | |
388 if (pcreg==b->address) { | |
389 if (b->count) b->count--; | |
390 if (b->count==0) { | |
391 goto restart0; | |
392 } | |
393 } | |
394 } | |
395 return; | |
396 } | |
397 if (stkskip) { // skip until return | |
398 if (sreg < stkskip ) return; | |
399 } | |
400 restart0: | |
401 stkskip = 0; | |
402 restore_term(); | |
9 | 403 #ifdef USE_MMU |
11 | 404 Byte *phyadr = mem0(phymem,pcreg,mmu); |
9 | 405 prog = (char*)phyadr - pcreg; |
406 #endif | |
0 | 407 do_trace(stdout); |
408 if (trskip>1) { // show trace and step | |
409 trskip--; | |
410 set_term(escchar); | |
411 return; | |
412 } | |
413 restart: | |
414 printf("v09>"); | |
415 fgets(s, 80, stdin); | |
416 if (s[0]) | |
417 s[strlen(s) - 1] = 0; | |
418 switch (s[0]) { | |
419 case 's': // one step trace | |
420 trskip = 1; | |
421 if (s[1]) { | |
422 trskip = getarg(s+1,0); | |
423 } | |
424 bpskip = 0; | |
425 attention = escape = 1; | |
426 break; | |
427 case 'n': // step over | |
428 stkskip = sreg; | |
429 attention = escape = 1; | |
430 break; | |
431 case 'f': // finish this call (until stack pop) | |
432 stkskip = sreg + 2; | |
433 attention = escape = 1; | |
434 break; | |
435 case 'b': // set break point | |
436 { | |
437 BPTR bp = calloc(1,sizeof(BP)); | |
438 bp->next = breakpoint; | |
439 breakpoint = bp; | |
440 bp->count = 1; | |
441 if (s[1]) { | |
442 char *next; | |
443 bp->address = getarg(s+1,&next); | |
444 if (next[0]) { | |
445 bp->count = getarg(next,&next); | |
446 } | |
447 } else { | |
448 bp->address = pcreg; | |
449 } | |
450 } | |
451 bpskip = -1; | |
452 goto restart; | |
453 case 'l': // break point list | |
454 for(BPTR bp = breakpoint; bp ; bp = bp->next) { | |
455 printf("%x %i\n", bp->address, bp->count); | |
456 } | |
457 goto restart; | |
458 case 'd': // delte break point list | |
459 if (s[1]) { | |
460 int trskip = getarg(s+1,0); | |
461 BPTR *prev = &breakpoint; | |
462 for(BPTR bp = breakpoint; bp ; bp = bp->next) { | |
463 if (trskip-- == 0) { | |
464 if (bp) { | |
465 *prev = bp->next; | |
466 } | |
467 break; | |
468 } | |
469 prev = &bp->next; | |
470 } | |
471 } | |
472 goto restart; | |
473 case 'c': // continue; | |
474 bpskip = -1; | |
475 attention = escape = 1; | |
476 if (s[1]) { | |
477 bpskip = getarg(s+1,0); | |
478 } | |
479 break; | |
480 case 'x': // dump | |
481 skip = 1; | |
482 if (s[1]=='i') skip=2; | |
9 | 483 if (s[1]=='p') skip=2; |
0 | 484 if (s[skip]) { |
485 char *next; | |
486 int adr = getarg(s+skip,&next); | |
487 int len = 32; | |
488 if (next[0]) { | |
489 len = getarg(next,&next); | |
490 } | |
9 | 491 if (skip==2 && s[1]=='i') { |
492 for(int i=0; len > 0 ; i+=16, len-=16) { | |
493 #ifdef USE_MMU | |
11 | 494 Byte *phyadr = mem0(phymem,adr+i,mmu); |
9 | 495 prog = (char*)phyadr - adr; |
496 #endif | |
11 | 497 disasm(adr+i,adr+i+(len>16?16:len)); |
9 | 498 } |
0 | 499 } else { |
9 | 500 #ifdef USE_MMU |
501 for(int i=0; len > 0 ; i+=16, len-=16) { | |
502 if (skip==2 && s[1]=='p') { | |
503 if (adr+i > memsize) goto restart; | |
504 hexadump(phymem+adr+i,len>16?16:len,adr+i,16); | |
505 } else { | |
11 | 506 Byte *phyadr = mem0(phymem,adr+i,mmu); |
9 | 507 if (phyadr > phymem+memsize) goto restart; |
508 hexadump(phyadr,len>16?16:len,adr+i,16); | |
509 } | |
510 } | |
511 #else | |
0 | 512 for(int i=0; len > 0 ; i+=16, len-=16) { |
513 hexadump(mem+adr+i,len>16?16:len,adr+i,16); | |
514 } | |
9 | 515 #endif |
0 | 516 } |
517 } else | |
518 disasm(pcreg,pcreg+32); | |
519 goto restart; | |
520 case 'L': | |
521 if (logfile) | |
522 fclose(logfile); | |
523 logfile = 0; | |
524 if (s[1]) { | |
1 | 525 int i=1; while(s[i]==' ') i++; |
526 logfile = fopen(s + i, "w"); | |
0 | 527 } |
528 break; | |
529 case 'S': | |
530 if (infile) | |
531 fclose(infile); | |
532 infile = 0; | |
533 if (s[1]) { | |
1 | 534 int i=1; while(s[i]==' ') i++; |
535 infile = fopen(s + i, "r"); | |
0 | 536 } |
537 break; | |
538 case 'h': | |
539 case '?': | |
540 printhelp(); | |
541 goto restart; | |
542 case 'X': | |
543 case 'q': | |
544 if (!xmstat) | |
545 do_exit(); | |
546 else { | |
547 xmstat = 0; | |
548 fclose(xfile); | |
549 xfile = 0; | |
550 } | |
551 break; | |
1 | 552 case '0': |
553 case '1': | |
554 { FILE **drv = &disk[ s[0]-'0'] ; | |
555 if (*drv) | |
556 fclose(*drv); | |
557 *drv = 0; | |
558 if (s[1]) { | |
559 int i=1; while(s[i]==' ') i++; | |
560 *drv = fopen(s + i, "r+b"); | |
561 if ( *drv == 0 ) { printf("can't open %s\n", &s[i]); } | |
562 } | |
563 } | |
564 break; | |
0 | 565 case 'U': |
566 if (xfile) | |
567 fclose(xfile); | |
568 xfile = 0; | |
569 if (s[1]) { | |
1 | 570 int i=1; while(s[i]==' ') i++; |
571 xfile = fopen(s + i, "rb"); | |
572 if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); } | |
0 | 573 } |
574 if (xfile) | |
575 xmstat = 1; | |
576 else | |
577 xmstat = 0; | |
578 xidx = 0; | |
579 acknak = 21; | |
580 rcvdnak = EOF; | |
581 blocknum = 1; | |
582 break; | |
583 case 'D': | |
584 if (xfile) | |
585 fclose(xfile); | |
586 xfile = 0; | |
587 if (s[1]) { | |
1 | 588 int i=1; while(s[i]==' ') i++; |
589 xfile = fopen(s + i, "wb"); | |
590 if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); } | |
0 | 591 } |
592 if (xfile) | |
593 xmstat = 2; | |
594 else | |
595 xmstat = 0; | |
596 xidx = 0; | |
597 acknak = 21; | |
598 blocknum = 1; | |
599 break; | |
600 case 'R': | |
601 pcreg = (mem[0xfffe] << 8) + mem[0xffff]; | |
602 break; | |
603 } | |
604 if (tracing||breakpoint||trskip||bpskip||stkskip) { attention = escape = 1; } | |
605 else attention = 0; | |
606 set_term(escchar); | |
607 } | |
608 | |
609 void timehandler(int sig) { | |
610 attention = 1; | |
611 irq = 2; | |
612 signal(SIGALRM, timehandler); | |
613 } | |
614 | |
615 void handler(int sig) { | |
616 escape = 1; | |
617 attention = 1; | |
618 bpskip = 0; | |
619 stkskip = 0; | |
620 } | |
621 | |
622 void set_term(char c) { | |
623 struct termios newterm; | |
624 struct itimerval timercontrol; | |
625 signal(SIGQUIT, SIG_IGN); | |
626 signal(SIGTSTP, SIG_IGN); | |
627 signal(SIGINT, handler); | |
628 signal(SIGUSR1, handler); | |
629 tcgetattr(0, &termsetting); | |
630 newterm = termsetting; | |
631 newterm.c_iflag = newterm.c_iflag & ~INLCR & ~ICRNL; | |
632 newterm.c_lflag = newterm.c_lflag & ~ECHO & ~ICANON; | |
633 newterm.c_cc[VTIME] = 0; | |
634 newterm.c_cc[VMIN] = 1; | |
635 newterm.c_cc[VINTR] = escchar; | |
636 tcsetattr(0, TCSAFLUSH, &newterm); | |
637 tflags = fcntl(0, F_GETFL, 0); | |
638 fcntl(0, F_SETFL, tflags | O_NDELAY); /* Make input from stdin non-blocking */ | |
639 signal(SIGALRM, timehandler); | |
640 timercontrol.it_interval.tv_sec = 0; | |
641 timercontrol.it_interval.tv_usec = 20000; | |
642 timercontrol.it_value.tv_sec = 0; | |
643 timercontrol.it_value.tv_usec = 20000; | |
644 if (timer) | |
645 setitimer(ITIMER_REAL, &timercontrol, NULL); | |
646 } |