Compare commits
3
Commits
1bfcfcc1f1
...
c159e09ce3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c159e09ce3 | ||
|
|
2c3109e795 | ||
|
|
e95e7452fe |
+23
-13
@@ -5,11 +5,13 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <cstdint> // uint8_t, uint32_t
|
||||
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
#include <iostream>
|
||||
#include "ruc/format/print.h"
|
||||
|
||||
CPU::CPU(unsigned int frequency)
|
||||
CPU::CPU(uint32_t frequency)
|
||||
: ProcessingUnit(frequency)
|
||||
{
|
||||
}
|
||||
@@ -20,26 +22,34 @@ CPU::~CPU()
|
||||
|
||||
void CPU::update()
|
||||
{
|
||||
printf("This is an update from the CPU\n");
|
||||
Emu::the().writeMemory("RAM", 123, 42);
|
||||
printf("fff");
|
||||
m_wait_cycles--;
|
||||
if (m_wait_cycles <= 0) {
|
||||
// Read next opcode
|
||||
}
|
||||
|
||||
void CPU::add(uint8_t byte, uint8_t immediate)
|
||||
print("This is an update from the CPU\n");
|
||||
Emu::the().writeMemory("RAM", 123, 42);
|
||||
print("fff");
|
||||
}
|
||||
|
||||
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_af >> 8) + immediate == 0;
|
||||
m_z = m_a + immediate == 0;
|
||||
m_n = 0;
|
||||
m_h = (m_af >> 8) + immediate > 16;
|
||||
m_c = (m_af >> 8) + immediate > 255;
|
||||
m_h = m_a + immediate > 16;
|
||||
m_c = m_a + immediate > 255;
|
||||
|
||||
// A = A + r
|
||||
m_af = m_af + (immediate << 8);
|
||||
m_a += immediate;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -37,17 +37,19 @@ public:
|
||||
// Miscellaneous Instructions
|
||||
|
||||
private:
|
||||
// 16-bit registers
|
||||
uint16_t m_af { 0 }; // Accumulator & Flags
|
||||
// Registers
|
||||
uint8_t m_a { 0 }; // Accumulator
|
||||
uint16_t m_bc { 0 }; // BC
|
||||
uint16_t m_de { 0 }; // DE
|
||||
uint16_t m_hl { 0 }; // HL
|
||||
uint16_t m_sp { 0 }; // Stack Pointer
|
||||
uint16_t m_pc { 0 }; // Program Counter
|
||||
|
||||
// 8-bit registers (flags)
|
||||
// Flags
|
||||
uint8_t m_z { 0 }; // Zero flag
|
||||
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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user