2705
|
1 #"Minimum instruction cycle is 333 ns for internal ROM 500 ns for external at 12 MHz"
|
|
2 #That's 4 clks for internal ROM, 6 clocks external
|
|
3 #Above seems to be defined based on external clock input, but there's an internal divider
|
|
4 #Instruction timing tables seem to specified in terms of this divided clock
|
|
5 info
|
|
6 prefix upd78k2_
|
|
7 opcode_size 8
|
|
8 header upd78k2.h
|
|
9 body upd78k2_run_op
|
|
10 extra_tables sfr bit1 bit2 muldiv base sfrbit spmov indexed regind alt_base alt_indexed alt_regind mov_reg
|
|
11 include upd78k2_util.c
|
|
12 regs
|
|
13 main 8 x a c b e d l h
|
|
14 psw 8
|
|
15 pc 16
|
|
16 sp 16
|
|
17 rbs 8
|
|
18 int_enable 8
|
|
19 int_priority_flag 8
|
|
20 chflags 8
|
|
21 zflag 8
|
|
22 scratch1 32
|
|
23 scratch2 32
|
|
24 mem_pointers ptr8 4
|
|
25 port_data 8 8
|
|
26 port_mode 8 8
|
|
27 mm 8
|
|
28 iram 8 256
|
|
29 flags
|
|
30 register psw
|
|
31 I 7 none int_enable
|
|
32 Z 6 zero zflag
|
|
33 R 5 none rbs.1
|
|
34 A 4 half-carry chflags.3
|
|
35 B 3 none rbs.0
|
|
36 P 1 none int_priority_flag
|
|
37 C 0 carry chflags.7
|
|
38 declare
|
|
39 uint8_t upd78237_sfr_read(uint32_t address, void *context);
|
|
40 void *upd78237_sfr_write(uint32_t address, void *context, uint8_t value);
|
|
41 void init_upd78k2_opts(upd78k2_options *opts, memmap_chunk const *chunks, uint32_t num_chunks);
|
|
42 upd78k2_context *init_upd78k2_context(upd78k2_options *opts);
|
|
43
|
|
44 #Prefix bytes
|
|
45 # 0000 0001 -> saddr becomes sfr, mem becomes &mem
|
|
46 # 0000 0010 -> bit instructions/ conditional branches
|
|
47 # 0000 0011 -> more bit instructions / conditional branches
|
|
48 # 0000 0110 -> base mode
|
|
49 # 0000 1000 -> saddr/sfr bit instructions / conditional branches
|
|
50 # 0000 1001 -> mov !addr16/stbc
|
|
51 # 0000 1010 -> indexed mode
|
|
52 # 0001 0110 -> register indirect
|
|
53
|
|
54 sfr_read
|
|
55 arg offset 8
|
|
56 scratch1 = offset + 0xFF00
|
|
57 ocall read_8
|
|
58
|
|
59 sfr_write
|
|
60 arg offset 8
|
|
61 arg value 8
|
|
62 scratch2 = offset + 0xFF00
|
|
63 scratch1 = value
|
|
64 ocall write_8
|
|
65
|
|
66 iram_read
|
|
67 arg offset 8
|
|
68 local normal_iram 8
|
|
69 normal_iram = 1
|
|
70 if offset >=U 0xE0
|
|
71 #register bank area
|
|
72 switch rbs
|
|
73 case 0
|
|
74 if offset >=U 0xF8
|
|
75 normal_iram = 0
|
|
76 end
|
|
77 case 1
|
|
78 if offset >=U 0xF0
|
|
79 if offset >=U 0xF8
|
|
80 else
|
|
81 normal_iram = 0
|
|
82 end
|
|
83 end
|
|
84 case 2
|
|
85 if offset >=U 0xE8
|
|
86 if offset >=U 0xF0
|
|
87 else
|
|
88 normal_iram = 0
|
|
89 end
|
|
90 end
|
|
91 case 3
|
|
92 if offset >=U 0xE8
|
|
93 else
|
|
94 normal_iram = 0
|
|
95 end
|
|
96 end
|
|
97 end
|
|
98 if normal_iram
|
|
99 scratch1 = iram.offset
|
|
100 else
|
|
101 scratch1 = offset & 7
|
|
102 scratch1 = main.scratch1
|
|
103 end
|
|
104
|
|
105 iram_write
|
|
106 arg offset 8
|
|
107 arg value 8
|
|
108 local normal_iram 8
|
|
109 local regnum 8
|
|
110 normal_iram = 1
|
|
111 if offset >=U 0xE0
|
|
112 #register bank area
|
|
113 switch rbs
|
|
114 case 0
|
|
115 if offset >=U 0xF8
|
|
116 normal_iram = 0
|
|
117 end
|
|
118 case 1
|
|
119 if offset >=U 0xF0
|
|
120 if offset >=U 0xF8
|
|
121 else
|
|
122 normal_iram = 0
|
|
123 end
|
|
124 end
|
|
125 case 2
|
|
126 if offset >=U 0xE8
|
|
127 if offset >=U 0xF0
|
|
128 else
|
|
129 normal_iram = 0
|
|
130 end
|
|
131 end
|
|
132 case 3
|
|
133 if offset >=U 0xE8
|
|
134 else
|
|
135 normal_iram = 0
|
|
136 end
|
|
137 end
|
|
138 if normal_iram
|
|
139 iram.offset = value
|
|
140 else
|
|
141 regnum = offset & 8
|
|
142 main.regnum = value
|
|
143 end
|
|
144
|
|
145 mem_read_no_exp
|
|
146 arg addr 32
|
|
147 local offset 8
|
|
148 if addr >=U 0xFE00
|
|
149 if addr >=U 0xFF00
|
|
150 offset = addr
|
|
151 sfr_read offset
|
|
152 else
|
|
153 offset = addr
|
|
154 iram_read offset
|
|
155 end
|
|
156 else
|
|
157 scratch1 = addr
|
|
158 ocall read_8
|
|
159 end
|
|
160
|
|
161 mem_write_no_exp
|
|
162 arg addr 32
|
|
163 arg value 8
|
|
164 local offset 8
|
|
165 if addr >=U 0xFE00
|
|
166 if addr >=U 0xFF00
|
|
167 offset = addr
|
|
168 sfr_write offset value
|
|
169 else
|
|
170 offset = addr
|
|
171 iram_write offset value
|
|
172 end
|
|
173 else
|
|
174 scratch2 = addr
|
|
175 scratch1 = value
|
|
176 ocall write_8
|
|
177 end
|
|
178
|
|
179 upd78k2_op_fetch
|
|
180 mem_read_no_exp pc
|
|
181 pc += 1
|
|
182
|
|
183 upd78k2_op_fetch_word
|
|
184 local tmp 8
|
|
185 upd78k2_op_fetch
|
|
186 tmp = scratch1
|
|
187 upd78k2_op_fetch
|
|
188 scratch1 <<= 8
|
|
189 scratch1 |= tmp
|
|
190
|
|
191 upd78k2_run_op
|
|
192 upd78k2_op_fetch
|
|
193 dispatch scratch1
|
|
194
|
|
195 saddr_read
|
|
196 arg offset 8
|
|
197 local tmp 8
|
|
198 if offset >=U 0xE0
|
|
199 #sfr area
|
|
200 tmp = offset - 0xE0
|
|
201 sfr_read tmp
|
|
202 else
|
|
203 tmp = offset + 0x20
|
|
204 iram_read tmp
|
|
205 end
|
|
206
|
|
207 saddr_write
|
|
208 arg offset 8
|
|
209 arg value 8
|
|
210 local tmp 8
|
|
211 if offset >=U 0xE0
|
|
212 #sfr area
|
|
213 tmp = offset - 0xE0
|
|
214 sfr_write tmp value
|
|
215 else
|
|
216 tmp = offset + 0x20
|
|
217 iram_write tmp value
|
|
218 end
|
|
219
|
|
220 mem_read
|
|
221 arg address 16
|
|
222 arg alt_bank 8
|
|
223 local full_address 32
|
|
224 local meg_enable 8
|
|
225 meg_enable = mm & 0x40
|
|
226 if meg_enable
|
|
227 if alt_bank
|
|
228 full_address = port_data.6 & 0xF
|
|
229 else
|
|
230 full_address = port_mode.6 & 0xF
|
|
231 end
|
|
232 full_address <<= 16
|
|
233 full_address |= address
|
|
234 else
|
|
235 full_address = address
|
|
236 end
|
|
237 mem_read_no_exp full_address
|
|
238
|
|
239 mem_write
|
|
240 arg address 16
|
|
241 arg value 8
|
|
242 arg alt_bank 8
|
|
243 local full_address 32
|
|
244 local meg_enable 8
|
|
245 meg_enable = mm & 0x40
|
|
246 if meg_enable
|
|
247 if alt_bank
|
|
248 full_address = port_data.6 & 0xF
|
|
249 else
|
|
250 full_address = port_mode.6 & 0xF
|
|
251 end
|
|
252 full_address <<= 16
|
|
253 full_address |= address
|
|
254 else
|
|
255 full_address = address
|
|
256 end
|
|
257 mem_write_no_exp full_address value
|
|
258
|
|
259 push_word
|
|
260 arg value 16
|
|
261 local tmp 8
|
|
262 tmp = value >> 8
|
|
263 sp -= 1
|
|
264 mem_write_no_exp sp tmp
|
|
265 tmp = value
|
|
266 sp -= 1
|
|
267 mem_write_no_exp sp tmp
|
|
268
|
|
269 pop_word
|
|
270 mem_read_no_exp sp
|
|
271 dst = scratch1
|
|
272 sp += 1
|
|
273 mem_read_no_exp sp
|
|
274 scratch1 <<= 8
|
|
275 dst |= scratch1
|
|
276 sp += 1
|
|
277
|
|
278 00000000 nop
|
|
279 cycles 2 #minimum cycle time appears to be 4 (ignoring internal divider)
|
|
280
|
|
281 00000001 sfr_prefix
|
|
282 upd78k2_op_fetch
|
|
283 dispatch scratch1 sfr
|
|
284
|
|
285 00000010 bit1_prefix
|
|
286 upd78k2_op_fetch
|
|
287 dispatch scratch1 bit1
|
|
288
|
|
289 00000011 bit2_prefix
|
|
290 upd78k2_op_fetch
|
|
291 dispatch scratch1 bit2
|
|
292
|
|
293 00000101 muldiv_prefix
|
|
294 upd78k2_op_fetch
|
|
295 dispatch scratch1 muldiv
|
|
296
|
|
297 00000110 base_prefix
|
|
298 upd78k2_op_fetch
|
|
299 dispatch scratch1 base
|
|
300
|
|
301 00001000 sfrbit_prefix
|
|
302 upd78k2_op_fetch
|
|
303 dispatch scratch1 sfrbit
|
|
304
|
|
305 00001001 spmov_prefix
|
|
306 upd78k2_op_fetch
|
|
307 dispatch scratch1 spmov
|
|
308
|
|
309 00001010 indexed_prefix
|
|
310 upd78k2_op_fetch
|
|
311 dispatch scratch1 indexed
|
|
312
|
|
313 00010110 regind_prefix
|
|
314 upd78k2_op_fetch
|
|
315 dispatch scratch1 regind
|
|
316
|
|
317 00100100 mov_reg_prefix
|
|
318 upd78k2_op_fetch
|
|
319 dispatch scratch1 mov_reg
|
|
320
|
|
321 sfr 00000110 alt_base_prefix
|
|
322 upd78k2_op_fetch
|
|
323 dispatch scratch1 alt_base
|
|
324
|
|
325 sfr 00001010 alt_indexed_prefix
|
|
326 upd78k2_op_fetch
|
|
327 dispatch scratch1 alt_indexed
|
|
328
|
|
329 sfr 00010110 alt_regind_prefix
|
|
330 upd78k2_op_fetch
|
|
331 dispatch scratch1 alt_regind
|
|
332
|
|
333 aluop
|
|
334 arg op 8
|
|
335 arg src 8
|
|
336 switch op
|
|
337 case 0
|
|
338 dst += src
|
|
339 update_flags ZAC
|
|
340 case 1
|
|
341 adc dst src dst
|
|
342 update_flags ZAC
|
|
343 case 2
|
|
344 dst -= src
|
|
345 update_flags ZAC
|
|
346 case 3
|
|
347 sbc dst src dst
|
|
348 update_flags ZAC
|
|
349 case 4
|
|
350 dst &= src
|
|
351 update_flags Z
|
|
352 case 5
|
|
353 dst ^= src
|
|
354 update_flags Z
|
|
355 case 6
|
|
356 dst |= src
|
|
357 update_flags Z
|
|
358 case 7
|
|
359 cmp dst src
|
|
360 update_flags ZAC
|
|
361 end
|
|
362
|
|
363 aluop16
|
|
364 arg op 8
|
|
365 arg src 16
|
|
366 switch op
|
|
367 case 0
|
|
368 dst += src
|
|
369 update_flags ZAC
|
|
370 case 2
|
|
371 dst -= src
|
|
372 update_flags ZAC
|
|
373 case 7
|
|
374 dst -= src
|
|
375 update_flags ZAC
|
|
376 default
|
|
377 #TODO: what happens in these invalid cases
|
|
378 end
|
|
379
|
|
380 10001PPP alu_r_r
|
|
381 local tmp_src 16
|
|
382 local tmp_dst 16
|
|
383 upd78k2_op_fetch
|
|
384 scratch2 = scratch1 >> 4
|
|
385 if scratch2 >=U 7
|
|
386 #TODO: is MSB just ignored or is this treated as some kind of illegal instruction or nop?
|
|
387 else
|
|
388 scratch1 &= 0xF
|
|
389 if scratch1 >=U 7
|
|
390 scratch1 &= 7
|
|
391 meta dst tmp_dst
|
|
392 tmp_dst = a << 8
|
|
393 tmp_dst |= x
|
|
394 switch scratch1
|
|
395 case 0
|
|
396 tmp_src = a << 8
|
|
397 tmp_src |= x
|
|
398 case 2
|
|
399 tmp_src = b << 8
|
|
400 tmp_src |= c
|
|
401 case 4
|
|
402 tmp_src = d << 8
|
|
403 tmp_src |= e
|
|
404 case 6
|
|
405 tmp_src = h << 8
|
|
406 tmp_src |= l
|
|
407 default
|
|
408 #TODO: what happens in these invalid cases
|
|
409 end
|
|
410 aluop16 P tmp_src
|
|
411 x = tmp_dst
|
|
412 a = tmp_dst >> 8
|
|
413 else
|
|
414 meta dst main.scratch2
|
|
415 cycles 2 #penalty for extra IRAM access since regs are technically stored there?
|
|
416 aluop P main.scratch1
|
|
417 end
|
|
418 end
|
|
419
|
|
420 10101PPP alu_immed
|
|
421 upd78k2_op_fetch
|
|
422 meta dst a
|
|
423 aluop P scratch1
|
|
424
|
|
425 calc_addr_base
|
|
426 arg regpair 8
|
|
427 local tmp 16
|
|
428 upd78k2_op_fetch
|
|
429 switch regpair
|
|
430 case 0
|
|
431 #[de+byte]
|
|
432 tmp = d << 8
|
|
433 tmp |= e
|
|
434 adst += tmp
|
|
435 case 1
|
|
436 #[sp+byte]
|
|
437 adst += sp
|
|
438 case 2
|
|
439 #[hl+byte]
|
|
440 tmp = h << 8
|
|
441 tmp |= l
|
|
442 adst += tmp
|
|
443 end
|
|
444
|
|
445 read_base_mode
|
|
446 arg regpair 8
|
|
447 arg alt_bank 8
|
|
448 meta adst scratch1
|
|
449 calc_addr_base regpair
|
|
450 mem_read scratch1 alt_bank
|
|
451
|
|
452 write_base_mode
|
|
453 arg regpair 8
|
|
454 arg value 8
|
|
455 arg alt_bank 8
|
|
456 meta adst scratch2
|
|
457 calc_addr_base regpair
|
|
458 mem_write scratch2 value alt_bank
|
|
459
|
|
460 calc_addr_regind
|
|
461 arg regpair 8
|
|
462 local tmp 16
|
|
463 switch regpair
|
|
464 case 0
|
|
465 #[de+]
|
|
466 adst = d << 8
|
|
467 adst |= e
|
|
468 tmp = adst + 1
|
|
469 e = tmp
|
|
470 d = tmp >> 8
|
|
471 case 1
|
|
472 #[hl+]
|
|
473 adst = h << 8
|
|
474 adst |= l
|
|
475 tmp = adst + 1
|
|
476 l = tmp
|
|
477 h = tmp >> 8
|
|
478 case 2
|
|
479 #[de-]
|
|
480 adst = d << 8
|
|
481 adst |= e
|
|
482 tmp = adst - 1
|
|
483 e = tmp
|
|
484 d = tmp >> 8
|
|
485 case 3
|
|
486 #[hl-]
|
|
487 adst = h << 8
|
|
488 adst |= l
|
|
489 tmp = adst - 1
|
|
490 l = tmp
|
|
491 h = tmp >> 8
|
|
492 case 4
|
|
493 #[de]
|
|
494 adst = d << 8
|
|
495 adst |= e
|
|
496 case 5
|
|
497 #[hl]
|
|
498 adst = h << 8
|
|
499 adst |= l
|
|
500 end
|
|
501
|
|
502 read_regind_mode
|
|
503 arg regpair 8
|
|
504 arg alt_bank 8
|
|
505 meta adst scratch1
|
|
506 calc_addr_regind regpair
|
|
507 mem_read scratch1 alt_bank
|
|
508
|
|
509 write_regind_mode
|
|
510 arg regpair 8
|
|
511 arg value 8
|
|
512 arg alt_bank 8
|
|
513 meta adst scratch2
|
|
514 calc_addr_regind regpair
|
|
515 mem_write scratch2 value alt_bank
|
|
516
|
|
517 calc_addr_indexed
|
|
518 arg index_reg 8
|
|
519 local tmp 16
|
|
520 upd78k2_op_fetch_word
|
|
521 switch index_reg
|
|
522 case 0
|
|
523 tmp = d << 8
|
|
524 tmp |= e
|
|
525 adst += tmp
|
|
526 case 1
|
|
527 adst += a
|
|
528 case 2
|
|
529 tmp = h << 8
|
|
530 tmp |= l
|
|
531 adst += tmp
|
|
532 case 3
|
|
533 adst += b
|
|
534 end
|
|
535
|
|
536 read_indexed_mode
|
|
537 arg index_reg 8
|
|
538 arg alt_bank 8
|
|
539 meta adst scratch1
|
|
540 calc_addr_indexed index_reg
|
|
541 mem_read scratch1 alt_bank
|
|
542
|
|
543 write_indexed_mode
|
|
544 arg index_reg 8
|
|
545 arg value 8
|
|
546 arg alt_bank 8
|
|
547 meta adst scratch2
|
|
548 calc_addr_indexed index_reg
|
|
549 mem_write scratch2 value alt_bank
|
|
550
|
|
551 base 00RR1PPP alu_base
|
|
552 invalid R 3
|
|
553 read_base_mode R 0
|
|
554 meta dst a
|
|
555 aluop P scratch1
|
|
556
|
|
557 alt_base 00RR1PPP alu_alt_base
|
|
558 invalid R 3
|
|
559 read_base_mode R 1
|
|
560 meta dst a
|
|
561 aluop P scratch1
|
|
562
|
|
563 base 00RR0000 mov_a_base
|
|
564 invalid R 3
|
|
565 read_base_mode R 0
|
|
566 a = scratch1
|
|
567
|
|
568 alt_base 00RR0000 alt_mov_a_base
|
|
569 invalid R 3
|
|
570 read_base_mode R 1
|
|
571 a = scratch1
|
|
572
|
|
573 base 10RR0000 mov_base_a
|
|
574 invalid R 3
|
|
575 write_base_mode R a 0
|
|
576
|
|
577 alt_base 10RR0000 alt_mov_base_a
|
|
578 invalid R 3
|
|
579 write_base_mode R a 1
|
|
580
|
|
581 regind 0RRR1PPP alu_reg_indirect
|
|
582 invalid R 6
|
|
583 invalid R 7
|
|
584 read_regind_mode R 0
|
|
585 meta dst a
|
|
586 aluop P scratch1
|
|
587
|
|
588 alt_regind 0RRR1PPP alu_alt_reg_indirect
|
|
589 invalid R 6
|
|
590 invalid R 7
|
|
591 read_regind_mode R 1
|
|
592 meta dst a
|
|
593 aluop P scratch1
|
|
594
|
|
595 regind 0RRR0000 mov_a_reg_indirect
|
|
596 invalid R 6
|
|
597 invalid R 7
|
|
598 read_regind_mode R 0
|
|
599 a = scratch1
|
|
600
|
|
601 alt_regind 0RRR0000 alt_mov_a_reg_indirect
|
|
602 invalid R 6
|
|
603 invalid R 7
|
|
604 read_regind_mode R 1
|
|
605 a = scratch1
|
|
606
|
|
607 regind 1RRR0000 mov_reg_indirect_a
|
|
608 invalid R 6
|
|
609 invalid R 7
|
|
610 write_regind_mode R a 0
|
|
611
|
|
612 alt_regind 1RRR0000 alt_mov_reg_indirect_a
|
|
613 invalid R 6
|
|
614 invalid R 7
|
|
615 write_regind_mode R a 1
|
|
616
|
|
617 01010RRR mov_reg_indirect_a_short
|
|
618 invalid R 6
|
|
619 invalid R 7
|
|
620 write_regind_mode R a 0
|
|
621
|
|
622 01011RRR mov_a_reg_indirect_short
|
|
623 invalid R 6
|
|
624 invalid R 7
|
|
625 read_regind_mode R 0
|
|
626 a = scratch1
|
|
627
|
|
628 indexed 00RR1PPP alu_indexed
|
|
629 read_indexed_mode R 0
|
|
630 meta dst a
|
|
631 aluop P scratch1
|
|
632
|
|
633 alt_indexed 00RR1PPP alu_alt_indexed
|
|
634 read_indexed_mode R 1
|
|
635 meta dst a
|
|
636 aluop P scratch1
|
|
637
|
|
638 indexed 00RR0000 mov_a_indexed
|
|
639 read_indexed_mode R 0
|
|
640 a = scratch1
|
|
641
|
|
642 alt_indexed 00RR0000 alt_mov_a_indexed
|
|
643 read_indexed_mode R 1
|
|
644 a = scratch1
|
|
645
|
|
646 indexed 10RR0000 mov_indexed_a
|
|
647 write_indexed_mode R a 0
|
|
648
|
|
649 alt_indexed 10RR0000 alt_mov_indexed_a
|
|
650 write_indexed_mode R a 1
|
|
651
|
|
652 mov_reg 0DD01SS0 movw_rp_rp
|
|
653 local dst 8
|
|
654 local src 8
|
|
655 dst = D << 1
|
|
656 src = S << 1
|
|
657 main.dst = main.src
|
|
658 dst += 1
|
|
659 src += 1
|
|
660 main.dst = main.src
|
|
661
|
|
662 mov_reg 0DDD0SSS mov_r_r
|
|
663 main.D = main.S
|
|
664
|
|
665 01100PP0 movw_rp_immed
|
|
666 local dst 8
|
|
667 dst = P << 1
|
|
668 upd78k2_op_fetch
|
|
669 main.dst = scratch1
|
|
670 dst += 1
|
|
671 upd78k2_op_fetch
|
|
672 main.dst = scratch1
|
|
673
|
|
674 11000RRR inc_r
|
|
675 cycles 2
|
|
676 main.R += 1
|
|
677 update_flags ZA
|
|
678
|
|
679 11001RRR dec_r
|
|
680 cycles 2
|
|
681 main.R -= 1
|
|
682 update_flags ZA
|
|
683
|
|
684 11010RRR mov_a_r
|
|
685 a = main.R
|
|
686
|
|
687 muldiv 01001PP0 br_rp
|
|
688 local reg 8
|
|
689 local tmp 16
|
|
690 reg = P << 1
|
|
691 pc = main.reg
|
|
692 reg += 1
|
|
693 tmp = main.reg << 8
|
|
694 pc |= tmp
|
|
695
|
|
696 00010100 br_rel
|
|
697 upd78k2_op_fetch
|
|
698 sext 16 scratch1 scratch1
|
|
699 pc += scratch1
|
|
700
|
|
701 00101100 br_abs
|
|
702 upd78k2_op_fetch_word
|
|
703 pc = scratch1
|
|
704
|
|
705 100000FS bcc
|
|
706 local flag 8
|
|
707 upd78k2_op_fetch
|
|
708 if F
|
|
709 flag = chflags >> 7
|
|
710 else
|
|
711 flag = zflag
|
|
712 end
|
|
713 if flag = S
|
|
714 sext 16 scratch1 scratch1
|
|
715 pc += scratch1
|
|
716 end
|
|
717
|
|
718 muldiv 01011PP0 call_rp
|
|
719 local reg 8
|
|
720 local tmp 16
|
|
721 push_word pc
|
|
722 reg = P << 1
|
|
723 pc = main.reg
|
|
724 reg += 1
|
|
725 tmp = main.reg << 8
|
|
726 pc |= tmp
|
|
727
|
|
728 00101000 call_long
|
|
729 local address 16
|
|
730 upd78k2_op_fetch_word
|
|
731 address = scratch1
|
|
732 push_word pc
|
|
733 pc = address
|
|
734
|
|
735 10010AAA call_short
|
|
736 local address 16
|
|
737 address = A << 8
|
|
738 address |= 0x800
|
|
739 upd78k2_op_fetch
|
|
740 address |= scratch1
|
|
741 push_word pc
|
|
742 pc = address
|
|
743
|
|
744 111TTTTT call_table
|
|
745 local address 16
|
|
746 mem_read_no_exp T
|
|
747 address = scratch1
|
|
748 scratch1 = T + 1
|
|
749 mem_read_no_exp scratch1
|
|
750 scratch1 <<= 8
|
|
751 address |= 8
|
|
752 push_word pc
|
|
753 pc = address
|
|
754
|
|
755 01010110 ret
|
|
756 meta dst pc
|
|
757 pop_word
|
|
758
|
|
759 001101PP pop_rp
|
|
760 local rp 8
|
|
761 local word 16
|
|
762 meta dst word
|
|
763 pop_word
|
|
764 main.rp = word
|
|
765 rp += 1
|
|
766 main.rp = word >> 8
|
|
767
|
|
768 001111PP push_rp
|
|
769 local rp 8
|
|
770 local word 16
|
|
771 rp = P << 1
|
|
772 rp += 1
|
|
773 word = main.rp << 8
|
|
774 rp -= 1
|
|
775 word |= main.rp
|
|
776 push_word word
|
|
777
|
|
778 muldiv 101010NN sel
|
|
779 local offset 8
|
|
780 if N != rbs
|
|
781 offset = rbs << 3
|
|
782 offset = 0xF8 - offset
|
|
783 iram.offset = x
|
|
784 offset += 1
|
|
785 iram.offset = a
|
|
786 offset += 1
|
|
787 iram.offset = c
|
|
788 offset += 1
|
|
789 iram.offset = b
|
|
790 offset += 1
|
|
791 iram.offset = e
|
|
792 offset += 1
|
|
793 iram.offset = d
|
|
794 offset += 1
|
|
795 iram.offset = l
|
|
796 offset += 1
|
|
797 iram.offset = h
|
|
798 offset = N << 3
|
|
799 offset = 0xF8 - offset
|
|
800 x = iram.offset
|
|
801 offset += 1
|
|
802 a = iram.offset
|
|
803 offset += 1
|
|
804 c = iram.offset
|
|
805 offset += 1
|
|
806 b = iram.offset
|
|
807 offset += 1
|
|
808 e = iram.offset
|
|
809 offset += 1
|
|
810 d = iram.offset
|
|
811 offset += 1
|
|
812 l = iram.offset
|
|
813 offset += 1
|
|
814 h = iram.offset
|
|
815 rbs = N
|
|
816 end
|
|
817
|
|
818 muldiv 11001000 incw_sp
|
|
819 sp += 1
|
|
820
|
|
821 muldiv 11001001 decw_sp
|
|
822 sp -= 1
|
|
823
|
|
824 00001011 movw_sfrp_immed
|
|
825 upd78k2_op_fetch
|
|
826 if scratch1 = 0xFC
|
|
827 #unclear if SP is actually mapped in the SFR space
|
|
828 #or if this is special cased, but the docs don't
|
|
829 #suggest you can write to SP with other SFR-targeting
|
|
830 #instructions so I'm assuming the latter.
|
|
831 upd78k2_op_fetch
|
|
832 sp = scratch1
|
|
833 upd78k2_op_fetch
|
|
834 scratch1 <<= 8
|
|
835 sp |= scratch1
|
|
836 else
|
|
837 scratch2 = scratch1
|
|
838 upd78k2_op_fetch
|
|
839 sfr_write scratch2 scratch1
|
|
840 scratch2 += 1
|
|
841 upd78k2_op_fetch
|
|
842 sfr_write scratch2 scratch1
|
|
843 end
|
|
844
|
|
845 00001100 movw_sadrp_word
|
|
846 local offset 8
|
|
847 upd78k2_op_fetch
|
|
848 offset = scratch1
|
|
849 upd78k2_op_fetch
|
|
850 saddr_write offset scratch1
|
|
851 offset += 1
|
|
852 upd78k2_op_fetch
|
|
853 saddr_write offset scratch1 |