initial commit

This commit is contained in:
~d6 2024-07-12 22:26:33 -04:00
commit f2998aef21
5 changed files with 1220 additions and 0 deletions

20
.gitignore vendored Normal file
View File

@ -0,0 +1,20 @@
# use glob syntax.
syntax: glob
*.pyc
*.pyo
*~
TAGS
*.rom
img
etc
test-roms
junk
img
.theme
.snarf
*.sym
wave
*.mp3
*.wav
*.mp4
scratch

256
card-sprites.tal Normal file
View File

@ -0,0 +1,256 @@
ff ff e7 fb e7 fb e7 ff ff 80 98 84 98 84 98 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff ff ff ff ff ff ff 80 80 80 80 80 80 80 80
ff ff ff ff ff ff ff ff 01 01 01 01 01 01 01 01
ff fb f1 e0 e0 e4 ff ff 80 84 8e 9f 9f 9b 80 ff
ff e7 df e7 df e7 ff ff 01 19 21 19 21 19 01 ff
ff ff f3 eb e3 eb eb ff ff 80 8c 94 9c 94 94 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff ff ff ff ff ff ff 80 80 80 80 80 80 80 80
ff ff ff ff ff ff ff ff 01 01 01 01 01 01 01 01
ff fb f1 e0 f1 fb ff ff 80 84 8e 9f 8e 84 80 ff
ff d7 d7 c7 d7 c7 ff ff 01 29 29 39 29 39 01 ff
f8 f8 fb fb fb f9 f8 fc 85 87 83 83 83 81 80 80
0f 0f ff ff 9f 6f ef 0f 51 f1 61 f1 91 61 e1 01
f8 f8 fb fb fb f9 f8 fc 82 80 87 87 87 87 87 83
0f 0f ff ff 9f 6f ef 0f a1 01 61 f1 f1 f1 f1 f1
00 7f 6f 54 6f 7e 6d 6d 00 7f 7f 7f 7f 7f 7f 7f
00 fe f6 2a f6 7e b6 b6 00 fe fe fe fe fe fe fe
6e 6f 6e 6d 6d 6e 6f 6e 7f 7f 7f 7f 7f 7f 7f 7f
76 f6 76 b6 b6 76 f6 76 fe fe fe fe fe fe fe fe
6d 6d 7e 6f 54 6f 7f 00 7f 7f 7f 7f 7f 7f 7f 00
b6 b6 7e f6 2a f6 fe 00 fe fe fe fe fe fe fe 00
ff ff eb eb e7 eb eb ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
f8 f8 fb fb fb f9 f8 fc 85 87 83 83 83 81 80 80
0f 0f ff ff 9f 6f ef 0f 51 f1 61 f1 91 61 e1 01
ff f1 fb e0 f1 fb ff ff 80 80 80 80 80 80 80 ff
ff d7 d7 e7 d7 d7 ff ff 01 01 01 01 01 01 01 ff
f8 f0 f0 f2 f3 d9 c1 e1 80 80 80 82 83 83 81 81
1f 0f ef ef ef ef ff ff 01 01 e1 41 e1 f1 e1 81
f8 f0 f0 f2 f3 d9 c1 e1 87 8f 8f 8f 8f a5 bf 9f
1f 0f ef ef ef ef ff ff e1 f1 f1 51 f1 e1 e1 81
00 00 00 00 00 00 00 00 ff ea ff bf ff bb ff bf
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e3 eb eb e7 f3 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
f8 f0 f0 f2 f3 d9 c1 e1 80 80 80 82 83 83 81 81
1f 0f ef ef ef ef ff ff 01 01 e1 41 e1 f1 e1 81
ff ec f4 fb e4 e4 ff ff 80 80 80 80 80 80 80 ff
ff cf e7 d7 d7 c7 ff ff 01 01 01 01 01 01 01 ff
fe fc f8 f8 f9 f8 f9 ff 81 83 80 80 81 80 81 83
3f 1f 1f ff ff ff ff ff c1 e1 01 e1 41 e1 e1 c1
fe fc f8 f8 f9 f8 f9 ff 80 80 87 87 87 87 87 83
3f 1f 1f ff ff ff ff ff 01 01 e1 e1 41 e1 e1 c1
ff ff f3 eb e3 eb eb ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff f3 eb e3 eb eb ff ff 80 8c 94 9c 94 94 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff f3 eb e3 eb eb ff ff 80 8c 94 9c 94 94 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff f3 eb e3 eb eb ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
80 c0 e0 f0 f8 e0 10 00 80 c0 e0 f0 f8 e0 10 00
00 00 00 00 00 00 00 00 df ca c7 83 c1 83 fb bf
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e7 fb f7 ef e3 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e7 fb f7 ef e3 ff ff 80 98 84 88 90 9c 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e7 fb f7 ef e3 ff ff 80 98 84 88 90 9c 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e7 fb f7 ef e3 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 ff ea ff bf ff bb ff bf
00 00 00 00 00 00 00 00 ef e2 e3 a1 e0 a1 fd bf
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e7 fb e7 fb e7 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e7 fb e7 fb e7 ff ff 80 98 84 98 84 98 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e7 fb e7 fb e7 ff ff 80 98 84 98 84 98 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e7 fb e7 fb e7 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff eb eb e3 fb fb ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff eb eb e3 fb fb ff ff 80 94 94 9c 84 84 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff eb eb e3 fb fb ff ff 80 94 94 9c 84 84 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff eb eb e3 fb fb ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e3 ef e3 fb e7 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e3 ef e3 fb e7 ff ff 80 9c 90 9c 84 98 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e3 ef e3 fb e7 ff ff 80 9c 90 9c 84 98 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e3 ef e3 fb e7 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
f8 f8 fb fb fb f9 f8 fc 85 87 83 83 83 81 80 80
0f 0f ff ff 9f 6f ef 0f 51 f1 61 f1 91 61 e1 01
f8 f8 fb fb fb f9 f8 fc 82 80 87 87 87 87 87 83
0f 0f ff ff 9f 6f ef 0f a1 01 61 f1 f1 f1 f1 f1
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff f3 ef e3 eb e3 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff f3 ef e3 eb e3 ff ff 80 8c 90 9c 94 9c 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff f3 ef e3 eb e3 ff ff 80 8c 90 9c 94 9c 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff f3 ef e3 eb e3 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
f8 f0 f0 f2 f3 d9 c1 e1 80 80 80 82 83 83 81 81
1f 0f ef ef ef ef ff ff 01 01 e1 41 e1 f1 e1 81
f8 f0 f0 f2 f3 d9 c1 e1 87 8f 8f 8f 8f a5 bf 9f
1f 0f ef ef ef ef ff ff e1 f1 f1 51 f1 e1 e1 81
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e3 fb f7 f7 f7 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e3 fb f7 f7 f7 ff ff 80 9c 84 88 88 88 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e3 fb f7 f7 f7 ff ff 80 9c 84 88 88 88 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e3 fb f7 f7 f7 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
fe fc f8 f8 f9 f8 f9 ff 81 83 80 80 81 80 81 83
3f 1f 1f ff ff ff ff ff c1 e1 01 e1 41 e1 e1 c1
fe fc f8 f8 f9 f8 f9 ff 80 80 87 87 87 87 87 83
3f 1f 1f ff ff ff ff ff 01 01 e1 e1 41 e1 e1 c1
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e3 eb e3 eb e3 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e3 eb e3 eb e3 ff ff 80 9c 94 9c 94 9c 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e3 eb e3 eb e3 ff ff 80 9c 94 9c 94 9c 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e3 eb e3 eb e3 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e3 eb e3 fb e7 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e3 eb e3 fb e7 ff ff 80 9c 94 9c 84 98 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e3 eb e3 fb e7 ff ff 80 9c 94 9c 84 98 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e3 eb e3 fb e7 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff d1 d5 d5 d5 d1 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff d1 d5 d5 d5 d1 ff ff 80 ae aa aa aa ae 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff d1 d5 d5 d5 d1 ff ff 80 ae aa aa aa ae 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff d1 d5 d5 d5 d1 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff f3 fb fb fb e7 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff f3 fb fb fb e7 ff ff 80 8c 84 84 84 98 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff f3 fb fb fb e7 ff ff 80 8c 84 84 84 98 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff f3 fb fb fb e7 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff e3 eb eb e7 f3 ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff e3 eb eb e7 f3 ff ff 80 9c 94 94 98 8c 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff e3 eb eb e7 f3 ff ff 80 9c 94 94 98 8c 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff e3 eb eb e7 f3 ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ff ff eb eb e7 eb eb ff ff 80 80 80 80 80 80 80
ff ff df 8f 07 df 8f ff ff 01 01 01 01 01 01 01
ff ff eb eb e7 eb eb ff ff 80 94 94 98 94 94 80
ff ff 27 07 07 8f df ff ff 01 d9 f9 f9 71 21 01
ff ff eb eb e7 eb eb ff ff 80 94 94 98 94 94 80
ff ff df 8f 07 8f df ff ff 01 21 71 f9 71 21 01
ff ff eb eb e7 eb eb ff ff 80 80 80 80 80 80 80
ff ff 27 27 df 2f 37 ff ff 01 01 01 01 01 01 01
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

418
cards.tal Normal file
View File

@ -0,0 +1,418 @@
( cards.tal )
( CARD LAYOUT )
( )
( cards are stored as 16-bit values. )
( the high byte holds the flags. )
( the low byte holds the card id. )
( )
( FLAGS )
( bit 1: flipping, #80 face down, #00 face up )
( bits 2-6: unused )
( bits 7-8: rotation, #00 north, #01 east, #02 south, #03 west )
( )
( IDENTIFIER )
( 00: ace of spades )
( 01: two of spades )
( ... )
( 0c: king of spades )
( 0d: ace of hearts )
( 0e: two of hearts )
( ... )
( 19: king of hearts )
( 1a: ace of diamonds )
( 1b: two of diamonds )
( ... )
( 26: king of diamonds )
( 27: ace of clubs )
( 28: two of clubs )
( 33: king of clubs )
( BUG: stack is growing, maybe redraw-all ? )
( TODO: move piles )
( TODO: shuffle deck only )
( TODO: try out rounded corners )
( - face down can use white as transparent )
( - face up black cards use red as transparent )
( - face up red cards use black as transparent )
( TODO: optional snap-to-grid setting? )
( ROTATION )
( N 00 to E 01: dx=+0 dy=+8 )
( 01 to 02: dx=+0 dy=+0 )
( 02 to 03: dx=-8 dy=+0 )
( 03 to 00: dx=+8 dy=-8 )
( will require unhardcoding bounding boxes )
( BUG: try moving the "whole deck" and get into a weird state )
@move-card ( card* dx^ dy^ -> )
SWP SWP2 STH2 INC2r INC2r ( dy^ dx^ [card+2*] )
STH2kr LDA ADD STH2kr STA INC2r ( dy^ [card+3*] ; card.x+=dx )
STH2kr LDA ADD STH2r STA JMP2r ( ; card.y+=dy )
( put all cards face down, and stack them )
( in a single deck in the middle of the screen )
@reset ( -> )
all-cards-face-down
shuffle ( FIXME )
#08 #18 stack-cards
draw-background
!draw-cards
( f: addr* -> )
@for-all-cards ( f* -> )
STH2 ;cards/end ;cards ( limit* start* [f*] )
&loop DUP2 STH2kr JSR2 ( limit* pos* [f*] )
#0004 ADD2 GTH2k ?&loop ( limit* pos+4* [f*] )
POP2 POP2 POP2r JMP2r ( )
@all-cards-face-down ( -> )
;turn-card-face-down !for-all-cards
@stack-cards ( x^ y^ -> )
,stack-card/y STR ,stack-card/x STR #00 ,stack-card/c STR
;stack-card !for-all-cards
@stack-card ( addr* -> )
INC2 INC2 STH2 ( [addr+2*] )
LIT [ &x $1 ] STH2kr STA INC2r ( [addr+3] ; addr+2<-x )
LIT [ &y $1 ] STH2r STA ( ; addr+3<-y )
LIT [ &c $1 ] ?&skip
,&y LDR #01 SUB ,&y STR
&skip ,&c LDR INC #03 AND ,&c STR JMP2r
@flip-all-cards ( -> )
;cards/end ;cards ( limit* start* )
&loop DUP2 flip-card ( limit* pos* )
#0004 ADD2 GTH2k ?&loop ( limit* pos+4* )
POP2 POP2 !draw-cards ( )
@shuffle ( -> )
;cards/last ;cards ( last* start* )
&loop ( last* pos* )
SUB2k #02 SFT2 INC2 ( last* pos* n=[last-pos]/4+1* )
random SWP2 ( last* pos* r* n* )
DIV2k MUL2 SUB2 ( last* pos* i=r%n* )
#20 SFT2 OVR2 ADD2 ( last* pos* alt=pos+4i* )
LDA2k ,&c STR2 ( last* pos* alt* ; c<-alt )
STH2 LDA2k STH2r STA2 STH2 ( last* [pos*] ; alt<-pos )
LIT2 [ &c $2 ] STH2kr STA2 ( last* [pos*] )
STH2r #0004 ADD2 ( last* pos+4* )
GTH2k ?&loop ( last* pos+4* )
POP2 POP2 JMP2r ( )
@try-to-flip ( -> )
find-mouse-over-card
ORAk ?&found POP2 JMP2r
&found flip-card !draw-cards
@flip-card ( addr* -> )
LDA2k #8000 EOR2 SWP2 STA2 JMP2r
@turn-card-face-down ( addr* -> )
LDA2k #8000 ORA2 SWP2 STA2 JMP2r
@turn-card-face-up ( addr* -> )
LDA2k #7fff AND2 SWP2 STA2 JMP2r
@randomize ( -> )
init-cards
draw-background
!draw-cards
@mod ( n* d* -> n%d* )
DIV2k MUL2 SUB2 JMP2r
@init-cards ( -> )
#0034 #0000 ( limit* 0* )
&loop ( limit* c* )
;cards OVR2 ( limit* c* cards* c* )
#0004 MUL2 ADD2 ( limit* c* addr=cards+4c* )
INC2 STAk ( limit* c* addr+1* ; addr+1<-c )
INC2 STH2 ( limit* c* [addr+2*] )
random #00f0 mod NIP ( limit* c* x^ [addr+2*] )
STH2kr STA INC2r ( limit* c* [addr+3*] ; addr+2<-x )
random #00a8 mod NIP ( limit* c* y^ [addr+3*] )
STH2r STA ( limit* c* ; addr+3<-y )
INC2 GTH2k ?&loop ( limit* c+1* )
POP2 POP2 JMP2r
@raise-card ( addr* -> )
DUP2 ;cards/last EQU2 ?&skip ( addr* )
LDA2k ,&card STR2 INC2 INC2 ( addr+2* )
LDA2k ,&xy STR2 #0002 SUB2 ( addr-2* )
;cards/end SWP2 ( end* pos* )
&loop ( end* pos* )
STH2k #0004 ADD2 LDA2 ( end* n* [pos*] )
STH2kr STA2 ( end* [pos*] ; pos<-n )
STH2r INC2 INC2 ( end pos+2* )
GTH2k ?&loop ( end* pos+2* )
POP2 POP2 LIT2r =cards/last ( [last*] )
LIT2 [ &card $2 ] ( c* [last*] )
STH2kr STA2 INC2r INC2r ( [last+2*] ; last<-c )
LIT2 [ &xy $2 ] ( xy* [last+2*] )
STH2r STA2 JMP2r ( ; last+2<-xy )
&skip POP2 JMP2r ( )
( raises card at addr and everything it lifts )
@raise-cards ( addr* -> count^ )
#0004 ,&d STR2 ( ; d<-4 )
;raise-cards/buf ;raise-cards/pos STA2 ( addr* ; pos<-buf[0] )
DUP2 raise-cards/enqueue STH2 ( addr* [pos*] ; buf[0]<-addr )
;cards/end SWP2 #0004 ADD2 ( limit* addr+4* [pos*] )
&loop ( limit* addr* [pos*] )
STH2kr OVR2 card-lifts ?&lift ( limit* addr* [pos*] )
STH2k LIT2r [ &d $2 ] SUB2r ( limit* addr* [pos* addr-d*] )
LDA2k STH2kr STA2 ( limit* addr* [pos* addr-d*] ; copy 1-2 )
INC2 INC2 INC2r INC2r ( limit* addr+2* [pos* addr-d+2*] )
LDA2k STH2r STA2 INC2 INC2 ( limit* addr+4* [pos*] ; copy 3-4 )
GTH2k ?&loop !&done ( limit* addr+4* [pos*] )
&lift ( limit* addr* [pos*] )
,&d LDR2 #0004 ADD2 ,&d STR2 ( limit* addr* [pos*] ; d<-d+4 )
DUP2 ( limit* addr* addr* )
raise-cards/enqueue POP2 ( limit* addr* [pos*] )
#0004 ADD2 GTH2k ?&loop ( limit* addr+4* [pos*] )
&done ( limit* limit* [pos*] )
POP2 POP2r ( limit* )
,&d LDR2 SUB2 STH2 ( [dst=limit-d*] )
,&pos LDR2 ;raise-cards/buf ( end* buf* [dst*] )
SUB2k #02 SFT2 STH2 SWP2r ( end* buf* [count* dst*] )
&copy ( end* pos* [count* dst*] )
LDA2k STH2kr STA2 ( end* pos* [count* dst*] ; pos<-dst )
INC2 INC2 INC2r INC2r ( end* pos+2* [count* dst+2*] )
GTH2k ?&copy ( end* pos+2* [count* dst+2*] )
POP2 POP2 POP2r ( [count*] )
NIPr STHr JMP2r ( count^ )
&enqueue ( c* -> pos* )
,&pos LDR2 STH2 LDA2k STH2kr STA2 ( c* [pos*] ; buf[pos]<-c )
INC2 INC2 INC2kr INC2r ( c+2* [pos* pos+2*] )
LDA2 STH2kr STA2 INC2r INC2r ( [pos* pos+4*] ; buf[pos+2]<-c+2 )
STH2r ,&pos STR2 STH2r JMP2r ( pos* ; pos<-pos+4 )
[ &pos $2 &buf $cc ]
@abs-within ( x^ y^ d^ -> abs[x-y] <= d^ )
STH SUB STHkr ADD ( x-y+d^ [d^] )
STHr DUP ADD INC LTH JMP2r ( x-y+d<2d+1^ )
@card-overlaps ( a* b* -> ok^ )
INC2 INC2 LDA2 STH2 ( a* [bx^ by^] )
INC2 INC2 LDA2 ( ax^ ay^ [bx^ by^] )
STHr #17 abs-within SWP ( ay-by<16^ ax^ [bx^] )
STHr #0f abs-within AND ( ay-by<16&ax-bx<24^ )
JMP2r
( returns true if the card below lifts the card above )
@card-lifts ( below* above* -> bool^ )
GTH2k ?&no !card-overlaps &no POP2 POP2 #00 JMP2r
@find-mouse-over-card ( -> addr* )
.Mouse/x DEI2 .Mouse/y DEI2 !find-card
( returns top card at coords, or 0000 if no card. )
@find-card ( x* y* -> addr* )
LIT2r =cards LIT2r =cards/last ( x* y* [limit* first*] )
&loop ( x* y* [limit* pos*] )
OVR2 OVR2 STH2kr ( x* y* x* y* pos* [limit* pos*] )
intersects ?&done ( x* y* [limit* pos*] )
LIT2r 0004 SUB2r ( x* y* [limit* pos-4*] )
GTH2kr STHr ?&notfound ( x* y* [limit* pos-4*] )
!&loop ( x* y* [limit* pos-4*] )
&notfound POP2r LIT2r 0000 ( x* y* [limit* 0*] )
&done ( x* y* [limit* addr*] )
POP2 POP2 STH2r POP2r JMP2r ( addr* )
( returns true if the given card x,y coordinates )
( intersect the rectangle of the given card. )
( cards are 16 pixels wide and 24 pixels tall. )
( so the result is: )
( cx <= x < cx+16 && cy <= y < cy+24 )
@intersects ( x* y* card* -> bool^ )
ROT2 STH2 LITr 00 ( y* card* [x* 0^] )
#0002 ADD2 LDAk STH SUB2r ( y* card+2* [x-cx*] )
LIT2r 0010 LTH2r STHr ?&x-ok ( y* card+2* )
POP2 POP2 #00 JMP2r ( 0^ )
&x-ok ( y* card+2* )
LITr 00 INC2 LDA STH STH2r ( y* cy* )
SUB2 #0018 LTH2 JMP2r ( ok^ )
@draw-cards
;draw-card !draw-all-cards
@held-end-offset ( -> offset* )
;cards/end #00 .card-is-held LDZ #0004 MUL2 SUB2 JMP2r
( TODO: if the top card is being "held" then we )
( should not draw that here, because it will be )
( drawn in the foreground using a mask. )
@draw-all-cards ( draw* -> )
,&draw STR2 ( )
held-end-offset STH2 ( [limit*] )
LIT2r =cards ( [limit* pos*] )
&loop ( [limit* pos*] )
STH2kr LDA2 INC2r INC2r ( card* [limit* pos+2*] )
#00 STH2kr LDA INC2r ( card* x* [limit* pos+3*] )
#00 STH2kr LDA INC2r ( card* x* y* [limit* pos+4*] )
LIT2 [ &draw $2 ] JSR2 ( [limit* pos+4] )
GTH2kr STHr ?&loop ( [limit* pos+4] )
POP2r POP2r ( )
LIT2r =cards/end ( [limit*] )
held-end-offset STH2 ( [limit* offset*] )
&mloop ( [limit* pos*] )
STH2kr LDA2 INC2r INC2r ( card* [limit* pos+2*] )
#00 STH2kr LDA INC2r ( card* x* [limit* pos+3*] )
#00 STH2kr LDA INC2r ( card* x* y* [limit* pos+4*] )
draw-mask ( [limit* pos+4] )
GTH2kr STHr ?&mloop ( [limit* pos+4] )
POP2r POP2r JMP2r ( )
@draw-background ( -> )
#f2 .Screen/auto DEO
;tiles #0200 ADD2 .Screen/addr DEO2
#0080 .Screen/x DEO2
draw-background/twice
#0000 .Screen/x DEO2
&twice
#0000 .Screen/y DEO2
#81 .Screen/sprite
DEOk DEOk DEOk DEOk DEOk DEOk DEOk DEOk
DEOk DEOk DEOk DEOk DEOk DEOk DEOk DEOk
DEOk DEOk DEOk DEOk DEOk DEOk DEOk DEO JMP2r
@draw-mask ( idx* x* y* -> )
.Screen/y DEO2 .Screen/x DEO2
OVR #80 LTH ?draw-mask-up POP2 !draw-mask-down
@draw-card ( idx* x* y* -> )
.Screen/y DEO2 .Screen/x DEO2
OVR #80 LTH ?draw-face-up POP2 !draw-face-down
( assumes x/y already set )
@draw-mask-down ( -> )
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
;masks #0080 ADD2 .Screen/addr DEO2
#04 .Screen/sprite DEOk DEOk DEO
JMP2r
( assumes x/y already set )
@draw-face-down ( -> )
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
;tiles #0100 ADD2 .Screen/addr DEO2
#81 .Screen/sprite DEOk DEOk DEO
JMP2r
@card-is-black ( idx* -> bool^ )
#000c DIV2
@q-is-black ( q* -> bool^ )
NIP #01 SUB #fe AND JMP2r ( [q-1]&fe )
@card-is-red ( idx* -> bool^ )
#000c DIV2
@q-is-red ( q* -> bool^ )
NIP #03 MUL #02 AND JMP2r ( [q*3]&2 )
@find-middle-addr ( idx* -> addr* )
#000d DIV2k STH2k MUL2 SUB2 ( r* [q*] )
DUP2 #000a LTH2 ?&normal
DUP2 #000a NEQ2 ?&not-j POP2 #0200 !&face
&not-j #000b NEQ2 ?&not-q #0100 !&face
&not-q #0000
&face ;tiles ADD2 #00c0 ADD2
STH2r card-is-red ?&is-red JMP2r
&is-red #0020 ADD2 JMP2r
&normal POP2 POP2r ;tiles #0020 ADD2 JMP2r
( assumes x/y already set )
@draw-mask-up ( idx* -> )
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
#00ff AND2 ( idx* ; remove rotation/flip info for now )
DUP2 ( idx* idx* )
#000d DIV2k STH2k MUL2 SUB2 ( idx* r* [q*] )
#0080 MUL2 ;masks #0180 ADD2 ( idx* 128r* card+384* [q*] )
ADD2 STH2r #0010 MUL2 ADD2 ( idx* a=card+384+128r+16q* )
STH2k .Screen/addr DEO2 ( idx* [a*] )
#04 .Screen/sprite DEO ( idx* [a*] ; draw top of card )
find-middle-addr ( mid* [a*] )
;tiles SUB2 #01 SFT2 ;masks ADD2
.Screen/addr DEO2 ( [a*] )
#04 .Screen/sprite DEO ( [a*] ; draw middle of card )
STH2r DUP2 #0008 ADD2 ( a* a+8* )
( TODO: does flipping also flip move direction now? )
SWP2 #0008 .Screen/x DEI2 ADD2 .Screen/x DEO2
.Screen/addr DEO2 ( )
#01 .Screen/auto DEO ( ; draw 1 tile, increment x )
#34 .Screen/sprite DEO ( ; draw bottom left of card )
.Screen/addr DEO2 ( )
#34 .Screen/sprite DEO ( ; draw bottom right of card )
JMP2r
( assumes x/y already set )
@draw-face-up ( idx* -> )
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
#00ff AND2 ( idx* ; remove rotation/flip info for now )
DUP2 ( idx* idx* )
#000d DIV2k STH2k MUL2 SUB2 ( idx* r* [q*] )
#0100 MUL2 ;tiles #0300 ADD2 ( idx* 256r* card+768* [q*] )
ADD2 STH2r #0020 MUL2 ADD2 ( idx* a=card+768+256r+32q* )
STH2k .Screen/addr DEO2 ( idx* [a*] )
#81 .Screen/sprite DEO ( idx* [a*] ; draw top of card )
find-middle-addr ( mid* [a*] )
.Screen/addr DEO2 ( [a*] )
#81 .Screen/sprite DEO ( [a*] ; draw middle of card )
STH2r DUP2 #0010 ADD2 ( a* a+16* )
( TODO: does flipping also flip move direction now? )
SWP2 #0008 .Screen/x DEI2 ADD2 .Screen/x DEO2
.Screen/addr DEO2 ( )
#01 .Screen/auto DEO ( ; draw 1 tile, increment x )
#b1 .Screen/sprite DEO ( ; draw bottom left of card )
.Screen/addr DEO2 ( )
#b1 .Screen/sprite DEO ( ; draw bottom right of card )
JMP2r
@init-rng-from-datetime ( -> )
#00 .DateTime/dow #5180 MUL2
#00 .DateTime/hr DEI #0e10 MUL2 ADD2
#00 .DateTime/min DEI #003c MUL2 ADD2
#00 .DateTime/sec DEI ADD2 ( s* )
DUP2 .DateTime/doy DEI2 MUL2 ( s* sdoy* )
( fall-through )
@init-rng ( x* y* -> )
#0001 ROT2 OVR2 ( y* 1* x* 1* )
ORA2 ;rng/x STA2 ( y* 1* )
ORA2 ;rng/x STA2 JMP2r ( )
@random ( -> x* )
;rng/x LDA2 DUP2 #50 SFT2 EOR2 ( t=x^[x<<5]* )
;rng/y LDA2 DUP2 ;rng/x STA2 ( t* y* ; x<-y )
DUP2 #01 SFT2 EOR2 ( t* u=y^[y>>1]* )
SWP2 DUP2 #03 SFT2 EOR2 ( u* v=t^[t>>3]* )
EOR2 DUP2 ;rng/y STA2 JMP2r ( u^v* ; y<-u^v )
( 52 cards x 4 bytes per card = 208 bytes )
( each card has: )
( )
( - byte 1: flags )
( - byte 2: card suit/value )
( - byte 3: x position )
( - byte 4: y position )
( )
( confusingly the "top" card is actually at the end )
( this ends up being convenient for coding but is a )
( bit confusing to think about )
@cards $0cc &last $4 &end
@cursor 80c0 e0f0 f8e0 1000
@cursox 7f3f 1f0f 071f efff
@blank 0000 0000 0000 0000
@rng &x $2 &y $2
( each tile is 16 bytes: a 2-bit 8x8 image )
@tiles ~card-sprites.tal
( each mask tile is 8 bytes: a 1-bit 8x8 image )
@masks ~mask-sprites.tal

270
impatience.tal Normal file
View File

@ -0,0 +1,270 @@
( deck.tal )
|00 @System [ &vect $2 &expansion $2 &title $2 &metadata $2 &r $2 &g $2 &b $2 ]
|10 @Console [ &vect $2 &r $1 &exec $2 &mode $1 &dead $1 &exit $1 &w $1 ]
|20 @Screen [ &vect $2 &w $2 &h $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &px $1 &sprite $1 ]
|80 @Controller [ &vect $2 &button $1 &key $1 &fn $1 ]
|90 @Mouse [ &vect $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 ]
|a0 @File1 [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|b0 @File2 [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|c0 @DateTime [ &y $2 &m $1 &d $1 &hr $1 &min $1 &sec $1 &dow $1 &doy $2 &isdst $1 ]
( 1 byte per card )
( #01 ace ... #0d king )
( #00 club #10 diamond #20 spade #30 heart )
( #00 face up, #40 face down )
( #00 normal #80 held )
( examples: )
( - #00 no card )
( - #01 ace of clubs )
( - #1a ten of diamonds )
( - #24 four of hearts )
( - #3d king of spades )
( - #6c queen of hearts, face down )
( - #93 three of diamonds, held )
|0000
@stock $34 ( draw pile - 52 bytes )
@waste $18 ( face up pile - 24 bytes )
@foundation $4 ( one per suit - 4 bytes, 4x1 )
@tableau $85 ( the main board - 133 bytes, 7x19 )
@prev-button $1
@prev-mouse-state $1
@prev-mouse-x $2
@prev-mouse-y $2
@card-is-held $1
|0100
#2d8b .System/r DEO2
#2d18 .System/g DEO2
#2d14 .System/b DEO2
#0100 .Screen/w DEO2
#00c0 .Screen/h DEO2
init-rng-from-datetime
draw-background
init-stock init-waste init-foundation
shuffle-stock deal-tableau
draw-stock draw-waste draw-foundation draw-tableau
;on-mouse .Mouse/vect DEO2
( ;on-key .Controller/vect DEO2 )
BRK
@init-stock ( -> )
LITr -stock #8000 #4e41
&outer DUP2
&inner DUP STHkr STZ INC INCr GTHk ?&inner
POP2 #1010 ADD2 GTH2k ?&outer
POP2 POP2 POPr JMP2r
@init-waste ( -> )
#00 LITr -waste LITr 18 OVRr ADDr SWPr
&loop DUP STHkr STZ INCr GTHkr STHr ?&loop
POP POP2r JMP2r
@init-foundation
#01 .foundation #00 ADD STZ
#11 .foundation #01 ADD STZ
#21 .foundation #02 ADD STZ
#00 .foundation #03 ADD STZ
JMP2r
@shuffle-stock ( -> )
.stock #33 OVR ADD SWP ( last^ start^ )
&loop ( last^ pos^ )
SUBk INC #00 SWP ( last^ pos^ n=last-pos+1* )
random SWP2 ( last^ pos^ r* n* )
DIV2k MUL2 SUB2 NIP ( last^ pos^ i=r%n^ )
OVR ADD LDZk ,&c STR ( last^ pos^ alt=pos+i^ ; c<-alt )
STH LDZk STHr STZ STH ( last^ [pos^] ; alt<-pos )
LIT [ &c $1 ] STHkr STZ ( last^ [pos^] ; pos<-c )
STHr INC GTHk ?&loop ( last^ pos+1^ )
POP2 JMP2r ( )
@deal-tableau ( -> )
#33 LIT2r -tableau 00
&loop STH2kr deal-column
LIT2r 1301 ADD2r
STHkr #07 LTH ?&loop
POP2r POP JMP2r
@deal-column ( src^ dst^ count^ -> src2^ )
#00 SWP SUB STH SWP ( dst^ src^ [-count^] )
&loop STHkr ?&ok !&done ( d^ s^ [-c^] )
&ok DUP2 LDZ SWP STZ ( d^ s^ [-c^] ; d<-s|64 )
#01 SUB SWP INC SWP ( d+1^ s-1^ [-c^] )
INCr !&loop ( d+1^ s-1^ [-c+1^] )
&done POPr SWP ( s^ d^)
OVR LDZ #bf AND SWP STZ ( s^ ; d<-s )
#01 SUB JMP2r ( s-1^ )
@swap-c ( src^ dst^ -> )
LDZk STH ( src^ dst^ [d^] )
OVR LDZ ( src^ dst^ s^ [d^] )
SWP STZ ( src^ [d^] ; dst<-s )
STHr SWP ( d^ src^ )
STZ JMP2r ( ; src<-d )
@draw-stock ( -> )
#0008 ,&y STR2 ( ; y0<-8 )
.stock #34 OVR ADD SWP LITr 01 ( stock+52 stock^ [n^] )
&loop LDZk DUP ?&ok !&done ( lim^ zp^ c^ [n^] )
&ok ( lim^ zp^ c^ [n^] )
#0008 .Screen/x DEO2 ( lim^ zp^ c^ [n^] ; x<-8 )
LIT2 [ &y $2 ] .Screen/y DEO2 ( lim^ zp^ c^ [n^] ; y<- )
draw-c STHkr ?&skip ( lim^ zp^ [n^] ; draw c )
,&y LDR2 #0001 SUB2 ,&y STR2 ( lim^ zp^ [n^] ; y<-y-1 )
&skip INC INCr LITr 07 ANDr GTHk ?&loop ( lim^ zp+1^ [(n+1)%8] )
&done POP2 POPr JMP2r ( )
@draw-waste ( -> )
#001c ,&x STR2 ( ; x0<-28 )
.waste #18 OVR ADD SWP ( waste+24^ waste^ )
&loop LDZk DUP ?&ok !&done ( lim^ zp^ c^ )
&ok ( lim^ zp^ c^ )
#0008 .Screen/y DEO2 ( lim^ zp^ c^ ; y<-8 )
LIT2 [ &x $2 ] .Screen/x DEO2 ( lim^ zp^ c^ ; x<- )
draw-c ( lim^ zp^ ; draw c )
,&x LDR2 #0008 ADD2 ,&x STR2 ( lim^ zp^ ; x<-x+8 )
INC GTHk ?&loop ( lim^ zp+1^ )
&done POP2 JMP2r ( )
@draw-foundation ( -> )
#0030 ,&y STR2 ( ; y0<-48 )
.foundation #04 OVR ADD SWP ( lim^ zp^ )
&loop ( lim^ zp^ )
#0008 .Screen/x DEO2 ( lim^ zp^ ; x<-8 )
LIT2 [ &y $2 ] .Screen/y DEO2 ( lim^ zp^ ; y<- )
LDZk maybe-draw-c ( lim^ zp^ ; draw )
,&y LDR2 #0020 ADD2 ,&y STR2 ( lim^ zp^ ; y<-y+32 )
INC GTHk ?&loop ( lim^ zp+1^ )
&done POP2 JMP2r ( )
@draw-tableau
#0700 &loop DUP draw-column INC GTHk ?&loop JMP2r
@draw-column ( idx^ -> )
#00 OVR #0018 MUL2 #0030 ADD2 ,&x STR2 ( idx^ ; x<-32+24*idx )
#0024 ,&y STR2 ( idx^ ; y<-32 )
#13 MUL .tableau ADD ( pos=t+idx*19^ )
DUP #13 ADD SWP ( lim=pos+19^ pos^ )
&loop ( lim^ pos^ )
LDZk DUP ?&ok !&done ( lim^ pos^ c^ )
&ok LIT2 [ &x $2 ] .Screen/x DEO2 ( lim^ pos^ ; s/x<-x )
LIT2 [ &y $2 ] .Screen/y DEO2 ( lim^ pos^ ; s/y<-y )
draw-c INC ( lim^ pos+1^ )
,&y LDR2 #0008 ADD2 ,&y STR2 ( lim^ pos+1^ )
GTHk ?&loop ( lim^ pos+1^ )
&done POP POP2 JMP2r ( )
@maybe-draw-c
DUP ?{ POP !draw-mask-down } !draw-c
( assumes x/y already set )
@draw-c ( card^ -> )
DUP #40 LTH ?&norm
DUP #80 LTH ?&down
DUP #c0 LTH ?&held
POP !draw-mask-down
&norm adjust-c !draw-face-up
&down POP !draw-face-down
&held adjust-c !draw-mask-up
( we map from our sparse, logical card format )
( to the dense, tile position card location )
( clubs: #01 -> #27 ... #0d -> #33 )
( diamonds: #11 -> #1a ... #1d -> #26 )
( spades: #21 -> #00 ... #2d -> #0c )
( hearts: #31 -> #0d ... #3d -> #19 )
@adjust-c ( card^ -> idx* )
#00 SWP
DUP #21 LTH ?&lt
DUP #31 LTH #03 MUL ADD #24 SUB JMP2r
&lt DUP #11 LTH #1d MUL ADD #09 ADD JMP2r
@on-mouse ( -> brk )
on-move
( on-click-down )
( on-click-up )
.Mouse/state DEI .prev-mouse-state STZ
BRK
@mouse-dx ( -> dx* ) .Mouse/x DEI2 .prev-mouse-x LDZ2 SUB2 JMP2r
@mouse-dy ( -> dy* ) .Mouse/y DEI2 .prev-mouse-y LDZ2 SUB2 JMP2r
@mouse-dx8 ( -> dx^ ) .Mouse/x DEI2 .prev-mouse-x LDZ2 SUB2 NIP JMP2r
@mouse-dy8 ( -> dy^ ) .Mouse/y DEI2 .prev-mouse-y LDZ2 SUB2 NIP JMP2r
@on-move ( -> )
.Mouse/x DEI2 .prev-mouse-x LDZ2 NEQ2 ?&redraw
.Mouse/y DEI2 .prev-mouse-y LDZ2 NEQ2 ?&redraw
JMP2r
&redraw #00 .Screen/auto DEO
clear-prev-mouse draw-curr-mouse JMP2r
@clear-prev-mouse ( -> )
.prev-mouse-x LDZ2 .Screen/x DEO2
.prev-mouse-y LDZ2 .Screen/y DEO2
;blank .Screen/addr DEO2
#41 .Screen/sprite DEO JMP2r
@draw-curr-mouse ( -> )
.Mouse/x DEI2 DUP2 .prev-mouse-x STZ2 .Screen/x DEO2
.Mouse/y DEI2 DUP2 .prev-mouse-y STZ2 .Screen/y DEO2
;cursor .Screen/addr DEO2
#43 .Screen/sprite DEO JMP2r
@on-click-down ( -> )
.Mouse/state DEI ( state^ )
.prev-mouse-state LDZ #ff EOR AND ( down^ )
#01 AND ( TODO: support more than one button )
?&click JMP2r ( TODO: check particular button )
&click
find-mouse-over-card
ORAk ?&found POP2 JMP2r
&found
raise-cards .card-is-held STZ
!draw-cards
@on-click-up ( -> )
.Mouse/state DEI #ff EOR ( not-state^ )
.prev-mouse-state LDZ AND ( up^ )
#01 AND ( TODO: support more than one button )
?&unclick JMP2r ( TODO: check particular button )
&unclick
#00 .card-is-held STZ
draw-background draw-cards
JMP2r
@on-key ( -> brk )
on-press on-release
.Controller/button DEI .prev-button STZ
BRK
@on-release ( -> )
.Controller/button DEI #ff EOR ( not-button^ )
.prev-button LDZ AND ( release^ )
DUP #00 EQU ?&skip
DUP #08 AND ?&start
&skip POP JMP2r
&start POP !draw-cards
@on-press ( -> )
.Controller/button DEI ( button^ )
.prev-button LDZ #ff EOR AND ( press^ )
DUP #00 EQU ?&skip
DUP #01 AND ?&ctrl
DUP #02 AND ?&alt
DUP #04 AND ?&select
DUP #08 AND ?&start
&skip POP JMP2r
&ctrl POP !try-to-flip
&alt POP !flip-all-cards
&select POP !randomize
&start POP !reset
~cards.tal

256
mask-sprites.tal Normal file
View File

@ -0,0 +1,256 @@
ff ff e7 fb e7 fb e7 ff
ff ff 27 07 07 8f df ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff fb f1 e0 e0 e4 ff ff
ff e7 df e7 df e7 ff ff
ff ff f3 eb e3 eb eb ff
ff ff df 8f 07 8f df ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff fb f1 e0 f1 fb ff ff
ff d7 d7 c7 d7 c7 ff ff
f8 f8 fb fb fb f9 f8 fc
0f 0f ff ff 9f 6f ef 0f
f8 f8 fb fb fb f9 f8 fc
0f 0f ff ff 9f 6f ef 0f
00 7f 6f 54 6f 7e 6d 6d
00 fe f6 2a f6 7e b6 b6
6e 6f 6e 6d 6d 6e 6f 6e
76 f6 76 b6 b6 76 f6 76
6d 6d 7e 6f 54 6f 7f 00
b6 b6 7e f6 2a f6 fe 00
ff ff eb eb e7 eb eb ff
ff ff df 8f 07 df 8f ff
f8 f8 fb fb fb f9 f8 fc
0f 0f ff ff 9f 6f ef 0f
ff f1 fb e0 f1 fb ff ff
ff d7 d7 e7 d7 d7 ff ff
f8 f0 f0 f2 f3 d9 c1 e1
1f 0f ef ef ef ef ff ff
f8 f0 f0 f2 f3 d9 c1 e1
1f 0f ef ef ef ef ff ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e3 eb eb e7 f3 ff
ff ff 27 27 df 2f 37 ff
f8 f0 f0 f2 f3 d9 c1 e1
1f 0f ef ef ef ef ff ff
ff ec f4 fb e4 e4 ff ff
ff cf e7 d7 d7 c7 ff ff
fe fc f8 f8 f9 f8 f9 ff
3f 1f 1f ff ff ff ff ff
fe fc f8 f8 f9 f8 f9 ff
3f 1f 1f ff ff ff ff ff
ff ff f3 eb e3 eb eb ff
ff ff df 8f 07 df 8f ff
ff ff f3 eb e3 eb eb ff
ff ff 27 07 07 8f df ff
ff ff f3 eb e3 eb eb ff
ff ff df 8f 07 8f df ff
ff ff f3 eb e3 eb eb ff
ff ff 27 27 df 2f 37 ff
80 c0 e0 f0 f8 e0 10 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e7 fb f7 ef e3 ff
ff ff df 8f 07 df 8f ff
ff ff e7 fb f7 ef e3 ff
ff ff 27 07 07 8f df ff
ff ff e7 fb f7 ef e3 ff
ff ff df 8f 07 8f df ff
ff ff e7 fb f7 ef e3 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e7 fb e7 fb e7 ff
ff ff df 8f 07 df 8f ff
ff ff e7 fb e7 fb e7 ff
ff ff 27 07 07 8f df ff
ff ff e7 fb e7 fb e7 ff
ff ff df 8f 07 8f df ff
ff ff e7 fb e7 fb e7 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff eb eb e3 fb fb ff
ff ff df 8f 07 df 8f ff
ff ff eb eb e3 fb fb ff
ff ff 27 07 07 8f df ff
ff ff eb eb e3 fb fb ff
ff ff df 8f 07 8f df ff
ff ff eb eb e3 fb fb ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e3 ef e3 fb e7 ff
ff ff df 8f 07 df 8f ff
ff ff e3 ef e3 fb e7 ff
ff ff 27 07 07 8f df ff
ff ff e3 ef e3 fb e7 ff
ff ff df 8f 07 8f df ff
ff ff e3 ef e3 fb e7 ff
ff ff 27 27 df 2f 37 ff
f8 f8 fb fb fb f9 f8 fc
0f 0f ff ff 9f 6f ef 0f
f8 f8 fb fb fb f9 f8 fc
0f 0f ff ff 9f 6f ef 0f
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff f3 ef e3 eb e3 ff
ff ff df 8f 07 df 8f ff
ff ff f3 ef e3 eb e3 ff
ff ff 27 07 07 8f df ff
ff ff f3 ef e3 eb e3 ff
ff ff df 8f 07 8f df ff
ff ff f3 ef e3 eb e3 ff
ff ff 27 27 df 2f 37 ff
f8 f0 f0 f2 f3 d9 c1 e1
1f 0f ef ef ef ef ff ff
f8 f0 f0 f2 f3 d9 c1 e1
1f 0f ef ef ef ef ff ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e3 fb f7 f7 f7 ff
ff ff df 8f 07 df 8f ff
ff ff e3 fb f7 f7 f7 ff
ff ff 27 07 07 8f df ff
ff ff e3 fb f7 f7 f7 ff
ff ff df 8f 07 8f df ff
ff ff e3 fb f7 f7 f7 ff
ff ff 27 27 df 2f 37 ff
fe fc f8 f8 f9 f8 f9 ff
3f 1f 1f ff ff ff ff ff
fe fc f8 f8 f9 f8 f9 ff
3f 1f 1f ff ff ff ff ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e3 eb e3 eb e3 ff
ff ff df 8f 07 df 8f ff
ff ff e3 eb e3 eb e3 ff
ff ff 27 07 07 8f df ff
ff ff e3 eb e3 eb e3 ff
ff ff df 8f 07 8f df ff
ff ff e3 eb e3 eb e3 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e3 eb e3 fb e7 ff
ff ff df 8f 07 df 8f ff
ff ff e3 eb e3 fb e7 ff
ff ff 27 07 07 8f df ff
ff ff e3 eb e3 fb e7 ff
ff ff df 8f 07 8f df ff
ff ff e3 eb e3 fb e7 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff d1 d5 d5 d5 d1 ff
ff ff df 8f 07 df 8f ff
ff ff d1 d5 d5 d5 d1 ff
ff ff 27 07 07 8f df ff
ff ff d1 d5 d5 d5 d1 ff
ff ff df 8f 07 8f df ff
ff ff d1 d5 d5 d5 d1 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff f3 fb fb fb e7 ff
ff ff df 8f 07 df 8f ff
ff ff f3 fb fb fb e7 ff
ff ff 27 07 07 8f df ff
ff ff f3 fb fb fb e7 ff
ff ff df 8f 07 8f df ff
ff ff f3 fb fb fb e7 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff e3 eb eb e7 f3 ff
ff ff df 8f 07 df 8f ff
ff ff e3 eb eb e7 f3 ff
ff ff 27 07 07 8f df ff
ff ff e3 eb eb e7 f3 ff
ff ff df 8f 07 8f df ff
ff ff e3 eb eb e7 f3 ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
ff ff eb eb e7 eb eb ff
ff ff df 8f 07 df 8f ff
ff ff eb eb e7 eb eb ff
ff ff 27 07 07 8f df ff
ff ff eb eb e7 eb eb ff
ff ff df 8f 07 8f df ff
ff ff eb eb e7 eb eb ff
ff ff 27 27 df 2f 37 ff
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00