summaryrefslogtreecommitdiff
path: root/tetris/io.prn
blob: 539cbee0b75ecd0df9af58837a4cd3dbfc996d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
	pop
	"+" 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
	pop
	"+" 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
	pop
	#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
	pop
	#1000000 sleep
}

@defun "io_windowbox" {
	io_pos_windowstart io_pos_windowend io_pos_windowstart diff2 io_box
}

@defun "io_square" { #args: x y
	"y" store
	"x" store
	x y io_goto
	#"+--+" print
	#x y 1 + io_goto
	#"|  |" print
	#x y 2 + io_goto
	#"+--+" print
	"xxx\x1B[3D\x1B[Bxxx" print
}

@defun "io_pos_square" { #args: x y
	swap
	tile_sizex * padding_x +
	swap
	tile_sizey * padding_y +
}

@defun "io_gsquare" { #args: x y blockidx
	"b_blockclrs" swapoutvar swap arridx swap "b_blockclrs" gstore
	io_setcolour
	io_pos_square io_square
	io_resetcolour
}


@defun "io_setcolour" { #args: coloridx [0..7]
	"\x1B[3" swap + "m" + print
}

@defun "io_resetcolour" {
	"\x1B[0m" print
}