Add the ability to interactively play music with a "tracker keyboard"
This commit is contained in:
parent
49f532a85b
commit
59e6b969af
32
jopl.c
32
jopl.c
|
@ -1,3 +1,4 @@
|
|||
#include <dir.h>
|
||||
#include "jorth.h"
|
||||
#include "adlib.h"
|
||||
#include "kbd.h"
|
||||
|
@ -24,6 +25,30 @@ 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 do_repl() {
|
||||
char buf[128];
|
||||
|
||||
|
@ -35,7 +60,12 @@ void do_repl() {
|
|||
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);
|
||||
f_loadfile("jopl.jor");
|
||||
ontick = f_lookupcp("ontick");
|
||||
timer_setcallback(timer_callback);
|
||||
|
|
19
jopl.jor
19
jopl.jor
|
@ -146,6 +146,25 @@ var t2
|
|||
|
||||
: 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
|
||||
default
|
||||
startt2
|
||||
|
|
Loading…
Reference in a new issue