1-bit sound effects in contended memory

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

1-bit sound effects in contended memory

Post by jorgegv »

Good morning,

I'm playing a bit with the 1-bit sound effects (bit_beepfx), compiling with SDCC, my ORG is at $6224.

Previously I had an old copy of Shiru's player included in my sources, and sound effects played nice. Examining the game map, the player was being located at $a2f8, and sound data was also located above $8000. Both of them above contended memory.

When I use the bit_beepfx() function from the sound.h library, the sound data is still located above $8000, but the asm_bit_beepfx routine gets located at around $6xxx, and then the sound sounds quite worse than before. I presume this is due to the sound code being stored in contended memory ($4000-$7fff).

Is there any option or pragma I can use to direct the compiler to store some code in upper addresses? Even specifying the ordering of code sections would be probably fine, since I see these functions have their own section...

Any ideas?
Thanks in advance
Jorge
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: 1-bit sound effects in contended memory

Post by Timmy »

As I've written many times in the threads, I normally treat the music part of the code as a binary blob.

I would compile it separately (at 60000, for example), load it separately (as a separate block of a TAP file), call it separately (using an assembly CALL), and put it somewhere in uncontended memory. Also, make sure your own program doesn't use that part of the memory.

As an alternative, put your music code at the end of your C code. I noticed that the compiler (sccz80) usually compile things sequentially, so there's more chance that code at the end of the file is placed after 32767.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: 1-bit sound effects in contended memory

Post by jorgegv »

Thanks, good point, I think I'll try the separate blob way.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1-bit sound effects in contended memory

Post by stefano »

Z88dk supports sections, but ATM we haven't a specific section assignment in the sound library, nor automatic relocation tricks for it.
It is feasible in theory, but probably a bit pointless.. should it be for a 48k / 128k model or..?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: 1-bit sound effects in contended memory

Post by dom »

Looking at the name of the function I can see that this was from newlib.

Interestingly, newlib places library code earlier in the binary, the order is:

library code
user code

Where as classic does it this way round:

user code
library code

So I suspect that this issue won't come up in classic since the user code will push library code into non-contended memory.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1-bit sound effects in contended memory

Post by stefano »

I didn't know that!
I can sort out the games content, if you think it is worth to have yet another section ?
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: 1-bit sound effects in contended memory

Post by jorgegv »

stefano wrote: Mon Feb 15, 2021 5:42 pm Z88dk supports sections, but ATM we haven't a specific section assignment in the sound library, nor automatic relocation tricks for it.
It is feasible in theory, but probably a bit pointless.. should it be for a 48k / 128k model or..?
Well, it's for a 48k model. I guess with 128K model the issue is much less important, since music is not played directly by the CPU, but by the sound chip. But playing music on the 48k is highly time-sensitive, and so memory contention is a big problem.

Regarding havig a specific section for music code, this is what I see in the libsrc/_DEVELOPMENT/sound/bit/c/sdcc_iy/bit_beepfx.asm source file:

Code: Select all

...
SECTION code_sound_bit
...
Also I remember seeing this in the generated map file. This is a dedicated section, right? I presume all these sections will be collated into the code_compiler section somehow in the final link phase...

BR
J.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1-bit sound effects in contended memory

Post by stefano »

Uh.. this it yet something I haven't noticed.
It's probably easier then. :)
Post Reply