2 // (Last build: 7/1/1998)
6 // (c) 1998 Underground Software
22 #include "sbdrv.h" // Goes before GUI so it can have access to uint..
24 #define ROM21 "RT1-21.ROM"
25 #define ROM22 "RT2-22.ROM"
27 #define BYTE unsigned char
28 #define WORD unsigned short int
29 #define DWORD unsigned long int
35 fstream tr; // Tracelog hook
37 bool snd_go = false; // for sound routines...
38 uint32 start_pos, end_pos, rom_pos;
43 // Sound stuff (Will go elsewhere???)
47 snd_go = true; rom_pos = start_pos; sample = 0;
49 void SoundFunc(uint8 * buff, uint16 num)
51 uint16 cnt = 0; // 0-22 different sounds...
52 uint8 start_samp, end_samp;
54 memset(buff, 128, num); // Kill sound...
61 start_samp = voice_rom[rom_pos++];
62 end_samp = voice_rom[rom_pos];
63 delta_x = (end_samp - start_samp) / 4; // Interpolation value...
66 buff[cnt++] = start_samp;
67 start_samp += delta_x;
69 if (rom_pos == end_pos) // Reached cutoff yet?
78 // Generic Load file into image space
79 // (No error checking performed! Responsibility of caller!)
81 bool LoadImg(char * filename, BYTE * mem, DWORD address, DWORD length)
86 ff.open(filename, ios::binary | ios::in); // Open 'da file...
89 for(DWORD i=0; i<length; i++) // Read it in...
91 ff.get(ch); mem[address+i] = ch;
93 ff.close(); // Close 'da file...
98 // Show screen routine
100 void ShowScreen(void)
102 cout << "Start: " << hex << start_pos << " End: " << end_pos << " "
108 int main(int /*argc*/, char * /*argv[]*/)
111 fstream ff; // Declare fstream without file hooks...
112 bool running = true; // CPU running state flag...
113 DWORD debounce = 0; // Key de-bounce counter
114 BYTE x; // General placeholder...
116 tr.open("sound.log", ios::binary | ios::out); // Tracelog
118 cout << "Looking for soundcard..." << endl;
119 if (!OpenSB(22050, 800)) { cerr << "No soundcard found!" << endl
120 << "Aborting!" << endl; return -1; }
121 Start_audio_output(AUTO_DMA, SoundFunc); // Start sound...
123 cout << "Allocating memory..." << endl;
124 set_new_handler(0); // Make 'new' return NULL on failure...
125 voice_rom = new BYTE[0x20000];
126 if (voice_rom == NULL) { cerr << "Could not allocate ROM voice data!" << endl
127 << "Aborting!" << endl; return -1; }
129 cout << "Loading ROMs..." << endl;
130 if (!LoadImg(ROM21, voice_rom, 0, 0x10000)) // Load 21st ROM
131 { cerr << "Could not open file '" << ROM21 << "'!" << endl; return -1; }
133 if (!LoadImg(ROM22, voice_rom, 0x10000, 0x10000)) // Load 22nd ROM
134 { cerr << "Could not open file '" << ROM22 << "'!" << endl; return -1; }
136 for(int i=0; i<128; i++) keys[i] = 0; // Clear keyboard buffer...
137 SnagKeyboard(); // Snag the interrupt...
138 ChainKeyboard(0); // No chaining!
139 start_pos = 0; end_pos = 1;
143 if (keys[0x01]) running = false; // ESC to exit...
145 if (debounce) debounce--;
146 if (keys[57] && !debounce)
148 SpawnSound(); // Space
151 if (keys[12]) { start_pos--; ShowScreen(); } // '-'
152 if (keys[13]) { start_pos++; ShowScreen(); } // '+'
153 if (keys[26]) { end_pos--; ShowScreen(); } // '['
154 if (keys[27]) { end_pos++; ShowScreen(); } // ']'
155 if (keys[19]) tr << hex << start_pos << ":" << end_pos << endl; // 'R'
157 ReleaseKeyboard(); // Release the interrupt...
159 CloseSB(); // Shut down sound card
161 tr.close(); // Close tracelog