I'm trying to define and show a sprite, in C, using CC65. It's a mess and I'm not sure what I'm doing wrong, so I'm going to write it afresh here and see if anyone can see what I'm doing wrong.
I am thinking that the following code should be sufficient to define and display a sprite, assuming of course that VRAM has been initialized with the sprite data at location $4000.
First, I have to set the port address in VERA. I'll use port 0.
(Version 2)
#define SPRITE_REGISTERS(spritenum) ((spritenum << 3) + 0xfc00)
//
// set port 0 address and increment
//
VERA.control = 0; // port 0
VERA.address = SPRITE_REGISTERS(1);
VERA.address_hi = VERA_INC_1 + 1; // the "+1" is the VRAM high address bit.
// So $1FC08 begins the registers for sprite 1. Right?
Now I should be able to define sprites.
// sprite blocks are in 32 byte chunks.
#define SPRITE_BLOCK(addr) (addr >> 5)
#define SPRITE_MODE_8BPP 128
#define SPRITE_32_BY_32 (128 + 32)
#define SPRITE_64_BY_64 (196 + 48)
#define SPRITE_DISABLED 0
#define SPRITE_LAYER_BACKGROUND (1 << 2)
#define SPRITE_LAYER_0 (2 << 2)
#define SPRITE_LAYER_1 (3 << 2)
int block = SPRITE_BLOCK(0x4000);
int mode = SPRITE_MODE_8BPP;
int x = 100;
int y = 100;
int z = SPRITE_LAYER_1;
int dimensions = SPRITE_32_BY_32;
int palette_offset = 0;
vera_sprites_enable(1); // cx16.h
VERA.data0 = block & 0xff; // lower VRAM address bits
VERA.data0 = mode + ((block >> 8) & 0x1f);
VERA.data0 = x & 0xff;
VERA.data0 = x >> 8;
VERA.data0 = y & 0xff;
VERA.data0 = y >> 8;
VERA.data0 = z; // leave collision mask and flips alone for now.
VERA.data0 = dimensions + palette_offset;
Question
rje
I'm trying to define and show a sprite, in C, using CC65. It's a mess and I'm not sure what I'm doing wrong, so I'm going to write it afresh here and see if anyone can see what I'm doing wrong.
I am thinking that the following code should be sufficient to define and display a sprite, assuming of course that VRAM has been initialized with the sprite data at location $4000.
First, I have to set the port address in VERA. I'll use port 0.
(Version 2)
Now I should be able to define sprites.
Link to comment
Share on other sites
42 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.