1 // Rolling Thunder hacker #5: more character graphics
3 // I *think* that the ROMs R17-R20 are character graphics data encoded:
5 // BYTE 1: char # (0-255)
6 // BYTE 2: Top 3 bits = charset index (i.e. idx*256)
19 // With C++ string constants, you need to use a double backslash in
20 // order to indicate a single backslash. Confusing? You bet!
21 // [It's called "escaping the escape character."]
23 #define fn1 "rt1-7.rom"
24 #define fn2 "rt1-8.rom"
25 #define fn3 "rt1-5.rom"
26 #define fn4 "rt1-6.rom"
28 // Global shit (shouldn't be, but I can't think of an alternative)
30 fstream ff, ff2, ff3, ff4, ff5; // Creates FSTREAMs without any file hooks
31 char * charset, * cs2, * cs3; // Place holders for our charsets
33 int main(int argc, char *argv[])
35 int idx[8] = { 7, 5, 3, 1, 6, 4, 2, 0 };
36 char pal[768], file[120], scr[2016];
37 unsigned char ch, ch2;
38 int x, y, index = 1, scridx, chrsel = 0;
40 extern bool transparent;
47 strcat(file, argv[1]); strcat(file, ".rom");
48 if (atoi(argv[1]) > 18) file[2] = '3';
52 strcat(file, "17.rom");
55 set_new_handler(0); // Make 'new' return NULL on failure...
56 charset = new char[0xC000]; // charspace
57 if (!charset) cerr << "Could not allocate character RAM!";
58 cs2 = new char[0xC000]; // charspace
59 if (!cs2) cerr << "Could not allocate character RAM!";
60 cs3 = new char[0xC000]; // charspace
61 if (!cs3) cerr << "Could not allocate character RAM!";
63 ff.open(fn1, ios::binary|ios::in); // Open as a binary file
64 if (!ff) { cerr << "Could not open 'ff'"; // Handle any errors...
66 ff2.open(fn2, ios::binary|ios::in); // ditto
67 if (!ff2) { cerr << "Could not open 'ff2'";
69 ff4.open(fn3, ios::binary|ios::in); // Open as a binary file
70 if (!ff) { cerr << "Could not open 'ff'"; // Handle any errors...
72 ff5.open(fn4, ios::binary|ios::in); // ditto
73 if (!ff2) { cerr << "Could not open 'ff2'";
75 ff3.open(file, ios::binary|ios::in); // ditto
76 if (!ff3) { cerr << "Could not open '" << file << "'";
79 for(i=0; i<0xC000; i+=3)
81 ff.get(ch); charset[i] = ch;
82 ff.get(ch); charset[i+1] = ch;
83 ff2.get(ch); charset[i+2] = ch;
85 for(i=0; i<0xC000; i+=3)
87 ff.get(ch); cs2[i] = ch;
88 ff.get(ch); cs2[i+1] = ch;
89 ff2.get(ch); cs2[i+2] = ch;
91 for(i=0; i<0xC000; i+=3)
93 ff4.get(ch); cs3[i] = ch;
94 ff4.get(ch); cs3[i+1] = ch;
95 ff5.get(ch); cs3[i+2] = ch;
98 ff.close(); ff2.close(); ff4.close(); ff5.close(); // Close da filez...
100 // for(i=0; i<0xC000; i++) cout << (unsigned int)charset[i] << " ";
102 SetModeX(); // Set up VGA screen
104 pal[0] = 0x00; pal[1] = 0x00; pal[2] = 0x00; // Black
105 pal[3] = 0x30; pal[4] = 0x00; pal[5] = 0x00; // Darker Red
106 pal[6] = 0x28; pal[7] = 0x00; pal[8] = 0x00; // Darkest Red
107 pal[9] = 0x2f; pal[10] = 0x2f; pal[11] = 0x2F; // Light Grey
108 pal[12] = 0x1F; pal[13] = 0x1f; pal[14] = 0x1f; // Med Grey
109 pal[15] = 0x0F; pal[16] = 0x0f; pal[17] = 0x0f; // Dark Grey
110 pal[18] = 0x3F; pal[19] = 0x30; pal[20] = 0x20; // Peach?
111 pal[21] = 0x20; pal[22] = 0x20; pal[23] = 0x00;
112 pal[24] = 0x08; pal[25] = 0x3f; pal[26] = 0x10;
113 pal[27] = 0x06; pal[28] = 0x06; pal[29] = 0x06; // Dk Dk Dk Grey
114 pal[30] = 0x08; pal[31] = 0x08; pal[32] = 0x10; // Dk Dk Grey
115 pal[33] = 0x00; pal[34] = 0x3f; pal[35] = 0x00;
117 pal[45] = 0x00; pal[46] = 0x00; pal[47] = 0x00;
119 outp(0x03C8, 0); // Tell VGA palette data is coming...
122 outp(0x03C9, pal[i]); // Send it...
125 for(i=0; i<2016; i++) { ff3.get(ch); scr[i] = ch; }
133 for(int q=0; q<4; q++)
135 ch = scr[scridx++]; index = (int)((scr[scridx++] >> 5) & 0x07);
137 PlotChar(x+q, y, ch, idx[index], (unsigned char *)charset);
139 PlotChar(x+q, y, ch, idx[index], (unsigned char *)cs2);
141 PlotChar(x+q, y, ch, idx[index], (unsigned char *)cs3);
146 if (i==27) break; // Break out on ESC
147 if (i==32) { for(i=0; i<2016; i++) { ff3.get(ch); scr[i] = ch; } }
148 if (i=='[') { int temp = idx[0]; for(i=0; i<7; i++) idx[i] = idx[i+1];
150 if (i==']') { chrsel++; if (chrsel==3) chrsel = 0; }
152 SetMode(0x03); // Reset text mode
156 for(i=0; i<2016; i++)
157 { printf("%02X ", (unsigned char)scr[i]);
158 scridx++; if (scridx == 24) {cout << endl; scridx = 0;}
160 delete[] charset; delete[] cs2; delete[] cs3;