Disable tty echo
This commit is contained in:
parent
6b29a0cb08
commit
a46fb7bd7e
|
@ -1,4 +1,3 @@
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -6,10 +5,6 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <linux/fb.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
|
|
||||||
#include "shorthand.h"
|
#include "shorthand.h"
|
||||||
#include "ppu.c"
|
#include "ppu.c"
|
||||||
#include "uxn-fast.c"
|
#include "uxn-fast.c"
|
||||||
|
|
112
src/ppu.c
112
src/ppu.c
|
@ -1,19 +1,25 @@
|
||||||
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
|
#include <linux/fb.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "ppu.h"
|
#include "ppu.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2021 Devine Lu Linvega
|
Copyright (c) 2021 Devine Lu Linvega
|
||||||
Copyright (c) 2021 Andrew Alderwick
|
Copyright (c) 2021 Andrew Alderwick
|
||||||
Copyright (c) 2021 Bad Diode
|
Copyright (c) 2021 Bad Diode
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
copyright notice and this permission notice appear in all copies.
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
WITH REGARD TO THIS SOFTWARE.
|
WITH REGARD TO THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static size_t screen_width = 0;
|
static size_t screen_width = 0;
|
||||||
static size_t screen_height = 0;
|
static size_t screen_height = 0;
|
||||||
|
@ -37,12 +43,12 @@ static u8 blending[5][16] = {
|
||||||
|
|
||||||
void
|
void
|
||||||
ppu_pixel(u8 *layer, u16 x, u16 y, u8 color) {
|
ppu_pixel(u8 *layer, u16 x, u16 y, u8 color) {
|
||||||
if(x < screen_width && y < screen_height) {
|
if(x < screen_width && y < screen_height) {
|
||||||
Uint32 i = x + y *screen_width;
|
Uint32 i = x + y *screen_width;
|
||||||
if(color != layer[i]) {
|
if(color != layer[i]) {
|
||||||
layer[i] = color;
|
layer[i] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dirty_lines[y] |= 1;
|
dirty_lines[y] |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +60,9 @@ ppu_1bpp(u8 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) {
|
||||||
u8 ch1 = (sprite[v] >> (7 - h)) & 0x1;
|
u8 ch1 = (sprite[v] >> (7 - h)) & 0x1;
|
||||||
if(ch1 || blending[4][color])
|
if(ch1 || blending[4][color])
|
||||||
ppu_pixel(layer,
|
ppu_pixel(layer,
|
||||||
x + (flipx ? 7 - h : h),
|
x + (flipx ? 7 - h : h),
|
||||||
y + (flipy ? 7 - v : v),
|
y + (flipy ? 7 - v : v),
|
||||||
blending[ch1][color]);
|
blending[ch1][color]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +76,9 @@ ppu_2bpp(u8 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) {
|
||||||
u8 ch = ch1 + ch2 * 2;
|
u8 ch = ch1 + ch2 * 2;
|
||||||
if(ch || blending[4][color])
|
if(ch || blending[4][color])
|
||||||
ppu_pixel(layer,
|
ppu_pixel(layer,
|
||||||
x + (flipx ? 7 - h : h),
|
x + (flipx ? 7 - h : h),
|
||||||
y + (flipy ? 7 - v : v),
|
y + (flipy ? 7 - v : v),
|
||||||
blending[ch][color]);
|
blending[ch][color]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,32 +91,48 @@ redraw_screen(void) {
|
||||||
|
|
||||||
int
|
int
|
||||||
ppu_init(void) {
|
ppu_init(void) {
|
||||||
// Open frambuffer and get the size.
|
// Open frambuffer and get the size.
|
||||||
int fb = open("/dev/fb0", O_RDWR);
|
int fb = open("/dev/fb0", O_RDWR);
|
||||||
if (fb <= 0) {
|
if (fb <= 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);
|
||||||
}
|
}
|
||||||
struct fb_var_screeninfo info;
|
struct fb_var_screeninfo info;
|
||||||
if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) {
|
if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) {
|
||||||
fprintf(stderr, "error: couldn't get the framebuffer size\n");
|
fprintf(stderr, "error: couldn't get the framebuffer size\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mmap the framebuffer to a buffer object.
|
// Mmap the framebuffer to a buffer object.
|
||||||
screen_width = info.xres;
|
screen_width = info.xres;
|
||||||
screen_height = info.yres;
|
screen_height = info.yres;
|
||||||
size_t len = 4 * screen_width * screen_height;
|
size_t len = 4 * screen_width * screen_height;
|
||||||
framebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
|
framebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
|
||||||
if (framebuffer == MAP_FAILED) {
|
if (framebuffer == MAP_FAILED) {
|
||||||
fprintf(stderr, "error: couldn't mmap the framebuffer\n");
|
fprintf(stderr, "error: couldn't mmap the framebuffer\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate intermediate buffers.
|
// Allocate intermediate buffers.
|
||||||
pixels_fg = malloc(screen_width * screen_height);
|
pixels_fg = malloc(screen_width * screen_height);
|
||||||
pixels_bg = malloc(screen_width * screen_height);
|
pixels_bg = malloc(screen_width * screen_height);
|
||||||
dirty_lines = malloc(screen_height);
|
dirty_lines = malloc(screen_height);
|
||||||
|
if (pixels_fg == NULL || pixels_bg == NULL || dirty_lines == NULL) {
|
||||||
|
fprintf(stderr, "error: couldn't allocate memory for the ppu\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable echo.
|
||||||
|
struct termios t;
|
||||||
|
if (tcgetattr(STDIN_FILENO, &t)) {
|
||||||
|
fprintf(stderr, "error: couldn't disable terminal echo\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
t.c_lflag &= ~((tcflag_t) ECHO);
|
||||||
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) {
|
||||||
|
fprintf(stderr, "error: couldn't disable terminal echo\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize default palette.
|
// Initialize default palette.
|
||||||
palette[0] = 0x444444;
|
palette[0] = 0x444444;
|
||||||
|
|
Loading…
Reference in New Issue