Help needed with flagged loop

8 replies [Last post]
Offline
Joined: Jan 12 2005
Posts: 104

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

__________________

Dustin

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Offline
Joined: Jan 12 2005
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?

__________________

Dustin

Offline
Joined: Dec 20 2003
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

__________________

replica 1 The Apple 1 replica and the new Micro-KIM!
brielcomputers.com

Offline
Joined: Apr 11 2006
Posts: 1013
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
Offline
Joined: Dec 16 2003
Posts: 2460
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.

__________________

Admin

Offline
Joined: Jan 12 2005
Posts: 104
Thanks, worked like a charm

I now have a flagged TVTypewriter.

__________________

Dustin

Offline
Joined: Jan 12 2005
Posts: 104
Newline fixed that problem

Thanks for the tip.

__________________

Dustin

Offline
Joined: Jun 23 2005
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
Joined: Oct 2 2006
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

__________________

My Apple 1 projects on http://www.sbprojects.com