mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-06-01 20:41:36 +00:00
Compare commits
3 Commits
master
...
libretro-w
Author | SHA1 | Date | |
---|---|---|---|
|
7183d06e88 | ||
|
a0f7992465 | ||
|
784c7c999d |
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -47,6 +47,7 @@
|
|||
"typescript-formatter": "^7.2.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@wasmer/wasi": "^1.2.2",
|
||||
"chromedriver": "*",
|
||||
"heapdump": "^0.3.15",
|
||||
"jsfuzz": "^1.0.14",
|
||||
|
@ -1046,6 +1047,12 @@
|
|||
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@wasmer/wasi": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@wasmer/wasi/-/wasi-1.2.2.tgz",
|
||||
"integrity": "sha512-39ZB3gefOVhBmkhf7Ta79RRSV/emIV8LhdvcWhP/MOZEjMmtzoZWMzt7phdKj8CUXOze+AwbvGK60lKaKldn1w==",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/abab": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz",
|
||||
|
@ -8829,6 +8836,12 @@
|
|||
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
|
||||
"dev": true
|
||||
},
|
||||
"@wasmer/wasi": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@wasmer/wasi/-/wasi-1.2.2.tgz",
|
||||
"integrity": "sha512-39ZB3gefOVhBmkhf7Ta79RRSV/emIV8LhdvcWhP/MOZEjMmtzoZWMzt7phdKj8CUXOze+AwbvGK60lKaKldn1w==",
|
||||
"optional": true
|
||||
},
|
||||
"abab": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz",
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
"typescript-formatter": "^7.2.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@wasmer/wasi": "^1.2.2",
|
||||
"chromedriver": "*",
|
||||
"heapdump": "^0.3.15",
|
||||
"jsfuzz": "^1.0.14",
|
||||
|
|
300
presets/c64/plasma.c
Normal file
300
presets/c64/plasma.c
Normal file
|
@ -0,0 +1,300 @@
|
|||
/*****************************************************************************\
|
||||
** plasma test program for cc65. **
|
||||
** **
|
||||
** (w)2001 by groepaz **
|
||||
** **
|
||||
** Cleanup and porting by Ullrich von Bassewitz. **
|
||||
** **
|
||||
\*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <conio.h>
|
||||
#include <cc65.h>
|
||||
|
||||
|
||||
|
||||
#if defined(__C64__) || defined(__C128__)
|
||||
# define SCREEN1 0xE000
|
||||
# define SCREEN2 0xE400
|
||||
# define CHARSET 0xE800
|
||||
# define outb(addr,val) (*(addr)) = (val)
|
||||
# define inb(addr) (*(addr))
|
||||
#elif defined(__CBM510__)
|
||||
# define SCREEN1 0xF000
|
||||
# define SCREEN2 0xF400
|
||||
# define CHARSET 0xE000
|
||||
# define outb(addr,val) pokebsys ((unsigned)(addr), val)
|
||||
# define inb(addr) peekbsys ((unsigned)(addr))
|
||||
#elif defined(__PLUS4__)
|
||||
# define SCREEN1 0x6400
|
||||
# define SCREEN2 0x6C00
|
||||
# define CHARSET 0x7000
|
||||
# define outb(addr,val) (*(addr)) = (val)
|
||||
# define inb(addr) (*(addr))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Values for the VIC address register to switch between the two pages */
|
||||
#if defined(__PLUS4__)
|
||||
#define PAGE1 ((SCREEN1 >> 8) & 0xF8)
|
||||
#define PAGE2 ((SCREEN2 >> 8) & 0xF8)
|
||||
#define CHARADR ((CHARSET >> 8) & 0xFC)
|
||||
#else
|
||||
#define PAGE1 ((SCREEN1 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
|
||||
#define PAGE2 ((SCREEN2 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Use static local variables for speed */
|
||||
#pragma static-locals (1);
|
||||
|
||||
|
||||
static const unsigned char sinustable[0x100] = {
|
||||
0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a,
|
||||
0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52,
|
||||
0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c,
|
||||
0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28,
|
||||
0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18,
|
||||
0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c,
|
||||
0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
|
||||
0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
|
||||
0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
|
||||
0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0a,
|
||||
0x0b, 0x0c, 0x0d, 0x0f, 0x10, 0x11, 0x13, 0x15,
|
||||
0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24,
|
||||
0x26, 0x28, 0x2b, 0x2d, 0x2f, 0x32, 0x34, 0x37,
|
||||
0x39, 0x3c, 0x3f, 0x41, 0x44, 0x47, 0x4a, 0x4d,
|
||||
0x4f, 0x52, 0x55, 0x58, 0x5b, 0x5e, 0x61, 0x64,
|
||||
0x67, 0x6a, 0x6d, 0x70, 0x74, 0x77, 0x7a, 0x7d,
|
||||
0x80, 0x83, 0x86, 0x89, 0x8c, 0x90, 0x93, 0x96,
|
||||
0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8, 0xab, 0xae,
|
||||
0xb1, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc1, 0xc4,
|
||||
0xc7, 0xc9, 0xcc, 0xce, 0xd1, 0xd3, 0xd5, 0xd8,
|
||||
0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8,
|
||||
0xea, 0xeb, 0xed, 0xef, 0xf0, 0xf1, 0xf3, 0xf4,
|
||||
0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfa, 0xfb, 0xfc,
|
||||
0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfd,
|
||||
0xfd, 0xfc, 0xfb, 0xfa, 0xfa, 0xf9, 0xf8, 0xf6,
|
||||
0xf5, 0xf4, 0xf3, 0xf1, 0xf0, 0xef, 0xed, 0xeb,
|
||||
0xea, 0xe8, 0xe6, 0xe4, 0xe2, 0xe0, 0xde, 0xdc,
|
||||
0xda, 0xd8, 0xd5, 0xd3, 0xd1, 0xce, 0xcc, 0xc9,
|
||||
0xc7, 0xc4, 0xc1, 0xbf, 0xbc, 0xb9, 0xb6, 0xb3,
|
||||
0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9f, 0x9c,
|
||||
0x99, 0x96, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void doplasma (register unsigned char* scrn)
|
||||
{
|
||||
unsigned char xbuf[40];
|
||||
unsigned char ybuf[25];
|
||||
unsigned char c1a,c1b;
|
||||
unsigned char c2a,c2b;
|
||||
unsigned char c1A,c1B;
|
||||
unsigned char c2A,c2B;
|
||||
register unsigned char i, ii;
|
||||
|
||||
c1a = c1A;
|
||||
c1b = c1B;
|
||||
for (ii = 0; ii < 25; ++ii) {
|
||||
ybuf[ii] = (sinustable[c1a] + sinustable[c1b]);
|
||||
c1a += 4;
|
||||
c1b += 9;
|
||||
}
|
||||
c1A += 3;
|
||||
c1B -= 5;
|
||||
c2a = c2A;
|
||||
c2b = c2B;
|
||||
for (i = 0; i < 40; ++i) {
|
||||
xbuf[i] = (sinustable[c2a] + sinustable[c2b]);
|
||||
c2a += 3;
|
||||
c2b += 7;
|
||||
}
|
||||
c2A += 2;
|
||||
c2B -= 3;
|
||||
for (ii = 0; ii < 25; ++ii) {
|
||||
/* Unrolling the following loop will give a speed increase of
|
||||
** nearly 100% (~24fps), but it will also increase the code
|
||||
** size a lot.
|
||||
*/
|
||||
for (i = 0; i < 40; ++i, ++scrn) {
|
||||
*scrn = (xbuf[i] + ybuf[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void makechar (void)
|
||||
{
|
||||
static const unsigned char bittab[8] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
|
||||
};
|
||||
unsigned char i, ii, b, s;
|
||||
unsigned c;
|
||||
|
||||
gotoxy (0, 1);
|
||||
for (c = 0; c < 0x100; ++c) {
|
||||
s = sinustable[c];
|
||||
for (i = 0; i < 8; ++i){
|
||||
b = 0;
|
||||
for (ii = 0; ii < 8; ++ii) {
|
||||
if ((rand() & 0xFFu) > s) {
|
||||
b |= bittab[ii];
|
||||
}
|
||||
}
|
||||
((unsigned char*)CHARSET) [(c*8) + i] = b;
|
||||
}
|
||||
if ((c & 0x07) == 0) {
|
||||
cputc ('.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
unsigned char border;
|
||||
unsigned char background;
|
||||
unsigned char text;
|
||||
unsigned char v;
|
||||
clock_t t;
|
||||
unsigned long f = 0;
|
||||
unsigned long sec;
|
||||
unsigned sec10;
|
||||
unsigned long fps;
|
||||
unsigned fps10;
|
||||
|
||||
|
||||
#if defined(__C64__)
|
||||
unsigned char block;
|
||||
#endif
|
||||
#if defined(__C128__)
|
||||
unsigned char block;
|
||||
unsigned char initflag;
|
||||
unsigned char graphflag;
|
||||
#endif
|
||||
#if defined(__PLUS4__)
|
||||
unsigned int i;
|
||||
unsigned char v2;
|
||||
#endif
|
||||
|
||||
clrscr ();
|
||||
cprintf ("Making charset, mompls");
|
||||
makechar();
|
||||
|
||||
/* Set the border and background colors */
|
||||
border = bordercolor (COLOR_BLUE);
|
||||
background = bgcolor (COLOR_BLUE);
|
||||
text = textcolor (COLOR_BLACK);
|
||||
clrscr ();
|
||||
|
||||
#if defined(__C64__) || defined(__C128__)
|
||||
/* Move the VIC 16K block */
|
||||
block = inb (&CIA2.pra);
|
||||
outb (&CIA2.pra, (block & 0xFC) | ((SCREEN1 >> 14) ^ 0x03));
|
||||
#endif
|
||||
#if defined(__C128__)
|
||||
/* Save and change some flags, so that kernal/basic interrupt handler will
|
||||
** not interfere with our routine.
|
||||
*/
|
||||
initflag = *(unsigned char*) 0xA04;
|
||||
*(unsigned char*) 0xA04 &= 0xFE;
|
||||
graphflag = *(unsigned char*) 0xD8;
|
||||
*(unsigned char*) 0xD8 = 0xFF;
|
||||
#endif
|
||||
|
||||
/* Remember the VIC address register */
|
||||
#if defined(__PLUS4__)
|
||||
v = inb (&TED.char_addr);
|
||||
v2 = inb (&TED.video_addr);
|
||||
#else
|
||||
v = inb (&VIC.addr);
|
||||
#endif
|
||||
|
||||
#if defined(__PLUS4__)
|
||||
for (i=0;i<1000;i++) {
|
||||
((unsigned char *) (SCREEN1-0x0400))[i] = 0;
|
||||
((unsigned char *) (SCREEN2-0x0400))[i] = 0;
|
||||
}
|
||||
outb (&TED.char_addr, CHARADR);
|
||||
#endif
|
||||
|
||||
/* Run the demo until a key was hit */
|
||||
t = clock ();
|
||||
while (!kbhit()) {
|
||||
/* Build page 1, then make it visible */
|
||||
doplasma ((unsigned char*)SCREEN1);
|
||||
#if defined(__PLUS4__)
|
||||
outb (&TED.video_addr, PAGE1);
|
||||
#else
|
||||
outb (&VIC.addr, PAGE1);
|
||||
#endif
|
||||
|
||||
/* Build page 2, then make it visible */
|
||||
doplasma ((unsigned char*)SCREEN2);
|
||||
#if defined(__PLUS4__)
|
||||
outb (&TED.video_addr, PAGE2);
|
||||
#else
|
||||
outb (&VIC.addr, PAGE2);
|
||||
#endif
|
||||
|
||||
/* Count frames */
|
||||
f += 2;
|
||||
}
|
||||
t = clock() - t;
|
||||
|
||||
/* Switch back the VIC screen */
|
||||
#if defined(__PLUS4__)
|
||||
outb (&TED.video_addr, v2);
|
||||
outb (&TED.char_addr, v);
|
||||
#else
|
||||
outb (&VIC.addr, v);
|
||||
#endif
|
||||
|
||||
#if defined(__C64__) || defined(__C128__)
|
||||
/* Move back the VIC 16K block */
|
||||
outb (&CIA2.pra, block);
|
||||
#endif
|
||||
#if defined(__C128__)
|
||||
/* Restore the flags */
|
||||
*(unsigned char*) 0xA04 = initflag;
|
||||
*(unsigned char*) 0xD8 = graphflag;
|
||||
#endif
|
||||
|
||||
/* Fetch the character from the keyboard buffer and discard it */
|
||||
(void) cgetc();
|
||||
|
||||
/* Reset screen colors */
|
||||
bordercolor (border);
|
||||
bgcolor (background);
|
||||
textcolor (text);
|
||||
clrscr ();
|
||||
|
||||
/* Calculate stats */
|
||||
sec = (t * 10) / CLK_TCK;
|
||||
sec10 = sec % 10;
|
||||
sec /= 10;
|
||||
fps = (f * (CLK_TCK * 10)) / t;
|
||||
fps10 = fps % 10;
|
||||
fps /= 10;
|
||||
|
||||
/* Output stats */
|
||||
gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);
|
||||
gotoxy (0, 1); cprintf ("frames: %lu", f);
|
||||
gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);
|
||||
|
||||
if (doesclrscrafterexit ()) {
|
||||
cputsxy (0, 4, "Press any key when done...");
|
||||
(void) cgetc ();
|
||||
}
|
||||
|
||||
/* Done */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -124,6 +124,7 @@ void update_scoreboard() {
|
|||
|
||||
void add_score(int delta) {
|
||||
score = bcd_add(score, delta);
|
||||
update_scoreboard();
|
||||
}
|
||||
|
||||
// clear scoreboard and draw initial strings
|
||||
|
@ -257,7 +258,6 @@ void detect_player_collision(byte bgcoll, byte sprcoll) {
|
|||
sprshad.spr_color[PLAYER_INDEX] = COLOR_LIGHTRED;
|
||||
SID_PLAY_TONE(500);
|
||||
if (score != 0) { add_score(0x9999); } // BCD -1
|
||||
update_scoreboard();
|
||||
} else {
|
||||
sprshad.spr_color[PLAYER_INDEX] = COLOR_GREEN;
|
||||
}
|
||||
|
@ -266,7 +266,6 @@ void detect_player_collision(byte bgcoll, byte sprcoll) {
|
|||
sprshad.spr_color[POWERUP_INDEX] += 1; // cycle colors
|
||||
SID_PLAY_TONE(8000);
|
||||
add_score(1);
|
||||
update_scoreboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
143
presets/c64/test_display_list.c
Normal file
143
presets/c64/test_display_list.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
|
||||
#include "common.h"
|
||||
//#link "common.c"
|
||||
|
||||
#include "rasterirq.h"
|
||||
//#link "rasterirq.ca65"
|
||||
|
||||
#include "bcd.h"
|
||||
//#link "bcd.c"
|
||||
|
||||
///// DEFINES
|
||||
|
||||
#define GAME_BASE 0x400 // scrolling screen ram
|
||||
#define SCORE_BASE 0x2c00 // scoreboard screen ram
|
||||
|
||||
#define SCROLL_TOP 8 // scroll top row
|
||||
#define SCROLL_ROWS 14 // scroll # of rows
|
||||
#define GROUND_ROW 7 // ground row (+ top row)
|
||||
|
||||
///// VARIABLES
|
||||
|
||||
word scroll_x = 0; // current scroll X position
|
||||
word score = 0; // current player score
|
||||
|
||||
///// FUNCTIONS
|
||||
|
||||
// display list used by rasterirq.h
|
||||
// draws scoreboard and sets scroll register
|
||||
void display_list() {
|
||||
// set x scroll register to scroll value
|
||||
SET_SCROLL_X(scroll_x);
|
||||
// set background color
|
||||
VIC.bgcolor[0] = COLOR_CYAN;
|
||||
// next interrupt is two rows from bottom
|
||||
DLIST_NEXT(250-16);
|
||||
|
||||
// set background color
|
||||
VIC.bgcolor[0] = COLOR_BLUE;
|
||||
// screen memory = 0x2800
|
||||
SET_VIC_SCREEN(SCORE_BASE);
|
||||
// clear x scroll register
|
||||
SET_SCROLL_X(0);
|
||||
// next interrupt is bottom of frame
|
||||
DLIST_NEXT(250);
|
||||
|
||||
// reset screen to 0x400
|
||||
SET_VIC_SCREEN(0x400);
|
||||
// next interrupt is above top of next frame
|
||||
DLIST_RESTART(40);
|
||||
}
|
||||
|
||||
void update_scoreboard() {
|
||||
draw_bcd_word(SCRNADR(SCORE_BASE,7,24), score);
|
||||
}
|
||||
|
||||
void add_score(int delta) {
|
||||
score = bcd_add(score, delta);
|
||||
}
|
||||
|
||||
// clear scoreboard and draw initial strings
|
||||
void init_scoreboard() {
|
||||
memset((void*)SCORE_BASE, ' ', 1024);
|
||||
memcpy((void*)SCRNADR(SCORE_BASE,1,24), "SCORE:", 6);
|
||||
update_scoreboard();
|
||||
}
|
||||
|
||||
byte get_char_for_row(byte row) {
|
||||
// ground?
|
||||
if (row >= GROUND_ROW) { return 253; }
|
||||
// obstacle?
|
||||
if (row >= GROUND_ROW-3) {
|
||||
// only show obstacle for certain values of scroll_x
|
||||
if ((scroll_x & 0b1110000) == 0) { return 247; }
|
||||
}
|
||||
// default is the sky (empty space)
|
||||
return 32;
|
||||
}
|
||||
|
||||
void draw_right_column() {
|
||||
// get the top-right corner address of scroll area
|
||||
word addr = SCRNADR(GAME_BASE, 39, SCROLL_TOP);
|
||||
byte row;
|
||||
// draw one character per row
|
||||
for (row=0; row<SCROLL_ROWS; row++) {
|
||||
POKE(addr, get_char_for_row(row));
|
||||
addr += 40;
|
||||
}
|
||||
}
|
||||
|
||||
void scroll_one_column_left() {
|
||||
// copy several rows of screen memory
|
||||
// backwards one byte
|
||||
const word start = SCRNADR(GAME_BASE, 0, SCROLL_TOP);
|
||||
const word nbytes = SCROLL_ROWS*40-1;
|
||||
memcpy((byte*)start, (byte*)start+1, nbytes);
|
||||
// draw the right column of characters
|
||||
draw_right_column();
|
||||
}
|
||||
|
||||
void scroll_one_pixel_left() {
|
||||
// scroll left one pixel
|
||||
scroll_x -= 1;
|
||||
// set scroll register with lower three bits
|
||||
VIC.ctrl2 = (VIC.ctrl2 & ~7) | (scroll_x & 7);
|
||||
// move screen memory if the scroll register
|
||||
// has just gone past 0 and wrapped to 7
|
||||
if ((scroll_x & 7) == 7) {
|
||||
scroll_one_column_left();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
// clear screen, set background color
|
||||
clrscr();
|
||||
VIC.bgcolor[0] = COLOR_CYAN;
|
||||
VIC.bordercolor = COLOR_BLUE;
|
||||
|
||||
// set vertical scroll = 3, 25 rows
|
||||
VIC.ctrl1 = 0b00011011;
|
||||
// set 38 column mode (for X scrolling)
|
||||
VIC.ctrl2 = 0b00000000;
|
||||
// set uniform color of characters
|
||||
memset(COLOR_RAM, COLOR_WHITE, 1000);
|
||||
|
||||
// setup scoreboard
|
||||
init_scoreboard();
|
||||
|
||||
// setup rasterirq library for scoreboard split
|
||||
DLIST_SETUP(display_list);
|
||||
|
||||
// game loop, repeat forever
|
||||
while (1) {
|
||||
// wait for end of frame
|
||||
waitvsync();
|
||||
|
||||
// scroll screen
|
||||
scroll_one_pixel_left();
|
||||
|
||||
// add to score
|
||||
add_score(0x0001);
|
||||
update_scoreboard();
|
||||
}
|
||||
}
|
BIN
res/quicknes_libretro.wasm
Executable file
BIN
res/quicknes_libretro.wasm
Executable file
Binary file not shown.
BIN
res/stella2014_libretro.wasm
Executable file
BIN
res/stella2014_libretro.wasm
Executable file
Binary file not shown.
51
src/common/libretroplatform.ts
Normal file
51
src/common/libretroplatform.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { init, WASI } from '@wasmer/wasi';
|
||||
import { AnimationTimer } from './emu';
|
||||
import { Platform } from './baseplatform';
|
||||
|
||||
export class BaseLibretroPlatform { // implements Platform {
|
||||
|
||||
mainElement: HTMLElement;
|
||||
timer: AnimationTimer;
|
||||
wasi: WASI;
|
||||
|
||||
constructor(mainElement) {
|
||||
this.mainElement = mainElement;
|
||||
this.timer = new AnimationTimer(60, this.update.bind(this));
|
||||
}
|
||||
|
||||
async start() {
|
||||
// This is needed to load the WASI library first (since is a Wasm module)
|
||||
await init();
|
||||
|
||||
let wasi = new WASI({
|
||||
env: {
|
||||
// 'ENVVAR1': '1',
|
||||
// 'ENVVAR2': '2'
|
||||
},
|
||||
args: [
|
||||
// 'command', 'arg1', 'arg2'
|
||||
],
|
||||
});
|
||||
|
||||
const moduleBytes = fetch("res/quicknes_libretro.wasm");
|
||||
const module = await WebAssembly.compileStreaming(moduleBytes);
|
||||
// Instantiate the WASI module
|
||||
const instance = await wasi.instantiate(module, {});
|
||||
|
||||
// Run the start function
|
||||
let exitCode = wasi.start();
|
||||
let stdout = wasi.getStdoutString();
|
||||
|
||||
// This should print "hello world (exit code: 0)"
|
||||
console.log(`${stdout}(exit code: ${exitCode})`);
|
||||
|
||||
this.wasi = wasi;
|
||||
}
|
||||
|
||||
update() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
reset() {
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ const C64_PRESETS = [
|
|||
{id:'hello.dasm', name:'Hello World (ASM)'},
|
||||
{id:'23matches.c', name:'23 Matches'},
|
||||
{id:'tgidemo.c', name:'TGI Graphics Demo'},
|
||||
{id:'plasma.c', name:'Plasma Demo'},
|
||||
{id:'upandaway.c', name:'Up, Up and Away'},
|
||||
{id:'siegegame.c', name:'Siege Game'},
|
||||
{id:'joymove.c', name:'Sprite Movement'},
|
||||
|
@ -17,6 +18,7 @@ const C64_PRESETS = [
|
|||
{id:'scroll3.c', name:'Scrolling (Multidirectional)'},
|
||||
{id:'scroll4.c', name:'Scrolling (Color RAM Buffering)'},
|
||||
{id:'scroll5.c', name:'Scrolling (Camera Following)'},
|
||||
{id:'test_display_list.c', name:'Display List / Raster IRQ'},
|
||||
{id:'side_scroller.c', name:'Side-Scrolling Game'},
|
||||
{id:'fullscrollgame.c', name:'Full-Scrolling Game'},
|
||||
{id:'test_multiplex.c', name:'Sprite Retriggering'},
|
||||
|
|
|
@ -9,6 +9,7 @@ import { NullProbe, Probeable, ProbeAll } from "../common/devices";
|
|||
import Mousetrap = require('mousetrap');
|
||||
import jsnes = require('../../jsnes');
|
||||
import { BaseMAME6502Platform } from "../common/mameplatform";
|
||||
import { BaseLibretroPlatform } from "../common/libretroplatform";
|
||||
|
||||
const JSNES_PRESETS = [
|
||||
{id:'hello.c', name:'Hello World'},
|
||||
|
@ -567,4 +568,3 @@ class NESMAMEPlatform extends BaseMAME6502Platform implements Platform {
|
|||
PLATFORMS['nes'] = JSNESPlatform;
|
||||
PLATFORMS['nes-asm'] = JSNESPlatform;
|
||||
PLATFORMS['nes.mame'] = NESMAMEPlatform;
|
||||
|
||||
|
|
126
src/test/testlibretro.ts
Normal file
126
src/test/testlibretro.ts
Normal file
|
@ -0,0 +1,126 @@
|
|||
import * as fs from 'fs';
|
||||
import { init, WASI } from '@wasmer/wasi';
|
||||
|
||||
describe('libretro WASI', function () {
|
||||
it('Should run core', async function () {
|
||||
await init();
|
||||
|
||||
let wasi = new WASI({
|
||||
env: {
|
||||
// 'ENVVAR1': '1',
|
||||
// 'ENVVAR2': '2'
|
||||
},
|
||||
args: [
|
||||
// 'command', 'arg1', 'arg2'
|
||||
],
|
||||
});
|
||||
|
||||
// import sock_accept
|
||||
let imports = {
|
||||
wasi_snapshot_preview1: {
|
||||
sock_accept: function (fd, addr, addrlen) {
|
||||
console.log('sock_accept', fd, addr, addrlen);
|
||||
}
|
||||
},
|
||||
env: {
|
||||
// A placeholder implementation of __cxa_allocate_exception
|
||||
__cxa_allocate_exception: (size) => {
|
||||
console.error('__cxa_allocate_exception called with size:', size);
|
||||
// You should allocate 'size' bytes and return a pointer to this memory
|
||||
// The implementation here depends on how your WASM module handles memory
|
||||
// This is just a dummy implementation and likely won't work correctly
|
||||
return 0; // Returning 0 as a dummy pointer
|
||||
},
|
||||
__cxa_throw: (ptr, type, destructor) => {
|
||||
console.error('__cxa_throw called, ptr:', ptr, 'type:', type, 'destructor:', destructor);
|
||||
// This function should not return
|
||||
// This is just a dummy implementation and likely won't work correctly
|
||||
throw new Error('cxa_throw called');
|
||||
},
|
||||
retro_environment_callback: function (cmd, data) {
|
||||
console.log('retro_environment_callback', cmd, data);
|
||||
return 0;
|
||||
},
|
||||
retro_video_refresh_callback: function (data, width, height, pitch) {
|
||||
console.log('retro_video_refresh_callback', data, width, height, pitch);
|
||||
},
|
||||
retro_audio_sample_callback: function (left, right) {
|
||||
console.log('retro_audio_sample_callback', left, right);
|
||||
},
|
||||
retro_audio_sample_batch_callback: function (data, frames) {
|
||||
console.log('retro_audio_sample_batch_callback', data, frames);
|
||||
return frames;
|
||||
},
|
||||
retro_input_poll_callback: function () {
|
||||
console.log('retro_input_poll_callback');
|
||||
},
|
||||
retro_input_state_callback: function (port, device, index, id) {
|
||||
console.log('retro_input_state_callback', port, device, index, id);
|
||||
return 1;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
//const moduleBytes = fs.readFileSync("res/quicknes_libretro.wasm");
|
||||
const moduleBytes = fs.readFileSync("res/stella2014_libretro.wasm");
|
||||
const module = await WebAssembly.compile(moduleBytes);
|
||||
// Instantiate the WASI module
|
||||
const instance = await wasi.instantiate(module, imports);
|
||||
const exports: any = instance.exports;
|
||||
|
||||
// Run the initialize function
|
||||
exports._initialize();
|
||||
|
||||
console.log(exports);
|
||||
console.log('API version', exports.retro_api_version());
|
||||
console.log('callbacks')
|
||||
exports.retro_init_callbacks();
|
||||
console.log('init');
|
||||
exports.retro_init();
|
||||
console.log('loading');
|
||||
const rompath = 'test/roms/nes/shoot2.c.rom';
|
||||
// load rom bytes
|
||||
const romdata = fs.readFileSync(rompath);
|
||||
/*
|
||||
const RetroGameInfo = new Struct({
|
||||
path: 'string',
|
||||
data: ['char',0],
|
||||
size: 'size_t',
|
||||
meta: ['char',0]
|
||||
});
|
||||
const gameinfo = new RetroGameInfo({
|
||||
path: rompath,
|
||||
data: romdata,
|
||||
size: 40976,
|
||||
meta: []
|
||||
});
|
||||
const library = new Wrapper({
|
||||
manipulate: [RetroGameInfo],
|
||||
}, {memory: instance.exports.memory});
|
||||
library.manipulate(gameinfo);
|
||||
console.log(gameinfo, gameinfo.ref());
|
||||
exports.retro_load_game(gameinfo);
|
||||
*/
|
||||
// TODO
|
||||
const rombytes = new Int32Array(romdata.buffer, 0, romdata.length / 4);
|
||||
//exports.retro_load_rom(rompath, rombytes, rombytes.length, "");
|
||||
|
||||
let biosBinary = romdata.buffer;
|
||||
let biosptr = exports.malloc(biosBinary.byteLength);
|
||||
console.log(biosptr, romdata.length);
|
||||
//let biosarr = new Uint8Array(exports.memory.buffer, biosptr, biosBinary.byteLength);
|
||||
exports.retro_load_rom(rompath, biosptr, romdata.length, rompath);
|
||||
|
||||
//console.log('callbacks again')
|
||||
//exports.retro_init_callbacks();
|
||||
console.log('set inputs');
|
||||
exports.retro_set_controller_port_device(0,1);
|
||||
exports.retro_set_controller_port_device(1,1);
|
||||
// run
|
||||
exports.retro_reset();
|
||||
console.log('running');
|
||||
exports.retro_run();
|
||||
console.log('ran');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user