static void destroy(RomMapperGIde* rm) { int portBase; portBase = (boardGetType() == BOARD_SVI) ? 0x40:0x60; ioPortUnregister(portBase | 0x04); ioPortUnregister(portBase | 0x05); ioPortUnregister(portBase | 0x06); ioPortUnregister(portBase | 0x07); ioPortUnregister(portBase | 0x08); ioPortUnregister(portBase | 0x09); ioPortUnregister(portBase | 0x0a); ioPortUnregister(portBase | 0x0b); ioPortUnregister(portBase | 0x0c); ioPortUnregister(portBase | 0x0d); ioPortUnregister(portBase | 0x0e); ioPortUnregister(portBase | 0x0f); deviceManagerUnregister(rm->deviceHandle); debugDeviceUnregister(rm->debugHandle); harddiskIdeDestroy(rm->hdide); free(rm); }
void joystickPortUpdateBoardInfo() { int i; BoardType boardType = boardGetType(); memset(&joystickConfig, 0, sizeof(joystickConfig)); switch (boardType) { case BOARD_MSX: for (i = 0; i < 2; i++) { joystickConfig.typeEnabled[i][JOYSTICK_PORT_NONE] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_JOYSTICK] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_MOUSE] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_TETRIS2DONGLE] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_GUNSTICK] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_MAGICKEYDONGLE] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_ASCIILASER] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_ARKANOID_PAD] = 1; joystickConfig.defaultType[i] = JOYSTICK_PORT_NONE; } joystickConfig.keyboardEnabled = 1; break; case BOARD_SG1000: case BOARD_SVI: for (i = 0; i < 2; i++) { joystickConfig.typeEnabled[i][JOYSTICK_PORT_NONE] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_JOYSTICK] = 1; joystickConfig.defaultType[i] = JOYSTICK_PORT_NONE; } joystickConfig.keyboardEnabled = 1; break; case BOARD_COLECO: for (i = 0; i < 2; i++) { joystickConfig.typeEnabled[i][JOYSTICK_PORT_COLECOJOYSTICK] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_SUPERACTION] = 1; joystickConfig.typeEnabled[i][JOYSTICK_PORT_STEERINGWHEEL] = 1; joystickConfig.defaultType[i] = JOYSTICK_PORT_COLECOJOYSTICK; } joystickConfig.keyboardEnabled = 0; break; case BOARD_MSX_FORTE_II: joystickConfig.typeEnabled[0][JOYSTICK_PORT_JOYSTICK] = 1; joystickConfig.defaultType[0] = JOYSTICK_PORT_JOYSTICK; joystickConfig.keyboardEnabled = 1; break; default: break; } for (i = 0; i < JOYSTICK_MAX_PORTS; i++) { if (!joystickPortTypeEnabled(i, inputType[i])) { joystickPortSetType(i, joystickConfig.defaultType[i]); } } }
int romMapperCasetteCreate(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperCasette* rm; int pages = size / 0x2000; int i; if (pages == 0 || (startPage + pages) > 8) { return 0; } rm = malloc(sizeof(RomMapperCasette)); rm->deviceHandle = deviceManagerRegister(ROM_CASPATCH, &callbacks, rm); slotRegister(slot, sslot, startPage, pages, NULL, NULL, NULL, destroy, rm); rm->romData = malloc(size); memcpy(rm->romData, romData, size); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; if (boardGetType() == BOARD_SVI) { // Patch the SVI-328 BIOS and BASIC for cassette handling for (i = 0; patchAddressSVI[i]; i++) { UInt8* ptr = rm->romData + patchAddressSVI[i]; ptr[0] = 0xed; ptr[1] = 0xfe; ptr[2] = 0xc9; } rm->romData[0x2073]=0x01; // Skip delay loop after save rm->romData[0x20D0]=0x10; // Write $55 only $10 times, instead rm->romData[0x20D1]=0x00; // of $190 rm->romData[0x20E3]=0x00; // Cancel instruction rm->romData[0x20E4]=0x00; rm->romData[0x20E5]=0x00; rm->romData[0x20E6]=0xED; rm->romData[0x20E7]=0xFE; } else { // Patch the casette rom for (i = 0; patchAddress[i]; i++) { UInt8* ptr = rm->romData + patchAddress[i]; ptr[0] = 0xed; ptr[1] = 0xfe; ptr[2] = 0xc9; } } for (i = 0; i < pages; i++) { slotMapPage(slot, sslot, i + startPage, rm->romData + 0x2000 * i, 1, 0); } return 1; }
int romMapperGIdeCreate(int hdId) { DeviceCallbacks callbacks = { (DeviceCallback)destroy, (DeviceCallback)reset, (DeviceCallback)saveState, (DeviceCallback)loadState }; DebugCallbacks dbgCallbacks = { (void(*)(void*,DbgDevice*))getDebugInfo, NULL, NULL, NULL }; RomMapperGIde* rm; int portBase; rm = malloc(sizeof(RomMapperGIde)); rm->deviceHandle = deviceManagerRegister(ROM_GIDE, &callbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_PORT, langDbgDevIdeGide(), &dbgCallbacks, rm); portBase = (boardGetType() == BOARD_SVI) ? 0x40:0x60; ioPortRegister(portBase | 0x04, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x05, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x06, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x07, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x08, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x09, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x0a, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x0b, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x0c, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x0d, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x0e, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); ioPortRegister(portBase | 0x0f, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); rm->hdide = harddiskIdeCreate(diskGetHdDriveId(hdId, 0)); reset(rm); return 1; }
/** * \fn guiPlay(BoardSize size) * \brief This function is the main game loop * \details Function that create a new game, perform the game loop and display the game with SDL * \param size Variable representing the size of the Board (Small, Medium or Large) */ int guiPlay(BoardSize size) { /*******************/ /** VARIABLES **/ /*******************/ /***** SDL Variables *****/ SDL_Event event; //Variable to capture mouse/keyboard events SDL_Surface* screen;//Buffer that will contain the pixels to render on the screen /***** General Variables *****/ Assets assets; //Variable that will contain all the assets used in the game Timer timer; //Variable used to control the actions based on the time /***** Structure Variables *****/ bool continueGameMove1, continueGameMove2; //Variable used to check if the snake x is dead bool snake1InDebuff, snake2InDebuff; Game game; //Variable to access the game Board board; //Variable to access the board Snake snake1; //Variable to access the first snake Snake snake2; //Variable to access the first snake /************************/ /** INITIALIZATION **/ /************************/ /***** SDL Initialization *****/ SDL_Init(SDL_INIT_VIDEO); //Initialization of the SDL Library TTF_Init(); SDL_WM_SetCaption("Larasnake", NULL); //Set the title and icon name of the displayed window screen = guiCreateScreen(size); /***** General Variables *****/ srand(time(NULL)); //Initialization of the random function timer = guiCreateTimer(); assets = guiLoadAssets(size); /***** Structure Variables *****/ continueGameMove1 = true; continueGameMove2 = true; snake1InDebuff = false; snake2InDebuff = false; game = gameCreate(size); board = gameGetBoard(game); guiSetFieldType(game, assets, size); snake1 = gameGetSnake(game, 1); snake2 = gameGetSnake(game, 2); //music of the game Mix_Music *musiqueGame = Mix_LoadMUS("./sound/musiqueGame.mp3"); //music of the game Mix_PlayMusic(musiqueGame, -1); //loop --PLAY HERE Mix_VolumeMusic(MIX_MAX_VOLUME / 6); //half of the maximum sound /************************/ /** GAME LOOP **/ /************************/ gameFeed(game, true); //first ham appeared while (gameGetIsPlaying(game)) { timer->start = SDL_GetTicks(); // Start of the current frame guiEvent(&event, snake1, game); // catch player event and set the direction of snake1 if(!gameGetIsPaused(game)) { if(gameGetPauseTimer(game)==0) //know if we don't leave the pause { if(boardGetType(board)) //if we have to change the background { boardSetType(board, false); //disable change flag guiChangeBackground(screen, assets,size); guiSetFieldType(game, assets, size); printf("MAP CHANGED\n"); //the map is now changed } ////// Move of snake 1 (player) ////// timer->snake1MoveTimer += SDL_GetTicks() - timer->snake1LastMove; if (timer->snake1MoveTimer >= snakeGetSpeed(snake1)) { // test if we wait enough time to move the snake 1 continueGameMove1 = gameMoveSnake(game, snake1); // move th snake1. if snake1 is dead continueGameMove1=false timer->snake1MoveTimer = 0; // set the move timer to 0 when the snake move } timer->snake1LastMove = SDL_GetTicks(); ///////////////////////////////////// ////// Move of snake 2 (AI) ////// timer->snake2MoveTimer += SDL_GetTicks() - timer->snake2LastMove; if (timer->snake2MoveTimer >= snakeGetSpeed(snake2)) { // test if we wait enough time to move the snake 2 snakeSetDirection(snake2, iaSurviveDepth(board, snake2, snake1)); // let ia choose the best direction of snake2 continueGameMove2 = gameMoveSnake(game, snake2); // move the snake2. if snake2 is dead continueGameMove2=false timer->snake2MoveTimer = 0; // set the move timer to 0 when the snake move } timer->snake2LastMove = SDL_GetTicks(); ///////////////////////////////// ///////////////// Debuff snake1 ///////////////// if (!itemListIsEmpty(snakeGetItemList(snake1))) { if (!snake1InDebuff) { snake1InDebuff = true; timer->snake1LastDebuff = SDL_GetTicks(); } else { timer->snake1DebuffTimer += SDL_GetTicks() - timer->snake1LastDebuff; if(timer->snake1DebuffTimer >= ITEM_DEBUFF_INTERVAL) { gameItemDebuff(snakeGetItemList(snake1)->next, snake1); snake1InDebuff = false; timer->snake1DebuffTimer = 0; } timer->snake1LastDebuff = SDL_GetTicks(); } } //////////////////////////////////////////////// ///////////////// Debuff snake2 ///////////////// if (!itemListIsEmpty(snakeGetItemList(snake2))) { if (!snake2InDebuff) { snake2InDebuff = true; timer->snake2LastDebuff = SDL_GetTicks(); } else { timer->snake2DebuffTimer += SDL_GetTicks() - timer->snake2LastDebuff; if(timer->snake2DebuffTimer >= ITEM_DEBUFF_INTERVAL) { gameItemDebuff(snakeGetItemList(snake2)->next, snake2); snake2InDebuff = false; timer->snake2DebuffTimer = 0; } timer->snake2LastDebuff = SDL_GetTicks(); } } //////////////////////////////////////////////// ///////// Item pop ///////// timer->itemPopTimer += SDL_GetTicks() - timer->itemLastPop; if(timer->itemPopTimer >= ITEM_POP_INTERVAL) { gameFeed(game, false); //Function called to put some food on the board timer->itemPopTimer = 0; } timer->itemLastPop = SDL_GetTicks(); ///////// Item pop ///////// //>>>>>>> 43afef4547198632093d7b891941aa8c99643d24 } } /////// Draw /////// guiDrawGame(screen, game, assets, size); // draw the board on screen with surfaces stored in the Assets struct guiReloadScreen(screen); // reload all the screen //boardDisplay(board); /////////////////// if(!continueGameMove1 || !continueGameMove2) // if one snake die the game is over gameEnd(game); ////// Framerate management ////// timer->end = SDL_GetTicks(); // Get the time after the calculations timer->delay = FRAME_MS - (timer->end - timer->start); // Calculate how long to delay should be if(timer->delay > 0) { SDL_Delay(timer->delay); // Delay processing } } int idWinner; if(continueGameMove1) { if(snakeGetId(snake1) == 1) idWinner = 1; else idWinner = 2; } else { if(snakeGetId(snake1) == 1) idWinner = 2; else idWinner = 1; } ////// Free ////// gameFree(game); guiFreeAssets(assets); Mix_FreeMusic(musiqueGame); //free the music //TTF_Quit(); //SDL_Quit(); return idWinner; }