https://github.com/akkartik/mu/blob/main/linux/apps/texture.mu
 1 # Playing with emitting cool textures.
 2 #
 3 # To run (on Linux):
 4 #   $ git clone https://github.com/akkartik/mu
 5 #   $ cd mu
 6 #   $ ./translate apps/texture.mu
 7 #   $ ./a.elf > a.ppm
 8 
 9 fn main -> _/ebx: int {
10 #?   var width/esi: int <- copy 0x190  # 400
11 #?   var height/edi: int <- copy 0xe1  # 225; aspect ratio 16:9
12   var width/esi: int <- copy 0xff
13   var height/edi: int <- copy 0xff
14   print-string 0/screen, "P3\n"
15   print-int32-decimal 0/screen, width
16   print-string 0/screen, " "
17   print-int32-decimal 0/screen, height
18   print-string 0/screen, "\n"
19   print-string 0/screen, "255\n"  # color depth
20   var row/ecx: int <- copy 0
21   {
22     compare row, height
23     break-if->=
24     var col/edx: int <- copy 0
25     {
26       compare col, width
27       break-if->=
28       # r
29       var tmp/eax: int <- copy col
30       tmp <- multiply row
31       tmp <- and 0x7f
32       tmp <- add 0x80
33       tmp <- copy 0xff
34       print-int32-decimal 0/screen, tmp
35       print-string 0/screen, " "
36       # g
37       tmp <- copy row
38       tmp <- multiply col
39       tmp <- and 0x7f
40       tmp <- add 0x80
41 #?       tmp <- copy 0xcf
42       print-int32-decimal 0/screen, tmp
43       print-string 0/screen, " "
44       # b
45       tmp <- copy row
46       tmp <- multiply col
47       tmp <- and 0x7f
48       tmp <- add 0x80
49       print-int32-decimal 0/screen, tmp
50       print-string 0/screen, "\n"
51       col <- increment
52       loop
53     }
54     row <- increment
55     loop
56   }
57   return 0
58 }