Code for waiting for keyboard input?

Talk about your replica, what you have done and what you use it for

Code for waiting for keyboard input?

Postby castiglione » Aug Mon 01, 2011 11:41 pm

I've been trying to write some code for the Replica 1 where the program waits for you to press any key on the keyboard before progressing but I seem to be running into a wall so I thought I'd post my woes over here:

First, I tried something like this:

In Apple BASIC:

10 IF PEEK(-12271)>=0 THEN 10
20 PRINT "KEY PRESSED!"
30 END

When run, the program waits for a keyboard input but once a key is pressed, the message "STOPPED AT 10" comes up and then the familiar BASIC prompt ">" immediately followed by "}" (at least I think it looks like a "}").


I then decided on a workaround, writing a small routine in 6502 ML and then calling it in BASIC:

33C:AD 11 D0 10 FB 60

or in Assembly

33C:
LDA $DO11
BPL 33C
RTS

-then-

10 CALL 828
20 PRINT "KEY PRESSED!"
30 END

When RUN, the same things as in the purely BASIC approach happens, I get a "STOPPED AT 10" and the ">}".

Frankly, I'm at a loss here.

Can anyone point out where I'm messing up?

Thanks in advance!

c
castiglione
 
Posts: 8
Joined: Jun Sun 05, 2011 1:33 am

Re: Code for waiting for keyboard input?

Postby vbriel » Aug Tue 02, 2011 1:44 am

Just a quick guess, but basic stops with any key pressed (not just ctrl-c) when not at an input. So, your routine would need to be strickly assembly to work. I could be wrong since I've not torn down basic fully, but this appears to be the logical answer.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 1:10 pm
Location: Ohio

Re: Code for waiting for keyboard input?

Postby vbriel » Aug Tue 02, 2011 1:44 am

Just a quick guess, but basic stops with any key pressed (not just ctrl-c) when not at an input. So, your routine would need to be strickly assembly to work. I could be wrong since I've not torn down basic fully, but this appears to be the logical answer.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 1:10 pm
Location: Ohio

Re: Code for waiting for keyboard input?

Postby castiglione » Aug Tue 02, 2011 1:22 pm

Thanks, Vince.

This certainly explains thing.

c
castiglione
 
Posts: 8
Joined: Jun Sun 05, 2011 1:33 am

Re: Code for waiting for keyboard input?

Postby MikeWillegal » Sep Wed 14, 2011 7:38 pm

This is kind of late, but might be helpful for someone in the future. Vince had it right, unless BASIC is actually waiting for keyboard input, it will stop if it encounters a key strobe. This is a most annoying feature of Apple 1 Basic. Apple II basic added a check to make sure the input is a control-C, before it stops.

You can make the assembly code work by clearing the strobe before returning, so that the next time basic checks it, the key strobe is no longer present.

rdkey:
LDA 0xD011 ;Wait for key press
BPL rdkey ;No key yet!
LDA 0Xd010 ;Clear strobe
MikeWillegal
 
Posts: 5
Joined: Jul Sat 17, 2010 4:29 pm

Re: Code for waiting for keyboard input?

Postby tranter » Feb Tue 14, 2012 7:25 pm

For completeness, here is a working example.

Code: Select all
10 REM EXAMPLE OF GETTING KEYBOARD KEY
20 POKE 768,173:POKE 769,17:POKE 770,208:POKE 771,16:POKE 772,251:POKE 773,173:POKE 774,16:POKE 775,208:POKE 776,96
30 CALL 768
40 K = PEEK(-12272)
50 IF K > 128 THEN K = K - 128
60 PRINT "GOT KEY: ";K
70 REM PRESS Q TO QUIT
80 IF K <> 81 THEN 30
90 END
User avatar
tranter
 
Posts: 96
Joined: Jan Sun 15, 2012 7:39 pm
Location: Ottawa, Ontario, Canada


Return to replica 1 General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron