summaryrefslogtreecommitdiff
path: root/src/sim86/libs/reference_decoder/sim86_instruction.cpp
blob: 34fcf1ffdfa8dc194d16b94b238ddc800445b482 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ========================================================================

   (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
   
   This software is provided 'as-is', without any express or implied
   warranty. In no event will the authors be held liable for any damages
   arising from the use of this software.
   
   Please see https://computerenhance.com for more information
   
   ======================================================================== */

static b32 OperandIsType(instruction Instruction, u32 Index, operand_type Type)
{
    b32 Result = (Instruction.Operands[Index].Type == Type);
    return Result;
}

static instruction_operand GetOperand(instruction Instruction, u32 Index)
{
    assert(Index < ArrayCount(Instruction.Operands));
    instruction_operand Result = Instruction.Operands[Index];
    return Result;
}

static register_access RegisterAccess(u32 Index, u32 Offset, u32 Count)
{
    register_access Result = {};
    
    Result.Index = Index;
    Result.Offset = Offset;
    Result.Count = Count;
    
    return Result;
}

static instruction_operand IntersegmentAddressOperand(u32 Segment, s32 Displacement)
{
    instruction_operand Result = {};
    
    Result.Type = Operand_Memory;
    Result.Address.ExplicitSegment = Segment;
    Result.Address.Displacement = Displacement;
    Result.Address.Flags = Address_ExplicitSegment;
    
    return Result;
}

static instruction_operand EffectiveAddressOperand(register_access Term0, register_access Term1, s32 Displacement)
{
    instruction_operand Result = {};
    
    Result.Type = Operand_Memory;
    Result.Address.Terms[0].Register = Term0;
    Result.Address.Terms[0].Scale = 1;
    Result.Address.Terms[1].Register = Term1;
    Result.Address.Terms[1].Scale = 1;
    Result.Address.Displacement = Displacement;
    
    return Result;
}

static instruction_operand RegisterOperand(u32 Index, u32 Count)
{
    instruction_operand Result = {};
    
    Result.Type = Operand_Register;
    Result.Register.Index = Index;
    Result.Register.Offset = 0;
    Result.Register.Count = Count;
    
    return Result;
}

static instruction_operand ImmediateOperand(u32 Value, u32 Flags = 0)
{
    instruction_operand Result = {};
    
    Result.Type = Operand_Immediate;
    Result.Immediate.Value = Value;
    Result.Immediate.Flags = Flags;
    
    return Result;
}