comparison emu/main.c @ 29:83e80c2c489c

seperated working emu code from broken emu code. wrote dbg interface
author james <jb302@eecs.qmul.ac.uk>
date Sun, 13 Apr 2014 22:42:57 +0100
parents 6d32e54e5c16
children b4a4ae2f127e
comparison
equal deleted inserted replaced
28:6d32e54e5c16 29:83e80c2c489c
40 PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, 40 PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH, PUSH,
41 POP, POP, POP, POP, POP, POP, POP, POP, 41 POP, POP, POP, POP, POP, POP, POP, POP,
42 MUL, DIV, DA, NOP, IN, OUT, INT, HLT 42 MUL, DIV, DA, NOP, IN, OUT, INT, HLT
43 }; 43 };
44 44
45 BYTE run; 45 BYTE free_run; /* free run if not 0 */
46 WIDE ac; 46 WIDE ac; /* address counter */
47 BYTE args[4]; 47 BYTE args[4]; /* dbg args */
48 48
49 /* don't need the file on the MCS-51 version */ 49 /* don't need the file on the MCS-51 version */
50 FILE *fp; 50 FILE *fp;
51 void 51 void
52 snd(BYTE c) { 52 snd(BYTE c) {
65 step(void) { 65 step(void) {
66 IR = fetch(); 66 IR = fetch();
67 (*iset[IR])(); 67 (*iset[IR])();
68 } 68 }
69 69
70 void
71 boot(void) {
72 run = 0;
73 }
74
75
76 void dbgi() { 70 void dbgi() {
77 if (run == 0) { 71 if (free_run == 0) {
78 switch (rcv()) { 72 switch (rcv()) {
79 73
80 /* step */ 74 /* step */
81 case 0x00: 75 case 0x00:
82 step(); 76 step();
83 break; 77 break;
84 78
85 /* run */ 79 /* run */
86 case 0x01: 80 case 0x01:
87 run = 1; 81 args[0] = rcv(); /* length high */
82 args[1] = rcv(); /* length low */
83 tmpw = get_wide(PC);
84 for (ac = tmpw ; ac < tmpw + MWIDE(args[0], args[1]) ; ac++) {
85 step();
86 }
88 break; 87 break;
89 88
90 /* set reg */ 89 /* set reg */
91 case 0x02: 90 case 0x02:
92 args[0] = rcv(); /* reg */ 91 args[0] = rcv(); /* reg */
117 case 0x06: 116 case 0x06:
118 args[0] = rcv(); /* addr high */ 117 args[0] = rcv(); /* addr high */
119 args[1] = rcv(); /* addr low */ 118 args[1] = rcv(); /* addr low */
120 args[2] = rcv(); /* length high */ 119 args[2] = rcv(); /* length high */
121 args[3] = rcv(); /* length low */ 120 args[3] = rcv(); /* length low */
122 tmpw = args[1] | (args[0] << 8); 121 tmpw = MWIDE(args[0], args[1]);
123 for (ac = tmpw; ac < (tmpw + (args[3] | (args[2] << 8))); ac++) { 122 for (ac = tmpw; ac < tmpw + MWIDE(args[2], args[3]); ac++) {
124 if (ac >= 0xFFFF) { 123 if (ac >= 0xFFFF) {
125 break; 124 break;
126 } 125 }
127 mem[ac] = rcv(); 126 mem[ac] = rcv();
128 } 127 }
132 case 0x07: 131 case 0x07:
133 args[0] = rcv(); /* addr high */ 132 args[0] = rcv(); /* addr high */
134 args[1] = rcv(); /* addr low */ 133 args[1] = rcv(); /* addr low */
135 args[2] = rcv(); /* length high */ 134 args[2] = rcv(); /* length high */
136 args[3] = rcv(); /* length low */ 135 args[3] = rcv(); /* length low */
137 tmpw = args[1] | (args[0] << 8); 136 tmpw = MWIDE(args[0], args[1]);
138 for (ac = tmpw; ac < (tmpw + (args[3] | (args[2] << 8))); ac++) { 137 for (ac = tmpw; ac < tmpw + MWIDE(args[2], args[3]); ac++) {
139 if (ac >= 0xFFFF) { 138 if (ac >= 0xFFFF) {
140 break; 139 break;
141 } 140 }
142 snd(mem[ac]); 141 snd(mem[ac]);
143 } 142 }
144 break; 143 break;
145 144
146 /* get A */ 145 /* get A */
147 case 0x09: 146 case 0x09:
148 snd(A); 147 snd(A);
148 break;
149 149
150 /* get flags */ 150 /* get flags */
151 case 0x0F: 151 case 0x0A:
152 snd(flags); 152 snd(flags);
153 break;
153 154
154 /* get instruction register */ 155 /* get instruction register */
155 case 0x10: 156 case 0x0B:
156 snd(IR); 157 snd(IR);
158 break;
157 } 159 }
158 } 160 }
159 } 161 }
160 162
161 void 163 void
162 main(void) { 164 main(void) {
163 165 /* dont go into free run on restart */
164 A = 0xAA; 166 free_run = 0;
165 IR = 0x12; 167 for (;;) {
166 168 dbgi();
167 unsigned char i;
168 for (i = 0 ; i < 8 ; i++) {
169 set_flag(i, 1);
170 } 169 }
171
172 set_wide(DPTR, 0xDE1D);
173 set_wide(PC, 0xBEFA);
174 set_wide(SP, 0xADEA);
175 set_wide(TMP, 0xEFC3);
176
177 for (i = 0; i < 4; i++) {
178 regs[i] = i;
179 }
180
181 for (i = 8; i < 0x0C; i++) {
182 regs[i] = 0x10 | (i - 8);
183 }
184
185 /* 0xAA 0x12 0xFF
186 * 0x00 0x01 0x02 0x03
187 * 0xDE 0xAD 0xBE 0xFF
188 * 0x10 0x11 0x12 0x13
189 * 0x1D 0xEA 0xFA 0xC3 */
190
191 putchar(A);
192 putchar(IR);
193 putchar(flags);
194
195 for (i = 0; i < 0x10; i++) {
196 putchar(regs[i]);
197 }
198
199 unsigned short int data_pointer = get_wide(DPTR);
200 unsigned short int program_counter = get_wide(PC);
201 unsigned short int stack_pointer = get_wide(SP);
202 unsigned short int temp = get_wide(tmp);
203
204
205
206
207 } 170 }
208 171