@andrivet/z80-assembler 1.4.0 → 1.4.1
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/{libs/z80-assembler/public/CHANGELOG.md → CHANGELOG.md} +8 -0
- package/README.md +27 -53
- package/{libs/z80-assembler/src/index.ts → index.d.ts} +1 -1
- package/index.js +312 -0
- package/index.mjs +6449 -0
- package/{libs/z80-assembler/src/lib/compiler/Assets.ts → lib/compiler/Assets.d.ts} +1 -6
- package/lib/compiler/Ast.d.ts +210 -0
- package/lib/compiler/Compiler.d.ts +53 -0
- package/lib/compiler/Formatter.d.ts +23 -0
- package/lib/compiler/Generator.d.ts +40 -0
- package/lib/compiler/Labels.d.ts +47 -0
- package/lib/grammar/LowLevel.d.ts +68 -0
- package/lib/grammar/Parse.d.ts +48 -0
- package/lib/grammar/z80.d.ts +2939 -0
- package/lib/types/Error.d.ts +62 -0
- package/{libs/z80-assembler/src/lib/types/Types.ts → lib/types/Types.d.ts} +11 -26
- package/package.json +14 -52
- package/.editorconfig +0 -13
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -35
- package/.github/workflows/node.js.yml +0 -47
- package/.prettierignore +0 -3
- package/.prettierrc +0 -3
- package/.vscode/extensions.json +0 -7
- package/apps/.gitkeep +0 -0
- package/apps/z80-assembler-app/.eslintrc.json +0 -18
- package/apps/z80-assembler-app/index.html +0 -16
- package/apps/z80-assembler-app/postcss.config.js +0 -24
- package/apps/z80-assembler-app/project.json +0 -70
- 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 +0 -25
- package/apps/z80-assembler-app/public/robots.txt +0 -3
- package/apps/z80-assembler-app/src/app/app.module.css +0 -0
- package/apps/z80-assembler-app/src/app/app.tsx +0 -122
- package/apps/z80-assembler-app/src/app/binary.tsx +0 -39
- package/apps/z80-assembler-app/src/app/editor.tsx +0 -228
- package/apps/z80-assembler-app/src/app/errors.tsx +0 -31
- package/apps/z80-assembler-app/src/app/footer.tsx +0 -20
- package/apps/z80-assembler-app/src/app/header.tsx +0 -57
- package/apps/z80-assembler-app/src/app/misc.ts +0 -13
- package/apps/z80-assembler-app/src/app/opcodes.tsx +0 -335
- 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 +0 -22
- package/apps/z80-assembler-app/src/styles.css +0 -8
- package/apps/z80-assembler-app/tailwind.config.js +0 -28
- package/apps/z80-assembler-app/tsconfig.app.json +0 -22
- package/apps/z80-assembler-app/tsconfig.json +0 -21
- package/apps/z80-assembler-app/tsconfig.spec.json +0 -23
- package/apps/z80-assembler-app/vite.config.ts +0 -64
- 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 +0 -551
- 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 +0 -18
- package/libs/z80-assembler/package.json +0 -20
- package/libs/z80-assembler/project.json +0 -35
- package/libs/z80-assembler/public/README.md +0 -54
- package/libs/z80-assembler/src/lib/assets/code/basic-end.zx81 +0 -4
- package/libs/z80-assembler/src/lib/assets/code/basic-line1.zx81 +0 -4
- package/libs/z80-assembler/src/lib/assets/code/basic-line2.zx81 +0 -9
- package/libs/z80-assembler/src/lib/assets/code/characters.zx81 +0 -190
- package/libs/z80-assembler/src/lib/assets/code/display.zx81 +0 -50
- package/libs/z80-assembler/src/lib/assets/code/system-variables.zx81 +0 -46
- package/libs/z80-assembler/src/lib/compiler/Ast.ts +0 -545
- package/libs/z80-assembler/src/lib/compiler/Compiler.test.ts +0 -2141
- package/libs/z80-assembler/src/lib/compiler/Compiler.ts +0 -185
- package/libs/z80-assembler/src/lib/compiler/Formatter.ts +0 -43
- package/libs/z80-assembler/src/lib/compiler/Generator.ts +0 -255
- package/libs/z80-assembler/src/lib/compiler/Labels.ts +0 -165
- package/libs/z80-assembler/src/lib/grammar/LowLevel.ts +0 -163
- package/libs/z80-assembler/src/lib/grammar/Parse.ts +0 -128
- package/libs/z80-assembler/src/lib/grammar/z80.peg +0 -1252
- package/libs/z80-assembler/src/lib/grammar/z80.ts +0 -10649
- package/libs/z80-assembler/src/lib/types/Error.ts +0 -105
- package/libs/z80-assembler/tsconfig.json +0 -23
- package/libs/z80-assembler/tsconfig.lib.json +0 -10
- package/libs/z80-assembler/tsconfig.spec.json +0 -19
- package/libs/z80-assembler/vite.config.ts +0 -58
- package/nx.json +0 -57
- package/tsconfig.base.json +0 -22
|
@@ -7,15 +7,10 @@
|
|
|
7
7
|
* License: GPLv3
|
|
8
8
|
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12
|
-
//@ts-nocheck
|
|
13
|
-
|
|
14
10
|
import assetCharacters from '../assets/code/characters.zx81?raw';
|
|
15
11
|
import assetSystemVariables from '../assets/code/system-variables.zx81?raw';
|
|
16
12
|
import assetBasicLine1 from '../assets/code/basic-line1.zx81?raw';
|
|
17
13
|
import assetBasicLine2 from '../assets/code/basic-line2.zx81?raw';
|
|
18
14
|
import assetDisplay from '../assets/code/display.zx81?raw';
|
|
19
15
|
import assetBasicEnd from '../assets/code/basic-end.zx81?raw';
|
|
20
|
-
|
|
21
|
-
export {assetCharacters, assetSystemVariables, assetBasicLine1, assetBasicLine2, assetDisplay, assetBasicEnd}
|
|
16
|
+
export { assetCharacters, assetSystemVariables, assetBasicLine1, assetBasicLine2, assetDisplay, assetBasicEnd };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Ast.ts
|
|
5
|
+
* Description: Types for building the Abstract Syntax Tree
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
import { Address, bytes } from '../types/Types';
|
|
11
|
+
import { ByteValue, Expression, PosInfo, WordValue } from "../grammar/z80";
|
|
12
|
+
/**
|
|
13
|
+
* A function returning a number (if it is known) or null (if it is unknown).
|
|
14
|
+
*/
|
|
15
|
+
export type EvalFunc = (pc: Address, mustExist: boolean) => number | null;
|
|
16
|
+
/**
|
|
17
|
+
* An abstract element generated by the parser.
|
|
18
|
+
*/
|
|
19
|
+
export interface AstBase {
|
|
20
|
+
/**
|
|
21
|
+
* The number of bytes that will be generated by this element.
|
|
22
|
+
*/
|
|
23
|
+
get size(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Generate actual bytes.
|
|
26
|
+
* @param instructionAddress Address of the next byte to generate,
|
|
27
|
+
*/
|
|
28
|
+
generate(instructionAddress: number): bytes;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* An AST element is either a number (the raw byte value) or derived from AstBase.
|
|
32
|
+
*/
|
|
33
|
+
export type AstElement = number | AstBase;
|
|
34
|
+
/**
|
|
35
|
+
* Array of AST elements
|
|
36
|
+
*/
|
|
37
|
+
export type AstElements = AstElement[];
|
|
38
|
+
/**
|
|
39
|
+
* Determine if an AST element is a raw byte or derived from AstBase (i.e. abstract)
|
|
40
|
+
* @param element The element to test.
|
|
41
|
+
* @return true if the element is concrete (a raw byte value), false if it is abstract.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isAbstract(element: AstElement): element is AstBase;
|
|
44
|
+
/**
|
|
45
|
+
* Determine the actual size in byte of an AST element.
|
|
46
|
+
* @param element The AST element.
|
|
47
|
+
* @return The number of bytes that will be generated by this element
|
|
48
|
+
*/
|
|
49
|
+
export declare function getByteSize(element: AstElement): number;
|
|
50
|
+
/**
|
|
51
|
+
* Get the low part of a 16-bit little endian value.
|
|
52
|
+
* @param value A 16-bit little endian value.
|
|
53
|
+
*/
|
|
54
|
+
export declare function low(value: number): number;
|
|
55
|
+
/**
|
|
56
|
+
* Get the high part of a 16-bit little endian value.
|
|
57
|
+
* @param value A 16-bit little endian value.
|
|
58
|
+
*/
|
|
59
|
+
export declare function high(value: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* An Evaluable interface, i.e. that contains an eval function that returns a number or null.
|
|
62
|
+
*/
|
|
63
|
+
interface Evaluable {
|
|
64
|
+
eval: EvalFunc;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* An Inner Expression i.e. that extends an Evaluable interface.
|
|
68
|
+
*/
|
|
69
|
+
interface InnerExpression<E extends Evaluable> {
|
|
70
|
+
e: E;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A Binary operation interface, i.e. a function with two arguments and that returns a number.
|
|
74
|
+
*/
|
|
75
|
+
type BinaryOperation = (a: number, b: number) => number;
|
|
76
|
+
/**
|
|
77
|
+
* A Unary operation interface, i.e. a function with one argument and that returns a number.
|
|
78
|
+
*/
|
|
79
|
+
type UnaryOperation = (a: number) => number;
|
|
80
|
+
/**
|
|
81
|
+
* A Binary operation such as: 2 * 4.
|
|
82
|
+
* @param left Left side of the binary function.
|
|
83
|
+
* @param right Right side of the binary function.
|
|
84
|
+
* @param op Operation to be applied to the left and right side.
|
|
85
|
+
*/
|
|
86
|
+
export declare function binaryOperation<Operation extends BinaryOperation, Inner extends Evaluable, Left extends InnerExpression<Inner>, Right extends Evaluable>(left: Left | null, right: Right, op: Operation): EvalFunc;
|
|
87
|
+
/**
|
|
88
|
+
* A map of strings versus binary operations. For example: '*' => operatorMul
|
|
89
|
+
*/
|
|
90
|
+
type BinaryOperationsMap = {
|
|
91
|
+
[key: string]: BinaryOperation;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* A map of strings versus unary operations. For example: '-' => operatorNeg
|
|
95
|
+
*/
|
|
96
|
+
type UnaryOperationsMap = {
|
|
97
|
+
[key: string]: UnaryOperation;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* An Inner Operator i.e. that extends an Inner Expression, itself extending an Evaluable.
|
|
101
|
+
*/
|
|
102
|
+
interface InnerOp<E extends Evaluable> extends InnerExpression<E> {
|
|
103
|
+
op: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A Binary operation such as: 2 * 4.
|
|
107
|
+
* @param left Left side of the binary function.
|
|
108
|
+
* @param right Right side of the binary function.
|
|
109
|
+
* @param map Map the operations to be applied to the left and right side.
|
|
110
|
+
*/
|
|
111
|
+
export declare function binaryOperations<Inner extends Evaluable, Left extends InnerOp<Inner>, Right extends Evaluable>(left: Left | null, right: Right, map: BinaryOperationsMap): EvalFunc;
|
|
112
|
+
/**
|
|
113
|
+
* A Unary operation.
|
|
114
|
+
* @param e The argument.
|
|
115
|
+
* @param op The operation to be applied to the argument.
|
|
116
|
+
*/
|
|
117
|
+
export declare function unaryOperation<Operation extends UnaryOperation, E extends Evaluable>(e: E, op: Operation): EvalFunc;
|
|
118
|
+
/**
|
|
119
|
+
* A Unary operation.
|
|
120
|
+
* @param e The argument.
|
|
121
|
+
* @param op The operation to be applied to the argument as a string.
|
|
122
|
+
* @param map Map the operations to be applied to the argument.
|
|
123
|
+
*/
|
|
124
|
+
export declare function unaryOperations<E extends Evaluable>(e: E, op: string, map: UnaryOperationsMap): EvalFunc;
|
|
125
|
+
export declare const operatorOr: (a: number, b: number) => number;
|
|
126
|
+
export declare const operatorXor: (a: number, b: number) => number;
|
|
127
|
+
export declare const operatorAnd: (a: number, b: number) => number;
|
|
128
|
+
export declare const operatorLeftShift: (a: number, b: number) => number;
|
|
129
|
+
export declare const operatorRightShift: (a: number, b: number) => number;
|
|
130
|
+
export declare const operatorAdd: (a: number, b: number) => number;
|
|
131
|
+
export declare const operatorSub: (a: number, b: number) => number;
|
|
132
|
+
export declare const operatorMul: (a: number, b: number) => number;
|
|
133
|
+
export declare const operatorDiv: (a: number, b: number) => number;
|
|
134
|
+
export declare const operatorModulo: (a: number, b: number) => number;
|
|
135
|
+
export declare const operatorPlus: (a: number) => number;
|
|
136
|
+
export declare const operatorNeg: (a: number) => number;
|
|
137
|
+
export declare const operatorInvert: (a: number) => number;
|
|
138
|
+
export declare const operatorIdentity: (a: number) => number;
|
|
139
|
+
/**
|
|
140
|
+
* Returns an AST element that represents the low part of a little-endian 16-bit value.
|
|
141
|
+
* @param pos The position of the element in the source.
|
|
142
|
+
* @param e The 16-bit value.
|
|
143
|
+
*/
|
|
144
|
+
export declare function value16LE(pos: PosInfo, e: Expression): AstElement;
|
|
145
|
+
/**
|
|
146
|
+
* Returns an AST element that represents an 8-bit unsigned value.
|
|
147
|
+
* @param pos The position of the element in the source.
|
|
148
|
+
* @param e The 8-bit unsigned value.
|
|
149
|
+
*/
|
|
150
|
+
export declare function value8(pos: PosInfo, e: Expression): AstElement;
|
|
151
|
+
/**
|
|
152
|
+
* Returns an AST element that represents an 8-bit signed offset for IX or IY.
|
|
153
|
+
* @offset The offset for IX or IY with:
|
|
154
|
+
* pos The position of the element in the source.
|
|
155
|
+
* s The sign of the value.
|
|
156
|
+
*/
|
|
157
|
+
export declare function index(offset: {
|
|
158
|
+
pos: PosInfo;
|
|
159
|
+
s: string;
|
|
160
|
+
d: Expression;
|
|
161
|
+
} | null): AstElement;
|
|
162
|
+
/**
|
|
163
|
+
* Returns an AST element that represents an offset for a JR (jump relative) opcode.
|
|
164
|
+
* @param pos The position of the element in the source.
|
|
165
|
+
* @param e The offset value.
|
|
166
|
+
*/
|
|
167
|
+
export declare function jrOffset(pos: PosInfo, e: Expression): AstElement;
|
|
168
|
+
/**
|
|
169
|
+
* Returns an AST element that represents an relative offset for a JR (jump relative) opcode.
|
|
170
|
+
* @param pos The position of the element in the source.
|
|
171
|
+
* @param label The label that will give the offset value
|
|
172
|
+
*/
|
|
173
|
+
export declare function jrRelativeOffset(pos: PosInfo, label: string): AstElement;
|
|
174
|
+
/**
|
|
175
|
+
* An Inner Byte, i.e. it contains an inner field that is a Byte value.
|
|
176
|
+
*/
|
|
177
|
+
export interface InnerByte {
|
|
178
|
+
inner: ByteValue;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* An Inner Word, i.e. it contains an inner field that is a Word value.
|
|
182
|
+
*/
|
|
183
|
+
export interface InnerWord {
|
|
184
|
+
inner: WordValue;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The bytes of a Byte directive.
|
|
188
|
+
* @param _ The position of the bytes in the source code.
|
|
189
|
+
* @param data0 The first byte.
|
|
190
|
+
* @param data The other bytes.
|
|
191
|
+
*/
|
|
192
|
+
export declare function dataBytes(_: PosInfo, data0: ByteValue, data: InnerByte[]): AstElements;
|
|
193
|
+
/**
|
|
194
|
+
* The words of a Word directive.
|
|
195
|
+
* @param _ The position of the words in the source code.
|
|
196
|
+
* @param data0 The first word.
|
|
197
|
+
* @param data The other words.
|
|
198
|
+
*/
|
|
199
|
+
export declare function dataWords(_: PosInfo, data0: WordValue, data: InnerWord[]): AstElements;
|
|
200
|
+
/**
|
|
201
|
+
* The parameters of a block of data.
|
|
202
|
+
* @param pos0 The position of the length in the source code.
|
|
203
|
+
* @param length The length (in bytes) of the block
|
|
204
|
+
* @param pos1 The position of the value in the source code.
|
|
205
|
+
* @param value The value used to initialize the block.
|
|
206
|
+
*/
|
|
207
|
+
export declare function dataBlock(pos0: PosInfo, length: Expression, pos1: PosInfo | undefined, value: Expression | undefined): AstElement;
|
|
208
|
+
export declare function labelValue(pos: PosInfo, name: string): (pc: Address, mustExist: boolean) => number | null;
|
|
209
|
+
export declare function value(nn: number): (pc: Address, mustExist: boolean) => number;
|
|
210
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Compiler.ts
|
|
5
|
+
* Description: Compiler (assembler)
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
import { PosInfo } from "../grammar/z80";
|
|
11
|
+
import { CompilationInfo, LinesInfo } from "../types/Types";
|
|
12
|
+
/**
|
|
13
|
+
* Type of the internal data.
|
|
14
|
+
*/
|
|
15
|
+
interface ParseData {
|
|
16
|
+
outputName: string;
|
|
17
|
+
sldName: string;
|
|
18
|
+
deviceName: string;
|
|
19
|
+
basePath: string;
|
|
20
|
+
fileName: string;
|
|
21
|
+
getFileCode: (filename: string) => string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Internal data (i.e. globals).
|
|
25
|
+
* Unfortunately, tsPEG does not allow to declare a context for the parsing.
|
|
26
|
+
* So instead, we use this ugly global.
|
|
27
|
+
*/
|
|
28
|
+
declare const parseData: ParseData;
|
|
29
|
+
/**
|
|
30
|
+
* Set the outputs names (output directive).
|
|
31
|
+
* @param filename Filename for the binary.
|
|
32
|
+
* @param sld Filename for the SLD.
|
|
33
|
+
*/
|
|
34
|
+
declare function setOutputName(filename: string, sld?: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Set the name of the target (device directive)
|
|
37
|
+
* @param name The name of the device
|
|
38
|
+
*/
|
|
39
|
+
declare function setDevice(name: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Include an assembly file (include directive).
|
|
42
|
+
* @param pos Position of the include directive.
|
|
43
|
+
* @param filename The filename of the file to be included.
|
|
44
|
+
*/
|
|
45
|
+
declare function includeFile(pos: PosInfo, filename: string): LinesInfo;
|
|
46
|
+
/**
|
|
47
|
+
* Compile an assembly source code.
|
|
48
|
+
* @param filepath The file path of the source code.
|
|
49
|
+
* @param code The assembly source code.
|
|
50
|
+
* @param getFileCode A function to get the content of included files.
|
|
51
|
+
*/
|
|
52
|
+
declare function compile(filepath: string, code: string, getFileCode: (filename: string) => string): CompilationInfo;
|
|
53
|
+
export { parseData, compile, includeFile, setOutputName, setDevice };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Formatter.ts
|
|
5
|
+
* Description: Format bytes to display them easily
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Represents a chunk of data to display binary.
|
|
12
|
+
*/
|
|
13
|
+
interface Chunk {
|
|
14
|
+
address: string;
|
|
15
|
+
bytes: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Format bytes to display them.
|
|
19
|
+
* @param bytes An array of bytes.
|
|
20
|
+
* @param perLine Number of bytes per line.
|
|
21
|
+
*/
|
|
22
|
+
declare function formatBytes(bytes: number[], perLine: number): Chunk[];
|
|
23
|
+
export { formatBytes, Chunk };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Generator.ts
|
|
5
|
+
* Description: Generate bytes and SLD
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
import { bytes, LinesInfo } from '../types/Types';
|
|
11
|
+
/**
|
|
12
|
+
* Information about a compiled program.
|
|
13
|
+
*/
|
|
14
|
+
interface ProgramInfo {
|
|
15
|
+
bytes: bytes;
|
|
16
|
+
outputName: string;
|
|
17
|
+
outputSldName: string;
|
|
18
|
+
address: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Compute, whenever possible, the value associated with labels.
|
|
22
|
+
* @param address The starting address.
|
|
23
|
+
* @param infos The lines (i.e. the AST)
|
|
24
|
+
* @return the address that corresponds to the code after the lines (i.e. the new starting address).
|
|
25
|
+
*/
|
|
26
|
+
declare function computeLabels(address: number, infos: LinesInfo[]): number;
|
|
27
|
+
interface GenerationData {
|
|
28
|
+
bytes: bytes;
|
|
29
|
+
sld: string;
|
|
30
|
+
address: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate machine code bytes and SLD for an array of lines (i.e. an AST)
|
|
34
|
+
* @param mainfile Main file name
|
|
35
|
+
* @param address The current address.
|
|
36
|
+
* @param infos The lines (i.e. the AST) with the associated filename
|
|
37
|
+
* @return An array of bytes (numbers), debug data and the next address
|
|
38
|
+
*/
|
|
39
|
+
declare function generate(mainfile: string, address: number, infos: LinesInfo[]): GenerationData;
|
|
40
|
+
export { computeLabels, generate, ProgramInfo };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Labels.ts
|
|
5
|
+
* Description: Labels associated to locations in memory
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
import { Expression, PosInfo } from "../grammar/z80";
|
|
11
|
+
import { Address, Position } from '../types/Types';
|
|
12
|
+
/**
|
|
13
|
+
* Reset the labels.
|
|
14
|
+
*/
|
|
15
|
+
declare function resetLabels(): void;
|
|
16
|
+
declare function resetLabelsRecursion(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Add a label.
|
|
19
|
+
* @param pos The position of the label in the source code.
|
|
20
|
+
* @param name The name of the label.
|
|
21
|
+
* @param value The value of the label (if known) or null (if unknown).
|
|
22
|
+
*/
|
|
23
|
+
declare function addLabel(pos: Position, name: string, value: number | null): void;
|
|
24
|
+
/**
|
|
25
|
+
* Add a label and its associated expression.
|
|
26
|
+
* @param _ The position of the label in the source code.
|
|
27
|
+
* @param name The name of the label.
|
|
28
|
+
* @param expression The expression that gives that value of the label.
|
|
29
|
+
*/
|
|
30
|
+
declare function addLabelExpression(_: PosInfo, name: string, expression: Expression): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get the value associated with a label.
|
|
33
|
+
* @param pc Current program counter (PC).
|
|
34
|
+
* @param name The name of the label.
|
|
35
|
+
* @param pos Where this label is used.
|
|
36
|
+
* @param setUsed If set, mark the label as used.
|
|
37
|
+
* @param mustExist If set, the value of the label has to be known (not null).
|
|
38
|
+
* @return The value associated with a label or null if it is unknown.
|
|
39
|
+
*/
|
|
40
|
+
declare function getLabelValue(pc: Address, name: string, pos: Position, setUsed: boolean, mustExist: boolean): number | null;
|
|
41
|
+
/**
|
|
42
|
+
* Is a label used in the program or only declared?
|
|
43
|
+
* @param name The name of the label.
|
|
44
|
+
* @return true if the label is used, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
declare function isLabelUsed(name: string): boolean | undefined;
|
|
47
|
+
export { resetLabels, resetLabelsRecursion, addLabel, addLabelExpression, getLabelValue, isLabelUsed };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: LoweLevel.ts
|
|
5
|
+
* Description: Low level functions for the parser
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
import { byte } from "../types/Types";
|
|
11
|
+
/**
|
|
12
|
+
* Compute the binary representation of the r argument.
|
|
13
|
+
* @param r The argument of the opcode.
|
|
14
|
+
* @param offset The number of bits to shift to the left.
|
|
15
|
+
*/
|
|
16
|
+
export declare function r_bits(r: string, offset?: number): byte;
|
|
17
|
+
/**
|
|
18
|
+
* Compute the binary representation of the dd argument.
|
|
19
|
+
* @param dd The argument of the opcode.
|
|
20
|
+
* @param offset The number of bits to shift to the left.
|
|
21
|
+
*/
|
|
22
|
+
export declare function dd_bits(dd: string, offset?: number): byte;
|
|
23
|
+
/**
|
|
24
|
+
* Compute the binary representation of the qq argument.
|
|
25
|
+
* @param qq The argument of the opcode.
|
|
26
|
+
* @param offset The number of bits to shift to the left.
|
|
27
|
+
*/
|
|
28
|
+
export declare function qq_bits(qq: string, offset?: number): byte;
|
|
29
|
+
/**
|
|
30
|
+
* Compute the binary representation of the ss argument.
|
|
31
|
+
* @param ss The argument of the opcode.
|
|
32
|
+
* @param offset The number of bits to shift to the left.
|
|
33
|
+
*/
|
|
34
|
+
export declare function ss_bits(ss: string, offset?: number): byte;
|
|
35
|
+
/**
|
|
36
|
+
* Compute the binary representation of the pp argument.
|
|
37
|
+
* @param pp The argument of the opcode.
|
|
38
|
+
* @param offset The number of bits to shift to the left.
|
|
39
|
+
*/
|
|
40
|
+
export declare function pp_bits(pp: string, offset?: number): byte;
|
|
41
|
+
/**
|
|
42
|
+
* Compute the binary representation of the rr argument.
|
|
43
|
+
* @param rr The argument of the opcode.
|
|
44
|
+
* @param offset The number of bits to shift to the left.
|
|
45
|
+
*/
|
|
46
|
+
export declare function rr_bits(rr: string, offset?: number): byte;
|
|
47
|
+
/**
|
|
48
|
+
* Compute the binary representation of the cc argument.
|
|
49
|
+
* @param cc The argument of the opcode.
|
|
50
|
+
* @param offset The number of bits to shift to the left.
|
|
51
|
+
*/
|
|
52
|
+
export declare function cc_bits(cc: string, offset?: number): byte;
|
|
53
|
+
/**
|
|
54
|
+
* Compute the binary representation of the jj argument.
|
|
55
|
+
* @param jj The argument of the opcode.
|
|
56
|
+
*/
|
|
57
|
+
export declare function jj_bits(jj?: string): byte;
|
|
58
|
+
/**
|
|
59
|
+
* Compute the binary representation of the p argument.
|
|
60
|
+
* @param p The argument of the opcode.
|
|
61
|
+
* @param offset The number of bits to shift to the left.
|
|
62
|
+
*/
|
|
63
|
+
export declare function p_bits(p: number, offset?: number): byte;
|
|
64
|
+
/**
|
|
65
|
+
* Compute the binary representation of the mode argument.
|
|
66
|
+
* @param mode The argument of the opcode.
|
|
67
|
+
*/
|
|
68
|
+
export declare function imode(mode: string): byte;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z80 Assembler in Typescript
|
|
3
|
+
*
|
|
4
|
+
* File: Parse.ts
|
|
5
|
+
* Description: Fonctions uses by the parser to convert strings
|
|
6
|
+
* Author: Sebastien Andrivet
|
|
7
|
+
* License: GPLv3
|
|
8
|
+
* Copyrights: Copyright (C) 2023 Sebastien Andrivet
|
|
9
|
+
*/
|
|
10
|
+
import { PosInfo } from "./z80";
|
|
11
|
+
/**
|
|
12
|
+
* Parse a number.
|
|
13
|
+
* @param pos Position of the number in the source code.
|
|
14
|
+
* @param str The characters of the number.
|
|
15
|
+
* @param base The base of the number.
|
|
16
|
+
* @param nbBytes The number of bytes to represent this number (1 or 2)
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseNumber(pos: PosInfo, str: string, base: number, nbBytes: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Parse a simple escape, i.e. a backslash followed by a character.
|
|
21
|
+
* @param pos Position of the character in the source code.
|
|
22
|
+
* @param c The character after the backslash.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseSimpleEscape(pos: PosInfo, c: string): number[];
|
|
25
|
+
/**
|
|
26
|
+
* Parse an octal value.
|
|
27
|
+
* @param pos Position of the value in the source code.
|
|
28
|
+
* @param value The characters representing the value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseOctalEscape(pos: PosInfo, value: string): number[];
|
|
31
|
+
/**
|
|
32
|
+
* Parse a hexadecimal value.
|
|
33
|
+
* @param pos Position of the value in the source code.
|
|
34
|
+
* @param value The characters representing the value.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseHexadecimalEscape(pos: PosInfo, value: string): number[];
|
|
37
|
+
/**
|
|
38
|
+
* Parse a ZX81 character written in ASCII.
|
|
39
|
+
* @param pos Position of the character in the source code.
|
|
40
|
+
* @param c The ASCII character.
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseZX81Char(pos: PosInfo, c: string): [number];
|
|
43
|
+
/**
|
|
44
|
+
* Parse a ZX81 string written in ASCII.
|
|
45
|
+
* @param pos Position of the string in the source code.
|
|
46
|
+
* @param str The ASCII string.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseZX81String(pos: PosInfo, str: string): number[];
|