This commit is contained in:
Nico 2021-11-07 19:14:52 +00:00
parent ee32942ebb
commit 2ca7b61c84
1 changed files with 34 additions and 10 deletions

View File

@ -306,6 +306,9 @@ unsigned int palette[3];
static Uint8 framebuffer[LCD_HEIGHT * LCD_WIDTH * 4];
static fb_data *lcd_fb = NULL;
static unsigned long starttick;
static void
memzero8(void *src, uint64_t n)
{
@ -443,18 +446,35 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
return 1;
}
// TODO mono, greyscale
// TODO mono and greyscale that don't suck
static void redraw(void)
{
if (!lcd_fb)
{
struct viewport *vp_main = rb->lcd_set_viewport(NULL);
lcd_fb = vp_main->buffer->fb_ptr;
}
for(int y = 0 ; y < LCD_WIDTH*LCD_HEIGHT; y++ ) {
lcd_fb[y] = palette[ppu_read(&ppu, y%LCD_WIDTH, y/LCD_HEIGHT)];
}
rb->lcd_update();
#if LCD_DEPTH > 4
if (!lcd_fb)
{
struct viewport *vp_main = rb->lcd_set_viewport(NULL);
lcd_fb = vp_main->buffer->fb_ptr;
}
for(int i = 0 ; i < LCD_WIDTH*LCD_HEIGHT; i++ ) {
Uint32 row = i / 2;
Uint8 shift = !(i & 0x1) << 2;
Uint8 pix = framebuffer[row] >> shift;
if(pix & 0x0c)
pix = pix >> 2;
lcd_fb[i] = palette[pix & 0x3];
}
rb->lcd_update();
#else
rb->lcd_clear_display();
for(Uint16 x = 0; x < LCD_WIDTH; x++ ) {
for(Uint16 y = 0; y < LCD_HEIGHT; y++ ) {
if(palette[ppu_read(&ppu, x, y)]) {
rb->lcd_drawpixel(x, y);
}
}
}
rb->lcd_update();
#endif
ppu.reqdraw = 0;
}
@ -468,6 +488,7 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
// TODO fix timing
static void run() {
starttick = *rb->current_tick;
while(!devsystem->dat[0xf]) {
uxn_eval(&u, devscreen->vector);
if(ppu.reqdraw || devsystem->dat[0xe])
@ -513,6 +534,9 @@ static void run() {
uxn_eval(&u, peek16(devctrl->dat, 0));
}
if((*rb->current_tick - starttick)<HZ/60) {
rb->sleep(*rb->current_tick - starttick);
}
}
}