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

Fixed identification of identical Phi RValues that are constant pointers to symbols.

This commit is contained in:
Jesper Gravgaard 2019-05-22 15:29:47 +02:00
parent 67db0f0f6f
commit 39c4f0d6b4
5 changed files with 38 additions and 67 deletions

View File

@ -0,0 +1,4 @@
lda {z1}
sta {c1}
lda {z1}+1
sta {c1}+1

View File

@ -6,6 +6,8 @@ import dk.camelot64.kickc.model.symbols.Symbol;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import java.util.Objects;
/** A pointer to a symbol (variable or procedure) */
public class ConstantSymbolPointer implements ConstantValue {
@ -44,4 +46,18 @@ public class ConstantSymbolPointer implements ConstantValue {
public String toString() {
return toString(null);
}
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
ConstantSymbolPointer that = (ConstantSymbolPointer) o;
return Objects.equals(toSymbol, that.toSymbol);
}
@Override
public int hashCode() {
return Objects.hash(toSymbol);
}
}

View File

@ -60,39 +60,19 @@ utoa16w: {
lsr
lsr
lsr
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
ldx #0
jsr utoa16n
lda value+1
and #$f
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
jsr utoa16n
lda value
lsr
lsr
lsr
lsr
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
jsr utoa16n
lda value
and #$f
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
ldx #1
jsr utoa16n
lda #0
@ -101,26 +81,22 @@ utoa16w: {
rts
}
// Hexadecimal utoa() for a single nybble
// utoa16n(byte register(Y) nybble, word** zeropage(6) dst, byte register(X) started)
// utoa16n(byte register(A) nybble, byte register(X) started)
utoa16n: {
.label dst = 6
cpy #0
cmp #0
beq b1
ldx #1
b1:
cpx #0
beq breturn
tay
lda DIGITS,y
ldy dst
sty !++1
ldy #0
sta (utoa16w.dst),y
inc utoa16w.dst
bne !+
inc utoa16w.dst+1
!:
sta ($ff),y
ldy #0
lda (dst),y
clc
adc #1
sta (dst),y
breturn:
rts
}

View File

@ -4,7 +4,7 @@
.pc = $80d "Program"
.label screen1 = $400
.label screen2 = $400+$28
.label screen = 6
.label screen = 4
bbegin:
lda #<$400
sta screen
@ -13,10 +13,6 @@ bbegin:
jsr main
rts
main: {
lda #<screen
sta setscreen.screen
lda #>screen
sta setscreen.screen+1
lda #<screen1
sta setscreen.val
lda #>screen1
@ -25,10 +21,6 @@ main: {
lda #'a'
ldy #0
sta (screen),y
lda #<screen
sta setscreen.screen
lda #>screen
sta setscreen.screen+1
lda #<screen2
sta setscreen.val
lda #>screen2
@ -39,15 +31,12 @@ main: {
sta (screen),y
rts
}
// setscreen(byte** zeropage(4) screen, byte* zeropage(2) val)
// setscreen(byte* zeropage(2) val)
setscreen: {
.label val = 2
.label screen = 4
ldy #0
lda val
sta (screen),y
iny
sta screen
lda val+1
sta (screen),y
sta screen+1
rts
}

View File

@ -9,33 +9,19 @@ main: {
sta screen
lda #>$400
sta screen+1
lda #<screen
sta sub.dst
lda #>screen
sta sub.dst+1
ldx #'a'
lda #'a'
jsr sub
lda #<screen
sta sub.dst
lda #>screen
sta sub.dst+1
ldx #'b'
lda #'b'
jsr sub
rts
}
// sub(byte register(X) ch, byte** zeropage(2) dst)
// sub(byte register(A) ch)
sub: {
.label dst = 2
txa
ldy dst
sty !++1
ldy #0
sta (main.screen),y
inc main.screen
bne !+
inc main.screen+1
!:
sta ($ff),y
ldy #0
lda (dst),y
clc
adc #1
sta (dst),y
rts
}