PSG sounds for SMS and GameGear

Post Reply
Fabrizio
Member
Posts: 114
Joined: Tue Jul 11, 2017 9:28 pm

PSG sounds for SMS and GameGear

Post by Fabrizio »

Hi!
I have never managed to figure out how to produce sounds with the PSG APIs on the SMS and GameGear.
Bit-banging may not work (no sound is reproduced by KegaFusion even though commercial games do)
and I am not able to compile a simple example with SN PSG (with new APIs such as `psg_channels`).
I have just opened issue #1995 (https://github.com/z88dk/z88dk/issues/1995).
It looks like a bug but maybe I am doing something wrong with the code or the compilation line.

Could someone please provide a simple example that can be compiled and can produce a beep sound on the SMS and/or GameGear?
In particular, as shown in the issue, it seems that `psg_channels` is not found.
If possible I would like to do it with generic code that can be used on several SN PSG targets.

Fabrizio
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: PSG sounds for SMS and GameGear

Post by cborn »

Hello,
is that about AY and YM sound generators?
the ay on zx uses different ports and even 16bit adrsing aginst eg MSX or gameboy which uses 8bit adresing.
in c , i dont know, but i wanted to mention the differences.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: PSG sounds for SMS and GameGear

Post by Timmy »

I don't know how to make SMS code (and I don't really care about it much), but after reading some documentation, it's probably simple to make a really simple routine for the SMS SN.

This SN chip is a tone generating chip, it has much less features than an AY chip. That means you can "only" make a tone yourself and then disable it sometime later.

(none of the following is tested, I don't even have an SMS emulator nor do I know how to make a simple program for it.)
(no guarantees at all.)

Code: Select all


#asm
  ld a, 142
  out (127), a
  ld a, 15
  out (127), a
  ld a, 144
  out (127), a
#endasm

// code for waiting for 30 frames here
// maybe 30 x halt?

#asm
  ld a, 159
  out (127), a
#endasm

// wait another 30 frames

// then loop this

Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: PSG sounds for SMS and GameGear

Post by Timmy »

Strange, I've tried compiling the example in "examples/sound/psglib", and it didn't made any sound for me in an emulator either.

So I've finished the minimal code in the previous post, and managed to compiled it and it made sound in an emulator.

Code: Select all

/*
 * A SMS psg test, april 1st 2022
 *
 * Compile with:
 *    zcc +sms -create-app -o sms1.sms sms1.c
 */
 
void main()
{
	char i;
	
	while(1) 
	{
		#asm
		  ld a, 142
		  out (127), a
		  ld a, 15
		  out (127), a
		  ld a, 144
		  out (127), a
		#endasm

		for (i=0;i<30;i++)
		#asm
			halt
		#endasm

		#asm
		  ld a, 159
		  out (127), a
		#endasm

		for (i=0;i<30;i++)
		#asm
			halt
		#endasm
  }
}
Can you check if this make any sounds in your emulator? Just to check if your emulator is working.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: PSG sounds for SMS and GameGear

Post by Timmy »

One more thing: Strangely, on my emulator (Fusion) if I change the "psg" port into $40, then there is no sound.

But it works if I set the port to $7F then the code above plays a note.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: PSG sounds for SMS and GameGear

Post by stefano »

this latter case is understandable, in your asm inclusion you are outputting to port 127 (= $7F).
Probably changing the OUT instructions to port 64 it would switch to $40
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: PSG sounds for SMS and GameGear

Post by Timmy »

Oops, I meant that if I changed my code above into port $40, there is no sound coming out of my emulator.

Which is strange, since in https://github.com/z88dk/z88dk/blob/mas ... n76489.inc , there is this bit of code:

Code: Select all

IF FORsms
	defc psgport	= $40
ENDIF
Why is the default psg port on the sms defined as $40? The default port is $7F. (at least, in the places i looked up on duck.com)
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: PSG sounds for SMS and GameGear

Post by dom »

It's interesting, because the PSG is meant to be available on port $40 -> $7f (https://www.smspower.org/Development/SN ... opment.PSG)

I'm not sure why $40 was chosen but in theory it should work.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: PSG sounds for SMS and GameGear

Post by jorgegv »

Mmmm in that very same reference It also says that Port 7f was the recommended Port for writing...
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: PSG sounds for SMS and GameGear

Post by Timmy »

I guess Fabrizio is the only person who can verify whether this is a default port problem or not, by testing the program I wrote above. It's mostly speculations from my side. It could have been something else.
Post Reply