diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 55fcca90..30f26ef7 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -3,7 +3,7 @@ on: push: paths-ignore: - 'README.md' - - 'demo/snake.zip' + - 'demo/snake.com' - 'demo/qr.png' workflow_dispatch: permissions: @@ -20,14 +20,13 @@ jobs: - uses: actions/checkout@v4 - run: | sudo apt-get install qrencode nasm python3 -y > /dev/null - nasm snake.asm -o snake.com + nasm snake.asm -o demo/snake.com gcc -Os -w -xc - <<< "main;" - xxd -p snake.com | python3 docs/update.py - qrencode -r snake.com -8 -o demo/qr.png - zip demo/snake.zip snake.com -q + xxd -p demo/snake.com | python3 docs/update.py + qrencode -r demo/snake.com -8 -o demo/qr.png git config --global user.email "$GITHUB_REPOSITORY_OWNER_ID+$GITHUB_REPOSITORY_OWNER@users.noreply.github.com" git config --global user.name "$GITHUB_REPOSITORY_OWNER" - git commit -am "${GITHUB_WORKFLOW,,}" -q + git commit -am "${GITHUB_WORKFLOW,,}" -q || true git push -q - uses: actions/upload-pages-artifact@v3 with: diff --git a/.gitignore b/.gitignore index 25b3e25a..cba7efc8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -snake.com a.out diff --git a/demo/main.js b/demo/main.js index d3f71b00..3794bf5a 100644 --- a/demo/main.js +++ b/demo/main.js @@ -1,14 +1,33 @@ const canvas = document.getElementById("jsdos"); +const xhr = new XMLHttpRequest(); +const zip = hex => { + const int2hex = x => [x, x >> 8, x >> 16, x >> 24].map(i => i & 0xff); + const length = int2hex(hex.length); + return new Uint8Array([0x50, 0x4b, 3, 4, ...Array(14).fill(0), + ...length, ...length, 8, 0, 0, 0, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x63, + 0x6f, 0x6d, ...hex, 0x50, 0x4b, 1, 2, ...Array(16).fill(0), + ...length, ...length, 8, ...Array(11).fill(0), 0x80, 0x81, 0, 0, 0, 0, + 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x50, 0x4b, + 5, 6, 0, 0, 0, 0, 1, 0, 1, 0, 0x36, 0, 0, 0, + ...int2hex(hex.length + 0x26), 0, 0]); +}; -Dos(canvas, { cycles: 2, onprogress: ()=>{} }).ready((fs, main) => - fs.extract("snake.zip").then(() => - main(["snake.com"]).then(ci => { - swipedetect(swipedir => swipedir && ci.simulateKeyPress(36 + swipedir)); - document.title = "Snake"; - span(canvas); - }) +xhr.open('GET', 'snake.com', true); +xhr.responseType = 'arraybuffer'; + +xhr.onload = _ => + Dos(canvas, { cycles: 2, onprogress: ()=>{} }).ready((fs, main) => + fs.extract(URL.createObjectURL(new Blob([zip(new Uint8Array(xhr.response))]))).then(() => + main(["main.com"]).then(ci => { + swipedetect(swipedir => swipedir && ci.simulateKeyPress(36 + swipedir)); + document.title = "Snake"; + span(canvas); + }) + ) ) -); +; + +xhr.send(); function span(element) { element.style.height = "auto"; diff --git a/demo/snake.com b/demo/snake.com new file mode 100644 index 00000000..188f068d Binary files /dev/null and b/demo/snake.com differ diff --git a/demo/snake.zip b/demo/snake.zip deleted file mode 100644 index 7adde3c3..00000000 Binary files a/demo/snake.zip and /dev/null differ diff --git a/main.sh b/main.sh index fb49f3b6..b5e0ba01 100755 --- a/main.sh +++ b/main.sh @@ -1,5 +1,4 @@ #!/bin/bash set -e -nasm -f bin snake.asm -o snake.com -zip demo/snake.zip snake.com +nasm -f bin snake.asm -o demo/snake.com python3 -m http.server -d demo