CdInit() in psyq

General help for the PSY-Q SDK, such as setting the SDK up, compiling correctly, linking and debugging
Post Reply
ericde45
Curious PSXDEV User
Curious PSXDEV User
Posts: 18
Joined: August 7th, 2024, 6:57 pm
Location: France

CdInit() in psyq

Post by ericde45 » September 2nd, 2024, 7:00 am

hello

i'm using a nugget converted version of psyq, to be able to use it on my windows 10
i am able to compile a simple hello world, or more advanced code
but when i try to do a simple CdInit(), after #include <libcd.h> i get a link error ;

undefined reference to `CdInit'

i got the already converted file psyq-4.7-converted-full.7z

is there an alternative to download another version of psyq converted ?
can someone confirm that he encounters the same issue with cdinit ?

update : i tried pysq converted, light version, and i tried to convert it myself using https://gitlab.com/jype/psyq2elf/-/tree/master
and i still have the same issue

thanks

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 643
Joined: November 12th, 2012, 2:36 pm
Contact:

Post by nocash » September 2nd, 2024, 1:44 pm

In the PSX kernel, CdInit is an internal function that should be never called from normal software. I would be just not doing such things, unless you are on some ultra-low-level hacking quest, or unless that psyq has a different function with same name that needs to be called from software.

PS. My preferred pronouns are none & anyone. Why did you ask him? Is that you year of birth, 45? Cringe, man!

ericde45
Curious PSXDEV User
Curious PSXDEV User
Posts: 18
Joined: August 7th, 2024, 6:57 pm
Location: France

Post by ericde45 » September 2nd, 2024, 4:53 pm

hello,

thanks a lot for your answer.

ok i will dig that with extern, but yes i am working on the usb cartridge made by Orion and i am trying to add unlock to it, so that i can use the CD on my ps1 that have no modchip.

i would prefer using psnoobsdk, but as orion did his cartridge software using psyq, once the ps1 is running psyq init+int handler and so on, switching to psnoobsdk code and calling unlock just crash.

his cartridge is really very convenient to be able to upload using usb.

ps : and no, i'm 53... and currently finishing a 36800 asm lines game for the Atari Jaguar : https://forums.atariage.com/topic/355685-xenowings/

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 643
Joined: November 12th, 2012, 2:36 pm
Contact:

Post by nocash » September 2nd, 2024, 5:42 pm

Okay, normally you could try to call kernel functions via A0h vectors, but if you have booted from expansion rom instead of cdrom then you can't even do that, unless it has the mid-boot trick implemented....

https://problemkaputt.de/psxspx-exp1-ex ... header.htm

On the other hand, for a project under 2Mbyte, you would be better off to store your data in the exe file, the cdrom seek times for loading multiple small files would only slow down the boot process.

ericde45
Curious PSXDEV User
Curious PSXDEV User
Posts: 18
Joined: August 7th, 2024, 6:57 pm
Location: France

Post by ericde45 » September 2nd, 2024, 5:54 pm

yes, Orion's cartridge is using https://github.com/Lameguy64/PSn00bSDK/ ... el/cartrom, so exactly the mid boot trick

do you know if unlocking the CD is possible anytime , for example after a lot of initializations, like ResetCallback(); or InstallExceptionHandler(); ?

or shall it be done just after the breakpoint of the mid boot ?

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 643
Joined: November 12th, 2012, 2:36 pm
Contact:

Post by nocash » September 2nd, 2024, 7:42 pm

The unlock commands should work anytime, but obviously best done before loading data from cdrom (including things like loading the root directory, which should happen automatically, but won't work if the disc wasn't unlocked at that time).

So yes, better do the unlock early on, and take care that the unlock commands won't collide with other cdrom commands. It's probably safest to issue the unlock commands right in the pre-boot handler.

ericde45
Curious PSXDEV User
Curious PSXDEV User
Posts: 18
Joined: August 7th, 2024, 6:57 pm
Location: France

Post by ericde45 » September 2nd, 2024, 8:02 pm

thanks
and thanks for all your work, contributing to create a real ps1 scene for homebrew.
the global work done on ps1 is impressive, for someone coming from other consoles :)

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 643
Joined: November 12th, 2012, 2:36 pm
Contact:

Post by nocash » September 3rd, 2024, 7:15 am

Did you get it working?

I've looked up some things:

Unlock working anytime wasn't quite right: After power-up, or after resetting the cdrom controller, one must wait 1/8 seconds before sending unlock commands (or any other commands) to the cdrom.

Uhm, and for CdInit, I seem to have renamed some kernel functions, the official name seems to be _96_init (supposedly short for ISO9660). The function is quite slow (includes a hardcoded 0.5 second delay), so it's best to send it only if need (only if you really want to access the cdrom, and only if the EXE wasn't already read from cdrom).

ericde45
Curious PSXDEV User
Curious PSXDEV User
Posts: 18
Joined: August 7th, 2024, 6:57 pm
Location: France

Post by ericde45 » September 3rd, 2024, 5:18 pm

yes i got it to work, i was missing a flag in the linker to link the CD library.
and cdinit is the right function to launch before unlock if i follow all existing examples of sources i found.

i moved to another stategy : instead of using psyq that is old and with no source available, i recoded some parts of orion's firmware using PSnoobSDK.

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 643
Joined: November 12th, 2012, 2:36 pm
Contact:

Post by nocash » September 5th, 2024, 2:15 am

I would have done Unlock before CdInit.

If that didn't work, maybe CdInit did initialize some control registers, which were required by your Unlock function. Or, if it was done early after power on, maybe the 1/2 second delay in CdInit did solve must wait 1/8 seconds after reset issue.

CdInit does setup some IRQ handling, which might conflict with the unlock commands, and CdInit tries to read the Path Tables, which can't work before unlock (but as it's working, the kernel does apparently manage to read the Path Tables later on).

ericde45
Curious PSXDEV User
Curious PSXDEV User
Posts: 18
Joined: August 7th, 2024, 6:57 pm
Location: France

Post by ericde45 » September 5th, 2024, 5:54 am

hello,

without any previous initializations, coming nearly directly from the mid boot breakpoint, i do with success:

ResetGraph( 0 );

// unlock CD...
printf("Init CD...\n");
CdInit();
CdlRegionCode code_region = CdGetRegion();
printf("region : %d\n",code_region);
int retour_unlock = CdUnlock(code_region);

which gives :

Executing...
psxgpu: setup done, default mode is NTSC
Init CD...
psxcd: shell opened, invalidating cache
psxcd: CdSync() timeout
psxcd: setup done
psxcd: drive firmware version: 0xc3
psxcd: drive region: for Europe
region : 3
psxcd: drive error, status=0x03, code=0x00
psxcd: unlock successful

so it seems to be working :)

i am able to read system.cnf from my CDR ( with no modchip of course )


PS : using PSnoobSDK, of course. as CdUnlock is a function available in this SDK directly.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests