Fixed issue with midi

This commit is contained in:
neauoire 2021-05-08 07:59:03 -07:00
parent 5294b92ebd
commit 12550c3703
5 changed files with 135 additions and 3 deletions

View File

@ -34,7 +34,7 @@ else
fi
echo "Assembling.."
./bin/assembler projects/demos/life.usm bin/boot.rom
./bin/assembler projects/demos/drum-rack.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];

View File

@ -0,0 +1,123 @@
( a blank file )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
( fixed-point )
%RESF { #0008 }
%TO2F { RESF #0040 SFT2 SFT2 }
%MUL2F { MUL2 RESF SFT2 }
%DIV2F { SWP2 TO2F SWP2 DIV2 }
%RTN { JMP2r }
%TOB { SWP POP }
%MOD2 { OVR2 OVR2 DIV2 MUL2 SUB2 }
%MOD { DUP2 / * - }
%SFL2 { #0040 SFT2 SFT2 }
%DEBUG { .Console/byte DEO #0a .Console/char DEO }
%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO }
%WIDTH { #0080 }
%HEIGHT { #0080 }
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 ]
|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|70 @Midi [ &vector $2 &channel $1 &note $1 &velocity $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
( variables )
|0000
@zoom $1
@iter $1
@fractal [ &c_re $2 &c_im $2 &x $2 &y $2 ]
( program )
|0100 ( -> )
( theme )
#f840 .System/r DEO2
#f840 .System/g DEO2
#f840 .System/b DEO2
#20 .iter POK
#04 .zoom POK
#0000 #0080
&ver
( col ) OVR2 .Screen/y DEO2
#0000 #0080
&hor
( row ) OVR2 .Screen/x DEO2
,mandelbrot JSR
( incr ) SWP2 #0001 ++ SWP2
OVR2 OVR2 LTH2 ,&hor JNZ
POP2 POP2
( incr ) SWP2 #0001 ++ SWP2
OVR2 OVR2 LTH2 ,&ver JNZ
POP2 POP2
BRK
@mandelbrot ( -- )
(
.Screen/x DEI2
.Screen/y DEI2 )
(
double c_re = [col - width/2.0]*4.0/width;
double c_im = [row - height/2.0]*4.0/width;
double x = 0, y = 0;
int iteration = 0;
while [x*x+y*y <= 4 && iteration < max] {
double x_new = x*x - y*y + c_re;
y = 2*x*y + c_im;
x = x_new;
iteration++;
}
if [iteration < max] putpixel[col, row, white];
else putpixel[col, row, black];
)
( c_re = [col - width / 2.0] * 4.0 / width )
(
.Screen/x DEI2 TO2F
WIDTH TO2F
#0002 TO2F
DIV2F
SUB2
#0002 TO2F
WIDTH TO2F
DIV2F
MUL2F
.fractal/c_re POK2
)
#01 .Screen/color DEO
RTN

View File

@ -23,11 +23,19 @@ initmpu(Mpu *m, Uint8 device)
Pm_GetDeviceInfo(i)->name,
i == device ? "[x]" : "[ ]");
Pm_OpenInput(&m->midi, device, NULL, 128, 0, NULL);
m->queue = 0;
m->error = pmNoError;
return 1;
}
void
listenmpu(Mpu *m)
{
m->queue = Pm_Read(m->midi, m->events, 32);
const int result = Pm_Read(m->midi, m->events, 32);
if(result < 0) {
m->error = (PmError)result;
m->queue = 0;
return;
}
m->queue = result;
}

View File

@ -20,6 +20,7 @@ typedef struct {
Uint8 queue;
PmStream *midi;
PmEvent events[32];
PmError error;
} Mpu;
int initmpu(Mpu *m, Uint8 device);

View File

@ -99,7 +99,7 @@ void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->s
void op_and16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b & a); }
void op_ora16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b | a); }
void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b ^ a); }
void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b >> (a & 0x000f) << ((a & 0x00f0) >> 4)); }
void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b >> (a & 0x0007) << ((a & 0x0070) >> 4)); }
void (*ops[])(Uxn *u) = {
op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_ovr, op_rot,