-
Notifications
You must be signed in to change notification settings - Fork 21
/
romdecodergato.cpp
94 lines (74 loc) · 2.43 KB
/
romdecodergato.cpp
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
#include "romdecodergato.h"
#include "maskromtool.h"
#include "romdecoderascii.h"
#include "gatorom.h"
RomDecoderGato::RomDecoderGato(){}
//Returns a GatoROM structure of the bits.
GatoROM RomDecoderGato::gatorom(MaskRomTool *mrt){
this->mrt=mrt;
RomDecoderAscii exporter;
QString ascii=exporter.preview(mrt);
RomBitItem* firstbit = mrt->markBitTable();
//We'll need to reapply the angle after regenerating the matrix.
int angle=mrt->gr.angle;
//We rebuild from the preserved class
mrt->gr.loadFromString(ascii);
//Reapply the preserved angle before processing.
mrt->gr.rotate(angle,true);
unsigned int row=0, col=0;
RomBitItem* rowbit=firstbit;
//Match them together.
while(rowbit){
RomBitItem* bit=rowbit;
while(bit){
/* Update the input bit to point to the RomBitItem*.
This can be handy in drawing results back to the screen,
but be careful that the pointers don't become stale!
We can't set the address and mask yet because we don't know them.
*/
GatoBit* gb=mrt->gr.inputbit(row,col);
if(!gb){
qDebug()<<"Bailing early from RomDecoderGato::gatorom() as alignment is bad.";
return mrt->gr;
}
gb->ptr=bit;
bit=bit->nexttoright; //Skip down the row.
col++;
}
rowbit=rowbit->nextrow; //Skip to the next row.
col=0;
row++;
}
row=0; col=0;
rowbit=firstbit;
//Set the bits.
mrt->gr.decode();
//Then loop again to set addresses and masks.
while(rowbit){
RomBitItem* bit=rowbit;
while(bit){
//Now we can set the address and mask.
mrt->gr.inputbit(row,col)->ptr=bit;
bit->adr=mrt->gr.inputbit(row,col)->adr;
bit->mask=mrt->gr.inputbit(row,col)->mask;
bit=bit->nexttoright; //Skip down the row.
col++;
}
rowbit=rowbit->nextrow; //Skip to the next row.
col=0;
row++;
}
return mrt->gr;
}
//This returns a text preview.
QString RomDecoderGato::preview(MaskRomTool *m){
return "";
}
//Exports the preview to a file.
void RomDecoderGato::writeFile(MaskRomTool *m, QString filename){
GatoROM gr=gatorom(m);
QByteArray bytes=gr.decode();
QFile fout(filename);
fout.open(QIODevice::WriteOnly);
fout.write(bytes);
}