| ... | ... |
@@ -7,6 +7,8 @@ clang-format -i src/ppu.h |
| 7 | 7 |
clang-format -i src/ppu.c |
| 8 | 8 |
clang-format -i src/apu.h |
| 9 | 9 |
clang-format -i src/apu.c |
| 10 |
+clang-format -i src/mpu.h |
|
| 11 |
+clang-format -i src/mpu.c |
|
| 10 | 12 |
clang-format -i src/assembler.c |
| 11 | 13 |
clang-format -i src/emulator.c |
| 12 | 14 |
clang-format -i src/debugger.c |
| ... | ... |
@@ -23,12 +25,12 @@ if [ "${1}" = '--debug' ];
|
| 23 | 25 |
then |
| 24 | 26 |
echo "[debug]" |
| 25 | 27 |
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/assembler.c -o bin/assembler |
| 26 |
- cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/ppu.c src/emulator.c src/apu.c -L/usr/local/lib -lSDL2 -o bin/emulator |
|
| 28 |
+ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/ppu.c src/apu.c src/mpu.c src/emulator.c -L/usr/local/lib -lSDL2 -lportmidi -o bin/emulator |
|
| 27 | 29 |
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/debugger.c -o bin/debugger |
| 28 | 30 |
else |
| 29 | 31 |
cc src/assembler.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o bin/assembler |
| 30 | 32 |
cc src/uxn.c src/debugger.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o bin/debugger |
| 31 |
- cc src/uxn.c src/ppu.c src/emulator.c src/apu.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator |
|
| 33 |
+ cc src/uxn.c src/ppu.c src/apu.c src/mpu.c src/emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -lportmidi -o bin/emulator |
|
| 32 | 34 |
fi |
| 33 | 35 |
|
| 34 | 36 |
echo "Assembling.." |
| ... | ... |
@@ -10,10 +10,12 @@ |
| 10 | 10 |
( devices ) |
| 11 | 11 |
|
| 12 | 12 |
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
| 13 |
+|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ] |
|
| 13 | 14 |
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] |
| 14 | 15 |
|30 @Audio [ &pad $8 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
| 15 | 16 |
|40 @Controller [ &vector $2 &button $1 &key $1 ] |
| 16 | 17 |
|60 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ] |
| 18 |
+|90 @Midi [ &vector $2 &message $2 ] |
|
| 17 | 19 |
|
| 18 | 20 |
( variables ) |
| 19 | 21 |
|
| ... | ... |
@@ -42,6 +44,8 @@ |
| 42 | 44 |
( vectors ) |
| 43 | 45 |
;on-control .Controller/vector DEO2 |
| 44 | 46 |
;on-mouse .Mouse/vector DEO2 |
| 47 |
+ ;on-midi .Midi/vector DEO2 |
|
| 48 |
+ ;on-frame .Screen/vector DEO2 |
|
| 45 | 49 |
|
| 46 | 50 |
( find center ) |
| 47 | 51 |
.Screen/width DEI2 2/ .center/x POK2 |
| ... | ... |
@@ -79,6 +83,23 @@ |
| 79 | 83 |
|
| 80 | 84 |
BRK |
| 81 | 85 |
|
| 86 |
+@on-frame ( -> ) |
|
| 87 |
+ |
|
| 88 |
+ .wave-view/x1 PEK2 #0028 ADD2 .Screen/x DEO2 |
|
| 89 |
+ .wave-view/y1 PEK2 #0010 SUB2 .Screen/y DEO2 |
|
| 90 |
+ .Audio/volume DEI #04 SFT TOS #0008 MUL2 ;meter ADD2 .Screen/addr DEO2 |
|
| 91 |
+ #21 .Screen/color DEO |
|
| 92 |
+ #88 .Audio/volume DEO |
|
| 93 |
+ |
|
| 94 |
+ |
|
| 95 |
+BRK |
|
| 96 |
+ |
|
| 97 |
+@on-midi ( -> ) |
|
| 98 |
+ |
|
| 99 |
+ .Midi/message DEI .Audio/pitch DEO |
|
| 100 |
+ |
|
| 101 |
+BRK |
|
| 102 |
+ |
|
| 82 | 103 |
@on-mouse ( -> ) |
| 83 | 104 |
|
| 84 | 105 |
;draw-cursor JSR2 |
| ... | ... |
@@ -436,6 +457,24 @@ RTN |
| 436 | 457 |
07 06 05 03 02 01 00 00 |
| 437 | 458 |
00 00 01 02 03 05 06 07 ] |
| 438 | 459 |
|
| 460 |
+@meter [ |
|
| 461 |
+ 0000 0000 0000 0000 |
|
| 462 |
+ 0000 0000 0000 0070 |
|
| 463 |
+ 0000 0000 0000 007e |
|
| 464 |
+ 0000 0000 0000 707e |
|
| 465 |
+ 0000 0000 0070 7e7e |
|
| 466 |
+ 0000 0000 007e 7e7e |
|
| 467 |
+ 0000 0000 707e 7e7e |
|
| 468 |
+ 0000 0000 7e7e 7e7e |
|
| 469 |
+ 0000 0070 7e7e 7e7e |
|
| 470 |
+ 0000 007e 7e7e 7e7e |
|
| 471 |
+ 0000 707e 7e7e 7e7e |
|
| 472 |
+ 0000 7e7e 7e7e 7e7e |
|
| 473 |
+ 0070 7e7e 7e7e 7e7e |
|
| 474 |
+ 007e 7e7e 7e7e 7e7e |
|
| 475 |
+ 707e 7e7e 7e7e 7e7e |
|
| 476 |
+ 7e7e 7e7e 7e7e 7e7e ] |
|
| 477 |
+ |
|
| 439 | 478 |
@font-hex ( 0-F ) |
| 440 | 479 |
[ |
| 441 | 480 |
007c 8282 8282 827c 0030 1010 1010 1010 |
| ... | ... |
@@ -16,6 +16,7 @@ WITH REGARD TO THIS SOFTWARE. |
| 16 | 16 |
#include "uxn.h" |
| 17 | 17 |
#include "ppu.h" |
| 18 | 18 |
#include "apu.h" |
| 19 |
+#include "mpu.h" |
|
| 19 | 20 |
|
| 20 | 21 |
static SDL_AudioDeviceID audio_id; |
| 21 | 22 |
static SDL_Window *gWindow; |
| ... | ... |
@@ -23,7 +24,8 @@ static SDL_Renderer *gRenderer; |
| 23 | 24 |
static SDL_Texture *gTexture; |
| 24 | 25 |
static Ppu ppu; |
| 25 | 26 |
static Apu apu[POLYPHONY]; |
| 26 |
-static Device *devscreen, *devmouse, *devctrl; |
|
| 27 |
+static Mpu mpu; |
|
| 28 |
+static Device *devscreen, *devmouse, *devctrl, *devmidi; |
|
| 27 | 29 |
|
| 28 | 30 |
Uint8 zoom = 0, debug = 0, reqdraw = 0; |
| 29 | 31 |
|
| ... | ... |
@@ -102,6 +104,8 @@ init(void) |
| 102 | 104 |
SDL_AudioSpec as; |
| 103 | 105 |
if(!initppu(&ppu, 48, 32, 16)) |
| 104 | 106 |
return error("PPU", "Init failure");
|
| 107 |
+ if(!initmpu(&mpu, 1)) |
|
| 108 |
+ return error("MPU", "Init failure");
|
|
| 105 | 109 |
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) |
| 106 | 110 |
return error("Init", SDL_GetError());
|
| 107 | 111 |
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ppu.width * zoom, ppu.height * zoom, SDL_WINDOW_SHOWN);
|
| ... | ... |
@@ -288,6 +292,14 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w) |
| 288 | 292 |
(void)w; |
| 289 | 293 |
} |
| 290 | 294 |
|
| 295 |
+void |
|
| 296 |
+midi_talk(Device *d, Uint8 b0, Uint8 w) |
|
| 297 |
+{
|
|
| 298 |
+ (void)d; |
|
| 299 |
+ (void)b0; |
|
| 300 |
+ (void)w; |
|
| 301 |
+} |
|
| 302 |
+ |
|
| 291 | 303 |
void |
| 292 | 304 |
nil_talk(Device *d, Uint8 b0, Uint8 w) |
| 293 | 305 |
{
|
| ... | ... |
@@ -304,6 +316,7 @@ start(Uxn *u) |
| 304 | 316 |
evaluxn(u, 0x0100); |
| 305 | 317 |
redraw(ppu.output, u); |
| 306 | 318 |
while(1) {
|
| 319 |
+ int i; |
|
| 307 | 320 |
SDL_Event event; |
| 308 | 321 |
double elapsed, start = SDL_GetPerformanceCounter(); |
| 309 | 322 |
while(SDL_PollEvent(&event) != 0) {
|
| ... | ... |
@@ -333,6 +346,11 @@ start(Uxn *u) |
| 333 | 346 |
break; |
| 334 | 347 |
} |
| 335 | 348 |
} |
| 349 |
+ listenmpu(&mpu); |
|
| 350 |
+ for(i = 0; i < mpu.queue; ++i) {
|
|
| 351 |
+ mempoke16(devmidi->dat, 2, mpu.events[i].message); |
|
| 352 |
+ evaluxn(u, mempeek16(devmidi->dat, 0)); |
|
| 353 |
+ } |
|
| 336 | 354 |
evaluxn(u, mempeek16(devscreen->dat, 0)); |
| 337 | 355 |
if(reqdraw) |
| 338 | 356 |
redraw(ppu.output, u); |
| ... | ... |
@@ -366,7 +384,7 @@ main(int argc, char **argv) |
| 366 | 384 |
devmouse = portuxn(&u, 0x6, "mouse", nil_talk); |
| 367 | 385 |
portuxn(&u, 0x7, "file", file_talk); |
| 368 | 386 |
portuxn(&u, 0x8, "---", nil_talk); |
| 369 |
- portuxn(&u, 0x9, "midi", nil_talk); |
|
| 387 |
+ devmidi = portuxn(&u, 0x9, "midi", midi_talk); |
|
| 370 | 388 |
portuxn(&u, 0xa, "datetime", datetime_talk); |
| 371 | 389 |
portuxn(&u, 0xb, "---", nil_talk); |
| 372 | 390 |
portuxn(&u, 0xc, "---", nil_talk); |
| 373 | 391 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 1 |
+/* |
|
| 2 |
+Copyright (c) 2021 Devine Lu Linvega |
|
| 3 |
+Copyright (c) 2021 Andrew Alderwick |
|
| 4 |
+ |
|
| 5 |
+Permission to use, copy, modify, and distribute this software for any |
|
| 6 |
+purpose with or without fee is hereby granted, provided that the above |
|
| 7 |
+copyright notice and this permission notice appear in all copies. |
|
| 8 |
+ |
|
| 9 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
| 10 |
+WITH REGARD TO THIS SOFTWARE. |
|
| 11 |
+*/ |
|
| 12 |
+ |
|
| 13 |
+#include "mpu.h" |
|
| 14 |
+ |
|
| 15 |
+int |
|
| 16 |
+initmpu(Mpu *m, Uint8 device) |
|
| 17 |
+{
|
|
| 18 |
+ int i; |
|
| 19 |
+ Pm_Initialize(); |
|
| 20 |
+ for(i = 0; i < Pm_CountDevices(); ++i) |
|
| 21 |
+ printf("Device #%d -> %s%s\n",
|
|
| 22 |
+ i, |
|
| 23 |
+ Pm_GetDeviceInfo(i)->name, |
|
| 24 |
+ i == device ? "[x]" : "[ ]"); |
|
| 25 |
+ Pm_OpenInput(&m->midi, device, NULL, 128, 0, NULL); |
|
| 26 |
+ return 1; |
|
| 27 |
+} |
|
| 28 |
+ |
|
| 29 |
+void |
|
| 30 |
+listenmpu(Mpu *m) |
|
| 31 |
+{
|
|
| 32 |
+ m->queue = Pm_Read(m->midi, m->events, 32); |
|
| 33 |
+} |
| 0 | 34 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,26 @@ |
| 1 |
+#include <stdio.h> |
|
| 2 |
+#include <stdlib.h> |
|
| 3 |
+#include <portmidi.h> |
|
| 4 |
+ |
|
| 5 |
+/* |
|
| 6 |
+Copyright (c) 2021 Devine Lu Linvega |
|
| 7 |
+Copyright (c) 2021 Andrew Alderwick |
|
| 8 |
+ |
|
| 9 |
+Permission to use, copy, modify, and distribute this software for any |
|
| 10 |
+purpose with or without fee is hereby granted, provided that the above |
|
| 11 |
+copyright notice and this permission notice appear in all copies. |
|
| 12 |
+ |
|
| 13 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
| 14 |
+WITH REGARD TO THIS SOFTWARE. |
|
| 15 |
+*/ |
|
| 16 |
+ |
|
| 17 |
+typedef unsigned char Uint8; |
|
| 18 |
+ |
|
| 19 |
+typedef struct {
|
|
| 20 |
+ Uint8 queue; |
|
| 21 |
+ PmStream *midi; |
|
| 22 |
+ PmEvent events[32]; |
|
| 23 |
+} Mpu; |
|
| 24 |
+ |
|
| 25 |
+int initmpu(Mpu *m, Uint8 device); |
|
| 26 |
+void listenmpu(Mpu *m); |