-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAssortedGraphicUtils.h
111 lines (98 loc) · 4.57 KB
/
AssortedGraphicUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef ASSORTEDGRAPHICUTILS_H
#define ASSORTEDGRAPHICUTILS_H
#include <QString>
#include <QColor>
#include <QVector>
#include <QByteArray>
#include "ROMUtils.h"
namespace AssortedGraphicUtils
{
// structs
enum AssortedGraphicTileDataType
{
Tile8x8_4bpp_no_comp_Tileset_text_bg = 0,
Tile8x8_4bpp_no_comp = 1 // user-made graphic for their own use, should not work atm
};
enum AssortedGraphicMappingDataCompressionType
{
No_mapping_data_comp = 0, // reserved for some shit things, and perhaps non-text bg mode, should not work atm
RLE_mappingtype_0x20 = 1 // RLE for mapping Tile8x8 directly
};
/***
* Save the whole struct into the ROM by converting
*
*/
struct AssortedGraphicEntryItem
{
// info params need to saved into the AssortedGraphicListChunk
unsigned int TileDataAddress;
unsigned int TileDataSizeInByte; // unit: Byte
unsigned int TileDataRAMOffsetNum = 0; // unit: per Tile8x8
enum AssortedGraphicTileDataType TileDataType;
QString TileDataName;
unsigned int MappingDataAddress;
unsigned int MappingDataSizeAfterCompressionInByte; // unit: Byte
enum AssortedGraphicMappingDataCompressionType MappingDataCompressType;
QString MappingDataName;
unsigned int PaletteAddress = 0;
unsigned int PaletteNum = 1; // when (optionalPaletteAddress + PaletteNum) > 16, we just discard the latter palettes
unsigned int PaletteRAMOffsetNum = 0; // unit: per palette, 16 color
unsigned int optionalGraphicWidth = 0; // overwrite size params when the mapping data include size info
unsigned int optionalGraphicHeight = 0;
// things not saved in the AssortedGraphicListChunk
QByteArray tileData;
QVector<QRgb> palettes[16];
QVector<unsigned short> mappingData;
AssortedGraphicEntryItem &operator = (const AssortedGraphicEntryItem &entry)
{
this->TileDataAddress = entry.TileDataAddress;
this->TileDataSizeInByte = entry.TileDataSizeInByte;
this->TileDataRAMOffsetNum = entry.TileDataRAMOffsetNum;
this->TileDataType = entry.TileDataType;
this->TileDataName = entry.TileDataName;
this->MappingDataAddress = entry.MappingDataAddress;
this->MappingDataSizeAfterCompressionInByte = entry.MappingDataSizeAfterCompressionInByte;
this->MappingDataCompressType = entry.MappingDataCompressType;
this->MappingDataName = entry.MappingDataName;
this->PaletteAddress = entry.PaletteAddress;
this->PaletteNum = entry.PaletteNum;
this->PaletteRAMOffsetNum = entry.PaletteRAMOffsetNum;
this->optionalGraphicWidth = entry.optionalGraphicWidth;
this->optionalGraphicHeight = entry.optionalGraphicHeight;
this->tileData = entry.tileData;
for(int i = 0; i < 16; i++)
{
this->palettes[i] = entry.palettes[i];
}
this->mappingData = entry.mappingData;
return *this;
}
// used in palette import lambda functions
void SetColor(int paletteId, int colorId, QRgb newcolor) { palettes[paletteId][colorId] = newcolor; }
};
// used for reset AssortedGraphicListChunk only
enum chunkSaveDataType
{
graphicPalette = 0,
graphictiles = 1,
graphicmappingdata = 2
};
struct entry_datatype_chunk
{
unsigned int entryID = 0;
enum chunkSaveDataType datatype = graphicPalette;
unsigned int chunkID = 0;
};
// functions
QVector<struct AssortedGraphicUtils::AssortedGraphicEntryItem> GetAssortedGraphicsFromROM();
void ExtractDataFromEntryInfo_v1(struct AssortedGraphicUtils::AssortedGraphicEntryItem &entry);
QString SaveAssortedGraphicsToROM(QVector<struct AssortedGraphicUtils::AssortedGraphicEntryItem> &entries);
// savechunk relative functions
QVector<unsigned int> GetSaveDataAddresses(AssortedGraphicEntryItem &entry);
QVector<struct ROMUtils::SaveData> CreateSaveData(AssortedGraphicEntryItem &entry, unsigned int entryId);
// helper functions
bool CheckEditability(struct AssortedGraphicUtils::AssortedGraphicEntryItem &entry, unsigned int &find_l, unsigned int &find_r, unsigned int &find_t);
bool FindbgGFXptrInAllTilesets(unsigned int address, unsigned int *tilesetId_find);
bool FindLayerptrInAllRooms(unsigned int address, unsigned int *levelId_found, unsigned int *roomId_found);
};
#endif // ASSORTEDGRAPHICUTILS_H