diff options
Diffstat (limited to 'html/070display.cc.html')
-rw-r--r-- | html/070display.cc.html | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/html/070display.cc.html b/html/070display.cc.html new file mode 100644 index 00000000..2f9504da --- /dev/null +++ b/html/070display.cc.html @@ -0,0 +1,250 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>~/Desktop/s/mu/070display.cc.html</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v1"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; } +body { font-family: monospace; color: #d0d0d0; background-color: #000000; } +* { font-size: 1em; } +.cSpecial { color: #008000; } +.Identifier { color: #008080; } +.Constant { color: #008080; } +.Comment { color: #8080ff; } +.Delimiter { color: #c000c0; } +.SalientComment { color: #00ffff; } +.CommentedCode { color: #6c6c6c; } +.PreProc { color: #c000c0; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment">//: Take charge of the text-mode display and keyboard.</span> + +<span class="Comment">// uncomment to debug console programs</span> +<span class="Delimiter">:(before "End Globals")</span> +<span class="CommentedCode">//? ofstream LOG("log.txt");</span> + +<span class="SalientComment">//:: Display management</span> + +<span class="Delimiter">:(before "End Globals")</span> +index_t Display_row = <span class="Constant">0</span><span class="Delimiter">,</span> Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +SWITCH_TO_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"switch-to-display"</span>] = SWITCH_TO_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case SWITCH_TO_DISPLAY: <span class="Delimiter">{</span> + tb_init<span class="Delimiter">();</span> + Display_row = Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +RETURN_TO_CONSOLE<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"return-to-console"</span>] = RETURN_TO_CONSOLE<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case RETURN_TO_CONSOLE: <span class="Delimiter">{</span> + tb_shutdown<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +CLEAR_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"clear-display"</span>] = CLEAR_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case CLEAR_DISPLAY: <span class="Delimiter">{</span> + tb_clear<span class="Delimiter">();</span> + Display_row = Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +CLEAR_LINE_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"clear-line-on-display"</span>] = CLEAR_LINE_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case CLEAR_LINE_ON_DISPLAY: <span class="Delimiter">{</span> + size_t width = tb_width<span class="Delimiter">();</span> + for <span class="Delimiter">(</span>index_t x = Display_column<span class="Delimiter">;</span> x < width<span class="Delimiter">;</span> ++x<span class="Delimiter">)</span> <span class="Delimiter">{</span> + tb_change_cell<span class="Delimiter">(</span>x<span class="Delimiter">,</span> Display_row<span class="Delimiter">,</span> <span class="Constant">' '</span><span class="Delimiter">,</span> TB_WHITE<span class="Delimiter">,</span> TB_DEFAULT<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +PRINT_CHARACTER_TO_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"print-character-to-display"</span>] = PRINT_CHARACTER_TO_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case PRINT_CHARACTER_TO_DISPLAY: <span class="Delimiter">{</span> + vector<long long int> arg = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + int h=tb_height<span class="Delimiter">(),</span> w=tb_width<span class="Delimiter">();</span> + size_t height = <span class="Delimiter">(</span>h >= <span class="Constant">0</span><span class="Delimiter">)</span> ? h : <span class="Constant">0</span><span class="Delimiter">;</span> + size_t width = <span class="Delimiter">(</span>w >= <span class="Constant">0</span><span class="Delimiter">)</span> ? w : <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>arg[<span class="Constant">0</span>] == <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>Display_row < height<span class="Delimiter">)</span> <span class="Delimiter">{</span> + Display_column = <span class="Constant">0</span><span class="Delimiter">;</span> + ++Display_row<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + tb_change_cell<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">,</span> arg[<span class="Constant">0</span>]<span class="Delimiter">,</span> TB_WHITE<span class="Delimiter">,</span> TB_DEFAULT<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Display_column < width<span class="Delimiter">)</span> <span class="Delimiter">{</span> + Display_column++<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + <span class="Delimiter">}</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +CURSOR_POSITION_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"cursor-position-on-display"</span>] = CURSOR_POSITION_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case CURSOR_POSITION_ON_DISPLAY: <span class="Delimiter">{</span> + vector<long long int> row<span class="Delimiter">;</span> + row<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Display_row<span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> row<span class="Delimiter">);</span> + vector<long long int> column<span class="Delimiter">;</span> + column<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Display_column<span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> column<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +MOVE_CURSOR_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"move-cursor-on-display"</span>] = MOVE_CURSOR_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case MOVE_CURSOR_ON_DISPLAY: <span class="Delimiter">{</span> + vector<long long int> row = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + vector<long long int> column = read_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">1</span>]<span class="Delimiter">);</span> + Display_row = row[<span class="Constant">0</span>]<span class="Delimiter">;</span> + Display_column = column[<span class="Constant">0</span>]<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +MOVE_CURSOR_DOWN_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"move-cursor-down-on-display"</span>] = MOVE_CURSOR_DOWN_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case MOVE_CURSOR_DOWN_ON_DISPLAY: <span class="Delimiter">{</span> + Display_row++<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +MOVE_CURSOR_UP_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"move-cursor-up-on-display"</span>] = MOVE_CURSOR_UP_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case MOVE_CURSOR_UP_ON_DISPLAY: <span class="Delimiter">{</span> + Display_row--<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +MOVE_CURSOR_RIGHT_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"move-cursor-right-on-display"</span>] = MOVE_CURSOR_RIGHT_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case MOVE_CURSOR_RIGHT_ON_DISPLAY: <span class="Delimiter">{</span> + Display_column++<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +MOVE_CURSOR_LEFT_ON_DISPLAY<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"move-cursor-left-on-display"</span>] = MOVE_CURSOR_LEFT_ON_DISPLAY<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case MOVE_CURSOR_LEFT_ON_DISPLAY: <span class="Delimiter">{</span> + Display_column--<span class="Delimiter">;</span> + tb_set_cursor<span class="Delimiter">(</span>Display_column<span class="Delimiter">,</span> Display_row<span class="Delimiter">);</span> + tb_present<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="SalientComment">//:: Keyboard management</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +WAIT_FOR_KEY_FROM_KEYBOARD<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"wait-for-key-from-keyboard"</span>] = WAIT_FOR_KEY_FROM_KEYBOARD<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case WAIT_FOR_KEY_FROM_KEYBOARD: <span class="Delimiter">{</span> +<span class="CommentedCode">//? LOG << "AAA\n"; LOG.flush();</span> + struct tb_event event<span class="Delimiter">;</span> + do <span class="Delimiter">{</span> + tb_poll_event<span class="Delimiter">(</span>&event<span class="Delimiter">);</span> + <span class="Delimiter">}</span> while <span class="Delimiter">(</span>event<span class="Delimiter">.</span>type != TB_EVENT_KEY<span class="Delimiter">);</span> +<span class="CommentedCode">//? LOG << "AAA 2\n"; LOG.flush();</span> + vector<long long int> result<span class="Delimiter">;</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>event<span class="Delimiter">.</span>ch<span class="Delimiter">);</span> +<span class="CommentedCode">//? LOG << "AAA 3\n"; LOG.flush();</span> + if <span class="Delimiter">(</span>!current_instruction<span class="Delimiter">().</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> +<span class="CommentedCode">//? LOG << "AAA 9\n"; LOG.flush();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +READ_KEY_FROM_KEYBOARD<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"read-key-from-keyboard"</span>] = READ_KEY_FROM_KEYBOARD<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case READ_KEY_FROM_KEYBOARD: <span class="Delimiter">{</span> + struct tb_event event<span class="Delimiter">;</span> + int event_type = tb_peek_event<span class="Delimiter">(</span>&event<span class="Delimiter">,</span> <span class="Constant">5</span><span class="Comment">/*</span><span class="Comment">ms</span><span class="Comment">*/</span><span class="Delimiter">);</span> + vector<long long int> result<span class="Delimiter">;</span> + vector<long long int> found<span class="Delimiter">;</span> + if <span class="Delimiter">(</span>event_type != TB_EVENT_KEY<span class="Delimiter">)</span> <span class="Delimiter">{</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + found<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> + else <span class="Delimiter">{</span> + result<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>event<span class="Delimiter">.</span>ch<span class="Delimiter">);</span> + found<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">);</span> + <span class="Delimiter">}</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">0</span>]<span class="Delimiter">,</span> result<span class="Delimiter">);</span> + write_memory<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>products[<span class="Constant">1</span>]<span class="Delimiter">,</span> found<span class="Delimiter">);</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(before "End Includes")</span> +<span class="PreProc">#include</span><span class="Constant">"termbox/termbox.h"</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> |