Emulator: Add cycles to wait after executing opcode

This commit is contained in:
Riyyi
2022-08-18 14:35:24 +02:00
parent e95e7452fe
commit 2c3109e795
2 changed files with 22 additions and 10 deletions
+17 -7
View File
@@ -5,11 +5,13 @@
* SPDX-License-Identifier: MIT
*/
#include "cpu.h"
#include "emu.h"
#include <cstdint> // uint8_t, uint32_t
#include <iostream>
CPU::CPU(unsigned int frequency)
#include "cpu.h"
#include "emu.h"
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;
+5 -3
View File
@@ -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 };
};