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