summaryrefslogtreecommitdiff
path: root/tetris
diff options
context:
space:
mode:
Diffstat (limited to 'tetris')
-rw-r--r--tetris/blocks.prn45
-rw-r--r--tetris/blocks.txt43
-rw-r--r--tetris/io.prn105
-rw-r--r--tetris/tetris.prn13
-rw-r--r--tetris/utility.prn22
5 files changed, 228 insertions, 0 deletions
diff --git a/tetris/blocks.prn b/tetris/blocks.prn
new file mode 100644
index 0000000..3147b41
--- /dev/null
+++ b/tetris/blocks.prn
@@ -0,0 +1,45 @@
+@includeonce "io.prn"
+
+7 "b_nblocks" store
+
+15 "b_block1" store #I
+23 "b_block2" store #L
+71 "b_block3" store #J
+51 "b_block4" store #O
+54 "b_block5" store #S
+99 "b_block6" store #Z
+114 "b_block7" store #T
+
+@defun "b_getblock" { #arg: block idx [1..7]
+ "b_block" swap + get
+}
+
+@defun "b_drawblock" { #args: x y blockidx
+ b_getblock
+ "blockbits" store
+ "y" store
+ "x" store
+
+ blockbits 16 % "row1" store
+ blockbits 16 / "row2" store
+
+ x "xx" store
+ row1 while
+ row1 2 % if
+ xx y io_gsquare
+ end
+ xx 1 + "xx" store
+ row1 2 / "row1" store
+ row1 end
+
+ y 1 + "y" store
+
+ x "xx" store
+ row2 while
+ row2 2 % if
+ xx y io_gsquare
+ end
+ xx 1 + "xx" store
+ row2 2 / "row2" store
+ row2 end
+}
diff --git a/tetris/blocks.txt b/tetris/blocks.txt
new file mode 100644
index 0000000..f0f55f1
--- /dev/null
+++ b/tetris/blocks.txt
@@ -0,0 +1,43 @@
+THE TEMPLATE:
+
+....
+....
+
+byte: 76543210
+
+0123
+4567
+
+
+THE BLOCKS:
+
+****
+....
+-> 15
+
+***.
+*...
+-> 23
+
+***.
+..*.
+-> 71
+
+**..
+**..
+-> 51
+
+.**.
+**..
+-> 54
+
+**..
+.**.
+-> 99
+
+.*..
+***.
+-> 114
+
+
+15 23 71 51 54 99 114
diff --git a/tetris/io.prn b/tetris/io.prn
new file mode 100644
index 0000000..7b2c704
--- /dev/null
+++ b/tetris/io.prn
@@ -0,0 +1,105 @@
+2 "padding_x" store
+2 "padding_y" store
+10 "ntiles_x" store
+12 "ntiles_y" store
+3 "tile_sizex" store
+2 "tile_sizey" store
+
+@defun "io_pos_windowstart" { #puts: x y
+ 0 0
+}
+
+@defun "io_pos_windowend" { #puts: x y
+ ntiles_x tile_sizex * padding_x 2 * + 1 -
+ ntiles_y tile_sizey * padding_y 2 * +
+}
+
+@defun "io_pos_after" { #puts: x y
+ 0
+ ntiles_y tile_sizey * padding_y 2 * + 1 +
+}
+
+@defun "io_clearscreen" {
+ "\x1B[2J\x1B[H" print
+}
+
+@defun "io_goto" { #args: x y
+ "y" store
+ "x" store
+ #"going to (" x + "," + y + ")" + print
+ "\x1B[" y 1 + + ";" + x 1 + + "H" + print
+}
+
+@defun "io_box" { #args: x y w h; w/h are the distances from edge to edge
+ #stackdump
+ #1000000 sleep
+ "h" store
+ "w" store
+ "y" store
+ "x" store
+
+ x y io_goto
+ "+" print
+ 0
+ dup w < while
+ "-" print
+ 1 +
+ dup w < end
+ "+" print
+ #1000000 sleep
+
+ #"x = " print x print
+ #"y = " print y print
+
+ x y h + io_goto
+ "+" print
+ 0
+ dup w < while
+ "-" print
+ 1 +
+ dup w < end
+ "+" print
+ #1000000 sleep
+
+ #"x = " print x print
+ #"y = " print y print
+
+ x y 1 + io_goto
+ 0
+ dup h 1 - < while
+ "|\x1B[D\x1B[B" print #bar, left, down
+ 1 +
+ dup h 1 - < end
+ #1000000 sleep
+
+ x w + 1 + y 1 + io_goto
+ 0
+ dup h 1 - < while
+ "|\x1B[D\x1B[B" print #bar, left, down
+ 1 +
+ dup h 1 - < end
+ #1000000 sleep
+}
+
+@defun "io_windowbox" {
+ io_pos_windowstart io_pos_windowend io_pos_windowstart diff2 io_box
+}
+
+@defun "io_square" { #args: x y (equivalent to x y 3 2 io_box)
+ "y" store
+ "x" store
+ x y io_goto
+ "+--+" print
+ x y 1 + io_goto
+ "| |" print
+ x y 2 + io_goto
+ "+--+" print
+}
+
+@defun "io_gsquare" { #args: x y
+ swap
+ tile_sizex * padding_x +
+ swap
+ tile_sizey * padding_y +
+ io_square
+}
diff --git a/tetris/tetris.prn b/tetris/tetris.prn
new file mode 100644
index 0000000..729f491
--- /dev/null
+++ b/tetris/tetris.prn
@@ -0,0 +1,13 @@
+@includeonce "io.prn"
+@includeonce "utility.prn"
+@includeonce "blocks.prn"
+
+1 "i" store
+i 8 < while
+ io_clearscreen
+ io_windowbox
+ 0 0 i b_drawblock
+ 1000000 sleep
+ i 1 + "i" store
+i 8 < end
+io_pos_after io_goto
diff --git a/tetris/utility.prn b/tetris/utility.prn
new file mode 100644
index 0000000..ca68dfe
--- /dev/null
+++ b/tetris/utility.prn
@@ -0,0 +1,22 @@
+@defun "diff2" {
+ "y2" store
+ "x2" store
+ "y1" store
+ "x1" store
+ x1 x2 -
+ y1 y2 -
+}
+
+@defun "dup2" {
+ "b" store
+ "a" store
+ a b a b
+}
+
+@defun "swap2" {
+ "b2" store
+ "b1" store
+ "a2" store
+ "a1" store
+ b1 b2 a1 a2
+}