From 99370530f5f68971384862c7aa1d7393f27b6e88 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 5 Nov 2023 18:10:35 -0600 Subject: [PATCH] vcs: new skeleton for cc65 --- presets/vcs/skeleton.cc65 | 110 +++++++++++++++++++--------------- scripts/docker/Dockerfile | 19 ++++-- scripts/docker/run.sh | 20 +++++++ src/worker/server/buildenv.ts | 2 +- src/worker/server/server.ts | 2 +- 5 files changed, 96 insertions(+), 57 deletions(-) create mode 100644 scripts/docker/run.sh diff --git a/presets/vcs/skeleton.cc65 b/presets/vcs/skeleton.cc65 index 4785ad90..d347f9e4 100644 --- a/presets/vcs/skeleton.cc65 +++ b/presets/vcs/skeleton.cc65 @@ -1,56 +1,68 @@ -/*****************************************************************************/ -/* */ -/* Atari VCS 2600 sample C program */ -/* */ -/* Florent Flament (contact@florentflament.com), 2017 */ -/* */ -/*****************************************************************************/ -#include +/* +See the "VCSLib Demo" example for more features. +*/ -// PAL Timings -// Roughly computed based on Stella Programmer's guide (Steve Wright) -// scanlines count per section. -#define VBLANK_TIM64 51 // 45 lines * 76 cycles/line / 64 cycles/tick -#define KERNAL_T1024 17 // 228 lines * 76 cycles/line / 1024 cycles/tick -#define OVERSCAN_TIM64 42 // 36 lines * 76 cycles/line / 64 cycles/tick +//#resource "vcslib/vcs-ca65.inc" +//#resource "vcslib/kernel.inc" -// Testing memory zones -const unsigned char rodata_v[] = "Hello!"; -unsigned char data_v = 0x77; -unsigned char bss_v; +//#link "vcslib/vcslib.ca65" +//#link "vcslib/frameloop.c" +//#link "vcslib/mapper_3e.ca65" -void main(void) { - unsigned char color = 0x79; // Stack variable - bss_v = 0x88; // Testing BSS variable +#include +#include "vcslib/bcd.h" +#include "vcslib/vcslib.h" - for/*ever*/(;;) { - // Vertical Sync signal - TIA.vsync = 0x02; - TIA.wsync = 0x00; - TIA.wsync = 0x00; - TIA.wsync = 0x00; - TIA.vsync = 0x00; +#pragma wrapped-call (push, bankselect, bank) +#pragma code-name (push, "ROM0") - // Vertical Blank timer setting - RIOT.tim64t = VBLANK_TIM64; - - // Doing frame computation during blank - TIA.colubk = color++; // Update color - - // Wait for end of Vertical Blank - while (RIOT.timint == 0) {} - TIA.wsync = 0x00; - TIA.vblank = 0x00; // Turn on beam - - // Display frame - RIOT.t1024t = KERNAL_T1024; - while (RIOT.timint == 0) {} - TIA.wsync = 0x00; - TIA.vblank = 0x02; // Turn off beam - - // Overscan - RIOT.tim64t = OVERSCAN_TIM64; - while (RIOT.timint == 0) {} - } +void init(void) { + // init code here } + +void my_preframe(void) { + // stuff that happens before the frame is drawn + TIA.colubk = 0x00; +} + +void my_kernel(void) { + byte i; + for (i=0; i<190; i++) { + do_wsync(); + TIA.colubk = i; + } +} + +void my_postframe(void) { + // stuff that happens after the frame is drawn +} + +void kernel_loop() { + while (1) { + kernel_1(); + my_preframe(); + kernel_2(); + my_kernel(); + kernel_3(); + my_postframe(); + kernel_4(); + } +} + +#pragma code-name (pop) +#pragma wrapped-call (pop) + +/* +The main() function is called at startup. +It resides in the shared ROM area (PERM). +*/ +void main(void) { + + // initialization + init(); + + // main kernel loop + kernel_loop(); +} + diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 308c5098..90b0492a 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -4,8 +4,8 @@ FROM --platform=linux/amd64 debian:11-slim # Set the working directory WORKDIR /app -# Set the 8BITWS_SERVER_ROOT environment variable -ENV 8BITWS_SERVER_ROOT /app +# Set the _8BITWS_SERVER_ROOT environment variable +ENV _8BITWS_SERVER_ROOT /app # Change to app dir RUN cd /app @@ -27,17 +27,24 @@ RUN apt-get install -y nodejs # Fetch the LLVM-Mos tarball and extract it RUN curl -L https://github.com/llvm-mos/llvm-mos-sdk/releases/latest/download/llvm-mos-linux.tar.xz | xz -d | tar x -C /app +# Fetch the SDCC tarball +#RUN apt-get install -y bzip2 +#RUN curl -L https://cytranet.dl.sourceforge.net/project/sdcc/sdcc-linux-amd64/4.3.0/sdcc-4.3.0-amd64-unknown-linux2.5.tar.bz2 | tar xj -C /app + # Clean up after APT RUN apt-get autoremove -y \ && apt-get clean -y \ && apt-get autoclean -y RUN rm -rf /var/lib/apt/lists/* -# Fetch the Node.js Express server.js file from a GitHub URL -RUN curl -O https://sehugg.github.io/8bitworkshop/gen/server/server.js - # Expose the port your server will listen on EXPOSE 3009 +# Fetch the Node.js Express server.js file at runtime +RUN curl -O https://sehugg.github.io/8bitworkshop/gen/server/server.js + +# Copy the run script +COPY run.sh /app/run.sh + # Start the Node.js Express server -CMD ["node", "server.js"] +CMD ["sh", "-a", "run.sh"] diff --git a/scripts/docker/run.sh b/scripts/docker/run.sh new file mode 100644 index 00000000..72f99554 --- /dev/null +++ b/scripts/docker/run.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +export _8BITWS_SERVER_ROOT=/app + +cd "$_8BITWS_SERVER_ROOT" + +while true; do + curl -O https://sehugg.github.io/8bitworkshop/gen/server/server.js + + node server.js + + # Check if the server crashed (exited with a non-zero status) + if [ $? -ne 0 ]; then + echo "Server crashed. Restarting in 10 seconds..." + sleep 10 + else + # If the server exited normally (e.g., due to manual termination), exit the loop + break + fi +done diff --git a/src/worker/server/buildenv.ts b/src/worker/server/buildenv.ts index 7b78719b..aa798271 100644 --- a/src/worker/server/buildenv.ts +++ b/src/worker/server/buildenv.ts @@ -56,7 +56,7 @@ export function findBestTool(step: BuildStep) { } export const TOOLS: ServerBuildTool[] = [ - Object.assign({}, LLVM_MOS_TOOL, { version: '0.13.2' }), + Object.assign({}, LLVM_MOS_TOOL, { version: 'latest' }), ]; interface ServerBuildTool { diff --git a/src/worker/server/server.ts b/src/worker/server/server.ts index ecccc373..7c72dcb7 100644 --- a/src/worker/server/server.ts +++ b/src/worker/server/server.ts @@ -70,7 +70,7 @@ const port = 3009; origin: [`http://localhost:${port}`, 'http://localhost:8000'] }));*/ -const SERVER_ROOT = process.env['8BITWS_SERVER_ROOT'] || path.resolve('./server-root'); +const SERVER_ROOT = process.env['_8BITWS_SERVER_ROOT'] || path.resolve('./server-root'); const SESSION_ROOT = path.join(SERVER_ROOT, 'sessions'); if (!fs.existsSync(SESSION_ROOT)) { fs.mkdirSync(SESSION_ROOT);