| 1 |
|
| 2 |
#include "common.h" |
| 3 |
#include "params.h" |
| 4 |
#include "game_defines.h" |
| 5 |
|
| 6 |
typedef void (*ByteStreamCallback)(); |
| 7 |
extern ByteStreamCallback ByteStreamCallbacks[_COMMAND_COUNT]; |
| 8 |
|
| 9 |
|
| 10 |
void ClearMessageWindow(unsigned char paperColor) |
| 11 |
{ |
| 12 |
int i; |
| 13 |
char* ptrScreen=(char*)0xbb80+40*18; |
| 14 |
for (i=18;i<=23;i++) |
| 15 |
{ |
| 16 |
*ptrScreen=paperColor; |
| 17 |
memset(ptrScreen+1,32,39); |
| 18 |
ptrScreen+=40; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
void InitializeGraphicMode() |
| 24 |
{ |
| 25 |
ClearTextWindow(); |
| 26 |
poke(0xbb80+40*0,31|128); // Switch to HIRES, using video inverse to keep the 6 pixels white |
| 27 |
poke(0xa000+40*128,26); // Switch to TEXT |
| 28 |
|
| 29 |
// from the old BASIC code, will fix later |
| 30 |
// CYAN on BLACK for the scene description |
| 31 |
poke(0xBB80+40*16,7); // Line with the arrow character and the clock |
| 32 |
poke(0xBB80+40*17,6); |
| 33 |
|
| 34 |
// BLUE background for the log output |
| 35 |
ClearMessageWindow(16+4); |
| 36 |
|
| 37 |
// BLACK background for the inventory area |
| 38 |
poke(0xBB80+40*24,16); |
| 39 |
poke(0xBB80+40*25,16); |
| 40 |
poke(0xBB80+40*26,16); |
| 41 |
poke(0xBB80+40*27,16); |
| 42 |
|
| 43 |
// Initialize the ALT charset numbers |
| 44 |
memcpy((char*)0xb800+'0'*8,gSevenDigitDisplay,8*11); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
void DrawRectangleOutline(unsigned char xPos, unsigned char yPos, unsigned char width, unsigned char height, unsigned char fillValue) |
| 49 |
{ |
| 50 |
gDrawAddress = (unsigned char*)0xa000; |
| 51 |
|
| 52 |
gDrawPattern= fillValue; |
| 53 |
|
| 54 |
gDrawPosX = xPos; |
| 55 |
gDrawPosY = yPos+1; |
| 56 |
gDrawWidth = width; |
| 57 |
gDrawHeight = height-2; |
| 58 |
DrawVerticalLine(); |
| 59 |
|
| 60 |
gDrawPosX = xPos+1; |
| 61 |
gDrawPosY = yPos; |
| 62 |
gDrawWidth = width-2; |
| 63 |
gDrawHeight = height; |
| 64 |
DrawHorizontalLine(); |
| 65 |
|
| 66 |
gDrawPosX = xPos+width-1; |
| 67 |
gDrawPosY = yPos+1; |
| 68 |
gDrawWidth = width+1; |
| 69 |
gDrawHeight = height-2; |
| 70 |
DrawVerticalLine(); |
| 71 |
|
| 72 |
gDrawPosX = xPos+1; |
| 73 |
gDrawPosY = yPos+height-1; |
| 74 |
gDrawWidth = width-2; |
| 75 |
gDrawHeight = height; |
| 76 |
DrawHorizontalLine(); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
void SetByteStream(const char* byteStream) |
| 81 |
{ |
| 82 |
gCurrentStream = byteStream; |
| 83 |
gDelayStream = 0; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
void PlayStream(const char* byteStream) |
| 88 |
{ |
| 89 |
const char* originalByteStream = gCurrentStream; |
| 90 |
gCurrentStream = byteStream; |
| 91 |
gDelayStream = 0; |
| 92 |
|
| 93 |
do |
| 94 |
{ |
| 95 |
WaitIRQ(); |
| 96 |
HandleByteStream(); |
| 97 |
} |
| 98 |
while (gCurrentStream); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
void ByteStreamCommandINFO_MESSAGE() |
| 103 |
{ |
| 104 |
PrintInformationMessage(gCurrentStream); // Should probably return the length or pointer to the end of string |
| 105 |
gCurrentStream += strlen(gCurrentStream)+1; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
void ByteStreamCommandBITMAP() |
| 110 |
{ |
| 111 |
unsigned char loaderId = *gCurrentStream++; |
| 112 |
if (gFlagCurrentSpriteSheet!=loaderId) |
| 113 |
{ |
| 114 |
// We only load the image if it's not already the one in memory |
| 115 |
LoadFileAt(loaderId,SecondImageBuffer); |
| 116 |
gFlagCurrentSpriteSheet=loaderId; |
| 117 |
} |
| 118 |
gDrawWidth = *gCurrentStream++; |
| 119 |
gDrawHeight = *gCurrentStream++; |
| 120 |
gSourceStride = *gCurrentStream++; |
| 121 |
gDrawSourceAddress = (unsigned char*) *gCurrentStreamInt++; |
| 122 |
gDrawAddress = (unsigned char*) *gCurrentStreamInt++; |
| 123 |
BlitSprite(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
void ByteStreamCommandFULLSCREEN_ITEM() |
| 128 |
{ |
| 129 |
unsigned char loaderId = *gCurrentStream++; |
| 130 |
|
| 131 |
ClearMessageWindow(16+4); |
| 132 |
LoadFileAt(loaderId,ImageBuffer); |
| 133 |
PrintTopDescription(gCurrentStream); |
| 134 |
BlitBufferToHiresWindow(); |
| 135 |
|
| 136 |
gCurrentStream += strlen(gCurrentStream)+1; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
unsigned int* jumpLocation; |
| 141 |
char check = 0; |
| 142 |
|
| 143 |
|
| 144 |
unsigned char car; |
| 145 |
unsigned char index; |
| 146 |
unsigned char count; |
| 147 |
unsigned char color; |
| 148 |
const char* coordinates; |
| 149 |
|
| 150 |
void ByteStreamCommandBUBBLE() |
| 151 |
{ |
| 152 |
count = *gCurrentStream++; |
| 153 |
color = *gCurrentStream++; |
| 154 |
coordinates = gCurrentStream; |
| 155 |
for (index=0;index<count;index++) |
| 156 |
{ |
| 157 |
unsigned char x = *coordinates++; |
| 158 |
unsigned char y = *coordinates++; |
| 159 |
unsigned char w = 2; |
| 160 |
unsigned char h = 15; |
| 161 |
coordinates++; // offset y |
| 162 |
while (car=*coordinates++) // Skip string |
| 163 |
{ |
| 164 |
if (car>127) w+=(char)car; |
| 165 |
else w+=gFont12x14Width[car-32]+1; |
| 166 |
|
| 167 |
} |
| 168 |
//sprintf((char*)0xbb80+40*(20+index),"%d %d %d %d ",x,y,w,h); |
| 169 |
DrawRectangleOutline(x-1,y-1,w+2,h+2,color); |
| 170 |
} |
| 171 |
|
| 172 |
color ^= 63; |
| 173 |
gDrawPattern = color; |
| 174 |
|
| 175 |
coordinates = gCurrentStream; |
| 176 |
for (index=0;index<count;index++) |
| 177 |
{ |
| 178 |
gDrawPosX = *coordinates++; |
| 179 |
gDrawPosY = *coordinates++; |
| 180 |
gDrawHeight = 15; |
| 181 |
coordinates++; // offset y |
| 182 |
gDrawWidth=2; |
| 183 |
while (car=*coordinates++) // Skip string |
| 184 |
{ |
| 185 |
if (car>127) gDrawWidth+=(char)car; |
| 186 |
else gDrawWidth+=gFont12x14Width[car-32]+1; |
| 187 |
} |
| 188 |
|
| 189 |
DrawFilledRectangle(); |
| 190 |
} |
| 191 |
|
| 192 |
color ^= 63; |
| 193 |
gDrawPattern = color; |
| 194 |
coordinates = gCurrentStream; |
| 195 |
for (index=0;index<count;index++) |
| 196 |
{ |
| 197 |
gDrawPosX = *coordinates++; |
| 198 |
gDrawPosY = *coordinates++; |
| 199 |
gDrawHeight = 15; |
| 200 |
gDrawPosX += 1; // offset x |
| 201 |
gDrawPosY += *coordinates++; // offset y |
| 202 |
gDrawExtraData = coordinates; |
| 203 |
PrintFancyFont(); |
| 204 |
coordinates = gDrawExtraData; // modified by the PrintFancyFont function |
| 205 |
} |
| 206 |
gCurrentStream = coordinates; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
// The various commands: |
| 212 |
// - COMMAND_END indicates the end of the stream |
| 213 |
// - COMMAND_BUBBLE draws speech bubble and requires a number of parameters: |
| 214 |
// - Number of bubbles |
| 215 |
// - Main color |
| 216 |
// - For each bubble: X,Y,W,H, |
| 217 |
// - COMMAND_TEXT |
| 218 |
// - x,y,color,message |
| 219 |
void HandleByteStream() |
| 220 |
{ |
| 221 |
if (gDelayStream) |
| 222 |
{ |
| 223 |
// _VblCounter |
| 224 |
gDelayStream--; |
| 225 |
return; |
| 226 |
} |
| 227 |
|
| 228 |
if (gCurrentStream) |
| 229 |
{ |
| 230 |
gDrawAddress = (unsigned char*)0xa000; |
| 231 |
gCurrentStreamStop = 0; |
| 232 |
do |
| 233 |
{ |
| 234 |
unsigned char command=*gCurrentStream++; |
| 235 |
if (command>=_COMMAND_COUNT) |
| 236 |
{ |
| 237 |
Panic(); |
| 238 |
} |
| 239 |
ByteStreamCallbacks[command](); |
| 240 |
} |
| 241 |
while (!gCurrentStreamStop); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
|