a2d/desk.acc/puzzle.s

1204 lines
37 KiB
ArmAsm
Raw Normal View History

.setcpu "6502"
2017-09-11 03:40:32 +00:00
.include "apple2.inc"
2017-09-15 04:13:54 +00:00
.include "../inc/apple2.inc"
2017-09-11 03:40:32 +00:00
.include "../inc/auxmem.inc"
2018-01-05 05:57:50 +00:00
.include "../inc/prodos.inc"
2017-09-11 03:40:32 +00:00
2018-01-29 05:18:00 +00:00
.include "../mgtk.inc"
.include "../desktop.inc" ; redraw icons after window move, font
2018-02-07 02:42:00 +00:00
.include "../macros.inc"
.org $800
2017-09-11 03:40:32 +00:00
jmp copy2aux
.res 36, 0
2017-09-11 03:40:32 +00:00
;;; ==================================================
;;; Copy the DA to AUX and invoke it
2017-09-11 06:09:33 +00:00
stash_stack: .byte 0
.proc copy2aux
tsx
2017-09-11 03:40:32 +00:00
stx stash_stack
start := enter_da
end := last
sta ALTZPOFF
2017-09-12 04:06:37 +00:00
lda ROMIN2
2018-02-07 02:42:00 +00:00
copy16 #start, STARTLO
copy16 #end, ENDLO
copy16 #start, DESTINATIONLO
sec ; main>aux
jsr AUXMOVE
2018-02-07 02:42:00 +00:00
copy16 #enter_da, XFERSTARTLO
php
pla
ora #$40 ; set overflow: use aux zp/stack
pha
plp
sec ; control main>aux
jmp XFER
.endproc
;;; ==================================================
;;; Set up / tear down
.proc exit_da
sta ALTZPON
lda LCBANK1
lda LCBANK1
2017-09-11 03:40:32 +00:00
ldx stash_stack
txs
rts
.endproc
.proc enter_da
sta ALTZPON
lda LCBANK1
lda LCBANK1
2017-09-11 06:09:33 +00:00
lda #0
sta $08
2017-09-12 03:38:58 +00:00
jmp create_window
.endproc
2018-01-31 08:05:54 +00:00
da_window_id := 51
2017-09-11 06:09:33 +00:00
;;; ==================================================
2018-02-03 04:10:19 +00:00
;;; Redraw the screen (all windows) after a event_kind_drag
2017-09-18 15:10:19 +00:00
.proc redraw_screen
dest := $20
2017-09-18 15:10:19 +00:00
;; copy following routine to $20 and call it
2017-09-12 03:38:58 +00:00
ldx #sizeof_routine
loop: lda routine,x
sta dest,x
dex
bpl loop
jsr dest
2017-09-15 02:11:21 +00:00
;; now check the window pos
2018-01-31 08:05:54 +00:00
lda #da_window_id
2017-09-15 02:11:21 +00:00
jsr check_window_pos
2017-09-12 04:06:37 +00:00
2017-09-15 02:11:21 +00:00
bit window_pos_flag
bmi skip
2017-09-11 06:38:20 +00:00
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_REDRAW_ICONS
2017-09-11 06:38:20 +00:00
2017-09-15 02:11:21 +00:00
skip: lda #0
sta window_pos_flag
rts
.proc routine
sta RAMRDOFF
sta RAMWRTOFF
2017-09-18 15:10:19 +00:00
jsr JUMP_TABLE_REDRAW_ALL
sta RAMRDON
sta RAMWRTON
rts
.endproc
2017-09-12 03:38:58 +00:00
sizeof_routine := * - routine
.endproc
;;; ==================================================
2017-09-12 03:38:58 +00:00
;;; ???
screen_height := 192
2017-09-15 02:11:21 +00:00
window_pos_flag:
.byte 0 ; ???
2017-09-12 04:06:37 +00:00
;; called with window_id in A
2017-09-15 02:11:21 +00:00
check_window_pos:
2018-01-31 08:05:54 +00:00
sta getwinport_params_window_id
lda winfo_viewloc_ycoord ; is top on screen?
2017-09-12 03:38:58 +00:00
cmp #screen_height-1
2017-09-12 04:06:37 +00:00
bcc :+ ; yes
lda #$80 ; no, so ... ???
2017-09-15 02:11:21 +00:00
sta window_pos_flag
rts
2018-01-30 04:14:34 +00:00
: MGTK_CALL MGTK::GetWinPort, getwinport_params
MGTK_CALL MGTK::SetPort, setport_params
2018-01-31 08:05:54 +00:00
lda getwinport_params_window_id
cmp #da_window_id
2017-09-12 03:38:58 +00:00
bne :+
2017-09-15 02:11:21 +00:00
jmp draw_window
2017-09-12 03:38:58 +00:00
: rts
;;; ==================================================
;;; Param Blocks
2017-09-12 04:06:37 +00:00
;; following memory space is re-used so x/y overlap
2018-01-31 08:05:54 +00:00
.proc dragwindow_params
window_id := * + 0
dragx := * + 1 ; x overlap
dragy := * + 3 ; y overlap
it_moved := * + 5 ; ignored
.endproc
2018-01-30 04:14:34 +00:00
.proc screentowindow_params
2018-01-31 08:05:54 +00:00
window_id := * + 0
2017-09-12 04:06:37 +00:00
screenx := * + 1 ; x overlap
screeny := * + 3 ; y overlap
2018-01-31 08:05:54 +00:00
windowx := * + 5
windowy := * + 7
.endproc
2018-01-30 04:14:34 +00:00
.proc event_params
2018-01-30 05:11:32 +00:00
kind: .byte 0
key := *
modifiers := *+1
2017-09-12 04:06:37 +00:00
xcoord := * ; x overlap
ycoord := *+2 ; y overlap
.endproc
2018-01-30 04:14:34 +00:00
.proc findwindow_params
2018-01-31 08:05:54 +00:00
mousex := * ; x overlap
mousey := *+2 ; y overlap
which_area := *+4
window_id := *+5
2017-09-12 04:06:37 +00:00
.endproc
.res 8, 0 ; storage for above
2017-09-12 04:06:37 +00:00
.byte 0,0 ; ???
2017-09-12 03:38:58 +00:00
2018-01-30 04:14:34 +00:00
.proc trackgoaway_params
2018-01-31 08:05:54 +00:00
goaway:.byte 0
2017-09-12 03:38:58 +00:00
.endproc
2018-01-30 04:14:34 +00:00
.proc getwinport_params
2018-01-31 08:05:54 +00:00
window_id: .byte 0
a_grafport: .addr setport_params
.endproc
2018-01-31 08:05:54 +00:00
getwinport_params_window_id := getwinport_params::window_id
2017-09-12 04:06:37 +00:00
;; Puzzle piece row/columns
2017-09-12 03:38:58 +00:00
cw := 28
c1 := 5
c2 := c1 + cw
c3 := c2 + cw
c4 := c3 + cw
rh := 16
r1 := 3
r2 := r1 + rh
r3 := r2 + rh
r4 := r3 + rh
space_positions: ; left, top for all 16 holes
.word c1,r1
.word c2,r1
.word c3,r1
.word c4,r1
.word c1,r2
.word c2,r2
.word c3,r2
.word c4,r2
.word c1,r3
.word c2,r3
.word c3,r3
.word c4,r3
.word c1,r4
.word c2,r4
.word c3,r4
.word c4,r4
2017-09-11 05:58:30 +00:00
2017-09-14 04:58:37 +00:00
.proc bitmap_table
2017-09-12 04:06:37 +00:00
.addr piece1, piece2, piece3, piece4
.addr piece5, piece6, piece7, piece8
.addr piece9, piece10, piece11, piece12
.addr piece13, piece14, piece15, piece16
2017-09-11 05:58:30 +00:00
.endproc
2017-09-11 06:09:33 +00:00
;; Current position table
position_table:
.res 16, 0
2017-09-11 05:58:30 +00:00
2018-01-31 08:05:54 +00:00
.proc paintbits_params
2017-09-11 05:58:30 +00:00
left: .word 0
top: .word 0
2018-01-30 04:49:42 +00:00
mapbits: .addr 0
mapwidth: .byte 4
2018-01-31 08:05:54 +00:00
.byte 0 ; reserved
DEFINE_RECT 0, 0, 27, 15
2017-09-11 05:58:30 +00:00
.endproc
piece1:
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece2:
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%0000000),px(%0011111),px(%1111110)
.byte px(%0111000),px(%1010101),px(%0100001),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece3:
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1110001),px(%1111110)
.byte px(%0111111),px(%1111111),px(%0010101),px(%0111110)
.byte px(%0111111),px(%1111101),px(%0101010),px(%1011110)
.byte px(%0111111),px(%1110010),px(%1010101),px(%0111110)
.byte px(%0111111),px(%1100101),px(%0101010),px(%0111110)
.byte px(%0111111),px(%0001010),px(%1010100),px(%1111110)
.byte px(%0111110),px(%1010101),px(%0101001),px(%1111110)
.byte px(%0111101),px(%0101010),px(%1000111),px(%1111110)
.byte px(%0111010),px(%1010101),px(%0011111),px(%1111110)
.byte px(%0110101),px(%0101000),px(%0111111),px(%1111110)
.byte px(%0110010),px(%1010011),px(%1111111),px(%1111110)
.byte px(%0110101),px(%0001111),px(%1111100),px(%0000000)
.byte px(%0110000),px(%1111111),px(%1000010),px(%1010100)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece4:
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0000111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0101000),px(%0111111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece5:
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1110100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1101010)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1011110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%0111110)
.byte px(%0111111),px(%1111111),px(%1111110),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111101),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111101),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111011),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1110111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1110111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1110110),px(%1101100)
.byte px(%0111111),px(%1111111),px(%1101101),px(%1011010)
.byte px(%0111111),px(%1111111),px(%1101011),px(%0110110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece6:
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0010101),px(%0101010),px(%1010101),px(%0101010)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0010101),px(%0101010),px(%1010101),px(%0101010)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0110110),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0101101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece7:
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0010101),px(%0101010),px(%1010101),px(%0101010)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0010101),px(%0101010),px(%1010101),px(%0101010)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0110110),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0101101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece8:
.byte px(%0101010),px(%1010001),px(%1111111),px(%1111110)
.byte px(%0010101),px(%0101010),px(%0111111),px(%1111110)
.byte px(%0101010),px(%1010101),px(%0001111),px(%1111110)
.byte px(%0010101),px(%0101010),px(%1000111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%0011111),px(%1111110)
.byte px(%0111111),px(%1111110),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111101),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111011),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1110111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1110111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1101111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1101111),px(%1111111),px(%1111110)
.byte px(%0101101),px(%1001111),px(%1111111),px(%1111110)
.byte px(%0011011),px(%0011111),px(%1111111),px(%1111110)
.byte px(%0110110),px(%1011111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece9:
.byte px(%0111111),px(%1111111),px(%1110011),px(%0110110)
.byte px(%0111111),px(%1111111),px(%1110110),px(%1101100)
.byte px(%0111111),px(%1111111),px(%1110101),px(%1011010)
.byte px(%0111111),px(%1111111),px(%1110011),px(%0110110)
.byte px(%0111111),px(%1111111),px(%1111010),px(%1010100)
.byte px(%0111111),px(%1111111),px(%1111010),px(%1010100)
.byte px(%0111111),px(%1111111),px(%1111100),px(%1010100)
.byte px(%0111111),px(%1111111),px(%1111110),px(%1010100)
.byte px(%0111111),px(%1111111),px(%1111110),px(%1010100)
.byte px(%0111111),px(%1111111),px(%1111110),px(%1010100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%0010100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1001100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1100110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1110100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111010)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece10:
.byte px(%0101101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0110110),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0101101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0100110),px(%0110011),px(%0011001),px(%1001100)
.byte px(%0110011),px(%0011001),px(%1001100),px(%1100110)
.byte px(%0100110),px(%0110011),px(%0011001),px(%1001100)
.byte px(%0110011),px(%0011001),px(%1001100),px(%1100110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece11:
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0110110),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0101101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0101010),px(%1010101),px(%0101010),px(%1010100)
.byte px(%0100110),px(%0110011),px(%0011001),px(%1001100)
.byte px(%0110011),px(%0011001),px(%1001100),px(%1100110)
.byte px(%0100110),px(%0110011),px(%0011001),px(%1001100)
.byte px(%0110011),px(%0011001),px(%1001100),px(%1100110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece12:
.byte px(%0110110),px(%1011111),px(%1111111),px(%1111110)
.byte px(%0101101),px(%1011111),px(%1111111),px(%1111110)
.byte px(%0011011),px(%0101111),px(%1111111),px(%1111110)
.byte px(%0110110),px(%1101111),px(%1111111),px(%1111110)
.byte px(%0101010),px(%1010111),px(%1111111),px(%1111110)
.byte px(%0101010),px(%1010011),px(%1111111),px(%1111110)
.byte px(%0101010),px(%1010011),px(%1111111),px(%1111110)
.byte px(%0101010),px(%1010101),px(%1111111),px(%1111110)
.byte px(%0101010),px(%1010100),px(%1111111),px(%1111110)
.byte px(%0101010),px(%1010101),px(%0011111),px(%1111110)
.byte px(%0101010),px(%1010101),px(%0100111),px(%1111110)
.byte px(%0100110),px(%0110011),px(%0010111),px(%1111110)
.byte px(%0110011),px(%0011001),px(%1001111),px(%1111110)
.byte px(%0100110),px(%0110011),px(%0001111),px(%1111110)
.byte px(%0110011),px(%0011001),px(%1011111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
2017-09-12 03:38:58 +00:00
piece13: ; the hole
2017-09-11 05:58:30 +00:00
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111011),px(%1011101),px(%1101110),px(%1110110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0101110),px(%1110111),px(%0111011),px(%1011100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111011),px(%1011101),px(%1101110),px(%1110110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0101110),px(%1110111),px(%0111011),px(%1011100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111011),px(%1011101),px(%1101110),px(%1110110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0101110),px(%1110111),px(%0111011),px(%1011100)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111011),px(%1011101),px(%1101110),px(%1110110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece14:
.byte px(%0001100),px(%1100110),px(%0110011),px(%0011000)
.byte px(%0100110),px(%0110011),px(%0011001),px(%1001100)
.byte px(%0110011),px(%0011001),px(%1001100),px(%1100110)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0100101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0110010),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0111001),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0111110),px(%0111011),px(%0110110),px(%1101100)
.byte px(%0111111),px(%1000101),px(%1011000),px(%0000000)
.byte px(%0111111),px(%1111000),px(%0000001),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece15:
.byte px(%0001100),px(%1100110),px(%0110011),px(%0011000)
.byte px(%0100110),px(%0110011),px(%0011001),px(%1001100)
.byte px(%0110011),px(%0011001),px(%1001100),px(%1100110)
.byte px(%0110110),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0101101),px(%1011011),px(%0110110),px(%1101100)
.byte px(%0110110),px(%1101101),px(%1011011),px(%0110110)
.byte px(%0011011),px(%0110110),px(%1101101),px(%1011010)
.byte px(%0000000),px(%0000000),px(%0000110),px(%1101100)
.byte px(%0111111),px(%1111111),px(%1100000),px(%0000010)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
piece16:
.byte px(%0001100),px(%1100110),px(%0011111),px(%1111110)
.byte px(%0100110),px(%0110011),px(%0111111),px(%1111110)
.byte px(%0110011),px(%0011000),px(%1111111),px(%1111110)
.byte px(%0101101),px(%1011001),px(%1111111),px(%1111110)
.byte px(%0110110),px(%1100111),px(%1111111),px(%1111110)
.byte px(%0011011),px(%0011111),px(%1111111),px(%1111110)
.byte px(%0101110),px(%0111111),px(%1111111),px(%1111110)
.byte px(%0100111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0111111),px(%1111111),px(%1111111),px(%1111110)
.byte px(%0000000),px(%0000000),px(%0000000),px(%0000000)
.proc fill_rect_params
2018-01-31 08:05:54 +00:00
DEFINE_RECT 1, 0, default_width, default_height
.endproc
.proc pattern_speckles
2018-01-31 08:05:54 +00:00
.byte %01110111
.byte %11011101
.byte %01110111
.byte %11011101
.byte %01110111
.byte %11011101
.byte %01110111
.byte %11011101
.endproc
.byte $00 ; ???
.proc pattern_black
2018-01-31 08:05:54 +00:00
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.endproc
2017-09-11 05:58:30 +00:00
2017-09-12 04:06:37 +00:00
;; ???
.byte $00
.res 8, $FF
.byte $00
2017-09-19 04:43:35 +00:00
;; line across top of puzzle (bitmaps include bottom edges)
.proc set_pos_params
xcoord: .word 5
ycoord: .word 2
.endproc
2018-01-30 04:14:34 +00:00
.proc line_params
2017-09-19 04:43:35 +00:00
xdelta: .word 112
ydelta: .word 0
.endproc
2017-09-12 03:38:58 +00:00
;; hole position (0..3, 0..3)
hole_x: .byte 0
hole_y: .byte 0
;; click location (0..3, 0..3)
click_x: .byte $00
2017-09-15 02:11:21 +00:00
click_y: .byte $00
2017-09-12 03:38:58 +00:00
;; param for draw_row/draw_col
draw_rc: .byte $00
;; params for draw_selected
draw_end: .byte $00
draw_inc: .byte $00
2018-01-30 04:14:34 +00:00
.proc closewindow_params
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id
2017-09-12 04:06:37 +00:00
.endproc
2017-09-15 02:11:21 +00:00
.byte $73,$00,$F7,$FF
.addr str
.byte $01
.byte $00,$00,$00,$00,$00,$06,$00,$05
2017-09-15 02:11:21 +00:00
.byte $00
str: .byte $41,$35,$47,$37,$36,$49 ; "A#G%#I" ?
2017-09-14 04:35:23 +00:00
;; SET_STATE params (filled in by QUERY_STATE)
2018-01-30 04:14:34 +00:00
setport_params:
2017-09-12 04:06:37 +00:00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$0D
.byte $00,$00,$20,$80,$00,$00,$00,$00
.byte $00,$2F,$02,$B1,$00,$00,$01,$02
.byte $06
2017-09-12 03:38:58 +00:00
2017-09-12 04:06:37 +00:00
default_left := 220
default_top := 80
default_width := $79
default_height := $44
2017-09-12 03:38:58 +00:00
2018-01-30 04:49:42 +00:00
.proc winfo
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id
2018-01-30 05:11:32 +00:00
options: .byte MGTK::option_go_away_box
2017-09-12 03:38:58 +00:00
title: .addr name
2018-01-29 05:18:00 +00:00
hscroll:.byte MGTK::scroll_option_none
vscroll:.byte MGTK::scroll_option_none
2018-01-30 04:49:42 +00:00
hthumbmax: .byte 0
hthumbpos: .byte 0
vthumbmax: .byte 0
vthumbpos: .byte 0
2018-01-30 05:11:32 +00:00
status: .byte 0
reserved: .byte 0
2018-01-30 04:49:42 +00:00
mincontwidth: .word default_width
mincontlength: .word default_height
maxcontwidth: .word default_width
maxcontlength: .word default_height
2018-01-31 08:05:54 +00:00
port:
DEFINE_POINT default_left, default_top, viewloc
2018-01-30 04:49:42 +00:00
mapbits: .addr MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
2018-01-31 08:05:54 +00:00
cliprect: DEFINE_RECT 0, 0, default_width, default_height
pattern:.res 8, $FF
2018-01-30 05:11:32 +00:00
colormasks: .byte MGTK::colormask_and, MGTK::colormask_or
2018-01-31 08:05:54 +00:00
penloc: DEFINE_POINT 0, 0
2018-01-30 05:11:32 +00:00
penwidth: .byte 1
penheight: .byte 1
penmode: .byte 0
textback: .byte $7F
textfont: .addr DEFAULT_FONT
nextwinfo: .addr 0
2017-09-15 02:11:21 +00:00
.endproc
2018-01-31 08:05:54 +00:00
winfo_viewloc_ycoord := winfo::viewloc::ycoord
2018-01-31 08:05:54 +00:00
;; This is grafport cruft only below
.proc port_cruft ; Unknown usage
viewloc: DEFINE_POINT default_left, default_top
2018-01-30 04:49:42 +00:00
mapbits: .addr MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
2018-01-31 08:05:54 +00:00
cliprect: DEFINE_RECT 0, 0, default_width, default_height
2017-09-15 02:11:21 +00:00
pattern:.res 8, $FF
2018-01-30 05:11:32 +00:00
colormasks: .byte MGTK::colormask_and, MGTK::colormask_or
2018-01-31 08:05:54 +00:00
penloc: DEFINE_POINT 0, 0
2018-01-30 05:11:32 +00:00
penwidth: .byte 1
penheight: .byte 1
penmode: .byte 0
textback: .byte $7F
textfont: .addr DEFAULT_FONT
2017-09-12 03:38:58 +00:00
.endproc
2017-09-15 02:11:21 +00:00
2018-01-31 08:05:54 +00:00
.byte 0,0 ; ???
2017-09-12 03:38:58 +00:00
name: PASCAL_STRING "Puzzle"
2017-09-11 06:09:33 +00:00
;;; ==================================================
;;; Create the window
2017-09-12 03:38:58 +00:00
.proc create_window
jsr save_zp
2018-01-30 04:49:42 +00:00
MGTK_CALL MGTK::OpenWindow, winfo
2017-09-12 03:38:58 +00:00
;; init pieces
ldy #15
loop: tya
2017-09-11 06:09:33 +00:00
sta position_table,y
dey
2017-09-12 03:38:58 +00:00
bpl loop
2018-01-31 08:05:54 +00:00
lda #da_window_id
2017-09-15 02:11:21 +00:00
jsr check_window_pos
2018-01-29 16:38:23 +00:00
MGTK_CALL MGTK::FlushEvents
2017-09-12 04:06:37 +00:00
;; Scramble?
2017-09-15 02:11:21 +00:00
.proc scramble
ldy #3
sloop: tya
pha
2017-09-11 06:09:33 +00:00
ldx position_table
2017-09-12 03:38:58 +00:00
ldy #0
ploop: lda position_table+1,y
2017-09-11 06:09:33 +00:00
sta position_table,y
iny
2017-09-12 03:38:58 +00:00
cpy #15
bcc ploop
2017-09-11 06:09:33 +00:00
stx position_table+15
pla
tay
dey
2017-09-15 02:11:21 +00:00
bne sloop
2017-09-11 06:09:33 +00:00
ldx position_table
lda position_table+1
sta position_table
stx position_table+1
2017-09-15 02:11:21 +00:00
.endproc
2017-09-12 03:38:58 +00:00
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
2018-01-30 05:11:32 +00:00
lda event_params::kind
2017-09-15 02:11:21 +00:00
beq scramble
2017-09-11 06:38:20 +00:00
jsr check_victory
2017-09-15 02:11:21 +00:00
bcs scramble
2017-09-12 03:38:58 +00:00
jsr draw_all
jsr find_hole
; fall through
.endproc
;;; ==================================================
;;; Input loop and processing
2017-09-12 03:38:58 +00:00
.proc input_loop
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
2018-01-30 05:11:32 +00:00
lda event_params::kind
2018-02-03 04:10:19 +00:00
cmp #MGTK::event_kind_button_down
bne :+
2017-09-12 03:38:58 +00:00
jsr on_click
jmp input_loop
;; key?
2018-02-03 04:10:19 +00:00
: cmp #MGTK::event_kind_key_down
bne input_loop
jsr check_key
jmp input_loop
;; click - where?
2017-09-12 03:38:58 +00:00
on_click:
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::FindWindow, findwindow_params
2018-01-31 08:05:54 +00:00
lda findwindow_params::window_id
cmp #da_window_id
bne bail
2018-01-31 08:05:54 +00:00
lda findwindow_params::which_area
bne :+
bail: rts
;; client area?
2018-01-29 05:18:00 +00:00
: cmp #MGTK::area_content
bne :+
jsr find_click_piece
bcc bail
2017-09-12 06:16:29 +00:00
jmp process_click
2018-01-30 04:49:42 +00:00
;; close port?
2018-01-29 05:18:00 +00:00
: cmp #MGTK::area_close_box
bne check_title
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::TrackGoAway, trackgoaway_params
2018-01-31 08:05:54 +00:00
lda trackgoaway_params::goaway
beq bail
2017-09-12 03:38:58 +00:00
destroy:
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::CloseWindow, closewindow_params
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_REDRAW_ICONS
2017-09-11 03:40:32 +00:00
2017-09-12 03:38:58 +00:00
target = $20 ; copy following to ZP and run it
ldx #sizeof_routine
loop: lda routine,x
sta target,x
dex
2017-09-12 03:38:58 +00:00
bpl loop
jmp target
2017-09-12 03:38:58 +00:00
.proc routine
2017-09-15 02:11:21 +00:00
sta RAMRDOFF
sta RAMWRTOFF
jmp exit_da
2017-09-12 03:38:58 +00:00
.endproc
sizeof_routine := * - routine
;; title bar?
check_title:
2018-01-29 05:18:00 +00:00
cmp #MGTK::area_dragbar
bne bail
2018-01-31 08:05:54 +00:00
lda #da_window_id
sta dragwindow_params::window_id
MGTK_CALL MGTK::DragWindow, dragwindow_params
ldx #$23
2017-09-18 15:10:19 +00:00
jsr redraw_screen
rts
;; on key press - exit if Escape
check_key:
2018-01-30 04:14:34 +00:00
lda event_params::modifiers
bne :+
2018-01-30 04:14:34 +00:00
lda event_params::key
2017-09-15 04:13:54 +00:00
cmp #KEY_ESCAPE
2017-09-12 03:38:58 +00:00
beq destroy
: rts
2017-09-12 03:38:58 +00:00
.endproc
;;; ==================================================
;;; Map click to piece x/y
.proc find_click_piece
2018-01-31 08:05:54 +00:00
lda #da_window_id
sta screentowindow_params::window_id
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::ScreenToWindow, screentowindow_params
2018-01-31 08:05:54 +00:00
lda screentowindow_params::windowx+1
ora screentowindow_params::windowy+1
bne nope ; ensure high bytes are 0
2018-01-31 08:05:54 +00:00
lda screentowindow_params::windowy
ldx screentowindow_params::windowx
2017-09-12 03:38:58 +00:00
cmp #r1
bcc nope
2017-09-12 03:38:58 +00:00
cmp #r2+1
bcs :+
2017-09-15 02:11:21 +00:00
jsr find_click_x
bcc nope
lda #0
beq yep
2017-09-12 03:38:58 +00:00
: cmp #r3+1
bcs :+
2017-09-15 02:11:21 +00:00
jsr find_click_x
bcc nope
lda #1
bne yep
2017-09-12 03:38:58 +00:00
: cmp #r4+1
bcs :+
2017-09-15 02:11:21 +00:00
jsr find_click_x
bcc nope
lda #2
bne yep
2017-09-12 03:38:58 +00:00
: cmp #r4+rh+1
bcs nope
2017-09-15 02:11:21 +00:00
jsr find_click_x
bcc nope
lda #3
2017-09-15 02:11:21 +00:00
yep: sta click_y
sec
rts
nope: clc
rts
.endproc
2017-09-15 02:11:21 +00:00
.proc find_click_x
2017-09-12 03:38:58 +00:00
cpx #c1
bcc nope
2017-09-12 03:38:58 +00:00
cpx #c2
bcs :+
lda #0
beq yep
2017-09-12 03:38:58 +00:00
: cpx #c3+1
bcs :+
lda #1
bne yep
2017-09-12 03:38:58 +00:00
: cpx #c4+1
bcs :+
lda #2
bne yep
2017-09-12 03:38:58 +00:00
: cpx #c4+cw
bcs nope
lda #3
2017-09-15 02:11:21 +00:00
yep: sta click_x
sec
rts
nope: clc
rts
.endproc
;;; ==================================================
;;; Process piece click
2017-09-12 03:38:58 +00:00
hole_piece := 12
2017-09-12 06:16:29 +00:00
.proc process_click
2017-09-15 02:11:21 +00:00
2017-09-12 06:16:29 +00:00
lda #0
2017-09-12 03:38:58 +00:00
ldy hole_y
beq L0FC9
L0FC3: clc
2017-09-12 06:16:29 +00:00
adc #4
dey
bne L0FC3
2017-09-15 02:11:21 +00:00
2017-09-12 03:38:58 +00:00
L0FC9: sta draw_rc
clc
2017-09-12 03:38:58 +00:00
adc hole_x
tay
2017-09-12 03:38:58 +00:00
lda click_x
2017-09-15 02:11:21 +00:00
cmp hole_x
beq click_in_col
lda click_y
2017-09-12 03:38:58 +00:00
cmp hole_y
2017-09-15 02:11:21 +00:00
beq click_in_row
miss: rts ; Click on hole, or not row/col with hole
2017-09-15 02:11:21 +00:00
.proc click_in_row
lda click_x
2017-09-12 03:38:58 +00:00
cmp hole_x
2017-09-15 02:11:21 +00:00
beq miss
bcs after
lda hole_x ; click before of hole
sec
2017-09-15 02:11:21 +00:00
sbc click_x
tax
2017-09-15 02:11:21 +00:00
bloop: lda position_table-1,y
2017-09-11 06:09:33 +00:00
sta position_table,y
dey
dex
2017-09-15 02:11:21 +00:00
bne bloop
2017-09-12 06:16:29 +00:00
beq row
2017-09-15 02:11:21 +00:00
after: lda click_x ; click after hole
sec
2017-09-12 03:38:58 +00:00
sbc hole_x
tax
2017-09-15 02:11:21 +00:00
aloop: lda position_table+1,y
2017-09-11 06:09:33 +00:00
sta position_table,y
iny
dex
2017-09-15 02:11:21 +00:00
bne aloop
2017-09-12 06:16:29 +00:00
beq row
2017-09-15 02:11:21 +00:00
.endproc
.proc click_in_col
lda click_y
2017-09-12 03:38:58 +00:00
cmp hole_y
2017-09-15 02:11:21 +00:00
beq miss
bcs after
lda hole_y ; click before hole
sec
2017-09-15 02:11:21 +00:00
sbc click_y
tax
2017-09-15 02:11:21 +00:00
bloop: lda position_table-4,y
2017-09-11 06:09:33 +00:00
sta position_table,y
dey
dey
dey
dey
dex
2017-09-15 02:11:21 +00:00
bne bloop
2017-09-12 06:16:29 +00:00
beq col
2017-09-15 02:11:21 +00:00
after: lda click_y ; click after hole
sec
2017-09-12 03:38:58 +00:00
sbc hole_y
tax
2017-09-15 02:11:21 +00:00
aloop: lda position_table+4,y
2017-09-11 06:09:33 +00:00
sta position_table,y
iny
iny
iny
iny
dex
2017-09-15 02:11:21 +00:00
bne aloop
.endproc
2017-09-12 06:16:29 +00:00
col: lda #hole_piece
2017-09-11 06:09:33 +00:00
sta position_table,y
2017-09-12 03:38:58 +00:00
jsr draw_col
2017-09-12 06:16:29 +00:00
jmp done
2017-09-12 06:16:29 +00:00
row: lda #hole_piece
2017-09-11 06:09:33 +00:00
sta position_table,y
2017-09-12 03:38:58 +00:00
jsr draw_row
2017-09-12 06:16:29 +00:00
done: jsr check_victory
2017-09-15 02:11:21 +00:00
bcc after_click
2017-09-12 06:16:29 +00:00
;; Yay! Play the sound 4 times
2017-09-15 02:11:21 +00:00
.proc on_victory
2017-09-12 03:38:58 +00:00
ldx #4
2017-09-15 02:11:21 +00:00
loop: txa
pha
jsr play_sound
pla
tax
dex
2017-09-15 02:11:21 +00:00
bne loop
.endproc
after_click:
jmp find_hole
2017-09-12 06:16:29 +00:00
rts ; ???
.endproc
;;; ==================================================
;;; Clear the background
2017-09-15 02:11:21 +00:00
draw_window:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetPattern, pattern_speckles
MGTK_CALL MGTK::PaintRect, fill_rect_params
MGTK_CALL MGTK::SetPattern, pattern_black
2017-09-19 04:43:35 +00:00
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, set_pos_params
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::Line, line_params
2017-09-19 04:43:35 +00:00
2017-09-12 03:38:58 +00:00
jsr draw_all
2018-01-31 08:05:54 +00:00
lda #da_window_id
sta getwinport_params::window_id
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetWinPort, getwinport_params
MGTK_CALL MGTK::SetPort, setport_params
rts
;;; ==================================================
2017-09-11 06:38:20 +00:00
.proc save_zp
ldx #$00
loop: lda $00,x
sta saved_zp,x
dex
2017-09-11 06:38:20 +00:00
bne loop
rts
2017-09-11 06:38:20 +00:00
.endproc
2017-09-11 06:38:20 +00:00
.proc restore_zp
ldx #$00
2017-09-11 06:38:20 +00:00
loop: lda saved_zp,x
sta $00,x
dex
2017-09-11 06:38:20 +00:00
bne loop
rts
2017-09-11 06:38:20 +00:00
.endproc
2017-09-11 06:38:20 +00:00
saved_zp:
.res 256, 0
2017-09-11 03:40:32 +00:00
;;; ==================================================
;;; Draw pieces
2017-09-12 03:38:58 +00:00
.proc draw_all
ldy #1
sty draw_inc
dey
2017-09-12 03:38:58 +00:00
lda #16
sta draw_end
bne draw_selected
.endproc
.proc draw_row ; row specified in draw_rc
lda #1
sta draw_inc
lda draw_rc
tay
clc
2017-09-12 03:38:58 +00:00
adc #4
sta draw_end
bne draw_selected
.endproc
.proc draw_col ; col specified in draw_rc
lda #4
sta draw_inc
ldy hole_x
lda #16
sta draw_end
;; fall through
.endproc
;; Draw pieces from A to draw_end, step draw_inc
.proc draw_selected
tya
pha
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::HideCursor
2018-01-31 08:05:54 +00:00
lda #da_window_id
sta getwinport_params::window_id
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetWinPort, getwinport_params
MGTK_CALL MGTK::SetPort, setport_params
pla
tay
2017-09-12 03:38:58 +00:00
loop: tya
pha
asl a
asl a
tax
2018-02-07 02:42:00 +00:00
copy16 space_positions,x, paintbits_params::left
copy16 space_positions+2,x, paintbits_params::top
2017-09-11 06:09:33 +00:00
lda position_table,y
asl a
tax
2018-02-07 02:42:00 +00:00
copy16 bitmap_table,x, paintbits_params::mapbits
2018-01-31 08:05:54 +00:00
MGTK_CALL MGTK::PaintBits, paintbits_params
pla
clc
2017-09-12 03:38:58 +00:00
adc draw_inc
tay
2017-09-12 03:38:58 +00:00
cpy draw_end
bcc loop
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::ShowCursor
rts
2017-09-12 03:38:58 +00:00
.endproc
;;; ==================================================
;;; Play sound
.proc play_sound
ldx #$80
2017-09-12 03:38:58 +00:00
loop1: lda #$58
loop2: ldy #$1B
delay1: dey
bne delay1
bit SPKR
tay
2017-09-12 03:38:58 +00:00
delay2: dey
bne delay2
sbc #1
beq loop1
bit SPKR
dex
2017-09-12 03:38:58 +00:00
bne loop2
rts
.endproc
;;; ==================================================
;;; Puzzle complete?
2017-09-11 06:38:20 +00:00
;; Returns with carry set if puzzle complete
.proc check_victory ; Allows for swapped indistinct pieces, etc.
;; 0/12 can be swapped
lda position_table
beq :+
cmp #12
bne nope
: ldy #1
c1234: tya
2017-09-11 06:09:33 +00:00
cmp position_table,y
2017-09-11 06:38:20 +00:00
bne nope
iny
2017-09-11 06:38:20 +00:00
cpy #5
bcc c1234
;; 5/6 are identical
2017-09-11 06:09:33 +00:00
lda position_table+5
2017-09-11 06:38:20 +00:00
cmp #5
beq :+
cmp #6
bne nope
: lda position_table+6
cmp #5
beq :+
cmp #6
bne nope
: lda position_table+7
cmp #7
bne nope
2017-09-11 06:09:33 +00:00
lda position_table+8
2017-09-11 06:38:20 +00:00
cmp #8
bne nope
;; 9/10 are identical
2017-09-11 06:09:33 +00:00
lda position_table+9
2017-09-11 06:38:20 +00:00
cmp #9
beq :+
cmp #10
bne nope
: lda position_table+10
cmp #9
beq :+
cmp #10
bne nope
: lda position_table+11
cmp #11
bne nope
;; 0/12 can be swapped
2017-09-11 06:09:33 +00:00
lda position_table+12
2017-09-11 06:38:20 +00:00
beq :+
cmp #12
bne nope
: ldy #13
c131415:tya
2017-09-11 06:09:33 +00:00
cmp position_table,y
2017-09-11 06:38:20 +00:00
bne nope
iny
2017-09-11 06:38:20 +00:00
cpy #16
bcc c131415
rts
2017-09-11 06:38:20 +00:00
nope: clc
rts
2017-09-11 06:38:20 +00:00
.endproc
2017-09-12 03:38:58 +00:00
;;; ==================================================
;;; Find hole piece
2017-09-12 03:38:58 +00:00
.proc find_hole
ldy #15
loop: lda position_table,y
cmp #hole_piece
beq :+
dey
2017-09-12 03:38:58 +00:00
bpl loop
: lda #0
sta hole_x
sta hole_y
tya
2017-09-12 03:38:58 +00:00
again: cmp #4
bcc done
2017-09-11 06:09:33 +00:00
sbc #4
2017-09-12 03:38:58 +00:00
inc hole_y
bne again
done: sta hole_x
rts
2017-09-12 03:38:58 +00:00
.endproc
last := *