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

Question: BIOS calls like PLAYER_START? #11

Closed
city41 opened this issue Dec 8, 2018 · 5 comments · Fixed by #29
Closed

Question: BIOS calls like PLAYER_START? #11

city41 opened this issue Dec 8, 2018 · 5 comments · Fixed by #29

Comments

@city41
Copy link

city41 commented Dec 8, 2018

I am brand new to Neo Geo dev.

I've been reading the examples over at https://github.com/freem/freemlib-neogeo/tree/master/examples

I'm curious how to deal with things like PLAYER_START, DEMO_END, COIN_SOUND and BIOS_USER_REQUEST in ngdevkit?

I see if the game defines a function named rom_callback_VBlank then it will get called on vblank. Is it possible to do a similar callback approach for the above subroutines?

Thanks!

@city41
Copy link
Author

city41 commented Dec 8, 2018

I think I figured it out.

It looks like runtime/crt0.s is the program header file for the ROM.

neogeodev has one here: https://wiki.neogeodev.org/index.php?title=68k_program_header

Where they do

    jmp        USER
    jmp        PLAYER_START
    jmp        DEMO_END
    jmp        COIN_SOUND

ngdevkit's crt0.S does

	/* ROM Entry Point */
	jmp     GAME_BOOT.l
	jmp     .LStart2.l
	jmp     .LStart3.l

where GAME_BOOT calls C's main(), and the others are noops.

So it looks like if I needed support for say COIN_SOUND, I could edit crt0.S and add it.

@dciabrin
Copy link
Owner

I need a bit of time to figure out that one.

The whole idea behind the devkit is to have a ld linkscript that woudl automatically map your user-provided functions in the program header, like it's done for the VBlank interrupt handler, and revert to default no-op otherwise.

As a proof-of-concept, I did the vblank and hblank interrupt handlers, but I didn't map anything else yet in the ld linkscript.

I suspect though that this jump table is meant to be called by the original BIOS, so if we want a similar support in ngdevkit, we'd have to implement input polling and jmp in nullbios.

Until I come back with an example in the devkit, I think you don't have any other choice than to poll the inputs yourself in your own vblank handler.

@city41
Copy link
Author

city41 commented Dec 27, 2018

I'm currently exploring this. My first goal is to get the eye catcher to run then to move onto the game.
I've edited crt0.S and attempted to get it to follow what freem did in his neo geo lib.

So far the rom just boots to the cross hatch in gngeo.

I'm not exploring it by trying to get user defined functions in the linkscript, just editing the assembly directly. If I can get this working, I'll see about the linkscript next.

@city41
Copy link
Author

city41 commented Dec 27, 2018

I'm slowly but surely learning 68k asm :)

This hack allows the eyecatcher to run, then boots into the game proper:

https://github.com/city41/ngdevkit/commit/2f3395ee5208c5bc5746f95434628bba75b53293

Not good enough to make official, but if anyone reading this has any suggestions, I'd love to hear it.

(oh and you need the real neo geo bios instead of null bios)

dciabrin added a commit that referenced this issue Jan 5, 2020
It better reflects that this is a configurable value, and it will
avoid a name conflict when implementing #11

Ref #19
dciabrin added a commit that referenced this issue Jan 5, 2020
Currently the game boots straight to the C's main function, without
honoring the various initial command calls that the Neo Geo BIOS may
request at startup. This prevents the Eye Catcher animation from
showing properly.

Fix that by implementing implementing the request calls as expected
by the BIOS. Make nullbios mimick that behaviour as well.

The default is now to jump to C's main only after the Eye Catcher,
but that behaviour can be overriden by providing your own functions
with the same name (the link script will use them automatically).

Closes #11
@dciabrin
Copy link
Owner

dciabrin commented Jan 5, 2020

OK so I finally came up with what I believe is what you asked for in the first place. I fixed how crt0 behaves when the BIOS calls it, so it can distinguish between request type 0 (StartupInit) and request type 2 (Game).

Previously, crt0 would jump into your C main as soon as USER subroutine is called.
On MVS though, the first time you plug the cartridge into the board, the BIOS detects it and calls USER subroutine with request 0 before running the Eye Catcher, so crt0 pre-empts the Eye Catcher. It does it only once though, so on next soft or hard reset, my understanding is that the Eye Catcher would be run. (you can experience that with MAME by re-running the emulator several times).

Now crt0 correctly honours what the BIOS is requesting, and calls default functions for all the 4 request types. At link time, the linker checks whether you provided your own functions for each request type, and if so it will use it, otherwise it will default to what crt0 provides currently: initializing the C runtime and calling the C main.

Also, all those behaviour happens at the right time, so the Eye Catcher will play if configured to. If needed, you can disable the Eye Catcher as explained in #19.

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

Successfully merging a pull request may close this issue.

2 participants