1 | unit Instructions;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Generics.Collections, CpuZ80;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TParamType = (ptNone, ptNumberByte, ptNumberByteIndir,
|
---|
10 | ptNumberWord, ptNumberWordIndir, ptRegA,
|
---|
11 | ptRegB, ptRegC, ptRegD, ptRegE, ptRegH, ptRegL, ptRegBC, ptRegDE, ptRegHL,
|
---|
12 | ptRegSP, ptRegIX, ptRegIY, ptRegBCIndir, ptRegDEIndir, ptRegHLIndir,
|
---|
13 | ptFlagZ, ptFlagNZ, ptFlagC, ptFlagNC, pt00, pt08, pt10, pt18, pt20, pt28,
|
---|
14 | pt30, pt38, pt0, pt1, pt2);
|
---|
15 |
|
---|
16 | TParamTypes = array of TParamType;
|
---|
17 |
|
---|
18 | TInstructionInfo = class
|
---|
19 | Instruction: TInstruction;
|
---|
20 | Name: string;
|
---|
21 | Params: TParamTypes;
|
---|
22 | Description: string;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | { TInstructionSet }
|
---|
26 |
|
---|
27 | TInstructionSet = class
|
---|
28 | Items: TObjectList<TInstructionInfo>;
|
---|
29 | function SearchName(Name: string): TInstructionInfo;
|
---|
30 | function SearchInstruction(Instruction: TInstruction): TInstructionInfo;
|
---|
31 | function AddNew(Instruction: TInstruction; Name: string;
|
---|
32 | Params: TParamTypes; Description: string = ''): TInstructionInfo;
|
---|
33 | constructor Create;
|
---|
34 | destructor Destroy; override;
|
---|
35 | end;
|
---|
36 |
|
---|
37 | const
|
---|
38 | ParamTypeText: array[TParamType] of string = ('', 'n', '(n)', 'nn', '(nn)', 'A', 'B',
|
---|
39 | 'C', 'D', 'E', 'H', 'L', 'BC', 'DE', 'HL', 'SP', 'IX', 'IY', '(BC)',
|
---|
40 | '(DE)', '(HL)', 'Z', 'NZ', 'C', 'NC', '00', '08', '10', '18', '20', '28',
|
---|
41 | '30', '38', '0', '1', '2');
|
---|
42 |
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | { TInstructionSet }
|
---|
47 |
|
---|
48 | function TInstructionSet.SearchName(Name: string): TInstructionInfo;
|
---|
49 | var
|
---|
50 | I: Integer;
|
---|
51 | begin
|
---|
52 | I := 0;
|
---|
53 | while (I < Items.Count) and (Items[I].Name <> Name) do Inc(I);
|
---|
54 | if I < Items.Count then Result := Items[I]
|
---|
55 | else Result := nil;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | function TInstructionSet.SearchInstruction(Instruction: TInstruction
|
---|
59 | ): TInstructionInfo;
|
---|
60 | var
|
---|
61 | I: Integer;
|
---|
62 | begin
|
---|
63 | I := 0;
|
---|
64 | while (I < Items.Count) and (Items[I].Instruction <> Instruction) do Inc(I);
|
---|
65 | if I < Items.Count then Result := Items[I]
|
---|
66 | else Result := nil;
|
---|
67 | end;
|
---|
68 |
|
---|
69 | function TInstructionSet.AddNew(Instruction: TInstruction; Name: string;
|
---|
70 | Params: TParamTypes; Description: string = ''): TInstructionInfo;
|
---|
71 | begin
|
---|
72 | Result := TInstructionInfo.Create;
|
---|
73 | Result.Instruction := Instruction;
|
---|
74 | Result.Name := Name;
|
---|
75 | Result.Params := Params;
|
---|
76 | Result.Description := Description;
|
---|
77 | Items.Add(Result);
|
---|
78 | end;
|
---|
79 |
|
---|
80 | constructor TInstructionSet.Create;
|
---|
81 | begin
|
---|
82 | Items := TObjectList<TInstructionInfo>.Create;
|
---|
83 | AddNew(inNop, 'NOP', []);
|
---|
84 | AddNew(inHalt, 'HALT', []);
|
---|
85 | AddNew(inLdAN, 'LD', [ptRegA, ptNumberByte]);
|
---|
86 | AddNew(inLdBN, 'LD', [ptRegB, ptNumberByte]);
|
---|
87 | AddNew(inLdSpNn, 'LD', [ptRegSP, ptNumberWord]);
|
---|
88 | AddNew(inLdAC, 'LD', [ptRegA, ptRegC]);
|
---|
89 | AddNew(inLdHlNn, 'LD', [ptRegHL, ptNumberWord]);
|
---|
90 | AddNew(inLdBcNn, 'LD', [ptRegBC, ptNumberWord]);
|
---|
91 | AddNew(inLdDeNn, 'LD', [ptRegDE, ptNumberWord]);
|
---|
92 | AddNew(inLdHlIndirectN, 'LD', [ptRegHLIndir, ptNumberByte]);
|
---|
93 | AddNew(inLdNnIndirectA, 'LD', [ptNumberWordIndir, ptRegA]);
|
---|
94 | AddNew(inLdCHlIndirect, 'LD', [ptRegC, ptRegHLIndir]);
|
---|
95 | AddNew(inLdBcIndirectA, 'LD', [ptRegBCIndir, ptRegA]);
|
---|
96 | AddNew(inLdHlIndirectNn, 'LD', [ptRegHLIndir, ptNumberWord]);
|
---|
97 | AddNew(inJpNn, 'JP', [ptNumberWord]);
|
---|
98 | AddNew(inJpZNn, 'JP', [ptFlagZ, ptNumberWord]);
|
---|
99 | AddNew(inCpN, 'CP', [ptNumberByte]);
|
---|
100 | AddNew(inCpD, 'CP', [ptRegD]);
|
---|
101 | AddNew(inCpE, 'CP', [ptRegE]);
|
---|
102 | AddNew(inCallNn, 'CALL', [ptNumberWord]);
|
---|
103 | AddNew(inRet, 'RET', []);
|
---|
104 | AddNew(inRst00, 'RST', [pt00]);
|
---|
105 | AddNew(inRst08, 'RST', [pt08]);
|
---|
106 | AddNew(inRst10, 'RST', [pt10]);
|
---|
107 | AddNew(inRst18, 'RST', [pt18]);
|
---|
108 | AddNew(inRst20, 'RST', [pt20]);
|
---|
109 | AddNew(inRst28, 'RST', [pt28]);
|
---|
110 | AddNew(inRst30, 'RST', [pt30]);
|
---|
111 | AddNew(inRst38, 'RST', [pt38]);
|
---|
112 | AddNew(inDi, 'DI', []);
|
---|
113 | AddNew(inEi, 'EI', []);
|
---|
114 | AddNew(inIm1, 'IM', [pt1]);
|
---|
115 | AddNew(inXorA, 'XOR', [ptRegA]);
|
---|
116 | AddNew(inPushBC, 'PUSH', [ptRegBC]);
|
---|
117 | AddNew(inPushDE, 'PUSH', [ptRegDE]);
|
---|
118 | AddNew(inPushHL, 'PUSH', [ptRegHL]);
|
---|
119 | AddNew(inSbcHlDe, 'SBC', [ptRegHL, ptRegDE]);
|
---|
120 | AddNew(inExDeHl, 'EX', [ptRegDE, ptRegHL]);
|
---|
121 | AddNew(inDecHl, 'DEC', [ptRegHL]);
|
---|
122 | AddNew(inDecB, 'INC', [ptRegB]);
|
---|
123 | AddNew(inIncHl, 'INC', [ptRegHL]);
|
---|
124 | AddNew(inIncBc, 'INC', [ptRegBC]);
|
---|
125 | AddNew(inIncB, 'INC', [ptRegB]);
|
---|
126 | AddNew(inLdHlIndirectE, 'LD', [ptRegHLIndir, ptRegE]);
|
---|
127 | AddNew(inLdHlIndirectD, 'LD', [ptRegHLIndir, ptRegD]);
|
---|
128 | AddNew(inLdAHlIndirect, 'LD', [ptRegA, ptRegHLIndir]);
|
---|
129 | AddNew(inJrNzD, 'JR', [ptFlagNZ, ptNumberByte]);
|
---|
130 | AddNew(inJrNcD, 'JR', [ptFlagNC, ptNumberByte]);
|
---|
131 | AddNew(inOutNA, 'OUT', [ptNumberByteIndir, ptRegA]);
|
---|
132 | end;
|
---|
133 |
|
---|
134 | destructor TInstructionSet.Destroy;
|
---|
135 | begin
|
---|
136 | FreeAndNil(Items);
|
---|
137 | inherited;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | end.
|
---|
141 |
|
---|