Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement keyboard controls #1

Open
FrenkelS opened this issue Aug 29, 2024 · 7 comments
Open

Implement keyboard controls #1

FrenkelS opened this issue Aug 29, 2024 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@FrenkelS
Copy link
Owner

How do you implement keyboard events in ELKS?

In the DOS version the keyboard interrupt is replaced by an implementation that stores every key press in a buffer. Then in I_StartTic() the keys in the buffer are processed.

@FrenkelS FrenkelS added enhancement New feature or request help wanted Extra attention is needed labels Aug 29, 2024
@FrenkelS
Copy link
Owner Author

Pretty straightforward, with the possible exception of ANSI keyboard sequence ESC handling: use struct termios to set the keyboard (file descriptor 0) into RAW mode, then just read(0, &c, 1) to read a character, UNIX style. Look at a Linux version of Doom, this should port right over.

FrenkelS/doomtd3#12 (comment)

@FrenkelS
Copy link
Owner Author

FrenkelS commented Aug 29, 2024

I've tried something. The menu works, but the game crashes due to not enough memory. Even e1m8 crashes.

Ingame is probably not gonna work well, because I didn't implement ev_keyup events.

Can I copy this code of doomgeneric-ascii?

@FrenkelS
Copy link
Owner Author

FrenkelS commented Aug 31, 2024

I've implemented a hack around the missing ev_keyup events that kinda works during gameplay. This hack isn't implemented in the automap, so it's still like you've got sticky keys over there.

E1m1 is kinda playable thanks to using 2 memory blocks instead of 1.

@FrenkelS
Copy link
Owner Author

FrenkelS commented Sep 2, 2024

"When a key was held previously, but not now, send a ev_keyup event.

This only seems to work on fast computers.

And the keyboard repeat rate and delay time is annoying: Holding a key down will only do something after a short delay."

#3

@ghaerr
Copy link

ghaerr commented Sep 3, 2024

Hi @FrenkelS,

I haven't had time to dive into the specific Doom code (yet), but want to make the suggestion, if possible that a way be made available, if not already done, that allows using just regular keyboard keys to run Doom. Something like h/l for left right and j/k for up down, etc.

I can definitely help you get arrow keys working for ELKS, but its a bit complicated, and depends on Doom calling read rather than having its own IRQ 1 handler.

Does Doom currently read scan codes directly from the keyboard, or is it going through the ELKS read function? Given that you're already grabbing the INT 8 timer interrupt (which is problematic, but we'll talk about that later), if there is already a bunch of code to handle keyboard scan codes directly from INT 9, that could also work. I need to understand more to suggest the best way for ELKS. Of course, whenever any interrupt is grabbed, the ELKS timesharing mechanism goes out the window, but that may not matter right now.

And the keyboard repeat rate and delay time is annoying: Holding a key down will only do something after a short delay.

There's a way to directly program the keyboard controller to change the delay time - I can look that up if you're interested. Basically, you send a byte or two to the 8042 chip and it sets the keyboard repeat rate (and possibly the delay, have to look at that also).

Can I copy this code of doomgeneric-ascii?

Yes, parsing the ESC [ A sequences etc should work for ELKS, but that method requires using read. If you're getting scan codes directly then a different method will have to be used - and more complicated.

@ghaerr
Copy link

ghaerr commented Sep 3, 2024

Can I copy this code of doomgeneric-ascii?

I just reviewed that code, and yes, it looks very good and should be able to port over to ELKS Doom with few problems. I say give it a try for sure!

Apparently they have got Doom running without scan codes or keyup events; making the ELKS version the same way and not depending on the keyboard interrupt will go a long way to being able to run Doom without denigrating the kernel, allowing other tasks to run in the background if desired.

@toncho11
Copy link

toncho11 commented Sep 3, 2024

The arrows on my numeric keyboard on my laptop do work with numlock on Box86 emulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants