diff --git a/test-programs/move-pixel-with-keypad.asm b/test-programs/move-pixel-with-keypad.asm new file mode 100644 index 0000000..d6fa898 --- /dev/null +++ b/test-programs/move-pixel-with-keypad.asm @@ -0,0 +1,144 @@ +; Draw a pixel, and move it when a key is pressed +; 2023-08-26 + +;; WIP - up and right should be working, +;; but currently they're being tested with a +;; faked keyboard input at the end of @xy2id +;; (and down and left are still TODO) + +#flagZ 1 +#flagN 2 +#keypad $1B ; contains latest key pressed + +; Starting (x, y) coordinates +#input_x 1 +#input_y 2 + +; Some handy shortcuts +#x $FA +#y $FB +#px_addr $FD ; holds return value from @xy2id +#return_addr_ptr $FE + +; Main variables: +; F8 +; F9 - xy2id temp +; FA - x coord +; FB - y coord +; FC - xy2id temp +; FD - xy2id return value / xy2id temp +; FE - Return address for subroutine + + +@setup + LDA #input_x + STO #x + LDA #input_y + STO #y + LDA @update + STO #return_addr_ptr + JMP @xy2id + + +@update + ; draw pixel + LDA $FF + STO (#px_addr) + + ; determine direction + #up 2 + #right 6 + #down 8 + #left 4 + ;; #key_copy $FC + + ; test up + lda (#keypad) + sub #up + ftg #flagZ + fhp #flagZ + jmp @up + + ; test right + lda (#keypad) + sub #right + ftg #flagZ + fhp #flagZ + jmp @right + + ; TODO: down, left + end + + @up + lda (#y) + sub 1 + ftg #flagN + fhp #flagN + jmp @stay_put + sto #y + ; redundant - it's already in there: + lda @update + sto #return_addr_ptr + jmp @xy2id + + @right + lda (#x) + sub 4 + ftg #flagZ + fhp #flagZ + jmp @stay_put + lda (#x) + add 1 + sto #x + ; redundant - it's already in there: + lda @update + sto #return_addr_ptr + jmp @xy2id + + @stay_put + ; draw pixel + LDA $FF + STO (#px_addr) + ; TODO + END + + +;; Convert a pair of (x, y) coords +;; to the address of a pixel on the display +;; +;; Call with: +;; - x in #x +;; - y in #y +;; - return address in #return_addr_ptr +;; +;; Returns: +;; - pixel address in #px_addr +@xy2id + ; stash x, y... + #xy2id_y $FC + #xy2id_x $F9 + LDA (#y) + STO #xy2id_y + LDA (#x) + STO #xy2id_x + STO #px_addr + + ; check if this is row 0... + LDA (#xy2id_y) + FHP #flagZ + JMP @xy2id_loop + JMP (#return_addr_ptr) ; if row 0, we're done + + @xy2id_loop + LDA (#px_addr) + ADD 5 ; add 5 to get to the next row + STO #px_addr + LDA (#xy2id_y) ; decrement y (it's acting as a loop counter) ... + SUB 1 + STO #xy2id_y + FHP #flagZ + JMP @xy2id_loop + ;; JUST TO TEST: LOAD #up INTO KEYPAD MEM: + lda #right + sto #keypad + JMP (#return_addr_ptr) \ No newline at end of file