Remove NST bits from this repo
This commit is contained in:
parent
abaeae55f1
commit
3f90241e3b
4
Makefile
4
Makefile
|
@ -12,8 +12,8 @@ KBD_PATH ?= /dev/input/event1
|
||||||
MOUSE_PATH ?= /dev/input/mice
|
MOUSE_PATH ?= /dev/input/mice
|
||||||
C_DEFINES := -DKBD_PATH=\"$(KBD_PATH)\" -DMOUSE_PATH=\"$(MOUSE_PATH)\"
|
C_DEFINES := -DKBD_PATH=\"$(KBD_PATH)\" -DMOUSE_PATH=\"$(MOUSE_PATH)\"
|
||||||
|
|
||||||
CC := ../ndk/bin/arm-linux-androideabi-gcc
|
CC ?= cc
|
||||||
CFLAGS := -Wall -Wextra -std=c99
|
CFLAGS := -Wall -Wextra -static
|
||||||
|
|
||||||
REL_FLAGS := -DNDEBUG -O2
|
REL_FLAGS := -DNDEBUG -O2
|
||||||
DEB_FLAGS := -DDEBUG -O0 -g
|
DEB_FLAGS := -DDEBUG -O0 -g
|
||||||
|
|
60
src/main.c
60
src/main.c
|
@ -60,7 +60,6 @@ typedef struct Mouse {
|
||||||
typedef struct Input {
|
typedef struct Input {
|
||||||
int kbd_fd;
|
int kbd_fd;
|
||||||
int mouse_fd;
|
int mouse_fd;
|
||||||
int home_fd;
|
|
||||||
char map[KEY_MAX / 8 + 1];
|
char map[KEY_MAX / 8 + 1];
|
||||||
u8 controller;
|
u8 controller;
|
||||||
Mouse mouse;
|
Mouse mouse;
|
||||||
|
@ -77,22 +76,14 @@ init_input(void) {
|
||||||
in.kbd_fd = -1;
|
in.kbd_fd = -1;
|
||||||
in.mouse_fd = -1;
|
in.mouse_fd = -1;
|
||||||
|
|
||||||
// in.kbd_fd = open(KBD_PATH, O_RDONLY | O_NONBLOCK);
|
in.kbd_fd = open(KBD_PATH, O_RDONLY | O_NONBLOCK);
|
||||||
in.kbd_fd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
|
|
||||||
if (in.kbd_fd == -1) {
|
if (in.kbd_fd == -1) {
|
||||||
// NOTE: Some applications may not require a keyboard so this is
|
// NOTE: Some applications may not require a keyboard so this is
|
||||||
// optional, but we are still displaying an error.
|
// optional, but we are still displaying an error.
|
||||||
fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
|
fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: nook home and power buttons event handler.
|
in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
|
||||||
in.home_fd = open("/dev/input/event1", O_RDONLY | O_NONBLOCK);
|
|
||||||
if (in.home_fd == -1) {
|
|
||||||
fprintf(stderr, "error: couldn't open home buttons %s: %s.\n", "/dev/input/event1", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
// in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
|
|
||||||
in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
|
|
||||||
if (in.mouse_fd == -1) {
|
if (in.mouse_fd == -1) {
|
||||||
// NOTE: Some applications may not require a mouse so this is
|
// NOTE: Some applications may not require a mouse so this is
|
||||||
// optional, but we are still displaying an error.
|
// optional, but we are still displaying an error.
|
||||||
|
@ -127,16 +118,16 @@ poll_mouse(void) {
|
||||||
if (mouse_event.type == EV_REL) {
|
if (mouse_event.type == EV_REL) {
|
||||||
if (mouse_event.code == REL_X) {
|
if (mouse_event.code == REL_X) {
|
||||||
in.mouse.x = CLAMP(
|
in.mouse.x = CLAMP(
|
||||||
in.mouse.x / zoom + (s32)mouse_event.value, 0, (s32)screen_width);
|
in.mouse.x / (s32)zoom + (s32)mouse_event.value, 0, (s32)screen_width);
|
||||||
} else if (mouse_event.code == REL_Y) {
|
} else if (mouse_event.code == REL_Y) {
|
||||||
in.mouse.y = CLAMP(
|
in.mouse.y = CLAMP(
|
||||||
in.mouse.y / zoom + (s32)mouse_event.value, 0, (s32)screen_height);
|
in.mouse.y / (s32)zoom + (s32)mouse_event.value, 0, (s32)screen_height);
|
||||||
}
|
}
|
||||||
} else if (mouse_event.type == EV_ABS) {
|
} else if (mouse_event.type == EV_ABS) {
|
||||||
if (mouse_event.code == ABS_X) {
|
if (mouse_event.code == ABS_X) {
|
||||||
in.mouse.x = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_width);
|
in.mouse.x = CLAMP((s32)mouse_event.value / (s32)zoom, 0, (s32)screen_width);
|
||||||
} else if (mouse_event.code == ABS_Y) {
|
} else if (mouse_event.code == ABS_Y) {
|
||||||
in.mouse.y = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_height);
|
in.mouse.y = CLAMP((s32)mouse_event.value / (s32)zoom, 0, (s32)screen_height);
|
||||||
}
|
}
|
||||||
} else if (mouse_event.type == EV_KEY) {
|
} else if (mouse_event.type == EV_KEY) {
|
||||||
switch (mouse_event.code) {
|
switch (mouse_event.code) {
|
||||||
|
@ -154,39 +145,17 @@ poll_mouse(void) {
|
||||||
in.mouse.buttons &= ~0x10;
|
in.mouse.buttons &= ~0x10;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
default: {
|
default: break;
|
||||||
// NOTE: nook press.
|
|
||||||
if (mouse_event.value == 1) {
|
|
||||||
in.mouse.buttons |= 0x01;
|
|
||||||
} else {
|
|
||||||
in.mouse.buttons &= ~0x01;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.mouse.update = true;
|
in.mouse.update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
poll_home(void) {
|
|
||||||
if (in.home_fd == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct input_event event;
|
|
||||||
if (read(in.home_fd, &event, sizeof(event)) != -1) {
|
|
||||||
if (event.code == 102 && event.value == 1) {
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
poll_input(void) {
|
poll_input(void) {
|
||||||
poll_keyboard();
|
poll_keyboard();
|
||||||
poll_mouse();
|
poll_mouse();
|
||||||
poll_home();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -317,15 +286,6 @@ handle_keyboard(void) {
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Nook overrides.
|
|
||||||
switch (key_code) {
|
|
||||||
case 156: { rune = 0x10; } break; // top left
|
|
||||||
case 139: { rune = 0x20; } break; // bottom left
|
|
||||||
case 151: { rune = 0x40; } break; // top right
|
|
||||||
case 158: { rune = 0x80; } break; // bottom right
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rune) {
|
if (rune) {
|
||||||
controller_now |= rune;
|
controller_now |= rune;
|
||||||
continue;
|
continue;
|
||||||
|
@ -567,8 +527,6 @@ main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// Main loop.
|
// Main loop.
|
||||||
Time frame_time = time_now();
|
Time frame_time = time_now();
|
||||||
size_t frames_update = 0;
|
|
||||||
size_t frames_refresh = 0;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
poll_input();
|
poll_input();
|
||||||
size_t elapsed = time_elapsed(frame_time);
|
size_t elapsed = time_elapsed(frame_time);
|
||||||
|
@ -580,10 +538,6 @@ main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// Blit ppu.pixels to the framebuffer.
|
// Blit ppu.pixels to the framebuffer.
|
||||||
blit_framebuffer();
|
blit_framebuffer();
|
||||||
if (++frames_update > frames_per_update) {
|
|
||||||
write(fb_file, "0", 0);
|
|
||||||
frames_update = 0;
|
|
||||||
}
|
|
||||||
frame_time = time_now();
|
frame_time = time_now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
92
src/ppu.c
92
src/ppu.c
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <linux/fb.h>
|
#include <linux/fb.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
// #include <sys/kd.h>
|
#include <sys/kd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "ppu.h"
|
#include "ppu.h"
|
||||||
|
@ -23,16 +23,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Parameters.
|
// Parameters.
|
||||||
static int zoom = 2;
|
static size_t zoom = 4;
|
||||||
static int frames_per_update = 5;
|
|
||||||
static int blits_per_refresh = 60 * 5;
|
|
||||||
|
|
||||||
static size_t screen_width = 0;
|
static size_t screen_width = 0;
|
||||||
static size_t screen_height = 0;
|
static size_t screen_height = 0;
|
||||||
static size_t bpp = 0;
|
static size_t bpp = 0;
|
||||||
static int fb_file = 0;
|
static int fb_file = 0;
|
||||||
static int refresh_file = 0;
|
|
||||||
static frames_refresh = 0;
|
|
||||||
|
|
||||||
static u8 *framebuffer = 0;
|
static u8 *framebuffer = 0;
|
||||||
|
|
||||||
|
@ -121,51 +117,45 @@ set_tty(bool graphics) {
|
||||||
fprintf(stderr,"error: couldn't open tty\n");
|
fprintf(stderr,"error: couldn't open tty\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
if (graphics) {
|
||||||
// if (graphics) {
|
if (ioctl(tty, KDSETMODE, KD_GRAPHICS)) {
|
||||||
// if (ioctl(tty, KDSETMODE, KD_GRAPHICS)) {
|
fprintf(stderr,"error: setting graphics mode failed\n");
|
||||||
// fprintf(stderr,"error: setting graphics mode failed\n");
|
exit(EXIT_FAILURE);
|
||||||
// exit(EXIT_FAILURE);
|
}
|
||||||
// }
|
struct termios t;
|
||||||
// struct termios t;
|
if (tcgetattr(STDIN_FILENO, &t)) {
|
||||||
// if (tcgetattr(STDIN_FILENO, &t)) {
|
fprintf(stderr, "error: couldn't disable terminal echo\n");
|
||||||
// fprintf(stderr, "error: couldn't disable terminal echo\n");
|
exit(EXIT_FAILURE);
|
||||||
// exit(EXIT_FAILURE);
|
}
|
||||||
// }
|
prev_t = t;
|
||||||
// prev_t = t;
|
t.c_lflag &= ~((tcflag_t) ECHO);
|
||||||
// t.c_lflag &= ~((tcflag_t) ECHO);
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) {
|
||||||
// if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) {
|
fprintf(stderr, "error: couldn't disable terminal echo\n");
|
||||||
// fprintf(stderr, "error: couldn't disable terminal echo\n");
|
exit(EXIT_FAILURE);
|
||||||
// exit(EXIT_FAILURE);
|
}
|
||||||
// }
|
} else {
|
||||||
// } else {
|
if (ioctl(tty, KDSETMODE, KD_TEXT)) {
|
||||||
// if (ioctl(tty, KDSETMODE, KD_TEXT)) {
|
fprintf(stderr,"error: setting text mode failed\n");
|
||||||
// fprintf(stderr,"error: setting text mode failed\n");
|
exit(EXIT_FAILURE);
|
||||||
// exit(EXIT_FAILURE);
|
}
|
||||||
// }
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &prev_t)) {
|
||||||
// if (tcsetattr(STDIN_FILENO, TCSANOW, &prev_t)) {
|
fprintf(stderr, "error: couldn't restore terminal attributes\n");
|
||||||
// fprintf(stderr, "error: couldn't restore terminal attributes\n");
|
exit(EXIT_FAILURE);
|
||||||
// exit(EXIT_FAILURE);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
close(tty);
|
close(tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ppu_init(void) {
|
ppu_init(void) {
|
||||||
// Open frambuffer and get the size.
|
// Open frambuffer and get the size.
|
||||||
fb_file = open("/dev/graphics/fb0", O_RDWR);
|
// TODO: Pass as macro or input parameter
|
||||||
|
fb_file = open("/dev/fb0", O_RDWR);
|
||||||
if (fb_file <= 0) {
|
if (fb_file <= 0) {
|
||||||
fprintf(stderr, "error: couldn't open the framebuffer\n");
|
fprintf(stderr, "error: couldn't open the framebuffer\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_file = open("/sys/class/graphics/fb0/epd_refresh", O_RDWR);
|
|
||||||
if (refresh_file == 0) {
|
|
||||||
fprintf(stderr, "error: couldn't open the refresh file\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct fb_var_screeninfo info;
|
struct fb_var_screeninfo info;
|
||||||
if (ioctl(fb_file, FBIOGET_VSCREENINFO, &info) != 0) {
|
if (ioctl(fb_file, FBIOGET_VSCREENINFO, &info) != 0) {
|
||||||
fprintf(stderr, "error: couldn't get the framebuffer size\n");
|
fprintf(stderr, "error: couldn't get the framebuffer size\n");
|
||||||
|
@ -195,7 +185,7 @@ ppu_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare TTY for graphics mode.
|
// Prepare TTY for graphics mode.
|
||||||
// set_tty(true);
|
set_tty(true);
|
||||||
|
|
||||||
// Initialize default palette.
|
// Initialize default palette.
|
||||||
palette[0] = 0x444444;
|
palette[0] = 0x444444;
|
||||||
|
@ -210,11 +200,11 @@ ppu_init(void) {
|
||||||
|
|
||||||
// Clear framebuffer.
|
// Clear framebuffer.
|
||||||
memset(framebuffer, 0xFF, len);
|
memset(framebuffer, 0xFF, len);
|
||||||
write(refresh_file, "1", 1);
|
|
||||||
|
|
||||||
// Make sure we perform an initial screen drawing.
|
// Make sure we perform an initial screen drawing.
|
||||||
reqdraw = 1;
|
reqdraw = 1;
|
||||||
redraw_screen();
|
redraw_screen();
|
||||||
|
close(fb_file);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +221,7 @@ blit_framebuffer(void) {
|
||||||
for (size_t i = 0; i < screen_width; i++) {
|
for (size_t i = 0; i < screen_width; i++) {
|
||||||
size_t idx = i + j * screen_width;
|
size_t idx = i + j * screen_width;
|
||||||
if (bpp == 16) {
|
if (bpp == 16) {
|
||||||
u16 *p = framebuffer;
|
u16 *p = (u16*)framebuffer;
|
||||||
for (size_t zz = 0; zz < zoom; zz++) {
|
for (size_t zz = 0; zz < zoom; zz++) {
|
||||||
size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
|
size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
|
||||||
for (size_t z = 0; z < zoom; z++) {
|
for (size_t z = 0; z < zoom; z++) {
|
||||||
|
@ -239,8 +229,13 @@ blit_framebuffer(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (bpp == 32) {
|
} else if (bpp == 32) {
|
||||||
u32 *p = framebuffer;
|
u32 *p = (u32*)framebuffer;
|
||||||
p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]];
|
for (size_t zz = 0; zz < zoom; zz++) {
|
||||||
|
size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
|
||||||
|
for (size_t z = 0; z < zoom; z++) {
|
||||||
|
p[fb_idx + z] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]];
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "error: wrong bits per pixel (expected 16 or 32)\n");
|
fprintf(stderr, "error: wrong bits per pixel (expected 16 or 32)\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -249,12 +244,5 @@ blit_framebuffer(void) {
|
||||||
}
|
}
|
||||||
dirty_lines[j] = 0;
|
dirty_lines[j] = 0;
|
||||||
}
|
}
|
||||||
// NOTE: Maybe this should happen on blit_framebuffer depending on
|
|
||||||
// the number of actual updates (uxn applications that don't modify
|
|
||||||
// the framebuffer shouldn't have to blink).
|
|
||||||
if (++frames_refresh > blits_per_refresh) {
|
|
||||||
write(refresh_file, "1", 1);
|
|
||||||
frames_refresh = 0;
|
|
||||||
}
|
|
||||||
reqdraw = 0;
|
reqdraw = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue