NESEmulator/NES Emulator/bus.h

46 lines
905 B
C
Raw Permalink Normal View History

2021-10-20 20:39:29 +00:00
#ifndef _BUS_H_
#define _BUS_H_
#include "types.h"
2021-10-30 19:01:27 +00:00
#include "controller.h"
2021-10-24 11:47:11 +00:00
#include <SDL.h>
2021-10-20 20:39:29 +00:00
struct CPU;
2021-10-23 17:30:02 +00:00
struct PPU;
2021-10-20 20:39:29 +00:00
struct Cartridge;
2021-10-30 19:01:27 +00:00
2021-10-20 20:39:29 +00:00
// Main communication path for devices and memory in the NES
struct Bus
{
Byte* ram;
2021-10-22 22:47:33 +00:00
Byte* io;
2021-10-20 20:39:29 +00:00
struct CPU* cpu;
2021-10-23 17:30:02 +00:00
struct PPU* ppu;
2021-10-20 20:39:29 +00:00
struct Cartridge* cartridge;
2021-10-30 19:01:27 +00:00
struct Controller controller;
2021-10-23 18:36:38 +00:00
Byte masterClockTimer;
2021-10-24 11:47:11 +00:00
SDL_Renderer* screen;
2021-10-20 20:39:29 +00:00
};
// Sets up the Bus, allocates memory and creates devices
2021-10-24 11:47:11 +00:00
struct Bus* createBus(SDL_Renderer* renderer);
2021-10-20 20:39:29 +00:00
// Destroys the bus, cleans up memory and destroys devices on the Bus
void destroyBus(struct Bus* bus);
// Read/Write to and from the bus
2021-10-20 21:23:16 +00:00
Byte readBus(struct Bus* bus, Word addr);
void writeBus(struct Bus* bus, Word addr, Byte val);
2021-10-20 20:39:29 +00:00
2021-10-21 17:24:53 +00:00
// Ticks the master clock 12 times (i.e. 1 CPU tick & 3 PPU dots)
2021-10-23 18:36:38 +00:00
int tick(struct Bus* bus);
int doInstruction(struct Bus* bus);
int doFrame(struct Bus* bus);
2021-10-21 17:24:53 +00:00
2021-10-20 20:39:29 +00:00
#endif // _BUS_H_