about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--020run.cc1
-rw-r--r--050scenario.cc2
-rw-r--r--071print.mu9
-rw-r--r--072scenario_screen.cc45
-rw-r--r--chessboard.mu53
5 files changed, 91 insertions, 19 deletions
diff --git a/020run.cc b/020run.cc
index 635356c4..b93b7c98 100644
--- a/020run.cc
+++ b/020run.cc
@@ -98,6 +98,7 @@ void run_current_routine()
     }
 //?     cout << "DDD: " << current_instruction().to_string() << '\n'; //? 1
     current_step_index() = instruction_counter+1;
+//?     cerr << "screen: " << Memory[SCREEN] << '\n'; //? 1
   }
   stop_running_current_routine:;
 }
diff --git a/050scenario.cc b/050scenario.cc
index d5b7d546..15981b06 100644
--- a/050scenario.cc
+++ b/050scenario.cc
@@ -88,7 +88,7 @@ time_t mu_time; time(&mu_time);
 cerr << "\nMu tests: " << ctime(&mu_time);
 for (index_t i = 0; i < Scenarios.size(); ++i) {
 //?   cerr << Passed << '\n'; //? 1
-//?   cerr << i << ": " << Scenarios.at(i).name << '\n'; //? 2
+//?   cerr << i << ": " << Scenarios.at(i).name << '\n'; //? 3
   run_mu_scenario(Scenarios.at(i));
   if (Passed) cerr << ".";
 }
diff --git a/071print.mu b/071print.mu
index 94b645d3..2c7250ba 100644
--- a/071print.mu
+++ b/071print.mu
@@ -30,6 +30,8 @@ recipe init-fake-screen [
 recipe clear-screen [
   default-space:address:array:location <- new location:type, 30:literal
   x:address:screen <- next-ingredient
+#?   $print [clearing screen
+#? ] #? 1
   # if x exists
   {
     break-unless x:address:screen
@@ -45,6 +47,11 @@ recipe clear-screen [
       i:number <- add i:number, 1:literal
       loop
     }
+    # reset cursor
+    cur:address:number <- get-address x:address:screen/deref, cursor-row:offset
+    cur:address:number/deref <- copy 0:literal
+    cur:address:number <- get-address x:address:screen/deref, cursor-column:offset
+    cur:address:number/deref <- copy 0:literal
     reply x:address:screen/same-as-ingredient:0
   }
   # otherwise, real screen
@@ -101,6 +108,8 @@ recipe print-character [
       }
       reply x:address:screen/same-as-ingredient:0
     }
+#?     $print [saving character ], c:character, [ to fake screen ], cursor:address/screen, [ 
+#? ] #? 1
     cursor:address:character/deref <- copy c:character
     # increment column unless it's already all the way to the right
     {
diff --git a/072scenario_screen.cc b/072scenario_screen.cc
index d7e98f2f..4f2cfd0a 100644
--- a/072scenario_screen.cc
+++ b/072scenario_screen.cc
@@ -85,6 +85,7 @@ case SCREEN_SHOULD_CONTAIN: {
 
 :(code)
 void check_screen(const string& contents) {
+//?   cerr << "Checking screen\n"; //? 1
   assert(!Current_routine->calls.front().default_space);  // not supported
   index_t screen_location = Memory[SCREEN];
   int data_offset = find_element_name(Type_number["screen"], "data");
@@ -121,10 +122,15 @@ void check_screen(const string& contents) {
     if ((!Memory[screen_data_start+i] && !isspace(expected_contents.at(i)))  // uninitialized memory => spaces
         || (Memory[screen_data_start+i] && Memory[screen_data_start+i] != expected_contents.at(i))) {
 //?       cerr << "CCC " << Trace_stream << " " << Hide_warnings << '\n'; //? 1
-      if (Current_scenario && !Hide_warnings)  // Hide_warnings indicates we're checking for the warning at the C++ level rather than raising a test failure at the mu level
+      if (Current_scenario && !Hide_warnings) {
+        // genuine test in a mu file
         raise << "\nF - " << Current_scenario->name << ": expected screen location (" << i/screen_width << ", " << i%screen_width << ") to contain '" << expected_contents.at(i) << "' instead of '" << static_cast<char>(Memory[screen_data_start+i]) << "'\n";
-      else
+        dump_screen();
+      }
+      else {
+        // just testing check_screen
         raise << "expected screen location (" << i/screen_width << ", " << i%screen_width << ") to contain '" << expected_contents.at(i) << "' instead of '" << static_cast<char>(Memory[screen_data_start+i]) << "'\n";
+      }
       if (!Hide_warnings) {
         Passed = false;
         ++Num_failures;
@@ -133,3 +139,38 @@ void check_screen(const string& contents) {
     }
   }
 }
+
+:(before "End Primitive Recipe Declarations")
+_DUMP_SCREEN,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["$dump-screen"] = _DUMP_SCREEN;
+:(before "End Primitive Recipe Implementations")
+case _DUMP_SCREEN: {
+  dump_screen();
+  break;
+}
+
+:(code)
+void dump_screen() {
+  assert(!Current_routine->calls.front().default_space);  // not supported
+  index_t screen_location = Memory[SCREEN];
+  int width_offset = find_element_name(Type_number["screen"], "num-columns");
+  size_t screen_width = Memory[screen_location+width_offset];
+  int height_offset = find_element_name(Type_number["screen"], "num-rows");
+  size_t screen_height = Memory[screen_location+height_offset];
+  int data_offset = find_element_name(Type_number["screen"], "data");
+  assert(data_offset >= 0);
+  index_t screen_data_location = screen_location+data_offset;  // type: address:array:character
+  index_t screen_data_start = Memory[screen_data_location];  // type: array:character
+//?   cerr << "data start: " << screen_data_start << '\n'; //? 1
+  assert(Memory[screen_data_start] == screen_width*screen_height);
+  index_t curr = screen_data_start+1;  // skip length
+  for (index_t row = 0; row < screen_height; ++row) {
+//?     cerr << curr << ":\n"; //? 1
+    for (index_t col = 0; col < screen_width; ++col) {
+      cerr << static_cast<char>(Memory[curr]);
+      ++curr;
+    }
+    cerr << '\n';
+  }
+}
diff --git a/chessboard.mu b/chessboard.mu
index dd0d388f..340e2d33 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -26,28 +26,40 @@ recipe main [
 # program.
 
 scenario print-board-and-read-move [
-  assume-screen 30:literal/width, 12:literal/height
-  # initialize keyboard to type in a move, then quit
+  assume-screen 120:literal/width, 20:literal/height
+  # initialize keyboard to type in a move
   assume-keyboard [a2-a4
-q
 ]
   run [
     screen:address, keyboard:address <- chessboard screen:address, keyboard:address
+#?     data:address <- get screen:address:screen/deref, data:offset #? 1
+#?     $print [screen is at ], screen:address, [ ], data:address, [ 
+#? ] #? 1
+#?     $dump-screen #? 1
   ]
   screen-should-contain [
-  #  012345678901234567890123456789
-    .8 | r n b q k b n r           .
-    .7 | p p p p p p p p           .
-    .6 |                           .
-    .5 |                           .
-    .4 | P                         .
-    .3 |                           .
-    .2 |   P P P P P P P           .
-    .1 | R N B Q K B N R           .
-    .  +----------------           .
-    .    a b c d e f g h           .
-    .                              .
-    .                              .
+  #  0         1         2         3         4         5         6         7         8         9         10        11
+  #  012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+    .Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves.         .
+    .                                                                                                                        .
+    .8 | r n b q k b n r                                                                                                     .
+    .7 | p p p p p p p p                                                                                                     .
+    .6 |                                                                                                                     .
+    .5 |                                                                                                                     .
+    .4 | P                                                                                                                   .
+    .3 |                                                                                                                     .
+    .2 |   P P P P P P P                                                                                                     .
+    .1 | R N B Q K B N R                                                                                                     .
+    .  +----------------                                                                                                     .
+    .    a b c d e f g h                                                                                                     .
+    .                                                                                                                        .
+    .Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>.                               .
+    .                                                                                                                        .
+    .Hit 'q' to exit.                                                                                                        .
+    .                                                                                                                        .
+    .move:                                                                                                                   .
+    .                                                                                                                        .
+    .                                                                                                                        .
   ]
 ]
 
@@ -155,9 +167,13 @@ recipe print-board [
   board:address:array:address:array:character <- next-ingredient
   row:number <- copy 7:literal  # start printing from the top of the board
   # print each row
+#?   $print [printing board to screen ], screen:address, [ 
+#? ] #? 1
   {
     done?:boolean <- lesser-than row:number, 0:literal
     break-if done?:boolean
+#?     $print [printing rank ], row:number, [ 
+#? ] #? 1
     # print rank number as a legend
     rank:number <- add row:number, 1:literal
     print-integer screen:address, rank:number
@@ -180,6 +196,8 @@ recipe print-board [
     loop
   }
   # print file letters as legend
+#?   $print [printing legend
+#? ] #? 1
   s:address:array:character <- new [  +----------------]
   print-string screen:address, s:address:array:character
   screen:address <- cursor-to-next-line screen:address
@@ -187,6 +205,8 @@ recipe print-board [
   s:address:array:character <- new [    a b c d e f g h]
   screen:address <- print-string screen:address, s:address:array:character
   screen:address <- cursor-to-next-line screen:address
+#?   $print [done printing board
+#? ] #? 1
 ]
 
 # board:address:array:address:array:character <- initial-position
@@ -219,6 +239,7 @@ scenario printing-the-board [
   run [
     1:address:array:address:array:character/board <- initial-position
     screen:address <- print-board screen:address, 1:address:array:address:array:character/board
+#?     $dump-screen #? 1
   ]
   screen-should-contain [
   #  012345678901234567890123456789