about summary refs log blame commit diff stats
path: root/html/071print.mu.html
blob: b70e75c983b46c463df3ba50aded8f845716bc9c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12



                                                                                          
                               






                                                                                         

                                                                                                 
                        
                             
                              
                               

                             
                            
                                  
                              













                                                                                                        




                      





                                
 
 
                                                      
                                           
                                                                          
                                                                                                                     
                                                                                                             
                                                                                                                   
                                                                                                              
                                                                                              




                                                                                                                        

                                                                                                                               
                                    
                                                            
 
 
                                                   
                                           
                                                                                                   

                                                               

                                            
                                                                
                                                    

                                                                                                            
                                                                                            
                                    
                                                                                            
                                                           




                                                                                                                                   
                                                                                                       
                                         
                                    




                                                                                                                  
                                                                              


                                                       
                                                                            
 
 



















                                                                                                                 
                                                      
                                           


                                                                                                                     

                                                         
                                                                

                                                                                                      






                                                                                                                           

                                              
                                                                                         
                                                                

                                                                                                  










                                                                                                                                           

                                                        
                                                                                                                             
                                                                                                         
                                                                  

                                                                         

                                                                                                                        
                                                                  



                                                                                                                                         
                                                                                
                                    
                                                                

                                                                                                   
                                                                                                            
                                                                                            


                                                                                                                      
                                                                    


                                                                                                                                                
                                                                

                                                                                                                                                    





                                                                                                                                          
                                      
                                                                                
                                    
                                                                                                                                                




                                                                                                                                      

                                                                                                

                                                                                                                     
                                                               
                                                                                                                                             
                                    
                                                                              

                                                       
                                                                       
                                                                            
 
 
                                                                      
       
                                                             
                                                                                                                                                                     
                                                                                                                                                                      












                                                                                                          
                                                                                                                                                                     


                                                                                                                                                                                 

                         

                                                                                       

                                                                              

   
 
                                                                    

                                                             


















                                                                                                                                                                           

                                                                                                                                                                           
                                                                                                                                                                           
                                                                                                

                                                                                                          




                                                                                          

                                                                                


   




















                                                                                                                                                                      
                                                                  

                                                             
                                                                                                                                                                     



                                                                                                                                                                      

                                                                                                          





                                                                                        

                                                                                


   












































                                                                                                                                                                       
                                                 
                                           
                                                                                                   

                                                                       
                                                                
                                                                                                  

                                                                                                                     
                                                             
                                                             
                                    
                                                                                                  

                                                                                                                    
                                                           
                                                                                                                                     
                                         

                                                                   
                                                                                              
                                                                              


                                                       
                                                                            
 
 
                                                      
                                           
                                                                                                   

                                                                          
                                                                

                                                                                                     
                                                                                                         
                                  
                                                                                         
                                                                                                       
 
 
                                                  
                                           


                                                                                                    

                                                                        
                                                                



                                                                                                                     
                                                                              

                                                       
                                                          
                                                                            
 
 
                                                                               

                                                             
                                                                                                                                                                     
                                                    
                                                                                                                                                                      
                                                               
                                                                                                                                                                                 

                                                                                   

                                                                                                          
   
                                                       
                         

                                                                                       
                                          
                                          
                                          
                                          






                                           

   
 
                                                  
                                           
                                                                                                   

                                                                        
                                                                
                                    
                                                         

                                                                                                                 

                                                                                                                   
                                                                
                                                
                                                                                                                                       
                                                                                                                                       
                                                                                                                                       
                                                               
                                    
                                                                              


                                                       
                                                                            
 
 
                                                
                                           
                                                                                                   

                                                                        
                                                                
                                    
                                                  
                                                                                                                 
                                                                                                                                          
                                                             
                                                
                                                                                                                                            
                                    
                                                                              


                                                       
                                                                            
 
 
                                                   
                                           
                                                                                                   

                                                                        
                                                                
                                    
                                                           

                                                                                                                       

                                                                                                                    
                                                                
                                                      
                                                                                                                                             
                                    
                                                                              


                                                       
                                                                            
 
 
                                                  
                                           
                                                                                                   

                                                                        
                                                                
                                    
                                                     
                                                                                                                       
                                                                                                                                             
                                                             
                                                      
                                                                                                                                                  
                                    
                                                                              


                                                       
                                                                            

 
                                                              
                                           
                                                                                                   


                                                                                                             
                                                                            

 
                                                          
                                           
                                                                                                   

                                                                                              
                                                                            

 
                                                   
                                           
                                                                                                   

                                                                        
                                                                
                                                                                                  
                                                     


                                                               
                                                   


                                                    
                                           
                                                                                                   

                                                                        
                                                                
                                                                                                
                                                      


                                                                 
                                                    

 
                                                  
                                           











                                                                                                   
                                           











                                                                                                   
                                           











                                                                                                   
                                           










                                                                                                   
                                                   
                                           


                                                                                                                     

                                                         
                                                                

                                                                                                      





                                                                                                                           



                                                                                          
                                                         
                                                                                                  
                                                                                
                                                                                                     
                                       
                                  
                                                                            

 



















                                                                                                                                                                     
                                                    
                                           


                                                                                                                     

                                                         
                                                                

                                                                                                      





                                                                                                                           

                                                                                                 
                                                                                         
                                                                            
 



                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 071print.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muRecipe { color: #ff8700; }
.Delimiter { color: #a04060; }
.muScenario { color: #00af00; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.muControl { color: #c0a020; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># Wrappers around print primitives that take a 'screen' object and are thus</span>
<span class="Comment"># easier to test.</span>

container screen [
  num-rows:number
  num-columns:number
  cursor-row:number
  cursor-column:number
  data:address:array:screen-cell
]

container screen-cell [
  contents:character
  color:number
]

<span class="muRecipe">recipe</span> new-fake-screen [
  <span class="Constant">local-scope</span>
  result:address:screen<span class="Special"> &lt;- </span>new screen:type
  width:address:number<span class="Special"> &lt;- </span>get-address result:address:screen/deref, num-columns:offset
  width:address:number/deref<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  height:address:number<span class="Special"> &lt;- </span>get-address result:address:screen/deref, num-rows:offset
  height:address:number/deref<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
<span class="CommentedCode">#?   $print height:address:number/deref, 10:literal/newline</span>
  row:address:number<span class="Special"> &lt;- </span>get-address result:address:screen/deref, cursor-row:offset
  row:address:number/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  column:address:number<span class="Special"> &lt;- </span>get-address result:address:screen/deref, cursor-column:offset
  column:address:number/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  bufsize:number<span class="Special"> &lt;- </span>multiply width:address:number/deref, height:address:number/deref
  buf:address:address:array:screen-cell<span class="Special"> &lt;- </span>get-address result:address:screen/deref, data:offset
  buf:address:address:array:screen-cell/deref<span class="Special"> &lt;- </span>new screen-cell:type, bufsize:number
  clear-screen result:address:screen
  <span class="muControl">reply</span> result:address:screen
]

<span class="muRecipe">recipe</span> clear-screen [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
<span class="CommentedCode">#?   $print [clearing screen</span>
<span class="CommentedCode">#? ] #? 1</span>
  <span class="Comment"># if x exists</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="Comment"># clear fake screen</span>
    buf:address:array:screen-cell<span class="Special"> &lt;- </span>get x:address:screen/deref, data:offset
    max:number<span class="Special"> &lt;- </span>length buf:address:array:screen-cell/deref
    i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
    <span class="Delimiter">{</span>
      done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i:number, max:number
      <span class="muControl">break-if</span> done?:boolean
      curr:address:screen-cell<span class="Special"> &lt;- </span>index-address buf:address:array:screen-cell/deref, i:number
      curr-content:address:character<span class="Special"> &lt;- </span>get-address curr:address:screen-cell/deref, contents:offset
      curr-content:address:character/deref<span class="Special"> &lt;- </span>copy <span class="Constant">[ ]</span>
      curr-color:address:character<span class="Special"> &lt;- </span>get-address curr:address:screen-cell/deref, color:offset
      curr-color:address:character/deref<span class="Special"> &lt;- </span>copy <span class="Constant">7:literal/white</span>
      i:number<span class="Special"> &lt;- </span>add i:number, <span class="Constant">1:literal</span>
      <span class="muControl">loop</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># reset cursor</span>
    cur:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-row:offset
    cur:address:number/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
    cur:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-column:offset
    cur:address:number/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  clear-display
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> fake-screen-is-clear? [
  <span class="Constant">local-scope</span>
  screen:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="muControl">reply-unless</span> screen:address:screen, <span class="Constant">1:literal/true</span>
  buf:address:array:screen-cell<span class="Special"> &lt;- </span>get screen:address:screen/deref, data:offset
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  len:number<span class="Special"> &lt;- </span>length buf:address:array:screen-cell/deref
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i:number, len:number
    <span class="muControl">break-if</span> done?:boolean
    curr:screen-cell<span class="Special"> &lt;- </span>index buf:address:array:screen-cell/deref, i:number
    curr-contents:character<span class="Special"> &lt;- </span>get curr:screen-cell, contents:offset
    i:number<span class="Special"> &lt;- </span>add i:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop-unless</span> curr-contents:character
    <span class="Comment"># not 0</span>
    <span class="muControl">reply</span> <span class="Constant">0:literal/false</span>
  <span class="Delimiter">}</span>
  <span class="muControl">reply</span> <span class="Constant">1:literal/true</span>
]

<span class="muRecipe">recipe</span> print-character [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  c:character<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">7:literal/white</span>
  <span class="Delimiter">}</span>
  bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default bg-color to black</span>
    <span class="muControl">break-if</span> bg-color-found?:boolean
    bg-color:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal/black</span>
  <span class="Delimiter">}</span>
<span class="CommentedCode">#?   trace [app], [print character] #? 1</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># if x exists</span>
    <span class="Comment"># (handle special cases exactly like in the real screen)</span>
    <span class="muControl">break-unless</span> x:address:screen
    width:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-columns:offset
    height:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-rows:offset
    <span class="Comment"># if cursor is out of bounds, silently exit</span>
    row:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-row:offset
    legal?:boolean<span class="Special"> &lt;- </span>greater-or-equal row:address:number/deref, <span class="Constant">0:literal</span>
    <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen
    legal?:boolean<span class="Special"> &lt;- </span>lesser-than row:address:number/deref, height:number
    <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen
    column:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-column:offset
    legal?:boolean<span class="Special"> &lt;- </span>greater-or-equal column:address:number/deref, <span class="Constant">0:literal</span>
    <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen
    legal?:boolean<span class="Special"> &lt;- </span>lesser-than column:address:number/deref, width:number
    <span class="muControl">reply-unless</span> legal?:boolean, x:address:screen
    <span class="Comment"># special-case: newline</span>
    <span class="Delimiter">{</span>
      newline?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">10:literal/newline</span>
<span class="CommentedCode">#?       $print c:character, [ ], newline?:boolean, 10:literal/newline</span>
      <span class="muControl">break-unless</span> newline?:boolean
      <span class="Delimiter">{</span>
        <span class="Comment"># unless cursor is already at bottom</span>
        bottom:number<span class="Special"> &lt;- </span>subtract height:number, <span class="Constant">1:literal</span>
        at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal row:address:number/deref, bottom:number
        <span class="muControl">break-if</span> at-bottom?:boolean
        <span class="Comment"># move it to the next row</span>
        column:address:number/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
        row:address:number/deref<span class="Special"> &lt;- </span>add row:address:number/deref, <span class="Constant">1:literal</span>
      <span class="Delimiter">}</span>
      <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
    <span class="Delimiter">}</span>
    <span class="Comment"># save character in fake screen</span>
    index:number<span class="Special"> &lt;- </span>multiply row:address:number/deref, width:number
    index:number<span class="Special"> &lt;- </span>add index:number, column:address:number/deref
    buf:address:array:screen-cell<span class="Special"> &lt;- </span>get x:address:screen/deref, data:offset
    len:number<span class="Special"> &lt;- </span>length buf:address:array:screen-cell/deref
    <span class="Comment"># special-case: backspace</span>
    <span class="Delimiter">{</span>
      backspace?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">8:literal</span>
      <span class="muControl">break-unless</span> backspace?:boolean
      <span class="Delimiter">{</span>
        <span class="Comment"># unless cursor is already at left margin</span>
        at-left?:boolean<span class="Special"> &lt;- </span>lesser-or-equal column:address:number/deref, <span class="Constant">0:literal</span>
        <span class="muControl">break-if</span> at-left?:boolean
        <span class="Comment"># clear previous location</span>
        column:address:number/deref<span class="Special"> &lt;- </span>subtract column:address:number/deref, <span class="Constant">1:literal</span>
        index:number<span class="Special"> &lt;- </span>subtract index:number, <span class="Constant">1:literal</span>
        cursor:address:screen-cell<span class="Special"> &lt;- </span>index-address buf:address:array:screen-cell/deref, index:number
        cursor-contents:address:character<span class="Special"> &lt;- </span>get-address cursor:address:screen-cell/deref, contents:offset
        cursor-color:address:number<span class="Special"> &lt;- </span>get-address cursor:address:screen-cell/deref, color:offset
        cursor-contents:address:character/deref<span class="Special"> &lt;- </span>copy <span class="Constant">32:literal/space</span>
        cursor-color:address:number/deref<span class="Special"> &lt;- </span>copy <span class="Constant">7:literal/white</span>
      <span class="Delimiter">}</span>
      <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
    <span class="Delimiter">}</span>
<span class="CommentedCode">#?     $print [saving character ], c:character, [ to fake screen ], cursor:address/screen, 10:literal/newline</span>
    cursor:address:screen-cell<span class="Special"> &lt;- </span>index-address buf:address:array:screen-cell/deref, index:number
    cursor-contents:address:character<span class="Special"> &lt;- </span>get-address cursor:address:screen-cell/deref, contents:offset
    cursor-color:address:number<span class="Special"> &lt;- </span>get-address cursor:address:screen-cell/deref, color:offset
    cursor-contents:address:character/deref<span class="Special"> &lt;- </span>copy c:character
    cursor-color:address:number/deref<span class="Special"> &lt;- </span>copy color:number
    <span class="Comment"># increment column unless it's already all the way to the right</span>
    <span class="Delimiter">{</span>
      right:number<span class="Special"> &lt;- </span>subtract width:number, <span class="Constant">1:literal</span>
      at-right?:boolean<span class="Special"> &lt;- </span>greater-or-equal column:address:number/deref, right:number
      <span class="muControl">break-if</span> at-right?:boolean
      column:address:number/deref<span class="Special"> &lt;- </span>add column:address:number/deref, <span class="Constant">1:literal</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  print-character-to-display c:character, color:number, bg-color:number
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muScenario">scenario</span> print-character-at-top-left [
  run [
<span class="CommentedCode">#?     $start-tracing #? 3</span>
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    2:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    3:array:screen-cell<span class="Special"> &lt;- </span>copy 2:address:array:screen-cell/deref
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    4<span class="Special"> &lt;- </span>97  <span class="Comment"># 'a'</span>
    5<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    6<span class="Special"> &lt;- </span>0
  ]
]

<span class="muScenario">scenario</span> print-character-color [
  run [
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal/a</span>, <span class="Constant">1:literal/red</span>
    2:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    3:array:screen-cell<span class="Special"> &lt;- </span>copy 2:address:array:screen-cell/deref
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    4<span class="Special"> &lt;- </span>97  <span class="Comment"># 'a'</span>
    5<span class="Special"> &lt;- </span>1  <span class="Comment"># red</span>
    6<span class="Special"> &lt;- </span>0
  ]
]

<span class="muScenario">scenario</span> print-backspace-character [
  run [
<span class="CommentedCode">#?     $start-tracing #? 3</span>
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">8:literal</span>  <span class="Comment"># backspace</span>
    2:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-column:offset
    3:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    4:array:screen-cell<span class="Special"> &lt;- </span>copy 3:address:array:screen-cell/deref
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>0  <span class="Comment"># cursor column</span>
    4<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    5<span class="Special"> &lt;- </span>32  <span class="Comment"># space, not 'a'</span>
    6<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    7<span class="Special"> &lt;- </span>0
  ]
]

<span class="muScenario">scenario</span> print-extra-backspace-character [
  run [
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">8:literal</span>  <span class="Comment"># backspace</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">8:literal</span>  <span class="Comment"># backspace</span>
    2:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-column:offset
    3:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    4:array:screen-cell<span class="Special"> &lt;- </span>copy 3:address:array:screen-cell/deref
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>0  <span class="Comment"># cursor column</span>
    4<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    5<span class="Special"> &lt;- </span>32  <span class="Comment"># space, not 'a'</span>
    6<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    7<span class="Special"> &lt;- </span>0
  ]
]

<span class="muScenario">scenario</span> print-at-right-margin [
  run [
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">2:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">98:literal</span>  <span class="Comment"># 'b'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">99:literal</span>  <span class="Comment"># 'c'</span>
    2:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-column:offset
    3:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    4:array:screen-cell<span class="Special"> &lt;- </span>copy 3:address:array:screen-cell/deref
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>1  <span class="Comment"># cursor column</span>
    4<span class="Special"> &lt;- </span>4  <span class="Comment"># width*height</span>
    5<span class="Special"> &lt;- </span>97  <span class="Comment"># 'a'</span>
    6<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    7<span class="Special"> &lt;- </span>99  <span class="Comment"># 'c' over 'b'</span>
    8<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    9<span class="Special"> &lt;- </span>0
  ]
]

<span class="muScenario">scenario</span> print-newline-character [
  run [
<span class="CommentedCode">#?     $start-tracing #? 3</span>
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span>
    2:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-row:offset
    3:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-column:offset
    4:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    5:array:screen-cell<span class="Special"> &lt;- </span>copy 4:address:array:screen-cell/deref
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>1  <span class="Comment"># cursor row</span>
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># cursor column</span>
    5<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    6<span class="Special"> &lt;- </span>97  <span class="Comment"># 'a'</span>
    7<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    8<span class="Special"> &lt;- </span>0
  ]
]

<span class="muScenario">scenario</span> print-newline-at-bottom-line [
  run [
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span>
    2:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-row:offset
    3:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-column:offset
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>1  <span class="Comment"># cursor row</span>
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># cursor column</span>
  ]
]

<span class="muScenario">scenario</span> print-at-bottom-right [
  run [
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">2:literal/width</span>, <span class="Constant">2:literal/height</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">98:literal</span>  <span class="Comment"># 'b'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">99:literal</span>  <span class="Comment"># 'c'</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">10:literal/newline</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">100:literal</span>  <span class="Comment"># 'd'</span>
    2:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-row:offset
    3:number<span class="Special"> &lt;- </span>get 1:address:screen/deref, cursor-column:offset
    4:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    5:array:screen-cell<span class="Special"> &lt;- </span>copy 4:address:array:screen-cell/deref
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>1  <span class="Comment"># cursor row</span>
    3<span class="Special"> &lt;- </span>1  <span class="Comment"># cursor column</span>
    5<span class="Special"> &lt;- </span>4  <span class="Comment"># width*height</span>
    6<span class="Special"> &lt;- </span>0  <span class="Comment"># unused</span>
    7<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    8<span class="Special"> &lt;- </span>0  <span class="Comment"># unused</span>
    9<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    10<span class="Special"> &lt;- </span>97 <span class="Comment"># 'a'</span>
    11<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    12<span class="Special"> &lt;- </span>100  <span class="Comment"># 'd' over 'b' and 'c' and newline</span>
    13<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    14<span class="Special"> &lt;- </span>0
  ]
]

<span class="muRecipe">recipe</span> clear-line [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, clear line in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    width:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-columns:offset
    column:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-column:offset
    original-column:number<span class="Special"> &lt;- </span>copy column:address:number/deref
    <span class="Comment"># space over the entire line</span>
<span class="CommentedCode">#?     $start-tracing #? 1</span>
    <span class="Delimiter">{</span>
<span class="CommentedCode">#?       $print column:address:number/deref, 10:literal/newline</span>
      right:number<span class="Special"> &lt;- </span>subtract width:number, <span class="Constant">1:literal</span>
      done?:boolean<span class="Special"> &lt;- </span>greater-or-equal column:address:number/deref, right:number
      <span class="muControl">break-if</span> done?:boolean
      print-character x:address:screen, <span class="Constant">[ ]</span>  <span class="Comment"># implicitly updates 'column'</span>
      <span class="muControl">loop</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># now back to where the cursor was</span>
    column:address:number/deref<span class="Special"> &lt;- </span>copy original-column:number
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  clear-line-on-display
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> cursor-position [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, lookup cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    row:number<span class="Special"> &lt;- </span>get x:address:screen/deref, cursor-row:offset
    column:number<span class="Special"> &lt;- </span>get x:address:screen/deref, cursor-column:offset
    <span class="muControl">reply</span> row:number, column:number, x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  row:number, column:number<span class="Special"> &lt;- </span>cursor-position-on-display
  <span class="muControl">reply</span> row:number, column:number, x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> move-cursor [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  new-row:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  new-column:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    row:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-row:offset
    row:address:number/deref<span class="Special"> &lt;- </span>copy new-row:number
    column:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-column:offset
    column:address:number/deref<span class="Special"> &lt;- </span>copy new-column:number
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-on-display new-row:number, new-column:number
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muScenario">scenario</span> clear-line-erases-printed-characters [
  run [
<span class="CommentedCode">#?     $start-tracing #? 4</span>
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    <span class="Comment"># print a character</span>
    1:address:screen<span class="Special"> &lt;- </span>print-character 1:address:screen, <span class="Constant">97:literal</span>  <span class="Comment"># 'a'</span>
    <span class="Comment"># move cursor to start of line</span>
    1:address:screen<span class="Special"> &lt;- </span>move-cursor 1:address:screen, <span class="Constant">0:literal/row</span>, <span class="Constant">0:literal/column</span>
    <span class="Comment"># clear line</span>
    1:address:screen<span class="Special"> &lt;- </span>clear-line 1:address:screen
    2:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    3:array:screen-cell<span class="Special"> &lt;- </span>copy 2:address:array:screen-cell/deref
  ]
  <span class="Comment"># screen should be blank</span>
  memory-should-contain [
    3<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    4<span class="Special"> &lt;- </span>0
    5<span class="Special"> &lt;- </span>7
    6<span class="Special"> &lt;- </span>0
    7<span class="Special"> &lt;- </span>7
    8<span class="Special"> &lt;- </span>0
    9<span class="Special"> &lt;- </span>7
    10<span class="Special"> &lt;- </span>0
    11<span class="Special"> &lt;- </span>7
    12<span class="Special"> &lt;- </span>0
    13<span class="Special"> &lt;- </span>7
    14<span class="Special"> &lt;- </span>0
    15<span class="Special"> &lt;- </span>7
  ]
]

<span class="muRecipe">recipe</span> cursor-down [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="Delimiter">{</span>
      <span class="Comment"># if row &lt; height-1</span>
      height:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-rows:offset
      row:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-row:offset
      max:number<span class="Special"> &lt;- </span>subtract height:number, <span class="Constant">1:literal</span>
      at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal row:address:number/deref, max:number
      <span class="muControl">break-if</span> at-bottom?:boolean
      <span class="Comment"># row = row+1</span>
<span class="CommentedCode">#?       $print [AAA: ], row:address:number, [ -&gt; ], row:address:number/deref, 10:literal/newline</span>
      row:address:number/deref<span class="Special"> &lt;- </span>add row:address:number/deref, <span class="Constant">1:literal</span>
<span class="CommentedCode">#?       $print [BBB: ], row:address:number, [ -&gt; ], row:address:number/deref, 10:literal/newline</span>
<span class="CommentedCode">#?       $start-tracing #? 1</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-down-on-display
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> cursor-up [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="Delimiter">{</span>
      <span class="Comment"># if row &gt; 0</span>
      row:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-row:offset
      at-top?:boolean<span class="Special"> &lt;- </span>lesser-or-equal row:address:number/deref, <span class="Constant">0:literal</span>
      <span class="muControl">break-if</span> at-top?:boolean
      <span class="Comment"># row = row-1</span>
      row:address:number/deref<span class="Special"> &lt;- </span>subtract row:address:number/deref, <span class="Constant">1:literal</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-up-on-display
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> cursor-right [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="Delimiter">{</span>
      <span class="Comment"># if column &lt; width-1</span>
      width:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-columns:offset
      column:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-column:offset
      max:number<span class="Special"> &lt;- </span>subtract width:number, <span class="Constant">1:literal</span>
      at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal column:address:number/deref, max:number
      <span class="muControl">break-if</span> at-bottom?:boolean
      <span class="Comment"># column = column+1</span>
      column:address:number/deref<span class="Special"> &lt;- </span>add column:address:number/deref, <span class="Constant">1:literal</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-right-on-display
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> cursor-left [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="Delimiter">{</span>
      <span class="Comment"># if column &gt; 0</span>
      column:address:number<span class="Special"> &lt;- </span>get-address x:address:screen/deref, cursor-column:offset
      at-top?:boolean<span class="Special"> &lt;- </span>lesser-or-equal column:address:number/deref, <span class="Constant">0:literal</span>
      <span class="muControl">break-if</span> at-top?:boolean
      <span class="Comment"># column = column-1</span>
      column:address:number/deref<span class="Special"> &lt;- </span>subtract column:address:number/deref, <span class="Constant">1:literal</span>
    <span class="Delimiter">}</span>
    <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  move-cursor-left-on-display
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> cursor-to-start-of-line [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  row:number, _, x:address:screen<span class="Special"> &lt;- </span>cursor-position x:address:screen
  column:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  x:address:screen<span class="Special"> &lt;- </span>move-cursor x:address:screen, row:number, column:number
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> cursor-to-next-line [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  x:address:screen<span class="Special"> &lt;- </span>cursor-down x:address:screen
  x:address:screen<span class="Special"> &lt;- </span>cursor-to-start-of-line x:address:screen
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muRecipe">recipe</span> screen-width [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    width:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-columns:offset
    <span class="muControl">reply</span> width:number
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  width:number<span class="Special"> &lt;- </span>display-width
  <span class="muControl">reply</span> width:number
]

<span class="muRecipe">recipe</span> screen-height [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists, move cursor in fake screen</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    height:number<span class="Special"> &lt;- </span>get x:address:screen/deref, num-rows:offset
    <span class="muControl">reply</span> height:number
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  height:number<span class="Special"> &lt;- </span>display-height
  <span class="muControl">reply</span> height:number
]

<span class="muRecipe">recipe</span> hide-cursor [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="muControl">reply</span> x:address:screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  hide-cursor-on-display
  <span class="muControl">reply</span> x:address:screen
]

<span class="muRecipe">recipe</span> show-cursor [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="muControl">reply</span> x:address:screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  show-cursor-on-display
  <span class="muControl">reply</span> x:address:screen
]

<span class="muRecipe">recipe</span> hide-screen [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="muControl">reply</span> x:address:screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  hide-display
  <span class="muControl">reply</span> x:address:screen
]

<span class="muRecipe">recipe</span> show-screen [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if x exists (not real display), do nothing</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-unless</span> x:address:screen
    <span class="muControl">reply</span> x:address:screen
  <span class="Delimiter">}</span>
  <span class="Comment"># otherwise, real screen</span>
  show-display
  <span class="muControl">reply</span> x:address:screen
]

<span class="muRecipe">recipe</span> print-string [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  s:address:array:character<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">7:literal/white</span>
  <span class="Delimiter">}</span>
  bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default bg-color to black</span>
    <span class="muControl">break-if</span> bg-color-found?:boolean
    bg-color:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal/black</span>
  <span class="Delimiter">}</span>
  len:number<span class="Special"> &lt;- </span>length s:address:array:character/deref
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  <span class="Delimiter">{</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i:number, len:number
    <span class="muControl">break-if</span> done?:boolean
    c:character<span class="Special"> &lt;- </span>index s:address:array:character/deref, i:number
    print-character x:address:screen, c:character, color:number, bg-color:number
    i:number<span class="Special"> &lt;- </span>add i:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]

<span class="muScenario">scenario</span> print-string-stops-at-right-margin [
  run [
    1:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3:literal/width</span>, <span class="Constant">2:literal/height</span>
    2:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcd]</span>
    1:address:screen<span class="Special"> &lt;- </span>print-string 1:address:screen, 2:address:array:character
    3:address:array:screen-cell<span class="Special"> &lt;- </span>get 1:address:screen/deref, data:offset
    4:array:screen-cell<span class="Special"> &lt;- </span>copy 3:address:array:screen-cell/deref
  ]
  memory-should-contain [
    4<span class="Special"> &lt;- </span>6  <span class="Comment"># width*height</span>
    5<span class="Special"> &lt;- </span>97  <span class="Comment"># 'a'</span>
    6<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    7<span class="Special"> &lt;- </span>98  <span class="Comment"># 'b'</span>
    8<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    9<span class="Special"> &lt;- </span>100  <span class="Comment"># 'd' overwrites 'c'</span>
    10<span class="Special"> &lt;- </span>7  <span class="Comment"># white</span>
    11<span class="Special"> &lt;- </span>0  <span class="Comment"># unused</span>
  ]
]

<span class="muRecipe">recipe</span> print-integer [
  <span class="Constant">local-scope</span>
  x:address:screen<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  n:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">7:literal/white</span>
  <span class="Delimiter">}</span>
  bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default bg-color to black</span>
    <span class="muControl">break-if</span> bg-color-found?:boolean
    bg-color:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal/black</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># todo: other bases besides decimal</span>
  s:address:array:character<span class="Special"> &lt;- </span>integer-to-decimal-string n:number
  print-string x:address:screen, s:address:array:character, color:number, bg-color:number
  <span class="muControl">reply</span> x:address:screen/same-as-ingredient:0
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->