{"id":2315,"date":"2025-03-11T00:05:48","date_gmt":"2025-03-10T22:05:48","guid":{"rendered":"https:\/\/www.julien-nevo.com\/arkostracker\/?page_id=2315"},"modified":"2025-08-22T11:56:39","modified_gmt":"2025-08-22T09:56:39","slug":"a-simple-z80-example","status":"publish","type":"page","link":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/a-simple-z80-example\/","title":{"rendered":"A simple Z80 example"},"content":{"rendered":"\n<p>If you&#8217;re working in Z80, this page is for you. There are already ready-to-use testers in the AT3 package (&#8220;<em>players\/playerAkg\/sources\/tester<\/em>&#8220;, to name only one), but here is a very simple example of how the players work.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Garvalf has also created working examples (for CPC, Spectrum and Garvuino), which you can find on his <a href=\"https:\/\/github.com\/farvardin\/8bit_music\/tree\/master\/arkos_exports\" data-type=\"link\" data-id=\"https:\/\/github.com\/farvardin\/8bit_music\/tree\/master\/arkos_exports\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub repository<\/a> (for AT2, but it works the same). Thanks to him!<\/p>\n<\/blockquote>\n\n\n\n<p>We will use AKG player here, which is the &#8220;generic&#8221; player, but the&nbsp;<a href=\"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/players-overview\/\" data-type=\"page\" data-id=\"1399\" target=\"_blank\" rel=\"noreferrer noopener\">other players<\/a>&nbsp;work the same way.<\/p>\n\n\n\n<p>This page is made to be straightforward, so let&#8217;s be concise.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Export of the song via command line<\/h3>\n\n\n\n<p>Let&#8217;s use the command line tools to export your song. You can do it from the graphic interface&nbsp;inside the software, but we want to go fast!<\/p>\n\n\n\n<p>There are many example songs, but let&#8217;s focus on &#8220;<em>Targhan &#8211; A Harmless Grenade.aks<\/em>&#8221; located in the&nbsp;<em>songs\\ArkosTracker2\\3Channels<\/em>&nbsp;folder.<\/p>\n\n\n\n<p>The command line tools are located in the&nbsp;<em>tools<\/em>&nbsp;folder. The following command will create the source code of the exported music, which we call&nbsp;<em>music.asm<\/em>. The input file is of course the music we talked about just above:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SongToAkg.exe \"Targhan - A Harmless Grenade.aks\" music.asm<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Assemble the whole<\/h3>\n\n\n\n<p>The AKG player is located in the\u00a0<em>players\\playerAkg\\sources<\/em>\u00a0folder, and named\u00a0<em>PlayerAkg.asm<\/em>. Let&#8217;s create a wrapper around it to play the song every 50hz. We use Rasm to assemble. If you want to use any other assembler, please\u00a0<a href=\"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/using-a-song-in-production-using-any-assembler\/\" data-type=\"page\" data-id=\"2324\" target=\"_blank\" rel=\"noreferrer noopener\">check this tutorial<\/a>.<\/p>\n\n\n\n<p>This sample targets the Amstrad CPC, but choosing a MSX, Spectrum or anything else works exactly the same. The only specific code is the wait for the frame flyback. Please adapt it according to your target computer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    org #1000\n\n    ;Moves the system out of the way.\n    di\n    \n    ld hl,#c9fb\n    ld (#38),hl\n\n    ;Put the stack out of the way (it can destroy the beginning of our code, we don't care).    \n    ld sp,$\n\n    ;Let's initialize the song.\n    ld hl,MusicStart    ;Declared below.\n    \n    xor a                 ;Subsong 0 (the main one).\n    call PLY_AKG_Init\n\n    ;Wait for the frame flyback.\n    ;On CPC, we do it this way:\nSync:\n    ld b,#f5\nSync2: in a,(c)\n    rra\n    jr nc,Sync2\n\n    ei\n    nop\n    halt\n    halt\n    di\n\n    ;Let's play our song!\n    call PLY_AKG_Play\n    jr Sync\n\n    ;Of course, we need to include the player and the music to play.\n    ;Uncomment the target you want. Declare this BEFORE the player is included.\n    PLY_AKG_HARDWARE_CPC = 1\n    ;PLY_AKG_HARDWARE_MSX = 1\n    ;PLY_AKG_HARDWARE_SPECTRUM = 1\n    ;PLY_AKG_HARDWARE_PENTAGON = 1\n\n    include \"PlayerAkg.asm\"\nMusicStart\n    include \"music.asm\"<\/code><\/pre>\n\n\n\n<p>That&#8217;s it! Just execute this code, starting in 0x1000 and music will be heard!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re working in Z80, this page is for you. There are already ready-to-use testers in the AT3 package (&#8220;players\/playerAkg\/sources\/tester&#8220;, to name [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":186,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"class_list":["post-2315","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages\/2315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/comments?post=2315"}],"version-history":[{"count":5,"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages\/2315\/revisions"}],"predecessor-version":[{"id":2331,"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages\/2315\/revisions\/2331"}],"wp:attachment":[{"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/media?parent=2315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}