about summary refs log blame commit diff stats
path: root/linux/texture.mu
blob: 8178424bd867cbd37ed1e3c7596b7b00aa6d50d5 (plain) (tree)
e170b35d ^




<
# example program: read a character from one file and write it to another
# BEWARE: this will modify your file system
# before running it, put a character into /tmp/mu-x
# after running it, check /tmp/mu-y

def main [
  local-scope
  f:num/file <- $open-file-for-reading [/tmp/mu-x]
  $print [file to read from: ], f, 10/newline
  c:char, eof?:bool <- $read-from-file f
  $print [copying ], c, 10/newline
  f <- $close-file f
  $print [file after closing: ], f, 10/newline
  f <- $open-file-for-writing [/tmp/mu-y]
  $print [file to write to: ], f, 10/newline
  $write-to-file f, c
  f <- $close-file f
]
>

                     
                         


                         

                                       
         

                         

                     

                                       





                      
          
 
# Playing with emitting cool textures.
#
# To run (on Linux):
#   $ git clone https://github.com/akkartik/mu
#   $ cd mu
#   $ ./translate texture.mu
#   $ ./a.elf > a.ppm

fn main -> _/ebx: int {
#?   var width/esi: int <- copy 0x190  # 400
#?   var height/edi: int <- copy 0xe1  # 225; aspect ratio 16:9
  var width/esi: int <- copy 0xff
  var height/edi: int <- copy 0xff
  print-string 0/screen, "P3\n"
  print-int32-decimal 0/screen, width
  print-string 0/screen, " "
  print-int32-decimal 0/screen, height
  print-string 0/screen, "\n"
  print-string 0/screen, "255\n"  # color depth
  var row/ecx: int <- copy 0
  {
    compare row, height
    break-if->=
    var col/edx: int <- copy 0
    {
      compare col, width
      break-if->=
      # r
      var tmp/eax: int <- copy col
      tmp <- multiply row
      tmp <- and 0x7f
      tmp <- add 0x80
      tmp <- copy 0xff
      print-int32-decimal 0/screen, tmp
      print-string 0/screen, " "
      # g
      tmp <- copy row
      tmp <- multiply col
      tmp <- and 0x7f
      tmp <- add 0x80
#?       tmp <- copy 0xcf
      print-int32-decimal 0/screen, tmp
      print-string 0/screen, " "
      # b
      tmp <- copy row
      tmp <- multiply col
      tmp <- and 0x7f
      tmp <- add 0x80
      print-int32-decimal 0/screen, tmp
      print-string 0/screen, "\n"
      col <- increment
      loop
    }
    row <- increment
    loop
  }
  return 0
}