6

Turbo Pascal 3.3 for MSX apparently didn't didn't have graphics, sound or other useful functions to write games, however it allows inline machine code to be injected by using the reserved word "inline".

I am trying to write helper procedures and functions in order to surpass this limitation. However, I would like to follow good practices and make BIOS calls in order to maintain compatibility with as many machines as possible.

Regarding the keyboard, I have seen that I could read a matrix row as is, but then it would depend on the matrix implementation. The alternative is to use the BIOS function CHGET (009FH), which checks the input buffer and gets the first character. However this function is blocking and will wait for the user to make an input in order to continue the execution. This fact makes it unsuitable for writing games.

I am using this MSX 2 manual as a guide. Please, is there a way in which I could use that function or write a new one that works like Pascal's readkey from unit crtc?

3
  • 1
    Depending on use case you may as well use MSX-DOS Direct Console I/O (function 06), which returns 00 if no key is pressed or the related character (already cooked).
    – Raffzahn
    CommentedMar 27 at 11:31
  • @raffzahn ...which obviously only works when MSX-DOS is loaded.
    – tofro
    CommentedMar 27 at 16:11
  • @tofro Of course. It all depends on the use case the program presents.
    – Raffzahn
    CommentedMar 27 at 22:59

1 Answer 1

7

There is no need to go directly to the matrix. The MSX BIOS supplies a number of routines to interact with the keyboard - one of them is CHSNS ($9c) which returns the keyboard queue status in the Z flag (Mentioned in your manual here). If it returns with the zero flag cleared, a character is available in the buffer and can be retrieved using (the blocking) CHGET ($9F), returning the buffered character in the accumulator.

So, something along the line of (ignore the dots, please)

 FUNCTION KeyPressed; VAR key : CHAR; BEGIN Inline ($CD/$9c/$00/. { CALL $009c } $28/$07/. { JR Z,nokey } $21/key/. { LD HL,key. } $36/$01/. { LD (HL),1. } $18/$05/. { JR end. } $21/key/. { nokey: LD HL,key. } $36/$0. { LD (HL),0. } { END: } ) KeyPressed := key; END 

should do what you want (untested, and absolutely not optimal Z80 code, so please take it with a grain of salt). I also seem to have forgotten more about Turbo Pascal Inline than I ever knew, you might have to make "key" global for that code to work.

You would use that function like

 IF (KeyPressed) ch := ChGet; 

assuming ChGet is implemented using the same technique to call the BIOS CHGET.

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.