trouble with chget

By salutte

Expert (69)

salutte's picture

25-07-2020, 07:02

Hi all!

I'm trying for a (rushed) MSX-DEV entry, but I am having trouble with CHGET. Probably this has been asked and answered before, but I am too sleep deprived at the moment to find it.

That's my getch rutine:

	_msxhal_getch::
		call #0x009C      ; call CHSNS
		ld l,#0
		ret z
		call #0x009f		; call CHGET
		ld l,a
		ret

This is a puzzle game, and I am using getch to navigate through the cells of the puzzle and also look for certain key presses.
The problem is that, sometimes, arrow keypresses are either detected twice, or not detected at all for a few seconds.

The problem is most present on MSX1 machines, when on a Turbo-R it almost always works as intended.

Also, what I could not test: does chget provide any feedback to joystick inputs?

Finally, does CHGET enable or disable interrupts on exit?

Thanks!

Login or register to post comments

By thegeps

Champion (485)

thegeps's picture

25-07-2020, 07:43

For joysticks (and cursors too) you can use gtstck at 0d5h.
Chget wait for a kay ti be pressed or read next char from the keybuffer, so keys are recorded in the buffer and you have multiple keypress or no keypress at all (the buffer is full and need to be initialized calling kilbuf at 156h )
No interrupt enable/disable from chget.
Gtstck works as stick() on basic: the value in accumulator set the device you are checking:
0 cursors
1 joy1
2 joy2

For fire buttons use gttrig (same as basic strig())

By theNestruo

Master (155)

theNestruo's picture

25-07-2020, 09:26

I agree with thegeps: GTSTCK & GTTRIG do a better job when reading cursors/joystick/space bar/triggers.
For triggers you can also read TRGFLG from RAM, but it is updated in the BIOS KEYINT, so expect 0~3 frames of delay.

CHGET is intended for typing: A will give you "a", and Shift+A will give you "A". Most of the time, that is not particularly suitable for reading game input (you need keypresses, not characters).

If you sparsely need to detect additional key presses besides cursors/joystick/space bar/triggers (such as: M, SELECT, etc.) use SNSMAT, or read NEWKEY and OLDKEY from RAM if you can tolerate 0~3 frames of delay.

By salutte

Expert (69)

salutte's picture

26-07-2020, 05:12

As this game is a puzzle, I actually want the CHGET behavior, but I will combine CHGET and the NEWKEY/OLDKEY method. I can definitely tolerate a few frames of delay.

Thanks for the feedback!!