about summary refs log tree commit diff stats
path: root/apps/ex15.mu
blob: 570704d63ce37feae84baff35f443e40b463db38 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Demo of combining-character support in Mu, which can be summarized as, "the
# old typewriter-based approach of backing up one character and adding the
# accent or _matra_ in."
#   https://en.wikipedia.org/wiki/Combining_character
#
# Mu uses this approach for both accents in Latin languages and vowel
# diacritics in Abugida scripts.
#   https://en.wikipedia.org/wiki/Diacritic
#   https://en.wikipedia.org/wiki/Abugida
#
# Steps for trying it out:
#   1. Translate this example into a disk image code.img.
#       ./translate apps/ex15.mu
#   2. Run:
#       qemu-system-i386 -hda code.img -hdb data.img
#
# Expected output, showing off what this approach can and cannot do:
#   'à' in green in a few places near the top-left corner of screen, with
#   other letters nearby showing cases where characters blend to the eye.
#
#   A few Devanagari letter combinations. Devanagari works well except for
#   characters blending together.
#
#   A few Tamil letter combinations. Tamil often doesn't look right, and
#   requires ligatures for many letter combinations.
#
#   Others? (Patches welcome.) I suspect Tibetan in particular will not work
#   well with this approach. But I need native readers to assess quality.

fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
  # at the top of screen, the accent is almost cropped
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x61/a,                       0/x 0/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0300/combining-grave-accent,  0/x 0/y, 3/fg 0/bg

  # below a code-point-utf8 with a descender, the accent uglily overlaps
  #   https://en.wikipedia.org/wiki/Descender
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x67/g,                       4/x 3/y, 3/fg 0/bg
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x61/a,                       4/x 4/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0300/combining-grave-accent,  4/x 4/y, 3/fg 0/bg

  # beside a code-point-utf8 with a descender, it becomes more obvious that monowidth fonts can't make baselines line up
  #   https://en.wikipedia.org/wiki/Baseline_(typography)
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x67/g,                       8/x 3/y, 3/fg 0/bg
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x61/a,                       9/x 3/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0300/combining-grave-accent,  9/x 3/y, 3/fg 0/bg

  # a single devanagari letter combined with different vowel _matras_
  # ka
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 4/x 8/y, 3/fg 0/bg
  # kaa
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 7/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x093e/devanagari-vowel-aa, 7/x 8/y, 3/fg 0/bg
  # ki
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xa/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x093f/devanagari-vowel-i, 0xa/x 8/y, 3/fg 0/bg
  # kee
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xd/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0940/devanagari-vowel-ii, 0xd/x 8/y, 3/fg 0/bg
  # ku
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x10/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0941/devanagari-vowel-u, 0x10/x 8/y, 3/fg 0/bg
  # koo
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x13/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0942/devanagari-vowel-oo, 0x13/x 8/y, 3/fg 0/bg
  # kay
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 4/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0947/devanagari-vowel-E, 4/x 9/y, 3/fg 0/bg
  # kai
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 7/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0948/devanagari-vowel-ai, 7/x 9/y, 3/fg 0/bg
  # ko
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xa/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x094b/devanagari-vowel-o, 0xa/x 9/y, 3/fg 0/bg
  # kow
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xd/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x094f/devanagari-vowel-aw, 0xd/x 9/y, 3/fg 0/bg
  # kan
  # bump this letter down to show the letter without overlap; we've already established above that overlap is an issue
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x10/x 0xa/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0902/devanagari-anusvara, 0x10/x 0xa/y, 3/fg 0/bg
  # kaha
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x13/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0903/devanagari-visarga, 0x13/x 9/y, 3/fg 0/bg

  # render the same devanagari letters as a single stream of utf-8 code-point-utf8s rather than individual code-points.
  var text-storage: (stream byte 0x200)
  var text/esi: (addr stream byte) <- address text-storage
  var g/eax: code-point-utf8 <- to-utf8 0x0915/devanagari-letter-ka
  var ka/ecx: code-point-utf8 <- copy g
  # ka
  write-code-point-utf8 text, ka
  # kaa
  write-code-point-utf8 text, ka
  g <- to-utf8 0x093e/devanagari-vowel-aa
  write-code-point-utf8 text, g
  # ki
  write-code-point-utf8 text, ka
  g <- to-utf8 0x093f/devanagari-vowel-i
  write-code-point-utf8 text, g
  # kee
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0940/devanagari-vowel-ii
  write-code-point-utf8 text, g
  # ku
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0941/devanagari-vowel-u
  write-code-point-utf8 text, g
  # koo
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0942/devanagari-vowel-oo
  write-code-point-utf8 text, g
  # kay
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0947/devanagari-vowel-E
  write-code-point-utf8 text, g
  # kai
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0948/devanagari-vowel-ai
  write-code-point-utf8 text, g
  # ko
  write-code-point-utf8 text, ka
  g <- to-utf8 0x094b/devanagari-vowel-o
  write-code-point-utf8 text, g
  # kow
  write-code-point-utf8 text, ka
  g <- to-utf8 0x094f/devanagari-vowel-aw
  write-code-point-utf8 text, g
  # kan
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0902/devanagari-anusvara
  write-code-point-utf8 text, g
  # kaha
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0903/devanagari-visarga
  write-code-point-utf8 text, g
  # render everything
  set-cursor-position screen, 4/x 0xe/y
  draw-stream-wrapping-right-then-down-from-cursor-over-full-screen screen, text, 3/fg 0/bg

  # a stream of tamil code-point-utf8s (with interspersed spaces for clarity) that don't look the same in Mu
  set-cursor-position 0, 4/x 0x12/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "எ ஃ கு ", 3/fg 0/bg
  set-cursor-position 0, 4/x 0x13/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "அ ன் று ", 3/fg 0/bg
  set-cursor-position 0, 4/x 0x14/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "அ தா வ து " , 3/fg 0/bg
  set-cursor-position 0, 4/x 0x15/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "அ ஃ தா ன் று ", 3/fg 0/bg
}