From 7b68b152b6b103cfc88181e34b4db1fc67aa8535 Mon Sep 17 00:00:00 2001
From: JasonMo1 <111677135+JasonMo1@users.noreply.github.com>
Date: Sun, 25 Jun 2023 13:15:44 +0800
Subject: [PATCH] Electron: Add electron support
---
.gitignore | 4 +++
README.md | 71 ++++++++++++++++++++++++++++++++++++++++---------
forge.config.js | 30 +++++++++++++++++++++
index.js | 47 ++++++++++++++++++++++++++++++++
package.json | 33 +++++++++++++++++++++++
preload.js | 0
6 files changed, 172 insertions(+), 13 deletions(-)
create mode 100644 .gitignore
create mode 100644 forge.config.js
create mode 100644 index.js
create mode 100644 package.json
create mode 100644 preload.js
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5e5b4ae
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+node_modules/
+
+*.lock
+out/
\ No newline at end of file
diff --git a/README.md b/README.md
index 26feeac..bfb4839 100644
--- a/README.md
+++ b/README.md
@@ -12,13 +12,52 @@ This project is a software emulator for Zeal 8-bit Computer: a homebrew 8-bit co
## Why this project?
-The goal of this project is to reproduce the exact same behavior of the real machine, in order to be able to execute and mainly **debug** the programs written for it directly from a host computer, without the need to flash any EEPROM or NOR Flash in order to test it. This makes development and test cycles much faster and more convenient.
+The goal of this project is to reproduce the exact same behavior of the real machine, in order to be able to execute and mainly **debug** the programs written for it directly from a host computer, without the need to flash any EEPROM or NOR Flash in order to test it. This makes development and test cycles much faster and more convenient.
+
+## How to start it with electron?
+
+##### Import
+
+Use electron import script:
+
+Yarn:
+
+```
+yarn add --dev @electron-forge/cli
+yarn electron-forge import
+```
+
+Npm:
+
+```
+cd my-app
+npm install --save-dev @electron-forge/cli
+npm exec --package=@electron-forge/cli -c "electron-forge import"
+```
+
+If it doesn't work, you can find some information at [here.](https://www.electronforge.io/import-existing-project)
+
+##### Run
+
+Yarn:
+
+```
+Yarn start
+```
+
+Npm:
+
+```
+npm start
+```
+
+For more informations, check for [Get Started - Electron forge](https://www.electronforge.io/).
## Why a web-based emulator ? (HTML/CSS/JavaScript)
The main goal is to integrate this emulator as part of [zeal8bit.com](https://zeal8bit.com) website. Thus, choosing HTML/CSS and Javascript was a bit obvious on this side.
-On the other side, another goal of this project is also to let anybody test or write programs for Zeal 8-bit Computer on any platform (Linux/Windows/Mac OS X) without the need of a toolchain installed.
+On the other side, another goal of this project is also to let anybody test or write programs for Zeal 8-bit Computer on any platform (Linux/Windows/Mac OS X) without the need of a toolchain installed.
The emulator has been tested on Opera and Google Chrome.
@@ -28,11 +67,12 @@ The emulator is slower than the real hardware, even though the real hardware is
Moreover, the emulator is not really accurate it terms of timings, more details below, in the *features* section.
-Writing a native emulator in **C** (w/ SDL) would cover the requirement of a full-speed emulator, which would be more accurate in terms of timings. However, this needs some time investment. Feel free to contact me or contribute if such project interest you.
+Writing a native emulator in **C** (w/ SDL) would cover the requirement of a full-speed emulator, which would be more accurate in terms of timings. However, this needs some time investment. Feel free to contact me or contribute if such project interest you.
## Features
Currently, the following features from Zeal 8-bit Computer are emulated:
+
* Z80 CPU ([thanks to *Molly Howell*](https://github.com/DrGoldfire/Z80.js))
* Z80 PIO: all modes supported, both port A and B. Implementation is independent from connected devices.
* 22-bit MMU
@@ -45,6 +85,7 @@ Currently, the following features from Zeal 8-bit Computer are emulated:
* I2C RTC: always returns the current date
Features of the emulator itself implemented:
+
* Debugger: breakpoints, step, step over instruction, continue until next breakpoint
* Load a binary file, loaded into ROM directly
* Load a dump file generated from `z88dk-dis` to view assembly code while doing step by step debugging
@@ -55,10 +96,11 @@ Features of the emulator itself implemented:
## TODO
Of course a lot of things are still remaining to do. On the emulation side:
-* PIO: complete the implementation for the user port (A) to act as a regular GPIO, and system port (port B) to activate/deactivate the interrupts, the H-blank, V-blank, I2C, UART, etc... (Done, PIO is now a regular GPIO component, separated from connected components)
-* UART emulation (needs PIO port B) (Done, it is possible to read and write characters, baudrates are hardcoded at the moment. Would be interesting to be able to send a file through UART Done)
-* I2C RTC (needs PIO port B) (Partially implemented: it always returns the current browser date, so writing to it will have no effect)
-* I2C 32KB EEPROM emulation (needs PIO port B)
+
+* ``PIO: complete the implementation for the user port (A) to act as a regular GPIO, and system port (port B) to activate/deactivate the interrupts, the H-blank, V-blank, I2C, UART, etc...`` (Done, PIO is now a regular GPIO component, separated from connected components)
+* ``UART emulation (needs PIO port B)`` (``Done, it is possible to read and write characters, baudrates are hardcoded at the moment. Would be interesting to be able to send a file through UART`` Done)
+* ``I2C RTC (needs PIO port B)`` (Partially implemented: it always returns the current browser date, so writing to it will have no effect)
+* I2C 32KB EEPROM emulation ``(needs PIO port B)``
* Sound support¹
* SD Card emulation²
* Video chip: 320x240 text mode, 320x240 graphic mode², sprites², 4-bit palettes², etc...
@@ -67,8 +109,8 @@ Of course a lot of things are still remaining to do. On the emulation side:
²: features **not** in high priority as they have not been implemented on real hardware yet.
-
On the project/debugger side itself:
+
* A better **interface** for the debugger's buttons, with some shortcuts
* A better way to **parse breakpoint input**. A know bug is providing a label starting hex letters would be interpreted as a PC value instead of a label. For example, inputting *date_routine* as a label to break in would result in the addition of a breakpoint at address 0xda instead of the address of label *date_routine* (because *date* starts with hex letters *da*)
* **Refactoring**. Some part of the code, mainly in `zeal.js` are a bit dirty in the sense that several different things are managed by this file: breakpoints, disassembly view, memory viewer, Zeal emulation, etc... It should be cleaned and split up between multiple files.
@@ -82,20 +124,23 @@ Anyone can contribute to this project, contributions are welcome!
Feel free to fix any bug that you may see or encounter, implement any feature that is present in the TODO list or a new one that you find useful or important.
To contribute:
- * Fork the Project
- * Create your feature Branch (*optional*)
- * Commit your changes. Please make a clear and concise commit message (*)
- * Push to the branch
- * Open a Pull Request
+* Fork the Project
+* Create your feature Branch (*optional*)
+* Commit your changes. Please make a clear and concise commit message (*)
+* Push to the branch
+* Open a Pull Request
(*) A good commit message is as follow:
+
```
Module: add/fix/remove a from b
Explanation on what/how/why
```
+
For example:
+
```
Video chip: implement 320x240 text-mode
diff --git a/forge.config.js b/forge.config.js
new file mode 100644
index 0000000..179a35e
--- /dev/null
+++ b/forge.config.js
@@ -0,0 +1,30 @@
+module.exports = {
+ packagerConfig: {
+ asar: true,
+ },
+ rebuildConfig: {},
+ makers: [
+ {
+ name: '@electron-forge/maker-squirrel',
+ config: {},
+ },
+ {
+ name: '@electron-forge/maker-zip',
+ platforms: ['darwin'],
+ },
+ {
+ name: '@electron-forge/maker-deb',
+ config: {},
+ },
+ {
+ name: '@electron-forge/maker-rpm',
+ config: {},
+ },
+ ],
+ plugins: [
+ {
+ name: '@electron-forge/plugin-auto-unpack-natives',
+ config: {},
+ },
+ ],
+};
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..01b4566
--- /dev/null
+++ b/index.js
@@ -0,0 +1,47 @@
+const { app, BrowserWindow } = require('electron');
+const path = require('path');
+
+// Handle creating/removing shortcuts on Windows when installing/uninstalling.
+if (require('electron-squirrel-startup')) {
+ app.quit();
+}
+
+const createWindow = () => {
+ // Create the browser window.
+ const mainWindow = new BrowserWindow({
+ width: 1200,
+ height: 800,
+ webPreferences: {
+ preload: path.join(__dirname, 'preload.js'),
+ },
+ });
+
+ // and load the index.html of the app.
+ mainWindow.loadFile(path.join(__dirname, 'index.html'));
+
+};
+
+// This method will be called when Electron has finished
+// initialization and is ready to create browser windows.
+// Some APIs can only be used after this event occurs.
+app.on('ready', createWindow);
+
+// Quit when all windows are closed, except on macOS. There, it's common
+// for applications and their menu bar to stay active until the user quits
+// explicitly with Cmd + Q.
+app.on('window-all-closed', () => {
+ if (process.platform !== 'darwin') {
+ app.quit();
+ }
+});
+
+app.on('activate', () => {
+ // On OS X it's common to re-create a window in the app when the
+ // dock icon is clicked and there are no other windows open.
+ if (BrowserWindow.getAllWindows().length === 0) {
+ createWindow();
+ }
+});
+
+// In this file you can include the rest of your app's specific main process
+// code. You can also put them in separate files and import them here.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..3c34007
--- /dev/null
+++ b/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "zealwebemulator",
+ "productName": "Zeal-WebEmulator",
+ "version": "1.0.0",
+ "description": "A emulator for Zeal 8-bit Computer based on electron",
+ "main": "index.js",
+ "scripts": {
+ "start": "electron-forge start",
+ "package": "electron-forge package",
+ "make": "electron-forge make",
+ "publish": "electron-forge publish",
+ "lint": "echo \"No linting configured\""
+ },
+ "keywords": [],
+ "author": {
+ "name": "Zeal8bit",
+ "email": "contact@zeal8bit.com"
+ },
+ "license": "Apache",
+ "dependencies": {
+ "electron-squirrel-startup": "^1.0.0"
+ },
+ "devDependencies": {
+ "@electron-forge/cli": "^6.2.1",
+ "@electron-forge/maker-deb": "^6.2.1",
+ "@electron-forge/maker-rpm": "^6.2.1",
+ "@electron-forge/maker-squirrel": "^6.2.1",
+ "@electron-forge/maker-zip": "^6.2.1",
+ "@electron-forge/plugin-auto-unpack-natives": "^6.2.1",
+ "electron": "25.2.0",
+ "electron-squirrel-startup": "^1.0.0"
+ }
+}
diff --git a/preload.js b/preload.js
new file mode 100644
index 0000000..e69de29