ca65 V2.15 - Git f7cdfbf
Main file   : string.s65
Current file: string.s65

000000r 1                                 .setcpu "6502"
000000r 1                                 .include "macros.inc65"
000000r 2               ; Push X
000000r 2               .macro phx
000000r 2                 sta TMP_STACK
000000r 2                 txa
000000r 2                 pha
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Push Y
000000r 2               .macro phy
000000r 2                 sta TMP_STACK
000000r 2                 tya
000000r 2                 pha
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Push X and Y
000000r 2               .macro phxy
000000r 2                 sta TMP_STACK
000000r 2                 txa
000000r 2                 pha
000000r 2                 tya
000000r 2                 pha
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Push A and X
000000r 2               .macro phax
000000r 2                 sta TMP_STACK
000000r 2                 pha
000000r 2                 txa
000000r 2                 pha
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Push A and Y
000000r 2               .macro phay
000000r 2                 sta TMP_STACK
000000r 2                 pha
000000r 2                 tya
000000r 2                 pha
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Push A, X and Y
000000r 2               .macro phaxy
000000r 2                 sta TMP_STACK
000000r 2                 pha
000000r 2                 txa
000000r 2                 pha
000000r 2                 tya
000000r 2                 pha
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Pull X
000000r 2               .macro plx
000000r 2                 sta TMP_STACK
000000r 2                 pla
000000r 2                 tax
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Pull Y
000000r 2               .macro ply
000000r 2                 sta TMP_STACK
000000r 2                 pla
000000r 2                 tay
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Pull X and Y
000000r 2               .macro plxy
000000r 2                 sta TMP_STACK
000000r 2                 pla
000000r 2                 tay
000000r 2                 pla
000000r 2                 tax
000000r 2                 lda TMP_STACK
000000r 2               .endmacro
000000r 2               
000000r 2               ; Pull A and X
000000r 2               .macro plax
000000r 2                 pla
000000r 2                 tax
000000r 2                 pla
000000r 2               .endmacro
000000r 2               
000000r 2               ; Pull A and Y
000000r 2               .macro play
000000r 2                 pla
000000r 2                 tay
000000r 2                 pla
000000r 2               .endmacro
000000r 2               
000000r 2               ; Pull A, X and Y
000000r 2               .macro plaxy
000000r 2                 pla
000000r 2                 tay
000000r 2                 pla
000000r 2                 tax
000000r 2                 pla
000000r 2               .endmacro
000000r 2               
000000r 2               ; Load zero page register reg/reg+1 with the 16-bit value, destroys A
000000r 2               .macro ld16 reg, value
000000r 2                 lda #<(value)
000000r 2                 sta reg
000000r 2                 lda #>(value)
000000r 2                 sta reg + 1
000000r 2               .endmacro
000000r 2               
000000r 1                                 .include "zeropage.inc65"
000000r 2               .importzp RES
000000r 2               .importzp R0
000000r 2               .importzp R1
000000r 2               .importzp TMP0
000000r 2               .importzp TMP1
000000r 2               .importzp TMP_STACK
000000r 2               
000000r 1               
000000r 1                                 .export fmt_hex_char
000000r 1                                 .export fmt_bin_string
000000r 1                                 .export fmt_hex_string
000000r 1                                 .export scan_hex_char
000000r 1                                 .export scan_hex
000000r 1                                 .export scan_hex16
000000r 1               
000000r 1                                 .code
000000r 1               
000000r 1               ; Format the value of the accu as a binary string
000000r 1               ; The string is written into (R0)..(R0)+8 (9 bytes)
000000r 1  85 rr        fmt_bin_string:   sta TMP0
000002r 1  85 rr 48 98                    phay
000006r 1  48 A5 rr     
000009r 1  A0 08                          ldy #8
00000Br 1  A9 00                          lda #0
00000Dr 1  91 rr                          sta (R0),y
00000Fr 1  88                             dey
000010r 1  46 rr        @next_bit:        lsr TMP0
000012r 1  B0 05                          bcs @bit_is_1
000014r 1  A9 30        @bit_is_0:        lda #'0'
000016r 1  4C rr rr                       jmp @store_char
000019r 1  A9 31        @bit_is_1:        lda #'1'
00001Br 1  91 rr        @store_char:      sta (R0),y
00001Dr 1  88                             dey
00001Er 1  10 F0                          bpl @next_bit
000020r 1  68 A8 68                       play
000023r 1  60                             rts
000024r 1               
000024r 1               ; Convert the 4-bit value of the accu into it's hex ascii character
000024r 1               ; The hex ascii character is returned in the accu
000024r 1  C9 0A        fmt_hex_char:     cmp #10
000026r 1  90 07                          bcc @less_then_10
000028r 1  38           @greater_then_10: sec
000029r 1  E9 0A                          sbc #10
00002Br 1  18                             clc
00002Cr 1  69 41                          adc #'A'
00002Er 1  60                             rts
00002Fr 1  18           @less_then_10:    clc
000030r 1  69 30                          adc #'0'
000032r 1  60                             rts
000033r 1               
000033r 1               ; Format the value of the accu as a hex string
000033r 1               ; The string is written into (R0)..(R0)+2 (3 bytes)
000033r 1  85 rr        fmt_hex_string:   sta TMP0
000035r 1  85 rr 48 98                    phay
000039r 1  48 A5 rr     
00003Cr 1  A0 00                          ldy #0
00003Er 1  A5 rr                          lda TMP0
000040r 1  4A                             lsr
000041r 1  4A                             lsr
000042r 1  4A                             lsr
000043r 1  4A                             lsr
000044r 1  20 rr rr                       jsr fmt_hex_char
000047r 1  91 rr                          sta (R0),y
000049r 1  C8                             iny
00004Ar 1  A5 rr                          lda TMP0
00004Cr 1  29 0F                          and #$0f
00004Er 1  20 rr rr                       jsr fmt_hex_char
000051r 1  91 rr                          sta (R0),y
000053r 1  C8                             iny
000054r 1  A9 00                          lda #0
000056r 1  91 rr                          sta (R0),y
000058r 1  68 A8 68                       play
00005Br 1  60                             rts
00005Cr 1               
00005Cr 1               ; Convert the hex character in the accu to its integer value
00005Cr 1               ; The integer value is returned in the accu
00005Cr 1  C9 30        scan_hex_char:    cmp #'0'
00005Er 1  90 20                          bcc @invalid
000060r 1  C9 3A                          cmp #('9' + 1)
000062r 1  B0 04                          bcs @no_digit
000064r 1  38                             sec
000065r 1  E9 30                          sbc #'0'
000067r 1  60                             rts
000068r 1  C9 41        @no_digit:        cmp #'A'
00006Ar 1  90 14                          bcc @invalid
00006Cr 1  C9 47                          cmp #('F' + 1)
00006Er 1  B0 04                          bcs @no_upper_hex
000070r 1  38                             sec
000071r 1  E9 37                          sbc #('A' - 10)
000073r 1  60                             rts
000074r 1  C9 61        @no_upper_hex:    cmp #'a'
000076r 1  90 08                          bcc @invalid
000078r 1  C9 67                          cmp #('f' + 1)
00007Ar 1  B0 04                          bcs @invalid
00007Cr 1  38                             sec
00007Dr 1  E9 57                          sbc #('a' - 10)
00007Fr 1  60                             rts
000080r 1  A9 00        @invalid:         lda #0
000082r 1  60                             rts
000083r 1               
000083r 1               ; Convert two hex characters starting at (R0) into an integer value
000083r 1               ; The integer value is returned in the accu
000083r 1  98           scan_hex:         tya
000084r 1  48                             pha
000085r 1  A0 00                          ldy #0
000087r 1  B1 rr                          lda (R0),y
000089r 1  20 rr rr                       jsr scan_hex_char
00008Cr 1  0A                             asl
00008Dr 1  0A                             asl
00008Er 1  0A                             asl
00008Fr 1  0A                             asl
000090r 1  85 rr                          sta TMP0
000092r 1  C8                             iny
000093r 1  B1 rr                          lda (R0),y
000095r 1  20 rr rr                       jsr scan_hex_char
000098r 1  05 rr                          ora TMP0
00009Ar 1  85 rr                          sta TMP0
00009Cr 1  68                             pla
00009Dr 1  A8                             tay
00009Er 1  A5 rr                          lda TMP0
0000A0r 1  60                             rts
0000A1r 1               
0000A1r 1               ; Convert four hex characters starting at (R0) into an integer value
0000A1r 1               ; The integer value is returned in RES..RES+1
0000A1r 1  85 rr 48 98  scan_hex16:       phay
0000A5r 1  48 A5 rr     
0000A8r 1  A0 00                          ldy #0
0000AAr 1  B1 rr                          lda (R0),y
0000ACr 1  20 rr rr                       jsr scan_hex_char
0000AFr 1  0A                             asl
0000B0r 1  0A                             asl
0000B1r 1  0A                             asl
0000B2r 1  0A                             asl
0000B3r 1  85 rr                          sta RES + 1
0000B5r 1  C8                             iny
0000B6r 1  B1 rr                          lda (R0),y
0000B8r 1  20 rr rr                       jsr scan_hex_char
0000BBr 1  05 rr                          ora RES + 1
0000BDr 1  85 rr                          sta RES + 1
0000BFr 1  C8                             iny
0000C0r 1  B1 rr                          lda (R0),y
0000C2r 1  20 rr rr                       jsr scan_hex_char
0000C5r 1  0A                             asl
0000C6r 1  0A                             asl
0000C7r 1  0A                             asl
0000C8r 1  0A                             asl
0000C9r 1  85 rr                          sta RES
0000CBr 1  C8                             iny
0000CCr 1  B1 rr                          lda (R0),y
0000CEr 1  20 rr rr                       jsr scan_hex_char
0000D1r 1  05 rr                          ora RES
0000D3r 1  85 rr                          sta RES
0000D5r 1  68 A8 68                       play
0000D8r 1  60                             rts
0000D8r 1               
