FrenkelS / elksdoom

DOOM for ELKS
GNU General Public License v2.0
7 stars 0 forks source link

Implement keyboard controls #1

Open FrenkelS opened 2 weeks ago

FrenkelS commented 2 weeks ago

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 commented 2 weeks ago

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.

https://github.com/FrenkelS/doomtd3/pull/12#issuecomment-2317648595

FrenkelS commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

"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."

https://github.com/FrenkelS/elksdoom/pull/3

ghaerr commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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