Skip to content

Commit b807dfb

Browse files
authored
Don't zip the file ahead (#64)
1 parent f777182 commit b807dfb

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

.github/workflows/update.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push:
44
paths-ignore:
55
- 'README.md'
6-
- 'demo/snake.zip'
6+
- 'demo/snake.com'
77
- 'demo/qr.png'
88
workflow_dispatch:
99
permissions:
@@ -20,14 +20,13 @@ jobs:
2020
- uses: actions/checkout@v4
2121
- run: |
2222
sudo apt-get install qrencode nasm python3 -y > /dev/null
23-
nasm snake.asm -o snake.com
23+
nasm snake.asm -o demo/snake.com
2424
gcc -Os -w -xc - <<< "main;"
25-
xxd -p snake.com | python3 docs/update.py
26-
qrencode -r snake.com -8 -o demo/qr.png
27-
zip demo/snake.zip snake.com -q
25+
xxd -p demo/snake.com | python3 docs/update.py
26+
qrencode -r demo/snake.com -8 -o demo/qr.png
2827
git config --global user.email "$GITHUB_REPOSITORY_OWNER_ID+$GITHUB_REPOSITORY_OWNER@users.noreply.github.com"
2928
git config --global user.name "$GITHUB_REPOSITORY_OWNER"
30-
git commit -am "${GITHUB_WORKFLOW,,}" -q
29+
git commit -am "${GITHUB_WORKFLOW,,}" -q || true
3130
git push -q
3231
- uses: actions/upload-pages-artifact@v3
3332
with:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
snake.com
21
a.out

demo/main.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
const canvas = document.getElementById("jsdos");
2+
const xhr = new XMLHttpRequest();
3+
const zip = hex => {
4+
const int2hex = x => [x, x >> 8, x >> 16, x >> 24].map(i => i & 0xff);
5+
const length = int2hex(hex.length);
6+
return new Uint8Array([0x50, 0x4b, 3, 4, ...Array(14).fill(0),
7+
...length, ...length, 8, 0, 0, 0, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x63,
8+
0x6f, 0x6d, ...hex, 0x50, 0x4b, 1, 2, ...Array(16).fill(0),
9+
...length, ...length, 8, ...Array(11).fill(0), 0x80, 0x81, 0, 0, 0, 0,
10+
0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x50, 0x4b,
11+
5, 6, 0, 0, 0, 0, 1, 0, 1, 0, 0x36, 0, 0, 0,
12+
...int2hex(hex.length + 0x26), 0, 0]);
13+
};
214

3-
Dos(canvas, { cycles: 2, onprogress: ()=>{} }).ready((fs, main) =>
4-
fs.extract("snake.zip").then(() =>
5-
main(["snake.com"]).then(ci => {
6-
swipedetect(swipedir => swipedir && ci.simulateKeyPress(36 + swipedir));
7-
document.title = "Snake";
8-
span(canvas);
9-
})
15+
xhr.open('GET', 'snake.com', true);
16+
xhr.responseType = 'arraybuffer';
17+
18+
xhr.onload = _ =>
19+
Dos(canvas, { cycles: 2, onprogress: ()=>{} }).ready((fs, main) =>
20+
fs.extract(URL.createObjectURL(new Blob([zip(new Uint8Array(xhr.response))]))).then(() =>
21+
main(["main.com"]).then(ci => {
22+
swipedetect(swipedir => swipedir && ci.simulateKeyPress(36 + swipedir));
23+
document.title = "Snake";
24+
span(canvas);
25+
})
26+
)
1027
)
11-
);
28+
;
29+
30+
xhr.send();
1231

1332
function span(element) {
1433
element.style.height = "auto";

demo/snake.com

58 Bytes
Binary file not shown.

demo/snake.zip

-226 Bytes
Binary file not shown.

main.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
22
set -e
3-
nasm -f bin snake.asm -o snake.com
4-
zip demo/snake.zip snake.com
3+
nasm -f bin snake.asm -o demo/snake.com
54
python3 -m http.server -d demo

0 commit comments

Comments
 (0)