diff options
-rw-r--r-- | sky/disk.cpp | 154 | ||||
-rw-r--r-- | sky/grid.cpp | 132 | ||||
-rw-r--r-- | sky/intro.cpp | 26 | ||||
-rw-r--r-- | sky/module.mk | 1 | ||||
-rw-r--r-- | sky/screen.cpp | 58 | ||||
-rw-r--r-- | sky/sky.cpp | 37 | ||||
-rw-r--r-- | sky/sky.h | 36 | ||||
-rw-r--r-- | sky/skydefs.h | 21 |
8 files changed, 298 insertions, 167 deletions
diff --git a/sky/disk.cpp b/sky/disk.cpp index 4f98f47fcb..ec496f3cdb 100644 --- a/sky/disk.cpp +++ b/sky/disk.cpp @@ -27,122 +27,120 @@ #include "sky/sky.h" #include "sky/rnc_deco.h" -#define no_of_files_hd 1600 -#define no_of_files_cd 5200 -#define max_files_in_list 60 +#define MAX_FILES_IN_LIST 60 -const char *data_file_name = "sky.dsk"; -const char *dinner_file_name = "sky.dnr"; -uint8 *dinner_table_area, *fixed_dest, *file_dest, *comp_dest; -uint32 dinner_table_entries, file_flags, file_offset, file_size, decomp_size, comp_file; -uint16 build_list[max_files_in_list]; -uint32 loaded_file_list[max_files_in_list]; +const char *dataFilename = "sky.dsk"; +const char *dinnerFilename = "sky.dnr"; +uint8 *dinnerTableArea, *fixedDest, *fileDest, *compDest; +uint32 dinnerTableEntries, fileFlags, fileOffset, fileSize, decompSize, compFile; +uint16 buildList[MAX_FILES_IN_LIST]; +uint32 loadedFileList[MAX_FILES_IN_LIST]; -File *data_disk_handle = new File(); -File *dnr_handle = new File(); +File *dataDiskHandle = new File(); +File *dnrHandle = new File(); -void SkyState::initialise_disk() -{ - uint32 entries_read; +void SkyState::initialiseDisk() { - dnr_handle->open(dinner_file_name, _gameDataPath); - if (dnr_handle->isOpen() == false) - error("Could not open %s%s!\n", _gameDataPath, dinner_file_name); + uint32 entriesRead; - if (!(dinner_table_entries = dnr_handle->readUint32LE())) + dnrHandle->open(dinnerFilename, _gameDataPath); + if (dnrHandle->isOpen() == false) + error("Could not open %s%s!\n", _gameDataPath, dinnerFilename); + + if (!(dinnerTableEntries = dnrHandle->readUint32LE())) error("Error reading from sky.dnr!\n"); //even though it was opened correctly?! - debug(1, "Entries in dinner table: %d", dinner_table_entries); + debug(1, "Entries in dinner table: %d", dinnerTableEntries); - if (dinner_table_entries > 1600) + if (dinnerTableEntries > 1600) _isCDVersion = true; else _isCDVersion = false; - dinner_table_area = (uint8 *)malloc(dinner_table_entries * 8); - entries_read = dnr_handle->read(dinner_table_area, 8 * dinner_table_entries) / 8; + dinnerTableArea = (uint8 *)malloc(dinnerTableEntries * 8); + entriesRead = dnrHandle->read(dinnerTableArea, 8 * dinnerTableEntries) / 8; - if (entries_read != dinner_table_entries) - warning("bytes_read != dinner_table_entries. [%d/%d]\n", entries_read, dinner_table_entries); + if (entriesRead != dinnerTableEntries) + warning("entriesRead != dinnerTableEntries. [%d/%d]\n", entriesRead, dinnerTableEntries); - data_disk_handle->open(data_file_name, _gameDataPath); - if (data_disk_handle->isOpen() == false) - error("Error opening %s%s!\n", _gameDataPath, data_file_name); + dataDiskHandle->open(dataFilename, _gameDataPath); + if (dataDiskHandle->isOpen() == false) + error("Error opening %s%s!\n", _gameDataPath, dataFilename); } //load in file file_nr to address dest //if dest == NULL, then allocate memory for this file -uint16 *SkyState::load_file(uint16 file_nr, uint8 *dest) -{ +uint16 *SkyState::loadFile(uint16 fileNr, uint8 *dest) { + uint8 cflag; - int32 bytes_read; - uint8 *file_ptr, *inputPtr, *outputPtr; - dataFileHeader file_header; + int32 bytesRead; + uint8 *filePtr, *inputPtr, *outputPtr; + dataFileHeader fileHeader; #ifdef file_order_chk warning("File order checking not implemented yet!\n"); #endif - comp_file = file_nr; - debug(1, "load file %d,%d (%d)", (file_nr >> 11), (file_nr & 2047), file_nr); + compFile = fileNr; + debug(1, "load file %d,%d (%d)", (fileNr >> 11), (fileNr & 2047), fileNr); - file_ptr = (uint8 *)get_file_info(file_nr); - if (file_ptr == NULL) { - printf("File %d not found!\n", file_nr); + filePtr = (uint8 *)getFileInfo(fileNr); + if (filePtr == NULL) { + printf("File %d not found!\n", fileNr); return NULL; } - file_flags = READ_LE_UINT32((file_ptr + 5)); - file_size = file_flags & 0x03fffff; + fileFlags = READ_LE_UINT32((filePtr + 5)); + fileSize = fileFlags & 0x03fffff; - file_offset = READ_LE_UINT32((file_ptr + 2)) & 0x0ffffff; + fileOffset = READ_LE_UINT32((filePtr + 2)) & 0x0ffffff; - cflag = (uint8)((file_offset >> (23)) & 0x1); - file_offset = (((1 << (23)) ^ 0xFFFFFFFF) & file_offset); + cflag = (uint8)((fileOffset >> (23)) & 0x1); + fileOffset = (((1 << (23)) ^ 0xFFFFFFFF) & fileOffset); if (cflag) - file_offset <<= 4; + fileOffset <<= 4; - fixed_dest = dest; - file_dest = dest; - comp_dest = dest; + fixedDest = dest; + fileDest = dest; + compDest = dest; if (dest == NULL) //we need to allocate memory for this file - file_dest = (uint8 *)malloc(file_size); + fileDest = (uint8 *)malloc(fileSize); - data_disk_handle->seek(file_offset, SEEK_SET); + dataDiskHandle->seek(fileOffset, SEEK_SET); #ifdef file_order_chk warning("File order checking not implemented yet!\n"); #endif //now read in the data - bytes_read = data_disk_handle->read(file_dest, 1*file_size); + bytesRead = dataDiskHandle->read(fileDest, 1 * fileSize); - if (bytes_read != (int32)file_size) - printf("ERROR: Unable to read %d bytes from datadisk (%d bytes read)\n", file_size, bytes_read); + if (bytesRead != (int32)fileSize) + printf("ERROR: Unable to read %d bytes from datadisk (%d bytes read)\n", fileSize, bytesRead); - cflag = (uint8)((file_flags >> (23)) & 0x1); + cflag = (uint8)((fileFlags >> (23)) & 0x1); //if cflag == 0 then file is compressed, 1 == uncompressed if (!cflag) { debug(1, "File is compressed..."); - memcpy(&file_header, file_dest, sizeof(struct dataFileHeader)); - if ( (uint8)((FROM_LE_16(file_header.flag) >> 7) & 0x1) ) { + memcpy(&fileHeader, fileDest, sizeof(struct dataFileHeader)); + if ( (uint8)((FROM_LE_16(fileHeader.flag) >> 7) & 0x1) ) { debug(1, "with RNC!"); - decomp_size = (FROM_LE_16(file_header.flag) & 0xFFFFFF00) << 8; - decomp_size |= FROM_LE_16((uint16)file_header.s_tot_size); + decompSize = (FROM_LE_16(fileHeader.flag) & 0xFFFFFF00) << 8; + decompSize |= FROM_LE_16((uint16)fileHeader.s_tot_size); - if (fixed_dest == NULL) // is this valid? - comp_dest = (uint8 *)malloc(decomp_size); + if (fixedDest == NULL) // is this valid? + compDest = (uint8 *)malloc(decompSize); - inputPtr = file_dest; - outputPtr = comp_dest; + inputPtr = fileDest; + outputPtr = compDest; - if ( (uint8)(file_flags >> (22) & 0x1) ) //do we include the header? + if ( (uint8)(fileFlags >> (22) & 0x1) ) //do we include the header? inputPtr += sizeof(struct dataFileHeader); else { memcpy(outputPtr, inputPtr, sizeof(struct dataFileHeader)); @@ -156,40 +154,40 @@ uint16 *SkyState::load_file(uint16 file_nr, uint8 *dest) debug(2, "UnpackM1 returned: %d", unPackLen); if (unPackLen == 0) { //Unpack returned 0: file was probably not packed. - if (fixed_dest == NULL) - free(comp_dest); + if (fixedDest == NULL) + free(compDest); - return (uint16 *)file_dest; + return (uint16 *)fileDest; } - if (! (uint8)(file_flags >> (22) & 0x1) ) { // include header? + if (! (uint8)(fileFlags >> (22) & 0x1) ) { // include header? unPackLen += sizeof(struct dataFileHeader); - if (unPackLen != (int32)decomp_size) { - debug(1, "ERROR: invalid decomp size! (was: %d, should be: %d)", unPackLen, decomp_size); + if (unPackLen != (int32)decompSize) { + debug(1, "ERROR: invalid decomp size! (was: %d, should be: %d)", unPackLen, decompSize); } } - if (fixed_dest == NULL) - free(file_dest); + if (fixedDest == NULL) + free(fileDest); } else debug(1, "but not with RNC! (?!)"); } else - return (uint16 *)file_dest; + return (uint16 *)fileDest; - return (uint16 *)comp_dest; + return (uint16 *)compDest; } -uint16 *SkyState::get_file_info(uint16 file_nr) -{ +uint16 *SkyState::getFileInfo(uint16 fileNr) { + uint16 i; - uint16 *dnr_tbl_16_ptr = (uint16 *)dinner_table_area; + uint16 *dnrTbl16Ptr = (uint16 *)dinnerTableArea; - for (i = 0; i < dinner_table_entries; i++) { - if (READ_LE_UINT16(dnr_tbl_16_ptr + (i * 4)) == file_nr) { - debug(1, "file %d found!", file_nr); - return (dnr_tbl_16_ptr + (i * 4)); + for (i = 0; i < dinnerTableEntries; i++) { + if (READ_LE_UINT16(dnrTbl16Ptr + (i * 4)) == fileNr) { + debug(1, "file %d found!", fileNr); + return (dnrTbl16Ptr + (i * 4)); } } diff --git a/sky/grid.cpp b/sky/grid.cpp new file mode 100644 index 0000000000..dc2a6a6eb5 --- /dev/null +++ b/sky/grid.cpp @@ -0,0 +1,132 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2003 The ScummVM project + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#include "stdafx.h" +#include "sky/sky.h" +#include "sky/skydefs.h" + +#define GRID_FILE_START 60000 + +int8 gridConvertTable[] = { + + 1, //1 + 2, //2 + 3, //3 + 4, //4 + 5, //5 + 6, //6 + 7, //7 + 8, //8 + 9, //9 + 10, //10 + 11, //11 + 12, //12 + 13, //13 + 14, //14 + 15, //15 + 16, //16 + 17, //17 + 18, //18 + 19, //19 + 20, //20 + 21, //21 + 22, //22 + 23, //23 + 24, //24 + 25, //25 + 26, //26 + 27, //27 + 28, //28 + 29, //29 + 30, //30 + 31, //31 + 32, //32 + 33, //33 + 34, //34 + -1, //35 + 35, //36 + 36, //37 + 37, //38 + 38, //39 + 39, //40 + 40, //41 + 41, //42 + -1, //43 + 42, //44 + 43, //45 + 44, //46 + 45, //47 + 46, //48 + -1, //49 + -1, //50 + -1, //51 + -1, //52 + -1, //53 + -1, //54 + -1, //55 + -1, //56 + -1, //57 + -1, //58 + -1, //59 + -1, //60 + -1, //61 + -1, //62 + -1, //63 + -1, //64 + 47, //65 + TOT_NO_GRIDS, //66 + 48, //67 + 49, //68 + 50, //69 + 51, //70 + 52, //71 + 53, //72 + 54, //73 + 55, //74 + 56, //75 + 57, //76 + 58, //77 + 59, //78 + 60, //79 + -1, //80 + 61, //81 + 62, //82 + -1, //83 + -1, //84 + -1, //85 + -1, //86 + -1, //87 + -1, //88 + TOT_NO_GRIDS, //89 + 63, //90 + 64, //91 + 65, //92 + 66, //93 + 67, //94 + 68, //95 + 69, //96 +}; + +void SkyState::initialiseGrids() { + + _gameGrids = (byte *)malloc(TOT_NO_GRIDS * GRID_SIZE); +} + diff --git a/sky/intro.cpp b/sky/intro.cpp index 872f86452e..04761bf45b 100644 --- a/sky/intro.cpp +++ b/sky/intro.cpp @@ -216,25 +216,25 @@ uint32 anim6b_commands[] = uint32 *command_pointer = (uint32 *)zero_commands; -void SkyState::init_virgin() -{ - _temp_pal = (uint8 *)load_file(60111, NULL); - if (_temp_pal != NULL) - set_palette(_temp_pal); +void SkyState::initVirgin() { + + _tempPal = (uint8 *)loadFile(60111, NULL); + if (_tempPal != NULL) + setPalette(_tempPal); - _work_screen = (uint8 *)load_file(60110, NULL); + _workScreen = (uint8 *)loadFile(60110, NULL); - if (_work_screen != NULL) - show_screen(); + if (_workScreen != NULL) + showScreen(); // free the memory that was malloc'ed indirectly via load_file - free(_work_screen); - free(_temp_pal); + free(_workScreen); + free(_tempPal); } -void SkyState::show_screen(void) -{ - _system->copy_rect(_work_screen, 320, 0, 0, 320, 200); +void SkyState::showScreen(void) { + + _system->copy_rect(_workScreen, 320, 0, 0, 320, 200); _system->update_screen(); } diff --git a/sky/module.mk b/sky/module.mk index a057473fd4..8e6bad9543 100644 --- a/sky/module.mk +++ b/sky/module.mk @@ -6,6 +6,7 @@ MODULE_OBJS = \ sky/screen.o \ sky/intro.o \ sky/rnc_deco.o \ + sky/grid.o \ # Include common rules include common.rules diff --git a/sky/screen.cpp b/sky/screen.cpp index 1dd6de0f1f..cf8725fa4f 100644 --- a/sky/screen.cpp +++ b/sky/screen.cpp @@ -25,13 +25,13 @@ #include "sky/skydefs.h" #include "sky/sky.h" -#define fade_jump 2 -#define scroll_jump 16 +#define FADE_JUMP 2 +#define SCROLL_JUMP 16 -#define vga_colours 256 -#define game_colours 240 +#define VGA_COLOURS 256 +#define GAME_COLOURS 240 -uint8 top_16_colours[] = +uint8 top16Colours[] = { 0, 0, 0, 38, 38, 38, @@ -51,46 +51,46 @@ uint8 top_16_colours[] = 63, 63, 63 }; -void SkyState::initialise_screen(void) -{ +void SkyState::initialiseScreen(void) { + int i; - uint8 tmp_pal[1024]; + uint8 tmpPal[1024]; - _system->init_size(full_screen_width, full_screen_height); - _backscreen = (uint8 *)malloc(full_screen_width * full_screen_height); - _game_grid = (uint8 *)malloc(GRID_X * GRID_Y * 2); - _work_palette = (uint8 *)malloc(vga_colours * 3); + _system->init_size(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT); + _backScreen = (uint8 *)malloc(FULL_SCREEN_WIDTH * FULL_SCREEN_HEIGHT); + _gameGrid = (uint8 *)malloc(GRID_X * GRID_Y * 2); + _workPalette = (uint8 *)malloc(VGA_COLOURS * 3); //blank the first 240 colors of the palette - memset(tmp_pal, 0, game_colours * 4); + memset(tmpPal, 0, GAME_COLOURS * 4); //set the remaining colors - for (i = 0; i < (vga_colours-game_colours); i++) { - tmp_pal[game_colours + i * 4] = (top_16_colours[i * 3] << 2) + (top_16_colours[i * 3] & 3); - tmp_pal[game_colours + i * 4 + 1] = (top_16_colours[i * 3 + 1] << 2) + (top_16_colours[i * 3 + 1] & 3); - tmp_pal[game_colours + i * 4 + 2] = (top_16_colours[i * 3 + 2] << 2) + (top_16_colours[i * 3 + 2] & 3); - tmp_pal[game_colours + i * 4 + 3] = 0x00; + for (i = 0; i < (VGA_COLOURS-GAME_COLOURS); i++) { + tmpPal[GAME_COLOURS + i * 4] = (top16Colours[i * 3] << 2) + (top16Colours[i * 3] & 3); + tmpPal[GAME_COLOURS + i * 4 + 1] = (top16Colours[i * 3 + 1] << 2) + (top16Colours[i * 3 + 1] & 3); + tmpPal[GAME_COLOURS + i * 4 + 2] = (top16Colours[i * 3 + 2] << 2) + (top16Colours[i * 3 + 2] & 3); + tmpPal[GAME_COLOURS + i * 4 + 3] = 0x00; } //set the palette - _system->set_palette(tmp_pal, 0, 256); + _system->set_palette(tmpPal, 0, 256); } //set a new palette, pal is a pointer to dos vga rgb components 0..63 -void SkyState::set_palette(uint8 *pal) -{ - convert_palette(pal, _palette); +void SkyState::setPalette(uint8 *pal) { + + convertPalette(pal, _palette); _system->set_palette(_palette, 0, 256); } -void SkyState::convert_palette(uint8 *inpal, uint8* outpal) //convert 3 byte 0..63 rgb to 4byte 0..255 rgbx -{ +void SkyState::convertPalette(uint8 *inPal, uint8* outPal) { //convert 3 byte 0..63 rgb to 4byte 0..255 rgbx + int i; - for (i = 0; i < vga_colours; i++) { - outpal[4 * i] = (inpal[3 * i] << 2) + (inpal[3 * i] & 3); - outpal[4 * i + 1] = (inpal[3 * i + 1] << 2) + (inpal[3 * i + 1] & 3); - outpal[4 * i + 2] = (inpal[3 * i + 2] << 2) + (inpal[3 * i + 2] & 3); - outpal[4 * i + 3] = 0x00; + for (i = 0; i < VGA_COLOURS; i++) { + outPal[4 * i] = (inPal[3 * i] << 2) + (inPal[3 * i] & 3); + outPal[4 * i + 1] = (inPal[3 * i + 1] << 2) + (inPal[3 * i + 1] & 3); + outPal[4 * i + 2] = (inPal[3 * i + 2] << 2) + (inPal[3 * i + 2] & 3); + outPal[4 * i + 3] = 0x00; } } diff --git a/sky/sky.cpp b/sky/sky.cpp index 6c9ef97427..fbd4840b63 100644 --- a/sky/sky.cpp +++ b/sky/sky.cpp @@ -40,19 +40,17 @@ static const VersionSettings sky_settings[] = { {NULL, NULL, 0, 0, 0, 0, 0, NULL} }; -const VersionSettings *Engine_SKY_targetList() -{ +const VersionSettings *Engine_SKY_targetList() { return sky_settings; } -Engine *Engine_SKY_create(GameDetector *detector, OSystem *syst) -{ +Engine *Engine_SKY_create(GameDetector *detector, OSystem *syst) { return new SkyState(detector, syst); } SkyState::SkyState(GameDetector *detector, OSystem *syst) - : Engine(detector, syst) -{ + : Engine(detector, syst) { + _game = detector->_gameId; _debugMode = detector->_debugMode; @@ -60,19 +58,18 @@ SkyState::SkyState(GameDetector *detector, OSystem *syst) _language = detector->_language; } -SkyState::~SkyState() -{ +SkyState::~SkyState() { } -void SkyState::pollMouseXY() -{ +void SkyState::pollMouseXY() { + _mouse_x = _sdl_mouse_x; _mouse_y = _sdl_mouse_y; } -void SkyState::go() -{ +void SkyState::go() { + if (!_dump_file) _dump_file = stdout; @@ -83,18 +80,20 @@ void SkyState::go() } } -void SkyState::initialise(void) -{ +void SkyState::initialise(void) { + //initialise_memory(); //init_timer(); //init_music(); - initialise_disk(); - initialise_screen(); - init_virgin(); + initialiseDisk(); + initialiseScreen(); + initVirgin(); + //initMouse(); + initialiseGrids(); } -void SkyState::delay(uint amount) //copied and mutilated from Simon.cpp -{ +void SkyState::delay(uint amount) { //copied and mutilated from Simon.cpp + OSystem::Event event; uint32 start = _system->get_msecs(); @@ -43,7 +43,7 @@ protected: uint8 _palette[1024]; - int _num_screen_updates; + int _numScreenUpdates; // int _timer_id; @@ -53,14 +53,15 @@ protected: int _sdl_mouse_x, _sdl_mouse_y; - byte *_work_screen; - byte *_backscreen; - byte *_temp_pal; - byte *_work_palette; - byte *_half_palette; - - byte *_game_grid; - + byte *_workScreen; + byte *_backScreen; + byte *_tempPal; + byte *_workPalette; + byte *_halfPalette; + + byte *_gameGrid; + byte *_gameGrids; + public: SkyState(GameDetector *detector, OSystem *syst); virtual ~SkyState(); @@ -69,16 +70,17 @@ protected: void delay(uint amount); void pollMouseXY(); void go(); - void convert_palette(uint8 *inpal, uint8* outpal); + void convertPalette(uint8 *inpal, uint8* outpal); void initialise(); - void initialise_disk(); - void initialise_screen(); - void set_palette(uint8 *pal); - uint16 *load_file(uint16 file_nr, uint8 *dest); - uint16 *get_file_info(uint16 file_nr); - void init_virgin(); - void show_screen(); + void initialiseDisk(); + void initialiseScreen(); + void initialiseGrids(); + void setPalette(uint8 *pal); + uint16 *loadFile(uint16 fileNr, uint8 *dest); + uint16 *getFileInfo(uint16 fileNr); + void initVirgin(); + void showScreen(); static int CDECL game_thread_proc(void *param); diff --git a/sky/skydefs.h b/sky/skydefs.h index 803e3961cb..0174731fc7 100644 --- a/sky/skydefs.h +++ b/sky/skydefs.h @@ -23,18 +23,17 @@ //This file is incomplete, several flags still missing. -#define key_buffer_size 80 -#define sequence_count 3 +#define KEY_BUFFER_SIZE 80 +#define SEQUENCE_COUNT 3 //screen/grid defines -#define game_screen_width 320 -#define game_screen_height 192 -#define full_screen_width 320 -#define full_screen_height 200 +#define GAME_SCREEN_WIDTH 320 +#define GAME_SCREEN_HEIGHT 192 +#define FULL_SCREEN_WIDTH 320 +#define FULL_SCREEN_HEIGHT 200 -#define tot_no_grids 70 - -#define grid_size 120 +#define TOT_NO_GRIDS 70 //total no. of grids supported +#define GRID_SIZE 120 //grid size in bytes #define GRID_X 20 #define GRID_Y 24 @@ -44,8 +43,8 @@ #define GRID_W_SHIFT 4 #define GRID_H_SHIFT 3 -#define top_left_x 128 -#define top_left_y 136 +#define TOP_LEFT_X 128 +#define TOP_LEFT_Y 136 //item list defines #define section_0_item 119 |