inkey$ command and player choice

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Crayon21
Posts: 83
Joined: Sun Nov 04, 2018 2:33 am

inkey$ command and player choice

Post by Crayon21 » Tue Jul 02, 2019 3:38 am

would it be better for me to program a inkey$ loop instruction instead of Get a$? the zx81 doesn't really have a provision for scanning the keyboard to find a certain key. Still working on treasure hunt, but this aspect of programming is still hard to pull off. I can get away with an input command here or there, but I miss out on declaring other variables. Will this help or not? For those interested, the story is done. It's nothing major, but my goal is to get the game to be just under 4k. thanks in advance.
zx81: great yet flawed
Zx spectrum: masterpiece that keeps on giving

(wish it weren't so expensive) :o

User avatar
mrtinb
Posts: 1043
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: inkey$ command and player choice

Post by mrtinb » Wed Jul 03, 2019 8:58 pm

A simple wait for a key if you are in SLOW mode:
  • loop:
  • CALL SCAN
  • If key is $FFFF JR Z loop
  • CALL DECODE
  • RET
It’s not copy-paste, because it’s just from my memory.
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

User avatar
XavSnap
Posts: 740
Joined: Sat May 10, 2008 4:23 pm

Re: inkey$ command and player choice

Post by XavSnap » Thu Jul 04, 2019 1:14 am

:shock:
What it is Martin ?
10 REM loop:
20 REM SCAN
30 If key is $FFFF JR Z loop
40 CALL DECODE
50 RET
:oops:

Code: Select all

1 FOR A=0 TO 4E4
2 IF INKEY$="" THEN NEXT A 
3 PRINT INKEY$

User avatar
mrtinb
Posts: 1043
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: inkey$ command and player choice

Post by mrtinb » Thu Jul 04, 2019 3:37 pm

I’m on vacation and don’t have all my ZX81 books and manuals with me.

I’ve looked most of it up, on the Internet.

It’s machine language.

Loop:
LD HL,$FFFF
LD BC, LAST_K
AND A
SBC HL,BC
JR Z Loop
CALL DECODE ($07BD)
PUSH HL
POP BC
RET

100 REM GET KEY
10 LET KEY=USR xxxxx
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

Crayon21
Posts: 83
Joined: Sun Nov 04, 2018 2:33 am

Re: inkey$ command and player choice

Post by Crayon21 » Mon Oct 07, 2019 2:52 am

I'm working on a parser for the zx81

my goal is to make a 4k version of the hobbit but with a better parser

Here is what i have so far
Attachments
parser.z81
nothing fancy, though the "ok" is missing, seems to work otherwise
(2.62 KiB) Downloaded 6 times
zx81: great yet flawed
Zx spectrum: masterpiece that keeps on giving

(wish it weren't so expensive) :o

Crayon21
Posts: 83
Joined: Sun Nov 04, 2018 2:33 am

Re: inkey$ command and player choice

Post by Crayon21 » Mon Oct 07, 2019 3:03 am

here is the second parser (feel free to use it as you see fit)
Attachments
parset.tzx
should work...hopefully. crammed as much as i could into 4k
(2.63 KiB) Downloaded 6 times
zx81: great yet flawed
Zx spectrum: masterpiece that keeps on giving

(wish it weren't so expensive) :o

dr beep
Posts: 1199
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: inkey$ command and player choice

Post by dr beep » Tue Oct 08, 2019 9:01 pm

mrtinb wrote:
Thu Jul 04, 2019 3:37 pm
I’m on vacation and don’t have all my ZX81 books and manuals with me.

I’ve looked most of it up, on the Internet.

It’s machine language.

Loop:
LD HL,$FFFF
LD BC, LAST_K
AND A
SBC HL,BC
JR Z Loop
CALL DECODE ($07BD)
PUSH HL
POP BC
RET

100 REM GET KEY
10 LET KEY=USR xxxxx
I mostly code
Loop:
LD BC,( LAST_K)
LD A,C
INC A
JR Z Loop


In BASIC you can also PEEK LAST_K and use the IN ports for input.

User avatar
1024MAK
Posts: 2484
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: inkey$ command and player choice

Post by 1024MAK » Tue Oct 08, 2019 10:06 pm

There is no IN function in ZX81 BASIC, but it is possible to have a short machine code routine in a REM line to perform the Z80 IN.

Mark

User avatar
XavSnap
Posts: 740
Joined: Sat May 10, 2008 4:23 pm

Re: inkey$ command and player choice

Post by XavSnap » Tue Oct 08, 2019 11:52 pm

True, we had to buy a fuc*** Spectrum to get 'IN' and the famous 'OUT'!
:mrgreen:

User avatar
1024MAK
Posts: 2484
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: inkey$ command and player choice

Post by 1024MAK » Wed Oct 09, 2019 3:58 pm

1024MAK wrote:
Tue Oct 08, 2019 10:06 pm
There is no IN function in ZX81 BASIC, but it is possible to have a short machine code routine in a REM line to perform the Z80 IN.
The code in this post demonstrates using a small bit of machine code to perform a read from a hardware port using one of the Z80s IN opcodes.

Mark

Post Reply