mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-07 20:31:32 +00:00
Improved utoa16 implementation using pointer to pointer.
This commit is contained in:
parent
ff7e4bff2a
commit
aaf556abe1
@ -65,27 +65,21 @@ void utoa10w(unsigned int value, unsigned char* dst) {
|
|||||||
*dst = 0;
|
*dst = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Holds the destination address for the hexadecimal utoa()
|
|
||||||
unsigned char* utoa16_dst;
|
|
||||||
// Holds whether the hexadecimal utoa() has started outputting digits
|
|
||||||
unsigned char utoa16_started;
|
|
||||||
|
|
||||||
// Hexadecimal utoa() for an unsigned int (16bits)
|
// Hexadecimal utoa() for an unsigned int (16bits)
|
||||||
void utoa16w(unsigned int value, unsigned char* dst) {
|
void utoa16w(unsigned int value, unsigned char* dst) {
|
||||||
utoa16_dst = dst;
|
unsigned char started = 0;
|
||||||
utoa16_started = 0;
|
started = utoa16n((>value)>>4, &dst, started);
|
||||||
utoa16n((>value)>>4);
|
started = utoa16n((>value)&0x0f, &dst, started);
|
||||||
utoa16n((>value)&0x0f);
|
started = utoa16n((<value)>>4, &dst, started);
|
||||||
utoa16n((<value)>>4);
|
utoa16n((<value)&0x0f, &dst, 1);
|
||||||
utoa16_started = 1;
|
*dst = 0;
|
||||||
utoa16n((<value)&0x0f);
|
|
||||||
*utoa16_dst = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hexadecimal utoa() for a single nybble
|
// Hexadecimal utoa() for a single nybble
|
||||||
void utoa16n(unsigned char nybble) {
|
unsigned char utoa16n(unsigned char nybble, unsigned **dst, unsigned char started) {
|
||||||
if(nybble!=0) utoa16_started=1;
|
if(nybble!=0) started=1;
|
||||||
if(utoa16_started!=0) {
|
if(started!=0) {
|
||||||
*utoa16_dst++ = DIGITS[nybble];
|
*(*dst)++ = DIGITS[nybble];
|
||||||
}
|
}
|
||||||
|
return started;
|
||||||
}
|
}
|
@ -5,11 +5,9 @@
|
|||||||
.label control = $d011
|
.label control = $d011
|
||||||
.label raster = $d012
|
.label raster = $d012
|
||||||
.label bordercol = $d020
|
.label bordercol = $d020
|
||||||
.label utoa16_dst = 2
|
|
||||||
.label utoa16_started = 4
|
|
||||||
main: {
|
main: {
|
||||||
.label _1 = 4
|
.label _1 = 4
|
||||||
.label time_start = 5
|
.label time_start = 4
|
||||||
sei
|
sei
|
||||||
jsr cls
|
jsr cls
|
||||||
b1:
|
b1:
|
||||||
@ -25,53 +23,53 @@ main: {
|
|||||||
sta bordercol
|
sta bordercol
|
||||||
lda raster
|
lda raster
|
||||||
sta time_start
|
sta time_start
|
||||||
lda #0
|
|
||||||
sta utoa16w.value
|
|
||||||
sta utoa16w.value+1
|
|
||||||
lda #<$400
|
lda #<$400
|
||||||
sta utoa16w.dst
|
sta utoa16w.dst
|
||||||
lda #>$400
|
lda #>$400
|
||||||
sta utoa16w.dst+1
|
sta utoa16w.dst+1
|
||||||
|
lda #0
|
||||||
|
sta utoa16w.value
|
||||||
|
sta utoa16w.value+1
|
||||||
jsr utoa16w
|
jsr utoa16w
|
||||||
inc bordercol
|
inc bordercol
|
||||||
lda #<$4d2
|
|
||||||
sta utoa16w.value
|
|
||||||
lda #>$4d2
|
|
||||||
sta utoa16w.value+1
|
|
||||||
lda #<$400+$28
|
lda #<$400+$28
|
||||||
sta utoa16w.dst
|
sta utoa16w.dst
|
||||||
lda #>$400+$28
|
lda #>$400+$28
|
||||||
sta utoa16w.dst+1
|
sta utoa16w.dst+1
|
||||||
|
lda #<$4d2
|
||||||
|
sta utoa16w.value
|
||||||
|
lda #>$4d2
|
||||||
|
sta utoa16w.value+1
|
||||||
jsr utoa16w
|
jsr utoa16w
|
||||||
inc bordercol
|
inc bordercol
|
||||||
lda #<$162e
|
|
||||||
sta utoa16w.value
|
|
||||||
lda #>$162e
|
|
||||||
sta utoa16w.value+1
|
|
||||||
lda #<$400+$28+$28
|
lda #<$400+$28+$28
|
||||||
sta utoa16w.dst
|
sta utoa16w.dst
|
||||||
lda #>$400+$28+$28
|
lda #>$400+$28+$28
|
||||||
sta utoa16w.dst+1
|
sta utoa16w.dst+1
|
||||||
|
lda #<$162e
|
||||||
|
sta utoa16w.value
|
||||||
|
lda #>$162e
|
||||||
|
sta utoa16w.value+1
|
||||||
jsr utoa16w
|
jsr utoa16w
|
||||||
inc bordercol
|
inc bordercol
|
||||||
lda #<$270f
|
|
||||||
sta utoa16w.value
|
|
||||||
lda #>$270f
|
|
||||||
sta utoa16w.value+1
|
|
||||||
lda #<$400+$28+$28+$28
|
lda #<$400+$28+$28+$28
|
||||||
sta utoa16w.dst
|
sta utoa16w.dst
|
||||||
lda #>$400+$28+$28+$28
|
lda #>$400+$28+$28+$28
|
||||||
sta utoa16w.dst+1
|
sta utoa16w.dst+1
|
||||||
|
lda #<$270f
|
||||||
|
sta utoa16w.value
|
||||||
|
lda #>$270f
|
||||||
|
sta utoa16w.value+1
|
||||||
jsr utoa16w
|
jsr utoa16w
|
||||||
inc bordercol
|
inc bordercol
|
||||||
lda #<$e608
|
|
||||||
sta utoa16w.value
|
|
||||||
lda #>$e608
|
|
||||||
sta utoa16w.value+1
|
|
||||||
lda #<$400+$28+$28+$28+$28
|
lda #<$400+$28+$28+$28+$28
|
||||||
sta utoa16w.dst
|
sta utoa16w.dst
|
||||||
lda #>$400+$28+$28+$28+$28
|
lda #>$400+$28+$28+$28+$28
|
||||||
sta utoa16w.dst+1
|
sta utoa16w.dst+1
|
||||||
|
lda #<$e608
|
||||||
|
sta utoa16w.value
|
||||||
|
lda #>$e608
|
||||||
|
sta utoa16w.value+1
|
||||||
jsr utoa16w
|
jsr utoa16w
|
||||||
ldx raster
|
ldx raster
|
||||||
lda #0
|
lda #0
|
||||||
@ -176,58 +174,51 @@ utoa10w: {
|
|||||||
jmp b1
|
jmp b1
|
||||||
}
|
}
|
||||||
// Hexadecimal utoa() for an unsigned int (16bits)
|
// Hexadecimal utoa() for an unsigned int (16bits)
|
||||||
// utoa16w(word zeropage(6) value, byte* zeropage(2) dst)
|
// utoa16w(word zeropage(2) value, byte* zeropage(6) dst)
|
||||||
utoa16w: {
|
utoa16w: {
|
||||||
.label dst = 2
|
.label value = 2
|
||||||
.label value = 6
|
.label dst = 6
|
||||||
lda value+1
|
lda value+1
|
||||||
lsr
|
lsr
|
||||||
lsr
|
lsr
|
||||||
lsr
|
lsr
|
||||||
lsr
|
lsr
|
||||||
tax
|
ldx #0
|
||||||
lda #0
|
|
||||||
sta utoa16_started
|
|
||||||
jsr utoa16n
|
jsr utoa16n
|
||||||
lda value+1
|
lda value+1
|
||||||
ldx #$f
|
and #$f
|
||||||
axs #0
|
|
||||||
jsr utoa16n
|
jsr utoa16n
|
||||||
lda value
|
lda value
|
||||||
lsr
|
lsr
|
||||||
lsr
|
lsr
|
||||||
lsr
|
lsr
|
||||||
lsr
|
lsr
|
||||||
tax
|
|
||||||
jsr utoa16n
|
jsr utoa16n
|
||||||
lda value
|
lda value
|
||||||
ldx #$f
|
and #$f
|
||||||
axs #0
|
ldx #1
|
||||||
lda #1
|
|
||||||
sta utoa16_started
|
|
||||||
jsr utoa16n
|
jsr utoa16n
|
||||||
lda #0
|
lda #0
|
||||||
tay
|
tay
|
||||||
sta (utoa16_dst),y
|
sta (dst),y
|
||||||
rts
|
rts
|
||||||
}
|
}
|
||||||
// Hexadecimal utoa() for a single nybble
|
// Hexadecimal utoa() for a single nybble
|
||||||
// utoa16n(byte register(X) nybble)
|
// utoa16n(byte register(A) nybble, byte register(X) started)
|
||||||
utoa16n: {
|
utoa16n: {
|
||||||
cpx #0
|
|
||||||
beq b1
|
|
||||||
lda #1
|
|
||||||
sta utoa16_started
|
|
||||||
b1:
|
|
||||||
lda utoa16_started
|
|
||||||
cmp #0
|
cmp #0
|
||||||
|
beq b1
|
||||||
|
ldx #1
|
||||||
|
b1:
|
||||||
|
cpx #0
|
||||||
beq breturn
|
beq breturn
|
||||||
lda DIGITS,x
|
tay
|
||||||
|
lda DIGITS,y
|
||||||
ldy #0
|
ldy #0
|
||||||
sta (utoa16_dst),y
|
sta (utoa16w.dst),y
|
||||||
inc utoa16_dst
|
inc utoa16w.dst
|
||||||
bne !+
|
bne !+
|
||||||
inc utoa16_dst+1
|
inc utoa16w.dst+1
|
||||||
!:
|
!:
|
||||||
breturn:
|
breturn:
|
||||||
rts
|
rts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user