(screen.c) Improved readability of the code

This commit is contained in:
Devine Lu Linvega 2023-04-13 21:33:16 -07:00
parent 891204610a
commit d0db4f9223
2 changed files with 39 additions and 26 deletions

View File

@ -154,11 +154,11 @@ JMP2r
(
@|assets )
@x-icn
0000 0018 1800 0000
@preview-chr
0f38 675f dfbf bfbf 0007 1820 2344 4848
@font-icn ( 0-f )
@x-icn [
0000 0018 1800 0000 ]
@preview-chr [
0f38 675f dfbf bfbf 0007 1820 2344 4848 ]
@font-icn ( 0-f ) [
007c 8282 8282 827c 0030 1010 1010 1010
007c 8202 7c80 80fe 007c 8202 1c02 827c
000c 1424 4484 fe04 00fe 8080 7c02 827c
@ -166,11 +166,11 @@ JMP2r
007c 8282 7c82 827c 007c 8282 7e02 827c
007c 8202 7e82 827e 00fc 8282 fc82 82fc
007c 8280 8080 827c 00fc 8282 8282 82fc
007c 8280 f080 827c 007c 8280 f080 8080
@anim-chr
007c 8280 f080 827c 007c 8280 f080 8080 [
@anim-chr [
0000 0018 1800 0000 c381 0000 0000 81c3 0000 183c 3c18 0000 0000 0000 0000 0000
0018 3c7e 7e3c 1800 0000 0000 0000 0000 3c7e ffe7 e7ff 7e3c 0000 0018 1800 0000
ffff e7c3 c3e7 ffff 0000 183c 3c18 0000 ffe7 c381 81c3 e7ff 0018 3c7e 7e3c 1800
c381 0000 0000 81c3 3c7e ffe7 e7ff 7e3c 0000 0000 0000 0000 ffff e7c3 c3e7 ffff
0000 0000 0000 0000 ffe7 c381 81c3 e7ff
0000 0000 0000 0000 ffe7 c381 81c3 e7ff ]

View File

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include "../uxn.h"
#include "screen.h"
@ -36,14 +37,9 @@ static void
screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color)
{
int x, y;
if(x2 >= p->width) x2 = p->width;
if(y2 >= p->height) y2 = p->height;
if(x1 >= x2 || y1 >= y2)
return;
for(y = y1; y < y2; y++)
for(x = x1; x < x2; x++)
for(y = y1; y < y2 && y < p->height; y++)
for(x = x1; x < x2 && x < p->width; x++)
layer->pixels[x + y * p->width] = color;
layer->changed = 1;
}
static void
@ -135,13 +131,26 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
screen_resize(&uxn_screen, uxn_screen.width, PEEK2(d + 4));
break;
case 0xe: {
Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa);
Layer *layer = (d[0xe] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
if(d[0xe] & 0x80) {
Uint8 xflip = d[0xe] & 0x10, yflip = d[0xe] & 0x20;
screen_fill(&uxn_screen, layer, xflip ? 0 : x, yflip ? 0 : y, xflip ? x : uxn_screen.width, yflip ? y : uxn_screen.height, d[0xe] & 0x3);
} else {
screen_pixel(&uxn_screen, layer, x, y, d[0xe] & 0x3);
Uint8 ctrl = d[0xe];
Uint8 color = ctrl & 0x3;
Uint16 x = PEEK2(d + 0x8);
Uint16 y = PEEK2(d + 0xa);
Layer *layer = (ctrl & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
/* fill mode */
if(ctrl & 0x80) {
Uint16 x2 = uxn_screen.width;
Uint16 y2 = uxn_screen.height;
if(ctrl & 0x10) x2 = x, x = 0;
if(ctrl & 0x20) y2 = y, y = 0;
screen_fill(&uxn_screen, layer, x, y, x2, y2, color);
layer->changed = 1;
}
/* pixel mode */
else {
Uint16 width = uxn_screen.width;
Uint16 height = uxn_screen.height;
if(x < width && y < height)
layer->pixels[x + y * width] = color;
layer->changed = 1;
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */
@ -149,11 +158,15 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
break;
}
case 0xf: {
Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa), dx, dy, addr = PEEK2(d + 0xc);
Uint8 i, n = d[0x6] >> 4, twobpp = !!(d[0xf] & 0x80);
Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
dx = (d[0x6] & 0x01) << 3;
dy = (d[0x6] & 0x02) << 2;
Uint16 x = PEEK2(d + 0x8);
Uint16 y = PEEK2(d + 0xa);
Uint16 addr = PEEK2(d + 0xc);
Uint16 dx = (d[0x6] & 0x01) << 3;
Uint16 dy = (d[0x6] & 0x02) << 2;
Uint8 n = d[0x6] >> 4;
Uint8 twobpp = !!(d[0xf] & 0x80);
Uint8 i;
if(addr > 0x10000 - ((n + 1) << (3 + twobpp)))
return;
for(i = 0; i <= n; i++) {