90 lines
1.5 KiB
C
Executable file
90 lines
1.5 KiB
C
Executable file
#include <dir.h>
|
|
#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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void f_keydown() {
|
|
TOP().i = keyIsDown(TOP().i);
|
|
}
|
|
|
|
void do_repl() {
|
|
char buf[128];
|
|
|
|
adlib_init();
|
|
|
|
timer_init(TIMER_18HZ);
|
|
f_init();
|
|
|
|
CDEF("quit", f_quit);
|
|
CDEF("adlib!", f_adlib_write);
|
|
CDEF("adlib@", f_adlib_read);
|
|
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);
|
|
CDEF("key-down", f_keydown);
|
|
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();
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
do_repl();
|
|
return 0;
|
|
} |