Skip to content

Commit

Permalink
Implement r/w status register
Browse files Browse the repository at this point in the history
  • Loading branch information
SirBob01 committed Nov 27, 2023
1 parent d4f4dfe commit 345edd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/apu.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ void create_apu(apu_t *apu, interrupt_t *interrupt) {

void destroy_apu(apu_t *apu) { destroy_buffer(&apu->buffer); }

unsigned char read_status_apu(apu_t *apu) { return apu->status; }

void write_status_apu(apu_t *apu, unsigned char value) {
// Clear DMC interrupt flag
apu->status = value;
apu->channel_registers.dmc[0] &= ~APU_DMC_INTERRUPT;
}

void update_apu(apu_t *apu) {
// TODO: Implement this
apu->cycles++;
Expand Down
31 changes: 21 additions & 10 deletions src/apu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,30 @@
#include "./interrupt.h"

#define AUDIO_BUFFER_SIZE 0x400
#define APU_DMC_INTERRUPT 0x80

/**
* @brief APU registers.
*
*/
typedef struct {
/**
* @brief Pulse 1 channel registers.
* @brief Pulse (1 and 2) channel registers.
*
*/
unsigned char pulse1[4];

/**
* @brief Pulse 2 channel registers.
*
*/
unsigned char pulse2[4];
unsigned char pulse[8];

/**
* @brief Triangle channel registers.
*
*/
unsigned char triangle[4];
unsigned char triangle[3];

/**
* @brief Noise channel registers.
*
*/
unsigned char noise[4];
unsigned char noise[3];

/**
* @brief DMC channel registers.
Expand Down Expand Up @@ -99,6 +94,22 @@ void create_apu(apu_t *apu, interrupt_t *interrupt);
*/
void destroy_apu(apu_t *apu);

/**
* @brief Read the status register of the APU.
*
* @param apu
* @return unsigned char
*/
unsigned char read_status_apu(apu_t *apu);

/**
* @brief Write to the status register of the APU.
*
* @param apu
* @param value
*/
void write_status_apu(apu_t *apu, unsigned char value);

/**
* @brief Update the APU.
*
Expand Down
6 changes: 5 additions & 1 deletion src/cpu_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ unsigned char read_cpu_bus(cpu_bus_t *bus, address_t address) {
return read_joy1_controller(bus->controller);
case CTRL_REG_JOYPAD2:
return read_joy2_controller(bus->controller);
// TODO: Handle APU registers
case APU_REG_STATUS:
return read_status_apu(bus->apu);
default:
return bus->memory[address];
}
Expand Down Expand Up @@ -100,6 +101,9 @@ void write_cpu_bus(cpu_bus_t *bus, address_t address, unsigned char value) {
write_strobe_controller(bus->controller, value);
break;
// TODO: Handle APU registers
case APU_REG_STATUS:
write_status_apu(bus->apu, value);
break;
default:
bus->memory[address] = value;
break;
Expand Down

0 comments on commit 345edd2

Please sign in to comment.