kgkotzamanidis

SM83.h

Mar 23rd, 2025
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | Gaming | 0 0
  1. /*
  2.  *An Gameboy and GameboyColor emulation with project name GkotzamBoyGR
  3.  *Copyright (C) <Fri Mar 21 2025>  <KGkotzamanidis>
  4.  *
  5.  *This program is free software: you can redistribute it and/or modify
  6.  *it under the terms of the GNU General Public License as published by
  7.  *the Free Software Foundation, either version 3 of the License, or
  8.  *(at your option) any later version.
  9.  *
  10.  *This program is distributed in the hope that it will be useful,
  11.  *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *GNU General Public License for more details.
  14.  *
  15.  *You should have received a copy of the GNU General Public License
  16.  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  17.  */
  18. #include <cstdint>
  19.  
  20. #include "EmulationUtils.h"
  21. #include "Motherboard.h"
  22.  
  23. class SM83
  24. {
  25. public:
  26.     SM83(Motherboard &mem);
  27.  
  28.     void reset(void);
  29.     void step(void);
  30.  
  31.     bool getDoubleSpeed();
  32.     int getlastCycleCount();
  33.  
  34. private: /* CPU Functions */
  35.     Motherboard *mem;
  36.  
  37.     int lastCycleCount;
  38.  
  39.     static const int instructionCount[];
  40.     static const int prefixedinstructionCount[];
  41.  
  42.     void executeInstruction(uint8_t opcode);
  43.     void executePrefixedInstruction(uint8_t opcode);
  44.  
  45. private: /* CPU Register functions */
  46.     uint8_t A, B, C, D, E, F, H, L;
  47.     uint16_t PC, SP;
  48.     uint16_t AF();
  49.     uint16_t BC();
  50.     uint16_t DE();
  51.     uint16_t HL();
  52.  
  53.     bool IME, IMEhold, ishalt, EIDIFlag, DoubleSpeed;
  54.  
  55.     void setAF(uint16_t data);
  56.     void setBC(uint16_t data);
  57.     void setDE(uint16_t data);
  58.     void setHL(uint16_t data);
  59.  
  60. private: /* Flags */
  61.     void setFlag(uint8_t flag, bool state);
  62.     bool getFlag(uint8_t flag);
  63.  
  64.     bool getFlagZ();
  65.     bool getFlagC();
  66.  
  67. private: /* Arithemtic and Logical Unit (ALU) */
  68.     void alu16bitADD(uint16_t data);
  69.     void alu16bitSPADD();
  70.  
  71.     void alu8bitADD(uint8_t data);
  72.     void alu8bitADC(uint8_t data, bool carry);
  73.     void alu8bitSUB(uint8_t data);
  74.     void alu8bitSBC(uint8_t data, bool carry);
  75.  
  76.     uint8_t alu8bitINC(uint8_t data);
  77.     uint8_t alu8bitDEC(uint8_t data);
  78.  
  79.     void logic8bitAND(uint8_t data);
  80.     void logic8bitOR(uint8_t data);
  81.     void logic8bitXOR(uint8_t data);
  82.     void logic8bitCP(uint8_t data);
  83.     void logic8bitDAA();
  84.     void logic8bitCPL();
  85.  
  86. private: /* Rotate and Shift */
  87.     uint8_t RLC(uint8_t data);
  88.     uint8_t RL(uint8_t data);
  89.     uint8_t RRC(uint8_t data);
  90.     uint8_t RR(uint8_t data);
  91.     uint8_t SLA(uint8_t data);
  92.     uint8_t SRA(uint8_t data);
  93.     uint8_t SRL(uint8_t data);
  94.     uint8_t SWAP(uint8_t data);
  95.  
  96.     void BIT(int bit, uint8_t data);
  97.     uint8_t SET(int bit, uint8_t data);
  98.     uint8_t RES(int bit, uint8_t data);
  99.  
  100. private: /* CPU Control Instruction */
  101.     void ccf(void);
  102.     void scf(void);
  103.     void nop(void);
  104.     void halt(void);
  105.     void stop(void);
  106.     void di(void);
  107.     void ei(void);
  108.  
  109. private: /* Jump Instruction */
  110.     void jp(bool state);
  111.     void jr(bool state);
  112.     void call(bool state);
  113.     void ret(bool state);
  114.     void reti(void);
  115.     void rst(uint8_t data);
  116. };
Advertisement
Add Comment
Please, Sign In to add comment