Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bf9a4c2
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
; a blinking ball controllable with WASD | ||
|
||
define W 119 | ||
define S 115 | ||
define A 97 | ||
define D 100 | ||
|
||
jsr init | ||
|
||
loop: | ||
jsr draw_player | ||
jsr clear_player | ||
jsr handle_movement | ||
jmp loop | ||
|
||
init: | ||
ldx #0 ; player position | ||
stx $1 ; make sure $1 is zeroed | ||
lda #1 ; color | ||
rts | ||
|
||
handle_movement: | ||
lda $ff ; load last pressed key | ||
|
||
; reset the last pressed key so that we only move on new input | ||
ldy #0 | ||
sty $ff | ||
|
||
cmp #W | ||
beq move_up | ||
cmp #S | ||
beq move_down | ||
cmp #A | ||
beq move_left | ||
cmp #D | ||
beq move_right | ||
|
||
rts | ||
|
||
move_up: | ||
txa | ||
sbc #$20 | ||
tax | ||
rts | ||
|
||
move_down: | ||
txa | ||
adc #$1f | ||
tax | ||
rts | ||
|
||
move_left: | ||
dex | ||
rts | ||
|
||
move_right: | ||
inx | ||
rts | ||
|
||
draw_player: | ||
lda #1 ; white | ||
sta $0200, X | ||
rts | ||
|
||
clear_player: | ||
lda #0 ; black | ||
sta $0200, X | ||
rts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; A = color to draw | ||
LDA #0 | ||
|
||
; X = graphics index | ||
LDX #0 | ||
|
||
draw: | ||
STA $0200, X ; store A (the color) at $0200 + X | ||
|
||
ADC #1 | ||
|
||
CPX #$ff | ||
INX | ||
BNE draw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
LDA #0 ; color and index | ||
|
||
first_draw_pass: | ||
TAX | ||
STA $0200, X | ||
PHA ; push for the second pass | ||
ADC #1 | ||
CMP #$10 | ||
BNE first_draw_pass | ||
|
||
TAX | ||
DEX | ||
|
||
second_draw_pass: | ||
PLA | ||
INX | ||
STA $0200, X | ||
CPX #$20 | ||
BNE second_draw_pass |