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: 348
Joined: Sun Nov 04, 2018 2:33 am

inkey$ command and player choice

Post by Crayon21 »

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.
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: inkey$ command and player choice

Post by mrtinb »

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
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: inkey$ command and player choice

Post by XavSnap »

: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$
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: inkey$ command and player choice

Post by mrtinb »

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
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

Re: inkey$ command and player choice

Post by Crayon21 »

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 222 times
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

Re: inkey$ command and player choice

Post by Crayon21 »

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 223 times
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: inkey$ command and player choice

Post by dr beep »

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: 5103
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 »

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
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: inkey$ command and player choice

Post by XavSnap »

True, we had to buy a fuc*** Spectrum to get 'IN' and the famous 'OUT'!
:mrgreen:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
1024MAK
Posts: 5103
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 »

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
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply