Help needed with flagged loop

Apple I

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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?

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

david__schmidt's picture

Dual JMP Monitors

vieuxnez wrote:
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

Re: Dual JMP Monitors

david__schmidt wrote:
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.

Thanks, worked like a charm

I now have a flagged TVTypewriter.

Newline fixed that problem

Thanks for the tip.

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



\

F000R


F000: A9

KRUSADER 1.2 BY KEN WESSEN

? N

000 ECHO   .=  $FFEF

001 MONTOR .=  $FF1F

002 KBDRDY .=  $D011

003 KBD    .=  $D010

004

005 BEGIN  .M

006        JSR GETCH

007        CMP #$9B          ESCAPE?

008        BEQ DONE

009        JSR ECHO

00A        JMP BEGIN

00B

00C GETCH  .M

00D        LDA KBDRDY

00E        BPL GETCH

00F        LDA KBD

010        RTS

011

012 DONE   .M

013        LDA #$24

014        JSR ECHO

015        JMP MONTOR

? A

0300

BEGIN  005 0300

GETCH  00C 030D

DONE   012 0316-031D

? D BEGIN

0300   20 0D 03    JSR   $030D

0303   C9 9B       CMP   #$9B

0305   F0 0F       BEQ   $0316

0307   20 EF FF    JSR   $FFEF

030A   4C 00 03    JMP   $0300

030D   AD 11 D0    LDA   $D011

0310   10 FB       BPL   $030D

0312   AD 10 D0    LDA   $D010

0315   60          RTS

0316   A9 24       LDA   #$24

0318   20 EF FF    JSR   $FFEF

031B   4C 1F FF    JMP   $FF1F

...

? R BEGIN

ABCDEF

GHIJKL$

F01A


F01A: 71

R


? I 7

007        BRK               DEBUGGER

008

? A

0300

BEGIN  005 0300

GETCH  00D 030F

DONE   013 0318-031F

? R BEGIN


A-C1 X-01 Y-07 S-EF P-F0 NVB

0305   C9 9B       CMP   #$9B

-RA

A-9B X-01 Y-07 S-EF P-F1 NVBC

0305   C9 9B       CMP   #$9B

-R$

F01A


F01A: 71

R


?

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