Page 1 of 1

Cd functions when using exe

Posted: November 18th, 2022, 1:53 pm
by Tylerpsx
When I use exe for debug on my psx emulator when running cd type function
In the development librarys will the exe be able to get the library’s like if it was using the cd but virtually or will I have to use a program to turn the files or modify the files to be read by the exe and if so can someone point me in the right direction

Re: Cd functions when using exe

Posted: November 18th, 2022, 4:15 pm
by Shadow
If you're using an emulator, you can read the files from the CD (be it via malloc or a hard coded memory location). Otherwise, you will need to include them as raw binary data in the EXE itself which wastes a lot of BSS room. If you're making a game, I'd recommend using some malloc routines when using the CD so you can load data into the heap, use it as needed and then free that heap space for other stuff later.

Re: Cd functions when using exe

Posted: December 3rd, 2022, 9:57 am
by Xavi92
Shadow wrote:I'd recommend using some malloc routines when using the CD so you can load data into the heap, use it as needed and then free that heap space for other stuff later.
If using fread(3) to read CD-ROM data, a more space-efficient (although possibly a bit slower) alternative is buffered I/O. This means the underlying libc implementation stores a sector-sized (i.e., 2048 byte) cache in order to allow applications to read from memory (which is faster than CD-ROM access) as long as it resides within the same sector. I keep a forked copy of PSXSDK where I have implemented this.

If using buffered I/O, applications do not need to allocate a large amount of memory to read a complete file, but only the exact amount of bytes that are needed, and let the libc implementation do the rest. This is an example from a video game I am working on, where small amounts of memory are allocated on the stack to read a TIM file from CD-ROM to GPU.