.export init .feature c_comments numL := $02 ; low byte of a 16-bit number numH := $03 ; low byte of a 16-bit number num2L := $04 num2H := $05 GETIN := $ffe4 CHROUT := $ffd2 CLRCHN := $e544 ; one byte for each cell, 1000 bytes because 40x25 screen; is identical to ; screen memory (i.e. $a0 is alive and $20 is dead) prev_grid := $0801 ; initialisation: clear screen and set num to point to screen mem start init: ; clear screen lda #$93 jsr CHROUT ldy #$00 lda #$00 sta numH sta numL jsr CLRCHN jmp loop ; main loop ; num stores offset from grid loop: 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 beq if_space cmp #$30 ; end program if 0 pressed bne loop jmp end if_right: jsr inc_num jmp loop 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 #$93 jsr CHROUT jmp loop if_space: lda numL sta num2L lda numH clc adc #$04 sta num2H ldy #$00 lda (num2L),y cmp #$a0 beq if_cell_filled jmp if_cell_empty if_cell_filled: lda #$20 jsr print_byte jmp loop if_cell_empty: lda #$a0 jsr print_byte jmp loop ; print byte in A at location in screen_mem+num; destroys Y; num2 is expected ; to be $0400 (screen_mem zero location) and is set to that at the end print_byte: tay lda numH pha clc adc #$04 sta numH tya ldy #$00 sta (numL),y pla sta numH rts ; adds A to num a16b: clc adc numL sta numL lda #$00 adc numH sta numH rts ; adds A to num2 a16b2: clc adc num2L sta num2L lda #$00 adc num2H sta num2H rts ; subtracts A from num (destroys X) s16b: pha lda numL tsx inx sec sbc $0100,x sta numL lda numH sbc #$00 sta numH pla rts ; might change functions to take from stack but this is easier for now as I ; only have 2 16 bit numbers to deal with anyways ; subtracts A from num2 (destroys X) s16b2: pha lda num2L tsx inx sec sbc $0100,x sta num2L lda num2H sbc #$00 sta num2H pla rts inc_num: inc numL beq inc_H rts inc_H: inc numH rts dec_num: pha dec numL lda numL cmp #$ff beq dec_H pla rts dec_H: dec numH pla rts end: brk