debug ISR, recording word

This commit is contained in:
Jeremy Penner 2019-04-05 19:35:43 -04:00
parent 59e6b969af
commit 8ce9ab33b5
6 changed files with 57 additions and 13 deletions

5
jopl.c
View file

@ -49,6 +49,10 @@ void f_keyWasPressed() {
consumeKey(k); consumeKey(k);
} }
void f_keydown() {
TOP().i = keyIsDown(TOP().i);
}
void do_repl() { void do_repl() {
char buf[128]; char buf[128];
@ -66,6 +70,7 @@ void do_repl() {
CDEF("key-end", kbd_cleanup); CDEF("key-end", kbd_cleanup);
CDEF("key-debounce", kbd_debounce); CDEF("key-debounce", kbd_debounce);
CDEF("key-pressed", f_keyWasPressed); CDEF("key-pressed", f_keyWasPressed);
CDEF("key-down", f_keydown);
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

@ -9,9 +9,11 @@ REPL start-repl
var voice var voice
var op var op
: +voice! voice @ + 10 % voice ! ;
: op-with-voice voice @ : op-with-voice voice @
dup 2 > if 5 + then
dup 5 > if 5 + then dup 5 > if 5 + then
dup 2 > if 5 + then
+ op @ + ; + op @ + ;
: opreg create b, does> ub@ op-with-voice ; : opreg create b, does> ub@ op-with-voice ;
: voicereg create b, does> ub@ voice @ + ; : voicereg create b, does> ub@ voice @ + ;
@ -90,11 +92,12 @@ var songticks
var notestate var notestate
var octave var octave
: oct+ octave @ 12 * + ;
: rest songticks @ begin dup songticks @ != until drop ; : rest songticks @ begin dup songticks @ != until drop ;
: beat begin dup songticks @ swap % 0 != while rest repeat drop ; : beat begin dup songticks @ swap % 0 != while rest repeat drop ;
: %O octave ! ; : %O octave ! ;
: %V voice ! ; : %V voice ! ;
: mknote create b, does> ub@ octave @ 12 * + notestate @ if b, else noteon rest then ; : mknote create b, does> ub@ oct+ notestate @ if b, else noteon rest then ;
: %loop 0xfe b, , ; : %loop 0xfe b, , ;
: % notestate @ if 0xf0 b, else rest then ; : % notestate @ if 0xf0 b, else rest then ;
: %% 0 for % next ; : %% 0 for % next ;
@ -132,7 +135,7 @@ array tracks 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
: shush 0 voice @ track ! %- ; : shush 0 voice @ track ! %- ;
: player : player
songticks @ 1 + songticks ! 1 songticks +!
voice @ voice @
0 10 for i voice ! i track-tick next 0 10 for i voice ! i track-tick next
voice ! ; voice ! ;
@ -155,17 +158,43 @@ var t2
|inline ] 0 29 for dup i + ub@ key-pressed if drop i 3 + rdrop rdrop ret then next |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 ; drop 51 key-pressed if 15 else 0 then ;
: keyboard : onkeynote ( cp -- ) keynote dup if oct+ swap execute else drop drop then ;
key-start begin
: dokeys ( cp -- )
r> key-start begin
key-debounce 1 key-pressed not while key-debounce 1 key-pressed not while
keynote dup if octave @ 12 * + noteon else drop then
78 key-pressed if 1 octave +! then 78 key-pressed if 1 octave +! then
74 key-pressed if -1 octave +! then 74 key-pressed if -1 octave +! then
41 key-pressed if noteoff then 75 key-pressed if -1 +voice! then
77 key-pressed if 1 +voice! then
r@ execute
rest rest
repeat key-end ; repeat key-end rdrop ;
: nextnote ( ip -- ip )
dup if
dup ub@ r>
r@ 0xff = if drop 0 else
r@ 0xfe = if 1 + @ nextnote then then
rdrop
then ;
: setnote ( note -- )
voice @ track @ nextnote
dup if b! else drop drop then ;
: record
:| ' setnote onkeynote
41 key-pressed if 0xfd setnote then
52 key-down if 0xf0 setnote then
|; dokeys ;
: jam
:| ' noteon onkeynote
41 key-pressed if noteoff then
|; dokeys ;
:noname :noname
default 9 -1 for i voice ! default next
startt2 startt2
; ' onload redefine ; ' onload redefine

BIN
jopl.prj

Binary file not shown.

13
kbd.c
View file

@ -18,12 +18,13 @@ static void interrupt kbd_isr() {
unsigned char raw; unsigned char raw;
char ctl; char ctl;
asm sti; disable();
*((int far*)MK_FP(0xb800, 0)) = 0x0165;
raw = inp(0x60); raw = inp(0x60);
ctl = inp(0x61) | 0x82; ctl = inp(0x61) | 0x82;
outp(0x61, ctl); outp(0x61, ctl);
outp(0x61, ctl & 0x7f); outp(0x61, ctl & 0x7f);
outp(0x20, 0x20);
if (raw & 0x80) { if (raw & 0x80) {
keybuf[raw & 0x7f] &= ~KEY_SIGNAL; keybuf[raw & 0x7f] &= ~KEY_SIGNAL;
@ -31,6 +32,9 @@ static void interrupt kbd_isr() {
keybuf[raw] |= KEY_SIGNAL; keybuf[raw] |= KEY_SIGNAL;
} }
kbd_triggered = raw; kbd_triggered = raw;
outp(0x20, 0x20);
enable();
*((int far*)MK_FP(0xb800, 0)) = 0x0166 + (raw % 4);
} }
unsigned char kbd_wait() { unsigned char kbd_wait() {
@ -50,7 +54,8 @@ void kbd_init() {
void kbd_debounce() { void kbd_debounce() {
int i = 0; int i = 0;
asm cli;
disable();
for (i = 0; i < 128; i ++) { for (i = 0; i < 128; i ++) {
unsigned char signal = keybuf[i] & KEY_SIGNAL; unsigned char signal = keybuf[i] & KEY_SIGNAL;
unsigned char keystate = keybuf[i] & 0x0f; unsigned char keystate = keybuf[i] & 0x0f;
@ -71,5 +76,5 @@ void kbd_debounce() {
keybuf[i] = signal | keystate; keybuf[i] = signal | keystate;
} }
asm sti; enable();
} }

View file

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