@andrivet/z80-assembler 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +35 -0
- package/.github/workflows/node.js.yml +47 -0
- package/.prettierignore +3 -0
- package/.prettierrc +3 -0
- package/.vscode/extensions.json +7 -0
- package/README.md +53 -27
- package/apps/.gitkeep +0 -0
- package/apps/z80-assembler-app/.eslintrc.json +18 -0
- package/apps/z80-assembler-app/index.html +16 -0
- package/apps/z80-assembler-app/postcss.config.js +24 -0
- package/apps/z80-assembler-app/project.json +70 -0
- package/apps/z80-assembler-app/public/favicon.ico +0 -0
- package/apps/z80-assembler-app/public/logo.png +0 -0
- package/apps/z80-assembler-app/public/logo192.png +0 -0
- package/apps/z80-assembler-app/public/logo512.png +0 -0
- package/apps/z80-assembler-app/public/manifest.json +25 -0
- package/apps/z80-assembler-app/public/robots.txt +3 -0
- package/apps/z80-assembler-app/src/app/app.module.css +0 -0
- package/apps/z80-assembler-app/src/app/app.tsx +122 -0
- package/apps/z80-assembler-app/src/app/binary.tsx +39 -0
- package/apps/z80-assembler-app/src/app/editor.tsx +228 -0
- package/apps/z80-assembler-app/src/app/errors.tsx +31 -0
- package/apps/z80-assembler-app/src/app/footer.tsx +20 -0
- package/apps/z80-assembler-app/src/app/header.tsx +57 -0
- package/apps/z80-assembler-app/src/app/misc.ts +13 -0
- package/apps/z80-assembler-app/src/app/opcodes.tsx +335 -0
- package/apps/z80-assembler-app/src/assets/.gitkeep +0 -0
- package/apps/z80-assembler-app/src/assets/images/logo192.png +0 -0
- package/apps/z80-assembler-app/src/main.tsx +22 -0
- package/apps/z80-assembler-app/src/styles.css +8 -0
- package/apps/z80-assembler-app/tailwind.config.js +28 -0
- package/apps/z80-assembler-app/tsconfig.app.json +22 -0
- package/apps/z80-assembler-app/tsconfig.json +21 -0
- package/apps/z80-assembler-app/tsconfig.spec.json +23 -0
- package/apps/z80-assembler-app/vite.config.ts +64 -0
- package/assets/images/compile.png +0 -0
- package/assets/images/logo.png +0 -0
- package/assets/images/menu.png +0 -0
- package/assets/images/opcodes-load8.png +0 -0
- package/assets/images/opcodes.png +0 -0
- package/assets/images/open-dir.png +0 -0
- package/assets/images/z80-assembler-app.png +0 -0
- package/docs/assembly.md +551 -0
- package/docs/images/ZX81-0x00.png +0 -0
- package/docs/images/ZX81-0x0B.png +0 -0
- package/docs/images/ZX81-0x0C.png +0 -0
- package/docs/images/ZX81-0x0D.png +0 -0
- package/docs/images/ZX81-0x0E.png +0 -0
- package/docs/images/ZX81-0x0F.png +0 -0
- package/docs/images/ZX81-0x10.png +0 -0
- package/docs/images/ZX81-0x11.png +0 -0
- package/docs/images/ZX81-0x12.png +0 -0
- package/docs/images/ZX81-0x13.png +0 -0
- package/docs/images/ZX81-0x14.png +0 -0
- package/docs/images/ZX81-0x15.png +0 -0
- package/docs/images/ZX81-0x16.png +0 -0
- package/docs/images/ZX81-0x17.png +0 -0
- package/docs/images/ZX81-0x18.png +0 -0
- package/docs/images/ZX81-0x19.png +0 -0
- package/docs/images/ZX81-0x1A.png +0 -0
- package/docs/images/ZX81-0x1B.png +0 -0
- package/docs/images/ZX81-0x1C.png +0 -0
- package/docs/images/ZX81-0x1D.png +0 -0
- package/docs/images/ZX81-0x1E.png +0 -0
- package/docs/images/ZX81-0x1F.png +0 -0
- package/docs/images/ZX81-0x20.png +0 -0
- package/docs/images/ZX81-0x21.png +0 -0
- package/docs/images/ZX81-0x22.png +0 -0
- package/docs/images/ZX81-0x23.png +0 -0
- package/docs/images/ZX81-0x24.png +0 -0
- package/docs/images/ZX81-0x25.png +0 -0
- package/docs/images/ZX81-0x26.png +0 -0
- package/docs/images/ZX81-0x27.png +0 -0
- package/docs/images/ZX81-0x28.png +0 -0
- package/docs/images/ZX81-0x29.png +0 -0
- package/docs/images/ZX81-0x2A.png +0 -0
- package/docs/images/ZX81-0x2B.png +0 -0
- package/docs/images/ZX81-0x2C.png +0 -0
- package/docs/images/ZX81-0x2D.png +0 -0
- package/docs/images/ZX81-0x2E.png +0 -0
- package/docs/images/ZX81-0x2F.png +0 -0
- package/docs/images/ZX81-0x30.png +0 -0
- package/docs/images/ZX81-0x31.png +0 -0
- package/docs/images/ZX81-0x32.png +0 -0
- package/docs/images/ZX81-0x33.png +0 -0
- package/docs/images/ZX81-0x34.png +0 -0
- package/docs/images/ZX81-0x35.png +0 -0
- package/docs/images/ZX81-0x36.png +0 -0
- package/docs/images/ZX81-0x37.png +0 -0
- package/docs/images/ZX81-0x38.png +0 -0
- package/docs/images/ZX81-0x39.png +0 -0
- package/docs/images/ZX81-0x3A.png +0 -0
- package/docs/images/ZX81-0x3B.png +0 -0
- package/docs/images/ZX81-0x3C.png +0 -0
- package/docs/images/ZX81-0x3D.png +0 -0
- package/docs/images/ZX81-0x3E.png +0 -0
- package/docs/images/ZX81-0x3F.png +0 -0
- package/docs/images/ZX81-0x80.png +0 -0
- package/docs/images/ZX81-0x8B.png +0 -0
- package/docs/images/ZX81-0x8C.png +0 -0
- package/docs/images/ZX81-0x8D.png +0 -0
- package/docs/images/ZX81-0x8E.png +0 -0
- package/docs/images/ZX81-0x8F.png +0 -0
- package/docs/images/ZX81-0x90.png +0 -0
- package/docs/images/ZX81-0x91.png +0 -0
- package/docs/images/ZX81-0x92.png +0 -0
- package/docs/images/ZX81-0x93.png +0 -0
- package/docs/images/ZX81-0x94.png +0 -0
- package/docs/images/ZX81-0x95.png +0 -0
- package/docs/images/ZX81-0x96.png +0 -0
- package/docs/images/ZX81-0x97.png +0 -0
- package/docs/images/ZX81-0x98.png +0 -0
- package/docs/images/ZX81-0x99.png +0 -0
- package/docs/images/ZX81-0x9A.png +0 -0
- package/docs/images/ZX81-0x9B.png +0 -0
- package/docs/images/ZX81-0x9C.png +0 -0
- package/docs/images/ZX81-0x9D.png +0 -0
- package/docs/images/ZX81-0x9E.png +0 -0
- package/docs/images/ZX81-0x9F.png +0 -0
- package/docs/images/ZX81-0xA0.png +0 -0
- package/docs/images/ZX81-0xA1.png +0 -0
- package/docs/images/ZX81-0xA2.png +0 -0
- package/docs/images/ZX81-0xA3.png +0 -0
- package/docs/images/ZX81-0xA4.png +0 -0
- package/docs/images/ZX81-0xA5.png +0 -0
- package/docs/images/ZX81-0xA6.png +0 -0
- package/docs/images/ZX81-0xA7.png +0 -0
- package/docs/images/ZX81-0xA8.png +0 -0
- package/docs/images/ZX81-0xA9.png +0 -0
- package/docs/images/ZX81-0xAA.png +0 -0
- package/docs/images/ZX81-0xAB.png +0 -0
- package/docs/images/ZX81-0xAC.png +0 -0
- package/docs/images/ZX81-0xAD.png +0 -0
- package/docs/images/ZX81-0xAE.png +0 -0
- package/docs/images/ZX81-0xAF.png +0 -0
- package/docs/images/ZX81-0xB0.png +0 -0
- package/docs/images/ZX81-0xB1.png +0 -0
- package/docs/images/ZX81-0xB2.png +0 -0
- package/docs/images/ZX81-0xB3.png +0 -0
- package/docs/images/ZX81-0xB4.png +0 -0
- package/docs/images/ZX81-0xB5.png +0 -0
- package/docs/images/ZX81-0xB6.png +0 -0
- package/docs/images/ZX81-0xB7.png +0 -0
- package/docs/images/ZX81-0xB8.png +0 -0
- package/docs/images/ZX81-0xB9.png +0 -0
- package/docs/images/ZX81-0xBA.png +0 -0
- package/docs/images/ZX81-0xBB.png +0 -0
- package/docs/images/ZX81-0xBC.png +0 -0
- package/docs/images/ZX81-0xBD.png +0 -0
- package/docs/images/ZX81-0xBE.png +0 -0
- package/docs/images/ZX81-0xBF.png +0 -0
- package/libs/.gitkeep +0 -0
- package/libs/z80-assembler/.eslintrc.json +18 -0
- package/libs/z80-assembler/package.json +20 -0
- package/libs/z80-assembler/project.json +35 -0
- package/libs/z80-assembler/public/README.md +54 -0
- package/{index.d.ts → libs/z80-assembler/src/index.ts} +1 -1
- package/libs/z80-assembler/src/lib/assets/code/basic-end.zx81 +4 -0
- package/libs/z80-assembler/src/lib/assets/code/basic-line1.zx81 +4 -0
- package/libs/z80-assembler/src/lib/assets/code/basic-line2.zx81 +9 -0
- package/libs/z80-assembler/src/lib/assets/code/characters.zx81 +190 -0
- package/libs/z80-assembler/src/lib/assets/code/display.zx81 +50 -0
- package/libs/z80-assembler/src/lib/assets/code/system-variables.zx81 +46 -0
- package/{lib/compiler/Assets.d.ts → libs/z80-assembler/src/lib/compiler/Assets.ts} +6 -1
- package/libs/z80-assembler/src/lib/compiler/Ast.ts +545 -0
- package/libs/z80-assembler/src/lib/compiler/Compiler.test.ts +2141 -0
- package/libs/z80-assembler/src/lib/compiler/Compiler.ts +185 -0
- package/libs/z80-assembler/src/lib/compiler/Formatter.ts +43 -0
- package/libs/z80-assembler/src/lib/compiler/Generator.ts +255 -0
- package/libs/z80-assembler/src/lib/compiler/Labels.ts +165 -0
- package/libs/z80-assembler/src/lib/grammar/LowLevel.ts +163 -0
- package/libs/z80-assembler/src/lib/grammar/Parse.ts +128 -0
- package/libs/z80-assembler/src/lib/grammar/z80.peg +1252 -0
- package/libs/z80-assembler/src/lib/grammar/z80.ts +10649 -0
- package/libs/z80-assembler/src/lib/types/Error.ts +105 -0
- package/{lib/types/Types.d.ts → libs/z80-assembler/src/lib/types/Types.ts} +26 -11
- package/libs/z80-assembler/tsconfig.json +23 -0
- package/libs/z80-assembler/tsconfig.lib.json +10 -0
- package/libs/z80-assembler/tsconfig.spec.json +19 -0
- package/libs/z80-assembler/vite.config.ts +58 -0
- package/nx.json +57 -0
- package/package.json +52 -14
- package/tsconfig.base.json +22 -0
- package/index.js +0 -312
- package/index.mjs +0 -6441
- package/lib/compiler/Ast.d.ts +0 -210
- package/lib/compiler/Compiler.d.ts +0 -53
- package/lib/compiler/Formatter.d.ts +0 -23
- package/lib/compiler/Generator.d.ts +0 -40
- package/lib/compiler/Labels.d.ts +0 -47
- package/lib/grammar/LowLevel.d.ts +0 -68
- package/lib/grammar/Parse.d.ts +0 -48
- package/lib/grammar/z80.d.ts +0 -2938
- package/lib/types/Error.d.ts +0 -62
- /package/{CHANGELOG.md → libs/z80-assembler/public/CHANGELOG.md} +0 -0
|
@@ -0,0 +1,2141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Compile.tests.ts
|
|
5
|
+
* Description: Tests of the compiler
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {compile as rawCompile} from "./Compiler";
|
|
12
|
+
import {expect} from "vitest";
|
|
13
|
+
|
|
14
|
+
function compileCode(code: string) {
|
|
15
|
+
const info = rawCompile('test.asm', code, () => '');
|
|
16
|
+
expect(info.errs[0]?.toString()).toBeUndefined();
|
|
17
|
+
return info.bytes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function compileCodes(codes: {filename: string, code: string}[]) {
|
|
21
|
+
const info = rawCompile(codes[0].filename, codes[0].code, (filename) =>
|
|
22
|
+
codes.find(c => c.filename === filename)?.code ?? '');
|
|
23
|
+
expect(info.errs[0]?.toString()).toBeUndefined();
|
|
24
|
+
return info.bytes;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function compileWithError(code: string) {
|
|
28
|
+
const info = rawCompile('test.asm', code, () => '');
|
|
29
|
+
expect(info.errs[0]?.toString()).toBeDefined();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function compileWithSld(code: string) {
|
|
33
|
+
const info = rawCompile('test.asm', code, () => '');
|
|
34
|
+
expect(info.sld).toBeDefined();
|
|
35
|
+
return {bytes: info.bytes, sld: info.sld};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// -------------------------------------------------------
|
|
39
|
+
// Numbers
|
|
40
|
+
// -------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
test("Loading decimal", () => {
|
|
43
|
+
const bytes = compileCode(' ld a, 123');
|
|
44
|
+
expect(bytes).toEqual([0x3e, 0x7B]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("Loading positive decimal", () => {
|
|
48
|
+
const bytes = compileCode(' ld a, +123');
|
|
49
|
+
expect(bytes).toEqual([0x3e, 0x7B]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("Loading negative decimal", () => {
|
|
53
|
+
const bytes = compileCode(' ld a, -123');
|
|
54
|
+
expect(bytes).toEqual([0x3e, 0x85]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("Loading hexadecimal with $", () => {
|
|
58
|
+
const bytes = compileCode(' ld a, $55');
|
|
59
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("Loading hexadecimal with #", () => {
|
|
63
|
+
const bytes = compileCode(' ld a, #55');
|
|
64
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
test("Loading hexadecimal with 0x", () => {
|
|
69
|
+
const bytes = compileCode(' ld a, 0x55');
|
|
70
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("Loading hexadecimal with 0X", () => {
|
|
74
|
+
const bytes = compileCode(' ld a, 0X55');
|
|
75
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("Loading hexadecimal with h", () => {
|
|
79
|
+
const bytes = compileCode(' ld a, 55h');
|
|
80
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("Loading hexadecimal with H", () => {
|
|
84
|
+
const bytes = compileCode(' ld a, 55H');
|
|
85
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("Loading hexadecimal with only letters", () => {
|
|
89
|
+
const bytes = compileCode(' ld a, abh');
|
|
90
|
+
expect(bytes).toEqual([0x3e, 0xab]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("Loading hexadecimal with letters prefixed with 0", () => {
|
|
94
|
+
const bytes = compileCode(' ld a, 0abh');
|
|
95
|
+
expect(bytes).toEqual([0x3e, 0xab]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("Loading hexadecimal with mix of cases", () => {
|
|
99
|
+
const bytes = compileCode(' ld a, Abh');
|
|
100
|
+
expect(bytes).toEqual([0x3e, 0xab]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("Loading binary with 0b", () => {
|
|
104
|
+
const bytes = compileCode(' ld a, 0b10101010');
|
|
105
|
+
expect(bytes).toEqual([0x3e, 0xAA]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("Loading binary with 0B", () => {
|
|
109
|
+
const bytes = compileCode(' ld a, 0B10101010');
|
|
110
|
+
expect(bytes).toEqual([0x3e, 0xAA]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("Loading binary with b suffix", () => {
|
|
114
|
+
const bytes = compileCode(' ld a, 10101010b');
|
|
115
|
+
expect(bytes).toEqual([0x3e, 0xAA]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("Loading binary with B suffix", () => {
|
|
119
|
+
const bytes = compileCode(' ld a, 10101010B');
|
|
120
|
+
expect(bytes).toEqual([0x3e, 0xAA]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
test("Loading binary with %", () => {
|
|
125
|
+
const bytes = compileCode(' ld a, %10101010');
|
|
126
|
+
expect(bytes).toEqual([0x3e, 0xAA]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("Loading octal with 0q", () => {
|
|
130
|
+
const bytes = compileCode(' ld a, 0q125');
|
|
131
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("Loading octal with 0o", () => {
|
|
135
|
+
const bytes = compileCode(' ld a, 0o125');
|
|
136
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("Loading octal with 0O", () => {
|
|
140
|
+
const bytes = compileCode(' ld a, 0O125');
|
|
141
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("Loading octal with q", () => {
|
|
145
|
+
const bytes = compileCode(' ld a, 125q');
|
|
146
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("Loading octal with Q", () => {
|
|
150
|
+
const bytes = compileCode(' ld a, 125Q');
|
|
151
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("Loading octal with o", () => {
|
|
155
|
+
const bytes = compileCode(' ld a, 125o');
|
|
156
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("Loading octal with O", () => {
|
|
160
|
+
const bytes = compileCode(' ld a, 125O');
|
|
161
|
+
expect(bytes).toEqual([0x3e, 0x55]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("Loading label with colon", () => {
|
|
165
|
+
const bytes = compileCode('ld a, 1\nlabel1:\nld a, label1');
|
|
166
|
+
expect(bytes).toEqual([0x3e, 0x01, 0x3e, 0x02]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("Loading label without colon", () => {
|
|
170
|
+
const bytes = compileCode('ld a, 1\nlabel1\nld a, label1');
|
|
171
|
+
expect(bytes).toEqual([0x3e, 0x01, 0x3e, 0x02]);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// "chances" starts wich "ch", that cam be confused with C in hexadecimal
|
|
175
|
+
test("Loading ambiguous label", () => {
|
|
176
|
+
const bytes = compileCode('chances eq 0x44\nld a, chances');
|
|
177
|
+
expect(bytes).toEqual([0x3e, 0x44]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// -------------------------------------------------------
|
|
181
|
+
// Expressions
|
|
182
|
+
// -------------------------------------------------------
|
|
183
|
+
|
|
184
|
+
test("Expression unary +", () => {
|
|
185
|
+
const bytes = compileCode('LD A, +$55');
|
|
186
|
+
expect(bytes).toEqual([0x3E, 0x55]);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("Expression unary +", () => {
|
|
190
|
+
const bytes = compileCode('LD A, -$55');
|
|
191
|
+
expect(bytes).toEqual([0x3E, 0xAB]);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("Expression binary +", () => {
|
|
195
|
+
const bytes = compileCode('LD A, $55 + 2');
|
|
196
|
+
expect(bytes).toEqual([0x3E, 0x57]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("Expression binary -", () => {
|
|
200
|
+
const bytes = compileCode('LD A, $55 - 2');
|
|
201
|
+
expect(bytes).toEqual([0x3E, 0x53]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("Expression *", () => {
|
|
205
|
+
const bytes = compileCode('LD A, $55 * 2');
|
|
206
|
+
expect(bytes).toEqual([0x3E, 0xAA]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("Expression /", () => {
|
|
210
|
+
const bytes = compileCode('LD A, $55 / 2');
|
|
211
|
+
expect(bytes).toEqual([0x3E, 0x2A]);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("Expression %", () => {
|
|
215
|
+
const bytes = compileCode('LD A, $55 % 2');
|
|
216
|
+
expect(bytes).toEqual([0x3E, 0x01]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("Expression <<", () => {
|
|
220
|
+
const bytes = compileCode('LD A, $55 << 1');
|
|
221
|
+
expect(bytes).toEqual([0x3E, 0xAA]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("Expression <<", () => {
|
|
225
|
+
const bytes = compileCode('LD A, $55 >> 4');
|
|
226
|
+
expect(bytes).toEqual([0x3E, 0x05]);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("Expression AND &", () => {
|
|
230
|
+
const bytes = compileCode('LD A, $55 & 0x06');
|
|
231
|
+
expect(bytes).toEqual([0x3E, 0x04]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("Expression XOR ^", () => {
|
|
235
|
+
const bytes = compileCode('LD A, $55 ^ 0xFA');
|
|
236
|
+
expect(bytes).toEqual([0x3E, 0xAF]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("Expression OR |", () => {
|
|
240
|
+
const bytes = compileCode('LD A, $55 | 0xAA');
|
|
241
|
+
expect(bytes).toEqual([0x3E, 0xFF]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("Expression with parenthesis at the beginning", () => {
|
|
245
|
+
const bytes = compileCode('LD A, ($55 + 2) % 28');
|
|
246
|
+
expect(bytes).toEqual([0x3E, 0x03]);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("Expression with parenthesis at the end", () => {
|
|
250
|
+
const bytes = compileCode('LD A, 2 * ($55 + 2)');
|
|
251
|
+
expect(bytes).toEqual([0x3E, 0xAE]);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("Expression with parenthesis int the middle", () => {
|
|
255
|
+
const bytes = compileCode('LD A, 2 * ($55 + 2) % 28');
|
|
256
|
+
expect(bytes).toEqual([0x3E, 0x06]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("Expression with multiple parenthesis", () => {
|
|
260
|
+
const bytes = compileCode('LD A, 2 * ($55 + ($44 - $42)) % 28');
|
|
261
|
+
expect(bytes).toEqual([0x3E, 0x06]);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("Expression with (left) additive associativity", () => {
|
|
265
|
+
const bytes = compileCode('LD A, 10 - 4 - 2 - 1');
|
|
266
|
+
expect(bytes).toEqual([0x3E, 0x03]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("Expression with (left) additive associativity and different operations", () => {
|
|
270
|
+
const bytes = compileCode('LD A, 42 + 3 + 1 - 4');
|
|
271
|
+
expect(bytes).toEqual([0x3E, 42]);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("Expression with multiplication, subtraction, division and a label", () => {
|
|
275
|
+
const bytes = compileCode('label1 equ 8\nLD A, 42 * 5 - label1 / 2');
|
|
276
|
+
expect(bytes).toEqual([0x3E, 206]);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("Expression with (left) multiplicative associativity", () => {
|
|
280
|
+
const bytes = compileCode('LD A, 20 / 2 / 5');
|
|
281
|
+
expect(bytes).toEqual([0x3E, 0x02]);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// -------------------------------------------------------
|
|
285
|
+
// Instructions
|
|
286
|
+
// -------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
test("Instruction LD r, r'", () => {
|
|
289
|
+
const bytes = compileCode('LD A, B');
|
|
290
|
+
expect(bytes).toEqual([0x78]);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("Instruction LD r, (HL)", () => {
|
|
294
|
+
const bytes = compileCode('LD B, (HL)');
|
|
295
|
+
expect(bytes).toEqual([0x46]);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("Instruction LD r, (HL) with E", () => {
|
|
299
|
+
const bytes = compileCode('LD E, (HL)');
|
|
300
|
+
expect(bytes).toEqual([0x5E]);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("Instruction LD r, (IX+d)", () => {
|
|
304
|
+
const bytes = compileCode('LD B, (IX+3)');
|
|
305
|
+
expect(bytes).toEqual([0xDD, 0x46, 0x03]);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test("Instruction LD r, (IX+d) with negative d", () => {
|
|
309
|
+
const bytes = compileCode('LD B, (IX-3)');
|
|
310
|
+
expect(bytes).toEqual([0xDD, 0x46, 0xFD]);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("Instruction LD r, (IX+d) with no d", () => {
|
|
314
|
+
const bytes = compileCode('LD B, (IX)');
|
|
315
|
+
expect(bytes).toEqual([0xDD, 0x46, 0x00]);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("Instruction LD r, (IY+d)", () => {
|
|
319
|
+
const bytes = compileCode('LD B, (IY+3)');
|
|
320
|
+
expect(bytes).toEqual([0xFD, 0x46, 0x03]);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("Instruction LD r, (IY+d)", () => {
|
|
324
|
+
const bytes = compileCode('LD B, (IY-3)');
|
|
325
|
+
expect(bytes).toEqual([0xFD, 0x46, 0xFD]);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("Instruction LD r, (IY)", () => {
|
|
329
|
+
const bytes = compileCode('LD B, (IY)');
|
|
330
|
+
expect(bytes).toEqual([0xFD, 0x46, 0x00]);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test("Instruction LD r, n with label", () => {
|
|
334
|
+
const bytes = compileCode('LD A, label1\nlabel1:');
|
|
335
|
+
expect(bytes).toEqual([0x3E, 0x02]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("Instruction LD (HL), r", () => {
|
|
339
|
+
const bytes = compileCode('LD (HL), B');
|
|
340
|
+
expect(bytes).toEqual([0x70]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("Instruction LD (HL), r", () => {
|
|
344
|
+
const bytes = compileCode('LD (HL), B');
|
|
345
|
+
expect(bytes).toEqual([0x70]);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("Instruction LD (IX+d), r", () => {
|
|
349
|
+
const bytes = compileCode('LD (IX+5), B');
|
|
350
|
+
expect(bytes).toEqual([0xDD, 0x70, 0x05]);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("Instruction LD (IX+d), r", () => {
|
|
354
|
+
const bytes = compileCode('LD (IY+5), B');
|
|
355
|
+
expect(bytes).toEqual([0xFD, 0x70, 0x05]);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test("Instruction LD (HL), n", () => {
|
|
359
|
+
const bytes = compileCode('LD (HL), 0x55');
|
|
360
|
+
expect(bytes).toEqual([0x36, 0x55]);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test("Instruction LD (HL), n with expression", () => {
|
|
364
|
+
const bytes = compileCode('LD (HL), 0 + (0x55 + 2) % 2');
|
|
365
|
+
expect(bytes).toEqual([0x36, 0x01]);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("Instruction LD (IX+d), n", () => {
|
|
369
|
+
const bytes = compileCode('LD (IX+3), 0x55');
|
|
370
|
+
expect(bytes).toEqual([0xDD, 0x36, 3, 0x55]);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test("Instruction LD (IY+d), n", () => {
|
|
374
|
+
const bytes = compileCode('LD (IY+3), 0x55');
|
|
375
|
+
expect(bytes).toEqual([0xFD, 0x36, 3, 0x55]);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("Instruction LD (IX), n", () => {
|
|
379
|
+
const bytes = compileCode('LD (IX), 0x55');
|
|
380
|
+
expect(bytes).toEqual([0xDD, 0x36, 0, 0x55]);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test("Instruction LD (IY), n", () => {
|
|
384
|
+
const bytes = compileCode('LD (IY), 0x55');
|
|
385
|
+
expect(bytes).toEqual([0xFD, 0x36, 0, 0x55]);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test("Instruction LD A, (BC)", () => {
|
|
389
|
+
const bytes = compileCode('LD A, (BC)');
|
|
390
|
+
expect(bytes).toEqual([0x0A]);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test("Instruction LD A, (DE)", () => {
|
|
394
|
+
const bytes = compileCode('LD A, (DE)');
|
|
395
|
+
expect(bytes).toEqual([0x1A]);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test("Instruction LD A, (nn)", () => {
|
|
399
|
+
const bytes = compileCode('LD A, (0x1234)');
|
|
400
|
+
expect(bytes).toEqual([0x3A, 0x34, 0x12]);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test("Instruction LD A, (label)", () => {
|
|
404
|
+
const bytes = compileCode('CHANCES EQ 0x44\nLD A, (CHANCES)');
|
|
405
|
+
expect(bytes).toEqual([0x3A, 0x44, 0x00]);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("Instruction LD A, (hex) with ambiguity", () => {
|
|
409
|
+
const bytes = compileCode('CH EQ 0x44\nLD A, (CH)');
|
|
410
|
+
expect(bytes).toEqual([0x3A, 0x0C, 0x00]);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test("Instruction LD (BC), A", () => {
|
|
414
|
+
const bytes = compileCode('LD (BC), A');
|
|
415
|
+
expect(bytes).toEqual([0x02]);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test("Instruction LD (DE), A", () => {
|
|
419
|
+
const bytes = compileCode('LD (DE), A');
|
|
420
|
+
expect(bytes).toEqual([0x12]);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test("Instruction LD (nn), A", () => {
|
|
424
|
+
const bytes = compileCode('LD (0x1234), A');
|
|
425
|
+
expect(bytes).toEqual([0x32, 0x34, 0x12]);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test("Instruction LD (nn), A with Expression", () => {
|
|
429
|
+
const bytes = compileCode('LD (0x1234 + 4), A');
|
|
430
|
+
expect(bytes).toEqual([0x32, 0x38, 0x12]);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test("Instruction LD A, I", () => {
|
|
434
|
+
const bytes = compileCode('LD A, I');
|
|
435
|
+
expect(bytes).toEqual([0xED, 0x57]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test("Instruction LD A, R", () => {
|
|
439
|
+
const bytes = compileCode('LD A, R');
|
|
440
|
+
expect(bytes).toEqual([0xED, 0x5F]);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
test("Instruction LD I, A", () => {
|
|
444
|
+
const bytes = compileCode('LD I, A');
|
|
445
|
+
expect(bytes).toEqual([0xED, 0x47]);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
test("Instruction LD R, A", () => {
|
|
449
|
+
const bytes = compileCode('LD R, A');
|
|
450
|
+
expect(bytes).toEqual([0xED, 0x4F]);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
test("Instruction LD r, n", () => {
|
|
454
|
+
const bytes = compileCode('LD A, $55');
|
|
455
|
+
expect(bytes).toEqual([0x3E, 0x55]);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
test("Instruction LD r, n with E", () => {
|
|
459
|
+
const bytes = compileCode('LD E, $55');
|
|
460
|
+
expect(bytes).toEqual([0x1E, 0x55]);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
test("Instruction LD dd, nn", () => {
|
|
465
|
+
const bytes = compileCode('LD BC, $55');
|
|
466
|
+
expect(bytes).toEqual([0x01, 0x55, 0x00]);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test("Instruction LD dd, nn with Expression", () => {
|
|
470
|
+
const bytes = compileCode('LD BC, $55 + 2');
|
|
471
|
+
expect(bytes).toEqual([0x01, 0x57, 0x00]);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test("Instruction LD IX, nn", () => {
|
|
475
|
+
const bytes = compileCode('LD IX, $55');
|
|
476
|
+
expect(bytes).toEqual([0xDD, 0x21, 0x55, 0x00]);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
test("Instruction LD IX, nn with Expression", () => {
|
|
480
|
+
const bytes = compileCode('LD IX, $55 + 2');
|
|
481
|
+
expect(bytes).toEqual([0xDD, 0x21, 0x57, 0x00]);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
test("Instruction LD IY, nn", () => {
|
|
485
|
+
const bytes = compileCode('LD IY, $55');
|
|
486
|
+
expect(bytes).toEqual([0xFD, 0x21, 0x55, 0x00]);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test("Instruction LD IY, nn with Expression", () => {
|
|
490
|
+
const bytes = compileCode('LD IY, $55 + 2');
|
|
491
|
+
expect(bytes).toEqual([0xFD, 0x21, 0x57, 0x00]);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
test("Instruction LD IX, (nn)", () => {
|
|
495
|
+
const bytes = compileCode('LD IX, ($5544)');
|
|
496
|
+
expect(bytes).toEqual([0xDD, 0x2A, 0x44, 0x55]);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
test("Instruction LD IX, (nn) with Expression", () => {
|
|
500
|
+
const bytes = compileCode('LD IX, ($5544 + 2)');
|
|
501
|
+
expect(bytes).toEqual([0xDD, 0x2A, 0x46, 0x55]);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("Instruction LD IY, (nn)", () => {
|
|
505
|
+
const bytes = compileCode('LD IY, ($5555)');
|
|
506
|
+
expect(bytes).toEqual([0xFD, 0x2A, 0x55, 0x55]);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
test("Instruction LD IY, (nn) with Expression", () => {
|
|
510
|
+
const bytes = compileCode('LD IY, ($5544 + 2)');
|
|
511
|
+
expect(bytes).toEqual([0xFD, 0x2A, 0x46, 0x55]);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
test("Instruction LD (nn), HL", () => {
|
|
515
|
+
const bytes = compileCode('LD ($5544), HL');
|
|
516
|
+
expect(bytes).toEqual([0x22, 0x44, 0x55]);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
test("Instruction LD (nn), HL with Expression", () => {
|
|
520
|
+
const bytes = compileCode('LD ($5544 + 2), HL');
|
|
521
|
+
expect(bytes).toEqual([0x22, 0x46, 0x55]);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
test("Instruction LD (nn), dd", () => {
|
|
525
|
+
const bytes = compileCode('LD ($5544), BC');
|
|
526
|
+
expect(bytes).toEqual([0xED, 0x43, 0x44, 0x55]);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test("Instruction LD (nn), dd with Expression", () => {
|
|
530
|
+
const bytes = compileCode('LD ($5544+2), BC');
|
|
531
|
+
expect(bytes).toEqual([0xED, 0x43, 0x46, 0x55]);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test("Instruction LD (nn), IX", () => {
|
|
535
|
+
const bytes = compileCode('LD ($5544), IX');
|
|
536
|
+
expect(bytes).toEqual([0xDD, 0x22, 0x44, 0x55]);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
test("Instruction LD (nn), IY", () => {
|
|
540
|
+
const bytes = compileCode('LD ($5544), IY');
|
|
541
|
+
expect(bytes).toEqual([0xFD, 0x22, 0x44, 0x55]);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
test("Instruction LD SP, HL", () => {
|
|
545
|
+
const bytes = compileCode('LD SP, HL');
|
|
546
|
+
expect(bytes).toEqual([0xF9]);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
test("Instruction LD SP, IX", () => {
|
|
550
|
+
const bytes = compileCode('LD SP, IX');
|
|
551
|
+
expect(bytes).toEqual([0xDD, 0xF9]);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
test("Instruction LD SP, IY", () => {
|
|
555
|
+
const bytes = compileCode('LD SP, IY');
|
|
556
|
+
expect(bytes).toEqual([0xFD, 0xF9]);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
test("Instruction PUSH qq", () => {
|
|
560
|
+
const bytes = compileCode('PUSH HL');
|
|
561
|
+
expect(bytes).toEqual([0xE5]);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
test("Instruction PUSH IX", () => {
|
|
565
|
+
const bytes = compileCode('PUSH IX');
|
|
566
|
+
expect(bytes).toEqual([0xDD, 0xE5]);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
test("Instruction PUSH IY", () => {
|
|
570
|
+
const bytes = compileCode('PUSH IY');
|
|
571
|
+
expect(bytes).toEqual([0xFD, 0xE5]);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
test("Instruction POP qq", () => {
|
|
575
|
+
const bytes = compileCode('POP HL');
|
|
576
|
+
expect(bytes).toEqual([0xE1]);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
test("Instruction POP IX", () => {
|
|
580
|
+
const bytes = compileCode('POP IX');
|
|
581
|
+
expect(bytes).toEqual([0xDD, 0xE1]);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
test("Instruction POP IY", () => {
|
|
585
|
+
const bytes = compileCode('POP IY');
|
|
586
|
+
expect(bytes).toEqual([0xFD, 0xE1]);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test("Instruction EX DE, HL", () => {
|
|
590
|
+
const bytes = compileCode('EX DE, HL');
|
|
591
|
+
expect(bytes).toEqual([0xEB]);
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
test("Instruction EX AF, AF'", () => {
|
|
595
|
+
const bytes = compileCode('EX AF, AF\'');
|
|
596
|
+
expect(bytes).toEqual([0x08]);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
test("Instruction EXX", () => {
|
|
600
|
+
const bytes = compileCode('EXX');
|
|
601
|
+
expect(bytes).toEqual([0xD9]);
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
test("Instruction EX (SP), HL", () => {
|
|
605
|
+
const bytes = compileCode('EX (SP), HL');
|
|
606
|
+
expect(bytes).toEqual([0xE3]);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("Instruction EX (SP), IX", () => {
|
|
610
|
+
const bytes = compileCode('EX (SP), IX');
|
|
611
|
+
expect(bytes).toEqual([0xDD, 0xE3]);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
test("Instruction EX (SP), IY", () => {
|
|
615
|
+
const bytes = compileCode('EX (SP), IY');
|
|
616
|
+
expect(bytes).toEqual([0xFD, 0xE3]);
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
test("Instruction LDI", () => {
|
|
620
|
+
const bytes = compileCode('LDI');
|
|
621
|
+
expect(bytes).toEqual([0xED, 0xA0]);
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
test("Instruction LDIR", () => {
|
|
625
|
+
const bytes = compileCode('LDIR');
|
|
626
|
+
expect(bytes).toEqual([0xED, 0xB0]);
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
test("Instruction LDI", () => {
|
|
630
|
+
const bytes = compileCode('LDI');
|
|
631
|
+
expect(bytes).toEqual([0xED, 0xA0]);
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
test("Instruction LDDR", () => {
|
|
635
|
+
const bytes = compileCode('LDDR');
|
|
636
|
+
expect(bytes).toEqual([0xED, 0xB8]);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("Instruction LDD", () => {
|
|
640
|
+
const bytes = compileCode('LDD');
|
|
641
|
+
expect(bytes).toEqual([0xED, 0xA8]);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
test("Instruction CPIR", () => {
|
|
645
|
+
const bytes = compileCode('CPIR');
|
|
646
|
+
expect(bytes).toEqual([0xED, 0xB1]);
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
test("Instruction CPI", () => {
|
|
650
|
+
const bytes = compileCode('CPI');
|
|
651
|
+
expect(bytes).toEqual([0xED, 0xA1]);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
test("Instruction CPDR", () => {
|
|
655
|
+
const bytes = compileCode('CPDR');
|
|
656
|
+
expect(bytes).toEqual([0xED, 0xB9]);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
test("Instruction CPD", () => {
|
|
660
|
+
const bytes = compileCode('CPD');
|
|
661
|
+
expect(bytes).toEqual([0xED, 0xA9]);
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
test("Instruction ADD A, r", () => {
|
|
665
|
+
const bytes = compileCode('ADD A, B');
|
|
666
|
+
expect(bytes).toEqual([0x80]);
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
test("Instruction ADD A, n", () => {
|
|
670
|
+
const bytes = compileCode('ADD A, 0x55');
|
|
671
|
+
expect(bytes).toEqual([0xC6, 0x55]);
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
test("Instruction ADD A, (HL)", () => {
|
|
675
|
+
const bytes = compileCode('ADD A, (HL)');
|
|
676
|
+
expect(bytes).toEqual([0x86]);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
test("Instruction ADD A, (IX+d)", () => {
|
|
680
|
+
const bytes = compileCode('ADD A, (IX+$55)');
|
|
681
|
+
expect(bytes).toEqual([0xDD, 0x86, 0x55]);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
test("Instruction ADD A, (IY+d)", () => {
|
|
685
|
+
const bytes = compileCode('ADD A, (IY+$55)');
|
|
686
|
+
expect(bytes).toEqual([0xFD, 0x86, 0x55]);
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
test("Instruction ADC A, r", () => {
|
|
690
|
+
const bytes = compileCode('ADC A, B');
|
|
691
|
+
expect(bytes).toEqual([0x88]);
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
test("Instruction ADC A, n", () => {
|
|
695
|
+
const bytes = compileCode('ADC A, 0x55');
|
|
696
|
+
expect(bytes).toEqual([0xCE, 0x55]);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
test("Instruction ADC A, (HL)", () => {
|
|
700
|
+
const bytes = compileCode('ADC A, (HL)');
|
|
701
|
+
expect(bytes).toEqual([0x8E]);
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
test("Instruction ADC A, (IX+d)", () => {
|
|
705
|
+
const bytes = compileCode('ADC A, (IX+$55)');
|
|
706
|
+
expect(bytes).toEqual([0xDD, 0x8E, 0x55]);
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
test("Instruction ADC A, (IY+d)", () => {
|
|
710
|
+
const bytes = compileCode('ADC A, (IY+$55)');
|
|
711
|
+
expect(bytes).toEqual([0xFD, 0x8E, 0x55]);
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
test("Instruction SUB A, r", () => {
|
|
715
|
+
const bytes = compileCode('SUB A, B');
|
|
716
|
+
expect(bytes).toEqual([0x90]);
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test("Instruction SUB A, n", () => {
|
|
720
|
+
const bytes = compileCode('SUB A, 0x55');
|
|
721
|
+
expect(bytes).toEqual([0xD6, 0x55]);
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
test("Instruction SUB A, (HL)", () => {
|
|
725
|
+
const bytes = compileCode('SUB A, (HL)');
|
|
726
|
+
expect(bytes).toEqual([0x96]);
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
test("Instruction SUB A, (IX+d)", () => {
|
|
730
|
+
const bytes = compileCode('SUB A, (IX+$55)');
|
|
731
|
+
expect(bytes).toEqual([0xDD, 0x96, 0x55]);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
test("Instruction SUB A, (IY+d)", () => {
|
|
735
|
+
const bytes = compileCode('SUB A, (IY+$55)');
|
|
736
|
+
expect(bytes).toEqual([0xFD, 0x96, 0x55]);
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
test("Instruction SBC A, r", () => {
|
|
740
|
+
const bytes = compileCode('SBC A, B');
|
|
741
|
+
expect(bytes).toEqual([0x98]);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
test("Instruction SBC A, n", () => {
|
|
745
|
+
const bytes = compileCode('SBC A, 0x55');
|
|
746
|
+
expect(bytes).toEqual([0xDE, 0x55]);
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
test("Instruction SBC A, (HL)", () => {
|
|
750
|
+
const bytes = compileCode('SBC A, (HL)');
|
|
751
|
+
expect(bytes).toEqual([0x9E]);
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
test("Instruction SBC A, (IX+d)", () => {
|
|
755
|
+
const bytes = compileCode('SBC A, (IX+$55)');
|
|
756
|
+
expect(bytes).toEqual([0xDD, 0x9E, 0x55]);
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
test("Instruction SBC A, (IY+d)", () => {
|
|
760
|
+
const bytes = compileCode('SBC A, (IY+$55)');
|
|
761
|
+
expect(bytes).toEqual([0xFD, 0x9E, 0x55]);
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
test("Instruction AND A, r", () => {
|
|
765
|
+
const bytes = compileCode('AND A, B');
|
|
766
|
+
expect(bytes).toEqual([0xA0]);
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
test("Instruction AND A, n", () => {
|
|
770
|
+
const bytes = compileCode('AND A, 0x55');
|
|
771
|
+
expect(bytes).toEqual([0xE6, 0x55]);
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
test("Instruction AND A, (HL)", () => {
|
|
775
|
+
const bytes = compileCode('AND A, (HL)');
|
|
776
|
+
expect(bytes).toEqual([0xA6]);
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
test("Instruction AND A, (IX+d)", () => {
|
|
780
|
+
const bytes = compileCode('AND A, (IX+$55)');
|
|
781
|
+
expect(bytes).toEqual([0xDD, 0xA6, 0x55]);
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
test("Instruction AND A, (IY+d)", () => {
|
|
785
|
+
const bytes = compileCode('AND A, (IY+$55)');
|
|
786
|
+
expect(bytes).toEqual([0xFD, 0xA6, 0x55]);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
test("Instruction OR A, r", () => {
|
|
790
|
+
const bytes = compileCode('OR A, B');
|
|
791
|
+
expect(bytes).toEqual([0xB0]);
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
test("Instruction OR A, n", () => {
|
|
795
|
+
const bytes = compileCode('OR A, 0x55');
|
|
796
|
+
expect(bytes).toEqual([0xF6, 0x55]);
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
test("Instruction OR A, (HL)", () => {
|
|
800
|
+
const bytes = compileCode('OR A, (HL)');
|
|
801
|
+
expect(bytes).toEqual([0xB6]);
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
test("Instruction OR A, (IX+d)", () => {
|
|
805
|
+
const bytes = compileCode('OR A, (IX+$55)');
|
|
806
|
+
expect(bytes).toEqual([0xDD, 0xB6, 0x55]);
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
test("Instruction OR A, (IY+d)", () => {
|
|
810
|
+
const bytes = compileCode('OR A, (IY+$55)');
|
|
811
|
+
expect(bytes).toEqual([0xFD, 0xB6, 0x55]);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
test("Instruction XOR A, r", () => {
|
|
815
|
+
const bytes = compileCode('XOR A, B');
|
|
816
|
+
expect(bytes).toEqual([0xA8]);
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
test("Instruction XOR A, n", () => {
|
|
820
|
+
const bytes = compileCode('XOR A, 0x55');
|
|
821
|
+
expect(bytes).toEqual([0xEE, 0x55]);
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
test("Instruction XOR A, (HL)", () => {
|
|
825
|
+
const bytes = compileCode('XOR A, (HL)');
|
|
826
|
+
expect(bytes).toEqual([0xAE]);
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
test("Instruction XOR A, (IX+d)", () => {
|
|
830
|
+
const bytes = compileCode('XOR A, (IX+$55)');
|
|
831
|
+
expect(bytes).toEqual([0xDD, 0xAE, 0x55]);
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
test("Instruction XOR A, (IY+d)", () => {
|
|
835
|
+
const bytes = compileCode('XOR A, (IY+$55)');
|
|
836
|
+
expect(bytes).toEqual([0xFD, 0xAE, 0x55]);
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
test("Instruction CP A, r", () => {
|
|
840
|
+
const bytes = compileCode('CP A, B');
|
|
841
|
+
expect(bytes).toEqual([0xB8]);
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
test("Instruction CP A, n", () => {
|
|
845
|
+
const bytes = compileCode('CP A, 0x55');
|
|
846
|
+
expect(bytes).toEqual([0xFE, 0x55]);
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
test("Instruction CP A, (HL)", () => {
|
|
850
|
+
const bytes = compileCode('CP A, (HL)');
|
|
851
|
+
expect(bytes).toEqual([0xBE]);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
test("Instruction CP A, (IX+d)", () => {
|
|
855
|
+
const bytes = compileCode('CP A, (IX+$55)');
|
|
856
|
+
expect(bytes).toEqual([0xDD, 0xBE, 0x55]);
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
test("Instruction CP A, (IY+d)", () => {
|
|
860
|
+
const bytes = compileCode('CP A, (IY+$55)');
|
|
861
|
+
expect(bytes).toEqual([0xFD, 0xBE, 0x55]);
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
test("Instruction ADD r", () => {
|
|
865
|
+
const bytes = compileCode('ADD B');
|
|
866
|
+
expect(bytes).toEqual([0x80]);
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
test("Instruction ADD n", () => {
|
|
870
|
+
const bytes = compileCode('ADD 0x55');
|
|
871
|
+
expect(bytes).toEqual([0xC6, 0x55]);
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
test("Instruction ADD (HL)", () => {
|
|
875
|
+
const bytes = compileCode('ADD (HL)');
|
|
876
|
+
expect(bytes).toEqual([0x86]);
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
test("Instruction ADD (IX+d)", () => {
|
|
880
|
+
const bytes = compileCode('ADD (IX+$55)');
|
|
881
|
+
expect(bytes).toEqual([0xDD, 0x86, 0x55]);
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
test("Instruction ADD (IY+d)", () => {
|
|
885
|
+
const bytes = compileCode('ADD (IY+$55)');
|
|
886
|
+
expect(bytes).toEqual([0xFD, 0x86, 0x55]);
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
test("Instruction ADC r", () => {
|
|
890
|
+
const bytes = compileCode('ADC B');
|
|
891
|
+
expect(bytes).toEqual([0x88]);
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
test("Instruction ADC n", () => {
|
|
895
|
+
const bytes = compileCode('ADC 0x55');
|
|
896
|
+
expect(bytes).toEqual([0xCE, 0x55]);
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
test("Instruction ADC (HL)", () => {
|
|
900
|
+
const bytes = compileCode('ADC (HL)');
|
|
901
|
+
expect(bytes).toEqual([0x8E]);
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
test("Instruction ADC (IX+d)", () => {
|
|
905
|
+
const bytes = compileCode('ADC (IX+$55)');
|
|
906
|
+
expect(bytes).toEqual([0xDD, 0x8E, 0x55]);
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
test("Instruction ADC (IY+d)", () => {
|
|
910
|
+
const bytes = compileCode('ADC (IY+$55)');
|
|
911
|
+
expect(bytes).toEqual([0xFD, 0x8E, 0x55]);
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
test("Instruction SUB r", () => {
|
|
915
|
+
const bytes = compileCode('SUB B');
|
|
916
|
+
expect(bytes).toEqual([0x90]);
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
test("Instruction SUB n", () => {
|
|
920
|
+
const bytes = compileCode('SUB 0x55');
|
|
921
|
+
expect(bytes).toEqual([0xD6, 0x55]);
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
test("Instruction SUB (HL)", () => {
|
|
925
|
+
const bytes = compileCode('SUB (HL)');
|
|
926
|
+
expect(bytes).toEqual([0x96]);
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
test("Instruction SUB (IX+d)", () => {
|
|
930
|
+
const bytes = compileCode('SUB (IX+$55)');
|
|
931
|
+
expect(bytes).toEqual([0xDD, 0x96, 0x55]);
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
test("Instruction SUB (IY+d)", () => {
|
|
935
|
+
const bytes = compileCode('SUB (IY+$55)');
|
|
936
|
+
expect(bytes).toEqual([0xFD, 0x96, 0x55]);
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
test("Instruction SBC r", () => {
|
|
940
|
+
const bytes = compileCode('SBC B');
|
|
941
|
+
expect(bytes).toEqual([0x98]);
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
test("Instruction SBC n", () => {
|
|
945
|
+
const bytes = compileCode('SBC 0x55');
|
|
946
|
+
expect(bytes).toEqual([0xDE, 0x55]);
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
test("Instruction SBC (HL)", () => {
|
|
950
|
+
const bytes = compileCode('SBC (HL)');
|
|
951
|
+
expect(bytes).toEqual([0x9E]);
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
test("Instruction SBC (IX+d)", () => {
|
|
955
|
+
const bytes = compileCode('SBC (IX+$55)');
|
|
956
|
+
expect(bytes).toEqual([0xDD, 0x9E, 0x55]);
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
test("Instruction SBC (IY+d)", () => {
|
|
960
|
+
const bytes = compileCode('SBC (IY+$55)');
|
|
961
|
+
expect(bytes).toEqual([0xFD, 0x9E, 0x55]);
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
test("Instruction AND r", () => {
|
|
965
|
+
const bytes = compileCode('AND B');
|
|
966
|
+
expect(bytes).toEqual([0xA0]);
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
test("Instruction AND n", () => {
|
|
970
|
+
const bytes = compileCode('AND 0x55');
|
|
971
|
+
expect(bytes).toEqual([0xE6, 0x55]);
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
test("Instruction AND (HL)", () => {
|
|
975
|
+
const bytes = compileCode('AND (HL)');
|
|
976
|
+
expect(bytes).toEqual([0xA6]);
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
test("Instruction AND (IX+d)", () => {
|
|
980
|
+
const bytes = compileCode('AND (IX+$55)');
|
|
981
|
+
expect(bytes).toEqual([0xDD, 0xA6, 0x55]);
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
test("Instruction AND (IY+d)", () => {
|
|
985
|
+
const bytes = compileCode('AND (IY+$55)');
|
|
986
|
+
expect(bytes).toEqual([0xFD, 0xA6, 0x55]);
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
test("Instruction OR r", () => {
|
|
990
|
+
const bytes = compileCode('OR B');
|
|
991
|
+
expect(bytes).toEqual([0xB0]);
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
test("Instruction OR n", () => {
|
|
995
|
+
const bytes = compileCode('OR 0x55');
|
|
996
|
+
expect(bytes).toEqual([0xF6, 0x55]);
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
test("Instruction OR (HL)", () => {
|
|
1000
|
+
const bytes = compileCode('OR (HL)');
|
|
1001
|
+
expect(bytes).toEqual([0xB6]);
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
test("Instruction OR (IX+d)", () => {
|
|
1005
|
+
const bytes = compileCode('OR (IX+$55)');
|
|
1006
|
+
expect(bytes).toEqual([0xDD, 0xB6, 0x55]);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
test("Instruction OR (IY+d)", () => {
|
|
1010
|
+
const bytes = compileCode('OR (IY+$55)');
|
|
1011
|
+
expect(bytes).toEqual([0xFD, 0xB6, 0x55]);
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
test("Instruction XOR r", () => {
|
|
1015
|
+
const bytes = compileCode('XOR B');
|
|
1016
|
+
expect(bytes).toEqual([0xA8]);
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
test("Instruction XOR n", () => {
|
|
1020
|
+
const bytes = compileCode('XOR 0x55');
|
|
1021
|
+
expect(bytes).toEqual([0xEE, 0x55]);
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
test("Instruction XOR (HL)", () => {
|
|
1025
|
+
const bytes = compileCode('XOR (HL)');
|
|
1026
|
+
expect(bytes).toEqual([0xAE]);
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
test("Instruction XOR (IX+d)", () => {
|
|
1030
|
+
const bytes = compileCode('XOR (IX+$55)');
|
|
1031
|
+
expect(bytes).toEqual([0xDD, 0xAE, 0x55]);
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
test("Instruction XOR (IY+d)", () => {
|
|
1035
|
+
const bytes = compileCode('XOR (IY+$55)');
|
|
1036
|
+
expect(bytes).toEqual([0xFD, 0xAE, 0x55]);
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
test("Instruction CP r", () => {
|
|
1040
|
+
const bytes = compileCode('CP B');
|
|
1041
|
+
expect(bytes).toEqual([0xB8]);
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
test("Instruction CP n", () => {
|
|
1045
|
+
const bytes = compileCode('CP 0x55');
|
|
1046
|
+
expect(bytes).toEqual([0xFE, 0x55]);
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
test("Instruction CP (HL)", () => {
|
|
1050
|
+
const bytes = compileCode('CP (HL)');
|
|
1051
|
+
expect(bytes).toEqual([0xBE]);
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
test("Instruction CP (IX+d)", () => {
|
|
1055
|
+
const bytes = compileCode('CP (IX+$55)');
|
|
1056
|
+
expect(bytes).toEqual([0xDD, 0xBE, 0x55]);
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
test("Instruction CP (IY+d)", () => {
|
|
1060
|
+
const bytes = compileCode('CP (IY+$55)');
|
|
1061
|
+
expect(bytes).toEqual([0xFD, 0xBE, 0x55]);
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
test("Instruction INC r", () => {
|
|
1065
|
+
const bytes = compileCode('INC B');
|
|
1066
|
+
expect(bytes).toEqual([0x04]);
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
test("Instruction INC (HL)", () => {
|
|
1070
|
+
const bytes = compileCode('INC (HL)');
|
|
1071
|
+
expect(bytes).toEqual([0x34]);
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
test("Instruction INC (IX+d)", () => {
|
|
1075
|
+
const bytes = compileCode('INC (IX+$55)');
|
|
1076
|
+
expect(bytes).toEqual([0xDD, 0x34, 0x55]);
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
test("Instruction INC (IY+d)", () => {
|
|
1080
|
+
const bytes = compileCode('INC (IY+$55)');
|
|
1081
|
+
expect(bytes).toEqual([0xFD, 0x34, 0x55]);
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
test("Instruction DEC r", () => {
|
|
1085
|
+
const bytes = compileCode('DEC B');
|
|
1086
|
+
expect(bytes).toEqual([0x05]);
|
|
1087
|
+
});
|
|
1088
|
+
|
|
1089
|
+
test("Instruction DEC (HL)", () => {
|
|
1090
|
+
const bytes = compileCode('DEC (HL)');
|
|
1091
|
+
expect(bytes).toEqual([0x35]);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
test("Instruction DEC (IX+d)", () => {
|
|
1095
|
+
const bytes = compileCode('DEC (IX+$55)');
|
|
1096
|
+
expect(bytes).toEqual([0xDD, 0x35, 0x55]);
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
test("Instruction DEC (IY+d)", () => {
|
|
1100
|
+
const bytes = compileCode('DEC (IY+$55)');
|
|
1101
|
+
expect(bytes).toEqual([0xFD, 0x35, 0x55]);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
test("Instruction DAA", () => {
|
|
1105
|
+
const bytes = compileCode('DAA');
|
|
1106
|
+
expect(bytes).toEqual([0x27]);
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
test("Instruction CPL", () => {
|
|
1110
|
+
const bytes = compileCode('CPL');
|
|
1111
|
+
expect(bytes).toEqual([0x2F]);
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
test("Instruction NEG", () => {
|
|
1115
|
+
const bytes = compileCode('NEG');
|
|
1116
|
+
expect(bytes).toEqual([0xED, 0x44]);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
test("Instruction CCF", () => {
|
|
1120
|
+
const bytes = compileCode('CCF');
|
|
1121
|
+
expect(bytes).toEqual([0x3F]);
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
test("Instruction SCF", () => {
|
|
1125
|
+
const bytes = compileCode('SCF');
|
|
1126
|
+
expect(bytes).toEqual([0x37]);
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
test("Instruction NOP", () => {
|
|
1130
|
+
const bytes = compileCode('NOP');
|
|
1131
|
+
expect(bytes).toEqual([0x00]);
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
test("Instruction HALT", () => {
|
|
1135
|
+
const bytes = compileCode('HALT');
|
|
1136
|
+
expect(bytes).toEqual([0x76]);
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
test("Instruction DI", () => {
|
|
1140
|
+
const bytes = compileCode('DI');
|
|
1141
|
+
expect(bytes).toEqual([0xF3]);
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
test("Instruction EI", () => {
|
|
1145
|
+
const bytes = compileCode('EI');
|
|
1146
|
+
expect(bytes).toEqual([0xFB]);
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
test("Instruction IM 0", () => {
|
|
1150
|
+
const bytes = compileCode('IM 0');
|
|
1151
|
+
expect(bytes).toEqual([0xED, 0x46]);
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
test("Instruction IM 1", () => {
|
|
1155
|
+
const bytes = compileCode('IM 1');
|
|
1156
|
+
expect(bytes).toEqual([0xED, 0x56]);
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
test("Instruction IM 2", () => {
|
|
1160
|
+
const bytes = compileCode('IM 2');
|
|
1161
|
+
expect(bytes).toEqual([0xED, 0x5E]);
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
test("Instruction ADD HL, ss", () => {
|
|
1165
|
+
const bytes = compileCode('ADD HL, BC');
|
|
1166
|
+
expect(bytes).toEqual([0x09]);
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
test("Instruction ADC HL, ss", () => {
|
|
1170
|
+
const bytes = compileCode('ADC HL, BC');
|
|
1171
|
+
expect(bytes).toEqual([0xED, 0x4A]);
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
test("Instruction SBC HL, ss", () => {
|
|
1175
|
+
const bytes = compileCode('SBC HL, BC');
|
|
1176
|
+
expect(bytes).toEqual([0xED, 0x42]);
|
|
1177
|
+
});
|
|
1178
|
+
|
|
1179
|
+
test("Instruction ADD IX, ss", () => {
|
|
1180
|
+
const bytes = compileCode('ADD IX, BC');
|
|
1181
|
+
expect(bytes).toEqual([0xDD, 0x09]);
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
test("Instruction ADD IY, ss", () => {
|
|
1185
|
+
const bytes = compileCode('ADD IY, BC');
|
|
1186
|
+
expect(bytes).toEqual([0xFD, 0x09]);
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
test("Instruction INC ss", () => {
|
|
1190
|
+
const bytes = compileCode('INC BC');
|
|
1191
|
+
expect(bytes).toEqual([0x03]);
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
test("Instruction INC IX", () => {
|
|
1195
|
+
const bytes = compileCode('INC IX');
|
|
1196
|
+
expect(bytes).toEqual([0xDD, 0x23]);
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
test("Instruction INC IY", () => {
|
|
1200
|
+
const bytes = compileCode('INC IY');
|
|
1201
|
+
expect(bytes).toEqual([0xFD, 0x23]);
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
test("Instruction DEC ss", () => {
|
|
1205
|
+
const bytes = compileCode('DEC BC');
|
|
1206
|
+
expect(bytes).toEqual([0x0B]);
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1209
|
+
test("Instruction DEC IX", () => {
|
|
1210
|
+
const bytes = compileCode('DEC IX');
|
|
1211
|
+
expect(bytes).toEqual([0xDD, 0x2B]);
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
test("Instruction DEC IY", () => {
|
|
1215
|
+
const bytes = compileCode('DEC IY');
|
|
1216
|
+
expect(bytes).toEqual([0xFD, 0x2B]);
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
test("Instruction RLCA", () => {
|
|
1220
|
+
const bytes = compileCode('RLCA');
|
|
1221
|
+
expect(bytes).toEqual([0x07]);
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
test("Instruction RLA", () => {
|
|
1225
|
+
const bytes = compileCode('RLA');
|
|
1226
|
+
expect(bytes).toEqual([0x17]);
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
test("Instruction RRCA", () => {
|
|
1230
|
+
const bytes = compileCode('RRCA');
|
|
1231
|
+
expect(bytes).toEqual([0x0F]);
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
test("Instruction RRA", () => {
|
|
1235
|
+
const bytes = compileCode('RRA');
|
|
1236
|
+
expect(bytes).toEqual([0x1F]);
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
test("Instruction RLC r", () => {
|
|
1240
|
+
const bytes = compileCode('RLC B');
|
|
1241
|
+
expect(bytes).toEqual([0xCB, 0x00]);
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
test("Instruction RLC (HL)", () => {
|
|
1245
|
+
const bytes = compileCode('RLC (HL)');
|
|
1246
|
+
expect(bytes).toEqual([0xCB, 0x06]);
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
test("Instruction RLC (IX+d)", () => {
|
|
1250
|
+
const bytes = compileCode('RLC (IX+3)');
|
|
1251
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x06]);
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
test("Instruction RLC (IY+d)", () => {
|
|
1255
|
+
const bytes = compileCode('RLC (IY+3)');
|
|
1256
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x06]);
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
test("Instruction RL r", () => {
|
|
1260
|
+
const bytes = compileCode('RL B');
|
|
1261
|
+
expect(bytes).toEqual([0xCB, 0x10]);
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
test("Instruction RL (HL)", () => {
|
|
1265
|
+
const bytes = compileCode('RL (HL)');
|
|
1266
|
+
expect(bytes).toEqual([0xCB, 0x16]);
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
test("Instruction RL (IX+d)", () => {
|
|
1270
|
+
const bytes = compileCode('RL (IX+3)');
|
|
1271
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x16]);
|
|
1272
|
+
});
|
|
1273
|
+
|
|
1274
|
+
test("Instruction RL (IY+d)", () => {
|
|
1275
|
+
const bytes = compileCode('RL (IY+3)');
|
|
1276
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x16]);
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
test("Instruction RRC r", () => {
|
|
1280
|
+
const bytes = compileCode('RRC B');
|
|
1281
|
+
expect(bytes).toEqual([0xCB, 0x08]);
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1284
|
+
test("Instruction RRC (HL)", () => {
|
|
1285
|
+
const bytes = compileCode('RRC (HL)');
|
|
1286
|
+
expect(bytes).toEqual([0xCB, 0x0E]);
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
test("Instruction RRC (IX+d)", () => {
|
|
1290
|
+
const bytes = compileCode('RRC (IX+3)');
|
|
1291
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x0E]);
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
test("Instruction RRC (IY+d)", () => {
|
|
1295
|
+
const bytes = compileCode('RRC (IY+3)');
|
|
1296
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x0E]);
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
test("Instruction RR r", () => {
|
|
1300
|
+
const bytes = compileCode('RR B');
|
|
1301
|
+
expect(bytes).toEqual([0xCB, 0x18]);
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1304
|
+
test("Instruction RR (HL)", () => {
|
|
1305
|
+
const bytes = compileCode('RR (HL)');
|
|
1306
|
+
expect(bytes).toEqual([0xCB, 0x1E]);
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
test("Instruction RR (IX+d)", () => {
|
|
1310
|
+
const bytes = compileCode('RR (IX+3)');
|
|
1311
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x1E]);
|
|
1312
|
+
});
|
|
1313
|
+
|
|
1314
|
+
test("Instruction RR (IY+d)", () => {
|
|
1315
|
+
const bytes = compileCode('RR (IY+3)');
|
|
1316
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x1E]);
|
|
1317
|
+
});
|
|
1318
|
+
|
|
1319
|
+
test("Instruction SLA r", () => {
|
|
1320
|
+
const bytes = compileCode('SLA B');
|
|
1321
|
+
expect(bytes).toEqual([0xCB, 0x20]);
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
test("Instruction SLA (HL)", () => {
|
|
1325
|
+
const bytes = compileCode('SLA (HL)');
|
|
1326
|
+
expect(bytes).toEqual([0xCB, 0x26]);
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
test("Instruction SLA (IX+d)", () => {
|
|
1330
|
+
const bytes = compileCode('SLA (IX+3)');
|
|
1331
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x26]);
|
|
1332
|
+
});
|
|
1333
|
+
|
|
1334
|
+
test("Instruction SLA (IY+d)", () => {
|
|
1335
|
+
const bytes = compileCode('SLA (IY+3)');
|
|
1336
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x26]);
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
test("Instruction SRA r", () => {
|
|
1340
|
+
const bytes = compileCode('SRA B');
|
|
1341
|
+
expect(bytes).toEqual([0xCB, 0x28]);
|
|
1342
|
+
});
|
|
1343
|
+
|
|
1344
|
+
test("Instruction SRA (HL)", () => {
|
|
1345
|
+
const bytes = compileCode('SRA (HL)');
|
|
1346
|
+
expect(bytes).toEqual([0xCB, 0x2E]);
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
test("Instruction SRA (IX+d)", () => {
|
|
1350
|
+
const bytes = compileCode('SRA (IX+3)');
|
|
1351
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x2E]);
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
test("Instruction SRA (IY+d)", () => {
|
|
1355
|
+
const bytes = compileCode('SRA (IY+3)');
|
|
1356
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x2E]);
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
test("Instruction SRL r", () => {
|
|
1360
|
+
const bytes = compileCode('SRL B');
|
|
1361
|
+
expect(bytes).toEqual([0xCB, 0x38]);
|
|
1362
|
+
});
|
|
1363
|
+
|
|
1364
|
+
test("Instruction SRL (HL)", () => {
|
|
1365
|
+
const bytes = compileCode('SRL (HL)');
|
|
1366
|
+
expect(bytes).toEqual([0xCB, 0x3E]);
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
test("Instruction SRL (IX+d)", () => {
|
|
1370
|
+
const bytes = compileCode('SRL (IX+3)');
|
|
1371
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x3E]);
|
|
1372
|
+
});
|
|
1373
|
+
|
|
1374
|
+
test("Instruction SRL (IY+d)", () => {
|
|
1375
|
+
const bytes = compileCode('SRL (IY+3)');
|
|
1376
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x3E]);
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
test("Instruction RLD", () => {
|
|
1380
|
+
const bytes = compileCode('RLD');
|
|
1381
|
+
expect(bytes).toEqual([0xED, 0x6F]);
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
test("Instruction RRD", () => {
|
|
1385
|
+
const bytes = compileCode('RRD');
|
|
1386
|
+
expect(bytes).toEqual([0xED, 0x67]);
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
test("Instruction BIT b, r", () => {
|
|
1390
|
+
const bytes = compileCode('BIT 2, B');
|
|
1391
|
+
expect(bytes).toEqual([0xCB, 0x50]);
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
test("Instruction BIT b, (HL)", () => {
|
|
1395
|
+
const bytes = compileCode('BIT 2, (HL)');
|
|
1396
|
+
expect(bytes).toEqual([0xCB, 0x56]);
|
|
1397
|
+
});
|
|
1398
|
+
|
|
1399
|
+
test("Instruction BIT b, (IX+d)", () => {
|
|
1400
|
+
const bytes = compileCode('BIT 2, (IX+3)');
|
|
1401
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x56]);
|
|
1402
|
+
});
|
|
1403
|
+
|
|
1404
|
+
test("Instruction BIT b, (IY+d)", () => {
|
|
1405
|
+
const bytes = compileCode('BIT 2, (IY+3)');
|
|
1406
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x56]);
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
test("Instruction SET b, r", () => {
|
|
1410
|
+
const bytes = compileCode('SET 2, B');
|
|
1411
|
+
expect(bytes).toEqual([0xCB, 0xD0]);
|
|
1412
|
+
});
|
|
1413
|
+
|
|
1414
|
+
test("Instruction SET b, (HL)", () => {
|
|
1415
|
+
const bytes = compileCode('SET 2, (HL)');
|
|
1416
|
+
expect(bytes).toEqual([0xCB, 0xD6]);
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
test("Instruction SET b, (IX+d)", () => {
|
|
1420
|
+
const bytes = compileCode('SET 2, (IX+3)');
|
|
1421
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0xD6]);
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
test("Instruction SET b, (IY+d)", () => {
|
|
1425
|
+
const bytes = compileCode('SET 2, (IY+3)');
|
|
1426
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0xD6]);
|
|
1427
|
+
});
|
|
1428
|
+
|
|
1429
|
+
test("Instruction RES b, r", () => {
|
|
1430
|
+
const bytes = compileCode('RES 2, B');
|
|
1431
|
+
expect(bytes).toEqual([0xCB, 0x90]);
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
test("Instruction RES b, (HL)", () => {
|
|
1435
|
+
const bytes = compileCode('RES 2, (HL)');
|
|
1436
|
+
expect(bytes).toEqual([0xCB, 0x96]);
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
test("Instruction RES b, (IX+d)", () => {
|
|
1440
|
+
const bytes = compileCode('RES 2, (IX+3)');
|
|
1441
|
+
expect(bytes).toEqual([0xDD, 0xCB, 0x03, 0x96]);
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
test("Instruction RES b, (IY+d)", () => {
|
|
1445
|
+
const bytes = compileCode('RES 2, (IY+3)');
|
|
1446
|
+
expect(bytes).toEqual([0xFD, 0xCB, 0x03, 0x96]);
|
|
1447
|
+
});
|
|
1448
|
+
|
|
1449
|
+
test("Instruction JP nn", () => {
|
|
1450
|
+
const bytes = compileCode('JP $5522');
|
|
1451
|
+
expect(bytes).toEqual([0xC3, 0x22, 0x55]);
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1454
|
+
test("Instruction JP NZ, nn", () => {
|
|
1455
|
+
const bytes = compileCode('JP NZ, $5522');
|
|
1456
|
+
expect(bytes).toEqual([0xC2, 0x22, 0x55]);
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
test("Instruction JP Z, nn", () => {
|
|
1460
|
+
const bytes = compileCode('JP Z, $5522');
|
|
1461
|
+
expect(bytes).toEqual([0xCA, 0x22, 0x55]);
|
|
1462
|
+
});
|
|
1463
|
+
|
|
1464
|
+
test("Instruction JP NC, nn", () => {
|
|
1465
|
+
const bytes = compileCode('JP NC, $5522');
|
|
1466
|
+
expect(bytes).toEqual([0xD2, 0x22, 0x55]);
|
|
1467
|
+
});
|
|
1468
|
+
|
|
1469
|
+
test("Instruction JP C, nn", () => {
|
|
1470
|
+
const bytes = compileCode('JP C, $5522');
|
|
1471
|
+
expect(bytes).toEqual([0xDA, 0x22, 0x55]);
|
|
1472
|
+
});
|
|
1473
|
+
|
|
1474
|
+
test("Instruction JP PO, nn", () => {
|
|
1475
|
+
const bytes = compileCode('JP PO, $5522');
|
|
1476
|
+
expect(bytes).toEqual([0xE2, 0x22, 0x55]);
|
|
1477
|
+
});
|
|
1478
|
+
|
|
1479
|
+
test("Instruction JP PE, nn", () => {
|
|
1480
|
+
const bytes = compileCode('JP PE, $5522');
|
|
1481
|
+
expect(bytes).toEqual([0xEA, 0x22, 0x55]);
|
|
1482
|
+
});
|
|
1483
|
+
|
|
1484
|
+
test("Instruction JP P, nn", () => {
|
|
1485
|
+
const bytes = compileCode('JP P, $5522');
|
|
1486
|
+
expect(bytes).toEqual([0xF2, 0x22, 0x55]);
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
test("Instruction JP M, nn", () => {
|
|
1490
|
+
const bytes = compileCode('JP M, $5522');
|
|
1491
|
+
expect(bytes).toEqual([0xFA, 0x22, 0x55]);
|
|
1492
|
+
});
|
|
1493
|
+
|
|
1494
|
+
test("Instruction JR e", () => {
|
|
1495
|
+
const bytes = compileCode('JR 24');
|
|
1496
|
+
expect(bytes).toEqual([0x18, 0x16]);
|
|
1497
|
+
});
|
|
1498
|
+
|
|
1499
|
+
test("Instruction JR e with negative offset", () => {
|
|
1500
|
+
const bytes = compileCode('JR -24');
|
|
1501
|
+
expect(bytes).toEqual([0x18, 0xE6]);
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
test("Instruction JR e on the next instruction", () => {
|
|
1505
|
+
const bytes = compileCode('NOP\nNOP\nJR label1\nlabel1:\nNOP\nNOP\nNOP\n');
|
|
1506
|
+
expect(bytes).toEqual([0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00]);
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
test("Instruction JR e with forward label", () => {
|
|
1510
|
+
const bytes = compileCode('NOP\nNOP\nJR label1\nNOP\nNOP\nNOP\nlabel1:');
|
|
1511
|
+
expect(bytes).toEqual([0x00, 0x00, 0x18, 0x03, 0x00, 0x00, 0x00]);
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
test("Instruction JR e with backward label", () => {
|
|
1515
|
+
const bytes = compileCode('label1:\nNOP\nNOP\nNOP\nNOP\nJR label1');
|
|
1516
|
+
expect(bytes).toEqual([0x00, 0x00, 0x00, 0x00, 0x18, 0xFA]);
|
|
1517
|
+
});
|
|
1518
|
+
|
|
1519
|
+
test("Instruction JR NZ, e", () => {
|
|
1520
|
+
const bytes = compileCode('JR NZ, 24');
|
|
1521
|
+
expect(bytes).toEqual([0x20, 0x16]);
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
test("Instruction JR Z, e", () => {
|
|
1525
|
+
const bytes = compileCode('JR Z, 24');
|
|
1526
|
+
expect(bytes).toEqual([0x28, 0x16]);
|
|
1527
|
+
});
|
|
1528
|
+
|
|
1529
|
+
test("Instruction JR NC, e", () => {
|
|
1530
|
+
const bytes = compileCode('JR NC, 24');
|
|
1531
|
+
expect(bytes).toEqual([0x30, 0x16]);
|
|
1532
|
+
});
|
|
1533
|
+
|
|
1534
|
+
test("Instruction JR C, e", () => {
|
|
1535
|
+
const bytes = compileCode('JR C, 24');
|
|
1536
|
+
expect(bytes).toEqual([0x38, 0x16]);
|
|
1537
|
+
});
|
|
1538
|
+
|
|
1539
|
+
test("Instruction JP (HL)", () => {
|
|
1540
|
+
const bytes = compileCode('JP (HL)');
|
|
1541
|
+
expect(bytes).toEqual([0xE9]);
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
test("Instruction JP (IX)", () => {
|
|
1545
|
+
const bytes = compileCode('JP (IX)');
|
|
1546
|
+
expect(bytes).toEqual([0xDD, 0xE9]);
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
test("Instruction JP (IY)", () => {
|
|
1550
|
+
const bytes = compileCode('JP (IY)');
|
|
1551
|
+
expect(bytes).toEqual([0xFD, 0xE9]);
|
|
1552
|
+
});
|
|
1553
|
+
|
|
1554
|
+
test("Instruction DJNZ e", () => {
|
|
1555
|
+
const bytes = compileCode('DJNZ $55');
|
|
1556
|
+
expect(bytes).toEqual([0x10, 0x53]);
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1559
|
+
test("Instruction DJNZ e with negative offset", () => {
|
|
1560
|
+
const bytes = compileCode('DJNZ -24');
|
|
1561
|
+
expect(bytes).toEqual([0x10, 0xE6]);
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
test("Instruction DJNZ e with forward label", () => {
|
|
1565
|
+
const bytes = compileCode('DJNZ label1\ndb $55\nlabel1:');
|
|
1566
|
+
expect(bytes).toEqual([0x10, 0x01, 0x55]);
|
|
1567
|
+
});
|
|
1568
|
+
|
|
1569
|
+
test("Instruction DJNZ e with backward label", () => {
|
|
1570
|
+
const bytes = compileCode('label1:\ndb $55\nDJNZ label1');
|
|
1571
|
+
expect(bytes).toEqual([0x55, 0x10, 0xFD]);
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
test("Instruction CALL nn", () => {
|
|
1575
|
+
const bytes = compileCode('CALL $5522');
|
|
1576
|
+
expect(bytes).toEqual([0xCD, 0x22, 0x55]);
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
test("Instruction CALL NZ, nn", () => {
|
|
1580
|
+
const bytes = compileCode('CALL NZ, $5522');
|
|
1581
|
+
expect(bytes).toEqual([0xC4, 0x22, 0x55]);
|
|
1582
|
+
});
|
|
1583
|
+
|
|
1584
|
+
test("Instruction CALL NZ, nn", () => {
|
|
1585
|
+
const bytes = compileCode('CALL NZ, $5522');
|
|
1586
|
+
expect(bytes).toEqual([0xC4, 0x22, 0x55]);
|
|
1587
|
+
});
|
|
1588
|
+
|
|
1589
|
+
test("Instruction CALL NZ, nn", () => {
|
|
1590
|
+
const bytes = compileCode('CALL NZ, $5522');
|
|
1591
|
+
expect(bytes).toEqual([0xC4, 0x22, 0x55]);
|
|
1592
|
+
});
|
|
1593
|
+
|
|
1594
|
+
test("Instruction CALL Z, nn", () => {
|
|
1595
|
+
const bytes = compileCode('CALL Z, $5522');
|
|
1596
|
+
expect(bytes).toEqual([0xCC, 0x22, 0x55]);
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
test("Instruction CALL NC, nn", () => {
|
|
1600
|
+
const bytes = compileCode('CALL NC, $5522');
|
|
1601
|
+
expect(bytes).toEqual([0xD4, 0x22, 0x55]);
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
test("Instruction CALL C, nn", () => {
|
|
1605
|
+
const bytes = compileCode('CALL C, $5522');
|
|
1606
|
+
expect(bytes).toEqual([0xDC, 0x22, 0x55]);
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
test("Instruction CALL PO, nn", () => {
|
|
1610
|
+
const bytes = compileCode('CALL PO, $5522');
|
|
1611
|
+
expect(bytes).toEqual([0xE4, 0x22, 0x55]);
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
test("Instruction CALL PE, nn", () => {
|
|
1615
|
+
const bytes = compileCode('CALL PE, $5522');
|
|
1616
|
+
expect(bytes).toEqual([0xEC, 0x22, 0x55]);
|
|
1617
|
+
});
|
|
1618
|
+
|
|
1619
|
+
test("Instruction CALL P, nn", () => {
|
|
1620
|
+
const bytes = compileCode('CALL P, $5522');
|
|
1621
|
+
expect(bytes).toEqual([0xF4, 0x22, 0x55]);
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1624
|
+
test("Instruction CALL M, nn", () => {
|
|
1625
|
+
const bytes = compileCode('CALL M, $5522');
|
|
1626
|
+
expect(bytes).toEqual([0xFC, 0x22, 0x55]);
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
test("Instruction RET", () => {
|
|
1630
|
+
const bytes = compileCode('RET');
|
|
1631
|
+
expect(bytes).toEqual([0xC9]);
|
|
1632
|
+
});
|
|
1633
|
+
|
|
1634
|
+
test("Instruction RET NZ", () => {
|
|
1635
|
+
const bytes = compileCode('RET NZ');
|
|
1636
|
+
expect(bytes).toEqual([0xC0]);
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
test("Instruction RET Z", () => {
|
|
1640
|
+
const bytes = compileCode('RET Z');
|
|
1641
|
+
expect(bytes).toEqual([0xC8]);
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
test("Instruction RET NC", () => {
|
|
1645
|
+
const bytes = compileCode('RET NC');
|
|
1646
|
+
expect(bytes).toEqual([0xD0]);
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
test("Instruction RET C", () => {
|
|
1650
|
+
const bytes = compileCode('RET C');
|
|
1651
|
+
expect(bytes).toEqual([0xD8]);
|
|
1652
|
+
});
|
|
1653
|
+
|
|
1654
|
+
test("Instruction RET PO", () => {
|
|
1655
|
+
const bytes = compileCode('RET PO');
|
|
1656
|
+
expect(bytes).toEqual([0xE0]);
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
test("Instruction RET PE", () => {
|
|
1660
|
+
const bytes = compileCode('RET PE');
|
|
1661
|
+
expect(bytes).toEqual([0xE8]);
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
test("Instruction RET P", () => {
|
|
1665
|
+
const bytes = compileCode('RET P');
|
|
1666
|
+
expect(bytes).toEqual([0xF0]);
|
|
1667
|
+
});
|
|
1668
|
+
|
|
1669
|
+
test("Instruction RET M", () => {
|
|
1670
|
+
const bytes = compileCode('RET M');
|
|
1671
|
+
expect(bytes).toEqual([0xF8]);
|
|
1672
|
+
});
|
|
1673
|
+
|
|
1674
|
+
test("Instruction RETI", () => {
|
|
1675
|
+
const bytes = compileCode('RETI');
|
|
1676
|
+
expect(bytes).toEqual([0xED, 0x4D]);
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1679
|
+
test("Instruction RETN", () => {
|
|
1680
|
+
const bytes = compileCode('RETN');
|
|
1681
|
+
expect(bytes).toEqual([0xED, 0x45]);
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
test("Instruction RST p", () => {
|
|
1685
|
+
const bytes = compileCode('RST 0x08');
|
|
1686
|
+
expect(bytes).toEqual([0xCF]);
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
test("Instruction IN A, (n)", () => {
|
|
1690
|
+
const bytes = compileCode('IN A, ($55)');
|
|
1691
|
+
expect(bytes).toEqual([0xDB, 0x55]);
|
|
1692
|
+
});
|
|
1693
|
+
|
|
1694
|
+
test("Instruction IN r, (C) with B", () => {
|
|
1695
|
+
const bytes = compileCode('IN B, (C)');
|
|
1696
|
+
expect(bytes).toEqual([0xED, 0x40]);
|
|
1697
|
+
});
|
|
1698
|
+
|
|
1699
|
+
test("Instruction IN r, (C) with A", () => {
|
|
1700
|
+
const bytes = compileCode('IN A, (C)');
|
|
1701
|
+
expect(bytes).toEqual([0xED, 0x78]);
|
|
1702
|
+
});
|
|
1703
|
+
|
|
1704
|
+
test("Instruction INI", () => {
|
|
1705
|
+
const bytes = compileCode('INI');
|
|
1706
|
+
expect(bytes).toEqual([0xED, 0xA2]);
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1709
|
+
test("Instruction INIR", () => {
|
|
1710
|
+
const bytes = compileCode('INIR');
|
|
1711
|
+
expect(bytes).toEqual([0xED, 0xB2]);
|
|
1712
|
+
});
|
|
1713
|
+
|
|
1714
|
+
test("Instruction IND", () => {
|
|
1715
|
+
const bytes = compileCode('IND');
|
|
1716
|
+
expect(bytes).toEqual([0xED, 0xAA]);
|
|
1717
|
+
});
|
|
1718
|
+
|
|
1719
|
+
test("Instruction INDR", () => {
|
|
1720
|
+
const bytes = compileCode('INDR');
|
|
1721
|
+
expect(bytes).toEqual([0xED, 0xBA]);
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
test("Instruction OUT (n), A", () => {
|
|
1725
|
+
const bytes = compileCode('OUT ($55), A');
|
|
1726
|
+
expect(bytes).toEqual([0xD3, 0x55]);
|
|
1727
|
+
});
|
|
1728
|
+
|
|
1729
|
+
test("Instruction OUT (C), r", () => {
|
|
1730
|
+
const bytes = compileCode('OUT (C), B');
|
|
1731
|
+
expect(bytes).toEqual([0xED, 0x41]);
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
test("Instruction OUTI", () => {
|
|
1735
|
+
const bytes = compileCode('OUTI');
|
|
1736
|
+
expect(bytes).toEqual([0xED, 0xA3]);
|
|
1737
|
+
});
|
|
1738
|
+
|
|
1739
|
+
test("Instruction OTIR", () => {
|
|
1740
|
+
const bytes = compileCode('OTIR');
|
|
1741
|
+
expect(bytes).toEqual([0xED, 0xB3]);
|
|
1742
|
+
});
|
|
1743
|
+
|
|
1744
|
+
test("Instruction OUTD", () => {
|
|
1745
|
+
const bytes = compileCode('OUTD');
|
|
1746
|
+
expect(bytes).toEqual([0xED, 0xAB]);
|
|
1747
|
+
});
|
|
1748
|
+
|
|
1749
|
+
test("Instruction OTDR", () => {
|
|
1750
|
+
const bytes = compileCode('OTDR');
|
|
1751
|
+
expect(bytes).toEqual([0xED, 0xBB]);
|
|
1752
|
+
});
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
// -------------------------------------------------------
|
|
1756
|
+
// Labels
|
|
1757
|
+
// -------------------------------------------------------
|
|
1758
|
+
|
|
1759
|
+
test("Label with a colon", () => {
|
|
1760
|
+
const bytes = compileCode('label1:');
|
|
1761
|
+
expect(bytes).toEqual([]);
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
test("Label without a colon", () => {
|
|
1765
|
+
const bytes = compileCode('label1');
|
|
1766
|
+
expect(bytes).toEqual([]);
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1769
|
+
test("Label with a name starting with the name of an instruction", () => {
|
|
1770
|
+
const bytes = compileCode('init:');
|
|
1771
|
+
expect(bytes).toEqual([]);
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
test("Label not defined", () => {
|
|
1775
|
+
compileWithError('ld a, label1');
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
test("Label transitive", () => {
|
|
1779
|
+
const bytes = compileCode('label1 equ label2\nlabel2 equ label3\nlabel3 equ $55\nld a, label1');
|
|
1780
|
+
expect(bytes).toEqual([0x3E, 0x55]);
|
|
1781
|
+
});
|
|
1782
|
+
|
|
1783
|
+
test("Circular Labels", () => {
|
|
1784
|
+
compileWithError('label1 equ label2\nlabel2 equ label3\nlabel3 equ label1\nld a, label1');
|
|
1785
|
+
});
|
|
1786
|
+
|
|
1787
|
+
test("Circular equalities", () => {
|
|
1788
|
+
compileWithError('label1 equ label1\ndb label1');
|
|
1789
|
+
});
|
|
1790
|
+
|
|
1791
|
+
test("Labels with computation EQU", () => {
|
|
1792
|
+
const bytes = compileCode(`
|
|
1793
|
+
before equ 0
|
|
1794
|
+
after equ 5
|
|
1795
|
+
defw after-before-4
|
|
1796
|
+
`);
|
|
1797
|
+
expect(bytes).toEqual([0x01, 0x00]);
|
|
1798
|
+
});
|
|
1799
|
+
|
|
1800
|
+
test("Labels with computation DEFW", () => {
|
|
1801
|
+
const bytes = compileCode(`before:
|
|
1802
|
+
defb $55, $44
|
|
1803
|
+
defw after-before-4
|
|
1804
|
+
defb $66
|
|
1805
|
+
after:`);
|
|
1806
|
+
expect(bytes).toEqual([0x55, 0x44, 0x01, 0x00, 0x66]);
|
|
1807
|
+
});
|
|
1808
|
+
|
|
1809
|
+
test("Label redefined", () => {
|
|
1810
|
+
compileWithError('lbl: db $00\nlbl: db $01\ndb lbl');
|
|
1811
|
+
});
|
|
1812
|
+
|
|
1813
|
+
test("Label forbidden", () => {
|
|
1814
|
+
compileWithError('equ: db $00\nld a, 0x44');
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1817
|
+
test("Label almost forbidden", () => {
|
|
1818
|
+
const bytes = compileCode('_equ: db $00\nld a, 0x44');
|
|
1819
|
+
expect(bytes).toEqual([0x00, 0x3E, 0x44]);
|
|
1820
|
+
});
|
|
1821
|
+
|
|
1822
|
+
// -------------------------------------------------------
|
|
1823
|
+
// Data
|
|
1824
|
+
// -------------------------------------------------------
|
|
1825
|
+
|
|
1826
|
+
test("Declaring bytes", () => {
|
|
1827
|
+
const bytes = compileCode('db $44, $01, $55');
|
|
1828
|
+
expect(bytes).toEqual([0x44, 0x01, 0x55]);
|
|
1829
|
+
});
|
|
1830
|
+
|
|
1831
|
+
test("Declaring bytes with expressions", () => {
|
|
1832
|
+
const bytes = compileCode('db $44 + 2, $01 * 2, $55');
|
|
1833
|
+
expect(bytes).toEqual([0x46, 0x02, 0x55]);
|
|
1834
|
+
});
|
|
1835
|
+
|
|
1836
|
+
test("Declaring string", () => {
|
|
1837
|
+
const bytes = compileCode('db "HELLO WORLD"');
|
|
1838
|
+
expect(bytes).toEqual([0x2D, 0x2A, 0x31, 0x31, 0x34, 0x00, 0x3C, 0x34, 0x37, 0x31, 0x29]);
|
|
1839
|
+
});
|
|
1840
|
+
|
|
1841
|
+
test("Declaring string with simple quotes", () => {
|
|
1842
|
+
const bytes = compileCode('db \'HELLO WORLD\'');
|
|
1843
|
+
expect(bytes).toEqual([0x2D, 0x2A, 0x31, 0x31, 0x34, 0x00, 0x3C, 0x34, 0x37, 0x31, 0x29]);
|
|
1844
|
+
});
|
|
1845
|
+
|
|
1846
|
+
test("Declaring strings", () => {
|
|
1847
|
+
const bytes = compileCode('db "HELLO", "WORLD"');
|
|
1848
|
+
expect(bytes).toEqual([0x2D, 0x2A, 0x31, 0x31, 0x34, 0x3C, 0x34, 0x37, 0x31, 0x29]);
|
|
1849
|
+
});
|
|
1850
|
+
|
|
1851
|
+
test("Declaring words", () => {
|
|
1852
|
+
const bytes = compileCode('dw $22, $4455, $0102, $55AA');
|
|
1853
|
+
expect(bytes).toEqual([0x22, 0x00, 0x55, 0x44, 0x02, 0x01, 0xAA, 0x55]);
|
|
1854
|
+
});
|
|
1855
|
+
|
|
1856
|
+
test("Declaring words with label", () => {
|
|
1857
|
+
const bytes = compileCode('values:\ndw label2*2+0x55\nlabel2:');
|
|
1858
|
+
expect(bytes).toEqual([0x59, 0x00]);
|
|
1859
|
+
});
|
|
1860
|
+
|
|
1861
|
+
test("Declaring block with explicit value", () => {
|
|
1862
|
+
const bytes = compileCode('ds 10, 0xFF');
|
|
1863
|
+
expect(bytes).toEqual([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
1864
|
+
});
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
test("Declaring block with implicit value", () => {
|
|
1868
|
+
const bytes = compileCode('ds 10');
|
|
1869
|
+
expect(bytes).toEqual([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
1870
|
+
});
|
|
1871
|
+
|
|
1872
|
+
test("Declaring block with length from previous label", () => {
|
|
1873
|
+
const bytes = compileCode('db 0x00, 0x01, 0x02, 0x03\nlength:\nds length, 0xFF');
|
|
1874
|
+
expect(bytes).toEqual([0x00, 0x01, 0x02, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1877
|
+
test("Declaring block with length from following label", () => {
|
|
1878
|
+
compileWithError('db 0x00, 0x01, 0x02, 0x03\nds length, 0xFF\nlength:');
|
|
1879
|
+
});
|
|
1880
|
+
|
|
1881
|
+
test("Declaring block with length from previous equ", () => {
|
|
1882
|
+
const bytes = compileCode('length equ 10\nds length, 0xFF');
|
|
1883
|
+
expect(bytes).toEqual([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
1884
|
+
});
|
|
1885
|
+
|
|
1886
|
+
test("Declaring block with length from following equ", () => {
|
|
1887
|
+
const bytes = compileCode('ds length, 0xFF\nlength equ 10');
|
|
1888
|
+
expect(bytes).toEqual([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
1889
|
+
});
|
|
1890
|
+
|
|
1891
|
+
test("Declaring block with length dependent of the size", () => {
|
|
1892
|
+
compileWithError('length equ label1\ndb 0x55, 0x56, 0x57\nds length, 0xFF\nlabel1:\n db 0x44');
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
// -------------------------------------------------------
|
|
1896
|
+
// Directives
|
|
1897
|
+
// -------------------------------------------------------
|
|
1898
|
+
|
|
1899
|
+
test("Directive EQU", () => {
|
|
1900
|
+
const bytes = compileCode('label1 EQU $55\nDB label1');
|
|
1901
|
+
expect(bytes).toEqual([0x55]);
|
|
1902
|
+
});
|
|
1903
|
+
|
|
1904
|
+
test("Directive EQU with colon", () => {
|
|
1905
|
+
const bytes = compileCode('label1: EQU $55\nDB label1');
|
|
1906
|
+
expect(bytes).toEqual([0x55]);
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
test("Directive EQU with dot", () => {
|
|
1910
|
+
const bytes = compileCode('label1 .EQU $55\nDB label1');
|
|
1911
|
+
expect(bytes).toEqual([0x55]);
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1914
|
+
test("Directive EQU with period and colon", () => {
|
|
1915
|
+
const bytes = compileCode('label1: .EQU $55\nDB label1');
|
|
1916
|
+
expect(bytes).toEqual([0x55]);
|
|
1917
|
+
});
|
|
1918
|
+
|
|
1919
|
+
test("Origin directive", () => {
|
|
1920
|
+
const bytes = compileCode('org $5544\nlabel1:\nld hl, label1');
|
|
1921
|
+
expect(bytes).toEqual([0x21, 0x44, 0x55]);
|
|
1922
|
+
});
|
|
1923
|
+
|
|
1924
|
+
test("Directive EQU with equal symbol", () => {
|
|
1925
|
+
const bytes = compileCode('label1 = $55\nDB label1');
|
|
1926
|
+
expect(bytes).toEqual([0x55]);
|
|
1927
|
+
});
|
|
1928
|
+
|
|
1929
|
+
test("Directive EQU with colon and equal symbol", () => {
|
|
1930
|
+
const bytes = compileCode('label1: = $55\nDB label1');
|
|
1931
|
+
expect(bytes).toEqual([0x55]);
|
|
1932
|
+
});
|
|
1933
|
+
|
|
1934
|
+
test("Origin directive with dot", () => {
|
|
1935
|
+
const bytes = compileCode('.org $5544\nlabel1:\nld hl, label1');
|
|
1936
|
+
expect(bytes).toEqual([0x21, 0x44, 0x55]);
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
test("Include", () => {
|
|
1940
|
+
const bytes = compileCode('include test.asm');
|
|
1941
|
+
expect(bytes).toEqual([]);
|
|
1942
|
+
});
|
|
1943
|
+
|
|
1944
|
+
test("Include with dot", () => {
|
|
1945
|
+
const bytes = compileCode('.include test.asm');
|
|
1946
|
+
expect(bytes).toEqual([]);
|
|
1947
|
+
});
|
|
1948
|
+
|
|
1949
|
+
test("Include with quotes", () => {
|
|
1950
|
+
const bytes = compileCode('include "test.asm"');
|
|
1951
|
+
expect(bytes).toEqual([]);
|
|
1952
|
+
});
|
|
1953
|
+
|
|
1954
|
+
test("Include with label definition", () => {
|
|
1955
|
+
const bytes = compileCodes([
|
|
1956
|
+
{filename: 'main.asm', code: 'include "inc1.asm"\ndb test1'},
|
|
1957
|
+
{filename: 'inc1.asm', code: 'test1 equ $55'}
|
|
1958
|
+
]);
|
|
1959
|
+
expect(bytes).toEqual([0x55]);
|
|
1960
|
+
});
|
|
1961
|
+
|
|
1962
|
+
test("Include with label defined after inclusion", () => {
|
|
1963
|
+
const bytes = compileCodes([
|
|
1964
|
+
{filename: 'main.asm', code: 'include "inc1.asm"\ntest2 equ $55\ndb test1'},
|
|
1965
|
+
{filename: 'inc1.asm', code: 'test1 equ test2'}
|
|
1966
|
+
]);
|
|
1967
|
+
expect(bytes).toEqual([0x55]);
|
|
1968
|
+
});
|
|
1969
|
+
|
|
1970
|
+
test("Include with address defined after inclusion", () => {
|
|
1971
|
+
const bytes = compileCodes([
|
|
1972
|
+
{filename: 'main.asm', code: 'db $AA, $AA, $AA, $AA\ninclude "inc1.asm"\ntest1: db $55'},
|
|
1973
|
+
{filename: 'inc1.asm', code: 'db test1'}
|
|
1974
|
+
]);
|
|
1975
|
+
expect(bytes).toEqual([0xAA, 0xAA, 0xAA, 0xAA, 0x05, 0x55]);
|
|
1976
|
+
});
|
|
1977
|
+
|
|
1978
|
+
test("Include with address defined in another inclusion", () => {
|
|
1979
|
+
const bytes = compileCodes([
|
|
1980
|
+
{filename: 'main.asm', code: 'db $AA, $AA, $AA, $AA\ninclude "inc1.asm"\ndb $55\ninclude "inc2.asm"\ndb $66'},
|
|
1981
|
+
{filename: 'inc1.asm', code: 'test1: defw test2'},
|
|
1982
|
+
{filename: 'inc2.asm', code: 'test2: db $22, $22, $22, $22'}
|
|
1983
|
+
]);
|
|
1984
|
+
expect(bytes).toEqual([0xAA, 0xAA, 0xAA, 0xAA, 0x07, 0x00, 0x55, 0x22, 0x22, 0x22, 0x22, 0x66]);
|
|
1985
|
+
});
|
|
1986
|
+
|
|
1987
|
+
test("Output", () => {
|
|
1988
|
+
const bytes = compileCode('output test.P');
|
|
1989
|
+
expect(bytes).toEqual([]);
|
|
1990
|
+
});
|
|
1991
|
+
|
|
1992
|
+
test("Output with dot", () => {
|
|
1993
|
+
const bytes = compileCode('.output test.P');
|
|
1994
|
+
expect(bytes).toEqual([]);
|
|
1995
|
+
});
|
|
1996
|
+
|
|
1997
|
+
test("Output with quotes", () => {
|
|
1998
|
+
const bytes = compileCode('output "test.P"');
|
|
1999
|
+
expect(bytes).toEqual([]);
|
|
2000
|
+
});
|
|
2001
|
+
|
|
2002
|
+
test("Output with SLD", () => {
|
|
2003
|
+
const bytes = compileCode('output test.P, sld test.sld');
|
|
2004
|
+
expect(bytes).toEqual([]);
|
|
2005
|
+
});
|
|
2006
|
+
|
|
2007
|
+
test("Output with SLD and quotes", () => {
|
|
2008
|
+
const bytes = compileCode('output "test.P", sld "test.sld"');
|
|
2009
|
+
expect(bytes).toEqual([]);
|
|
2010
|
+
});
|
|
2011
|
+
|
|
2012
|
+
test("Device", () => {
|
|
2013
|
+
const bytes = compileCode('device test');
|
|
2014
|
+
expect(bytes).toEqual([]);
|
|
2015
|
+
});
|
|
2016
|
+
|
|
2017
|
+
test("Device with dot", () => {
|
|
2018
|
+
const bytes = compileCode('.device test');
|
|
2019
|
+
expect(bytes).toEqual([]);
|
|
2020
|
+
});
|
|
2021
|
+
|
|
2022
|
+
test("End Directive", () => {
|
|
2023
|
+
const bytes = compileCode('ld a,1\nend\nld a,2');
|
|
2024
|
+
expect(bytes).toEqual([0x3E, 0x01]);
|
|
2025
|
+
});
|
|
2026
|
+
|
|
2027
|
+
|
|
2028
|
+
// -------------------------------------------------------
|
|
2029
|
+
// Comments
|
|
2030
|
+
// -------------------------------------------------------
|
|
2031
|
+
|
|
2032
|
+
test("Comment alone", () => {
|
|
2033
|
+
const bytes = compileCode('; a comment');
|
|
2034
|
+
expect(bytes).toEqual([]);
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
test("Comment with spaces", () => {
|
|
2038
|
+
const bytes = compileCode(' ; a comment');
|
|
2039
|
+
expect(bytes).toEqual([]);
|
|
2040
|
+
});
|
|
2041
|
+
|
|
2042
|
+
test("Comment with label", () => {
|
|
2043
|
+
const bytes = compileCode('test1: ; a comment');
|
|
2044
|
+
expect(bytes).toEqual([]);
|
|
2045
|
+
});
|
|
2046
|
+
|
|
2047
|
+
test("Comment with instruction", () => {
|
|
2048
|
+
const bytes = compileCode(' ld a, $55 ; a comment');
|
|
2049
|
+
expect(bytes).toEqual([0x3E, 0x55]);
|
|
2050
|
+
});
|
|
2051
|
+
|
|
2052
|
+
test("Comment with label and instruction", () => {
|
|
2053
|
+
const bytes = compileCode('test1: ld a, $55 ; a comment');
|
|
2054
|
+
expect(bytes).toEqual([0x3E, 0x55]);
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
// -------------------------------------------------------
|
|
2058
|
+
// Pseudo label $ for current program counter
|
|
2059
|
+
// -------------------------------------------------------
|
|
2060
|
+
|
|
2061
|
+
test("Pseudo label $", () => {
|
|
2062
|
+
const bytes = compileCode('ld a, $55\nld hl, $');
|
|
2063
|
+
expect(bytes).toEqual([0x3E, 0x55, 0x21, 0x02, 0x00]);
|
|
2064
|
+
});
|
|
2065
|
+
|
|
2066
|
+
// -------------------------------------------------------
|
|
2067
|
+
// SLD
|
|
2068
|
+
// -------------------------------------------------------
|
|
2069
|
+
|
|
2070
|
+
test("SLD with label alone on a line", () => {
|
|
2071
|
+
const info = compileWithSld(`
|
|
2072
|
+
ld a, $44
|
|
2073
|
+
start:
|
|
2074
|
+
ld a, $55
|
|
2075
|
+
ld b, $66
|
|
2076
|
+
ld hl, start
|
|
2077
|
+
`);
|
|
2078
|
+
expect(info.bytes).toEqual([0x3E, 0x44, 0x3E, 0x55, 0x06, 0x66, 0x21, 0x02, 0x00]);
|
|
2079
|
+
expect(info.sld).toEqual(`|SLD.data.version|1
|
|
2080
|
+
test.asm|1||0|-1|-1|Z|pages.size:65536,pages.count:32,slots.count:1,slots.adr:0
|
|
2081
|
+
test.asm|2||0|0|0|T|
|
|
2082
|
+
test.asm|3||0|0|2|L|,start,
|
|
2083
|
+
test.asm|4||0|0|2|T|
|
|
2084
|
+
test.asm|5||0|0|4|T|
|
|
2085
|
+
test.asm|6||0|0|6|T|
|
|
2086
|
+
`);
|
|
2087
|
+
});
|
|
2088
|
+
|
|
2089
|
+
test("SLD with label in front of statement", () => {
|
|
2090
|
+
const info = compileWithSld(`
|
|
2091
|
+
ld a, $44
|
|
2092
|
+
start: ld a, $55
|
|
2093
|
+
ld b, $66
|
|
2094
|
+
ld hl, start
|
|
2095
|
+
`);
|
|
2096
|
+
expect(info.bytes).toEqual([0x3E, 0x44, 0x3E, 0x55, 0x06, 0x66, 0x21, 0x02, 0x00]);
|
|
2097
|
+
expect(info.sld).toEqual(`|SLD.data.version|1
|
|
2098
|
+
test.asm|1||0|-1|-1|Z|pages.size:65536,pages.count:32,slots.count:1,slots.adr:0
|
|
2099
|
+
test.asm|2||0|0|0|T|
|
|
2100
|
+
test.asm|3||0|0|2|L|,start,
|
|
2101
|
+
test.asm|3||0|0|2|T|
|
|
2102
|
+
test.asm|4||0|0|4|T|
|
|
2103
|
+
test.asm|5||0|0|6|T|
|
|
2104
|
+
`);
|
|
2105
|
+
});
|
|
2106
|
+
|
|
2107
|
+
test("SLD with label alone on a line and $", () => {
|
|
2108
|
+
const info = compileWithSld(`
|
|
2109
|
+
ld a, $44
|
|
2110
|
+
start:
|
|
2111
|
+
ld a, $55
|
|
2112
|
+
ld b, $66
|
|
2113
|
+
ld hl, $ - start
|
|
2114
|
+
`);
|
|
2115
|
+
expect(info.bytes).toEqual([0x3E, 0x44, 0x3E, 0x55, 0x06, 0x66, 0x21, 0x04, 0x00]);
|
|
2116
|
+
expect(info.sld).toEqual(`|SLD.data.version|1
|
|
2117
|
+
test.asm|1||0|-1|-1|Z|pages.size:65536,pages.count:32,slots.count:1,slots.adr:0
|
|
2118
|
+
test.asm|2||0|0|0|T|
|
|
2119
|
+
test.asm|3||0|0|2|L|,start,
|
|
2120
|
+
test.asm|4||0|0|2|T|
|
|
2121
|
+
test.asm|5||0|0|4|T|
|
|
2122
|
+
test.asm|6||0|0|6|T|
|
|
2123
|
+
`);
|
|
2124
|
+
});
|
|
2125
|
+
|
|
2126
|
+
test("SLD with $", () => {
|
|
2127
|
+
const info = compileWithSld(`
|
|
2128
|
+
start:
|
|
2129
|
+
ds 10, $44
|
|
2130
|
+
size eq $ - start
|
|
2131
|
+
ld hl, size
|
|
2132
|
+
`);
|
|
2133
|
+
expect(info.bytes).toEqual([0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
|
|
2134
|
+
0x21, 0x0A, 0x00]);
|
|
2135
|
+
expect(info.sld).toEqual(`|SLD.data.version|1
|
|
2136
|
+
test.asm|1||0|-1|-1|Z|pages.size:65536,pages.count:32,slots.count:1,slots.adr:0
|
|
2137
|
+
test.asm|2||0|0|0|L|,start,
|
|
2138
|
+
test.asm|4||0|-1|10|L|,size,,+equ
|
|
2139
|
+
test.asm|5||0|0|10|T|
|
|
2140
|
+
`);
|
|
2141
|
+
});
|