Changes in / [56746cf:49efb91] in buchla-emu
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r56746cf r49efb91 3 3 ifndef WIN 4 4 GCC := gcc 5 GPP := g++6 5 SDL2 := /opt/sdl2 7 RTMIDI := /opt/rtmidi8 6 EXT := 9 7 else 10 8 GCC := x86_64-w64-mingw32-gcc 11 GPP := x86_64-w64-mingw32-g++12 9 SDL2 := /opt/sdl2-win 13 RTMIDI := /opt/rtmidi-win14 10 EXT := .exe 15 11 endif … … 17 13 SDL2_INC := $(SDL2)/include 18 14 SDL2_LIB := $(SDL2)/lib 19 20 RTMIDI_INC := $(RTMIDI)/include21 RTMIDI_LIB := $(RTMIDI)/lib22 15 23 16 FLAGS := -std=c99 -O2 -gdwarf-4 … … 30 23 -Wpedantic -Wconversion -Wsign-conversion -Wshadow \ 31 24 -Wstrict-prototypes -Wmissing-declarations -Wredundant-decls \ 32 -I cpu -I emu -I build -I $(SDL2_INC) -I $(RTMIDI_INC)25 -I cpu -I emu -I build -I $(SDL2_INC) 33 26 34 27 FLAGS_AUX := $(FLAGS) -Wall -Wextra \ … … 44 37 $(SDL2_LIB)/libSDL2_ttf.a \ 45 38 $(SDL2_LIB)/libfreetype.a \ 46 $(RTMIDI_LIB)/librtmidi.a \ 47 -ldl -lm -lasound 39 -ldl -lm 48 40 endif 49 41 … … 55 47 $(SDL2_LIB)/libSDL2_ttf.a \ 56 48 $(SDL2_LIB)/libfreetype.a \ 57 $(RTMIDI_LIB)/librtmidi.a \58 49 -framework AppKit \ 59 50 -framework AudioToolbox \ 60 51 -framework Carbon \ 61 -framework CoreMIDI \62 52 -framework CoreAudio \ 63 53 -framework CoreFoundation \ … … 70 60 else 71 61 FLAGS_EMU += -D EMU_WIN 72 FLAGS_LNK := $(FLAGS) -Wall -Wextra -static -static-libstdc++62 FLAGS_LNK := $(FLAGS) -Wall -Wextra 73 63 LIBS := -l mingw32 \ 74 64 $(SDL2_LIB)/libSDL2.a \ … … 77 67 $(SDL2_LIB)/libSDL2_ttf.a \ 78 68 $(SDL2_LIB)/libfreetype.a \ 79 $(RTMIDI_LIB)/librtmidi.a \80 69 -l gdi32 \ 81 70 -l imm32 \ … … 127 116 128 117 buchla$(EXT): $(CPU_OP) $(GEN_OP) $(EMU_OP) 129 $(G PP) $(FLAGS_LNK) -o buchla$(EXT) \118 $(GCC) $(FLAGS_LNK) -o buchla$(EXT) \ 130 119 $(CPU_OP) $(GEN_OP) $(EMU_OP) \ 131 120 $(LIBS) -
emu/cpu.c
r56746cf r49efb91 91 91 { 0x3a4001, 0x3a8001, 0, lcd_init, lcd_quit, lcd_exec, lcd_read, lcd_write }, 92 92 { 0x3a8001, 0x3ac001, 5, ser_init, ser_quit, ser_exec, ser_read, ser_write }, 93 { 0x3ac001, 0x3b0001, 5, mid_init, mid_quit, mid_exec, mid_read, mid_write },93 { 0x3ac001, 0x3b0001, 0, mid_init, mid_quit, mid_exec, mid_read, mid_write }, 94 94 { 0x3b0001, 0x3b4001, 0, fdd_init, fdd_quit, fdd_exec, fdd_read, fdd_write }, 95 95 { 0x3b4001, 0x3b8001, 0, snd_init, snd_quit, snd_exec, snd_read, snd_write }, -
emu/mid.c
r56746cf r49efb91 17 17 18 18 #include <all.h> 19 #include <rtmidi/rtmidi_c.h>20 19 21 20 #define ver(...) _ver(mid_verbose, 0, __VA_ARGS__) 22 21 #define ver2(...) _ver(mid_verbose, 1, __VA_ARGS__) 23 22 #define ver3(...) _ver(mid_verbose, 2, __VA_ARGS__) 23 24 int32_t mid_verbose = 0; 24 25 25 26 #define REG_IER_ISR 0 … … 28 29 #define REG_TDR_RDR 3 29 30 30 #define BUF_SZ 12831 32 typedef struct {33 int32_t buf_hd;34 int32_t buf_tl;35 uint8_t buf[BUF_SZ];36 bool irq_r;37 bool irq_t;38 bool rdr_ok;39 uint8_t rdr;40 } state_t;41 42 static state_t state[] = {43 { .buf_hd = 0, .buf_tl = 0, .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 },44 { .buf_hd = 0, .buf_tl = 0, .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 }45 };46 47 int32_t mid_verbose = 0;48 49 struct RtMidiWrapper* midiin;50 51 static void xmit(int32_t un)52 {53 int32_t i = state[un].buf_tl;54 ver2("mid xmit %d %d", i, state[un].buf_hd);55 56 if (i >= state[un].buf_hd) {57 return;58 }59 60 uint8_t byte = state[un].buf[i % BUF_SZ];61 ver2("mid xmit 0x%02x", byte);62 63 state[un].rdr = byte;64 state[un].rdr_ok = true;65 state[un].irq_r = true;66 67 state[un].buf_tl = i + 1;68 69 if (state[un].buf_tl >= BUF_SZ) {70 state[un].buf_hd -= BUF_SZ;71 state[un].buf_tl -= BUF_SZ;72 ver2("mid adj %d %d", state[un].buf_tl, state[un].buf_hd);73 }74 }75 76 static void out_lk(int32_t un, uint8_t c)77 {78 int32_t i = state[un].buf_hd;79 ver2("mid out %d %d 0x%02x", state[un].buf_tl, i, c);80 81 if (i >= state[un].buf_tl + BUF_SZ) {82 err("midi port %d losing data", un);83 return;84 }85 86 state[un].buf[i % BUF_SZ] = c;87 state[un].buf_hd = i + 1;88 89 if (!state[un].irq_r && !state[un].rdr_ok) {90 xmit(un);91 }92 }93 94 static void out(int32_t un, uint8_t c)95 {96 if (SDL_LockMutex(cpu_mutex) < 0) {97 fail("SDL_LockMutex() failed: %s", SDL_GetError());98 }99 100 out_lk(un, c);101 102 if (SDL_UnlockMutex(cpu_mutex) < 0) {103 fail("SDL_UnlockMutex() failed: %s", SDL_GetError());104 }105 }106 107 static void midi_callback(double timeStamp, const unsigned char* message, void *userData) {108 ver2("Timestamp %f\n", timeStamp);109 110 for (uint8_t i = 0; i < sizeof(message); i++) {111 ver2("Message %i %u", i, (uint8_t) message[i]);112 out(0, message[i]);113 }114 }115 116 31 void mid_init(void) 117 32 { 118 33 ver("mid init"); 119 120 midiin = rtmidi_in_create_default();121 ver2("%p", midiin->ptr);122 // check if null123 uint32_t portcount = rtmidi_get_port_count(midiin);124 ver2("%d", midiin->ok);125 126 if (portcount == 0) {127 midiin = NULL;128 ver2("no midi ports\n");129 return;130 }131 132 for (uint32_t i = 0; i < portcount; i++) {133 ver2("Port %d: %s", i, rtmidi_get_port_name(midiin, i));134 }135 136 rtmidi_open_port(midiin, 0, rtmidi_get_port_name(midiin, 0));137 if(!midiin->ok) {138 fail("Failed to open Midi port");139 }140 141 rtmidi_in_set_callback(midiin, midi_callback, midiin->data);142 if(!midiin->ok) {143 fail("Failed to set Midi Callback");144 }145 34 } 146 35 147 36 void mid_quit(void) 148 37 { 149 if(midiin) {150 rtmidi_close_port(midiin);151 rtmidi_in_free(midiin);152 }153 154 38 ver("mid quit"); 155 39 } … … 158 42 { 159 43 ver3("mid exec"); 160 return state[0].irq_r || state[0].irq_t || state[1].irq_r || state[1].irq_t;44 return false; 161 45 } 162 46 … … 164 48 { 165 49 ver2("mid rd %u:%d", off, sz * 8); 166 167 if (sz != 1 || off > 7) { 168 fail("invalid mid rd %u:%d", off, sz * 8); 169 } 170 171 int32_t rg = (int32_t)(off % 4); 172 int32_t un = (int32_t)(off / 4); 173 174 uint32_t rv; 175 176 switch (rg) { 177 case REG_IER_ISR: 178 rv = (uint32_t)(0xc0 | (state[un].rdr_ok ? 0x01 : 0x00)); 179 state[un].irq_r = false; 180 state[un].irq_t = false; 181 ver2("ISR[%d] 0x%02x", un, rv); 182 break; 183 184 case REG_TDR_RDR: 185 rv = state[un].rdr; 186 state[un].rdr_ok = false; 187 ver2("RDR[%d] 0x%02x", un, rv); 188 break; 189 190 default: 191 rv = 0x00; 192 break; 193 } 194 195 if (!state[un].irq_r && !state[un].rdr_ok) { 196 xmit(un); 197 } 198 199 return rv; 50 return 0; 200 51 } 201 52 -
readme.txt
r56746cf r49efb91 91 91 ../configure --prefix=/opt/sdl2 --with-sdl-prefix=/opt/sdl2 92 92 93 make94 make install95 96 # Build and install rtmidi97 98 tar zxvf rtmidi-3.0.0.tar.gz99 cd rtmidi-3.0.0100 mkdir build101 cd build102 103 ../configure --prefix=/opt/rtmidi104 105 93 make 106 94 make install
Note:
See TracChangeset
for help on using the changeset viewer.