]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/utils.asm
* FAT buffer on ATmega328
[avrcpm.git] / avr / utils.asm
index 0e7e0c3889b528a023d08fe66c45c4d35df26eb7..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
@@ -202,73 +202,162 @@ printstr_end:
        pop     zh
        ret
        
-; --------------- Debugging stuff ---------------
-; Print a line with the Z80 main registers
+; ------------------------ String functions -------------------------
+;
 
-;.if INS_DEBUG
+#if 0
+; String compare (z, y), one z-string in flash.
 
-zflags_to_ch:
-       .db     "SZ H PNC",0,0
-       
-printregs:
-       printnewline
+strcmp_p:
+       lpm     _tmp0,z+
+       tst     _tmp0
+       breq    strcmp_pex
 
-       push    zl
-       push    zh
-       ldiw    z,zflags_to_ch*2
-       mov     temp2,z_flags
-pr_zfl_next:
-       lpm     temp,z+
-       tst     temp
-       breq    pr_zfl_end
-       cpi     temp,' '                        ; Test if no flag
-       breq    pr_zfl_noflag
-       sbrs    temp2,7                 ; 
-        ldi    temp,' '                        ; Flag not set
-       rcall   uartputc
-pr_zfl_noflag:
-       rol     temp2
-       rjmp    pr_zfl_next
-pr_zfl_end:
-       pop     zh
-       pop     zl      
+       ld      temp, y+
+       lpm     _tmp0, z+
+       sub     temp,_tmp0
+       brne    strcmp_pex
+       tst     _tmp0
+       brne    strcmp_p
+strcmp_pex:
+       ret
+#endif
+
+; String compare (x, y, temp2). Max temp2 bytes are compared.
 
+strncmp_p:
+       subi    temp2,1
+       brcs    strncmp_peq
+       ld      temp,y+
+       lpm     _tmp0, z+
+       sub     temp,_tmp0
+       brne    strncmp_pex
+       tst     _tmp0
+       brne    strncmp_p
+strncmp_peq:
+       sub     temp,temp
+strncmp_pex:
+       ret
+
+
+; --------------- Debugging stuff ---------------
+; Print a line with the 8080/Z80 registers
+
+printregs:
+       mov     temp,z_flags
+       rcall   printflags
        printstring "  A ="
        mov     temp,z_a
        rcall   printhex        
        printstring " BC ="
-       lds     temp2,z_b
-       lds     temp, z_c
+#if 1
+       movw    temp,z_c
+#else
+       ldd     temp2,y+oz_b
+       ldd     temp,y+oz_c
+#endif
        rcall   printhexw
        printstring " DE ="
-       lds     temp2,z_d
-       lds     temp, z_e
+#if 1
+       movw    temp,z_e
+#else
+       ldd     temp2,y+oz_d
+       ldd     temp,y+oz_e
+#endif
        rcall   printhexw
        printstring " HL ="
-       lds     temp2,z_h
-       lds     temp, z_l
+#if 1
+       movw    temp,z_l
+#else
+       ldd     temp,y+oz_l
+       ldd     temp2,y+oz_h
+#endif
        rcall   printhexw
-       printstring " SP ="
+       printstring " SP="
        movw    temp, z_spl
        rcall   printhexw
-       printstring " PC ="
+       printstring " PC="
        movw    temp, z_pcl
        rcall   printhexw
        printstring "       "
        movw    xl,z_pcl
-       mem_read
+       lcall   dram_read_pp
        rcall   printhex
        printstring " "
-       adiw    x,1
-       mem_read
+       lcall   dram_read_pp
        rcall   printhex
        printstring " "
-       adiw    x,1
-       mem_read
+       lcall   dram_read
        rcall   printhex
        printstring " "
+
+#if EM_Z80
+       ldd     temp,y+oz_f2
+       rcall   printflags
+       printstring "  a'="
+       ldd     temp,y+oz_a2
+       rcall   printhex        
+       printstring " bc'="
+       ldd     temp2,y+oz_b2
+       ldd     temp,y+oz_c2
+       rcall   printhexw
+       printstring " de'="
+       ldd     temp2,y+oz_d2
+       ldd     temp,y+oz_e2
+       rcall   printhexw
+       printstring " hl'="
+       ldd     temp2,y+oz_h2
+       ldd     temp,y+oz_l2
+       rcall   printhexw
+       printstring " IX="
+       ldd     temp2,y+oz_xh
+       ldd     temp,y+oz_xl
+       rcall   printhexw
+       printstring " IY="
+       ldd     temp2,y+oz_yh
+       ldd     temp,y+oz_yl
+       rcall   printhexw
+       printstring " I="
+       ldd     temp,y+oz_i
+       rcall   printhex        
+
+       printstring "       "
+#endif
+       ret
+
+
+#if EM_Z80
+zflags_to_ch:
+       .db     "SZ H VNC",0,0
+#else  
+zflags_to_ch:
+       .db     "SZ H PNC",0,0
+#endif
+       
+printflags:
+       push    temp2
+       mov     temp2,temp
+       printnewline
+       push    zl
+       push    zh
+       ldiw    z,zflags_to_ch*2
+pr_zfl_next:
+       lpm     temp,z+
+       tst     temp
+       breq    pr_zfl_end
+       cpi     temp,' '                        ; Test if no flag
+       breq    pr_zfl_noflag
+       sbrs    temp2,7                 ; 
+        ldi    temp,' '                        ; Flag not set
+       rcall   uartputc
+pr_zfl_noflag:
+       rol     temp2
+       rjmp    pr_zfl_next
+pr_zfl_end:
+       pop     zh
+       pop     zl      
+       pop     temp2
        ret
-;.endif
 
 ; vim:set ts=8 noet nowrap