Skip to content

Instantly share code, notes, and snippets.

@alannakelly
Created June 30, 2021 09:13
Show Gist options
  • Save alannakelly/e8e0cb2fc9510feb5ed070a72437ac74 to your computer and use it in GitHub Desktop.
Save alannakelly/e8e0cb2fc9510feb5ed070a72437ac74 to your computer and use it in GitHub Desktop.
Player 76 - Commodore 64 Moveable Sprite in 76 bytes
; Player 76
;
; Commodore 64 Moveable Sprite in 76b
;
; 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 "player76.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
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 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
; 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
; This code suggested by @0xC0DE6502
; saves 1b
vsync:
ldx $d012
inx
bne vsync
; Loop
beq main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment