Author Topic: [CPCtelera] Help needed for converted Arkos Player 2  (Read 666 times)

0 Members and 1 Guest are viewing this topic.

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
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).

Code: [Select]
#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
« Last Edit: 16:29, 15 April 18 by Arnaud »

Offline freemac

  • CPC6128
  • ****
  • Posts: 296
  • Country: 00
  • Liked: 231
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #1 on: 16:36, 15 April 18 »
Relative jump
Code: [Select]
jr nc,. + 3does refer jump you disabled (in comments) :
Code: [Select]
;jp _PLY_AKG_Play          ;PLY_AKG_Start + 3.so it doesn't jump jump ?
« Last Edit: 16:47, 15 April 18 by freemac »

Offline freemac

  • CPC6128
  • ****
  • Posts: 296
  • Country: 00
  • Liked: 231
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #2 on: 16: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

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #3 on: 17:01, 15 April 18 »
Relative jump
Code: [Select]
jr nc,. + 3does refer jump you disabled (in comments) :
Code: [Select]
;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):
Code: [Select]
        ;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

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.




Offline ronaldo

  • Dev
  • 6128 Plus
  • *****
  • Posts: 587
  • Country: es
    • Fremos Blog
  • Liked: 781
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #4 on: 23:37, 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:

Code: [Select]
;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:

Code: [Select]
   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.

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #5 on: 13:15, 16 April 18 »
Your problem is in the way you retrieve parameters.
I add only three lines of my own and it's the problem  ::)

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.


Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #6 on: 15: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?

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #7 on: 20:33, 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.

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #8 on: 00:09, 17 April 18 »
Quote
There'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.

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #9 on: 13:34, 17 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

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #10 on: 13:40, 17 April 18 »
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.

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #11 on: 22:57, 18 April 18 »
Hello,
finally i found the problem ;D

In the main :
Code: [Select]
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
« Last Edit: 23:02, 18 April 18 by Arnaud »

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #12 on: 10:24, 19 April 18 »
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.).


Quote
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)


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".

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #13 on: 09:43, 29 April 18 »
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.
« Last Edit: 14:25, 29 April 18 by Arnaud »

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #14 on: 21:50, 01 May 18 »
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!

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #15 on: 21: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!!).

Offline Arnaud

  • Supporter
  • 464 Plus
  • *
  • Posts: 448
  • Country: fr
  • Liked: 354
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #16 on: 22:31, 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.

Offline Targhan

  • Supporter
  • 6128 Plus
  • *
  • Posts: 782
  • Country: fr
  • Liked: 708
Re: [CPCtelera] Help needed for converted Arkos Player 2
« Reply #17 on: 00:23, 02 May 18 »
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.