Implemented scaling

This commit is contained in:
Devine Lu Linvega 2023-05-05 17:21:46 -07:00
parent cac4e5d093
commit 7377477f23
3 changed files with 11 additions and 9 deletions

View File

@ -84,7 +84,7 @@ screen_resize(Uint16 width, Uint16 height)
return; return;
bg = realloc(uxn_screen.bg, width * height), bg = realloc(uxn_screen.bg, width * height),
fg = realloc(uxn_screen.fg, width * height); fg = realloc(uxn_screen.fg, width * height);
pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32)); pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32) * SCALE * SCALE);
if(!bg || !fg || !pixels) if(!bg || !fg || !pixels)
return; return;
uxn_screen.bg = bg; uxn_screen.bg = bg;
@ -101,17 +101,18 @@ screen_redraw(void)
{ {
Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg; Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg;
Uint32 palette[16], *pixels = uxn_screen.pixels; Uint32 palette[16], *pixels = uxn_screen.pixels;
int i, x, y, w = uxn_screen.width, h = uxn_screen.height; int i, j, x, y, w = uxn_screen.width, h = uxn_screen.height;
int x1 = uxn_screen.x1; int x1 = uxn_screen.x1 * SCALE;
int y1 = uxn_screen.y1; int y1 = uxn_screen.y1 * SCALE;
int x2 = uxn_screen.x2 > w ? w : uxn_screen.x2; int x2 = (uxn_screen.x2 > w ? w : uxn_screen.x2) * SCALE;
int y2 = uxn_screen.y2 > h ? h : uxn_screen.y2; int y2 = (uxn_screen.y2 > h ? h : uxn_screen.y2) * SCALE;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
palette[i] = uxn_screen.palette[(i >> 2) ? (i >> 2) : (i & 3)]; palette[i] = uxn_screen.palette[(i >> 2) ? (i >> 2) : (i & 3)];
for(y = y1; y < y2; y++) for(y = y1; y < y2; y++)
for(x = x1; x < x2; x++) { for(x = x1; x < x2; x++) {
i = x + y * w; i = x / SCALE + y / SCALE * w;
pixels[i] = palette[fg[i] << 2 | bg[i]]; j = x + y * w * SCALE;
pixels[j] = palette[fg[i] << 2 | bg[i]];
} }
uxn_screen.x1 = uxn_screen.y1 = 0xffff; uxn_screen.x1 = uxn_screen.y1 = 0xffff;
uxn_screen.x2 = uxn_screen.y2 = 0; uxn_screen.x2 = uxn_screen.y2 = 0;

View File

@ -22,3 +22,5 @@ void screen_resize(Uint16 width, Uint16 height);
void screen_redraw(void); void screen_redraw(void);
Uint8 screen_dei(Uxn *u, Uint8 addr); Uint8 screen_dei(Uxn *u, Uint8 addr);
void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
#define SCALE 3

View File

@ -33,7 +33,6 @@ static Window window;
char *rom_path; char *rom_path;
#define SCALE 1
#define WIDTH (64 * 8) #define WIDTH (64 * 8)
#define HEIGHT (40 * 8) #define HEIGHT (40 * 8)
#define PAD 4 #define PAD 4