1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-01-10 16:29:48 +00:00

c64: updates, .ca65 -> .s, joystick #2

This commit is contained in:
Steven Hugg 2024-10-30 13:58:10 -05:00
parent 19c2032545
commit a91b721609
32 changed files with 91 additions and 87 deletions

View File

@ -7,10 +7,10 @@
#include "sidplaysfx.h"
//#resource "sidmusic1.bin"
//#link "sidplaysfx.ca65"
//#link "sidplaysfx.s"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "bcd.h"
//#link "bcd.c"
@ -647,7 +647,7 @@ void pickup_object(Actor* actor) {
}
void move_player() {
char joy = joy_read(0);
char joy = joy_read(1);
move_actor(&actors[0], joy, true);
pickup_object(&actors[0]);
}

View File

@ -63,7 +63,7 @@ void main(void) {
clrscr();
digi_setup();
while (1) {
digi_play(digisound, 0xacf8L);
digi_play(digisound, sizeof(digisound));
printf("\nPress ENTER to restart digi...\n");
getchar();
}

View File

@ -3,7 +3,7 @@
//#link "common.c"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "bcd.h"
//#link "bcd.c"

View File

@ -20,7 +20,7 @@
#include "sprites.h"
//#link "sprites.c"
//#link "level2.ca65"
//#link "level2.s"
#define CAMERA_OFFSET_X 158
#define CAMERA_OFFSET_Y 120
@ -57,8 +57,8 @@ extern const byte chartileset_tag_data[];
extern const byte map_data[];
static byte framecount;
static byte framemask;
static byte framecount; // frame counter
static byte framemask; // single bit rotates each frame
const byte BITMASKS[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
@ -112,17 +112,18 @@ static void build_tile_flag_map(void) {
}
}
static void draw_cell(word ofs, byte scrn_x, byte scrn_y) {
byte ch, color;
void draw_cell(word ofs, byte scrn_x, byte scrn_y) {
byte ch, color; // character and color to draw
// get the character and color from the level map
if (get_cell_at(scrn_x + origin_x, scrn_y + origin_y)) {
ch = tilechar;
color = chartileset_colour_data[tileindex];
ch = tilechar; // character from tileset
color = chartileset_colour_data[tileindex]; // color from tileset
} else {
ch = DEFAULT_CHAR;
color = DEFAULT_COLOR;
ch = DEFAULT_CHAR; // default character
color = DEFAULT_COLOR; // default color
}
hidbuf[ofs] = ch;
colorbuf[ofs] = color;
hidbuf[ofs] = ch; // draw character to hidden buffer
colorbuf[ofs] = color; // draw color to color buffer
}
void scroll_draw_column(byte col) {
@ -273,12 +274,12 @@ typedef enum {
} ActorState;
typedef struct Actor {
word xx;
word yy;
sbyte xvel;
sbyte yvel;
word xx; // X coord
word yy; // Y coord
sbyte xvel; // X velocity
sbyte yvel; // Y velocity
ActorState state;
bool faceleft;
bool faceleft; // facing left?
} Actor;
Actor actors[MAX_ACTORS];
@ -290,7 +291,7 @@ void draw_actor(register Actor* actor, byte index) {
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;
ypos = 255; // hide the sprite
}
switch (actor->state) {
case STANDING:
@ -318,23 +319,10 @@ const char velocity_bitmasks[8] = {
0b01110101, // 5/8
0b11101110, // 6/8
0b11110111, // 7/8
// 0b11111111, // 8/8
};
static byte box[4]; // hit box
/*
void actor_set_position(register Actor* actor,
word world_x,
word world_y,
ActorState state) {
actor->xx = world_x;
actor->yy = world_y;
actor->state = state;
actor->tileindex = (world_x>>5) | (world_y>>5)*MAP_COLS;
}
*/
void move_actor(register Actor* actor,
sbyte cmd_dx,
sbyte cmd_dy) {
@ -553,7 +541,7 @@ void next_frame() {
// increment frame counter
framemask = BITMASKS[++framecount & 7];
// get joystick bits
joy = joy_read(0);
joy = joy_read(1);
// move player
control_actor(player, joy);
// move enemy
@ -615,20 +603,12 @@ void main(void) {
// repaint screen memory w/ the map
scroll_refresh();
player->xx = 3*32+8;
player->yy = 2*32+8-16;
// set player initial position
player->xx = 0;
player->yy = 31;
player->state = STANDING;
/*
player->xx = 32;
player->yy = 0;
player->xx = 33;
player->yy = 100;
player->state = JUMPING;
*/
// actor_set_position(player, 63, 63, STANDING);
// set other actor's initial position
actors[1].xx = 128;
// infinite loop

View File

@ -117,7 +117,7 @@ void main(void) {
sprite_update(DEFAULT_SCREEN);
// get joystick bits
joy = joy_read(0);
joy = joy_read(1);
move_player(joy);
// move other objects
move_non_players();

View File

@ -37,7 +37,7 @@ void main(void) {
// loop forever
while (1) {
// get joystick bits
joy = joy_read(0);
joy = joy_read(1);
// move sprite based on joystick
if (JOY_LEFT(joy)) { x -= 1; } // move left 1 pixel
if (JOY_RIGHT(joy)) { x += 1; } // move right 1 pixel

View File

@ -3,7 +3,7 @@
//#link "common.c"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "bcd.h"
//#link "bcd.c"

View File

@ -189,7 +189,7 @@ char music_update() {
void handleInput() {
char key = 0;
char joy = joy_read(0);
char joy = joy_read(1);
if (joy == 0) return;
if (JOY_UP(joy)) key = 'i';
if (JOY_DOWN(joy)) key = 'k';

View File

@ -104,7 +104,7 @@ void main(void) {
// infinite loop
while (1) {
// get joystick bits
char joy = joy_read(0);
char joy = joy_read(1);
// move sprite based on arrow keys
if (JOY_LEFT(joy)) scroll_horiz(-1);
if (JOY_UP(joy)) scroll_vert(-1);

View File

@ -72,7 +72,7 @@ void main(void) {
while (1) {
static char speed = 1;
// get joystick bits
char joy = joy_read(0);
char joy = joy_read(1);
// speed up scrolling while button pressed
speed = JOY_BTN_1(joy) ? 2 : 1;
// move sprite based on arrow keys

View File

@ -101,7 +101,7 @@ void main(void) {
static char joy;
static bool slowframe = false;
// get joystick bits
joy = joy_read(0);
joy = joy_read(1);
// speed up scrolling while button pressed
speed = JOY_BTN_1(joy) ? 3 : 1;
// if we copied screen memory last frame,

View File

@ -11,7 +11,7 @@
//#link "common.c"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
// generated from https://8bitworkshop.com/bitmapfontgenerator/
// 16 x 32 MSB first y offset 6 Terminus

View File

@ -20,7 +20,7 @@
#include "sprites.h"
//#link "sprites.c"
//#link "level1.ca65"
//#link "level2.s"
extern const byte charset_data[];
extern const byte charset_attrib_data[];
@ -152,7 +152,7 @@ void main(void) {
static char joy;
static bool slowframe = false;
// get joystick bits
joy = joy_read(0);
joy = joy_read(1);
// speed up scrolling while button pressed
speed = JOY_BTN_1(joy) ? 3 : 1;
// if we copied screen memory last frame,

View File

@ -9,7 +9,7 @@
#define CFGFILE c64-sid.cfg
//#resource "sidmusic1.bin"
//#link "sidplaysfx.ca65"
//#link "sidplaysfx.s"
#include "sidplaysfx.h"
static const unsigned char Palette[2] =
@ -85,7 +85,7 @@ void main(void) {
while (1) {
// play sound effect when joystick is moved
byte joy = joy_read(0);
byte joy = joy_read(1);
if (joy) {
sid_sfx(joy & 3);
// exit when fire button pressed

View File

@ -6,7 +6,7 @@
//#link "sprites.c"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "bcd.h"
//#link "bcd.c"
@ -332,7 +332,7 @@ void main() {
detect_player_collision(bg_coll, spr_coll);
// get joystick bits and move player
move_player(joy_read(0));
move_player(joy_read(1));
// move obstacle and powerup sprites
move_items();

View File

@ -30,10 +30,10 @@ typedef struct {
bool human; // is this player a human?
} Player;
Player players[2]; // two player structs
Player players[2]; // player #0 and #1 data
byte frames_per_move;
byte gameover;
byte frames_per_move; // speed of game
byte gameover; // = 1 if game is over
#define START_SPEED 12
#define MAX_SPEED 5
@ -44,6 +44,7 @@ byte gameover;
const char BOX_CHARS[8] = { '+', '+', '+', '+',
'-', '-', '!', '!'};
// draw a box from coordinate (x,y) to (x2,y2)
void draw_box(byte x, byte y, byte x2, byte y2, const char* chars) {
byte x1 = x;
cputcxy(x, y, chars[2]);
@ -60,6 +61,7 @@ void draw_box(byte x, byte y, byte x2, byte y2, const char* chars) {
}
}
// draw the playfield border and score
void draw_playfield() {
draw_box(0,1,COLS-1,ROWS-1,BOX_CHARS);
cputsxy( 0, 0, "plyr1:");
@ -68,10 +70,12 @@ void draw_playfield() {
cputcxy(27, 0, players[1].score+'0');
}
// constants for the 4 cardinal directions
typedef enum { D_RIGHT, D_DOWN, D_LEFT, D_UP } dir_t;
const sbyte DIR_X[4] = { 1, 0, -1, 0 };
const sbyte DIR_Y[4] = { 0, 1, 0, -1 };
// initialize game and player data
void init_game() {
memset(players, 0, sizeof(players));
players[0].head_attr = '1';
@ -81,6 +85,7 @@ void init_game() {
frames_per_move = START_SPEED;
}
// reset players to initial conditions
void reset_players() {
players[0].x = players[0].y = 5;
players[0].dir = D_RIGHT;
@ -90,10 +95,12 @@ void reset_players() {
players[0].collided = players[1].collided = 0;
}
// draw player character at head
void draw_player(Player* p) {
cputcxy(p->x, p->y, p->head_attr);
}
// move player and detect collision
void move_player(Player* p) {
cputcxy(p->x, p->y, p->tail_attr);
p->x += DIR_X[p->dir];
@ -103,12 +110,13 @@ void move_player(Player* p) {
draw_player(p);
}
// read joystick and move player
void human_control(Player* p) {
byte dir = 0xff;
char joy;
if (!p->human) return;
if (!kbhit()) return;
joy = joy_read(0);
joy = joy_read(1);
if (JOY_UP(joy)) dir = D_UP;
if (JOY_LEFT(joy)) dir = D_LEFT;
if (JOY_RIGHT(joy)) dir = D_RIGHT;
@ -119,6 +127,9 @@ void human_control(Player* p) {
}
}
// AI player: try to move in direction 'dir'
// the number of squares (1 << shift)
// return 1 if successful, and change p->dir
byte ai_try_dir(Player* p, dir_t dir, byte shift) {
byte x,y;
dir &= 3;
@ -133,6 +144,7 @@ byte ai_try_dir(Player* p, dir_t dir, byte shift) {
}
}
// AI computer player routine
void ai_control(Player* p) {
dir_t dir;
if (p->human) return;
@ -147,9 +159,9 @@ void ai_control(Player* p) {
}
}
// flash player(s) that collided
void flash_colliders() {
byte i;
// flash players that collided
for (i=0; i<56; i++) {
delay(2);
revers(players[0].collided && (i&1));
@ -160,6 +172,7 @@ void flash_colliders() {
revers(0);
}
// move both players
void make_move() {
byte i;
for (i=0; i<frames_per_move; i++) {
@ -176,6 +189,7 @@ void make_move() {
textcolor(COLOR_WHITE);
}
// end of game, show the winner
void declare_winner(byte winner) {
byte i;
clrscr();
@ -190,6 +204,8 @@ void declare_winner(byte winner) {
gameover = 1;
}
// play a round of the game
// if someone got MAX_SCORE points, show the winner
void play_round() {
reset_players();
clrscr();
@ -214,6 +230,7 @@ void play_round() {
}
}
// play a complete game until someone wins
void play_game() {
gameover = 0;
init_game();
@ -223,6 +240,7 @@ void play_game() {
}
}
// main routine
void main() {
joy_install (joy_static_stddrv);
play_game();

View File

@ -2,7 +2,7 @@
//#link "common.c"
#include "common.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "rasterirq.h"
//#link "sprites.c"

View File

@ -2,7 +2,7 @@
//#link "common.c"
#include "common.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "rasterirq.h"
//#link "sprites.c"

View File

@ -2,7 +2,7 @@
//#link "common.c"
#include "common.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "rasterirq.h"
//#link "sprites.c"

View File

@ -3,7 +3,7 @@
//#link "common.c"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#include "bcd.h"
//#link "bcd.c"

View File

@ -3,10 +3,10 @@
//#link "common.c"
#include "multisprite.h"
//#link "multisprite.ca65"
//#link "multisprite.s"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#define NUM_TEST_SPRITES 24

View File

@ -2,10 +2,10 @@
#include "common.h"
//#link "common.c"
//#link "multisprite.ca65"
//#link "multisprite.s"
#include "rasterirq.h"
//#link "rasterirq.ca65"
//#link "rasterirq.s"
#define NUM_TEST_SPRITES 24

View File

@ -703,6 +703,12 @@ export class WASIRunner {
__syscall_readlinkat: this.path_readlinkat.bind(this),
__syscall_getcwd() { warning("TODO: getcwd"); return WASIErrors.NOTSUP; },
__syscall_rmdir() { warning("TODO: rmdir"); return WASIErrors.NOTSUP; },
segfault() { warning("TODO: segfault"); return WASIErrors.NOTSUP; },
alignfault() { warning("TODO: alignfault"); return WASIErrors.NOTSUP; },
__wasilibc_cwd: new WebAssembly.Global({
value: 'i32',
mutable: true
}, 0)
}
}
}

View File

@ -160,11 +160,11 @@ export class C64_WASMMachine extends BaseWASMMachine
var mask = 0;
var mask2 = 0;
switch (key) {
case 32: mask = 0x10; break;
case 37: key = 0x8; mask = 0x4; break; // LEFT
case 38: key = 0xb; mask = 0x1; break; // UP
case 39: key = 0x9; mask = 0x8; break; // RIGHT
case 40: key = 0xa; mask = 0x2; break; // DOWN
case 32: mask = mask2 = 0x10; break; // FIRE
case 37: key = 0x8; mask = mask2 = 0x4; break; // LEFT
case 38: key = 0xb; mask = mask2 = 0x1; break; // UP
case 39: key = 0x9; mask = mask2 = 0x8; break; // RIGHT
case 40: key = 0xa; mask = mask2 = 0x2; break; // DOWN
case 113: key = 0xf1; break; // F2
case 115: key = 0xf3; break; // F4
case 119: key = 0xf5; break; // F8

View File

@ -82,16 +82,18 @@ describe('test WASI cc7800', function () {
});
});
/*
describe('test WASI oscar64', function () {
it('oscar64 compile', async function () {
let shim = await loadOscar64();
const zipdata = fs.readFileSync(`./src/worker/fs/oscar64-fs.zip`);
shim.fs = await unzipWASIFilesystem(zipdata, "/root/");
// https://github.com/WebAssembly/wasi-filesystem/issues/24
// https://github.com/WebAssembly/wasi-libc/pull/214
shim.addPreopenDirectory("/root");
shim.fs.putSymbolicLink("/proc/self/exe", "/root/bin/oscar64");
shim.fs.putFile("/root/main.c", "#include <stdio.h>\nint main() { return 0; }");
shim.setArgs(["oscar64", '-v', '-o=foo.prg', 'main.c']);
shim.fs.putFile("/root/main.c", `#include <stdio.h>\nint main() { printf("FOO"); return 0; }`);
shim.setArgs(["oscar64", '-v', '-g', '-O', '-o=foo.prg', 'main.c']);
let errno = shim.run();
const stdout = shim.fds[1].getBytesAsString();
console.log(stdout);
@ -99,7 +101,6 @@ describe('test WASI oscar64', function () {
console.log(stderr);
assert.strictEqual(errno, 0);
assert.ok(stdout.indexOf('Starting oscar64') >= 0);
console.log(shim.fs.getFile("./foo.asm").getBytesAsString());
console.log(shim.fs.getFile("/root/foo.asm").getBytesAsString());
});
});
*/

View File

@ -180,7 +180,6 @@ export function linkLD65(step: BuildStep): BuildStepResult {
//'--dbgfile', 'main.dbg', // TODO: get proper line numbers
'-o', 'main',
'-m', 'main.map'].concat(step.args, libargs);
//console.log(args);
execMain(step, LD65, args);
if (errors.length)
return { errors: errors };
@ -325,7 +324,6 @@ export function compileCC65(step: BuildStep): BuildStepResult {
var customArgs = params.extra_compiler_args || ['-T', '-g', '-Oirs', '-Cl', '-W', '-pointer-sign,-no-effect'];
args = args.concat(customArgs, args);
args.push(step.path);
//console.log(args);
execMain(step, CC65, args);
if (errors.length)
return { errors: errors };

View File

@ -47,7 +47,7 @@ export async function compileOscar64(step: BuildStep): Promise<BuildStepResult>
if (errors.length) {
return { errors };
}
const output = wasi.fs.getFile(destpath).getBytes();
const output = wasi.fs.getFile(rootDir + destpath).getBytes();
putWorkFile(destpath, output);
return {
output,

View File

@ -81,6 +81,7 @@ export function execMain(step: BuildStep, mod, args: string[]) {
var run = mod.callMain || mod.run; // TODO: run?
run(args);
endtime(step.tool);
console.log('exec', step.tool, args.join(' '));
}
/// asm.js / WASM / filesystem loading