Browse Source

Emulator: Add cycles to wait after executing opcode

master
Riyyi 2 years ago
parent
commit
2c3109e795
  1. 22
      src/cpu.cpp
  2. 8
      src/cpu.h

22
src/cpu.cpp

@ -5,11 +5,13 @@
* SPDX-License-Identifier: MIT
*/
#include <cstdint> // uint8_t, uint32_t
#include <iostream>
#include "cpu.h"
#include "emu.h"
#include <iostream>
CPU::CPU(unsigned int frequency)
CPU::CPU(uint32_t frequency)
: ProcessingUnit(frequency)
{
}
@ -20,17 +22,25 @@ CPU::~CPU()
void CPU::update()
{
m_wait_cycles--;
if (m_wait_cycles <= 0) {
// Read next opcode
}
printf("This is an update from the CPU\n");
Emu::the().writeMemory("RAM", 123, 42);
printf("fff");
}
void CPU::add(uint8_t byte, uint8_t immediate)
void CPU::add(uint8_t opcode, uint8_t immediate)
{
switch (byte) {
switch (opcode) {
case 0xc6: // ADD A,d8
// program_counter += 2;
// clock += 8;
// Program counter +2
m_pc += 2;
// Clock cycles +8
m_wait_cycles += 8;
// Flags: Z0HC
m_z = m_a + immediate == 0;

8
src/cpu.h

@ -7,20 +7,20 @@
#pragma once
#include <cstdint> // uint8_t, uint16_t
#include <cstdint> // int8_t, uint8_t, uint16_t, uint32_t
#include "processing-unit.h"
class CPU final : public ProcessingUnit {
public:
CPU(unsigned int frequency);
explicit CPU(uint32_t frequency);
virtual ~CPU();
void update() override;
// 8-bit Arithmetic and Logic Instructions
void add(uint8_t byte, uint8_t immediate = 0);
void add(uint8_t opcode, uint8_t immediate = 0);
// 16-bit Arithmetic Instructions
@ -50,4 +50,6 @@ private:
uint8_t m_n { 0 }; // Subtraction flag (BCD)
uint8_t m_h { 0 }; // Half Carry flag (BCD)
uint8_t m_c { 0 }; // Carry flag
int8_t m_wait_cycles { 0 };
};

Loading…
Cancel
Save