How to inject joystick input into code

Door st1mpy

Paladin (779)

afbeelding van st1mpy

29-12-2020, 12:21

Say there is an existing tool/game that has a joystick port connection and receives up/down button presses.
I want to modify it so that I can run that without the joystick connected, and just somehow make it believe there was an input by feeding the input data in real time.
The existing software could be using the bios to read the joystick or could be reading the I/O directly.
How would you do this?

Aangemeld of registreer om reacties te plaatsen

Van Daemos

Paragon (1948)

afbeelding van Daemos

29-12-2020, 16:26

check map.grauw.nl on source examples. You need to read the joystick input right?

Here a small piece of code that reads the entire joystick. It checks all directions and both buttons.

.joystick:
;2button support. Reads two buttons and sets the spinjump bit if up and button A are simultaniously pressed

  di
	ld	a, 15	; Lee el puerto de joystick y almacena
	out	($A0), a	; los estados en las variables.
	in	a, ($A2)
	and	10101111b
	out	($A1), a
	ld	a, 14
	out	($A0), a
	ei
	in	a, ($A2) ;read left right up down and button 1 and 2

  cpl
  and %00111111
  ld c,a
  ;check if up and down are both pressed
  
  and %00010001
  cp 17
  jp nz,.nospinjump
 
  set 6,c
  res 4,c  
  
.nospinjump:

  ld a,c
    
  ld (Controls),a

ret

Van st1mpy

Paladin (779)

afbeelding van st1mpy

29-12-2020, 18:36

The existing program is probably doing that.
But I want to not touch that code (if possible) and unplug the joystick.
Then simulate a press.

So, a possible solution is, if possible to write into the a register the up/down press before the existing original code reads the a register.
Or write into psg's r14 through the i/o port the value, but it is read only so is it impossible??
Or totally forget all that and change the i/o port it reads to something else, or a memory location. (This need to modify every call in the existing program.)

Van Daemos

Paragon (1948)

afbeelding van Daemos

29-12-2020, 19:04

I see. The joystick registers cannot be manipulated that easy. Only way to emulate then is to actually really insert something in the joyport. If the program only reads the joy register each frame you could offcourse intercept the call and write whatever you need into the register where the joyport stuff is stored in.

Van Danjovic

Master (191)

afbeelding van Danjovic

30-12-2020, 15:09

Do you want a software mod or a hardware mod? What do you want to achieve?

Van Grauw

Ascended (9904)

afbeelding van Grauw

30-12-2020, 15:13

If it reads the I/O directly, there is nothing you can do.

The BIOS can be altered in the DRAM mode on the turboR, on an earlier MSX you’d probably need to detect and patch BIOS calls in the program.

Van st1mpy

Paladin (779)

afbeelding van st1mpy

30-12-2020, 16:23

The reason for this is I have built a develo box myself and it works and was going to make a pcb so others can enjoy, but it has too many fiddly parts (soldering 4 different cables and socket/plugs etc) and printer port connector and joystick connectors are costly.
So to make it cheaper, I'm redesigning it to fit it in a cartridge. A cartridge with one cable out to pc engine comms, one for pc engine pad through. And so I can get rid of the printer port by just putting the i/o decoding inside the cart which is easy to do, and the final bit is the joystick port which is only used for msx getting input data from pc engine. Printer port is the output.
In the future I could even put a whole pc engine + cdrom fpga 'emulator' inside the cart then every one without pc engine can enjoy the develo system. I don't think any pce software emulator does output from the joystick port and probably the timing is all not consistent to be able to do comms, so it would need to be fpga.

So, yes for this joystick problem, part of it has hardware mod which is 2 wire inputs up or down button. I can place a buffer that holds these values, then a software can read that in the existing develo program when it checks the joystick port condition.

Van st1mpy

Paladin (779)

afbeelding van st1mpy

30-12-2020, 16:16

I wanted the mod to be without change to the existing develo tools (there are 30 tools, not all related to the joystick input).
But I guess it is looking like I patch the IN port reads with something else in all programs that calls it. And put a hardware buffer in the cart for the data and decode this new io port.