From fd1c80b52f24b185feda6763ff22df08139f2178 Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Thu, 6 Jan 2011 13:49:53 +1000 Subject: [PATCH] TETRIS title screen and demo work!!! --- GameboyGraphics.cc | 0 GameboyGraphics.hh | 66 +++++++++++++++++++++++++++++++++++++++ GameboyJoypad.cc | 0 GameboyJoypad.hh | 0 Log.cc | 0 Log.hh | 0 Main.cc | 0 Memory.cc => MemoryMap.cc | 0 Memory.hh => MemoryMap.hh | 0 RAM.cc | 55 ++++++++++++++++++++++++++++++++ RAM.hh | 56 +++++++++++++++++++++++++++++++++ ROM.cc | 22 +++++++++++++ ROM.hh | 25 +++++++++++++++ 13 files changed, 224 insertions(+) create mode 100644 GameboyGraphics.cc create mode 100644 GameboyGraphics.hh create mode 100644 GameboyJoypad.cc create mode 100644 GameboyJoypad.hh create mode 100644 Log.cc create mode 100644 Log.hh create mode 100644 Main.cc rename Memory.cc => MemoryMap.cc (100%) rename Memory.hh => MemoryMap.hh (100%) create mode 100644 RAM.cc create mode 100644 RAM.hh create mode 100644 ROM.cc create mode 100644 ROM.hh diff --git a/GameboyGraphics.cc b/GameboyGraphics.cc new file mode 100644 index 0000000..e69de29 diff --git a/GameboyGraphics.hh b/GameboyGraphics.hh new file mode 100644 index 0000000..18afd1c --- /dev/null +++ b/GameboyGraphics.hh @@ -0,0 +1,66 @@ +#ifndef MM80_GAMEBOYGRAPHICS_HH +#define MM80_GAMEBOYGRAPHICS_HH + +#include "mm80.hh" + +#include "MemoryMap.hh" + + +class GameboyGraphics +{ +public: + void renderScanLine(); + +private: + // Graphics system operates with 8x8 pixel tiles. There is space for 384 + // tiles. 256 tiles map be used in a map. Map 1 uses tile numbers 0 to 255, + // other uses -128 to 127. + // There are 2 maps held in memory, but only one displayed at a time. + // 0x8000 - 0x87FF: Tile Set #1: 0 - 127. + // 0x8800 - 0x8FFF: Tile Set #1: 128-255. Tile Set #0: -1 to -128 + // 0x9000 - 0x97FF: Tile Set #0: tiles 0-127 + // 0x9800 - 0x9BFF: Tile map #0 + // 0x9C00 - 0x9FFF: Tile map #1 + std::tr1::shared_ptr m_vram; + + enum SpriteOptions + { + SPRITE_PALETTE = 0x10, // 0 = Pallete #0, 1 = Pallete #2 + SPRITE_XFLIP = 0x20, // 0 = Normal, 1 = flip. + SPRITE_YFLIP = 0x40, // 0 = Normal, 1 = flip + SPRITE_PRIORITY = 0x80 // 0 = Above Background, 1 = Below background + // (background colour 0 == transparent) + }; + + struct __attribute__ ((packed)) Sprite + { + uint8_t y; // Y-coordinate - 16 + uint8_t x; // X-coordinate - 8 + uint8_t tile; // Tile number + uint8_t options; + } + + // Object Attribute Memory (Up to 40 sprites), as per Sprite struct. + std::tr1::shared_ptr m_oam; // 0xFE00 - 0xFE9F + + struct __attribute__((packed)) Registers + { + uint8_t LCDC; + uint8_t STAT; + uint8_t SCY; + uint8_t SCX; + uint8_t LY; + uint8_t LYC; + uint8_t DMA; + uint8_t OBP0; + uint8_t OBP1; + uint8_t WY; + uint8_t WX; + }; + + // Memory-mapped IO Registers + std::tr1::shared_ptr m_reg; +}; + +#endif + diff --git a/GameboyJoypad.cc b/GameboyJoypad.cc new file mode 100644 index 0000000..e69de29 diff --git a/GameboyJoypad.hh b/GameboyJoypad.hh new file mode 100644 index 0000000..e69de29 diff --git a/Log.cc b/Log.cc new file mode 100644 index 0000000..e69de29 diff --git a/Log.hh b/Log.hh new file mode 100644 index 0000000..e69de29 diff --git a/Main.cc b/Main.cc new file mode 100644 index 0000000..e69de29 diff --git a/Memory.cc b/MemoryMap.cc similarity index 100% rename from Memory.cc rename to MemoryMap.cc diff --git a/Memory.hh b/MemoryMap.hh similarity index 100% rename from Memory.hh rename to MemoryMap.hh diff --git a/RAM.cc b/RAM.cc new file mode 100644 index 0000000..dfd546a --- /dev/null +++ b/RAM.cc @@ -0,0 +1,55 @@ +/** + * Flat memory-model emulation. + * + * Authors: Michael McMaster + * Copyright: Michael McMaster + */ + +#include "mm80.hh" +#include "Memory.hh" + +using namespace mm80; + +Memory::Memory(address_t initialSize) +{ + m_mem.resize(initialSize); +} + +uint8_t +Memory::read8(DWORD address, int8_t offset) +{ + return m_mem[address.host() + offset]; +} + +DWORD +Memory::read16(DWORD address, int8_t offset) +{ + return CreateDWORD(&m_mem[address.host() + offset]); +} + +void +Memory::write8(DWORD address, uint8_t value) +{ + m_mem[address.host()] = value; +} + +void +Memory::write8(DWORD address, int8_t offset, uint8_t value) +{ + m_mem[address.host() + offset] = value; +} + +void +Memory::write16(DWORD address, DWORD value) +{ + m_mem[address.host()] = value.l; + m_mem[address.host() + 1] = value.h; +} + +void +Memory::write16(DWORD address, int8_t offset, DWORD value) +{ + m_mem[address.host() + offset] = value.l; + m_mem[address.host() + offset + 1] = value.h; +} + diff --git a/RAM.hh b/RAM.hh new file mode 100644 index 0000000..8f82353 --- /dev/null +++ b/RAM.hh @@ -0,0 +1,56 @@ +/** + * Flat memory-model emulation. + * + * Authors: Michael McMaster + * Copyright: Michael McMaster + */ + +#ifndef MM80_MEMORYMAP_HH +#define MM80_MEMORYMAP_HH + +#include "mm80.hh" +#include "DWORD.hh" + +#include +#include +namespace mm80 +{ + +class MemoryMap +{ +public: + class Memory + { + public: + virtual ~Memory; + + uint8_t read8(DWORD address) = 0; + void write8(DWORD address, uint8_t value) = 0; + }; + + Memory(); + + void map( + address_t base, + address_t size, + const std::tr1::shared_ptr& mem + ); + + uint8_t read8(DWORD address, int8_t offset = 0); + void write8(DWORD address, uint8_t value); + void write8(DWORD address, int8_t offset, uint8_t value); + + DWORD read16(DWORD address, int8_t offset = 0); + void write16(DWORD address, DWORD value); + void write16(DWORD address, int8_t offset, DWORD value); + +private: + + std::vector m_map; + std::vector m_mem; +}; + +} // namespace mm80 + +#endif + diff --git a/ROM.cc b/ROM.cc new file mode 100644 index 0000000..4c3f03d --- /dev/null +++ b/ROM.cc @@ -0,0 +1,22 @@ +#include "mm80.hh" +#include "RAM.hh" + +using namespace mm80; + +RAM::RAM(uint16_t size) +{ + m_mem.resize(size); +} + +uint8_t +RAM::read8(uint16_t address) +{ + return m_mem[address]; +} + +void +RAM::write8(uint16_t address, uint8_t value) +{ + m_mem[address] = value; +} + diff --git a/ROM.hh b/ROM.hh new file mode 100644 index 0000000..812bfc7 --- /dev/null +++ b/ROM.hh @@ -0,0 +1,25 @@ +#ifndef MM80_RAM_HH +#define MM80_RAM_HH + +#include "mm80.hh" +#include "MemoryMap.hh" + +#include +namespace mm80 +{ + +class ROM : public MemoryMap::Memory +{ +public: + RAM(uint16_t size); + virtual uint8_t read8(uint16_t address) = 0; + virtual void write8(uint16_t address, uint8_t value) = 0; + +private: + std::vector m_mem; +}; + +} // namespace mm80 + +#endif + -- 2.38.5