]> Shamusworld >> Repos - thunder/blob - test/rthack3.cpp
Fixes to makefile, file permissions.
[thunder] / test / rthack3.cpp
1 // Rolling Thunder hacker #3: Title graphics
2 //
3
4 #include <fstream.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <iomanip.h>
8 #include <stdio.h>
9 #include <conio.h>
10 #include <dos.h>
11 #include "screen.h"
12
13 // With C++ string constants, you need to use a double backslash in
14 // order to indicate a single backslash.  Confusing?  You bet!
15 // [It's called "escaping the escape character."]
16
17 #define fn1 "c:\\games\\romhac~1\\r5"
18 #define fn2 "c:\\games\\romhac~1\\r6"
19
20 // Global constants
21
22 char far *screen = (char far *) MK_FP(0xA000,0);
23
24 int scx[128] = {
25    0,  1,  2,  3,  4,  5,  6,  7,
26    0,  1,  2,  3,  4,  5,  6,  7,
27    8,  9, 10, 11, 12, 13, 14, 15,
28    8,  9, 10, 11, 12, 13, 14, 15,
29   16, 17,  0,  1, 16, 17,  0,  1,
30   16, 17,  0,  1, 16, 17,  0,  1,
31   16, 17,  0,  1, 16, 17,  0,  1,
32   16, 17,  0,  1, 16, 17,  0,  1,
33    2,  3,  4,  5,  6,  7,  8,  9,
34    2,  3,  4,  5,  6,  7,  8,  9,
35   10, 11, 12, 13, 14, 15, 16, 17,
36   10, 11, 12, 13, 14, 15, 16, 17,
37    0,  1,  2,  3,  4,  5,  6,  7,
38    0,  1,  2,  3,  4,  5,  6,  7,
39    8,  9, 10, 11, 12, 13, 14, 15,
40    8,  9, 10, 11, 12, 13, 14, 15}, scy[128] = {
41
42    0,  0,  0,  0,  0,  0,  0,  0,
43    1,  1,  1,  1,  1,  1,  1,  1,
44    0,  0,  0,  0,  0,  0,  0,  0,
45    1,  1,  1,  1,  1,  1,  1,  1,
46    0,  0,  2,  2,  2,  2,  4,  4,
47    1,  1,  3,  3,  3,  3,  5,  5,
48    4,  4,  6,  6,  6,  6,  8,  8,
49    5,  5,  7,  7,  7,  7,  9,  9,
50    8,  8,  8,  8,  8,  8,  8,  8,
51    9,  9,  9,  9,  9,  9,  9,  9,
52    8,  8,  8,  8,  8,  8,  8,  8,
53    9,  9,  9,  9,  9,  9,  9,  9,
54   10, 10, 10, 10, 10, 10, 10, 10,
55   11, 11, 11, 11, 11, 11, 11, 11,
56   10, 10, 10, 10, 10, 10, 10, 10,
57   11, 11, 11, 11, 11, 11, 11, 11};
58     
59 // Plot point on the screen
60
61 void plot(int x, int y, int c)
62 {
63   screen[x + y*320] = c;
64 }
65
66 // Decode the color info from three bytes @ xx, yy
67
68 void decode(int b1, int b2, int b3, int xx, int yy)
69 {
70   int cc = ((b1 & 0x80) >> 5) | ((b1 & 0x08) >> 2) | ((b3 & 0x80) >> 7);
71   plot(xx, yy, cc);
72   cc = ((b1 & 0x40) >> 4) | ((b1 & 0x04) >> 1) | ((b3 & 0x40) >> 6);
73   plot(xx+1, yy, cc);
74   cc = ((b1 & 0x20) >> 3) | (b1 & 0x02) | ((b3 & 0x20) >> 5);
75   plot(xx+2, yy, cc);
76   cc = ((b1 & 0x10) >> 2) | ((b1 & 0x01) << 1) | ((b3 & 0x10) >> 4);
77   plot(xx+3, yy, cc);
78   cc = ((b2 & 0x80) >> 5) | ((b2 & 0x08) >> 2) | ((b3 & 0x08) >> 3);
79   plot(xx+4, yy, cc);
80   cc = ((b2 & 0x40) >> 4) | ((b2 & 0x04) >> 1) | ((b3 & 0x04) >> 2);
81   plot(xx+5, yy, cc);
82   cc = ((b2 & 0x20) >> 3) | (b2 & 0x02) | ((b3 & 0x02) >> 1);
83   plot(xx+6, yy, cc);
84   cc = ((b2 & 0x10) >> 2) | ((b2 & 0x01) << 1) | (b3 & 0x01);
85   plot(xx+7, yy, cc);
86 }
87
88 void main(void)
89 {
90   char pal[768] = {0,  0,  0,   41,  0,  0,    0, 50,  0,   46, 46, 46,
91                    0, 63, 63,   24, 24, 24,   31, 31,  0,   31, 31, 31};
92   unsigned char ch;
93   int i, j, x, y;
94   ifstream ff, ff2;       // Creates an IFSTREAM but without any file hooks
95
96   ff.open(fn1, ios::binary);   // Open as a binary file
97   ff2.open(fn2, ios::binary);  // ditto
98
99   ff.ignore(8*8*32*2);  ff2.ignore(8*8*32);
100
101   if (!ff) cerr << "Could not open 'ff'";
102   if (!ff2) cerr << "Could not open 'ff2'";
103
104   setmode(0x13);    // Set up VGA screen
105
106   setpalette(pal);  // Set the pallete
107
108   while (!kbhit())
109   {
110     for(int in=0; in<128; in++)
111     {
112       i = scx[in];  j = scy[in];
113
114         x = i * 16;  y = j * 16;
115         for(int a=0; a<8; a++)
116         {
117           ff.get(ch);   int b1 = (int)ch;
118           ff.get(ch);   int b2 = (int)ch;
119           ff2.get(ch);  int b3 = (int)ch;
120           decode(b1, b2, b3, x, y+a);
121         }
122         x += 8;  
123         for(int a=0; a<8; a++)
124         {
125           ff.get(ch);   int b1 = (int)ch;
126           ff.get(ch);   int b2 = (int)ch;
127           ff2.get(ch);  int b3 = (int)ch;
128           decode(b1, b2, b3, x, y+a);
129         }
130         x = i * 16;  y += 8; 
131         for(int a=0; a<8; a++)
132         {
133           ff.get(ch);   int b1 = (int)ch;
134           ff.get(ch);   int b2 = (int)ch;
135           ff2.get(ch);  int b3 = (int)ch;
136           decode(b1, b2, b3, x, y+a);
137         }
138         x += 8; 
139         for(int a=0; a<8; a++)
140         {
141           ff.get(ch);   int b1 = (int)ch;
142           ff.get(ch);   int b2 = (int)ch;
143           ff2.get(ch);  int b3 = (int)ch;
144           decode(b1, b2, b3, x, y+a);
145         }
146     }
147     i = getch();
148     if (i==27)  break;  // Break out on ESC
149   }
150   setmode(0x03);  // Reset text mode
151 }