diff options
-rw-r--r-- | chessboard-graphic.mu | 195 | ||||
-rw-r--r-- | graphics.mu | 7 | ||||
-rw-r--r-- | mu.arc | 47 |
3 files changed, 221 insertions, 28 deletions
diff --git a/chessboard-graphic.mu b/chessboard-graphic.mu index fd66c852..19607e89 100644 --- a/chessboard-graphic.mu +++ b/chessboard-graphic.mu @@ -53,7 +53,165 @@ (reply result:file-address cursor:list-address) ]) -(function print-board [ +;; data structure: sprite +(and-record sprite [ + width:integer + height:integer + data:integer-array-address +]) + +(address sprite-address (sprite)) + +(function read-sprite [ + (default-space:space-address <- new space:literal 30:literal) + (print-primitive ((" init-list\n" literal))) +(q-pbm:list-address <- init-list + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 0:literal 0:literal + 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal + 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal + 0:literal 2:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 2:literal 0:literal + 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 1:literal 2:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 2:literal 1:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 2:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 2:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 0:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 2:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 1:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 2:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal + 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal 0:literal) + (print-primitive ((" init-list done\n" literal))) +;? (pbm:list-address <- next-input) + (result:sprite-address <- new sprite:literal) + (w:integer-address <- get-address result:sprite-address/deref width:offset) + (w:integer-address/deref <- copy 40:literal) + (print-primitive w:integer-address/deref) + (h:integer-address <- get-address result:sprite-address/deref height:offset) + (h:integer-address/deref <- copy 40:literal) + (print-primitive h:integer-address/deref) + (capacity:integer <- multiply w:integer-address/deref h:integer-address/deref) + (buf:integer-array-address-address <- get-address result:sprite-address/deref data:offset) + (print-primitive ((" list-to-array\n" literal))) + (buf:integer-array-address-address/deref <- list-to-array capacity:integer q-pbm:list-address) + (print-primitive ((" read-sprite done\n" literal))) + (reply result:sprite-address) +]) + +(function next-int-from-list [ + (default-space:space-address <- new space:literal 30:literal) + (curr:list-address <- next-input) + (x:tagged-value-address <- list-value-address curr:list-address) + (result:integer <- get x:tagged-value-address/deref payload:offset) ; unsafe + (next:list-address <- list-next curr:list-address) + (reply result:integer next:list-address) +]) + +(function list-to-array [ + (default-space:space-address <- new space:literal 30:literal) + (size:integer <- next-input) + (in:list-address <- next-input) + (result:integer-array-address <- new integer-array:literal size:integer) + (i:integer <- copy 0:literal) + { begin + (done?:boolean <- greater-or-equal i:integer size:integer) + (break-if done?:boolean) + (assert in:list-address (("insufficient elements in list" literal))) + (src:tagged-value-address <- list-value-address in:list-address) + (dest:integer-address <- index-address result:integer-array-address/deref i:integer) + (dest:integer-address/deref <- get src:tagged-value-address/deref payload:offset) + (i:integer <- add i:integer 1:literal) + (in:list-address <- list-next in:list-address) + (loop) + } + (reply result:integer-array-address) +]) + +(function draw-sprite [ + (default-space:space-address <- new space:literal 30:literal) + (origx:integer <- next-input) ; screen + (origy:integer <- next-input) + (img:sprite-address <- next-input) + (buf:integer-array-address <- get img:sprite-address/deref data:offset) + (w:integer <- get img:sprite-address/deref width:offset) ; sprite + (h:integer <- get img:sprite-address/deref height:offset) + (xmax:integer <- add w:integer origx:integer) ; screen + (ymax:integer <- add h:integer origy:integer) + (y:integer <- copy origy:integer) ; screen + (idx:integer <- copy 0:literal) ; sprite +;? (print-primitive y:integer) +;? (print-primitive ((" -> " literal))) +;? (print-primitive ymax:integer) +;? (print-primitive (("\n" literal))) + { begin ; for y from origy to ymax + (done?:boolean <- greater-or-equal y:integer ymax:integer) + (break-if done?:boolean) +;? (print-primitive ((" y: " literal))) +;? (print-primitive y:integer) +;? (print-primitive (("\n" literal))) + (x:integer <- copy origx:integer) + { begin ; for x from origx to xmax + (done?:boolean <- greater-or-equal x:integer xmax:integer) + (break-if done?:boolean) +;? (print-primitive ((" x: " literal))) +;? (print-primitive x:integer) +;? (print-primitive (("\n" literal))) + { begin ; switch sprite[x][y] + (color:integer <- index buf:integer-array-address/deref idx:integer) + { begin + (transparent?:boolean <- equal color:integer 0:literal) + (break-unless transparent?:boolean) + ; do nothing + (break 2:blocks) + } + { begin + (white?:boolean <- equal color:integer 1:literal) + (break-unless white?:boolean) + (point x:integer y:integer (("white" literal))) + (break 2:blocks) + } + { begin + (black?:boolean <- equal color:integer 2:literal) + (break-unless black?:boolean) + (point x:integer y:integer (("black" literal))) + (break 2:blocks) + } + } + (x:integer <- add x:integer 1:literal) + (idx:integer <- add idx:integer 1:literal) + (loop) + } + (y:integer <- add y:integer 1:literal) + (loop) + } +]) + +(function draw-board [ (default-space:space-address <- new space:literal 30:literal) (b:board-address <- next-input) (y:integer <- copy 0:literal) @@ -71,13 +229,17 @@ (f:file-address <- index b:board-address/deref col:integer) (s:square <- index f:file-address/deref row:integer) { begin - ; print black squares, leave others white - ; todo: print pieces - (t1:integer <- add row:integer col:integer) - (_ t2:integer <- divide-with-remainder t1:integer 2:literal) - (black?:boolean <- equal t2:integer 1:literal) - (break-if black?:boolean) - (rectangle x:integer y:integer 40:literal 40:literal (("black" literal))) + { begin + ; print black squares, leave others white + ; todo: print pieces + (t1:integer <- add row:integer col:integer) + (_ t2:integer <- divide-with-remainder t1:integer 2:literal) + (black?:boolean <- equal t2:integer 1:literal) + (break-if black?:boolean) + (rectangle x:integer y:integer 40:literal 40:literal (("dark gray" literal))) + (break 2:blocks) + } + (rectangle x:integer y:integer 40:literal 40:literal (("light gray" literal))) } (col:integer <- add col:integer 1:literal) (x:integer <- add x:integer 40:literal) @@ -108,14 +270,25 @@ (function main [ (default-space:space-address <- new space:literal 30:literal) (b:board-address <- read-board) - (graphics-on) + (graphics-on (("chessboard" literal)) 320:literal 320:literal) ;? (rectangle 0:literal 0:literal 100:literal 200:literal (("black" literal))) ;? (wait-for-key) ;? (reply) { begin (clear-screen) - (print-board b:board-address) - (wait-for-mouse) +;? (draw-board b:board-address) + (print-primitive (("read-sprite\n" literal))) + (x:sprite-address <- read-sprite) + (print-primitive (("draw-sprite\n" literal))) + (foo) + (draw-sprite 0:literal 0:literal x:sprite-address) +;? (print-primitive (("done\n" literal))) +;? (wait-for-key) + (break) + (image (("Q3.png" literal)) 0:literal 0:literal) + (x:integer <- color-at 1:literal 1:literal) + (print-primitive x:integer) +;? (wait-for-mouse) ;? (m:move-address <- read-move) ;? (b:board-address <- make-move b:board-address m:move-address) ;? (loop) diff --git a/graphics.mu b/graphics.mu index c4520c8f..5f19367b 100644 --- a/graphics.mu +++ b/graphics.mu @@ -1,13 +1,10 @@ ; open a viewport, print coordinates of mouse clicks ; currently need to ctrl-c to exit after closing the viewport (function main [ - (graphics-on) + (graphics-on (("practice" literal)) 300:literal 300:literal) { begin (pos:integer-integer-pair click?:boolean <- mouse-position) - { begin - (break-if click?:boolean) - (loop 2:blocks) - } + (loop-unless click?:boolean) (x:integer <- get pos:integer-integer-pair 0:offset) (y:integer <- get pos:integer-integer-pair 1:offset) (print-primitive x:integer) diff --git a/mu.arc b/mu.arc index 80d71e0d..85a96226 100644 --- a/mu.arc +++ b/mu.arc @@ -25,6 +25,7 @@ (+ b 1))))) (def print-times() + (prn (current-process-milliseconds)) (prn "gc " (current-gc-milliseconds)) (each (name time) (tablist times*) (prn name " " time))) @@ -58,14 +59,16 @@ (= curr-trace-file* filename)) (= dump-trace* nil) -(def trace (label . args) - (when (or (is dump-trace* t) - (and dump-trace* (is label "-")) - (and dump-trace* (pos label dump-trace*!whitelist)) - (and dump-trace* (no dump-trace*!whitelist) (~pos label dump-trace*!blacklist))) - (apply prn label ": " args)) - (enq (list label (apply tostring:prn args)) - traces*)) +(mac trace (label . args) + nil) +;? (def trace (label . args) +;? (when (or (is dump-trace* t) +;? (and dump-trace* (is label "-")) +;? (and dump-trace* (pos label dump-trace*!whitelist)) +;? (and dump-trace* (no dump-trace*!whitelist) (~pos label dump-trace*!blacklist))) +;? (apply prn label ": " args)) +;? (enq (list label (apply tostring:prn args)) +;? traces*)) (redef tr args ; why am I still returning to prn when debugging? Will this help? (do1 nil @@ -385,7 +388,7 @@ (= Viewport nil) ; run instructions from 'routine*' for 'time-slice' -(def run-for-time-slice (time-slice) +(deftimed run-for-time-slice (time-slice) (point return (for ninstrs 0 (< ninstrs time-slice) (++ ninstrs) (if (empty body.routine*) (err "@stack.routine*.0!fn-name not defined")) @@ -611,7 +614,8 @@ graphics-on (do1 nil ($.open-graphics) - (= Viewport ($.open-viewport "screen" 320 320))) + (= Viewport ($.open-viewport (m arg.0) ; name + (m arg.1) (m arg.2)))) ; width height graphics-off (do1 nil ($.close-viewport Viewport) ; why doesn't this close the window? works in naked racket. not racket vs arc. @@ -632,6 +636,25 @@ ($.make-posn (m arg.0) (m arg.1)) ; origin (m arg.2) (m arg.3) ; width height (m arg.4))) ; color + point + (do1 nil +;? (let t0 (msec) + (($.draw-pixel Viewport) ($.make-posn (m arg.0) (m arg.1)) + (m arg.2)) +;? (update-time "point" t0) + ) ; color +;? ) + + image + (do1 nil + (($.draw-pixmap Viewport) (m arg.0) ; filename + ($.make-posn (m arg.1) (m arg.2)))) + color-at + (let pixel (($.get-color-pixel Viewport) ($.make-posn (m arg.0) (m arg.1))) + (prn ($.rgb-red pixel) " " ($.rgb-blue pixel) " " ($.rgb-green pixel)) + ($:rgb-red pixel)) + foo + (= times* (table)) ; user-defined functions next-input @@ -1813,9 +1836,9 @@ ;? (prn function*!factorial) (run 'main) (if ($.current-charterm) ($.close-charterm)) - (prn "\nmemory: " int-canon.memory*) +;? (prn "\nmemory: " int-canon.memory*) (each routine completed-routines* (aif rep.routine!error (prn "error - " it))) ) (reset) -;? (print-times) +(print-times) |