@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.
Files changed (197) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.json +35 -0
  4. package/.github/workflows/node.js.yml +47 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +3 -0
  7. package/.vscode/extensions.json +7 -0
  8. package/README.md +53 -27
  9. package/apps/.gitkeep +0 -0
  10. package/apps/z80-assembler-app/.eslintrc.json +18 -0
  11. package/apps/z80-assembler-app/index.html +16 -0
  12. package/apps/z80-assembler-app/postcss.config.js +24 -0
  13. package/apps/z80-assembler-app/project.json +70 -0
  14. package/apps/z80-assembler-app/public/favicon.ico +0 -0
  15. package/apps/z80-assembler-app/public/logo.png +0 -0
  16. package/apps/z80-assembler-app/public/logo192.png +0 -0
  17. package/apps/z80-assembler-app/public/logo512.png +0 -0
  18. package/apps/z80-assembler-app/public/manifest.json +25 -0
  19. package/apps/z80-assembler-app/public/robots.txt +3 -0
  20. package/apps/z80-assembler-app/src/app/app.module.css +0 -0
  21. package/apps/z80-assembler-app/src/app/app.tsx +122 -0
  22. package/apps/z80-assembler-app/src/app/binary.tsx +39 -0
  23. package/apps/z80-assembler-app/src/app/editor.tsx +228 -0
  24. package/apps/z80-assembler-app/src/app/errors.tsx +31 -0
  25. package/apps/z80-assembler-app/src/app/footer.tsx +20 -0
  26. package/apps/z80-assembler-app/src/app/header.tsx +57 -0
  27. package/apps/z80-assembler-app/src/app/misc.ts +13 -0
  28. package/apps/z80-assembler-app/src/app/opcodes.tsx +335 -0
  29. package/apps/z80-assembler-app/src/assets/.gitkeep +0 -0
  30. package/apps/z80-assembler-app/src/assets/images/logo192.png +0 -0
  31. package/apps/z80-assembler-app/src/main.tsx +22 -0
  32. package/apps/z80-assembler-app/src/styles.css +8 -0
  33. package/apps/z80-assembler-app/tailwind.config.js +28 -0
  34. package/apps/z80-assembler-app/tsconfig.app.json +22 -0
  35. package/apps/z80-assembler-app/tsconfig.json +21 -0
  36. package/apps/z80-assembler-app/tsconfig.spec.json +23 -0
  37. package/apps/z80-assembler-app/vite.config.ts +64 -0
  38. package/assets/images/compile.png +0 -0
  39. package/assets/images/logo.png +0 -0
  40. package/assets/images/menu.png +0 -0
  41. package/assets/images/opcodes-load8.png +0 -0
  42. package/assets/images/opcodes.png +0 -0
  43. package/assets/images/open-dir.png +0 -0
  44. package/assets/images/z80-assembler-app.png +0 -0
  45. package/docs/assembly.md +551 -0
  46. package/docs/images/ZX81-0x00.png +0 -0
  47. package/docs/images/ZX81-0x0B.png +0 -0
  48. package/docs/images/ZX81-0x0C.png +0 -0
  49. package/docs/images/ZX81-0x0D.png +0 -0
  50. package/docs/images/ZX81-0x0E.png +0 -0
  51. package/docs/images/ZX81-0x0F.png +0 -0
  52. package/docs/images/ZX81-0x10.png +0 -0
  53. package/docs/images/ZX81-0x11.png +0 -0
  54. package/docs/images/ZX81-0x12.png +0 -0
  55. package/docs/images/ZX81-0x13.png +0 -0
  56. package/docs/images/ZX81-0x14.png +0 -0
  57. package/docs/images/ZX81-0x15.png +0 -0
  58. package/docs/images/ZX81-0x16.png +0 -0
  59. package/docs/images/ZX81-0x17.png +0 -0
  60. package/docs/images/ZX81-0x18.png +0 -0
  61. package/docs/images/ZX81-0x19.png +0 -0
  62. package/docs/images/ZX81-0x1A.png +0 -0
  63. package/docs/images/ZX81-0x1B.png +0 -0
  64. package/docs/images/ZX81-0x1C.png +0 -0
  65. package/docs/images/ZX81-0x1D.png +0 -0
  66. package/docs/images/ZX81-0x1E.png +0 -0
  67. package/docs/images/ZX81-0x1F.png +0 -0
  68. package/docs/images/ZX81-0x20.png +0 -0
  69. package/docs/images/ZX81-0x21.png +0 -0
  70. package/docs/images/ZX81-0x22.png +0 -0
  71. package/docs/images/ZX81-0x23.png +0 -0
  72. package/docs/images/ZX81-0x24.png +0 -0
  73. package/docs/images/ZX81-0x25.png +0 -0
  74. package/docs/images/ZX81-0x26.png +0 -0
  75. package/docs/images/ZX81-0x27.png +0 -0
  76. package/docs/images/ZX81-0x28.png +0 -0
  77. package/docs/images/ZX81-0x29.png +0 -0
  78. package/docs/images/ZX81-0x2A.png +0 -0
  79. package/docs/images/ZX81-0x2B.png +0 -0
  80. package/docs/images/ZX81-0x2C.png +0 -0
  81. package/docs/images/ZX81-0x2D.png +0 -0
  82. package/docs/images/ZX81-0x2E.png +0 -0
  83. package/docs/images/ZX81-0x2F.png +0 -0
  84. package/docs/images/ZX81-0x30.png +0 -0
  85. package/docs/images/ZX81-0x31.png +0 -0
  86. package/docs/images/ZX81-0x32.png +0 -0
  87. package/docs/images/ZX81-0x33.png +0 -0
  88. package/docs/images/ZX81-0x34.png +0 -0
  89. package/docs/images/ZX81-0x35.png +0 -0
  90. package/docs/images/ZX81-0x36.png +0 -0
  91. package/docs/images/ZX81-0x37.png +0 -0
  92. package/docs/images/ZX81-0x38.png +0 -0
  93. package/docs/images/ZX81-0x39.png +0 -0
  94. package/docs/images/ZX81-0x3A.png +0 -0
  95. package/docs/images/ZX81-0x3B.png +0 -0
  96. package/docs/images/ZX81-0x3C.png +0 -0
  97. package/docs/images/ZX81-0x3D.png +0 -0
  98. package/docs/images/ZX81-0x3E.png +0 -0
  99. package/docs/images/ZX81-0x3F.png +0 -0
  100. package/docs/images/ZX81-0x80.png +0 -0
  101. package/docs/images/ZX81-0x8B.png +0 -0
  102. package/docs/images/ZX81-0x8C.png +0 -0
  103. package/docs/images/ZX81-0x8D.png +0 -0
  104. package/docs/images/ZX81-0x8E.png +0 -0
  105. package/docs/images/ZX81-0x8F.png +0 -0
  106. package/docs/images/ZX81-0x90.png +0 -0
  107. package/docs/images/ZX81-0x91.png +0 -0
  108. package/docs/images/ZX81-0x92.png +0 -0
  109. package/docs/images/ZX81-0x93.png +0 -0
  110. package/docs/images/ZX81-0x94.png +0 -0
  111. package/docs/images/ZX81-0x95.png +0 -0
  112. package/docs/images/ZX81-0x96.png +0 -0
  113. package/docs/images/ZX81-0x97.png +0 -0
  114. package/docs/images/ZX81-0x98.png +0 -0
  115. package/docs/images/ZX81-0x99.png +0 -0
  116. package/docs/images/ZX81-0x9A.png +0 -0
  117. package/docs/images/ZX81-0x9B.png +0 -0
  118. package/docs/images/ZX81-0x9C.png +0 -0
  119. package/docs/images/ZX81-0x9D.png +0 -0
  120. package/docs/images/ZX81-0x9E.png +0 -0
  121. package/docs/images/ZX81-0x9F.png +0 -0
  122. package/docs/images/ZX81-0xA0.png +0 -0
  123. package/docs/images/ZX81-0xA1.png +0 -0
  124. package/docs/images/ZX81-0xA2.png +0 -0
  125. package/docs/images/ZX81-0xA3.png +0 -0
  126. package/docs/images/ZX81-0xA4.png +0 -0
  127. package/docs/images/ZX81-0xA5.png +0 -0
  128. package/docs/images/ZX81-0xA6.png +0 -0
  129. package/docs/images/ZX81-0xA7.png +0 -0
  130. package/docs/images/ZX81-0xA8.png +0 -0
  131. package/docs/images/ZX81-0xA9.png +0 -0
  132. package/docs/images/ZX81-0xAA.png +0 -0
  133. package/docs/images/ZX81-0xAB.png +0 -0
  134. package/docs/images/ZX81-0xAC.png +0 -0
  135. package/docs/images/ZX81-0xAD.png +0 -0
  136. package/docs/images/ZX81-0xAE.png +0 -0
  137. package/docs/images/ZX81-0xAF.png +0 -0
  138. package/docs/images/ZX81-0xB0.png +0 -0
  139. package/docs/images/ZX81-0xB1.png +0 -0
  140. package/docs/images/ZX81-0xB2.png +0 -0
  141. package/docs/images/ZX81-0xB3.png +0 -0
  142. package/docs/images/ZX81-0xB4.png +0 -0
  143. package/docs/images/ZX81-0xB5.png +0 -0
  144. package/docs/images/ZX81-0xB6.png +0 -0
  145. package/docs/images/ZX81-0xB7.png +0 -0
  146. package/docs/images/ZX81-0xB8.png +0 -0
  147. package/docs/images/ZX81-0xB9.png +0 -0
  148. package/docs/images/ZX81-0xBA.png +0 -0
  149. package/docs/images/ZX81-0xBB.png +0 -0
  150. package/docs/images/ZX81-0xBC.png +0 -0
  151. package/docs/images/ZX81-0xBD.png +0 -0
  152. package/docs/images/ZX81-0xBE.png +0 -0
  153. package/docs/images/ZX81-0xBF.png +0 -0
  154. package/libs/.gitkeep +0 -0
  155. package/libs/z80-assembler/.eslintrc.json +18 -0
  156. package/libs/z80-assembler/package.json +20 -0
  157. package/libs/z80-assembler/project.json +35 -0
  158. package/libs/z80-assembler/public/README.md +54 -0
  159. package/{index.d.ts → libs/z80-assembler/src/index.ts} +1 -1
  160. package/libs/z80-assembler/src/lib/assets/code/basic-end.zx81 +4 -0
  161. package/libs/z80-assembler/src/lib/assets/code/basic-line1.zx81 +4 -0
  162. package/libs/z80-assembler/src/lib/assets/code/basic-line2.zx81 +9 -0
  163. package/libs/z80-assembler/src/lib/assets/code/characters.zx81 +190 -0
  164. package/libs/z80-assembler/src/lib/assets/code/display.zx81 +50 -0
  165. package/libs/z80-assembler/src/lib/assets/code/system-variables.zx81 +46 -0
  166. package/{lib/compiler/Assets.d.ts → libs/z80-assembler/src/lib/compiler/Assets.ts} +6 -1
  167. package/libs/z80-assembler/src/lib/compiler/Ast.ts +545 -0
  168. package/libs/z80-assembler/src/lib/compiler/Compiler.test.ts +2141 -0
  169. package/libs/z80-assembler/src/lib/compiler/Compiler.ts +185 -0
  170. package/libs/z80-assembler/src/lib/compiler/Formatter.ts +43 -0
  171. package/libs/z80-assembler/src/lib/compiler/Generator.ts +255 -0
  172. package/libs/z80-assembler/src/lib/compiler/Labels.ts +165 -0
  173. package/libs/z80-assembler/src/lib/grammar/LowLevel.ts +163 -0
  174. package/libs/z80-assembler/src/lib/grammar/Parse.ts +128 -0
  175. package/libs/z80-assembler/src/lib/grammar/z80.peg +1252 -0
  176. package/libs/z80-assembler/src/lib/grammar/z80.ts +10649 -0
  177. package/libs/z80-assembler/src/lib/types/Error.ts +105 -0
  178. package/{lib/types/Types.d.ts → libs/z80-assembler/src/lib/types/Types.ts} +26 -11
  179. package/libs/z80-assembler/tsconfig.json +23 -0
  180. package/libs/z80-assembler/tsconfig.lib.json +10 -0
  181. package/libs/z80-assembler/tsconfig.spec.json +19 -0
  182. package/libs/z80-assembler/vite.config.ts +58 -0
  183. package/nx.json +57 -0
  184. package/package.json +52 -14
  185. package/tsconfig.base.json +22 -0
  186. package/index.js +0 -312
  187. package/index.mjs +0 -6441
  188. package/lib/compiler/Ast.d.ts +0 -210
  189. package/lib/compiler/Compiler.d.ts +0 -53
  190. package/lib/compiler/Formatter.d.ts +0 -23
  191. package/lib/compiler/Generator.d.ts +0 -40
  192. package/lib/compiler/Labels.d.ts +0 -47
  193. package/lib/grammar/LowLevel.d.ts +0 -68
  194. package/lib/grammar/Parse.d.ts +0 -48
  195. package/lib/grammar/z80.d.ts +0 -2938
  196. package/lib/types/Error.d.ts +0 -62
  197. /package/{CHANGELOG.md → libs/z80-assembler/public/CHANGELOG.md} +0 -0
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # Editor configuration, see http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.md]
12
+ max_line_length = off
13
+ trim_trailing_whitespace = false
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ libs/z80-assembler/src/lib/grammar/z80.ts
3
+ libs/z80-assembler/src/lib/**/*.test.ts
package/.eslintrc.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "root": true,
3
+ "ignorePatterns": ["**/*"],
4
+ "plugins": ["@nx"],
5
+ "overrides": [
6
+ {
7
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8
+ "rules": {
9
+ "@nx/enforce-module-boundaries": [
10
+ "error",
11
+ {
12
+ "enforceBuildableLibDependency": true,
13
+ "allow": [],
14
+ "depConstraints": [
15
+ {
16
+ "sourceTag": "*",
17
+ "onlyDependOnLibsWithTags": ["*"]
18
+ }
19
+ ]
20
+ }
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "files": ["*.ts", "*.tsx"],
26
+ "extends": ["plugin:@nx/typescript"],
27
+ "rules": {}
28
+ },
29
+ {
30
+ "files": ["*.js", "*.jsx"],
31
+ "extends": ["plugin:@nx/javascript"],
32
+ "rules": {}
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,47 @@
1
+ name: CD
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version: [16.x, 18.x, 20.x]
15
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v3
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v3
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ cache: 'npm'
24
+ - name: Install dependencies
25
+ run: npm ci --legacy-peer-deps
26
+ - name: Build
27
+ run: npx nx build z80-assembler-app --prod --baseHref=/z80-assembler/
28
+ - name: Run tests
29
+ run: npx nx test z80-assembler
30
+ - name: Upload artifact
31
+ uses: actions/upload-pages-artifact@v1
32
+ with:
33
+ path: dist/apps/z80-assembler-app
34
+
35
+ deploy:
36
+ needs: build
37
+ permissions:
38
+ pages: write
39
+ id-token: write
40
+ environment:
41
+ name: github-pages
42
+ url: ${{ steps.deployment.outputs.page_url }}
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - name: Deploy to GitHub Pages
46
+ id: deployment
47
+ uses: actions/deploy-pages@v2
@@ -0,0 +1,3 @@
1
+ # Add files here to ignore them from prettier formatting
2
+ /dist
3
+ /coverage
package/.prettierrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "singleQuote": true
3
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "recommendations": [
3
+ "nrwl.angular-console",
4
+ "esbenp.prettier-vscode",
5
+ "dbaeumer.vscode-eslint"
6
+ ]
7
+ }
package/README.md CHANGED
@@ -1,53 +1,79 @@
1
1
  # z80-assembler
2
2
 
3
- A Z80 assembler library entirely written in Typescript and derived from a PEG grammar.
4
- It optimized for the old ZX81 computer but can also be used with any other Z80 targets.
3
+ ![Z80](assets/images/logo.png)
5
4
 
6
- ## Demo application
5
+ A Z80 assembler entirely written in Typescript and derived from a PEG grammar.
7
6
 
8
- A demo application is available: https://andrivet.github.io/z80-assembler/.
7
+ ## Components
9
8
 
10
- ## Quick guide to use the library
9
+ * The first component is the library itself, `z80-assembler` that can be used like any npm library.
10
+ * The second component is an application, `z80-assembler-app` that uses this library.
11
+ It can be used by itself or as an example of how to use the library. It is written in Typescript with React.
11
12
 
12
- To install the library:
13
+ ![z80-assembler-app](assets/images/z80-assembler-app.png)
14
+
15
+ This assembler is also used in the [ZX81 Debugger](https://github.com/andrivet/ZX81-Debugger).
16
+
17
+ ## How to build from source
13
18
 
14
19
  ```
15
- $ npm install @andrivet/z80-assembler
20
+ npm --legacy-peer-deps install
21
+ ./node_modules/.bin/nx run z80-assembler-app:build:production
16
22
  ```
17
23
 
18
- The main function is simply called `compile`. It takes three arguments:
24
+ Notes:
19
25
 
20
- * the name of the source file
21
- * the Z80 source code to compile
22
- * a function used to return the content of included files
26
+ * For the moment, you have to use `--legacy-peer-deps` because react-daisyui is not yet updated for DaisyUI 3.
27
+ Once it is the case, this flag will no more be necessary.
23
28
 
24
- It returns an object of type `CompilationInfo` with the following fields:
29
+ * If you have installed NX globally, you do not need to specify its path.
25
30
 
26
- * `outputName`: The name of the output as set by the `output` directive.
27
- * `bytes`: A array of numbers. Each element represents a byte of the generated machine code.
28
- * `sld`: The Source Level Debugging data as a string. This is used in order to debug the code.
29
- * `errs`: An array of errors
30
-
31
- A typical way to use the function is:
31
+ ## How to run the application
32
32
 
33
33
  ```
34
- const info = compile(filepath, code, handleGetFileCode);
35
- if(info.errs.length > 0)
36
- displayErrors(info.errs);
37
- else
38
- saveOutput(info.outputName, info.bytes);
34
+ nx run z80-assembler-app:dev:production
39
35
  ```
40
36
 
41
- You can find a complete example in the [demo application](https://github.com/andrivet/z80-assembler/), in particular in the `app.tsx` file.
37
+ Open a navigator at the URL http://localhost:4200/
38
+
39
+
40
+ ## Quick guide to use the application
41
+
42
+ Under the **File** menu, you find the following commands:
43
+
44
+ ![Z80](assets/images/menu.png)
45
+
46
+ * **Open Code**: Open a Z80 source file.
47
+ * **Open Code Directory**: Open a directory with Z80 source files. This is especially useful if your source files contain includes.
48
+ * **Save Code**: Save the current code file.
49
+ * **Save Binary**: Save the compiled binary.
50
+ * **Save SLD File**: Save the Source Level Debugging data in text format.
51
+ * **Close Code**: Close the current code.
52
+ * **Close All**: Close all the open codes.
53
+
54
+ ![Z80](assets/images/open-dir.png)
55
+
56
+ Once one or more files are open, click on Compile to compile the code.
57
+ The binary are displayed on the right side:
58
+
59
+ ![Z80](assets/images/compile.png)
60
+
61
+ While writing your Z80 assembly code, you can display the list of Z80 opcodes by clicking on **Z80 Opcodes**:
62
+
63
+ ![Z80](assets/images/opcodes.png)
64
+
65
+ Click on a category to see the corresponding opcodes:
66
+
67
+ ![Z80](assets/images/opcodes-load8.png)
42
68
 
69
+ ## Z80 assembly
43
70
 
44
- ## Source code
71
+ The format of assembly source file is described in [Z80 Assembly Source Code Format](./docs/assembly.md).
45
72
 
46
- The source code is published on GitHub: https://github.com/andrivet/z80-assembler/.
47
73
 
48
74
  ## Licence
49
75
 
50
- This library and associated application are released under GPLv3.
76
+ This library and application are released under GPLv3.
51
77
 
52
78
  ## Copyrights
53
79
 
package/apps/.gitkeep ADDED
File without changes
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": ["plugin:@nx/react", "../../.eslintrc.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Z80 Assembler in Typescript</title>
6
+ <base href="/" />
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
9
+ <link rel="icon" type="image/x-icon" href="/favicon.ico" />
10
+ <link rel="stylesheet" href="/src/styles.css" />
11
+ </head>
12
+ <body>
13
+ <div id="root"></div>
14
+ <script type="module" src="/src/main.tsx"></script>
15
+ </body>
16
+ </html>
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Z80 Assembler in Typescript
3
+ *
4
+ * File: postcss.config.js
5
+ * Description: Configuration for PostCSS
6
+ * Author: Sebastien Andrivet
7
+ * License: GPLv3
8
+ * Copyrights: Copyright (C) 2023 Sebastien Andrivet
9
+ */
10
+ const { join } = require('path');
11
+
12
+ // Note: If you use library-specific PostCSS/Tailwind configuration then you should remove the `postcssConfig` build
13
+ // option from your application's configuration (i.e. project.json).
14
+ //
15
+ // See: https://nx.dev/guides/using-tailwind-css-in-react#step-4:-applying-configuration-to-libraries
16
+
17
+ module.exports = {
18
+ plugins: {
19
+ tailwindcss: {
20
+ config: join(__dirname, 'tailwind.config.js'),
21
+ },
22
+ autoprefixer: {},
23
+ },
24
+ };
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "z80-assembler-app",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "apps/z80-assembler-app/src",
5
+ "projectType": "application",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "@nx/vite:build",
9
+ "outputs": ["{options.outputPath}"],
10
+ "defaultConfiguration": "production",
11
+ "options": {
12
+ "outputPath": "dist/apps/z80-assembler-app"
13
+ },
14
+ "configurations": {
15
+ "development": {
16
+ "mode": "development"
17
+ },
18
+ "production": {
19
+ "mode": "production"
20
+ }
21
+ }
22
+ },
23
+ "dev": {
24
+ "executor": "@nx/vite:dev-server",
25
+ "defaultConfiguration": "development",
26
+ "options": {
27
+ "buildTarget": "z80-assembler-app:build"
28
+ },
29
+ "configurations": {
30
+ "development": {
31
+ "buildTarget": "z80-assembler-app:build:development",
32
+ "hmr": true
33
+ },
34
+ "production": {
35
+ "buildTarget": "z80-assembler-app:build:production",
36
+ "hmr": false
37
+ }
38
+ }
39
+ },
40
+ "preview": {
41
+ "executor": "@nx/vite:preview-server",
42
+ "defaultConfiguration": "development",
43
+ "options": {
44
+ "buildTarget": "z80-assembler-app:build"
45
+ },
46
+ "configurations": {
47
+ "development": {
48
+ "buildTarget": "z80-assembler-app:build:development"
49
+ },
50
+ "production": {
51
+ "buildTarget": "z80-assembler-app:build:production"
52
+ }
53
+ }
54
+ },
55
+ "lint": {
56
+ "executor": "@nx/linter:eslint",
57
+ "outputs": ["{options.outputFile}"],
58
+ "options": {
59
+ "lintFilePatterns": ["apps/z80-assembler-app/**/*.{ts,tsx,js,jsx}"]
60
+ }
61
+ },
62
+ "serve-static": {
63
+ "executor": "@nx/web:file-server",
64
+ "options": {
65
+ "buildTarget": "z80-assembler-app:build"
66
+ }
67
+ }
68
+ },
69
+ "tags": []
70
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "short_name": "React App",
3
+ "name": "Create React App Sample",
4
+ "icons": [
5
+ {
6
+ "src": "favicon.ico",
7
+ "sizes": "64x64 32x32 24x24 16x16",
8
+ "type": "image/x-icon"
9
+ },
10
+ {
11
+ "src": "logo192.png",
12
+ "type": "image/png",
13
+ "sizes": "192x192"
14
+ },
15
+ {
16
+ "src": "logo512.png",
17
+ "type": "image/png",
18
+ "sizes": "512x512"
19
+ }
20
+ ],
21
+ "start_url": ".",
22
+ "display": "standalone",
23
+ "theme_color": "#000000",
24
+ "background_color": "#ffffff"
25
+ }
@@ -0,0 +1,3 @@
1
+ # https://www.robotstxt.org/robotstxt.html
2
+ User-agent: *
3
+ Disallow:
File without changes
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Z80 Assembler in Typescript
3
+ *
4
+ * File: app.tsx
5
+ * Description: Application view
6
+ * Author: Sebastien Andrivet
7
+ * License: GPLv3
8
+ * Copyrights: Copyright (C) 2023 Sebastien Andrivet
9
+ */
10
+
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ import styles from './app.module.css';
13
+
14
+ import React, {useRef, useState} from 'react';
15
+ import {AppOpcodes} from "./opcodes";
16
+ import {Chunk, CompilationError, compile, formatBytes} from "@andrivet/z80-assembler";
17
+ import AppFooter from "./footer";
18
+ import AppHeader from "./header";
19
+ import AppBinary from "./binary";
20
+ import AppEditor, {AppEditorHandlers} from "./editor";
21
+ import Errors from "./errors";
22
+ import {closeDropdown} from "./misc";
23
+ import {fileSave} from "browser-fs-access";
24
+
25
+ interface BinaryOrOpCodesProps {
26
+ showOpCodes: boolean,
27
+ chunks: Chunk[] | undefined;
28
+ }
29
+
30
+ function BinaryOrOpCodes({showOpCodes, chunks}: BinaryOrOpCodesProps) {
31
+ return showOpCodes ? <AppOpcodes /> : <AppBinary chunks={chunks} />;
32
+ }
33
+
34
+ export function App() {
35
+ const [code, setCode] = useState<string>('');
36
+ const [filepath, setFilepath] = useState<string>('');
37
+ const [errors, setErrors] = useState<CompilationError[] | undefined>();
38
+ const [bytes, setBytes] = useState<number[] | undefined>();
39
+ const [sld, setSld] = useState<string>('');
40
+ const [chunks, setChunks] = useState<Chunk[] | undefined>();
41
+ const [showOpCodes, setShowOpCodes] = useState<boolean>(false);
42
+ const [outputName, setOutputName] = useState<string | undefined>(undefined);
43
+ const ref = useRef<AppEditorHandlers>(null);
44
+
45
+ function handleGetFileCode(filename: string): string {
46
+ if(ref.current == null) throw new Error(`Invalid reference to the editor`);
47
+ return ref.current.getCode(filename);
48
+ }
49
+
50
+ function handleCompile() {
51
+ const info = compile(filepath, code, handleGetFileCode);
52
+ if(info.errs.length > 0) {
53
+ setBytes([]);
54
+ setSld('');
55
+ setChunks([]);
56
+ setErrors(info.errs);
57
+ }
58
+ else {
59
+ setShowOpCodes(false);
60
+ setOutputName(info.outputName);
61
+ setBytes(info.bytes);
62
+ setSld(info.sld);
63
+ setChunks(formatBytes(info.bytes, 16));
64
+ setErrors([]);
65
+ }
66
+ }
67
+
68
+ async function handleSaveBinary() {
69
+ closeDropdown();
70
+ if (!bytes || !outputName) return;
71
+ const data = Uint8Array.from(bytes);
72
+ const blob = new Blob([data]);
73
+ await fileSave(blob, {
74
+ fileName: outputName,
75
+ extensions: ['.P']
76
+ });
77
+ }
78
+
79
+ async function handleSaveSld() {
80
+ closeDropdown();
81
+ if (sld.length <= 0 || !outputName) return;
82
+ const blob = new Blob([sld]);
83
+ await fileSave(blob, {
84
+ fileName: outputName.replace(/\.P$/, ''),
85
+ extensions: ['.sld']
86
+ });
87
+ }
88
+
89
+ return (
90
+ <div className="flex flex-col h-screen bg-neutral-600">
91
+ <AppHeader
92
+ onOpenCode={() => ref.current?.openCode()}
93
+ onOpenCodeDirectory={() => ref.current?.openCodeDirectory()}
94
+ onSaveCode={() => ref.current?.saveCode()}
95
+ onSaveBinary={handleSaveBinary}
96
+ onSaveSld={handleSaveSld}
97
+ onClose={() => ref.current?.closeCode()}
98
+ onCloseAll={() => ref.current?.closeAll()}
99
+ onCompile={handleCompile}
100
+ onShowOpCodes={() => setShowOpCodes(true)}
101
+ />
102
+ <div className="flex-1 flex m-4 gap-4">
103
+ <div className="flex flex-col w-2/3">
104
+ <AppEditor
105
+ ref={ref}
106
+ code={code}
107
+ setFilePath={setFilepath}
108
+ setCode={setCode}
109
+ errors={errors}
110
+ setErrors={setErrors} />
111
+ </div>
112
+ <div className="flex flex-col w-1/3 z-0">
113
+ <BinaryOrOpCodes showOpCodes={showOpCodes} chunks={chunks}/>
114
+ </div>
115
+ </div>
116
+ <Errors errors={errors} />
117
+ <AppFooter />
118
+ </div>
119
+ );
120
+ }
121
+
122
+ export default App;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Z80 Assembler in Typescript
3
+ *
4
+ * File: binary,tsx
5
+ * Description: Binary view
6
+ * Author: Sebastien Andrivet
7
+ * License: GPLv3
8
+ * Copyrights: Copyright (C) 2023 Sebastien Andrivet
9
+ */
10
+ import React from "react";
11
+ import {Table} from "react-daisyui";
12
+ import {Chunk} from "@andrivet/z80-assembler";
13
+
14
+ interface AppBinaryProps {
15
+ chunks: Chunk[] | undefined;
16
+ }
17
+
18
+ export default function AppBinary({chunks}: AppBinaryProps) {
19
+ return (chunks == null || chunks.length <= 0) ? null : (
20
+ <>
21
+ <h1 className="font-bold mb-2 text-orange-400">Machine Code</h1>
22
+ <div className="flex flex-auto h-full relative mt-0">
23
+ <div className="absolute top-0 bottom-0 left-0 right-0 overflow-auto">
24
+ <Table zebra={true}>
25
+ <Table.Head>{['Address', 'Bytes']}</Table.Head>
26
+ <Table.Body>
27
+ {chunks?.map((data, index) => (
28
+ <Table.Row key={data.address} className="font-mono">{[
29
+ <strong key={`addr-${data.address}`} className="text-orange-400">{data.address}</strong>,
30
+ <span key={`data-${data.address}`} >{data.bytes}</span>
31
+ ]}</Table.Row>
32
+ ))}
33
+ </Table.Body>
34
+ </Table>
35
+ </div>
36
+ </div>
37
+ </>
38
+ );
39
+ }