From 775f77c3346d231fc6133de2c7da2bb1e8ef0c2e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 29 Nov 2020 13:36:32 -0800 Subject: 7306 --- html/apps/tile/surface.mu.html | 626 ++++++++++++++++++++--------------------- 1 file changed, 312 insertions(+), 314 deletions(-) (limited to 'html/apps/tile/surface.mu.html') diff --git a/html/apps/tile/surface.mu.html b/html/apps/tile/surface.mu.html index f1b84f8c..33ab2637 100644 --- a/html/apps/tile/surface.mu.html +++ b/html/apps/tile/surface.mu.html @@ -81,10 +81,10 @@ if ('onhashchange' in window) { 21 fn initialize-surface-with _self: (addr surface), in: (addr array byte) { 22 var self/esi: (addr surface) <- copy _self 23 # fill in nrows, ncols - 24 var nrows/ecx: int <- num-lines in + 24 var nrows/ecx: int <- num-lines in 25 var dest/eax: (addr int) <- get self, nrows 26 copy-to *dest, nrows - 27 var ncols/edx: int <- first-line-length in # assume all lines are the same length + 27 var ncols/edx: int <- first-line-length in # assume all lines are the same length 28 dest <- get self, ncols 29 copy-to *dest, ncols 30 # fill in data @@ -94,7 +94,7 @@ if ('onhashchange' in window) { 34 var data/eax: (addr handle array screen-cell) <- get out, data 35 populate data, len 36 var data-addr/eax: (addr array screen-cell) <- lookup *data - 37 fill-in data-addr, in + 37 fill-in data-addr, in 38 # fill in screen-nrows, screen-ncols 39 { 40 var screen-ah/eax: (addr handle screen) <- get self, screen @@ -160,318 +160,316 @@ if ('onhashchange' in window) { 100 } 101 102 fn print-surface-cell-at _self: (addr surface), screen-row: int, screen-col: int { -103 $print-surface-cell-at:body: { -104 var self/esi: (addr surface) <- copy _self -105 var row/ecx: int <- screen-row-to-surface self, screen-row -106 var col/edx: int <- screen-col-to-surface self, screen-col -107 var data-ah/edi: (addr handle array screen-cell) <- get self, data -108 var _data-addr/eax: (addr array screen-cell) <- lookup *data-ah -109 var data-addr/edi: (addr array screen-cell) <- copy _data-addr -110 var idx/eax: int <- surface-screen-cell-index self, row, col -111 # if out of bounds, print ' ' -112 compare idx, 0 -113 { -114 break-if->= -115 var space/ecx: grapheme <- copy 0x20 -116 var screen-ah/edi: (addr handle screen) <- get self, screen -117 var screen/eax: (addr screen) <- lookup *screen-ah -118 print-grapheme screen, space -119 break $print-surface-cell-at:body -120 } -121 # otherwise print the appropriate screen-cell -122 var offset/ecx: (offset screen-cell) <- compute-offset data-addr, idx -123 var src/ecx: (addr screen-cell) <- index data-addr, offset -124 var screen-ah/edi: (addr handle screen) <- get self, screen -125 var screen/eax: (addr screen) <- lookup *screen-ah -126 print-screen-cell screen, src -127 } -128 } -129 -130 # print a cell with all its formatting at the cursor location -131 fn print-screen-cell screen: (addr screen), _cell: (addr screen-cell) { -132 var cell/esi: (addr screen-cell) <- copy _cell -133 reset-formatting screen -134 var fg/eax: (addr int) <- get cell, color -135 var bg/ecx: (addr int) <- get cell, background-color -136 start-color screen, *fg, *bg -137 var tmp/eax: (addr boolean) <- get cell, bold? -138 { -139 compare *tmp, 0 -140 break-if-= -141 start-bold screen -142 } -143 { -144 tmp <- get cell, underline? -145 compare *tmp, 0 -146 break-if-= -147 start-underline screen -148 } -149 { -150 tmp <- get cell, reverse? -151 compare *tmp, 0 -152 break-if-= -153 start-reverse-video screen -154 } -155 { -156 tmp <- get cell, blink? -157 compare *tmp, 0 -158 break-if-= -159 start-blinking screen -160 } -161 var g/eax: (addr grapheme) <- get cell, data -162 print-grapheme screen, *g -163 #? var g2/eax: grapheme <- copy *g -164 #? var g3/eax: int <- copy g2 -165 #? print-int32-hex-to-real-screen g3 -166 #? print-string-to-real-screen "\n" -167 } -168 -169 fn surface-screen-cell-index _self: (addr surface), row: int, col: int -> _/eax: int { -170 var self/esi: (addr surface) <- copy _self -171 #? print-int32-hex-to-real-screen row -172 #? print-string-to-real-screen ", " -173 #? print-int32-hex-to-real-screen col -174 #? print-string-to-real-screen "\n" -175 var result/eax: int <- copy -1 -176 { -177 compare row, 1 +103 var self/esi: (addr surface) <- copy _self +104 var row/ecx: int <- screen-row-to-surface self, screen-row +105 var col/edx: int <- screen-col-to-surface self, screen-col +106 var data-ah/edi: (addr handle array screen-cell) <- get self, data +107 var _data-addr/eax: (addr array screen-cell) <- lookup *data-ah +108 var data-addr/edi: (addr array screen-cell) <- copy _data-addr +109 var idx/eax: int <- surface-screen-cell-index self, row, col +110 # if out of bounds, print ' ' +111 compare idx, 0 +112 { +113 break-if->= +114 var space/ecx: grapheme <- copy 0x20 +115 var screen-ah/edi: (addr handle screen) <- get self, screen +116 var screen/eax: (addr screen) <- lookup *screen-ah +117 print-grapheme screen, space +118 return +119 } +120 # otherwise print the appropriate screen-cell +121 var offset/ecx: (offset screen-cell) <- compute-offset data-addr, idx +122 var src/ecx: (addr screen-cell) <- index data-addr, offset +123 var screen-ah/edi: (addr handle screen) <- get self, screen +124 var screen/eax: (addr screen) <- lookup *screen-ah +125 print-screen-cell screen, src +126 } +127 +128 # print a cell with all its formatting at the cursor location +129 fn print-screen-cell screen: (addr screen), _cell: (addr screen-cell) { +130 var cell/esi: (addr screen-cell) <- copy _cell +131 reset-formatting screen +132 var fg/eax: (addr int) <- get cell, color +133 var bg/ecx: (addr int) <- get cell, background-color +134 start-color screen, *fg, *bg +135 var tmp/eax: (addr boolean) <- get cell, bold? +136 { +137 compare *tmp, 0 +138 break-if-= +139 start-bold screen +140 } +141 { +142 tmp <- get cell, underline? +143 compare *tmp, 0 +144 break-if-= +145 start-underline screen +146 } +147 { +148 tmp <- get cell, reverse? +149 compare *tmp, 0 +150 break-if-= +151 start-reverse-video screen +152 } +153 { +154 tmp <- get cell, blink? +155 compare *tmp, 0 +156 break-if-= +157 start-blinking screen +158 } +159 var g/eax: (addr grapheme) <- get cell, data +160 print-grapheme screen, *g +161 #? var g2/eax: grapheme <- copy *g +162 #? var g3/eax: int <- copy g2 +163 #? print-int32-hex-to-real-screen g3 +164 #? print-string-to-real-screen "\n" +165 } +166 +167 fn surface-screen-cell-index _self: (addr surface), row: int, col: int -> _/eax: int { +168 var self/esi: (addr surface) <- copy _self +169 #? print-int32-hex-to-real-screen row +170 #? print-string-to-real-screen ", " +171 #? print-int32-hex-to-real-screen col +172 #? print-string-to-real-screen "\n" +173 var result/eax: int <- copy -1 +174 { +175 compare row, 1 +176 break-if-< +177 compare col, 1 178 break-if-< -179 compare col, 1 -180 break-if-< -181 var nrows-addr/ecx: (addr int) <- get self, nrows -182 var nrows/ecx: int <- copy *nrows-addr -183 compare row, nrows -184 break-if-> -185 var ncols-addr/ecx: (addr int) <- get self, ncols -186 var ncols/ecx: int <- copy *ncols-addr -187 compare col, ncols -188 break-if-> -189 #? print-string-to-real-screen "!\n" -190 result <- copy row -191 result <- subtract 1 -192 result <- multiply ncols -193 result <- add col -194 result <- subtract 1 -195 } -196 return result -197 } -198 -199 fn screen-row-to-surface _self: (addr surface), screen-row: int -> _/ecx: int { -200 var self/esi: (addr surface) <- copy _self -201 var result/ecx: int <- copy screen-row -202 var tmp/eax: (addr int) <- get self, pin-row -203 result <- add *tmp -204 tmp <- get self, pin-screen-row -205 result <- subtract *tmp -206 return result -207 } -208 -209 fn max _a: int, b: int -> _/eax: int { -210 var a/eax: int <- copy _a -211 compare a, b -212 { -213 break-if-> -214 return b -215 } -216 return a -217 } -218 -219 fn min _a: int, b: int -> _/eax: int { -220 var a/eax: int <- copy _a -221 compare a, b -222 { -223 break-if-> -224 return a -225 } -226 return b -227 } -228 -229 fn screen-col-to-surface _self: (addr surface), screen-col: int -> _/edx: int { -230 var self/esi: (addr surface) <- copy _self -231 var result/edx: int <- copy screen-col -232 var tmp/eax: (addr int) <- get self, pin-col -233 result <- add *tmp -234 tmp <- get self, pin-screen-col -235 result <- subtract *tmp -236 return result -237 } -238 -239 fn surface-row-to-screen _self: (addr surface), row: int -> _/ecx: int { -240 var self/esi: (addr surface) <- copy _self -241 var result/ecx: int <- copy row -242 var tmp/eax: (addr int) <- get self, pin-screen-row -243 result <- add *tmp -244 tmp <- get self, pin-row -245 result <- subtract *tmp -246 return result -247 } -248 -249 fn surface-col-to-screen _self: (addr surface), col: int -> _/edx: int { -250 var self/esi: (addr surface) <- copy _self -251 var result/edx: int <- copy col -252 var tmp/eax: (addr int) <- get self, pin-screen-col -253 result <- add *tmp -254 tmp <- get self, pin-col -255 result <- subtract *tmp -256 return result -257 } -258 -259 # assumes last line doesn't end in '\n' -260 fn num-lines in: (addr array byte) -> _/ecx: int { -261 var s: (stream byte 0x100) -262 var s-addr/esi: (addr stream byte) <- address s -263 write s-addr, in -264 var result/ecx: int <- copy 1 -265 { -266 var done?/eax: boolean <- stream-empty? s-addr -267 compare done?, 0 # false -268 break-if-!= -269 var g/eax: grapheme <- read-grapheme s-addr -270 compare g, 0xa # newline -271 loop-if-!= -272 result <- increment -273 loop -274 } -275 return result -276 } -277 -278 fn first-line-length in: (addr array byte) -> _/edx: int { -279 var s: (stream byte 0x100) -280 var s-addr/esi: (addr stream byte) <- address s -281 write s-addr, in -282 var result/edx: int <- copy 0 -283 { -284 var done?/eax: boolean <- stream-empty? s-addr -285 compare done?, 0 # false -286 break-if-!= -287 var g/eax: grapheme <- read-grapheme s-addr -288 compare g, 0xa # newline -289 break-if-= -290 result <- increment -291 loop -292 } -293 return result -294 } -295 -296 fn fill-in _out: (addr array screen-cell), in: (addr array byte) { -297 var s: (stream byte 0x100) -298 var out/edi: (addr array screen-cell) <- copy _out -299 var s-addr/esi: (addr stream byte) <- address s -300 write s-addr, in -301 var idx/ecx: int <- copy 0 -302 { -303 var done?/eax: boolean <- stream-empty? s-addr -304 compare done?, 0 # false -305 break-if-!= -306 var g/eax: grapheme <- read-grapheme s-addr -307 compare g, 0xa # newline -308 loop-if-= -309 var offset/edx: (offset screen-cell) <- compute-offset out, idx -310 var dest/edx: (addr screen-cell) <- index out, offset -311 var dest2/edx: (addr grapheme) <- get dest, data -312 copy-to *dest2, g -313 idx <- increment -314 loop -315 } -316 } -317 -318 # pin (1, 1) to (1, 1) on screen -319 fn test-surface-pin-at-origin { -320 var s: surface -321 var s-addr/esi: (addr surface) <- address s -322 # surface contents are a fixed grid with 8 rows and 6 columns -323 # (strip vowels second time around to break vertical alignment of letters) -324 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" -325 pin-surface-at s-addr, 1, 1 # surface row and column -326 pin-surface-to s-addr, 1, 1 # screen row and column -327 render-surface s-addr -328 var screen-ah/eax: (addr handle screen) <- get s-addr, screen -329 var screen-addr/eax: (addr screen) <- lookup *screen-ah -330 check-screen-row screen-addr, 1, "abcd", "F - test-surface-pin-at-origin" -331 check-screen-row screen-addr, 2, "ghij", "F - test-surface-pin-at-origin" -332 check-screen-row screen-addr, 3, "mnop", "F - test-surface-pin-at-origin" -333 } -334 -335 # pin (1, 1) to (2, 1) on screen; screen goes past edge of the universe -336 fn test-surface-pin-2 { -337 var s: surface -338 var s-addr/esi: (addr surface) <- address s -339 # surface contents are a fixed grid with 8 rows and 6 columns -340 # (strip vowels second time around to break vertical alignment of letters) -341 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" -342 pin-surface-at s-addr, 1, 1 # surface row and column -343 pin-surface-to s-addr, 2, 1 # screen row and column -344 render-surface s-addr -345 var screen-ah/eax: (addr handle screen) <- get s-addr, screen -346 var screen-addr/eax: (addr screen) <- lookup *screen-ah -347 # surface edge reached (should seldom happen in the app) -348 check-screen-row screen-addr, 1, " ", "F - test-surface-pin-2" -349 check-screen-row screen-addr, 2, "abcd", "F - test-surface-pin-2" -350 check-screen-row screen-addr, 3, "ghij", "F - test-surface-pin-2" -351 } -352 -353 # pin (2, 1) to (1, 1) on screen -354 fn test-surface-pin-3 { -355 var s: surface -356 var s-addr/esi: (addr surface) <- address s -357 # surface contents are a fixed grid with 8 rows and 6 columns -358 # (strip vowels second time around to break vertical alignment of letters) -359 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" -360 pin-surface-at s-addr, 2, 1 # surface row and column -361 pin-surface-to s-addr, 1, 1 # screen row and column -362 render-surface s-addr -363 var screen-ah/eax: (addr handle screen) <- get s-addr, screen -364 var screen-addr/eax: (addr screen) <- lookup *screen-ah -365 check-screen-row screen-addr, 1, "ghij", "F - test-surface-pin-3" -366 check-screen-row screen-addr, 2, "mnop", "F - test-surface-pin-3" -367 check-screen-row screen-addr, 3, "stuv", "F - test-surface-pin-3" -368 } -369 -370 # pin (1, 1) to (1, 2) on screen; screen goes past edge of the universe -371 fn test-surface-pin-4 { -372 var s: surface -373 var s-addr/esi: (addr surface) <- address s -374 # surface contents are a fixed grid with 8 rows and 6 columns -375 # (strip vowels second time around to break vertical alignment of letters) -376 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" -377 pin-surface-at s-addr, 1, 1 # surface row and column -378 pin-surface-to s-addr, 1, 2 # screen row and column -379 render-surface s-addr -380 var screen-ah/eax: (addr handle screen) <- get s-addr, screen -381 var screen-addr/eax: (addr screen) <- lookup *screen-ah -382 # surface edge reached (should seldom happen in the app) -383 check-screen-row screen-addr, 1, " abc", "F - test-surface-pin-4" -384 check-screen-row screen-addr, 2, " ghi", "F - test-surface-pin-4" -385 check-screen-row screen-addr, 3, " mno", "F - test-surface-pin-4" -386 } -387 -388 # pin (1, 2) to (1, 1) on screen -389 fn test-surface-pin-5 { -390 var s: surface -391 var s-addr/esi: (addr surface) <- address s -392 # surface contents are a fixed grid with 8 rows and 6 columns -393 # (strip vowels second time around to break vertical alignment of letters) -394 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" -395 pin-surface-at s-addr, 1, 2 # surface row and column -396 pin-surface-to s-addr, 1, 1 # screen row and column -397 render-surface s-addr -398 var screen-ah/eax: (addr handle screen) <- get s-addr, screen -399 var screen-addr/eax: (addr screen) <- lookup *screen-ah -400 check-screen-row screen-addr, 1, "bcde", "F - test-surface-pin-5" -401 check-screen-row screen-addr, 2, "hijk", "F - test-surface-pin-5" -402 check-screen-row screen-addr, 3, "nopq", "F - test-surface-pin-5" -403 } -404 -405 fn initialize-surface-with-fake-screen _self: (addr surface), nrows: int, ncols: int, in: (addr array byte) { -406 var self/esi: (addr surface) <- copy _self -407 # fill in screen -408 var screen-ah/eax: (addr handle screen) <- get self, screen -409 allocate screen-ah -410 var screen-addr/eax: (addr screen) <- lookup *screen-ah -411 initialize-screen screen-addr, nrows, ncols -412 # fill in everything else -413 initialize-surface-with self, in -414 } +179 var nrows-addr/ecx: (addr int) <- get self, nrows +180 var nrows/ecx: int <- copy *nrows-addr +181 compare row, nrows +182 break-if-> +183 var ncols-addr/ecx: (addr int) <- get self, ncols +184 var ncols/ecx: int <- copy *ncols-addr +185 compare col, ncols +186 break-if-> +187 #? print-string-to-real-screen "!\n" +188 result <- copy row +189 result <- subtract 1 +190 result <- multiply ncols +191 result <- add col +192 result <- subtract 1 +193 } +194 return result +195 } +196 +197 fn screen-row-to-surface _self: (addr surface), screen-row: int -> _/ecx: int { +198 var self/esi: (addr surface) <- copy _self +199 var result/ecx: int <- copy screen-row +200 var tmp/eax: (addr int) <- get self, pin-row +201 result <- add *tmp +202 tmp <- get self, pin-screen-row +203 result <- subtract *tmp +204 return result +205 } +206 +207 fn max _a: int, b: int -> _/eax: int { +208 var a/eax: int <- copy _a +209 compare a, b +210 { +211 break-if-> +212 return b +213 } +214 return a +215 } +216 +217 fn min _a: int, b: int -> _/eax: int { +218 var a/eax: int <- copy _a +219 compare a, b +220 { +221 break-if-> +222 return a +223 } +224 return b +225 } +226 +227 fn screen-col-to-surface _self: (addr surface), screen-col: int -> _/edx: int { +228 var self/esi: (addr surface) <- copy _self +229 var result/edx: int <- copy screen-col +230 var tmp/eax: (addr int) <- get self, pin-col +231 result <- add *tmp +232 tmp <- get self, pin-screen-col +233 result <- subtract *tmp +234 return result +235 } +236 +237 fn surface-row-to-screen _self: (addr surface), row: int -> _/ecx: int { +238 var self/esi: (addr surface) <- copy _self +239 var result/ecx: int <- copy row +240 var tmp/eax: (addr int) <- get self, pin-screen-row +241 result <- add *tmp +242 tmp <- get self, pin-row +243 result <- subtract *tmp +244 return result +245 } +246 +247 fn surface-col-to-screen _self: (addr surface), col: int -> _/edx: int { +248 var self/esi: (addr surface) <- copy _self +249 var result/edx: int <- copy col +250 var tmp/eax: (addr int) <- get self, pin-screen-col +251 result <- add *tmp +252 tmp <- get self, pin-col +253 result <- subtract *tmp +254 return result +255 } +256 +257 # assumes last line doesn't end in '\n' +258 fn num-lines in: (addr array byte) -> _/ecx: int { +259 var s: (stream byte 0x100) +260 var s-addr/esi: (addr stream byte) <- address s +261 write s-addr, in +262 var result/ecx: int <- copy 1 +263 { +264 var done?/eax: boolean <- stream-empty? s-addr +265 compare done?, 0 # false +266 break-if-!= +267 var g/eax: grapheme <- read-grapheme s-addr +268 compare g, 0xa # newline +269 loop-if-!= +270 result <- increment +271 loop +272 } +273 return result +274 } +275 +276 fn first-line-length in: (addr array byte) -> _/edx: int { +277 var s: (stream byte 0x100) +278 var s-addr/esi: (addr stream byte) <- address s +279 write s-addr, in +280 var result/edx: int <- copy 0 +281 { +282 var done?/eax: boolean <- stream-empty? s-addr +283 compare done?, 0 # false +284 break-if-!= +285 var g/eax: grapheme <- read-grapheme s-addr +286 compare g, 0xa # newline +287 break-if-= +288 result <- increment +289 loop +290 } +291 return result +292 } +293 +294 fn fill-in _out: (addr array screen-cell), in: (addr array byte) { +295 var s: (stream byte 0x100) +296 var out/edi: (addr array screen-cell) <- copy _out +297 var s-addr/esi: (addr stream byte) <- address s +298 write s-addr, in +299 var idx/ecx: int <- copy 0 +300 { +301 var done?/eax: boolean <- stream-empty? s-addr +302 compare done?, 0 # false +303 break-if-!= +304 var g/eax: grapheme <- read-grapheme s-addr +305 compare g, 0xa # newline +306 loop-if-= +307 var offset/edx: (offset screen-cell) <- compute-offset out, idx +308 var dest/edx: (addr screen-cell) <- index out, offset +309 var dest2/edx: (addr grapheme) <- get dest, data +310 copy-to *dest2, g +311 idx <- increment +312 loop +313 } +314 } +315 +316 # pin (1, 1) to (1, 1) on screen +317 fn test-surface-pin-at-origin { +318 var s: surface +319 var s-addr/esi: (addr surface) <- address s +320 # surface contents are a fixed grid with 8 rows and 6 columns +321 # (strip vowels second time around to break vertical alignment of letters) +322 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" +323 pin-surface-at s-addr, 1, 1 # surface row and column +324 pin-surface-to s-addr, 1, 1 # screen row and column +325 render-surface s-addr +326 var screen-ah/eax: (addr handle screen) <- get s-addr, screen +327 var screen-addr/eax: (addr screen) <- lookup *screen-ah +328 check-screen-row screen-addr, 1, "abcd", "F - test-surface-pin-at-origin" +329 check-screen-row screen-addr, 2, "ghij", "F - test-surface-pin-at-origin" +330 check-screen-row screen-addr, 3, "mnop", "F - test-surface-pin-at-origin" +331 } +332 +333 # pin (1, 1) to (2, 1) on screen; screen goes past edge of the universe +334 fn test-surface-pin-2 { +335 var s: surface +336 var s-addr/esi: (addr surface) <- address s +337 # surface contents are a fixed grid with 8 rows and 6 columns +338 # (strip vowels second time around to break vertical alignment of letters) +339 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" +340 pin-surface-at s-addr, 1, 1 # surface row and column +341 pin-surface-to s-addr, 2, 1 # screen row and column +342 render-surface s-addr +343 var screen-ah/eax: (addr handle screen) <- get s-addr, screen +344 var screen-addr/eax: (addr screen) <- lookup *screen-ah +345 # surface edge reached (should seldom happen in the app) +346 check-screen-row screen-addr, 1, " ", "F - test-surface-pin-2" +347 check-screen-row screen-addr, 2, "abcd", "F - test-surface-pin-2" +348 check-screen-row screen-addr, 3, "ghij", "F - test-surface-pin-2" +349 } +350 +351 # pin (2, 1) to (1, 1) on screen +352 fn test-surface-pin-3 { +353 var s: surface +354 var s-addr/esi: (addr surface) <- address s +355 # surface contents are a fixed grid with 8 rows and 6 columns +356 # (strip vowels second time around to break vertical alignment of letters) +357 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" +358 pin-surface-at s-addr, 2, 1 # surface row and column +359 pin-surface-to s-addr, 1, 1 # screen row and column +360 render-surface s-addr +361 var screen-ah/eax: (addr handle screen) <- get s-addr, screen +362 var screen-addr/eax: (addr screen) <- lookup *screen-ah +363 check-screen-row screen-addr, 1, "ghij", "F - test-surface-pin-3" +364 check-screen-row screen-addr, 2, "mnop", "F - test-surface-pin-3" +365 check-screen-row screen-addr, 3, "stuv", "F - test-surface-pin-3" +366 } +367 +368 # pin (1, 1) to (1, 2) on screen; screen goes past edge of the universe +369 fn test-surface-pin-4 { +370 var s: surface +371 var s-addr/esi: (addr surface) <- address s +372 # surface contents are a fixed grid with 8 rows and 6 columns +373 # (strip vowels second time around to break vertical alignment of letters) +374 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" +375 pin-surface-at s-addr, 1, 1 # surface row and column +376 pin-surface-to s-addr, 1, 2 # screen row and column +377 render-surface s-addr +378 var screen-ah/eax: (addr handle screen) <- get s-addr, screen +379 var screen-addr/eax: (addr screen) <- lookup *screen-ah +380 # surface edge reached (should seldom happen in the app) +381 check-screen-row screen-addr, 1, " abc", "F - test-surface-pin-4" +382 check-screen-row screen-addr, 2, " ghi", "F - test-surface-pin-4" +383 check-screen-row screen-addr, 3, " mno", "F - test-surface-pin-4" +384 } +385 +386 # pin (1, 2) to (1, 1) on screen +387 fn test-surface-pin-5 { +388 var s: surface +389 var s-addr/esi: (addr surface) <- address s +390 # surface contents are a fixed grid with 8 rows and 6 columns +391 # (strip vowels second time around to break vertical alignment of letters) +392 initialize-surface-with-fake-screen s-addr, 3, 4, "abcdef\nghijkl\nmnopqr\nstuvwx\nyzabcd\nfghjkl\nmnpqrs\ntvwxyz" +393 pin-surface-at s-addr, 1, 2 # surface row and column +394 pin-surface-to s-addr, 1, 1 # screen row and column +395 render-surface s-addr +396 var screen-ah/eax: (addr handle screen) <- get s-addr, screen +397 var screen-addr/eax: (addr screen) <- lookup *screen-ah +398 check-screen-row screen-addr, 1, "bcde", "F - test-surface-pin-5" +399 check-screen-row screen-addr, 2, "hijk", "F - test-surface-pin-5" +400 check-screen-row screen-addr, 3, "nopq", "F - test-surface-pin-5" +401 } +402 +403 fn initialize-surface-with-fake-screen _self: (addr surface), nrows: int, ncols: int, in: (addr array byte) { +404 var self/esi: (addr surface) <- copy _self +405 # fill in screen +406 var screen-ah/eax: (addr handle screen) <- get self, screen +407 allocate screen-ah +408 var screen-addr/eax: (addr screen) <- lookup *screen-ah +409 initialize-screen screen-addr, nrows, ncols +410 # fill in everything else +411 initialize-surface-with self, in +412 } -- cgit 1.4.1-2-gfad0