- Timestamp:
- 08/20/2017 09:47:23 PM (7 years ago)
- Branches:
- master
- Children:
- 7ba68aa, c1c1ca5
- Parents:
- a9861f3
- Location:
- emu
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/all.h
ra9861f3 r657abdf 121 121 extern void ser_key(SDL_KeyboardEvent *ev); 122 122 123 extern void ser_mou_res(void); 124 extern void ser_mou_mov(SDL_MouseMotionEvent *ev); 125 extern void ser_mou_dn(SDL_MouseButtonEvent *ev); 126 extern void ser_mou_up(SDL_MouseButtonEvent *ev); 127 123 128 extern void mid_init(void); 124 129 extern void mid_quit(void); -
emu/sdl.c
ra9861f3 r657abdf 106 106 ver("sdl ev down-arrow"); 107 107 rel_mod = true; 108 ser_mou_res(); 108 109 continue; 109 110 } … … 113 114 rel_mod = false; 114 115 continue; 116 } 117 118 if (rel_mod) { 119 if (ev.type == SDL_MOUSEMOTION) { 120 ver("sdl ev mousemotion (%d, %d)", ev.motion.xrel, ev.motion.yrel); 121 ser_mou_mov(&ev.motion); 122 continue; 123 } 124 125 if (ev.type == SDL_MOUSEBUTTONDOWN) { 126 ver("sdl ev mousebuttondown %d", ev.button.button); 127 ser_mou_dn(&ev.button); 128 continue; 129 } 130 131 if (ev.type == SDL_MOUSEBUTTONUP) { 132 ver("sdl ev mousebuttonup %d", ev.button.button); 133 ser_mou_up(&ev.button); 134 continue; 135 } 115 136 } 116 137 -
emu/ser.c
ra9861f3 r657abdf 28 28 29 29 #define BEL_CYC 10000 30 #define MOU_CYC 10000 30 31 31 32 #define CON_W 80 … … 37 38 #define CON_FGR ((SDL_Color){ .r = 255, .b = 255, .g = 255, .a = 255 }) 38 39 40 #define BUF_SZ 16 41 39 42 #define REG_IER_ISR 0 40 43 #define REG_CFR_SR 1 … … 43 46 44 47 typedef struct { 48 int32_t buf_hd; 49 int32_t buf_tl; 50 uint8_t buf[BUF_SZ]; 45 51 bool irq_r; 46 52 bool irq_t; … … 50 56 51 57 static state_t state[] = { 52 { . irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 },53 { . irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 }58 { .buf_hd = 0, .buf_tl = 0, .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 }, 59 { .buf_hd = 0, .buf_tl = 0, .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 } 54 60 }; 55 61 … … 68 74 static int32_t cur_x = 0, cur_y = 0; 69 75 static int32_t bel = 0; 76 77 static int32_t mou; 78 static int32_t mou_dx, mou_dy; 79 static bool mou_l, mou_r; 70 80 71 81 static void scroll(void) … … 151 161 } 152 162 163 static void xmit(int32_t un) 164 { 165 int32_t i = state[un].buf_tl; 166 ver2("ser xmit %d %d", i, state[un].buf_hd); 167 168 if (i >= state[un].buf_hd) { 169 return; 170 } 171 172 uint8_t byte = state[un].buf[i % BUF_SZ]; 173 ver2("ser xmit 0x%02x", byte); 174 175 state[un].rdr = byte; 176 state[un].rdr_ok = true; 177 state[un].irq_r = true; 178 179 state[un].buf_tl = i + 1; 180 181 if (state[un].buf_tl >= BUF_SZ) { 182 state[un].buf_hd -= BUF_SZ; 183 state[un].buf_tl -= BUF_SZ; 184 ver2("ser adj %d %d", state[un].buf_tl, state[un].buf_hd); 185 } 186 } 187 188 static void out_lk(int32_t un, uint8_t c) 189 { 190 int32_t i = state[un].buf_hd; 191 ver2("ser out %d %d 0x%02x", state[un].buf_tl, i, c); 192 193 if (i >= state[un].buf_tl + BUF_SZ) { 194 err("serial port %d losing data", un); 195 return; 196 } 197 198 state[un].buf[i % BUF_SZ] = c; 199 state[un].buf_hd = i + 1; 200 201 if (!state[un].irq_r && !state[un].rdr_ok) { 202 xmit(un); 203 } 204 } 205 153 206 static void out(int32_t un, uint8_t c) 154 207 { … … 157 210 } 158 211 159 state[un].rdr = c; 160 state[un].rdr_ok = true; 161 state[un].irq_r = true; 212 out_lk(un, c); 162 213 163 214 if (SDL_UnlockMutex(cpu_mutex) < 0) { 164 215 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 165 216 } 217 } 218 219 static void mouse(uint8_t c) 220 { 221 if (c == 't') { 222 ver2("ser mou init"); 223 } 224 225 out_lk(0, 'V'); 226 out_lk(0, 'O'); 166 227 } 167 228 … … 266 327 } 267 328 329 static void mou_ev(void) 330 { 331 ver2("ser mou ev (%d, %d) %c %c", 332 mou_dx, mou_dy, mou_l ? 'l' : '-', mou_r ? 'r' : '-'); 333 334 int32_t dx = mou_dx; 335 int32_t dy = mou_dy; 336 337 if (dx < -128) { 338 dx = -128; 339 } 340 else if (dx > 127) { 341 dx = 127; 342 } 343 344 if (dy < -128) { 345 dy = -128; 346 } 347 else if (dy > 127) { 348 dy = 127; 349 } 350 351 dx = dx & 0xff; 352 dy = dy & 0xff; 353 354 int32_t b1 = 0x40; 355 356 if (mou_l) { 357 b1 |= 0x20; 358 } 359 360 if (mou_r) { 361 b1 |= 0x10; 362 } 363 364 b1 |= (dy & 0xc0) >> 4; 365 b1 |= (dx & 0xc0) >> 6; 366 367 int32_t b2 = dx & 0x3f; 368 int32_t b3 = dy & 0x3f; 369 370 out_lk(0, (uint8_t)b1); 371 out_lk(0, (uint8_t)b2); 372 out_lk(0, (uint8_t)b3); 373 374 mou_dx = mou_dy = 0; 375 } 376 377 static void mou_ev_chk(void) 378 { 379 if (--mou > 0) { 380 return; 381 } 382 383 mou = MOU_CYC; 384 385 if (mou_dx == 0 && mou_dy == 0) { 386 return; 387 } 388 389 mou_ev(); 390 } 391 392 void ser_mou_res(void) 393 { 394 if (SDL_LockMutex(cpu_mutex) < 0) { 395 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 396 } 397 398 mou = MOU_CYC; 399 mou_dx = mou_dy = 0; 400 mou_l = mou_r = false; 401 402 if (SDL_UnlockMutex(cpu_mutex) < 0) { 403 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 404 } 405 } 406 407 void ser_mou_mov(SDL_MouseMotionEvent *ev) 408 { 409 if (SDL_LockMutex(cpu_mutex) < 0) { 410 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 411 } 412 413 mou_dx += ev->xrel; 414 mou_dy += ev->yrel; 415 416 if (SDL_UnlockMutex(cpu_mutex) < 0) { 417 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 418 } 419 } 420 421 void ser_mou_dn(SDL_MouseButtonEvent *ev) 422 { 423 if (SDL_LockMutex(cpu_mutex) < 0) { 424 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 425 } 426 427 if (ev->button == SDL_BUTTON_LEFT) { 428 mou_l = true; 429 } 430 else if (ev->button == SDL_BUTTON_RIGHT) { 431 mou_r = true; 432 } 433 else { 434 return; 435 } 436 437 mou_ev(); 438 439 if (SDL_UnlockMutex(cpu_mutex) < 0) { 440 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 441 } 442 } 443 444 void ser_mou_up(SDL_MouseButtonEvent *ev) 445 { 446 if (SDL_LockMutex(cpu_mutex) < 0) { 447 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 448 } 449 450 if (ev->button == SDL_BUTTON_LEFT) { 451 mou_l = false; 452 } 453 else if (ev->button == SDL_BUTTON_RIGHT) { 454 mou_r = false; 455 } 456 else { 457 return; 458 } 459 460 mou_ev(); 461 462 if (SDL_UnlockMutex(cpu_mutex) < 0) { 463 fail("SDL_UnlockMutex() failed: %s", SDL_GetError()); 464 } 465 } 466 268 467 void ser_init(void) 269 468 { … … 343 542 } 344 543 } 544 545 mou_ev_chk(); 345 546 346 547 return state[0].irq_r || state[0].irq_t || state[1].irq_r || state[1].irq_t; … … 379 580 } 380 581 582 if (!state[un].irq_r && !state[un].rdr_ok) { 583 xmit(un); 584 } 585 381 586 return rv; 382 587 } … … 396 601 case REG_TDR_RDR: 397 602 ver2("TDR[%d] 0x%02x", un, val); 398 echo((uint8_t)val); 603 604 if (un == 1) { 605 echo((uint8_t)val); 606 } 607 else { 608 mouse((uint8_t)val); 609 } 610 399 611 state[un].irq_t = true; 400 612 break;
Note:
See TracChangeset
for help on using the changeset viewer.