pW COSINE IER
and the HL registers, HL doesn’t matter at this point, but A contains the character,
so as we need the character in the B register for the following part of the program we
might as well tuck it out of sight now before the newline is displayed.
Now to find out if the character has been used before, and this is done by
scanning through the used letters buffer CHRTRD. Remember the letter is already in B.
The characters are picked up one by one into A and compared with B until either an 00
is detected indicating the end of the buffer or a compare is found. If a compare is
found a message to announce that fact is displayed, and the program goes back to the
start of the main loop to get another character.
If the character isn’t found in CHRTRD, then it must be put there, the
scanning routine was so arranged to leave HL pointing at what was the buffer
delimiter, the 00. There is a LD (HL),B instruction, but when I wrote the program I
forgot it existed, so I copied B into A again and used LD (HL),A to copy it into
CHRTRD. Silly of me. This sort of oversight becomes apparent when you read through the
listing. However, having already edited the listing into DISKPEN printable format,
it’s too late to do anything about that now. I dare say there are other instances
where I’ve wasted a couple of bytes in this fashion. I’ll offer a £5.00 prize for the
maximum number of ‘oversights’ of this sort found in the program. Don’t cheat just
‘cos there’s some loot in it. I’m sure there are much more efficient and space saving
(if less transparent) methods of writing this program. I’ll be the judge of how much
code juggling you are allowed to indulge in to save a few bytes. Anyway, having put
the character in CHRTRD, HL is incremented by one and a new 00 placed at the end of
the buffer to delimit it. Now I hope you see why we put an 0O at the start of the
puffer when the program started.
The next step, as we’ve accepted the letter is to count it. This is done by
getting the contents of TRYS into A, incrementing A by one, performing our old friend
DAA on it to keep a packed BCD number, and putting the new number back in TRYS.
Now to look for the letter in the word. The scan procedure is almost identical
to the previous one. If a compare with B is found then the letter is ‘flagged’ to make
it visible. This is done by setting bit 7. There are a number of ways to do this, I
favour the simplest to understand which is to add 80H to the letter. Having flagged
the letter, it is put back in it’s place in the word.
Having flagged (or not flagged) the letter it’s time for another scan, this
time to see if all the letters in the word are flagged. This works in the same way as
the previous two scans except in this instance the letters are compared with 80H and
the result of this decides whether it is flagged or not. The compare instruction is
effectively a subtract instruction which does not affect the contents of the A
register, so if the character is less than 80H, that is, unflagged, there will be a
carry. If the character is equal to or greater than 80H then there will be no carry,
indicating that the character is flagged. As soon as a character that is less that 80H
is detected the old trick of ORing A is performed. If there is no Z, then the
character must be a letter, in which case there is at least one letter remaining which
is unflagged. If the OR A results in a Z then the character must be 00 indicating the
end of the buffer, which means all the letters have been flagged, and therefore you
win. Think about this step carefully because this is where the decisions are taken.
In the winning case a message is displayed to say ‘you win’ and the program
jumps back to RSTART to display the word and ask if you want to continue.
In any other instance, the ‘number of trys’ message is displayed followed by
the number of trys from TRYS. Now as TRYS is a packed BCD number, ideal for display by
our old friend B2HEX. So just to prove it has it’s uses in programs it has been
included for the sole purpose of displaying TRYS. Notice the output part of B2HEX has
been altered slightly to accomodate OUTCHR. Having displayed TRYS, the next thing is a