• entries
    104
  • comments
    101
  • views
    254275

A C64 game - Step 3

Sign in to follow this  
Endurion

4825 views

Quite similar to step 2 this time we set up sprites. Note that I used another selfmade tool (similar to SpritePad). The file J.SPR contains the sprites and is included into the source as binary. The sprites are located "under" the I/O ROM at $D000 onwards.

step3.png.74af24c791462c939c7f24c3c7cc16ba.png


And another note: Since I'm lazy I built the sprite copy loop to always copy packages of 4 sprites (1 sprite comes as 63 + 1 byte, so 4 make nice 256 byte packages).

The current step should display the known charset garbage and "HELLO" as before, but also show an elegantly handicrafted sprite.


Right below the charset copy routine we add the copy call.

 

          ;take source address from SPRITES
          lda #<SPRITES
          sta ZEROPAGE_POINTER_1
          lda #>SPRITES
          sta ZEROPAGE_POINTER_1 + 1
          jsr CopySprites

 

The sprite copy routine is quite similar to the charset copy but a tad shorter due to the 256 byte packaging:

          ;------------------------------------------------------------
          ;copies sprites from ZEROPAGE_POINTER_1 to ZEROPAGE_POINTER_2
          ; sprites are copied in numbers of four
          ;------------------------------------------------------------
          
!zone CopySprites
CopySprites
          ldy #$00
          ldx #$00
          lda #00
          sta ZEROPAGE_POINTER_2
          lda #$d0
          sta ZEROPAGE_POINTER_2 + 1
          
          ;4 sprites per loop
.SpriteLoop
          lda (ZEROPAGE_POINTER_1),y
          sta (ZEROPAGE_POINTER_2),y
          iny
          bne .SpriteLoop
          
          inx
          inc ZEROPAGE_POINTER_1 + 1
          inc ZEROPAGE_POINTER_2 + 1
          cpx #NUMBER_OF_SPRITES_DIV_4
          bne .SpriteLoop
          
          rts

 

In front of GameLoop we put the sprite display code. The sprite is positioned at coordinates 100,100, the sprite pointer set to the correct image and the sprite is enabled.

          ;set sprite 1 pos
          lda #100
          sta VIC_SPRITE_X_POS
          sta VIC_SPRITE_Y_POS
          
          ;set sprite image
          lda #SPRITE_PLAYER
          sta SPRITE_POINTER_BASE
          
          ;enable sprite 1
          lda #1
          sta VIC_SPRITE_ENABLE

 

step3.zip

Previous Step 2 Next Step 4

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now