??? 05/13/07 16:11 Read: times |
#139178 - Shall we continue this??? Responding to: ???'s previous message |
It's amazing how hard it is to get a little patch of code like this correct. Now that (we think?) we have identified all the errors in Jan's program, let's see what a robust, well documented, reusable version of the same thing would look like.
Then, once we have a working version, it might be fun to see how small we can make it. That should definitely be a second project, however. As they say, "Make it work, then make it small." As a starting point, here's a mini spec in the form of a function header for the input routine. What should be added/deleted/changed to make this subroutine really, really good? -- Russ ;------------------------------------------------------------------------------ ; ReceiveString ;------------------------------------------------------------------------------ ; DESCRIPTION: This subroutine is called from many places to receive a line of ; input from a human user via a terminal connected to the onboard ; UART. Each line of input starts with the first character ; entered after this subroutine is called, and ends with a ; carriage return. ; ; This subroutine accumulates the data in a buffer called ; 'RxBuffer', which is located in the upper 128 bytes of internal ; data RAM (accessible only via indirect addressing). The symbol ; RX_BUFFER_SIZE gives the size of the buffer, in bytes. Two ; more symbols, NO_ERROR and BUFFER_OVERFLOW, define status codes ; (more on these below). ; ; On entry, this function does minor internal housekeeping to ; prepare for a new line of input. It then receives characters ; one by one from the user. It handles each received character ; as follows: ; ; - Backspace (08h): If the buffer is not empty, removes the ; newest character from the buffer and echoes the ; three-character sequence 08h 20h 08h (backspace space ; backspace) to the terminal to erase the most recently typed ; character from the user's screen. If the buffer is empty ; when the backspace character is received, echoes a single ; 07h (beep) to the terminal. ; ; - Carriage Return (0Dh): Appends the character to the buffer ; to mark the end of the line and returns to the caller with ; the accumulator set to NO_ERROR. ; ; - Printable characters (20h through 7Eh, inclusive): Appends ; the character to the buffer. If the buffer becomes full as ; a result, returns to the caller with the accumulator set to ; BUFFER_OVERFLOW. ; ; - All other characters: Does nothing. ; ; As noted above, this function returns when it receives a ; carriage return, or when the buffer gets full, whichever occurs ; first. On exit, all registers are restored to their state at ; the time of the call except the accumulator, which contains a ; status code as described above. ; ; REVISIONS: 13 May 07 - RAC - Initial specification ; ----------------------------------------------------------------------------- |