News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Arnaud

[CPCtelera] Help needed for converted Arkos Player 2

Started by Arnaud, 14:10, 15 April 18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Arnaud

Hello,
i'm a trying to use Arkos Player 2 with CPCtelera / SDCC, i have managed to convert the assembly code (according to the work already done for Arkos Player 1) and make an example project.

I heard some noise but not the original music, i had to make some mistakes while converting but i have not idea what is wrong.

The music "AHarmlessGrenade" was exported in binary at 0x4000 and converted into array __at(0x4000).


#include <cpctelera.h>
#include "Music_AHarmlessGrenade.h"

extern void PLY_AKG_Init(void* songdata, u8 subSong) __z88dk_callee;
extern void PLY_AKG_Play();

void main(void) {
    cpct_disableFirmware();
    PLY_AKG_Init(G_Music_AHarmlessGrenade, 0);

    while (1)
    {
        cpct_waitVSYNC();
        PLY_AKG_Play();
    }
}


In the zip i have also included by convenient the original source code (PlayerAkg.asm_org and PlayerAkg_SoundEffects.asm_org)

Thanks,
Arnaud

freemac

Relative jump
jr nc,. + 3
does refer jump you disabled (in comments) :
;jp _PLY_AKG_Play          ;PLY_AKG_Start + 3.
so it doesn't jump jump ?

freemac

On https://github.com/renaudhelias/RubikCubePaletteCPC/blob/master/JDVPA%233_test/combat2.c

I compiled SKS with WinAPE and load it directly :
LoadFile("sks2000.bin", (char *)0x2000);
LoadFile("sudo3000.bin", (char *)0x3000);

and I implemented cpct_akp_musicInit() and cpct_akp_musicPlay() using a set of instruction for protecting "backup/restore Z80 state" inspired from http://norecess.cpcscene.net/using-interrupts.html

Arnaud

Quote from: freemac on 14:36, 15 April 18
Relative jump
jr nc,. + 3
does refer jump you disabled (in comments) :
;jp _PLY_AKG_Play          ;PLY_AKG_Start + 3.
so it doesn't jump jump ?

I comment this line because this commentary (i set back this line but it doesn't work either):
        ;Hooks for external calls. Can be removed if not needed.

and i call directly in C the functions  : PLY_AKG_Init and PLY_AKG_Play

Quote from: freemac on 14:44, 15 April 18
On https://github.com/renaudhelias/RubikCubePaletteCPC/blob/master/JDVPA%233_test/combat2.c

I compiled SKS with WinAPE and load it directly :
LoadFile("sks2000.bin", (char *)0x2000);
LoadFile("sudo3000.bin", (char *)0x3000);

and I implemented cpct_akp_musicInit() and cpct_akp_musicPlay() using a set of instruction for protecting "backup/restore Z80 state" inspired from http://norecess.cpcscene.net/using-interrupts.html

If i can't make my code working i'll try this solution. Thanks.




ronaldo

Quote from: Arnaud on 14:10, 15 April 18
I heard some noise but not the original music, i had to make some mistakes while converting but i have not idea what is wrong.

Your problem is in the way you retrieve parameters. This is your code:


;Initializes the player.
;IN:    HL = music address.
;       A = subsong index (>=0).
_PLY_AKG_Init::
        ;; Get Parameters from the Stack
        pop  bc          ;; BC = Return address
        pop  hl          ;; HL = Music address
        pop  af          ;; A  = Subsong index (>=0)
        push bc          ;; [4] BC = Returning back address in the stack because function uses __z88dk_callee convention


The problem here is that PUSH AF gets the first 8-bit value from the stack in F and the second in A, because Z80 is little endian. Therefore, the value you want (subsong index) ends up in F and not in A. You may easily fix it doing this:


   pop  af          ;; AF = Return address
   pop  hl          ;; HL = Music address
   pop  bc          ;; C  = Subsong index (>=0)  (B = Rubbish)
   push af          ;; Save back return address in the stack to fullfill __z88dk_callee convention
   ld   a, c          ;; A = Subsong index


I've tested it and song plays. Don't know if more tweaks are requiered or not, but it plays.

Arnaud

Quote from: ronaldo on 21:37, 15 April 18
Your problem is in the way you retrieve parameters.
I add only three lines of my own and it's the problem  ::)

Quote from: ronaldo on 21:37, 15 April 18
I've tested it and song plays. Don't know if more tweaks are requiered or not, but it plays.
Yes the music play, but only the first pattern.

Thanks for help @ronaldo.


Targhan

I know nothing about CPCTelera, but just to be sure, does your music play fine when using the "normal" player and test code provided with AT2?
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Arnaud

Quote from: Targhan on 13:50, 16 April 18
I know nothing about CPCTelera, but just to be sure, does your music play fine when using the "normal" player and test code provided with AT2?

Just compiled and tested with RASM all is OK.

There's something wrong in my code.

Targhan

QuoteThere's something wrong in my code.


That's what I wanted to hear :). When calling the init, make sure A is 0 (the first subsong). HL should point on your song, there's no trick there.
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Arnaud

Quote from: Targhan on 22:09, 16 April 18

That's what I wanted to hear :) . When calling the init, make sure A is 0 (the first subsong). HL should point on your song, there's no trick there.

The problem is not in my own code (@ronaldo correct it) but in my convertion to ASZ80 assembly.

@reidrac have already convert to ASZ80 the  lightweight player, maybe he can have idea of the problem ?  :D

Targhan

On simple solution is to compile the player (with Rasm for example) at a fixed location, and load the binary in your code. This won't be as flexible as integrating it in your sources, but it can save you some huge debugging time.
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Arnaud

Hello,
finally i found the problem ;D

In the main :

void main(void) {
    cpct_disableFirmware();
    PLY_AKG_Init(G_Music_AHarmlessGrenade, 0);

    while (1)    {
        cpct_waitVSYNC();
        __asm   
        ei
        nop
        halt
        halt
        di
        __endasm;
        PLY_AKG_Play();
    }
}


The asm code was needed (taken from the example PlayerAkgTester_CPC.asm).
And i need to understand, if this code is needed to play music, why it is not directly included in the function PLY_AKG_Play ?


I also tried to compile with RASM (v0.84) the second example PlayerAkgWithSoundEffectTester_CPC.asm and there are numerous compilation errors (missing expressions, relative offset and truncating errors)
Are specific options to use to compile ?

Arnaud

Targhan

This snippet is not part of the player, because it does more than just calling the player: it waits for the vsync, plays the song, in an infinite loop. So it is up to your game/demo to do that. A game will maybe put the music under interruption. Or call any other code of your production (move the sprites, etc.).


QuoteI also tried to compile with RASM (v0.84) the second example PlayerAkgWithSoundEffectTester_CPC.asm and there are numerous compilation errors (missing expressions, relative offset and truncating errors)


You must not compile it as a stand alone program! There is a flag in the PlayerAkg to enable the sound effect (something like PLY_AKG_SoundEffects, I don't have the code here). It is "PlayerAkg.asm" than will include "PlayerAkgWithSoundEffectTester_CPC.asm".
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Arnaud

Hello,
i always have some problems to convert Arkos Player2 to SDCC-ASZ80 (Cpctelera).

Now the music play well, but the FX are "corrupted". I have converted the AKG and AKL code, but i have the same problem with the two players, the SFX doesn't work well.

Here my example, it plays molusk song (exported as AKL in bin) and when pressing a key the fx is played (\3Channels\SoundEffects.aks exported as AKX in bin).

I really don't see what is the problem :'( (ASZ80 specificity ?) because all is ok under RASM.

Thanks for Help,
Arnaud.

Targhan

Do you confirm that *everything* works with Rasm (music and SFX)? The examples within AT2 are working flawlessly with both Rasm and SJAsmPlus.


If it is sdcc/cpctelera related, then there is nothing I can do. One advice: make a binary comparison of the code compiled with Rasm, and with SDCC to see if the code compiled differently. If yes, there is a mistake in your conversion!
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Targhan

Hmmm, just checked the code (PlayerLightweight_SoundEffects.asm) in your zip file... Is it normal that ALL the values are prefixed with #, even non hexadecimal ones? #16, #255... These won't work if they are interpreted as hex, they are decimal values. But forget my ignorance about SDCC if this is normal (and rather confusing... ditch this compiler!!).
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Arnaud

Quote from: Targhan on 19:55, 01 May 18
Hmmm, just checked the code (PlayerLightweight_SoundEffects.asm) in your zip file... Is it normal that ALL the values are prefixed with #, even non hexadecimal ones? #16, #255... These won't work if they are interpreted as hex, they are decimal values. But forget my ignorance about SDCC if this is normal (and rather confusing... ditch this compiler!!).

Yes it's a bit confusing, the convention is #nn for decimal, #0xnn hexa and #0bnn for binary.

Targhan

Well, I'm afraid I can not help you more with that, since I don't know about Cpctelera. If you do just like my testers show, this should work. I suppose you can debug with Winape right ? One possibility would be to have winapes: one running a sound effect with code assembled with Rasm, another Winape running the same sound effect with code assembled with sdacc. Make a step-by-step debugging. At some point, a difference will be shown, then you must understand why. The code of the sound effect is small so this shouldn't take long.
Targhan/Arkos

Arkos Tracker 2.0.1 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

Powered by SMFPacks Menu Editor Mod