annotate io.c @ 2:31d96e2b364e

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