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

Emulate a phazer with the mouse #34

Open
ColinPitrat opened this issue Aug 4, 2016 · 22 comments
Open

Emulate a phazer with the mouse #34

ColinPitrat opened this issue Aug 4, 2016 · 22 comments

Comments

@ColinPitrat
Copy link
Owner

Detecting the clicked (or hovered ?) pixel and setting the light pen input high when the CRTC reaches it:
http://www.cpcwiki.eu/index.php/Trojan_Light_Phazer

@ColinPitrat
Copy link
Owner Author

Similar devices (would be nice for support to be generic enough to emulate any of them):
https://www.cpcwiki.eu/index.php/Amstrad_LP-1_light_pen
http://www.cpcwiki.eu/index.php/Amstrad_Magnum_Phaser

@ColinPitrat
Copy link
Owner Author

And another one mentioned in #214:
https://www.cpcwiki.eu/index.php/Gunstick

@Huntsman360
Copy link

amstrad cpc has this guns that i know:
Gunstick
Magnum
Trojan
Westphaser

Any possibility to add mouse / actual guns support? i have a sinden lightgun and will be a very nice nostalgia moment

Best regards

@ColinPitrat
Copy link
Owner Author

Right, the Westphaser:
https://www.cpcwiki.eu/index.php/Loriciel_Phaser_(West_Phaser)

I'll look into mouse support when time permits. It should work for Sinden lightgun too as it behaves as a mouse.

@Huntsman360
Copy link

Huntsman360 commented Aug 30, 2021

thanks a lot, i have a arcade machine with retroarch so if you compile it in libretro core for windows i appreciate so much

Sorry for a lot a requests

Edit: sorry refloating this topic, any news about phaser support?

@Huntsman360
Copy link

Sorry, any news on lightguns support? i know it's not prioritary but i hope some day

@ColinPitrat
Copy link
Owner Author

I gave it a try but couldn't find a clean way to do it.

We'd need to activate the input (Joystick Up, Joystick Down, CRTC Light Pen Input depending on the model emulated) at this place in the code:

PreRender(); // translate CPC video memory bytes to entries referencing the palette

This would require identify which pixel we're drawing which, interestingly, is not that easy in the current code.
IIRC:

  • CRTC.sl_count gives the Y, but maybe with some subtleties (impacted by overscan?)
  • CRTC.char_count would give the X (with some calculation) with some approximation (8 pixel)

I'm not 100% sure how well this would work. I'd need a game, or even better a test program to validate it.

I'm not sure if we can do better. This code would need some better documentation which, at this point, means some reverse engineering.

I'll see if I find some time to give it a try in the coming weeks.

@Huntsman360
Copy link

Huntsman360 commented Aug 15, 2022

thanks a lot.

For a reference, the real hardware when you push trigger gun the game shows white rectangles on shootable objects. If the gun sees this white bright rectangle, then impacts. Every rectangle is shown in order. for example, if you have 3 objects, when you pull the trigger, 3 rectangles appear but not at the same time, if the gun sees one in that frame time, the object is hit.

Maybe you can trace this rectangles too and if the cursor mouse is in on one of them at the proper time it hits

This is high level function, how to implement it i don't know

Sorry my english

@ColinPitrat
Copy link
Owner Author

ColinPitrat commented Aug 15, 2022

That's not how emulation works :-) I have to emulate what the hardware is doing. The rectangles are drawn by the software running on the CPC.

What I need to do is:

  • When the mouse button is clicked, do as if a joystick button was pressed (or for the Magnum, answer on port FBFEh)
  • Continuously, when the pixel under the mouse is drawn, set the CRTC Light Pen Input (and reset when not)

My assumption that it's not possible to have a precision to the pixel is confirmed by the technical specifications:
https://www.cpcwiki.eu/index.php/Amstrad_Magnum_Phaser#Technical

The` accuracy is 1 CRTC character (R9 lines in height - normally 8) and 2 bytes horizontally. This is due to the way the CRTC outputs are mapped to memory addresses.

@ColinPitrat
Copy link
Owner Author

I started to look into this and the first finding is that it requires specific games to support it.

For example, the Magnum Phazer was sold with 6 games supporting it:
https://cpcrulez.fr/GamesTest/compilation-magnum_light_phaser.htm

This can be found in ROMs where there are many versions and one is identified as the LIGHTGUN one:
https://cpcrulez.fr/GamesTest/operation_wolf.htm

When trying it on Caprice, every other frame is completely white. Not sure whether it's a bug in Caprice or a consequence of not having a Phazer "plugged".

Testing another game ("Mission" on the compilation disk) there's the same huge white rectangle in the whole area where you can shoot every other frame.

IIUC, these white areas should only display when pressing the phazer button?

@Huntsman360
Copy link

Huntsman360 commented Aug 15, 2022

here in spain we have "gunstick" with games like:

Bestial Warrior
Cosmic Sheriff
El Equipo A
Guillermo Tell
Mike Gunner
Outlaws
Solo
Sootland
Space Smugglers
Target Plus
Trigger

and that i remember, when you press the trigger the white areas flash very quick and in order, and the gun if sees one, send the message to computer that can determine what objet is hit by the frametime gun says it saw a white rectangle

PD: i loaded target plus in retroarch caprice 32, and every time i press the button white squares flashes
PD2: and obviusly this is not pixel perfect like gun-con, if the gun sees the rectangle is a hit
PD3: the only thing to do is determine if the cursor is on the rectangle when it shows up that is when shots and send the info the gun sends to the hard when this ocurs. Other thing is how, jejej

@ColinPitrat
Copy link
Owner Author

ColinPitrat commented Aug 17, 2022

So, good news is that I have some code that works for one gun (Amstrad Magnum Phazer) with one game from the compilation (Mission) when running in windowed mode.

I know this sounds promising, but it relies on some weird hardcoded values and there's still a lot of things that are not well understood...

In particular, it doesn't work in mode 0 (and probably not in mode 2). It doesn't work in fullscreen (because the mouse coordinates are different in this case). And I'm pretty sure it wouldn't work well with overscan or other weird CRTC parameters.

@Huntsman360
Copy link

thanks a lot for the effort

It's more difficult than i thought

@Tovarichtch
Copy link

Tovarichtch commented Aug 25, 2022

I'm currently testing for light gun support on a frontend I'm helping with and I'm very interested to see where this is going ! Caprice32 with light gun support would be amazing for GX 4000 / CPC+. I wish I could help, but I have no coding knowledge.

@ColinPitrat
Copy link
Owner Author

Experimental support is now in for Amstrad Magnum Phaser (https://www.cpcwiki.eu/index.php/Amstrad_Magnum_Phaser).

To try it, press Shift+F7 and use the mouse. This requires games that specially support the Amstrad Magnum Phaser (and not another lightgun as these are likely working differently)

@Tovarichtch
Copy link

Great news !

I would love to try it, but latest release on Windows is from november 2021. Sadly, I don't know how to compile myself. If you can update the binaries so I can test it, that would be great !

@ColinPitrat
Copy link
Owner Author

Yeah Windows release was broken. There were multiple issues but it's now fixed:
https://github.com/ColinPitrat/caprice32/releases/tag/latest

@ColinPitrat
Copy link
Owner Author

Added the support for Trojan Light Phazer.
Pressing Shift+F7 once switches to the Amstrad Magnum Phazer. Pressing a second time switch to the Trojan Light Phazer.

I tested it with all the supported games:

  • Amstrad Magnum Phaser
    • Operation Wolf (clearly the best)
    • Bullseye
    • Missile Ground Zero
    • Robot Attack
    • Rookie
    • Solar Invasion
    • American Turbo-King
    • Billy the Kid
    • Bronx Street Cop
    • F-16 Fighting Falcon
    • Jungle Warfare
  • Trojan Light Phazer
    • The Enforcer
    • Skee Shoot

@Tovarichtch
Copy link

Tovarichtch commented Oct 3, 2022

I've tested the same games as you listed above my comment, plus the other unsupported ones (West Phaser and Gunstick games). Good news is : Amstrad Magnum Phaser and Trojan Light Phazer games are working very well ! So I confirm your play test.

Trojan Light Phazer does trigger the fire for Gunstick/West Phaser light gun games. That's at least something to look into. Almost working.

Well done on adding light gun support ! I know people that will be really happy to hear that.

@ColinPitrat
Copy link
Owner Author

Yeah Gunstick works differently. I don't yet understand how, it's very poorly documented.

@Tovarichtch
Copy link

Tovarichtch commented Oct 3, 2022

You are right. Almost all the docs are in spanish with almost no details. Several emulators have this integrated already like CPCEC, CPCEPower, CaPriCe Forever and even WiiTuka (for Wii), maybe their code could reveal something interesting ?

There are lot of links in the description of this youtube video with a full demonstration of the hardware here.

@ColinPitrat
Copy link
Owner Author

Yeah I was having a look at WiiTuka but I'm not sure whether their implementation is really faithful to the hardware. I'll check how the other emulators implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants