mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-14 10:09:29 +03:00
Refactor CG loaders
Now they return a newly introduced CG object instead of writing directly to VRAM. The palette is still written directly in the load functions.
This commit is contained in:
+28
-37
@@ -7,7 +7,7 @@
|
||||
#include "ags.h"
|
||||
#include <string.h>
|
||||
|
||||
void AGS::load_gm3(const std::vector<uint8_t>& data, int transparent)
|
||||
CG AGS::load_gm3(const std::vector<uint8_t>& data, int transparent)
|
||||
{
|
||||
// ヘッダ取得
|
||||
uint16 tmp = (data[0x30] | (data[0x31] << 8)) - 0x8000;
|
||||
@@ -30,6 +30,10 @@ void AGS::load_gm3(const std::vector<uint8_t>& data, int transparent)
|
||||
}
|
||||
|
||||
// GM3展開
|
||||
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, width * 8, height * 2, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
if (transparent >= 0) {
|
||||
SDL_SetColorKey(surface, SDL_TRUE, transparent | base);
|
||||
}
|
||||
uint8 cgdata[3][80][3];
|
||||
int p = 0x36;
|
||||
memset(cgdata, 0, sizeof(cgdata));
|
||||
@@ -89,46 +93,33 @@ void AGS::load_gm3(const std::vector<uint8_t>& data, int transparent)
|
||||
}
|
||||
}
|
||||
|
||||
// VRAMに転送
|
||||
if(extract_cg) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int pl = 0; pl < 3; pl++) {
|
||||
cgdata[pl][x][2] = cgdata[pl][x][1];
|
||||
cgdata[pl][x][1] = cgdata[pl][x][0];
|
||||
}
|
||||
uint8 b0, b1, b2, c[8];
|
||||
b0 = cgdata[0][x][0];
|
||||
b1 = cgdata[1][x][0];
|
||||
b2 = cgdata[2][x][0];
|
||||
c[0] = ((b0 >> 7) & 1) | ((b1 >> 6) & 2) | ((b2 >> 5) & 4);
|
||||
c[1] = ((b0 >> 6) & 1) | ((b1 >> 5) & 2) | ((b2 >> 4) & 4);
|
||||
c[2] = ((b0 >> 5) & 1) | ((b1 >> 4) & 2) | ((b2 >> 3) & 4);
|
||||
c[3] = ((b0 >> 4) & 1) | ((b1 >> 3) & 2) | ((b2 >> 2) & 4);
|
||||
c[4] = ((b0 >> 3) & 1) | ((b1 >> 2) & 2) | ((b2 >> 1) & 4);
|
||||
c[5] = ((b0 >> 2) & 1) | ((b1 >> 1) & 2) | ((b2 ) & 4);
|
||||
c[6] = ((b0 >> 1) & 1) | ((b1 ) & 2) | ((b2 << 1) & 4);
|
||||
c[7] = ((b0 ) & 1) | ((b1 << 1) & 2) | ((b2 << 2) & 4);
|
||||
// Transfer to the surface
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int pl = 0; pl < 3; pl++) {
|
||||
cgdata[pl][x][2] = cgdata[pl][x][1];
|
||||
cgdata[pl][x][1] = cgdata[pl][x][0];
|
||||
}
|
||||
uint8 b0, b1, b2, c[8];
|
||||
b0 = cgdata[0][x][0];
|
||||
b1 = cgdata[1][x][0];
|
||||
b2 = cgdata[2][x][0];
|
||||
c[0] = ((b0 >> 7) & 1) | ((b1 >> 6) & 2) | ((b2 >> 5) & 4);
|
||||
c[1] = ((b0 >> 6) & 1) | ((b1 >> 5) & 2) | ((b2 >> 4) & 4);
|
||||
c[2] = ((b0 >> 5) & 1) | ((b1 >> 4) & 2) | ((b2 >> 3) & 4);
|
||||
c[3] = ((b0 >> 4) & 1) | ((b1 >> 3) & 2) | ((b2 >> 2) & 4);
|
||||
c[4] = ((b0 >> 3) & 1) | ((b1 >> 2) & 2) | ((b2 >> 1) & 4);
|
||||
c[5] = ((b0 >> 2) & 1) | ((b1 >> 1) & 2) | ((b2 ) & 4);
|
||||
c[6] = ((b0 >> 1) & 1) | ((b1 ) & 2) | ((b2 << 1) & 4);
|
||||
c[7] = ((b0 ) & 1) | ((b1 << 1) & 2) | ((b2 << 2) & 4);
|
||||
|
||||
uint8_t* dest0 = &vram[dest_screen][(y + sy) * 2 + 0][(x + sx) * 8];
|
||||
uint8_t* dest1 = &vram[dest_screen][(y + sy) * 2 + 1][(x + sx) * 8];
|
||||
if(transparent == -1) {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
dest0[i] = dest1[i] = c[i] | base;
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
if(c[i] != transparent) {
|
||||
dest0[i] = dest1[i] = c[i] | base;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint8_t* dest0 = surface_line(surface, y * 2) + x * 8;
|
||||
uint8_t* dest1 = dest0 + surface->pitch;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
dest0[i] = dest1[i] = c[i] | base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 画面更新
|
||||
if(dest_screen == 0 && extract_cg) {
|
||||
draw_screen(sx * 8, sy * 2, width * 8, height * 2);
|
||||
}
|
||||
return CG(surface, sx * 8, sy * 2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user