// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // Copyright (C) 1999-2003 Forgotten // Copyright (C) 2004-2006 Forgotten and the VBA development team // Copyright (C) 2007-2008 VBA-M development team and Shay Green // 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, 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. #include #include #include #include #include "System.h" #include "NLS.h" #include "Util.h" #include "gba/Flash.h" #include "gba/GBA.h" #include "gba/Globals.h" #include "gba/RTC.h" #include "common/Port.h" #include "../utils/unzip/unzip.h" extern "C" { #include "common/memgzio.h" } #ifndef _MSC_VER #define _stricmp strcasecmp #endif // ! _MSC_VER extern int systemColorDepth; extern int systemRedShift; extern int systemGreenShift; extern int systemBlueShift; extern u16 systemColorMap16[0x10000]; //extern u32 systemColorMap32[0x10000]; extern u32 *systemColorMap32; static int (*utilGzWriteFunc)(gzFile, const voidp, unsigned int) = NULL; static int (*utilGzReadFunc)(gzFile, voidp, unsigned int) = NULL; static int (*utilGzCloseFunc)(gzFile) = NULL; static z_off_t (*utilGzSeekFunc)(gzFile, z_off_t, int) = NULL; extern bool cpuIsMultiBoot; bool utilIsGBAImage(const char * file) { cpuIsMultiBoot = false; if(strlen(file) > 4) { const char * p = strrchr(file,'.'); if(p != NULL) { if((_stricmp(p, ".agb") == 0) || (_stricmp(p, ".gba") == 0) || (_stricmp(p, ".bin") == 0) || (_stricmp(p, ".elf") == 0)) return true; if(_stricmp(p, ".mb") == 0) { cpuIsMultiBoot = true; return true; } } } return false; } bool utilIsGBImage(const char * file) { if(strlen(file) > 4) { const char * p = strrchr(file,'.'); if(p != NULL) { if((_stricmp(p, ".dmg") == 0) || (_stricmp(p, ".gb") == 0) || (_stricmp(p, ".gbc") == 0) || (_stricmp(p, ".cgb") == 0) || (_stricmp(p, ".sgb") == 0)) return true; } } return false; } bool utilIsZipFile(const char *file) { if(strlen(file) > 4) { char * p = strrchr(file,'.'); if(p != NULL) { if(_stricmp(p, ".zip") == 0) return true; } } return false; } void utilPutDword(u8 *p, u32 value) { *p++ = value & 255; *p++ = (value >> 8) & 255; *p++ = (value >> 16) & 255; *p = (value >> 24) & 255; } void utilPutWord(u8 *p, u16 value) { *p++ = value & 255; *p = (value >> 8) & 255; } void utilWriteInt(gzFile gzFile, int i) { utilGzWrite(gzFile, &i, sizeof(int)); } int utilReadInt(gzFile gzFile) { int i = 0; utilGzRead(gzFile, &i, sizeof(int)); return i; } void utilReadData(gzFile gzFile, variable_desc* data) { while(data->address) { utilGzRead(gzFile, data->address, data->size); data++; } } void utilReadDataSkip(gzFile gzFile, variable_desc* data) { while(data->address) { utilGzSeek(gzFile, data->size, SEEK_CUR); data++; } } void utilWriteData(gzFile gzFile, variable_desc *data) { while(data->address) { utilGzWrite(gzFile, data->address, data->size); data++; } } gzFile utilGzOpen(const char *file, const char *mode) { utilGzWriteFunc = (int (ZEXPORT *)(void *,void * const, unsigned int))gzwrite; utilGzReadFunc = gzread; utilGzCloseFunc = gzclose; utilGzSeekFunc = gzseek; return gzopen(file, mode); } gzFile utilMemGzOpen(char *memory, int available, const char *mode) { utilGzWriteFunc = memgzwrite; utilGzReadFunc = memgzread; utilGzCloseFunc = memgzclose; return memgzopen(memory, available, mode); } int utilGzWrite(gzFile file, const voidp buffer, unsigned int len) { return utilGzWriteFunc(file, buffer, len); } int utilGzRead(gzFile file, voidp buffer, unsigned int len) { return utilGzReadFunc(file, buffer, len); } int utilGzClose(gzFile file) { return utilGzCloseFunc(file); } z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence) { return utilGzSeekFunc(file, offset, whence); } long utilGzMemTell(gzFile file) { return memtell(file); }