about summary refs log tree commit diff stats
path: root/prototypes/tile/4.mu
blob: bd2bd77c53050257c36f0fecc0e196f1768c942c (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
48
49
50
51
52
53
54
55
56
# animate a large box
#
# To run (on Linux and x86):
#   $ git clone https://github.com/akkartik/mu
#   $ cd mu
#   $ ./translate_mu prototypes/tile/4.mu
#   $ ./a.elf

fn main -> exit-status/ebx: int {
  clear-screen 0
  enable-keyboard-immediate-mode
  var dummy/eax: byte <- read-key
  draw-box 5, 5, 0x23, 0x23  # 35, 35
  sleep 0 0x5f5e100  # 100ms
  sleep 0 0x5f5e100  # 100ms
  draw-box 5, 5, 0x23, 0x69  # 35, 105
  sleep 0 0x5f5e100  # 100ms
  sleep 0 0x5f5e100  # 100ms
  draw-box 5, 5, 0x23, 0xaf  # 35, 175
  var dummy/eax: byte <- read-key
  enable-keyboard-type-mode
  clear-screen 0
  exit-status <- copy 0
}

fn draw-box row1: int, col1: int, row2: int, col2: int {
  clear-screen 0
  draw-horizontal-line row1, col1, col2
  draw-vertical-line row1, row2, col1
  draw-horizontal-line row2, col1, col2
  draw-vertical-line row1, row2, col2
}

fn draw-horizontal-line row: int, col1: int, col2: int {
  var col/eax: int <- copy col1
  move-cursor 0, row, col
  {
    compare col, col2
    break-if->=
    print-string 0, "-"
    col <- increment
    loop
  }
}

fn draw-vertical-line row1: int, row2: int, col: int {
  var row/eax: int <- copy row1
  {
    compare row, row2
    break-if->=
    move-cursor 0, row, col
    print-string 0, "|"
    row <- increment
    loop
  }
}