]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/utils.asm
Tag for Version 3.2
[avrcpm.git] / avr / utils.asm
index 4d8122a763904b996116998ae1e71e5f58130a64..5ae5c1df71c42c9967078eb90883778cba68778e 100644 (file)
@@ -1,6 +1,6 @@
 ;    Print and Debug functions
 ;
-;    Copyright (C) 2010 Leo C.
+;    Copyright (C) 2010-2013 Leo C.
 ;
 ;    This file is part of avrcpm.
 ;
 
 
 ;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
@@ -114,11 +114,162 @@ printhexn_isno:
 
 ; Prints a single space
 
-dbg_printspace:
+printspace:
+       push    temp
        ldi     temp,' '
-       rjmp    uartputc
+       rcall   uartputc
+       pop     temp
+       ret
+
+;-----------------------------------------------------------------------
+;Prints the zero-terminated string following the call statement. 
+
+printstr:
+       push    zh              ;SP+5
+       push    zl              ;   4
+       push    yh              ;   3
+       push    yl              ;   2
+       push    temp            ;   1
+       in      yh,sph
+       in      yl,spl
+       ldd     zl,y+7          ;SP+7  == "return adr." == String adr.
+       ldd     zh,y+6          ;SP+6
+
+       lsl zl                  ;word to byte conv.
+       rol zh
+printstr_loop:
+       lpm temp,z+
+       cpi temp,0
+       breq printstr_end
+       rcall uartputc
+       cpi temp,13
+       brne printstr_loop
+       ldi temp,10
+       rcall uartputc
+       rjmp printstr_loop
+
+printstr_end:
+       adiw zl,1               ;rounding up
+       lsr zh                  ;byte to word conv.
+       ror zl
+
+       std     y+7,zl
+       std     y+6,zh
+       pop     temp
+       pop     yl
+       pop     yh
+       pop     zl
+       pop     zh
+       ret
+       
+; ------------------------ String functions -------------------------
+;
+
+#if 0
+; String compare (z, y), one z-string in flash.
+
+strcmp_p:
+       ld      temp,y+
+       lpm     _tmp0, z+
+       sub     temp,_tmp0
+       brne    strcmp_pex
+       tst     _tmp0
+       brne    strcmp_p
+       sub     temp,temp
+strcmp_pex:
+       ret
 
-; Prints 16 bytes pointed to by Z in hex.
+#endif
+
+#if 0
+
+strcmp_p:
+       ld      temp,y+
+       lpm     _tmp0,z+
+       sub     temp,_tmp0
+       cpse    _tmp0,_0
+       breq    strcmp_p
+       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
+
+;-----------------------------------------------------------------------
+; Memory compare: DRAM - AVR-RAM
+;      DRAM-Addr. in x, AVRRAM-Addr. in y 
+;      Compare temp3 bytes.
+;
+;      Return Z-Flag == 1 if match
+;      temp, _tmp0  destroyed
+;
+
+memcmp_d:
+       rcall   dram_read_pp
+       ld      _tmp0,y+
+       cp      temp,_tmp0
+       brne    memcmpd_nomatch
+       dec     temp3
+       brne    memcmp_d
+memcmpd_nomatch:
+       ret
+
+; --------------- Debugging stuff ---------------
+
+
+.if SRAM_FILL
+
+stackusage_print:
+       ldiw    z,ramtop
+       ldi     temp,  low(RAMEND+1)
+       ldi     temp2,high(RAMEND+1)
+       ldi     temp3,SRAMFILL_VAL
+stack_search_l:
+       ld      _tmp0,z+
+       cp      temp3,_tmp0
+       brne    stack_search_found
+       cp      zl,temp
+       cpc     zh,temp2
+       brne    stack_search_l
+
+stack_search_found:
+       sbiw    z,1
+       sub     temp, zl
+       sbc     temp2,zh
+       printnewline
+       printstring "Stack used (bytes): "
+       push    r15
+       push    r14
+       clr     r14
+       clr     r15
+       rcall   print_ultoa
+       pop     r14
+       pop     r15
+       ret
+.endif
+
+
+
+;-----------------------------------------------------------------------
+; Prints 16 bytes RAM, pointed to by Z in hex.
+
+#if 0
 
 dbg_hexdump_line:                      ;Address in z
        push    temp2
@@ -127,21 +278,21 @@ dbg_hexdump_line:                 ;Address in z
        movw    temp,z                  ;Print address
        rcall   printhexw
        ldi     temp2,16                ;16 byte per line
-       rcall   dbg_printspace
+       rcall   printspace
 dbg_hdl1:
        cpi     temp2,8
        brne    PC+2
-       rcall   dbg_printspace
+       rcall   printspace
        
-       rcall   dbg_printspace
+       rcall   printspace
        ld      temp,z+
        rcall   printhex
        dec     temp2
        brne    dbg_hdl1
        sbiw    z,16
        
-       rcall   dbg_printspace
-       rcall   dbg_printspace
+       rcall   printspace
+       rcall   printspace
        ldi     temp2,16
 dbg_hdl2:
        ld      temp,z+
@@ -156,67 +307,113 @@ dbg_hdp:
        dec     temp2
        brne    dbg_hdl2
        sbiw    z,16
-       rcall   dbg_printspace
+       rcall   printspace
        pop     temp
        pop     temp2
        ret
+#endif
        
+;-----------------------------------------------------------------------
+; Print a line with the 8080/Z80 registers
 
-;Prints the zero-terminated string following the call statement. 
-
-printstr:
-       push    zh
-       push    zl
-       push    yh
-       push    yl
-       push    temp
-       in      yh,sph
-       in      yl,spl
-       ldd     zl,y+7
-       ldd     zh,y+6
-
-       lsl zl
-       rol zh
-printstr_loop:
-       lpm temp,z+
-       cpi temp,0
-       breq printstr_end
-       rcall uartputc
-       cpi temp,13
-       brne printstr_loop
-       ldi temp,10
-       rcall uartputc
-       rjmp printstr_loop
+printregs:
+       mov     temp,z_flags
+       rcall   printflags
+       printstring "  A ="
+       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 ="
+#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
+       rcall   printhexw
+       printstring " PC="
+       movw    temp, z_pcl
+       rcall   printhexw
+       printstring "       "
+       movw    xl,z_pcl
+       lcall   dram_read_pp
+       rcall   printhex
+       printstring " "
+       lcall   dram_read_pp
+       rcall   printhex
+       printstring " "
+       lcall   dram_read
+       rcall   printhex
+       printstring " "
 
-printstr_end:
-       adiw zl,1               ;rounding
-       lsr zh
-       ror zl
+#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        
 
-       std     y+7,zl
-       std     y+6,zh
-       pop     temp
-       pop     yl
-       pop     yh
-       pop     zl
-       pop     zh
+       printstring "       "
+#endif
        ret
-       
-; --------------- Debugging stuff ---------------
-; Print a line with the Z80 main registers
 
-;.if INS_DEBUG
 
+#if EM_Z80
+zflags_to_ch:
+       .db     "SZ H VNC",0,0
+#else  
 zflags_to_ch:
        .db     "SZ H PNC",0,0
+#endif
        
-printregs:
+printflags:
+       push    temp2
+       mov     temp2,temp
        printnewline
-
        push    zl
        push    zh
        ldiw    z,zflags_to_ch*2
-       mov     temp2,z_flags
 pr_zfl_next:
        lpm     temp,z+
        tst     temp
@@ -232,43 +429,8 @@ pr_zfl_noflag:
 pr_zfl_end:
        pop     zh
        pop     zl      
-
-       printstring "  A ="
-       mov     temp,z_a
-       rcall   printhex        
-       printstring " BC ="
-       lds     temp2,z_b
-       lds     temp, z_c
-       rcall   printhexw
-       printstring " DE ="
-       lds     temp2,z_d
-       lds     temp, z_e
-       rcall   printhexw
-       printstring " HL ="
-       lds     temp2,z_h
-       lds     temp, z_l
-       rcall   printhexw
-       printstring " SP ="
-       movw    temp, z_spl
-       rcall   printhexw
-       printstring " PC ="
-       movw    temp, z_pcl
-       rcall   printhexw
-       printstring "       "
-       movw    xl,z_pcl
-       mem_read
-       rcall   printhex
-       printstring " "
-       adiw    x,1
-       mem_read
-       rcall   printhex
-       printstring " "
-       adiw    x,1
-       mem_read
-       rcall   printhex
-       printstring " "
+       pop     temp2
        ret
-;.endif
 
 ; vim:set ts=8 noet nowrap