{"id":14305,"date":"2017-09-18T11:14:29","date_gmt":"2017-09-18T15:14:29","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=14305"},"modified":"2025-01-08T07:53:25","modified_gmt":"2025-01-08T12:53:25","slug":"importing-applesoft-basic-programs-on-the-apple-iie","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2017\/09\/18\/importing-applesoft-basic-programs-on-the-apple-iie\/","title":{"rendered":"importing Applesoft BASIC programs on the Apple IIe"},"content":{"rendered":"<p>Just what no-one has needed since about 1979 or so \u2026<\/p>\n<p>BASIC on the Apple II has no easy way to import text as a program. When you LOAD a file, it must be in Apple&#8217;s <a href=\"http:\/\/justsolve.archiveteam.org\/wiki\/Applesoft_BASIC_tokenized_file\">tokenized format<\/a>. While Apple DOS has the EXEC facility to run script files as if they were typed from the keyboard, it&#8217;s very picky about the file format:<\/p>\n<ol>\n<li>There must be a carriage return character (CR, ASCII 13) before the first line<\/li>\n<li>All line numbers must have an extra space before and after them<\/li>\n<li>All tokens must be in upper case<\/li>\n<li>All tokens (keywords and functions) must have a space after them.<\/li>\n<\/ol>\n<p>The right way to do this conversion would be to write a tokenizer that spits out the correct binary file. But you can (kinda) fudge it with this shell command, operating from BASIC source PROG.BAS:<\/p>\n<pre>sed 's\/^[0-9][0-9]*\/&amp; \/;s\/^\/ \/;1s\/^\/\\n\/;s\/$\/ \/;s\/[:()]\/ &amp; \/g;' PROG.BAS | tr '\\n' '\\r' | ac.sh -p EG.dsk PROG T<\/pre>\n<p>ac.sh is the command line version of <a href=\"http:\/\/applecommander.sourceforge.net\/\">AppleCommander<\/a>, and the file EG.dsk referred to above is an Apple DOS 3.3 image created with<\/p>\n<pre>ac.sh -dos140 EG.dsk<\/pre>\n<p>It still needs work, as there are functions that will mess this up, and Applesoft&#8217;s parser makes a mess of code like <strong>IF A THEN \u2026<\/strong>, turning it into <strong>IF AT HEN \u2026<\/strong>.<\/p>\n<p>So if I wanted to import the following futile program:<\/p>\n<pre>10 REM A FUTILE PROGRAM BY SCRUSS\n20 HOME\n30 FOR X=1 TO 20\n40 PRINT SPC(X);\"FUTILE\"\n50 NEXT X<\/pre>\n<p>Run through the script (but before EOL conversion) it would look like this:<\/p>\n<pre> 10  REM A FUTILE PROGRAM BY SCRUSS \n 20  HOME \n 30  FOR X=1 TO 20 \n 40  PRINT SPC ( X ) ;\"FUTILE\" \n 50  NEXT X<\/pre>\n<p>Make a disk and put the modified program text on it:<\/p>\n<pre>ac.sh -dos140 futile.dsk\nsed 's\/^[0-9][0-9]*\/&amp; \/;s\/^\/ \/;1s\/^\/\\n\/;s\/$\/ \/;s\/[:()]\/ &amp; \/g;' futile.bas | tr '\\n' '\\r' | ac.sh -p futile.dsk FUT T<\/pre>\n<p>Load the disk into your Apple II, clear out the init program, and import the code with <code>EXEC FUT<\/code>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14306\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple15.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple15.png 800w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple15-160x120.png 160w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple15-320x240.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple15-768x576.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>If all you get is <strong>]<\/strong> cursors printed and no syntax errors, then something might be working. List it:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14307\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple16.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple16.png 800w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple16-160x120.png 160w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple16-320x240.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple16-768x576.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Run it:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14308\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple17.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple17.png 800w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple17-160x120.png 160w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple17-320x240.png 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/linapple17-768x576.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Disk image: <a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/09\/futile-AppleII-dsk.zip\">futile-AppleII-dsk.zip<\/a>, containing:<\/p>\n<pre>$ ac.sh -l futile.dsk\n\nDISK VOLUME #254\n T 002 FUT \n A 002 FUTILE \nDOS 3.3 format; 134,144 bytes free; 9,216 bytes used.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just what no-one has needed since about 1979 or so \u2026 BASIC on the Apple II has no easy way to import text as a program. When you LOAD a file, it must be in Apple&#8217;s tokenized format. While Apple DOS has the EXEC facility to run script files as if they were typed from [&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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[3071,2062,24,2556],"class_list":["post-14305","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-appleii","tag-basic","tag-futile","tag-retrocomputing"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-3IJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14305","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=14305"}],"version-history":[{"count":5,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14305\/revisions"}],"predecessor-version":[{"id":17705,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14305\/revisions\/17705"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=14305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=14305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=14305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}