Mercurial > hg > Members > kono > os9 > sbc09
annotate io.c @ 7:a6db579d8c11
level 2 rom preparing...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 05 Jul 2018 02:00:14 +0900 |
parents | 6159cc57d44e |
children | cb7aa75418b8 |
rev | line source |
---|---|
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
1 /* 6808 Simulator V09. |
0 | 2 |
3 created 1993,1994 by L.C. Benschop. | |
4 copyleft (c) 1994-2014 by the sbc09 team, see AUTHORS for more details. | |
5 license: GNU General Public License version 2, see LICENSE for more details. | |
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); | |
102 | |
1 | 103 void do_timer(int,int); |
104 void do_disk(int,int); | |
4 | 105 void do_mmu(int,int); |
0 | 106 |
107 int char_input(void) { | |
108 int c, w, sum; | |
109 if (!xmstat) { | |
110 if (infile) { | |
111 c = getc(infile); | |
112 if (c == EOF) { | |
113 fclose(infile); | |
114 infile = 0; | |
115 return char_input(); | |
116 } | |
117 if (c == '\n') | |
118 c = '\r'; | |
119 return c; | |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
120 } else { |
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
121 usleep(100); |
0 | 122 return getchar(); |
2
31d96e2b364e
add virtual hd option to v09
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
123 } |
0 | 124 } else if (xmstat == 1) { |
125 if (xidx) { | |
126 c = xmbuf[xidx++]; | |
127 if (xidx == 132) { | |
128 xidx = 0; | |
129 rcvdnak = EOF; | |
130 acknak = 6; | |
131 } | |
132 } else { | |
133 if ((acknak == 21 && rcvdnak == 21) || (acknak == 6 && rcvdnak == 6)) { | |
134 rcvdnak = 0; | |
135 memset(xmbuf, 0, 132); | |
136 w = fread(xmbuf + 3, 1, 128, xfile); | |
137 if (w) { | |
138 printf("Block %3d transmitted, ", blocknum); | |
139 xmbuf[0] = 1; | |
140 xmbuf[1] = blocknum; | |
141 xmbuf[2] = 255 - blocknum; | |
142 blocknum = (blocknum + 1) & 255; | |
143 sum = 0; | |
144 for (w = 3; w < 131; w++) | |
145 sum = (sum + xmbuf[w]) & 255; | |
146 xmbuf[131] = sum; | |
147 acknak = 6; | |
148 c = 1; | |
149 xidx = 1; | |
150 } else { | |
151 printf("EOT transmitted, "); | |
152 acknak = 4; | |
153 c = 4; | |
154 } | |
155 } else if (rcvdnak == 21) { | |
156 rcvdnak = 0; | |
157 printf("Block %3d retransmitted, ", xmbuf[1]); | |
158 c = xmbuf[xidx++]; /*retransmit the same block */ | |
159 } else | |
160 c = EOF; | |
161 } | |
162 return c; | |
163 } else { | |
164 if (acknak == 4) { | |
165 c = 6; | |
166 acknak = 0; | |
167 fclose(xfile); | |
168 xfile = 0; | |
169 xmstat = 0; | |
170 } else if (acknak) { | |
171 c = acknak; | |
172 acknak = 0; | |
173 } else | |
174 c = EOF; | |
175 if (c == 6) | |
176 printf("ACK\n"); | |
177 if (c == 21) | |
178 printf("NAK\n"); | |
179 return c; | |
180 } | |
181 } | |
182 | |
183 int do_input( a) { | |
184 static int c, f = EOF; | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
185 if (a == 0+(IOPAGE&0xff)) { |
0 | 186 if (f == EOF) |
187 f = char_input(); | |
188 if (f != EOF) | |
189 c = f; | |
190 return 2 + (f != EOF); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
191 } else if (a == 1+(IOPAGE&0xff)) { /*data port*/ |
0 | 192 if (f == EOF) |
193 f = char_input(); | |
194 if (f != EOF) { | |
195 c = f; | |
196 f = EOF; | |
197 } | |
198 return c; | |
199 } | |
3 | 200 return mem[IOPAGE + a]; |
0 | 201 } |
202 | |
203 void do_output(int a, int c) { | |
204 int i, sum; | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
205 if (a == 1+(IOPAGE&0xff)) { /* ACIA data port,ignore address */ |
0 | 206 if (!xmstat) { |
207 if (logfile && c != 127 && (c >= ' ' || c == '\n')) | |
208 putc(c, logfile); | |
209 putchar(c); | |
210 fflush(stdout); | |
211 } else if (xmstat == 1) { | |
212 rcvdnak = c; | |
213 if (c == 6 && acknak == 4) { | |
214 fclose(xfile); | |
215 xfile = 0; | |
216 xmstat = 0; | |
217 } | |
218 if (c == 6) | |
219 printf("ACK\n"); | |
220 if (c == 21) | |
221 printf("NAK\n"); | |
222 if (c == 24) { | |
223 printf("CAN\n"); | |
224 fclose(xfile); | |
225 xmstat = 0; | |
226 xfile = 0; | |
227 } | |
228 } else { | |
229 if (xidx == 0 && c == 4) { | |
230 acknak = 4; | |
231 printf("EOT received, "); | |
232 } | |
233 xmbuf[xidx++] = c; | |
234 if (xidx == 132) { | |
235 sum = 0; | |
236 for (i = 3; i < 131; i++) | |
237 sum = (sum + xmbuf[i]) & 255; | |
238 if (xmbuf[0] == 1 && xmbuf[1] == 255 - xmbuf[2] | |
239 && sum == xmbuf[131]) | |
240 acknak = 6; | |
241 else | |
242 acknak = 21; | |
243 printf("Block %3d received, ", xmbuf[1]); | |
244 if (blocknum == xmbuf[1]) { | |
245 blocknum = (blocknum + 1) & 255; | |
246 fwrite(xmbuf + 3, 1, 128, xfile); | |
247 } | |
248 xidx = 0; | |
249 } | |
250 } | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
251 } else if (a >= 0x10+(IOPAGE&0xff)) { /* mmu */ |
4 | 252 do_mmu(a,c); |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
253 } else if (a >= 0x30+(IOPAGE&0xff)) { /* timer */ |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
254 do_timer(a,c); |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
255 } else if (a >= 0x40+(IOPAGE&0xff)) { /* disk */ |
4 | 256 do_disk(a,c); |
0 | 257 } |
258 } | |
259 | |
260 void restore_term(void) { | |
261 tcsetattr(0, TCSAFLUSH, &termsetting); | |
262 fcntl(0, F_SETFL, tflags); | |
263 signal(SIGALRM, SIG_IGN); | |
264 } | |
265 | |
266 void do_exit(void) { | |
267 restore_term(); | |
268 exit(0); | |
269 } | |
270 | |
1 | 271 void do_timer(int a, int c) { |
272 struct itimerval timercontrol; | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
273 if (a==0x30 && c==0x8f) { |
1 | 274 timercontrol.it_interval.tv_sec = 0; |
275 timercontrol.it_interval.tv_usec = 20000; | |
276 timercontrol.it_value.tv_sec = 0; | |
277 timercontrol.it_value.tv_usec = 20000; | |
278 setitimer(ITIMER_REAL, &timercontrol, NULL); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
279 } else if (a==0x30 && c==0x80) { |
1 | 280 timercontrol.it_interval.tv_sec = 0; |
281 timercontrol.it_interval.tv_usec = 0; | |
282 setitimer(ITIMER_REAL, &timercontrol, NULL); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
283 } else if (a==0x30 && c==0x04) { |
1 | 284 time_t tm = time(0); |
285 struct tm *t = localtime(&tm); | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
286 mem[IOPAGE+0x31] = t->tm_year; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
287 mem[IOPAGE+0x32] = t->tm_mon; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
288 mem[IOPAGE+0x33] = t->tm_mday; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
289 mem[IOPAGE+0x34] = t->tm_hour; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
290 mem[IOPAGE+0x35] = t->tm_min; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
291 mem[IOPAGE+0x36] = t->tm_sec; |
1 | 292 } else { |
293 mem[IOPAGE+a]=c; | |
294 } | |
295 } | |
296 | |
297 void do_disk(int a, int c) { | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
298 if (a!=0x40) { |
1 | 299 mem[IOPAGE+a]=c; |
300 return; | |
301 } | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
302 int drv = mem[IOPAGE+0x41]; |
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
303 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
|
304 int buf = (mem[IOPAGE+0x45]<<8) + mem[IOPAGE+0x46]; |
1 | 305 if (drv > 1 || disk[drv]==0) goto error; |
306 if (c==0x81) { | |
307 if (lseek(fileno(disk[drv]),lsn*SECSIZE,SEEK_SET)==-1) goto error; | |
308 if (read(fileno(disk[drv]),&mem[buf],SECSIZE)==-1) goto error; | |
309 } else if (c==0x55) { | |
310 if (lseek(fileno(disk[drv]),lsn*SECSIZE,SEEK_SET)==-1) goto error; | |
311 if (write(fileno(disk[drv]),&mem[buf],SECSIZE)==-1) goto error; | |
312 } | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
313 mem[IOPAGE+0x40] = 0; |
1 | 314 return; |
315 error : | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
316 mem[IOPAGE+0x40] = 0xff; |
1 | 317 } |
318 | |
4 | 319 void do_mmu(int a, int c) |
320 { | |
321 #ifdef USE_MMU | |
322 | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
323 if (a==0x11) { |
4 | 324 if (c&0) { |
325 mmu = phymem+memsize-0x10000+0xffa0; | |
326 } else { | |
327 mmu = phymem+memsize-0x10000+0xffa8; | |
328 } | |
329 mem[IOPAGE+a] = c; | |
7
a6db579d8c11
level 2 rom preparing...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
330 } if (0x20 <= a && a <= 0x2f) { |
4 | 331 mem[IOPAGE+a] = c; |
332 } | |
333 | |
334 #endif | |
335 } | |
336 | |
0 | 337 typedef struct bp { |
338 int address; | |
339 int count; | |
340 struct bp *next; | |
341 } BP, *BPTR; | |
342 | |
343 BPTR breakpoint = 0; | |
344 int bpskip = 0; | |
345 int trskip = 0; | |
346 int stkskip = 0; | |
347 | |
348 int getarg(char *buf, char** next) { | |
349 return strtol(buf,(char**)next,0); | |
350 } | |
351 | |
352 void printhelp(void) | |
353 { | |
354 printf( | |
355 " s [count] one step trace\n" | |
356 " n step over\n" | |
357 " f finish this call (until stack pop)\n" | |
358 " b [adr] set break point\n" | |
359 " l break point list\n" | |
360 " d [n] delte break point list\n" | |
361 " c [count] continue;\n" | |
362 " x [adr] dump\n" | |
363 " xi [adr] disassemble\n" | |
1 | 364 " 0 file disk drive 0 image\n" |
365 " 1 file disk drive 1 image\n" | |
0 | 366 " L file start log to file\n" |
367 " S file set input file\n" | |
368 " X exit\n" | |
369 " q exit\n" | |
370 " U file upload from srecord file \n" | |
371 " D file download to srecord file \n" | |
372 " R do reset\n" | |
373 " h,? print this\n" | |
374 ); | |
375 } | |
376 | |
377 void do_escape(void) { | |
378 char s[80]; | |
379 int adr,skip; | |
380 if (bpskip) { // skip unbreak instruction | |
381 bpskip--; | |
382 for(BPTR b = breakpoint; b ; b=b->next) { | |
383 if (pcreg==b->address) { | |
384 if (b->count) b->count--; | |
385 if (b->count==0) { | |
386 goto restart0; | |
387 } | |
388 } | |
389 } | |
390 return; | |
391 } | |
392 if (stkskip) { // skip until return | |
393 if (sreg < stkskip ) return; | |
394 } | |
395 restart0: | |
396 stkskip = 0; | |
397 restore_term(); | |
398 do_trace(stdout); | |
399 if (trskip>1) { // show trace and step | |
400 trskip--; | |
401 set_term(escchar); | |
402 return; | |
403 } | |
404 restart: | |
405 printf("v09>"); | |
406 fgets(s, 80, stdin); | |
407 if (s[0]) | |
408 s[strlen(s) - 1] = 0; | |
409 switch (s[0]) { | |
410 case 's': // one step trace | |
411 trskip = 1; | |
412 if (s[1]) { | |
413 trskip = getarg(s+1,0); | |
414 } | |
415 bpskip = 0; | |
416 attention = escape = 1; | |
417 break; | |
418 case 'n': // step over | |
419 stkskip = sreg; | |
420 attention = escape = 1; | |
421 break; | |
422 case 'f': // finish this call (until stack pop) | |
423 stkskip = sreg + 2; | |
424 attention = escape = 1; | |
425 break; | |
426 case 'b': // set break point | |
427 { | |
428 BPTR bp = calloc(1,sizeof(BP)); | |
429 bp->next = breakpoint; | |
430 breakpoint = bp; | |
431 bp->count = 1; | |
432 if (s[1]) { | |
433 char *next; | |
434 bp->address = getarg(s+1,&next); | |
435 if (next[0]) { | |
436 bp->count = getarg(next,&next); | |
437 } | |
438 } else { | |
439 bp->address = pcreg; | |
440 } | |
441 } | |
442 bpskip = -1; | |
443 goto restart; | |
444 case 'l': // break point list | |
445 for(BPTR bp = breakpoint; bp ; bp = bp->next) { | |
446 printf("%x %i\n", bp->address, bp->count); | |
447 } | |
448 goto restart; | |
449 case 'd': // delte break point list | |
450 if (s[1]) { | |
451 int trskip = getarg(s+1,0); | |
452 BPTR *prev = &breakpoint; | |
453 for(BPTR bp = breakpoint; bp ; bp = bp->next) { | |
454 if (trskip-- == 0) { | |
455 if (bp) { | |
456 *prev = bp->next; | |
457 } | |
458 break; | |
459 } | |
460 prev = &bp->next; | |
461 } | |
462 } | |
463 goto restart; | |
464 case 'c': // continue; | |
465 bpskip = -1; | |
466 attention = escape = 1; | |
467 if (s[1]) { | |
468 bpskip = getarg(s+1,0); | |
469 } | |
470 break; | |
471 case 'x': // dump | |
472 skip = 1; | |
473 if (s[1]=='i') skip=2; | |
474 if (s[skip]) { | |
475 char *next; | |
476 int adr = getarg(s+skip,&next); | |
477 int len = 32; | |
478 if (next[0]) { | |
479 len = getarg(next,&next); | |
480 } | |
481 if (skip==2) { | |
482 disasm(adr,adr+len); | |
483 } else { | |
484 for(int i=0; len > 0 ; i+=16, len-=16) { | |
485 hexadump(mem+adr+i,len>16?16:len,adr+i,16); | |
486 } | |
487 } | |
488 } else | |
489 disasm(pcreg,pcreg+32); | |
490 goto restart; | |
491 case 'L': | |
492 if (logfile) | |
493 fclose(logfile); | |
494 logfile = 0; | |
495 if (s[1]) { | |
1 | 496 int i=1; while(s[i]==' ') i++; |
497 logfile = fopen(s + i, "w"); | |
0 | 498 } |
499 break; | |
500 case 'S': | |
501 if (infile) | |
502 fclose(infile); | |
503 infile = 0; | |
504 if (s[1]) { | |
1 | 505 int i=1; while(s[i]==' ') i++; |
506 infile = fopen(s + i, "r"); | |
0 | 507 } |
508 break; | |
509 case 'h': | |
510 case '?': | |
511 printhelp(); | |
512 goto restart; | |
513 case 'X': | |
514 case 'q': | |
515 if (!xmstat) | |
516 do_exit(); | |
517 else { | |
518 xmstat = 0; | |
519 fclose(xfile); | |
520 xfile = 0; | |
521 } | |
522 break; | |
1 | 523 case '0': |
524 case '1': | |
525 { FILE **drv = &disk[ s[0]-'0'] ; | |
526 if (*drv) | |
527 fclose(*drv); | |
528 *drv = 0; | |
529 if (s[1]) { | |
530 int i=1; while(s[i]==' ') i++; | |
531 *drv = fopen(s + i, "r+b"); | |
532 if ( *drv == 0 ) { printf("can't open %s\n", &s[i]); } | |
533 } | |
534 } | |
535 break; | |
0 | 536 case 'U': |
537 if (xfile) | |
538 fclose(xfile); | |
539 xfile = 0; | |
540 if (s[1]) { | |
1 | 541 int i=1; while(s[i]==' ') i++; |
542 xfile = fopen(s + i, "rb"); | |
543 if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); } | |
0 | 544 } |
545 if (xfile) | |
546 xmstat = 1; | |
547 else | |
548 xmstat = 0; | |
549 xidx = 0; | |
550 acknak = 21; | |
551 rcvdnak = EOF; | |
552 blocknum = 1; | |
553 break; | |
554 case 'D': | |
555 if (xfile) | |
556 fclose(xfile); | |
557 xfile = 0; | |
558 if (s[1]) { | |
1 | 559 int i=1; while(s[i]==' ') i++; |
560 xfile = fopen(s + i, "wb"); | |
561 if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); } | |
0 | 562 } |
563 if (xfile) | |
564 xmstat = 2; | |
565 else | |
566 xmstat = 0; | |
567 xidx = 0; | |
568 acknak = 21; | |
569 blocknum = 1; | |
570 break; | |
571 case 'R': | |
572 pcreg = (mem[0xfffe] << 8) + mem[0xffff]; | |
573 break; | |
574 } | |
575 if (tracing||breakpoint||trskip||bpskip||stkskip) { attention = escape = 1; } | |
576 else attention = 0; | |
577 set_term(escchar); | |
578 } | |
579 | |
580 void timehandler(int sig) { | |
581 attention = 1; | |
582 irq = 2; | |
583 signal(SIGALRM, timehandler); | |
584 } | |
585 | |
586 void handler(int sig) { | |
587 escape = 1; | |
588 attention = 1; | |
589 bpskip = 0; | |
590 stkskip = 0; | |
591 } | |
592 | |
593 void set_term(char c) { | |
594 struct termios newterm; | |
595 struct itimerval timercontrol; | |
596 signal(SIGQUIT, SIG_IGN); | |
597 signal(SIGTSTP, SIG_IGN); | |
598 signal(SIGINT, handler); | |
599 signal(SIGUSR1, handler); | |
600 tcgetattr(0, &termsetting); | |
601 newterm = termsetting; | |
602 newterm.c_iflag = newterm.c_iflag & ~INLCR & ~ICRNL; | |
603 newterm.c_lflag = newterm.c_lflag & ~ECHO & ~ICANON; | |
604 newterm.c_cc[VTIME] = 0; | |
605 newterm.c_cc[VMIN] = 1; | |
606 newterm.c_cc[VINTR] = escchar; | |
607 tcsetattr(0, TCSAFLUSH, &newterm); | |
608 tflags = fcntl(0, F_GETFL, 0); | |
609 fcntl(0, F_SETFL, tflags | O_NDELAY); /* Make input from stdin non-blocking */ | |
610 signal(SIGALRM, timehandler); | |
611 timercontrol.it_interval.tv_sec = 0; | |
612 timercontrol.it_interval.tv_usec = 20000; | |
613 timercontrol.it_value.tv_sec = 0; | |
614 timercontrol.it_value.tv_usec = 20000; | |
615 if (timer) | |
616 setitimer(ITIMER_REAL, &timercontrol, NULL); | |
617 } |