1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-21 21:29:17 +00:00

npm update

This commit is contained in:
Steven Hugg 2019-12-21 15:06:25 -06:00
parent 39dad45b47
commit 363fbee4a9
6 changed files with 1277 additions and 45 deletions

1140
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,11 +23,11 @@
"jsdom": "^12.2.0",
"lzg": "^1.0.x",
"mocha": "^5.2.x",
"nightwatch": "^1.2.4",
"nightwatch": "^1.3.2",
"octokat": "^0.10.0",
"pngjs": "^3.4.0",
"rgbquant": "^1.1.2",
"typescript": "^3.6.3",
"typescript": "^3.7.4",
"typescript-formatter": "^7.2.2"
},
"main": "main.js",

72
presets/c64/joymove.c Normal file
View File

@ -0,0 +1,72 @@
// ported from
// https://odensskjegg.home.blog/2018/12/29/recreating-the-commodore-64-user-guide-code-samples-in-cc65-part-three-sprites/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <peekpoke.h>
#include <c64.h>
#include <joystick.h>
/*{w:24,h:21,bpp:1,brev:1}*/
const char sprite[3*21] = {
0x00,0x7F,0x00,0x01,0xFF,0xC0,0x03,0xFF,0xE0,
0x03,0xE7,0xE0,0x07,0xD9,0xF0,0x07,0xDF,0xF0,
0x07,0xD9,0xF0,0x03,0xE7,0xE0,0x03,0xFF,0xE0,
0x03,0xFF,0xE0,0x02,0xFF,0xA0,0x01,0x7F,0x40,
0x01,0x3E,0x40,0x00,0x9C,0x80,0x00,0x9C,0x80,
0x00,0x49,0x00,0x00,0x49,0x00,0x00,0x3E,0x00,
0x00,0x3E,0x00,0x00,0x3E,0x00,0x00,0x1C,0x00
};
// Raster wait with line argument
void rasterWait(unsigned char line) {
while (VIC.rasterline < line) ;
}
int main (void)
{
int n;
int x,y;
// install the joystick driver
joy_install (joy_static_stddrv);
// set background color
VIC.bgcolor0 = 3;
// clear interrupts to avoid glitching
__asm__("SEI");
// set sprite bitmap data
for (n = 0 ; n < sizeof(sprite) ; n++) {
POKE(832 + n, sprite[n]);
}
// enable 1st sprite
VIC.spr_ena = 0x01;
// 2x zoom 1st sprite
VIC.spr_exp_x = 0x01;
VIC.spr_exp_y = 0x01;
// set address of sprite data
POKE(2040, 13);
// set initial x/y positions
x = 160;
y = 128;
// loop
while (1) {
// get joystick bits
char joy = joy_read(0);
// move sprite based on arrow keys
if (JOY_LEFT(joy)) --x;
if (JOY_UP(joy)) --y;
if (JOY_RIGHT(joy)) ++x;
if (JOY_DOWN(joy)) ++y;
// set VIC registers based on position
VIC.spr0_x = x;
VIC.spr0_y = y;
VIC.spr_hi_x = (x & 256) ? 1 : 0;
// change color when we collide with background
VIC.spr0_color = (VIC.spr_bg_coll & 1) ? 10 : 0;
// wait for end of frame
rasterWait(255);
}
// uninstall joystick driver (not really necessary)
joy_uninstall();
return EXIT_SUCCESS;
}

92
presets/c64/upandaway.c Normal file
View File

@ -0,0 +1,92 @@
// ported from
// https://odensskjegg.home.blog/2018/12/29/recreating-the-commodore-64-user-guide-code-samples-in-cc65-part-three-sprites/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <peekpoke.h>
#include <c64.h>
/*{w:24,h:21,bpp:1,brev:1}*/
const char sprite[3*21] = {
0x00,0x7F,0x00,0x01,0xFF,0xC0,0x03,0xFF,0xE0,
0x03,0xE7,0xE0,0x07,0xD9,0xF0,0x07,0xDF,0xF0,
0x07,0xD9,0xF0,0x03,0xE7,0xE0,0x03,0xFF,0xE0,
0x03,0xFF,0xE0,0x02,0xFF,0xA0,0x01,0x7F,0x40,
0x01,0x3E,0x40,0x00,0x9C,0x80,0x00,0x9C,0x80,
0x00,0x49,0x00,0x00,0x49,0x00,0x00,0x3E,0x00,
0x00,0x3E,0x00,0x00,0x3E,0x00,0x00,0x1C,0x00
};
// Pre-calculated sinus values
const char yValues[] = {
32, 35, 38, 41, 44, 47, 49, 52,
54, 56, 58, 60, 61, 62, 63, 63,
64, 63, 63, 62, 61, 60, 58, 56,
54, 52, 49, 47, 44, 41, 38, 35,
32, 28, 25, 22, 19, 16, 14, 11,
9, 7, 5, 3, 2, 1, 0, 0,
0, 0, 0, 1, 2, 3, 5, 7,
9, 11, 14, 16, 19, 22, 25, 28
};
// Raster wait with line argument
void rasterWait(unsigned char line) {
while (VIC.rasterline < line) ;
}
int main (void)
{
unsigned char n, t;
int rx, x;
char sx, msb;
VIC.bgcolor0 = 3;
__asm__("SEI"); // clear interrupts to avoid glitching
for (n = 0 ; n < sizeof(sprite) ; n++) {
POKE(832 + n, sprite[n]);
}
VIC.spr_ena = 255;
for (t = 0 ; t < 8 ; t++) {
POKE(2040 + t, 13); // Set sprite x data from 13th block for all sprites
}
do {
for (x = 0 ; x < 550; x++) {
msb = 0; // MSB of X coordinates
// Wait until raster hits position 250 before drawing upper sprites
rasterWait(250);
// Set border color, which indicates the raster position
VIC.bordercolor = 1;
rx = x;
for (t = 0 ; t < 8 ; t++) {
rx -= 24;
if (rx >= 0 && rx < 366) {
// Usually I would calculate the sprite X coordinate using
// the expression sx = rx % 256, but bitwise operation is
// significant faster
sx = rx & 255;
if (rx > 255) {
// Set MSB of x coordinate for sprite if x position > 255
msb |= 1 << t;
}
VIC.spr_pos[t].x = sx;
// Y position is an indirect Sinus function of X, using array
// index for retrieving the Y value
VIC.spr_pos[t].y = yValues[sx & 63] + 40;
} else {
VIC.spr_pos[t].x = 0;
}
}
VIC.spr_hi_x = msb; // Set MSB of x coordinate
// Wait until raster hits position 135 before drawing lower sprites
rasterWait(135);
VIC.bordercolor = 2; // Set border color
for (t = 0 ; t < 8 ; t++) {
// Add 128 to current sprite Y position
VIC.spr_pos[t].y += 128;
}
}
} while (1);
return EXIT_SUCCESS;
}

View File

@ -1140,6 +1140,7 @@ export class WASMMachine implements Machine {
prgstart : number;
initstring : string;
initindex : number;
joymask0 = 0;
constructor(prefix: string) {
this.prefix = prefix;
@ -1189,6 +1190,8 @@ export class WASMMachine implements Machine {
// create audio buffer
var sampbufsize = 4096*4;
this.audioarr = new Float32Array(this.exports.memory.buffer, this.exports.machine_get_sample_buffer(), sampbufsize);
// enable c64 joystick map to arrow keys (TODO)
//this.exports.c64_set_joystick_type(this.sys, 1);
}
reset() {
this.exports.machine_reset(this.sys);
@ -1318,11 +1321,20 @@ export class WASMMachine implements Machine {
if (key == 16 || key == 17 || key == 18 || key == 224) return; // meta keys
//console.log(key, code, flags);
//if (flags & KeyFlags.Shift) { key += 64; }
// convert to c64
var mask = 0;
if (key == 37) { key = 0x8; mask = 0x4; } // LEFT
if (key == 38) { key = 0xb; mask = 0x1; } // UP
if (key == 39) { key = 0x9; mask = 0x8; } // RIGHT
if (key == 40) { key = 0xa; mask = 0x2; } // DOWN
if (flags & KeyFlags.KeyDown) {
this.exports.machine_key_down(this.sys, key);
this.joymask0 |= mask;
} else if (flags & KeyFlags.KeyUp) {
this.exports.machine_key_up(this.sys, key);
this.joymask0 &= ~mask;
}
this.exports.c64_joystick(this.sys, this.joymask0, 0); // TODO: c64
}
connectAudio(audio : SampledAudioSink) : void {
this.audio = audio;

View File

@ -8,6 +8,8 @@ const C64_PRESETS = [
{id:'sidtune.dasm', name:'SID Tune (ASM)'},
{id:'eliza.c', name:'Eliza (C)'},
{id:'tgidemo.c', name:'TGI Graphics Demo (C)'},
{id:'upandaway.c', name:'Up, Up and Away (C)'},
{id:'joymove.c', name:'Joystick Movement (C)'},
];
const C64_MEMORY_MAP = { main:[