- Timestamp:
- 09/05/2017 09:49:45 AM (7 years ago)
- Branches:
- master
- Children:
- c8a92ef
- Parents:
- 5475ecf (diff), ca77925 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- emu
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/all.h
r5475ecf rf51359c 66 66 67 67 extern SDL_atomic_t run; 68 69 extern uint32_t vid_win; 70 extern uint32_t ser_win; 68 71 69 72 extern void sdl_init(void); … … 160 163 extern uint32_t kbd_read(uint32_t off, int32_t sz); 161 164 extern void kbd_write(uint32_t off, int32_t sz, uint32_t val); 165 166 extern void kbd_key(SDL_KeyboardEvent *ev, bool dn); -
emu/cpu.c
r5475ecf rf51359c 82 82 { 0x3b4001, 0x3b8001, 0, snd_init, snd_quit, snd_exec, snd_read, snd_write }, 83 83 { 0x3b8001, 0x3bc001, 0, led_init, led_quit, led_exec, led_read, led_write }, 84 { 0x3bc001, 0x3c0001, 0, kbd_init, kbd_quit, kbd_exec, kbd_read, kbd_write }84 { 0x3bc001, 0x3c0001, 3, kbd_init, kbd_quit, kbd_exec, kbd_read, kbd_write } 85 85 }; 86 86 -
emu/kbd.c
r5475ecf rf51359c 24 24 int32_t kbd_verbose = 0; 25 25 26 #define BUF_SZ 16 27 28 static int32_t buf_hd = 0; 29 static int32_t buf_tl = 0; 30 static uint8_t buf[BUF_SZ]; 31 32 static uint8_t reg = 0; 33 static bool irq = false; 34 35 static void xmit(void) 36 { 37 ver2("kbd xmit %d %d", buf_tl, buf_hd); 38 39 if (buf_tl >= buf_hd) { 40 return; 41 } 42 43 reg = buf[buf_tl % BUF_SZ]; 44 irq = true; 45 ver2("kbd xmit 0x%02x", reg); 46 47 ++buf_tl; 48 49 if (buf_tl >= BUF_SZ) { 50 buf_hd -= BUF_SZ; 51 buf_tl -= BUF_SZ; 52 ver2("kbd adj %d %d", buf_tl, buf_hd); 53 } 54 } 55 56 static void out(uint8_t c) 57 { 58 ver2("kbd out %d %d 0x%02x", buf_tl, buf_hd, c); 59 60 if (SDL_LockMutex(cpu_mutex) < 0) { 61 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 62 } 63 64 if (buf_hd >= buf_tl + BUF_SZ) { 65 err("keyboard port losing data"); 66 } 67 else { 68 buf[buf_hd % BUF_SZ] = c; 69 ++buf_hd; 70 71 if (!irq) { 72 xmit(); 73 } 74 } 75 76 if (SDL_UnlockMutex(cpu_mutex) < 0) { 77 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 78 } 79 } 80 81 static void but_on(int32_t sig) 82 { 83 out((uint8_t)(0x80 | sig)); 84 out(0x01); 85 } 86 87 static void but_off(int32_t sig) 88 { 89 out((uint8_t)(0x80 | sig)); 90 out(0x00); 91 } 92 93 static void key_touch(int32_t sig, int32_t val) 94 { 95 out((uint8_t)(0x80 | sig)); 96 out(0x01); 97 out((uint8_t)val); 98 } 99 100 static void key_off(int32_t sig) 101 { 102 out((uint8_t)(0x80 | sig)); 103 out(0x00); 104 } 105 106 #if defined NOT_YET 107 static void pot_128(int32_t sig, int32_t val) 108 { 109 out((uint8_t)(0x80 | sig)); 110 out((uint8_t)val); 111 } 112 113 static void pot_256(int32_t sig, int32_t val) 114 { 115 out((uint8_t)(0x80 | sig)); 116 out((uint8_t)((val >> 7) & 0x01)); 117 out((uint8_t)(val & 0x7f)); 118 } 119 #endif 120 121 void kbd_key(SDL_KeyboardEvent *ev, bool dn) 122 { 123 if ((ev->keysym.mod & KMOD_SHIFT) != 0 && 124 ev->keysym.sym >= SDLK_a && ev->keysym.sym <= SDLK_x) { 125 int32_t i = ev->keysym.sym - SDLK_a; 126 ver2("kbd key %d %s", i, dn ? "dn" : "up"); 127 128 if (dn) { 129 key_touch(1 + i, 0x7f); 130 } 131 else { 132 key_off(1 + i); 133 } 134 135 return; 136 } 137 138 int32_t sig; 139 140 if (ev->keysym.sym >= SDLK_0 && ev->keysym.sym <= '9') { 141 int32_t i = ev->keysym.sym - SDLK_0; 142 ver2("kbd dat %d %s", i, dn ? "dn" : "up"); 143 sig = 60 + i; 144 } 145 else { 146 switch (ev->keysym.sym) { 147 case SDLK_x: 148 ver2("kbd x %s", dn ? "dn" : "up"); 149 sig = 70; 150 break; 151 152 case SDLK_e: 153 ver2("kbd e %s", dn ? "dn" : "up"); 154 sig = 71; 155 break; 156 157 case SDLK_m: 158 ver2("kbd m %s", dn ? "dn" : "up"); 159 sig = 72; 160 break; 161 162 default: 163 return; 164 } 165 } 166 167 if (dn) { 168 but_on(sig); 169 } 170 else { 171 but_off(sig); 172 } 173 } 174 26 175 void kbd_init(void) 27 176 { … … 37 186 { 38 187 ver3("kbd exec"); 39 return false;188 return irq; 40 189 } 41 190 … … 43 192 { 44 193 ver2("kbd rd %u:%d", off, sz * 8); 45 return 0; 194 195 if (sz != 1 || off > 0) { 196 fail("invalid kbd rd %u:%d", off, sz * 8); 197 } 198 199 irq = false; 200 uint32_t res = reg; 201 202 xmit(); 203 204 return res; 46 205 } 47 206 … … 49 208 { 50 209 ver2("kbd wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val); 51 } 210 fail("invalid kbd wr %u:%d", off, sz * 8); 211 } -
emu/sdl.c
r5475ecf rf51359c 67 67 68 68 bool rel_mod = false; 69 uint32_t win = 0; 69 70 70 71 while (SDL_AtomicGet(&run) != 0) { … … 101 102 SDL_AtomicSet(&run, 0); 102 103 continue; 104 } 105 106 if (ev.type == SDL_WINDOWEVENT) { 107 if (ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { 108 ver("sdl ev win %u", ev.window.windowID); 109 win = ev.window.windowID; 110 } 103 111 } 104 112 … … 138 146 if (ev.type == SDL_TEXTINPUT) { 139 147 ver("sdl ev text input %d", ev.text.text[0]); 140 ser_text(&ev.text); 148 149 if (win == ser_win) { 150 ser_text(&ev.text); 151 } 152 141 153 continue; 142 154 } … … 144 156 if (ev.type == SDL_KEYDOWN) { 145 157 ver("sdl ev key down %d", (int32_t)ev.key.keysym.sym); 146 ser_key(&ev.key); 158 159 if (win == ser_win) { 160 ser_key(&ev.key); 161 } 162 else if (win == vid_win) { 163 kbd_key(&ev.key, true); 164 } 165 166 continue; 167 } 168 169 if (ev.type == SDL_KEYUP) { 170 ver("sdl ev key up %d", (int32_t)ev.key.keysym.sym); 171 172 if (win == vid_win) { 173 kbd_key(&ev.key, false); 174 } 175 147 176 continue; 148 177 } -
emu/ser.c
r5475ecf rf51359c 63 63 64 64 static SDL_Window *win; 65 uint32_t ser_win; 66 65 67 static SDL_Renderer *ren; 66 68 static SDL_atomic_t frame; … … 477 479 } 478 480 481 ser_win = SDL_GetWindowID(win); 482 483 if (ser_win == 0) { 484 fail("SDL_GetWindowID() failed: %s", SDL_GetError()); 485 } 486 479 487 ren = SDL_CreateRenderer(win, -1, 0); 480 488 -
emu/vid.c
r5475ecf rf51359c 50 50 #define OD0_CB 0x0800 51 51 52 #define AT_UND 0x0100 52 53 #define AT_CG 0x8000 53 54 … … 80 81 81 82 static SDL_Window *win; 83 uint32_t vid_win; 84 82 85 static SDL_Renderer *ren; 83 86 static SDL_Texture *tex; … … 123 126 int32_t fg = (at & 0x00f0) >> 4; 124 127 125 uint16_t *cg = (at & AT_CG) != 0 ? cg0 : cg1; 126 int32_t bits = cg[256 * line + ch]; 128 int32_t bits; 129 130 if ((at & AT_UND) != 0 && line == 1) { 131 bits = 0xff; 132 } 133 else { 134 uint16_t *cg = (at & AT_CG) != 0 ? cg0 : cg1; 135 bits = cg[256 * line + ch]; 136 } 137 127 138 int32_t mask = 0x01; 128 139 … … 225 236 if (win == NULL) { 226 237 fail("SDL_CreateWindow() failed: %s", SDL_GetError()); 238 } 239 240 vid_win = SDL_GetWindowID(win); 241 242 if (vid_win == 0) { 243 fail("SDL_GetWindowID() failed: %s", SDL_GetError()); 227 244 } 228 245
Note:
See TracChangeset
for help on using the changeset viewer.