#pragma once #include "stdafx.h" #include "IAssembler.h" class LabelManager; enum class ParamType { None, Literal, Byte, Short, Address, HighAddress, RelAddress, StackOffset }; struct ParamEntry { string Param; ParamType Type; }; struct OpCodeEntry { uint16_t OpCode; int ParamCount; ParamEntry Param1; ParamEntry Param2; }; class GbAssembler : public IAssembler { private: unordered_map> _opCodes; shared_ptr _labelManager; void InitParamEntry(ParamEntry& entry, string param); bool IsRegisterName(string op); void InitAssembler(); int ReadValue(string operand, int min, int max, unordered_map& localLabels, bool firstPass); bool IsMatch(ParamEntry& entry, string operand, uint32_t address, unordered_map& localLabels, bool firstPass); void PushOp(uint16_t opCode, vector& output, uint32_t& address); void PushByte(uint8_t operand, vector& output, uint32_t& address); void PushWord(uint16_t operand, vector& output, uint32_t& address); void ProcessOperand(ParamEntry& entry, string operand, vector& output, uint32_t& address, unordered_map& localLabels, bool firstPass); void RunPass(vector& output, string code, uint32_t address, int16_t* assembledCode, bool firstPass, unordered_map& localLabels); public: GbAssembler(shared_ptr labelManager); virtual ~GbAssembler(); uint32_t AssembleCode(string code, uint32_t startAddress, int16_t* assembledCode); };