about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-25 01:41:40 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-25 01:41:40 -0800
commitbee53b4b169feab631658b5450328a317779831a (patch)
treeedcbafff1d75e1467586540f5b216ba093e67e6c
parenta5fb9d1554bc04fcd0480cf0634855942e045d7b (diff)
downloadmu-bee53b4b169feab631658b5450328a317779831a.tar.gz
619 - chessboard now working right
2 bugs found:
  a) Have to slurp the newlines.
  b) Have to clear the line-buffer at the start of each line.
-rw-r--r--chessboard.mu20
-rw-r--r--mu.arc13
2 files changed, 28 insertions, 5 deletions
diff --git a/chessboard.mu b/chessboard.mu
index e976e3ab..9479ab24 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -107,6 +107,7 @@
   (expect-stdin stdin:channel-address ((#\- literal)))
   (to-file:integer <- read-file stdin:channel-address)
   (to-rank:integer <- read-rank stdin:channel-address)
+  (expect-stdin stdin:channel-address ((#\newline literal)))
   ; construct the move object
   (result:move-address <- new move:literal)
   (f:integer-integer-pair-address <- get-address result:move-address/deref from:offset)
@@ -127,9 +128,14 @@
   (default-space:space-address <- new space:literal 30:literal)
   (stdin:channel-address <- next-input)
   (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
+;?   (print-primitive-to-host x:tagged-value) ;? 1
+;?   (print-primitive-to-host (("\n" literal))) ;? 1
   (a:character <- copy ((#\a literal)))
   (file-base:integer <- character-to-integer a:character)
   (c:character <- maybe-coerce x:tagged-value character:literal)
+;?   (print-primitive-to-host (("AAA " literal))) ;? 1
+;?   (print-primitive-to-host c:character) ;? 1
+;?   (print-primitive-to-host (("\n" literal))) ;? 1
   { begin
     (quit:boolean <- equal c:character ((#\q literal)))
     (break-unless quit:boolean)
@@ -150,6 +156,9 @@
   (stdin:channel-address <- next-input)
   (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
   (c:character <- maybe-coerce x:tagged-value character:literal)
+;?   (print-primitive-to-host (("BBB " literal))) ;? 1
+;?   (print-primitive-to-host c:character) ;? 1
+;?   (print-primitive-to-host (("\n" literal))) ;? 1
   { begin
     (quit:boolean <- equal c:character ((#\q literal)))
     (break-unless quit:boolean)
@@ -167,10 +176,10 @@
   (reply rank:integer)
 ])
 
+; slurp a character and check that it matches
 (function expect-stdin [
   (default-space:space-address <- new space:literal 30:literal)
   (stdin:channel-address <- next-input)
-  ; slurp hyphen
   (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
   (c:character <- maybe-coerce x:tagged-value character:literal)
   (expected:character <- next-input)
@@ -223,12 +232,19 @@
     (cursor-to-next-line nil:literal/terminal)
     (print-board nil:literal/terminal b:board-address)
     (cursor-to-next-line nil:literal/terminal)
-    (print-primitive-to-host (("Type in your move as <from square>-<to square>. For example: 'a2-a4'. Currently very unforgiving of typos; exactly five letters, no <Enter>, no uppercase." literal)))
+    (print-primitive-to-host (("Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>." literal)))
     (cursor-to-next-line nil:literal/terminal)
     (print-primitive-to-host (("Hit 'q' to exit." literal)))
     (cursor-to-next-line nil:literal/terminal)
     (print-primitive-to-host (("move: " literal)))
     (m:move-address <- read-move buffered-stdin:channel-address)
+;?     (retro-mode) ;? 1
+;?     (print-primitive-to-host stdin:channel-address) ;? 1
+;?     (print-primitive-to-host (("\n" literal))) ;? 1
+;?     (print-primitive-to-host buffered-stdin:channel-address) ;? 1
+;?     (print-primitive-to-host (("\n" literal))) ;? 1
+;?     (dump-memory) ;? 1
+;?     (cursor-mode) ;? 1
     (break-unless m:move-address)
     (b:board-address <- make-move b:board-address m:move-address)
     (loop)
diff --git a/mu.arc b/mu.arc
index ca98f72b..46c28494 100644
--- a/mu.arc
+++ b/mu.arc
@@ -739,6 +739,11 @@
                     (prn ($.rgb-red pixel) " " ($.rgb-blue pixel) " " ($.rgb-green pixel))
                     ($:rgb-red pixel))
 
+                ; debugging aide
+                dump-memory
+                  (do1 nil
+                    (prn:repr int-canon.memory*))
+
                 ; user-defined functions
                 next-input
                   (let idx caller-arg-idx.routine*
@@ -2022,14 +2027,18 @@
   (default-space:space-address <- new space:literal 30:literal)
   (stdin:channel-address <- next-input)
   (buffered-stdin:channel-address <- next-input)
-  (line:buffer-address <- init-buffer 30:literal)
   ; repeat forever
   { begin
+    (line:buffer-address <- init-buffer 30:literal)
     ; read characters from stdin until newline, copy into line
     { begin
       (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
       (c:character <- maybe-coerce x:tagged-value character:literal)
       (assert c:character)
+;?       (print-primitive-to-host line:buffer-address) ;? 1
+;?       (print-primitive-to-host (("\n" literal))) ;? 1
+;?       (print-primitive-to-host c:character) ;? 1
+;?       (print-primitive-to-host (("\n" literal))) ;? 1
       { begin
         (backspace?:boolean <- equal c:character ((#\backspace literal)))
         (break-unless backspace?:boolean)
@@ -2039,8 +2048,6 @@
       }
       (line:buffer-address <- append line:buffer-address c:character)
       (line-contents:string-address <- get line:buffer-address/deref data:offset)
-;?       (print-primitive-to-host c:character) ;? 0
-;?       (print-primitive-to-host (("\n" literal))) ;? 2
       (line-done?:boolean <- equal c:character ((#\newline literal)))
       (break-if line-done?:boolean)
       (eof?:boolean <- equal c:character ((#\null literal)))