2019-04-03 01:52:02 +00:00
|
|
|
#include <dir.h>
|
2019-08-25 02:37:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2019-03-31 23:29:16 +00:00
|
|
|
#include "jorth.h"
|
|
|
|
#include "adlib.h"
|
|
|
|
#include "kbd.h"
|
|
|
|
#include "timer.h"
|
2019-05-09 00:37:40 +00:00
|
|
|
#include "serial.h"
|
2019-03-31 23:29:16 +00:00
|
|
|
|
|
|
|
cell ontick = 0;
|
|
|
|
void f_adlib_read() {
|
|
|
|
PUSHU(adlib_read());
|
|
|
|
}
|
|
|
|
|
|
|
|
void f_adlib_write() {
|
|
|
|
adlib_write(TOP().u & 0xff, ST1().u & 0xff);
|
|
|
|
DROP(2);
|
|
|
|
}
|
|
|
|
|
2019-04-14 19:08:13 +00:00
|
|
|
volatile int WAKE = 0;
|
2019-03-31 23:29:16 +00:00
|
|
|
static void timer_callback() {
|
2019-04-14 19:08:13 +00:00
|
|
|
if (adlib_read() & 0x20) {
|
|
|
|
WAKE = 1;
|
2019-03-31 23:29:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DONE = 0;
|
|
|
|
static void f_quit() {
|
|
|
|
DONE = 1;
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:52:02 +00:00
|
|
|
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-14 19:08:13 +00:00
|
|
|
char *gather_input() {
|
|
|
|
static char buf[128];
|
|
|
|
static int ibuf = 0;
|
|
|
|
|
|
|
|
if (bioskey(1)) {
|
|
|
|
int key = bioskey(0);
|
|
|
|
char ch = key & 0xff;
|
|
|
|
if (ch == 0x08) {
|
|
|
|
if (ibuf > 0) {
|
|
|
|
printf("%c %c", ch, ch);
|
|
|
|
ibuf --;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buf[ibuf] = ch;
|
|
|
|
ibuf ++;
|
|
|
|
if (ch == 0x0d) {
|
|
|
|
printf("\n");
|
|
|
|
buf[ibuf] = 0;
|
|
|
|
ibuf = 0;
|
|
|
|
return buf;
|
|
|
|
} else {
|
|
|
|
printf("%c", ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-03-31 23:29:16 +00:00
|
|
|
|
2019-05-09 00:37:40 +00:00
|
|
|
void f_seremit() {
|
|
|
|
ser_write_byte(TOP().i);
|
|
|
|
if (TOP().i == '\n') {
|
|
|
|
ser_write_byte('\r');
|
|
|
|
}
|
|
|
|
DROP(1);
|
|
|
|
}
|
|
|
|
|
2019-08-25 02:37:00 +00:00
|
|
|
void f_random() {
|
|
|
|
TOP().i = random(TOP().i);
|
|
|
|
}
|
|
|
|
|
2019-04-14 19:08:13 +00:00
|
|
|
void do_repl(char *exe) {
|
2019-03-31 23:29:16 +00:00
|
|
|
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
|
|
|
|
2019-05-09 00:37:40 +00:00
|
|
|
ser_init(SER_COM2, BAUD_19200, SER_8N1);
|
|
|
|
CDEF("seremit", f_seremit);
|
2019-04-13 14:30:36 +00:00
|
|
|
CDEF("_quit", f_quit);
|
2019-03-31 23:29:16 +00:00
|
|
|
CDEF("adlib!", f_adlib_write);
|
|
|
|
CDEF("adlib@", f_adlib_read);
|
2019-04-03 01:52:02 +00:00
|
|
|
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-08-25 02:37:00 +00:00
|
|
|
CDEF("rnd", f_random);
|
2019-03-31 23:29:16 +00:00
|
|
|
f_loadfile("jopl.jor");
|
|
|
|
ontick = f_lookupcp("ontick");
|
|
|
|
timer_setcallback(timer_callback);
|
|
|
|
|
|
|
|
f_taskloop();
|
|
|
|
|
|
|
|
while (!DONE) {
|
2019-04-14 19:08:13 +00:00
|
|
|
char *buf = gather_input();
|
|
|
|
if (buf) {
|
|
|
|
PUSHS(buf);
|
|
|
|
f_runstring("REPL send");
|
|
|
|
}
|
|
|
|
if (WAKE) {
|
|
|
|
WAKE = 0;
|
|
|
|
if (ontick.p != NULL) {
|
|
|
|
f_execcp(ontick);
|
|
|
|
}
|
|
|
|
}
|
2019-03-31 23:29:16 +00:00
|
|
|
f_taskloop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 19:08:13 +00:00
|
|
|
#define RIGHT 0x01
|
|
|
|
#define LEFT 0x02
|
|
|
|
#define CTRL 0x04
|
|
|
|
#define ALT 0x08
|
|
|
|
|
|
|
|
void keything() {
|
|
|
|
int key, modifiers, done;
|
|
|
|
done = 0;
|
|
|
|
while (!done) {
|
|
|
|
/* function 1 returns 0 until a key is pressed */
|
|
|
|
while (bioskey(1) == 0);
|
|
|
|
|
|
|
|
/* function 0 returns the key that is waiting */
|
|
|
|
key = bioskey(0);
|
|
|
|
|
|
|
|
/* use function 2 to determine if shift keys were used */
|
|
|
|
modifiers = bioskey(2);
|
|
|
|
if (modifiers)
|
|
|
|
{
|
|
|
|
printf("[%#02x", modifiers);
|
|
|
|
if (modifiers & RIGHT) printf(" RIGHT");
|
|
|
|
if (modifiers & LEFT) printf(" LEFT");
|
|
|
|
if (modifiers & CTRL) printf(" CTRL");
|
|
|
|
if (modifiers & ALT) printf(" ALT");
|
|
|
|
printf("]");
|
|
|
|
}
|
|
|
|
/* print out the character read */
|
|
|
|
printf("'%c' %#02x\n", key & 0xff, key);
|
|
|
|
if ((key & 0xff) == 'q') done = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 02:00:32 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2019-04-14 19:08:13 +00:00
|
|
|
// keything();
|
2019-08-25 02:37:00 +00:00
|
|
|
randomize();
|
2019-04-10 02:00:32 +00:00
|
|
|
do_repl(argv[0]);
|
2019-03-31 23:29:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|