1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-28 08:50:22 +00:00

c64: presets

This commit is contained in:
Steven Hugg 2022-08-25 15:52:04 -05:00
parent 936608d6d5
commit fe8f3de450
13 changed files with 247 additions and 55 deletions

View File

@ -37,7 +37,7 @@ typedef enum { false, true } bool; // boolean
CIA2.pra = (CIA2.pra & ~3) | (((((_addr)>>8)&0xc0)>>6)^3);
// set VIC character memory (given the start address)
#define SET_VIC_CHAR(_addr) \
#define SET_VIC_BITMAP(_addr) \
VIC.addr = (VIC.addr & 0b11110001) | ((((_addr)>>8)&0x38)>>2);
// set VIC screen memory (given the start address)

View File

@ -48,21 +48,21 @@
#define FLAG_LADDER 4
// level map data
extern const byte charset_data[];
extern const byte charset_attrib_data[];
extern const byte chartileset_data[];
extern const byte chartileset_colour_data[];
extern const byte chartileset_tag_data[];
extern const byte map_data[];
static byte framecount;
static byte framemask;
const byte BITMASKS[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
extern const byte charset_data[];
extern const byte charset_attrib_data[];
extern const byte chartileset_data[];
extern const byte chartileset_colour_data[];
extern const byte chartileset_tag_data[];
extern const byte* map_row_pointers[];
static byte tileflagmap[MAP_ROWS*MAP_COLS];
static byte tileindex;
static byte tilechar;
@ -74,8 +74,8 @@ static bool get_cell_at(byte world_x, byte world_y) {
if (col < 0 || col >= MAP_COLS || row < 0 || row >= MAP_ROWS) {
return false;
} else {
tileindex = map_row_pointers[row][col];
tilechar = chartileset_data[xofs + yofs*4 + tileindex*16];
tileindex = map_data[col + row * MAP_ROWS];
tilechar = chartileset_data[xofs + (yofs + tileindex*4)*4];
return true;
}
}
@ -283,12 +283,15 @@ typedef struct Actor {
Actor actors[MAX_ACTORS];
Actor* player = &actors[0];
Actor* const player = &actors[0];
void draw_actor(register Actor* actor) {
word xpos = actor->xx;
word ypos = actor->yy;
void draw_actor(register Actor* actor, byte index) {
byte shape = 240;
word xpos = actor->xx + pixofs_x + fine_correct_x + ACTOR_OFFSET_X;
word ypos = actor->yy + pixofs_y + fine_correct_y + ACTOR_OFFSET_Y;
if (xpos > 320 || ypos > 250) {
ypos = 255;
}
switch (actor->state) {
case STANDING:
if (actor->xvel && actor->xx & 4) shape += 4;
@ -303,10 +306,7 @@ void draw_actor(register Actor* actor) {
if (actor->yy & 2) shape += 5;
break;
}
sprite_draw(0,
xpos + pixofs_x + fine_correct_x + ACTOR_OFFSET_X,
ypos + pixofs_y + fine_correct_y + ACTOR_OFFSET_Y,
shape);
sprite_draw(index, xpos, ypos, shape);
}
const char velocity_bitmasks[8] = {
@ -531,10 +531,51 @@ void camera_follow(register Actor* actor) {
}
}
void control_enemy(struct Actor* enemy) {
byte control = 0;
int pdx = player->xx - enemy->xx;
int pdy = player->yy - enemy->yy;
if (pdy > 0) {
control |= JOY_DOWN_MASK;
} else if (pdy < 0) {
control |= JOY_UP_MASK;
}
if (pdx < -32) {
control |= JOY_LEFT_MASK;
} else if (pdx > 32) {
control |= JOY_RIGHT_MASK;
}
control_actor(enemy, control);
}
void next_frame() {
char joy;
// increment frame counter
framemask = BITMASKS[++framecount & 7];
// get joystick bits
joy = joy_read(0);
// move player
control_actor(player, joy);
// move enemy
control_enemy(&actors[1]);
// move the camera if needed
camera_follow(player);
// animate sprites in shadow sprite ram
draw_actor(&actors[0], 0);
draw_actor(&actors[1], 1);
// wait for vblank
wait_vblank();
// then update sprite registers
sprite_update(visbuf);
// do scrolling stuff each frame
scroll_update();
}
void setup_sprites(void) {
sprite_clear();
sprite_set_shapes(SPRITE_DATA, 240, NUM_SPRITE_PATTERNS);
sprshad.spr_color[0] = COLOR_WHITE;
sprshad.spr_color[1] = COLOR_LIGHTRED;
sprshad.spr_mcolor = 0xff;
VIC.spr_mcolor0 = 12;
VIC.spr_mcolor1 = 14;
@ -552,26 +593,6 @@ void setup_charset() {
memcpy((char*)0x8800, charset_data, 0x800);
}
void next_frame() {
char joy;
// increment frame counter
framemask = BITMASKS[++framecount & 7];
// get joystick bits
joy = joy_read(0);
// move player
control_actor(player, joy);
// move the camera if needed
camera_follow(player);
// animate sprite in shadow sprite ram
draw_actor(player);
// wait for vblank
wait_vblank();
// then update sprite registers
sprite_update(visbuf);
// do scrolling stuff each frame
scroll_update();
}
void main(void) {
clrscr();
@ -608,6 +629,7 @@ void main(void) {
player->state = JUMPING;
*/
// actor_set_position(player, 63, 63, STANDING);
actors[1].xx = 128;
// infinite loop
while (1) {

View File

@ -16,9 +16,9 @@ const char SPRITE_DATA[64] = {
void main(void) {
// variables
int x = 172; // sprite X position (16-bit)
char y = 145; // sprite Y position (8-bit)
char bgcoll; // sprite background collision flags
char joy; // joystick flags
byte y = 145; // sprite Y position (8-bit)
byte bgcoll; // sprite background collision flags
byte joy; // joystick flags
// copy sprite pattern to RAM address 0x3800
memcpy((char*)0x3800, SPRITE_DATA, sizeof(SPRITE_DATA));

View File

@ -8,7 +8,7 @@ void setup_bitmap_multi() {
VIC.ctrl1 = 0x38;
VIC.ctrl2 = 0x18;
SET_VIC_BANK(MCB_BITMAP);
SET_VIC_CHAR(MCB_BITMAP);
SET_VIC_BITMAP(MCB_BITMAP);
SET_VIC_SCREEN(MCB_COLORS);
memset((void*)MCB_BITMAP, 0, 0x2000);
memset((void*)MCB_COLORS, 0, 0x800);

View File

@ -13,3 +13,4 @@ void set_pixel(byte x, byte y, byte color);
void draw_line(int x0, int y0, int x1, int y1, byte color);
byte flood_fill(byte x, byte y, byte color);

View File

@ -67,14 +67,13 @@ void camera_follow(byte moving) {
if (dx > 8) dx = 8;
else if (dx < -8) dx = -8;
camerax -= dx;
scroll_horiz(dx);
}
if (dy) {
if (dy > 8) dy = 8;
else if (dy < -8) dy = -8;
cameray -= dy;
scroll_vert(dy);
}
scroll_xy(dx, dy);
}
void main(void) {

View File

@ -108,7 +108,7 @@ void scroll_update() {
}
}
void scroll_left() {
static void scroll_left() {
copy_if_needed();
memmove(hidbuf, hidbuf+1, COLS*ROWS-1);
memmove(colorbuf, colorbuf+1, COLS*ROWS-1);
@ -117,7 +117,7 @@ void scroll_left() {
swap_needed = true;
}
void scroll_up() {
static void scroll_up() {
copy_if_needed();
memmove(hidbuf, hidbuf+COLS, COLS*(ROWS-1));
memmove(colorbuf, colorbuf+COLS, COLS*(ROWS-1));
@ -126,7 +126,7 @@ void scroll_up() {
swap_needed = true;
}
void scroll_right() {
static void scroll_right() {
copy_if_needed();
memmove(hidbuf+1, hidbuf, COLS*ROWS-1);
memmove(colorbuf+1, colorbuf, COLS*ROWS-1);
@ -135,7 +135,7 @@ void scroll_right() {
swap_needed = true;
}
void scroll_down() {
static void scroll_down() {
copy_if_needed();
memmove(hidbuf+COLS, hidbuf, COLS*(ROWS-1));
memmove(colorbuf+COLS, colorbuf, COLS*(ROWS-1));
@ -168,6 +168,11 @@ void scroll_vert(sbyte delta_y) {
}
}
void scroll_xy(sbyte delta_x, sbyte delta_y) {
if (delta_x) scroll_horiz(delta_x);
if (delta_y) scroll_vert(delta_y);
}
void scroll_setup() {
scroll_fine_x = scroll_fine_y = 0;
origin_x = origin_y = 0;

View File

@ -20,6 +20,7 @@ extern byte swap_needed; // TRUE if scroll_update() swaps
void scroll_setup(void);
// scroll in X or Y directions
void scroll_xy(sbyte delta_x, sbyte delta_y);
void scroll_horiz(sbyte delta_x);
void scroll_vert(sbyte delta_y);

File diff suppressed because one or more lines are too long

View File

@ -255,7 +255,7 @@ void detect_player_collision(byte bgcoll, byte sprcoll) {
player_vel_y = -JUMP_VELOCITY;
player_x -= 1;
sprshad.spr_color[PLAYER_INDEX] = COLOR_LIGHTRED;
PLAY_TONE(500);
SID_PLAY_TONE(500);
if (score != 0) { add_score(0x9999); } // BCD -1
update_scoreboard();
} else {
@ -264,7 +264,7 @@ void detect_player_collision(byte bgcoll, byte sprcoll) {
// did we hit powerup?
if (hit_powerup) {
sprshad.spr_color[POWERUP_INDEX] += 1; // cycle colors
PLAY_TONE(8000);
SID_PLAY_TONE(8000);
add_score(1);
update_scoreboard();
}

View File

@ -43,13 +43,13 @@
SID.voice.ctrl = (SID.voice.ctrl & 1) | (options)
// play a quick square wave pulse
#define SID_PULSE_DECAY(voice, period) \
#define SID_PULSE_DECAY(voice, freq) \
SID_STOP(voice) \
SID_FREQ(voice,period); \
SID_FREQ(voice,freq); \
SID_PULSEWIDTH(voice,0x200); \
SID_ADSR(voice,8,8,0,4); \
SID_WAVE(voice,SID_SQUARE|SID_GATE); \
// play a tone if one is not already playing
#define PLAY_TONE(period) \
if (!SID.read3) { SID_PULSE_DECAY(v3, (period)) }
#define SID_PLAY_TONE(freq) \
if (!SID.read3) { SID_PULSE_DECAY(v3, (freq)) }

View File

@ -21,6 +21,7 @@ const C64_PRESETS = [
{id:'fullscrollgame.c', name:'Full-Scrolling Game'},
{id:'test_multiplex.c', name:'Sprite Retriggering'},
{id:'test_multispritelib.c', name:'Sprite Multiplexing Library'},
{id:'scrolling_text.c', name:'Big Scrolling Text'},
{id:'mcbitmap.c', name:'Multicolor Bitmap Mode'},
//{id:'mandel.c', name:'Mandelbrot Fractal'},
{id:'musicplayer.c', name:'Music Player'},

View File

@ -1178,6 +1178,7 @@ var TOOL_PRELOADFS = {
'wiz': 'wiz',
'ecs-vcs': '65-none', // TODO: support multiple platforms
'ecs-nes': '65-nes', // TODO: support multiple platforms
'ecs-c64': '65-c64', // TODO: support multiple platforms
}
//const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay)); // for testing