Help needed with flagged loop

9 posts / 0 new
Last post
Offline
Last seen: 9 years 2 months ago
Joined: Jan 12 2005 - 18:09
Posts: 104
Help needed with flagged loop

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

Offline
Last seen: 9 years 2 months ago
Joined: Jan 12 2005 - 18:09
Posts: 104
Dual 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?

Offline
Last seen: 4 days 10 hours ago
Joined: Dec 20 2003 - 10:38
Posts: 249
Try adding $80 to your compar

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

Offline
Last seen: 8 years 11 months ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
Dual JMP Monitors

In case anyone thinks that the:
JMP Monitor
JMP Monitor
is an error, (in a sense it is)

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.

Tom Owad's picture
Offline
Last seen: 1 day 10 hours ago
Joined: Dec 16 2003 - 15:14
Posts: 3383
Re: Dual JMP Monitors


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.

Offline
Last seen: 9 years 2 months ago
Joined: Jan 12 2005 - 18:09
Posts: 104
Thanks, worked like a charm

I now have a flagged TVTypewriter.

Offline
Last seen: 9 years 2 months ago
Joined: Jan 12 2005 - 18:09
Posts: 104
Newline fixed that problem

Thanks for the tip.

Offline
Last seen: 4 years 3 months ago
Joined: Jun 22 2005 - 21:06
Posts: 48
Debugging this program on the host machine

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.)

<br /> \<br /> F000R</p> <p>F000: A9<br /> KRUSADER 1.2 BY KEN WESSEN<br /> ? N<br /> 000 ECHO .= $FFEF<br /> 001 MONTOR .= $FF1F<br /> 002 KBDRDY .= $D011<br /> 003 KBD .= $D010<br /> 004<br /> 005 BEGIN .M<br /> 006 JSR GETCH<br /> 007 CMP #$9B ESCAPE?<br /> 008 BEQ DONE<br /> 009 JSR ECHO<br /> 00A JMP BEGIN<br /> 00B<br /> 00C GETCH .M<br /> 00D LDA KBDRDY<br /> 00E BPL GETCH<br /> 00F LDA KBD<br /> 010 RTS<br /> 011<br /> 012 DONE .M<br /> 013 LDA #$24<br /> 014 JSR ECHO<br /> 015 JMP MONTOR<br /> ? A<br /> 0300<br /> BEGIN 005 0300<br /> GETCH 00C 030D<br /> DONE 012 0316-031D<br /> ? D BEGIN<br /> 0300 20 0D 03 JSR $030D<br /> 0303 C9 9B CMP #$9B<br /> 0305 F0 0F BEQ $0316<br /> 0307 20 EF FF JSR $FFEF<br /> 030A 4C 00 03 JMP $0300<br /> 030D AD 11 D0 LDA $D011<br /> 0310 10 FB BPL $030D<br /> 0312 AD 10 D0 LDA $D010<br /> 0315 60 RTS<br /> 0316 A9 24 LDA #$24<br /> 0318 20 EF FF JSR $FFEF<br /> 031B 4C 1F FF JMP $FF1F<br /> ...<br /> ? R BEGIN<br /> ABCDEF<br /> GHIJKL$<br /> F01A</p> <p>F01A: 71<br /> R</p> <p>? I 7<br /> 007 BRK DEBUGGER<br /> 008<br /> ? A<br /> 0300<br /> BEGIN 005 0300<br /> GETCH 00D 030F<br /> DONE 013 0318-031F<br /> ? R BEGIN</p> <p>A-C1 X-01 Y-07 S-EF P-F0 NVB<br /> 0305 C9 9B CMP #$9B<br /> -RA<br /> A-9B X-01 Y-07 S-EF P-F1 NVBC<br /> 0305 C9 9B CMP #$9B<br /> -R$<br /> F01A</p> <p>F01A: 71<br /> R</p> <p>?<br />

Offline
Last seen: 14 years 2 months ago
Joined: Oct 2 2006 - 16:47
Posts: 5
SB-Assembler

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

Log in or register to post comments