Skip to content

Commit

Permalink
Merge branch 'mini_vz'
Browse files Browse the repository at this point in the history
  • Loading branch information
fvdhoef committed Oct 20, 2024
2 parents 695cdbd + 7c2d851 commit 5ddaf32
Show file tree
Hide file tree
Showing 365 changed files with 47,278 additions and 28,256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: ESP-IDF build
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.2.2
esp_idf_version: v5.3.1
target: esp32s3
path: "System/esp32"
- name: Build release
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
**/.vscode/settings.json
.DS_Store
*.lnk
SDK/projects/game_galaxian/.vscode/c_cpp_properties.json
Expand Down
7 changes: 3 additions & 4 deletions EndUser/sdcard/autoexec.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
10 SET FNKEY 10 TO \"RUN\"/aqds/aqds.aqx\"\r"
20 SET FNKEY 11 TO \"CD\"/cpm\":RUN\"gocpm.aqx\"\r"
30 SET FNKEY 12 TO \"RUN\"esp:settings\"\r"
40 NEW
10 SET FNKEY 1 TO \"RUN\"/aqds/aqds.aqx\"\r"
20 SET FNKEY 2 TO \"CD\"/cpm\":RUN\"gocpm.aqx\"\r"
30 NEW
Binary file not shown.
Binary file added EndUser/sdcard/config/Aquarius+/map_gp_hc/default
Binary file not shown.
Binary file added EndUser/sdcard/config/Aquarius+/map_gp_kb/Inufuto
Binary file not shown.
Binary file added EndUser/sdcard/config/Aquarius+/map_gp_kb/default
Binary file not shown.
1 change: 1 addition & 0 deletions EndUser/sdcard/config/Aquarius+/map_kb_hc/default
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IJKLMN
Binary file modified EndUser/sdcard/cores/aqms/aqms.core
Binary file not shown.
43 changes: 43 additions & 0 deletions SDK/tools/descramble_rom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/env python3
import sys
import argparse

parser = argparse.ArgumentParser(description="Descramble Aquarius ROM file")
parser.add_argument(
"in_file",
metavar="in_file.rom",
help="ROM to descramble",
)
parser.add_argument("out_file", metavar="out_file.rom", help="Descrambled ROM output")
args = parser.parse_args()

with open(args.in_file, "rb") as f:
data = f.read()

if len(data) != 8192 and len(data) != 16384:
print("Error: ROM file should be either 8KB or 16KB in size", file=sys.stderr)
exit(1)

id = data[0:16] if len(data) == 8192 else data[0x2000:0x2010]

# Check constant identifier bytes
if [id[15], id[13], id[11], id[9], id[7], id[5]] != [112, 168, 100, 108, 176, 156]:
print("Error: Invalid ROM image", file=sys.stderr)
exit(1)

scramble_code = (
(674 + (id[3] + id[4] + id[6] + id[8] + id[10] + id[12] + id[14]) + 112) & 0xFF
) ^ 112

out_data = [val ^ scramble_code for val in data]

# Replace header so the descrambled ROM can also be booted
fixup = list(id[0:3]) + [0, 0, 156, 0, 176, 0, 108, 0, 100, 0, 168, 94, 112]
if len(out_data) == 8192:
out_data = fixup + out_data[16:]
else:
out_data = out_data[0:8192] + fixup + out_data[8192 + 16 :]


with open(args.out_file, "wb") as f:
f.write(bytes(out_data))
2 changes: 1 addition & 1 deletion System/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Aquarius+ System
This directory contains:
- [Schematic and PCB](pcb/)
- [FPGA firmware](fpga/)
- [FPGA firmware](fpga_cores/)
- [ESP32 firmware](esp32/)
- [ROM extensions source code](rom_src/aqplus_rom/)
- [Emulator source code](emulator/)
Expand Down
2 changes: 1 addition & 1 deletion System/emulator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LFLAGS += `pkg-config --libs sdl2`
endif

FLAGS += -D_BSD_SOURCE -D_DEFAULT_SOURCE -pedantic
FLAGS += -Wall -Wextra -Wshadow -Winit-self -Wfloat-conversion -Wmissing-include-dirs
FLAGS += -Wall -Wextra -Wshadow -Winit-self -Wfloat-conversion -Wmissing-include-dirs -Wno-unused-parameter
CFLAGS += -Werror=implicit-function-declaration
BUILD_DIR ?= build

Expand Down
144 changes: 2 additions & 142 deletions System/emulator/Shared/AqKeyboard.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
#include "AqKeyboard.h"
#include "AqKeyboardDefs.h"

#ifdef EMULATOR
#include <SDL.h>
#include "EmuState.h"
#include "Config.h"
#else
#include "FPGA.h"
#include <esp_system.h>
#include "USBHost.h"
#include "MemDump.h"
#include <nvs_flash.h>
#endif

#ifndef EMULATOR
static const char *TAG = "keyboard";
#endif

#define FLAG_SHFT (1 << 7)
#define FLAG_CTRL (1 << 6)
Expand Down Expand Up @@ -227,11 +214,7 @@ void KeyboardLayout::processScancode(unsigned scanCode, bool keyDown) {
repeat = code;
}
if (code > 0) {
#ifdef EMULATOR
emuState.kbBufWrite(code);
#else
FPGA::instance().aqpWriteKeybBuffer(code);
#endif
}

} else {
Expand Down Expand Up @@ -330,13 +313,7 @@ void KeyboardLayout::processScancode(unsigned scanCode, bool keyDown) {

if (ch > 0) {
repeat = ch;

#ifdef EMULATOR
emuState.kbBufWrite(ch);
#else
FPGA::instance().aqpWriteKeybBuffer(ch);
#endif
// printf("'%c' (%02x)\n", (ch >= ' ' && ch <= '~') ? ch : '.', ch);
}
}
}
Expand Down Expand Up @@ -466,74 +443,13 @@ AqKeyboard &AqKeyboard::instance() {
}

void AqKeyboard::init() {
#ifndef EMULATOR
mutex = xSemaphoreCreateRecursiveMutex();

const esp_timer_create_args_t periodic_timer_args = {
.callback = &keyRepeatTimer,
.arg = (void *)this,
.name = "key_repeat",
.skip_unhandled_events = true,
};

ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, 16666));
#endif
}

#ifndef EMULATOR
void AqKeyboard::keyRepeatTimer(void *arg) {
static_cast<AqKeyboard *>(arg)->repeatTimer();
}
#endif

void AqKeyboard::handleScancode(unsigned scanCode, bool keyDown) {
// printf("%3d: %s\n", scanCode, keyDown ? "DOWN" : "UP");
#ifndef EMULATOR
RecursiveMutexLock lock(mutex);
#endif
kbLayout.repeat = 0;
kbLayout.pressCounter = 0;

#ifndef EMULATOR
// Special keys
{
uint8_t combinedModifiers = (kbLayout.modifiers & 0xF) | (kbLayout.modifiers >> 4);
if (combinedModifiers == KeyboardLayout::ModLGui && keyDown && scanCode == SCANCODE_F12) {
MemDump::dumpCartridge();
return;
} else if (keyDown && scanCode == SCANCODE_PRINTSCREEN) {
MemDump::dumpScreen();
return;
} else if (combinedModifiers == KeyboardLayout::ModLGui && keyDown && scanCode == SCANCODE_F10) {
FPGA::instance().aqpSetVideoTimingMode(0);

nvs_handle_t h;
if (nvs_open("settings", NVS_READWRITE, &h) == ESP_OK) {
if (nvs_set_u8(h, "videoTiming", 0) == ESP_OK) {
nvs_commit(h);
}
nvs_close(h);
}

return;

} else if (combinedModifiers == KeyboardLayout::ModLGui && keyDown && scanCode == SCANCODE_F11) {
FPGA::instance().aqpSetVideoTimingMode(1);

nvs_handle_t h;
if (nvs_open("settings", NVS_READWRITE, &h) == ESP_OK) {
if (nvs_set_u8(h, "videoTiming", 1) == ESP_OK) {
nvs_commit(h);
}
nvs_close(h);
}

return;
}
}
#endif

// Hand controller emulation
if (handController(scanCode, keyDown))
return;
Expand Down Expand Up @@ -649,48 +565,27 @@ void AqKeyboard::handleScancode(unsigned scanCode, bool keyDown) {
uint8_t combinedModifiers = (kbLayout.modifiers & 0xF) | (kbLayout.modifiers >> 4);
if (scanCode == SCANCODE_ESCAPE && keyDown) {
if (combinedModifiers == KeyboardLayout::ModLCtrl) {
#ifdef EMULATOR
emuState.reset();
#else
FPGA::instance().aqpReset();
#endif
} else if (combinedModifiers == (KeyboardLayout::ModLShift | KeyboardLayout::ModLCtrl)) {
#ifdef EMULATOR
emuState.reset();
#else
// CTRL-SHIFT-ESCAPE -> reset ESP32 (somewhat equivalent to power cycle)
FPGA::instance().aqpAqcuireBus();
FPGA::instance().aqpReset();
esp_restart();
#endif
}
}
}

if (ledStatus != kbLayout.leds) {
ledStatus = kbLayout.leds;
#ifndef EMULATOR
USBHost::instance().keyboardSetLeds(ledStatus);
#endif
}
}

void AqKeyboard::repeatTimer() {
#ifndef EMULATOR
RecursiveMutexLock lock(mutex);
#endif
if ((keyMode & 1) == 0 || (keyMode & 4) == 0 || kbLayout.repeat == 0) {
kbLayout.pressCounter = 0;
return;
}

kbLayout.pressCounter++;
if (kbLayout.pressCounter > 15 && kbLayout.pressCounter % 3 == 0) {
#ifdef EMULATOR
emuState.kbBufWrite(kbLayout.repeat);
#else
FPGA::instance().aqpWriteKeybBuffer(kbLayout.repeat);
#endif
}
}

Expand Down Expand Up @@ -758,33 +653,22 @@ bool AqKeyboard::handController(unsigned scanCode, bool keyDown) {
}

void AqKeyboard::updateMatrix() {
#ifndef EMULATOR
RecursiveMutexLock lock(mutex);
#endif
if (prevMatrix != keybMatrix) {
// printf("keybMatrix: %016llx\n", keybMatrix);

uint64_t tmpMatrix = ~keybMatrix;

#ifdef EMULATOR
memcpy(emuState.keybMatrix, &tmpMatrix, 8);
#else
FPGA::instance().aqpUpdateKeybMatrix(tmpMatrix);
#endif
prevMatrix = keybMatrix;
}

uint8_t handCtrl1_merged = handCtrl1 & handCtrl_gameCtrl;

if (prevHandCtrl1 != handCtrl1_merged || prevHandCtrl2 != handCtrl2) {
#ifdef EMULATOR
emuState.handCtrl1 = handCtrl1_merged;
emuState.handCtrl2 = handCtrl2;
#else
FPGA::instance().aqpUpdateHandCtrl(handCtrl1_merged, handCtrl2);
#endif
prevHandCtrl1 = handCtrl1_merged;
prevHandCtrl2 = handCtrl2;
prevHandCtrl1 = handCtrl1_merged;
prevHandCtrl2 = handCtrl2;
}
}

Expand All @@ -793,29 +677,5 @@ void AqKeyboard::pressKey(unsigned char ch) {
ch = '\r';
}

#ifdef EMULATOR
emuState.kbBufWrite(ch);
#else
if (ch == 0x1C) {
// Delay for 100ms
vTaskDelay(pdMS_TO_TICKS(100));
return;
}
if (ch == 0x1D) {
// Delay for 500ms
vTaskDelay(pdMS_TO_TICKS(500));
return;
}
if (ch == 0x1E) {
// Reset
FPGA::instance().aqpReset();
vTaskDelay(pdMS_TO_TICKS(500));
return;
}
if (ch > '~')
return;
FPGA::instance().aqpWriteKeybBuffer(ch);
vTaskDelay(pdMS_TO_TICKS(10));

#endif
}
6 changes: 0 additions & 6 deletions System/emulator/Shared/AqKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ class AqKeyboard {
uint8_t handCtrl_gameCtrl = 0xFF;

private:
#ifndef EMULATOR
SemaphoreHandle_t mutex;
static void keyRepeatTimer(void *arg);
esp_timer_handle_t periodic_timer;
#endif

KeyboardLayout kbLayout;

unsigned handCtrl1Pressed = 0;
Expand Down
1 change: 0 additions & 1 deletion System/emulator/Shared/AqKeyboardDefs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// This file is shared between the emulator and ESP32. It needs to be manually copied when changed.
#pragma once

// Aquarius keys
Expand Down
Loading

0 comments on commit 5ddaf32

Please sign in to comment.