summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tetris/blocks.prn45
-rw-r--r--tetris/blocks.txt43
-rw-r--r--tetris/io.prn113
-rw-r--r--tetris/tetris.prn13
-rw-r--r--tetris/utility.prn22
5 files changed, 236 insertions, 0 deletions
diff --git a/tetris/blocks.prn b/tetris/blocks.prn
new file mode 100644
index 0000000..bc37cb9
--- /dev/null
+++ b/tetris/blocks.prn
@@ -0,0 +1,45 @@
+@includeonce "io.prn"
+
+7 "b_nblocks" store
+
+15 "b_block1" store 6 "b_block1c" store #I: cyan
+23 "b_block2" store 3 "b_block2c" store #L: orange
+71 "b_block3" store 4 "b_block3c" store #J: blue
+51 "b_block4" store 7 "b_block4c" store #O: yellow (ish)
+54 "b_block5" store 2 "b_block5c" store #S: lime
+99 "b_block6" store 1 "b_block6c" store #Z: red
+114 "b_block7" store 5 "b_block7c" store #T: purple
+
+@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..0d18c44
--- /dev/null
+++ b/tetris/io.prn
@@ -0,0 +1,113 @@
+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_pos_square" { #args: x y
+ swap
+ tile_sizex * padding_x +
+ swap
+ tile_sizey * padding_y +
+}
+
+@defun "io_gsquare" { #args: x y
+ io_pos_square io_square
+}
+
+
+@defun "io_setcolour" { #args: coloridx [0..7]
+ "\x1B[3" swap + "m" + print
+}
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
+}