From 01954b1d34a42fa4a51a3e0d690ba4ad5a1f8298 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 13 Mar 2022 18:08:09 +0100 Subject: Moved palette to GameWinDX9 --- Stars45/GameWinDX9.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'Stars45/GameWinDX9.cpp') diff --git a/Stars45/GameWinDX9.cpp b/Stars45/GameWinDX9.cpp index f40be9b..bf7876f 100644 --- a/Stars45/GameWinDX9.cpp +++ b/Stars45/GameWinDX9.cpp @@ -6,6 +6,10 @@ #include "GameWinDX9.h" +#include +#include + +#include "DataLoader.h" #include "Game.h" #include "MachineInfo.h" #include "Panic.h" @@ -192,3 +196,71 @@ GameWinDX9::InitInstance(HINSTANCE hInstance, int nCmdShow) Print(" Instance initialized.\n"); return true; } + + +bool +GameWinDX9::InitGame() +{ + if (server) return true; + if (!SetupPalette()) { + Panic::Panic("Could not set up the palette."); + return false; + } + Print(" Palette laoded\n"); + return Game::InitGame(); +} + + +bool +GameWinDX9::SetupPalette() +{ + if (LoadPalette(standard_palette, inverse_palette)) { + Color::SetPalette(standard_palette, 256, inverse_palette); + return true; + } + + return false; +} + + +bool +GameWinDX9::LoadPalette(PALETTEENTRY* pal, BYTE* inv) +{ + char palheader[32]; + struct { + WORD Version; + WORD NumberOfEntries; + PALETTEENTRY Entries[256]; + } Palette = { 0x300, 256 }; + + DataLoader* loader = DataLoader::GetLoader(); + BYTE* block; + char fname[256]; + sprintf_s(fname, "%s.pal", palette_name); + + if (!loader->LoadBuffer(fname, block)) { + Print(" Could not open file '%s'\n", fname); + return false; + } + + memcpy(&palheader, block, 24); + memcpy((char*) Palette.Entries, (block+24), 256*4); + + for (int i = 0; i < 256; i++) { + *pal++ = Palette.Entries[i]; + } + + loader->ReleaseBuffer(block); + + sprintf_s(fname, "%s.ipl", palette_name); + int size = loader->LoadBuffer(fname, block); + if (size < 32768) { + Print(" Could not open file '%s'\n", fname); + return false; + } + + memcpy(inv, block, 32768); + loader->ReleaseBuffer(block); + + return true; +} -- cgit v1.1