void writeByte(struct gameboy * gameboy, uint16_t address, uint8_t data) { //0000-8000 is read only if (address < CARTRIDGE_SIZE){ handleBankWrite(gameboy, address, data); } //anything written to echo RAM should be written to work RAM. else if ((address >= ECHO_RAM_START_UPPER) && (address < ECHO_RAM_END_UPPER)){ gameboy->memory.mem[address] = data; gameboy->memory.mem[address - ECHO_OFFSET] = data; } else if ((address >= ECHO_RAM_START_LOWER) && (address < ECHO_RAM_END_LOWER)){ gameboy->memory.mem[address] = data; gameboy->memory.mem[address + ECHO_OFFSET] = data; } else if ((address >= RESTRICTED_START) && (address < RESTRICTED_END)){ //printf("sp: %x\n", gameboy->cpu.sp); //printf("WriteMemory: address %x is within restricted memory %x - %x\n", address, RESTRICTED_START, RESTRICTED_END); // fprintf(stderr, "WriteMemory: address %x is within restricted memory %x - %x\n", address, RESTRICTED_START, RESTRICTED_END); //printDebugTrace(gameboy); } else if (address == TMC){ //the game is trying to change the timer controller int currentFreq = getTimerFrequency(gameboy); gameboy->memory.mem[TMC] = data; int newFreq = getTimerFrequency(gameboy); if (newFreq != currentFreq){ initialiseTimerCounter(gameboy); } } else if (address == DIV_REG){ //any writes to the divider register resets it to 0 gameboy->memory.mem[DIV_REG] = 0; } else if (address == DMA_ADDRESS){ doDMATransfer(gameboy, data); } else if (address == CONTROL_REG){ gameboy->screen.control = data; } else if (address == CURRENT_SCANLINE){ //printf("resetting scanline\n"); gameboy->screen.currentScanline = 0; } else if (address == STATUS_REG){ gameboy->screen.status = data; } else { gameboy->memory.mem[address] = data; } }
double CStatisticTimer::GetTime() { uint64 total = mTotal; if (mRunning) total += getTimer()-mStart; return (double)((int64)(total/getTimerFrequency())); }
uint64 CStatisticTimer::GetFraction(uint32 fraction) { uint64 total = mTotal; if (mRunning) total += getTimer()-mStart; if (fraction == 0) return total; else return total/(getTimerFrequency()/fraction); }