aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c132
1 files changed, 130 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 8d19d95..53aa5c3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,14 +80,14 @@ init_input(void) {
80 if (in.kbd_fd == -1) { 80 if (in.kbd_fd == -1) {
81 // NOTE: Some applications may not require a keyboard so this is 81 // NOTE: Some applications may not require a keyboard so this is
82 // optional, but we are still displaying an error. 82 // optional, but we are still displaying an error.
83 fprintf(stderr, "error: no couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); 83 // fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
84 } 84 }
85 85
86 in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); 86 in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
87 if (in.mouse_fd == -1) { 87 if (in.mouse_fd == -1) {
88 // NOTE: Some applications may not require a mouse so this is 88 // NOTE: Some applications may not require a mouse so this is
89 // optional, but we are still displaying an error. 89 // optional, but we are still displaying an error.
90 fprintf(stderr, "error: no couldn't open mouse %s: %s.\n", MOUSE_PATH, strerror(errno)); 90 // fprintf(stderr, "error: couldn't open mouse %s: %s.\n", MOUSE_PATH, strerror(errno));
91 } 91 }
92} 92}
93 93
@@ -367,6 +367,20 @@ screen_dei(Device *d, u8 port) {
367void 367void
368screen_deo(Device *d, u8 port) { 368screen_deo(Device *d, u8 port) {
369 switch(port) { 369 switch(port) {
370 // case 0x3:
371 // if(!FIXED_SIZE) {
372 // Uint16 w;
373 // DEVPEEK16(w, 0x2);
374 // screen_resize(&uxn_screen, clamp(w, 1, 1024), uxn_screen.height);
375 // }
376 // break;
377 // case 0x5:
378 // if(!FIXED_SIZE) {
379 // Uint16 h;
380 // DEVPEEK16(h, 0x4);
381 // screen_resize(&uxn_screen, uxn_screen.width, clamp(h, 1, 1024));
382 // }
383 // break;
370 case 0xe: { 384 case 0xe: {
371 u16 x, y; 385 u16 x, y;
372 u8 layer = d->dat[0xe] & 0x40; 386 u8 layer = d->dat[0xe] & 0x40;
@@ -509,6 +523,7 @@ main(int argc, char *argv[]) {
509 523
510 // Main loop. 524 // Main loop.
511 Time frame_time = time_now(); 525 Time frame_time = time_now();
526 size_t frames = 0;
512 while (true) { 527 while (true) {
513 poll_input(); 528 poll_input();
514 size_t elapsed = time_elapsed(frame_time); 529 size_t elapsed = time_elapsed(frame_time);
@@ -520,9 +535,122 @@ main(int argc, char *argv[]) {
520 535
521 // Blit ppu.pixels to the framebuffer. 536 // Blit ppu.pixels to the framebuffer.
522 blit_framebuffer(); 537 blit_framebuffer();
538 if (++frames > 5) {
539 // memset(framebuffer, 0xFF, screen_width * screen_height * bpp);
540 // system("echo 0 > /dev/graphics/fb0");
541 // redraw_screen();
542 // blit_framebuffer();
543
544 // FIXME: Thre HAS to be a better way to refresh the display lol.
545 system("echo 0 > /dev/graphics/fb0");
546
547 // Time t = time_now();
548 // while (time_elapsed(t) < 16666666 * 2) {
549 // // nop wait X frames for the refresh?
550 // }
551 // wait(ret);
552 // memset(framebuffer, 0xFF, screen_width * screen_height * bpp);
553 // redraw_screen();
554 // memset(framebuffer, 0x00, screen_width * screen_height * bpp);
555 // redraw_screen();
556
557 frames = 0;
558 }
523 frame_time = time_now(); 559 frame_time = time_now();
524 } 560 }
525 } 561 }
526 562
527 return 0; 563 return 0;
528} 564}
565
566// int
567// main(int argc, char *argv[]) {
568// // FIXME: Experimental
569// int fb = open("/dev/graphics/fb0", O_RDWR);
570// if (fb <= 0) {
571// fprintf(stderr, "error: couldn't open the framebuffer\n");
572// exit(EXIT_FAILURE);
573// }
574// struct fb_var_screeninfo info;
575// if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) {
576// fprintf(stderr, "error: couldn't get the framebuffer size\n");
577// exit(EXIT_FAILURE);
578// }
579// size_t screen_width = info.xres;
580// size_t screen_height = info.yres;
581// size_t bpp = info.bits_per_pixel / 8;
582// size_t len = bpp * screen_width * screen_height;
583// u8 *framebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
584// if (framebuffer == MAP_FAILED) {
585// fprintf(stderr, "error: couldn't mmap the framebuffer\n");
586// exit(EXIT_FAILURE);
587// }
588
589// // Print all relevant elements from the fb_var_screeninfo struct
590// printf("> xres: %d\n"
591// "> yres: %d\n"
592// "> xres_virtual: %d\n"
593// "> yres_virtual: %d\n"
594// "> xoffset: %d\n"
595// "> yoffset: %d\n"
596// "> bits_per_pixel: %d\n"
597// "> grayscale: %d\n"
598// "> activate: %d\n"
599// "> height: %d\n"
600// "> width: %d\n"
601// "> hsync_len: %d\n"
602// "> vsync_len: %d\n"
603// "> sync: %d\n"
604// "> vmode: %d\n"
605// "> rotate: %d\n"
606// "> len: %d\n",
607// info.xres,
608// info.yres,
609// info.xres_virtual,
610// info.yres_virtual,
611// info.xoffset,
612// info.yoffset,
613// info.bits_per_pixel,
614// info.grayscale,
615// info.activate,
616// info.height,
617// info.width,
618// info.hsync_len,
619// info.vsync_len,
620// info.sync,
621// info.vmode,
622// info.rotate,
623// len);
624
625
626// // Clean screen
627// // memset(framebuffer, 0x00, screen_width * screen_height * 2); // black
628// memset(framebuffer, 0xFF, len); // white
629// for (size_t i = 0, k = 0; i < (screen_width * screen_height) / 2; i++) {
630// for (size_t b = 0; b < bpp; b++) {
631// framebuffer[k++] = 0xF0;
632// }
633// // p[i] = 0xF0F0;
634// // framebuffer[k++] = 0xFF;
635// // framebuffer[k++] = 0x00;
636// }
637
638// // Main loop.
639// Time frame_time = time_now();
640// size_t frames = 0;
641// while (true) {
642// size_t elapsed = time_elapsed(frame_time);
643// if (elapsed >= 16666666) {
644
645// // FIXME: Thre HAS to be a better way lol.
646// frame_time = time_now();
647// frames++;
648// if (frames > 10) {
649// system("echo 0 > /dev/graphics/fb0");
650// frames = 0;
651// }
652// }
653// }
654
655// return 0;
656// }