about summary refs log tree commit diff stats
path: root/relayout
blob: e5f9a164f649c035ec529095cc9e1965714dbbe4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env zsh
# Helper to change the numerical prefixes across the repo, say if you want to
# create room between 023 and 024, and so on.
#
# Assumes there's only ever one file with any numeric prefix. If you move
# 003trace.tests you might need to do some manual patch-up.

setopt extendedglob

if [[ $# -eq 0 && `git diff HEAD |wc -l` -gt 0 ]]
then
  echo "Uncommitted changes"
  exit
fi

if [[ $# -gt 0 ]] # dry run
then
  git() {
    echo $*
  }
fi

#

index=0
ls [0-9]* |grep -v "trace.test" |sort -n |
  while read file
  do
    echo $file >&2
    while [[ $file != `printf "%03d" $index`* ]]
    do
      echo
      index=$(($index+1))
    done
    echo $file
    index=$(($index+1))
  done > .layout

vim -c "set nu" .layout

#

root() {
  echo $1 |perl -pwe 's/^[0-9]*//'
}

index=0
cat .layout |
  while read file
  do
    if [ ! -z $file ]
    then
      newfile=`printf "%03d" $index``root $file`
      if [[ $newfile != $file ]]
      then
        git mv $file $newfile
      fi
    fi
    index=$(($index+1))
  done

#

rm .layout
.subx?h=main&id=20d6be52405130930fde9ca5bb5e95131ba4e659'>^
dbf434f0 ^
7f8770ae ^



dbf434f0 ^
7f8770ae ^



7363c6df ^
7f8770ae ^

6e36ce06 ^
6ce43fce ^
7f8770ae ^
7363c6df ^

6ce43fce ^
7f8770ae ^













6ce43fce ^
7f8770ae ^









44131682 ^
6e36ce06 ^
44131682 ^



121a9eba ^

6ce43fce ^
44131682 ^




63be7b7d ^
422ebaf8 ^




121a9eba ^
6e36ce06 ^
121a9eba ^
6e36ce06 ^
121a9eba ^
6ce43fce ^
422ebaf8 ^






cec5ef31 ^
63be7b7d ^



f0ef1ca2 ^
cec5ef31 ^
63be7b7d ^








cec5ef31 ^
63be7b7d ^







44131682 ^

121a9eba ^
63be7b7d ^


cec5ef31 ^
63be7b7d ^






121a9eba ^
63be7b7d ^

121a9eba ^
44131682 ^
121a9eba ^
44131682 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173


                                                                             
                                  



                                                                             


       


                                                          

                                                                          
                                                                                               









                                     
                            
                                     
                                  

                                                                                            
                                                         
                               
                               

                                     
                               
                                     

                                  
                                

                               
                                    
                                                  
                                       
                                 
                               
                                
                                       



                                                
                                 



                                                        
                                                 

                                       
                                                      
                                                              
         

                                                    
                                       













                          
                                  









                         
 
                                                            



                                                                                

                                         
                                    




                        
                                                     




                        
     
                            
                                         
                              
                                         
                                        






                         
                                     



                                                                            
                                                                             
                                          








                                                         
                                







                         

       
                                                               


                                                                             
                                                    






                                                                                
 

                                                                            
                     
         
                     
         
# Use the built-in font to draw a grapheme to real screen.
#
# We need to do this in machine code because Mu doesn't have global variables
# yet (for the start of the font).
#
# There are uncomfortable assumptions baked in here about english/latin
# script. We convert the grid of pixels into a fixed-width grid of graphemes,
# which may not work well with other language families.

== code

# The Mu computer's screen is 1024px wide and 768px tall.
# The Mu computer's font is 8px wide and 16px tall.
# Therefore 'x' here is in [0, 128), and 'y' is in [0, 48)
# Doesn't update the cursor; where the cursor should go after printing the
# current grapheme is a higher-level concern.
draw-grapheme-on-real-screen:  # g: grapheme, x: int, y: int, color: int, background-color: int
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    51/push-ecx
    52/push-edx
    53/push-ebx
    56/push-esi
    # var letter-bitmap/esi = font[g]
    8b/-> *(ebp+8) 6/r32/esi
    c1 4/subop/shift-left %esi 4/imm8
    81 0/subop/add %esi Font/imm32
    # if (letter-bitmap >= 0x9400) return  # characters beyond ASCII currently not supported
    81 7/subop/compare %esi 0x9400/imm32
    7d/jump-if->= $draw-grapheme-on-real-screen:end/disp8
    # var ycurr/edx: int = y*16
    8b/-> *(ebp+0x10) 2/r32/edx
    c1 4/subop/shift-left %edx 4/imm8
    # var ymax/ebx: int = ycurr + 16
    8b/-> *(ebp+0x10) 3/r32/ebx
    c1 4/subop/shift-left %ebx 4/imm8
    81 0/subop/add %ebx 0x10/imm32
    {
      # if (ycurr >= ymax) break
      39/compare %edx 3/r32/ebx
      7d/jump-if->= break/disp8
      # var xcurr/eax: int = x*8 + 7
      8b/-> *(ebp+0xc) 0/r32/eax  # font-width - 1
      c1 4/subop/shift-left %eax 3/imm8
      81 0/subop/add %eax 7/imm32
      # var xmin/ecx: int = x*8
      8b/-> *(ebp+0xc) 1/r32/ecx
      c1 4/subop/shift-left %ecx 3/imm8
      # var row-bitmap/ebx: int = *letter-bitmap
      53/push-ebx
      8b/-> *esi 3/r32/ebx
      {
        # if (xcurr < xmin) break
        39/compare %eax 1/r32/ecx
        7c/jump-if-< break/disp8
        # shift LSB from row-bitmap into carry flag (CF)
        c1 5/subop/shift-right-logical %ebx 1/imm8
        # if LSB, draw a pixel in the given color
        {
          73/jump-if-not-CF break/disp8
          (pixel-on-real-screen %eax %edx *(ebp+0x14))
          eb/jump $draw-grapheme-on-real-screen:continue/disp8
        }
        # otherwise use the background color
        (pixel-on-real-screen %eax %edx *(ebp+0x18))
$draw-grapheme-on-real-screen:continue:
        # --x
        48/decrement-eax
        #
        eb/jump loop/disp8
      }
      # reclaim row-bitmap
      5b/pop-to-ebx
      # ++y
      42/increment-edx
      # next bitmap row
      46/increment-esi
      #
      eb/jump loop/disp8
    }
$draw-grapheme-on-real-screen:end:
    # . restore registers
    5e/pop-to-esi
    5b/pop-to-ebx
    5a/pop-to-edx
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

cursor-position-on-real-screen:  # -> _/eax: int, _/ecx: int
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # TODO: support fake screen; we currently assume 'screen' is always 0 (real)
    8b/-> *Real-screen-cursor-x 0/r32/eax
    8b/-> *Real-screen-cursor-y 1/r32/ecx
$cursor-position-on-real-screen:end:
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

set-cursor-position-on-real-screen:  # x: int, y: int
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    #
    8b/-> *(ebp+8) 0/r32/eax
    89/<- *Real-screen-cursor-x 0/r32/eax
    8b/-> *(ebp+0xc) 0/r32/eax
    89/<- *Real-screen-cursor-y 0/r32/eax
$set-cursor-position-on-real-screen:end:
    # . restore registers
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

# Not a real `show-cursor` primitive:
#   - does not clear previous location cursor was shown at.
#   - does not preserve what was at the cursor. Caller is responsible for
#     tracking what was on the screen at this position before and passing it
#     in again.
#   - does not stop showing the cursor at this location when the cursor moves
draw-cursor-on-real-screen:  # g: grapheme
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    51/push-ecx
    #
    (cursor-position-on-real-screen)  # => eax, ecx
    (draw-grapheme-on-real-screen *(ebp+8) %eax %ecx 0 7)
$draw-cursor-on-real-screen:end:
    # . restore registers
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

== data

# The cursor is where certain Mu functions (usually of the form
# 'draw*cursor*') print to by default.
#
# We don't bother displaying the cursor when drawing. It only becomes visible
# on draw-cursor, which is quite rickety (see above)
#
# It's up to applications to manage cursor display:
#   - clean up where it used to be
#   - display the cursor before waiting for a key
#   - ensure its location appropriately suggests the effect keystrokes will have
#   - ensure its contents (and colors) appropriately reflect the state of the
#     screen
#
# There's no blinking, etc. We aren't using any hardware-supported text mode
# here.
Real-screen-cursor-x:
  0/imm32
Real-screen-cursor-y:
  0/imm32