store exe timestamp in JIM files; small game cleanups

This commit is contained in:
Jeremy Penner 2019-04-09 22:00:32 -04:00
parent 640471a59e
commit d23e8c1172
14 changed files with 79 additions and 25 deletions

View file

@ -60,11 +60,14 @@ defer onload
: postload ' onload definition ' noop ' onload redefine execute ;
: loadimage ( -- [0 | onload] )
fget fget fget fget fget ( onload tasks latest size start )
here != if tell + seek drop drop drop 0 else
dup here fread here + here! latest! tasks! then ;
imagemagic fget = if
fget fget fget fget fget ( onload tasks latest size start )
here != if tell + seek drop drop drop 0 else
dup here fread here + here! latest! tasks! then
else 0 then ;
: saveimage ( herestart -- )
imagemagic fput
' onload definition here drop fput
tasks fput
latest fput

BIN
game.exe

Binary file not shown.

BIN
game.prj

Binary file not shown.

8
jopl.c
View file

@ -53,13 +53,13 @@ void f_keydown() {
TOP().i = keyIsDown(TOP().i);
}
void do_repl() {
void do_repl(char *exe) {
char buf[128];
adlib_init();
timer_init(TIMER_18HZ);
f_init();
f_init(exe);
CDEF("quit", f_quit);
CDEF("adlib!", f_adlib_write);
@ -84,7 +84,7 @@ void do_repl() {
}
}
int main() {
do_repl();
int main(int argc, char *argv[]) {
do_repl(argv[0]);
return 0;
}

BIN
jopl.exe

Binary file not shown.

View file

@ -99,6 +99,7 @@ var octave
: %V voice ! ;
: mknote create b, does> ub@ oct+ notestate @ if b, else noteon rest then ;
: %loop 0xfe b, , ;
: mod % ;
: % notestate @ if 0xf0 b, else rest then ;
: %% 0 for % next ;
: %- notestate @ if 0xfd b, else noteoff then ;
@ -134,11 +135,14 @@ array tracks 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
: ;track %loop 0 notestate ! ;
: shush 0 voice @ track ! %- ;
var tempo 1 tempo !
: player
1 songticks +!
voice @
0 10 for i voice ! i track-tick next
voice ! ;
songticks @ tempo @ mod 0 = if
voice @
0 10 for i voice ! i track-tick next
voice !
then ;
var t2
: startt2

BIN
jopl.prj

Binary file not shown.

46
jorth.c
View file

@ -2,6 +2,7 @@
#include <stdio.h>
#include <sys/stat.h>
#include <dos.h>
#include "jorth.h"
#include "serial.h"
@ -164,6 +165,26 @@ void f_bset() {
DROP(1);
}
void f_farset() {
*((cell far *)MK_FP(TOP().u, ST1().u)) = ST2();
DROP(3);
}
void f_farget() {
ST1() = *((cell far *)MK_FP(TOP().u, ST1().u));
DROP(1);
}
void f_farbset() {
*((char far *)MK_FP(TOP().u, ST1().u)) = ST2().i;
DROP(3);
}
void f_farbget() {
ST1().i = *((char far *)MK_FP(TOP().u, ST1().u));
DROP(1);
}
void f_addset() {
TOP().p->i += ST1().i;
DROP(2);
@ -841,10 +862,25 @@ void f_image_up_to_date() {
TOP().i = uptodate;
}
static int imagemagic = -1;
static void f_calc_imagemagic(char *exefilename) {
struct stat exe;
if (stat(exefilename, &exe) == 0) {
imagemagic = exe.st_mtime;
}
}
void f_loadimage() {
cell *start, *latestNew, *tasksNew;
size_t size;
int magic;
fread(&magic, sizeof(int), 1, ACTIVE_FILE);
if (magic != imagemagic) {
PUSHI(0);
return;
}
fread(&start, sizeof(cell *), 1, ACTIVE_FILE);
fread(&latestNew, sizeof(cell *), 1, ACTIVE_FILE);
fread(&tasksNew, sizeof(cell *), 1, ACTIVE_FILE);
@ -863,6 +899,7 @@ void f_loadimage() {
void f_saveimage() {
size_t size = (size_t)(((char*)HERE) - TOP().s);
fwrite(&imagemagic, sizeof(int), 1, ACTIVE_FILE);
fwrite(&TOP().p, sizeof(cell *), 1, ACTIVE_FILE);
fwrite(&LATEST, sizeof(cell *), 1, ACTIVE_FILE);
fwrite(&TASKS, sizeof(cell *), 1, ACTIVE_FILE);
@ -991,7 +1028,9 @@ void f_taskusersize() {
PUSHU(TASK_USER_SIZE);
}
void f_init() {
void f_init(char *exe) {
f_calc_imagemagic(exe);
CDEF("[", f_compileoff); f_immediate();
CDEF("]", f_compileon);
CDEF("key", f_key);
@ -1053,6 +1092,10 @@ void f_init() {
CDEF("b@", f_bget);
CDEF("ub@", f_ubget);
CDEF("b!", f_bset);
CDEF("!far", f_farset);
CDEF("@far", f_farget);
CDEF("b!far", f_farbset);
CDEF("b@far", f_farbget);
CDEF("dup", f_dup);
CDEF("over", f_over);
CDEF("drop", f_drop);
@ -1112,6 +1155,7 @@ void f_init() {
PCONST("$DOCREATE", f_docreate);
PCONST("$DOVAR", f_dovar);
PCONST("$DODEFERRED", f_dodeferred);
ICONST("imagemagic", imagemagic);
#ifdef TRACE
CDEF("traceon", f_traceon);
CDEF("traceoff", f_traceoff);

View file

@ -4,7 +4,7 @@
#define STACK_SIZE 64
#define RSTACK_SIZE 32
void f_init();
void f_init(char *exe);
void f_cdef();
void f_immediate();

View file

@ -4,7 +4,9 @@
:noname
1 player.state DRIVING f!
:| player yield chuck yield 0 |; ' entities redefine
:| player yield
chuck.state @ CHUCK-HOME = if chuck yield then
0 |; ' entities redefine
:|
touch-begin E leaving? dup
if pete say" It's 100 miles to the next town." then

Binary file not shown.

View file

@ -1,4 +1,5 @@
0 const CHUCK-LOST
1 const CHUCK-FOLLOW
2 const CHUCK-HOME
0 const CHUCK-GONE
1 const CHUCK-SEARCH
2 const CHUCK-FOLLOW
3 const CHUCK-HOME
var chuck.state

View file

@ -199,8 +199,8 @@ void f_adlib() {
DROP(2);
}
void game_f_init() {
f_init();
void game_f_init(char *exe) {
f_init(exe);
CDEF("seremit", f_seremit);
CDEF("key-pressed", f_keyWasPressed);
CDEF("key-down", f_keyIsDown);
@ -253,10 +253,10 @@ int DONE = 0;
static void f_quit() {
DONE = 1;
}
void do_repl() {
void do_repl(char *exe) {
char buf[128];
f_init();
f_init(exe);
CDEF("quit", f_quit);
CDEF("adlib", f_adlib);
@ -270,15 +270,15 @@ void do_repl() {
}
}
int main(int argc) {
int main(int argc, char *argv[]) {
cell tick, draw;
if (argc > 1) {
do_repl();
do_repl(argv[0]);
return 0;
}
ser_init(SER_COM2, BAUD_19200, SER_8N1);
game_init();
game_f_init();
game_f_init(argv[0]);
tick = f_lookupcp("tick");
draw = f_lookupcp("draw");

View file

@ -11,7 +11,7 @@ car :touch
0 player.state DRIVING f!
:| player yield
chuck.state @ CHUCK-LOST = if e_chuck yield then
chuck.state @ CHUCK-SEARCH = if e_chuck yield then
player.driving? not if car yield then
0 |; ' entities redefine
@ -22,7 +22,7 @@ touch-begin S leaving? dup
else player move-entity 13 7 road.jor queue-level
then
then
chuck.state @ CHUCK-LOST = if
chuck.state @ CHUCK-SEARCH = if
touch-next 37 60 2= dup
if
pete say" Oh for the love of..."