{"id":573,"date":"2015-11-15T16:13:01","date_gmt":"2015-11-15T16:13:01","guid":{"rendered":"http:\/\/tlindner.macmess.org\/?page_id=573"},"modified":"2015-11-15T16:13:01","modified_gmt":"2015-11-15T16:13:01","slug":"modifying-super-extended-color-basic","status":"publish","type":"page","link":"https:\/\/tlindner.macmess.org\/?page_id=573","title":{"rendered":"Modifying Super Extended Color BASIC"},"content":{"rendered":"<p>On a recent project I needed to read and write unsigned double byte values from memory. The standard version of BASIC does not include such commands so they must be accomplished using multiple commands. For reading a two byte value this is usually how it is done:\n<code>&lt;pre&gt;\n10 A = PEEK(&amp;H6000)&lt;em&gt;256+PEEK(&amp;H6001)\n&lt;\/pre&gt;<\/code>\nVariable A will now contain an unsigned two byte value starting from $6000. This is an example of writing a two byte value:\n<code>&lt;pre&gt;\n10 A=RND(65535)\n20 POKE &amp;H6000,A\/256\n30 POKE &amp;H6001,256&lt;\/em&gt;(A\/256-INT(A\/256))\n&lt;\/pre&gt;<\/code>\nIt turns out all this math was causing my recent project to slow down to unacceptable levels. So I had the idea of rewriting the Super Extended Color BASIC commands LPEEK and LPOKE to perform double byte reads and writes. Looking thru the commented source disassembly, I discovered that if it was acceptable to completely replace the functionality of the commands I had 27 bytes for LPEEK and 45 bytes for LPOKE to work with.<\/p>\n<p>So I took the code from regular PEEK and and placed it where LPEEK was and change the opcode to read two bytes instead of one. This caused a problem, the standard return from a function subroutine converts the D register to a signed value from -32767 to 32766. I wanted an unsigned result from 0 to 65535. In the LIST command I discovered a bit of code that prints the line number to do exactly what I wanted.\n<code>&lt;pre&gt;\n0050     00001 fpa0 equ $50\n002B     00002 binval equ $2b\n00003\n00004 # Modify LPEEK to return two bytes (unsigned)\n00005  org $e573\nE573 17D1CA   00006  lbsr $b740 convert FPA0 to integer in register X\nE576 EC84     00007  ldd ,x read two bytes\nE578 DD50     00008  std fpa0 convert Reg D to FP and return\nE57A C690     00009  ldb #$90\nE57C 43       00010  coma\nE57D BDBC86   00011  jsr $bc86\nE580 39       00012  rts\n&lt;\/pre&gt;<\/code>\nThe new LPOKE function needed to read two comma separated values from the program and write the value to the address.\n<code>&lt;pre&gt;\n00014 # Modify LPOKE to store two bytes (unsigned)\n00015  org $e545\nE545 17D1F5   00016  lbsr $b73d eval expression return in X\nE548 9F2B     00017  stx binval store address in binval\nE54A BDB26D   00018  jsr $b26d syntax check for a comma\nE54D 17D1ED   00019  lbsr $b73d eval expression return in X\nE550 1F10     00020  tfr x,d transfer value to D\nE552 9E2B     00021  ldx binval load address\nE554 ED84     00022  std ,x store value in address\nE556 39       00023  rts\n&lt;\/pre&gt;<\/code>\nAfter overlaying this code onto SECB, I now have a double byte version of PEEK and POKE. Soon I discovered I had a new slow down. I was filling buffers with the same byte, over and over. Like this:\n<code>&lt;pre&gt;\n10 FOR X = &amp;H6000 TO &amp;H64FF\n20 POKE X, &amp;H55\n30 NEXT X\n&lt;\/pre&gt;<\/code>\nThis turned out to be a slow method of filling memory. I needed a new command to quickly accomplish the same thing. I began looking for another command in SECB that I could replace. I decided to replace HPAINT.\n<code>&lt;pre&gt;\n00025 # Modify HPAINT to be a memory fill command\n00026 # Example: HPAINT &amp;H7400, &amp;H2300, &amp;H80\n00027 # Write byte $80 to buffer in $7400 to $96FF\n00028  org $ebf5\nEBF5 17CB45   00029  lbsr $b73d eval expression return in X\nEBF8 9F2B     00030  stx binval store address in binval\nEBFA BDB26D   00031  jsr $b26d syntax check for a comma\nEBFD 17CB3D   00032  lbsr $b73d eval expression return in X\nEC00 3410     00033  pshs x\nEC02 BDB26D   00034  jsr $b26d syntax check for a comma\nEC05 BDB70B   00035  jsr $b70b eval expression return in B\nEC08 9E2B     00036  ldx binval\nEC0A 3520     00037  puls y\n00038 loop\nEC0C E780     00039  stb ,x+\nEC0E 313F     00040  leay -1,y\nEC10 26FA     00041  bne loop\nEC12 39       00042  rts\n00043  end\n&lt;\/pre&gt;<\/code>\nTo test it I wrote this screen saver:<\/p>\n<pre><code>\n10 WIDTH 32:CLS\n20 HPAINT &amp;H3FF+RND(512),RND(128),127+RND(128)\n30 GOTO 20\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>On a recent project I needed to read and write unsigned double byte values from memory. The standard version of BASIC does not include such commands so they must be accomplished using multiple commands. For reading a two byte value &hellip; <a href=\"https:\/\/tlindner.macmess.org\/?page_id=573\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-573","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=\/wp\/v2\/pages\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=573"}],"version-history":[{"count":13,"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=\/wp\/v2\/pages\/573\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=\/wp\/v2\/pages\/573\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/tlindner.macmess.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}