summaryrefslogtreecommitdiff
path: root/tetris/engine.prn
diff options
context:
space:
mode:
Diffstat (limited to 'tetris/engine.prn')
-rw-r--r--tetris/engine.prn79
1 files changed, 70 insertions, 9 deletions
diff --git a/tetris/engine.prn b/tetris/engine.prn
index bd00433..390e1d2 100644
--- a/tetris/engine.prn
+++ b/tetris/engine.prn
@@ -14,6 +14,12 @@ mkarray "e_blockqueue" store #(rot<<3) + idx
e_pushnewblock
e_newcblock #initialises cblock vars
+
+ sys_rawmode
+}
+
+@defun "e_teardown" {
+ sys_unrawmode
}
@defun "e_test" {
@@ -94,13 +100,6 @@ mkarray "e_blockqueue" store #(rot<<3) + idx
ntiles_x 3 + 1
e_peekblock dup 8 % swap 8 /
b_drawblock
-
- e_cblockpos dup ntiles_x % swap ntiles_x /
- e_cblock dup 8 % swap 8 /
- dup4
- b_drawblock
- sleep_time sleep
- b_undrawblock
}
@defun "e_validcbp" { #args: cblock cblockpos (compares purely to e_boardfilled)
@@ -162,9 +161,64 @@ mkarray "e_blockqueue" store #(rot<<3) + idx
"e_boardfilled" gstore
}
-@defun "e_runloop" {
+@defun "e_getuserinput" {
+ getc
+ dup "h" = if
+ e_cblockpos 1 - "newcbp" store
+ e_cblockpos ntiles_x % 0 > e_cblock newcbp e_validcbp & if
+ newcbp "e_cblockpos" gstore
+ end
+ end
+ dup "l" = if
+ e_cblockpos 1 + "newcbp" store
+ e_cblockpos ntiles_x % ntiles_x 1 - < e_cblock newcbp e_validcbp & if
+ newcbp "e_cblockpos" gstore
+ end
+ end
+ dup "j" = if
+ e_cblock 8 % e_cblock 8 / 3 + 4 % 8 * + "newcb" store
+ newcb e_cblockpos e_validcbp if
+ newcb "e_cblock" gstore
+ end
+ end
+ dup "j" = if
+ e_cblock 8 % e_cblock 8 / 1 + 4 % 8 * + "newcb" store
+ newcb e_cblockpos e_validcbp if
+ newcb "e_cblock" gstore
+ end
+ end
+ pop
+}
+
+@defun "e_sleep_userinput" {
+ sleep_time "timeout" store
1 while
+ 0 1 mkarrayp mkarray mkarray timeout sys_select
+ "timeout" store
+ pop pop
+ arrlen if
+ e_getuserinput
+ stackdump
+ end
+ pop
+ timeout end
+}
+
+@defun "e_runloop" {
+ 0 "exitrunloop" store
+ exitrunloop ! while
e_fullrender
+
+ e_cblockpos dup ntiles_x % swap ntiles_x /
+ e_cblock dup 8 % swap 8 /
+ dup4
+ b_drawblock
+ io_pos_after io_goto
+ #sleep_time sleep
+ e_sleep_userinput
+ b_undrawblock
+
+
e_cblockpos ntiles_x + #new cblockpos
dup e_cblock swap e_validcbp if
"e_cblockpos" gstore
@@ -172,6 +226,13 @@ mkarray "e_blockqueue" store #(rot<<3) + idx
pop
e_cblock e_cblockpos e_applyblock
e_newcblock
+ e_cblock e_cblockpos e_validcbp ! if
+ 1 "exitrunloop" store
+ e_blockqueue e_cblock arrpushf "e_blockqueue" gstore
+ e_fullrender
+ io_pos_after io_goto
+ "GAME OVER!\n" print
+ end
end
- 1 end
+ exitrunloop ! end
}