Simple AY music demo in z88dk (with source)

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Simple AY music demo in z88dk (with source)

Post by Timmy »

I've noticed there wasn't an AY music playing library, so I've made one for fun.

http://www.worldofspectrum.org/forums/s ... hp?t=40525

This one specifically works on the 128k spectrum, but should be easily convertable to other machines with AY chip.
(output port have to be changed for other machines, as well as note periods that is dependent of clock rate.)

(I also realise that this is not my best program, but I thought it might be interesting to some of you.) :P
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Timmy,
good job, I like the demo too.

The only soundchip lib available at the moment is for the MSX (http://z88dk.cvs.sourceforge.net/z88dk/z88dk/include/msx.h?view=markup ..see the PSG stuff), but I never managed tp make it general, so as soon as you think it is complete or at a stable stage, just tell.. I'd be glad to include it in the library.
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Thanks for the reply. Glad you like it.

I will work a little bit more on it because not every function of the AY chip is exposed yet.

As for the MSX PSG functions, well, the ZX 128 as the MSX use the same music chip.

I just read that part of the code, and the msx functions actually do the same things, only in higher level C code. You could probably salvage those PSG functions as well by just swapping msx_set_psg for ay_command in my library, if you want to. At this stage I'm not sure if I want those high level C code in the library yet.

Anyway, you're much more experienced in making libraries than me, so any suggestions are welcome. :) Or if you just want to use part of the code to write your own library for it, I don't mind too.
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Yup, every machine had its addressing peculiarities own to reach the chip registers.
As for similar things z88dk just permits an easier portability between the target platforms ;)
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

You know, I've decided that I will keep this for now. If I need more functions I can always expand it later, but this should already work as is.

Something that I can't use in my spectrum library but I can put it here, according to http://www.vdsteenoven.com/aquarius/psgprog.html

You can swap the function for this if you want to play it on the Aquarius. (obviously all note periods will still need be changed, but that's currently outside my library :))

Code: Select all

void __FASTCALL__ ay_command(unsigned char *p)
{
        // Note: Plays on the Mattel Aquarius! (untested)
        // IN:  h=register, l=value
        // OUT: out 0xF7,h : out 0xF6,l

        #asm
                ld a, h
                out (0xf7), a
                ld a, l
                out (0xf6), a
        #endasm
}
I have obviously no use for this code, but perhaps you can.
Last edited by Timmy on Fri Aug 24, 2012 8:33 pm, edited 1 time in total.
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Just wanted to say that there's a new version of the library, in which some comments have been changed.

The code, however, has not been changed.

Also a new demo. (with sources, although with the older version of the library.)

http://www.worldofspectrum.org/forums/s ... 525&page=2
Last edited by Timmy on Tue Aug 28, 2012 3:03 pm, edited 1 time in total.
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

5 Years later... And I finally got this working on the MSX too.

The code needed for MSX was this:

Code: Select all

void __FASTCALL__ ay_command(unsigned char *p)
{
        // Note: Plays on the MSX! (tested only on one MSX configuration on one MSX emulator)
        // IN:  h=register, l=value
        // OUT: out 0xA0,h : out 0xA1,l

        #asm
                ld a, h
                out (0xA0), a
                ld a, l
                out (0xA1), a
        #endasm
}
IMPORTANT NOTE: This is a library to send data to the PSG directly, with no data checking (for speed purposes) and do not use the MSX BIOS calls. DO NOT USE IT IF YOU HAVE NO IDEA HOW THE CHIP ON THE MSX WORKS. Sending incompatible data to the AY chip on the MSX could result in a broken computer!

(Also, the fact that it does not have any bios calls means it's more suitable for ROMs rather than tape files. Because, I've been told, the psg bios init function GICINI should normally be called before a tape program, because it's more likely the PSG was used before, and needs to be reinitialised.)

I should port my music demo to the MSX too... One day... :)
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

I wonder if the PSG library could help the portability.
In PSG.h you have:
set_psg(unsigned int reg, unsigned int val)
Already available for an interesting number of targets.
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

stefano wrote:I wonder if the PSG library could help the portability.
In PSG.h you have:
set_psg(unsigned int reg, unsigned int val)
Already available for an interesting number of targets.
Thanks!

I just tried and compiled psgtest.c (on an older version of z88dk) and it seems that that library is very similiar to the library here (but larger in size).

I think it's nice and we can use that instead but stuff like https://github.com/z88dk/z88dk/blob/mas ... callee.asm is still worrying me.

Note that there are still stuff that is dangerous because the psg can also be used for other purposes. The psg is, unlike the name suggests, also a chip with in- and output ports. Setting some bits there incorrectly might cause some in- and output doing unintended things, and that's why some MSX machines don't like ported Spectrum AY code. In fact, some MSX emulators even warn the user that the PSG usage of some games might break the computer.
Post Reply