From 11a366005f71b2ff9fe91012b20de0a3b8418554 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Fri, 17 Jan 2025 15:02:54 +0900 Subject: [PATCH] AGS: Refactor VRAM accessors --- src/sys/ags.cpp | 20 +------------------- src/sys/ags.h | 12 ++++++------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index fa8a1e1..aae434a 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -80,14 +80,7 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty( // DIBSection 8bpp * 3 (表, 裏, メニュー) for(int i = 0; i < 3; i++) { hBmpScreen[i] = SDL_CreateRGBSurfaceWithFormat(0, 640, 480, 8, SDL_PIXELFORMAT_INDEX8); - - // TODO: clear surface - // memset(lpBmpScreen[i], 0, 640 * 480 * sizeof(DWORD)); - - // 仮想VRAMへのポインタ取得 - for(int j = 0; j < 480; j++) { - vram[i][j] = (uint8_t*)hBmpScreen[i]->pixels + hBmpScreen[i]->pitch * j; - } + vram[i] = reinterpret_cast(hBmpScreen[i]->pixels); } // All surfaces share the same palette. @@ -97,7 +90,6 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty( // DIBSection 24bpp * 1 (最終出力先) display_surface = hBmpDest = SDL_CreateRGBSurface(0, 640, 480, 32, 0, 0, 0, 0); - // TODO: clear surface // フォント TTF_Init(); @@ -464,16 +456,6 @@ std::vector AGS::get_screen_palette() const return palette; } -uint8 AGS::get_pixel(int dest, int x, int y) -{ - return vram[dest][y][x]; -} - -void AGS::set_pixel(int dest, int x, int y, uint8 color) -{ - vram[dest][y][x] = color; -} - void AGS::fade_out(int duration_ms, bool white) { if (fade_level) diff --git a/src/sys/ags.h b/src/sys/ags.h index 025c017..7dc049a 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -35,6 +35,10 @@ private: // Surface SDL_Surface* hBmpScreen[3]; // 8bpp * 3 (表, 裏, メニュー) SDL_Surface* hBmpDest; // DIBSection 24bpp (最終出力先) + uint8_t (*vram[3])[640]; // convenience pointer to hBmpScreen[i]->pixels + + SDL_Palette* program_palette; + SDL_Palette* screen_palette; // フォント SDL_RWops* rw_font; @@ -67,10 +71,6 @@ private: uint8_t palB(uint8_t col) const { return screen_palette->colors[col].b; } int nearest_color(int r, int g, int b); - uint8_t* vram[3][480]; // 仮想VRAMへのポインタ - - SDL_Palette* program_palette; - SDL_Palette* screen_palette; uint8 gaiji[188][32]; int fade_level = 0; // 0-255 @@ -89,8 +89,8 @@ public: void set_palette(int index, uint8_t r, uint8_t g, uint8_t b); std::vector get_screen_palette() const; - uint8 get_pixel(int dest, int x, int y); - void set_pixel(int dest, int x, int y, uint8 color); + uint8 get_pixel(int dest, int x, int y) const { return vram[dest][y][x]; } + void set_pixel(int dest, int x, int y, uint8 color) { vram[dest][y][x] = color; } void fade_out(int duration_ms, bool white); void fade_in(int duration_ms);