2019-04-03 01:52:02 +00:00
|
|
|
#include <dir.h>
|
2019-03-31 23:29:16 +00:00
|
|
|
#include "jorth.h"
|
|
|
|
#include "adlib.h"
|
|
|
|
#include "kbd.h"
|
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
cell ontick = 0;
|
|
|
|
void f_adlib_read() {
|
|
|
|
PUSHU(adlib_read());
|
|
|
|
}
|
|
|
|
|
|
|
|
void f_adlib_write() {
|
|
|
|
adlib_write(TOP().u & 0xff, ST1().u & 0xff);
|
|
|
|
DROP(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void timer_callback() {
|
|
|
|
if (ontick.p) {
|
|
|
|
f_execcp(ontick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DONE = 0;
|
|
|
|
static void f_quit() {
|
|
|
|
DONE = 1;
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:52:02 +00:00
|
|
|
struct ffblk findfile;
|
|
|
|
void f_findfirst() {
|
|
|
|
int result = findfirst(TOP().s, &findfile, 0);
|
|
|
|
if (result == 0) {
|
|
|
|
PUSHS(findfile.ff_name);
|
|
|
|
} else {
|
|
|
|
PUSHU(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void f_findnext() {
|
|
|
|
int result = findnext(&findfile);
|
|
|
|
if (result == 0) {
|
|
|
|
PUSHS(findfile.ff_name);
|
|
|
|
} else {
|
|
|
|
PUSHU(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void f_keyWasPressed() {
|
|
|
|
int k = TOP().i;
|
|
|
|
TOP().i = keyWasPressed(k);
|
|
|
|
consumeKey(k);
|
|
|
|
}
|
|
|
|
|
2019-04-05 23:35:43 +00:00
|
|
|
void f_keydown() {
|
|
|
|
TOP().i = keyIsDown(TOP().i);
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:00:32 +00:00
|
|
|
void do_repl(char *exe) {
|
2019-03-31 23:29:16 +00:00
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
adlib_init();
|
|
|
|
|
|
|
|
timer_init(TIMER_18HZ);
|
2019-04-10 02:00:32 +00:00
|
|
|
f_init(exe);
|
2019-03-31 23:29:16 +00:00
|
|
|
|
|
|
|
CDEF("quit", f_quit);
|
|
|
|
CDEF("adlib!", f_adlib_write);
|
|
|
|
CDEF("adlib@", f_adlib_read);
|
2019-04-03 01:52:02 +00:00
|
|
|
CDEF("findfile", f_findfirst);
|
|
|
|
CDEF("findnext", f_findnext);
|
|
|
|
CDEF("key-start", kbd_init);
|
|
|
|
CDEF("key-end", kbd_cleanup);
|
|
|
|
CDEF("key-debounce", kbd_debounce);
|
|
|
|
CDEF("key-pressed", f_keyWasPressed);
|
2019-04-05 23:35:43 +00:00
|
|
|
CDEF("key-down", f_keydown);
|
2019-03-31 23:29:16 +00:00
|
|
|
f_loadfile("jopl.jor");
|
|
|
|
ontick = f_lookupcp("ontick");
|
|
|
|
timer_setcallback(timer_callback);
|
|
|
|
|
|
|
|
f_taskloop();
|
|
|
|
|
|
|
|
while (!DONE) {
|
|
|
|
PUSHS(gets(buf));
|
|
|
|
f_runstring("REPL send");
|
|
|
|
f_taskloop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 02:00:32 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
do_repl(argv[0]);
|
2019-03-31 23:29:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|