-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
700 additions
and
766 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sdl
updated
2426 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
target_sources(8ChocChip PRIVATE | ||
sdl.cpp | ||
sdl.h) | ||
Emulator.cpp | ||
Emulator.h | ||
MainMenu.cpp | ||
MainMenu.h | ||
InputHandler.cpp | ||
InputHandler.h | ||
Window.cpp | ||
Window.h | ||
) | ||
|
||
add_subdirectory(emulator) | ||
add_subdirectory(emulator) | ||
add_subdirectory(ui) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "Emulator.h" | ||
|
||
Emulator::Emulator(const std::string &rom) : cpu(&renderWrapper, &keyboard, &speaker), rom(rom) {} | ||
|
||
void Emulator::init() { | ||
Window::init(); | ||
|
||
if (this->rom.empty()) { | ||
std::cerr << "No ROM file has been specified :(" << std::endl; | ||
return; | ||
} | ||
|
||
std::ifstream file(this->rom, std::ios::binary | std::ios::ate); | ||
if (!file.good()) { | ||
std::cerr << "Can not find file " << this->rom << std::endl; | ||
return; | ||
} | ||
|
||
cpu.loadSpritesIntoMemory(); | ||
|
||
cpu.loadProgramIntoMemory(&file); | ||
} | ||
|
||
bool Emulator::handleEvent(SDL_Event& event) { | ||
if (!Window::handleEvent(event)) { | ||
return false; | ||
} | ||
|
||
switch (event.type) { | ||
case SDL_EVENT_KEY_DOWN: | ||
keyboard.handleKeyDown(event.key.scancode); | ||
break; | ||
case SDL_EVENT_KEY_UP: | ||
keyboard.handleKeyUp(event.key.scancode); | ||
break; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// void Emulator::focus() { | ||
// if (!mShown) { | ||
// SDL_ShowWindow(mWindow); | ||
// } | ||
// | ||
// SDL_RaiseWindow(mWindow); | ||
// } | ||
|
||
void Emulator::update() { | ||
// Run a cycle of the emulator | ||
this->cpu.cycle(); | ||
} | ||
|
||
void Emulator::render() { | ||
// Set renderer draw color | ||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 0); | ||
// Clear the window | ||
SDL_RenderClear(this->renderer); | ||
|
||
// Render the window | ||
this->renderWrapper.render(this->renderer); | ||
SDL_RenderPresent(this->renderer); | ||
|
||
SDL_Delay(16); | ||
} |
Oops, something went wrong.