Created
June 29, 2021 23:55
-
-
Save alannakelly/904b5deccebb1cb292ec1ad87e1bb4b4 to your computer and use it in GitHub Desktop.
Player 84 - Commodore 64 Moveable Sprite in 84 bytes
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
; Player 84 | |
; | |
; Commodore 64 Moveable Sprite in 84b | |
; | |
; Joystick in Port 2 to move sprite. | |
; Purely for fun to see how few bytes it | |
; can be done in. Public Domain, do what | |
; you want with the code but credit is | |
; always appreciated. | |
; | |
; By: https://github.com/alannakelly | |
; Date: 2021-06-30 | |
!to "player84.prg",cbm | |
; Kernal CLS Routine | |
INIT_SCREEN = $e544 | |
; Variables | |
player_x = $d000 | |
player_y = $d001 | |
player_c = $d027 | |
; Start at BASIC | |
* = $801 | |
; BASIC Launcher | |
!08 $0b, $08, $0a, $00, $9e ; 10 SYS | |
!08 $32, $30, $36, $31 ; 2061 | |
!08 $00, $00, $00 ; End | |
; Setup screen and sprites | |
; X = 0 | |
; Set Background to Black | |
stx $d020 | |
stx $d021 | |
dex ; X = 255 | |
; Make a Square Player Sprite | |
txa ; A = 255 | |
ldx #63 ; 63 bytes in a sprite pattern | |
; Using 132 because the Y will be 132 | |
; after calling INIT_SCREEN | |
- | |
sta 132*64,x | |
dex | |
bpl - | |
; Clear Screen | |
jsr INIT_SCREEN | |
; Setup Player | |
sty $07f8 ; Set sprite pointer | |
sty player_x ; Set player x | |
sty player_y ; Set player y | |
;X = 1 after INIT_SCREEN | |
stx player_c ; set color to white | |
stx $d015 ; enable sprite 1 | |
; Program loop | |
main: | |
; Read Joystick Port 2 | |
lda $dc00 | |
; Read Up | |
lsr ; Up -> Carry | |
bcs down ; If C==0 up is pushed | |
dec player_y ; player_y-- | |
down: ; Read Down | |
lsr | |
bcs left | |
inc player_y ; player_y++ | |
left: ; Read Left | |
lsr | |
bcs right | |
dec player_x ; player_x-- | |
right: ; Read Right | |
lsr | |
bcs vsync | |
inc player_x ; player_x++ | |
; Wait for next frame | |
vsync: | |
lda $d012 | |
cmp #$ff | |
bne vsync | |
; Loop | |
bpl main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment