{"id":7907,"date":"2012-09-29T13:05:22","date_gmt":"2012-09-29T17:05:22","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=7907"},"modified":"2021-04-17T10:57:15","modified_gmt":"2021-04-17T14:57:15","slug":"sometimes-things-do-not-go-exactly-as-planned-c-development-for-amstrad-cpc-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2012\/09\/29\/sometimes-things-do-not-go-exactly-as-planned-c-development-for-amstrad-cpc-on-raspberry-pi\/","title":{"rendered":"Sometimes, things do not go exactly as planned &#8230; C development for Amstrad CPC on Raspberry Pi"},"content":{"rendered":"\n<p class=\"has-text-color\" style=\"color:#ff0000\"><strong>Hey! This is ancient!<\/strong> But since we&#8217;re talking about even more ancient computers, those bits still work. I&#8217;d recommend looking at the current <a href=\"https:\/\/github.com\/z88dk\/z88dk#installation\">installation instructions for z88dk<\/a> rather than what I&#8217;ve got here.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"200\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank.png\" alt=\"\" class=\"wp-image-7908\" title=\"what you get if your Amstrad program runs off the rails\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank-160x100.png 160w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><figcaption>a very very crashed Amstrad CPC screen<\/figcaption><\/figure><\/div>\n\n\n\n<p>If you crash an Amstrad CPC, you often got some pretty patterns. Like the one above, which was supposed to print the alphabet, but got about as far as R, then started making coloured spots on the screen. My alphabet doesn&#8217;t (usually) contain coloured spots, so something went wrong.<\/p>\n\n\n\n<p>This post is only about the Raspberry Pi in that it&#8217;s the nearest always-on Linux system that I have. This would likely work fine on any Linux machine. While the Z80 cross compiler I use (<a href=\"http:\/\/www.z88dk.org\/forum\/\">z88dk<\/a>) is available in the repos, I can&#8217;t get it to build anything, so I just pulled down the latest version. To build the compiler:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nwget http:\/\/nightly.z88dk.org\/z88dk-latest.tgz\ntar xvzf z88dk-latest.tgz\ncd z88dk\nexport Z80_OZFILES=$(pwd)\/lib\/\nexport ZCCCFG=${Z80_OZFILES}config\/\nexport PATH=${PATH}:$(pwd)\/bin\n.\/build.sh\n<\/pre><\/div>\n\n\n<p>This should result in a working environment. We can test it with a simple C program:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* alfa.c - print the alphabet *\/\n#include &lt;stdio.h&gt;\n\nint main(void) {\n  char a=&#039;A&#039;;\n  char b=26;\n  while (b&gt;0) {\n    putchar(a);\n    a++;\n    b--;\n  }\n}\n<\/pre><\/div>\n\n\n<p>You can build it with:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nzcc +cpc -create-app -make-app -O3 -unsigned -o alfa.bin alfa.c -lcpcfs -zorg=16384\n<\/pre><\/div>\n\n\n<p>You should end up with a file <code>alpha.bin<\/code> of approximately 4749 (!) bytes. You can copy it to a disc image using <a href=\"http:\/\/koaks.amstrad.free.fr\/amstrad\/projets\/\">iDSK<\/a>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\niDSK blank.dsk -i alfa.bin -c 4000 -e 4000 -t 1\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"296\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank1.png\" alt=\"\" class=\"wp-image-7911\" title=\"CPC running C program (enlarged to show texture)\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank1.png 630w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank1-160x75.png 160w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank1-320x150.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank1-500x234.png 500w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/figure><\/div>\n\n\n\n<p>It runs like this:<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"248\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank2.png\" alt=\"\" class=\"wp-image-7912\" title=\"Z80 Assembly Language in Maxam (enlarged to show texture)\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank2.png 598w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank2-160x66.png 160w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank2-320x132.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/09\/blank2-500x207.png 500w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/figure><\/div>\n\n\n\n<p>You can do the same with Z80 assembly language (shown here in the most gratuitously pretty Amstrad assembler, Maxam):<br>Although this results in only 11 bytes of code, it&#8217;s not portable; the C code above compiled and ran on both my Raspberry Pi and my Mac. It wouldn&#8217;t even run properly on a different Z80 system, as only the Amstrad CPC knows that <code>call #bb5a<\/code> prints the character in the A register. On the ZX Spectrum, for example, it was the completely different instruction <code>rst 16<\/code> to print a character.<\/p>\n\n\n\n<p>(There&#8217;s a lot more on z88dk on the <a href=\"http:\/\/www.cpcwiki.eu\/index.php\/Z88DK\">CPCWiki<\/a>.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey! This is ancient! But since we&#8217;re talking about even more ancient computers, those bits still work. I&#8217;d recommend looking at the current installation instructions for z88dk rather than what I&#8217;ve got here. If you crash an Amstrad CPC, you often got some pretty patterns. Like the one above, which was supposed to print the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[641,2563,2061,270,2565,2510,2557,2564],"class_list":["post-7907","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-amstrad","tag-c","tag-cpc","tag-linux","tag-maxam","tag-raspberrypi","tag-z80","tag-z88dk"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-23x","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/7907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=7907"}],"version-history":[{"count":7,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/7907\/revisions"}],"predecessor-version":[{"id":16663,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/7907\/revisions\/16663"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=7907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=7907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=7907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}