Author Topic: Multiple questions about PCE dev  (Read 201 times)

not_again

  • Newbie
  • *
  • Posts: 3
Multiple questions about PCE dev
« on: February 28, 2025, 10:26:20 PM »
Hello, I'm new here and to the PC-Engine in general.  :)

I've have experience with NES/SNES dev.

I'm testing my code on emulators (Mednafen / Mesen).

I'm using assembly.

So far I got the basics down for developing a HUCard game. But I can already see how ROM space would be an issue when developing a full game. Hence, I have some questions regarding CD games programming:

  • How can one signal to emulators that the game binary is a CD game?
  • I've notice that CD games have different binary formats, why?
  • Where in the HuC6280 address space do a CD game starts in? I mean, what is the process of the game code in the CD to 'take over'?

Quote
The TurboGrafx-16 CD hardware consists of the following:

 - 64K general purpose RAM for the CD software to use

  • What exactly does this mean? 64K to decompress tiles, etc?
  • Can one access this RAM without the System Card? If so, how?
    (I tried setting the address with $1808/$1809 and then writing to $180A, but the RAM did not changed)

Quote
- 64K ADPCM RAM for sample storage
  • Regarding ADPCM, is this a completely different system from the base PC-Engine's PSG sound system?

Quote
- 2K battery backed RAM for save game data and high scores
  • Is this 2k for all games? How does one know the amount of RAM available for your game, and at which location?

Is it possible for a HuCard game to run the CD hardware without the need of a System Card?

Thank you for your help!!! Sorry if my questions are too basic.  :-[
« Last Edit: February 28, 2025, 10:28:33 PM by not_again »

elmer

  • Hero Member
  • *****
  • Posts: 2159
Re: Multiple questions about PCE dev
« Reply #1 on: March 01, 2025, 12:27:57 PM »
I'm using assembly.

Welcome, it's always nice to see someone willing to program in asm!


How can one signal to emulators that the game binary is a CD game?

Generally you tell them to load/run a .CUE file instead of a .PCE/.SGX HuCARD image.

A .CUE file is a text file that describes a CD track layout, including the names the other files on your computer that contain the data for each of those tracks (whether the tracks are CD audio data or CD-ROM data).

The data in the tracks can be either the raw CD standard-compliant bitstream with includes all the additional error-correction information, or it can be just a number of 2048-byte binary sectors for the CD-ROM tracks, and a set of .WAV files for the CD-AUDIO tracks.

The CD-ROM tracks have no filesystem, that luxury didn't happen until many years later.

In the case of the PC Engine, the System Card reads the first 2 sectors of the first CD-ROM track on the disc, and if they contain the appropriate signature data that it's looking for, then it uses the information in second sector to tell it what data sectors to load from the CD, where to put them in memory, and what address to jump to to start executing the game program.


I've notice that CD games have different binary formats, why?

Well, technically they don't ... it's always an image of a CD.

But there have been many different ways of representing the contents of a CD that have been used over the years, and emulators often have to support a number of different conventions because there was no universal standard when people started to rip the contents of CD discs onto their computers.

The easiest convention to use for developing homebrew is the .CUE/.BIN/.WAV format.


Where in the HuC6280 address space do a CD game starts in? I mean, what is the process of the game code in the CD to 'take over'?

As mentioned above, this is determined by the game's boot sectors.

Have you found Hudson's official System Card documentation yet? The boot process is described in there.

Most developers really don't get too deep into that stuff because we have tools to take care of that stuff and make life easier.

What toolchain are you currently using for you PC Engine experiments?

Coming from the NES and SNES, I could see you using CA65 or WLA-DX ... but those really aren't the best tools for PC Engine coding (IMHO).


The TurboGrafx-16 CD hardware consists of the following:

 - 64K general purpose RAM for the CD software to use


What exactly does this mean? 64K to decompress tiles, etc?

It means that you have 64KBytes of CPU accessible memory available for your program and data.

If you need different code/data, then you have to load it from your game's CD-ROM track.

There aren't many sane reasons to develop for the original System Card these days, you're going to get much nicer results if you develop for the Super System Card which bumps up the RAM to 256KBytes.


Can one access this RAM without the System Card? If so, how?

It's just RAM in banks $80..$87 (or banks $68..$87 for the Super System Card).


(I tried setting the address with $1808/$1809 and then writing to $180A, but the RAM did not changed)

Regarding ADPCM, is this a completely different system from the base PC-Engine's PSG sound system?

Yes, it's a completely different system from the PSG, with its own 64KBytes of memory.

Those registers that you're playing with are for reading/writing that ADPCM memory from the main CPU. It's quite slow.

Early PC Engine CD games with the 64KByte RAM limit sometimes stored extra graphics/code in the ADPCM memory because that was (sometimes) faster than seeking to find the data on the CD-ROM.


- 2K battery backed RAM for save game data and high scores

Is this 2k for all games? How does one know the amount of RAM available for your game, and at which location?

2KBytes shared for all games. There is a storage convention that you use for allocating and using "files" within that 2KBytes. You normally use the System Card functions to do the reading/writing if you're developing a CD game.


Is it possible for a HuCard game to run the CD hardware without the need of a System Card?

Perfectly possible, just rarely done because it makes little sense for game development.

If you're developing a HuCARD game then you're generally doing it because you want it to run on PC Engine hardware that doesn't have a CD drive.

If you're developing a CD game, then there's no reason to include the horrific expense of including a HuCARD as well, it doesn't get you any benefits.

not_again

  • Newbie
  • *
  • Posts: 3
Re: Multiple questions about PCE dev
« Reply #2 on: March 04, 2025, 05:49:53 AM »
Thank you for your time, and sorry for the late respond. 


Quote
Generally you tell them to load/run a .CUE file instead of a .PCE/.SGX HuCARD image.

A .CUE file is a text file that describes a CD track layout, including the names the other files on your computer that contain the data for each of those tracks (whether the tracks are CD audio data or CD-ROM data).

The data in the tracks can be either the raw CD standard-compliant bitstream with includes all the additional error-correction information, or it can be just a number of 2048-byte binary sectors for the CD-ROM tracks, and a set of .WAV files for the CD-AUDIO tracks.
I've never programmed anything CD based. Can one think of theses sectors as banks?


Quote
In the case of the PC Engine, the System Card reads the first 2 sectors of the first CD-ROM track on the disc, and if they contain the appropriate signature data that it's looking for, then it uses the information in second sector to tell it what data sectors to load from the CD, where to put them in memory, and what address to jump to to start executing the game program.


The easiest convention to use for developing homebrew is the .CUE/.BIN/.WAV format.
What is the best format for burning to a CD and playing in real hardware?


Quote
Have you found Hudson's official System Card documentation yet? The boot process is described in there.
I've found one named "Hu7 CD System - BIOS Manual.pdf" and one named "Hu7 CD System - Software Manual.pdf". Are those it?

Quote
Most developers really don't get too deep into that stuff because we have tools to take care of that stuff and make life easier.

What toolchain are you currently using for you PC Engine experiments?

Coming from the NES and SNES, I could see you using CA65 or WLA-DX ... but those really aren't the best tools for PC Engine coding (IMHO).
Yep, I'm using WLA. What is a better toolchain for dev in assembly?


So for a base unit, the RAM is inside the System Card and accessed in banks $68..$87, and ADPCM RAM is inside the CD unit and accessed by $1808/$1809/$180A? (I understand there are various version of the hardware that contains the System Card within.)

Developing for Super System Card seems more sane.  :)

Thanks again.

BTW: Can I used this thread to share my progress and files or should I make a different one?
« Last Edit: March 04, 2025, 05:52:35 AM by not_again »

elmer

  • Hero Member
  • *****
  • Posts: 2159
Re: Multiple questions about PCE dev
« Reply #3 on: March 04, 2025, 01:06:00 PM »
I've never programmed anything CD based. Can one think of theses sectors as banks?

You can, if you like, but there's not a lot of reason to do so.

A CD sector is 2KBytes, and a bank is 8KBytes, so they don't always align ... but that's a simple conversion that you can do in your head.

It's generally a bit easier, and conceptually cleaner, to think of CD-ROM data as a bunch of files, just like on your computer's hard drive, and there are tools and library code available to use them in that way.

You don't have to do things that way if you don't want to, but you'll end up having to create some of your own tools if you wish to just deal with the CD-ROM track as what is basically just a large sequence of 2KByte sectors.

It's not overly difficult, but it is usually a rather annoying way to develop something, and so I wouldn't particularly recommend it as a starting point.


Quote
What is the best format for burning to a CD and playing in real hardware?

Most of the time you can just use Mesen for development, but when you're ready to burn something for testing ...

.CUE/.BIN/.WAV is supported by all CD buring software that I know.

Your bigger problem is going to be in burning a CD that the old hardware will read. The PC Engine's CD drives were designed before CD burners existed, and they were never designed to read burned CDs.

You may need to try a few different types of CD-R and different burners before you'll come up with a combination that your PC Engine will read. I *highly* recommend using 74-minute (650MB) CD-R discs instead of 80-minute (700MB) CD-R discs.

You may find this person's experiences helpful ...

https://consolemods.org/wiki/User:Derf/CD_Burning_Shenanigans


Quote
I've found one named "Hu7 CD System - BIOS Manual.pdf" and one named "Hu7 CD System - Software Manual.pdf". Are those it?

Yes!


Quote
Yep, I'm using WLA. What is a better toolchain for dev in assembly?

https://github.com/pce-devel/huc

HuC contains the latest PCEAS assembler and other PC Engine tools, and a bunch of assembly language examples ... it's not just for C! ;-)


Quote
So for a base unit, the RAM is inside the System Card and accessed in banks $68..$87, and ADPCM RAM is inside the CD unit and accessed by $1808/$1809/$180A? (I understand there are various version of the hardware that contains the System Card within.)

Yes!


Quote
BTW: Can I used this thread to share my progress and files or should I make a different one?

Completely up to you.

This forum is a bit quiet these days, and you might find a tiny bit more life on the PC Engine Software Bible forum ... but honestly most developers seem to have moved to Discord.

not_again

  • Newbie
  • *
  • Posts: 3
Re: Multiple questions about PCE dev
« Reply #4 on: March 18, 2025, 11:35:00 PM »
Hello again Elmer :)

I managed to get some CD code working, but I'm sticking with Hucard ver for now. :P

Regarding DDA output for the PSG:

1. Samples are mono - 5 bit, right?
2. What's the best way to transform wav to something that sounds good?
    I tried using Audacity -> raw out put : mono / 8 bit; then shifting right each byte by 3. It sounds like a mess.
3. What Hz should the sample be in?

Thank you for your time.

elmer

  • Hero Member
  • *****
  • Posts: 2159
Re: Multiple questions about PCE dev
« Reply #5 on: March 19, 2025, 11:51:39 PM »
I managed to get some CD code working, but I'm sticking with Hucard ver for now. :P

 :thumbsup:


Quote
1. Samples are mono - 5 bit, right?

5-bit mono per channel, yes.

You *can* use 2 channels to get 10-bit sample output, but then that costs you 2 channels.


Quote
2. What's the best way to transform wav to something that sounds good?

Burn it to a CD? Convert it to ADPCM?  :-k

I really don't know why so many people seem to think that spending lots of CPU time to manually pump a 5-bit sample output is somehow a good idea.  :roll:


Quote
I tried using Audacity -> raw out put : mono / 8 bit; then shifting right each byte by 3. It sounds like a mess.

Depending upon your definition of "mess", you've probably got a bug in your code.


Quote
3. What Hz should the sample be in?

That entirely depends upon how you intend to control the timing of your output. It's 100% manual, so it's up to you.

Most people use the timer interrupt, and the maximum rate for that is 6991Hz.

You can also use the RCR interrupt to get 15KHz, but that's both more work, and also interferes with using the RCR interrupt for scrolling.

Or you can be like Deflemask's monumentally-stupid ROM output and use 100% of the CPU time and software-loops to get much faster sample output.

It's all up to you.