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
|
# load test: animate a whole lot of text
#
# Requires a large file called "x" containing just ascii characters. One way
# to generate it:
# cat /dev/urandom |base64 - |head -n 1000 > x
# then merge pairs of lines.
#
# also assumes it's in a window 185 characters wide
fn main -> exit-status/ebx: int {
var num-lines/ecx: int <- copy 0x10
clear-screen
# open a file
var f: (addr buffered-file)
{
var f-handle: (handle buffered-file)
var f-in/eax: (addr handle buffered-file) <- address f-handle
open "x", 0, f-in # for reading
var f-out/eax: (addr buffered-file) <- lookup f-handle
copy-to f, f-out
}
# main loop
var row/eax: int <- copy 1
{
compare row, 0x10 # 16
break-if->
render f, row, num-lines
row <- increment
#? sleep 0 0x5f5e100 # 100ms
loop
}
# wait for a key
{
enable-keyboard-immediate-mode
var dummy/eax: byte <- read-key
enable-keyboard-type-mode
}
# clean up
clear-screen
exit-status <- copy 0
}
fn render f: (addr buffered-file), start-row: int, num-rows: int {
var num-cols/ecx: int <- copy 0xb9 # 185
# if necessary, clear the row above
$render:clear-loop: {
compare start-row, 1
break-if-<=
decrement start-row
var col/eax: int <- copy 1
move-cursor-on-screen start-row, col
{
compare col, num-cols
break-if->
print-string-to-screen " "
col <- increment
loop
}
increment start-row
}
# render rest of screen below
var row/edx: int <- copy start-row
var col/ebx: int <- copy 1
move-cursor-on-screen row, col
$render:render-loop: {
compare row, num-rows
break-if->=
var c/eax: byte <- read-byte-buffered f
compare c, 0xffffffff # EOF marker
break-if-=
compare c, 0xa # newline
{
break-if-!=
row <- increment
col <- copy 0
move-cursor-on-screen row, col
loop $render:render-loop
}
print-byte-to-screen c
col <- increment
loop
}
}
|