about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-20 17:35:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-20 17:35:32 -0700
commit12d73ee8db0f6748fabf65f4d0789c79f76c8d1f (patch)
tree3a31fa1c5eb98584a71af8a5e442e277ccf21e94
parentf08a13e1f709c69375202e8ecafb337a24abed45 (diff)
downloadmu-12d73ee8db0f6748fabf65f4d0789c79f76c8d1f.tar.gz
1114 - more primitives for managing the cursor
-rw-r--r--cpp/070console64
-rw-r--r--cpp/console.mu14
2 files changed, 78 insertions, 0 deletions
diff --git a/cpp/070console b/cpp/070console
index c8a51f9d..dcb6da96 100644
--- a/cpp/070console
+++ b/cpp/070console
@@ -3,6 +3,8 @@
 :(before "End Includes")
 #include<ncurses.h>
 
+//:: Display management
+
 :(before "End Primitive Recipe Declarations")
 CURSOR_MODE,
 :(before "End Primitive Recipe Numbers")
@@ -24,6 +26,68 @@ case RETRO_MODE: {
 }
 
 :(before "End Primitive Recipe Declarations")
+CLEAR_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["clear-display"] = CLEAR_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case CLEAR_DISPLAY: {
+  clear();
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+CLEAR_LINE_ON_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["clear-line-on-display"] = CLEAR_LINE_ON_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case CLEAR_LINE_ON_DISPLAY: {
+  clrtoeol();
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+PRINT_CHARACTER_TO_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["print-character-to-display"] = PRINT_CHARACTER_TO_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case PRINT_CHARACTER_TO_DISPLAY: {
+  vector<int> arg = read_memory(instructions[pc].ingredients[0]);
+  addch(arg[0]);
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+CURSOR_POSITION_ON_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["cursor-position-on-display"] = CURSOR_POSITION_ON_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case CURSOR_POSITION_ON_DISPLAY: {
+  size_t cursor_row = 0, cursor_column = 0;
+  getyx(stdscr, cursor_row, cursor_column);
+  vector<int> row;
+  row.push_back(cursor_row);
+  write_memory(instructions[pc].products[0], row);
+  vector<int> column;
+  column.push_back(cursor_column);
+  write_memory(instructions[pc].products[1], column);
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+MOVE_CURSOR_ON_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["move-cursor-on-display"] = MOVE_CURSOR_ON_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case MOVE_CURSOR_ON_DISPLAY: {
+  vector<int> row = read_memory(instructions[pc].ingredients[0]);
+  vector<int> column = read_memory(instructions[pc].ingredients[1]);
+  move(row[0], column[0]);
+  break;
+}
+
+//:: Keyboard management
+
+:(before "End Primitive Recipe Declarations")
 WAIT_FOR_KEY_FROM_KEYBOARD,
 :(before "End Primitive Recipe Numbers")
 Recipe_number["wait-for-key-from-keyboard"] = WAIT_FOR_KEY_FROM_KEYBOARD;
diff --git a/cpp/console.mu b/cpp/console.mu
index a25f94cb..d83619c7 100644
--- a/cpp/console.mu
+++ b/cpp/console.mu
@@ -1,5 +1,19 @@
 recipe main [
   cursor-mode 0:literal/screen
+  print-character-to-display 97:literal
+  1:integer/raw, 2:integer/raw <- cursor-position-on-display
+  $print 1:integer/raw
+  $print [, ]
+  $print 2:integer/raw
+  $print [
+]
+  wait-for-key-from-keyboard
+  clear-display
+  move-cursor-on-display 0:literal, 4:literal
+  print-character-to-display 98:literal
+  wait-for-key-from-keyboard
+  move-cursor-on-display 0:literal, 0:literal
+  clear-line-on-display
   wait-for-key-from-keyboard
   retro-mode 0:literal/screen
 ]