]> cloudbase.mooo.com Git - avrcpm.git/commitdiff
* avr/z80.asm:
authorLeo <erbl259-lmu@yahoo.de>
Wed, 28 Jul 2010 19:32:31 +0000 (19:32 +0000)
committerLeo <erbl259-lmu@yahoo.de>
Wed, 28 Jul 2010 19:32:31 +0000 (19:32 +0000)
  - Added macro DRAM_WAITSTATES
 - Some clean up in the init code.
 - mmc read/write: Enable 32 bit sector/byte addresses.
 - adrl/adrh are no longer used as dedicated dram adress registers. Replaced by the predefined names yl/yh.
  - added keywords

git-svn-id: svn://cu.loc/avr-cpm/trunk@57 57430480-672e-4586-8877-bcf8adbbf3b7

avrcpm/avr/z80.asm

index 2be56aa35cc438406a5cd0c0e299aae04b59e92e..333350f593409882a5792a05e5356f666c060efb 100644 (file)
@@ -15,6 +15,9 @@
 ;
 ;    You should have received a copy of the GNU General Public License
 ;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;
+;    $Id$
+;
 
 ;.nolist
 #if defined atmega8
@@ -46,6 +49,7 @@
 #define        RXBUFSIZE 64            /* USART recieve buffer size. Must be power of 2 */
 #define        TXBUFSIZE 64            /* USART transmit buffer size. Must be power of 2 */
 
+#define DRAM_WAITSTATES 1      /* Number of additional clock cycles for dram read access */
 #define REFR_RATE   64000       /* dram refresh rate in cycles/s. */
                                /* Most drams need 1/15.6µs. */
 #define REFR_PRE    8           /* timer prescale factor */
 #define REFR_CNT    F_CPU / REFR_RATE / REFR_PRE
 
 
-#if defined __ATmega8__
-       .equ refr_vect = OC2addr
-#else
-       .equ refr_vect = OC2Aaddr
-#endif
 
 #define DRAM_WORD_ACCESS 0     /* experimental */
 
 .equ ZFL_C     =       0
 
 ;Register definitions
-.undef xl              ;r26
-.undef xh              ;r27
 
 .def   _tmp    = r0    ;  0
 .def   _0      = r1
 .def   oph     = r23   ;
 .def   z_pcl   = r24   ;
 .def   z_pch   = r25   ;
-.def   adrl    = r26   ;
-.def   adrh    = r27   ;
 ; yl           ;r28
 ; yh           ;r29
 ; zl           ;r30    ;
 .equ   UBRR0H  = UBRRH
 .equ   UBRR0L  = UBRRL
 .equ   OCR2A   = OCR2
+.equ   OC2Aaddr= OC2addr
 .equ   TCCR2A  = TCCR2
 .equ   TCCR2B  = TCCR2
 .equ   TIMSK1  = TIMSK
 
 
 
+;----------------------------------------
+; add wait states
+;      dram_wait  number_of_cycles
+
+.macro dram_wait
+.if @0 > 1
+       rjmp    PC+1
+       dram_wait @0 - 2
+.elif @0 > 0
+       nop
+       dram_wait @0 - 1
+.endif
+.endm
+
+
 .cseg
 .org 0
        rjmp start              ; reset vector
-.org refr_vect
+.org OC2Aaddr
        rjmp refrint            ; tim2cmpa
 .org OC1Aaddr                  ; Timer/Counter1 Compare Match A
        rjmp sysclockint        ; 1ms system timer
@@ -279,6 +290,17 @@ start:
        ldi temp,(1<<WDCE)
        outm8   WDTCSR,temp
 
+; - Clear RAM
+
+       ldi     zl,low(SRAM_START)
+       ldi     zh,high(SRAM_START)
+       ldi     temp2,high(ramtop)
+clr_l:
+       st      z+,_0
+       cpi     zl,low(ramtop)
+       cpc     zh,temp2
+       brne    clr_l
+
 ; - Setup Ports
        ldi     temp,(1<<PUD)           ;disable pullups
        outm8   P_PUD,temp
@@ -298,13 +320,6 @@ start:
 
 ; - Init serial port
 
-       sts     rxcount,_0      ; reset receive buffer
-       sts     rxidx_r,_0
-       sts     rxidx_w,_0
-       sts     txcount,_0      ; reset transmit buffer
-       sts     txidx_r,_0
-       sts     txidx_w,_0
-       
        ldi temp, (1<<TXEN0) | (1<<RXEN0) | (1<<RXCIE0)
        outm8 UCSR0B,temp
 .ifdef URSEL
@@ -318,30 +333,8 @@ start:
        ldi temp, LOW(UBRR_VAL)
        outm8 UBRR0L,temp
 
-;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
-
-       ldi     temp,REFR_CNT*2                 ; 2 cycles per int
-       outm8   OCR2A,temp
-       inm8    temp,TCCR2A
-       ori     temp,(1<<WGM21)                 ;CTC mode
-       outm8   TCCR2A,temp
-       inm8    temp,TCCR2B
-       ori     temp,REFR_CS                    ;clk/REFR_PRE
-       outm8   TCCR2B,temp
-       inm8    temp,TIMSK2
-       ori     temp, (1<<OCIE2A)
-       outm8   TIMSK2,temp
-
 ; Init clock/timer system
 
-       ldi     zl,low(timer_base)
-       ldi     zh,high(timer_base)
-       ldi     temp2,timer_size
-ti_loop:
-       st      z+,_0
-       dec     temp2
-       brne    ti_loop
-
 ; Init timer 1 as 1 ms system clock tick.
 
        ldi     temp,high(F_CPU/1000)
@@ -354,6 +347,20 @@ ti_loop:
        ori     temp,(1<<OCIE1A)
        outm8   TIMSK1,temp
 
+;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
+
+       ldi     temp,REFR_CNT*2                 ; 2 cycles per int
+       outm8   OCR2A,temp
+       inm8    temp,TCCR2A
+       ori     temp,(1<<WGM21)                 ;CTC mode
+       outm8   TCCR2A,temp
+       inm8    temp,TCCR2B
+       ori     temp,REFR_CS                    ;clk/REFR_PRE
+       outm8   TCCR2B,temp
+       inm8    temp,TIMSK2
+       ori     temp, (1<<OCIE2A)
+       outm8   TIMSK2,temp
+
        sei
 
 
@@ -377,13 +384,13 @@ ti_loop:
        .db "Testing RAM: fill...",0,0
 
 ;Fill RAM
-       ldi adrl,0
-       ldi adrh,0
+       ldi xl,0
+       ldi xh,0
 ramtestw:
-       mov temp,adrh
-       eor temp,adrl
+       mov temp,xh
+       eor temp,xl
        rcall memwritebyte
-       adiw adrl,1
+       adiw xl,1
        brcc ramtestw
        rcall printstr
        .db "wait...",0
@@ -399,61 +406,63 @@ ramtestwl:
        .db "reread...",13,0,0
 
 ;re-read RAM
-       ldi adrl,0
-       ldi adrh,0
+       ldi xl,0
+       ldi xh,0
 ramtestr:
        rcall memReadByte
-       mov temp2,adrh
-       eor temp2,adrl
+       mov temp2,xh
+       eor temp2,xl
        cp temp,temp2
        breq ramtestrok
        rcall printhex
        ldi temp,'<'
        rcall uartPutc
-       mov temp,adrh
-       eor temp,adrl
+       mov temp,xh
+       eor temp,xl
        rcall printhex
        ldi temp,'@'
        rcall uartPutc
-       mov temp,adrh
+       mov temp,xh
        rcall printhex
-       mov temp,adrl
+       mov temp,xl
        rcall printhex
        ldi temp,13
        rcall uartPutc
 ramtestrok:
-       adiw adrl,1
+       adiw xl,1
        brcc ramtestr
 
 .endif
 
 .if MEMFILL_CB
        ;Fill ram with cbs, which (for now) will trigger an invalid opcode error.
-       ldi adrl,0
-       ldi adrh,0
+       ldi xl,0
+       ldi xh,0
 ramfillw:
        ldi temp,0xcb
        rcall memwritebyte
-       adiw adrl,1
+       adiw xl,1
        brcc ramfillw
 .endif
 
 
 
 ;Load initial sector from MMC (512 bytes)
-       ldi adrh,0
-       ldi adrl,0
-       rcall mmcReadSect
+       ldi     yh,0
+       ldi     yl,0
+       ldi     xh,0
+       ldi     xl,0
+       rcall   mmcReadSect
 
 ;Save to Z80 RAM (only 128 bytes because that's retro)
        ldi zl,low(hostbuf)
        ldi zh,high(hostbuf)
-       ldi adrh,0x20
-       ldi adrl,0x00
+       ldi xh,0x20
+       ldi xl,0x00
 iplwriteloop:
        ld temp,z+
        rcall memWriteByte
-       adiw adrl,1
+       adiw xl,1
        cpi zl,low(hostbuf+128)
        brne iplwriteloop
        cpi zh,high(hostbuf+128)
@@ -499,7 +508,7 @@ noprintpc:
 .endif
 
        ; *** Stage 1: Fetch next opcode
-       movw adrl,z_pcl
+       movw xl,z_pcl
        rcall memReadByte
 
 
@@ -642,8 +651,8 @@ notrace6:
 ;18    - Sector select
 ;20    - Write addr l
 ;21    - Write addr h
-;22    - Trigger - write 1 to read, 2 to write a sector using the above info;
-;                      3 - 5, write to allocated/dirctory/unallocated
+;22    - Trigger - write  to read, to write a sector using the above info;
+;                      , write to allocated/dirctory/unallocated
 
        .equ    READ_FUNC  = 7
        .equ    WRITE_FUNC = 6
@@ -968,35 +977,30 @@ dsk_rwoper:
 
        ;Convert track/sector to an LBA address (in 128byte blocks)
 
-       lds     adrl,seeksec            ;
-       ldi     adrh,0                  ;
+       lds     xl,seeksec              ;
+       ldi     xh,0                    ;
        lds     temp3,seektrk           ;
        lds     temp4,seektrk+1         ;
        ldi     temp,CPMSPT             ;
        mul     temp3,temp              ;
-       add     adrl,r0                 ;
-       adc     adrh,r1                 ;
+       add     xl,r0                   ;
+       adc     xh,r1                   ;
        mul     temp4,temp              ;
-       add     adrh,r0                 ;adrh:adrl := sec + trk * SectorsPerTrack
+       add     xh,r0                   ;xh:xl := sec + trk * SectorsPerTrack
        clr     _0
 
-       mov     temp,adrl
+       mov     temp,xl
        andi    temp,SECMSK             ;mask buffer number
        push    temp                    ;save for later
-.if DISK_DEBUG
-       rcall printstr
-       .db "; bufnr: ",0,0
-       rcall printhex
-.endif
 
        ;Convert from CP/M LBA blocks to host LBA blocks
        ldi temp,SECSHF
 dsk_sh1:
-       lsr     adrh
-       ror     adrl
+       lsr     xh
+       ror     xl
        dec     temp
        brne    dsk_sh1
-                                       ;adrh:adrl = host block to seek
+                                       ;xh:xl = host block to seek
 ;      active host sector?
        sbis    flags,hostact           ;host active?
         rjmp   dsk_filhst              ;fill host if not
@@ -1010,8 +1014,8 @@ dsk_sh1:
 ;      same disk, same block?
        lds     temp3,hostlba
        lds     temp4,hostlba+1
-       cp      adrl,temp3
-       cpc     adrh,temp4      
+       cp      xl,temp3
+       cpc     xh,temp4        
        breq    dsk_match
 ;
 dsk_nomatch:
@@ -1023,8 +1027,8 @@ dsk_filhst:
        ;may have to fill the host buffer
        lds     temp,seekdsk
        sts     hostdsk,temp
-       sts     hostlba,adrl
-       sts     hostlba+1,adrh
+       sts     hostlba,xl
+       sts     hostlba+1,xh
 
        sbic    flags,rsflag            ;need to read?
         rcall  dsk_readhost            ;yes, if 1
@@ -1054,31 +1058,29 @@ dsk_match:
 .endif
        clr     _0
 
-       lds     adrl,dmaadr
-       lds     adrh,dmaadr+1
-       push    yl
-       ldi     yl,128                  ;length of move
+       lds     xl,dmaadr
+       lds     xh,dmaadr+1
+       ldi     temp3,128                       ;length of move
        sbic    flags,readop            ;which way?
         rjmp   dsk_rmove               ;skip if read
 
 ;      mark write operation
        sbi     flags,hostwrt           ;hostwrt = 1
 dsk_wmove:
-       rcall memReadByte
-       st z+,temp
-       adiw adrl,1
-       dec yl
+       rcall   memReadByte
+       st      z+,temp
+       adiw    xl,1
+       dec     temp3
        brne dsk_wmove
        rjmp    dsk_rwmfin
        
 dsk_rmove:
        ld      temp,z+
        rcall   memWriteByte
-       adiw    adrl,1
-       dec     yl
+       adiw    xl,1
+       dec     temp3
        brne    dsk_rmove
 dsk_rwmfin:
-       pop     yl
 ;      data has been moved to/from host buffer
        lds     temp,wrtype     ;write type
        cpi     temp,WRDIR      ;to directory?
@@ -1115,13 +1117,19 @@ dsk_writehost:
        ;error flag in erflag.
        ;Return erflag non-zero if error
        
-       push    adrh
-       push    adrl
-       lds     adrl,hostlba
-       lds     adrh,hostlba+1
+       push    yh
+       push    yl
+       push    xh
+       push    xl
+       lds     xl,hostlba
+       lds     xh,hostlba+1
+       ldi     yl,0
+       ldi     yh,0
        rcall   mmcWriteSect
-       pop     adrl
-       pop     adrh
+       pop     xl
+       pop     xh
+       pop     yl
+       pop     yh
        sts     erflag,_0
        ret
 
@@ -1130,13 +1138,19 @@ dsk_readhost:
        ;Read "hostsiz" bytes into hostbuf and return 
        ;error flag in erflag.
 
-       push    adrh
-       push    adrl
-       lds     adrl,hostlba
-       lds     adrh,hostlba+1
+       push    yh
+       push    yl
+       push    xh
+       push    xl
+       lds     xl,hostlba
+       lds     xh,hostlba+1
+       ldi     yl,0
+       ldi     yh,0
        rcall   mmcReadSect
-       pop     adrl
-       pop     adrh
+       pop     xl
+       pop     xh
+       pop     yl
+       pop     yh
        sts     erflag,_0
        ret
 
@@ -1150,8 +1164,6 @@ mmcByteNoSend:
 mmcByte:
 
 .if MMC_DEBUG
-       push zl
-       push zh
        rcall printstr
        .db "MMC: <--",0
        rcall printhex
@@ -1165,15 +1177,11 @@ mmcWrByteW:
        in temp,SPDR
 
 .if MMC_DEBUG
-       push temp
        rcall printstr
        .db ", -->",0
        rcall printhex
        rcall printstr
        .db ".",13,0
-       pop temp
-       pop zh
-       pop zl
 .endif
        ret
 
@@ -1310,8 +1318,8 @@ mmcInitOcrLoopDone:
        ret
 
 
-;Call this with adrh:adrl = sector number
-;16bit lba address means a max reach of 32M.
+;Call this with yh:yl:xh:xl = sector number
+;
 mmcReadSect:
        ldi temp,0x50
        out SPCR,temp
@@ -1320,14 +1328,14 @@ mmcReadSect:
        rcall mmcByteNoSend
        ldi temp,0x51   ;cmd (read sector)
        rcall mmcByte
-       ldi temp,0
-       lsl adrl
-       rol adrh
-       rol temp
+       lsl     xl                      ;convert to byte address (*512)
+       rol     xh
+       rol     yl
+       mov     temp,yl
        rcall mmcByte
-       mov temp,adrh ;pxl
+       mov temp,xh ;pxl
        rcall mmcByte
-       mov temp,adrl ;pyh
+       mov temp,xl ;pyh
        rcall mmcByte
        ldi temp,0  ;pyl
        rcall mmcByte
@@ -1366,8 +1374,8 @@ mmcreadloop:
        ret
 
 
-;Call this with adrh:adrl = sector number
-;16bit lba address means a max reach of 32M.
+;Call this with yh:yl:xh:xl = sector number
+;
 mmcWriteSect:
        ldi temp,0x50
        out SPCR,temp
@@ -1377,14 +1385,14 @@ mmcWriteSect:
 
        ldi temp,0x58   ;cmd (write sector)
        rcall mmcByte
-       ldi temp,0
-       lsl adrl
-       rol adrh
-       rol temp
+       lsl     xl                      ;convert to byte address (*512)
+       rol     xh
+       rol     yl
+       mov     temp,yl
        rcall mmcByte
-       mov temp,adrh ;pxl
+       mov temp,xh ;pxl
        rcall mmcByte
-       mov temp,adrl ;pyh
+       mov temp,xl ;pyh
        rcall mmcByte
        ldi temp,0  ;pyl
        rcall mmcByte
@@ -1463,24 +1471,24 @@ resetwait:
        out P_AH,temp
 .endm
 
-;Loads the byte on address adrh:adrl into temp.
-;must not alter adrh:adrl
+;Loads the byte on address xh:xl into temp.
+;must not alter xh:xl
 
 dram_read:
        cli
-       DRAM_SETADDR adrh, ~0,(1<<ram_ras), ~(1<<ram_a8), (1<<ram_oe)
+       DRAM_SETADDR xh, ~0,(1<<ram_ras), ~(1<<ram_a8), (1<<ram_oe)
        cbi P_RAS,ram_ras
-       DRAM_SETADDR adrl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
+       DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
        cbi P_CAS,ram_cas
        cbi P_A8,ram_a8
-       nop
+       dram_wait DRAM_WAITSTATES       ;
        in  temp,P_DQ-2         ; PIN
        sbi P_CAS,ram_cas
 
        cbi P_CAS,ram_cas
        andi temp,0x0f
        swap temp
-       nop
+       dram_wait DRAM_WAITSTATES       ;
        in  temp2,P_DQ-2        ; PIN
        andi temp2,0x0f
        or  temp,temp2
@@ -1493,12 +1501,12 @@ dram_read:
 
 #if DRAM_WORD_ACCESS
 dram_read_w:
-       cpi adrl,255
+       cpi xl,255
        brne dram_read_w1
        
        rcall dram_read
        push temp
-       adiw adrl,1
+       adiw xl,1
        rcall dram_read
        mov temp2,temp
        pop temp
@@ -1506,9 +1514,9 @@ dram_read_w:
 
 dram_read_w1:
        cli
-       DRAM_SETADDR adrh, ~0,(1<<ram_ras), ~(1<<ram_a8),(1<<ram_oe)
+       DRAM_SETADDR xh, ~0,(1<<ram_ras), ~(1<<ram_a8),(1<<ram_oe)
        cbi P_RAS,ram_ras
-       DRAM_SETADDR adrl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
+       DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
        cbi P_CAS,ram_cas
        cbi P_A8,ram_a8
        nop
@@ -1525,8 +1533,8 @@ dram_read_w1:
        
 ;      push temp
        mov _wl,temp
-       inc adrl
-       DRAM_SETADDR adrl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
+       inc xl
+       DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
        cbi P_CAS,ram_cas
        cbi P_A8,ram_a8
        nop
@@ -1549,8 +1557,8 @@ dram_read_w1:
        ret
 #endif
 
-;Writes the byte in temp to  adrh:adrl
-;must not alter adrh:adrl
+;Writes the byte in temp to  xh:xl
+;must not alter xh:xl
 
 dram_write:
        cli
@@ -1561,9 +1569,9 @@ dram_write:
        andi temp,RAM_DQ_MASK & ~(1<<ram_w)
        ori temp,(1<<ram_cas)
        out PORTC,temp
-       DRAM_SETADDR adrh, ~0,(1<<ram_ras), ~(1<<ram_a8),(1<<ram_oe)
+       DRAM_SETADDR xh, ~0,(1<<ram_ras), ~(1<<ram_a8),(1<<ram_oe)
        cbi P_RAS,ram_ras
-       DRAM_SETADDR adrl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
+       DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
        cbi PORTC,ram_cas
        sbi PORTC,ram_cas
 
@@ -1585,13 +1593,13 @@ dram_write:
 
 #if DRAM_WORD_ACCESS
 dram_write_w:
-       cpi adrl,255
+       cpi xl,255
        brne dram_write_w1
        
        push temp2
        rcall dram_write
        pop temp
-       adiw adrl,1
+       adiw xl,1
        rcall dram_write
        ret     
 
@@ -1606,9 +1614,9 @@ dram_write_w1:
        ori temp,(1<<ram_cas)
        out PORTC,temp
 
-       DRAM_SETADDR adrh, ~0,(1<<ram_ras), ~(1<<ram_a8),(1<<ram_oe)
+       DRAM_SETADDR xh, ~0,(1<<ram_ras), ~(1<<ram_a8),(1<<ram_oe)
        cbi P_RAS,ram_ras
-       DRAM_SETADDR adrl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
+       DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
        cbi PORTC,ram_cas
        sbi PORTC,ram_cas
 
@@ -1623,13 +1631,13 @@ dram_write_w1:
        sbi PORTC,ram_cas
 
        pop temp
-       inc adrl
+       inc xl
        mov  temp2,temp
        andi temp,RAM_DQ_MASK & ~(1<<ram_w)
        ori temp,(1<<ram_cas)
        out PORTC,temp
 
-       DRAM_SETADDR adrl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
+       DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
        cbi PORTC,ram_cas
        sbi PORTC,ram_cas
 
@@ -1663,6 +1671,7 @@ refrint:
 ;      nop                     ;1      |0   |0   
        sbi P_RAS,ram_ras       ;2      |0   |0   
                                ;       |0   |0   
+       dram_wait DRAM_WAITSTATES-1     ;
 ;      nop                     ;1      |0   |0   
        cbi P_RAS,ram_ras       ;2      |0    1|  
                                ;       |0    1|  
@@ -1672,7 +1681,6 @@ refrint:
                                ;        1|   1|  
        reti                    ;4  --> 21 cycles
 
-; ****************************************************************************
 
 ; ------------- system timer 1ms ---------------
     .dseg
@@ -2107,6 +2115,7 @@ rxfifo:
 txfifo:
        .byte   TXBUFSIZE
 
+ramtop:                
        .cseg
 
 ; Save received character in a circular buffer. Do nothing if buffer overflows.
@@ -2341,53 +2350,53 @@ do_fetch_sp:
        ret
 
 do_fetch_mbc:
-       movw adrl,z_c
+       movw xl,z_c
        rcall memReadByte
        mov opl,temp
        ret
 
 do_fetch_mde:
-       movw adrl,z_e
+       movw xl,z_e
        rcall memReadByte
        mov opl,temp
        ret
 
 do_fetch_mhl:
-       movw adrl,z_l
+       movw xl,z_l
        rcall memReadByte
        mov opl,temp
        ret
 
 do_fetch_msp:
-       movw adrl,z_spl
+       movw xl,z_spl
 #if DRAM_WORD_ACCESS
        rcall memReadWord
        movw opl,temp
 #else
        rcall memReadByte
        mov opl,temp
-       adiw adrl,1
+       adiw xl,1
        rcall memReadByte
        mov oph,temp
 #endif 
        ret
 
 do_fetch_dir8:
-       movw adrl,z_pcl
+       movw xl,z_pcl
        rcall memReadByte
        adiw z_pcl,1
        mov opl,temp
        ret
 
 do_fetch_dir16:
-       movw adrl,z_pcl
+       movw xl,z_pcl
 #if DRAM_WORD_ACCESS
        rcall memReadWord
        movw opl,temp
 #else
        rcall memReadByte
        mov opl,temp
-       adiw adrl,1
+       adiw xl,1
        rcall memReadByte
        mov oph,temp
 #endif 
@@ -2395,9 +2404,9 @@ do_fetch_dir16:
        ret
 
 do_fetch_rst:
-       movw adrl,z_pcl
-       subi adrl,1
-       sbci adrh,0
+       movw xl,z_pcl
+       subi xl,1
+       sbci xh,0
        rcall memReadByte
        andi temp,0x38
        ldi oph,0
@@ -2507,32 +2516,32 @@ do_store_hl:
        ret
 
 do_store_mbc:
-       movw adrl,z_c
+       movw xl,z_c
        mov temp,opl
        rcall memWriteByte
        ret
 
 do_store_mde:
-       movw adrl,z_e
+       movw xl,z_e
        mov temp,opl
        rcall memWriteByte
        ret
 
 do_store_mhl:
-       movw adrl,z_l
+       movw xl,z_l
        mov temp,opl
        rcall memWriteByte
        ret
 
 do_store_msp:
-       movw adrl,z_spl
+       movw xl,z_spl
 #if DRAM_WORD_ACCESS
        movw temp,opl
        rcall memWriteWord
 #else
        mov temp,opl
        rcall memWriteByte
-       adiw adrl,1
+       adiw xl,1
        mov temp,oph
        rcall memWriteByte
 #endif
@@ -2561,7 +2570,7 @@ do_store_call:
        ret
 
 do_store_am:
-       movw adrl,opl
+       movw xl,opl
        mov temp,z_a
        rcall memWriteByte
        ret
@@ -2843,13 +2852,13 @@ opjumps:
 ;----------------------------------------------------------------
 
 
-.equ AVR_T = 6
-.equ AVR_H = 5
-.equ AVR_S = 4
-.equ AVR_V = 3
-.equ AVR_N = 2
-.equ AVR_Z = 1
-.equ AVR_C = 0
+.equ AVR_T = SREG_T
+.equ AVR_H = SREG_H
+.equ AVR_S = SREG_S
+.equ AVR_V = SREG_V
+.equ AVR_N = SREG_N
+.equ AVR_Z = SREG_Z
+.equ AVR_C = SREG_C
 
 ;------------------------------------------------;
 ; Move single bit between two registers
@@ -3251,14 +3260,14 @@ do_op_addhl:
 ;
 ;
 do_op_sthl: ;store hl to mem loc in opl:h
-       movw adrl,opl
+       movw xl,opl
 #if DRAM_WORD_ACCESS
        movw temp,z_l
        rcall memWriteWord
 #else
        mov temp,z_l
        rcall memWriteByte
-       adiw adrl,1
+       adiw xl,1
        mov temp,z_h
        rcall memWriteByte
 #endif
@@ -3271,14 +3280,14 @@ do_op_sthl: ;store hl to mem loc in opl:h
 ;
 ; 
 do_op_rmem16:
-       movw adrl,opl
+       movw xl,opl
 #if DRAM_WORD_ACCESS
        rcall memReadWord
        movw opl,temp
 #else
        rcall memReadByte
        mov opl,temp
-       adiw adrl,1
+       adiw xl,1
        rcall memReadByte
        mov oph,temp
 #endif 
@@ -3291,7 +3300,7 @@ do_op_rmem16:
 ;
 ;
 do_op_rmem8:
-       movw adrl,opl
+       movw xl,opl
        rcall memReadByte
        mov opl,temp
        ret
@@ -3476,17 +3485,17 @@ do_op_cpl:
 ;
 ;
 do_op_push16:
-       movw adrl,z_spl
-       subi adrl,2
-       sbci adrh,0
-       movw z_spl,adrl
+       movw xl,z_spl
+       subi xl,2
+       sbci xh,0
+       movw z_spl,xl
 #if DRAM_WORD_ACCESS   
        movw temp,opl
        rcall memWriteWord
 #else
        mov temp,opl
        rcall memWriteByte
-       adiw adrl,1
+       adiw xl,1
        mov temp,oph
        rcall memWriteByte
 #endif
@@ -3518,14 +3527,14 @@ do_op_push16:
 ;
 ;
 do_op_pop16:
-       movw adrl,z_spl
+       movw xl,z_spl
 #if DRAM_WORD_ACCESS
        rcall memReadWord
        movw opl,temp
 #else
        rcall memReadByte
        mov opl,temp
-       adiw adrl,1
+       adiw xl,1
        rcall memReadByte
        mov oph,temp
 #endif