#include #include #include #include #include "audio/AudioPlayer.h" #include "audio/Music.h" #include "system/Timer.h" #include "system/Video.h" #include "graphics/Bitmap.h" #include "graphics/Font.h" #include "scenes/Scene.h" #include "system/Keyboard.h" #include "util/Files.h" #include "util/Gbm.h" #include "util/Log.h" volatile bool showFps = true; volatile bool running = true; uint8_t *loadMusicFile(const char *filename) { void *data = nullptr; Files::allocateBufferAndLoadFromFile(filename, &data); return static_cast(data); } int main() { __djgpp_nearptr_enable(); srand(time(nullptr)); DefaultLog.log("Loading music\n"); Music music("spiral.rad"); if (!music.isValid()) { printf("Unable to load song\n"); return 1; } DefaultLog.log("Playing music\n"); audioPlayer.playMusic(music); DefaultLog.log("Changing video mode\n"); video.Enter(); // Run scenes auto fb = static_cast(video.GetFB()); unsigned fps{0}; unsigned frameCount{0}; uint32_t fpsTick{0}; char fpsDigits[3]{'0', '0', 0}; auto fontBitmap = Gbm::loadFromFile("font1.gbm"); Font font(&fontBitmap, 7, 9, 32, 127); keyboard.setKeyDownHandler([] (unsigned char key) { DefaultLog.log("KeyDown %u (%s)\n", key, keyboard.getKeyName(key)); }); keyboard.setKeyUpHandler([] (unsigned char key) { DefaultLog.log("KeyUp %u (%s)\n", key, keyboard.getKeyName(key)); switch (key) { case KeyEscape: running = false; break; case KeyF: showFps = !showFps; break; default: // Do nothing break; } }); keyboard.setKeyRepeatHandler([](unsigned char key) { DefaultLog.log("KeyRepeat %u (%s)\n", key, keyboard.getKeyName(key)); }); while (running) { auto scene = Scenes::getCurrentScene(); scene->run(); // Render fps if (showFps) { ++frameCount; auto ticks = timer.getTicks(); if (ticks > fpsTick + 50) { fpsTick = ticks; fps = frameCount; frameCount = 0; fpsDigits[0] = '0' + (fps / 10) % 10; fpsDigits[1] = '0' + fps % 10; } font.renderChar(fpsDigits[0], 0, 0, 242, 0, fb, SCREEN_WIDTH, SCREEN_HEIGHT); font.renderChar(fpsDigits[1], 7, 0, 242, 0, fb, SCREEN_WIDTH, SCREEN_HEIGHT); video.UpdateRect({0, 0, 14, 9 }); } // Wait for vertical retrace and then copy render buffer to screen video.WaitForVerticalSync(); video.Flip(); } audioPlayer.stopMusic(); }