]> cloudbase.mooo.com Git - ddt180.git/blobdiff - ddt180.z80
Renaming/minor opt (from tiny)
[ddt180.git] / ddt180.z80
index 60c588a5b160929895dca0da94c1f005bc03fde8..a4da4cb67532eb602e1204f978cdfc0bfc69b37e 100644 (file)
@@ -240,9 +240,8 @@ mainloop:
        jr c,ERROR\r
        cp 'Z'+1-'@'\r
        jr nc,ERROR\r
-       add a,a\r
        ld hl,CMDTAB\r
-       call add_hl_a\r
+       call add_hl_a2\r
        ld a,(hl)\r
        inc hl\r
        ld h,(hl)\r
@@ -258,9 +257,9 @@ p_msg_error:
 crlf:\r
        call    pstr_inl\r
        dc      CR,LF\r
-       call inchar\r
-       ld a,0\r
+       xor a\r
        ld (con_col),a\r
+       call inchar\r
        jr c,mainloop\r
        ret\r
 \r
@@ -286,8 +285,7 @@ l01bfh:
 sub_01d9h:\r
        call    pstr_inl\r
        dc      '-'\r
-       dec hl\r
-       jp cpl.hl\r
+       jp neg.hl\r
 \r
 out_hl_dec_neg:\r
        push hl\r
@@ -354,9 +352,8 @@ out.bin.b:
 l01c9h:\r
        rlca\r
        push    af\r
-       ld      a,'0'/2\r
-       adc     a,a\r
-       call    outchar\r
+       and     1\r
+       call    out_dgt\r
        pop af\r
        djnz l01c9h\r
        ld a,'"'\r
@@ -369,7 +366,8 @@ out.ascii:
        cp ' '\r
        push af\r
        call nc,outbl\r
-       call outquote\r
+       call    pstr_inl\r
+       dc      ''''\r
        pop af\r
        jr nc,l0242h\r
        sub 0c0h\r
@@ -381,7 +379,8 @@ l0242h:
        call outchar\r
        cp ''''\r
        call z,outchar\r
-       call outquote\r
+       call    pstr_inl\r
+       dc      ''''\r
        sla c\r
        pop bc\r
        ret nc\r
@@ -396,10 +395,6 @@ outbl2:
        call outbl\r
 outbl:\r
        ld a,' '\r
-       jr outchar\r
-\r
-outquote:\r
-       ld a,''''\r
 outchar:\r
        push ix\r
        push iy\r
@@ -421,21 +416,6 @@ outchar:
        pop ix\r
        ret\r
 \r
-pstr:\r
-       ld a,(hl)\r
-       inc hl\r
-       and a\r
-       ret z\r
-       call outchar\r
-       ret m\r
-       jr pstr\r
-\r
-pstr_inl:\r
-       ex      (sp),hl\r
-       call    pstr\r
-       ex      (sp),hl\r
-       ret\r
-\r
 p_align_@_sym:\r
        push    de\r
        ld      de,(var.@)\r
@@ -558,6 +538,8 @@ chk_stack:
 \r
 ;-------------------------------------------------------------------------------\r
 \r
+add_hl_a2:\r
+       add a,a\r
 add_hl_a:\r
        add a,l\r
        ld l,a\r
@@ -711,22 +693,23 @@ l031eh:
        pop bc\r
        ret\r
 l0336h:\r
-       call sub_0345h\r
+       call str_sel_next\r
 l0339h:\r
        pop de\r
        and a\r
        pop bc\r
        ret\r
 \r
-sel_dc_string:\r
+str_sel:\r
        inc b\r
-l033eh:\r
-       dec b\r
-       ret z\r
-       call sub_0345h\r
-       jr l033eh\r
+       jr str_sel2\r
+str_sel1:\r
+       call str_sel_next\r
+str_sel2:\r
+       djnz str_sel1\r
+       ret\r
 \r
-sub_0345h:\r
+str_sel_next:\r
        ld a,(hl)\r
        and a\r
        ret z\r
@@ -737,12 +720,12 @@ l0348h:
        ret m\r
        jr l0348h\r
 \r
-sub_034eh:\r
+get_arg_range_target:\r
        call get_arg_range\r
        push hl\r
        push bc\r
        call next_arg\r
-       call sub_0363h\r
+       call get_arg_final\r
        ex de,hl\r
        pop bc\r
        pop hl\r
@@ -753,7 +736,7 @@ sub_035dh:
        jr c,error0\r
        ret\r
 \r
-sub_0363h:\r
+get_arg_final:\r
        call sub_035dh\r
 l0366h:\r
        jp assert_eol\r
@@ -902,8 +885,7 @@ l0406h:
 l0411h:\r
        ld hl,tab_func_eqlege\r
        ld a,b\r
-       add a,a\r
-       call add_hl_a\r
+       call add_hl_a2\r
        ld c,(hl)\r
        inc hl\r
        ld b,(hl)\r
@@ -1057,8 +1039,7 @@ do_binary_op:
        call lookupch\r
        ld a,b\r
        ld hl,tblf_opa\r
-       add a,a\r
-       call add_hl_a\r
+       call add_hl_a2\r
        ld c,(hl)\r
        inc hl\r
        ld b,(hl)\r
@@ -1142,9 +1123,8 @@ fact_reg.Y:
        jr c,error1\r
        inc de\r
 get_y_val:\r
-       add a,a\r
        ld hl,reg_Y\r
-       call add_hl_a\r
+       call add_hl_a2\r
        ld a,(hl)\r
        inc hl\r
        ld h,(hl)\r
@@ -1184,14 +1164,19 @@ fact_reg.CPU:
        inc hl\r
        ld h,(hl)\r
        ld l,a\r
-       and a\r
+       xor a                   ;clr cy, a=0\r
        bit 0,c\r
        ret nz\r
-       ld h,000h\r
+       ld h,a\r
        ret\r
 \r
+fact_factinv:\r
+       call fact_factor\r
+       jr cpl.hl\r
+\r
 fact_factneg:\r
        call fact_factor\r
+neg.hl:\r
        dec hl\r
 cpl.hl:\r
        ld a,h\r
@@ -1202,10 +1187,6 @@ cpl.hl:
        ld l,a\r
        ret\r
 \r
-fact_factinv:\r
-       call fact_factor\r
-       jr cpl.hl\r
-\r
 fact_mem:\r
        call expr1\r
        jr c,error1\r
@@ -1435,13 +1416,13 @@ p_f:
        call p_flags\r
        ld a,(reg.iff)\r
        cp 0f3h\r
-       jp z,outbl\r
+       jr z,outbl_1\r
        ld a,'E'\r
        jp outchar\r
 p_f2:\r
        ld a,(reg.f2)\r
        call p_flags\r
-       jp outbl\r
+       jr outbl_1\r
 \r
 p_flags:\r
        push    hl\r
@@ -1496,10 +1477,10 @@ l06deh:
        ld a,(de)\r
        call out_hex\r
 l06e2h:\r
-       call outbl\r
        pop de\r
        pop hl\r
-       ret\r
+outbl_1:\r
+       jp outbl\r
 \r
 b_06e9_start:\r
        DC      'A '\r
@@ -2118,7 +2099,7 @@ sub_0bdch:
        add hl,bc\r
        ex de,hl\r
        ld c,003h\r
-       jp l0c33h\r
+       jr l0c33h\r
 \r
 ;-------------------------------------------------------------------------------\r
 ; > X\r
@@ -2142,7 +2123,7 @@ cmd_X:
        jp z,ERROR\r
        ex de,hl\r
        ld hl,t_reg_names\r
-       call sel_dc_string\r
+       call str_sel\r
 l0c12h:\r
        call l0c33h\r
 l0c15h:\r
@@ -2152,7 +2133,7 @@ l0c15h:
        call get_line\r
        call skipbl\r
        jr z,l0c30h\r
-       call sub_0363h\r
+       call get_arg_final\r
        ex de,hl\r
        pop bc\r
        pop hl\r
@@ -2454,7 +2435,7 @@ cmd_O:
 ;      Verify (compare) two memory areas\r
 \r
 cmd_V:\r
-       call sub_034eh\r
+       call get_arg_range_target\r
 l0dedh:\r
        push bc\r
        ld a,(de)\r
@@ -2476,12 +2457,9 @@ l0dedh:
        call crlf\r
 l0e10h:\r
        pop bc\r
-       inc hl\r
        inc de\r
-       dec bc\r
-       ld a,b\r
-       or c\r
-       jr nz,l0dedh\r
+       cpi\r
+       jp pe,l0dedh\r
        ret\r
 \r
 ;-------------------------------------------------------------------------------\r
@@ -2495,7 +2473,7 @@ cmd_M:
        inc de\r
 l0e1fh:\r
        push af\r
-       call sub_034eh\r
+       call get_arg_range_target\r
        push hl\r
        push de\r
        push bc\r
@@ -2709,9 +2687,9 @@ sub_0ee6h:
        ret nz\r
        jp ERROR\r
 \r
-sub_0ef7h:\r
+sub_0ef7h:                     ;from cmd_Q, cmd_Z\r
        db      0e6h            ; and 037h (clear carry)\r
-sub_0ef8h:\r
+sub_0ef8h:                     ;from cmd_S\r
        scf\r
 l0ef9h:\r
        push af\r
@@ -3766,7 +3744,7 @@ as.LD:
 l1395h:\r
        call assert_eol\r
        ld a,(prefix_ixiy)\r
-l139bh:\r
+as_store_4:\r
        ld (iy+000h),a\r
        ld (iy+001h),b\r
        ld (iy+002h),l\r
@@ -3781,7 +3759,7 @@ l13aah:
        inc de\r
        ld b,032h\r
 \r
-as.store_3:\r
+as_store_3:\r
        call assert_eol\r
        ld (iy+000h),b\r
        ld (iy+001h),l\r
@@ -3797,10 +3775,10 @@ l13c2h:
 l13c9h:\r
        call assert_eol\r
        ld a,0edh\r
-       jr l139bh\r
+       jr as_store_4\r
 l13d0h:\r
        ld b,022h\r
-       jr as.store_3\r
+       jr as_store_3\r
 \r
 l13d4h:\r
        ld b,a\r
@@ -3874,7 +3852,7 @@ l1432h:
        add a,006h\r
 l143fh:\r
        ld b,a\r
-as.store_2:\r
+as_store_2:\r
        call assert_eol\r
        ld (iy+000h),b\r
        ld (iy+001h),l\r
@@ -3901,7 +3879,7 @@ l1466h:
        call test_expr\r
        call test_paren_close\r
        ld b,03ah\r
-       jp as.store_3\r
+       jp as_store_3\r
 \r
 l1471h:\r
        call assert_comma\r
@@ -3965,7 +3943,7 @@ l14cch:
 \r
 l14e3h:\r
        ld b,02ah\r
-       jp as.store_3\r
+       jp as_store_3\r
 \r
 l14e8h:\r
        call test_expr\r
@@ -3973,7 +3951,7 @@ l14e8h:
        ld a,001h\r
        add a,b\r
        ld b,a\r
-       jp as.store_3\r
+       jp as_store_3\r
 l14f5h:\r
        call assert_comma\r
        call get_char_upper\r
@@ -4175,7 +4153,7 @@ l163ch:
 l163eh:\r
        pop af\r
        call test_expr\r
-       jp as.store_3\r
+       jp as_store_3\r
 \r
 as.RET:\r
        call arg.cc_ZCPS\r
@@ -4208,7 +4186,7 @@ l1666h:
        pop af\r
 l166eh:\r
        call test_expr\r
-       jp as.store_3\r
+       jp as_store_3\r
 l1674h:\r
        call assert_eol\r
        ld a,b\r
@@ -4223,7 +4201,7 @@ l1680h:
        ld b,0fdh\r
 l1687h:\r
        ld l,0e9h\r
-       jp as.store_2\r
+       jp as_store_2\r
 \r
 l168ch:\r
        DC      '(HL)'\r
@@ -4246,7 +4224,7 @@ l16a9h:
        call assert_comma\r
 l16aeh:\r
        call arg.j_displ\r
-       jp as.store_2\r
+       jp as_store_2\r
 \r
 as.IM:\r
        call arg.imm_8bit\r
@@ -4302,7 +4280,7 @@ as.IN:
        jr c,l1715h\r
        call arg.addr_8bit\r
        ld b,0dbh\r
-       jp as.store_2\r
+       jp as_store_2\r
 l170fh:\r
        call assert_comma\r
        call sub_171bh\r
@@ -4336,7 +4314,7 @@ l1739h:
        jr nz,error7\r
        inc de\r
        ld b,0d3h\r
-       jp as.store_2\r
+       jp as_store_2\r
 \r
 as.EX:\r
        ld hl,b_176d_start\r
@@ -4464,7 +4442,7 @@ error8:
 \r
 arg.zz:\r
        push hl\r
-       ld hl,t_BC.DE.HL.AF\r
+       ld hl,t_arg_rp2\r
        jr l181fh\r
 \r
 arg.reg_16bit:\r
@@ -4473,7 +4451,7 @@ arg.reg_16bit:
 \r
 arg.ww:\r
        push hl\r
-       ld hl,t_BC.DE.HL.SP\r
+       ld hl,t_arg_rp\r
 l181fh:\r
        push bc\r
        call sub_030ah\r
@@ -4493,7 +4471,7 @@ arg.r_HL_A:
        call skipbl\r
        push bc\r
        push hl\r
-       ld hl,t_BCDEHL_HL_A\r
+       ld hl,t_arg_r\r
        call sub_030ah\r
        ld a,b\r
        pop hl\r
@@ -4581,7 +4559,7 @@ arg.cc_ZCPS:
        jr l18b1h\r
 \r
 arg.cc_ZC:\r
-       ld hl,t_tstfl_ZC\r
+       ld hl,t_arg_cc\r
        ld c,003h\r
 l18b1h:\r
        push bc\r
@@ -4703,10 +4681,10 @@ p_disas_instr:
        ld      a,(con_col)\r
        add     a,5\r
        ld      c,a\r
-       call    pstr\r
+       call    pstr                                    ;print mnemonic\r
        call    p_goto_col\r
        ex de,hl\r
-       call call_hl\r
+       call call_hl                                    ;print arguments\r
        pop bc\r
        ld a,(disas_argtype)\r
        ld hl,(disas_arg_16)\r
@@ -4755,6 +4733,65 @@ l19b1h:
 \r
 ;-------------------------------------------------------------------------------\r
 \r
+disas_nopfx:\r
+       ld hl,b_1b54_start              ;2 byte opcodes\r
+       call lookup_op\r
+       ld b,2\r
+       ret c\r
+       ld hl,b_1ab6_start              ;1 byte opcodes (no parameters)\r
+       call sub_1a72h\r
+       ld b,1\r
+       ret c\r
+       ld hl,b_1ad1_start              ;1 byte opcodes\r
+       call lookup_op\r
+       ld b,1\r
+       ret c\r
+       ld hl,b_1b9b_start              ;3 byte opcodes\r
+       call lookup_op\r
+       ret nc\r
+       ld b,3\r
+       ret\r
+\r
+;-------------------------------------------------------------------------------\r
+\r
+disas_pfx.ED:\r
+       inc iy\r
+       ld hl,b_1bc9_start              ;1 byte opcode, no arguments\r
+       call sub_1a72h\r
+       ld b,2\r
+       ret c\r
+       ld hl,b_1bf4_start\r
+       call lookup_op\r
+       ld b,2\r
+       ret c\r
+\r
+       ld hl,l228bh\r
+       call lookup_op\r
+       ld b,3\r
+       ret c\r
+       ld hl,b_1c40_start\r
+       call lookup_op\r
+       ld b,4\r
+       ret\r
+\r
+;-------------------------------------------------------------------------------\r
+\r
+disas_pfx.CB:\r
+       push iy\r
+       inc iy\r
+       ld a,(isprefix_ixiy)\r
+       and a\r
+       jr z,l1a42h\r
+       inc iy\r
+l1a42h:\r
+       ld hl,b_1c55_start\r
+       call lookup_op\r
+       pop iy\r
+       ld b,2\r
+       ret\r
+\r
+;-------------------------------------------------------------------------------\r
+\r
 disas_pfx.DDFD:\r
        inc iy\r
        ld hl,b_19ef_start\r
@@ -4831,65 +4868,6 @@ l1a0ah:
 \r
 ;-------------------------------------------------------------------------------\r
 \r
-disas_pfx.ED:\r
-       inc iy\r
-       ld hl,b_1bc9_start\r
-       call sub_1a72h\r
-       ld b,2\r
-       ret c\r
-       ld hl,b_1bf4_start\r
-       call lookup_opc\r
-       ld b,2\r
-       ret c\r
-\r
-       ld hl,l228bh\r
-       call lookup_opc\r
-       ld b,3\r
-       ret c\r
-       ld hl,b_1c40_start\r
-       call lookup_opc\r
-       ld b,4\r
-       ret\r
-\r
-;-------------------------------------------------------------------------------\r
-\r
-disas_pfx.CB:\r
-       push iy\r
-       inc iy\r
-       ld a,(isprefix_ixiy)\r
-       and a\r
-       jr z,l1a42h\r
-       inc iy\r
-l1a42h:\r
-       ld hl,b_1c55_start\r
-       call lookup_opc\r
-       pop iy\r
-       ld b,2\r
-       ret\r
-\r
-;-------------------------------------------------------------------------------\r
-\r
-disas_nopfx:\r
-       ld hl,b_1b54_start\r
-       call lookup_opc\r
-       ld b,2\r
-       ret c\r
-       ld hl,b_1ab6_start\r
-       call sub_1a72h\r
-       ld b,1\r
-       ret c\r
-       ld hl,b_1ad1_start\r
-       call lookup_opc\r
-       ld b,1\r
-       ret c\r
-       ld hl,b_1b9b_start\r
-       call lookup_opc\r
-       ret nc\r
-       ld b,3\r
-       ret\r
-\r
-;-------------------------------------------------------------------------------\r
-\r
 sub_1a72h:\r
        ld a,(hl)\r
        cp 0ffh\r
@@ -4916,7 +4894,7 @@ test_DDFD:
        scf\r
        ret\r
 \r
-lookup_opc:\r
+lookup_op:\r
        ld a,(iy+000h)\r
        and (hl)\r
        inc hl\r
@@ -4928,7 +4906,7 @@ lookup_opc:
        inc hl\r
        ld a,(hl)\r
        and a\r
-       jr nz,lookup_opc\r
+       jr nz,lookup_op\r
        ret\r
 \r
 l1aa8h:\r
@@ -5023,7 +5001,7 @@ b_1ad1_start:
        dw l1ce5h\r
        db 0\r
 \r
-; 2 byte opdodes\r
+; 2 byte opcodes\r
 b_1b54_start:\r
        db 0c7h,006h,056h       ;ld r,nn\r
        dw l1cfah\r
@@ -5499,7 +5477,7 @@ l1e61h:
        jp p_arg_nn_rp\r
 \r
 p_arg_r1:\r
-       ld hl,t_BCDEHL_HL_A\r
+       ld hl,t_arg_r\r
        jr p_arg\r
 \r
 b_1e78_start:\r
@@ -5512,10 +5490,10 @@ p_arg_hlixiy:
        ld hl,t_HL.IX.IY\r
        jr p_arg\r
 p_arg_zz:\r
-       ld hl,t_BC.DE.HL.AF\r
+       ld hl,t_arg_rp2\r
        jr l1e8eh\r
 p_arg_ww:\r
-       ld hl,t_BC.DE.HL.SP\r
+       ld hl,t_arg_rp\r
 l1e8eh:\r
        ld a,(iy+000h)\r
        rra\r
@@ -5537,8 +5515,24 @@ p_arg_cc0:
        ld hl,t_tstfl_ZCPS\r
 p_arg:\r
        ld b,a\r
-       call sel_dc_string\r
-       jp pstr\r
+       ;fall thru\r
+pstr_sel:\r
+       call str_sel\r
+       ;fall thru\r
+pstr:\r
+       ld a,(hl)\r
+       inc hl\r
+       and a\r
+       ret z\r
+       call outchar\r
+       ret m\r
+       jr pstr\r
+\r
+pstr_inl:\r
+       ex      (sp),hl\r
+       call    pstr\r
+       ex      (sp),hl\r
+       ret\r
 \r
 ;-------------------------------------------------------------------------------\r
 \r
@@ -5622,7 +5616,7 @@ t_MNEMONICS:
        DC      'TSTIO'\r
        DB      0\r
 \r
-t_BCDEHL_HL_A:\r
+t_arg_r:\r
        DC      'B'\r
        DC      'C'\r
        DC      'D'\r
@@ -5632,13 +5626,13 @@ t_BCDEHL_HL_A:
        DC      '(HL)'\r
        DC      'A'\r
        DB      0\r
-t_BC.DE.HL.SP:\r
+t_arg_rp:\r
        DC      'BC'\r
        DC      'DE'\r
        DC      'HL'\r
        DC      'SP'\r
        DB      0\r
-t_BC.DE.HL.AF:\r
+t_arg_rp2:\r
        DC      'BC'\r
        DC      'DE'\r
 t_HL.AF:\r
@@ -5663,7 +5657,7 @@ t_IX.IY:
        DC      'IX'\r
        DC      'IY'\r
        DB      0\r
-t_tstfl_ZC:\r
+t_arg_cc:\r
        DC      'NZ'\r
        DC      'Z'\r
        DC      'NC'\r
@@ -5703,7 +5697,7 @@ tc_set_bp:
        ld de,BDOS\r
        and a\r
        sbc hl,de\r
-       ld hl,l20edh\r
+       ld hl,l20edh            ;set break after BDOS call\r
        jr z,l2031h\r
        ld iy,(reg.pc)\r
        call disas_get_instrlen\r
@@ -5715,7 +5709,7 @@ tc_set_bp:
        call bp_trace_enter\r
        ld iy,(reg.pc)\r
        ld hl,b_2039_start\r
-       call lookup_opc\r
+       call lookup_op\r
        ccf\r
        ret c\r
        ex de,hl\r
@@ -5849,7 +5843,7 @@ l20dch:
        pop hl\r
        ret\r
 l20edh:\r
-       ld hl,(reg_sp)\r
+       ld hl,(reg_sp)          ;break on return address\r
        ld e,(hl)\r
        inc hl\r
        ld d,(hl)\r
@@ -5931,7 +5925,7 @@ l2151h:
        call sub_21c8h\r
        jr z,l216bh\r
        ld hl,b_2048_start\r
-       call lookup_opc\r
+       call lookup_op\r
        jr nc,l214ch\r
 l216bh:\r
        ld a,(trace_UW_flag)            ;0 or 'U' or 'W'\r