Some changes

This commit is contained in:
2025-02-16 17:28:10 +01:00
parent 0fc4040ad7
commit 4d3755e2ce
18 changed files with 562 additions and 80 deletions

View File

@@ -4,6 +4,8 @@
#include "memory.h"
#define SFR_OFFSET (0xDF00)
uint8_t write_mem(CPU *cpu, uint32_t addr, uint8_t value) {
if (addr >= MEM_SIZE) {
return 1;
@@ -11,10 +13,50 @@ uint8_t write_mem(CPU *cpu, uint32_t addr, uint8_t value) {
switch (addr) {
case SFR_OFFSET + 0x00:
pcm_buffer_push(&audioData.pcmVoice, value << 8 | cpu->memory[SFR_OFFSET + 0x01]);
case SFR_OFFSET + 0x02:
audioData.synthVoices[0].volume = value;
case SFR_OFFSET + 0x03:
audioData.synthVoices[0].waveform = value;
case SFR_OFFSET + 0x04:
audioData.synthVoices[0].phase = value;
case SFR_OFFSET + 0x05:
audioData.synthVoices[0].frequency = value << 8 | cpu->memory[SFR_OFFSET + 0x06];
case SFR_OFFSET + 0x07:
audioData.synthVoices[1].volume = value;
case SFR_OFFSET + 0x08:
audioData.synthVoices[1].waveform = value;
case SFR_OFFSET + 0x09:
audioData.synthVoices[1].phase = value;
case SFR_OFFSET + 0x0A:
audioData.synthVoices[1].frequency = value << 8 | cpu->memory[SFR_OFFSET + 0x0B];
case SFR_OFFSET + 0x0C:
audioData.synthVoices[2].volume = value;
case SFR_OFFSET + 0x0D:
audioData.synthVoices[2].waveform = value;
case SFR_OFFSET + 0x0E:
audioData.synthVoices[2].phase = value;
case SFR_OFFSET + 0x0F:
audioData.synthVoices[2].frequency = value << 8 | cpu->memory[SFR_OFFSET + 0x10];
default:
cpu->memory[addr] = value;
break;
}
cpu->memory[addr] = value;
return 0;
}
@@ -50,6 +92,15 @@ uint32_t read_address_argument(CPU *cpu) {
return out;
}
uint8_t read_register_argument(CPU *cpu) {
uint8_t out = read_mem(cpu, cpu->pc);
cpu->pc += 1;
if (out >= REG_COUNT) {
out = REG_COUNT - 1;
}
return out;
}
// Push a 32-bit program counter (PC) onto the stack
void write_stack(CPU *cpu) {
if (cpu->pc >= MEM_SIZE) {