Created
June 30, 2021 09:41
-
-
Save alannakelly/737455bcbf71bdd275636ee215bc9424 to your computer and use it in GitHub Desktop.
Player 74 - Commodore 64 Moveable Sprite in 74 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 74 | |
; | |
; Commodore 64 Moveable Sprite in 74b | |
; | |
; 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. | |
; | |
; Authors and Contributors: | |
; Alanna Kelly | |
; - Original 84 byte version | |
; - Looped joystick read | |
; Roel Nieskens | |
; - Shorter sprite loader | |
; - vsync suggestions | |
; 0xC0DE | |
; - Saved a byte on vsync | |
; | |
; Date: 2021-06-30 | |
!to "player74.prg",cbm | |
; Kernal CLS Routine | |
INIT_SCREEN = $e544 | |
; Variables | |
pl_x = $d000 ; Player x position | |
pl_y = $d001 ; Player y position | |
pl_c = $d027 ; Player color | |
; 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 | |
; Using 132 because the Y will be 132 | |
; after calling INIT_SCREEN | |
; Shorter sprite load suggested by Roel Nieskens | |
- | |
sta 132*64,x | |
inx | |
bpl - | |
; Clear Screen | |
jsr INIT_SCREEN | |
; Setup Player | |
sty $07f8 ; Set sprite pointer | |
sty pl_x ; Set player x | |
sty pl_y ; Set player y | |
;X = 1 after INIT_SCREEN | |
; Set player color to white | |
stx pl_c | |
stx $d015 ; enable sprite 1 | |
txa | |
; Program loop | |
main: | |
; Loop joystick read code | |
ldx #1 | |
; Read Joystick Port 2 | |
lda $dc00 | |
; Joystick read loop. First iteration | |
; checks up and down. Second iteration | |
; checks left and right. | |
joy_read_loop: | |
lsr ; U or L to -> Carry | |
; If C==0 up is pushed | |
bcs down_or_right | |
dec pl_x,x ; pl_y or pl_x -- | |
; Read Down or Right | |
down_or_right: | |
lsr | |
bcs next | |
inc pl_x,x ; pl_y or pl_x ++ | |
next: | |
dex ; X-- | |
; Exit loop if X == -1 ($FF) | |
bpl joy_read_loop | |
; Wait for next frame | |
vsync: | |
cmp $d012 | |
bne vsync | |
; Loop | |
beq main | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment