summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile4
-rw-r--r--life.asm119
3 files changed, 125 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5baabe9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.o
+*.prg
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..28e66d4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+run: life.prg
+ x64 life.prg
+life.prg: life.asm
+ cl65 -C /usr/share/cc65/cfg/c64-asm.cfg -u __EXEHDR__ $^ -o $@
diff --git a/life.asm b/life.asm
new file mode 100644
index 0000000..d04fe7f
--- /dev/null
+++ b/life.asm
@@ -0,0 +1,119 @@
+.export init
+
+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
+
+; initialisation: clear screen and set num to point to screen mem start
+init:
+ jsr clear_screen
+ ldy #$00
+ lda #$04
+ sta numH
+ lda #$00
+ sta numL
+ jmp loop
+
+; main loop
+loop:
+ ; clear keyboard buffer; otherwise program will always think a key is pressed
+ lda #$00
+ sta key_buf_len
+
+ jsr key_wait
+ lda key_buf
+ jsr print_byte
+
+ ;pha
+ ;lda #1
+ ;jsr a16b
+ ;pla
+
+ inc numL
+ beq inc_H
+ jmp dinc_H
+ inc_H:
+ inc numH
+dinc_H:
+ cmp #$30
+ bne loop
+ jmp end
+
+; loops until keyboard buffer has any number of characters in it
+key_wait:
+ ; init: pha to retrieve before rts, to keep A intact
+ pha
+key_wait_loop:
+ lda key_buf_len ; shows how many keys are in key buffer
+ cmp #$00
+ beq key_wait_loop
+ pla
+ rts
+
+; clear the screen by filling it with spaces
+; destroys: A, Y, numL & numH (in memory)
+clear_screen:
+ ; init: y = 0 because you can't use indirect addressing without a register,
+ ; load start of screen memory into numL/numH
+ ldy #0
+ lda #$04
+ sta numH
+ lda #$00
+ sta numL
+ jmp cs_loop
+
+ ; add 1 to high bit, return if $08 (screen mem only goes to $07ff)
+ add_carry:
+ inc numH
+ lda numH
+ cmp #$08
+ bne cs_loop
+ rts
+
+ ; store a space in current screen mem address as specified by num, branch if
+ ; number overflows to 0 (i.e. add 1 to high bit of 16 bit number)
+ cs_loop:
+ lda #$20
+ sta (numL),y
+ inc numL
+ beq add_carry
+ jmp cs_loop
+
+; print byte in A at location in num
+print_byte:
+ ; init: store original A in X and push Y to stack
+ tax
+ tya
+ pha
+ txa
+
+ ldy #$00
+ sbc #$40 ; convert (very vaguely) to c64 screen codes
+ sta (numL),y
+
+ ; deinit: pull Y from stack and transfer original A from X to A
+ pla
+ tay
+ txa
+ rts
+
+; adds A to num (16 bit) (NOT WORKING)
+; destroys: X
+a16b:
+ pha
+ tsx
+ lda numL
+ adc $0100,x
+ sta numL
+ bcs a16b_carry
+ jmp a16b_end
+ a16b_carry:
+ inc numH
+ a16b_end:
+ clc
+ pla
+ rts
+
+end:
+ brk