https://github.com/akkartik/mu/blob/main/shell/main.mu
1
2
3
4 fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
5 var globals-storage: global-table
6 var globals/edi: (addr global-table) <- address globals-storage
7 initialize-globals globals
8 var sandbox-storage: sandbox
9 var sandbox/esi: (addr sandbox) <- address sandbox-storage
10 initialize-sandbox sandbox, 1/with-screen
11 load-sandbox data-disk, sandbox
12 {
13 render-globals screen, globals, 0/x, 0/y, 0x40/xmax, 0x2f/screen-height-without-menu
14 render-sandbox screen, sandbox, 0x40/x, 0/y, 0x80/screen-width, 0x2f/screen-height-without-menu, globals
15 {
16 var key/eax: byte <- read-key keyboard
17 compare key, 0
18 loop-if-=
19
20 edit-sandbox sandbox, key, globals, screen, keyboard, data-disk
21 }
22 loop
23 }
24 }
25
26
27
28 fn load-sandbox data-disk: (addr disk), _self: (addr sandbox) {
29 var self/esi: (addr sandbox) <- copy _self
30 var s-storage: (stream byte 0x200)
31 var s/ebx: (addr stream byte) <- address s-storage
32 load-sector data-disk, 0/lba, s
33 {
34 var done?/eax: boolean <- stream-empty? s
35 compare done?, 0/false
36 break-if-!=
37 var key/eax: byte <- read-byte s
38 compare key, 0/null
39 break-if-=
40 edit-sandbox self, key, 0/no-globals, 0/no-screen, 0/no-keyboard, 0/no-disk
41 loop
42 }
43 }