Tue, 15 Nov 2011, 20:38
I have just gotten through an email exchange with a student that was prompted by my email to the class yesterday, in which I pointed out that if a player typed three characters instead of two, it would cause at least one illegal move. But no harm would be done since eventually the players would see their screw-up, perform the obvious correction, and the game would continue just fine. In the exchange with this student, I discovered that he has a basic misunderstanding of what TRAP x20 does. Since this is fundamental and there may be other students with this misconception, I am writing to you all. First the email exchange, then some comments. > > > Professor Patt, > > > > > > In response to the last email sent where the validity of a players > > > input depends on only the first two characters: > > > > > > In my program I have decided to let the players input ONLY two characters. > > > So a player will not even have the ability to enter more than two. > > > > How do you propose to accomplish that? TRAP x20 gets you the first, > > TRAP x20 gets you the second, after which (A) someone types a key loading > > KBDR and setting KBSR[15]. How do your propose to prevent A from happening? > > > > Yale Patt > > Every time a player is asked to input a value, I set a register to a > counter of 2. And every time a trapx20 instruction is executed allowing > the player to input a character, the counter is decreased by one. The input > instruction then branches out to the rest of my code when the counter has > reached 0. Then the player is not allowed to press another key after that. > > <<name withheld to protect the student who is missing an important point>> Aha! I think I have figured out where his misconception is. TRAP x20 does NOT allow the player to input a character. Anyone sitting at the keyboard can type a character if he/she has the strength to push down on the keyboard with sufficient force. The person does not have to get permission. In fact, your little brother could type a character while you and your father are playing the game. What the TRAP x20 service routine does is examine KBSR[15] to see if someone has typed a character and if someone has, the ascii code for that character will be copied from KBDR to R0. It is true that in a lot of our discussions we have used TRAP x23 to print a banner on the screen inviting the user to input a character. We did this in order to encourage the user to input a character, rather than have our program sit there patiently waiting and hoping that someone would eventually type a character. (Anyone who has sat staring at the telephone, waiting for it to ring, understands the problem with just waiting patiently!) But TRAP x23 did not make the user type a character any more than some well-meaning friend can make that long awaited telephone call happen. In fact, in the case of TRAP x23, I can think of at least two students in our class who probably would stubbornly NOT type a character! In that case the TRAP x23 service routine would never finish and control would never return to the user program. Bottom line: In the same way that the TRAP x20 (or TRAP x23) service routine does not force a user to type a character, the absence of TRAP x20 (or TRAP x23) does not prevent a user from typing a character. In the case of the student who wrote, he thinks he is only allowing the player to type two keys. Wrong! If the player types three keys, the program will accept the first two as the player's move. The third key will then be put in KBDR and sit there waiting for the program to execute another TRAP x20, which in this case he expects to be the first character of the other player's turn. Unfortunately, it will be the third key of the first player's turn. The good news is, as I tried to make clear in my email to the class is that it will not be a problem. The program will keep rejecting inputs until the players see what they are doing and correct the situation, and bring the game back to where it should be. If some of you had the same misconception, I hope this helps. Good luck finishing the program before Thanksgiving. Yale Patt