Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:30 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMiteVGA: Quick PS2 hack for games developers

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 05:32pm 16 Oct 2022
Copy link to clipboard 
Print this post

As an experiment I've implemented a Basic interrupt triggered by raw PS2 codes.

PicoMiteVGA.zip




This allows you to manage keydown and keyup events. Let me know if this is useful. See https://wiki.osdev.org/PS/2_Keyboard for the scan codes (Set 2). I haven't implemented print screen pressed , print screen released, pause pressed , pause released for obvious reasons
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 05:50pm 16 Oct 2022
Copy link to clipboard 
Print this post

Thanks Peter,

Will try this with my 2 player Circle game. See if I can let them play on the WASD cluster and the arrows cluster on a single keyboard..
Edited 2022-10-17 03:51 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1233
Posted: 07:24am 17 Oct 2022
Copy link to clipboard 
Print this post

Thank you Peter,
after a Quick test
works fine, gets Keys like Right Shift/ctrl/Alt Left Shift/ctrl/AltGr
Repeat is still there (Cause of the Keyboard electronic) but stops sending as soon as the Key is released.

@Harm
no, only one key press is reported, so you dont get a "Mixed result" if more than one key is Pressed at once.

Will test it further.
Cheers
 Mart!n
'no comment
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 10:40pm 10 Nov 2022
Copy link to clipboard 
Print this post

Hi folks,

This code demonstrates conversion from "scan-codes" to the "key-codes" reported by the CMM2 KEYDOWN() method ... approximately(*)

Option Base 0
Option Default None
Option Explicit On

Dim map_00%(31)
Dim map_e0%(31)
Dim key_map%(31)

read_data()
On Ps2 on_ps2()
Do
 Pause 500
 print_keys_down()
Loop

End

Sub read_data()
 Local i%
 For i% = 0 To 31
   Read map_00%(i%)
 Next
 For i% = 0 To 31
   Read map_e0%(i%)
 Next
End Sub

Sub on_ps2()
 Local ch%, down%, scan_code% = Mm.Info(PS2)
 Select Case scan_code%
   Case Is < &hE000
     ch% = Peek(Var map_00%(), scan_code% And &hFF) : down% = 1
   Case Is < &hF000
     ch% = Peek(Var map_e0%(), scan_code% And &hFF) : down% = 1
   Case Is < &hE0F000
     ch% = Peek(Var map_00%(), scan_code% And &hFF)
   Case Else
     ch% = Peek(Var map_e0%(), scan_code% And &hFF)
 End Select
 Poke Var key_map%(), ch%, down%
End Sub

Sub print_keys_down()
 Local ch%, count%
 For ch% = 0 To 255
   If Peek(Var key_map%(), ch%) Then
     If count% > 0 Then Print ", ";
     If ch% > 32 And ch% < 127 Then
       Print Chr$(ch%) " ";
     Else If ch% <> 0 Then
       Print "[" + Hex$(ch%) + "] ";
     EndIf
     Inc count%
   EndIf
 Next ch%
 If count% > 0 Then Print
End Sub

Data &h9C92919395009900, &h0060099496989A00, &h0031710000018B00, &h00327761737A0000
Data &h0033346564786300, &h0035727466762000, &h0036796768626E00, &h003837756A6D0000
Data &h0039306F696B2C00, &h002D703B6C2F2E00, &h00003D5B00270000, &h000023005D0A0100
Data &h0008000000005C00, &h0000000000000000, &h001B000000002E00, &h0000002A2D002B9B
Data &h0000000097000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000

Data &h0000000000000000, &h0000000000000000, &h0000000000008B00, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000008782008700, &h0000808300817F84, &h0000889D00890000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000


@matherp

Somewhat randomly an F4 key-up doesn't seem to call the PS2 interrupt, is this a BUG ? or do I have a duff keyboard, it seems to be working otherwise because releasing and pressing F4 generates key-down interrupts (I only have one PS/2 keyboard so can't try a different one.)

Can we hope for anything more in the firmware, e.g. "scan-code" to "key-code" conversion or is this "our lot" ?

* It only "approximately" does what the CMM2 does because it doesn't perform the *magic* that KEYDOWN() does for the [Shift] and [Ctrl] modifier keys, and infact currently won't report their state at all.

Best wishes,

Tom
Edited 2022-11-11 10:01 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 12:08pm 11 Nov 2022
Copy link to clipboard 
Print this post

Hi Peter,

Sorry to (continue to) be a bloody nuisance, but could you please fix PicoMite/Keyboard.c#587 ?

Currrently:

if(!(Code==0xe0 || Code==0xf0 || (Code==0x12 && KeyE0) || (Code==12 && KeyUpCode)) && Code){


Should be:

if(!(Code==0xe0 || Code==0xf0 || (Code==0x12 && KeyE0) || (Code==0x12 && KeyUpCode)) && Code){


Note 12 => 0x12, I think that is why F4 isn't working properly.

  thwill said  Can we hope for anything more in the firmware, e.g. "scan-code" to "key-code" conversion or is this "our lot" ?


Actually in some ways what the PicoMite now does is better than what seems to be implemented in the CMM2. On the CMM2 is there anyway to determine if one of the modifier keys is down ? - I don't think KEYDOWN does it.

Also could you enlighten me as to whether when it comes to different language (PS/2) keyboards, are the scan-codes tied to location of the key on the keyboard or to the character the key will generate, I'm assuming the former ?

Best wishes,

Tom
Edited 2022-11-11 22:09 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 12:32pm 11 Nov 2022
Copy link to clipboard 
Print this post

  Quote  Note 12 => 0x12, I think that is why F4 isn't working properly.


Will fix

  Quote  On the CMM2 is there anyway to determine if one of the modifier keys is down ? - I don't think KEYDOWN does it.


Yes it does RTM

  Quote  KEYDOWN(7) will give any modifier keys that are pressed. These keys do
not add to the count in keydown(0)
The return value is a bitmask as follows:
lalt ? 1, lctrl ? 2, lgui ? 4, lshift ? 8, ralt ? 16, rctrl ? 32, rgui ? 64, rshift ? 128
KEYDOWN(8) will give the current status of the lock keys. These keys do
not add to the count in keydown(0)
The return value is a bitmask as follows:
caps_lock ? 1, num_lock ? 2, scroll_lock ? 4
Note that some keyboards will limit the number of active keys that they can
report.


  Quote  Can we hope for anything more in the firmware,


No

  Quote  Also could you enlighten me as to whether when it comes to different language (PS/2) keyboards, are the scan-codes tied to location of the key on the keyboard or to the character the key will generate, I'm assuming the former ?


Don't know which I why I'm not going to pursue conversion
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 01:59pm 11 Nov 2022
Copy link to clipboard 
Print this post

  matherp said  
  thwill said  Note 12 => 0x12, I think that is why F4 isn't working properly.


Will fix


Thanks Peter.

  matherp said  
  thwill said  On the CMM2 is there anyway to determine if one of the modifier keys is down ? - I don't think KEYDOWN does it.


Yes it does RTM


What do you know, I am human after all, that's probably a relief .

  matherp said  
  thwill said  Can we hope for anything more in the firmware,


No


Ack, you haven't made it easy to provide a platform independent keydown API that covers both the CMM2 and the PicoMiteVGA.

On spec can I ask for an MM.INFO$(OPTION KEYBOARD) on the PicoMite, c.f. MM.INFO$(OPTION USBKEYBOARD) on the CMM2 ?

  matherp said  
  thwill said  Also could you enlighten me as to whether when it comes to different language (PS/2) keyboards, are the scan-codes tied to location of the key on the keyboard or to the character the key will generate, I'm assuming the former ?


Don't know which I why I'm not going to pursue conversion


I suspect they are tied to the key position, could I prevail on someone with a non-English keyboard to try the attached and see what happens in the haunted wing of the keyboard - my suspicion is it will report the colocated UK keys:

   scancode.zip

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025