1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-27 04:49:27 +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.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer; import dk.camelot64.kickc.model.types.SymbolTypePointer;
import java.util.Objects;
/** A pointer to a symbol (variable or procedure) */ /** A pointer to a symbol (variable or procedure) */
public class ConstantSymbolPointer implements ConstantValue { public class ConstantSymbolPointer implements ConstantValue {
@ -44,4 +46,18 @@ public class ConstantSymbolPointer implements ConstantValue {
public String toString() { public String toString() {
return toString(null); 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 lsr
lsr lsr
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
ldx #0 ldx #0
jsr utoa16n jsr utoa16n
lda value+1 lda value+1
and #$f and #$f
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
jsr utoa16n jsr utoa16n
lda value lda value
lsr lsr
lsr lsr
lsr lsr
lsr lsr
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
jsr utoa16n jsr utoa16n
lda value lda value
and #$f and #$f
tay
lda #<dst
sta utoa16n.dst
lda #>dst
sta utoa16n.dst+1
ldx #1 ldx #1
jsr utoa16n jsr utoa16n
lda #0 lda #0
@ -101,26 +81,22 @@ utoa16w: {
rts rts
} }
// Hexadecimal utoa() for a single nybble // 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: { utoa16n: {
.label dst = 6 cmp #0
cpy #0
beq b1 beq b1
ldx #1 ldx #1
b1: b1:
cpx #0 cpx #0
beq breturn beq breturn
tay
lda DIGITS,y lda DIGITS,y
ldy dst
sty !++1
ldy #0 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: breturn:
rts rts
} }

View File

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

View File

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