diff options
-rw-r--r-- | chessboard-cursor.arc.t | 57 | ||||
-rw-r--r-- | chessboard-cursor.mu | 29 | ||||
-rw-r--r-- | mu.arc | 74 | ||||
-rw-r--r-- | mu.arc.t | 26 |
4 files changed, 167 insertions, 19 deletions
diff --git a/chessboard-cursor.arc.t b/chessboard-cursor.arc.t index 4cc4d0f5..662c0ee1 100644 --- a/chessboard-cursor.arc.t +++ b/chessboard-cursor.arc.t @@ -121,3 +121,60 @@ (prn "F - 'read-rank' checks that rank lies between '1' and '8'")) (reset) +(new-trace "print-board") +(add-code:readfile "chessboard-cursor.mu") +(add-code + '((function! main [ + (default-space:space-address <- new space:literal 30:literal/capacity) + (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)) + ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal)) + ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal)) + ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal)) + ((#\K literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\k literal)) + ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal)) + ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal)) + ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))) + (b:board-address <- init-board initial-position:list-address) + (screen:terminal-address <- init-fake-terminal 20:literal 10:literal) + (print-board screen:terminal-address b:board-address) + (5:string-address/raw <- get screen:terminal-address/deref data:offset) + ]))) +;? (set dump-trace*) +;? (= dump-trace* (obj whitelist '("run"))) +(run 'main) +(each routine completed-routines* + (awhen rep.routine!error + (prn "error - " it))) +;? (prn memory*.5) +;? (prn (memory* memory*.5)) +;? (write (memory* (+ memory*.5 1))) (prn) +;? (write (memory* (+ memory*.5 4))) (prn) +;? (write (memory* (+ memory*.5 5))) (prn) +;? (prn:type (memory* (+ memory*.5 5))) +;? (write (memory* (+ memory*.5 6))) (prn) +;? (prn int-canon.memory*) +;? (prn:len +;? (+ "8 | r n b q k b n r " +;? "7 | p p p p p p p p " +;? "6 | _ _ _ _ _ _ _ _ " +;? "5 | _ _ _ _ _ _ _ _ " +;? "4 | _ _ _ _ _ _ _ _ " +;? "3 | _ _ _ _ _ _ _ _ " +;? "2 | P P P P P P P P " +;? "1 | R N B Q K B N R " +;? " +---------------- " +;? " a b c d e f g h ")) +(when (~memory-contains-array memory*.5 + (+ "8 | r n b q k b n r " + "7 | p p p p p p p p " + "6 | _ _ _ _ _ _ _ _ " + "5 | _ _ _ _ _ _ _ _ " + "4 | _ _ _ _ _ _ _ _ " + "3 | _ _ _ _ _ _ _ _ " + "2 | P P P P P P P P " + "1 | R N B Q K B N R " + " +---------------- " + " a b c d e f g h ")) + (prn "F - print-board doesn't work; chessboard begins at @memory*.5")) + +(reset) diff --git a/chessboard-cursor.mu b/chessboard-cursor.mu index e8c13e78..da836fd4 100644 --- a/chessboard-cursor.mu +++ b/chessboard-cursor.mu @@ -58,7 +58,8 @@ ; print rank number as a legend (rank:integer <- add row:integer 1:literal) (print-integer screen:terminal-address rank:integer) - (print-primitive-to-host ((" | " literal))) + (s:string-address <- new " | ") + (print-string screen:terminal-address s:string-address) ; print each square in the row (col:integer <- copy 0:literal) { begin @@ -66,8 +67,8 @@ (break-if done?:boolean) (f:file-address <- index b:board-address/deref col:integer) (s:square <- index f:file-address/deref row:integer) - (print-primitive-to-host s:square) - (print-primitive-to-host ((" " literal))) + (print-character screen:terminal-address s:square) + (print-character screen:terminal-address ((#\space literal))) (col:integer <- add col:integer 1:literal) (loop) } @@ -76,9 +77,11 @@ (loop) } ; print file letters as legend - (print-primitive-to-host ((" +----------------" literal))) + (s:string-address <- new " +----------------") + (print-string screen:terminal-address s:string-address) (cursor-to-next-line screen:terminal-address) - (print-primitive-to-host ((" a b c d e f g h" literal))) + (s:string-address <- new " a b c d e f g h") + (print-string screen:terminal-address s:string-address) (cursor-to-next-line screen:terminal-address) ]) @@ -207,14 +210,14 @@ (function main [ (default-space:space-address <- new space:literal 30:literal) - (initial-position:list-address <- init-list R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal - N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal - B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal - Q:literal P:literal _:literal _:literal _:literal _:literal p:literal q:literal - K:literal P:literal _:literal _:literal _:literal _:literal p:literal k:literal - B:literal P:literal _:literal _:literal _:literal _:literal p:literal b:literal - N:literal P:literal _:literal _:literal _:literal _:literal p:literal n:literal - R:literal P:literal _:literal _:literal _:literal _:literal p:literal r:literal) + (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)) + ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal)) + ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal)) + ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal)) + ((#\K literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\k literal)) + ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal)) + ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal)) + ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))) (b:board-address <- init-board initial-position:list-address) (cursor-mode) ; hook up stdin diff --git a/mu.arc b/mu.arc index 775e87da..8a366a46 100644 --- a/mu.arc +++ b/mu.arc @@ -199,7 +199,7 @@ line-address-address (obj size 1 address t elem '(line-address)) screen (obj array t elem '(line-address)) screen-address (obj size 1 address t elem '(screen)) - terminal (obj size 3 and-record t elems '((integer) (integer) (string-address)) fields '(rows cols data)) + terminal (obj size 5 and-record t elems '((integer) (integer) (integer) (integer) (string-address)) fields '(num-rows num-cols cursor-row cursor-col data)) terminal-address (obj size 1 address t elem '(terminal)) ))) @@ -663,7 +663,10 @@ cursor-on-host-to-next-line (do1 nil ($.charterm-newline)) print-primitive-to-host - (do1 nil ((if ($.current-charterm) $.charterm-display pr) (m arg.0))) + (do1 nil +;? (prn (m arg.0) " => " (type (m arg.0))) + ((if ($.current-charterm) $.charterm-display pr) (m arg.0)) + ) read-key (if ($.current-charterm) (and ($.charterm-byte-ready?) ($.charterm-read-key)) @@ -1424,12 +1427,14 @@ (and (>= memory*.addr len.value) (loop (addr (+ addr 1) idx 0) -;? (prn "comparing @memory*.addr and @value.idx") +;? (prn "comparing @idx: @memory*.addr and @value.idx") (if (>= idx len.value) t (~is memory*.addr value.idx) (do1 nil - (prn "@addr should contain @value.idx but contains @memory*.addr")) + (prn "@addr should contain @(tostring (write value.idx)) but contains @(tostring (write memory*.addr))") +;? (recur (+ addr 1) (+ idx 1)) + ) :else (recur (+ addr 1) (+ idx 1)))))) @@ -1920,6 +1925,18 @@ (x:terminal-address <- next-input) { begin (break-unless x:terminal-address) +;? (print-primitive-to-host (("AAA" literal))) + (buf:string-address <- get x:terminal-address/deref data:offset) + (max:integer <- length buf:string-address/deref) + (i:integer <- copy 0:literal) + { begin + (done?:boolean <- greater-or-equal i:integer max:integer) + (break-if done?:boolean) + (x:byte-address <- index-address buf:string-address/deref i:integer) + (x:byte-address/deref <- copy ((#\space literal))) + (i:integer <- add i:integer 1:literal) + (loop) + } (reply) } (clear-host-screen) @@ -1928,10 +1945,14 @@ (init-fn cursor (default-space:space-address <- new space:literal 30:literal) (x:terminal-address <- next-input) - (row:integer <- next-input) - (col:integer <- next-input) + (newrow:integer <- next-input) + (newcol:integer <- next-input) { begin (break-unless x:terminal-address) + (row:integer-address <- get-address x:terminal-address/deref cursor-row:offset) + (row:integer-address/deref <- copy newrow:integer) + (col:integer-address <- get-address x:terminal-address/deref cursor-col:offset) + (col:integer-address/deref <- copy newcol:integer) (reply) } (cursor-on-host row:integer col:integer) @@ -1942,6 +1963,14 @@ (x:terminal-address <- next-input) { begin (break-unless x:terminal-address) + (row:integer-address <- get-address x:terminal-address/deref cursor-row:offset) +;? (print-primitive-to-host row:integer-address/deref) +;? (print-primitive-to-host (("\n" literal))) + (row:integer-address/deref <- add row:integer-address/deref 1:literal) + (col:integer-address <- get-address x:terminal-address/deref cursor-col:offset) +;? (print-primitive-to-host col:integer-address/deref) +;? (print-primitive-to-host (("\n" literal))) + (col:integer-address/deref <- copy 0:literal) (reply) } (cursor-on-host-to-next-line) @@ -1951,8 +1980,23 @@ (default-space:space-address <- new space:literal 30:literal) (x:terminal-address <- next-input) (c:character <- next-input) +;? (print-primitive-to-host (("printing character to screen " literal))) +;? (print-primitive-to-host c:character) +;? (reply) +;? (print-primitive-to-host (("\n" literal))) { begin (break-unless x:terminal-address) + (row:integer-address <- get-address x:terminal-address/deref cursor-row:offset) + (col:integer-address <- get-address x:terminal-address/deref cursor-col:offset) + (width:integer <- get x:terminal-address/deref num-cols:offset) + (t1:integer <- multiply row:integer-address/deref width:integer) + (idx:integer <- add t1:integer col:integer-address/deref) + (buf:string-address <- get x:terminal-address/deref data:offset) + (cursor:byte-address <- index-address buf:string-address/deref idx:integer) + (cursor:byte-address/deref <- copy c:character) + (col:integer-address/deref <- add col:integer-address/deref 1:literal) + ; we don't rely on any auto-wrap functionality + ; maybe die if we go out of screen bounds? (reply) } (print-primitive-to-host c:character) @@ -2125,6 +2169,24 @@ (sleep for-some-cycles:literal 1:literal) ) +(init-fn init-fake-terminal + (default-space:space-address <- new space:literal 30:literal/capacity) + (result:terminal-address <- new terminal:literal) + (width:integer-address <- get-address result:terminal-address/deref num-cols:offset) + (width:integer-address/deref <- next-input) + (height:integer-address <- get-address result:terminal-address/deref num-rows:offset) + (height:integer-address/deref <- next-input) + (row:integer-address <- get-address result:terminal-address/deref cursor-row:offset) + (row:integer-address/deref <- copy 0:literal) + (col:integer-address <- get-address result:terminal-address/deref cursor-col:offset) + (col:integer-address/deref <- copy 0:literal) + (bufsize:integer <- multiply width:integer-address/deref height:integer-address/deref) + (buf:string-address-address <- get-address result:terminal-address/deref data:offset) + (buf:string-address-address/deref <- new string:literal bufsize:integer) + (clear-screen result:terminal-address) + (reply result:terminal-address) +) + ; after all system software is loaded: ;? (= dump-trace* (obj whitelist '("cn0" "cn1"))) (freeze system-function*) diff --git a/mu.arc.t b/mu.arc.t index dcb38e0f..e132b598 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -4069,6 +4069,32 @@ (when (~memory-contains-array base "-237") (prn "F - converting negative integer to decimal string"))) +(reset) +(new-trace "fake-screen-initial") +(add-code:readfile "chessboard-cursor.mu") +(add-code + '((function! main [ + (default-space:space-address <- new space:literal 30:literal/capacity) + (screen:terminal-address <- init-fake-terminal 20:literal 10:literal) + (5:string-address/raw <- get screen:terminal-address/deref data:offset) + ]))) +(run 'main) +(each routine completed-routines* + (awhen rep.routine!error + (prn "error - " it))) +(when (~memory-contains-array memory*.5 + (+ " " + " " + " " + " " + " " + " " + " " + " " + " " + " ")) + (prn "F - fake screen starts out with all spaces")) + ) ; section 100 for string utilities (reset) |