]> cloudbase.mooo.com Git - avrcpm.git/commitdiff
* Z80/8080 registers BC, DE, HL moved from RAM to AVR CPU registers. 'temp4' removed.
authorLeo <erbl259-lmu@yahoo.de>
Sat, 30 Mar 2013 08:07:20 +0000 (08:07 +0000)
committerLeo <erbl259-lmu@yahoo.de>
Sat, 30 Mar 2013 08:07:20 +0000 (08:07 +0000)
* Parameter for 'print_ultoa' (32 bit integer) moved from 'temp4:temp3:temp2:temp' to 'r15:r14:temp2:temp'.
* init.asm: Do not set global pullup disable bit ('PUD'). Enable pullup on RXD pin.
* Do not disable interrupts on DRAM access.

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

16 files changed:
avr/Makefile
avr/Z80int-jmp.asm
avr/config.inc
avr/dram-8bit.asm
avr/dram-8bit.inc
avr/dsk_cpm.asm
avr/dsk_fat16.asm
avr/dsk_fsys.asm
avr/dsk_mgr.asm
avr/heap.asm
avr/i2c.asm
avr/init.asm
avr/mmc.asm
avr/timer.asm
avr/utils.asm
avr/virt_ports.asm

index 7c0328fee51dc981597773b2c3a53e240afc7a0f..b4fdfdc8e8cf64e91179631d30d8ced093275ed8 100644 (file)
@@ -11,7 +11,8 @@ MCU = atmega328P
 #DRAM_8BIT = 0
 #BAUD = 57600
 #BAUD = 115200
-#I2C = 0
+I2C_SUPPORT = 0
+#ADC_SUPPORT = 0
 #EM_Z80        = 0
 #FAT16_SUPPORT = 0
 #MMCBOOTLOADER = 0
@@ -51,8 +52,11 @@ endif
 ifdef BAUD
   CDEFS += -DBAUD=$(BAUD)
 endif
-ifdef I2C
-  CDEFS += -DI2C=$(I2C)
+ifdef I2C_SUPPORT
+  CDEFS += -DI2C_SUPPORT=$(I2C_SUPPORT)
+endif
+ifdef ADC_SUPPORT
+  CDEFS += -DADC_SUPPORT=$(ADC_SUPPORT)
 endif
 ifdef EM_Z80
   CDEFS += -DEM_Z80=$(EM_Z80)
index e2f8ea458ad55cec1b81fb10d1b72b50a9a06a29..675b287b8502b4940c808f1dca667c68adea0113 100644 (file)
 ;    $Id$
 ;
 
+#if EM_Z80
+
        .dseg
 z_regs:        
-z_b:   .byte   1
-z_c:   .byte   1
-z_d:   .byte   1
-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_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
-z_yh:  .byte   1
-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
+z_c2:
+       .equ    oz_c2 = z_c2 - z_regs
+       .byte   1
+z_b2:
+       .equ    oz_b2 = z_b2 - z_regs
+       .byte   1
+z_e2:
+       .equ    oz_e2 = z_e2 - z_regs
+       .byte   1
+z_d2:
+       .equ    oz_d2 = z_d2 - z_regs
+       .byte   1
+z_l2:
+       .equ    oz_l2 = z_l2 - z_regs
+       .byte   1
+z_h2:
+       .equ    oz_h2 = z_h2 - z_regs
+       .byte   1
+z_f2:
+       .equ    oz_f2 = z_f2 - z_regs
+       .byte   1
+z_a2:
+       .equ    oz_a2 = z_a2 - z_regs
+       .byte   1
+
+z_xl:
+       .equ    oz_xl = z_xl - z_regs
+       .byte   1
+z_xh:
+       .equ    oz_xh = z_xh - z_regs
+       .byte   1
+z_yl:
+       .equ    oz_yl = z_yl - z_regs
+       .byte   1
+z_yh:
+       .equ    oz_yh = z_yh - z_regs
+       .byte   1
+z_i:
+       .equ    oz_i  = z_i - z_regs
+       .byte   1
+z_r:
+       .equ    oz_r  = z_r - z_regs
+       .byte   1
+
+z_istat:
+       .equ    oz_istat = z_istat - z_regs
+       .byte   1
 
        .equ IM_MASK = 0x03             ;Mask IM 0..2
        .equ IM0     = 0
@@ -84,7 +83,6 @@ z_istat: .byte        1
 
        .equ IFF1 = 2                   ;IFF1 Flag
        .equ IFF2 = 3                   ;IFF2 Flag
-
 #endif
 
        .cseg
@@ -94,7 +92,6 @@ z80_init:
        ldiw    z_pc,IPLADDR
        ldiw    y,z_regs
 
-       cbi     flags,trace
        clr     intstat
 
        printnewline
@@ -124,7 +121,7 @@ noprintpc:
 
        ;TODO: hier kommt die Interruptbehandlung rein
 
-       cpse    intstat,_0              ;Fast path if no trace, int, break, ...
+       cpse    intstat,_0                      ;Fast path if no trace, int, break, ...
        rjmp    int_test
 
 int_instr:
@@ -137,6 +134,8 @@ int_instr:
 int_test:
        sbrs    intstat,i_trace
        rjmp    int_notrace
+       sbrs    intstat,i_halt
+       rjmp    int_notrace
        cpi     z_pch,DBG_TRACE_BOTTOM
        brlo    int_notrace
        cpi     z_pch,DBG_TRACE_TOP
@@ -372,23 +371,25 @@ do_fetch_rst:
 ;      ret
 
 .macro m_do_fetch_b
-       ldd opl,y+oz_b
+       mov     opl,z_b
 .endm
 
 .equ do_fetch_b = 0
+;      mov     opl,z_b
 ;      ldd opl,y+oz_b
 ;      ret
 
 .macro m_do_fetch_c
-       ldd     opl,y+oz_c
+       mov     opl,z_c
 .endm
 
 .equ do_fetch_c = 0
+;      mov     opl,z_c
 ;      ldd     opl,y+oz_c
 ;      ret
 
 .macro m_do_fetch_d
-       ldd     opl,y+oz_d
+       mov     opl,z_d
 .endm
 
 .equ do_fetch_d = 0
@@ -396,7 +397,7 @@ do_fetch_rst:
 ;      ret
 
 .macro m_do_fetch_e
-       ldd     opl,y+oz_e
+       mov     opl,z_e
 .endm
 
 .equ do_fetch_e = 0
@@ -404,41 +405,50 @@ do_fetch_rst:
 ;      ret
 
 .macro m_do_fetch_h
-       ldd     opl,y+oz_h
+       mov     opl,z_h
 .endm
 
 .equ do_fetch_h = 0
-;      ldd     opl,y+oz_h
+;      mov     opl,z_h
 ;      ret
 
 .macro m_do_fetch_l
-       ldd     opl,y+oz_l
+       mov     opl,z_l
 .endm
 
 .equ do_fetch_l = 0
-;      ldd     opl,y+oz_l
+;      mov     opl,z_l
 ;      ret
 
 do_fetch_af:
-       mov opl,z_flags
-       mov oph,z_a
+       movw    opl,z_flags
        ret
 
-do_fetch_bc:
-       ldd     opl,y+oz_c
-       ldd     oph,y+oz_b
-       ret
+.macro m_do_fetch_bc
+       movw    opl,z_c
+.endm
 
-do_fetch_de:
-       ldd     opl,y+oz_e
-       ldd     oph,y+oz_d
-       ret
+.equ do_fetch_bc = 0
+;      movw    opl,z_c
+;      ret
+
+.macro m_do_fetch_de
+       movw    opl,z_e
+.endm
 
-do_fetch_hl:
-       ldd     opl,y+oz_l
-       ldd     oph,y+oz_h
+.equ do_fetch_de = 0
+;      ldd     opl,y+oz_e
+;      ldd     oph,y+oz_d
        ret
 
+.macro m_do_fetch_hl
+       movw    opl,z_l
+.endm
+
+.equ do_fetch_hl = 0
+;      movw    opl,z_l
+;      ret
+
 .macro m_do_fetch_sp
        movw opl,z_spl
 .endm
@@ -448,20 +458,19 @@ do_fetch_hl:
 ;      ret
 
 do_fetch_mbc:
-       ldd     xh,y+oz_b
-       ldd     xl,y+oz_c
+       movw    x,z_c
        mem_read_d z_a
        ret
 
 do_fetch_mde:
-       ldd     xh,y+oz_d
-       ldd     xl,y+oz_e
+       movw    x,z_e
+;      ldd     xh,y+oz_d
+;      ldd     xl,y+oz_e
        mem_read_d z_a
        ret
 
 do_fetch_mhl:
-       ldd     xh,y+oz_h
-       ldd     xl,y+oz_l
+       movw    x,z_l
        mem_read_d opl
        ret
 
@@ -499,64 +508,61 @@ do_store_a:
 ;.endm
 ;.equ do_store_b = 0
 do_store_b:
-       std     y+oz_b,opl
+       mov     z_b,opl
        ret
 
 do_store_c:
-       std     y+oz_c,opl
+       mov     z_c,opl
        ret
 
 do_store_d:
-       std     y+oz_d,opl
+       mov     z_d,opl
        ret
 
 do_store_e:
-       std     y+oz_e,opl
+       mov     z_e,opl
        ret
 
 do_store_h:
-       std     y+oz_h,opl
+       mov     z_h,opl
        ret
 
 do_store_l:
-       std     y+oz_l,opl
+       mov     z_l,opl
        ret
 
 do_store_af:
-       mov z_a,oph
-       mov z_flags,opl
+       movw z_flags,opl
        ret
 
 do_store_bc:
-       std     y+oz_b,oph
-       std     y+oz_c,opl
+       movw    z_c,opl
        ret
 
 do_store_de:
-       std     y+oz_d,oph
-       std     y+oz_e,opl
+       movw    z_e,opl
+;      std     y+oz_d,oph
+;      std     y+oz_e,opl
        ret
 
 do_store_hl:
-       std     y+oz_h,oph
-       std     y+oz_l,opl
+       movw    z_l,opl
        ret
 
 do_store_mbc:
-       ldd     xh,y+oz_b
-       ldd     xl,y+oz_c
+       movw    x,z_c
        mem_write_s z_a
        ret
 
 do_store_mde:
-       ldd     xh,y+oz_d
-       ldd     xl,y+oz_e
+       movw    x,z_e
+;      ldd     xh,y+oz_d
+;      ldd     xl,y+oz_e
        mem_write_s z_a
        ret
 
 do_store_mhl:
-       ldd     xh,y+oz_h
-       ldd     xl,y+oz_l
+       movw    x,z_l
        mem_write_s opl
        ret
 
@@ -1011,6 +1017,19 @@ dbg_op_ina_2:
 
 do_op_inc:
 #if EM_Z80
+#if 1
+       andi    z_flags,(1<<ZFL_C)              ; preserve C-, Clear N-flag
+       subi    opl,-1
+       in      temp,sreg
+       sbrc    temp,AVR_N
+       sbr     z_flags,(1<<ZFL_S)
+       sbrc    temp,AVR_Z
+       sbr     z_flags,(1<<ZFL_Z)
+       sbrs    temp,AVR_H
+       sbr     z_flags,(1<<ZFL_H)
+       sbrc    temp,AVR_V
+       sbr     z_flags,(1<<ZFL_P)
+#else
        andi    z_flags,(1<<ZFL_C)              ; preserve C-, Clear N-flag
        ldi     temp,1
        add     opl,temp
@@ -1019,6 +1038,7 @@ do_op_inc:
        bmov    z_flags,ZFL_Z, temp,AVR_Z
        bmov    z_flags,ZFL_H, temp,AVR_H
        bmov    z_flags,ZFL_P, temp,AVR_V
+#endif
 #else /* 8080 */
        andi    z_flags,(1<<ZFL_C)|(1<<ZFL_H)   ; preserve C- and H-flag
        inc     opl
@@ -1027,15 +1047,24 @@ do_op_inc:
 #endif
        ret
 
+#if 0
+       bst     z_flags,ZFL_C                   ; save C flag
+       subi    opl,-1
+       in      temp,sreg
+       ldpmx   z_flags,flagmap_tab,temp        
+       bld     z_flags,ZFL_C
+       ret
+#endif
+
 do_op_inca:
 #if EM_Z80
        andi    z_flags,(1<<ZFL_C)              ; preserve C-, Clear N-flag
-       ldi     temp,1
-       add     z_a,temp
+       subi    z_a,-1
        in      temp,sreg
        bmov    z_flags,ZFL_S, temp,AVR_N
        bmov    z_flags,ZFL_Z, temp,AVR_Z
-       bmov    z_flags,ZFL_H, temp,AVR_H
+       sbrs    temp,AVR_H
+       sbr     z_flags,(1<<ZFL_H)
        bmov    z_flags,ZFL_P, temp,AVR_V
 #else /* 8080 */
        andi    z_flags,(1<<ZFL_C)|(1<<ZFL_H)   ; preserve C- and H-flag
@@ -1049,8 +1078,8 @@ do_op_inca:
 ;|Mnemonic  |SZHPNC|Description          |Notes                 |
 ;----------------------------------------------------------------
 ;|DEC r     |***V1-|Decrement            |s=s-1                 |
-;|DEC [HL]  |***V0-|Increment            |[HL]=[HL]-1           |
-;|DEC [xx+d]|***V0-|Increment            |[xx+d]=[xx+d]-1       |
+;|DEC [HL]  |***V1-|Increment            |[HL]=[HL]-1           |
+;|DEC [xx+d]|***V1-|Increment            |[xx+d]=[xx+d]-1       |
 ;|----------|SZHP C|---------- 8080 ----------------------------|
 ;|DEC r     |**-P -|Increment            |r=r-1                 |
 ;|DEC [HL]  |**-P -|Increment            |[HL]=[HL]-1           |
@@ -1075,8 +1104,7 @@ do_op_dec:
 
 do_op_deca:
 #if EM_Z80
-       ldi     temp,1
-       sub     z_a,temp
+       subi    z_a,1
        in      temp,sreg
        bmov    z_flags,ZFL_S, temp,AVR_N
        bmov    z_flags,ZFL_Z, temp,AVR_Z
@@ -1104,6 +1132,21 @@ do_op_inc16:
        sbci    oph,high(-1)
        ret
 
+do_op_incHL:
+       sub     z_l,_255
+       sbc     z_h,_255
+       ret
+
+do_op_incDE:
+       sub     z_e,_255
+       sbc     z_d,_255
+       ret
+
+do_op_incBC:
+       sub     z_c,_255
+       sbc     z_b,_255
+       ret
+
 ;----------------------------------------------------------------
 ;|Mnemonic  |SZHPNC|Description          |Notes                 |
 ;----------------------------------------------------------------
@@ -1116,6 +1159,21 @@ do_op_dec16:
        sbci   oph, 0
        ret
 
+do_op_decHL:
+       add     z_l,_255
+       adc     z_h,_255
+       ret
+
+do_op_decDE:
+       add     z_e,_255
+       adc     z_d,_255
+       ret
+
+do_op_decBC:
+       add     z_c,_255
+       adc     z_b,_255
+       ret
+
 ;----------------------------------------------------------------
 ;|Mnemonic  |SZHPNC|Description          |Notes                 |
 ;----------------------------------------------------------------
@@ -1341,12 +1399,8 @@ do_op_xora:
 ;
 ;
 do_op_addhl:
-       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
+       add     z_l,opl
+       adc     z_h,oph
        in      temp,sreg
        bmov    z_flags,ZFL_C, temp,AVR_C
        do_z80_flags_H
@@ -1361,11 +1415,9 @@ do_op_addhl:
 ;
 do_op_sthl: ;store hl to mem loc in opl:h
        movw    xl,opl
-       ldd     temp,y+oz_l
-       mem_write
+       mem_write_s z_l
        adiw    xl,1
-       ldd     temp,y+oz_h
-       mem_write
+       mem_write_s z_h
        ret
 
 ;----------------------------------------------------------------
@@ -1720,11 +1772,9 @@ do_op_pop16:
 ;-----------------------------Z80--------------------------------
 ; 
 do_op_exhl:
-       ldd     temp,y+oz_l
-       ldd     temp2,y+oz_h
-       std     y+oz_l,opl
-       std     y+oz_h,oph
-       movw opl,temp
+       movw    temp,z_l
+       movw    z_l,opl
+       movw    opl,temp
        ret
 
 ;----------------------------------------------------------------
@@ -1887,9 +1937,7 @@ do_op_ifm: ;sign negative, aka s=1
 
                                ; (Joe G.)
 do_op_DJNZ:                    ; decremt B, jump B=0
-       ldd     temp,y+oz_b     ; B in temp
-       dec     temp            ; temp decrementieren
-       std     y+oz_b,temp     ; temp in B
+       dec     z_b             ; B decrementieren
        breq    do_op_DJNZ_Z    ; bei B=0
        subi    opl, 0x80       ; z_pc + e im Zweierkomplement
        subi    z_pcl,0x80
@@ -1902,9 +1950,7 @@ do_op_DJNZ_Z:
 #else
 
 do_op_djnz:
-       ldd     temp,y+oz_b
-       dec     temp
-       std     y+oz_b,temp
+       dec     z_b
        brne    opdjnze
        pop     temp                            ; nix tun
        pop     temp                            ; direkt zurueck zu main        
@@ -1934,6 +1980,29 @@ do_op_EXAF:
 ;|EXX       |------|Exchange             |qq<->qq'   (except AF)|
 
 
+#if 1
+
+do_op_EXX:
+       ldd     temp ,y+oz_c2
+       ldd     temp2,y+oz_b2
+       std     y+oz_c2,z_c
+       std     y+oz_b2,z_b
+       movw    z_c,temp
+
+       ldd     temp ,y+oz_e2
+       ldd     temp2,y+oz_d2
+       std     y+oz_e2,z_e
+       std     y+oz_d2,z_d
+       movw    z_e,temp
+
+       ldd     temp ,y+oz_l2
+       ldd     temp2,y+oz_h2
+       std     y+oz_l2,z_l
+       std     y+oz_h2,z_h
+       movw    z_l,temp
+       ret
+#else
+
 do_op_EXX:
        ldiw    z,z_b
        ldi     temp3,6
@@ -1946,6 +2015,8 @@ opexx_loop:
        brne    opexx_loop
        ret
 
+#endif
+
 #else
 do_op_djnz:
 do_op_EXAF:
@@ -2037,7 +2108,8 @@ do_op_prefixCB:
 instr  fetch_nop,      op_nop,         store_nop       ;00             ;NOP
 instr  fetch_DIR16,    op_nop,         store_BC        ;01 nn nn       ;LD BC,nn
 instr  fetch_nop,      op_nop,         store_MBC       ;02             ;LD (BC),A
-instr  fetch_BC,       op_INC16,       store_BC        ;03             ;INC BC
+;instr         fetch_BC,       op_INC16,       store_BC        ;03             ;INC BC
+instr  fetch_nop,      op_INCBC,       store_nop       ;03             ;INC BC
 instr  fetch_B,        op_INC,         store_B         ;04             ;INC B
 instr  fetch_B,        op_DEC,         store_B         ;05             ;DEC B
 instr  fetch_DIR8,     op_nop,         store_B         ;06             ;LD B,n
@@ -2045,7 +2117,8 @@ instr     fetch_nop,      op_RLCA,        store_nop       ;07             ;RLCA
 instr  fetch_nop,      op_EXAF,        store_nop       ;08             ;EX AF,AF'
 instr  fetch_BC,       op_ADDHL,       store_nop       ;09             ;ADD HL,BC
 instr  fetch_MBC,      op_nop,         store_nop       ;0A             ;LD A,(BC)
-instr  fetch_BC,       op_DEC16,       store_BC        ;0B             ;DEC BC
+;instr         fetch_BC,       op_DEC16,       store_BC        ;0B             ;DEC BC
+instr  fetch_nop,      op_DECBC,       store_nop       ;0B             ;DEC BC
 instr  fetch_C,        op_INC,         store_C         ;0C             ;INC C
 instr  fetch_C,        op_DEC,         store_C         ;0D             ;DEC C
 instr  fetch_DIR8,     op_nop,         store_C         ;0E nn          ;LD C,n
@@ -2053,7 +2126,8 @@ instr     fetch_nop,      op_RRCA,        store_nop       ;0F             ;RRCA
 instr  fetch_DIR8,     op_DJNZ,        store_nop       ;10 oo          ;DJNZ o
 instr  fetch_DIR16,    op_nop,         store_DE        ;11 nn nn       ;LD DE,nn
 instr  fetch_nop,      op_nop,         store_MDE       ;12             ;LD (DE),A
-instr  fetch_DE,       op_INC16,       store_DE        ;13             ;INC DE
+;instr         fetch_DE,       op_INC16,       store_DE        ;13             ;INC DE
+instr  fetch_nop,      op_INCDE,       store_nop       ;13             ;INC DE
 instr  fetch_D,        op_INC,         store_D         ;14             ;INC D
 instr  fetch_D,        op_DEC,         store_D         ;15             ;DEC D
 instr  fetch_DIR8,     op_nop,         store_D         ;16 nn          ;LD D,n
@@ -2061,7 +2135,8 @@ instr     fetch_nop,      op_RLA,         store_nop       ;17             ;RLA
 instr  fetch_DIR8,     op_nop,         store_pcrel     ;18 oo          ;JR o
 instr  fetch_DE,       op_ADDHL,       store_nop       ;19             ;ADD HL,DE
 instr  fetch_MDE,      op_nop,         store_nop       ;1A             ;LD A,(DE)
-instr  fetch_DE,       op_DEC16,       store_DE        ;1B             ;DEC DE
+;instr         fetch_DE,       op_DEC16,       store_DE        ;1B             ;DEC DE
+instr  fetch_nop,      op_DECDE,       store_nop       ;1B             ;DEC DE
 instr  fetch_E,        op_INC,         store_E         ;1C             ;INC E
 instr  fetch_E,        op_DEC,         store_E         ;1D             ;DEC E
 instr  fetch_DIR8,     op_nop,         store_E         ;1E nn          ;LD E,n
@@ -2069,7 +2144,8 @@ instr     fetch_nop,      op_RRA,         store_nop       ;1F             ;RRA
 instr  fetch_DIR8,     op_IFNZ,        store_pcrel     ;20 oo          ;JR NZ,o
 instr  fetch_DIR16,    op_nop,         store_HL        ;21 nn nn       ;LD HL,nn
 instr  fetch_DIR16,    op_STHL,        store_nop       ;22 nn nn       ;LD (nn),HL
-instr  fetch_HL,       op_INC16,       store_HL        ;23             ;INC HL
+;instr         fetch_HL,       op_INC16,       store_HL        ;23             ;INC HL
+instr  fetch_nop,      op_INCHL,       store_nop       ;23             ;INC HL
 instr  fetch_H,        op_INC,         store_H         ;24             ;INC H
 instr  fetch_H,        op_DEC,         store_H         ;25             ;DEC H
 instr  fetch_DIR8,     op_nop,         store_H         ;26 nn          ;LD H,n
@@ -2077,7 +2153,8 @@ instr     fetch_A,        op_DAA,         store_A         ;27             ;DAA
 instr  fetch_DIR8,     op_IFZ,         store_pcrel     ;28 oo          ;JR Z,o
 instr  fetch_HL,       op_ADDHL,       store_nop       ;29             ;ADD HL,HL
 instr  fetch_DIR16,    op_RMEM16,      store_HL        ;2A nn nn       ;LD HL,(nn)
-instr  fetch_HL,       op_DEC16,       store_HL        ;2B             ;DEC HL
+;instr         fetch_HL,       op_DEC16,       store_HL        ;2B             ;DEC HL
+instr  fetch_nop,      op_DECHL,       store_nop       ;2B             ;DEC HL
 instr  fetch_L,        op_INC,         store_L         ;2C             ;INC L
 instr  fetch_L,        op_DEC,         store_L         ;2D             ;DEC L
 instr  fetch_DIR8,     op_nop,         store_L         ;2E nn          ;LD L,n
@@ -2939,15 +3016,17 @@ do_op_BIT2:
 do_op_BIT1:
        ldi     temp,0x02
        rjmp    opbit
-       checkspace PC, 8
+
+       checkspace PC, 7
 do_op_BIT0:
        ldi     temp,0x01
 opbit:
-       and     temp,opl
-       in      temp,sreg
+       andi    z_flags,~((1<<ZFL_N)|(1<<ZFL_Z))
        ori     z_flags,(1<<ZFL_H)
-       andi    z_flags,~(1<<ZFL_N)
-       bmov    z_flags,ZFL_Z, temp,AVR_Z
+       and     temp,opl
+       brne    opbite
+       ori     z_flags,(1<<ZFL_Z)
+opbite:
        ret
 
 
@@ -3070,32 +3149,32 @@ opbit:
 ;.equ do_store_b = 0
        checkspace PC, 2
 do_store2_b:
-       std     y+oz_b,opl
+       mov     z_b,opl
        ret
 
        checkspace PC, 2
 do_store2_c:
-       std     y+oz_c,opl
+       mov     z_c,opl
        ret
 
        checkspace PC, 2
 do_store2_d:
-       std     y+oz_d,opl
+       mov     z_d,opl
        ret
 
        checkspace PC, 2
 do_store2_e:
-       std     y+oz_e,opl
+       mov     z_e,opl
        ret
 
        checkspace PC, 2
 do_store2_h:
-       std     y+oz_h,opl
+       mov     z_h,opl
        ret
 
        checkspace PC, 2
 do_store2_l:
-       std     y+oz_l,opl
+       mov     z_l,opl
        ret
 
        checkspace PC, 2
@@ -3105,8 +3184,7 @@ do_store2_a:
 
        checkspace PC, 4
 do_fetch2_mhl:
-       ldd     xh,y+oz_h
-       ldd     xl,y+oz_l
+       movw    x,z_l
        mem_read_d opl
        ret
 
@@ -3682,12 +3760,12 @@ do_op_out:                      ; out (c),opl
        mov temp,opl
        lcall printhex
        printstring " -> ("
-       ldd temp,y+oz_c
+       mov     temp,z_c
        lcall printhex
        printstring ") "
 .endif
        mov     temp,opl
-       ldd     temp2,y+oz_c
+       mov     temp2,z_c
        lcall   portWrite
        ret
 
@@ -3699,11 +3777,9 @@ do_op_out:                       ; out (c),opl
 
 do_op_stbc:            ;store bc to mem loc in opl:h
        movw xl,opl
-       ldd     temp,y+oz_c
-       mem_write
+       mem_write_s z_c
        adiw xl,1
-       ldd     temp,y+oz_b
-       mem_write
+       mem_write_s z_b
        ret
 
 ;----------------------------------------------------------------
@@ -3714,11 +3790,9 @@ 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
-       ldd     temp,y+oz_e
-       mem_write
+       mem_write_s z_e
        adiw xl,1
-       ldd     temp,y+oz_d
-       mem_write
+       mem_write_s z_d
        ret
 
 ;----------------------------------------------------------------
@@ -3741,19 +3815,14 @@ do_op_stsp:             ;store sp to mem loc in opl:h
 ;
 
 do_op_ADCHL:
-       ldd     temp,y+oz_l
-       ldd     temp2,y+oz_h
-       clc
-       sbrc z_flags,ZFL_C
-        sec
-       adc opl,temp
-       in temp,sreg                            ; save lower Z 
-       adc oph,temp2
-       in temp2,sreg
-       std     y+oz_l,opl
-       std     y+oz_h,oph
-       and     temp,temp2                      ; 16bit Z
+       lsr     z_flags                         ; ZFL_C --> Carry
        ldi     z_flags,0                       ; clear N
+       adc     z_l,opl
+       in      temp,sreg                       ; save lower Z 
+       adc     z_h,oph
+       in      temp2,sreg
+
+       and     temp,temp2                      ; 16bit Z
        bmov    z_flags,ZFL_C, temp2,AVR_C
        bmov    z_flags,ZFL_P, temp2,AVR_V
        bmov    z_flags,ZFL_H, temp2,AVR_H
@@ -3770,18 +3839,12 @@ do_op_ADCHL:
        checkspace PC, 24
 
 do_op_sbchl:
-       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
-       std     y+oz_l,temp
-       std     y+oz_h,temp2
+       lsr     z_flags                         ; get Z80 carry
+       sez                                     ; set z
+       sbc     z_l,opl
+       sbc     z_h,oph
        in temp,sreg
-       ldi     z_flags,(1<<ZFL_N)                      ; set N
+       ldi     z_flags,(1<<ZFL_N)              ; set N
        bmov    z_flags,ZFL_C, temp,AVR_C
        bmov    z_flags,ZFL_P, temp,AVR_V
        bmov    z_flags,ZFL_H, temp,AVR_H
@@ -3925,54 +3988,43 @@ do_op_rrd:
 ;|LDIR      |--000-|Load, Inc., Repeat   |LDI till BC=0         |
 ;
 
-       checkspace PC, 19
+       checkspace PC, 13
 
 op_LDxx_common:
-       ldd     xh,y+oz_h               ;H
-       ldd     xl,y+oz_l               ;L
+       movw    x,z_l                   ;HL
 ;      mem_read_ds temp, z
        lcall   dram_read               ; temp = (HL)
-       movw    z,x
-
-       ldd     xh,y+oz_d               ;D
-       ldd     xl,y+oz_e               ;E
+       movw    x,z_e                   ;DE
 ;      mem_write_ds x, temp
        lcall   dram_write              ; (DE) = temp
 
-       ldd     oph,y+oz_b              ;B
-       ldd     opl,y+oz_c              ;C
-
        cbr     z_flags,(1<<ZFL_H) | (1<<ZFL_P) | (1<<ZFL_N)
-       subi    opl,1
-       sbci    oph,0
+
+       movw    x,z_c
+       sbiw    x,1                     ;BC--
+       movw    z_c,x
        breq    PC+2
         sbr    z_flags,(1<<ZFL_P)
-       std     y+oz_c,opl              ;C
-       std     y+oz_b,oph              ;B
        ret
 
-       checkspace PC, 8
+       checkspace PC, 6
 
 do_op_LDI:
        rcall   op_LDxx_common
-       adiw    z,1
-       adiw    x,1
-       std     y+oz_e,xl               ;E
-       std     y+oz_d,xh               ;D
-       std     y+oz_l,zl               ;L
-       std     y+oz_h,zh               ;H
+       sub     z_e,_255                ;-low(-1)       DE++
+       sbc     z_d,_255                ;-high(-1)
+       sub     z_l,_255                ;-low(-1)       HL++
+       sbc     z_h,_255                ;-high(-1)
        ret
 
-       checkspace PC, 8
+       checkspace PC, 6
 
 do_op_LDD:
        rcall   op_LDxx_common
-       sbiw    z,1
-       sbiw    x,1
-       std     y+oz_e,xl               ;E
-       std     y+oz_d,xh               ;D
-       std     y+oz_l,zl               ;L
-       std     y+oz_h,zh               ;H
+       add     z_e,_255                ;+low(-1)       DE--
+       adc     z_d,_255                ;+high(-1)
+       add     z_l,_255                ;+low(-1)       HL--
+       adc     z_h,_255                ;+high(-1)
        ret
 
        checkspace PC, 5
@@ -4011,18 +4063,15 @@ do_op_LDDR:
        checkspace PC, 21
 
 op_CPxx_common:
-       ldd     xh,y+oz_h               ; H
-       ldd     xl,y+oz_l               ; L
-       ldd     zh,y+oz_b               ; B
-       ldd     zl,y+oz_c               ; C
+       movw    x,z_l                   ; HL
+       
+       movw    z,z_c                   ;BC
 
        cbr     z_flags,(1<<ZFL_S)|(1<<ZFL_Z)|(1<<ZFL_H)|(1<<ZFL_P)
        sbr     z_flags,(1<<ZFL_N)
        lcall   dram_read               ; temp = (HL)
 
-;      mov     temp2,z_a
-;      sub     temp2,temp              ; A - (HL)
-       cp      z_a,temp
+       cp      z_a,temp                ; A - (HL)
 
        brpl    PC+2
         sbr    z_flags,(1<<ZFL_S)
@@ -4034,8 +4083,7 @@ op_CPxx_common:
        sbiw    z,1                     ; BC--
        breq    PC+2
         sbr    z_flags,(1<<ZFL_P)
-       std     y+oz_c,zl               ; C
-       std     y+oz_b,zh               ; B
+       movw    z_c,z                   ;BC
        ret
 
        checkspace PC, 5
@@ -4043,8 +4091,7 @@ op_CPxx_common:
 do_op_CPI:
        rcall   op_CPxx_common
        adiw    x,1                     ; HL++
-       std     y+oz_l,xl               ; L
-       std     y+oz_h,xh               ; H
+       movw    z_l,x                   ; HL
        ret
 
 
@@ -4053,8 +4100,7 @@ do_op_CPI:
 do_op_CPD:
        rcall   op_CPxx_common
        sbiw    x,1                     ; HL--
-       std     y+oz_l,xl               ; L
-       std     y+oz_h,xh               ; H
+       movw    z_l,x                   ; HL
        ret
 
        checkspace PC, 7
@@ -4087,39 +4133,34 @@ do_op_CPDR:
 ;|INIR      |?1??1-|Input, Inc., Repeat  |INI till B=0          |
 ;|INDR      |?1??1-|Input, Dec., Repeat  |IND till B=0          |
 
-       checkspace PC, 15
+       checkspace PC, 12
 
 op_INxx_common:
        cbr     z_flags,(1<<ZFL_Z)
        sbr     z_flags,(1<<ZFL_N)
-       ldd     temp2,y+oz_c    ;C
+       mov     temp2,z_c               ;C
        lcall   portRead
-       ldd     xh,y+oz_h               ;H
-       ldd     xl,y+oz_l               ;L
+       movw    x,z_l                   ;HL
        lcall   dram_write
-       ldd     temp,y+oz_b     ;B
-       dec     temp
-       std     y+oz_b,temp     ;B
+       dec     z_b                     ;B
        brne    PC+2
         sbr    z_flags,(1<<ZFL_Z)
        ret
 
-       checkspace PC, 5
+       checkspace PC, 4
 
 do_op_INI:
        rcall   op_INxx_common
        adiw    x,1
-       std     y+oz_l,xl               ;L
-       std     y+oz_h,xh               ;H
+       movw    z_l,x                   ;HL
        ret
 
-       checkspace PC, 5
+       checkspace PC, 4
 
 do_op_IND:
        rcall   op_INxx_common
        sbiw    x,1
-       std     y+oz_l,xl               ;L
-       std     y+oz_h,xh               ;H
+       movw    z_l,x                   ;HL
        ret
 
        checkspace PC, 5
@@ -4148,43 +4189,34 @@ do_op_INDR:
 ;|OTIR      |?1??1-|Output, Inc., Repeat |OUTI till B=0         |
 ;|OTDR      |?1??1-|Output, Dec., Repeat |OUTD till B=0         |
 
-       checkspace PC, 13
+       checkspace PC, 12
 
 op_OUTxx_common:
-       cbr     z_flags,(1<<ZFL_Z)
-       sbr     z_flags,(1<<ZFL_N)
+       movw    x,z_l                   ;HL
        lcall   dram_read               ;temp = (z)
-       ldd     temp2,y+oz_c    ;C
+       mov     temp2,z_c               ;C
        lcall   portWrite
-       ldd     temp,y+oz_b     ;B
-       dec     temp
-       std     y+oz_b,temp     ;B
+       cbr     z_flags,(1<<ZFL_Z)
+       sbr     z_flags,(1<<ZFL_N)
+       dec     z_b                     ;B
        brne    PC+2
         sbr    z_flags,(1<<ZFL_Z)
        ret
 
-       checkspace PC, 8
+       checkspace PC, 4
 
 do_op_OUTI:
-       ldd     xh,y+oz_h               ;H
-       ldd     xl,y+oz_l               ;L
-       adiw    x,1
-       std     y+oz_l,xl               ;L
-       std     y+oz_h,xh               ;H
-       sbiw    x,1
        rcall   op_OUTxx_common
+       sub     z_l,_255                ;-low(-1)
+       sbc     z_h,_255                ;-high(-1)
        ret
 
-       checkspace PC, 8
+       checkspace PC, 4
 
 do_op_OUTD:
-       ldd     xh,y+oz_h               ;H
-       ldd     xl,y+oz_l               ;L
-       sbiw    x,1
-       std     y+oz_l,xl               ;L
-       std     y+oz_h,xh               ;H
-       adiw    x,1
        rcall   op_OUTxx_common
+       add     z_l,_255                ;+low(-1)
+       adc     z_h,_255                ;+high(-1)
        ret
 
        checkspace PC, 5
index db69a8c614e80dc7e2237695ab9f3942731306f6..061887620e86d7afc7daa79b3ccca21a7ae14fd4 100644 (file)
@@ -22,7 +22,7 @@
 
 
 #define VMAJOR 3               /* Version number */
-#define VMINOR 1
+#define VMINOR 2
 
 ;-----------------------------------------------------------------------
 ;
 ; Baudrate of serial port (console).
 ;#define BAUD 115200
 
-; I2C defaults 1 on 8-bit-ram systems and must be 0 on 4-bit-ram systems.
+; I2C_SUPPORT defaults to 1 on 8-bit-ram systems and must be 0 on 4-bit-ram systems.
 ; Set this do 0, if you don't have  I2C peripherals and want to save some flash 
 ; or use the I2C pins for other purposes.
-;#define I2C  
+;#define I2C_SUPPORT  
 
 ; Emulate Z80 cpu if 1, 8080 otherwise.
 ;
 #define I2CADRL        0x07
 #define I2CADRH        0x08
 
+; Simple ADC Interface
+#define ADC80  0x17
+#define ADC81  0x18
+
 ; Port-Expander PCF8574
 #define PORT   0x80
 #define PORT0  0x80
 #ifndef BAUD
   #define BAUD   115200                /* console baud rate */
 #endif
-#ifndef I2C
-  #define I2C DRAM_8BIT        /* I2C requires 8 bit DRAM */
+#ifndef I2C_SUPPORT
+  #define I2C_SUPPORT DRAM_8BIT        /* I2C requires 8 bit DRAM */
+#endif
+#if I2C_SUPPORT && !DRAM_8BIT
+  #error "I2C_SUPPORT requires 8 bit DRAM (DRAM_8BIT=1)!"
 #endif
-#if I2C && !DRAM_8BIT
-  #error "I2C requires 8 bit DRAM (DRAM_8BIT=1)!"
+#ifndef ADC_SUPPORT
+  #define ADC_SUPPORT 0        
 #endif
 
 #ifndef EM_Z80
 .def   _WE     = r5
 .def   _255    = r6
 .def   _0      = r7
-.def   z_a     = r9
-;.def  stx_bitcount  = r9
-;.def  stx_dr        = r10
-
-.def   srx_lastedgel = r10
-.def   srx_lastedgeh = r11
-;.def  insstore= r8    ;
-;.def  insop   = r13   ;
-
-.def   insdecl = r12   ;
-.def   insdech = r13   ;
-.def   z_spl   = r14
+
+.def   z_c     = r8    ;
+.def   z_b     = r9    ;
+.def   z_e     = r10   ;
+.def   z_d     = r11   ;
+.def   z_l     = r12   ;
+.def   z_h     = r13   ;
+.def   z_spl   = r14   ;
 .def   z_sph   = r15   ;
 .def   temp    = r16   ;
 .def   temp2   = r17   ;
-.def   temp3   = r18
-.def   temp4   = r19
+.def   temp3   = r18   ;
+;.def  temp4   = r19   ;
+.def   intstat = r19   ;interpreter status / interrupt status
 .def   z_flags = r20   ;
-.def   intstat = r21   ; interpreter status / interrupt status
+.def   z_a     = r21   ;
 .def   opl     = r22   ;
 .def   oph     = r23   ;
 .def   z_pcl   = r24   ;
 ; xh           ;r27
 ; yl           ;r28
 ; yh           ;r29
-; zl           ;r30    ;
-; zh           ;r31    ;
+; zl           ;r30
+; zh           ;r31
 
 
 .equ   i_break = 0                     ;break detected flag
        .equ    readop  = 4             ;1 if read operation
 
        .equ    prefixfd = 1            ;Opcode prefix DD=0, FD=1
-       .equ    trace    = 0
 
 
 #if EM_Z80
index 466f9bb4660d6adb63380cf28ec99cc367d263a8..c0553138b4c0d196e20a2bdad728f50ff8c4e0f2 100644 (file)
@@ -29,7 +29,7 @@
 ;must not alter xh:xl
 
 dram_read:
-       cli                             ;
+;      cli                             ;
        out     PORTD,xh                ;1
        out     PORTC,_RAS0             ;1
        out     PORTD,xl                ;1
@@ -41,7 +41,7 @@ dram_read:
        in      temp,PIND               ;1
        out     PORTC,_255              ;1
        out     DDRD,_255               ;1
-       sei                             ;
+;      sei                             ;
        ret
 
 
@@ -50,7 +50,7 @@ dram_read:
 ;must not alter xh:xl
 
 dram_write:
-       cli
+;      cli
        out     PORTD,xh                ;1
        out     PORTC,_RAS0             ;1
        out     PORTD,xl                ;1
@@ -58,7 +58,7 @@ dram_write:
        out     PORTD,temp              ;1
        out     PORTC,_WE               ;1
        out     PORTC,_255              ;1  = 7
-       sei
+;      sei
        ret
 
 ; -------------------------------------------------------------------
index a2b2e0c78c99f8f6e87b1e4927d7719c6e464511..a7d8dbd12e51b2ef8633becbe313757b6deaf775 100644 (file)
@@ -42,7 +42,7 @@
 ;      mem_read_ds  destreg, memaddr
 
 .macro mem_read_ds
-       cli                             ;1
+;      cli                             ;1
        out     PORTD,@1h               ;1
        out     PORTC,_RAS0             ;1
        out     PORTD,@1l               ;1
@@ -53,7 +53,7 @@
        dram_wait DRAM_WAITSTATES       ;
        in      @0,PIND                 ;1
        out     PORTC,_255              ;1
-       sei                             ;1
+;      sei                             ;1
        out     DDRD,_255               ;1  = 14 + DRAM_WAITSTATES
 .endm
 
 ;      mem_write_ds  memaddr, sourcereg
 
 .macro mem_write_ds
-       cli                             ;1
+;      cli                             ;1
        out     PORTD,@0h               ;1
        out     PORTC,_RAS0             ;1
        out     PORTD,@0l               ;1
        out     PORTC,_CAS0             ;1
        out     PORTD,@1                ;1
        out     PORTC,_WE               ;1
-       sei                             ;1
+;      sei                             ;1
        out     PORTC,_255              ;1  = 9
 .endm
 
index 0999b7928989e1b61cd2af1810d6b3b837ad293d..0e7b27470f1ae997113dd7380a41048786c103b4 100644 (file)
@@ -60,38 +60,39 @@ cpm_hostparam:
 
        lds     temp,hostlba            ; get sector to access
        lds     temp2,hostlba+1
-;      lds     temp3,hostlba+2
 
 .if HOSTRW_DEBUG
        printstring "lba: "
-       clr     temp4
+       push    r15
+       push    r14
+       clr     r14
+       clr     r15
        lcall   print_ultoa
+       pop     r14
+       pop     r15
 .endif
 
        ldd     xl,z+5                  ; get disksize
        ldd     xh,z+6
-;      ldd     yl,z+7
        
        cp      temp,xl                 ; check given sector against disksize
        cpc     temp2,xh
-;      cpc     temp3,yl
        brcs    cpm_hp1
        
 .if HOSTRW_DEBUG
        printstring ", max: "
-       push    temp4
-       push    temp3
+       push    r15
+       push    r14
        push    temp2
        push    temp
        movw    temp,x
-;      mov     temp3,yl
-       clr     temp3
-       clr     temp4
+       clr     r14
+       clr     r15
        lcall   print_ultoa
        pop     temp
        pop     temp2
-       pop     temp3
-       pop     temp4
+       pop     r14
+       pop     r15
        printstring " "
 .endif
        
@@ -106,23 +107,22 @@ cpm_hp1:
 
        add     xl,temp                 ; add offset to startsector
        adc     xh,temp2
-;      adc     yl,temp3
        adc     yl,_0
        adc     yh,_0
 
 .if HOSTRW_DEBUG
        printstring ", abs:"
-       push    temp4
-       push    temp3
+       push    r15
+       push    r14
        push    temp2
        push    temp
        movw    temp,x
-       movw    temp3,y
+       movw    r14,y
        lcall   print_ultoa
        pop     temp
        pop     temp2
-       pop     temp3
-       pop     temp4
+       pop     r14
+       pop     r15
        printstring " "
 .endif
 
index 1072689fc5356357f03657dfa503c89c2e6767a8..34f793367e47d8944dd525f1cae9bb607a7559c2 100644 (file)
@@ -540,17 +540,17 @@ fat_look_not_ok:
 fat_scan_next_sector:
 
        
-       lds     temp3, fat_log_clust
-       lds     temp4, fat_log_clust+1
+       lds     _tmp0, fat_log_clust
+       lds     _tmp1, fat_log_clust+1
 
-       sub     temp3,temp2
-       sbc     temp4,_0
+       sub     _tmp0,temp2
+       sbc     _tmp1,_0
 
-       sts     fat_log_clust,temp3
-       sts     fat_log_clust+1,temp4
+       sts     fat_log_clust,_tmp0
+       sts     fat_log_clust+1,_tmp1
        
-       cp      temp3,_0
-       cpc     temp4,_0
+       cp      _tmp0,_0
+       cpc     _tmp1,_0
        breq    fat_scan_at_end 
 
        lds     temp,fat_clust_offset
@@ -876,16 +876,13 @@ fat_hostparam:
 fat_hostlend:
        lds     temp ,hostlba
        lds     temp2,hostlba+1
-;      lds     temp3,hostlba+2
 
 
        ldd     xl,z+5                  ; get size of disk in sectors
        ldd     xh,z+6
-;      ldd     yl,z+7
        
        cp      temp,xl                 ; check given sector against disksize
        cpc     temp2,xh
-;      cpc     temp3,yl
        brcs    fat_hp1
        
        clr     temp
@@ -897,7 +894,6 @@ fat_hp1:
 ; Get logical Sectornumber from temp
        mov     xl,temp
        mov     xh,temp2
-;      mov     yl,temp3
        mov     yl,_0
        mov     yh,_0
 ; Divide logical Sectornumber by size of Cluster in sectors
@@ -1086,17 +1082,17 @@ fat_readhost:
        
 .if FAT16_RWDEBUG > 0
        printstring "Read Image Sector:"
-       push    temp4
-       push    temp3
+       push    r15
+       push    r14
        push    temp2
        push    temp
        movw    temp,x
-       movw    temp3,y
+       movw    r14,y
        lcall   print_ultoa
        pop     temp
        pop     temp2
-       pop     temp3
-       pop     temp4
+       pop     r14
+       pop     r15
        printnewline
 .endif
        
index f2d656b3cba7601f50d9eb58040762c3b53e0fed..5df2f1eb42a21edcc529bf420f267f87a19f6661 100644 (file)
@@ -171,10 +171,10 @@ dbg_print_biosd:
 ; ====================================================================
 ; Parameters
 ; --------------------------------------------------------------------
-; Registers  : [w] z                   Pointer to the Partitionentry
-;              [r] zl                  Number of Diskentry to Read
-;             [w] _tmp0                scratch
-;             [w] _tmp1                "
+; Registers  : [w] z           Pointer to the Partitionentry
+;              [r] zl          Number of Diskentry to Read
+;             [w] r0           scratch
+;             [w] r1           "
 ; --------------------------------------------------------------------
 ; Description:
 ; ====================================================================
@@ -183,8 +183,8 @@ dsk_getpartentry:
        ldi     zh,PARTENTRY_SIZE
        mul     zh,zl
        ldiw    z,hostparttbl
-       add     zl,_tmp0
-       adc     zh,_tmp1
+       add     zl,r0
+       adc     zh,r1
        ret
 
 ; ====================================================================
@@ -1051,7 +1051,7 @@ dsk_read:
        andi    temp,dskType_MASK
 
 ; Isn't it a Disk ?
-       cpi             temp,dskType_None
+       cpi     temp,dskType_None
        brne    PC+2
        rjmp    dsk_read_err
 
@@ -1104,7 +1104,7 @@ dsk_write:
 
 ; It must be a FAT16-Imagefile or CP/M Partition.
 
-       rcall   dsk_setdrvparam         ;todo: do this only if needed (disk change)
+       rcall   dsk_setdrvparam         ;TODO: do this only if needed (disk change)
 
        andi    temp,WRTMSK
        sts     wrtype,temp             ;save write type
@@ -1141,10 +1141,10 @@ dsk_chkuna:
 ;      disks are the same
        lds     temp,unatrk
        lds     temp2,unatrk+1
-       lds     temp3,seektrk
-       lds     temp4,seektrk+1
-       cp      temp,temp3              ;seektrk = unatrk?
-       cpc     temp2,temp4
+       lds     _tmp0,seektrk
+       lds     _tmp1,seektrk+1
+       cp      temp,_tmp0              ;seektrk = unatrk?
+       cpc     temp2,_tmp1
        brne    dsk_alloc               ;skip if not
 
 ;      tracks are the same
@@ -1209,16 +1209,15 @@ dsk_rwoper:
        lds     temp,hdrsize            ;add image header size
        add     xl,temp                 ;
        adc     xh,_0                   ;
-       lds     temp3,seektrk           ;
-       lds     temp4,seektrk+1         ;
-       lds     temp,cpmspt             ;
-       mul     temp3,temp              ;
+       lds     temp,seektrk            ;
+       lds     temp2,seektrk+1         ;
+       lds     temp3,cpmspt            ;
+       mul     temp,temp3              ;
        add     xl,r0                   ;
        adc     xh,r1                   ;
-       mul     temp4,temp              ;
+       mul     temp2,temp3             ;
        add     xh,r0                   ;yl:xh:xl := sec + trk * SectorsPerTrack
        adc     yl,r1                   ;
-
        mov     temp,xl
        andi    temp,SECMSK             ;mask buffer number
        push    temp                    ;save for later
@@ -1239,12 +1238,20 @@ dsk_sh1:
 
        ;copy data to or from buffer
        ldiw    z,hostbuf
+#if 1
+       pop     temp2                   ;get buffer number (which part of hostbuf)
+       clr     temp
+       lsr     temp2                   ;temp2:temp = temp2 * 128
+       ror     temp
+       add     zl,temp                 ;offset in hostbuf
+       adc     zh,temp2
+#else  
        ldi     temp,128
        pop     temp2                   ;get buffer number (which part of hostbuf)
        mul     temp2,temp
        add     zl,r0                   ;offset in hostbuf
        adc     zh,r1
-
+#endif
 .if DISK_DEBUG > 2
        movw    temp,r0
        printstring "; host buf adr: "
@@ -1340,9 +1347,9 @@ dsk_rw_hostbuf:
 
 ;      same disk, same block?
        lds     _tmp0,hostlba
-       lds     _tmp1,hostlba+1
        cp      temp,_tmp0
-       cpc     temp2,_tmp1
+       lds     _tmp0,hostlba+1
+       cpc     temp2,_tmp0
        breq    dsk_match
 
 dsk_nomatch:
index db62ed1eb3c3c800dc9f4a29345a7c618bb3c22e..9cb1aefa959a9c01ef70e30ae52f17261e702bc7 100644 (file)
@@ -97,10 +97,10 @@ mgr_check_bootsektor:
 ;Test, if it has a valid MBR
 
        lds     temp,hostbuf+510        ;MBR signature (0xAA55)  at and of sector?
-       lds     temp2,hostbuf+510+1
-       ldi     temp4,0xAA
        cpi     temp,0x55               
-       cpc     temp2,temp4
+       lds     temp,hostbuf+510+1
+       ldi     temp2,0xAA
+       cpc     temp,temp2
        breq    mgr_search
 
 ;No MBR, no partition table ...
@@ -125,7 +125,6 @@ mgr_check_bootsektor:
 ; Search for valid Partitions and ImageFiles 
 mgr_search:
        ldiw    z,hostbuf+510-64        ;Point to  first byte of partition table
-       ldi     temp4,4                 ;Partition table has 4 entries.
 
 mgr_ploop:
 
@@ -145,14 +144,13 @@ mgr_ploop:
        
 mgr_nextp:
        adiw    z,16
-       dec     temp4
+       cpi     zl,low(hostbuf+510)     ;End of partition table reached?
        brne    mgr_ploop
 
 #if FAT16_SUPPORT
 
 ; Test for FAT16 Partition
        ldiw    z,hostbuf+510-64        ;Point to  first byte of partition table
-       ldi     temp4,4
 
 mgr_ploop2:
 ;      Get Partitiontype
@@ -174,7 +172,7 @@ mgr_fatfound:
 
 mgr_nextp2:
        adiw    zl,16
-       dec     temp4
+       cpi     zl,low(hostbuf+510)
        brne    mgr_ploop2
 #endif
 
@@ -212,17 +210,15 @@ mgr_prnt_parttbl:
        ldi     xh,'A'
 
 pprl:
-       ldd     temp ,z+1               ;Get partition start
-       ldd     temp2,z+2
-       ldd     temp3,z+3
-       ldd     temp4,z+4
-
        printnewline
 
-       cp      temp,_0                 ;If zero ...
-       cpc     temp2,_0
-       cpc     temp3,_0
-       cpc     temp4,_0
+       ldd     temp ,z+1               ;Get partition start
+       ldd     temp2,z+2
+       or      temp,temp2
+       ldd     temp2,z+3
+       or      temp,temp2
+       ldd     temp2,z+4
+       or      temp,temp2              ;If zero ...
        breq    mgr_prnop               ;... no partition table at 0
 
 ; Partitiontype examining
@@ -268,14 +264,15 @@ mgr_prnt_size:
 
        ldd     temp ,z+5               ;Get partition size
        ldd     temp2,z+6
-       ldi     temp3,0
-       ldi     temp4,0
-
-       lsr     temp4
-       ror     temp3
-       ror     temp2
+       push    r15
+       push    r14
+       clr     r14
+       clr     r15
+       lsr     temp2
        ror     temp
        lcall   print_ultoa
+       pop     r14
+       pop     r15
        printstring "KB."
 
 mgr_goto_next_part:    
index 0ff38e4a7dfbacb948321182cabfd0081e6916a8..e144369a0c4ab6118c877d32a1d0bab34798c139 100644 (file)
@@ -28,25 +28,25 @@ hp_top: .byte       2
 
 .if HEAP_DEBUG
 hp_print_free:
-       push    temp4
-       push    temp3
+       push    r15
+       push    r14
        push    temp2
        push    temp
        printstring ", bytes free: "
-       lds     temp3,hp_top
-       lds     temp4,hp_top+1
+       lds     r14,hp_top
+       lds     r15,hp_top+1
        ldi     temp,0
        ldi     temp2,0
-       sub     temp,temp3
-       sbc     temp2,temp4
-       ldi     temp3,0
-       ldi     temp4,0
+       sub     temp,r14
+       sbc     temp2,r15
+       clr     r14
+       clr     r15
        rcall   print_ultoa
        printstring " "
        pop     temp
        pop     temp2
-       pop     temp3
-       pop     temp4
+       pop     r14
+       pop     r15
        ret
 .endif         
 
@@ -80,30 +80,30 @@ hp_dbg1:
 ; return 0 if not enough space
 
 heap_get:
-       push    temp4
-       push    temp3
+       push    r15
+       push    r14
 .if HEAP_DEBUG
        push    temp2
        push    temp
        printnewline
        printstring "Heap get: "
-       ldi     temp3,0
-       ldi     temp4,0
+       clr     r14
+       clr     r15
        rcall   print_ultoa
        pop     temp
        pop     temp2   
 .endif         
-       lds     temp3,hp_top
-       lds     temp4,hp_top+1
-       add     temp,temp3
-       adc     temp2,temp4
+       lds     r14,hp_top
+       lds     r15,hp_top+1
+       add     temp,r14
+       adc     temp2,r15
        brcs    hp_full
                
 ; zero flag clear here
 
        sts     hp_top,temp
        sts     hp_top+1,temp2
-       movw    temp,temp3
+       movw    temp,r14
        rjmp    hp_get_ex
 hp_full:
        clr     temp
@@ -114,11 +114,11 @@ hp_get_ex:
        printstring "Error: "
 hp_get_dbg1:
        rcall   hp_print_free
-       mov     temp3,temp      ;restore zero flag
-       or      temp3,temp2
+       mov     r14,temp        ;restore zero flag
+       or      r14,temp2
 .endif
-       pop     temp3
-       pop     temp4
+       pop     r14
+       pop     r15
        ret
 
 
index 0d96ace594a04d2f64464c2241a148e1f488f9ba..9b13191c72134920c1f4be3e533085656f733668 100644 (file)
@@ -1,7 +1,7 @@
 ; I2C (TWI) master interface. 
 ; This is part of the Z80-CP/M emulator written by Sprite_tm.
 ;
-;    Copyright (C) 2010 Leo C.
+;    Copyright (C) 2013 Leo C.
 ;
 ;    This file is part of avrcpm.
 ;
@@ -21,7 +21,7 @@
 ;    $Id$
 ;
 
-#if I2C 
+#if I2C_SUPPORT 
 
 /* General TWI Master status codes */
 #define TWI_START                  0x08  /* START has been transmitted */
@@ -469,7 +469,7 @@ pcf8574_out:
        ret
 
 
-#endif /* I2C */
+#endif /* I2C_SUPPORT */
 ;------------------------------------------------------------------
 ; vim:set ts=8 noet nowrap
 
index a6a1d416e01b749faa861063bab121c5e2e48feb..469001a38545c815d391b812918d0ecb07ee425e 100644 (file)
@@ -60,9 +60,9 @@ cp_l: lpm     xh,z+
        
 ; - Setup Ports
 
-       ldi     temp,(1<<PUD)           ;disable pullups
-       outm8   P_PUD,temp
-       out     PORTD,_255              ;all pins high
+;      ldi     temp,(1<<PUD)           ;disable pullups
+;      outm8   P_PUD,temp
+       out     PORTD,_255              ;all pins high (enables pullup on input ports)
        out     PORTB,_255
        out     PORTC,_255
        out     DDRD,_255               ; all outputs
@@ -103,7 +103,7 @@ clr_l:
 
        rcall   uart_init
        
-;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
+;Init timer2. Refresh-call should happen every (8ms/512) cycles.
 
        ldi     temp,REFR_CNT*2                 ; 2 cycles per int
        outm8   OCR2A,temp
@@ -177,7 +177,7 @@ ramtestr:
        printstring "Addr xx yy "
 ramtestr1:
        printnewline
-       mov     temp4,temp
+       mov     zl,temp
        movw    temp,x
        rcall   printhexw
        rcall   printspace
@@ -186,16 +186,16 @@ ramtestr1:
        mov     temp2,temp
        rcall   printhex
        rcall   printspace
-       mov     temp,temp4
+       mov     temp,zl
        rcall   printhex
        rcall   printspace
        mov     temp,temp2
-       eor     temp,temp4
+       eor     temp,zl
        and     temp,temp2
        rcall   printxbits
        rcall   printspace
        mov     temp,temp2
-       eor     temp,temp4
+       eor     temp,zl
        com     temp2
        and     temp,temp2
        rcall   printxbits
index c16777f7d528e7711bbb55984c348b8438ea4b0c..887d54a984ce7413def8df8fb1330fe4eec04789 100644 (file)
@@ -316,18 +316,19 @@ mmc_cmdxcrc:
 ; Wait for a valid response in timeout of 10 attempts
 
 mmc_cmdres:
-       ldi     temp,10
-       mov     _tmp1,temp
+       push    temp2
+       ldi     temp2,10
 mmc_cmdrl:
        rcall   spi_rcvr
        sbrs    temp,7
        rjmp    mmc_cmdexit
-       dec     _tmp1
+       dec     temp2
        brne    mmc_cmdrl
 
 ; Return with  response value
 
 mmc_cmdexit:
+       pop     temp2
 .if MMC_DEBUG
        printstring " CMDRes: "
        rcall   printhex
@@ -371,7 +372,7 @@ mmc_timeout_1s:
        lds     temp,delay_timer1
        tst     temp
        brne    mmc_ttex
-       dec     temp4
+       dec     zh
        breq    mmc_ttex
        ldi     temp,100
        sts     delay_timer1,temp
@@ -411,7 +412,7 @@ mmci_lp:
        breq    mmci_1
        rjmp    mmci_lend
 mmci_1:        
-       ldi     temp4,10                ;Initialization timeout of 1000 ms.
+       ldi     zh,10                   ;Initialization timeout of 1000 ms.
        ldi     temp,100
        sts     delay_timer1,temp
        ldi     temp2,CMD8
index 402c9c9093b1871dc2b7c93b3c2e96e956cc01d9..5a4cc12280bfe81584629340a7a22ac06f0fc6cd 100644 (file)
@@ -300,7 +300,7 @@ clkput_l:
        dec     temp3
        brne    clkput_l
        sei
-#if I2C
+#if I2C_SUPPORT
        rcall   rtc_set                 ; set hardware clock
 #endif
        ret
@@ -364,10 +364,10 @@ bcdbin2:
        swap    temp2
        andi    temp2,0x0f
        andi    temp,0x0f               ;temp  = low digit
-       mov     _tmp0,temp2
+       mov     r0,temp2
        ldi     temp2,10
-       mul     temp2,_tmp0             ;high digit * 10
-       add     temp,_tmp0              ;high digit * 10 + low digit
+       mul     temp2,r0                ;high digit * 10
+       add     temp,r0                 ;high digit * 10 + low digit
        pop     temp2
        ret
 
@@ -379,13 +379,13 @@ bcdbin4:
        ldi     temp2,100
        mul     temp,temp2
        pop     temp
-       mov     temp2,_tmp1
-       add     temp,_tmp0
+       mov     temp2,r1
+       add     temp,r0
        adc     temp2,_0
        ret
 
 
-#if I2C
+#if I2C_SUPPORT
 
 ; ----------------------------------------------
 ; Set software clock from hardware clock
@@ -410,7 +410,7 @@ rtc_get:
        brmi    rtc_get_e               ;i2c error
 
        ldd     temp3,z+1               ;save year
-       ldd     temp4,z+2
+       ldd     xl,   z+2
 
        ldi     temp2,2                 ;register pointer. 2 = secs
        std     z+1,temp2
@@ -420,6 +420,7 @@ rtc_get:
        tst     temp
        brmi    rtc_get_e
 
+       mov     temp2,xl                ;year century
        ldd     temp,z+4                ;get year
        rol     temp
        rol     temp
@@ -427,8 +428,8 @@ rtc_get:
        eor     temp,temp3
        andi    temp,0x03
        breq    rtc_get_1
-       inc     temp3
-       adc     temp4,_0
+       subi    temp3, low(-1)  
+       sbci    temp2, high(-1)
 rtc_get_1:
        ldiw    x,clock
        cli
@@ -451,7 +452,7 @@ rtc_get_1:
        rcall   bcdbin2
        st      x+,temp                 ;store month
        st      x+,temp3                ;store year
-       st      x+,temp4                ;store year century
+       st      x+,temp2                ;store year century
        sei
 
 rtc_get_e:
@@ -468,7 +469,7 @@ rtc_get_e:
 ; 
 ; Register:    temp2:  s
 ;              temp3:  m
-;              temp4:  h
+;              xh:     h
 ;              xl:     D
 ;              temp:   M
 ;              yl:     Yl
@@ -479,7 +480,7 @@ rtc_set:
        cli
        ldd     temp2,z+0               ;sec
        ldd     temp3,z+1               ;min
-       ldd     temp4,z+2               ;hours
+       ldd     xh,z+2                  ;hours
        ldd     xl,z+3                  ;day
        ldd     temp,z+4                ;month
        ldd     yl,z+5                  ;yearl
@@ -496,7 +497,7 @@ rtc_set:
        andi    xl,0xc0
        or      temp,xl                 ;   combine with day
        push    temp                    ;-2 save year/day
-       mov     temp,temp4
+       mov     temp,xh
        rcall   binbcd2
        push    temp                    ;-3 save hours
        mov     temp,temp3
@@ -535,7 +536,7 @@ rtc_set:
        out     sph,zh
 
        ret
-#endif
+#endif /* I2C_SUPPORT */
 
 ; ----------------------------------------------
 ; 
@@ -629,6 +630,8 @@ ts_loop:
 ;
        
 timer_print:
+       push    r15             ;
+       push    r14             ;
        push    yh
        push    yl
        ldiw    z,timer_ms
@@ -658,14 +661,14 @@ tp_s:
        ld      yh,z+
        sbc     temp2,yh
 
-       ldd     temp3,z+timerofs
+       ldd     r14,z+timerofs
        ld      yl,z+
-       sbc     temp3,yl
+       sbc     r14,yl
 
        sei
-       ldd     temp4,z+timerofs
+       ldd     r15,z+timerofs
        ld      yh,z+
-       sbc     temp4,yh
+       sbc     r15,yh
        
        printnewline
        printstring "Timer running. Elapsed: "
@@ -674,16 +677,20 @@ tp_s:
        printstring "."
        pop     temp
        pop     temp2
-       ldi     temp3,0
-       ldi     temp4,0
+       clr     r14
+       clr     r15
        rcall   print_ultoa
        printstring "s."
 
        pop     yl
        pop     yh
+       pop     r14
+       pop     r15
        ret
        
 uptime_print:
+       push    r15
+       push    r14
        ldiw    z,cnt_1ms
        cli
        ld      temp,z+
@@ -693,9 +700,9 @@ uptime_print:
        
        ld      temp,z+
        ld      temp2,z+
-       ld      temp3,z+
+       ld      r14,z+
        sei
-       ld      temp4,z+
+       ld      r15,z+
        
        printnewline
        printstring "Uptime: "
@@ -703,13 +710,15 @@ uptime_print:
        rcall   print_ultoa
        printstring ","
 
-       ldi     temp3,0
-       ldi     temp4,0
+       clr     r14
+       clr     r15
        pop     temp2
        pop     temp
        rcall print_ultoa
        printstring "s."
 
+       pop     r14
+       pop     r15
        ret
 
 ; vim:set ts=8 noet nowrap
index 685ce569622f2eaf2f01bc01f3ea84fdc2fd0d28..a995179d4315aa53c03d98f05030a70105e1c3a8 100644 (file)
 
 
 ;Print a unsigned lonng value to the uart
-; temp4:temp3:temp2:temp = value
+; r15:r14:temp2:temp = value
 
 print_ultoa:
        push    yh
        push    yl
        push    z_flags
-       push    temp4
-       push    temp3
+       push    r15
+       push    r14
        push    temp2
        push    temp
                                
        clr     yl              ;yl = stack level
 
-ultoa1:        ldi     z_flags, 32     ;yh = temp4:temp % 10
-       clr     yh              ;temp4:temp /= 10
+ultoa1:        ldi     z_flags, 32     ;yh = r15:temp % 10
+       clr     yh              ;r15:temp /= 10
 ultoa2:        lsl     temp    
        rol     temp2   
-       rol     temp3   
-       rol     temp4   
+       rol     r14     
+       rol     r15     
        rol     yh      
        cpi     yh,10   
        brcs    ultoa3  
@@ -55,10 +55,10 @@ ultoa3:     dec     z_flags
        subi    yh, -'0'
        push    yh              ;Stack it
        inc     yl      
-       cp      temp,_0         ;Repeat until temp4:temp gets zero
+       cp      temp,_0         ;Repeat until r15:temp gets zero
        cpc     temp2,_0
-       cpc     temp3,_0
-       cpc     temp4,_0
+       cpc     r14,_0
+       cpc     r15,_0
        brne    ultoa1  
        
        ldi     temp, '0'
@@ -75,8 +75,8 @@ ultoa6:       pop     temp            ;Flush stacked digits
 
        pop     temp
        pop     temp2
-       pop     temp3
-       pop     temp4
+       pop     r14
+       pop     r15
        pop     z_flags
        pop     yl
        pop     yh
@@ -250,16 +250,28 @@ printregs:
        mov     temp,z_a
        rcall   printhex        
        printstring " BC ="
+#if 1
+       movw    temp,z_c
+#else
        ldd     temp2,y+oz_b
        ldd     temp,y+oz_c
+#endif
        rcall   printhexw
        printstring " DE ="
+#if 1
+       movw    temp,z_e
+#else
        ldd     temp2,y+oz_d
        ldd     temp,y+oz_e
+#endif
        rcall   printhexw
        printstring " HL ="
-       ldd     temp2,y+oz_h
+#if 1
+       movw    temp,z_l
+#else
        ldd     temp,y+oz_l
+       ldd     temp2,y+oz_h
+#endif
        rcall   printhexw
        printstring " SP="
        movw    temp, z_spl
index 05cfd933b47ee9d9ba0b5e87b34414c38742a379..96e3619c32f94ffb8a90300cb54962b92c95b487 100644 (file)
@@ -112,7 +112,7 @@ vport_tbl:
        .dw     dbg_stat
        .dw     dbg_ctrl
 
-#if I2C
+#if I2C_SUPPORT
        .db     I2CCTRL,1
        .dw     vi2c_stat_get
        .dw     vi2c_ctrl
@@ -164,14 +164,14 @@ dvp_12:
 
 vprw_loop:
        lpm     _tmp0,z+
-       lpm     temp4,z+        ;length
-       cpi     temp4,0
+       lpm     _tmp1,z+        ;length
+       cp      _tmp1,_0
        breq    vprw_exit       ;no more ports
 
        mov     temp3,temp2     
        sub     temp3,_tmp0     ;base port
        brcs    vprw_next       ;port # too high
-       cp      temp3,temp4     ;may be in range
+       cp      temp3,_tmp1     ;may be in range
        brcs    vprw_found      ;
 vprw_next:                     ;port # not in range, test next block.
        adiw    z,4
@@ -180,8 +180,8 @@ vprw_found:
        brtc    PC+2            ;read or write?
        adiw    z,2             ;skip read function pointer
        lpm     _tmp0,z+
-       lpm     _tmp1,z+
-       movw    z,_tmp0
+       lpm     zh,z
+       mov     zl,_tmp0
 
 .if PORT_DEBUG > 1
        push    temp2
@@ -222,13 +222,13 @@ vprw_exit:
 .if PORT_DEBUG > 1
        printstring ", not found!"
 .endif 
-vport_in_dummy:
        ldi     temp,0xff
-vport_out_dummy:
        pop     yl
        pop     yh
        ret
-       
+
+vport_out_dummy:
+       ret     
 
 uartstat:
        clr     temp