Puzzle: victory check

This commit is contained in:
Joshua Bell 2017-09-10 23:38:20 -07:00
parent 2ee842fa96
commit 089a18df14

View File

@ -8,7 +8,6 @@
.include "a2d.inc" .include "a2d.inc"
L0000 := $0000
L0020 := $0020 L0020 := $0020
L4015 := $4015 L4015 := $4015
@ -77,9 +76,11 @@ L0882: lda L08A3,x
jsr L08B4 jsr L08B4
bit L08B3 bit L08B3
bmi L089D bmi L089D
jsr UNKNOWN_CALL jsr UNKNOWN_CALL
.byte $0C .byte $0C
.addr L0000 .addr 0
L089D: lda #0 L089D: lda #0
sta L08B3 sta L08B3
rts rts
@ -470,7 +471,7 @@ L0E02: .byte $50,$00,$00,$20,$80,$00,$00,$00
.byte $00,$00,$06,$50,$75,$7A,$7A,$6C .byte $00,$00,$06,$50,$75,$7A,$7A,$6C
.byte $65 .byte $65
L0E53: jsr L10A5 L0E53: jsr save_zp
A2D_CALL A2D_CREATE_WINDOW, L0DEC A2D_CALL A2D_CREATE_WINDOW, L0DEC
ldy #$0F ldy #$0F
L0E5E: tya L0E5E: tya
@ -502,7 +503,7 @@ L0E79: lda position_table+1,y
A2D_CALL A2D_GET_INPUT, L08DB A2D_CALL A2D_GET_INPUT, L08DB
lda L08DB lda L08DB
beq L0E70 beq L0E70
jsr L1262 jsr check_victory
bcs L0E70 bcs L0E70
jsr L11BB jsr L11BB
jsr L12D2 jsr L12D2
@ -541,7 +542,7 @@ L0EF9: A2D_CALL A2D_DESTROY_WINDOW, L0D9C
jsr UNKNOWN_CALL jsr UNKNOWN_CALL
.byte $0C .byte $0C
.addr L0000 .addr 0
ldx #$09 ldx #$09
L0F07: lda L0F12,x L0F07: lda L0F12,x
@ -714,7 +715,7 @@ L104A: lda #$0C
L1055: lda #$0C L1055: lda #$0C
sta position_table,y sta position_table,y
jsr L11C8 jsr L11C8
L105D: jsr L1262 L105D: jsr check_victory
bcc L106E bcc L106E
ldx #$04 ldx #$04
L1064: txa L1064: txa
@ -740,21 +741,26 @@ L1072: A2D_CALL A2D_SET_PATTERN, L0D72
A2D_CALL A2D_SET_BOX1, L0DB3 A2D_CALL A2D_SET_BOX1, L0DB3
rts rts
L10A5: ldx #$00 .proc save_zp
L10A7: lda L0000,x
sta L10BB,x
dex
bne L10A7
rts
ldx #$00 ldx #$00
L10B2: lda L10BB,x loop: lda $00,x
sta L0000,x sta saved_zp,x
dex dex
bne L10B2 bne loop
rts rts
.endproc
L10BB: .byte 0,0,0,0,0,0,0,0 .proc restore_zp
ldx #$00
loop: lda saved_zp,x
sta $00,x
dex
bne loop
rts
.endproc
saved_zp:
.byte 0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0
@ -861,61 +867,75 @@ L1254: dey
bne L124B bne L124B
rts rts
L1262: lda position_table ;; Returns with carry set if puzzle complete
beq L126B .proc check_victory ; Allows for swapped indistinct pieces, etc.
cmp #$0C ;; 0/12 can be swapped
bne L12D0 lda position_table
L126B: ldy #$01 beq :+
L126D: tya cmp #12
bne nope
: ldy #1
c1234: tya
cmp position_table,y cmp position_table,y
bne L12D0 bne nope
iny iny
cpy #$05 cpy #5
bcc L126D bcc c1234
;; 5/6 are identical
lda position_table+5 lda position_table+5
cmp #$05 cmp #5
beq L1283 beq :+
cmp #$06 cmp #6
bne L12D0 bne nope
L1283: lda position_table+6 : lda position_table+6
cmp #$05 cmp #5
beq L128E beq :+
cmp #$06 cmp #6
bne L12D0 bne nope
L128E: lda position_table+7 : lda position_table+7
cmp #$07 cmp #7
bne L12D0 bne nope
lda position_table+8 lda position_table+8
cmp #$08 cmp #8
bne L12D0 bne nope
;; 9/10 are identical
lda position_table+9 lda position_table+9
cmp #$09 cmp #9
beq L12A7 beq :+
cmp #$0A cmp #10
bne L12D0 bne nope
L12A7: lda position_table+10 : lda position_table+10
cmp #$09 cmp #9
beq L12B2 beq :+
cmp #$0A cmp #10
bne L12D0 bne nope
L12B2: lda position_table+11
cmp #$0B : lda position_table+11
bne L12D0 cmp #11
bne nope
;; 0/12 can be swapped
lda position_table+12 lda position_table+12
beq L12C2 beq :+
cmp #$0C cmp #12
bne L12D0 bne nope
L12C2: ldy #$0D
L12C4: tya : ldy #13
c131415:tya
cmp position_table,y cmp position_table,y
bne L12D0 bne nope
iny iny
cpy #$10 cpy #16
bcc L12C4 bcc c131415
rts rts
L12D0: clc nope: clc
rts rts
.endproc
L12D2: ldy #$0F L12D2: ldy #$0F
L12D4: lda position_table,y L12D4: lda position_table,y