mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-19 16:42:33 +00:00
76 lines
2.6 KiB
Odin
76 lines
2.6 KiB
Odin
// rexcode · Brendan Punsky (dotbmp@github), original author
|
|
|
|
package rexcode_mos65816
|
|
|
|
// =============================================================================
|
|
// INSTRUCTION
|
|
// =============================================================================
|
|
|
|
Instruction_Flags :: bit_field u8 {
|
|
_: u8 | 8,
|
|
}
|
|
|
|
Instruction :: struct #packed {
|
|
ops: [2]Operand `fmt:"v,operand_count"`, // 20 bytes (only MVN/MVP use 2; rest use 0 or 1)
|
|
mnemonic: Mnemonic, // 2
|
|
operand_count: u8, // 1
|
|
flags: Instruction_Flags, // 1
|
|
length: u8, // 1
|
|
_: [7]u8, // 3
|
|
}
|
|
#assert(size_of(Instruction) == 32)
|
|
|
|
@(require_results)
|
|
inst_none :: #force_inline proc "contextless" (m: Mnemonic) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 0, length = 1}
|
|
}
|
|
|
|
@(require_results)
|
|
inst_a :: #force_inline proc "contextless" (m: Mnemonic) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 1, length = 1,
|
|
ops = {op_reg(A), {}}}
|
|
}
|
|
|
|
@(require_results)
|
|
inst_i8 :: #force_inline proc "contextless" (m: Mnemonic, v: i64) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 1, length = 2,
|
|
ops = {op_imm8(v), {}}}
|
|
}
|
|
|
|
@(require_results)
|
|
inst_i16 :: #force_inline proc "contextless" (m: Mnemonic, v: i64) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 1, length = 3,
|
|
ops = {op_imm16(v), {}}}
|
|
}
|
|
|
|
@(require_results)
|
|
inst_m :: #force_inline proc "contextless" (m: Mnemonic, mm: Memory) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 1, length = 0,
|
|
ops = {op_mem(mm), {}}}
|
|
}
|
|
|
|
@(require_results)
|
|
inst_rel :: #force_inline proc "contextless" (m: Mnemonic, label_id: u32) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 1, length = 2,
|
|
ops = {op_label(label_id, 1), {}}}
|
|
}
|
|
|
|
@(require_results)
|
|
inst_rel_long :: #force_inline proc "contextless" (m: Mnemonic, label_id: u32) -> Instruction {
|
|
return Instruction{mnemonic = m, operand_count = 1, length = 3,
|
|
ops = {op_label(label_id, 2), {}}}
|
|
}
|
|
|
|
// MVN/MVP src, dst -- caller writes "natural" order; encoder reverses to
|
|
// the WDC-specified opcode | dst_bank | src_bank byte layout.
|
|
@(require_results)
|
|
inst_block_move :: #force_inline proc "contextless" (m: Mnemonic, src_bank, dst_bank: u8) -> Instruction {
|
|
return Instruction{
|
|
mnemonic = m, operand_count = 2, length = 3,
|
|
ops = {
|
|
Operand{immediate = i64(src_bank), kind = .IMMEDIATE, size = 1},
|
|
Operand{immediate = i64(dst_bank), kind = .IMMEDIATE, size = 1},
|
|
},
|
|
}
|
|
}
|