Arkos Tracker 2 in z88dk

User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

I've checked out your project and with the plain checkout, the cartridge just continually resets. I've fixed up some issues I spotted, but it's still not quite there.

I can see that playerZ88dk.asm uses the code_user section but has a bunch of defw variables at the end of the file which are written to. Since it's a code section it will be located in ROM and they won't be modifiable. I temporarily changed it to data_user to get it into RAM.

The parameters for ply_akg_init are being handled incorrectly:

Code: Select all

-extern void ply_akg_init( void *song, unsigned int subsong ) __z88dk_callee;
+extern void ply_akg_init( void *song, unsigned int subsong ) __z88dk_callee __smallc;

 ;;
 ;; void ply_akg_init( void *song, uint8_t subsong ) __z88dk_callee __smallc;
-;;   (params pushed on the stack right to left, all 16-bit)
+;;   (params pushed on the stack left to right, all 16-bit)
 ;;
 _ply_akg_init:
   pop bc    ; BC = retaddr
+  pop de    ; E = subsong number
   pop hl    ; HL = song address
-  pop af    ; A = subsong number
   push bc   ; restore retaddr
+  ld   a,e
   jp PLY_AKG_INIT
It's now at a point where it doesn't reset, but changing to busy looping and some simple debugging:

Code: Select all

-  setup_int();
+//  setup_int();

   printf("After\n");

   while ( 1 ) {
-    /*(*(uint8_t *)0x4000)++;
-
+    printf(".");
     intrinsic_di();
     ply_akg_play();
     intrinsic_ei();
-    intrinsic_halt();*/
+    printf("/");
+    intrinsic_halt();
   }
Yields this:
Screenshot 2023-03-02 at 20.48.36.png
Which means the player is getting stuck again.
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

Or rather, the player is jumping into space:

Code: Select all

Clocks = 8150723636 (5) Since Scanline = 156/227 (224/262)
next    0000C9DE  JP d99c
- t
done    0000C9DE  JP d99c
F = [-------S]  A = 03  BC = 2FBC  DE = C4E8  HL = 00BA  IX = D93A  IY = D93A
F'= [--P--YZ-]  A'= 00  BC'= 00C0  DE'= 6003  HL'= C3C5  SP = CCCA  PC = D99C
        I = 00  R = 91 (BC)= CD30 (DE)= 4022 (HL)= FBC3 (SP)= 0088  DI:IFF2=0
Clocks = 8150723647 (11) Since Scanline = 167/227 (224/262)
next    0000D99C  JP 06e8
- t
done    0000D99C  JP 06e8
And d99c is:

Code: Select all

grep -i d99c prueba.map
PLY_AKG_CHANNEL_READEFFECTS_ENDJUMPINSTRANDADDRESS = $D99C ; addr, local, , playerZ88dk_asm, data_user, ./player/playerZ88dk.asm:4909
I somehow suspect that a jump into ROM isn't intended. To debug further, I think some memory breakpoints on $d99d and $d99e (or the equivalent addresses in your compilation) might help.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

Some horrible noise comes out if I match the space allocation from the original player with the converted player:

Code: Select all

 PLY_AKG_CHANNEL_READEFFECTS_ENDJUMPINSTRANDADDRESS:
+       defb    $c3
        defw  49188
Possibly progress...
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Arkos Tracker 2 in z88dk

Post by Timmy »

I haven't been able to get it not crashing after the printf("."), with the patches in the first post of this page, but I'd recommend not setting PLY_AKG_ROM_Buffer to #C000, because that's where z88dk also stores its regular C variables.

I also haven't checked if the interrupts is the same as the one we've discussed earlier: viewtopic.php?t=11196
eldeljar
Member
Posts: 33
Joined: Sun Feb 12, 2017 6:04 pm

Re: Arkos Tracker 2 in z88dk

Post by eldeljar »

Thanks for the answers.
I have made the changes indicated by dom and it does not give an error, although I do not hear anything.
I have changed to the AKM player and I have removed from the code:

Code: Select all

    PLY_AKM_ROM = 1
    PLY_AKM_ROM_Buffer = #c000
, so that instead of having the code in the ROM you have it in the RAM.
I have pushed the AKM changes to Github.
Now something is heard, but it is not the real music.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Arkos Tracker 2 in z88dk

Post by Timmy »

That's some progress, but I'm afraid that this only means that there are still errors in the player itself for MSX use.

I don't think there's an easy solution out there for now.

As an alternative, the wyz player is already available for the MSX. Perhaps you can use that for the moment.

PS. note to @dom I managed to get the wyz player working on the CPC too. But perhaps that's for another thread. (if there is any interest in that).
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

I'll be honest, this Arkos thing has, to be polite, annoyed me for years. So I'm starting from first principles and I'll see what I can do.

I did think WYZ was already working on the CPC, certainly there's an driver for it: https://github.com/z88dk/z88dk/blob/mas ... re_out.asm
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

Okay, I have a recipe that seems to work? - I'll raise a PR against the repo since going through the steps is pretty painful but I need to document it so I don't forget.

Starting from scratch, create player.asm in the Arkos Tracker playerAkm directory with the contents:

Code: Select all

PLY_AKM_Rom = 1
PLY_AKM_ROM_Buffer = #2000
PLY_AKM_HARDWARE_MSX = 1
INCLUDE "PlayerAkm.asm"
Transform using the documented way:

Code: Select all

% rasm Player.asm -o Player.bin -s -sl -sq
% disark Player.bin vasm.asm --symbolFile Player.sym --sourceProfile vasm
Now we have to do some editing on vasm.asm:

1. Regex replace: ^PLY with .PLY
2. Stick this at the top:

Code: Select all

        SECTION code_user
        PUBLIC  PLY_AKM_INIT
        PUBLIC  PLY_AKM_START
        PUBLIC  PLY_AKM_PLAY
        PUBLIC  PLY_AKM_STOP
3. Chop off the bottom of vasm.asm (from .PLY_AKM_DEFAULTSTARTINSTRUMENTINTRACKS equ 8207) into a new file called vars.asm
4. sort -k3 vars.asm > vars2.asm (this stage is optional)
5. Edit vars2.asm and add:

Code: Select all

SECTION bss_user

; Apparently we need 199 bytes
akm_vars:       defs    199
6. In vars.asm, searching and replace "equ" with "equ akm_vars - 8192 +"
7. Append vars2.asm to vasm.asm
8. Copy vasm.asm to player/playerZ88dk.asm in the repo

Now, it's time to work on the song, starting with songm.asm

1. Copy into player/song.asm
2. Regex replace ^Just with .Just
3. Search and replace # with 0x
4. Add this as a header to the file

Code: Select all

        SECTION rodata_user

        PUBLIC _SONG
_SONG:
Then the project setup:

1. Adjust zproject.lst to include player/song.asm
2. Remove the "/." printing since it slows things down
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

I've just spotted the python script that does most of the above, so I'm guessing the only difference is the handling of the variables.

The PR I raised puts the song and player in ROM with music playing on the interrupt which is what you originally wanted.

I'd like to raise a PR against Disark to do this conversion itself, but I see that it's not open source.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

Dom, you walked the exact same path I did some months ago for getting It working on the ZX. My scriot is in Perl, but everything is in the repo mentioned some posts ago: https://github.com/jorgegv/z88dk-arkos-relocatable

I did It passing through Pasmo syntax, but my procedire was almost the same as yours.

I contacted Julien some months ago and indeed Arkos is being open sourced at the moment, in fact I already sent himn a PR.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

Doh, that would have saved me a bit of time - though I was working on the conversion for the ROM player.

It seems Paulo has added quite a lot of support for alternate pseudo opcodes, so equ, db, dw conversion is no longer needed which just leaves the label termination as the required change (beyond exporting etc) for the RAM player.

It turns out, that the difference between Pasmo and vasm output is that the Pasmo output has defb out ld (ix+NN),rr etc which doesn't make much sense.

Looking forward to seeing the result of your PR, hopefully it will make it easier to include a player directly in the repo and simplify usage - if it added in sections that would be wonderful.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

I was already working on a Z88dk PR for including Arkos, but some personal issues got in the way... I'll try to catch-up again.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

I just pushed some more tests and demo code for the ZX in my Arkos test repo (see above), including interrupt driven playback, and relevantly, an interrupt driven demo with the player configured in ROM mode. All tests run and play successfully on the ZX target.

Any quick pointer to an MSX emulator that runs on Linux? Having a ROM-configured player that runs successfully, I think it will be much easier to get the MSX target working.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

For an MSX emulator I use the Takeda emulator (http://takeda-toshiya.my.coocan.jp) running in wine - it may not have all the features of some of the other emulators, but it's easy to drive and doesn't get in the way.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

OK, will try. For the moment I just managed to get OpenMSX running and I got some SVI 728 ROMS, all seems fine. Now I need some short time to familiarize with MSX commands and loading, etc.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

I got Arkos 2 working in "periodic" mode for a ROM target, see https://github.com/jorgegv/z88dk-arkos- ... riodic-rom .

In that repo, "periodic" is what I call the mode without interrupts, i.e. just a main loop which HALT's the CPU (to wait for the retrace interrupt) and immediately after that, calls the Arkos play routine (see code for details).

As I had the ZX periodic demo code working, the only changes that I needed to do to the player was configuring the build for ROM mode, MSX target, setting an address for the RAM buffer (I chose 0xC000) and selecting the target in Z88DK (zxx +msx -subtype=rom).

After that I run the generated cartridge with "openmsx arkos.rom", and the music played faithfully and exactly the same as it plays on the ZX code.

Next is learning how to setup interrupt routines in MSX (I believe it's done differently than ZX, right? and get Arkos working on MSX ROM in interrupt mode...
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Arkos Tracker 2 in z88dk

Post by Timmy »

I've posted a link earlier in this thread how to set up interrupts on the MSX.

I'll link it again: viewtopic.php?t=11196
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

I feel like a cracked record. The existing tracker examples show how to setup interrupts on machines: https://github.com/z88dk/z88dk/blob/mas ... /sound/wyz
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

Yes, I read it just after posting :-)

Funnily enough, I tried my "periodic" mode with MSX ROM target, and I just switched compilers (sdcc for sccz80) but no other code changes.

The resulting code does not work correctly and outputs strange noises. You can check it in my repo on the msx/periodic-rom-sccz80 directory. What can be the reason that one compiler runs fine and the same with other compiler does not? SDCC=OK, SCCZ80=NOK...
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

dom wrote: Mon Mar 06, 2023 5:18 pm I feel like a cracked record. The existing tracker examples show how to setup interrupts on machines: https://github.com/z88dk/z88dk/blob/mas ... /sound/wyz
Most probably it's my fault... I have a (nad?) habit of just posting my intended next steps, and it may sound like asking for help, but I'm not! :D

Any way, cracked or not, thanks to you both, Dom and Timmy :)

My current point of interest is knowing why the same code works with SDCC and not with SCCZ80.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

jorgegv wrote: Mon Mar 06, 2023 5:22 pmMy current point of interest is knowing why the same code works with SDCC and not with SCCZ80.
See my fix regarding ply_akg_init in this comment: https://z88dk.org/forum/viewtopic.php?p=21387#p21387
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

The ROM interrupt version seems to be okay as well with a couple of tweaks:

1. Add an im1_init() call into setup_interrupts()
2. Add -pragma-define:CRT_ORG_BSS=0xc100 to the link line to move all the C variables to above the Arkos buffer (actually both ROM versions would need this)
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

Thanks Dom, that indeed did the trick. And of course, the explanation of SDCC vs. SCCZ80 was the parameter passing, fool me twice :-)

Regarding 2: I have implemented a better solution.

The internal Arkos variable area (the "ROM buffer") is defined at the end of the generated ASM file and the config value PLY_AKG_ROM_Buffer defined in PlayerAkg.asm is used as a base to hardcode the addresses for each of its internal variables.

I have configured the PLY_AKG_ROM_Buffer to 0xC000, and I have modified my script so that when it detects this zone of variable definitions in the ASM file, it replaces them with relative offsets to an external symbol _arkos_var_buffer. Finally, I have just defined an "uint8_t arkos_var_buffer[ 269 ];" in main.c.

With this setup, the Arkos vars buffer is located in BSS, and we can let Z88DK automatically take care of its placement in memory, with its address being resolved at link time.

BTW, the docs say that a 255-byte buffer is enough, but it is not. The maximum offset from the start of the vars area is 268, so size must be 269.

Changes in the repo. :)
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arkos Tracker 2 in z88dk

Post by dom »

That's fantastic, makes it much easier to see how it can be added to the library now.

That's funny about the buffer size, I'm sure I read 199 bytes somewhere
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Arkos Tracker 2 in z88dk

Post by jorgegv »

Yes, the player source says:

Code: Select all

The buffer is PLY_AKG_ROM_BufferSize long (=250 max). (...)
So we were both wrong, but anyway, the important part is that it must be bigger, and that we can know the size.

I'm already working on the PR for merging Arkos2 support into Z88DK :) Stay tuned.
Post Reply