-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQDKEdit.h
297 lines (258 loc) · 6.13 KB
/
QDKEdit.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#ifndef QDKEDIT_H
#define QDKEDIT_H
#include "QTileEdit.h"
#include <QtCore/QFile>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtGui/QPainter>
//find rombanks containing the level data
#define ROMBANK_1 0x05
#define COMPARE_POS_1 0x25FC // < 0x2D
#define ROMBANK_POS_2 0x25FF // 0x06
#define COMPARE_POS_2 0x2603 // < 0x50
#define ROMBANK_POS_3 0x2606 // 0x12
// some constants
#define MAX_LEVEL_ID 256
#define LAST_LEVEL 105
#define MAX_TILESETS 0x22
#define MAX_SPRITES 0x1B
#define POINTER_TABLE 0x14000
#define SUBTILESET_TABLE 0x30EEB
#define SGB_SYSTEM_PAL 0x786F0 // decompressed size 0x1000
// the SGB packet is always 51.(quint16)var+0x80.E4 00.E5.00.E6 00.C1.00.00 00.00.00.00
// asm @ 0x0E70
#define PAL_ARCADE 0x30F9A
// the palette for the 4 arcade levels are @ 0x4F9A (bank 0x0C) + (6*id)
// this value is palette index + 0xC8
// not freely editable!
#define PAL_TABLE 0x6093B
// PAL_TABLE + (id-4)*8
// palettes for all other levels
// BGP depends on tileset asm @ 0E9D
#define TILE_INDEX_TABLE 0x60E5
#define ADDITIONAL_TILES_TABLE 0x30E55
#define VRAM_TILES 0x50
#define VRAM_SPRITES 0x100
#define ELEVATOR_TABLE 0x30F77
class QMouseEvent;
struct QDKSprite : QSprite
{
quint16 ramPos;
quint32 levelPos;
// quint8 addFlag;
};
struct QDKSwitchObject
{
quint8 x, y;
quint16 ramPos;
quint32 levelPos;
bool isSprite;
};
struct QDKSwitch
{
quint8 state;
quint8 x, y;
quint32 levelPos;
quint16 ramPos;
QList<QDKSwitchObject> connectedTo;
};
typedef QColor QGBPalette[4];
struct QDKLevel
{
quint8 id; // max 256 !
quint8 rombank;
quint32 offset;
quint8 size; // 0x00 -> 0x240 bytes for tilemap else 0x380 bytes
quint8 music;
quint8 tileset;
quint16 time;
bool switchData;
bool addSpriteData;
bool fullDataUpToDate;
QByteArray rawTilemap;
QByteArray displayTilemap;
quint16 paletteIndex;
QList<QDKSprite> sprites;
QList<QDKSwitch> switches;
QByteArray rawSwitchData; // 0x11 + 0x90 bytes
QByteArray rawAddSpriteData; // 0x40 bytes
QByteArray fullData;
};
struct QTileInfo
{
quint8 w, h;
quint8 type; // that's a bit vague - this is the pointer+N value
quint8 count;
quint8 fullCount;
quint8 setSpecific;
quint16 additionalTilesAt;
quint32 romOffset;
QList<int> needsTiles;
quint8 projectileTileCount;
bool compressed;
};
class QDKEdit : public QTileEdit
{
Q_OBJECT
public:
explicit QDKEdit(QWidget *parent = 0);
~QDKEdit();
bool loadAllLevels(QString romFile);
bool saveAllLevels(QString romFile);
bool exportCurrentLevel(QString filename);
bool importLevel(QString filename);
QString getLevelInfo();
void fillSpriteNames();
void fillTileNames();
void setupTileSelector(QTileSelector *tileSelector, float scale, int limitTileCount);
private:
void paintLevel(QPainter *painter);
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
QByteArray LZSSDecompress(QDataStream *in, quint16 decompressedSize);
QByteArray LZSSCompress(QByteArray *src);
bool readLevel(QFile *src, quint8 id, bool fromLvlFile = false);
bool readSGBPalettes(QFile *src);
bool recompressLevel(quint8 id);
bool expandRawTilemap(quint8 id);
bool updateRawTilemap(quint8 id);
void copyTileToSet(QFile *src, quint32 offset, QImage *img, quint16 tileID, quint8 tileSetID, bool compressed, quint8 tileCount, quint16 superOffset);
bool getTileInfo(QFile *src);
bool createTileSets(QFile *src, QGBPalette palette);
bool createSprites(QFile *src, QGBPalette palette);
void sortSprite(QImage *sprite, int id);
void copyTile(QImage *img, int x1, int y1, int x2, int y2, bool mirror);
void fillTile(QImage *img, int x, int y, int index);
void swapTiles(QImage *img, int x1, int y1, int x2, int y2);
QMap<QString, QPixmap *> spritePix;
QMap<QString, QImage *> spriteImg;
void updateTileset();
quint8 getSpriteDefaultFlag(int id);
void rebuildAddSpriteData(int id);
void rebuildSwitchData(int id);
quint16 vramTiles;
quint16 vramSprites;
QDKLevel levels[MAX_LEVEL_ID];
QImage tilesets[MAX_TILESETS];
quint8 tilesetBGP[MAX_TILESETS];
QTileInfo tiles[256];
QGBPalette sgbPal[512];
int currentLevel;
quint8 currentSize; // 0x00 -> 0x240 bytes for tilemap else 0x380 bytes
quint8 currentMusic;
quint8 currentTileset;
quint16 currentTime;
quint16 currentPalIndex;
bool switchMode;
int switchToEdit;
int swObjToMove;
QList<QDKSwitch> currentSwitches;
QStack<QList<QDKSwitch> > undoSwitches;
bool romLoaded;
bool transparentSprites;
static bool isSprite[256];
signals:
void paletteChanged(int palette);
void tilesetChanged(int set);
void timeChanged(int time);
void musicChanged(int music);
void sizeChanged(int size);
void switchAdded(QDKSwitch *sw);
void switchRemoved(int i);
void switchUpdated(int i, QDKSwitch *sw);
void tilesVRAMchanged(int used);
void spriteVRAMchanged(int used);
private slots:
void checkForLargeTile(int x, int y, int drawnTile);
void updateSprite(int num);
void undo();
void createUndoData();
void clearUndoData();
void deleteLastUndo();
bool calcVRAMusageOld();
bool calcVRAMusage();
public slots:
void changeLevel(int id);
void saveLevel();
void changeTime(int time);
void changePalette(int palette);
void changeTileset(int tileset);
void changeMusic(int music);
void changeSize(int size);
void changeSpriteTransparency(bool transparent);
void addSprite(int id);
void clearLevel();
void toggleSwitchMode(bool enabled);
void toggleSwitchMode(int enabled);
void selectSwitch(int num);
void deleteSwitchObj(int num);
void deleteCurrentSwitch();
QPixmap *getTilePixmap(int num);
};
#endif // QDKEDIT_H
/* sprite tiles:
3a
44
47
48
4d
4e
4f
50
54
57
58
5a
5c
5e
64
6e
7a
7c
7f
80
84
86
88
8a
8e
90
92
94
96
98
9a
9d
a2
a4
a6
a8
aa
ac
ae
b0
b6
b8
ba
be
c0
c2
c6
c8
ca
cc
from add sprite data:
54
5C
5E
6E
70 <-- new; but elevator "tiles"
72 <-- new; but elevator "tiles"
7F
80
84
98
9A
B8
CC
*/