about summary refs log tree commit diff stats
path: root/baremetal/103grapheme.subx
blob: 4ee423d72d32a8d6670ab23c2158e06b9473b678 (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
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
# Use the built-in font to draw a grapheme to real screen.
#
# We need to do this in machine code because Mu doesn't have global variables
# yet (for the start of video memory).

== code

draw-grapheme-on-real-screen:  # g: grapheme, x: int, y: int, color: int
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    51/push-ecx
    52/push-edx
    53/push-ebx
    56/push-esi
    # var letter-bitmap/esi = font[g]
    8b/-> *(ebp+8) 6/r32/esi
    c1 4/subop/shift-left %esi 4/imm8
    8d/copy-address *(esi+0x8800) 6/r32/esi  # font-start
    # if (letter-bitmap >= 0x9000) return  # characters beyond ASCII currently not supported
    81 7/subop/compare %esi 0x9000/imm32
    7d/jump-if->= $draw-grapheme:end/disp8
    # edx = y
    8b/-> *(ebp+0x10) 2/r32/edx
    # var ymax/ebx: int = y + 16
    8b/-> *(ebp+0x10) 3/r32/ebx
    81 0/subop/add %ebx 0x10/imm32
    {
      # if (y >= ymax) break
      39/compare %edx 3/r32/ebx
      7d/jump-if->= break/disp8
      # eax = x + 7
      8b/-> *(ebp+0xc) 0/r32/eax
      81 0/subop/add %eax 7/imm32
      # var xmin/ecx: int = x
      8b/-> *(ebp+0xc) 1/r32/ecx
      # var row-bitmap/ebx: int = *letter-bitmap
      53/push-ebx
      8b/-> *esi 3/r32/ebx
      {
        # if (x < xmin) break
        39/compare %eax 1/r32/ecx
        7c/jump-if-< break/disp8
        # shift LSB from row-bitmap into carry flag (CF)
        c1 5/subop/shift-right-logical %ebx 1/imm8
        # if LSB, draw a pixel
        {
          73/jump-if-not-CF break/disp8
          (pixel-on-real-screen %eax %edx *(ebp+0x14))
        }
        # --x
        48/decrement-eax
        #
        eb/jump loop/disp8
      }
      # reclaim row-bitmap
      5b/pop-to-ebx
      # ++y
      42/increment-edx
      # next bitmap row
      46/increment-esi
      #
      eb/jump loop/disp8
    }
$draw-grapheme:end:
    # . restore registers
    5e/pop-to-esi
    5b/pop-to-ebx
    5a/pop-to-edx
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

cursor-position-on-real-screen:  # -> _/eax: int, _/ecx: int
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # TODO: support fake screen; we currently assume 'screen' is always 0 (real)
    8b/-> *Default-next-x 0/r32/eax
    8b/-> *Default-next-y 1/r32/ecx
$cursor-position:end:
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

set-cursor-position-on-real-screen:  # x: int, y: int
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    # TODO: support fake screen; we currently assume 'screen' is always 0 (real)
    8b/-> *(ebp+8) 0/r32/eax
    89/<- *Default-next-x 0/r32/eax
    8b/-> *(ebp+0xc) 0/r32/eax
    89/<- *Default-next-y 0/r32/eax
$set-cursor-position:end:
    # . restore registers
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

== data

Default-next-x:
  0/imm32

Default-next-y:
  0/imm32