get initial screen implementation mostly working.
This commit is contained in:
parent
73688d2e96
commit
ab47d5974a
|
@ -29,13 +29,12 @@ ppu_clear(Ppu *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
ppu_set_size(Ppu *p, Uint16 width, Uint16 height)
|
ppu_init(Ppu *p, Uint16 width, Uint16 height, Uint8* buf)
|
||||||
{
|
{
|
||||||
ppu_clear(p);
|
ppu_clear(p);
|
||||||
p->width = width;
|
p->width = width;
|
||||||
p->height = height;
|
p->height = height;
|
||||||
p->pixels = realloc(p->pixels, p->width * p->height * sizeof(Uint8) / 2);
|
p->pixels = buf;
|
||||||
ppu_clear(p);
|
|
||||||
return !!p->pixels;
|
return !!p->pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ typedef struct Ppu {
|
||||||
Uint16 width, height;
|
Uint16 width, height;
|
||||||
} Ppu;
|
} Ppu;
|
||||||
|
|
||||||
Uint8 ppu_set_size(Ppu *p, Uint16 width, Uint16 height);
|
Uint8 ppu_init(Ppu *p, Uint16 width, Uint16 height, Uint8* buf);
|
||||||
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
|
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
|
||||||
void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color);
|
void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color);
|
||||||
void ppu_frame(Ppu *p);
|
void ppu_frame(Ppu *p);
|
||||||
|
|
|
@ -9,9 +9,9 @@ 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.
|
||||||
|
|
||||||
TODO screen vector, de-janking display code
|
TODO screen vector, de-janking display code, support for greyscale displays
|
||||||
TODO other devices
|
TODO other varvara devices
|
||||||
TODO hardware builds, support for hardware other than simulated e200
|
TODO hardware builds
|
||||||
TODO clean up
|
TODO clean up
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ static Uxn u;
|
||||||
static Ppu ppu;
|
static Ppu ppu;
|
||||||
static Device *devsystem, *devconsole, *devscreen;
|
static Device *devsystem, *devconsole, *devscreen;
|
||||||
unsigned int palette[3];
|
unsigned int palette[3];
|
||||||
|
static uint8_t framebuffer[LCD_HEIGHT * LCD_WIDTH * 4];
|
||||||
|
|
||||||
static void
|
static void
|
||||||
memzero8(void *src, uint64_t n)
|
memzero8(void *src, uint64_t n)
|
||||||
|
@ -165,7 +166,6 @@ inspect(Stack *s, char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO implement
|
|
||||||
static void
|
static void
|
||||||
set_palette(Uint8 *addr)
|
set_palette(Uint8 *addr)
|
||||||
{
|
{
|
||||||
|
@ -178,6 +178,15 @@ set_palette(Uint8 *addr)
|
||||||
b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
|
b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
|
||||||
palette[i] = LCD_RGBPACK(r*8,g*8,b*8);
|
palette[i] = LCD_RGBPACK(r*8,g*8,b*8);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 4; ++i) {
|
||||||
|
Uint8
|
||||||
|
sum = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f;
|
||||||
|
sum += (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
|
||||||
|
sum += (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
|
||||||
|
palette[i] = sum > 0x17;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,17 +279,21 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO store palette in a non-guesswork format, optimise, make build on non-color devices
|
// TODO optimise, make build on non-color devices
|
||||||
static int redraw(Uxn *u)
|
static void redraw(void)
|
||||||
{
|
{
|
||||||
|
rb->lcd_clear_display();
|
||||||
Uint16 x, y;
|
Uint16 x, y;
|
||||||
for(y = 0; y < ppu.height; ++y)
|
for(y = 0; y < ppu.height; ++y)
|
||||||
for(x = 0; x < ppu.width; ++x) {
|
for(x = 0; x < ppu.width; ++x) {
|
||||||
#if LCD_DEPTH > 1
|
#if LCD_DEPTH > 1
|
||||||
rb->lcd_set_foreground(palette[ppu_read(&ppu, x, y)]);
|
rb->lcd_set_foreground(palette[ppu_read(&ppu, x, y)]);
|
||||||
|
rb->lcd_drawpixel(x, y);
|
||||||
|
#else
|
||||||
|
if(palette[ppu_read(&ppu, x, y)]) {
|
||||||
|
rb->lcd_drawpixel(x, y);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
rb->lcd_drawpixel(x, y);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
rb->lcd_update();
|
rb->lcd_update();
|
||||||
ppu.reqdraw = 0;
|
ppu.reqdraw = 0;
|
||||||
|
@ -302,7 +315,7 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
(void)parameter;
|
(void)parameter;
|
||||||
|
|
||||||
DEBUGF("Setting PPU size\n");
|
DEBUGF("Setting PPU size\n");
|
||||||
ppu_set_size(&ppu, LCD_WIDTH, LCD_HEIGHT);
|
ppu_init(&ppu, LCD_WIDTH, LCD_HEIGHT, framebuffer);
|
||||||
DEBUGF("UXN init\n");
|
DEBUGF("UXN init\n");
|
||||||
// Clear RAM and copy rom to VM.
|
// Clear RAM and copy rom to VM.
|
||||||
DEBUGF("zeroing\n");
|
DEBUGF("zeroing\n");
|
||||||
|
@ -329,7 +342,7 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
/* empty */ uxn_port(&u, 0xf, nil_talk);
|
/* empty */ uxn_port(&u, 0xf, nil_talk);
|
||||||
DEBUGF("eval\n");
|
DEBUGF("eval\n");
|
||||||
uxn_eval(&u, 0x0100);
|
uxn_eval(&u, 0x0100);
|
||||||
redraw(&u);
|
redraw();
|
||||||
|
|
||||||
rb->button_get(true);
|
rb->button_get(true);
|
||||||
return PLUGIN_OK;
|
return PLUGIN_OK;
|
||||||
|
|
Loading…
Reference in New Issue