summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-12-23 21:42:49 +0100
committertomsmeding <tom.smeding@gmail.com>2016-12-23 21:42:49 +0100
commit0ad45225f7ecb1a8a5ee6751e8f682d5966c2fd8 (patch)
tree6ebb7593bae0ee2b5fb604475549cf30295da178
parent2a952e107509cbc743b351e32663bfc8c6df9211 (diff)
Some changes that were lying aroundHEADmaster
-rw-r--r--Makefile2
-rw-r--r--functions.cpp4
-rw-r--r--tetris/engine.prn79
-rw-r--r--tetris/io.prn6
-rw-r--r--tetris/tetris.prn5
5 files changed, 79 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index ded4503..4edfcba 100644
--- a/Makefile
+++ b/Makefile
@@ -12,5 +12,5 @@ clean:
remake: clean all
postrun: $(OBJECTS)
- g++ -Wall -O2 -std=c++11 -o postrun $(OBJECTS)
+ g++ $(CXXFLAGS) -o postrun $(OBJECTS)
strip postrun
diff --git a/functions.cpp b/functions.cpp
index 91f6ba9..1d5d48e 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -253,8 +253,8 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack
if(oflag==0)oflag=O_RDONLY;
int ret=open(fname.strval.c_str(),oflag);
if(ret<0)perror("open");
- fdtable[ret].read=(oflag&(O_RDONLY|O_RDWR))!=0;
- fdtable[ret].write=(oflag&(O_WRONLY|O_RDWR))!=0;
+ fdtable[ret].read=(oflag&O_RDONLY)==O_RDONLY||(oflag&O_RDWR)==O_RDWR;
+ fdtable[ret].write=(oflag&O_WRONLY)==O_WRONLY||(oflag&O_RDWR)==O_RDWR;
fdtable[ret].open=true;
S.emplace_back(ret);
}},
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
}
diff --git a/tetris/io.prn b/tetris/io.prn
index d749150..24fb4bb 100644
--- a/tetris/io.prn
+++ b/tetris/io.prn
@@ -5,13 +5,13 @@
}
@defun "io_pos_windowend" { #puts: x y
- ntiles_x tile_sizex * padding_x 2 * + origin_x +
- ntiles_y tile_sizey * padding_y 2 * + origin_y +
+ ntiles_x padding_x 2 * + tile_sizex * origin_x +
+ ntiles_y padding_y 2 * + tile_sizey * origin_y +
}
@defun "io_pos_after" { #puts: x y
0
- ntiles_y tile_sizey * padding_y 2 * + 1 +
+ ntiles_y padding_y 2 * + tile_sizey * origin_y +
}
@defun "io_clearscreen" {
diff --git a/tetris/tetris.prn b/tetris/tetris.prn
index c11ec57..c324a10 100644
--- a/tetris/tetris.prn
+++ b/tetris/tetris.prn
@@ -7,7 +7,7 @@
#PARAMETERS
0 "origin_x" store
5 "origin_y" store
-3 "padding_x" store
+2 "padding_x" store
2 "padding_y" store
11 "ntiles_x" store
13 "ntiles_y" store
@@ -21,4 +21,5 @@
e_init
#e_test
e_runloop
-io_pos_after io_goto
+e_teardown
+#io_pos_after io_goto