Skip to content

Commit

Permalink
Don't zip the file ahead (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
donno2048 committed Apr 19, 2024
1 parent f777182 commit b807dfb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
paths-ignore:
- 'README.md'
- 'demo/snake.zip'
- 'demo/snake.com'
- 'demo/qr.png'
workflow_dispatch:
permissions:
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
snake.com
a.out
35 changes: 27 additions & 8 deletions demo/main.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Binary file added demo/snake.com
Binary file not shown.
Binary file removed demo/snake.zip
Binary file not shown.
3 changes: 1 addition & 2 deletions main.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b807dfb

Please sign in to comment.