- Timestamp:
- 08/26/2017 11:36:48 PM (7 years ago)
- Branches:
- master
- Children:
- 5475ecf
- Parents:
- 7ba68aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/lcd.c
r7ba68aa r43ea417 22 22 #define ver3(...) _ver(lcd_verbose, 2, __VA_ARGS__) 23 23 24 #define WIN_W (1 520* 2 / 3)25 #define WIN_H ( 950* 2 / 3)24 #define WIN_W (1634 * 2 / 3) 25 #define WIN_H (342 * 2 / 3) 26 26 27 27 #define CON_W 86 28 #define CON_H 2528 #define CON_H 9 29 29 30 30 #define CON_BGR 0x00000000 … … 47 47 #define G_ERASE 0x52 48 48 #define G_SLEEP 0x53 49 #define G_DSPCTL 0x58 49 #define G_DSPOFF 0x58 50 #define G_DSPON 0x59 50 51 #define G_HSCRL 0x5A 51 52 #define G_OVRLAY 0x5B … … 59 60 static SDL_atomic_t frame; 60 61 62 static uint32_t render = 0; 63 61 64 static TTF_Font *fon; 62 65 static int32_t fon_w, fon_h; … … 72 75 static int32_t cur_ad_c = 0; 73 76 77 static uint32_t last_val = 0x00; 78 static uint32_t last_off = 0; 79 static int32_t last_sz = -1; 80 static int32_t mult_val_c = 0; 81 82 static void (*cursdir)(void); 83 74 84 int32_t lcd_verbose = 0; 75 85 … … 112 122 } 113 123 124 static void up(void) 125 { 126 if (cur_y > 0) { 127 --cur_y; 128 return; 129 } 130 131 // TODO: What happens when cursor out of bounds 132 } 133 114 134 static void down(void) 115 135 { … … 119 139 } 120 140 121 scroll();141 // TODO: What happens when cursor out of bounds 122 142 } 123 143 … … 126 146 uint32_t n_cur_y = cur_addr / 85; 127 147 128 printf("Cur x %u\n", n_cur_x); 129 printf("Cur y %u\n", n_cur_y); 148 ver2("lcd cur x %u\n", n_cur_x); 149 ver2("lcd cur y %u\n", n_cur_y); 150 130 151 if (n_cur_x < CON_W - 1) { 131 152 cur_x = (int32_t) n_cur_x; … … 139 160 } 140 161 else { 162 cur_x = 0; 163 cur_y = 9; 141 164 err("invalid y cursor pos in lcd %u:%d", n_cur_y, CON_H); 142 165 } … … 145 168 static void echo(uint8_t c) 146 169 { 147 if (c < 32) { 170 if (c >127) { 171 return; 172 } 173 else if (c < 32) { 148 174 switch (c) { 149 175 case '\r': … … 165 191 case 0: 166 192 mem[cur_y][cur_x] = ' '; 167 forw();193 (*cursdir)(); 168 194 break; 169 195 … … 183 209 else { 184 210 mem[cur_y][cur_x] = c; 185 forw(); 186 } 187 188 SDL_AtomicAdd(&frame, 1); 211 (*cursdir)(); 212 } 213 214 if (render) { 215 SDL_AtomicAdd(&frame, 1); 216 } 217 } 218 219 static void clear_mem(void) { 220 for (int32_t y = 0; y < CON_H; ++y) { 221 for (int32_t x = 0; x < CON_W; ++x) { 222 mem[y][x] = ' '; 223 } 224 225 mem[y][CON_W] = 0; 226 } 189 227 } 190 228 … … 308 346 } 309 347 310 for (int32_t y = 0; y < CON_H; ++y) { 311 for (int32_t x = 0; x < CON_W; ++x) { 312 mem[y][x] = ' '; 313 } 314 315 mem[y][CON_W] = 0; 316 } 348 clear_mem(); 317 349 318 350 } … … 343 375 switch (current_op) { 344 376 case G_MREAD: 345 printf("current op: %d\n", current_op);377 ver2("lcd current op: %d\n", current_op); 346 378 rv = mem[cur_y][cur_x]; 347 379 break; 380 348 381 default: 349 382 rv = 0x00; … … 355 388 void lcd_write(uint32_t off, int32_t sz, uint32_t val) 356 389 { 357 ver2("lcd wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val); 390 391 if(last_val != val && mult_val_c > 0) { 392 if(mult_val_c > 1) { 393 ver2("lcd wr %u:%d 0x%0*x was called %u more times", last_off, last_sz * 8, last_sz * 2, last_val, mult_val_c); 394 } 395 else { 396 ver2("lcd wr %u:%d 0x%0*x", last_off, last_sz * 8, last_sz * 2, last_val); 397 } 398 399 ver2("lcd wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val); 400 mult_val_c = 0; 401 } 402 else if(last_val == val && mult_val_c >= 0) { 403 ++mult_val_c; 404 } 405 else { 406 ver2("lcd wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val); 407 } 408 409 last_val = val; 410 last_off = off; 411 last_sz = sz; 358 412 359 413 if (off == 0) { … … 362 416 echo((uint8_t)val); 363 417 break; 418 364 419 case G_CRSWR: 365 420 if (cur_ad_c == 0) { … … 372 427 } 373 428 break; 429 430 case G_DSPON: 431 // TODO Configure blinking of cursor(s) 432 break; 433 374 434 default: 375 435 break; … … 381 441 current_op = G_MWRITE; 382 442 break; 443 383 444 case G_CRSMRT: 384 forw(); 385 break; 445 cursdir = &forw; 446 current_op = G_CRSMRT; 447 break; 448 449 case G_CRSMUP: 450 cursdir = &up; 451 current_op = G_CRSMUP; 452 break; 453 454 case G_CRSMDN: 455 cursdir = &down; 456 current_op = G_CRSMDN; 457 break; 458 386 459 case G_CRSWR: 387 460 current_op = G_CRSWR; 388 461 break; 462 389 463 case G_MREAD: 390 464 current_op = G_MREAD; 391 465 break; 466 467 case G_DSPOFF: 468 if (SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0xff) < 0) { 469 fail("SDL_SetRenderDrawColor() failed: %s", SDL_GetError()); 470 } 471 if (SDL_RenderClear(ren) < 0) { 472 fail("SDL_RenderClear() failed: %s", SDL_GetError()); 473 } 474 SDL_RenderPresent(ren); 475 render = 0; 476 current_op = G_DSPOFF; 477 break; 478 479 case G_DSPON: 480 render = 1; 481 current_op = G_DSPON; 482 break; 483 484 case G_CRSFRM: 485 // TODO Setup Cursor Form... 486 current_op = 0x00; 487 break; 488 392 489 default: 393 490 current_op = 0x00;
Note:
See TracChangeset
for help on using the changeset viewer.