From: Leo Date: Mon, 19 Mar 2012 19:36:07 +0000 (+0000) Subject: * avr/Z80int-jmp.asm X-Git-Tag: 3.0~7 X-Git-Url: http://cloudbase.mooo.com/gitweb/avrcpm.git/commitdiff_plain/e7a0f4030d1a41cb3e95ce226ba3ab0fc73c158f * avr/Z80int-jmp.asm - DD/FD-CB opcode table implemented - LDD, LDI, LDIR, CPI, CPIR, CPD, CPDR implementd - Use Y register as data pointer --> must not be changed in subroutine calls * avr/virt_ports.asm - Save Y register git-svn-id: svn://cu.loc/avr-cpm/avrcpm/trunk@181 57430480-672e-4586-8877-bcf8adbbf3b7 --- diff --git a/avr/Z80int-jmp.asm b/avr/Z80int-jmp.asm index 8a2c8ed..a172c92 100644 --- a/avr/Z80int-jmp.asm +++ b/avr/Z80int-jmp.asm @@ -1,4 +1,4 @@ -; 8080 Interpreter. +; 8080/Z80 Interpreter. ; This is part of the Z80-CP/M emulator written by Sprite_tm. ; @@ -24,8 +24,14 @@ ; $Id$ ; +#if EM_Z80 + #define OPC_TABSTART 0x1a00 +#else + #define OPC_TABSTART 0x1200 +#endif + .dseg - +z_regs: z_b: .byte 1 z_c: .byte 1 z_d: .byte 1 @@ -33,15 +39,32 @@ z_e: .byte 1 z_h: .byte 1 z_l: .byte 1 + .equ oz_b = 0 + .equ oz_c = 1 + .equ oz_d = 2 + .equ oz_e = 3 + .equ oz_h = 4 + .equ oz_l = 5 + + #if EM_Z80 -z_flags2: .byte 1 -z_a2: .byte 1 z_b2: .byte 1 z_c2: .byte 1 z_d2: .byte 1 z_e2: .byte 1 z_h2: .byte 1 z_l2: .byte 1 +z_f2: .byte 1 +z_a2: .byte 1 + .equ r2ofs = z_b2-z_b + .equ oz_b2 = 6 + .equ oz_c2 = 7 + .equ oz_d2 = 8 + .equ oz_e2 = 9 + .equ oz_h2 = 10 + .equ oz_l2 = 11 + .equ oz_f2 = 12 + .equ oz_a2 = 13 z_xh: .byte 1 z_xl: .byte 1 @@ -50,8 +73,15 @@ z_yl: .byte 1 z_i: .byte 1 z_r: .byte 1 + .equ oz_xh = 14 + .equ oz_xl = 15 + .equ oz_yh = 16 + .equ oz_yl = 17 + .equ oz_i = 18 + .equ oz_r = 19 z_istat: .byte 1 + .equ oz_istat = 20 .equ IM_MASK = 0x03 ;Mask IM 0..2 .equ IM0 = 0 @@ -61,23 +91,23 @@ z_istat: .byte 1 .equ IFF1 = 2 ;IFF1 Flag .equ IFF2 = 3 ;IFF2 Flag - .equ r2ofs = z_b2-z_b #endif .cseg ;Init z80 z80_init: - ldi z_pcl,low (IPLADDR) - ldi z_pch,high(IPLADDR) + ldiw z_pc,IPLADDR + ldiw y,z_regs cbi flags,trace clr intstat + printnewline -#if INS_DEBUG - sbr intstat,(1< 2047 + .set longdist_ = 1 + .else + rjmp do_@0 ; do op and return to main + .endif .endif .if op_ - rjmp do_@1 ; do op and return to main + .if (PC - do_@1) > 2047 + .set longdist_ = 1 + .else + rjmp do_@1 ; do op and return to main + .endif .endif .if store_ ; - rjmp do_@2 ; + .if (PC - do_@2) > 2047 + .set longdist_ = 1 + .else + rjmp do_@2 ; do op and return to main + .endif .endif - .else + .endif + + .set done_ = 0 + .if (cnt_ > 1) || longdist_ + + .set labelexists_ = 0 + .if defined (l_@0_@1_@2) + .set labelexists_ = 1 + .endif ; two or tree actions - .if defined do_@0_@1_@2 ; same combination of fetch/op/store allready present? - rjmp do_@0_@1_@2 ; generate a jump to action table - .else + .if labelexists_ ; same combination of fetch/op/store allready present? + .if (PC - l_@0_@1_@2) <= 2047 + rjmp l_@0_@1_@2 ; generate a jump to action table + .set done_ = 1 + .endif + .endif + + .if !done_ - .if todo_table_pos_ < opc_tabnext_ - .if todo_table_pos_ + 3 > opc_tablow_ - .set todo_table_pos_ = opc_tabnext_ + .if todo_table_pos_ == 0 + .set todo_table_pos_ = opcjmp_table_pos_ - 2048 + .if todo_table_pos_ < pc_save_ + .set todo_table_pos_ = pc_save_ .endif .endif - .equ do_@0_@1_@2 = todo_table_pos_ ; make a label - rjmp do_@0_@1_@2 ; generate a jump to action table + .if todo_table_pos_ < opc_tablow_ + .if todo_table_pos_ + 2*cnt_ > opc_tablow_ + .set todo_table_pos_ = opc_tabend_ + .endif + .endif + + .if labelexists_ + rjmp todo_table_pos_ + .org todo_table_pos_ + jmp l_@0_@1_@2 + .set todo_table_pos_ = PC + .set done_ = 1 + .endif + .endif - .org do_@0_@1_@2 + .if !done_ + + .equ l_@0_@1_@2 = todo_table_pos_ ; make a label + rjmp l_@0_@1_@2 ; generate a jump to action table + + .org l_@0_@1_@2 .if fetch_ ; must fetch - .if op_ || store_ - lcall do_@0 ; fetch and come back here - .else ; - ljmp do_@0 ; fetch and return to main + .if op_ || store_ + .if do_@0 == 0 + m_do_@0 + .else + lcall do_@0 ; fetch and come back here + .endif + .else + .if do_@0 == 0 + m_do_@0 + ret + .else + ljmp do_@0 ; do op and return to main + .endif .endif .endif .if op_ ; must exec op .if store_ - lcall do_@1 ; do op and come back here + .if do_@1 == 0 + m_do_@1 + .else + lcall do_@1 ; fetch and come back here + .endif .else - ljmp do_@1 ; do op and return to main + .if do_@1 == 0 + m_do_@1 + ret + .else + ljmp do_@1 ; do op and return to main + .endif .endif .endif - .if store_ ; must store - ljmp do_@2 ; store is allways last + .if store_ ; must store + .if do_@2 == 0 + m_do_@2 + ret + .else + ljmp do_@2 ; store is allways last + .endif .endif - + .set todo_table_pos_ = PC .endif .endif - .org todo_table_pos_ + .if todo_table_pos_ == 0 + .org pc_save_ + .else + .org todo_table_pos_ + .endif .endm - + +do_x_nop: + ret + ; ------------ Fetch phase stuff ----------------- -;.org (PC+255) & 0xff00 fetch_ops: -do_fetch_nop: - ret +.equ do_fetch_nop = do_x_nop + -do_fetch_a: +.macro m_do_fetch_a mov opl,z_a - ret +.endm -do_fetch_b: - lds opl,z_b - ret +.equ do_fetch_a = 0 +; mov opl,z_a +; ret -do_fetch_c: - lds opl,z_c - ret +.macro m_do_fetch_b + ldd opl,y+oz_b +.endm -do_fetch_d: - lds opl,z_d - ret +.equ do_fetch_b = 0 +; ldd opl,y+oz_b +; ret -do_fetch_e: - lds opl,z_e - ret +.macro m_do_fetch_c + ldd opl,y+oz_c +.endm -do_fetch_h: - lds opl,z_h - ret +.equ do_fetch_c = 0 +; ldd opl,y+oz_c +; ret -do_fetch_l: - lds opl,z_l - ret +.macro m_do_fetch_d + ldd opl,y+oz_d +.endm + +.equ do_fetch_d = 0 +; ldd opl,y+oz_d +; ret + +.macro m_do_fetch_e + ldd opl,y+oz_e +.endm + +.equ do_fetch_e = 0 +; ldd opl,y+oz_e +; ret + +.macro m_do_fetch_h + ldd opl,y+oz_h +.endm + +.equ do_fetch_h = 0 +; ldd opl,y+oz_h +; ret + +.macro m_do_fetch_l + ldd opl,y+oz_l +.endm + +.equ do_fetch_l = 0 +; ldd opl,y+oz_l +; ret do_fetch_af: mov opl,z_flags @@ -270,39 +408,43 @@ do_fetch_af: ret do_fetch_bc: - lds opl,z_c - lds oph,z_b + ldd opl,y+oz_c + ldd oph,y+oz_b ret do_fetch_de: - lds opl,z_e - lds oph,z_d + ldd opl,y+oz_e + ldd oph,y+oz_d ret do_fetch_hl: - lds opl,z_l - lds oph,z_h + ldd opl,y+oz_l + ldd oph,y+oz_h ret -do_fetch_sp: +.macro m_do_fetch_sp movw opl,z_spl - ret +.endm + +.equ do_fetch_sp = 0 +; movw opl,z_spl +; ret do_fetch_mbc: - lds xh,z_b - lds xl,z_c + ldd xh,y+oz_b + ldd xl,y+oz_c mem_read_d z_a ret do_fetch_mde: - lds xh,z_d - lds xl,z_e + ldd xh,y+oz_d + ldd xl,y+oz_e mem_read_d z_a ret do_fetch_mhl: - lds xh,z_h - lds xl,z_l + ldd xh,y+oz_h + ldd xl,y+oz_l mem_read_d opl ret @@ -335,37 +477,40 @@ do_fetch_rst: ; ------------ Store phase stuff ----------------- -;.org (PC+255) & 0xff00 store_ops: -do_store_nop: - ret +.equ do_store_nop = do_x_nop + do_store_a: mov z_a,opl ret +;.macro m_do_store_b +; std y+oz_b,opl +;.endm +;.equ do_store_b = 0 do_store_b: - sts z_b,opl + std y+oz_b,opl ret do_store_c: - sts z_c,opl + std y+oz_c,opl ret do_store_d: - sts z_d,opl + std y+oz_d,opl ret do_store_e: - sts z_e,opl + std y+oz_e,opl ret do_store_h: - sts z_h,opl + std y+oz_h,opl ret do_store_l: - sts z_l,opl + std y+oz_l,opl ret do_store_af: @@ -374,35 +519,35 @@ do_store_af: ret do_store_bc: - sts z_b,oph - sts z_c,opl + std y+oz_b,oph + std y+oz_c,opl ret do_store_de: - sts z_d,oph - sts z_e,opl + std y+oz_d,oph + std y+oz_e,opl ret do_store_hl: - sts z_h,oph - sts z_l,opl + std y+oz_h,oph + std y+oz_l,opl ret do_store_mbc: - lds xh,z_b - lds xl,z_c + ldd xh,y+oz_b + ldd xl,y+oz_c mem_write_s z_a ret do_store_mde: - lds xh,z_d - lds xl,z_e + ldd xh,y+oz_d + ldd xl,y+oz_e mem_write_s z_a ret do_store_mhl: - lds xh,z_h - lds xl,z_l + ldd xh,y+oz_h + ldd xl,y+oz_l mem_write_s opl ret @@ -478,7 +623,6 @@ do_store_am: mem_write_ds op, z_a ret - ; ------------ Operation phase stuff ----------------- ;---------------------------------------------------------------- @@ -760,6 +904,8 @@ do_store_am: ;---------------------------------------------------------------- +.equ do_op_nop = do_x_nop + do_op_inv: sbiw z_pcl,1 lcall printregs @@ -768,8 +914,6 @@ do_op_inv: haltinv: rjmp haltinv -do_op_nop: - ret ;---------------------------------------------------------------- ;|Mnemonic |SZHPNC|Description |Notes | @@ -786,7 +930,6 @@ do_op_HALT: printstring "CPU halted! " ret - ;---------------------------------------------------------------- ;|Mnemonic |SZHPNC|Description |Notes | ;---------------------------------------------------------------- @@ -807,7 +950,7 @@ do_op_outa: ; out (opl),a .endif mov temp,z_a mov temp2,opl - lcall portWrite + lcall portWrite ret ;---------------------------------------------------------------- @@ -1137,7 +1280,7 @@ do_op_ora: ; ; do_op_xora: - eor z_a,opl + eor z_a,opl ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C do_z80_flags_op_or ret @@ -1151,13 +1294,13 @@ do_op_xora: ; ; do_op_addhl: - lds temp,z_l - lds temp2,z_h - add opl,temp - adc oph,temp2 - sts z_l,opl - sts z_h,oph - in temp,sreg + ldd temp,y+oz_l + ldd temp2,y+oz_h + add opl,temp + adc oph,temp2 + std y+oz_l,opl + std y+oz_h,oph + in temp,sreg bmov z_flags,ZFL_C, temp,AVR_C do_z80_flags_H do_z80_flags_clear_N @@ -1170,11 +1313,11 @@ do_op_addhl: ; ; do_op_sthl: ;store hl to mem loc in opl:h - movw xl,opl - lds temp,z_l + movw xl,opl + ldd temp,y+oz_l mem_write - adiw xl,1 - lds temp,z_h + adiw xl,1 + ldd temp,y+oz_h mem_write ret @@ -1459,10 +1602,10 @@ do_op_pop16: ;-----------------------------Z80-------------------------------- ; do_op_exhl: - lds temp,z_l - lds temp2,z_h - sts z_l,opl - sts z_h,oph + ldd temp,y+oz_l + ldd temp2,y+oz_h + std y+oz_l,opl + std y+oz_h,oph movw opl,temp ret @@ -1474,15 +1617,19 @@ do_op_exhl: ; do_op_DI: - lds temp,z_istat +#if EM_Z80 + ldd temp,y+oz_istat andi temp,~((1<AF' | do_op_EXAF: - lds temp,z_flags2 - lds temp2,z_a2 - sts z_flags2,z_flags - sts z_a2,z_a + ldd temp,y+oz_f2 + ldd temp2,y+oz_a2 + std y+oz_f2,z_flags + std y+oz_a2,z_a mov z_flags,temp mov z_a,temp2 ret @@ -1698,12 +1845,31 @@ do_op_prefixCB: do_op_prefixDDFDCB: - mem_read_ds temp4,z_pc ;temp4 = displacement - adiw z_pcl,1 ;++z_pc + sbic flags,prefixfd + rjmp opprxcb_fd + ldd xh,y+oz_xh + ldd xl,y+oz_xl + rjmp opprxcb_1 +opprxcb_fd: + ldd xh,y+oz_yh + ldd xl,y+oz_yl +opprxcb_1: + mem_read_s z_pc ;get displacement + adiw z_pcl,1 ;++z_pc + clr temp2 ;sign extend + tst temp + brpl PC+2 + com temp2 + add xl,temp ;add displacement + adc xh,temp2 + mem_read_d opl + mem_read_ds zl,z_pc ;zl = opcode adiw z_pcl,1 ;++z_pc - ldi zh,high(DDFDCBjmp) ; - ijmp + ldi zh,high(DDFDCBjmp) ; + icall + mem_write_s opl + ret #else ; TODO: geht das so? @@ -1945,7 +2111,7 @@ instr fetch_nop, op_EXX, store_nop ;D9 ;EXX instr fetch_DIR16, op_IFC, store_PC ;DA nn nn ;JP C,nn instr fetch_DIR8, op_INA, store_nop ;DB nn ;IN A,(n) instr fetch_DIR16, op_IFC, store_CALL ;DC nn nn ;CALL C,nn -instr fetch_nop, op_prefixDD, store_nop ;DD ;(FD opcode prefix) +instr fetch_nop, op_prefixDD, store_nop ;DD ;(DD opcode prefix) instr fetch_DIR8, op_SBCFA, store_nop ;DE nn ;SBC A,n instr fetch_RST, op_nop, store_CALL ;DF ;RST 18H instr fetch_nop, op_IFPO, store_RET ;E0 ;RET PO @@ -1984,6 +2150,8 @@ instr fetch_RST, op_nop, store_CALL ;FF ;RST 38H #if EM_Z80 + + do_fetch_0: ldi opl,0 ret @@ -2024,7 +2192,7 @@ do_op_in: ; in opl,(opl) do_op_out: ; out (c),opl mov temp,opl - lds temp2,z_c + ldd temp2,y+oz_c lcall portWrite ret @@ -2036,10 +2204,10 @@ do_op_out: ; out (c),opl do_op_stbc: ;store bc to mem loc in opl:h movw xl,opl - lds temp,z_c + ldd temp,y+oz_c mem_write adiw xl,1 - lds temp,z_b + ldd temp,y+oz_b mem_write ret @@ -2051,10 +2219,10 @@ do_op_stbc: ;store bc to mem loc in opl:h ; do_op_stde: ;store de to mem loc in opl:h movw xl,opl - lds temp,z_e + ldd temp,y+oz_e mem_write adiw xl,1 - lds temp,z_d + ldd temp,y+oz_d mem_write ret @@ -2078,8 +2246,8 @@ do_op_stsp: ;store sp to mem loc in opl:h ; do_op_ADCHL: - lds temp,z_l - lds temp2,z_h + ldd temp,y+oz_l + ldd temp2,y+oz_h clc sbrc z_flags,ZFL_C sec @@ -2087,8 +2255,8 @@ do_op_ADCHL: in temp,sreg ; save lower Z adc oph,temp2 in temp2,sreg - sts z_l,opl - sts z_h,oph + std y+oz_l,opl + std y+oz_h,oph and temp,temp2 ; 16bit Z ldi z_flags,0 ; clear N bmov z_flags,ZFL_C, temp2,AVR_C @@ -2105,16 +2273,16 @@ do_op_ADCHL: ; ; do_op_sbchl: - lds temp,z_l - lds temp2,z_h + ldd temp,y+oz_l + ldd temp2,y+oz_h cp temp,opl ; set z clc sbrc z_flags,ZFL_C sec sbc temp,opl sbc temp2,oph - sts z_l,temp - sts z_h,temp2 + std y+oz_l,temp + std y+oz_h,temp2 in temp,sreg ldi z_flags,(1< 1 tst temp2 brne dvp_1 ;don't debug console status @@ -161,13 +163,22 @@ vprw_found: icall rcall printhex printstring " " + pop yl + pop yh ret dvp_2: rcall printhex printstring " " - ijmp ; relative port # in temp3 + ; relative port # in temp3 + icall + pop yl + pop yh + ret .else - ijmp + icall + pop yl + pop yh + ret .endif vprw_exit: @@ -178,6 +189,8 @@ vprw_exit: vport_in_dummy: ldi temp,0xff vport_out_dummy: + pop yl + pop yh ret