z80 init and sound effect playback

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Post Reply
slobu
Very interested
Posts: 85
Joined: Tue Apr 03, 2012 6:02 pm

z80 init and sound effect playback

Post by slobu » Tue Apr 03, 2012 6:12 pm

Right now I have z80 init by using Kramlib for BasiEgaXorz. This seems to work but Kramlib also forces you to include code and files that may be in a legal grey area. Is there some inline assembly that I could insert that inits the z80 on real hardware?

Also, I'm searching for a z80 driver for sound effects. I've heard good things about Echo. I don't know what's out there and what would be easiest to integrate into BEX.

I've managed to get almost everything working in BasiEgaXorz from scrolling, TFM Music, save RAM and level data loading but not this last bit. I'd really appreciate any clues you guys have!

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue Apr 03, 2012 6:30 pm

You don't need any special code to init the Z80, it is just few register writes - busreq on, fill Z80 RAM with your code, reset Z80, busreq off. You probably can easily do it with pokes in BEX, or, if there are some alignment problems, with few inline move opcodes that will act like pokes.

Something like this should work:

Code: Select all

...

    reload z80_driver
    
    pokeint &hA11100,&h100 'busreq on
    
    for i=0 to 8192 '8192 is the size of the driver, here it is just max to not bother with getting the size
    read n 'read a byte
    poke &hA00000+i,n 'put the byte into the Z80 RAM
    next
	
    pokeint &hA11200,0 'reset Z80
    pokeint &hA11200,&h100
    pokeint &hA11100,0 'busreq off

...

z80_driver:
    datafile z80_driver.bin,bin

slobu
Very interested
Posts: 85
Joined: Tue Apr 03, 2012 6:02 pm

Post by slobu » Tue Apr 03, 2012 7:00 pm

Thanks for the post Shiru. Er, what is z80_driver.bin? Is it the same file as in the ademo.zip from this topic:
viewtopic.php?t=586&start=45&postdays=0 ... highlight=

Do I just rename z80_tadpcm.o80 from ademo.zip?

I'm assuming the " poke &hA00000+i,n 'put the byte into the Z80 RAM " is putting some sort of z80 driver into memory. The lines below it, are.. clearing the z80? Usually I see a few nops to give the z80 some time but not here.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Apr 04, 2012 6:30 am

z80_driver.bin is any compiled Z80 code that you going to use as driver.

This code only loads the driver, however, you also will need a bit of similar code to pass parameters to the driver, instead of loop you'll have to do few pokes that will put the parameters into certain locations of the Z80 RAM, they are depend from the driver.

nops aren't needed. You may need to wait while busreq is confirmed, but it probably will work as is, since FOR setup and first READ take some time.

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

Post by Chilly Willy » Wed Apr 04, 2012 7:26 am

slobu wrote:Thanks for the post Shiru. Er, what is z80_driver.bin? Is it the same file as in the ademo.zip from this topic:
viewtopic.php?t=586&start=45&postdays=0 ... highlight=

Do I just rename z80_tadpcm.o80 from ademo.zip?

I'm assuming the " poke &hA00000+i,n 'put the byte into the Z80 RAM " is putting some sort of z80 driver into memory. The lines below it, are.. clearing the z80? Usually I see a few nops to give the z80 some time but not here.
z80_tadpcm.o80 is the z80 code assembled from the source. It's a plain binary file.

If you need it in a data list format to embed in the program, here's the C data version. It shouldn't be too hard to convert.

Code: Select all

#include "genesis.h"

const u8 z80_tadpcm[749] = {
    0xf3,0x31,0x00,0x20,0xed,0x56,0xc3,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xed,0x4d,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x06,0x10,0xaf,0x21,0x40,0x00,0x77,0x23,0x10,0xfc,0xfd,0x21,0x00,0x40,0xfd,0x36,
    0x02,0xb6,0x21,0x00,0x40,0x01,0x01,0x40,0x3e,0x80,0x36,0x2b,0x02,0x36,0x2a,0x02,
    0x3a,0x4e,0x00,0xb7,0x28,0xfa,0x3a,0x4d,0x00,0x32,0x03,0x40,0x11,0x00,0x00,0x21,
    0x00,0x00,0xd9,0xed,0x4b,0x43,0x00,0x3a,0x45,0x00,0xed,0x43,0x46,0x00,0x32,0x48,
    0x00,0xed,0x5b,0x41,0x00,0xed,0x4b,0x40,0x00,0xcb,0xf8,0xfd,0x60,0xfd,0x69,0xcb,
    0xb8,0x21,0x00,0x80,0xa7,0xed,0x42,0x3a,0x48,0x00,0xa7,0xc2,0xec,0x00,0x3a,0x46,
    0x00,0x95,0x3a,0x47,0x00,0x9c,0xf2,0xec,0x00,0x2a,0x46,0x00,0xe5,0xdd,0xe1,0xcd,
    0xd6,0x02,0xd9,0x3a,0x4f,0x00,0xb7,0xc2,0xbc,0x02,0xfd,0x56,0x00,0xfd,0x23,0xfd,
    0x4e,0x00,0x06,0x04,0xcb,0x39,0xda,0x3e,0x01,0x00,0x00,0x00,0x00,0xcb,0x39,0xda,
    0x28,0x01,0xa7,0xed,0x5a,0xe2,0x1b,0x01,0x21,0xff,0x7f,0x7c,0xc6,0x80,0x32,0x01,
    0x40,0x00,0x00,0x00,0x00,0xc3,0x73,0x01,0xa7,0xed,0x52,0xe2,0x31,0x01,0x21,0x00,
    0x80,0x7c,0xc6,0x80,0x32,0x01,0x40,0x00,0x00,0x00,0x00,0xc3,0x73,0x01,0xcb,0x3a,
    0xcb,0x1b,0xcb,0x39,0xda,0x5d,0x01,0xa7,0xed,0x5a,0xe2,0x50,0x01,0x21,0xff,0x7f,
    0x7c,0xc6,0x80,0x32,0x01,0x40,0xcb,0x23,0xcb,0x12,0xc3,0x73,0x01,0xa7,0xed,0x52,
    0xe2,0x66,0x01,0x21,0x00,0x80,0x7c,0xc6,0x80,0x32,0x01,0x40,0xcb,0x23,0xcb,0x12,
    0xc3,0x73,0x01,0x00,0x10,0x8e,0xfd,0x23,0xfd,0x4e,0x00,0x06,0x04,0xcb,0x39,0xda,
    0xb7,0x01,0x00,0x00,0x00,0x00,0xcb,0x39,0xda,0xa1,0x01,0xa7,0xed,0x5a,0xe2,0x94,
    0x01,0x21,0xff,0x7f,0x7c,0xc6,0x80,0x32,0x01,0x40,0x00,0x00,0x00,0x00,0xc3,0xec,
    0x01,0xa7,0xed,0x52,0xe2,0xaa,0x01,0x21,0x00,0x80,0x7c,0xc6,0x80,0x32,0x01,0x40,
    0x00,0x00,0x00,0x00,0xc3,0xec,0x01,0xcb,0x3a,0xcb,0x1b,0xcb,0x39,0xda,0xd6,0x01,
    0xa7,0xed,0x5a,0xe2,0xc9,0x01,0x21,0xff,0x7f,0x7c,0xc6,0x80,0x32,0x01,0x40,0xcb,
    0x23,0xcb,0x12,0xc3,0xec,0x01,0xa7,0xed,0x52,0xe2,0xdf,0x01,0x21,0x00,0x80,0x7c,
    0xc6,0x80,0x32,0x01,0x40,0xcb,0x23,0xcb,0x12,0xc3,0xec,0x01,0x00,0x10,0x8e,0xfd,
    0x23,0xfd,0x4e,0x00,0x06,0x04,0xcb,0x39,0xda,0x30,0x02,0x00,0x00,0x00,0x00,0xcb,
    0x39,0xda,0x1a,0x02,0xa7,0xed,0x5a,0xe2,0x0d,0x02,0x21,0xff,0x7f,0x7c,0xc6,0x80,
    0x32,0x01,0x40,0x00,0x00,0x00,0x00,0xc3,0x65,0x02,0xa7,0xed,0x52,0xe2,0x23,0x02,
    0x21,0x00,0x80,0x7c,0xc6,0x80,0x32,0x01,0x40,0x00,0x00,0x00,0x00,0xc3,0x65,0x02,
    0xcb,0x3a,0xcb,0x1b,0xcb,0x39,0xda,0x4f,0x02,0xa7,0xed,0x5a,0xe2,0x42,0x02,0x21,
    0xff,0x7f,0x7c,0xc6,0x80,0x32,0x01,0x40,0xcb,0x23,0xcb,0x12,0xc3,0x65,0x02,0xa7,
    0xed,0x52,0xe2,0x58,0x02,0x21,0x00,0x80,0x7c,0xc6,0x80,0x32,0x01,0x40,0xcb,0x23,
    0xcb,0x12,0xc3,0x65,0x02,0x00,0x10,0x8e,0xfd,0x23,0x01,0xfc,0xff,0xdd,0x09,0xdd,
    0x7d,0xdd,0xb4,0xc2,0xf3,0x00,0xd9,0x3a,0x46,0x00,0x95,0x6f,0x3a,0x47,0x00,0x9c,
    0x67,0x3a,0x48,0x00,0x06,0x00,0x98,0x47,0xb4,0xb5,0xca,0xa6,0x02,0x22,0x46,0x00,
    0x78,0x32,0x48,0x00,0x21,0x00,0x80,0xfd,0x21,0x00,0x80,0x7b,0xc6,0x80,0x5f,0xd2,
    0xd7,0x00,0x14,0xc3,0xd7,0x00,0x3a,0x4e,0x00,0xb7,0xfa,0xac,0x00,0x3d,0x32,0x4e,
    0x00,0xc2,0xac,0x00,0x3e,0x80,0x32,0x01,0x40,0xc3,0xa0,0x00,0x3e,0x80,0x32,0x01,
    0x40,0x3a,0x4f,0x00,0xb7,0xca,0xf3,0x00,0x3a,0x4e,0x00,0xb7,0xc2,0xc1,0x02,0xaf,
    0x32,0x4f,0x00,0xc3,0xa0,0x00,0x01,0x00,0x60,0x7b,0x07,0x02,0x7a,0x02,0x0f,0x02,
    0x0f,0x02,0x0f,0x02,0x0f,0x02,0x0f,0x02,0x0f,0x02,0x0f,0x02,0xc9,
};

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Apr 04, 2012 7:37 am

There is no include for source code in BEX, all the code should be in one huge file. So including binaries through datafile is more convinient.

slobu
Very interested
Posts: 85
Joined: Tue Apr 03, 2012 6:02 pm

Post by slobu » Wed Apr 04, 2012 2:13 pm

Interesting. So, I should be able to load Chilly Willys tadpcm driver into memory and the load time takes the place of nops. I could then look at Chilly Willys z80_tadpcm.s80 to figure out the labels used to call the sound functions.

Thanks for the help and patience guys :)

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

Post by Chilly Willy » Wed Apr 04, 2012 5:40 pm

Shiru wrote:There is no include for source code in BEX, all the code should be in one huge file. So including binaries through datafile is more convinient.
You can convert it to DATA statements. That's what I was talking about, not including the C as it is.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Apr 04, 2012 5:53 pm

Without the includes it is difficult to work with code as is, and having hex dumps instead of a single line in the middle is not convinient, that's what I'm talking about.

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

Post by Chilly Willy » Wed Apr 04, 2012 7:38 pm

Shiru wrote:Without the includes it is difficult to work with code as is, and having hex dumps instead of a single line in the middle is not convinient, that's what I'm talking about.
But it does make it all one single file... no extra files to "get lost" like the one he was looking for. So it all depends on how you like to do your BASIC programs. Everything in one HUGE file is probably the most popular format for BASIC I've seen - mainly because most old BASIC programs (8-bit) only accepted a single file. :lol:

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Apr 04, 2012 8:51 pm

Sure, one nice single file with thousands lines of hex dump for the graphics, or without graphics at all. Whatever.

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

Post by Chilly Willy » Wed Apr 04, 2012 9:40 pm

Shiru wrote:Sure, one nice single file with thousands lines of hex dump for the graphics, or without graphics at all. Whatever.
I'm not saying that, but the z80 driver is pretty small. You could easily have one file for all the game logic including the z80 driver, and then separate files for the game data.

Post Reply