c64: presets

This commit is contained in:
Steven Hugg 2022-08-21 23:30:35 -05:00
parent 1f17baf88e
commit fcad9abcd9
3 changed files with 140 additions and 2 deletions

View File

@ -1,7 +1,7 @@
MAX_MSPRITES = 28
MIN_Y_SPACING = 33
MIN_Y_SPACING = 35
DEBUG = 1
@ -179,6 +179,7 @@ bailout_line: .res 1
.global _msprite_color
.global _msprite_shape
.global _msprite_flags
.global _msprite_last_y
_msprite_order: .res MAX_MSPRITES
_msprite_x_lo: .res MAX_MSPRITES
@ -187,6 +188,7 @@ _msprite_y: .res MAX_MSPRITES
_msprite_color: .res MAX_MSPRITES
_msprite_shape: .res MAX_MSPRITES
_msprite_flags: .res MAX_MSPRITES
_msprite_last_y:.res 1
.global _msprite_x_frac
.global _msprite_xvel_lo

View File

@ -0,0 +1,135 @@
#include "common.h"
//#link "common.c"
#include "multisprite.h"
//#link "multisprite.ca65"
#include "rasterirq.h"
//#link "rasterirq.ca65"
#define NUM_TEST_SPRITES 24
byte* sprite_bank = (byte*)DEFAULT_SCREEN + 0x3f8;
/*{w:12,h:21,bpp:2,brev:1}*/
const char SPRITEMC[3*21] = {
0x00,0xAA,0x80,0x02,0xAA,0xA0,0x0A,0xAA,0xA8,
0x0A,0xAE,0xA8,0x0A,0xBB,0xA8,0x0A,0xBA,0xA8,
0x0A,0xBB,0xA8,0x0A,0xAE,0xA8,0x0A,0xAA,0xA8,
0x09,0xAA,0x98,0x08,0x6A,0x48,0x08,0x1D,0x08,
0x02,0x0C,0x20,0x02,0x0C,0x20,0x02,0x0C,0x20,
0x00,0x8C,0x80,0x00,0x8C,0x80,0x00,0x55,0x40,
0x00,0x77,0x40,0x00,0x5D,0x40,0x00,0x15,0x00
};
void sprite_shape(char* vicbank, byte index, const char* sprite_data) {
memmove(vicbank + index*64, sprite_data, 64);
}
void setup_sprites() {
byte i;
sprite_shape((void*)0x0, 255, SPRITEMC);
for (i=0; i<MAX_MSPRITES; i++) {
msprite_order[i] = i;
msprite_y[i] = 255;
}
for (i=0; i<NUM_TEST_SPRITES; i++) {
int x = i*13+20;
msprite_x_lo[i] = x;
msprite_x_hi[i] = x>>8;
msprite_y[i] = i*0+50;
// msprite_flags[i] = 0;
msprite_shape[i] = 255;
msprite_color[i] = i|8;
}
}
// constants for display list
#define Y0 21
#define Y1 35
#define YS 42
void display_list() {
msprite_render_init();
msprite_render_section();
DLIST_NEXT(Y1+YS*1);
msprite_render_section();
DLIST_NEXT(Y1+YS*2);
msprite_render_section();
DLIST_NEXT(Y1+YS*3);
msprite_render_section();
DLIST_NEXT(Y1+YS*4);
msprite_render_section();
VIC.bordercolor = 3;
msprite_sort();
VIC.bordercolor = 4;
msprite_add_velocity(NUM_TEST_SPRITES);
VIC.bordercolor = 0;
DLIST_RESTART(Y0);
}
void msprite_set_position(byte index, int x, byte y) {
asm("sei");
msprite_x_lo[index] = x;
msprite_x_hi[index] = x >> 8;
msprite_y[index] = y;
asm("cli");
}
void msprite_add_position(byte index, byte dx, byte dy) {
int x;
x = msprite_x_lo[index] | msprite_x_hi[index]*256;
x += dx;
asm("sei");
msprite_x_lo[index] = x;
msprite_x_hi[index] = x >> 8;
msprite_y[index] += dy;
asm("cli");
}
void apply_gravity() {
byte i;
for (i=0; i<NUM_TEST_SPRITES; i++) {
int xvel = msprite_xvel_lo[i] + msprite_xvel_hi[i]*256;
int yvel = msprite_yvel_lo[i] + msprite_yvel_hi[i]*256;
int xpos = msprite_x_lo[i] + msprite_x_hi[i]*256;
int ypos = msprite_y[i];
xpos -= 172;
ypos -= 145;
xvel -= xpos / 8;
yvel -= ypos / 8;
msprite_xvel_lo[i] = xvel;
msprite_xvel_hi[i] = xvel >> 8;
msprite_yvel_lo[i] = yvel;
msprite_yvel_hi[i] = yvel >> 8;
}
}
void do_test() {
byte i;
raster_wait(160);
for (i=0; i<NUM_TEST_SPRITES; i++) {
msprite_yvel_lo[i] = i*8;
//msprite_add_position(i,i&3,i&3);
}
}
void main() {
clrscr();
setup_sprites();
// set colors
VIC.spr_mcolor = 0xff;
VIC.spr_mcolor0 = 4;
VIC.spr_mcolor1 = 7;
DLIST_SETUP(display_list);
while (1) {
do_test();
}
}

View File

@ -12,7 +12,6 @@ const C64_PRESETS = [
{id:'siegegame.c', name:'Siege Game'},
{id:'joymove.c', name:'Sprite Movement'},
{id:'sprite_collision.c', name:'Sprite Collision'},
{id:'test_multiplex.c', name:'Sprite Multiplexing'},
{id:'scroll1.c', name:'Scrolling (Single Buffer)'},
{id:'scroll2.c', name:'Scrolling (Double Buffer)'},
{id:'scroll3.c', name:'Scrolling (Multidirectional)'},
@ -20,6 +19,8 @@ const C64_PRESETS = [
{id:'scroll5.c', name:'Scrolling (Camera Following)'},
{id:'side_scroller.c', name:'Side-Scrolling Game'},
{id:'fullscrollgame.c', name:'Full-Scrolling Game'},
{id:'test_multiplex.c', name:'Sprite Multiplexing (Simple)'},
{id:'test_multispritelib.c', name:'Sprite Multiplexing (Library)'},
{id:'mcbitmap.c', name:'Multicolor Lines+Flood Fill'},
//{id:'mandel.c', name:'Mandelbrot Fractal'},
{id:'musicplayer.c', name:'Music Player'},