]> cloudbase.mooo.com Git - ddt180.git/blob - ddt180.z80
lookup_branch_op minor opt
[ddt180.git] / ddt180.z80
1 ; Disassembled ddtz.com, version "DDT/Z [8101]"
2 ; with modified relocater.
3 ;
4 ; Build steps:
5 ; - Assemble to a .REL file with M80 or a compatible assembler.
6 ; - Use Digital Research Link-80 to generate a .PRL file (op switch).
7 ; - Cut the .PRL header (first 256 byte) end rename the result to DDTZ.COM.
8
9
10 maclib config.inc
11
12 ; Some greneral definitions
13
14 BS equ 08h
15 TAB equ 09h
16 CR equ 0dh
17 LF equ 0ah
18 DEL equ 7fh
19 CNTRX equ 'X'-'@'
20
21 ; CP/M memory layout
22
23 BDOS equ 5
24 TPA equ 0100h
25
26 ; ddtz specific definitions
27
28 STACK_SIZE equ 80 ;ddtz internal stack
29 CONBUF_SIZE equ 80 ;Size of console input buffer
30 BP_CNT equ 12 ;Number of breakpoints
31 BP_SIZE equ 4 ;Size of a breakpoint record
32
33 bitmap_size equ (prog_size+7)/8
34
35 ;-------------------------------------------------------------------------------
36
37 cseg
38 start:
39 ddtz_base:
40 jr reloc
41 nop
42 l0003h:
43 rst 30h ;rst used by ddtz
44 di_or_ei: ;ints enabled/disabled while ddtz is running
45 nop
46 ret
47
48 ;-------------------------------------------------------------------------------
49
50 signon:
51 db 'DDTZ/180'
52 db ' - Version '
53 maclib version.inc
54 defvers
55 dc ' ('
56
57 ;-------------------------------------------------------------------------------
58
59 reloc_getbit macro
60 local nextbit
61 exx
62 djnz nextbit
63 ld b,8 ;reload bit counter
64 ld e,(hl) ;get next 8 relocation bits
65 inc hl
66 nextbit:
67 sla e
68 exx
69 endm
70
71 ;-------------------------------------------------------------------------------
72 ; Clear old position
73
74 cmde_clr:
75 ld (hl),0
76 inc hl
77 dec bc
78 ld a,b
79 or c
80 jr nz,cmde_clr
81
82 ; Determine current position
83
84 reloc:
85 ld a,i ;get iff2
86 ex af,af'
87 di
88 ld sp,028h-2 ;rst instr needs a minimal stack
89 pop bc ;save 026h,027h
90 pop de ;save 028h,029h
91 ld hl,0e9e1h ;opcpdes pop hl/jp (hl)
92 push hl
93 rst 028h
94 wearehere:
95 ld (028h-2),bc
96 ld (028h),de
97 ld de,-(wearehere-ddtz_base)
98 add hl,de ; hl:
99
100 ld de,ddtz_base ; de:
101 or a
102 sbc hl,de
103 ex de,hl ; de: reloc offset
104 ld hl,stack
105 add hl,de
106 ld sp,hl
107 ex af,af'
108 push af
109 pop bc
110 bit 2,c
111 jr z,$+3
112 ei
113 ld hl,ddtz_end ;start of reloc bitmap
114 add hl,de
115 push hl
116 exx
117 pop hl
118 ld b,1 ;init bit counter b
119 exx
120
121 LD HL,ddtz_base
122 add hl,de ;--> ddtz_base
123
124 reloc_lp:
125 push de
126 push hl
127
128 ld de,4
129 ld a,2
130 ld hl,0
131 reloc_l:
132 reloc_getbit
133 jr nc,reloc_got
134 cp 16
135 jr z,reloc_done
136 add hl,de
137 ld b,a
138 ex de,hl
139 reloc_l1:
140 add hl,hl
141 djnz reloc_l1
142 ex de,hl
143 add a,a
144 jr reloc_l
145 reloc_got:
146 ex de,hl
147 ld hl,0
148 ld b,a
149 reloc_bitloop:
150 reloc_getbit
151 adc hl,hl
152 djnz reloc_bitloop
153 add hl,de
154 pop de
155 add hl,de
156 pop de
157
158 LD A,(HL)
159 ADD A,E
160 LD (HL),A
161 INC HL
162 LD A,(HL)
163 ADC A,D
164 LD (HL),A
165 inc hl
166 jr reloc_lp
167 reloc_done:
168 exx
169 ld (bitmap_end),hl
170 ;-------------------------------------------------------------------------------
171
172
173 init:
174 LD SP,stack
175
176 if CPM
177
178 ld hl,(1) ;wboot addr
179 ld de,convec
180 ex de,hl
181 ld b,3
182 vini_l:
183 inc de
184 inc de
185 inc de
186 inc hl
187 ld (hl),e
188 inc hl
189 ld (hl),d
190 inc hl
191 djnz vini_l
192 else
193 xor a
194 dec a
195 daa ; Z80: 099H, x180+: 0F9H
196 cp 99h ; Result on 180 type cpus is F9 here. Thanks Hitachi
197 jr z,ini_z80
198
199 xor a
200 call cinit
201 ld a,1
202 call cinit
203 jr ini_sign
204 ini_z80:
205 ; if ...
206 ; .printx Error: Not yet implemented!
207 ; db "Stop
208 ; endif
209 endif ; CPM
210
211 ini_sign:
212 ld hl,signon
213 call pstr
214 ld hl,ddtz_base
215 call out_hl
216 call pstr_inl
217 dc ' - '
218 ld hl,(bitmap_end)
219 dec hl
220 call out_hl
221 call pstr_inl
222 dc ')',CR,LF
223
224 ld a,i
225 ld (reg.i),a
226 ld a,0f3h
227 jp po,l0093h
228 ld a,0fbh
229 l0093h:
230 ld (reg.iff),a
231 call di_or_ei
232 ld hl,ddtz_base
233 ld l,000h
234 ld (reg_sp),hl
235
236 jp mainloop
237
238 ;-------------------------------------------------------------------------------
239
240 if CPM
241
242 convec:
243 const: jp 0 ; return console input status
244 conin: jp 0 ; return console input character
245 conout: jp 0 ; send console output character
246
247 else
248
249 include z180reg.inc
250
251 iobyte equ 3
252
253 max_device equ 3
254
255 ;-------------------------------------------------------------------------------
256
257 ; init device
258 cinit: ; a = device
259 call vector_io_0
260 dw as0init
261 dw rret
262 dw rret
263 dw rret
264
265 ; character input status
266 const: ; return a != 0 if character waiting
267 call vector_io
268 dw as0ista
269 dw null$status
270 dw csio_ista
271 dw null$status
272
273 ; character input
274 conin: ; return a = input char
275 call vector_io
276 dw as0inp
277 dw null$input
278 dw csio_inp
279 dw null$input
280
281 ; character output
282 conout: ; c = output char
283 call vector_io
284 dw as0out
285 dw rret
286 dw csio_out
287 dw rret
288
289 ;-------------------------------------------------------------------------------
290
291 vector_io:
292 ld a,(iobyte)
293 vector_io_0:
294 pop hl
295 cp max_device
296 jr c,exist
297 ld a,max_device ; use null device if a >= max$device
298 exist:
299 call add_hl_a2
300 ld a,(hl)
301 inc hl
302 ld h,(hl)
303 ld l,a
304 jp (hl)
305
306 ;-------------------------------------------------------------------------------
307
308 null$input:
309 ld a,1Ah
310 rret:
311 ret
312 ret$true:
313 or 0FFh
314 ret
315
316 null$status:
317 xor a
318 ret
319
320 ;-------------------------------------------------------------------------------
321 ;
322 ; TC = (f PHI /(2*baudrate*Clock_mode)) - 2
323 ;
324 ; TC = (f PHI / (32 * baudrate)) - 2
325 ;
326 ; Init Serial I/O for console input and output (ASCI1)
327 ;
328
329
330
331 as0init:
332 ld hl,initab0
333 jp ioiniml
334
335 as1init:
336 ld hl,initab1
337 jp ioiniml
338
339
340 ld a,M_MPBT
341 out0 (cntlb1),a
342 ld a,M_RE + M_TE + M_MOD2 ;Rx/Tx enable
343 out0 (cntla1),a
344 ld a,M_RIE
345 out0 (stat1),a ;Enable rx interrupts
346
347 ret ;
348
349
350 initab0:
351 db 1,stat0,0 ;Disable rx/tx interrupts
352 ;Enable baud rate generator
353 db 1,asext0,M_BRGMOD+M_DCD0DIS+M_CTS0DIS
354 db 2,astc0l,low 28, high 28
355 db 1,cntlb0,M_MPBT ;No MP Mode, X16
356 db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
357 db 0
358
359 initab1:
360 db 1,stat1,0 ;Disable rx/tx ints, disable CTS1
361 db 1,asext1,M_BRGMOD ;Enable baud rate generator
362 db 2,astc1l,low 3, high 3
363 db 1,cntlb1,M_MPBT ;No MP Mode, X16
364 db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
365 db 0
366
367 ;-------------------------------------------------------------------------------
368
369 ioiniml:
370 push bc
371 xor a
372 ioml_lp:
373 ld b,(hl)
374 inc hl
375 cp b
376 jr z,ioml_e
377
378 ld c,(hl)
379 inc hl
380 otimr
381 jr ioml_lp
382 ioml_e:
383 pop bc
384 ret
385
386 ;-------------------------------------------------------------------------------
387
388 as0ista:
389 in0 a,(stat0)
390 rlca
391 sbc a,a
392 ret
393
394 as1ista:
395 in0 a,(stat1)
396 rlca
397 sbc a,a
398 ret
399
400 as0inp:
401 in0 a,(stat0)
402 rlca
403 jr nc,as0inp
404 in0 a,rdr0
405 ret
406
407 as1inp:
408 in0 a,(stat1)
409 rlca
410 jr nc,as1inp
411 in0 a,rdr1
412 ret
413
414 as0out:
415 in0 a,(stat0)
416 and M_TDRE
417 jr z,as0out
418 out0 (tdr0),c
419 ld a,c
420 ret
421
422 as1out:
423 in0 a,(stat1)
424 and M_TDRE
425 jr z,as1out
426 out0 (tdr1),c
427 ld a,c
428 ret
429
430 ;-------------------------------------------------------------------------------
431
432
433 csio_rx_tmp: db 0ffh
434
435 csio_ista:
436 ld hl,csio_rx_tmp
437 ld a,(hl)
438 cp 0ffh
439 jr nz,csist_1
440 ld a,01
441 call csio_wr
442 call csio_rd
443 call csio_rd
444 ld (hl),a
445 sub a,0ffh
446 ret z
447 csist_1:
448 or 0ffh
449 ret
450
451 csio_inp:
452 ld hl,csio_rx_tmp
453 ld a,(hl)
454 ld (hl),0ffh
455 cp 0ffh
456 ret nz
457 csin_1:
458 ld a,01
459 call csio_wr
460 call csio_rd
461 call csio_rd
462 cp 0ffh
463 jr z,csin_1
464 ret
465
466 csio_rd:
467 ld a,M_CSIO_RE
468 call csio_cmd_wait
469 in0 a,(trdr)
470 ret
471
472 csio_out:
473 ld a,02
474 call csio_wr
475 call csio_rd
476 call csio_rd
477 or a
478 jr z,csio_out
479
480 ld a,c
481 inc a ;ff..02 --> 00..03
482 cp 04h
483 jr nc,csout_1
484 ld a,00h
485 call csio_wr
486 csout_1:
487 ld a,c
488 csio_wr:
489 out0 (trdr),a
490 ld a,M_CSIO_TE
491 csio_cmd_wait:
492 out0 (cntr),a
493 cswr_wait:
494 in0 a,(cntr)
495 and M_CSIO_TE+M_CSIO_RE
496 jr nz,cswr_wait
497 ret
498
499 endif ; CPM
500
501 ;-------------------------------------------------------------------------------
502
503 CMDTAB:
504 ; dw ERROR ;cmd_@ ;examine/substitute the displacement register @
505 ; dw ERROR ;cmd_A ;Assemble
506 dw cmd_B ;Breakpoints display/set/clear
507 dw ERROR ;cmd_C ;trace over Calls
508 dw cmd_D ;Display memory in hex and ascii
509 dw cmd_E ;rElocate debugger
510 dw ERROR ;cmd_F ;specify Filename and command line
511 dw cmd_G ;Go
512 dw cmd_H ;compute Hex and other expressions
513 dw cmd_I ;Input a byte from port
514 dw ERROR ;
515 dw ERROR ;
516 dw cmd_L ;List disassembled code
517 dw cmd_M ;Move memory [and verify]
518 dw ERROR ;
519 dw cmd_O ;Output a byte to port
520 dw ERROR ;
521 dw cmd_Q ;Qery memory for byte string
522 dw cmd_R ;Read binary or hex file
523 dw cmd_S ;Substitute memory
524 dw cmd_T ;Trace
525 dw ERROR ;
526 dw cmd_V ;Verify (compare) two memory areas
527 dw ERROR ;cmd_W ;Write a file to disk
528 dw cmd_X ;eXamine [and substitute] registers
529 dw ERROR ;cmd_Y ;examine [and substitute] Y variables
530 dw cmd_Z ;Zap (fill) memory with a byte string
531
532 ERROR:
533 call pstr_inl
534 dc '?',CR,LF
535 ;fall thru
536 mainloop:
537 ld sp,stack
538 ld hl,(reg.pc)
539 call bp_clr_temporary
540 ld hl,(cmd_rpt)
541 ld de,mainloop
542 push de
543 call cp_hl_de
544 ld a,'>'
545 call outchar
546 call nz,outchar
547 call z,outbl
548 call get_line
549 call skipbl
550 jr z,exe_hl
551 pop hl
552 push hl
553 ld (cmd_rpt),hl
554 inc de
555 sub 'B'
556 jr c,ERROR
557 cp 'Z'+1-'B'
558 jr nc,ERROR
559 ld hl,CMDTAB
560 call add_hl_a2
561 ld a,(hl)
562 inc hl
563 ld h,(hl)
564 ld l,a
565 exe_hl:
566 CALL_HL:
567 jp (hl)
568
569 ;-------------------------------------------------------------------------------
570
571 crlf:
572 call pstr_inl
573 dc CR,LF
574 xor a
575 ld (con_col),a
576 call inchar
577 jr c,mainloop
578 ret
579
580 sub_01d9h:
581 call pstr_inl
582 dc '-'
583 jp neg.hl
584
585 out_hl_dec_neg:
586 push hl
587 call sub_01d9h
588 defb 03eh ;ld a,.. swallow push hl
589 out.hl.dec:
590 push hl
591 ld b,006h
592 call sub_01f9h
593 pop hl
594 call pstr_inl
595 dc '.'
596 l01f3h:
597 call outbl
598 djnz l01f3h
599 ret
600
601 sub_01f9h:
602 dec b
603 push de
604 ld de,10
605 call div_hl_de
606 ld a,h
607 or l
608 call nz,sub_01f9h
609 ld a,e
610 pop de
611 jr out_dgt
612
613 out_hl_neg:
614 push hl
615 call sub_01d9h
616 call out_hl
617 pop hl
618 ret
619
620 out_hl:
621 ld a,h
622 call out_hex
623 ld a,l
624
625 out_hex:
626 push af
627 rra
628 rra
629 rra
630 rra
631 call out_dgt
632 pop af
633
634 out_dgt:
635 or 0f0h
636 daa
637 add a,0a0h
638 adc a,040h
639 jr outchar
640
641 out.bin.w:
642 ld a,h
643 call out.bin.b
644 ld a,l
645 out.bin.b:
646 ld b,8
647 l01c9h:
648 rlca
649 push af
650 and 1
651 call out_dgt
652 pop af
653 djnz l01c9h
654 ld a,'"'
655 jr outchar
656
657 out.ascii:
658 push bc
659 ld c,a
660 res 7,a
661 cp ' '
662 push af
663 call nc,outbl
664 call pstr_inl
665 dc ''''
666 pop af
667 jr nc,l0242h
668 sub 0c0h
669 ld b,a
670 call pstr_inl
671 dc '^'
672 ld a,b
673 l0242h:
674 call outchar
675 cp ''''
676 call z,outchar
677 call pstr_inl
678 dc ''''
679 sla c
680 pop bc
681 ret nc
682 ld a,'.'
683 jr outchar
684
685 outbl6:
686 call outbl2
687 outbl4:
688 call outbl2
689 outbl2:
690 call outbl
691 outbl:
692 ld a,' '
693 outchar:
694 push ix
695 push iy
696 push hl
697 push de
698 push bc
699 push af
700 and 07fh
701 ld c,a
702 call conout
703 ld hl,con_col
704 inc (hl)
705 pop af
706 pop bc
707 pop de
708 pop hl
709 pop iy
710 pop ix
711 ret
712
713 p_goto_col:
714 ld a,(con_col)
715 cp c
716 ret nc
717 ret z
718 call outbl
719 jr p_goto_col
720
721 ;-------------------------------------------------------------------------------
722
723 incharw:
724 call inchar
725 jr nc,incharw
726 ret
727
728 ;-------------------------------------------------------------------------------
729
730 inchar:
731 push ix
732 push hl
733 push de
734 push bc
735 call const
736 and a
737 jr z,inch1
738 call conin
739 scf
740 inch1:
741 pop bc
742 pop de
743 pop hl
744 pop ix
745 ret
746
747 ;-------------------------------------------------------------------------------
748
749 DELC:
750 ld a,b
751 or a
752 ret z
753 call DELC1
754 dec hl
755 dec b
756 ld a,(hl)
757 cp ' '
758 ret nc
759 DELC1:
760 call pstr_inl
761 dc BS,' ',BS
762 ret
763
764 DELL:
765 ld a,b ;
766 or a ;
767 ret z ;
768 call DELC ;
769 jr DELL ;
770
771 ;-------------------------------------------------------------------------------
772
773 get_line:
774 push hl ;
775 ld hl,conbuf ;
776 ld b,0 ;
777 inlnxtch:
778 ld a,b ;
779 cp CONBUF_SIZE ;
780 jr z,inl_e ;
781 call incharw ;
782 cp CR ;
783 jr z,inl_e ;Accept line
784 cp LF ;
785 jr z,inl_e ;Accept line
786
787 cp BS ;
788 jr z,gl_1 ;
789 cp DEL ;
790 jr nz,gl_2 ;
791 gl_1:
792 call DELC ;Delete Char
793 jr inlnxtch ;
794 gl_2:
795 cp CNTRX ;
796 jr nz,gl_3 ;
797 call DELL ;Delete Line
798 jr inlnxtch ;
799 gl_3:
800 cp TAB ;
801 jr nz,gl_4 ;
802 ld a,' ' ;
803 gl_4:
804 ld (hl),a ;
805 cp ' ' ;
806 jr nc,gl_5 ;
807 ld a,'^' ;Controll characters
808 call outchar ;
809 ld a,(hl) ;
810 add a,'@' ;
811 gl_5:
812 call outchar ;
813 inc hl ;
814 inc b ;
815 jr inlnxtch ;
816
817 inl_e:
818 ld (hl),0
819 call CRLF ;
820 ld de,conbuf ;
821 pop hl ;
822 ret ;
823
824 ;-------------------------------------------------------------------------------
825
826 get_char_upper:
827 ld a,(de)
828 toupper:
829 cp 'a'
830 ret c
831 cp 'z'+1
832 ccf
833 ret c
834 and 05fh
835 ret
836
837 ;-------------------------------------------------------------------------------
838
839 skipbl0:
840 inc de
841 skipbl:
842 call get_char_upper
843 cp ' '
844 jr z,skipbl0
845 or a
846 ret
847
848 ;-------------------------------------------------------------------------------
849
850 next_arg:
851 call skipbl
852 cp ','
853 ret nz
854 call skipbl0
855 cp a
856 ret
857
858 assert_eol:
859 call skipbl
860 ret z
861 to_error:
862 jp ERROR
863
864 ;-------------------------------------------------------------------------------
865
866 chk_stack:
867 push hl
868 push de
869 ld hl,0
870 add hl,sp
871 ld de,stack-(STACK_SIZE-28)
872 call cp_hl_de
873 pop de
874 pop hl
875 jr c,to_error
876 ret
877
878 ;-------------------------------------------------------------------------------
879
880 add_hl_a2:
881 add a,a
882 add_hl_a:
883 add a,l
884 ld l,a
885 ret nc
886 inc h
887 ret
888
889 cp_hl_de:
890 and a
891 sbc hl,de
892 add hl,de
893 ret
894
895 ;-------------------------------------------------------------------------------
896
897 lookupch:
898 ld b,0
899 l02f5h:
900 ld a,(hl)
901 and a
902 ret z
903 call get_char_upper
904 cp (hl)
905 jr z,l0300h
906 inc hl
907 inc b
908 jr l02f5h
909 l0300h:
910 scf
911 inc de
912 ret
913
914 sub_0303h:
915 ld hl,t_reg_names
916 ld b,07fh
917 l030ch:
918 inc b
919 ld a,(hl)
920 and a
921 ret z
922 call sub_031ch
923 jr nc,l030ch
924 res 7,b
925 ret
926
927 sub_031ch:
928 push bc
929 push de
930 l031eh:
931 call get_char_upper
932 xor (hl)
933 and 07fh
934 jr nz,l0336h
935 bit 7,(hl)
936 inc hl
937 inc de
938 jr z,l031eh
939 scf
940 bit 7,b
941 call z,sub_060ch
942 jr nc,l0339h
943 pop af
944 scf
945 pop bc
946 ret
947 l0336h:
948 call str_sel_next
949 l0339h:
950 pop de
951 and a
952 pop bc
953 ret
954
955 str_sel:
956 inc b
957 jr str_sel2
958 str_sel1:
959 call str_sel_next
960 str_sel2:
961 djnz str_sel1
962 ret
963
964 str_sel_next:
965 ld a,(hl)
966 and a
967 ret z
968 l0348h:
969 ld a,(hl)
970 inc hl
971 and a
972 ret m
973 jr l0348h
974
975 get_arg_range_target:
976 call get_arg_range
977 push hl
978 push bc
979 call next_arg
980 call get_arg_final
981 ex de,hl
982 pop bc
983 pop hl
984 ret
985
986 sub_035dh:
987 call expr
988 jr c,error0
989 ret
990
991 get_arg_final:
992 call sub_035dh
993 l0366h:
994 jp assert_eol
995
996 get_lastarg_def:
997 call get_arg_def
998 jr l0366h
999
1000 get_arg_def:
1001 push hl
1002 call expr
1003 jr c,l0375h
1004 ex (sp),hl
1005 l0375h:
1006 pop hl
1007 ret
1008
1009 sub_0377h:
1010 call b_037c_start
1011 jr l0366h
1012
1013 b_037c_start:
1014 defb 0e6h ;and a,.. clear carry
1015 get_arg_range:
1016 scf
1017 ex af,af'
1018 push bc
1019 push hl
1020 call expr
1021 jr nc,l038ch
1022 ex af,af'
1023 jr c,error0
1024 ex af,af'
1025 pop hl
1026 defb 03eh ;ld a,.. swallow pop af
1027 l038ch:
1028 pop af
1029 call get_range
1030 jr nc,l0398h
1031 ex af,af'
1032 pop bc
1033 ret nc
1034 error0:
1035 jp ERROR
1036 l0398h:
1037 pop af
1038 ret
1039
1040 get_range:
1041 call next_arg
1042 cp 'S'
1043 jr nz,l03a2h
1044 inc de
1045 l03a2h:
1046 push hl
1047 push af ;'S' flag
1048 call expr
1049 jr c,l03b8h
1050 ld b,h
1051 ld c,l
1052 pop af
1053 pop hl
1054 jr z,l03b6h ;'S'?
1055 ld a,c
1056 sub l
1057 ld c,a
1058 ld a,b
1059 sbc a,h
1060 ld b,a
1061 inc bc
1062 l03b6h:
1063 and a
1064 ret
1065 l03b8h:
1066 pop af
1067 pop hl
1068 jr z,error0 ;'S', but no expression following
1069 scf
1070 ret
1071
1072 ;-------------------------------------------------------------------------------
1073
1074 expr:
1075 call skipbl
1076 expr1:
1077 call do_factor
1078 ret c
1079 l0433h:
1080 call do_binary_op
1081 push hl
1082 push bc
1083 call do_factor
1084 pop bc
1085 ex de,hl
1086 ex (sp),hl
1087 jr nc,l0447h
1088 pop de
1089 ld a,b
1090 or c
1091 ret z
1092 jp ERROR
1093
1094 l0447h:
1095 ld a,b
1096 or c
1097 push bc
1098 ret nz
1099 pop bc
1100
1101 doop_add:
1102 add hl,de
1103 l044dh:
1104 pop de
1105 jr l0433h
1106
1107 doop_sub:
1108 and a
1109 sbc hl,de
1110 jr l044dh
1111
1112 doop_mlt:
1113 push bc
1114 ld b,h
1115 ld c,l
1116 ld hl,0
1117 ld a,010h
1118 l045dh:
1119 add hl,hl
1120 ex de,hl
1121 add hl,hl
1122 ex de,hl
1123 jr nc,l0464h
1124 add hl,bc
1125 l0464h:
1126 dec a
1127 jr nz,l045dh
1128 pop bc
1129 jr l044dh
1130
1131 doop_div:
1132 call div_hl_de
1133 jr l044dh
1134
1135 doop_mod:
1136 call div_hl_de
1137 ex de,hl
1138 jr l044dh
1139
1140 ; divide x/y
1141 ; hl: x
1142 ; de: y
1143 ; return:
1144 ; hl: q (x/y)
1145 ; de: r (x%y)
1146
1147 div_hl_de:
1148 push bc
1149 ex de,hl ;de: x
1150 ld b,h ;bc: y
1151 ld c,l
1152 ld hl,0 ;hl: r
1153 ld a,16
1154
1155 ; de: x (x shifted out, q shifted in)
1156 ; bc: y
1157 ; hl: r (initially 0)
1158
1159 div_lp:
1160 ex de,hl
1161 add hl,hl ;x <<= 1
1162 ex de,hl
1163 adc hl,hl ;r <<= 1
1164 inc de
1165 or a
1166 sbc hl,bc
1167 jr nc,div_norestore
1168 dec de
1169 add hl,bc
1170 div_norestore:
1171 dec a
1172 jr nz,div_lp
1173 ex de,hl
1174 pop bc
1175 ret
1176
1177 doop_and:
1178 ld a,h
1179 and d
1180 ld h,a
1181 ld a,l
1182 and e
1183 ld l,a
1184 jr l044dh
1185
1186 doop_or:
1187 ld a,h
1188 or d
1189 ld h,a
1190 ld a,l
1191 or e
1192 ld l,a
1193 jr l044dh
1194
1195 doop_xor:
1196 ld a,h
1197 xor d
1198 ld h,a
1199 ld a,l
1200 xor e
1201 ld l,a
1202 jr l044dh
1203
1204 do_binary_op:
1205 push hl
1206 ld hl,tab_op_a
1207 call lookupch
1208 ld a,b
1209 ld hl,tblf_opa
1210 call add_hl_a2
1211 ld c,(hl)
1212 inc hl
1213 ld b,(hl)
1214 pop hl
1215 ret
1216
1217 tab_op_a:
1218 DB '+-*/%&!#',0
1219
1220 tblf_opa:
1221 dw doop_add
1222 dw doop_sub
1223 dw doop_mlt
1224 dw doop_div
1225 dw doop_mod
1226 dw doop_and
1227 dw doop_or
1228 dw doop_xor
1229 dw 0
1230
1231 ;-------------------------------------------------------------------------------
1232
1233 fact_factor:
1234 call do_factor
1235 ret nc
1236 jp ERROR
1237
1238 do_factor:
1239 call chk_stack
1240 call get.number
1241 ret nc
1242 inc de
1243 ld hl,ddtz_base-1
1244 cp 'T'
1245 ret z
1246 ld hl,(high_load)
1247 cp 'H'
1248 ret z
1249 ld hl,(max_load)
1250 cp 'M'
1251 ret z
1252 ld hl,TPA
1253 cp 'L'
1254 ret z
1255 ld hl,(reg.pc)
1256 cp '$'
1257 ret z
1258 cp '-'
1259 jr z,fact_factneg
1260 cp '~'
1261 jr z,fact_factinv
1262 cp '+'
1263 jr z,fact_factor
1264 cp '^'
1265 jr z,fact_reg.CPU
1266 cp '('
1267 jr z,fact_mem
1268 cp '['
1269 jr z,expr_brckt
1270 cp ''''
1271 jr z,fact_factstring
1272 dec de
1273 scf
1274 ret
1275
1276 ;-------------------------------------------------------------------------------
1277
1278 fact_factstring:
1279 ld hl,0
1280 l054bh:
1281 ld a,(de)
1282 cp ''''
1283 jr z,l0557h
1284 and a
1285 ret z
1286 l0552h:
1287 ld h,l
1288 ld l,a
1289 inc de
1290 jr l054bh
1291 l0557h:
1292 inc de
1293 ld a,(de)
1294 cp ''''
1295 jr z,l0552h
1296 sub '.'
1297 or a
1298 ret nz
1299 inc de
1300 set 7,l
1301 ret
1302
1303 fact_reg.CPU:
1304 call sub_0caeh
1305 jr nc,error1
1306 ld a,(hl)
1307 inc hl
1308 ld h,(hl)
1309 ld l,a
1310 xor a ;clr cy, a=0
1311 bit 0,c
1312 ret nz
1313 ld h,a
1314 ret
1315
1316 fact_factinv:
1317 call fact_factor
1318 jr cpl.hl
1319
1320 fact_factneg:
1321 call fact_factor
1322 neg.hl:
1323 dec hl
1324 cpl.hl:
1325 ld a,h
1326 cpl
1327 ld h,a
1328 ld a,l
1329 cpl
1330 ld l,a
1331 ret
1332
1333 fact_mem:
1334 call expr1
1335 jr c,error1
1336 ld a,(de)
1337 cp ')'
1338 jr nz,error1
1339 inc de
1340 ld a,(hl)
1341 inc hl
1342 ld h,(hl)
1343 ld l,a
1344 ld a,(de)
1345 inc de
1346 cp '.'
1347 ret z
1348 dec de
1349 xor a
1350 ld h,a
1351 ret
1352
1353 expr_brckt:
1354 call expr1
1355 jr c,error1
1356 ld a,(de)
1357 cp ']'
1358 inc de
1359 ret z
1360 error1:
1361 jp ERROR
1362
1363 ;-------------------------------------------------------------------------------
1364
1365 get.number:
1366 call get.hexdigit
1367 ret c
1368 push de
1369 test_number:
1370 inc de
1371 call get.hexdigit
1372 jr nc,test_number
1373 pop de
1374 cp '.'
1375 jr z,get_dec_number
1376 cp '"'
1377 jr z,get_bin_number
1378 ld hl,0
1379 next_hexdigit:
1380 call get.hexdigit
1381 jr c,hexnum_done
1382 add hl,hl
1383 add hl,hl
1384 add hl,hl
1385 add hl,hl
1386 call add_hl_a
1387 inc de
1388 jr next_hexdigit
1389
1390 hexnum_done:
1391 xor 'H'
1392 ret nz
1393 inc de
1394 ret
1395
1396 get_bin_number:
1397 ld hl,0
1398 next_bindigit:
1399 call get.bindigit
1400 l05dbh:
1401 inc de
1402 jr c,l05e4h
1403 add hl,hl
1404 call add_hl_a
1405 jr next_bindigit
1406 l05e4h:
1407 cp '"'
1408 jr nz,error11
1409 call get.bindigit
1410 jr nc,l05dbh
1411 or a
1412 ret
1413
1414 get_dec_number:
1415 ld hl,0
1416 next_decdigit:
1417 call get.decdigit
1418 inc de
1419 jr c,decnum_done
1420 push bc
1421 add hl,hl
1422 ld b,h
1423 ld c,l
1424 add hl,hl
1425 add hl,hl
1426 add hl,bc
1427 pop bc
1428 call add_hl_a
1429 jr next_decdigit
1430 decnum_done:
1431 cp '.'
1432 ret z
1433 error11:
1434 jp ERROR
1435
1436 sub_060ch:
1437 call get_char_upper
1438 cp 'Z'+1
1439 jr l0614h
1440
1441 get.hexdigit:
1442 ld a,(de)
1443 hex_digit:
1444 call toupper
1445 cp 'F'+1
1446 l0614h:
1447 ccf
1448 ret c
1449 cp 'A'
1450 jr c,l061eh
1451 sub 'A'-10
1452 ret
1453
1454 get.decdigit:
1455 call get_char_upper
1456 l061eh:
1457 cp '9'+1
1458 jr l0625h
1459
1460 get.bindigit:
1461 call get_char_upper
1462 cp '1'+1
1463 l0625h:
1464 ccf
1465 ret c
1466 cp '0'
1467 ret c
1468 sub '0'
1469 ret
1470
1471 ;-------------------------------------------------------------------------------
1472
1473 p_cpustat0:
1474 call assert_eol
1475 p_cpustat:
1476 call p_f
1477 call outbl2
1478 ld hl,b_06e9_start
1479 ld de,b_0709_start
1480 ld b,6
1481 l063eh:
1482 call p_regs
1483 djnz l063eh
1484 call outbl6
1485 push hl
1486 push de
1487 ld iy,(reg.pc)
1488 call p_disas_instr
1489 pop de
1490 pop hl
1491 call crlf
1492 call p_f2
1493 call outbl2
1494 ld b,7
1495 l065bh:
1496 call p_regs
1497 djnz l065bh
1498 jp crlf
1499
1500 p_f:
1501 ld a,(reg.f)
1502 call p_flags
1503 ld a,(reg.iff)
1504 cp 0f3h
1505 jr z,outbl_1
1506 ld a,'E'
1507 jp outchar
1508 p_f2:
1509 ld a,(reg.f2)
1510 call p_flags
1511 jr outbl_1
1512
1513 p_flags:
1514 push hl
1515 ld hl,t_flag_names+7
1516 ld c,a
1517 ld b,8
1518 fl_loop:
1519 ld a,' '
1520 cp (hl)
1521 ld a,c
1522 rlca
1523 ld c,a
1524 jr z,fl_skip
1525 ld a,(hl)
1526 call c,outchar
1527 call nc,outbl
1528 fl_skip:
1529 dec hl
1530 djnz fl_loop
1531 pop hl
1532 ret
1533
1534 p_regs:
1535 push de
1536 call pstr
1537 call pstr_inl
1538 dc '='
1539 ex (sp),hl
1540 ld e,(hl)
1541 inc hl
1542 ld d,(hl)
1543 inc hl
1544 ld a,(hl)
1545 inc hl
1546 push hl
1547 and a
1548 jr z,l06deh
1549 ex de,hl
1550 ld e,(hl)
1551 inc hl
1552 ld d,(hl)
1553 ex de,hl
1554 call out_hl
1555 jr l06e2h
1556 l06deh:
1557 ld a,(de)
1558 call out_hex
1559 l06e2h:
1560 pop de
1561 pop hl
1562 outbl_1:
1563 jp outbl
1564
1565 b_06e9_start:
1566 DC 'A '
1567 DC 'BC '
1568 DC 'DE '
1569 DC 'HL '
1570 DC 'SP'
1571 DC 'PC'
1572 DC 'a'''
1573 DC 'bc'''
1574 DC 'de'''
1575 DC 'hl'''
1576 DC 'IX'
1577 DC 'IY'
1578 DC 'I'
1579 DB 0
1580
1581 b_0709_start:
1582 dw reg.a
1583 db 000h
1584 dw reg.c
1585 db 001h
1586 dw reg.e
1587 db 001h
1588 dw reg.l
1589 db 001h
1590 dw reg_sp
1591 db 001h
1592 dw reg.pc
1593 db 002h
1594 dw reg.a2
1595 db 000h
1596 dw reg.c2
1597 db 001h
1598 dw reg.e2
1599 db 001h
1600 dw reg.l2
1601 db 001h
1602 dw reg.ix
1603 db 001h
1604 dw reg.iy
1605 db 001h
1606 dw reg.i
1607 db 000h
1608 db 000h
1609
1610 ;-------------------------------------------------------------------------------
1611 ; > E addr
1612 ; relocate debugger to addr
1613 ; > ER addr
1614 ; relocate just below addr
1615 ;
1616 ; Move debugger to given address and restart.
1617 ; New location must not overlap with current location.
1618
1619
1620 cmd_E:
1621 call skipbl
1622 sub 'R'
1623 jr nz,$+3
1624 inc de
1625 push af
1626 call get_arg_final
1627
1628 ex de,hl
1629 ld hl,(bitmap_end)
1630 ld bc,ddtz_base
1631 or a
1632 sbc hl,bc
1633 ld b,h
1634 ld c,l
1635 ex de,hl
1636 pop af
1637 jr nz,cmde_bottom
1638 sbc hl,bc
1639 cmde_bottom:
1640 ld ix,cmde_clr-ddtz_base
1641 ex de,hl ;de = dst
1642 add ix,de
1643 ld hl,ddtz_base ;hl = src
1644
1645 push hl
1646 or a
1647 sbc hl,de
1648 call c,neg.hl ;abs(distance)
1649 or a
1650 sbc hl,bc
1651 jp c,error
1652 pop hl
1653 push hl
1654 push bc
1655 ldir
1656 pop bc
1657 pop hl
1658 jp (ix)
1659
1660 ;-------------------------------------------------------------------------------
1661 ; > G [startaddr] [;breakp..]
1662 ; Go [to start] [with temporary breakpoints]
1663
1664 cmd_G:
1665 call expr
1666 jr c,l0740h
1667 ld (reg.pc),hl
1668 l0740h:
1669 call skipbl
1670 jr z,user_go0
1671 cp ';'
1672 jp nz,ERROR
1673 inc de
1674 ld a,002h
1675 call bp_enter
1676 user_go0:
1677 jp user_go
1678
1679 ;-------------------------------------------------------------------------------
1680
1681 bpl_init:
1682 ld b,BP_CNT
1683 ld ix,bp_tab
1684 ex (sp),hl
1685 ld (pbl_loop_adr),hl
1686 ex (sp),hl
1687 ret
1688
1689 bpl_next:
1690 ld de,BP_SIZE
1691 push af
1692 add ix,de
1693 pop af
1694 dec b
1695 ret z
1696
1697 ex (sp),hl
1698 ld hl,(pbl_loop_adr)
1699 ex (sp),hl
1700 ret
1701
1702 bp_clr_temporary:
1703 call bpl_init
1704
1705 ld a,(ix+000h)
1706 and 0f1h
1707 ld (ix+000h),a
1708
1709 call bpl_next
1710 ret
1711
1712 ;-------------------------------------------------------------------------------
1713 ; > B
1714 ; display all breakpoints
1715 ; > B breakp [breakp..]
1716 ; set breakpoints
1717 ; > BX
1718 ; clear all breakpoints
1719 ; > BX breakp [breakp..]
1720 ; clear breakpoints
1721 ;
1722 ; breakp can be any valid expression
1723
1724 cmd_B:
1725 call skipbl
1726 jr z,bp_print
1727 inc de
1728 cp 'X'
1729 jr z,bp_clr0
1730 dec de
1731 ld a,001h
1732 jp bp_enter
1733
1734 bp_clr0:
1735 call skipbl
1736 jr z,bp_clr_all
1737 bp_clr_next:
1738 call expr
1739 jp c,assert_eol
1740 push de
1741 call bp_clr
1742 pop de
1743 call next_arg
1744 jr bp_clr_next
1745
1746 bp_clr_all:
1747 scf
1748 bp_clr:
1749 call bpl_init
1750
1751 push af
1752 jr c,l07a7h
1753 ld e,(ix+002h)
1754 ld d,(ix+003h)
1755 call cp_hl_de
1756 jr nz,l07aeh
1757 l07a7h:
1758 ld (ix+000h),000h
1759 l07aeh:
1760 pop af
1761 call bpl_next
1762 ret
1763
1764 bp_print:
1765 ld c,0
1766 call bpl_init
1767
1768 bit 0,(ix+000h)
1769 jr z,bp_pr_cont
1770 ld l,(ix+002h)
1771 ld h,(ix+003h)
1772 call out_hl
1773 call outbl2
1774 inc c
1775 bp_pr_cont:
1776 call bpl_next
1777 ld a,c
1778 or a
1779 call nz,crlf
1780 ret
1781
1782 ;-------------------------------------------------------------------------------
1783 ; Add break points to list
1784 ; A = 1 Permanent (B command)
1785 ; A = 2 Temporary (G command)
1786
1787 bp_enter:
1788 ld b,a
1789 call skipbl
1790 ret z
1791
1792 push bc
1793 call expr
1794 jr c,error12
1795 pop bc
1796 bit 0,b
1797 push bc
1798 push de
1799 push hl
1800 call nz,bp_clr
1801 pop hl
1802 call bp_get_freeslot
1803 pop de
1804 ld (ix+002h),l
1805 ld (ix+003h),h
1806 call next_arg
1807 pop af
1808 ld (ix+000h),a
1809 and 00fh
1810 jr bp_enter
1811
1812 bp_get_freeslot:
1813 call bpl_init
1814
1815 ld a,(ix+000h)
1816 and 00fh
1817 ret z
1818
1819 call bpl_next
1820 error12
1821 jp ERROR
1822
1823
1824 ;-------------------------------------------------------------------------------
1825 ; Breakpoint handling routine.
1826
1827 bpddtz:
1828 ld (reg.l),hl
1829 pop hl
1830 dec hl
1831 ld (reg.pc),hl
1832 ld (reg_sp),sp
1833 ld sp,reg.l
1834 push de
1835 push bc
1836 push af
1837 push ix
1838 push iy
1839 ld a,i
1840 call di_or_ei
1841 ld h,a
1842 ld l,000h
1843 push hl
1844 ld a,0f3h ; EI
1845 jp po,l08dfh
1846 ld a,0fbh ; DI
1847 l08dfh:
1848 ld (reg.iff),a
1849 ex af,af'
1850 push af
1851 exx
1852 push bc
1853 push de
1854 push hl
1855 call bp_restore_mem
1856 ld a,(b_21e2_start)
1857 dec a
1858 jr z,l090bh
1859 call inchar ;Keyboard hit?
1860 jr c,do_break ;yes
1861 call sub_0913h
1862 and a
1863 jp z,user_go
1864 and 083h
1865 jp z,l2151h
1866 do_break:
1867 call bp_clr_temporary
1868 call p_cpustat
1869 jp mainloop
1870
1871 l090bh:
1872 ld (b_21e2_start),a
1873 ld c,007h
1874 jp l0a41h
1875
1876 sub_0913h:
1877 ld a,080h
1878 ex af,af'
1879 call bpl_init
1880
1881 ld a,(ix+000h)
1882 and 007h
1883 jr z,l0938h
1884 ld e,(ix+002h)
1885 ld d,(ix+003h)
1886 ld hl,(reg.pc)
1887 call cp_hl_de
1888 jr nz,l0938h
1889 ex af,af'
1890 res 7,a
1891 or (ix+000h)
1892 ex af,af'
1893 l0938h:
1894 call bpl_next
1895 ex af,af'
1896 ret
1897
1898 bp_restore_mem:
1899 call bpl_init
1900
1901 bit 5,(ix+000h)
1902 res 5,(ix+000h)
1903 jr z,l099ah
1904 ld l,(ix+002h)
1905 ld h,(ix+003h)
1906 ld a,(l0003h)
1907 cp (hl)
1908 jr nz,l099ah
1909 ld a,(ix+001h)
1910 ld (hl),a
1911 l099ah:
1912 res 3,(ix+000h)
1913
1914 call bpl_next
1915 ret
1916
1917 bp_tst_@pc:
1918 call bpl_init
1919
1920 ld a,(ix+000h)
1921 and 003h ;User bp (temporary or permanent)?
1922 jr z,bp_tst_e ;No, check next
1923 ld e,(ix+002h)
1924 ld d,(ix+003h)
1925 ld hl,(reg.pc)
1926 call cp_hl_de ;Current PC is on a User bp
1927 ret z ;Return zero
1928 bp_tst_e:
1929 call bpl_next
1930 sub a
1931 inc a ;Not on a user bp
1932 ret ;Return not zero
1933
1934 bp_trace_enter:
1935 call bp_get_freeslot
1936 ld (ix+002h),l
1937 ld (ix+003h),h
1938 ld a,(b_21e2_start)
1939 and a
1940 ld a,008h
1941 jr nz,bp_t_e
1942 rra
1943 bp_t_e:
1944 ld (ix+000h),a
1945 ret
1946
1947 bp_set_to_mem:
1948 call bpl_init
1949
1950 ld a,(ix+000h)
1951 and c
1952 jr z,l0a1dh
1953 set 5,(ix+000h)
1954 ld l,(ix+002h)
1955 ld h,(ix+003h)
1956 ld a,(hl)
1957 ld (ix+001h),a
1958 ld a,(l0003h)
1959 ld (hl),a
1960 and 038h
1961 ld h,000h
1962 ld l,a
1963 ld (hl),0c3h
1964 inc hl
1965 ld de,bpddtz
1966 ld (hl),e
1967 inc hl
1968 ld (hl),d
1969 l0a1dh:
1970 call bpl_next
1971 ret
1972
1973 ;-------------------------------------------------------------------------------
1974
1975 user_go:
1976 sub a
1977 ld (b_21e2_start),a
1978 call bp_tst_@pc
1979 ld c,007h
1980 jr nz,l0a41h
1981 ld a,001h
1982 ld (b_21e2_start),a
1983 call tc_set_bp
1984 ld c,008h
1985 l0a41h:
1986 call bp_set_to_mem
1987 ld sp,reg.l2
1988 pop hl
1989 pop de
1990 pop bc
1991 pop af
1992 exx
1993 ex af,af'
1994 pop af
1995 ld i,a
1996 pop iy
1997 pop ix
1998 pop af
1999 pop bc
2000 pop de
2001 pop hl
2002 ld sp,(reg_sp)
2003 jp reg.iff
2004
2005 ;-------------------------------------------------------------------------------
2006 ; > Y
2007 ; examine all Y variables
2008 ; > Y[0..9]
2009 ; examine (and substitute) an Y variable
2010
2011
2012 ;-------------------------------------------------------------------------------
2013 ; > X
2014 ; eXamine (display) all cpu registers and
2015 ; the instruction at the current program counter
2016 ; > X register
2017 ; eXamine (and substitute) a register
2018
2019
2020 cmd_X:
2021 call skipbl
2022 call sub_0caeh
2023 jp nc,p_cpustat0
2024 call assert_eol
2025 ld a,b
2026 cp 25
2027 jr z,l0c5fh
2028 cp 26
2029 jr z,l0c4fh
2030 ex de,hl
2031 ld hl,t_reg_names
2032 call pstr_sel
2033 call l0c33h
2034
2035 call outbl
2036 push de
2037 push bc
2038 call get_line
2039 call skipbl
2040 jr z,l0c30h
2041 call get_arg_final
2042 ex de,hl
2043 pop bc
2044 pop hl
2045 ld (hl),e
2046 bit 0,c
2047 ret z
2048 inc hl
2049 ld (hl),d
2050 ret
2051 l0c30h:
2052 pop af
2053 pop hl
2054 ret
2055
2056 l0c33h:
2057 call pstr_inl
2058 dc '='
2059 ld a,(de)
2060 bit 0,c
2061 jp z,out_hex
2062 ld l,a
2063 inc de
2064 ld a,(de)
2065 dec de
2066 ld h,a
2067 jp out_hl
2068
2069 l0c4fh:
2070 call p_f
2071 ld a,0f3h
2072 ld (reg.iff),a
2073 scf
2074 call sub_0c6ah
2075 ld (reg.f),a
2076 ret
2077 l0c5fh:
2078 call p_f2
2079 and a
2080 call sub_0c6ah
2081 ld (reg.f2),a
2082 ret
2083
2084 sub_0c6ah:
2085 push af
2086 call outbl
2087 call assert_eol
2088 call get_line
2089 pop af
2090 ex af,af'
2091 ld b,0
2092 l0c76h:
2093 call skipbl
2094 ld a,b
2095 ret z
2096 push bc
2097 ld hl,t_flag_names
2098 call lookupch
2099 jp nc,ERROR
2100 inc b
2101 xor a
2102 scf
2103 nxt_f:
2104 rla
2105 djnz nxt_f
2106 pop bc
2107 jr c,l0c97h
2108 or b
2109 ld b,a
2110 jr l0c76h
2111
2112 l0c97h:
2113 ex af,af'
2114 jp nc,ERROR
2115 ex af,af'
2116 ld a,0fbh
2117 ld (reg.iff),a
2118 jr l0c76h
2119
2120 t_flag_names:
2121 db 'CNV H ZSE',0
2122
2123 sub_0caeh:
2124 call sub_0303h
2125 ret nc
2126 ld a,b
2127 add a,b
2128 add a,b
2129 ld hl,b_0cfa_start
2130 call add_hl_a
2131 ld c,(hl)
2132 inc hl
2133 ld a,(hl)
2134 inc hl
2135 ld h,(hl)
2136 ld l,a
2137 scf
2138 ret
2139
2140 t_reg_names:
2141 DC 'BC''' ;0
2142 DC 'DE''' ;1
2143 DC 'HL''' ;2
2144 DC 'BC' ;3
2145 DC 'DE' ;4
2146 DC 'HL' ;5
2147 DC 'A''' ;6
2148 DC 'B''' ;7
2149 DC 'C''' ;8
2150 DC 'D''' ;9
2151 DC 'E''' ;10
2152 DC 'H''' ;11
2153 DC 'L''' ;12
2154 DC 'A' ;13
2155 DC 'B' ;14
2156 DC 'C' ;15
2157 DC 'D' ;16
2158 DC 'E' ;17
2159 DC 'H' ;18
2160 DC 'L' ;19
2161 DC 'IX' ;20
2162 DC 'IY' ;21
2163 DC 'SP' ;22
2164 DC 'PC' ;23
2165 DC 'I' ;24
2166 DC 'F''' ;25
2167 DC 'F' ;26
2168 DB 0
2169
2170 b_0cfa_start:
2171 db 003h
2172 dw reg.c2
2173 db 003h
2174 dw reg.e2
2175 db 003h
2176 dw reg.l2
2177 db 003h
2178 dw reg.c
2179 db 003h
2180 dw reg.e
2181 db 003h
2182 dw reg.l
2183 db 000h
2184 dw reg.a2
2185 db 000h
2186 dw reg.b2
2187 db 000h
2188 dw reg.c2
2189 db 000h
2190 dw reg.d2
2191 db 000h
2192 dw reg.e2
2193 db 000h
2194 dw reg.h2
2195 db 000h
2196 dw reg.l2
2197 db 000h
2198 dw reg.a
2199 db 000h
2200 dw reg.b
2201 db 000h
2202 dw reg.c
2203 db 000h
2204 dw reg.d
2205 db 000h
2206 dw reg.e
2207 db 000h
2208 dw reg.h
2209 db 000h
2210 dw reg.l
2211 db 003h
2212 dw reg.ix
2213 db 003h
2214 dw reg.iy
2215 db 003h
2216 dw reg_sp
2217 db 003h
2218 dw reg.pc
2219 db 000h
2220 dw reg.i
2221 db 000h
2222 dw reg.f2
2223 db 000h
2224 dw reg.f
2225
2226 ;-------------------------------------------------------------------------------
2227 ; > S [startaddr]
2228 ; Substitute memory
2229
2230 cmd_S:
2231 ld hl,(last_S)
2232 call get_lastarg_def
2233 l0d60h:
2234 ld (last_S),hl
2235 call out_hl
2236 call outbl
2237 ld a,(hl)
2238 call out_hex
2239 call outbl2
2240 call get_line
2241 call skipbl
2242 inc hl
2243 jr z,l0d60h
2244 dec hl
2245 inc de
2246 cp '.'
2247 jr nz,cmds_dash
2248 call get_char_upper
2249 or a
2250 jr nz,l0d8ah
2251 ret
2252 cmds_dash:
2253 jp z,assert_eol
2254 cp '-'
2255 jr nz,l0d8ah
2256 call get_char_upper
2257 or a
2258 dec hl
2259 jr z,l0d60h
2260 inc hl
2261 l0d8ah:
2262 dec de
2263 call sub_0ef8h
2264 jr l0d60h
2265
2266 ;-------------------------------------------------------------------------------
2267 ; > @
2268 ; examine (substitute) displacement register @
2269
2270 ;cmd_@:
2271
2272 ;-------------------------------------------------------------------------------
2273 ; >>I [port]
2274 ; Input a byte from port
2275
2276 cmd_I:
2277 ld (cmd_rpt),hl
2278 ld hl,(last_I)
2279 call get_lastarg_def
2280 ld (last_I),hl
2281 ld b,h
2282 ld c,l
2283 in a,(c)
2284 push af
2285 call out_hex
2286 call outbl4
2287 pop af
2288 call out.bin.b
2289 jp crlf
2290
2291 ;-------------------------------------------------------------------------------
2292 ; >>O [byte] [port]
2293 ; Output a byte to a port
2294
2295 cmd_O:
2296 ld (cmd_rpt),hl
2297 ld hl,(last_O_val)
2298 call get_arg_def
2299 ld a,l
2300 ld (last_O_val),a
2301 push af
2302 call next_arg
2303 ld hl,(last_O_addr)
2304 call get_lastarg_def
2305 ld (last_O_addr),hl
2306 ld b,h
2307 ld c,l
2308 pop af
2309 out (c),a
2310 ret
2311
2312 ;-------------------------------------------------------------------------------
2313 ; > V startaddr endaddr targetaddr
2314 ; Verify (compare) two memory areas
2315
2316 cmd_V:
2317 call get_arg_range_target
2318 l0dedh:
2319 push bc
2320 ld a,(de)
2321 ld b,(hl)
2322 cp b
2323 jr z,l0e10h
2324 ld c,a
2325 call out_hl
2326 call outbl
2327 ld a,b
2328 call out_hex
2329 call outbl2
2330 ld a,c
2331 call out_hex
2332 call outbl
2333 ex de,hl
2334 call out_hl
2335 ex de,hl
2336 call crlf
2337 l0e10h:
2338 pop bc
2339 inc de
2340 cpi
2341 jp pe,l0dedh
2342 ret
2343
2344 ;-------------------------------------------------------------------------------
2345 ; > M startaddr endaddr destaddr
2346 ; Move memory
2347
2348 cmd_M:
2349 call get_arg_range_target
2350 call cp_hl_de
2351 jr nc,cmdm_up
2352 add hl,bc
2353 ex de,hl
2354 add hl,bc
2355 ex de,hl
2356 dec hl
2357 dec de
2358 lddr
2359 ret
2360 cmdm_up:
2361 ldir
2362 ret
2363
2364 ;-------------------------------------------------------------------------------
2365 ; > H
2366 ; display Highest load address of last filed loaded, Maximum "High"
2367 ; off all loaded files, and Top address of available memory
2368 ; > H expression
2369 ; evaluate expression and display result in hex, decimal and other formats
2370
2371 cmd_H:
2372 call expr
2373 jp c,p_max_high0
2374 call assert_eol
2375 call out_hl
2376 call outbl2
2377 call out_hl_neg
2378 call outbl4
2379 call out.hl.dec
2380 call outbl2
2381 call out_hl_dec_neg
2382 call outbl4
2383 call out.bin.w
2384 call outbl2
2385 ld a,l
2386 call out.ascii
2387 jp crlf
2388
2389 ;-------------------------------------------------------------------------------
2390 ; > Q[J] startaddr endaddr bytes
2391 ; Query memory for a byte string [Justified]
2392
2393 cmd_Q:
2394 call get_arg_range
2395 push bc
2396 push hl
2397 call sub_0ee6h
2398 pop hl
2399 l0e96h:
2400 push hl
2401 push de
2402 push bc
2403 l0edah:
2404 ld a,(de)
2405 cp (hl)
2406 jr nz,l0ee2h
2407 inc de
2408 inc hl
2409 djnz l0edah
2410 l0ee2h:
2411 pop bc
2412 pop de
2413 pop hl
2414 jr nz,l0eb0h
2415 push bc
2416 ld bc,16
2417 and a ;clear carry
2418 call sub_0f58h
2419 pop bc
2420 l0eb0h:
2421 inc hl
2422 ex (sp),hl
2423 dec hl
2424 ld a,h
2425 or l
2426 ex (sp),hl
2427 jr nz,l0e96h
2428 pop bc
2429 ret
2430
2431 ;-------------------------------------------------------------------------------
2432 ; > Z startaddr endaddr bytes
2433 ; Zap (fill) memory with a byte string
2434
2435 cmd_Z:
2436 call get_arg_range
2437 push bc
2438 push hl
2439 call sub_0ee6h
2440 ld a,b
2441 pop hl
2442 pop bc
2443 push hl
2444 ex de,hl
2445 l0ec7h:
2446 ldi
2447 jp po,l0ed3h
2448 dec a
2449 jr nz,l0ec7h
2450 pop hl
2451 ldir
2452 ret
2453 l0ed3h:
2454 pop hl
2455 ret
2456
2457 sub_0ee6h:
2458 ld hl,conbuf
2459 call sub_0ef7h
2460 ld de,conbuf
2461 and a
2462 sbc hl,de
2463 ld b,l
2464 ret nz
2465 jp ERROR
2466
2467 sub_0ef7h: ;from cmd_Q, cmd_Z
2468 db 0e6h ;and 037h (clear carry)
2469 sub_0ef8h: ;from cmd_S
2470 scf
2471 l0ef9h:
2472 push af
2473 call next_arg
2474 cp ''''
2475 jr z,l0f1eh
2476 push hl
2477 call expr
2478 ld a,l
2479 pop hl
2480 jr c,l0f42h
2481 ld (hl),a
2482 inc hl
2483 jr l0f3ah
2484 l0f1eh:
2485 inc de
2486 ld a,(de)
2487 cp ''''
2488 jr z,l0f2bh
2489 or a
2490 jr z,l0f42h
2491 l0f27h:
2492 ld (hl),a
2493 inc hl
2494 jr l0f1eh
2495 l0f2bh:
2496 inc de
2497 ld a,(de)
2498 cp ''''
2499 jr z,l0f27h
2500 cp '.'
2501 jr nz,l0f3ah
2502 inc de
2503 dec hl
2504 set 7,(hl)
2505 inc hl
2506 l0f3ah:
2507 pop af
2508 jr nc,l0ef9h
2509 ld (last_S),hl
2510 jr l0ef9h
2511 l0f42h:
2512 pop af
2513 ret nc
2514 ld (last_S),hl
2515 ret
2516
2517 ;-------------------------------------------------------------------------------
2518 ; >>D [startaddr] [endaddr]
2519 ; Display memory in hex and ASCII
2520
2521 cmd_D:
2522 ld (cmd_rpt),hl
2523 ld hl,(last_D)
2524 ld bc,128
2525 call sub_0377h
2526 scf
2527 sub_0f58h:
2528 push bc
2529 push de
2530 push hl
2531 push af
2532 l0f5ch:
2533 call out_hl
2534 call outbl2
2535 ld de,0
2536 l0f68h:
2537 ld a,(hl)
2538 inc hl
2539 call out_hex
2540 call outbl
2541 dec bc
2542 inc e
2543 ld a,e
2544 cp 010h
2545 jr z,l0f80h
2546 and 003h
2547 call z,outbl
2548 ld a,b
2549 or c
2550 jr nz,l0f68h
2551 l0f80h:
2552 call outbl
2553 and a
2554 sbc hl,de
2555 l0f86h:
2556 ld a,(hl)
2557 call sub_0fa3h
2558 call outchar
2559 inc hl
2560 dec e
2561 jr nz,l0f86h
2562 pop af
2563 push af
2564 jr nc,l0f97h
2565 ld (last_D),hl
2566 l0f97h:
2567 call crlf
2568 ld a,b
2569 or c
2570 jr nz,l0f5ch
2571 pop af
2572 pop hl
2573 pop de
2574 pop bc
2575 ret
2576
2577 sub_0fa3h:
2578 and 07fh
2579 cp 07fh
2580 jr z,l0fach
2581 cp ' '
2582 ret nc
2583 l0fach:
2584 ld a,'.'
2585 ret
2586
2587 ;-------------------------------------------------------------------------------
2588 ; > Fcommandline
2589 ; specifiy filenames and command line
2590
2591 ;cmd_F:
2592
2593 ;-------------------------------------------------------------------------------
2594 ; > R [displacement]
2595 ; Read Intel Hex File from console [add displacement]
2596
2597 cmd_R:
2598 ld hl,0
2599 call get_lastarg_def ;get offset from command line
2600 push hl
2601 ld hl,0
2602 ld (high_load),hl
2603 w_recstart:
2604 call i.getchar
2605 jr z,rdhex_done
2606 cp ':'
2607 jr nz,w_recstart
2608 ld c,0 ;init checksum
2609 call i.gethexbyte ;record len
2610 ld b,a
2611 call i.gethexbyte ;address high
2612 ld h,a
2613 call i.gethexbyte ;address low
2614 ld l,a
2615 call i.gethexbyte ;record type (ignored)
2616 ld a,b
2617 and a ;record len == 0?
2618 jr z,rdhex_done
2619 l16c6h:
2620 call i.gethexbyte
2621 pop de ;offset
2622 push de
2623 push hl
2624 add hl,de
2625 call i.storebyte
2626 pop hl
2627 inc hl
2628 djnz l16c6h ;repeat for record len
2629 call i.gethexbyte ;checksum
2630 ld a,c
2631 and a
2632 jr nz,error2 ;exit if checksum error
2633 jr w_recstart ;next record
2634
2635 rdhex_done:
2636 pop hl
2637 call i.gethexbyte
2638 jp p_max_high
2639
2640 i.gethexbyte:
2641 call sub_16f6h
2642 rlca
2643 rlca
2644 rlca
2645 rlca
2646 ld d,a
2647 call sub_16f6h
2648 add a,d
2649 ld d,a
2650 add a,c
2651 ld c,a
2652 ld a,d
2653 ret
2654
2655 sub_16f6h:
2656 call i.getchar
2657 jr z,error2
2658 call hex_digit
2659 ret nc
2660 error2:
2661 jp ERROR
2662
2663 i.getchar:
2664 call incharw
2665 cp 01ah
2666 ret
2667
2668 i.storebyte:
2669 push af
2670 push de
2671 ld de,ddtz_base ;don't load over ddtz
2672 call cp_hl_de
2673 jr nc,ist_1
2674
2675 ld de,(bitmap_end)
2676 call cp_hl_de
2677 jr nc,error2
2678 ist_1:
2679 ld de,(high_load)
2680 call cp_hl_de
2681 jr c,l1157h
2682 ld (high_load),hl
2683 l1157h:
2684 ld de,(max_load)
2685 call cp_hl_de
2686 jr c,l1163h
2687 ld (max_load),hl
2688 l1163h:
2689 pop de
2690 pop af
2691 ld (hl),a ;store byte
2692 ret
2693
2694 ;-------------------------------------------------------------------------------
2695
2696 p_max_high0:
2697 call assert_eol
2698 p_max_high:
2699 call pstr_inl
2700 DC 'High = '
2701 ld hl,(high_load)
2702 call out_hl
2703 call pstr_inl
2704 DC ' Max = '
2705 ld hl,(max_load)
2706 call out_hl
2707 call pstr_inl
2708 DC ' Top = '
2709 ld hl,ddtz_base-1
2710 call out_hl
2711 jp crlf
2712
2713 ;-------------------------------------------------------------------------------
2714 ; > Wstartaddr endaddr
2715 ; Write a file to disk
2716
2717 ;cmd_W:
2718
2719 ;-------------------------------------------------------------------------------
2720 ; > A [startaddr]
2721 ; Assemble Zilog Z180 mnemonics
2722
2723 ;cmd_A:
2724
2725 ;-------------------------------------------------------------------------------
2726 ; >>L [startaddr] [endaddr]
2727 ; List disassembled code
2728
2729 cmd_L:
2730 ld (cmd_rpt),hl
2731 call expr
2732 jr nc,l18dbh
2733 ld hl,(last_L)
2734 l18dbh:
2735 call next_arg
2736 call get_range
2737 jr nc,l1905h
2738 call assert_eol
2739 ld b,16
2740 l18ebh:
2741 push bc
2742 call cmdl_p_line
2743 pop bc
2744 djnz l18ebh
2745 ret
2746
2747 l1905h:
2748 call assert_eol
2749 ld d,h
2750 ld e,l
2751 add hl,bc
2752 ex de,hl
2753 l190fh:
2754 push de
2755 call cmdl_p_line
2756 pop de
2757 call cp_hl_de
2758 jr c,l190fh
2759 ret
2760
2761 ;-------------------------------------------------------------------------------
2762
2763 cmdl_p_line:
2764 push hl
2765 call out_hl
2766 call outbl2
2767 sub a
2768 ld (con_col),a
2769 push hl
2770 pop iy
2771 call p_disas_instr
2772 call crlf
2773 pop hl
2774 ld c,b
2775 ld b,0
2776 add hl,bc
2777 ld (last_L),hl
2778 ret
2779
2780 ;-------------------------------------------------------------------------------
2781
2782 p_disas_instr:
2783 call disas_get_instrlen
2784 jr nc,l197fh
2785 push bc
2786 ld a,(con_col)
2787 add a,5
2788 ld c,a
2789 call pstr ;print mnemonic
2790 call p_goto_col
2791 call pr_instr_args ;print arguments
2792 pop bc
2793 scf
2794 ret
2795
2796 l197fh:
2797 call pstr_inl
2798 DC '???'
2799 ld b,1
2800 sub a
2801 ret
2802
2803 ;-------------------------------------------------------------------------------
2804
2805 disas_get_instrlen:
2806 sub a
2807 ld (isprefix_ixiy),a
2808 ld a,(iy+000h)
2809 cp 0edh
2810 jr z,disas_pfx.ED
2811 cp 0ddh
2812 jr z,l19abh
2813 cp 0fdh
2814 jr z,l19afh
2815 sub_19a0h:
2816 ld a,(iy+000h)
2817 cp 0cbh
2818 jr z,disas_pfx.CB
2819 jr disas_nopfx
2820 l19abh:
2821 ld a,1
2822 jr l19b1h
2823 l19afh:
2824 ld a,2
2825 l19b1h:
2826 ld (isprefix_ixiy),a
2827 call disas_pfx.DDFD
2828 ret nc
2829 push bc
2830 call sub_19a0h
2831 pop af
2832 add a,b
2833 ld b,a
2834 scf
2835 ret
2836
2837 ;-------------------------------------------------------------------------------
2838
2839 disas_nopfx:
2840 ld hl,b_1b54_start ;2 byte opcodes
2841 call lookup_op_arg
2842 ld b,2
2843 ret c
2844 ld hl,b_1ab6_start ;1 byte opcodes (no parameters)
2845 call lookup_op
2846 ld b,1
2847 ret c
2848 ld hl,b_1ad1_start ;1 byte opcodes
2849 call lookup_op_arg
2850 ld b,1
2851 ret c
2852 ld hl,b_1b9b_start ;3 byte opcodes
2853 call lookup_op_arg
2854 ld b,3
2855 ret
2856
2857 ;-------------------------------------------------------------------------------
2858
2859 disas_pfx.ED:
2860 inc iy
2861 ld hl,l228bh
2862 call lookup_op_arg
2863 ld b,3
2864 ret c
2865 ld hl,b_1c40_start
2866 call lookup_op_arg
2867 ld b,4
2868 ret c
2869
2870 ld hl,b_1bc9_start ;1 byte opcode, no arguments
2871 call lookup_op
2872 jr c,da_ed1
2873
2874 ld hl,b_1bf4_start
2875 call lookup_op_arg
2876 ret nc
2877
2878 ld a,e
2879 cp a_noarg
2880 jr nz,da_ed0
2881 ld c,(iy+0)
2882 ld a,c
2883 rra
2884 and 0ch
2885 ld b,a
2886 ld a,c
2887 and 03h
2888 call str_sel_ab
2889
2890 da_ed0:
2891 scf
2892 da_ed1:
2893 ld b,2
2894 ret
2895
2896 ;-------------------------------------------------------------------------------
2897
2898 disas_pfx.CB:
2899 push iy
2900 inc iy
2901 ld a,(isprefix_ixiy)
2902 and a
2903 jr z,l1a42h
2904 inc iy
2905 l1a42h:
2906 ld hl,b_1c55_start
2907 call lookup_op_arg
2908 pop iy
2909 ld b,2
2910 ret
2911
2912 ;-------------------------------------------------------------------------------
2913
2914 disas_pfx.DDFD:
2915 inc iy
2916 ld hl,b_19ef_start
2917 call test_DDFD
2918 ld b,002h
2919 ret c
2920 ld hl,l1a0ah
2921 call test_DDFD
2922 ld b,001h
2923 ret c
2924 ld a,(iy+000h)
2925 cp 0cbh
2926 jr nz,l19edh
2927 ld a,(iy+002h)
2928 cp 036h
2929 ret z
2930 and 007h
2931 cp 006h
2932 jr nz,l19edh
2933 ld b,002h
2934 scf
2935 ret
2936 l19edh:
2937 and a
2938 ret
2939
2940 ;-------------------------------------------------------------------------------
2941 ; DD/FD 3 byte (ix+d)/(iy+d)
2942 b_19ef_start:
2943 db 034h
2944 db 035h
2945 db 036h
2946 db 046h
2947 db 04eh
2948 db 056h
2949 db 05eh
2950 db 066h
2951 db 06eh
2952 db 070h
2953 db 071h
2954 db 072h
2955 db 073h
2956 db 074h
2957 db 075h
2958 db 077h
2959 db 07eh
2960 db 086h
2961 db 08eh
2962 db 096h
2963 db 09eh
2964 db 0a6h
2965 db 0aeh
2966 db 0b6h
2967 db 0beh
2968 db 0
2969
2970 ; DD/FD 2 byte
2971 l1a0ah:
2972 db 009h
2973 db 019h
2974 db 021h
2975 db 022h
2976 db 023h
2977 db 029h
2978 db 02ah
2979 db 02bh
2980 db 039h
2981 db 0e1h
2982 db 0e3h
2983 db 0e5h
2984 db 0e9h
2985 db 0f9h
2986 db 0
2987
2988 ;-------------------------------------------------------------------------------
2989
2990 test_DDFD:
2991 ld a,(hl)
2992 and a
2993 ret z
2994 inc hl
2995 cp (iy+000h)
2996 jr nz,test_DDFD
2997 scf
2998 ret
2999
3000 lookup_op:
3001 ld a,(hl)
3002 inc hl
3003 cp 0ffh
3004 ret z
3005 cp (iy+000h)
3006 jr z,l1a7fh
3007 inc hl
3008 jr lookup_op
3009 l1a7fh:
3010 ld b,(hl)
3011 ld e,a_noarg
3012 jr get_mnemonic
3013
3014 lookup_op_arg:
3015 call lookup_branch_op
3016 ret nc
3017 ld a,e
3018 ld e,d
3019 cp a,0ffh
3020 ret z ;carry clear
3021 ld b,a
3022
3023 get_mnemonic:
3024 ld hl,t_MNEMONICS
3025 bit 7,b
3026 jr z,get_m1
3027 res 7,b
3028 ld a,(iy+000h)
3029 rra
3030 rra
3031 rra
3032 and 07h
3033 str_sel_ab:
3034 add b
3035 ld b,a
3036 get_m1:
3037 call str_sel
3038 scf
3039 ret
3040
3041 ;-------------------------------------------------------------------------------
3042 ; 1 byte opcodes (no parameters)
3043 ; Format: db opcode, t_MNEMONICS-index
3044 b_1ab6_start:
3045 db 076h,i_HALT ;halt
3046 db 0d9h,i_EXX ;exx
3047 db 0f3h,i_DI ;di
3048 db 0fbh,i_EI ;ei
3049 db 000h,i_NOP ;nop
3050 ; db 007h,i_RLCA ;rlca
3051 ; db 00fh,i_RRCA ;rrca
3052 ; db 017h,i_RLA ;rla
3053 ; db 01fh,i_RRA ;rra
3054 ; db 027h,i_DAA ;daa
3055 ; db 02fh,i_CPL ;cpl
3056 ; db 037h,i_SCF ;scf
3057 ; db 03fh,i_CCF ;ccf
3058 db 0c9h,i_RET ;ret
3059 db 0ffh
3060
3061
3062 ; 1 byte opcodes
3063 ; Format: db mask, match, t_MNEMONICS-index
3064 ; dw argument formating function
3065 b_1ad1_start:
3066 db 0c0h,040h,i_LD ;ld r[y],r[z]
3067 db a_rr
3068
3069 db 0c0h,080h,i_ADD+080h ;add a,r[z]
3070 db a_r
3071
3072 ; db 0f8h,080h,i_ADD ;add a,r[z]
3073 ; db a_ar
3074 ; db 0f8h,088h,i_ADC ;adc a,r[z]
3075 ; db a_ar
3076 ; db 0f8h,090h,i_SUB ;sub r[z]
3077 ; db a_r
3078 ; db 0f8h,098h,i_SBC ;sbc a,r[z]
3079 ; db a_ar
3080 ; db 0f8h,0a0h,i_AND ;and r[z]
3081 ; db a_r
3082 ; db 0f8h,0a8h,i_XOR ;xor r[z]
3083 ; db a_r
3084 ; db 0f8h,0b0h,i_OR ;or r[z]
3085 ; db a_r
3086 ; db 0f8h,0b8h,i_CP ;cp r[z]
3087 ; db a_r
3088
3089 db 0c7h,0c0h,i_RET ;ret cc
3090 db a_cc
3091 db 0c7h,0c7h,i_RST ;rst
3092 db a_rst
3093 db 0cfh,0c1h,i_POP ;pop rp2
3094 db a_p2
3095 db 0cfh,0c5h,i_PUSH ;push rp2
3096 db a_p2
3097 db 0ffh,0e3h,i_EX ;ex (sp),hl
3098 db a_esphl
3099 db 0ffh,0e9h,i_JP ;jp (hl)
3100 db a_hl
3101 db 0ffh,0ebh,i_EX ;ex de,hl
3102 db a_dehl
3103 db 0ffh,0f9h,i_LD ;ld sp,hl
3104 db a_lsphl
3105 db 0cfh,003h,i_INC ;inc rp
3106 db a_p
3107 db 0cfh,00bh,i_DEC ;dec rp
3108 db a_p
3109 db 0c7h,004h,i_INC ;inc r[y]
3110 db a_ry
3111 db 0c7h,005h,i_DEC ;dec r[y]
3112 db a_ry
3113 db 0ffh,008h,i_EX ;ex af,af'
3114 db a_eaf
3115 db 0cfh,009h,i_ADD ;add hl,rp
3116 db a_hlp
3117 db 0efh,002h,i_LD ;ld (rp),a ;rp=bc,de
3118 db a_pa
3119 db 0efh,00ah,i_LD ;ld a,(rp) ;rp=bc,de
3120 db a_ap
3121
3122 db 0c7h,007h,i_RLCA+080h;rlca
3123 db a_noarg
3124
3125 db 0
3126
3127 ; 2 byte opcodes
3128 b_1b54_start:
3129 db 0c7h,006h,i_LD ;ld r[y],nn
3130 db a_rn
3131
3132 db 0c7h,0c6h,i_ADD+080h ;add a,r[z]
3133 db a_n
3134
3135 ; db 0ffh,0c6h,i_ADD ;add a,nn
3136 ; db a_an
3137 ; db 0ffh,0ceh,i_ADC ;adc a,nn
3138 ; db a_an
3139 ; db 0ffh,0d6h,i_SUB ;sub nn
3140 ; db a_n
3141 ; db 0ffh,0deh,i_SBC ;sbc a,nn
3142 ; db a_an
3143 ; db 0ffh,0e6h,i_AND ;and nn
3144 ; db a_n
3145 ; db 0ffh,0eeh,i_XOR ;xor nn
3146 ; db a_n
3147 ; db 0ffh,0f6h,i_OR ;or nn
3148 ; db a_n
3149 ; db 0ffh,0feh,i_CP ;cp nn
3150 ; db a_n
3151
3152 db 0ffh,010h,i_DJNZ ;djnz
3153 db a_j
3154 db 0ffh,018h,i_JR ;jr
3155 db a_j
3156 db 0e7h,020h,i_JR ;jr cc,
3157 db a_ccj
3158 db 0ffh,0d3h,i_OUT ;out (nn),a
3159 db a_ma
3160 db 0ffh,0dbh,i_IN ;in a,(nn)
3161 db a_am
3162 db 0
3163
3164 ; 3 byte opcodes
3165 b_1b9b_start:
3166 db 0c7h,0c2h,i_JP ;jp cc,mn
3167 db a_ccnn
3168 db 0c7h,0c4h,i_CALL ;call cc,mn
3169 db a_ccnn
3170 db 0cfh,001h,i_LD ;ld ww,mn
3171 db a_rnn
3172 db 0ffh,0c3h,i_JP ;jp mn
3173 db a_nn
3174 db 0ffh,0cdh,i_CALL ;call mn
3175 db a_nn
3176 db 0ffh,022h,i_LD ;ld (mn),hl
3177 db a_mmhl
3178 db 0ffh,02ah,i_LD ;ld hl,(mn)
3179 db a_hlmm
3180 db 0ffh,032h,i_LD ;ld (mn),a
3181 db a_mma
3182 db 0ffh,03ah,i_LD ;ld a,(mn)
3183 db a_amm
3184 db 0
3185
3186 ; Prefix ED + 1 byte opcode, no arguments
3187 ; Format: opcode, t_MNEMONICS index
3188 b_1bc9_start:
3189 db 044h,i_NEG ;neg
3190 db 045h,i_RETN ;retn
3191 db 04dh,i_RETI ;reti
3192 db 067h,i_RRD ;rrd
3193 db 06fh,i_RLD ;rld
3194 ; db 0a0h,i_LDI ;ldi
3195 ; db 0a1h,i_CPI ;cpi
3196 ; db 0a2h,i_INI ;ini
3197 ; db 0a3h,i_OUTI ;outi
3198 ; db 0a8h,i_LDD ;ldd
3199 ; db 0a9h,i_CPD ;cpd
3200 ; db 0aah,i_IND ;ind
3201 ; db 0abh,i_OUTD ;outd
3202 ; db 0b0h,i_LDIR ;ldir
3203 ; db 0b1h,i_CPIR ;cpir
3204 ; db 0b2h,i_INIR ;inir
3205 ; db 0b3h,i_OTIR ;otir
3206 ; db 0b8h,i_LDDR ;lddr
3207 ; db 0b9h,i_CPDR ;cpdr
3208 ; db 0bah,i_INDR ;indr
3209 ; db 0bbh,i_OTDR ;otdr
3210 db 08bh,i_OTDM ;otdm
3211 db 09bh,i_OTDMR ;otdmr
3212 db 083h,i_OTIM ;otim
3213 db 093h,i_OTIMR ;otimr
3214 db 076h,i_SLP ;slp
3215 db 0ffh ;<end mark>
3216
3217 b_1bf4_start:
3218 db 0e4h,0a0h,i_LDI
3219 db a_noarg
3220 db 0ffh,070h,i_IN ;in (c) ;
3221 db a_c
3222 db 0c7h,040h,i_IN ;in r,(c) ;r=b,c,d,e,h,l,a
3223 db a_rc
3224 db 0ffh,071h,0ffh ;out (c),0 ;
3225 db a_cr
3226 db 0c7h,041h,i_OUT ;out (c),r ;r=b,c,d,e,h,l,a
3227 db a_cr
3228 db 0cfh,042h,i_SBC ;sbc hl,rp
3229 db a_hlp
3230 db 0cfh,04ah,i_ADC ;adc hl,rp
3231 db a_hlp
3232 db 0ffh,046h,i_IM ;im 0
3233 db a_im0
3234 db 0ffh,056h,i_IM ;im 1
3235 db a_im1
3236 db 0ffh,05eh,i_IM ;im 2
3237 db a_im2
3238 db 0e7h,047h,i_LD ;ld i,a ... ld a,r
3239 db a_ai
3240 db 0cfh,04ch,i_MLT ;mlt rr
3241 db a_p
3242 db 0c7h,004h,i_TST ;tst r
3243 db a_ry
3244 db 0
3245
3246 l228bh:
3247 db 0ffh,030h,i_IN0 ;in0 (m)
3248 db a_m
3249 db 0c7h,000h,i_IN0 ;in0 r,(m) ;r=b,c,d,e,h,l,a
3250 db a_rm
3251 db 0ffh,031h,0ffh ;out0 (m),0
3252 db a_mr
3253 db 0c7h,001h,i_OUT0 ;out0 (m),r ;r=b,c,d,e
3254 db a_mr
3255 db 0ffh,064h,i_TST ;tst m
3256 db a_n
3257 db 0ffh,074h,i_TSTIO ;tstio m
3258 db a_n
3259 db 0
3260
3261 ; Prefix ED + 1 byte opcode + 2 byte address
3262 ; Format: db mask, match, t_MNEMONICS-index
3263 ; dw argument formating function
3264 b_1c40_start:
3265 db 0cfh,043h,i_LD ;ld (mn),ww ;ww=bc,de,hl,sp
3266 db a_mmp
3267 db 0cfh,04bh,i_LD ;ld ww,(mn) ;ww=bc,de,hl,sp
3268 db a_pmm
3269 db 0
3270
3271 ; CB
3272 b_1c55_start:
3273 db 0c0h,000h,i_RLC+080h ;rlc g
3274 db a_cbr
3275
3276 ; db 0f8h,000h,i_RLC ;rlc g
3277 ; db a_cbr
3278 ; db 0f8h,008h,i_RRC ;rrc g
3279 ; db a_cbr
3280 ; db 0f8h,010h,i_RL ;rl g
3281 ; db a_cbr
3282 ; db 0f8h,018h,i_RR ;rr g
3283 ; db a_cbr
3284 ; db 0f8h,020h,i_SLA ;sla g
3285 ; db a_cbr
3286 ; db 0f8h,028h,i_SRA ;sra g
3287 ; db a_cbr
3288 ; db 0f8h,038h,i_SRL ;srl g
3289 ; db a_cbr
3290 db 0c0h,040h,i_BIT ;bit b,g
3291 db a_bcbr
3292 db 0c0h,080h,i_RES ;res b,g
3293 db a_bcbr
3294 db 0c0h,0c0h,i_SET ;set b,g
3295 db a_bcbr
3296 db 0
3297
3298 ;-------------------------------------------------------------------------------
3299 ;-------------------------------------------------------------------------------
3300
3301
3302 pr_instr_args:
3303 ld hl,t_argf
3304 ld d,0
3305 add hl,de
3306 pria_l:
3307 ld a,(hl) ;get next token
3308 inc hl
3309 or a
3310 ret z ;
3311 jp m,pria_1
3312 call outchar ;print as normal character
3313 jr pria_l
3314
3315 pria_1: ;
3316 push hl
3317 ld hl,do_arg_n
3318 and 07fh
3319 call add_hl_a2
3320 ld a,(hl)
3321 inc hl
3322 ld h,(hl)
3323 ld l,a
3324 ld a,(iy+000h)
3325 call CALL_HL
3326 pop hl
3327 jr pria_l
3328
3329 ;
3330 ; http://www.z80.info/decoding.htm
3331 ;
3332 ; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
3333 ; | x | y | z |
3334 ; | p | q |
3335 ;
3336
3337 t_argf:
3338 ; 1 byte opcodes
3339 a_rr equ $-t_argf
3340 db fi_ry,',' ;ld r[y],r[z]
3341 a_r equ $-t_argf
3342 db fi_rz,0 ;op r[z]
3343 ;a_ar equ $-t_argf
3344 ; db 'A,',fi_rz,0 ;op A,r[z]
3345 a_cc equ $-t_argf
3346 db fi_ccy,0 ;op cc[y]
3347 a_rst equ $-t_argf
3348 db fi_rst,0 ;rst y*8
3349 a_p2 equ $-t_argf
3350 db fi_rp2,0 ;rp2[p]
3351 a_esphl equ $-t_argf
3352 db '(SP),',fi_hlixiy,0 ;ex (sp),hl
3353 a_hl equ $-t_argf
3354 db '(',fi_hlixiy,')',0 ;jp (hl)
3355 a_dehl equ $-t_argf
3356 db 'DE,HL',0
3357 a_lsphl equ $-t_argf
3358 db 'SP,',fi_hlixiy,0 ;ld SP,HL
3359 a_eaf equ $-t_argf
3360 db 'AF,AF''',0 ;ex af,af'
3361 a_hlp equ $-t_argf
3362 db fi_hlixiy,',' ;add hl,rp
3363 a_p equ $-t_argf
3364 db fi_rp,0 ;rp[p]
3365 a_pa equ $-t_argf
3366 db '(',fi_rp,'),A',0 ;ld (rp),a ;rp=bc,de
3367 a_ap equ $-t_argf
3368 db 'A,(',fi_rp,')',0 ;ld a,(rp) ;rp=bc,de
3369
3370 ; 2 byte opcodes
3371 a_rn equ $-t_argf
3372 db fi_ry,',',fi_n,0 ;ld r[y],n
3373 ;a_an equ $-t_argf
3374 ; db 'A,' ;op a,n
3375 a_n equ $-t_argf
3376 db fi_n,0 ;op n
3377 a_ccj equ $-t_argf
3378 db fi_ccy2,',' ;jr cc,j ;cc = nz,z,nc,c
3379 a_j equ $-t_argf
3380 db fi_j,0 ;jr j
3381 a_ma equ $-t_argf
3382 db '(',fi_n,'),A',0 ;out (n),a
3383 a_am equ $-t_argf
3384 db 'A,(',fi_n,')',0 ;in a,(n)
3385
3386 ; 3 byte opcodes
3387 a_ccnn equ $-t_argf
3388 db fi_ccy,',',fi_nn,0 ;op cc[y],nn
3389 a_rnn equ $-t_argf
3390 db fi_rp,',' ;ld rp[p],nn
3391 a_nn equ $-t_argf
3392 db fi_nn,0 ;jp nn
3393 a_mmhl equ $-t_argf
3394 db '(',fi_nn,'),',fi_hlixiy,0 ;ld (nn),hl
3395 a_hlmm equ $-t_argf
3396 db fi_hlixiy,',(',fi_nn,')',0 ;ld hl,(nn)
3397 a_mma equ $-t_argf
3398 db '(',fi_nn,'),A',0 ;ld (nn),a
3399 a_amm equ $-t_argf
3400 db 'A,(',fi_nn,')',0 ;ld a,(nn)
3401
3402 ; Prefix ED + 1 byte opcode
3403 a_rc equ $-t_argf
3404 db fi_ry,',' ;in r[y],(c)
3405 a_c equ $-t_argf
3406 db '(C)',0 ;in (c)
3407 a_cr equ $-t_argf
3408 db '(C),' ;out (c),r[y]
3409 a_ry equ $-t_argf
3410 db fi_ry,0 ;inc r[y]
3411 a_im0 equ $-t_argf
3412 db '0',0 ;im 0
3413 a_im1 equ $-t_argf
3414 db '1',0 ;im 1
3415 a_im2 equ $-t_argf
3416 db '2',0 ;im 2
3417 a_ai equ $-t_argf
3418 db fi_ir,0 ;ld a,i ... r,a
3419
3420 ; Prefix ED + 2 byte (opcode + immediate)
3421 a_rm equ $-t_argf
3422 db fi_ry,',' ;in0 r[y],(n)
3423 a_m equ $-t_argf
3424 db '(',fi_n,')',0 ;in0 (n)
3425 a_mr equ $-t_argf
3426 db '(',fi_n,'),',fi_ry,0 ;out0 (n),r[y]
3427
3428 ; Prefix ED + 3 byte (opcode + address)
3429 a_mmp equ $-t_argf
3430 db '(',fi_nn,'),',fi_rp,0 ;ld (nn),rp
3431 a_pmm equ $-t_argf
3432 db fi_rp,',(',fi_nn,')',0 ;ld rp,(nn)
3433
3434 ; Prefix CB + 1 byte opcode
3435 a_bcbr equ $-t_argf
3436 db fi_y,',' ;op y,r[z]
3437 a_cbr equ $-t_argf
3438 db fi_rz_cb,0 ;op r[z]
3439 a_noarg equ $-t_argf
3440 db 0
3441
3442
3443 ;-------------------------------------------------------------------------------
3444
3445 argpf_index defl 0
3446
3447 argpf macro x
3448 fi_&x equ 80h+argpf_index
3449 dw p_&x
3450 argpf_index defl argpf_index+1
3451 endm
3452
3453 do_arg_n:
3454 argpf ry
3455 argpf rz
3456 argpf ccy
3457 argpf ccy2
3458 argpf rst
3459 argpf rp
3460 argpf rp2
3461 argpf hlixiy
3462 argpf n
3463 argpf j
3464 argpf nn
3465 argpf ir
3466 argpf rz_cb
3467 argpf y
3468
3469
3470 p_n:
3471 ld a,(isprefix_ixiy)
3472 and a
3473 ld a,(iy+001h)
3474 jr z,out_hex_0
3475 ld a,(iy+002h)
3476 jr out_hex_0
3477
3478 p_rst:
3479 and 038h
3480 out_hex_0:
3481 jp out_hex
3482
3483
3484 p_j:
3485 ld c,(iy+001h)
3486 ld a,c
3487 rla
3488 sbc a,a
3489 ld b,a
3490 push iy
3491 pop hl
3492 add hl,bc
3493 inc hl
3494 inc hl
3495 jr out_hl_0
3496
3497 p_nn:
3498 ld l,(iy+001h)
3499 ld h,(iy+002h)
3500 out_hl_0:
3501 jp out_hl
3502
3503 p_ir:
3504 rra
3505 rra
3506 rra
3507 and 03
3508 ld hl,t_arg_IR
3509 jr p_arg
3510
3511
3512 get_cb_opc:
3513 ld a,(isprefix_ixiy)
3514 and a
3515 ld a,(iy+001h)
3516 ret z
3517 ld a,(iy+002h)
3518 ret
3519
3520 p_y:
3521 call get_cb_opc
3522 rra
3523 rra
3524 rra
3525 and 007h
3526 jp out_dgt
3527
3528 p_rz_cb:
3529 call get_cb_opc
3530 jr p_rz
3531
3532 p_ry:
3533 rra
3534 rra
3535 rra
3536 p_rz:
3537 and 007h
3538 cp 006h
3539 ld b,a
3540 ld hl,t_arg_r
3541 jr nz,p_arg0
3542 ld a,(isprefix_ixiy)
3543 and a
3544 jr z,p_arg0
3545 ld hl,t_lp_IXIY
3546 dec a
3547 call p_arg
3548 ld a,(iy+001h)
3549 push af
3550 rlca
3551 ld a,'+'
3552 jr nc,l1e61h
3553 pop af
3554 neg
3555 push af
3556 ld a,'-'
3557 l1e61h:
3558 call outchar
3559 pop af
3560 call out_hex
3561 ld a,')'
3562 jp outchar
3563
3564 p_rp2:
3565 ld hl,t_arg_rp2
3566 db 0ddh ;swallow t_arg_rp in ix
3567 p_rp:
3568 ld hl,t_arg_rp
3569 rra
3570 rra
3571 rra
3572 rra
3573 and 003h
3574 cp 002h
3575 jr nz,p_arg
3576 p_hlixiy:
3577 ld a,(isprefix_ixiy)
3578 ld hl,t_HL.IX.IY
3579 jr p_arg
3580
3581 p_ccy2:
3582 and 018h
3583 p_ccy:
3584 rra
3585 rra
3586 rra
3587 and 007h
3588 ld hl,t_arg_cc
3589 p_arg:
3590 ld b,a
3591 p_arg0:
3592 ;fall thru
3593
3594 pstr_sel:
3595 call str_sel
3596 ;fall thru
3597 pstr:
3598 ld a,(hl)
3599 inc hl
3600 and a
3601 ret z
3602 call outchar
3603 ret m
3604 jr pstr
3605
3606 pstr_inl:
3607 ex (sp),hl
3608 call pstr
3609 ex (sp),hl
3610 ret
3611
3612 ;-------------------------------------------------------------------------------
3613
3614 opc macro x
3615
3616 i_&x equ opc_index
3617 ;o_&x equ $-opc_tabstart
3618 dc '&x'
3619 opc_index defl opc_index+1
3620 endm
3621
3622 t_MNEMONICS:
3623 ;opc_tabstart defl $
3624 opc_index defl 0
3625 ; 1-byte other
3626 opc NOP
3627 opc LD
3628 opc INC
3629 opc DEC
3630 opc DJNZ
3631 opc JR
3632 opc HALT
3633
3634 opc RLCA
3635 opc RRCA
3636 opc RLA
3637 opc RRA
3638 opc DAA
3639 opc CPL
3640 opc SCF
3641 opc CCF
3642
3643 ; 1-byte "alu"
3644 opc ADD
3645 opc ADC
3646 opc SUB
3647 opc SBC
3648 opc AND
3649 opc XOR
3650 opc OR
3651 opc CP
3652
3653 opc RET
3654 opc POP
3655 opc JP
3656 opc CALL
3657 opc PUSH
3658 opc RST
3659 opc OUT
3660 opc EXX
3661 opc IN
3662 opc EX
3663 opc DI
3664 opc EI
3665 ; CB
3666 opc RLC
3667 opc RRC
3668 opc RL
3669 opc RR
3670 opc SLA
3671 opc SRA
3672 opc SLL
3673 opc SRL
3674 opc BIT
3675 opc RES
3676 opc SET
3677
3678 ; ED
3679 opc NEG
3680 opc RETN
3681 opc RETI
3682 opc IM
3683 opc RRD
3684 opc RLD
3685
3686 ; Block instructions
3687 opc LDI
3688 opc CPI
3689 opc INI
3690 opc OUTI
3691 opc LDD
3692 opc CPD
3693 opc IND
3694 opc OUTD
3695 opc LDIR
3696 opc CPIR
3697 opc INIR
3698 opc OTIR
3699 opc LDDR
3700 opc CPDR
3701 opc INDR
3702 opc OTDR
3703
3704 ; Z180
3705 opc IN0
3706 opc OUT0
3707 opc TST
3708 opc MLT
3709 opc TSTIO
3710 opc SLP
3711 opc OTIM
3712 opc OTDM
3713 opc OTIMR
3714 opc OTDMR
3715
3716 DB 0
3717
3718 t_arg_r:
3719 DC 'B'
3720 DC 'C'
3721 DC 'D'
3722 DC 'E'
3723 DC 'H'
3724 DC 'L'
3725 DC '(HL)'
3726 DC 'A'
3727 DB 0
3728 t_arg_rp:
3729 DC 'BC'
3730 DC 'DE'
3731 DC 'HL'
3732 DC 'SP'
3733 DB 0
3734 t_arg_rp2:
3735 DC 'BC'
3736 DC 'DE'
3737 DC 'HL'
3738 DC 'AF'
3739 DB 0
3740 t_HL.IX.IY:
3741 DC 'HL'
3742 DC 'IX'
3743 DC 'IY'
3744 DB 0
3745 t_arg_cc:
3746 DC 'NZ'
3747 DC 'Z'
3748 DC 'NC'
3749 DC 'C'
3750 DC 'PO'
3751 DC 'PE'
3752 DC 'P'
3753 DC 'M'
3754 DB 0
3755
3756 t_lp_IXIY:
3757 DC '(IX'
3758 DC '(IY'
3759
3760 t_arg_IR:
3761 DC 'I,A'
3762 DC 'R,A'
3763 DC 'A,I'
3764 DC 'A,R'
3765 db 0
3766
3767 ;-------------------------------------------------------------------------------
3768
3769 lookup_branch_op:
3770 ld a,(hl)
3771 and a
3772 ret z
3773 inc hl
3774 and (iy+000h)
3775 cp (hl)
3776 inc hl
3777 ld e,(hl)
3778 inc hl
3779 ld d,(hl)
3780 inc hl
3781 jr nz,lookup_branch_op
3782 scf
3783 ret
3784
3785 ;-------------------------------------------------------------------------------
3786
3787 tc_set_bp:
3788 ld hl,(reg.pc)
3789 ld a,h
3790 or l
3791 jr z,l2037h
3792 ld de,BDOS
3793 and a
3794 sbc hl,de
3795 ld hl,l20edh ;set break after BDOS call
3796 jr z,l2031h
3797 ld iy,(reg.pc)
3798 call disas_get_instrlen
3799 jp nc,ERROR
3800 ld c,b
3801 ld b,0
3802 ld hl,(reg.pc)
3803 add hl,bc
3804 call bp_trace_enter
3805 ld iy,(reg.pc)
3806 ld hl,t_op_branch
3807 call lookup_branch_op
3808 ccf
3809 ret c
3810 ex de,hl
3811 l2031h:
3812 call CALL_HL
3813 call c,bp_trace_enter
3814 l2037h:
3815 scf
3816 ret
3817
3818 ;-------------------------------------------------------------------------------
3819
3820 t_op_branch:
3821 db 0ffh,0ddh ;Prefix DD
3822 dw l20a7h
3823 db 0ffh,0fdh ;Prefix FD
3824 dw l20ach
3825 db 0ffh,0edh ;Prefix ED
3826 dw l20b8h
3827
3828 db 0ffh,0cdh ;call mn
3829 dw l2080h
3830 db 0ffh,0c3h ;jp mn
3831 dw l208bh
3832 db 0ffh,0e9h ;jp ()
3833 dw l20a2h
3834 db 0ffh,0c9h ;ret
3835 dw l20dch
3836 db 0ffh,0cfh ;rst 8
3837 dw l2115h
3838 db 0c7h,0c7h ;rst n
3839 dw l20f9h
3840 db 0c7h,0c4h ;call cc,mn
3841 dw l2080h
3842 db 0f7h,010h ;djnz d; jr d
3843 dw l2093h
3844 db 0e7h,020h ;jr cc,d
3845 dw l2093h
3846 db 0c7h,0c2h ;jp cc,mn
3847 dw l208bh
3848 db 0c7h,0c0h ;ret cc
3849 dw l20c5h
3850 db 0
3851
3852 ;-------------------------------------------------------------------------------
3853 ; call mn call cc,mn
3854 l2080h:
3855
3856 ; jp mn jp cc,mn
3857 l208bh:
3858 ld l,(iy+001h)
3859 ld h,(iy+002h)
3860 scf
3861 ret
3862
3863 ;jr, djnz
3864 l2093h:
3865 ld c,(iy+001h)
3866 ld a,c
3867 rla
3868 sbc a,a
3869 ld b,a
3870 ld hl,(reg.pc)
3871 add hl,bc
3872 inc hl
3873 inc hl
3874 scf
3875 ret
3876
3877 ; jp (hl)
3878 l20a2h:
3879 ld hl,(reg.l)
3880 scf
3881 ret
3882
3883 ; Prefix DD
3884 l20a7h:
3885 ld hl,(reg.ix)
3886 jr l20afh
3887 ; Prefix FD
3888 l20ach:
3889 ld hl,(reg.iy)
3890 l20afh:
3891 ld a,(iy+001h)
3892 cp 0e9h ; jp (ix); jp (iy)
3893 scf
3894 ret z
3895 and a
3896 ret
3897
3898 ; Prefix ED
3899 l20b8h:
3900 ld a,(iy+001h)
3901 cp 04dh ; reti
3902 jr z,l20dch
3903 cp 045h ; retn
3904 jr z,l20dch
3905 and a
3906 ret
3907
3908 ;ret cc
3909 l20c5h:
3910 ld a,(iy+000h)
3911 ld (l20d7h),a
3912 ld hl,(reg.f)
3913 push hl
3914 pop af
3915 call l20d7h
3916 scf
3917 jr c,l20dch
3918 ret
3919 l20d7h:
3920 nop
3921 and a
3922 pop hl
3923 inc hl
3924 jp (hl)
3925
3926 ;ret
3927 l20dch:
3928 l20edh:
3929 ld hl,(reg_sp) ;break on return address
3930 ld e,(hl)
3931 inc hl
3932 ld d,(hl)
3933 ex de,hl
3934 call bp_trace_enter
3935 ;rst 8
3936 l2115h:
3937 and a
3938 ret
3939
3940 ;rst n
3941 l20f9h:
3942 ld a,(l0003h)
3943 cp (iy+000h)
3944 ret z
3945 ld a,(iy+000h)
3946 and 038h
3947 ld l,a
3948 ld h,000h
3949 scf
3950 ret
3951
3952 ;-------------------------------------------------------------------------------
3953 ; >>C[N][J] [steps]
3954 ; >>C[N][J] W expression
3955 ; >>C[N][J] U expression
3956 ; trace over Calls [No list] [Jumps only] /.While./.Until.
3957
3958
3959 ;-------------------------------------------------------------------------------
3960 ; >>T[N][J] [steps]
3961 ; >>T[N][J] W expression
3962 ; >>T[N][J] U expression
3963 ; Trace [no List] [Jumps only] / .While. / .Until.
3964
3965 cmd_T:
3966 ld (cmd_rpt),hl
3967 ld hl,1 ;default: 1 step
3968 call get_lastarg_def
3969 ld (trace_cnt_or_ptr),hl
3970 call tc_set_bp
3971 jr user_go1
3972
3973 l2151h:
3974 call bp_clr_temporary
3975 ld hl,(trace_cnt_or_ptr)
3976 dec hl
3977 ld (trace_cnt_or_ptr),hl
3978 ld a,h
3979 or l
3980 jp z,do_break
3981
3982 call tc_set_bp
3983 jp nc,do_break
3984 call p_cpustat
3985 user_go1:
3986 jp user_go
3987
3988 ;-------------------------------------------------------------------------------
3989
3990 con_col:
3991 db 0
3992
3993 ;-------------------------------------------------------------------------------
3994
3995 b_21e2_start:
3996 db 0
3997 trace_cnt_or_ptr:
3998 dw 0
3999 bp_tab:
4000 rept BP_CNT
4001 rept BP_SIZE
4002 db 0
4003 endm
4004 endm
4005
4006 ;-------------------------------------------------------------------------------
4007
4008 last_S:
4009 dw TPA
4010
4011 last_I:
4012 dw 0
4013
4014 last_O_addr:
4015 dw 0
4016 last_O_val:
4017 db 0
4018
4019 last_D:
4020 dw TPA
4021
4022 high_load:
4023 dw TPA
4024 max_load:
4025 dw TPA
4026
4027 isprefix_ixiy:
4028 db 0
4029 last_L:
4030 dw TPA
4031
4032 pbl_loop_adr:
4033 dw 0addeh
4034
4035 bitmap_end:
4036 dw 0
4037
4038 ;-------------------------------------------------------------------------------
4039
4040 conbuf:
4041 ds CONBUF_SIZE+1
4042
4043 ;-------------------------------------------------------------------------------
4044
4045 rept (STACK_SIZE+3)/4
4046 db 0deh,0adh,0beh,0efh
4047 endm
4048 stack:
4049 reg.l2: db 000h
4050 reg.h2: db 000h
4051 reg.e2: db 000h
4052 reg.d2: db 000h
4053 reg.c2: db 000h
4054 reg.b2: db 000h
4055 reg.f2: db 000h
4056 reg.a2: db 000h
4057 db 000h
4058 reg.i: db 000h
4059 reg.iy: dw 0000h
4060 reg.ix: dw 0000h
4061 reg.f: db 000h
4062 reg.a: db 000h
4063 reg.c: db 000h
4064 reg.b: db 000h
4065 reg.e: db 000h
4066 reg.d: db 000h
4067 reg.l: db 000h
4068 reg.h: db 000h
4069 reg_sp: dw TPA
4070 reg.iff:
4071 db 0f3h
4072 db 0c3h
4073 reg.pc: dw TPA
4074
4075 cmd_rpt:dw mainloop
4076 db 0ffh,0ffh,0ffh
4077 ;-------------------------------------------------------------------------------
4078
4079 ddtz_size equ $-ddtz_base
4080 prog_size equ $-start
4081 ddtz_end:
4082
4083 ;-------------------------------------------------------------------------------
4084
4085 end