about summary refs log tree commit diff stats
path: root/html/086scenario_console_test.mu.html
Commit message (Collapse)AuthorAgeFilesLines
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-3/+4
|
* 3761Kartik K. Agaram2017-03-071-14/+15
|
* 3716Kartik K. Agaram2016-12-261-0/+2
| | | | Make hyperlinks less salient in the rendered html since there's so many of them.
* 3713 - cross-link calls with definitions in htmlKartik K. Agaram2016-12-261-4/+4
|
* 3710Kartik K. Agaram2016-12-261-25/+25
| | | | | Turns out we don't need to explicitly add anchors for each line. Vim's TOhtml has magic for that out of the box.
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-28/+52
| | | | | | Each line number also gets an anchor name, but I'm not hyperlinking them for now because I don't want to encourage bookmarking these links just yet. They aren't permalinks because every revision may change what's at any given line number.
* 3569Kartik K. Agaram2016-10-231-12/+12
| | | | Update syntax highlighting to not color numeric locations like literals.
* 3567Kartik K. Agaram2016-10-231-4/+4
|
* 3456Kartik K. Agaram2016-10-061-4/+4
|
* 3431Kartik K. Agaram2016-09-301-3/+2
| | | | | Improvements to syntax highlighting, particularly for Mu code in C++ files.
* 3430Kartik K. Agaram2016-09-281-1/+2
|
* 3395Kartik K. Agaram2016-09-171-4/+4
|
* 2866Kartik K. Agaram2016-04-251-4/+4
|
* 2812Kartik K. Agaram2016-03-271-7/+16
|
* 2745Kartik K. Agaram2016-03-091-1/+1
|
* 2744Kartik K. Agaram2016-03-091-1/+1
| | | | Tweak colors and font-sizes in generated html.
* 2743Kartik K. Agaram2016-03-091-16/+7
| | | | | Looks like "TOhtml | <other command>" doesn't work on Mac OS X for some reason..
* 2710Kartik K. Agaram2016-02-251-6/+0
|
* 2706 - update htmlKartik K. Agaram2016-02-251-0/+6
|
* 2605Kartik K. Agaram2016-01-261-4/+4
|
* 2430 - make room for more transformsKartik K. Agaram2015-11-131-0/+59
nt-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Return colors 'near' a given r/g/b value (expressed in hex)
# If we did this rigorously we'd need to implement cosines. So we won't.
#
# To build:
#   $ ./translate colors.mu
#
# Example session:
#   $ qemu-system-i386 code.img
#   Enter 3 hex bytes for r, g, b (lowercase; no 0x prefix) separated by a single space> aa 0 aa
#   5
# This means only color 5 in the default palette is similar to #aa00aa.

fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
  var in-storage: (stream byte 0x10)
  var in/esi: (addr stream byte) <- address in-storage
  {
    # print prompt
    var x/eax: int <- draw-text-rightward screen, "Enter 3 hex bytes for r, g, b (lowercase; no 0x prefix) separated by a single space> ", 0x10/x, 0x80/xmax, 0x28/y, 3/fg/cyan, 0/bg
    # read line from keyboard
    clear-stream in
    {
      draw-cursor screen, 0x20/space
      var key/eax: byte <- read-key keyboard
      compare key, 0xa/newline
      break-if-=
      compare key, 0
      loop-if-=
      var key2/eax: int <- copy key
      append-byte in, key2
      var g/eax: grapheme <- copy key2
      draw-grapheme-at-cursor screen, g, 0xf/fg, 0/bg
      move-cursor-right 0
      loop
    }
    clear-screen screen
    # parse
    var a/ecx: int <- copy 0
    var b/edx: int <- copy 0
    var c/ebx: int <- copy 0
    # a, b, c = r, g, b
    a, b, c <- parse in
#?     set-cursor-position screen, 0x10/x, 0x1a/y
#?     draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, a, 7/fg, 0/bg
#?     draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?     draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, b, 7/fg, 0/bg
#?     draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?     draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, c, 7/fg, 0/bg
    a, b, c <- hsl a, b, c
    # return all colors in the same quadrant in h, s and l
    print-nearby-colors screen, a, b, c
    # another metric
    var color/eax: int <- nearest-color-euclidean-hsl a, b, c
    set-cursor-position screen, 0x10/x, 0x26/y
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "nearest (euclidean, h/s/l): ", 0xf/fg, 0/bg
    draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, color, 7/fg, 0/bg
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 0xf/fg, 0/bg
    draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "               ", 0/fg, color
    #
    loop
  }
}

# read exactly 3 words in a single line
# Each word consists of exactly 1 or 2 hex bytes. No hex prefix.
fn parse in: (addr stream byte) -> _/ecx: int, _/edx: int, _/ebx: int {
  # read first byte of r
  var tmp/eax: byte <- read-byte in
  {
    var valid?/eax: boolean <- hex-digit? tmp
    compare valid?, 0/false
    break-if-!=
    abort "invalid byte 0 of r"
  }
  tmp <- fast-hex-digit-value tmp
  var r/ecx: int <- copy tmp
#?   set-cursor-position 0/screen, 0x10/x, 0x10/y
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, r, 7/fg, 0/bg
  # read second byte of r
  tmp <- read-byte in
  {
    {
      var valid?/eax: boolean <- hex-digit? tmp
      compare valid?, 0/false
    }
    break-if-=
    r <- shift-left 4
    tmp <- fast-hex-digit-value tmp
#?     {
#?       var foo/eax: int <- copy tmp
#?       set-cursor-position 0/screen, 0x10/x, 0x11/y
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 7/fg, 0/bg
#?     }
    r <- add tmp
#?     {
#?       set-cursor-position 0/screen, 0x10/x, 0x12/y
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, r, 7/fg, 0/bg
#?     }
    tmp <- read-byte in  # skip space
  }
  # read first byte of g
  var tmp/eax: byte <- read-byte in
  {
    var valid?/eax: boolean <- hex-digit? tmp
    compare valid?, 0/false
    break-if-!=
    abort "invalid byte 0 of g"
  }
  tmp <- fast-hex-digit-value tmp
  var g/edx: int <- copy tmp
#?   set-cursor-position 0/screen, 0x10/x, 0x13/y
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, g, 7/fg, 0/bg
  # read second byte of g
  tmp <- read-byte in
  {
    {
      var valid?/eax: boolean <- hex-digit? tmp
      compare valid?, 0/false
    }
    break-if-=
    g <- shift-left 4
    tmp <- fast-hex-digit-value tmp
#?     {
#?       var foo/eax: int <- copy tmp
#?       set-cursor-position 0/screen, 0x10/x, 0x14/y
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 7/fg, 0/bg
#?     }
    g <- add tmp
#?     {
#?       set-cursor-position 0/screen, 0x10/x, 0x15/y
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, g, 7/fg, 0/bg
#?     }
    tmp <- read-byte in  # skip space
  }
  # read first byte of b
  var tmp/eax: byte <- read-byte in
  {
    var valid?/eax: boolean <- hex-digit? tmp
    compare valid?, 0/false
    break-if-!=
    abort "invalid byte 0 of b"
  }
  tmp <- fast-hex-digit-value tmp
  var b/ebx: int <- copy tmp
#?   set-cursor-position 0/screen, 0x10/x, 0x16/y
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, b, 7/fg, 0/bg
  # read second byte of b
  {
    {
      var done?/eax: boolean <- stream-empty? in
      compare done?, 0/false
    }
    break-if-!=
    tmp <- read-byte in
    {
      var valid?/eax: boolean <- hex-digit? tmp
      compare valid?, 0/false
    }
    break-if-=
    b <- shift-left 4
    tmp <- fast-hex-digit-value tmp
#?     {
#?       var foo/eax: int <- copy tmp
#?       set-cursor-position 0/screen, 0x10/x, 0x17/y
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, foo, 7/fg, 0/bg
#?     }
    b <- add tmp
#?     {
#?       set-cursor-position 0/screen, 0x10/x, 0x18/y
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, b, 7/fg, 0/bg
#?     }
  }
  return r, g, b
}

# no error checking
fn fast-hex-digit-value in: byte -> _/eax: byte {
  var result/eax: byte <- copy in
  compare result, 0x39
  {
    break-if->
    result <- subtract 0x30/0
    return result
  }
  result <- subtract 0x61/a
  result <- add 0xa/10
  return result
}

fn print-nearby-colors screen: (addr screen), h: int, s: int, l: int {
#?   set-cursor-position screen, 0x10/x, 0x1c/y
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, h, 7/fg, 0/bg
#?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, s, 7/fg, 0/bg
#?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, l, 7/fg, 0/bg
  # save just top 2 bits of each, so that we narrow down to 1/64th of the volume
  shift-right h, 6
  shift-right s, 6
  shift-right l, 6
#?   set-cursor-position screen, 0x10/x, 0x1/y
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, h, 7/fg, 0/bg
#?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, s, 7/fg, 0/bg
#?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?   draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, l, 7/fg, 0/bg
  var a/ecx: int <- copy 0
  var b/edx: int <- copy 0
  var c/ebx: int <- copy 0
  var color/eax: int <- copy 0
  var y/esi: int <- copy 2
  {
    compare color, 0x100
    break-if->=
    a, b, c <- color-rgb color
    a, b, c <- hsl a, b, c
    a <- shift-right 6
    b <- shift-right 6
    c <- shift-right 6
    {
      compare a, h
      break-if-!=
      compare b, s
      break-if-!=
      compare c, l
      break-if-!=
      set-cursor-position screen, 0x10/x, y
      draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, color, 7/fg, 0/bg
      set-cursor-position screen, 0x14/x, y
      draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
      draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "               ", 0/fg, color
#?       draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, a, 7/fg, 0/bg
#?       draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, b, 7/fg, 0/bg
#?       draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, " ", 7/fg, 0/bg
#?       draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen, c, 7/fg, 0/bg
      y <- increment
    }
    color <- increment
    loop
  }
}