Add the ability to interactively play music with a "tracker keyboard"

This commit is contained in:
Jeremy Penner 2019-04-02 21:52:02 -04:00
parent 49f532a85b
commit 59e6b969af
5 changed files with 51 additions and 1 deletions

32
jopl.c
View file

@ -1,3 +1,4 @@
#include <dir.h>
#include "jorth.h" #include "jorth.h"
#include "adlib.h" #include "adlib.h"
#include "kbd.h" #include "kbd.h"
@ -24,6 +25,30 @@ static void f_quit() {
DONE = 1; 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 do_repl() { void do_repl() {
char buf[128]; char buf[128];
@ -35,7 +60,12 @@ void do_repl() {
CDEF("quit", f_quit); CDEF("quit", f_quit);
CDEF("adlib!", f_adlib_write); CDEF("adlib!", f_adlib_write);
CDEF("adlib@", f_adlib_read); 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);
f_loadfile("jopl.jor"); f_loadfile("jopl.jor");
ontick = f_lookupcp("ontick"); ontick = f_lookupcp("ontick");
timer_setcallback(timer_callback); timer_setcallback(timer_callback);

BIN
jopl.exe

Binary file not shown.

View file

@ -146,6 +146,25 @@ var t2
: ontick adlib@ 0x20 & if startt2 player then ; : ontick adlib@ 0x20 & if startt2 player then ;
: files findfile begin dup while yield findnext repeat ;
: keynote [ inline|
44 b, 31 b, 45 b, 32 b, 46 b, 47 b, 34 b, 48 b, 35 b, 49 b, 36 b, 50 b,
16 b, 3 b, 17 b, 4 b, 18 b, 19 b, 6 b, 20 b, 7 b, 21 b, 8 b, 22 b,
23 b, 10 b, 24 b, 11 b, 25 b,
|inline ] 0 29 for dup i + ub@ key-pressed if drop i 3 + rdrop rdrop ret then next
drop 51 key-pressed if 15 else 0 then ;
: keyboard
key-start begin
key-debounce 1 key-pressed not while
keynote dup if octave @ 12 * + noteon else drop then
78 key-pressed if 1 octave +! then
74 key-pressed if -1 octave +! then
41 key-pressed if noteoff then
rest
repeat key-end ;
:noname :noname
default default
startt2 startt2

BIN
jopl.prj

Binary file not shown.

1
kbd.h
View file

@ -6,6 +6,7 @@ extern volatile char kbd_triggered;
void kbd_init(); void kbd_init();
void kbd_debounce(); // call once per frame void kbd_debounce(); // call once per frame
void kbd_cleanup();
unsigned char kbd_wait(); unsigned char kbd_wait();
#define KEY_OFF 0 #define KEY_OFF 0