Changes in / [49efb91:56746cf] in buchla-emu
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r49efb91 r56746cf 3 3 ifndef WIN 4 4 GCC := gcc 5 GPP := g++ 5 6 SDL2 := /opt/sdl2 7 RTMIDI := /opt/rtmidi 6 8 EXT := 7 9 else 8 10 GCC := x86_64-w64-mingw32-gcc 11 GPP := x86_64-w64-mingw32-g++ 9 12 SDL2 := /opt/sdl2-win 13 RTMIDI := /opt/rtmidi-win 10 14 EXT := .exe 11 15 endif … … 13 17 SDL2_INC := $(SDL2)/include 14 18 SDL2_LIB := $(SDL2)/lib 19 20 RTMIDI_INC := $(RTMIDI)/include 21 RTMIDI_LIB := $(RTMIDI)/lib 15 22 16 23 FLAGS := -std=c99 -O2 -gdwarf-4 … … 23 30 -Wpedantic -Wconversion -Wsign-conversion -Wshadow \ 24 31 -Wstrict-prototypes -Wmissing-declarations -Wredundant-decls \ 25 -I cpu -I emu -I build -I $(SDL2_INC) 32 -I cpu -I emu -I build -I $(SDL2_INC) -I $(RTMIDI_INC) 26 33 27 34 FLAGS_AUX := $(FLAGS) -Wall -Wextra \ … … 37 44 $(SDL2_LIB)/libSDL2_ttf.a \ 38 45 $(SDL2_LIB)/libfreetype.a \ 39 -ldl -lm 46 $(RTMIDI_LIB)/librtmidi.a \ 47 -ldl -lm -lasound 40 48 endif 41 49 … … 47 55 $(SDL2_LIB)/libSDL2_ttf.a \ 48 56 $(SDL2_LIB)/libfreetype.a \ 57 $(RTMIDI_LIB)/librtmidi.a \ 49 58 -framework AppKit \ 50 59 -framework AudioToolbox \ 51 60 -framework Carbon \ 61 -framework CoreMIDI \ 52 62 -framework CoreAudio \ 53 63 -framework CoreFoundation \ … … 60 70 else 61 71 FLAGS_EMU += -D EMU_WIN 62 FLAGS_LNK := $(FLAGS) -Wall -Wextra 72 FLAGS_LNK := $(FLAGS) -Wall -Wextra -static -static-libstdc++ 63 73 LIBS := -l mingw32 \ 64 74 $(SDL2_LIB)/libSDL2.a \ … … 67 77 $(SDL2_LIB)/libSDL2_ttf.a \ 68 78 $(SDL2_LIB)/libfreetype.a \ 79 $(RTMIDI_LIB)/librtmidi.a \ 69 80 -l gdi32 \ 70 81 -l imm32 \ … … 116 127 117 128 buchla$(EXT): $(CPU_OP) $(GEN_OP) $(EMU_OP) 118 $(G CC) $(FLAGS_LNK) -o buchla$(EXT) \129 $(GPP) $(FLAGS_LNK) -o buchla$(EXT) \ 119 130 $(CPU_OP) $(GEN_OP) $(EMU_OP) \ 120 131 $(LIBS) -
emu/cpu.c
r49efb91 r56746cf 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, 0, mid_init, mid_quit, mid_exec, mid_read, mid_write },93 { 0x3ac001, 0x3b0001, 5, 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
r49efb91 r56746cf 17 17 18 18 #include <all.h> 19 #include <rtmidi/rtmidi_c.h> 19 20 20 21 #define ver(...) _ver(mid_verbose, 0, __VA_ARGS__) 21 22 #define ver2(...) _ver(mid_verbose, 1, __VA_ARGS__) 22 23 #define ver3(...) _ver(mid_verbose, 2, __VA_ARGS__) 23 24 int32_t mid_verbose = 0;25 24 26 25 #define REG_IER_ISR 0 … … 29 28 #define REG_TDR_RDR 3 30 29 30 #define BUF_SZ 128 31 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 31 116 void mid_init(void) 32 117 { 33 118 ver("mid init"); 119 120 midiin = rtmidi_in_create_default(); 121 ver2("%p", midiin->ptr); 122 // check if null 123 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 } 34 145 } 35 146 36 147 void mid_quit(void) 37 148 { 149 if(midiin) { 150 rtmidi_close_port(midiin); 151 rtmidi_in_free(midiin); 152 } 153 38 154 ver("mid quit"); 39 155 } … … 42 158 { 43 159 ver3("mid exec"); 44 return false;160 return state[0].irq_r || state[0].irq_t || state[1].irq_r || state[1].irq_t; 45 161 } 46 162 … … 48 164 { 49 165 ver2("mid rd %u:%d", off, sz * 8); 50 return 0; 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; 51 200 } 52 201 -
readme.txt
r49efb91 r56746cf 91 91 ../configure --prefix=/opt/sdl2 --with-sdl-prefix=/opt/sdl2 92 92 93 make 94 make install 95 96 # Build and install rtmidi 97 98 tar zxvf rtmidi-3.0.0.tar.gz 99 cd rtmidi-3.0.0 100 mkdir build 101 cd build 102 103 ../configure --prefix=/opt/rtmidi 104 93 105 make 94 106 make install
Note:
See TracChangeset
for help on using the changeset viewer.