]> cloudbase.mooo.com Git - ddt180.git/blob - ddt180.z80
fd160766604e2b28dd78be3e3dc79eb9b95b316a
[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 bc,(028h-2)
86 ld de,(028h)
87 ld a,i ;get iff2
88 ex af,af'
89 di
90 ld sp,028h ;rst instr needs a minimal stack
91 ld hl,0e9e1h ;opcpdes pop hl/jp (hl)
92 ld (028h),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-'@'
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 and a
1311 bit 0,c
1312 ret nz
1313 ld h,000h
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 sub a
1666 ld (bp_p_cpu_flag),a
1667 call expr
1668 jr c,l0740h
1669 ld (reg.pc),hl
1670 l0740h:
1671 call skipbl
1672 jr z,user_go0
1673 cp ';'
1674 jp nz,ERROR
1675 inc de
1676 ld a,002h
1677 call bp_enter
1678 user_go0:
1679 jp user_go
1680
1681 ;-------------------------------------------------------------------------------
1682
1683 bpl_init:
1684 ld b,BP_CNT
1685 ld ix,bp_tab
1686 ex (sp),hl
1687 ld (pbl_loop_adr),hl
1688 ex (sp),hl
1689 ret
1690
1691 bpl_next:
1692 ld de,BP_SIZE
1693 push af
1694 add ix,de
1695 pop af
1696 dec b
1697 ret z
1698
1699 ex (sp),hl
1700 ld hl,(pbl_loop_adr)
1701 ex (sp),hl
1702 ret
1703
1704 bp_clr_temporary:
1705 call bpl_init
1706
1707 ld a,(ix+000h)
1708 and 0f1h
1709 ld (ix+000h),a
1710
1711 call bpl_next
1712 ret
1713
1714 ;-------------------------------------------------------------------------------
1715 ; > B
1716 ; display all breakpoints
1717 ; > B breakp [breakp..]
1718 ; set breakpoints
1719 ; > BX
1720 ; clear all breakpoints
1721 ; > BX breakp [breakp..]
1722 ; clear breakpoints
1723 ;
1724 ; breakp can be any valid expression
1725
1726 cmd_B:
1727 call skipbl
1728 jr z,bp_print
1729 inc de
1730 cp 'X'
1731 jr z,bp_clr0
1732 dec de
1733 ld a,001h
1734 jp bp_enter
1735
1736 bp_clr0:
1737 call skipbl
1738 jr z,bp_clr_all
1739 bp_clr_next:
1740 call expr
1741 jp c,assert_eol
1742 push de
1743 call bp_clr
1744 pop de
1745 call next_arg
1746 jr bp_clr_next
1747
1748 bp_clr_all:
1749 scf
1750 bp_clr:
1751 call bpl_init
1752
1753 push af
1754 jr c,l07a7h
1755 ld e,(ix+002h)
1756 ld d,(ix+003h)
1757 call cp_hl_de
1758 jr nz,l07aeh
1759 l07a7h:
1760 ld (ix+000h),000h
1761 l07aeh:
1762 pop af
1763 call bpl_next
1764 ret
1765
1766 bp_print:
1767 ld c,0
1768 call bpl_init
1769
1770 bit 0,(ix+000h)
1771 jr z,bp_pr_cont
1772 ld l,(ix+002h)
1773 ld h,(ix+003h)
1774 call out_hl
1775 call outbl2
1776 inc c
1777 bp_pr_cont:
1778 call bpl_next
1779 ld a,c
1780 or a
1781 call nz,crlf
1782 ret
1783
1784 ;-------------------------------------------------------------------------------
1785 ; Add break points to list
1786 ; A = 1 Permanent (B command)
1787 ; A = 2 Temporary (G command)
1788
1789 bp_enter:
1790 ld b,a
1791 call skipbl
1792 ret z
1793
1794 push bc
1795 call expr
1796 jr c,error12
1797 pop bc
1798 bit 0,b
1799 push bc
1800 push de
1801 push hl
1802 call nz,bp_clr
1803 pop hl
1804 call bp_get_freeslot
1805 pop de
1806 ld (ix+002h),l
1807 ld (ix+003h),h
1808 call next_arg
1809 pop af
1810 ld (ix+000h),a
1811 and 00fh
1812 jr bp_enter
1813
1814 bp_get_freeslot:
1815 call bpl_init
1816
1817 ld a,(ix+000h)
1818 and 00fh
1819 ret z
1820
1821 call bpl_next
1822 error12
1823 jp ERROR
1824
1825
1826 ;-------------------------------------------------------------------------------
1827 ; Breakpoint handling routine.
1828
1829 bpddtz:
1830 ld (reg.l),hl
1831 pop hl
1832 dec hl
1833 ld (reg.pc),hl
1834 ld (reg_sp),sp
1835 ld sp,reg.l
1836 push de
1837 push bc
1838 push af
1839 push ix
1840 push iy
1841 ld a,i
1842 call di_or_ei
1843 ld h,a
1844 ld l,000h
1845 push hl
1846 ld a,0f3h ; EI
1847 jp po,l08dfh
1848 ld a,0fbh ; DI
1849 l08dfh:
1850 ld (reg.iff),a
1851 ex af,af'
1852 push af
1853 exx
1854 push bc
1855 push de
1856 push hl
1857 call bp_restore_mem
1858 ld a,(b_21e2_start)
1859 dec a
1860 jr z,l090bh
1861 call inchar ;Keyboard hit?
1862 jr c,do_break ;yes
1863 call sub_0913h
1864 and a
1865 jp z,user_go
1866 and 083h
1867 jp z,l2151h
1868 do_break:
1869 call bp_clr_temporary
1870 call p_cpustat
1871 jp mainloop
1872
1873 l090bh:
1874 ld (b_21e2_start),a
1875 ld c,007h
1876 jp l0a41h
1877
1878 sub_0913h:
1879 ld a,080h
1880 ex af,af'
1881 sub a
1882 ld (bp_p_cpu_flag),a
1883 call bpl_init
1884
1885 ld a,(ix+000h)
1886 and 007h
1887 jr z,l0938h
1888 ld e,(ix+002h)
1889 ld d,(ix+003h)
1890 ld hl,(reg.pc)
1891 call cp_hl_de
1892 jr nz,l0938h
1893 ex af,af'
1894 res 7,a
1895 or (ix+000h)
1896 ex af,af'
1897 l0938h:
1898 call bpl_next
1899 ex af,af'
1900 ret
1901
1902 bp_restore_mem:
1903 call bpl_init
1904
1905 bit 5,(ix+000h)
1906 res 5,(ix+000h)
1907 jr z,l099ah
1908 ld l,(ix+002h)
1909 ld h,(ix+003h)
1910 ld a,(l0003h)
1911 cp (hl)
1912 jr nz,l099ah
1913 ld a,(ix+001h)
1914 ld (hl),a
1915 l099ah:
1916 res 3,(ix+000h)
1917
1918 call bpl_next
1919 ret
1920
1921 bp_tst_@pc:
1922 call bpl_init
1923
1924 ld a,(ix+000h)
1925 and 003h
1926 jr z,bp_tst_e
1927 ld e,(ix+002h)
1928 ld d,(ix+003h)
1929 ld hl,(reg.pc)
1930 call cp_hl_de
1931 ret z
1932 bp_tst_e:
1933 call bpl_next
1934 sub a
1935 inc a
1936 ret
1937
1938 bp_trace_enter:
1939 call bp_get_freeslot
1940 ld (ix+002h),l
1941 ld (ix+003h),h
1942 ld a,(b_21e2_start)
1943 and a
1944 ld a,008h
1945 jr nz,bp_t_e
1946 rra
1947 bp_t_e:
1948 ld (ix+000h),a
1949 ret
1950
1951 bp_set_to_mem:
1952 call bpl_init
1953
1954 ld a,(ix+000h)
1955 and c
1956 jr z,l0a1dh
1957 set 5,(ix+000h)
1958 ld l,(ix+002h)
1959 ld h,(ix+003h)
1960 ld a,(hl)
1961 ld (ix+001h),a
1962 ld a,(l0003h)
1963 ld (hl),a
1964 and 038h
1965 ld h,000h
1966 ld l,a
1967 ld (hl),0c3h
1968 inc hl
1969 ld de,bpddtz
1970 ld (hl),e
1971 inc hl
1972 ld (hl),d
1973 l0a1dh:
1974
1975 call bpl_next
1976 ret
1977
1978 ;-------------------------------------------------------------------------------
1979
1980 user_go:
1981 sub a
1982 ld (b_21e2_start),a
1983 ld a,(bp_p_cpu_flag)
1984 and a
1985 call nz,p_cpustat
1986 call bp_tst_@pc
1987 ld c,007h
1988 jr nz,l0a41h
1989 ld a,001h
1990 ld (b_21e2_start),a
1991 call tc_set_bp
1992 ld c,008h
1993 l0a41h:
1994 call bp_set_to_mem
1995 ld sp,reg.l2
1996 pop hl
1997 pop de
1998 pop bc
1999 pop af
2000 exx
2001 ex af,af'
2002 pop af
2003 ld i,a
2004 pop iy
2005 pop ix
2006 pop af
2007 pop bc
2008 pop de
2009 pop hl
2010 ld sp,(reg_sp)
2011 jp reg.iff
2012
2013 ;-------------------------------------------------------------------------------
2014 ; > Y
2015 ; examine all Y variables
2016 ; > Y[0..9]
2017 ; examine (and substitute) an Y variable
2018
2019
2020 ;-------------------------------------------------------------------------------
2021 ; > X
2022 ; eXamine (display) all cpu registers and
2023 ; the instruction at the current program counter
2024 ; > X register
2025 ; eXamine (and substitute) a register
2026
2027
2028 cmd_X:
2029 call skipbl
2030 call sub_0caeh
2031 jp nc,p_cpustat0
2032 call assert_eol
2033 ld a,b
2034 cp 25
2035 jr z,l0c5fh
2036 cp 26
2037 jr z,l0c4fh
2038 ex de,hl
2039 ld hl,t_reg_names
2040 call pstr_sel
2041 call l0c33h
2042
2043 call outbl
2044 push de
2045 push bc
2046 call get_line
2047 call skipbl
2048 jr z,l0c30h
2049 call get_arg_final
2050 ex de,hl
2051 pop bc
2052 pop hl
2053 ld (hl),e
2054 bit 0,c
2055 ret z
2056 inc hl
2057 ld (hl),d
2058 ret
2059 l0c30h:
2060 pop af
2061 pop hl
2062 ret
2063
2064 l0c33h:
2065 call pstr_inl
2066 dc '='
2067 ld a,(de)
2068 bit 0,c
2069 jp z,out_hex
2070 ld l,a
2071 inc de
2072 ld a,(de)
2073 dec de
2074 ld h,a
2075 jp out_hl
2076
2077 l0c4fh:
2078 call p_f
2079 ld a,0f3h
2080 ld (reg.iff),a
2081 scf
2082 call sub_0c6ah
2083 ld (reg.f),a
2084 ret
2085 l0c5fh:
2086 call p_f2
2087 and a
2088 call sub_0c6ah
2089 ld (reg.f2),a
2090 ret
2091
2092 sub_0c6ah:
2093 push af
2094 call outbl
2095 call assert_eol
2096 call get_line
2097 pop af
2098 ex af,af'
2099 ld b,0
2100 l0c76h:
2101 call skipbl
2102 ld a,b
2103 ret z
2104 push bc
2105 ld hl,t_flag_names
2106 call lookupch
2107 jp nc,ERROR
2108 inc b
2109 xor a
2110 scf
2111 nxt_f:
2112 rla
2113 djnz nxt_f
2114 pop bc
2115 jr c,l0c97h
2116 or b
2117 ld b,a
2118 jr l0c76h
2119
2120 l0c97h:
2121 ex af,af'
2122 jp nc,ERROR
2123 ex af,af'
2124 ld a,0fbh
2125 ld (reg.iff),a
2126 jr l0c76h
2127
2128 t_flag_names:
2129 db 'CNV H ZSE',0
2130
2131 sub_0caeh:
2132 call sub_0303h
2133 ret nc
2134 ld a,b
2135 add a,b
2136 add a,b
2137 ld hl,b_0cfa_start
2138 call add_hl_a
2139 ld c,(hl)
2140 inc hl
2141 ld a,(hl)
2142 inc hl
2143 ld h,(hl)
2144 ld l,a
2145 scf
2146 ret
2147
2148 t_reg_names:
2149 DC 'BC''' ;0
2150 DC 'DE''' ;1
2151 DC 'HL''' ;2
2152 DC 'BC' ;3
2153 DC 'DE' ;4
2154 DC 'HL' ;5
2155 DC 'A''' ;6
2156 DC 'B''' ;7
2157 DC 'C''' ;8
2158 DC 'D''' ;9
2159 DC 'E''' ;10
2160 DC 'H''' ;11
2161 DC 'L''' ;12
2162 DC 'A' ;13
2163 DC 'B' ;14
2164 DC 'C' ;15
2165 DC 'D' ;16
2166 DC 'E' ;17
2167 DC 'H' ;18
2168 DC 'L' ;19
2169 DC 'IX' ;20
2170 DC 'IY' ;21
2171 DC 'SP' ;22
2172 DC 'PC' ;23
2173 DC 'I' ;24
2174 DC 'F''' ;25
2175 DC 'F' ;26
2176 DB 0
2177
2178 b_0cfa_start:
2179 db 003h
2180 dw reg.c2
2181 db 003h
2182 dw reg.e2
2183 db 003h
2184 dw reg.l2
2185 db 003h
2186 dw reg.c
2187 db 003h
2188 dw reg.e
2189 db 003h
2190 dw reg.l
2191 db 000h
2192 dw reg.a2
2193 db 000h
2194 dw reg.b2
2195 db 000h
2196 dw reg.c2
2197 db 000h
2198 dw reg.d2
2199 db 000h
2200 dw reg.e2
2201 db 000h
2202 dw reg.h2
2203 db 000h
2204 dw reg.l2
2205 db 000h
2206 dw reg.a
2207 db 000h
2208 dw reg.b
2209 db 000h
2210 dw reg.c
2211 db 000h
2212 dw reg.d
2213 db 000h
2214 dw reg.e
2215 db 000h
2216 dw reg.h
2217 db 000h
2218 dw reg.l
2219 db 003h
2220 dw reg.ix
2221 db 003h
2222 dw reg.iy
2223 db 003h
2224 dw reg_sp
2225 db 003h
2226 dw reg.pc
2227 db 000h
2228 dw reg.i
2229 db 000h
2230 dw reg.f2
2231 db 000h
2232 dw reg.f
2233
2234 ;-------------------------------------------------------------------------------
2235 ; > S [startaddr]
2236 ; Substitute memory
2237
2238 cmd_S:
2239 ld hl,(last_S)
2240 call get_lastarg_def
2241 l0d60h:
2242 ld (last_S),hl
2243 call out_hl
2244 call outbl
2245 ld a,(hl)
2246 call out_hex
2247 call outbl2
2248 call get_line
2249 call skipbl
2250 inc hl
2251 jr z,l0d60h
2252 dec hl
2253 inc de
2254 cp '.'
2255 jr nz,cmds_dash
2256 call get_char_upper
2257 or a
2258 jr nz,l0d8ah
2259 ret
2260 cmds_dash:
2261 jp z,assert_eol
2262 cp '-'
2263 jr nz,l0d8ah
2264 call get_char_upper
2265 or a
2266 dec hl
2267 jr z,l0d60h
2268 inc hl
2269 l0d8ah:
2270 dec de
2271 call sub_0ef8h
2272 jr l0d60h
2273
2274 ;-------------------------------------------------------------------------------
2275 ; > @
2276 ; examine (substitute) displacement register @
2277
2278 ;cmd_@:
2279
2280 ;-------------------------------------------------------------------------------
2281 ; >>I [port]
2282 ; Input a byte from port
2283
2284 cmd_I:
2285 ld (cmd_rpt),hl
2286 ld hl,(last_I)
2287 call get_lastarg_def
2288 ld (last_I),hl
2289 ld b,h
2290 ld c,l
2291 in a,(c)
2292 push af
2293 call out_hex
2294 call outbl4
2295 pop af
2296 call out.bin.b
2297 jp crlf
2298
2299 ;-------------------------------------------------------------------------------
2300 ; >>O [byte] [port]
2301 ; Output a byte to a port
2302
2303 cmd_O:
2304 ld (cmd_rpt),hl
2305 ld hl,(last_O_val)
2306 call get_arg_def
2307 ld a,l
2308 ld (last_O_val),a
2309 push af
2310 call next_arg
2311 ld hl,(last_O_addr)
2312 call get_lastarg_def
2313 ld (last_O_addr),hl
2314 ld b,h
2315 ld c,l
2316 pop af
2317 out (c),a
2318 ret
2319
2320 ;-------------------------------------------------------------------------------
2321 ; > V startaddr endaddr targetaddr
2322 ; Verify (compare) two memory areas
2323
2324 cmd_V:
2325 call get_arg_range_target
2326 l0dedh:
2327 push bc
2328 ld a,(de)
2329 ld b,(hl)
2330 cp b
2331 jr z,l0e10h
2332 ld c,a
2333 call out_hl
2334 call outbl
2335 ld a,b
2336 call out_hex
2337 call outbl2
2338 ld a,c
2339 call out_hex
2340 call outbl
2341 ex de,hl
2342 call out_hl
2343 ex de,hl
2344 call crlf
2345 l0e10h:
2346 pop bc
2347 inc de
2348 cpi
2349 jp pe,l0dedh
2350 ret
2351
2352 ;-------------------------------------------------------------------------------
2353 ; > M startaddr endaddr destaddr
2354 ; Move memory
2355
2356 cmd_M:
2357 call get_arg_range_target
2358 call cp_hl_de
2359 jr nc,cmdm_up
2360 add hl,bc
2361 ex de,hl
2362 add hl,bc
2363 ex de,hl
2364 dec hl
2365 dec de
2366 lddr
2367 ret
2368 cmdm_up:
2369 ldir
2370 ret
2371
2372 ;-------------------------------------------------------------------------------
2373 ; > H
2374 ; display Highest load address of last filed loaded, Maximum "High"
2375 ; off all loaded files, and Top address of available memory
2376 ; > H expression
2377 ; evaluate expression and display result in hex, decimal and other formats
2378
2379 cmd_H:
2380 call expr
2381 jp c,p_max_high0
2382 call assert_eol
2383 call out_hl
2384 call outbl2
2385 call out_hl_neg
2386 call outbl4
2387 call out.hl.dec
2388 call outbl2
2389 call out_hl_dec_neg
2390 call outbl4
2391 call out.bin.w
2392 call outbl2
2393 ld a,l
2394 call out.ascii
2395 jp crlf
2396
2397 ;-------------------------------------------------------------------------------
2398 ; > Q[J] startaddr endaddr bytes
2399 ; Query memory for a byte string [Justified]
2400
2401 cmd_Q:
2402 call get_arg_range
2403 push bc
2404 push hl
2405 call sub_0ee6h
2406 pop hl
2407 l0e96h:
2408 push hl
2409 push de
2410 push bc
2411 l0edah:
2412 ld a,(de)
2413 cp (hl)
2414 jr nz,l0ee2h
2415 inc de
2416 inc hl
2417 djnz l0edah
2418 l0ee2h:
2419 pop bc
2420 pop de
2421 pop hl
2422 jr nz,l0eb0h
2423 push bc
2424 ld bc,16
2425 and a ;clear carry
2426 call sub_0f58h
2427 pop bc
2428 l0eb0h:
2429 inc hl
2430 ex (sp),hl
2431 dec hl
2432 ld a,h
2433 or l
2434 ex (sp),hl
2435 jr nz,l0e96h
2436 pop bc
2437 ret
2438
2439 ;-------------------------------------------------------------------------------
2440 ; > Z startaddr endaddr bytes
2441 ; Zap (fill) memory with a byte string
2442
2443 cmd_Z:
2444 call get_arg_range
2445 push bc
2446 push hl
2447 call sub_0ee6h
2448 ld a,b
2449 pop hl
2450 pop bc
2451 push hl
2452 ex de,hl
2453 l0ec7h:
2454 ldi
2455 jp po,l0ed3h
2456 dec a
2457 jr nz,l0ec7h
2458 pop hl
2459 ldir
2460 ret
2461 l0ed3h:
2462 pop hl
2463 ret
2464
2465 sub_0ee6h:
2466 ld hl,conbuf
2467 call sub_0ef7h
2468 ld de,conbuf
2469 and a
2470 sbc hl,de
2471 ld b,l
2472 ret nz
2473 jp ERROR
2474
2475 sub_0ef7h: ;from cmd_Q, cmd_Z
2476 db 0e6h ;and 037h (clear carry)
2477 sub_0ef8h: ;from cmd_S
2478 scf
2479 l0ef9h:
2480 push af
2481 call next_arg
2482 cp ''''
2483 jr z,l0f1eh
2484 push hl
2485 call expr
2486 ld a,l
2487 pop hl
2488 jr c,l0f42h
2489 ld (hl),a
2490 inc hl
2491 jr l0f3ah
2492 l0f1eh:
2493 inc de
2494 ld a,(de)
2495 cp ''''
2496 jr z,l0f2bh
2497 or a
2498 jr z,l0f42h
2499 l0f27h:
2500 ld (hl),a
2501 inc hl
2502 jr l0f1eh
2503 l0f2bh:
2504 inc de
2505 ld a,(de)
2506 cp ''''
2507 jr z,l0f27h
2508 cp '.'
2509 jr nz,l0f3ah
2510 inc de
2511 dec hl
2512 set 7,(hl)
2513 inc hl
2514 l0f3ah:
2515 pop af
2516 jr nc,l0ef9h
2517 ld (last_S),hl
2518 jr l0ef9h
2519 l0f42h:
2520 pop af
2521 ret nc
2522 ld (last_S),hl
2523 ret
2524
2525 ;-------------------------------------------------------------------------------
2526 ; >>D [startaddr] [endaddr]
2527 ; Display memory in hex and ASCII
2528
2529 cmd_D:
2530 ld (cmd_rpt),hl
2531 ld hl,(last_D)
2532 ld bc,128
2533 call sub_0377h
2534 scf
2535 sub_0f58h:
2536 push bc
2537 push de
2538 push hl
2539 push af
2540 l0f5ch:
2541 call out_hl
2542 call outbl2
2543 ld de,0
2544 l0f68h:
2545 ld a,(hl)
2546 inc hl
2547 call out_hex
2548 call outbl
2549 dec bc
2550 inc e
2551 ld a,e
2552 cp 010h
2553 jr z,l0f80h
2554 and 003h
2555 call z,outbl
2556 ld a,b
2557 or c
2558 jr nz,l0f68h
2559 l0f80h:
2560 call outbl
2561 and a
2562 sbc hl,de
2563 l0f86h:
2564 ld a,(hl)
2565 call sub_0fa3h
2566 call outchar
2567 inc hl
2568 dec e
2569 jr nz,l0f86h
2570 pop af
2571 push af
2572 jr nc,l0f97h
2573 ld (last_D),hl
2574 l0f97h:
2575 call crlf
2576 ld a,b
2577 or c
2578 jr nz,l0f5ch
2579 pop af
2580 pop hl
2581 pop de
2582 pop bc
2583 ret
2584
2585 sub_0fa3h:
2586 and 07fh
2587 cp 07fh
2588 jr z,l0fach
2589 cp ' '
2590 ret nc
2591 l0fach:
2592 ld a,'.'
2593 ret
2594
2595 ;-------------------------------------------------------------------------------
2596 ; > Fcommandline
2597 ; specifiy filenames and command line
2598
2599 ;cmd_F:
2600
2601 ;-------------------------------------------------------------------------------
2602 ; > R [displacement]
2603 ; Read Intel Hex File from console [add displacement]
2604
2605 cmd_R:
2606 ld hl,0
2607 call get_lastarg_def ;get offset from command line
2608 push hl
2609 ld hl,0
2610 ld (high_load),hl
2611 w_recstart:
2612 call i.getchar
2613 jr z,rdhex_done
2614 cp ':'
2615 jr nz,w_recstart
2616 ld c,0 ;init checksum
2617 call i.gethexbyte ;record len
2618 ld b,a
2619 call i.gethexbyte ;address high
2620 ld h,a
2621 call i.gethexbyte ;address low
2622 ld l,a
2623 call i.gethexbyte ;record type (ignored)
2624 ld a,b
2625 and a ;record len == 0?
2626 jr z,rdhex_done
2627 l16c6h:
2628 call i.gethexbyte
2629 pop de ;offset
2630 push de
2631 push hl
2632 add hl,de
2633 call i.storebyte
2634 pop hl
2635 inc hl
2636 djnz l16c6h ;repeat for record len
2637 call i.gethexbyte ;checksum
2638 ld a,c
2639 and a
2640 jr nz,error2 ;exit if checksum error
2641 jr w_recstart ;next record
2642
2643 rdhex_done:
2644 pop hl
2645 call i.gethexbyte
2646 jp p_max_high
2647
2648 i.gethexbyte:
2649 call sub_16f6h
2650 rlca
2651 rlca
2652 rlca
2653 rlca
2654 ld d,a
2655 call sub_16f6h
2656 add a,d
2657 ld d,a
2658 add a,c
2659 ld c,a
2660 ld a,d
2661 ret
2662
2663 sub_16f6h:
2664 call i.getchar
2665 jr z,error2
2666 call hex_digit
2667 ret nc
2668 error2:
2669 jp ERROR
2670
2671 i.getchar:
2672 call incharw
2673 cp 01ah
2674 ret
2675
2676 i.storebyte:
2677 push af
2678 push de
2679 ld de,ddtz_base ;don't load over ddtz
2680 call cp_hl_de
2681 jr nc,ist_1
2682
2683 ld de,(bitmap_end)
2684 call cp_hl_de
2685 jr nc,error2
2686 ist_1:
2687 ld de,(high_load)
2688 call cp_hl_de
2689 jr c,l1157h
2690 ld (high_load),hl
2691 l1157h:
2692 ld de,(max_load)
2693 call cp_hl_de
2694 jr c,l1163h
2695 ld (max_load),hl
2696 l1163h:
2697 pop de
2698 pop af
2699 ld (hl),a ;store byte
2700 ret
2701
2702 ;-------------------------------------------------------------------------------
2703
2704 p_max_high0:
2705 call assert_eol
2706 p_max_high:
2707 call pstr_inl
2708 DC 'High = '
2709 ld hl,(high_load)
2710 call out_hl
2711 call pstr_inl
2712 DC ' Max = '
2713 ld hl,(max_load)
2714 call out_hl
2715 call pstr_inl
2716 DC ' Top = '
2717 ld hl,ddtz_base-1
2718 call out_hl
2719 jp crlf
2720
2721 ;-------------------------------------------------------------------------------
2722 ; > Wstartaddr endaddr
2723 ; Write a file to disk
2724
2725 ;cmd_W:
2726
2727 ;-------------------------------------------------------------------------------
2728 ; > A [startaddr]
2729 ; Assemble Zilog Z180 mnemonics
2730
2731 ;cmd_A:
2732
2733 ;-------------------------------------------------------------------------------
2734 ; >>L [startaddr] [endaddr]
2735 ; List disassembled code
2736
2737 cmd_L:
2738 ld (cmd_rpt),hl
2739 call expr
2740 jr nc,l18dbh
2741 ld hl,(last_L)
2742 l18dbh:
2743 call next_arg
2744 call get_range
2745 jr nc,l1905h
2746 call assert_eol
2747 ld b,16
2748 l18ebh:
2749 push bc
2750 call cmdl_p_line
2751 pop bc
2752 djnz l18ebh
2753 ret
2754
2755 l1905h:
2756 call assert_eol
2757 ld d,h
2758 ld e,l
2759 add hl,bc
2760 ex de,hl
2761 l190fh:
2762 push de
2763 call cmdl_p_line
2764 pop de
2765 call cp_hl_de
2766 jr c,l190fh
2767 ret
2768
2769 ;-------------------------------------------------------------------------------
2770
2771 cmdl_p_line:
2772 push hl
2773 call out_hl
2774 call outbl2
2775 sub a
2776 ld (con_col),a
2777 push hl
2778 pop iy
2779 call p_disas_instr
2780 call crlf
2781 pop hl
2782 ld c,b
2783 ld b,0
2784 add hl,bc
2785 ld (last_L),hl
2786 ret
2787
2788 ;-------------------------------------------------------------------------------
2789
2790 p_disas_instr:
2791 call disas_get_instrlen
2792 jr nc,l197fh
2793 push bc
2794 ld a,(con_col)
2795 add a,5
2796 ld c,a
2797 call pstr ;print mnemonic
2798 call p_goto_col
2799 call pr_instr_args ;print arguments
2800 pop bc
2801 scf
2802 ret
2803
2804 l197fh:
2805 call pstr_inl
2806 DC '???'
2807 ld b,1
2808 sub a
2809 ret
2810
2811 disas_get_instrlen:
2812 sub a
2813 ld (isprefix_ixiy),a
2814 ld a,(iy+000h)
2815 cp 0edh
2816 jr z,disas_pfx.ED
2817 cp 0ddh
2818 jr z,l19abh
2819 cp 0fdh
2820 jr z,l19afh
2821 sub_19a0h:
2822 ld a,(iy+000h)
2823 cp 0cbh
2824 jr z,disas_pfx.CB
2825 jr disas_nopfx
2826 l19abh:
2827 ld a,1
2828 jr l19b1h
2829 l19afh:
2830 ld a,2
2831 l19b1h:
2832 ld (isprefix_ixiy),a
2833 call disas_pfx.DDFD
2834 ret nc
2835 push bc
2836 call sub_19a0h
2837 pop af
2838 add a,b
2839 ld b,a
2840 scf
2841 ret
2842
2843 ;-------------------------------------------------------------------------------
2844
2845 disas_nopfx:
2846 ld hl,b_1b54_start ;2 byte opcodes
2847 call lookup_op_arg
2848 ld b,2
2849 ret c
2850 ld hl,b_1ab6_start ;1 byte opcodes (no parameters)
2851 call lookup_op
2852 ld b,1
2853 ret c
2854 ld hl,b_1ad1_start ;1 byte opcodes
2855 call lookup_op_arg
2856 ld b,1
2857 ret c
2858 ld hl,b_1b9b_start ;3 byte opcodes
2859 call lookup_op_arg
2860 ld b,3
2861 ret
2862
2863 ;-------------------------------------------------------------------------------
2864
2865 disas_pfx.ED:
2866 inc iy
2867 ld hl,l228bh
2868 call lookup_op_arg
2869 ld b,3
2870 ret c
2871 ld hl,b_1c40_start
2872 call lookup_op_arg
2873 ld b,4
2874 ret c
2875
2876 ld hl,b_1bc9_start ;1 byte opcode, no arguments
2877 call lookup_op
2878 jr c,da_ed1
2879
2880 ld hl,b_1bf4_start
2881 call lookup_op_arg
2882 ret nc
2883
2884 ld a,e
2885 cp a_noarg
2886 jr nz,da_ed0
2887 ld c,(iy+0)
2888 ld a,c
2889 rra
2890 and 0ch
2891 ld b,a
2892 ld a,c
2893 and 03h
2894 call str_sel_ab
2895
2896 da_ed0:
2897 scf
2898 da_ed1:
2899 ld b,2
2900 ret
2901
2902 ;-------------------------------------------------------------------------------
2903
2904 disas_pfx.CB:
2905 push iy
2906 inc iy
2907 ld a,(isprefix_ixiy)
2908 and a
2909 jr z,l1a42h
2910 inc iy
2911 l1a42h:
2912 ld hl,b_1c55_start
2913 call lookup_op_arg
2914 pop iy
2915 ld b,2
2916 ret
2917
2918 ;-------------------------------------------------------------------------------
2919
2920 disas_pfx.DDFD:
2921 inc iy
2922 ld hl,b_19ef_start
2923 call test_DDFD
2924 ld b,002h
2925 ret c
2926 ld hl,l1a0ah
2927 call test_DDFD
2928 ld b,001h
2929 ret c
2930 ld a,(iy+000h)
2931 cp 0cbh
2932 jr nz,l19edh
2933 ld a,(iy+002h)
2934 cp 036h
2935 ret z
2936 and 007h
2937 cp 006h
2938 jr nz,l19edh
2939 ld b,002h
2940 scf
2941 ret
2942 l19edh:
2943 and a
2944 ret
2945
2946 ;-------------------------------------------------------------------------------
2947 ; DD/FD 3 byte (ix+d)/(iy+d)
2948 b_19ef_start:
2949 db 034h
2950 db 035h
2951 db 036h
2952 db 046h
2953 db 04eh
2954 db 056h
2955 db 05eh
2956 db 066h
2957 db 06eh
2958 db 070h
2959 db 071h
2960 db 072h
2961 db 073h
2962 db 074h
2963 db 075h
2964 db 077h
2965 db 07eh
2966 db 086h
2967 db 08eh
2968 db 096h
2969 db 09eh
2970 db 0a6h
2971 db 0aeh
2972 db 0b6h
2973 db 0beh
2974 db 0
2975
2976 ; DD/FD 2 byte
2977 l1a0ah:
2978 db 009h
2979 db 019h
2980 db 021h
2981 db 022h
2982 db 023h
2983 db 029h
2984 db 02ah
2985 db 02bh
2986 db 039h
2987 db 0e1h
2988 db 0e3h
2989 db 0e5h
2990 db 0e9h
2991 db 0f9h
2992 db 0
2993
2994 ;-------------------------------------------------------------------------------
2995
2996 test_DDFD:
2997 ld a,(hl)
2998 and a
2999 ret z
3000 inc hl
3001 cp (iy+000h)
3002 jr nz,test_DDFD
3003 scf
3004 ret
3005
3006 lookup_op:
3007 ld a,(hl)
3008 inc hl
3009 cp 0ffh
3010 ret z
3011 cp (iy+000h)
3012 jr z,l1a7fh
3013 inc hl
3014 jr lookup_op
3015 l1a7fh:
3016 ld b,(hl)
3017 ld e,a_noarg
3018 jr get_mnemonic
3019
3020 lookup_op_arg:
3021 call lookup_branch_op
3022 ret nc
3023 ld a,e
3024 ld e,d
3025 cp a,0ffh
3026 ret z ;carry clear
3027 ld b,a
3028
3029 get_mnemonic:
3030 ld hl,t_MNEMONICS
3031 bit 7,b
3032 jr z,get_m1
3033 res 7,b
3034 ld a,(iy+000h)
3035 rra
3036 rra
3037 rra
3038 and 07h
3039 str_sel_ab:
3040 add b
3041 ld b,a
3042 get_m1:
3043 call str_sel
3044 scf
3045 ret
3046
3047 lookup_branch_op ;TODO
3048 ld a,(hl)
3049 and a
3050 ret z
3051 inc hl
3052 and (iy+000h)
3053 cp (hl)
3054 inc hl
3055 jr z,l1aa8_br
3056 inc hl
3057 inc hl
3058 jr lookup_branch_op
3059
3060 l1aa8_br:
3061 ld e,(hl)
3062 inc hl
3063 ld d,(hl)
3064 scf
3065 ret
3066
3067 ;-------------------------------------------------------------------------------
3068 ; 1 byte opcodes (no parameters)
3069 ; Format: db opcode, t_MNEMONICS-index
3070 b_1ab6_start:
3071 db 076h,i_HALT ;halt
3072 db 0d9h,i_EXX ;exx
3073 db 0f3h,i_DI ;di
3074 db 0fbh,i_EI ;ei
3075 db 000h,i_NOP ;nop
3076 ; db 007h,i_RLCA ;rlca
3077 ; db 00fh,i_RRCA ;rrca
3078 ; db 017h,i_RLA ;rla
3079 ; db 01fh,i_RRA ;rra
3080 ; db 027h,i_DAA ;daa
3081 ; db 02fh,i_CPL ;cpl
3082 ; db 037h,i_SCF ;scf
3083 ; db 03fh,i_CCF ;ccf
3084 db 0c9h,i_RET ;ret
3085 db 0ffh
3086
3087
3088 ; 1 byte opcodes
3089 ; Format: db mask, match, t_MNEMONICS-index
3090 ; dw argument formating function
3091 b_1ad1_start:
3092 db 0c0h,040h,i_LD ;ld r[y],r[z]
3093 db a_rr
3094
3095 db 0c0h,080h,i_ADD+080h ;add a,r[z]
3096 db a_r
3097
3098 ; db 0f8h,080h,i_ADD ;add a,r[z]
3099 ; db a_ar
3100 ; db 0f8h,088h,i_ADC ;adc a,r[z]
3101 ; db a_ar
3102 ; db 0f8h,090h,i_SUB ;sub r[z]
3103 ; db a_r
3104 ; db 0f8h,098h,i_SBC ;sbc a,r[z]
3105 ; db a_ar
3106 ; db 0f8h,0a0h,i_AND ;and r[z]
3107 ; db a_r
3108 ; db 0f8h,0a8h,i_XOR ;xor r[z]
3109 ; db a_r
3110 ; db 0f8h,0b0h,i_OR ;or r[z]
3111 ; db a_r
3112 ; db 0f8h,0b8h,i_CP ;cp r[z]
3113 ; db a_r
3114
3115 db 0c7h,0c0h,i_RET ;ret cc
3116 db a_cc
3117 db 0c7h,0c7h,i_RST ;rst
3118 db a_rst
3119 db 0cfh,0c1h,i_POP ;pop rp2
3120 db a_p2
3121 db 0cfh,0c5h,i_PUSH ;push rp2
3122 db a_p2
3123 db 0ffh,0e3h,i_EX ;ex (sp),hl
3124 db a_esphl
3125 db 0ffh,0e9h,i_JP ;jp (hl)
3126 db a_hl
3127 db 0ffh,0ebh,i_EX ;ex de,hl
3128 db a_dehl
3129 db 0ffh,0f9h,i_LD ;ld sp,hl
3130 db a_lsphl
3131 db 0cfh,003h,i_INC ;inc rp
3132 db a_p
3133 db 0cfh,00bh,i_DEC ;dec rp
3134 db a_p
3135 db 0c7h,004h,i_INC ;inc r[y]
3136 db a_ry
3137 db 0c7h,005h,i_DEC ;dec r[y]
3138 db a_ry
3139 db 0ffh,008h,i_EX ;ex af,af'
3140 db a_eaf
3141 db 0cfh,009h,i_ADD ;add hl,rp
3142 db a_hlp
3143 db 0efh,002h,i_LD ;ld (rp),a ;rp=bc,de
3144 db a_pa
3145 db 0efh,00ah,i_LD ;ld a,(rp) ;rp=bc,de
3146 db a_ap
3147
3148 db 0c7h,007h,i_RLCA+080h;rlca
3149 db a_noarg
3150
3151 db 0
3152
3153 ; 2 byte opcodes
3154 b_1b54_start:
3155 db 0c7h,006h,i_LD ;ld r[y],nn
3156 db a_rn
3157
3158 db 0c7h,0c6h,i_ADD+080h ;add a,r[z]
3159 db a_n
3160
3161 ; db 0ffh,0c6h,i_ADD ;add a,nn
3162 ; db a_an
3163 ; db 0ffh,0ceh,i_ADC ;adc a,nn
3164 ; db a_an
3165 ; db 0ffh,0d6h,i_SUB ;sub nn
3166 ; db a_n
3167 ; db 0ffh,0deh,i_SBC ;sbc a,nn
3168 ; db a_an
3169 ; db 0ffh,0e6h,i_AND ;and nn
3170 ; db a_n
3171 ; db 0ffh,0eeh,i_XOR ;xor nn
3172 ; db a_n
3173 ; db 0ffh,0f6h,i_OR ;or nn
3174 ; db a_n
3175 ; db 0ffh,0feh,i_CP ;cp nn
3176 ; db a_n
3177
3178 db 0ffh,010h,i_DJNZ ;djnz
3179 db a_j
3180 db 0ffh,018h,i_JR ;jr
3181 db a_j
3182 db 0e7h,020h,i_JR ;jr cc,
3183 db a_ccj
3184 db 0ffh,0d3h,i_OUT ;out (nn),a
3185 db a_ma
3186 db 0ffh,0dbh,i_IN ;in a,(nn)
3187 db a_am
3188 db 0
3189
3190 ; 3 byte opcodes
3191 b_1b9b_start:
3192 db 0c7h,0c2h,i_JP ;jp cc,mn
3193 db a_ccnn
3194 db 0c7h,0c4h,i_CALL ;call cc,mn
3195 db a_ccnn
3196 db 0cfh,001h,i_LD ;ld ww,mn
3197 db a_rnn
3198 db 0ffh,0c3h,i_JP ;jp mn
3199 db a_nn
3200 db 0ffh,0cdh,i_CALL ;call mn
3201 db a_nn
3202 db 0ffh,022h,i_LD ;ld (mn),hl
3203 db a_mmhl
3204 db 0ffh,02ah,i_LD ;ld hl,(mn)
3205 db a_hlmm
3206 db 0ffh,032h,i_LD ;ld (mn),a
3207 db a_mma
3208 db 0ffh,03ah,i_LD ;ld a,(mn)
3209 db a_amm
3210 db 0
3211
3212 ; Prefix ED + 1 byte opcode, no arguments
3213 ; Format: opcode, t_MNEMONICS index
3214 b_1bc9_start:
3215 db 044h,i_NEG ;neg
3216 db 045h,i_RETN ;retn
3217 db 04dh,i_RETI ;reti
3218 db 067h,i_RRD ;rrd
3219 db 06fh,i_RLD ;rld
3220 ; db 0a0h,i_LDI ;ldi
3221 ; db 0a1h,i_CPI ;cpi
3222 ; db 0a2h,i_INI ;ini
3223 ; db 0a3h,i_OUTI ;outi
3224 ; db 0a8h,i_LDD ;ldd
3225 ; db 0a9h,i_CPD ;cpd
3226 ; db 0aah,i_IND ;ind
3227 ; db 0abh,i_OUTD ;outd
3228 ; db 0b0h,i_LDIR ;ldir
3229 ; db 0b1h,i_CPIR ;cpir
3230 ; db 0b2h,i_INIR ;inir
3231 ; db 0b3h,i_OTIR ;otir
3232 ; db 0b8h,i_LDDR ;lddr
3233 ; db 0b9h,i_CPDR ;cpdr
3234 ; db 0bah,i_INDR ;indr
3235 ; db 0bbh,i_OTDR ;otdr
3236 db 08bh,i_OTDM ;otdm
3237 db 09bh,i_OTDMR ;otdmr
3238 db 083h,i_OTIM ;otim
3239 db 093h,i_OTIMR ;otimr
3240 db 076h,i_SLP ;slp
3241 db 0ffh ;<end mark>
3242
3243 b_1bf4_start:
3244 db 0e4h,0a0h,i_LDI
3245 db a_noarg
3246 db 0ffh,070h,i_IN ;in (c) ;
3247 db a_c
3248 db 0c7h,040h,i_IN ;in r,(c) ;r=b,c,d,e,h,l,a
3249 db a_rc
3250 db 0ffh,071h,0ffh ;out (c),0 ;
3251 db a_cr
3252 db 0c7h,041h,i_OUT ;out (c),r ;r=b,c,d,e,h,l,a
3253 db a_cr
3254 db 0cfh,042h,i_SBC ;sbc hl,rp
3255 db a_hlp
3256 db 0cfh,04ah,i_ADC ;adc hl,rp
3257 db a_hlp
3258 db 0ffh,046h,i_IM ;im 0
3259 db a_im0
3260 db 0ffh,056h,i_IM ;im 1
3261 db a_im1
3262 db 0ffh,05eh,i_IM ;im 2
3263 db a_im2
3264 db 0e7h,047h,i_LD ;ld i,a ... ld a,r
3265 db a_ai
3266 db 0cfh,04ch,i_MLT ;mlt rr
3267 db a_p
3268 db 0c7h,004h,i_TST ;tst r
3269 db a_ry
3270 db 0
3271
3272 l228bh:
3273 db 0ffh,030h,i_IN0 ;in0 (m)
3274 db a_m
3275 db 0c7h,000h,i_IN0 ;in0 r,(m) ;r=b,c,d,e,h,l,a
3276 db a_rm
3277 db 0ffh,031h,0ffh ;out0 (m),0
3278 db a_mr
3279 db 0c7h,001h,i_OUT0 ;out0 (m),r ;r=b,c,d,e
3280 db a_mr
3281 db 0ffh,064h,i_TST ;tst m
3282 db a_n
3283 db 0ffh,074h,i_TSTIO ;tstio m
3284 db a_n
3285 db 0
3286
3287 ; Prefix ED + 1 byte opcode + 2 byte address
3288 ; Format: db mask, match, t_MNEMONICS-index
3289 ; dw argument formating function
3290 b_1c40_start:
3291 db 0cfh,043h,i_LD ;ld (mn),ww ;ww=bc,de,hl,sp
3292 db a_mmp
3293 db 0cfh,04bh,i_LD ;ld ww,(mn) ;ww=bc,de,hl,sp
3294 db a_pmm
3295 db 0
3296
3297 ; CB
3298 b_1c55_start:
3299 db 0c0h,000h,i_RLC+080h ;rlc g
3300 db a_cbr
3301
3302 ; db 0f8h,000h,i_RLC ;rlc g
3303 ; db a_cbr
3304 ; db 0f8h,008h,i_RRC ;rrc g
3305 ; db a_cbr
3306 ; db 0f8h,010h,i_RL ;rl g
3307 ; db a_cbr
3308 ; db 0f8h,018h,i_RR ;rr g
3309 ; db a_cbr
3310 ; db 0f8h,020h,i_SLA ;sla g
3311 ; db a_cbr
3312 ; db 0f8h,028h,i_SRA ;sra g
3313 ; db a_cbr
3314 ; db 0f8h,038h,i_SRL ;srl g
3315 ; db a_cbr
3316 db 0c0h,040h,i_BIT ;bit b,g
3317 db a_bcbr
3318 db 0c0h,080h,i_RES ;res b,g
3319 db a_bcbr
3320 db 0c0h,0c0h,i_SET ;set b,g
3321 db a_bcbr
3322 db 0
3323
3324 ;-------------------------------------------------------------------------------
3325 ;-------------------------------------------------------------------------------
3326
3327
3328 pr_instr_args:
3329 ld hl,t_argf
3330 ld d,0
3331 add hl,de
3332 pria_l:
3333 ld a,(hl) ;get next token
3334 inc hl
3335 or a
3336 ret z ;
3337 jp m,pria_1
3338 call outchar ;print as normal character
3339 jr pria_l
3340
3341 pria_1: ;
3342 push hl
3343 ld hl,do_arg_n
3344 and 07fh
3345 call add_hl_a2
3346 ld a,(hl)
3347 inc hl
3348 ld h,(hl)
3349 ld l,a
3350 ld a,(iy+000h)
3351 call CALL_HL
3352 pop hl
3353 jr pria_l
3354
3355 ;
3356 ; http://www.z80.info/decoding.htm
3357 ;
3358 ; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
3359 ; | x | y | z |
3360 ; | p | q |
3361 ;
3362
3363 t_argf:
3364 ; 1 byte opcodes
3365 a_rr equ $-t_argf
3366 db fi_ry,',' ;ld r[y],r[z]
3367 a_r equ $-t_argf
3368 db fi_rz,0 ;op r[z]
3369 ;a_ar equ $-t_argf
3370 ; db 'A,',fi_rz,0 ;op A,r[z]
3371 a_cc equ $-t_argf
3372 db fi_ccy,0 ;op cc[y]
3373 a_rst equ $-t_argf
3374 db fi_rst,0 ;rst y*8
3375 a_p2 equ $-t_argf
3376 db fi_rp2,0 ;rp2[p]
3377 a_esphl equ $-t_argf
3378 db '(SP),',fi_hlixiy,0 ;ex (sp),hl
3379 a_hl equ $-t_argf
3380 db '(',fi_hlixiy,')',0 ;jp (hl)
3381 a_dehl equ $-t_argf
3382 db 'DE,HL',0
3383 a_lsphl equ $-t_argf
3384 db 'SP,',fi_hlixiy,0 ;ld SP,HL
3385 a_eaf equ $-t_argf
3386 db 'AF,AF''',0 ;ex af,af'
3387 a_hlp equ $-t_argf
3388 db fi_hlixiy,',' ;add hl,rp
3389 a_p equ $-t_argf
3390 db fi_rp,0 ;rp[p]
3391 a_pa equ $-t_argf
3392 db '(',fi_rp,'),A',0 ;ld (rp),a ;rp=bc,de
3393 a_ap equ $-t_argf
3394 db 'A,(',fi_rp,')',0 ;ld a,(rp) ;rp=bc,de
3395
3396 ; 2 byte opcodes
3397 a_rn equ $-t_argf
3398 db fi_ry,',',fi_n,0 ;ld r[y],n
3399 ;a_an equ $-t_argf
3400 ; db 'A,' ;op a,n
3401 a_n equ $-t_argf
3402 db fi_n,0 ;op n
3403 a_ccj equ $-t_argf
3404 db fi_ccy2,',' ;jr cc,j ;cc = nz,z,nc,c
3405 a_j equ $-t_argf
3406 db fi_j,0 ;jr j
3407 a_ma equ $-t_argf
3408 db '(',fi_n,'),A',0 ;out (n),a
3409 a_am equ $-t_argf
3410 db 'A,(',fi_n,')',0 ;in a,(n)
3411
3412 ; 3 byte opcodes
3413 a_ccnn equ $-t_argf
3414 db fi_ccy,',',fi_nn,0 ;op cc[y],nn
3415 a_rnn equ $-t_argf
3416 db fi_rp,',' ;ld rp[p],nn
3417 a_nn equ $-t_argf
3418 db fi_nn,0 ;jp nn
3419 a_mmhl equ $-t_argf
3420 db '(',fi_nn,'),',fi_hlixiy,0 ;ld (nn),hl
3421 a_hlmm equ $-t_argf
3422 db fi_hlixiy,',(',fi_nn,')',0 ;ld hl,(nn)
3423 a_mma equ $-t_argf
3424 db '(',fi_nn,'),A',0 ;ld (nn),a
3425 a_amm equ $-t_argf
3426 db 'A,(',fi_nn,')',0 ;ld a,(nn)
3427
3428 ; Prefix ED + 1 byte opcode
3429 a_rc equ $-t_argf
3430 db fi_ry,',' ;in r[y],(c)
3431 a_c equ $-t_argf
3432 db '(C)',0 ;in (c)
3433 a_cr equ $-t_argf
3434 db '(C),' ;out (c),r[y]
3435 a_ry equ $-t_argf
3436 db fi_ry,0 ;inc r[y]
3437 a_im0 equ $-t_argf
3438 db '0',0 ;im 0
3439 a_im1 equ $-t_argf
3440 db '1',0 ;im 1
3441 a_im2 equ $-t_argf
3442 db '2',0 ;im 2
3443 a_ai equ $-t_argf
3444 db fi_ir,0 ;ld a,i ... r,a
3445
3446 ; Prefix ED + 2 byte (opcode + immediate)
3447 a_rm equ $-t_argf
3448 db fi_ry,',' ;in0 r[y],(n)
3449 a_m equ $-t_argf
3450 db '(',fi_n,')',0 ;in0 (n)
3451 a_mr equ $-t_argf
3452 db '(',fi_n,'),',fi_ry,0 ;out0 (n),r[y]
3453
3454 ; Prefix ED + 3 byte (opcode + address)
3455 a_mmp equ $-t_argf
3456 db '(',fi_nn,'),',fi_rp,0 ;ld (nn),rp
3457 a_pmm equ $-t_argf
3458 db fi_rp,',(',fi_nn,')',0 ;ld rp,(nn)
3459
3460 ; Prefix CB + 1 byte opcode
3461 a_bcbr equ $-t_argf
3462 db fi_y,',' ;op y,r[z]
3463 a_cbr equ $-t_argf
3464 db fi_rz_cb,0 ;op r[z]
3465 a_noarg equ $-t_argf
3466 db 0
3467
3468
3469 ;-------------------------------------------------------------------------------
3470
3471 argpf_index defl 0
3472
3473 argpf macro x
3474 fi_&x equ 80h+argpf_index
3475 dw p_&x
3476 argpf_index defl argpf_index+1
3477 endm
3478
3479 do_arg_n:
3480 argpf ry
3481 argpf rz
3482 argpf ccy
3483 argpf ccy2
3484 argpf rst
3485 argpf rp
3486 argpf rp2
3487 argpf hlixiy
3488 argpf n
3489 argpf j
3490 argpf nn
3491 argpf ir
3492 argpf rz_cb
3493 argpf y
3494
3495
3496 p_n:
3497 ld a,(isprefix_ixiy)
3498 and a
3499 ld a,(iy+001h)
3500 jr z,out_hex_0
3501 ld a,(iy+002h)
3502 jr out_hex_0
3503
3504 p_rst:
3505 and 038h
3506 out_hex_0:
3507 jp out_hex
3508
3509
3510 p_j:
3511 ld c,(iy+001h)
3512 ld a,c
3513 rla
3514 sbc a,a
3515 ld b,a
3516 push iy
3517 pop hl
3518 add hl,bc
3519 inc hl
3520 inc hl
3521 jr out_hl_0
3522
3523 p_nn:
3524 ld l,(iy+001h)
3525 ld h,(iy+002h)
3526 out_hl_0:
3527 jp out_hl
3528
3529 p_ir:
3530 rra
3531 rra
3532 rra
3533 and 03
3534 ld hl,t_arg_IR
3535 jr p_arg
3536
3537
3538 get_cb_opc:
3539 ld a,(isprefix_ixiy)
3540 and a
3541 ld a,(iy+001h)
3542 ret z
3543 ld a,(iy+002h)
3544 ret
3545
3546 p_y:
3547 call get_cb_opc
3548 rra
3549 rra
3550 rra
3551 and 007h
3552 jp out_dgt
3553
3554 p_rz_cb:
3555 call get_cb_opc
3556 jr p_rz
3557
3558 p_ry:
3559 rra
3560 rra
3561 rra
3562 p_rz:
3563 and 007h
3564 cp 006h
3565 ld b,a
3566 ld hl,t_arg_r
3567 jr nz,p_arg0
3568 ld a,(isprefix_ixiy)
3569 and a
3570 jr z,p_arg0
3571 ld hl,t_lp_IXIY
3572 dec a
3573 call p_arg
3574 ld a,(iy+001h)
3575 push af
3576 rlca
3577 ld a,'+'
3578 jr nc,l1e61h
3579 pop af
3580 neg
3581 push af
3582 ld a,'-'
3583 l1e61h:
3584 call outchar
3585 pop af
3586 call out_hex
3587 ld a,')'
3588 jp outchar
3589
3590 p_rp2:
3591 ld hl,t_arg_rp2
3592 db 0ddh ;swallow t_arg_rp in ix
3593 p_rp:
3594 ld hl,t_arg_rp
3595 rra
3596 rra
3597 rra
3598 rra
3599 and 003h
3600 cp 002h
3601 jr nz,p_arg
3602 p_hlixiy:
3603 ld a,(isprefix_ixiy)
3604 ld hl,t_HL.IX.IY
3605 jr p_arg
3606
3607 p_ccy2:
3608 and 018h
3609 p_ccy:
3610 rra
3611 rra
3612 rra
3613 and 007h
3614 ld hl,t_arg_cc
3615 p_arg:
3616 ld b,a
3617 p_arg0:
3618 ;fall thru
3619
3620 pstr_sel:
3621 call str_sel
3622 ;fall thru
3623 pstr:
3624 ld a,(hl)
3625 inc hl
3626 and a
3627 ret z
3628 call outchar
3629 ret m
3630 jr pstr
3631
3632 pstr_inl:
3633 ex (sp),hl
3634 call pstr
3635 ex (sp),hl
3636 ret
3637
3638 ;-------------------------------------------------------------------------------
3639
3640 opc macro x
3641
3642 i_&x equ opc_index
3643 ;o_&x equ $-opc_tabstart
3644 dc '&x'
3645 opc_index defl opc_index+1
3646 endm
3647
3648 t_MNEMONICS:
3649 ;opc_tabstart defl $
3650 opc_index defl 0
3651 ; 1-byte other
3652 opc NOP
3653 opc LD
3654 opc INC
3655 opc DEC
3656 opc DJNZ
3657 opc JR
3658 opc HALT
3659
3660 opc RLCA
3661 opc RRCA
3662 opc RLA
3663 opc RRA
3664 opc DAA
3665 opc CPL
3666 opc SCF
3667 opc CCF
3668
3669 ; 1-byte "alu"
3670 opc ADD
3671 opc ADC
3672 opc SUB
3673 opc SBC
3674 opc AND
3675 opc XOR
3676 opc OR
3677 opc CP
3678
3679 opc RET
3680 opc POP
3681 opc JP
3682 opc CALL
3683 opc PUSH
3684 opc RST
3685 opc OUT
3686 opc EXX
3687 opc IN
3688 opc EX
3689 opc DI
3690 opc EI
3691 ; CB
3692 opc RLC
3693 opc RRC
3694 opc RL
3695 opc RR
3696 opc SLA
3697 opc SRA
3698 opc SLL
3699 opc SRL
3700 opc BIT
3701 opc RES
3702 opc SET
3703
3704 ; ED
3705 opc NEG
3706 opc RETN
3707 opc RETI
3708 opc IM
3709 opc RRD
3710 opc RLD
3711
3712 ; Block instructions
3713 opc LDI
3714 opc CPI
3715 opc INI
3716 opc OUTI
3717 opc LDD
3718 opc CPD
3719 opc IND
3720 opc OUTD
3721 opc LDIR
3722 opc CPIR
3723 opc INIR
3724 opc OTIR
3725 opc LDDR
3726 opc CPDR
3727 opc INDR
3728 opc OTDR
3729
3730 ; Z180
3731 opc IN0
3732 opc OUT0
3733 opc TST
3734 opc MLT
3735 opc TSTIO
3736 opc SLP
3737 opc OTIM
3738 opc OTDM
3739 opc OTIMR
3740 opc OTDMR
3741
3742 DB 0
3743
3744 t_arg_r:
3745 DC 'B'
3746 DC 'C'
3747 DC 'D'
3748 DC 'E'
3749 DC 'H'
3750 DC 'L'
3751 DC '(HL)'
3752 DC 'A'
3753 DB 0
3754 t_arg_rp:
3755 DC 'BC'
3756 DC 'DE'
3757 DC 'HL'
3758 DC 'SP'
3759 DB 0
3760 t_arg_rp2:
3761 DC 'BC'
3762 DC 'DE'
3763 DC 'HL'
3764 DC 'AF'
3765 DB 0
3766 t_HL.IX.IY:
3767 DC 'HL'
3768 DC 'IX'
3769 DC 'IY'
3770 DB 0
3771 t_arg_cc:
3772 DC 'NZ'
3773 DC 'Z'
3774 DC 'NC'
3775 DC 'C'
3776 DC 'PO'
3777 DC 'PE'
3778 DC 'P'
3779 DC 'M'
3780 DB 0
3781
3782 t_lp_IXIY:
3783 DC '(IX'
3784 DC '(IY'
3785
3786 t_arg_IR:
3787 DC 'I,A'
3788 DC 'R,A'
3789 DC 'A,I'
3790 DC 'A,R'
3791 db 0
3792
3793
3794 ;-------------------------------------------------------------------------------
3795
3796 tc_set_bp:
3797 ld hl,(reg.pc)
3798 ld a,h
3799 or l
3800 jr z,l2037h
3801 ld de,BDOS
3802 and a
3803 sbc hl,de
3804 ld hl,l20edh ;set break after BDOS call
3805 jr z,l2031h
3806 ld iy,(reg.pc)
3807 call disas_get_instrlen
3808 jp nc,ERROR
3809 ld c,b
3810 ld b,0
3811 ld hl,(reg.pc)
3812 add hl,bc
3813 call bp_trace_enter
3814 ld iy,(reg.pc)
3815 ld hl,t_op_branch
3816 call lookup_branch_op
3817 ccf
3818 ret c
3819 ex de,hl
3820 l2031h:
3821 call CALL_HL
3822 call c,bp_trace_enter
3823 l2037h:
3824 scf
3825 ret
3826
3827 ;-------------------------------------------------------------------------------
3828
3829 t_op_branch:
3830 db 0ffh,0ddh ;Prefix DD
3831 dw l20a7h
3832 db 0ffh,0fdh ;Prefix FD
3833 dw l20ach
3834 db 0ffh,0edh ;Prefix ED
3835 dw l20b8h
3836
3837 db 0ffh,0cdh ;call mn
3838 dw l2080h
3839 db 0ffh,0c3h ;jp mn
3840 dw l208bh
3841 db 0ffh,0e9h ;jp ()
3842 dw l20a2h
3843 db 0ffh,0c9h ;ret
3844 dw l20dch
3845 db 0ffh,0cfh ;rst 8
3846 dw l2115h
3847 db 0c7h,0c7h ;rst n
3848 dw l20f9h
3849 db 0c7h,0c4h ;call cc,mn
3850 dw l2080h
3851 db 0f7h,010h ;djnz d; jr d
3852 dw l2093h
3853 db 0e7h,020h ;jr cc,d
3854 dw l2093h
3855 db 0c7h,0c2h ;jp cc,mn
3856 dw l208bh
3857 db 0c7h,0c0h ;ret cc
3858 dw l20c5h
3859 db 0
3860
3861 ;-------------------------------------------------------------------------------
3862 ; call mn call cc,mn
3863 l2080h:
3864
3865 ; jp mn jp cc,mn
3866 l208bh:
3867 ld l,(iy+001h)
3868 ld h,(iy+002h)
3869 scf
3870 ret
3871
3872 l2093h:
3873 ld c,(iy+001h)
3874 ld a,c
3875 rla
3876 sbc a,a
3877 ld b,a
3878 ld hl,(reg.pc)
3879 add hl,bc
3880 inc hl
3881 inc hl
3882 scf
3883 ret
3884
3885 ; jp (hl)
3886 l20a2h:
3887 ld hl,(reg.l)
3888 scf
3889 ret
3890
3891 ; Prefix DD
3892 l20a7h:
3893 ld hl,(reg.ix)
3894 jr l20afh
3895 ; Prefix FD
3896 l20ach:
3897 ld hl,(reg.iy)
3898 l20afh:
3899 ld a,(iy+001h)
3900 cp 0e9h ; jp (ix); jp (iy)
3901 scf
3902 ret z
3903 and a
3904 ret
3905
3906 ; Prefix ED
3907 l20b8h:
3908 ld a,(iy+001h)
3909 cp 04dh ; reti
3910 jr z,l20dch
3911 cp 045h ; retn
3912 jr z,l20dch
3913 and a
3914 ret
3915 l20c5h:
3916 ld a,(iy+000h)
3917 ld (l20d7h),a
3918 ld hl,(reg.f)
3919 push hl
3920 pop af
3921 call l20d7h
3922 scf
3923 jr c,l20dch
3924 ret
3925 l20d7h:
3926 nop
3927 and a
3928 pop hl
3929 inc hl
3930 jp (hl)
3931
3932 l20dch:
3933 l20edh:
3934 ld hl,(reg_sp) ;break on return address
3935 ld e,(hl)
3936 inc hl
3937 ld d,(hl)
3938 ex de,hl
3939 call bp_trace_enter
3940 l2115h:
3941 and a
3942 ret
3943
3944 l20f9h:
3945 ld a,(l0003h)
3946 cp (iy+000h)
3947 ret z
3948 ld a,(iy+000h)
3949 and 038h
3950 ld l,a
3951 ld h,000h
3952 ld a,(b_21e2_start)
3953 and a
3954 ret z
3955 scf
3956 ret
3957
3958 ;-------------------------------------------------------------------------------
3959 ; >>C[N][J] [steps]
3960 ; >>C[N][J] W expression
3961 ; >>C[N][J] U expression
3962 ; trace over Calls [No list] [Jumps only] /.While./.Until.
3963
3964
3965 ;-------------------------------------------------------------------------------
3966 ; >>T[N][J] [steps]
3967 ; >>T[N][J] W expression
3968 ; >>T[N][J] U expression
3969 ; Trace [no List] [Jumps only] / .While. / .Until.
3970
3971 cmd_T:
3972 ld (cmd_rpt),hl
3973 ld hl,1 ;default: 1 step
3974 call get_lastarg_def
3975 ld (trace_cnt_or_ptr),hl
3976 sub a
3977 ld (bp_p_cpu_flag),a
3978 call tc_set_bp
3979 jr user_go1
3980
3981 l2151h:
3982 call bp_clr_temporary
3983 ld hl,(trace_cnt_or_ptr)
3984 dec hl
3985 ld (trace_cnt_or_ptr),hl
3986 ld a,h
3987 or l
3988 jp z,do_break
3989
3990 call tc_set_bp
3991 jp nc,do_break
3992 sbc a,a
3993 ld (bp_p_cpu_flag),a
3994 user_go1:
3995 jp user_go
3996
3997 ;-------------------------------------------------------------------------------
3998
3999 con_col:
4000 db 0
4001
4002 ;-------------------------------------------------------------------------------
4003
4004 b_21e2_start:
4005 db 0
4006 trace_cnt_or_ptr:
4007 dw 0
4008
4009 bp_p_cpu_flag:
4010 db 0
4011
4012 bp_tab:
4013 rept BP_CNT
4014 rept BP_SIZE
4015 db 0
4016 endm
4017 endm
4018
4019 ;-------------------------------------------------------------------------------
4020
4021 last_S:
4022 dw TPA
4023
4024 last_I:
4025 dw 0
4026
4027 last_O_addr:
4028 dw 0
4029 last_O_val:
4030 db 0
4031
4032 last_D:
4033 dw TPA
4034
4035 high_load:
4036 dw TPA
4037 max_load:
4038 dw TPA
4039
4040 isprefix_ixiy:
4041 db 0
4042 last_L:
4043 dw TPA
4044
4045 pbl_loop_adr:
4046 dw 0addeh
4047
4048 bitmap_end:
4049 dw 0
4050
4051 ;-------------------------------------------------------------------------------
4052
4053 conbuf:
4054 ds CONBUF_SIZE+1
4055
4056 ;-------------------------------------------------------------------------------
4057
4058 rept (STACK_SIZE+3)/4
4059 db 0deh,0adh,0beh,0efh
4060 endm
4061 stack:
4062 reg.l2: db 000h
4063 reg.h2: db 000h
4064 reg.e2: db 000h
4065 reg.d2: db 000h
4066 reg.c2: db 000h
4067 reg.b2: db 000h
4068 reg.f2: db 000h
4069 reg.a2: db 000h
4070 db 000h
4071 reg.i: db 000h
4072 reg.iy: dw 0000h
4073 reg.ix: dw 0000h
4074 reg.f: db 000h
4075 reg.a: db 000h
4076 reg.c: db 000h
4077 reg.b: db 000h
4078 reg.e: db 000h
4079 reg.d: db 000h
4080 reg.l: db 000h
4081 reg.h: db 000h
4082 reg_sp: dw TPA
4083 reg.iff:
4084 db 0f3h
4085 db 0c3h
4086 reg.pc: dw TPA
4087
4088 cmd_rpt:dw mainloop
4089 db 0ffh,0ffh,0ffh
4090 ;-------------------------------------------------------------------------------
4091
4092 ddtz_size equ $-ddtz_base
4093 prog_size equ $-start
4094 ddtz_end:
4095
4096 ;-------------------------------------------------------------------------------
4097
4098 end