Cleanup format of GbaImageData
This commit is contained in:
		| @@ -4,8 +4,8 @@ set -e | ||||
|  | ||||
| echo NOSTALGIA_MEDIA_HEADER_________ > media_header.txt | ||||
|  | ||||
| oxfs format 32 1m nostalgia_media.oxfs | ||||
| ./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 101 -tiles 40 -bpp 4 -c | ||||
| ./build/current/deps/ox/src/ox/fs/oxfs format 32 1k nostalgia_media.oxfs | ||||
| ./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 101 -tiles 40 -c | ||||
|  | ||||
| ${DEVKITARM}/bin/padbin 32 build/gba-release/src/player/nostalgia.bin | ||||
| cat build/gba-release/src/player/nostalgia.bin media_header.txt nostalgia_media.oxfs > nostalgia.gba | ||||
|   | ||||
| @@ -17,14 +17,18 @@ typedef struct { uint32_t data[8]; } __attribute__((aligned(4))) Tile, Tile4; | ||||
| // d-tile: double-sized tile (8bpp) | ||||
| typedef struct { uint32_t data[16]; }  __attribute__((aligned(4))) Tile8; | ||||
| // tile block: 32x16 tiles, 16x16 d-tiles | ||||
| typedef uint16_t Pallete[256]; | ||||
| typedef uint16_t Palette[256]; | ||||
| typedef Tile  CharBlock[512]; | ||||
| typedef Tile8 CharBlock8[256]; | ||||
|  | ||||
| struct __attribute__((packed)) GbaImageData { | ||||
| 	Pallete pal; | ||||
| 	uint16_t tileCount; | ||||
| struct __attribute__((packed)) GbaImageDataHeader { | ||||
| 	uint8_t bpp; | ||||
| 	uint16_t tileCount; | ||||
| }; | ||||
|  | ||||
| struct __attribute__((packed)) GbaImageData { | ||||
| 	GbaImageDataHeader header; | ||||
| 	Palette __attribute__((packed)) pal; | ||||
| 	uint8_t tiles[1]; | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -130,18 +130,23 @@ ox::Error initGfx() { | ||||
| void initConsole() { | ||||
| 	auto fs = (FileStore32*) findMedia(); | ||||
|  | ||||
| 	GbaImageData imgData; | ||||
| 	fs->read(101, __builtin_offsetof(GbaImageData, tileCount), | ||||
| 	         sizeof(imgData.tileCount) + sizeof(imgData.bpp), | ||||
| 	         &imgData.tileCount, nullptr); | ||||
| 	GbaImageDataHeader imgData; | ||||
| 	fs->read(101, 0, sizeof(imgData), &imgData, nullptr); | ||||
|  | ||||
| 	REG_BG0CNT = (28 << 8) | 1; | ||||
| 	if (imgData.bpp == 8) { | ||||
| 		REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel | ||||
| 	} | ||||
| 	if (fs) { | ||||
| 		fs->read(101, __builtin_offsetof(GbaImageData, tiles), 64 * 38, &TILE8_ADDR[0][1], nullptr); | ||||
| 		fs->read(101, __builtin_offsetof(GbaImageData, pal), 512, &MEM_PALLETE_BG[0], nullptr); | ||||
| 		// load palette | ||||
| 		fs->read(101, sizeof(GbaImageDataHeader), | ||||
| 					512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr); | ||||
|  | ||||
| 		if (imgData.bpp == 4) { | ||||
| 			fs->read(101, __builtin_offsetof(GbaImageData, tiles), | ||||
| 			         sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr); | ||||
| 		} else { | ||||
| 			REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel | ||||
| 			fs->read(101, __builtin_offsetof(GbaImageData, tiles), | ||||
| 			         sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -81,8 +81,8 @@ int run(ClArgs args) { | ||||
| 		uint8_t imgDataBuff[imgDataBuffSize]; | ||||
| 		memset(&imgDataBuff, 0, imgDataBuffSize); | ||||
| 		GbaImageData *id = (GbaImageData*) imgDataBuff; | ||||
| 		id->bpp = argBpp; | ||||
| 		id->tileCount = argTiles; | ||||
| 		id->header.bpp = argBpp; | ||||
| 		id->header.tileCount = argTiles; | ||||
| 		int colorId = 0; | ||||
|  | ||||
| 		// copy pixels as color ids | ||||
|   | ||||
		Reference in New Issue
	
	Block a user