From 3fa7d73e70651dc90305f4f16a189bdd257b1c9d Mon Sep 17 00:00:00 2001 From: not_a_robot06 Date: Sun, 16 Feb 2025 10:33:39 +0000 Subject: handle up/down cursor movement - use GETIN kernal routine for handling input than my old crappy way - CLRCHN clears keyboard buffer before use - reset now clears screen - add subroutines a16b and s16b to add and subtract to num, respectively --- life.asm | 73 ++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'life.asm') diff --git a/life.asm b/life.asm index 2745dc6..44e3996 100644 --- a/life.asm +++ b/life.asm @@ -5,7 +5,9 @@ numL := $02 ; low byte of a 16-bit number numH := $03 ; low byte of a 16-bit number key_buf_len := $c6 key_buf := $0277 +GETIN := $ffe4 CHROUT := $ffd2 +CLRCHN := $e544 ; initialisation: clear screen and set num to point to screen mem start init: @@ -18,17 +20,22 @@ init: sta numH lda #$00 sta numL + jsr CLRCHN jmp loop ; main loop loop: - jsr key_wait - lda key_buf + jsr GETIN + beq loop cmp #$1d ; right arrow beq if_right cmp #$9d ; left arrow beq if_left + cmp #$91 ; up arrow + beq if_up + cmp #$11 ; down arrow + beq if_down cmp #$2d ; reset if - pressed beq if_reset cmp #$20 ; fill cell if space pressed @@ -45,11 +52,19 @@ if_left: jsr dec_num jmp loop +if_up: + lda #40 + jsr s16b + jmp loop + +if_down: + lda #40 + jsr a16b + jmp loop + if_reset: - lda #$04 - sta numH - lda #$00 - sta numL + lda #$93 + jsr CHROUT jmp loop if_space: @@ -67,20 +82,6 @@ if_cell_empty: jsr print_byte jmp loop - -; loops until keyboard buffer has any number of characters in it -key_wait: - pha -key_wait_loop: - lda key_buf_len ; shows how many keys are in key buffer - cmp #$00 - beq key_wait_loop - - lda #$00 - sta key_buf_len - pla - rts - ; print byte in A at location in num print_byte: ; init: store original A in X and push Y to stack @@ -98,22 +99,30 @@ print_byte: txa rts -; adds A to num (16 bit) (NOT WORKING) -; destroys: X +; adds A to num a16b: + clc + adc numL + sta numL + lda #$00 + adc numH + sta numH + rts + +; subtracts A from num +s16b: pha - tsx lda numL - adc $0100,x + tsx + inx + sec + sbc $0100,x sta numL - bcs a16b_carry - jmp a16b_end - a16b_carry: - inc numH - a16b_end: - clc - pla - rts + lda numH + sbc #$00 + sta numH + pla + rts inc_num: inc numL -- cgit v1.2.3