libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_isa.h File Reference

Go to the source code of this file.

Data Structures

struct  EvmuInstructionFormat
 
struct  EvmuInstruction
 
struct  EvmuOperands
 
struct  EvmuDecodedInstruction
 

Macros

#define EVMU_OPCODE_NOP   0x00
 
#define EVMU_OPCODE_BR   0x01
 
#define EVMU_OPCODE_LD   0x02
 
#define EVMU_OPCODE_LD_IND   0x04
 
#define EVMU_OPCODE_CALL   0x08
 
#define EVMU_OPCODE_CALLR   0x10
 
#define EVMU_OPCODE_BRF   0x11
 
#define EVMU_OPCODE_ST   0x12
 
#define EVMU_OPCODE_ST_IND   0x14
 
#define EVMU_OPCODE_CALLF   0x20
 
#define EVMU_OPCODE_JMPF   0x21
 
#define EVMU_OPCODE_MOV   0x22
 
#define EVMU_OPCODE_MOV_IND   0x24
 
#define EVMU_OPCODE_JMP   0x28
 
#define EVMU_OPCODE_MUL   0x30
 
#define EVMU_OPCODE_BEI   0x31
 
#define EVMU_OPCODE_BE   0x32
 
#define EVMU_OPCODE_BE_IND   0x34
 
#define EVMU_OPCODE_DIV   0x40
 
#define EVMU_OPCODE_BNEI   0x41
 
#define EVMU_OPCODE_BNE   0x42
 
#define EVMU_OPCODE_BNE_IND   0x44
 
#define EVMU_OPCODE_BPC   0x48
 
#define EVMU_OPCODE_LDF   0x50
 
#define EVMU_OPCODE_STF   0x51
 
#define EVMU_OPCODE_DBNZ   0x52
 
#define EVMU_OPCODE_DBNZ_IND   0x54
 
#define EVMU_OPCODE_PUSH   0x60
 
#define EVMU_OPCODE_INC   0x62
 
#define EVMU_OPCODE_INC_IND   0x64
 
#define EVMU_OPCODE_BP   0x68
 
#define EVMU_OPCODE_POP   0x70
 
#define EVMU_OPCODE_DEC   0x72
 
#define EVMU_OPCODE_DEC_IND   0x74
 
#define EVMU_OPCODE_BZ   0x80
 
#define EVMU_OPCODE_ADDI   0x81
 
#define EVMU_OPCODE_ADD   0x82
 
#define EVMU_OPCODE_ADD_IND   0x84
 
#define EVMU_OPCODE_BN   0x88
 
#define EVMU_OPCODE_BNZ   0x90
 
#define EVMU_OPCODE_ADDCI   0x91
 
#define EVMU_OPCODE_ADDC   0x92
 
#define EVMU_OPCODE_ADDC_IND   0x94
 
#define EVMU_OPCODE_RET   0xa0
 
#define EVMU_OPCODE_SUBI   0xa1
 
#define EVMU_OPCODE_SUB   0xa2
 
#define EVMU_OPCODE_SUB_IND   0xa4
 
#define EVMU_OPCODE_NOT1   0xa8
 
#define EVMU_OPCODE_RETI   0xb0
 
#define EVMU_OPCODE_SUBCI   0xb1
 
#define EVMU_OPCODE_SUBC   0xb2
 
#define EVMU_OPCODE_SUBC_IND   0xb4
 
#define EVMU_OPCODE_ROR   0xc0
 
#define EVMU_OPCODE_LDC   0xc1
 
#define EVMU_OPCODE_XCH   0xc2
 
#define EVMU_OPCODE_XCH_IND   0xc4
 
#define EVMU_OPCODE_CLR1   0xc8
 
#define EVMU_OPCODE_RORC   0xd0
 
#define EVMU_OPCODE_ORI   0xd1
 
#define EVMU_OPCODE_OR   0xd2
 
#define EVMU_OPCODE_OR_IND   0xd4
 
#define EVMU_OPCODE_ROL   0xe0
 
#define EVMU_OPCODE_ANDI   0xe1
 
#define EVMU_OPCODE_AND   0xe2
 
#define EVMU_OPCODE_AND_IND   0xe4
 
#define EVMU_OPCODE_SET1   0xe8
 
#define EVMU_OPCODE_ROLC   0xf0
 
#define EVMU_OPCODE_XORI   0xf1
 
#define EVMU_OPCODE_XOR   0xf2
 
#define EVMU_OPCODE_XOR_IND   0xf4
 
Program Status Word Flags

Flags which may be modified by a particular instruction

#define EVMU_ISA_PSW_SYSTEM_POS   3
 
#define EVMU_ISA_PSW_SYSTEM_MASK   0x8
 
#define EVMU_ISA_PSW_CY_POS   2
 
#define EVMU_ISA_PSW_CY_MASK   0x4
 
#define EVMU_ISA_PSW_AC_POS   1
 
#define EVMU_ISA_PSW_AC_MASK   0x2
 
#define EVMU_ISA_PSW_OV_POS   0
 
#define EVMU_ISA_PSW_OV_MASK   0x1
 
#define EVMU_ISA_PSW_NONE   0x0
 
Argument Packs

Macros for handling packed argument types

#define EVMU_ISA_ARG_FORMAT_PACK(...)    GBL_VA_OVERLOAD_CALL(EVMU_ISA_ARG_FORMAT_PACK, GBL_VA_OVERLOAD_SUFFIXER_ARGC, __VA_ARGS__)
 
#define EVMU_ISA_ARG_FORMAT_UNPACK(argFormat, field)    ((argFormat >> (field * 8u)) & 0xff)
 
#define EVMU_ISA_ARGC(argFmt)
 

Typedefs

typedef uint32_t EvmuIsaFlags
 
typedef uint32_t EvmuIsaArgFormat
 

Enumerations

enum  EVMU_ISA_ARG_TYPE
 
enum  EVMU_ISA_ARG
 
enum  EVMU_INSTRUCTION_BYTE
 

Functions

const EvmuInstructionFormatEvmuIsa_format (EvmuWord firstByte)
 
EVMU_RESULT EvmuIsa_fetch (EvmuInstruction *pEncoded, const void *pBuffer, size_t *pBytes)
 
EVMU_RESULT EvmuIsa_decode (const EvmuInstruction *pEncoded, EvmuDecodedInstruction *pDecoded)
 

Detailed Description

Instruction set, opcode, and operand info.

This file provides the API for everything relating to the instruction set architecture of the Sanyo LC86K:

  • Opcodes
  • Operand Info
  • Encoded Instructions
  • Decoded Instructions
Author
2023 Falco Girgis

Definition in file evmu_isa.h.

Macro Definition Documentation

◆ EVMU_ISA_ARG_FORMAT_PACK

#define EVMU_ISA_ARG_FORMAT_PACK (   ...)     GBL_VA_OVERLOAD_CALL(EVMU_ISA_ARG_FORMAT_PACK, GBL_VA_OVERLOAD_SUFFIXER_ARGC, __VA_ARGS__)

Packs the given argument types into an EvmuIsaArgFormat.

Definition at line 132 of file evmu_isa.h.

156 {
168
170typedef enum EVMU_ISA_ARG {
176
185typedef struct EvmuInstructionFormat {
186 const char* pMnemonic;
187 const char* pDesc;
188 uint8_t opcode;
189 uint8_t opBits;
191 uint8_t bytes;
192 uint8_t cc;
195
197typedef enum EVMU_INSTRUCTION_BYTE {
203
205typedef struct EvmuInstruction {
207 uint8_t byteCount;
209
211typedef struct EvmuOperands {
212 union {
213 uint16_t absolute;
214 uint16_t relative16;
215 uint16_t direct;
216 };
217 uint8_t bit;
218 uint8_t indirect;
219 int8_t relative8;
220 uint8_t immediate;
222
224typedef struct EvmuDecodedInstruction {
228
231 EvmuIsa_format (EvmuWord firstByte) GBL_NOEXCEPT;
232
235 const void* pBuffer,
236 size_t* pBytes) GBL_NOEXCEPT;
237
240 EvmuDecodedInstruction* pDecoded) GBL_NOEXCEPT;
241
242GBL_DECLS_END
243
245#define EVMU_ISA_ARG_FORMAT_PACK_3(arg1, arg2, arg3) \
246 ((EvmuIsaArgFormat) \
247 (((EvmuIsaArgFormat)arg1 & 0xffu) << ((EvmuIsaArgFormat)EVMU_ISA_ARG1 * 8)) | \
248 (((EvmuIsaArgFormat)arg2 & 0xffu) << ((EvmuIsaArgFormat)EVMU_ISA_ARG2 * 8)) | \
249 (((EvmuIsaArgFormat)arg3 & 0xffu) << ((EvmuIsaArgFormat)EVMU_ISA_ARG3 * 8)))
250
251#define EVMU_ISA_ARG_FORMAT_PACK_2(a, b) (EVMU_ISA_ARG_FORMAT_PACK_3(a, b, EVMU_ISA_ARG_TYPE_NONE))
252
253#define EVMU_ISA_ARG_FORMAT_PACK_1(a) (EVMU_ISA_ARG_FORMAT_PACK_2(a, EVMU_ISA_ARG_TYPE_NONE))
255
256#endif // EVMU_ISA_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
EVMU_ISA_ARG
Enumeration for each argument position in an EvmuIaArgFormat.
Definition evmu_isa.h:171
@ EVMU_ISA_ARG2
Second argument.
Definition evmu_isa.h:173
@ EVMU_ISA_ARG3
Third argument.
Definition evmu_isa.h:174
@ EVMU_ISA_ARG1
First argument.
Definition evmu_isa.h:172
@ EVMU_ISA_ARG_COUNT
Size of argument pack.
Definition evmu_isa.h:175
EVMU_ISA_ARG_TYPE
Enumeration with every type of instruction argument.
Definition evmu_isa.h:157
@ EVMU_ISA_ARG_TYPE_INDIRECT_2
2-bit indirection mode
Definition evmu_isa.h:163
@ EVMU_ISA_ARG_TYPE_BIT_3
3-bit bit position
Definition evmu_isa.h:166
@ EVMU_ISA_ARG_TYPE_COUNT
Number of different types.
Definition evmu_isa.h:167
@ EVMU_ISA_ARG_TYPE_ABSOLUTE_12
12-bit absolute address
Definition evmu_isa.h:164
@ EVMU_ISA_ARG_TYPE_DIRECT_9
9-bit direct address
Definition evmu_isa.h:162
@ EVMU_ISA_ARG_TYPE_ABSOLUTE_16
16-bit absolute address
Definition evmu_isa.h:165
@ EVMU_ISA_ARG_TYPE_RELATIVE_16
16-bit relative address
Definition evmu_isa.h:160
@ EVMU_ISA_ARG_TYPE_RELATIVE_8
8-bit relative address
Definition evmu_isa.h:159
@ EVMU_ISA_ARG_TYPE_NONE
No Argument.
Definition evmu_isa.h:158
@ EVMU_ISA_ARG_TYPE_IMMEDIATE_8
8-bit immediate value
Definition evmu_isa.h:161
uint32_t EvmuIsaFlags
Flags type for EvmuInstructionFormat::flags.
Definition evmu_isa.h:149
const EvmuInstructionFormat * EvmuIsa_format(EvmuWord firstByte)
Fetches information on an instruction from the internal database.
EVMU_RESULT EvmuIsa_fetch(EvmuInstruction *pEncoded, const void *pBuffer, size_t *pBytes)
Fetches an encoded instruction from a buffer.
EVMU_RESULT EvmuIsa_decode(const EvmuInstruction *pEncoded, EvmuDecodedInstruction *pDecoded)
Decodes an instruction into an EvmuDecodedInstruction.
EVMU_INSTRUCTION_BYTE
Enumeration containing each byte within an encoded EvmuInstruction.
Definition evmu_isa.h:198
@ EVMU_INSTRUCTION_BYTE_OPCODE
First byte of an encoded instruction (opcode)
Definition evmu_isa.h:199
@ EVMU_INSTRUCTION_BYTE_2
Second byte of an encoded instruction (if present)
Definition evmu_isa.h:200
@ EVMU_INSTRUCTION_BYTE_MAX
Maximum number of bytes in an encoded instruction (1 for padding)
Definition evmu_isa.h:202
@ EVMU_INSTRUCTION_BYTE_3
Third byte of an encoded instruction (if present)
Definition evmu_isa.h:201
uint32_t EvmuIsaArgFormat
Type for holding encoded instruction argument types in EvmuInstructionFormat::args.
Definition evmu_isa.h:152
EVMU_RESULT
extended GBL_RESULT type representing any status for the codebase
uint8_t EvmuWord
Represents a single 8-bit CPU word.
Represents an instruction which has been decoded.
Definition evmu_isa.h:225
EvmuWord opcode
Opcode byte (see Instruction Opcodes)
Definition evmu_isa.h:227
EvmuOperands operands
Decoded operands.
Definition evmu_isa.h:226
Structrure describing the format of each type of instruction.
Definition evmu_isa.h:186
uint8_t opBits
Bits for opcode (8 max)
Definition evmu_isa.h:190
uint8_t opcode
Opcode.
Definition evmu_isa.h:189
const char * pDesc
Instruction description.
Definition evmu_isa.h:188
EvmuIsaFlags flags
Program status word modifiers (CY, AC, DV)
Definition evmu_isa.h:194
uint8_t bytes
Bytes per instruction (1-3)
Definition evmu_isa.h:192
EvmuIsaArgFormat args
Operand arguments.
Definition evmu_isa.h:191
const char * pMnemonic
ASM instruction.
Definition evmu_isa.h:187
uint8_t cc
Clock cycles (1-7)
Definition evmu_isa.h:193
Contains a collection of bytes, representing an encoded instruction.
Definition evmu_isa.h:206
uint8_t byteCount
Byte size of instruciton data.
Definition evmu_isa.h:208
uint8_t bytes[EVMU_INSTRUCTION_BYTE_MAX]
Raw instruction byte data.
Definition evmu_isa.h:207
Contains the decoded operands of an instruction.
Definition evmu_isa.h:212
uint16_t direct
9-bit direct address
Definition evmu_isa.h:216
uint8_t immediate
8-bit immediate data
Definition evmu_isa.h:221
uint16_t absolute
12 or 16-bit absolute address
Definition evmu_isa.h:214
uint8_t bit
3-bit bit offset
Definition evmu_isa.h:218
uint16_t relative16
16-bit relative address
Definition evmu_isa.h:215
int8_t relative8
8-bit relative address
Definition evmu_isa.h:220
uint8_t indirect
2-bit indirection mode
Definition evmu_isa.h:219

◆ EVMU_ISA_ARG_FORMAT_UNPACK

#define EVMU_ISA_ARG_FORMAT_UNPACK (   argFormat,
  field 
)     ((argFormat >> (field * 8u)) & 0xff)

Unpacks the given field from the EvmuIsaArgFormat provided as argFormat.

Definition at line 136 of file evmu_isa.h.

◆ EVMU_ISA_ARGC

#define EVMU_ISA_ARGC (   argFmt)

Returns the number of arguments encoded within an EvmuIsaArgFormat.

Definition at line 140 of file evmu_isa.h.

◆ EVMU_ISA_PSW_AC_MASK

#define EVMU_ISA_PSW_AC_MASK   0x2

Auxiliary carry mask.

Definition at line 121 of file evmu_isa.h.

◆ EVMU_ISA_PSW_AC_POS

#define EVMU_ISA_PSW_AC_POS   1

Auxiliary carry bit.

Definition at line 120 of file evmu_isa.h.

◆ EVMU_ISA_PSW_CY_MASK

#define EVMU_ISA_PSW_CY_MASK   0x4

Carry mask.

Definition at line 119 of file evmu_isa.h.

◆ EVMU_ISA_PSW_CY_POS

#define EVMU_ISA_PSW_CY_POS   2

Carry bit.

Definition at line 118 of file evmu_isa.h.

◆ EVMU_ISA_PSW_NONE

#define EVMU_ISA_PSW_NONE   0x0

No PSW flags effected.

Definition at line 124 of file evmu_isa.h.

◆ EVMU_ISA_PSW_OV_MASK

#define EVMU_ISA_PSW_OV_MASK   0x1

Overflow mask.

Definition at line 123 of file evmu_isa.h.

◆ EVMU_ISA_PSW_OV_POS

#define EVMU_ISA_PSW_OV_POS   0

Overflow bit.

Definition at line 122 of file evmu_isa.h.

◆ EVMU_ISA_PSW_SYSTEM_MASK

#define EVMU_ISA_PSW_SYSTEM_MASK   0x8

System mask.

Definition at line 117 of file evmu_isa.h.

◆ EVMU_ISA_PSW_SYSTEM_POS

#define EVMU_ISA_PSW_SYSTEM_POS   3

System bit.

Definition at line 116 of file evmu_isa.h.

Typedef Documentation

◆ EvmuIsaArgFormat

typedef uint32_t EvmuIsaArgFormat

Type for holding encoded instruction argument types in EvmuInstructionFormat::args.

Definition at line 152 of file evmu_isa.h.

◆ EvmuIsaFlags

typedef uint32_t EvmuIsaFlags

Flags type for EvmuInstructionFormat::flags.

Definition at line 149 of file evmu_isa.h.

Enumeration Type Documentation

◆ EVMU_INSTRUCTION_BYTE

Enumeration containing each byte within an encoded EvmuInstruction.

Enumerator
EVMU_INSTRUCTION_BYTE_OPCODE 

First byte of an encoded instruction (opcode)

EVMU_INSTRUCTION_BYTE_2 

Second byte of an encoded instruction (if present)

EVMU_INSTRUCTION_BYTE_3 

Third byte of an encoded instruction (if present)

EVMU_INSTRUCTION_BYTE_MAX 

Maximum number of bytes in an encoded instruction (1 for padding)

Definition at line 198 of file evmu_isa.h.

◆ EVMU_ISA_ARG

Enumeration for each argument position in an EvmuIaArgFormat.

Enumerator
EVMU_ISA_ARG1 

First argument.

EVMU_ISA_ARG2 

Second argument.

EVMU_ISA_ARG3 

Third argument.

EVMU_ISA_ARG_COUNT 

Size of argument pack.

Definition at line 171 of file evmu_isa.h.

◆ EVMU_ISA_ARG_TYPE

Enumeration with every type of instruction argument.

Enumerator
EVMU_ISA_ARG_TYPE_NONE 

No Argument.

EVMU_ISA_ARG_TYPE_RELATIVE_8 

8-bit relative address

EVMU_ISA_ARG_TYPE_RELATIVE_16 

16-bit relative address

EVMU_ISA_ARG_TYPE_IMMEDIATE_8 

8-bit immediate value

EVMU_ISA_ARG_TYPE_DIRECT_9 

9-bit direct address

EVMU_ISA_ARG_TYPE_INDIRECT_2 

2-bit indirection mode

EVMU_ISA_ARG_TYPE_ABSOLUTE_12 

12-bit absolute address

EVMU_ISA_ARG_TYPE_ABSOLUTE_16 

16-bit absolute address

EVMU_ISA_ARG_TYPE_BIT_3 

3-bit bit position

EVMU_ISA_ARG_TYPE_COUNT 

Number of different types.

Definition at line 157 of file evmu_isa.h.

Function Documentation

◆ EvmuIsa_decode()

EVMU_RESULT EvmuIsa_decode ( const EvmuInstruction pEncoded,
EvmuDecodedInstruction pDecoded 
)

Decodes an instruction into an EvmuDecodedInstruction.

◆ EvmuIsa_fetch()

EVMU_RESULT EvmuIsa_fetch ( EvmuInstruction pEncoded,
const void *  pBuffer,
size_t *  pBytes 
)

Fetches an encoded instruction from a buffer.

◆ EvmuIsa_format()

const EvmuInstructionFormat * EvmuIsa_format ( EvmuWord  firstByte)

Fetches information on an instruction from the internal database.