From 9727add223e10ba1f48779d5630ff9f92514520b Mon Sep 17 00:00:00 2001 From: David Kuder Date: Tue, 25 Apr 2023 16:19:28 -0400 Subject: [PATCH] AGS performace tweaks and bugfixes Bypass legacy 80 column card when in SHR rendering mode Mask unused palette bits that were causing VGA PIO to fail Fixed color calculation for AGS hardware --- vga/render.h | 7 ++++--- vga/render_shr.c | 4 ++-- vga/vgaout.c | 18 ++++++++++++++++++ vga/vgaout.h | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/vga/render.h b/vga/render.h index b5f45ac..a33c7c4 100644 --- a/vga/render.h +++ b/vga/render.h @@ -8,6 +8,7 @@ extern uint16_t lores_palette[16]; extern uint16_t text_fore, text_back, text_border; extern uint8_t status_line[81]; +extern bool mono_rendering; extern void terminal_clear_screen(); @@ -53,9 +54,9 @@ extern void vga_deinit(); #ifdef ANALOG_GS #define _RGB(r, g, b) ( \ - (((((uint)(r) * 256 / 18) + 256) / 256) << 8) | \ - (((((uint)(g) * 256 / 18) + 256) / 256) << 4) | \ - ((((uint)(b) * 256 / 18) + 256) / 256) \ + (((((uint)(r) * 256 / 18) + 255) / 256) << 8) | \ + (((((uint)(g) * 256 / 18) + 255) / 256) << 4) | \ + ((((uint)(b) * 256 / 18) + 255) / 256) \ ) #define _RGBHALF 0x777 #else diff --git a/vga/render_shr.c b/vga/render_shr.c index 0cf3141..586e19f 100644 --- a/vga/render_shr.c +++ b/vga/render_shr.c @@ -9,7 +9,7 @@ static void render_shr_line(uint16_t line); #ifdef ANALOG_GS -#define rgb444(a) (a) +#define rgb444(a) (a & 0xFFF) #else static inline uint16_t rgb444(uint16_t a) { return ((a & 0xe00) >> 3) | ((a & 0xe0) >> 2) | ((a & 0xe) >> 1); @@ -27,7 +27,7 @@ void DELAYED_COPY_CODE(render_shr)() { } static void DELAYED_COPY_CODE(render_shr_line)(uint16_t line) { - struct vga_scanline *sl = vga_prepare_scanline(); + struct vga_scanline *sl = vga_prepare_scanline_quick(); uint sl_pos = 0; uint i; diff --git a/vga/vgaout.c b/vga/vgaout.c index 5649a9b..bbc4b14 100644 --- a/vga/vgaout.c +++ b/vga/vgaout.c @@ -249,6 +249,24 @@ struct vga_scanline * DELAYED_COPY_CODE(vga_prepare_scanline)() { return scanline; } +// Set up and return a new display scanline +struct vga_scanline * DELAYED_COPY_CODE(vga_prepare_scanline_quick)() { + struct vga_scanline *scanline = &scanline_queue[scanline_queue_head]; + + // Wait for the scanline buffer to become available again + while(scanline->_flags & FLAG_BUSY) + tight_loop_contents(); + + // Reinitialize the scanline struct for reuse + scanline->length = 0; + scanline->repeat_count = 0; + scanline->_flags = FLAG_BUSY; + scanline->_sync = (uint32_t)THEN_WAIT_HSYNC << 16; + + scanline_queue_head = (scanline_queue_head + 1) & (NUM_SCANLINE_BUFFERS-1); + + return scanline; +} // Mark the scanline as ready so it can be displayed void DELAYED_COPY_CODE(vga_submit_scanline)(struct vga_scanline *scanline) { spin_lock_t *lock = spin_lock_instance(CONFIG_VGA_SPINLOCK_ID); diff --git a/vga/vgaout.h b/vga/vgaout.h index 1410837..47f5b69 100644 --- a/vga/vgaout.h +++ b/vga/vgaout.h @@ -43,6 +43,7 @@ struct vga_scanline { extern void vga_prepare_frame(); extern struct vga_scanline *vga_prepare_scanline(); +extern struct vga_scanline *vga_prepare_scanline_quick(); extern void vga_submit_scanline(struct vga_scanline *scanline); extern void vga_stop();