I'm trying to create a looped program with TVTypewriter from "Apple I Replica Creation" as the base, that will quit when the user presses a specified key, rather than endlessly looping until the user resets. I've chosen '`', and my source code is below. For some reason, the program endlessly loops, behaving exactly like the TVTypewriter example. Can anyone show me what I'm doing wrong with this code?
Echo = $FFEF
Monitor = $FF1F
KbdReady = $D011
Kbd = $D010
Begin:
JSR GetChar ; Read character from keyboard and store in accumulator
CMP #$60 ; is the character equal to '`'?
BEQ Done ; if char is equal to '`', then finish
JSR Echo ; print out what is stored in the accumulator
JMP Begin ; Just keep on going
GetChar:
LDA KbdReady ; Key Ready?
BPL GetChar ; Loop until key is ready
LDA Kbd ; Load Character from Keyboard
RTS ; Return
Done:
LDA #$24 ; load a '$'
JSR Echo ; print a '$'
JMP Monitor ; That's all folks
JMP Monitor
In case anyone thinks that the:
JMP Monitor
JMP Monitor
is an error, (in a sense it is)
For some reason, when I compile files, the xa compiler leaves out 4C 1F FF at the end of the hex code unless I repeat the instruction in the assembly source.
Does anyone else have the same problem?
Try adding $80 to your compare value of $60. The reason is the 8th bit is always tied high when inputing keyboard data. So, at 7:30 in the morning with no coffee, that would be $E0 instead? Too early to count in hex. I didn't check over the rest of the code but if your loop isn't ending because it isn't seeing the keystroke that is because the 8th bit is always high. You can AND the byte with 7F and that will drop the 8th bit for you and give you the character you typed in.
Vince
I had the same problem with the SB-Assembler. Try adding a newline/linefeed/whatever after your first JMP Monitor. In other words, have a blank line at the end of the program. The assembler's parser is probably discarding the final line of the file if it doesn't see a newline.
Seconded. xa has this exact problem as well.
I now have a flagged TVTypewriter.
Thanks for the tip.
I thought I'd take the opportunity to show a session with KRUSADER (http://school.anhb.uwa.edu.au/personalpages/kwessen/apple1/Krusader.htm) that shows how you can use the integrated debugging environment to solve this kind of issue.
I used the escape key to cancel the typewriter because I don't think "`" is a valid Apple 1 character.
First I enter the program in KRUSADER format. Then I assemble it, and disassemble to check the result. Then I run it, and it works as expected. Resuming the assembler, I edit the code and put a BRK in before the compare, re-assemble and run.
First time I type an 'A'. It drops into the mini-monitor, and we can see C1 in register A (i.e. ASCII 'A' + high bit set). I continue with the 'R' command, and next type escape. This time we see the required $89 in A. For your original problem, you would have seen $E0 in A, rather than the $60 you were hoping for.
Ken
(edit: I can't seem to get the code below to format properly - it always adds an extra line.)
Just for the record: The end of file bug has been fixed in the SB-Assembler.
I will release an Apple-1 version of the SB-Assembler shortly. It uses the same syntax as the PC version of the SB-Assembler. However its functionality is a bit stripped down to make it fit in a 4k memory block.
Meanwhile there's lots to read about the Apple 1, its replicas, its emulators and software in my site http://www.sbprojects.com/projects/apple1/apple1.htm