JOPL status bar, remove jorth from ISR (for now??)

This commit is contained in:
Jeremy Penner 2019-04-14 15:08:13 -04:00
parent 4fcf03fd07
commit 6c4e5ff396
6 changed files with 129 additions and 15 deletions

79
jopl.c
View file

@ -14,9 +14,10 @@ void f_adlib_write() {
DROP(2);
}
volatile int WAKE = 0;
static void timer_callback() {
if (ontick.p) {
f_execcp(ontick);
if (adlib_read() & 0x20) {
WAKE = 1;
}
}
@ -53,9 +54,35 @@ void f_keydown() {
TOP().i = keyIsDown(TOP().i);
}
void do_repl(char *exe) {
char buf[128];
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;
}
void do_repl(char *exe) {
adlib_init();
timer_init(TIMER_18HZ);
@ -78,13 +105,55 @@ void do_repl(char *exe) {
f_taskloop();
while (!DONE) {
PUSHS(gets(buf));
char *buf = gather_input();
if (buf) {
PUSHS(buf);
f_runstring("REPL send");
}
if (WAKE) {
WAKE = 0;
if (ontick.p != NULL) {
f_execcp(ontick);
}
}
f_taskloop();
}
}
#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;
}
}
int main(int argc, char *argv[]) {
// keything();
do_repl(argv[0]);
return 0;
}

BIN
jopl.exe

Binary file not shown.

View file

@ -97,7 +97,7 @@ var songticks
var notestate
var octave
: oct+ octave @ 12 * + ;
: rest songticks @ begin dup songticks @ != until drop ;
: rest songticks @ begin suspend dup songticks @ != until drop ;
: beat begin dup songticks @ swap % 0 != while rest repeat drop ;
: %O octave ! ;
: %V voice ! ;
@ -161,6 +161,53 @@ array tracks 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
'name :track type bl swap type bl
begin dup ub@ emit-cmd while 1 + repeat drop ;
var textx
var texty
var textattr
0x1f textattr !
: out-direct ( c -- )
textattr @ 8 << |
texty @ 160 * textx @ 1 << +
0xb800 !far ;
: clearline
textattr @ 8 <<
texty @ 80 * textx @ +
texty @ 1 + 80 *
for dup i 1 << 0xb800 !far next drop ;
: +textx! ( n -- )
textx @ + dup 80 >= if drop cr else textx ! then ;
: emit-direct ( c -- )
dup '\n' = if 0 textx ! 1 texty +! drop else
dup '\r' = if drop else
out-direct 1 +textx! then then ;
: status
0 textx ! 0 texty !
s" V: " type voice @ .
s" O: " type octave @ .
s" T: " type songticks @ .
clearline ;
: emit-status-cmd ( ip -- ip )
dup ub@ swap 1 + swap
dup 0xf0 = if s" % " type then
dup 0xfd = if s" - " type then
dup 0xf0 < if dup emit-note then
dup 0xfe = if
16 textattr +!
swap @ emit-status-cmd swap
-16 textattr +!
then drop ;
: showtrack ( n -- )
dup . s" : " type
track @ dup if 20 0 for emit-status-cmd next then drop
clearline ;
: trackstatus cr voice @ showtrack ;
var tempo 1 tempo !
: player
@ -178,7 +225,7 @@ var t2
t2 @ 0x03 adlib!
0x42 0x04 adlib! ;
: ontick adlib@ 0x20 & if startt2 player then ;
: ontick startt2 player status trackstatus ;
: files findfile begin dup while yield findnext repeat ;
@ -199,7 +246,7 @@ var t2
75 key-pressed if -1 +voice! then
77 key-pressed if 1 +voice! then
r@ execute
rest
suspend
repeat key-end rdrop ;
: nextnote ( ip -- ip )
@ -215,10 +262,12 @@ var t2
dup if b! else drop drop then ;
: record
0x4f textattr !
:| ' setnote onkeynote
41 key-pressed if 0xfd setnote then
52 key-down if 0xf0 setnote then
|; dokeys ;
|; dokeys
0x1f textattr ! ;
: jam
:| ' noteon onkeynote
@ -228,4 +277,5 @@ var t2
:noname
9 -1 for i voice ! default next
startt2
' emit-direct task-emit !
; ' onload redefine

BIN
jopl.prj

Binary file not shown.

2
kbd.c
View file

@ -19,7 +19,6 @@ static void interrupt kbd_isr() {
char ctl;
disable();
*((int far*)MK_FP(0xb800, 0)) = 0x0165;
raw = inp(0x60);
ctl = inp(0x61) | 0x82;
@ -34,7 +33,6 @@ static void interrupt kbd_isr() {
kbd_triggered = raw;
outp(0x20, 0x20);
enable();
*((int far*)MK_FP(0xb800, 0)) = 0x0166 + (raw % 4);
}
unsigned char kbd_wait() {

View file

@ -13,13 +13,10 @@ static void (*callback)() = NULL;
static void interrupt timer_isr() {
disable();
*((int far*)MK_FP(0xb800, 2)) = 0x0165;
timer_counter ++;
if (callback) callback();
enable();
*((int far*)MK_FP(0xb800, 2)) = 0x0166;
oldTimerISR();
*((int far*)MK_FP(0xb800, 2)) = 0x0167;
}
void timer_setcallback(void (*cb)()) {