]> Shamusworld >> Repos - thunder/blob - test/rthack.cpp
Initial import (for historical reasons).
[thunder] / test / rthack.cpp
1 // Rolling Thunder hacker
2 //
3 // Just a simple test...
4
5 #include <fstream.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <iomanip.h>
9 #include <stdio.h>
10 #include <conio.h>
11 #include <dos.h>
12 #include "screen.h"
13 //
14 // Get a word from the current input stream
15 //
16 unsigned int GetWord(ifstream &fstr)
17 {
18   unsigned int word = 0;
19   unsigned char ch;
20
21   fstr.get(ch);  word = int(ch) << 8;
22   fstr.get(ch);  word |= (int)ch;
23   
24   return(word);
25 }
26 //
27 // Get a double word from the current input stream
28 //
29 unsigned long int GetDWord(ifstream &fstr)
30 {
31   unsigned long int dword = 0;
32   unsigned char ch;
33
34   for(int i=0; i<4; i++)
35   { 
36     fstr.get(ch);  dword <<= 8;  dword |= (int)ch;
37   }
38   return(dword);
39 }
40
41 void plot(int x, int y, int c)
42 {
43   extern char far * screen;
44
45   screen[x + y*320] = c;
46 }
47
48 void main(int argc, char *argv[])
49 {
50   char pal[768], file[120];
51   unsigned char ch;
52   int i,j;
53   ifstream ff;          // Creates an IFSTREAM but without any file hooks
54
55   strcpy(file, "c:\\games\\romhac~1\\");
56
57   if (argc == 2)
58   {
59     strcat(file, argv[1]);
60   }
61   else
62   {
63     strcat(file, "r9");
64   }
65
66   ff.open(file, ios::binary);  // Open as a binary file
67            
68   if (!ff) { cerr << "Could not open the file! (Maybe it doesn't exist...)";
69              return;}
70
71   SetMode(0x13);   // Set up screen...
72
73   pal[0]  = 0x3F;  pal[1]  = 0x00;  pal[2]  = 0x00;  // Red
74   pal[3]  = 0x30;  pal[4]  = 0x00;  pal[5]  = 0x00;  // Darker Red
75   pal[6]  = 0x28;  pal[7]  = 0x00;  pal[8]  = 0x00;  // Darkest Red
76   pal[9]  = 0x2f;  pal[10] = 0x2f;  pal[11] = 0x2F;  // Light Grey
77   pal[12] = 0x1F;  pal[13] = 0x1f;  pal[14] = 0x1f;  // Med Grey
78   pal[15] = 0x0F;  pal[16] = 0x0f;  pal[17] = 0x0f;  // Dark Grey
79   pal[18] = 0x3F;  pal[19] = 0x30;  pal[20] = 0x20;  // Peach?
80   pal[21] = 0x20;  pal[22] = 0x20;  pal[23] = 0x00;
81   pal[24] = 0x08;  pal[25] = 0x3f;  pal[26] = 0x10;  
82   pal[27] = 0x06;  pal[28] = 0x06;  pal[29] = 0x06;  // Dk Dk Dk Grey
83   pal[30] = 0x08;  pal[31] = 0x08;  pal[32] = 0x10;  // Dk Dk Grey
84   pal[33] = 0x00;  pal[34] = 0x3f;  pal[35] = 0x00;
85
86   pal[45] = 0x00;  pal[46] = 0x00;  pal[47] = 0x00;
87
88   outp(0x03C8, 0);                  // Tell VGA palette data is coming...
89   for(int i=0; i<48; i++)
90   {
91     outp(0x03C9, pal[i]);     // Send it...
92   }
93 //  setpalette(pal);
94   
95   while (!kbhit())
96   {
97     for(int x=0; x<320; x+=32)
98     {
99       for(int y=0; y<192; y+=16)
100       {
101         for(j=0; j<16; j++)
102         {
103           for(i=0; i<16; i+=2)
104           {
105             ff.get(ch);  int lo = ch & 0x0f;  int hi = ch / 16;
106             plot(x+i, y+j, hi);  plot(x+i+1, y+j, lo);
107           }
108         }
109         for(j=0; j<16; j++)
110         {
111           for(i=16; i<32; i+=2)
112           {
113             ff.get(ch);  int lo = ch & 0x0f;  int hi = ch / 16;
114             plot(x+i, y+j, hi);  plot(x+i+1, y+j, lo);
115           }
116         }
117       }
118     }
119   i = getch();    // Get keyboard char
120   if (i == 27) break; // ESC aborts...
121   }
122   SetMode(0x03);  // Reset text mode
123 }