Initial commit
This commit is contained in:
parent
9a85d09f29
commit
42328080e6
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
.sconsign.dblite
|
||||
laines
|
||||
*.o
|
||||
roms
|
||||
.nes
|
22
src/apu.cpp
22
src/apu.cpp
|
@ -5,46 +5,46 @@
|
|||
namespace APU {
|
||||
|
||||
|
||||
Nes_Apu apu;
|
||||
Blip_Buffer buf;
|
||||
//Nes_Apu apu;
|
||||
//Blip_Buffer buf;
|
||||
|
||||
const int OUT_SIZE = 4096;
|
||||
blip_sample_t outBuf[OUT_SIZE];
|
||||
//blip_sample_t outBuf[OUT_SIZE];
|
||||
|
||||
void init()
|
||||
/*void init()
|
||||
{
|
||||
buf.sample_rate(96000);
|
||||
buf.clock_rate(1789773);
|
||||
|
||||
apu.output(&buf);
|
||||
apu.dmc_reader(CPU::dmc_read);
|
||||
}
|
||||
}*/
|
||||
|
||||
void reset()
|
||||
/*void reset()
|
||||
{
|
||||
apu.reset();
|
||||
buf.clear();
|
||||
}
|
||||
}*/
|
||||
|
||||
template <bool write> u8 access(int elapsed, u16 addr, u8 v)
|
||||
{
|
||||
if (write)
|
||||
/*if (write)
|
||||
apu.write_register(elapsed, addr, v);
|
||||
else if (addr == apu.status_addr)
|
||||
v = apu.read_status(elapsed);
|
||||
v = apu.read_status(elapsed);*/
|
||||
|
||||
return v;
|
||||
}
|
||||
template u8 access<0>(int, u16, u8); template u8 access<1>(int, u16, u8);
|
||||
|
||||
void run_frame(int elapsed)
|
||||
/*void run_frame(int elapsed)
|
||||
{
|
||||
apu.end_frame(elapsed);
|
||||
buf.end_frame(elapsed);
|
||||
|
||||
if (buf.samples_avail() >= OUT_SIZE)
|
||||
GUI::new_samples(outBuf, buf.read_samples(outBuf, OUT_SIZE));
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "mappers/mapper2.hpp"
|
||||
#include "mappers/mapper3.hpp"
|
||||
#include "mappers/mapper4.hpp"
|
||||
#include "mappers/mapper7.hpp"
|
||||
#include "ppu.hpp"
|
||||
#include "cartridge.hpp"
|
||||
|
||||
|
@ -57,11 +58,12 @@ void load(const char* fileName)
|
|||
case 2: mapper = new Mapper2(rom); break;
|
||||
case 3: mapper = new Mapper3(rom); break;
|
||||
case 4: mapper = new Mapper4(rom); break;
|
||||
case 7: mapper = new Mapper7(rom); break;
|
||||
}
|
||||
|
||||
CPU::power();
|
||||
PPU::reset();
|
||||
APU::reset();
|
||||
//APU::reset();
|
||||
}
|
||||
|
||||
bool loaded()
|
||||
|
|
|
@ -275,7 +275,7 @@ void run_frame()
|
|||
exec();
|
||||
}
|
||||
|
||||
APU::run_frame(elapsed());
|
||||
//APU::run_frame(elapsed());
|
||||
}
|
||||
|
||||
|
||||
|
|
13
src/gui.cpp
13
src/gui.cpp
|
@ -1,7 +1,6 @@
|
|||
#include <csignal>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include "Sound_Queue.h"
|
||||
#include "apu.hpp"
|
||||
#include "cartridge.hpp"
|
||||
#include "cpu.hpp"
|
||||
|
@ -18,7 +17,7 @@ SDL_Texture* gameTexture;
|
|||
SDL_Texture* background;
|
||||
TTF_Font* font;
|
||||
u8 const* keys;
|
||||
Sound_Queue* soundQueue;
|
||||
//Sound_Queue* soundQueue;
|
||||
SDL_Joystick* joystick[] = { nullptr, nullptr };
|
||||
|
||||
// Menus:
|
||||
|
@ -51,9 +50,9 @@ void init()
|
|||
for (int i = 0; i < SDL_NumJoysticks(); i++)
|
||||
joystick[i] = SDL_JoystickOpen(i);
|
||||
|
||||
APU::init();
|
||||
soundQueue = new Sound_Queue;
|
||||
soundQueue->init(96000);
|
||||
//APU::init();
|
||||
//soundQueue = new Sound_Queue;
|
||||
//soundQueue->init(96000);
|
||||
|
||||
// Initialize graphics structures:
|
||||
window = SDL_CreateWindow ("LaiNES",
|
||||
|
@ -203,10 +202,10 @@ void new_frame(u32* pixels)
|
|||
SDL_UpdateTexture(gameTexture, NULL, pixels, WIDTH * sizeof(u32));
|
||||
}
|
||||
|
||||
void new_samples(const blip_sample_t* samples, size_t count)
|
||||
/*void new_samples(const blip_sample_t* samples, size_t count)
|
||||
{
|
||||
soundQueue->write(samples, count);
|
||||
}
|
||||
}*/
|
||||
|
||||
/* Render the screen */
|
||||
void render()
|
||||
|
|
|
@ -5,9 +5,9 @@ namespace APU {
|
|||
|
||||
|
||||
template <bool write> u8 access(int elapsed, u16 addr, u8 v = 0);
|
||||
void run_frame(int elapsed);
|
||||
void reset();
|
||||
void init();
|
||||
//void run_frame(int elapsed);
|
||||
//void reset();
|
||||
//void init();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <Nes_Apu.h>
|
||||
#include "common.hpp"
|
||||
|
||||
namespace GUI {
|
||||
|
@ -24,7 +23,7 @@ void render_texture(SDL_Texture* texture, int x, int y);
|
|||
|
||||
u8 get_joypad_state(int n);
|
||||
void new_frame(u32* pixels);
|
||||
void new_samples(const blip_sample_t* samples, size_t count);
|
||||
//void new_samples(const blip_sample_t* samples, size_t count);
|
||||
void set_size(int mul);
|
||||
|
||||
}
|
||||
|
|
19
src/include/mappers/mapper7.hpp
Normal file
19
src/include/mappers/mapper7.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
#include "mapper.hpp"
|
||||
#include "ppu.hpp"
|
||||
|
||||
class Mapper7 : public Mapper
|
||||
{
|
||||
u8 regs[1];
|
||||
void apply();
|
||||
|
||||
public:
|
||||
Mapper7(u8* rom) : Mapper(rom)
|
||||
{
|
||||
regs[0] = 0;
|
||||
apply();
|
||||
}
|
||||
|
||||
u8 write(u16 addr, u8 v);
|
||||
u8 chr_write(u16 addr, u8 v);
|
||||
};
|
|
@ -5,8 +5,7 @@ namespace PPU {
|
|||
|
||||
|
||||
enum Scanline { VISIBLE, POST, NMI, PRE };
|
||||
enum Mirroring { VERTICAL, HORIZONTAL };
|
||||
|
||||
enum Mirroring { VERTICAL, HORIZONTAL, ONE_SCREEN_HI, ONE_SCREEN_LO, FOUR_SCREEN };
|
||||
/* Sprite buffer */
|
||||
struct Sprite
|
||||
{
|
||||
|
|
|
@ -38,6 +38,8 @@ void Mapper1::apply()
|
|||
// Set mirroring:
|
||||
switch (regs[0] & 0b11)
|
||||
{
|
||||
case 0: set_mirroring(PPU::ONE_SCREEN_LO); break;
|
||||
case 1: set_mirroring(PPU::ONE_SCREEN_HI); break;
|
||||
case 2: set_mirroring(PPU::VERTICAL); break;
|
||||
case 3: set_mirroring(PPU::HORIZONTAL); break;
|
||||
}
|
||||
|
|
39
src/mappers/mapper7.cpp
Normal file
39
src/mappers/mapper7.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "ppu.hpp"
|
||||
#include "mappers/mapper7.hpp"
|
||||
|
||||
/* Based off of https://wiki.nesdev.com/w/index.php/AxROM */
|
||||
|
||||
/* Apply the registers state */
|
||||
void Mapper7::apply()
|
||||
{
|
||||
/*
|
||||
* 32 kb PRG ROM Banks
|
||||
* 0x8000 - 0xFFFF swappable
|
||||
*/
|
||||
map_prg<32>(0, regs[0] & 0b00001111);
|
||||
|
||||
/* 8k of CHR (ram) */
|
||||
map_chr<8>(0, 0);
|
||||
|
||||
/* Mirroring based on bit 5 */
|
||||
set_mirroring((regs[0] & 0b00010000) ? PPU::ONE_SCREEN_HI : PPU::ONE_SCREEN_LO);
|
||||
}
|
||||
|
||||
u8 Mapper7::write(u16 addr, u8 v)
|
||||
{
|
||||
/* check for bus contingency? (addr & 0x8000 == v?)
|
||||
* Seems not neccesary */
|
||||
|
||||
/* bank switching */
|
||||
if (addr & 0x8000)
|
||||
{
|
||||
regs[0] = v;
|
||||
apply();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
u8 Mapper7::chr_write(u16 addr, u8 v)
|
||||
{
|
||||
return chr[addr] = v;
|
||||
}
|
|
@ -42,6 +42,9 @@ u16 nt_mirror(u16 addr)
|
|||
{
|
||||
case VERTICAL: return addr % 0x800;
|
||||
case HORIZONTAL: return ((addr / 2) & 0x400) + (addr % 0x400);
|
||||
case ONE_SCREEN_LO:
|
||||
case ONE_SCREEN_HI:
|
||||
return ((addr & 0x3ff) + ((mirroring == ONE_SCREEN_HI) ? 0x400 : 0x0)) - 0x2000;
|
||||
default: return addr - 0x2000;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue