Skip to content

Commit

Permalink
pce.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdf committed Oct 29, 2013
1 parent c09841a commit 3551802
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 11 deletions.
63 changes: 63 additions & 0 deletions src/arch/ibmpc/cmd.c
Expand Up @@ -22,6 +22,7 @@

#include "main.h"
#include "ibmpc.h"
#include "cmd.h"

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -524,6 +525,68 @@ void pc_run (ibmpc_t *pc)
pce_stop();
}


/*
* emscripten specific main loop
*/

/*
* store global pointer to simulation state struct
* so that pc_run_emscripten_step doesn't require it as a parameter
*/
ibmpc_t *ibmpc_sim = NULL;

/*
* setup and run the simulation
*/
void pc_run_emscripten (ibmpc_t *pc)
{
ibmpc_sim = pc;

pce_start (&pc->brk);

pc_clock_discontinuity (pc);

#ifdef EMSCRIPTEN
emscripten_set_main_loop(pc_run_emscripten_step, 100, 1);
#else
while (!pc->brk) {
pc_run_emscripten_step();
}
#endif

pc->current_int &= 0xff;
// pce_stop();
}

/*
* run one iteration
*/
void pc_run_emscripten_step ()
{

// for each 'emscripten step' we'll run a bunch of actual cycles
// to minimise overhead from emscripten's main loop management
int i;
for (i = 0; i < 10000; ++i)
{
pc_clock (ibmpc_sim, 4 * ibmpc_sim->speed_current);

if (ibmpc_sim->brk) {
pce_stop();
#ifdef EMSCRIPTEN
emscripten_cancel_main_loop();
#endif
return;
}
}
}
/*
* end emscripten specific main loop
*/



#if 0
static
void pce_op_stat (void *ext, unsigned char op1, unsigned char op2)
Expand Down
2 changes: 2 additions & 0 deletions src/arch/ibmpc/cmd.h
Expand Up @@ -40,5 +40,7 @@ int pc_cmd (ibmpc_t *pc, cmd_t *cmd);

void pc_cmd_init (ibmpc_t *pc, monitor_t *mon);

void pc_run_emscripten (ibmpc_t *pc);
void pc_run_emscripten_step ();

#endif
18 changes: 17 additions & 1 deletion src/arch/ibmpc/main.c
Expand Up @@ -41,7 +41,6 @@
#include <lib/path.h>
#include <lib/sysdep.h>


const char *par_terminal = NULL;
const char *par_video = NULL;

Expand Down Expand Up @@ -336,6 +335,18 @@ int main (int argc, char *argv[])
}
}

int emscripten;
emscripten = 0;
#ifdef EMSCRIPTEN
// replace command line arg settings
pce_log_set_level (stderr, MSG_DEB);
par_video = "vga";
cfg = "roms/pce-config.cfg";
// run = 1;
// nomon = 1;
emscripten = 1;
#endif

pc_log_banner();

if (pce_load_config (par_cfg, cfg)) {
Expand Down Expand Up @@ -380,6 +391,11 @@ int main (int argc, char *argv[])

pc_reset (par_pc);


if (emscripten || 1) {
pc_run_emscripten(par_pc);
exit(1);
}
if (nomon) {
while (par_pc->brk != PCE_BRK_ABORT) {
pc_run (par_pc);
Expand Down
2 changes: 1 addition & 1 deletion src/arch/ibmpc/msg.c
Expand Up @@ -570,7 +570,7 @@ int pc_set_msg (ibmpc_t *pc, const char *msg, const char *val)
}
}

pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val);
// pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val);

return (1);
}
1 change: 1 addition & 0 deletions src/arch/macplus/Makefile.inc
Expand Up @@ -134,6 +134,7 @@ $(rel)/video.o: $(rel)/video.c

$(rel)/pce-macplus$(EXEEXT): $(PCE_MACPLUS_OBJ_EXT) $(PCE_MACPLUS_OBJ)
$(QP)echo " LD $@"
$(QP)echo "$(LD) $(PCE_MACPLUS_LDFLAGS) -o $@ $(PCE_MACPLUS_OBJ) $(PCE_MACPLUS_OBJ_EXT) $(PCE_MACPLUS_LIBS) -lm"
$(QR)$(LD) $(PCE_MACPLUS_LDFLAGS) -o $@ $(PCE_MACPLUS_OBJ) $(PCE_MACPLUS_OBJ_EXT) $(PCE_MACPLUS_LIBS) -lm

$(rel)/pce-mac-plus.cfg: $(rel)/pce-macplus.cfg.in
Expand Down
89 changes: 89 additions & 0 deletions src/arch/macplus/cmd_68k.c
Expand Up @@ -36,6 +36,9 @@
#include <lib/monitor.h>
#include <lib/sysdep.h>

#include <SDL.h>

// #include <emscripten.h>

mon_cmd_t par_cmd[] = {
{ "c", "[cnt]", "clock" },
Expand Down Expand Up @@ -387,6 +390,92 @@ void mac_run (macplus_t *sim)
pce_stop();
}

/*
* emscripten specific main loop
*/

/*
* store global reference to simulation state struct
* so that mac_run_emscripten_step doesn't require it as a parameter
*/
macplus_t *macplus_sim = NULL;

/*
* setup and run the simulation
*/
void mac_run_emscripten (macplus_t *sim)
{
macplus_sim = sim;
int brk = 0;

pce_start (&sim->brk);

mac_clock_discontinuity (sim);

#ifdef EMSCRIPTEN
emscripten_set_main_loop(mac_run_emscripten_step, 100, 1);
#else
while (!sim->brk) {
mac_run_emscripten_step();
}
#endif

// pce_stop();
}


/*
* run one iteration
*/
void mac_run_emscripten_step ()
{
int mousex;
int mousey;

// for each 'emscripten step' we'll run a bunch of actual cycles
// to minimise overhead from emscripten's main loop management
int i;
for (i = 0; i < 10000; ++i) {
// gross hacks to set mouse position in browser
if (i % 100 == 0) {
// pce_log_deb ("sdl: mouse x=%i y=%i \n", mousex, mousey);

// pce_log (MSG_DEB,
// "mouse data: %04X %04X\n",
// (unsigned) e68_get_mem16 (macplus_sim->cpu, 0x082c),
// (unsigned) e68_get_mem16 (macplus_sim->cpu, 0x082e)
// );
SDL_GetMouseState (&mousex, &mousey);
e68_set_mem16 (macplus_sim->cpu, 0x0828, (unsigned) mousey);
e68_set_mem16 (macplus_sim->cpu, 0x082c, (unsigned) mousey);
e68_set_mem16 (macplus_sim->cpu, 0x0830, (unsigned) mousey);
e68_set_mem16 (macplus_sim->cpu, 0x082a, (unsigned) mousex);
e68_set_mem16 (macplus_sim->cpu, 0x082e, (unsigned) mousex);
e68_set_mem16 (macplus_sim->cpu, 0x0832, (unsigned) mousex);
}
// presumably this is a very minor unrolling optimisation?
mac_clock (par_sim, 0);
mac_clock (par_sim, 0);

if (macplus_sim->brk) {
pce_stop();
#ifdef EMSCRIPTEN
emscripten_cancel_main_loop();
#endif
return;
}

while (macplus_sim->pause) {
pce_usleep (50UL * 1000UL);
trm_check (macplus_sim->trm);
}
}
// print state
// mac_prt_state_cpu(macplus_sim);
}
/*
* end emscripten specific main loop
*/

#if 0
static
Expand Down
3 changes: 3 additions & 0 deletions src/arch/macplus/cmd_68k.h
Expand Up @@ -38,5 +38,8 @@ int mac_cmd (macplus_t *sim, cmd_t *cmd);

void mac_cmd_init (macplus_t *sim, monitor_t *mon);

// emscripten specific run loop
void mac_run_emscripten (macplus_t *sim);
void mac_run_emscripten_step ();

#endif
17 changes: 17 additions & 0 deletions src/arch/macplus/main.c
Expand Up @@ -343,6 +343,18 @@ int main (int argc, char *argv[])
}
}

int emscripten;
emscripten = 0;
#ifdef EMSCRIPTEN
// replace command line arg settings
pce_log_set_level (stderr, MSG_DEB);
cfg = "roms/pce-config.cfg";
// run = 1;
// nomon = 1;
emscripten = 1;
#endif


mac_log_banner();

if (pce_load_config (par_cfg, cfg)) {
Expand Down Expand Up @@ -375,6 +387,7 @@ int main (int argc, char *argv[])

par_sim = mac_new (sct);


mon_init (&par_mon);
mon_set_cmd_fct (&par_mon, mac_cmd, par_sim);
mon_set_msg_fct (&par_mon, mac_set_msg, par_sim);
Expand All @@ -387,6 +400,10 @@ int main (int argc, char *argv[])

mac_reset (par_sim);

if (emscripten) {
mac_run_emscripten(par_sim);
exit(1);
}
if (nomon) {
while (par_sim->brk != PCE_BRK_ABORT) {
mac_run (par_sim);
Expand Down
2 changes: 0 additions & 2 deletions src/arch/macplus/main.h
Expand Up @@ -45,7 +45,6 @@
struct macplus_s;
typedef struct macplus_s macplus_t;


extern int par_verbose;

extern const char *par_terminal;
Expand All @@ -57,7 +56,6 @@ extern macplus_t *par_sim;

extern unsigned par_sig_int;


void mac_log_deb (const char *msg, ...);


Expand Down
2 changes: 1 addition & 1 deletion src/arch/macplus/msg.c
Expand Up @@ -508,7 +508,7 @@ int mac_set_msg (macplus_t *sim, const char *msg, const char *val)
}
}

pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val);
// pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val);

return (1);
}
2 changes: 1 addition & 1 deletion src/drivers/video/sdl.c
Expand Up @@ -31,7 +31,6 @@
#include <drivers/video/keys.h>
#include <drivers/video/sdl.h>


static int sdl_set_window_size (sdl_t *sdl, unsigned w, unsigned h, int force);


Expand Down Expand Up @@ -402,6 +401,7 @@ void sdl_update (sdl_t *sdl)
return;
}


if (SDL_BlitSurface (s, NULL, sdl->scr, &dst) != 0) {
fprintf (stderr, "sdl: blit error\n");
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/video/x11.c
Expand Up @@ -25,7 +25,7 @@

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
// #include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/video/x11.h
Expand Up @@ -28,7 +28,7 @@

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
// #include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>

Expand Down
6 changes: 3 additions & 3 deletions src/lib/sysdep.c
Expand Up @@ -147,12 +147,12 @@ void pce_set_fd_interactive (int fd, int interactive)
struct termios tios;

if (sios_ok == 0) {
tcgetattr (fd, &sios);
// tcgetattr (fd, &sios);
sios_ok = 1;
}

if (interactive) {
tcsetattr (fd, TCSANOW, &sios);
// tcsetattr (fd, TCSANOW, &sios);
}
else {
tios = sios;
Expand All @@ -162,7 +162,7 @@ void pce_set_fd_interactive (int fd, int interactive)
tios.c_cc[VMIN] = 1;
tios.c_cc[VTIME] = 0;

tcsetattr (fd, TCSANOW, &tios);
// tcsetattr (fd, TCSANOW, &tios);
}
#endif
}
Expand Down

0 comments on commit 3551802

Please sign in to comment.