]> Shamusworld >> Repos - thunder/blob - test/rthack2.cpp
Fixes to makefile, file permissions.
[thunder] / test / rthack2.cpp
1 // Rolling Thunder hacker #2: character 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\\r7"
18 #define fn2 "c:\\games\\romhac~1\\r8"
19
20 // Global constants
21
22 char far *screen = (char far *) MK_FP(0xA000,0);
23
24 // Get a word from the current input stream
25
26 unsigned int GetWord(ifstream &fstr)
27 {
28   unsigned int word = 0;
29   unsigned char ch;
30
31   fstr.get(ch);  word = int(ch) << 8;
32   fstr.get(ch);  word |= (int)ch;
33   
34   return(word);
35 }
36
37 // Get a double word from the current input stream
38
39 unsigned long int GetDWord(ifstream &fstr)
40 {
41   unsigned long int dword = 0;
42   unsigned char ch;
43
44   for(int i=0; i<4; i++)
45   { 
46     fstr.get(ch);  dword <<= 8;  dword |= (int)ch;
47   }
48   return(dword);
49 }
50
51 void plot(int x, int y, int c)
52 {
53   screen[x + y*320] = c;
54 }
55
56 void decode(int b1, int b2, int b3, int xx, int yy)
57 {
58   int cc = ((b1 & 0x80) >> 5) | ((b1 & 0x08) >> 2) | ((b3 & 0x80) >> 7);
59   plot(xx, yy, cc);
60   cc = ((b1 & 0x40) >> 4) | ((b1 & 0x04) >> 1) | ((b3 & 0x40) >> 6);
61   plot(xx+1, yy, cc);
62   cc = ((b1 & 0x20) >> 3) | (b1 & 0x02) | ((b3 & 0x20) >> 5);
63   plot(xx+2, yy, cc);
64   cc = ((b1 & 0x10) >> 2) | ((b1 & 0x01) << 1) | ((b3 & 0x10) >> 4);
65   plot(xx+3, yy, cc);
66   cc = ((b2 & 0x80) >> 5) | ((b2 & 0x08) >> 2) | ((b3 & 0x08) >> 3);
67   plot(xx+4, yy, cc);
68   cc = ((b2 & 0x40) >> 4) | ((b2 & 0x04) >> 1) | ((b3 & 0x04) >> 2);
69   plot(xx+5, yy, cc);
70   cc = ((b2 & 0x20) >> 3) | (b2 & 0x02) | ((b3 & 0x02) >> 1);
71   plot(xx+6, yy, cc);
72   cc = ((b2 & 0x10) >> 2) | ((b2 & 0x01) << 1) | (b3 & 0x01);
73   plot(xx+7, yy, cc);
74 }
75
76 void main(void)
77 {
78   char pal[768];
79   unsigned char ch;
80   int i, j, x, y;
81   ifstream ff, ff2;       // Creates an IFSTREAM but without any file hooks
82
83   ff.open(fn1, ios::binary);   // Open as a binary file
84   ff2.open(fn2, ios::binary);  // ditto
85            
86   if (!ff) cerr << "Could not open 'ff'";
87   if (!ff2) cerr << "Could not open 'ff2'";
88
89   setmode(0x13);  // Set up VGA screen
90
91 /*  for(i=0; i<256; i++)
92   {
93     pal[i*3]   = (int)random(64);
94     pal[i*3+1] = (int)random(64);
95     pal[i*3+2] = (int)random(64);
96   }
97   setpalette();
98 */  
99   while (!kbhit())
100   {
101     for(j=0; j<12; j++)
102     {
103       for(i=0; i<8; i++)
104       {
105         x = i * 16;  y = j * 16; 
106         for(int a=0; a<8; a++)
107         {
108           ff.get(ch);   int b1 = (int)ch;
109           ff.get(ch);   int b2 = (int)ch;
110           ff2.get(ch);  int b3 = (int)ch;
111           decode(b1, b2, b3, x, y+a);
112         }
113         x += 8;  
114         for(int a=0; a<8; a++)
115         {
116           ff.get(ch);   int b1 = (int)ch;
117           ff.get(ch);   int b2 = (int)ch;
118           ff2.get(ch);  int b3 = (int)ch;
119           decode(b1, b2, b3, x, y+a);
120         }
121         x = i * 16;  y += 8; 
122         for(int a=0; a<8; a++)
123         {
124           ff.get(ch);   int b1 = (int)ch;
125           ff.get(ch);   int b2 = (int)ch;
126           ff2.get(ch);  int b3 = (int)ch;
127           decode(b1, b2, b3, x, y+a);
128         }
129         x += 8; 
130         for(int a=0; a<8; a++)
131         {
132           ff.get(ch);   int b1 = (int)ch;
133           ff.get(ch);   int b2 = (int)ch;
134           ff2.get(ch);  int b3 = (int)ch;
135           decode(b1, b2, b3, x, y+a);
136         }
137       }
138     }
139     i = getch();
140     if (i==27)  break;  // Break out on ESC
141   }
142   setmode(0x03);  // Reset text mode
143 }