diff --git a/old/Application.cpp b/old/Application.cpp deleted file mode 100644 index 553b77b..0000000 --- a/old/Application.cpp +++ /dev/null @@ -1,339 +0,0 @@ -#include "Application.h" - -#include "resource.h" - -void Application::Run(const List& args) -{ - Application *a = get(); - - a->window = new GLWindow("Chips8TheSalsa", false); - a->window->AddEventHandler(windowEventHandler); - a->menu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1)); - a->window->SetMenu(a->menu); - - a->zoom = 8; - a->reflectZoom(); - - a->chip8 = new Chip8(); - - if (args.Count() >= 1) a->loadAndStartRom(args[0]); - - const string cfgFileName("config.bin"); - a->loadSettings(cfgFileName); - - a->reflectSettingsInMenu(); - - while (a->window->IsOpen()) - { - glViewport(0, 0, a->window->GetWidth(), a->window->GetHeight()); - - a->chip8->Update(); - a->window->Update(); - Sleep(1); - } - - a->saveSettings(cfgFileName); -} - -Application *Application::get() -{ - static Application a; - return &a; -} - -void Application::windowEventHandler(Window& w, int event, WPARAM wParam, LPARAM lParam) -{ - Application *a = get(); - - static char keyChars[] = { 'X', '1', '2', '3', 'Q', 'W', 'E', 'A', 'S', 'D', 'Z', 'C', '4', 'R', 'F', 'V' }; - - switch (event) - { - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case ID_FILE_LOADROM: - { - char *fileName = new char[MAX_PATH]; - for (int i = 0; i < MAX_PATH; i++) fileName[i] = 0; - OPENFILENAME ofn = - { - sizeof(OPENFILENAME), - a->window->GetHandle(), - 0, - "All Files (*.*)\0*.*\0", - 0, 0, - 1, - fileName, - MAX_PATH, - 0, 0, 0, - "Load ROM Image", - 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - if (GetOpenFileName(&ofn)) - { - a->loadAndStartRom(fileName); - } - delete [] fileName; - } - break; - - case ID_FILE_EXIT: - a->window->Close(); - break; - - case ID_SYSTEM_RESET: - a->chip8->Reset(); - if (a->chip8->HasRom()) a->chip8->Start(); - break; - - case ID_AUDIO_ENABLED: - a->chip8->SetAudioEnabled(!a->chip8->GetAudioEnabled()); - break; - - case ID_LATENCY_50MS: - a->chip8->SetAudioLatencyMs(50); - break; - - case ID_LATENCY_100MS: - a->chip8->SetAudioLatencyMs(100); - break; - - case ID_LATENCY_250MS: - a->chip8->SetAudioLatencyMs(250); - break; - - case ID_LATENCY_500MS: - a->chip8->SetAudioLatencyMs(500); - break; - - case ID_LATENCY_1000MS: - a->chip8->SetAudioLatencyMs(1000); - break; - - case ID_ZOOM_1X1: - a->zoom = 1; - a->reflectZoom(); - break; - - case ID_ZOOM_2X2: - a->zoom = 2; - a->reflectZoom(); - break; - - case ID_ZOOM_4X4: - a->zoom = 4; - a->reflectZoom(); - break; - - case ID_ZOOM_8X8: - a->zoom = 8; - a->reflectZoom(); - break; - - case ID_ZOOM_16X16: - a->zoom = 16; - a->reflectZoom(); - break; - - case ID_ZOOM_32X32: - a->zoom = 32; - a->reflectZoom(); - break; - - case ID_SPEED_1INSTRUCTION: - a->chip8->SetSpeed(1); - break; - - case ID_SPEED_2INSTRUCTIONS: - a->chip8->SetSpeed(2); - break; - - case ID_SPEED_5INSTRUCTIONS: - a->chip8->SetSpeed(5); - break; - - case ID_SPEED_10INSTRUCTIONS: - a->chip8->SetSpeed(10); - break; - - case ID_SPEED_20INSTRUCTIONS: - a->chip8->SetSpeed(20); - break; - - case ID_SPEED_50INSTRUCTIONS: - a->chip8->SetSpeed(50); - break; - - case ID_SPEED_100INSTRUCTIONS: - a->chip8->SetSpeed(100); - break; - - case ID_SPEED_200INSTRUCTIONS: - a->chip8->SetSpeed(200); - break; - - case ID_SPEED_500INSTRUCTIONS: - a->chip8->SetSpeed(500); - break; - - case ID_SPEED_1000INSTRUCTIONS: - a->chip8->SetSpeed(1000); - break; - - case ID_HELP_ABOUT: - MessageBox(a->window->GetHandle(), "Chips8TheSalsa\n\nA Chip-8 emulator for Windows. What a piece of shit this system is :D . Ah well, it was fun as hell to code.\n\nThe key layout is a bit strange; it's a 16-key hex keyboard that's mapped like this:\n123C\n456D\n789E\nA0BF\n\nand corresponds to the following keys:\n1234\nQWER\nASDF\nZXCV\n\nHave fun :)\n\n(C) 2012 Jake \"Ferris\" Taylor\nhttp://yupferris.blogspot.com\nyupferris@gmail.com", "About Chips8TheSalsa", MB_OK); - break; - } - - a->reflectSettingsInMenu(); - break; - - case WM_KEYDOWN: - { - if (wParam == VK_ESCAPE) - { - a->window->Close(); - } - else - { - for (int i = 0; i < 16; i++) - { - if (wParam == keyChars[i]) - { - a->chip8->SetInput(i, true); - break; - } - } - } - } - break; - - case WM_KEYUP: - { - for (int i = 0; i < 16; i++) - { - if (wParam == keyChars[i]) - { - a->chip8->SetInput(i, false); - break; - } - } - } - break; - } -} - -void Application::reflectZoom() -{ - window->SetSize(64 * zoom, 32 * zoom); -} - -void Application::reflectSettingsInMenu() -{ - CheckMenuItem(menu, ID_AUDIO_ENABLED, chip8->GetAudioEnabled() ? MF_CHECKED : MF_UNCHECKED); - int l = chip8->GetAudioLatencyMs(); - CheckMenuItem(menu, ID_LATENCY_50MS, (l == 50) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_LATENCY_100MS, (l == 100) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_LATENCY_250MS, (l == 250) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_LATENCY_500MS, (l == 500) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_LATENCY_1000MS, (l == 1000) ? MF_CHECKED : MF_UNCHECKED); - - CheckMenuItem(menu, ID_ZOOM_1X1, (zoom == 1) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_ZOOM_2X2, (zoom == 2) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_ZOOM_4X4, (zoom == 4) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_ZOOM_8X8, (zoom == 8) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_ZOOM_16X16, (zoom == 16) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_ZOOM_32X32, (zoom == 32) ? MF_CHECKED : MF_UNCHECKED); - - int s = chip8->GetSpeed(); - CheckMenuItem(menu, ID_SPEED_1INSTRUCTION, (s == 1) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_2INSTRUCTIONS, (s == 2) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_5INSTRUCTIONS, (s == 5) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_10INSTRUCTIONS, (s == 10) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_20INSTRUCTIONS, (s == 20) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_50INSTRUCTIONS, (s == 50) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_100INSTRUCTIONS, (s == 100) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_200INSTRUCTIONS, (s == 200) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_500INSTRUCTIONS, (s == 500) ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, ID_SPEED_1000INSTRUCTIONS, (s == 1000) ? MF_CHECKED : MF_UNCHECKED); -} - -void Application::loadAndStartRom(string fileName) -{ - chip8->Reset(); - chip8->LoadRom(fileName); - chip8->Start(); -} - -void Application::setWorkingDirectory() -{ - char *cd = new char[MAX_PATH]; - for (int i = 0; i < MAX_PATH; i++) cd[i] = 0; - GetModuleFileName(0, cd, MAX_PATH); - for (int i = MAX_PATH - 1; i >= 0; i--) - { - if (cd[i] == '\\' || cd[i] == '/') - { - cd[i] = 0; - break; - } - } - SetCurrentDirectory(cd); - delete [] cd; -} - -typedef struct -{ - int AudioEnabled; - int AudioLatencyMs; - int Zoom; - int Speed; -} settings; - -void Application::loadSettings(string fileName) -{ - try - { - setWorkingDirectory(); - - ifstream input(fileName, ios::binary | ios::ate); - if (input.fail()) throw EXCEPTION("Could not open config file."); - - int size = (int) input.tellg(); - if (size != sizeof(settings)) throw EXCEPTION("Invalid settings format."); - - input.seekg(0); - settings s; - input.read((char *) &s, size); - input.close(); - - chip8->SetAudioEnabled(s.AudioEnabled != 0); - chip8->SetAudioLatencyMs(s.AudioLatencyMs); - zoom = s.Zoom; - reflectZoom(); - chip8->SetSpeed(s.Speed); - } - catch (const Exception&) { } -} - -void Application::saveSettings(string fileName) -{ - try - { - setWorkingDirectory(); - - ofstream output(fileName, ios::binary); - if (output.fail()) throw new EXCEPTION("Could not open config file."); - - settings s; - s.AudioEnabled = chip8->GetAudioEnabled() ? 1 : 0; - s.AudioLatencyMs = chip8->GetAudioLatencyMs(); - s.Zoom = zoom; - s.Speed = chip8->GetSpeed(); - output.write((char *) &s, sizeof(settings)); - - output.close(); - } - catch (const Exception&) { } -} diff --git a/old/Application.h b/old/Application.h deleted file mode 100644 index bb5d17c..0000000 --- a/old/Application.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __APPLICATION_H__ -#define __APPLICATION_H__ - -#include "Common.h" -#include "List.h" -#include "GLWindow.h" -#include "Chip8.h" - -class Application -{ -public: - static void Run(const List& args); - -private: - static Application *get(); - - static void windowEventHandler(Window& w, int event, WPARAM wParam, LPARAM lParam); - void reflectZoom(); - void reflectSettingsInMenu(); - - void loadAndStartRom(string fileName); - - void setWorkingDirectory(); - void loadSettings(string fileName); - void saveSettings(string fileName); - - GLWindow *window; - HMENU menu; - int zoom; - Chip8 *chip8; -}; - -#endif diff --git a/old/Apu.cpp b/old/Apu.cpp deleted file mode 100644 index 3ea551e..0000000 --- a/old/Apu.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "Apu.h" - -#include - -Apu::Apu(int latencyMs) -{ - audioStream = new AudioStream(renderRouter, this, latencyMs); - - enabled = true; - beeping = false; - beepPhase = 0.0; -} - -Apu::~Apu() -{ - delete audioStream; -} - -void Apu::Update() -{ - audioStream->Update(); -} - -void Apu::SetLatencyMs(int latencyMs) -{ - audioStream->SetLatencyMs(latencyMs); -} - -int Apu::GetLatencyMs() const -{ - return audioStream->GetLatencyMs(); -} - -void Apu::SetEnabled(bool enabled) -{ - this->enabled = enabled; -} - -bool Apu::GetEnabled() const -{ - return enabled; -} - -void Apu::SetBeeping(bool value) -{ - beeping = value; -} - -void Apu::render(AudioFormat::Sample *buffer, int length) -{ - for (int i = 0; i < length; i++) - { - int s = -10000; - if (enabled && beeping) - { - if (sin(beepPhase) > 0.0) s = 10000; - beepPhase += .02; - } - buffer[i] = (AudioFormat::Sample) s; - } -} - -void Apu::renderRouter(AudioFormat::Sample *buffer, int length, void *apu) -{ - ((Apu *)apu)->render(buffer, length); -} diff --git a/old/Apu.h b/old/Apu.h deleted file mode 100644 index 83f7dce..0000000 --- a/old/Apu.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __APU_H__ -#define __APU_H__ - -#include "Common.h" -#include "AudioFormat.h" -#include "AudioStream.h" - -class Apu -{ -public: - Apu(int latencyMs = 100); - ~Apu(); - - void Update(); - - void SetLatencyMs(int latencyMs); - int GetLatencyMs() const; - void SetEnabled(bool enabled); - bool GetEnabled() const; - void SetBeeping(bool value); - -private: - void render(AudioFormat::Sample *buffer, int length); - static void renderRouter(AudioFormat::Sample *buffer, int length, void *apu); - - AudioStream *audioStream; - - bool enabled; - bool beeping; - double beepPhase; -}; - -#endif diff --git a/old/AudioFormat.h b/old/AudioFormat.h deleted file mode 100644 index 2e3a40d..0000000 --- a/old/AudioFormat.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __AUDIO_FORMAT_H__ -#define __AUDIO_FORMAT_H__ - -class AudioFormat -{ -public: - static const int SampleRate = 44100; - static const int Channels = 2; - static const int BitsPerSample = 16; - static const int BlockAlign = Channels * BitsPerSample / 8; - static const int BytesPerSec = SampleRate * BlockAlign; - - typedef short Sample; -}; - -#endif diff --git a/old/AudioStream.cpp b/old/AudioStream.cpp deleted file mode 100644 index dfdb253..0000000 --- a/old/AudioStream.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "AudioStream.h" - -AudioStream::AudioStream(RenderCallback renderCallback, void *userData, int latencyMs) -{ - this->latencyMs = latencyMs; - this->renderCallback = renderCallback; - this->userData = userData; - - init(); -} - -AudioStream::~AudioStream() -{ - free(); -} - -void AudioStream::Update() -{ - int playCursorPos; - buffer->GetCurrentPosition((LPDWORD) &playCursorPos, 0); - int bytesToRender = playCursorPos - oldPlayCursorPos; - if (bytesToRender) - { - if (bytesToRender < 0) bytesToRender += bufferSizeBytes; - AudioFormat::Sample *p1, *p2; - int b1, b2; - if (buffer->Lock(oldPlayCursorPos, bytesToRender, (LPVOID *) &p1, (LPDWORD) &b1, (LPVOID *) &p2, (LPDWORD) &b2, 0) != DS_OK) throw EXCEPTION("Could not lock buffer."); - renderCallback(p1, b1 / sizeof(AudioFormat::Sample), userData); - if (b2) renderCallback(p2, b2 / sizeof(AudioFormat::Sample), userData); - if (buffer->Unlock(p1, b1, p2, b2) != DS_OK) throw EXCEPTION("Could not unlock buffer."); - oldPlayCursorPos = playCursorPos; - } -} - -void AudioStream::SetLatencyMs(int latencyMs) -{ - if (this->latencyMs == latencyMs) return; - free(); - this->latencyMs = latencyMs; - init(); -} - -int AudioStream::GetLatencyMs() const -{ - return latencyMs; -} - -void AudioStream::init() -{ - bufferSizeBytes = AudioFormat::SampleRate * AudioFormat::BlockAlign * latencyMs / 1000; - - if (DirectSoundCreate8(0, &device, 0) != DS_OK) throw EXCEPTION("Could not create device."); - if (device->SetCooperativeLevel(GetForegroundWindow(), DSSCL_NORMAL) != DS_OK) throw EXCEPTION("Could not set device priority."); - - WAVEFORMATEX bufferFormat = - { - WAVE_FORMAT_PCM, - AudioFormat::Channels, - AudioFormat::SampleRate, - AudioFormat::BytesPerSec, - AudioFormat::BlockAlign, - AudioFormat::BitsPerSample, - 0 - }; - DSBUFFERDESC bufferDesc = - { - sizeof(DSBUFFERDESC), - DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2, - bufferSizeBytes, - 0, - &bufferFormat, - GUID_NULL - }; - if (device->CreateSoundBuffer(&bufferDesc, &buffer, 0) != DS_OK) throw EXCEPTION("Could not create secondary buffer."); - - oldPlayCursorPos = 0; - if (buffer->Play(0, 0, DSBPLAY_LOOPING) != DS_OK) throw EXCEPTION("Could not start buffer playback."); -} - -void AudioStream::free() -{ - buffer->Stop(); - buffer->Release(); - device->Release(); -} diff --git a/old/AudioStream.h b/old/AudioStream.h deleted file mode 100644 index af24048..0000000 --- a/old/AudioStream.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __AUDIO_STREAM__ -#define __AUDIO_STREAM__ - -#include "Common.h" -#include "AudioFormat.h" - -#include - -class AudioStream -{ -public: - typedef void (* RenderCallback)(AudioFormat::Sample *buffer, int length, void *userData); - - AudioStream(RenderCallback renderCallback, void *userData, int latencyMs = 100); - ~AudioStream(); - - void Update(); - - void SetLatencyMs(int latencyMs); - int GetLatencyMs() const; - -private: - void init(); - void free(); - - int latencyMs; - int bufferSizeBytes; - - RenderCallback renderCallback; - void *userData; - - LPDIRECTSOUND8 device; - LPDIRECTSOUNDBUFFER buffer; - int oldPlayCursorPos; -}; - -#endif diff --git a/old/Chip8.cpp b/old/Chip8.cpp deleted file mode 100644 index 99c3809..0000000 --- a/old/Chip8.cpp +++ /dev/null @@ -1,434 +0,0 @@ -#include "Chip8.h" - -#include "Random.h" -#include "Timer.h" - -unsigned char Chip8::charMem[] = -{ - 0xf0, 0x90, 0x90, 0x90, 0xf0, // 0 - 0x20, 0x60, 0x20, 0x20, 0x70, // 1 - 0xf0, 0x10, 0xf0, 0x80, 0xf0, // 2 - 0xf0, 0x10, 0xf0, 0x10, 0xf0, // 3 - 0x90, 0x90, 0xf0, 0x10, 0x10, // 4 - 0xf0, 0x80, 0xf0, 0x10, 0xf0, // 5 - 0xf0, 0x80, 0xf0, 0x90, 0xf0, // 6 - 0xf0, 0x10, 0x20, 0x40, 0x40, // 7 - 0xf0, 0x90, 0xf0, 0x90, 0xf0, // 8 - 0xf0, 0x90, 0xf0, 0x10, 0xf0, // 9 - 0xf0, 0x90, 0xf0, 0x90, 0x90, // a - 0xe0, 0x90, 0xe0, 0x90, 0xe0, // b - 0xf0, 0x80, 0x80, 0x80, 0xf0, // c - 0xe0, 0x90, 0x90, 0x90, 0xe0, // d - 0xf0, 0x80, 0xf0, 0x80, 0xf0, // e - 0xf0, 0x80, 0xf0, 0x80, 0x80, // f -}; - -Chip8::Chip8() -{ - Random::Seed(timeGetTime()); - ram = new unsigned char[4096]; - rom = 0; - romSize = 0; - stack = new Stack(16); - speed = 20; - Reset(); -} - -Chip8::~Chip8() -{ - delete [] ram; - if (rom) delete rom; - delete stack; -} - -void Chip8::Reset() -{ - pc = 0x200; - for (int i = 0; i < 16; i++) regs[i] = 0; - iReg = 0; - timerDelay = 0; - timerSound = 0; - for (int i = 0; i < 4096; i++) ram[i] = Random::NextInt() & 255; - for (int i = 0; i < 16 * 5; i++) ram[i] = charMem[i]; - for (int i = 0; i < 16; i++) inputs[i] = false; - gpu.Clear(); - apu.SetBeeping(false); - running = false; - waitingForKeypress = false; -} - -void Chip8::LoadRom(string fileName) -{ - try - { - ifstream input(fileName, ios::binary | ios::ate); - if (input.fail()) throw EXCEPTION("Could not load ROM image."); - int size = (int) input.tellg(); - if (size > 3584) throw EXCEPTION("ROM image is too large."); - romSize = size; - if (rom) delete rom; - rom = new unsigned char[romSize]; - input.seekg(0); - input.read((char *) rom, romSize); - input.close(); - } - catch (const Exception& e) - { - MessageBox(0, e.GetMsg().c_str(), "Chip8 Error", MB_OK); - } -} - -bool Chip8::HasRom() const -{ - return rom != 0; -} - -void Chip8::Start() -{ - if (running) throw EXCEPTION("Emulator already running."); - if (rom) - { - for (int i = 0; i < romSize; i++) ram[i + 0x200] = rom[i]; - } - running = true; - timer = Timer::GetTime(); -} - -void Chip8::Update() -{ - if (!running) return; - int t = 16 - (Timer::GetTime() - timer); - if (t < 1) t = 1; - Sleep(t); - timer = Timer::GetTime(); - - try - { - if (timerDelay > 0) timerDelay--; - if (timerSound > 0) - { - timerSound--; - apu.SetBeeping(timerSound > 0); - } - - int keyPressReg = 0; - for (int i = 0; i < speed; i++) - { - if (waitingForKeypress) - { - for (int j = 0; j < 16; j++) - { - if (GetInput(j)) - { - regs[keyPressReg] = j; - waitingForKeypress = false; - break; - } - } - continue; - } - - if (pc < 0 || pc >= 4095) throw EXCEPTION("PC out of bounds."); - unsigned short opcode = (ram[pc] << 8) | ram[pc + 1]; - pc += 2; - - int h = (opcode >> 12) & 0xf; - int x = (opcode >> 8) & 0xf; - int y = (opcode >> 4) & 0xf; - int n = opcode & 0xf; - int nn = opcode & 0xff; - int nnn = opcode & 0xfff; - - switch (h) - { - case 0: - if (opcode & 0x0f00) - { - // SYS addr (ignored) - } - else if(opcode == 0x00e0) - { - // CLS - gpu.Clear(); - } - else if (opcode == 0x00ee) - { - // RET - pc = stack->Pop(); - } - else - { - invalidOpcode(); - } - break; - - case 1: - // JP addr - pc = nnn; - break; - - case 2: - // CALL addr - stack->Push(pc); - pc = nnn; - break; - - case 3: - // SE Vx, byte - if (regs[x] == nn) pc += 2; - break; - - case 4: - // SNE Vx, byte - if (regs[x] != nn) pc += 2; - break; - - case 5: - if (n) invalidOpcode(); - - // SE Vx, Vy - if (regs[x] == regs[y]) pc += 2; - break; - - case 6: - // LD Vx, byte - regs[x] = nn; - break; - - case 7: - // ADD Vx, byte - regs[x] += nn; - break; - - case 8: - switch (opcode & 0xf) - { - case 0: - // LD Vx, Vy - regs[x] = regs[y]; - break; - - case 1: - // OR Vx, Vy - regs[x] |= regs[y]; - break; - - case 2: - // AND Vx, Vy - regs[x] &= regs[y]; - break; - - case 3: - // XOR Vx, Vy - regs[x] ^= regs[y]; - break; - - case 4: - { - // ADD Vx, Vy - int result = regs[x] + regs[y]; - regs[15] = (result > 255) ? 1 : 0; - regs[x] = result; - } - break; - - case 5: - // SUB Vx, Vy - regs[15] = (regs[x] < regs[y]) ? 0 : 1; - regs[x] -= regs[y]; - break; - - case 6: - // SHR Vx - regs[15] = regs[x] & 1; - regs[x] >>= 1; - break; - - case 7: - // SUBN Vx, Vy - regs[15] = (regs[y] < regs[x]) ? 0 : 1; - regs[x] = regs[y] - regs[x]; - break; - - case 0xe: - // SHL Vx - regs[15] = (regs[x] >> 7) & 1; - regs[x] <<= 1; - break; - - default: - invalidOpcode(); - } - break; - - case 9: - // SNE Vx, Vy - if (regs[x] != regs[y]) pc += 2; - break; - - case 0xa: - // LD i, addr - iReg = nnn; - break; - - case 0xb: - // JP V0, addr - pc = nnn + regs[0]; - break; - - case 0xc: - // RND Vx, byte - regs[x] = Random::NextInt() & nn; - break; - - case 0xd: - // DRW Vx, Vy, nibble - regs[15] = gpu.DrawSprite(regs[x], regs[y], ram + iReg, n); - break; - - case 0xe: - if (nn == 0x9e) - { - // SKP Vx - if (GetInput(regs[x])) pc += 2; - } - else if (nn == 0xa1) - { - // SKNP Vx - if (!GetInput(regs[x])) pc += 2; - } - else - { - invalidOpcode(); - } - break; - - case 0xf: - switch (nn) - { - case 0x07: - // LD Vx, DT - regs[x] = timerDelay; - break; - - case 0x0a: - // LD Vx, K - keyPressReg = x; - waitingForKeypress = true; - break; - - case 0x15: - // LD DT, Vx - timerDelay = regs[x]; - break; - - case 0x18: - // LD ST, Vx - timerSound = regs[x]; - break; - - case 0x1e: - // ADD I, Vx - iReg += regs[x]; - break; - - case 0x29: - // LD F, Vx - iReg = regs[x] * 5; - break; - - case 0x33: - { - // LD B, Vx - char c = regs[x]; - ram[iReg + 2] = c % 10; - ram[iReg + 1] = (c / 10) % 10; - ram[iReg] = (c / 100) % 10; - } - break; - - case 0x55: - { - // LD [I], Vx - for (int i = 0; i <= x; i++) ram[iReg + i] = regs[i]; - iReg += x + 1; - } - break; - - case 0x65: - { - // LD Vx, [I] - for (int i = 0; i <= x; i++) regs[i] = ram[iReg + i]; - iReg += x + 1; - } - break; - - default: - invalidOpcode(); - } - break; - - default: - invalidOpcode(); - } - } - } - catch (const Exception& e) - { - MessageBox(0, e.GetMsg().c_str(), "Chip8 Error", MB_OK); - running = false; - } - - gpu.Update(); - apu.Update(); -} - -bool Chip8::IsRunning() const -{ - return running; -} - -void Chip8::SetInput(int index, bool value) -{ - inputs[index & 0xf] = value; -} - -bool Chip8::GetInput(int index) -{ - return inputs[index & 0xf]; -} - -void Chip8::invalidOpcode() -{ - throw EXCEPTION("Invalid opcode."); -} - -void Chip8::SetSpeed(int speed) -{ - this->speed = speed; -} - -int Chip8::GetSpeed() const -{ - return speed; -} - -void Chip8::SetAudioEnabled(bool enabled) -{ - apu.SetEnabled(enabled); -} - -bool Chip8::GetAudioEnabled() const -{ - return apu.GetEnabled(); -} - -void Chip8::SetAudioLatencyMs(int latencyMs) -{ - apu.SetLatencyMs(latencyMs); -} - -int Chip8::GetAudioLatencyMs() const -{ - return apu.GetLatencyMs(); -} diff --git a/old/Chip8.h b/old/Chip8.h deleted file mode 100644 index 8524495..0000000 --- a/old/Chip8.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __CHIP8_H__ -#define __CHIP8_H__ - -#include "Common.h" -#include "Stack.h" -#include "Gpu.h" -#include "Apu.h" - -class Chip8 -{ -public: - Chip8(); - ~Chip8(); - - void Reset(); - void LoadRom(string fileName); - bool HasRom() const; - void Start(); - void Update(); - bool IsRunning() const; - void SetInput(int index, bool value); - bool GetInput(int index); - - void SetSpeed(int speed); - int GetSpeed() const; - void SetAudioEnabled(bool enabled); - bool GetAudioEnabled() const; - void SetAudioLatencyMs(int latencyMs); - int GetAudioLatencyMs() const; - -private: - static void invalidOpcode(); - - unsigned short pc; - unsigned char regs[16]; - unsigned short iReg; - unsigned char timerDelay; - unsigned char timerSound; - unsigned char *ram; - unsigned char *rom; - int romSize; - static unsigned char charMem[]; - Stack *stack; - bool inputs[16]; - Gpu gpu; - Apu apu; - bool running; - bool waitingForKeypress; - int speed; - unsigned int timer; -}; - -#endif diff --git a/old/Chips8TheSalsa.sln b/old/Chips8TheSalsa.sln deleted file mode 100644 index 13a1321..0000000 --- a/old/Chips8TheSalsa.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chips8TheSalsa", "Chips8TheSalsa.vcxproj", "{3D03B383-6E4E-4F31-B499-F428B47916FA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3D03B383-6E4E-4F31-B499-F428B47916FA}.Debug|Win32.ActiveCfg = Debug|Win32 - {3D03B383-6E4E-4F31-B499-F428B47916FA}.Debug|Win32.Build.0 = Debug|Win32 - {3D03B383-6E4E-4F31-B499-F428B47916FA}.Release|Win32.ActiveCfg = Release|Win32 - {3D03B383-6E4E-4F31-B499-F428B47916FA}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/old/Chips8TheSalsa.vcxproj b/old/Chips8TheSalsa.vcxproj deleted file mode 100644 index 54c7f15..0000000 --- a/old/Chips8TheSalsa.vcxproj +++ /dev/null @@ -1,120 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {3D03B383-6E4E-4F31-B499-F428B47916FA} - Win32Proj - Chips8TheSalsa - - - - Application - true - NotSet - - - Application - false - true - NotSet - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - opengl32.lib;winmm.lib;dsound.lib;%(AdditionalDependencies) - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - MultiThreaded - - - Windows - true - true - true - opengl32.lib;winmm.lib;dsound.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/old/Chips8TheSalsa.vcxproj.filters b/old/Chips8TheSalsa.vcxproj.filters deleted file mode 100644 index 62ebfbb..0000000 --- a/old/Chips8TheSalsa.vcxproj.filters +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/old/Common.h b/old/Common.h deleted file mode 100644 index ad4b0c8..0000000 --- a/old/Common.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __COMMON_H__ -#define __COMMON_H__ - -#include -#include -#include -#include -using namespace std; - -#include -#include - -#include "Exception.h" - -#endif diff --git a/old/Exception.cpp b/old/Exception.cpp deleted file mode 100644 index 748969b..0000000 --- a/old/Exception.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Exception.h" - -using namespace std; - -Exception::Exception(const string& msg, const string& file, int line) -{ - this->msg = msg; - this->file = file; - this->line = line; -} - -string Exception::GetMsg() const -{ - return msg; -} - -string Exception::GetFile() const -{ - return file; -} - -int Exception::GetLine() const -{ - return line; -} diff --git a/old/Exception.h b/old/Exception.h deleted file mode 100644 index 4ae2046..0000000 --- a/old/Exception.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __EXCEPTION_H__ -#define __EXCEPTION_H__ - -#include - -class Exception -{ -public: - Exception(const std::string& msg, const std::string& file, int line); - std::string GetMsg() const; - std::string GetFile() const; - int GetLine() const; - -private: - std::string msg, file; - int line; -}; - -#define EXCEPTION(x) Exception((x), __FILE__, __LINE__) - -#endif diff --git a/old/Final/Chips8TheSalsa-bin.zip b/old/Final/Chips8TheSalsa-bin.zip deleted file mode 100644 index 1da81a1..0000000 Binary files a/old/Final/Chips8TheSalsa-bin.zip and /dev/null differ diff --git a/old/Final/Chips8TheSalsa-src.zip b/old/Final/Chips8TheSalsa-src.zip deleted file mode 100644 index 4eb0fc1..0000000 Binary files a/old/Final/Chips8TheSalsa-src.zip and /dev/null differ diff --git a/old/Final/Chips8TheSalsa.exe b/old/Final/Chips8TheSalsa.exe deleted file mode 100644 index fe6e510..0000000 Binary files a/old/Final/Chips8TheSalsa.exe and /dev/null differ diff --git a/old/GLWindow.cpp b/old/GLWindow.cpp deleted file mode 100644 index 2e89a28..0000000 --- a/old/GLWindow.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "GLWindow.h" - -GLWindow::GLWindow(): Window() -{ - -} - -GLWindow::GLWindow(string title, bool fullscreen, int w, int h, int style) -{ - Open(title, fullscreen, w, h, style); -} - -GLWindow::~GLWindow() -{ - Close(); -} - -void GLWindow::Open(string title, bool fullscreen, int w, int h, int style) -{ - Window::Open(title, fullscreen, w, h, style); - dc = GetDC(handle); - - PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), - 1, - PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, - PFD_TYPE_RGBA, - 32, - 0, 0, 0, 0, 0, 0, - 0, // No alpha buffer - 0, - 0, // No accumulation buffer - 0, 0, 0, 0, - 24, // 24-bit z buffer - 0, // No stencil buffer - 0, // No auxilary buffer - PFD_MAIN_PLANE, - 0, 0, 0, 0 - }; - SetPixelFormat(dc, ChoosePixelFormat(dc, &pfd), &pfd); - rc = wglCreateContext(dc); - wglMakeCurrent(dc, rc); -} - -void GLWindow::Close() -{ - if (open) - { - wglMakeCurrent(NULL, NULL); - wglDeleteContext(rc); - ReleaseDC(handle, dc); - } - Window::Close(); -} - -void GLWindow::Update() -{ - Window::Update(); - SwapBuffers(dc); -} diff --git a/old/GLWindow.h b/old/GLWindow.h deleted file mode 100644 index 6b5569d..0000000 --- a/old/GLWindow.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __GLWINDOW_H__ -#define __GLWINDOW_H__ - -#include "Common.h" -#include "Window.h" - -class GLWindow: public Window -{ -public: - GLWindow(); - GLWindow(string title, bool fullscreen = false, int w = 800, int h = 600, int style = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); - ~GLWindow(); - virtual void Open(string title, bool fullscreen = false, int w = 800, int h = 600, int style = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); - virtual void Close(); - virtual void Update(); - -private: - HDC dc; - HGLRC rc; -}; - -#endif diff --git a/old/Gpu.cpp b/old/Gpu.cpp deleted file mode 100644 index d27681a..0000000 --- a/old/Gpu.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "Gpu.h" - -Gpu::Gpu() -{ - framebuffer = new unsigned int[64 * 32]; - Clear(); - texture = new Texture(64, 32, framebuffer); -} - -Gpu::~Gpu() -{ - delete [] framebuffer; - delete texture; -} - -void Gpu::Clear() -{ - for (int i = 0; i < 64 * 32; i++) framebuffer[i] = 0; -} - -void Gpu::Update() -{ - texture->SetData(framebuffer); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture->GetHandle()); - glColor3f(1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2i(0, 1); - glVertex2i(-1, -1); - glTexCoord2i(1, 1); - glVertex2i( 1, -1); - glTexCoord2i(1, 0); - glVertex2i( 1, 1); - glTexCoord2i(0, 0); - glVertex2i(-1, 1); - glEnd(); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); -} - -int Gpu::DrawSprite(int x, int y, unsigned char *buf, int n) -{ - int ret = 0; - for (int i = 0; i < n; i++) - { - if (y >= 0 && y < 32) - { - unsigned char c = buf[i]; - for (int j = 0; j < 8; j++) - { - if ((c >> (7 - j)) & 1) - { - int bi = y * 64 + ((x + j) & 63); - if (framebuffer[bi] != 0) - { - framebuffer[bi] = 0; - ret = 1; - } - else - { - framebuffer[bi] = 0xffffffff; - } - } - } - } - y++; - } - return ret; -} diff --git a/old/Gpu.h b/old/Gpu.h deleted file mode 100644 index 26bcfb5..0000000 --- a/old/Gpu.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __GPU_H__ -#define __GPU_H__ - -#include "Common.h" -#include "Texture.h" - -class Gpu -{ -public: - Gpu(); - ~Gpu(); - - void Clear(); - void Update(); - int DrawSprite(int x, int y, unsigned char *buf, int n); - -private: - unsigned int *framebuffer; - Texture *texture; -}; - -#endif diff --git a/old/List.h b/old/List.h deleted file mode 100644 index 08935ea..0000000 --- a/old/List.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef __LIST_H__ -#define __LIST_H__ - -#include "Common.h" - -template class List -{ -public: - List() - { - size = count = 0; - data = 0; - } - - ~List() - { - Clear(); - } - - bool Contains(const T& item) - { - for (int i = 0; i < count; i++) - { - if (data[i] == item) return true; - } - return false; - } - - void Add(const T& item) - { - if (Contains(item)) throw EXCEPTION("List already contains the given item."); - count++; - ensureCapacity(); - data[count - 1] = item; - } - - void Remove(const T& item) - { - for (int i = 0; i < count; i++) - { - if (data[i] == item) - { - Remove(i); - return; - } - } - throw EXCEPTION("List does not contain the given item."); - } - - void Insert(int index, const T& item) - { - if (Contains(item)) throw EXCEPTION("List already contains the given item."); - count++; - ensureCapacity(); - for (int i = count - 1; i >= index; i--) data[i + 1] = data[i]; - data[index] = item; - } - - void Remove(int index) - { - if (index < 0 || index >= count) throw EXCEPTION("List does not contain the given index."); - count--; - for (int i = index; i <= count; i++) data[i] = data[i + 1]; - } - - void RemoveRange(int start, int end) - { - for (int i = 0; i < end - start; i++) Remove(start); - } - - int Count() const - { - return count; - } - - void Clear() - { - size = count = 0; - if (data) delete [] data; - } - - T& At(int index) const - { - if (index < 0 || index >= count) throw EXCEPTION("List does not contain the given index."); - return data[index]; - } - - T& operator [](int index) const - { - if (index < 0 || index >= count) throw EXCEPTION("List does not contain the given index."); - return data[index]; - } - -private: - void ensureCapacity() - { - if (count > size) - { - T *newData = new T[count]; - for (int i = 0; i < size; i++) newData[i] = data[i]; - size = count; - if (data) delete [] data; - data = newData; - } - } - - int size, count; - T *data; -}; - -#endif diff --git a/old/Random.cpp b/old/Random.cpp deleted file mode 100644 index 5fae9e0..0000000 --- a/old/Random.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "Random.h" - -void Random::Seed(int seed) -{ - srand(seed); -} - -int Random::NextInt() -{ - return rand(); -} diff --git a/old/Random.h b/old/Random.h deleted file mode 100644 index 5042dd2..0000000 --- a/old/Random.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __RANDOM_H__ -#define __RANDOM_H__ - -#include "Common.h" - -class Random -{ -public: - static void Seed(int seed); - static int NextInt(); -}; - -#endif diff --git a/old/Resource.rc b/old/Resource.rc deleted file mode 100644 index ba843f5..0000000 Binary files a/old/Resource.rc and /dev/null differ diff --git a/old/Stack.h b/old/Stack.h deleted file mode 100644 index 94bfddb..0000000 --- a/old/Stack.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __STACK_H__ -#define __STACK_H__ - -template class Stack -{ -public: - Stack(int size) - { - data = new T[size]; - this->size = size; - index = 0; - } - - ~Stack() - { - delete [] data; - } - - void Push(T item) - { - if (index >= size) throw EXCEPTION("Stack overflow occurred."); - data[index] = item; - index++; - } - - T Pop() - { - if (index <= 0) throw EXCEPTION("Stack underflow occurred."); - index--; - return data[index]; - } - -private: - T *data; - int size; - int index; -}; - -#endif diff --git a/old/Test/15PUZZLE b/old/Test/15PUZZLE deleted file mode 100644 index 3ef0bc8..0000000 Binary files a/old/Test/15PUZZLE and /dev/null differ diff --git a/old/Test/BLINKY b/old/Test/BLINKY deleted file mode 100644 index 235cf98..0000000 Binary files a/old/Test/BLINKY and /dev/null differ diff --git a/old/Test/BLITZ b/old/Test/BLITZ deleted file mode 100644 index 0d2effa..0000000 Binary files a/old/Test/BLITZ and /dev/null differ diff --git a/old/Test/BRIX b/old/Test/BRIX deleted file mode 100644 index ad639d9..0000000 Binary files a/old/Test/BRIX and /dev/null differ diff --git a/old/Test/CONNECT4 b/old/Test/CONNECT4 deleted file mode 100644 index 200a67a..0000000 Binary files a/old/Test/CONNECT4 and /dev/null differ diff --git a/old/Test/GUESS b/old/Test/GUESS deleted file mode 100644 index 36f783d..0000000 Binary files a/old/Test/GUESS and /dev/null differ diff --git a/old/Test/HIDDEN b/old/Test/HIDDEN deleted file mode 100644 index bd6b18d..0000000 Binary files a/old/Test/HIDDEN and /dev/null differ diff --git a/old/Test/INVADERS b/old/Test/INVADERS deleted file mode 100644 index f7db5f5..0000000 Binary files a/old/Test/INVADERS and /dev/null differ diff --git a/old/Test/KALEID b/old/Test/KALEID deleted file mode 100644 index a1bc7cc..0000000 Binary files a/old/Test/KALEID and /dev/null differ diff --git a/old/Test/MAZE b/old/Test/MAZE deleted file mode 100644 index 152ae7d..0000000 Binary files a/old/Test/MAZE and /dev/null differ diff --git a/old/Test/MERLIN b/old/Test/MERLIN deleted file mode 100644 index 747843a..0000000 Binary files a/old/Test/MERLIN and /dev/null differ diff --git a/old/Test/MISSILE b/old/Test/MISSILE deleted file mode 100644 index 310e2de..0000000 Binary files a/old/Test/MISSILE and /dev/null differ diff --git a/old/Test/PONG b/old/Test/PONG deleted file mode 100644 index e371e91..0000000 Binary files a/old/Test/PONG and /dev/null differ diff --git a/old/Test/PONG2 b/old/Test/PONG2 deleted file mode 100644 index 295ce91..0000000 Binary files a/old/Test/PONG2 and /dev/null differ diff --git a/old/Test/PUZZLE b/old/Test/PUZZLE deleted file mode 100644 index bec7af0..0000000 Binary files a/old/Test/PUZZLE and /dev/null differ diff --git a/old/Test/SYZYGY b/old/Test/SYZYGY deleted file mode 100644 index b0653ef..0000000 Binary files a/old/Test/SYZYGY and /dev/null differ diff --git a/old/Test/TANK b/old/Test/TANK deleted file mode 100644 index ca4bbab..0000000 Binary files a/old/Test/TANK and /dev/null differ diff --git a/old/Test/TETRIS b/old/Test/TETRIS deleted file mode 100644 index 9f5e087..0000000 Binary files a/old/Test/TETRIS and /dev/null differ diff --git a/old/Test/TICTAC b/old/Test/TICTAC deleted file mode 100644 index 4d4bc99..0000000 Binary files a/old/Test/TICTAC and /dev/null differ diff --git a/old/Test/UFO b/old/Test/UFO deleted file mode 100644 index 7fa5a15..0000000 Binary files a/old/Test/UFO and /dev/null differ diff --git a/old/Test/VBRIX b/old/Test/VBRIX deleted file mode 100644 index 07f4006..0000000 Binary files a/old/Test/VBRIX and /dev/null differ diff --git a/old/Test/VERS b/old/Test/VERS deleted file mode 100644 index b0fe240..0000000 Binary files a/old/Test/VERS and /dev/null differ diff --git a/old/Test/WIPEOFF b/old/Test/WIPEOFF deleted file mode 100644 index 2d5e513..0000000 Binary files a/old/Test/WIPEOFF and /dev/null differ diff --git a/old/Texture.cpp b/old/Texture.cpp deleted file mode 100644 index 0e40129..0000000 --- a/old/Texture.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "Texture.h" - -Texture::Texture(int width, int height, void *data, GLenum intFormat) -{ - this->width = width; - this->height = height; - glGenTextures(1, &handle); - SetData(data, intFormat); - glBindTexture(GL_TEXTURE_2D, handle); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glBindTexture(GL_TEXTURE_2D, 0); -} - -Texture::~Texture() -{ - glDeleteTextures(1, &handle); -} - -GLuint Texture::GetHandle() const -{ - return handle; -} - -int Texture::GetWidth() const -{ - return width; -} - -int Texture::GetHeight() const -{ - return height; -} - -void Texture::SetData(void *data, GLenum intFormat) -{ - glBindTexture(GL_TEXTURE_2D, handle); - glTexImage2D(GL_TEXTURE_2D, 0, intFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - glBindTexture(GL_TEXTURE_2D, 0); -} diff --git a/old/Texture.h b/old/Texture.h deleted file mode 100644 index 7cb1099..0000000 --- a/old/Texture.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __TEXTURE_H__ -#define __TEXTURE_H__ - -#include "Common.h" - -class Texture -{ -public: - Texture(int width, int height, void *data = 0, GLenum intFormat = GL_RGBA); - ~Texture(); - GLuint GetHandle() const; - int GetWidth() const; - int GetHeight() const; - void SetData(void *data, GLenum intFormat = GL_RGBA); - -private: - GLuint handle; - int width, height; -}; - -#endif diff --git a/old/Timer.cpp b/old/Timer.cpp deleted file mode 100644 index 7342fb2..0000000 --- a/old/Timer.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Timer.h" - -unsigned int Timer::GetTime() -{ - return timeGetTime(); -} diff --git a/old/Timer.h b/old/Timer.h deleted file mode 100644 index 8763a9a..0000000 --- a/old/Timer.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __TIMER_H__ -#define __TIMER_H__ - -#include "Common.h" - -class Timer -{ -public: - static unsigned int GetTime(); -}; - -#endif diff --git a/old/Window.cpp b/old/Window.cpp deleted file mode 100644 index 56b070e..0000000 --- a/old/Window.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "Window.h" - -#include "resource.h" - -const string ClassName = "Class"; - -Window::Window() -{ - open = false; -} - -Window::Window(string title, bool fullscreen, int w, int h, int style) -{ - Open(title, fullscreen, w, h, style); -} - -Window::~Window() -{ - Close(); -} - -void Window::Open(string title, bool fullscreen, int w, int h, int style) -{ - menu = 0; - instance = GetModuleHandle(NULL); - this->x = x; - this->y = y; - width = w; - height = h; - this->style = style; - this->fullscreen = fullscreen; - - AddEventHandler(defaultEventHandler); - - WNDCLASSEX wndClass = - { - sizeof(WNDCLASSEX), - 0, - WndProcRouter, - 0, - 0, - instance, - LoadIcon(instance, MAKEINTRESOURCE(IDI_ICON1)/*NULL, IDI_APPLICATION*/), - LoadCursor(NULL, IDC_ARROW), - (HBRUSH) COLOR_WINDOW, - NULL, - ClassName.c_str(), - NULL - }; - - if (!RegisterClassEx(&wndClass)) throw EXCEPTION("Could not register window class."); - if (fullscreen) - { - DEVMODE ss; - memset(&ss, 0, sizeof(DEVMODE)); - ss.dmSize = sizeof(DEVMODE); - ss.dmPelsWidth = w; - ss.dmPelsHeight = h; - ss.dmBitsPerPel = 32; - ss.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - if (ChangeDisplaySettings(&ss, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) throw EXCEPTION("Could not create fullscreen window."); - handle = CreateWindow(ClassName.c_str(), title.c_str(), WS_POPUP, 0, 0, w, h, NULL, NULL, instance, this); - ShowCursor(false); - } - else - { - RECT rect = { 0, 0, w, h }; - AdjustWindowRect(&rect, style, true); - handle = CreateWindow(ClassName.c_str(), title.c_str(), style, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, instance, this); - } - - if (!handle) throw EXCEPTION("Could not create window."); - ShowWindow(handle, SW_SHOWNORMAL); - SetForegroundWindow(handle); - SetFocus(handle); - open = true; - - SetSize(width, height); -} - -void Window::Close() -{ - DestroyWindow(handle); - UnregisterClass(ClassName.c_str(), instance); - open = false; -} - -void Window::Update() -{ - MSG msg; - while (PeekMessage(&msg, handle, 0, 0, PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} - -void Window::ClearEventHandlers() -{ - eventHandlers.Clear(); -} - -void Window::AddEventHandler(EventHandler eh) -{ - for (int i = 0; i < eventHandlers.Count(); i++) - { - if (eventHandlers[i] == eh) return; - } - eventHandlers.Add(eh); -} - -void Window::RaiseEvent(int event, WPARAM wParam, LPARAM lParam) -{ - for (int i = 0; i < eventHandlers.Count(); i++) eventHandlers[i](*this, event, wParam, lParam); -} - -void Window::SetTitle(string title) -{ - if (!open) return; - SetWindowText(handle, title.c_str()); -} - -void Window::SetSize(int w, int h) -{ - if (!open) return; - width = w; - height = h; - RECT rect = { 0, 0, w, h }; - AdjustWindowRect(&rect, style, menu != 0); - MoveWindow(handle, x, y, rect.right - rect.left, rect.bottom - rect.top, true); -} - -void Window::SetMenu(HMENU menu) -{ - if (!open) return; - ::SetMenu(handle, menu); - if (this->menu) DestroyMenu(this->menu); - this->menu = menu; - SetSize(width, height); -} - -bool Window::IsOpen() const -{ - return open; -} - -HWND Window::GetHandle() const -{ - return handle; -} - -int Window::GetWidth() const -{ - return width; -} - -int Window::GetHeight() const -{ - return height; -} - -float Window::GetAspectRatio() const -{ - return (float) width / (float) height; -} - -LRESULT CALLBACK Window::WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) -{ - RaiseEvent(Msg, wParam, lParam); - return DefWindowProc(hWnd, Msg, wParam, lParam); -} - -LRESULT CALLBACK Window::WndProcRouter(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) -{ - Window *w = 0; - - switch (Msg) - { - case WM_GETMINMAXINFO: - return DefWindowProc(hWnd, Msg, wParam, lParam); - - case WM_NCCREATE: - w = (Window *) ((LPCREATESTRUCT) lParam)->lpCreateParams; - w->handle = hWnd; - SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR) w); - break; - - default: - w = (Window *) GetWindowLong(hWnd, GWL_USERDATA); - } - if (!w) throw EXCEPTION("Window event router invoked without a window handle."); - - return w->WndProc(hWnd, Msg, wParam, lParam); -} - -void Window::defaultEventHandler(Window& w, int Event, WPARAM wParam, LPARAM lParam) -{ - switch (Event) - { - case WM_MOVE: - w.x = LOWORD(lParam); - w.y = HIWORD(lParam); - break; - - case WM_SIZE: - w.width = LOWORD(lParam); - w.height = HIWORD(lParam); - break; - - case WM_CLOSE: - PostQuitMessage(WM_QUIT); - w.open = false; - } -} diff --git a/old/Window.h b/old/Window.h deleted file mode 100644 index 72972dd..0000000 --- a/old/Window.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __WINDOW_H__ -#define __WINDOW_H__ - -#include "Common.h" -#include "List.h" - -class Window -{ -public: - typedef void (* EventHandler)(Window& w, int event, WPARAM wParam, LPARAM lParam); - - Window(); - Window(string title, bool fullscreen = false, int w = 800, int h = 600, int style = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); - ~Window(); - virtual void Open(string title, bool fullscreen = false, int w = 800, int h = 600, int style = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX); - virtual void Close(); - virtual void Update(); - virtual void ClearEventHandlers(); - virtual void AddEventHandler(EventHandler eh); - virtual void RaiseEvent(int Event, WPARAM wParam, LPARAM lParam); - virtual void SetTitle(string title); - virtual void SetSize(int w, int h); - virtual void SetMenu(HMENU menu); - virtual bool IsOpen() const; - virtual HWND GetHandle() const; - virtual int GetWidth() const; - virtual int GetHeight() const; - virtual float GetAspectRatio() const; - -protected: - virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); - static LRESULT CALLBACK WndProcRouter(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); - static void defaultEventHandler(Window& w, int Event, WPARAM wParam, LPARAM lParam); - bool open; - HWND handle; - HMENU menu; - HINSTANCE instance; - int x, y; - int width, height; - int style; - bool fullscreen; - List eventHandlers; -}; - -#endif diff --git a/old/icon.ico b/old/icon.ico deleted file mode 100644 index 2877cba..0000000 Binary files a/old/icon.ico and /dev/null differ diff --git a/old/icon.png b/old/icon.png deleted file mode 100644 index 78d1bcc..0000000 Binary files a/old/icon.png and /dev/null differ diff --git a/old/main.cpp b/old/main.cpp deleted file mode 100644 index e95fb9d..0000000 --- a/old/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Chips8TheSalsa -// A Chip-8 Emulator for Windows - -// (C) 2012 Jake "Ferris" Taylor - -#include "Common.h" -#include "List.h" -#include "Application.h" - -int main(int argc, char **argv) -{ - try - { - List args; - for (int i = 1; i < argc; i++) args.Add(string(argv[i])); - - Application::Run(args); - } - catch (const Exception& e) - { - MessageBox(0, e.GetMsg().c_str(), "Chips8TheSalsa Fatal Error", MB_OK | MB_ICONEXCLAMATION); - return 1; - } - - return 0; -} - -#ifdef WIN32 -INT WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int cmdShow) -{ - return main(__argc, __argv); -} -#endif diff --git a/old/resource.h b/old/resource.h deleted file mode 100644 index f8db539..0000000 Binary files a/old/resource.h and /dev/null differ