Path: blob/master/libsnes/bsnes/snes/chip/hitachidsp/hitachidsp.cpp
2 views
#include <snes/snes.hpp>12#define HITACHIDSP_CPP3namespace SNES {45#include "memory.cpp"6#include "opcodes.cpp"7#include "registers.cpp"8#include "serialization.cpp"9HitachiDSP hitachidsp;1011//zero 01-sep-2014 - dont clobber these when reconstructing!12unsigned HitachiDSP::frequency;13uint24 HitachiDSP::dataROM[1024];1415void HitachiDSP::Enter() { hitachidsp.enter(); }1617void HitachiDSP::enter() {18while(true) {19// exit requested due to savestate20if(scheduler.sync == Scheduler::SynchronizeMode::All) {21scheduler.exit(Scheduler::ExitReason::SynchronizeEvent);22}2324// if we bail out due to savestating, the first thing we'll try afterwards is synchronize_cpu() again25synchronize_cpu();2627switch(state) {28case State::Idle:29step(1);30break;31case State::DMA:32for(unsigned n = 0; n < regs.dma_length; n++) {33bus.write(regs.dma_target + n, bus.read(regs.dma_source + n));34step(2);35}36state = State::Idle;37break;38case State::Execute:39unsigned offset = regs.program_offset + regs.pc * 2;40opcode = bus_read(offset + 0) << 0;41opcode |= bus_read(offset + 1) << 8;42regs.pc = (regs.pc & 0xffff00) | ((regs.pc + 1) & 0x0000ff);43exec();44step(1);45break;46}4748// this call is gone, but it's the first thing we try at the top of the loop AFTER we bail out49//synchronize_cpu();50}51}5253void HitachiDSP::init() {54}5556void HitachiDSP::load() {57}5859void HitachiDSP::unload() {60}6162void HitachiDSP::power() {63}6465void HitachiDSP::reset() {66create(HitachiDSP::Enter, frequency);67state = State::Idle;6869regs.n = 0;70regs.z = 0;71regs.c = 0;7273regs.dma_source = 0x000000;74regs.dma_length = 0x0000;75regs.dma_target = 0x000000;76regs.r1f48 = 0x00;77regs.program_offset = 0x000000;78regs.r1f4c = 0x00;79regs.page_number = 0x0000;80regs.program_counter = 0x00;81regs.r1f50 = 0x33;82regs.r1f51 = 0x00;83regs.r1f52 = 0x01;84}8586}878889