X-Git-Url: http://cloudbase.mooo.com/gitweb/avrcpm.git/blobdiff_plain/2639dd192bac61e0c081e7446a12e2a4508b71ca..21347864605f3d413cc202fc7316064554f60c09:/z80.asm diff --git a/z80.asm b/z80.asm old mode 100755 new mode 100644 index 1dca5ca..43ad4e0 --- a/z80.asm +++ b/z80.asm @@ -27,7 +27,6 @@ ;FUSE_L=0xF7 #endif .list - .listmac #ifndef DRAM_DQ_ORDER /* If this is set to 1, the portbits */ @@ -60,6 +59,7 @@ .equ refr_vect = OC2Aaddr #endif +#define DRAM_WORD_ACCESS 1 /* experimental */ #define EM_Z80 0 /* we don't have any z80 instructions yet */ @@ -142,37 +142,45 @@ .equ ZFL_C = 0 ;Register definitions -.def z_a = r2 +.def _tmp = r0 ; 0 +.def _0 = r1 +;.def z_a = r2 .def z_b = r3 .def z_c = r4 .def z_d = r5 .def z_e = r6 .def z_l = r7 .def z_h = r8 -.def z_spl = r9 -.def z_sph = r10 - -.def dsk_trk = r11 -.def dsk_sec = r12 -.def dsk_dmah = r13 -.def dsk_dmal = r14 - -;.def parityb = r15 - -.def temp = R16 ;The temp register -.def temp2 = R17 ;Second temp register -.def trace = r18 -.def opl = r19 -.def oph = r20 -.def adrl = r21 -.def adrh = r22 -.def insdecl = r23 -.def z_pcl = r24 -.def z_pch = r25 -.undef xl -.undef xh -.def insdech = r26 -.def z_flags = r27 +;.def z_spl = r9 +;.def z_sph = r10 + +.def z_a = r11 + + +.def _wl = r12 +.def _wh = r13 +.def z_spl = r14 +.def z_sph = r15 ; +.def temp = r16 ; +.def temp2 = r17 ; +.def temp3 = r18 +.def temp4 = r19 +.def z_flags = r20 ; +.def trace = r21 ; +.def insdecl = r22 ; +.def insdech = r23 ; +.def z_pcl = r24 ; +.def z_pch = r25 ; +.undef xl ;r26 +.undef xh ;r27 +.undef yl ;r28 +.undef yh ;r29 +.def opl = r26 ; +.def oph = r27 ; +.def adrl = r28 ; +.def adrh = r29 ; +; zl ;r30 ; +; zh ;r31 ; ; This is the base z80 port address for clock access @@ -191,6 +199,11 @@ ;SRAM .dseg +dsk_trk: .byte 1 +dsk_sec: .byte 1 +dsk_dmah: .byte 1 +dsk_dmal: .byte 1 + ;Sector buffer for 512 byte reads/writes from/to SD-card sectbuff: @@ -220,21 +233,23 @@ start: ; - Kill wdt wdr #if defined __ATmega8__ - ldi temp,0 - out MCUCSR,temp + out MCUCSR,_0 ldi temp,(1< 0xFF + ;the first answer must be 0x01 (Idle-Mode) cpi temp,0 - breq mmcInitOcrLoopDone + breq mmcInitOcrLoopDone ;second answer is 0x00 (Idle-Mode leave) CMD1 is OK - sbi P_MMC_CS,mmc_cs - rcall mmcByteNoSend + sbi P_MMC_CS,mmc_cs ;disable /CS + +; rcall mmcByteNoSend ;unnecessary + + ldi temp,10 + rcall delay_ms pop temp2 dec temp2 cpi temp2,0 - brne mmcInitOcrLoop + brne mmcInitOcrLoop ;repeat - ldi temp,4 + ldi temp2,4 rjmp mmcWaitErr mmcInitOcrLoopDone: pop temp2 - sbi P_MMC_CS,mmc_cs + sbi P_MMC_CS,mmc_cs ;disable /CS rcall mmcByteNoSend - ldi temp,0 - out SPCR,temp + out SPCR,_0 ret @@ -1142,8 +1122,7 @@ mmcreadloop: sbi P_MMC_CS,mmc_cs rcall mmcByteNoSend - ldi temp,0 - out SPCR,temp + out SPCR,_0 ret @@ -1209,8 +1188,7 @@ mmcwaitwritten: sbi P_MMC_CS,mmc_cs rcall mmcByteNoSend - ldi temp,0 - out SPCR,temp + out SPCR,_0 ret @@ -1234,238 +1212,24 @@ resetwait: ; ------------------ DRAM routines ------------- -; TODO: - -#if DRAM_DQ_ORDER == 1 - #define CLASSIC_DRAM 0 -#else - #define CLASSIC_DRAM 1 /* Change manualy, if you want new hw w/ old sw */ -#endif - - -#if DRAM_DQ_ORDER == 0 - #if CLASSIC_DRAM == 1 - #error "Old harware can not work with new software!" - #endif -#endif - -; **************************************************************************** - -#if CLASSIC_DRAM - -; ********************** DRAM routines from Sprite_tm ************************ - -;Sends the address in zh:zl to the ram -dram_setaddr: - push temp - in temp,portd - andi temp,0x17 - out portd,temp - in temp,portb - andi temp,0xE0 - out portb,temp - sbrc zl,0 - sbi portb,ram_a0 - sbrc zl,1 - sbi portb,ram_a1 - sbrc zl,2 - sbi portb,ram_a2 - sbrc zl,3 - sbi portb,ram_a3 - sbrc zl,4 - sbi portb,ram_a4 - sbrc zl,5 - sbi portd,ram_a5 - sbrc zl,6 - sbi portd,ram_a6 - sbrc zl,7 - sbi portd,ram_a7 - sbrc zh,0 - sbi portd,ram_a8 - pop temp - ret - -dram_getnibble: - andi temp,0xf0 - sbic pinc,ram_d0 - ori temp,0x1 - sbic pinc,ram_d1 - ori temp,0x2 - sbic pinc,ram_d2 - ori temp,0x4 - sbic pinc,ram_d3 - ori temp,0x8 - ret - -dram_sendnibble: - push temp2 - in temp2,portc - andi temp2,~RAM_DQ_MASK - - sbrc temp,0 - ori temp2,(1< |Rotate left/right | +;| [ ] |Indirect addressing | +;| [ ]+ -[ ] |Indirect addressing auto-increment/decrement| +;| { } |Combination of operands | +;| # |Also BC=BC-1,DE=DE-1 | +;| ## |Only lower 4 bits of accumulator A used | +;---------------------------------------------------------------- .equ AVR_T = 6 @@ -2654,11 +2585,8 @@ opjumps: ; (6 words, 8 cycles) .macro ldpmx - ldi zl,low (@1*2) - ldi zh,high(@1*2) - add zl,@2 - brcc PC+2 - inc zh + ldi zh,high(@1*2) ; table must be page aligned + mov zl,@2 lpm @0,z .endm @@ -2764,10 +2692,7 @@ do_op_dec: ; ; do_op_inc16: - inc opl - brne op_i16x - inc oph -op_i16x: + adiw opl,1 ret ;---------------------------------------------------------------- @@ -3003,20 +2928,18 @@ do_op_addhl: ; ; do_op_sthl: ;store hl to mem loc in opl:h - mov adrl,opl - mov adrh,oph + movw adrl,opl +#if DRAM_WORD_ACCESS + mov temp,z_l + mov temp2,z_h + rcall memWriteWord +#else mov temp,z_l rcall memWriteByte - - inc opl - brne op_sthlx - inc oph -op_sthlx: - mov adrl,opl - mov adrh,oph + adiw adrl,1 mov temp,z_h rcall memWriteByte - +#endif ret ;---------------------------------------------------------------- @@ -3026,16 +2949,17 @@ op_sthlx: ; ; do_op_rmem16: - mov adrl,opl - mov adrh,oph + movw adrl,opl +#if DRAM_WORD_ACCESS + rcall memReadWord + movw opl,temp +#else rcall memReadByte mov opl,temp - ldi temp,1 - add adrl,temp - ldi temp,0 - adc adrh,temp + adiw adrl,1 rcall memReadByte mov oph,temp +#endif ret ;---------------------------------------------------------------- @@ -3045,8 +2969,7 @@ do_op_rmem16: ; ; do_op_rmem8: - mov adrl,opl - mov adrh,oph + movw adrl,opl rcall memReadByte mov opl,temp ret @@ -3231,42 +3154,19 @@ do_op_cpl: ; ; do_op_push16: -#if 1 - ldi temp,1 - ldi temp2,0 - sub z_spl,temp - sbc z_sph,temp2 - - mov adrl,z_spl - mov adrh,z_sph - mov temp,oph - rcall memWriteByte - - ldi temp,1 - ldi temp2,0 - sub z_spl,temp - sbc z_sph,temp2 - - mov adrl,z_spl - mov adrh,z_sph + movw adrl,z_spl + subi adrl,2 + sbci adrh,0 + movw z_spl,adrl +#if DRAM_WORD_ACCESS + movw temp,opl + rcall memWriteWord +#else mov temp,opl rcall memWriteByte -#else - subi z_spl,1 - sbci z_sph,0 - - mov adrl,z_spl - mov adrh,z_sph + adiw adrl,1 mov temp,oph rcall memWriteByte - - subi z_spl,1 - sbci z_sph,0 - - mov adrl,z_spl - mov adrh,z_sph - mov temp,opl - rcall memWriteByte #endif .if STACK_DBG @@ -3296,25 +3196,21 @@ do_op_push16: ; ; do_op_pop16: - mov adrl,z_spl - mov adrh,z_sph + movw adrl,z_spl +#if DRAM_WORD_ACCESS + rcall memReadWord + movw opl,temp +#else rcall memReadByte mov opl,temp - - ldi temp,1 - ldi temp2,0 - add z_spl,temp - adc z_sph,temp2 - - mov adrl,z_spl - mov adrh,z_sph + adiw adrl,1 rcall memReadByte mov oph,temp +#endif - ldi temp,1 - ldi temp2,0 + ldi temp,2 add z_spl,temp - adc z_sph,temp2 + adc z_sph,_0 .if STACK_DBG rcall printstr @@ -3538,30 +3434,6 @@ do_op_in: ; in a,(opl) .endif ret -;---------------------------------------------------------------- - -#if 0 -do_op_calcparity: - ldi temp2,1 - sbrc parityb,0 - inc temp2 - sbrc parityb,1 - inc temp2 - sbrc parityb,2 - inc temp2 - sbrc parityb,3 - inc temp2 - sbrc parityb,4 - inc temp2 - sbrc parityb,5 - inc temp2 - sbrc parityb,6 - inc temp2 - sbrc parityb,7 - inc temp2 - andi temp2,1 - ret -#endif ;---------------------------------------------------------------- do_op_inv: @@ -3581,6 +3453,7 @@ haltinv: ; http://z80ex.sourceforge.net/ ; The S, Z, 5 and 3 bits and the parity of the lookup value +.org (PC+255) & 0xff00 sz53p_tab: .db 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c @@ -3624,27 +3497,28 @@ sz53p_tab: ; the fetch operation (bit 0-4), the processing operation (bit 10-16) and the store ; operation (bit 5-9). +.org (PC+255) & 0xff00 inst_table: -.dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 00 NOP -.dw (FETCH_DIR16| OP_NOP | STORE_BC ) ; 01 nn nn LD BC,nn -.dw (FETCH_A | OP_NOP | STORE_MBC ) ; 02 LD (BC),A -.dw (FETCH_BC | OP_INC16 | STORE_BC ) ; 03 INC BC -.dw (FETCH_B | OP_INC | STORE_B ) ; 04 INC B -.dw (FETCH_B | OP_DEC | STORE_B ) ; 05 DEC B -.dw (FETCH_DIR8 | OP_NOP | STORE_B ) ; 06 nn LD B,n -.dw (FETCH_A | OP_RLC | STORE_A ) ; 07 RLCA -.dw (FETCH_NOP | OP_INV | STORE_NOP) ; 08 EX AF,AF' (Z80) -.dw (FETCH_BC | OP_ADDHL | STORE_HL ) ; 09 ADD HL,BC -.dw (FETCH_MBC | OP_NOP | STORE_A ) ; 0A LD A,(BC) -.dw (FETCH_BC | OP_DEC16 | STORE_BC ) ; 0B DEC BC -.dw (FETCH_C | OP_INC | STORE_C ) ; 0C INC C -.dw (FETCH_C | OP_DEC | STORE_C ) ; 0D DEC C -.dw (FETCH_DIR8 | OP_NOP | STORE_C ) ; 0E nn LD C,n -.dw (FETCH_A | OP_RRC | STORE_A ) ; 0F RRCA -.dw (FETCH_NOP | OP_INV | STORE_NOP) ; 10 oo DJNZ o (Z80) +.dw (FETCH_NOP | OP_NOP | STORE_NOP) ; 00 NOP +.dw (FETCH_DIR16| OP_NOP | STORE_BC ) ; 01 nn nn LD BC,nn +.dw (FETCH_A | OP_NOP | STORE_MBC) ; 02 LD (BC),A +.dw (FETCH_BC | OP_INC16 | STORE_BC ) ; 03 INC BC +.dw (FETCH_B | OP_INC | STORE_B ) ; 04 INC B +.dw (FETCH_B | OP_DEC | STORE_B ) ; 05 DEC B +.dw (FETCH_DIR8 | OP_NOP | STORE_B ) ; 06 nn LD B,n +.dw (FETCH_A | OP_RLC | STORE_A ) ; 07 RLCA +.dw (FETCH_NOP | OP_INV | STORE_NOP) ; 08 EX AF,AF' (Z80) +.dw (FETCH_BC | OP_ADDHL | STORE_HL ) ; 09 ADD HL,BC +.dw (FETCH_MBC | OP_NOP | STORE_A ) ; 0A LD A,(BC) +.dw (FETCH_BC | OP_DEC16 | STORE_BC ) ; 0B DEC BC +.dw (FETCH_C | OP_INC | STORE_C ) ; 0C INC C +.dw (FETCH_C | OP_DEC | STORE_C ) ; 0D DEC C +.dw (FETCH_DIR8 | OP_NOP | STORE_C ) ; 0E nn LD C,n +.dw (FETCH_A | OP_RRC | STORE_A ) ; 0F RRCA +.dw (FETCH_NOP | OP_INV | STORE_NOP) ; 10 oo DJNZ o (Z80) .dw (FETCH_DIR16| OP_NOP | STORE_DE ) ; 11 nn nn LD DE,nn .dw (FETCH_A | OP_NOP | STORE_MDE) ; 12 LD (DE),A -.dw (FETCH_DE | OP_INC16 | STORE_DE ) ; 13 INC DE +.dw (FETCH_DE | OP_INC16 | STORE_DE ) ; 13 INC DE .dw (FETCH_D | OP_INC | STORE_D ) ; 14 INC D .dw (FETCH_D | OP_DEC | STORE_D ) ; 15 DEC D .dw (FETCH_DIR8 | OP_NOP | STORE_D ) ; 16 nn LD D,n @@ -3842,7 +3716,7 @@ inst_table: .dw (FETCH_DIR8 | OP_SUBFA | STORE_A ) ; D6 nn SUB n .dw (FETCH_RST | OP_NOP | STORE_CALL) ; D7 RST 10H .dw (FETCH_NOP | OP_IFC | STORE_RET) ; D8 RET C -.dw (FETCH_NOP | OP_INV | STORE_NOP) ; D9 EXX (Z80) +.dw (FETCH_NOP | OP_INV | STORE_NOP) ; D9 EXX (Z80) .dw (FETCH_DIR16| OP_IFC | STORE_PC ) ; DA nn nn JP C,nn .dw (FETCH_DIR8 | OP_IN | STORE_A ) ; DB nn IN A,(n) .dw (FETCH_DIR16| OP_IFC | STORE_CALL) ; DC nn nn CALL C,nn