1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-23 08:32:39 +00:00

Added pointer to pointer test.

This commit is contained in:
jespergravgaard 2019-05-21 01:45:32 +02:00
parent 3132790ab5
commit fd259fe47e
5 changed files with 216 additions and 0 deletions

View File

@ -0,0 +1,5 @@
ldy #0
lda {z1}
sta !+ +1
lda {c1},x
!: sta ({z1}),y

View File

@ -0,0 +1,5 @@
ldy #0
lda ({z1}),y
clc
adc #1
sta ({z1}),y

View File

@ -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");

View File

@ -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((<value)>>4, &dst, started);
utoa16n((<value)&0x0f, &dst, 1);
*dst = 0;
}
// Hexadecimal utoa() for a single nybble
unsigned char utoa16n(unsigned char nybble, unsigned **dst, unsigned char started) {
if(nybble!=0) started=1;
if(started!=0) {
*(*dst)++ = DIGITS[nybble];
}
return started;
}

View File

@ -0,0 +1,163 @@
// Testing binary to hex conversion using pointer to pointer
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
main: {
jsr cls
lda #<$400
sta utoa16w.dst
lda #>$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
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
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
lda #>dst
sta utoa16n.dst+1
jsr utoa16n
lda value
ldx #$f
axs #0
lda #<dst
sta utoa16n.dst
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
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 #<screen+$3e7+1
bne b1
rts
}
// Digits used for utoa()
DIGITS: .text "0123456789abcdef@"