From d22c1e6db371d191fbf5edc2a2499535101f5925 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Tue, 21 Feb 2023 22:48:56 +0100 Subject: [PATCH] [Platform] [PC-98] Hardware palette setters Optimally, these are called *at most* once per frame. No need to micro-optimize here. Part of P0232, funded by [Anonymous]. --- Makefile.mak | 2 +- Pipeline/grzview.cpp | 13 ++----------- platform/x86real/pc98/palette.cpp | 20 ++++++++++++++++++++ platform/x86real/pc98/palette.hpp | 8 ++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 platform/x86real/pc98/palette.cpp create mode 100644 platform/x86real/pc98/palette.hpp diff --git a/Makefile.mak b/Makefile.mak index 2bb7c663..19220007 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -56,7 +56,7 @@ th05:: $(TH05:\=bin\th05\) .obj.com: tlink /t /3 $** -bin\Pipeline\grzview.com: Pipeline\grzview.cpp th01\formats\grz.cpp bin\th01\f_imgd.obj +bin\Pipeline\grzview.com: Pipeline\grzview.cpp th01\formats\grz.cpp bin\th01\f_imgd.obj platform\x86real\pc98\palette.cpp $(CC) $(CFLAGS) -Z -DGAME=1 -mt -lt -nbin\Pipeline\ @&&| $** | masters.lib diff --git a/Pipeline/grzview.cpp b/Pipeline/grzview.cpp index ea75c7f4..c4638aa3 100644 --- a/Pipeline/grzview.cpp +++ b/Pipeline/grzview.cpp @@ -5,6 +5,7 @@ #include "pc98.h" #include "planar.h" #include "master.hpp" +#include "platform/x86real/pc98/palette.hpp" #include "th01/formats/grz.h" void grcg_setcolor_rmw(int col) @@ -17,16 +18,6 @@ void grcg_off_func(void) grcg_off(); } -void z_palette_set_all_show(const Palette4& pal) -{ - for(int i = 0; i < COLOR_COUNT; i++) { - outportb(0xA8, i); - outportb(0xAA, pal[i].c.g); - outportb(0xAC, pal[i].c.r); - outportb(0xAE, pal[i].c.b); - } -} - const Palette4 boss8_grz_pal = { 0x0, 0x0, 0x0, 0x5, 0x5, 0x5, @@ -71,7 +62,7 @@ int main(int argc, const char **argv) } text_hide(); graph_start(); - z_palette_set_all_show(boss8_grz_pal); + palette_show(boss8_grz_pal); grx_put(0); dos_getch(); diff --git a/platform/x86real/pc98/palette.cpp b/platform/x86real/pc98/palette.cpp new file mode 100644 index 00000000..94bc1b1c --- /dev/null +++ b/platform/x86real/pc98/palette.cpp @@ -0,0 +1,20 @@ +#include "platform.h" +#include "pc98.h" +#include "x86real.h" +#include "platform/x86real/pc98/palette.hpp" + +void palette_show_single(uint4_t col, const RGB4& c) +{ + outportb(0xA8, col); + outportb(0xAA, c.c.g); + outportb(0xAC, c.c.r); + outportb(0xAE, c.c.b); +} + +void palette_show(const Palette4& pal) +{ + const RGB4* color = pal.colors; + for(int i = 0; i < COLOR_COUNT; i++) { + palette_show_single(i, *(color++)); + } +} diff --git a/platform/x86real/pc98/palette.hpp b/platform/x86real/pc98/palette.hpp new file mode 100644 index 00000000..c5a334d4 --- /dev/null +++ b/platform/x86real/pc98/palette.hpp @@ -0,0 +1,8 @@ +// 16-color VRAM palette +// --------------------- + +// Sets the given hardware [col] to the given RGB value. +void palette_show_single(uint4_t col, const RGB4& c); + +// Calls palette_show_single() for all colors in [pal]. +void palette_show(const Palette4& pal);