From 1c5f82ed325e26ae4f05c0184a65c989943620b2 Mon Sep 17 00:00:00 2001 From: AnonymusRaccoon Date: Tue, 11 Feb 2020 14:37:42 +0100 Subject: [PATCH] Creating a real main --- main.cpp | 31 +++++++++---------------------- sources/APU/APU.cpp | 4 ++-- sources/APU/APU.hpp | 2 +- sources/CPU/CPU.cpp | 4 ++-- sources/CPU/CPU.hpp | 2 +- sources/PPU/PPU.cpp | 2 +- sources/PPU/PPU.hpp | 2 +- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/main.cpp b/main.cpp index 36cc9e6..61bc972 100644 --- a/main.cpp +++ b/main.cpp @@ -16,29 +16,16 @@ int main(int argc, char **argv) std::cout << "ComSquare:" << std::endl << "\tUsage: " << argv[0] << " rom_path" << std::endl; return 1; } - Memory::MemoryBus bus; - Renderer::SFRenderer renderer(600, 800, 60); - SNES snes(std::make_shared(bus), argv[1], renderer); - bus.mapComponents(snes); - int incx = 0; - int incy = 0; - uint32_t pixel = 0x000000FF; - - while (!renderer.shouldExit) { - renderer.putPixel(incy, incx++, pixel); - if (incx >= 800) { - incx = 0; - incy++; + try { + Renderer::SFRenderer renderer(600, 800, 60); + SNES snes(std::make_shared(), argv[1], renderer); + while (!renderer.shouldExit) { + unsigned cycleCount = snes.cpu->update(); + snes.ppu->update(cycleCount); + snes.apu->update(cycleCount); } - if (incy >= 600) { - incy = 0; - } - if (incx == 0) { - renderer.drawScreen(); - pixel += 0xFF00FF00; - } - renderer.getEvents(); + } catch (std::exception &e) { + std::cerr << "An error occurred: " << e.what() << std::endl; } - return 0; } \ No newline at end of file diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp index cdf06f4..a1e1f43 100644 --- a/sources/APU/APU.cpp +++ b/sources/APU/APU.cpp @@ -47,8 +47,8 @@ namespace ComSquare::APU } } - bool APU::update() + bool APU::update(unsigned cycles) { - throw NotImplementedException(); + (void)cycles; } } diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp index 6c67a8f..c0bff99 100644 --- a/sources/APU/APU.hpp +++ b/sources/APU/APU.hpp @@ -125,7 +125,7 @@ namespace ComSquare::APU //! @param data The new value of the register. //! @throw InvalidAddress will be thrown if the address is more than $FF (the number of register). void write(uint24_t addr, uint8_t data) override; - bool update(); + bool update(unsigned cycles); }; } diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index b0ed691..3bd6ded 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -184,9 +184,9 @@ namespace ComSquare::CPU } } - int CPU::update() + unsigned CPU::update() { - int cycles = 0; + unsigned cycles = 0; for (int i = 0; i < 0xFF; i++) cycles += this->executeInstruction(); diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index 13977a6..3f5a86f 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -216,7 +216,7 @@ namespace ComSquare::CPU explicit CPU(std::shared_ptr bus, Cartridge::Header &cartridgeHeader); //! @brief This function continue to execute the Cartridge code. //! @return The number of CPU cycles that elapsed - int update(); + unsigned update(); //! @brief Read from the internal CPU register. //! @param addr The address to read from. The address 0x0 should refer to the first byte of the register. //! @throw InvalidAddress will be thrown if the address is more than $1F (the number of register). diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 32bd47a..df40b39 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -70,7 +70,7 @@ namespace ComSquare::PPU } } - void PPU::update(int cycles) + void PPU::update(unsigned cycles) { (void)cycles; } diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index 702b7bc..0537100 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -392,7 +392,7 @@ namespace ComSquare::PPU void write(uint24_t addr, uint8_t data) override; //! @brief Update the PPU of n cycles. //! @param The number of cycles to update. - void update(int cycles); + void update(unsigned cycles); }; } #endif //COMSQUARE_PPU_HPP