-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathromdecodermarc4.cpp
86 lines (64 loc) · 2.14 KB
/
romdecodermarc4.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
#include "romdecodermarc4.h"
#include <stdint.h>
#include <QFile>
/* A MARC4 ROM has 16-bit wide columns. Each row of a column contains two bytes
* interlaced, and there's usually a large sequence of C1,C1 or 1111000000000011.
*
* The column order is not generically known, and some chips such as the T44C080C
* also include a manufacturer test region that is not a part of the normal memory
* map. For now, columns are dumped left to right and it's the user's responsibility
* to correct the page layout.
*/
RomDecoderMarc4::RomDecoderMarc4()
{
}
#define MAXCOLS 32
QByteArray RomDecoderMarc4::getbytes(MaskRomTool *m){
RomBitItem* rowbit = m->markBitTable();
QByteArray cols[MAXCOLS];
QByteArray output;
//Import all the rows into the byte arrays.
while(rowbit){
int bitinrow=0;
int column=0;
RomBitItem* bit=rowbit;
uint8_t bytea=0, byteb=0;
while(bit){
//Bits are interleved, so we grab one of each.
if((bitinrow&1)==0)
bytea=(bytea<<1)|(bit->bitValue()^1);
else
byteb=(byteb<<1)|(bit->bitValue()^1);
bit=bit->nexttoright; //Skip down the row.
bitinrow++;
if(bitinrow%16==0){
//Insert the two bytes into the column.
cols[column].append(bytea);
cols[column].append(byteb);
bytea=byteb=0;
column++;
if(column>=MAXCOLS){
qDebug()<<"No MARC4 ROM should have"<<column<<" columns. What's going on?";
column=0;
}
}
}
rowbit=rowbit->nextrow; //Skip to the next row.
}
for(int i=0; i<MAXCOLS; i++){
for(int j=0; j<cols[i].size(); j++){
output.append(cols[i].at(j));
}
}
return output;
}
//This returns a text preview.
QString RomDecoderMarc4::preview(MaskRomTool *m){
QString ascii="";
return ascii;
}
void RomDecoderMarc4::writeFile(MaskRomTool *m, QString filename){
QFile fout(filename);
fout.open(QIODevice::WriteOnly);
fout.write(getbytes(m));
}