32X PWM channel mapping

Ask anything your want about the 32X Mushroom programming.

Moderator: BigEvilCorporation

Post Reply
Michel Gerritse
Interested
Posts: 12
Joined: Sat Apr 25, 2020 7:25 pm
Location: The Netherlands

32X PWM channel mapping

Post by Michel Gerritse » Fri May 26, 2023 2:52 pm

I've been working on various sound cores and recently implemented the 32X PWM for my own VGM Player / emulation project.

The repository can be found here:
https://github.com/michelgerritse/TritonCore

The last feature I need to implement is the channel mapping for the PWM sound channels (minus some SH2 DREQ and interrupt stuff which is not needed for a VGM player. Also the 3-step FIFO is missing for obvious reasons).
According to the official documentation, this is controlled by the PWM Control Register. The layout is as follows:

Code: Select all

	
	| b15 | b14 | b13 | b12 | b11 | b10 | b09 | b08 | b07 | b06 | b05 | b04 | b03 | b02 | b01 | b00 |
	+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
	| --- | --- | --- | --- | TM3 | TM2 | TM1 | TM0 | RTP | --- | --- | --- | RMD0| RMD1| LMD0| LMD1|

	
	| RMD0| RMD1| OUT |		| LMD0| LMD1| OUT |
	+-----+-----+-----+		+-----+-----+-----+
	|  0  |  0  | OFF |		|  0  |  0  | OFF |
	|  0  |  1  |  R  |		|  0  |  1  |  L  |
	|  1  |  0  |  L  |		|  1  |  0  |  R  |
	|  1  |  1  | N/A |		|  1  |  1  | N/A |
The documentation tells you not to set both PWM channels to the same output (so both set to L or R). Also, setting each PWM channel to output to both L + R is not allowed.

The obvious question is: what happens if you ignore the documentation and try anyway ? Will you get clipping / distortion when both PWM channels are mapped to L or R ? Will the device go silent ? Is only a single PWM channel audible (if so, which one) ?

Since I don't have the hardware anymore I'm not able to test, can anyone with the hardware confirm what the 32X does ?

Edit: I noticed some game (e.g Tempo and Knuckles' Chaotix) set both RMD and LMD to OFF. So my conclusion here is that if you disable both PWM channels, they will still output normally. I had already figured this out over 20 years ago in Xega :S

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: 32X PWM channel mapping

Post by Chilly Willy » Sun May 28, 2023 9:29 pm

I haven't tried playing around with every setting of the PWM steering, but I know that how you are supposed to set it works as documented. If you want mono, you shouldn't try to map both channels to the both outputs (or the same output), you should use the PWM mono register, which writes the word written to it into both the left and right PWM registers. My demos that use mono do word DMA from the buffer of mono PWM word samples to the PWM MONO register. My demos that use stereo do long DMA from the buffer of stereo word samples to the PWM LEFT/RIGHT registers (storing a LONG value to the left register stores a word to the left register, and the next word to the right register which is immediately after the left register in memory).

Michel Gerritse
Interested
Posts: 12
Joined: Sat Apr 25, 2020 7:25 pm
Location: The Netherlands

Re: 32X PWM channel mapping

Post by Michel Gerritse » Tue May 30, 2023 11:34 am

Agreed, the PWM works as documented with the only exception:

When both channels are set to OFF (0x00 written to xMD), they will output normally as if the value 0x05 was written to the xMD registers. This is actually needed by a lot of games. This contradicts the statement in the 32X hardware manual: "The cycle counter does not operate when both L ch and R ch are off" (page 24).

What I'm really after is the behavior when you set xMD to something you are not supposed to do. It's not really important because I think no game does this, but for the sake of completeness I would like to implement the same behavior as the real hardware.

Post Reply