Thu, 21 Nov 2013, 21:22
My students, Every so often I get the question described below. Feel free to ignore it. I am sending it to you since some in the class would like to see it, but it is beyond what I think you need to know right now. You have TRAP x21 well in hand, so you know that if you put an ascii code in R0 and call the operating system, that ascii code will be printed to the screen where the cursor is. You even know that if it is the ascii code for a control character (like line feed), the cursor will move accordingly. A student writes: > This could be an irrelevant question for now, but how can you make > the lc-3 erase a letter when the button "backspace (or delete for mac)" > was pressed instead of showing a weird symbol? > > So when there is a GETC trap instruction for example, > and while executing the lc-3, it will run forever until > someone presses a key, right? > > But if we press a backspace key on a pc or a delete key on a mac, > it shows a character that somewhat looks like a white circle inside > of a black square. (Mine's mac so it may show a different symbol > on a pc.. I don't know) > > But in general (the way we actually know it or use it), the > backspace key should delete a key that was very recently typed. > > So how do we perform the backspace key (actually deleting the > previous key not showing a symbol) during the lc-3 is executing GETC? > > I hope this helps clarifying my question. > <<name withheld to protect the student who wants to remove what is printed>> The point is that the character printed is what is put in DDR. If you are using TRAP x21, the operating system is loading DDR from R0. Now the student wants to know how to get DDR to back up the cursor and "unprint" the last character printed. You have seen it done on your laptop! So what is REALLY going on? There are multiple ways the computer system can handle this. It depends on how the designer designed things. I will give you one simple possibility, which is not the normal way exactly, but will show you how it can be done.: Recall that TRAP x21 will print a character in the place pointed to by the cursor, and then move the cursor. Line feed moves the cursor to the next line, at the left edge. How about if the backspace key moved the cursor one space to the left, and we combined that with printing a blank. Then we could accomplish your task by: We load R0 with *backspace* and call TRAP x21. The trap service routine recognizes the *backspace* and does the following: 1. Load DDR with "cursor-left" That moves the cursor over the character to be erased. 2. Load DDR with "empty character." This overwrites the character that was there. 3. Load DDR with cursor-left. This moves the cursor back one space again as preparation for overwriting the empty character with what you want in that space. An example may help. Suppose you were trying to type "price," and hit the z rather than the c so that the screen shows priz_ You load R0 with *backspace* and call TRAP x21. The TRAP service routine recognizes the *backspace* character, and first loads DDR with cursor-left. Cursor moves under the z. Next DDR is loaded with empty character Screen now shows pri _ DDR loaded with *backspace* again -> Screen now shows pri_ Now you are ready to make the correction. You load R0 with c, and call TRAP x21 again. DDR is loaded with ascii code for c. Screen now shows pric_ OK? Yale Patt The backspace key is a control character like the line feed, only in this case, the effect is to (a) move the cursor back one space, and then (b) load DDR with the blank character. The blank character will write over the character that was there. Then the cursor will be moved again back one space.