{"id":2381,"date":"2025-03-13T02:20:43","date_gmt":"2025-03-13T00:20:43","guid":{"rendered":"https:\/\/www.julien-nevo.com\/arkostracker\/?page_id=2381"},"modified":"2025-08-22T12:01:55","modified_gmt":"2025-08-22T10:01:55","slug":"basic-cpc-integration","status":"publish","type":"page","link":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/basic-cpc-integration\/","title":{"rendered":"CPC Basic integration"},"content":{"rendered":"\n<pre class=\"wp-block-verse\">This example has been superseded by the\u00a0<a href=\"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/using-interruption-player-with-cpc-basic\/\" data-type=\"page\" data-id=\"2383\">interruption player<\/a> (one call and the music plays in the background!), so you should probably use it instead.<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The players can all be called from assembler or C. However, some of us are still developing games on our good old Basic! Here is a little walkthrough on how to do that.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a prerequisite, please download&nbsp;<a href=\"https:\/\/github.com\/EdouardBERGE\/rasm\" target=\"_blank\" rel=\"noreferrer noopener\">Rasm<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The example uses the AKG player, but it will work for all the other ones. Contrary to assembler, Basic requires a few securities, else it will crash, so we need to create a small assembler code to &#8220;secure&#8221; the calls to the players.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A few steps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the same folder, we will create our &#8220;secure&#8221; asm code. Either copy\/paste the&nbsp;<em>sources\/playerAkg\/testers<\/em>\/<em>Basic_CPC.asm<\/em>&nbsp;program where your music is, or use the code below. Save it as&nbsp;<em>Basic_CPC.asm<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Export your music (as source), let&#8217;s called it&nbsp;<em>MyMusic.asm<\/em>.&nbsp;<strong>Warning<\/strong>, make sure that the option &#8220;encode to address&#8221;, at the bottom of each export window, is&nbsp;<strong>unchecked<\/strong>&nbsp;(we don&#8217;t need to add an ORG to the music source as we directly include it to our own).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the\u00a0<em>PlayerAkg.asm<\/em>\u00a0player in the same folder. It is located in the\u00a0<em>sources\/playerAkg<\/em>\u00a0folder of the AT3 package.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>;Basic_CPC.asm&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;org #4000\n\n&nbsp;&nbsp;&nbsp;&nbsp;jp Init&nbsp;&nbsp; \n&nbsp;&nbsp;&nbsp;&nbsp;jp Play\n&nbsp;&nbsp;&nbsp;&nbsp;jp StopMusic\n\nInit:\n&nbsp;&nbsp;&nbsp;&nbsp;ld hl,Music&nbsp;&nbsp;&nbsp;&nbsp; ;Initializes the music.\n&nbsp;&nbsp;&nbsp;&nbsp;ld a,0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;The subsong number (0 is the first one).\n&nbsp;&nbsp;&nbsp;&nbsp;call Player + 0\n&nbsp;&nbsp;&nbsp;&nbsp;ret\n\nPlay:\n&nbsp;&nbsp; di\n&nbsp;&nbsp; ex af,af'\n&nbsp;&nbsp; exx\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push af&nbsp;&nbsp;;Saves a few registers the system needs.\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push bc\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push ix\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;push iy\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;call Player + 3&nbsp;&nbsp; ;Plays the music.\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pop iy\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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bsp;ret\n\nPlayer:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include \"PlayerAkg.asm\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;The player. Loads the one you want (AKG, AKM, Lightweight, AKY).\n\nMusic:&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include \"MyMusic.asm\"&nbsp;&nbsp;&nbsp;&nbsp;;The music.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t be scared if you don&#8217;t understand assembler! Let&#8217;s compile this into binary:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rasm Basic_CPC.asm -o playmus<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will create a&nbsp;<em>playmus.bin<\/em>&nbsp;file, which contains the &#8220;secure&#8221; calls to the player, the player itself and the music.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now load this file into Basic. There are many possibilities to do so:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you&#8217;re using Winape, you can inject it directly in memory (in the debugger, right click on the memory and load the file in #4000).<\/li>\n\n\n\n<li>Use ManageDsk by Demoniak to create a DSK and adds the file in it (as a binary, in #4000).<\/li>\n\n\n\n<li>For automated generation, some better tools exist, I let you search for them.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Load the file in Basic (unless you&#8217;ve injected it):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>memory &amp;3fff\nload\"playmus.bin\",&amp;4000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s play!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10 call &amp;4000&nbsp;&nbsp; 'initialize the music.\n20 call &amp;bd19:call &amp;4003&nbsp;&nbsp; 'plays one frame of the music, at 50hz.\n30 if inkey(47)&lt;&gt;0 then 20&nbsp;&nbsp;'loops as long as space is not pressed.\n40 call &amp;4006&nbsp;&nbsp; 'stops the music.\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I chose the &amp;4000 address, but you can change it (change the ORG in the source, as well as all the CALLs in the Basic example, and of course the LOAD address). Don&#8217;t forget to set the&nbsp;<em>memory<\/em>&nbsp;command one byte before, so that the Basic program doesn&#8217;t overwrite the binary (<em>memory &amp;1234<\/em>&nbsp;if you load the music in &amp;1235 for example). The address should be from &amp;1000 to &amp;9000, don&#8217;t go too high! Basic will prevent you from doing so anyway.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, it is possible to use interruptions in Basic to play the music while doing something else. If you need such facilities, please let me know and I&#8217;ll create another example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example has been superseded by the\u00a0interruption player (one call and the music plays in the background!), so you should probably use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":210,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"class_list":["post-2381","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages\/2381","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=2381"}],"version-history":[{"count":4,"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages\/2381\/revisions"}],"predecessor-version":[{"id":2395,"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/pages\/2381\/revisions\/2395"}],"wp:attachment":[{"href":"https:\/\/www.julien-nevo.com\/arkostracker\/index.php\/wp-json\/wp\/v2\/media?parent=2381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}