diff --git a/src/main/fragment/_deref__deref_pptz1=pbuc1_derefidx_vbuxx.asm b/src/main/fragment/_deref__deref_pptz1=pbuc1_derefidx_vbuxx.asm new file mode 100644 index 000000000..8f14bd50e --- /dev/null +++ b/src/main/fragment/_deref__deref_pptz1=pbuc1_derefidx_vbuxx.asm @@ -0,0 +1,5 @@ +ldy #0 +lda {z1} +sta !+ +1 +lda {c1},x +!: sta ({z1}),y diff --git a/src/main/fragment/_deref_pptz1=_inc__deref_pptz1.asm b/src/main/fragment/_deref_pptz1=_inc__deref_pptz1.asm new file mode 100644 index 000000000..d066e7dc9 --- /dev/null +++ b/src/main/fragment/_deref_pptz1=_inc__deref_pptz1.asm @@ -0,0 +1,5 @@ +ldy #0 +lda ({z1}),y +clc +adc #1 +sta ({z1}),y \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 4a2357ddc..319f189f0 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -63,6 +63,11 @@ public class TestPrograms { */ + @Test + public void testHex2DecPtrPtr() throws IOException, URISyntaxException { + compileAndCompare("hex2dec-ptrptr"); + } + @Test public void testHex2Dec() throws IOException, URISyntaxException { compileAndCompare("hex2dec"); diff --git a/src/test/kc/hex2dec-ptrptr.kc b/src/test/kc/hex2dec-ptrptr.kc new file mode 100644 index 000000000..18665be48 --- /dev/null +++ b/src/test/kc/hex2dec-ptrptr.kc @@ -0,0 +1,38 @@ +// Testing binary to hex conversion using pointer to pointer + +void main() { + cls(); + unsigned char *screen = 0x0400; + utoa16w(00000, screen); screen += 40; + utoa16w(01234, screen); screen += 40; + utoa16w(05678, screen); screen += 40; + utoa16w(09999, screen); screen += 40; + utoa16w(58888, screen); +} + +void cls() { + unsigned char *screen = 0x0400; + for( unsigned char *sc: screen..screen+999) *sc=' '; +} + +// Digits used for utoa() +unsigned char[] DIGITS = "0123456789abcdef"; + +// Hexadecimal utoa() for an unsigned int (16bits) +void utoa16w(unsigned int value, unsigned char* dst) { + unsigned char started = 0; + started = utoa16n((>value)>>4, &dst, started); + started = utoa16n((>value)&0x0f, &dst, started); + started = utoa16n((>4, &dst, started); + utoa16n(($400 + sta utoa16w.dst+1 + lda #0 + sta utoa16w.value + sta utoa16w.value+1 + jsr utoa16w + lda #<$400+$28 + sta utoa16w.dst + lda #>$400+$28 + sta utoa16w.dst+1 + lda #<$4d2 + sta utoa16w.value + lda #>$4d2 + sta utoa16w.value+1 + jsr utoa16w + lda #<$400+$28+$28 + sta utoa16w.dst + lda #>$400+$28+$28 + sta utoa16w.dst+1 + lda #<$162e + sta utoa16w.value + lda #>$162e + sta utoa16w.value+1 + jsr utoa16w + lda #<$400+$28+$28+$28 + sta utoa16w.dst + lda #>$400+$28+$28+$28 + sta utoa16w.dst+1 + lda #<$270f + sta utoa16w.value + lda #>$270f + sta utoa16w.value+1 + jsr utoa16w + lda #<$400+$28+$28+$28+$28 + sta utoa16w.dst + lda #>$400+$28+$28+$28+$28 + sta utoa16w.dst+1 + lda #<$e608 + sta utoa16w.value + lda #>$e608 + sta utoa16w.value+1 + jsr utoa16w + rts +} +// Hexadecimal utoa() for an unsigned int (16bits) +// utoa16w(word zeropage(2) value, byte* zeropage(4) dst) +utoa16w: { + .label value = 2 + .label dst = 4 + lda value+1 + lsr + lsr + lsr + lsr + tax + lda #dst + sta utoa16n.dst+1 + lda #0 + sta utoa16n.started + jsr utoa16n + lda utoa16n.return + tay + lda value+1 + ldx #$f + axs #0 + sty utoa16n.started + lda #dst + sta utoa16n.dst+1 + jsr utoa16n + lda utoa16n.return + tay + lda value + lsr + lsr + lsr + lsr + tax + sty utoa16n.started + lda #dst + sta utoa16n.dst+1 + jsr utoa16n + lda value + ldx #$f + axs #0 + lda #dst + sta utoa16n.dst+1 + lda #1 + sta utoa16n.started + jsr utoa16n + lda #0 + tay + sta (dst),y + rts +} +// Hexadecimal utoa() for a single nybble +// utoa16n(byte register(X) nybble, word** zeropage(6) dst, byte zeropage(8) started) +utoa16n: { + .label started = 8 + .label return = 8 + .label dst = 6 + cpx #0 + beq b1 + lda #1 + sta return + b1: + lda return + cmp #0 + beq breturn + ldy #0 + lda dst + sta !++1 + lda DIGITS,x + !: + sta (dst),y + ldy #0 + lda (dst),y + clc + adc #1 + sta (dst),y + breturn: + rts +} +cls: { + .label screen = $400 + .label sc = 2 + lda #screen + sta sc+1 + b1: + lda #' ' + ldy #0 + sta (sc),y + inc sc + bne !+ + inc sc+1 + !: + lda sc+1 + cmp #>screen+$3e7+1 + bne b1 + lda sc + cmp #