terminal_test.tac (6250B)
1 # terminal_test - Interactive terminal program allowing you to type commands to 2 # call specific methods. 3 # Uses the ExampleConfigurationROM circuit 4 ###################### Print the welcome string 5 lni 0x0,0xa,0x21,0x65,0x6d,0x6f,0x63,0x6c,0x65,0x57 6 pcr 7 jmp print 8 ###################### Print the terminal character '$ ' 9 setup: lni 0x0,0x20,0x24 10 pcr 11 jmp print 12 ###################### Set up our buffer pointer to live in GRC 13 li 32 # buffer pointer 14 mov GRA GRC 15 ###################### Set up our polling loop 16 poll: sop_xor 17 lni 128,252 # Load the bitmask for available data + the polling address 18 sps # Set the polling address 19 pop # Get the bitmask for available data 20 ###################### Poll until data is available 21 p_loop: lb GRB 22 cmp GRB GRA 23 jmp p_loop 24 ###################### Handle buffering the data and echo 25 ###################### Clears the byte out of the buffer in the keyboard 26 sb GRA 27 ###################### Did we read a backspace character? If so, handle that 28 lli 8 # ascii BS 29 cmp GRA GRB 30 jmp bcksp 31 ###################### Echo the byte 32 sb GRB 33 ###################### Write the byte in the buffer in RAM 34 sp GRC 35 sb GRB 36 ###################### Increment the buffer pointer 37 cin GRC GRC 38 ###################### If we have reached the end of the buffer, restart 39 li 110 # max buffer size = 78, 32 + 78 = 110 40 cmp GRA GRC 41 jmp setup 42 ###################### If the user pressed the enter key, output the buffer 43 lli 10 # ascii LF 44 cmp GRB GRA 45 jmp cmpr 46 jmp poll 47 ###################### Handle backspaces 48 bcksp: li 32 # buffer pointer 49 ###################### Are we at the start of the buffer? If so, we can return 50 cmp GRA GRC 51 jmp poll 52 ###################### Echo the byte 53 sb GRB 54 ###################### Decrement the buffer pointer and start polling again 55 lli 1 56 sop_sub 57 op GRC GRA GRC 58 jmp poll 59 ###################### Compare the buffer to our commands 60 ###################### Specify the string we will be comparing, and the length. 61 ###################### This is in reverse order, as the bytes will be pushed to 62 ###################### the stack. The last byte is the first byte out. 63 ###################### The last byte is the length of the string. 64 ##### first off, store our buffer end pointer in RAM 65 cmpr: li 32 # buffer pointer 66 push 67 sop_sub 68 op GRC GRA GRC 69 lli 0x01 70 sp GRA 71 sb GRC 72 ptrinc 73 sbs 74 ############ Respond to 'ping' with 'pong' 75 # "ping\n\0", length 5 76 lni 0x0,0x0a,0x67,0x6e,0x69,0x70,5 77 pcr 78 jmp cmpr_f 79 sop_and 80 ############ If the strings match, print our response, else continue to the next 81 cmp GRB GRB 82 jmp n0 83 ############ load the null-terminated string to print 84 ############ "pong\n\0" 85 lni 0x00,0x0a,0x67,0x6e,0x6f,0x70 86 pcr 87 jmp print 88 jmp setup 89 ############ Respond to 'testing123' with 'we are alive' 90 # "testing123\n\0", length 11 91 n0: lni 0x0,0x0a,0x33,0x32,0x31,0x67,0x6e,0x69,0x74,0x73,0x65,0x74,11 92 pcr 93 jmp cmpr_f 94 sop_and 95 ############ If the strings match, print our response, else go handle input 96 cmp GRB GRB 97 jmp n1 98 ############ load the null-terminated string 99 ############ "we are alive\n\0" 100 lni 0x0,0xa,0x65,0x76,0x69,0x6c,0x61,0x20,0x65,0x72,0x61,0x20,0x65,0x77 101 pcr 102 jmp print 103 jmp setup 104 ############ Respond to 'foo' with 'bar' 105 # "foo\n", length 4 106 n1: lni 0x0,0x0a,0x6f,0x6f,0x66,4 107 pcr 108 jmp cmpr_f 109 sop_and 110 ############ If the strings match, print our response, else go handle input 111 cmp GRB GRB 112 jmp n2 113 ############ load the null-terminated string 114 ############ "bar\n\0" 115 lni 0x0,0xa,0x72,0x61,0x62 116 pcr 117 jmp print 118 jmp setup 119 ############ Respond to 'clear' by clearing the TTY 120 # "clear\n", length 6 121 n2: lni 0x0,0xa,0x72,0x61,0x65,0x6c,0x63,6 122 pcr 123 jmp cmpr_f 124 sop_and 125 cmp GRB GRB 126 jmp setup 127 ########## clear the TTY 128 lni 12,252 # Load acii FF and our TTY MMIO address 129 sps 130 sbs 131 jmp setup 132 ######### compare function, compares the null-terminated string on the stack to 133 # the contents of the buffer and returns a boolean in GRB. 134 # Expects: 135 # Stack: return address, size of compare string, null-terminated compare string 136 # Memory: 137 # 0x0 - used for the return pointer address 138 # 0x1 - buffer length 139 # 0x2 - buffer pointer 140 cmpr_f: lli 0x0 # return pointer memory address 141 sp GRA 142 ######## Store the return pointer 143 sbs 144 lli 0x01 # buffer length / pointer 145 sp GRA 146 ######## Get the buffer length + start address 147 lb GRC 148 ptrinc 149 lb GRB 150 sp GRB 151 ######## If the length of our string does not match our buffer, 152 ######## just exit immediately. 153 pop 154 sop_xor 155 cmp GRC GRA 156 jmp c_loop 157 jmp c_fail 158 c_loop: pop 159 ######## Test if we've reached the end of our comparision buffer. 160 ######## If we've reached the end and haven't branched out, then 161 ######## it is a match! 162 cmp GRA NIL # test for a null byte 163 jmp c_match 164 lb GRB 165 ######## Increment our buffer pointer 166 ptrinc 167 ######## If the bytes match, continue looping 168 cmp GRB GRA 169 jmp c_loop 170 # Return false 171 c_fail: pop # Flush the stack until we get the null byte 172 cmp GRA NIL # test for a null byte 173 jmp c_r # if null, return 174 jmp c_fail # else continue flushing 175 # Return true 176 c_match: lli 0x01 177 c_r: mov GRA GRB 178 lli 0x0 179 sp GRA 180 lb GRA 181 goto 182 ############ Print routine that expects a null-terminated string on the stack 183 print: pop 184 mov GRA GRB 185 sop_and 186 li 252 # MMIO TTY address 187 sp GRA 188 print_loop: pop 189 cmp GRA GRA # test for a null byte 190 jmp print_done # if we get a null byte, return 191 sb GRA 192 jmp print_loop 193 print_done: mov GRB GRA 194 goto