about summary refs log tree commit diff stats
path: root/prototypes/tile/1.mu
blob: 4d0a79699e6bc5668db1c2442ba49244db3141e7 (plain) (blame)
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
# little example program: animate a line in text-mode
#
# To run (on Linux and x86):
#   $ git clone https://github.com/akkartik/mu
#   $ cd mu
#   $ ./translate_mu prototypes/tile/1.mu
#   $ ./a.elf
# You should see a line drawn on a blank screen. Press a key. You should see
# the line seem to fall down the screen. Press a second key to quit.
# https://archive.org/details/akkartik-2min-2020-07-01

fn main -> exit-status/ebx: int {
  clear-screen 0
  move-cursor 0, 5, 5
  print-string 0, "_________"
  enable-keyboard-immediate-mode
  var dummy/eax: grapheme <- read-key-from-real-keyboard
  var row/eax: int <- copy 5
  {
    compare row, 0xe  # 15
    break-if-=
    animate row
    row <- increment
    sleep 0 0x5f5e100  # 100ms
    loop
  }
  var dummy/eax: grapheme <- read-key-from-real-keyboard
  enable-keyboard-type-mode
  clear-screen 0
  exit-status <- copy 0
}

fn animate row: int {
  var col/eax: int <- copy 5
  {
    compare col, 0xe
    break-if-=
    move-cursor 0, row, col
    print-string 0, " "
    increment row
    move-cursor 0, row, col
    print-string 0, "_"
    decrement row
    col <- increment
    loop
  }
}