{"id":362,"date":"2025-05-17T16:56:38","date_gmt":"2025-05-17T06:56:38","guid":{"rendered":"http:\/\/electricadventures.net\/?p=362"},"modified":"2025-05-17T16:56:38","modified_gmt":"2025-05-17T06:56:38","slug":"beyond-basic-part-3","status":"publish","type":"post","link":"https:\/\/electricadventures.net\/?p=362","title":{"rendered":"Beyond Basic &#8211; Part 3"},"content":{"rendered":"\n<p><strong>Written By:<\/strong>&nbsp;Tony Cruise<\/p>\n\n\n\n<p><strong>First Published:<\/strong>&nbsp;Micro\u2019s Gazette \u2013 Issue 000 (November\/December 1988)<\/p>\n\n\n\n<p>This issue I will explain about the Hook HGONE, which can be used to add extra commands to your Basic programs.\u00a0\u00a0This eliminates the need to use USR statements, which can be confusing to use for people who are not familiar with machine code.\u00a0\u00a0It also limits the number of parameters to one.<\/p>\n\n\n\n<p>The Hook HGONE is called by the Basic ROM before each statement is processed.&nbsp;&nbsp;This allows you to add a routine that checks if the next Basic statement is one that you have added.&nbsp;&nbsp;For the ease of checking I will use the \u2018[\u2018 character to identify any commands that we add.<\/p>\n\n\n\n<p>The following routine creates two new Basic commands called [BANG and [ZAP.\u00a0\u00a0Each time you use these statements, they will produce a sound, [BANG an explosion sound and [ZAP a laser firing sound.\u00a0\u00a0These new commands can be used in your Basic programs.<\/p>\n\n\n\n<p>e.g.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10 PRINT \u201cTHIS IS A LASER...\u201d:&#91;ZAP\n20 FOR A=1 TO 500:NEXT A\n30 PRINT \u201cTHIS IS AN EXPLOSION...\u201d:&#91;BANG<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Machine Code Program<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>0000<\/td><td>&nbsp;<\/td><td>1 ORIGIN<\/td><td>&nbsp;<\/td><td>; Example of Hook HGONE<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>2<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D000<\/td><td>&nbsp;<\/td><td>3<\/td><td>ORG 0D000H<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>4<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>5 HGONE<\/td><td>EQU 0FF43H<\/td><td>; Hook Jump \u2013 Basic handler<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>6<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D000<\/td><td>F3<\/td><td>7 START<\/td><td>DI<\/td><td>&nbsp;<\/td><\/tr><tr><td>D001<\/td><td>210ED0<\/td><td>8<\/td><td>LD HL,CHECK<\/td><td>; Address to jump to<\/td><\/tr><tr><td>D004<\/td><td>2244FF<\/td><td>9<\/td><td>LD (HGONE+1),HL<\/td><td>; Load into Hook<\/td><\/tr><tr><td>D007<\/td><td>3EC3<\/td><td>10<\/td><td>LD A,0C3H<\/td><td>; Value for JUMP<\/td><\/tr><tr><td>D009<\/td><td>3243FF<\/td><td>11<\/td><td>LD (HGONE),A<\/td><td>; Load into Hook<\/td><\/tr><tr><td>D00C<\/td><td>FB<\/td><td>12<\/td><td>EI<\/td><td>&nbsp;<\/td><\/tr><tr><td>D00D<\/td><td>C9<\/td><td>13<\/td><td>RET<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>14<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D00E<\/td><td>FE5B<\/td><td>15<\/td><td>CHECK CP \u201c[\u201c<\/td><td>; Is next statement<\/td><\/tr><tr><td>D010<\/td><td>C0<\/td><td>16<\/td><td>RET NZ<\/td><td>; one of our commands<\/td><\/tr><tr><td>D011<\/td><td>F3<\/td><td>17<\/td><td>DI<\/td><td>;<\/td><\/tr><tr><td>D012<\/td><td>E5<\/td><td>18<\/td><td>PUSH HL<\/td><td>; Save pointer<\/td><\/tr><tr><td>D013<\/td><td>1149D0<\/td><td>19<\/td><td>LD DE,TABLE<\/td><td>; Table of new commands<\/td><\/tr><tr><td>D016<\/td><td>0600<\/td><td>20<\/td><td>LD B,0<\/td><td>; Loop counter<\/td><\/tr><tr><td>D018<\/td><td>23<\/td><td>21 LOOP1<\/td><td>INC HL<\/td><td>; Increment pointer<\/td><\/tr><tr><td>D019<\/td><td>1A<\/td><td>22<\/td><td>LD A,(DE)<\/td><td>;<\/td><\/tr><tr><td>D01A<\/td><td>FE00<\/td><td>23<\/td><td>CP 0<\/td><td>;<\/td><\/tr><tr><td>D01C<\/td><td>2002<\/td><td>24<\/td><td>JR NZ,LOOP2<\/td><td>; End of Table?<\/td><\/tr><tr><td>D01E<\/td><td>1842<\/td><td>25<\/td><td>JR EXIT<\/td><td>; Yes \u2013 Back to Basic<\/td><\/tr><tr><td>D020<\/td><td>FE2E<\/td><td>26 LOOP2<\/td><td>CP \u201c.\u201d<\/td><td>; End of statement<\/td><\/tr><tr><td>D022<\/td><td>2015<\/td><td>27<\/td><td>JR NZ,LOOP3<\/td><td>; No keep going<\/td><\/tr><tr><td>D024<\/td><td>33<\/td><td>28<\/td><td>INC SP<\/td><td>; Get rid of old<\/td><\/tr><tr><td>D025<\/td><td>33<\/td><td>29<\/td><td>INC SP<\/td><td>; pointer<\/td><\/tr><tr><td>D026<\/td><td>E5<\/td><td>30<\/td><td>PUSH HL<\/td><td>; save new pointer<\/td><\/tr><tr><td>D027<\/td><td>DD2153D0<\/td><td>31<\/td><td>LD IX,JMPTBL<\/td><td>;<\/td><\/tr><tr><td>D02B<\/td><td>1600<\/td><td>32<\/td><td>LD D,0<\/td><td>;<\/td><\/tr><tr><td>D02D<\/td><td>58<\/td><td>33<\/td><td>LD E,B<\/td><td>;<\/td><\/tr><tr><td>D02E<\/td><td>CB23<\/td><td>34<\/td><td>SLA E<\/td><td>;<\/td><\/tr><tr><td>D030<\/td><td>DD19<\/td><td>35<\/td><td>ADD IX,DE<\/td><td>;<\/td><\/tr><tr><td>D032<\/td><td>DD6E00<\/td><td>36<\/td><td>LD L,(IX+0)<\/td><td>; Calculate jump<\/td><\/tr><tr><td>D035<\/td><td>DD6601<\/td><td>37<\/td><td>LD H,(IX+1)<\/td><td>; address<\/td><\/tr><tr><td>D038<\/td><td>E9<\/td><td>38<\/td><td>JP (HL)<\/td><td>;<\/td><\/tr><tr><td>D039<\/td><td>4E<\/td><td>39 LOOP3<\/td><td>LD C,(HL)<\/td><td>; Get next character<\/td><\/tr><tr><td>D03A<\/td><td>13<\/td><td>40<\/td><td>INC DE<\/td><td>; Set DE for next loop<\/td><\/tr><tr><td>D03B<\/td><td>B9<\/td><td>41<\/td><td>CP C<\/td><td>; Match?<\/td><\/tr><tr><td>D03C<\/td><td>28DA<\/td><td>42<\/td><td>JR Z,LOOP1<\/td><td>; Yes, go again<\/td><\/tr><tr><td>D03E<\/td><td>04<\/td><td>43<\/td><td>INC B<\/td><td>; Next statement<\/td><\/tr><tr><td>D03F<\/td><td>E1<\/td><td>44<\/td><td>POP HL<\/td><td>;<\/td><\/tr><tr><td>D040<\/td><td>E5<\/td><td>45<\/td><td>PUSH HL<\/td><td>; Restore pointer<\/td><\/tr><tr><td>D041<\/td><td>1A<\/td><td>46 LOOP4<\/td><td>LD A,(DE)<\/td><td>;<\/td><\/tr><tr><td>D042<\/td><td>13<\/td><td>47<\/td><td>INC DE<\/td><td>; Move DE to next<\/td><\/tr><tr><td>D043<\/td><td>FE2E<\/td><td>48<\/td><td>CP \u201c.\u201d<\/td><td>; statement<\/td><\/tr><tr><td>D045<\/td><td>28D1<\/td><td>49<\/td><td>JR Z,LOOP1<\/td><td>; Loop again<\/td><\/tr><tr><td>D047<\/td><td>18F8<\/td><td>50<\/td><td>JR LOOP4<\/td><td>;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>51<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D049<\/td><td>42414E47<\/td><td>58 TABLE<\/td><td>DEFM \u201cBANG.\u201d<\/td><td>; Statement table<\/td><\/tr><tr><td>D04D<\/td><td>2E<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D04E<\/td><td>5A41592E<\/td><td>59<\/td><td>DEFM \u201cZAP.\u201d<\/td><td>;<\/td><\/tr><tr><td>D052<\/td><td>00<\/td><td>60<\/td><td>DEFB 0<\/td><td>;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>61<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D053<\/td><td>74D0<\/td><td>62 JMPTBL<\/td><td>DEFW BANG<\/td><td>; Jump Table<\/td><\/tr><tr><td>D055<\/td><td>8CD0<\/td><td>63<\/td><td>DEFW ZAP<\/td><td>;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>64<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D057<\/td><td>1A<\/td><td>65 SOUND<\/td><td>LD A,(DE)<\/td><td>; Get next value<\/td><\/tr><tr><td>D058<\/td><td>FEFF<\/td><td>66<\/td><td>CP 255<\/td><td>; End of List?<\/td><\/tr><tr><td>D05A<\/td><td>C8<\/td><td>67<\/td><td>RET Z<\/td><td>; Yes \u2013 Return<\/td><\/tr><tr><td>D05B<\/td><td>D3A0<\/td><td>68<\/td><td>OUT (0A0H),A<\/td><td>; Send value<\/td><\/tr><tr><td>D05D<\/td><td>13<\/td><td>69<\/td><td>INC DE<\/td><td>; Increment pointer<\/td><\/tr><tr><td>D05E<\/td><td>FE07<\/td><td>70<\/td><td>CP 7<\/td><td>; Is it register 7<\/td><\/tr><tr><td>D060<\/td><td>1A<\/td><td>71<\/td><td>LD A,(DE)<\/td><td>;<\/td><\/tr><tr><td>D061<\/td><td>2006<\/td><td>72<\/td><td>JR NZ,SNDLP1<\/td><td>; No &#8211; Continue<\/td><\/tr><tr><td>D063<\/td><td>47<\/td><td>73<\/td><td>LD B,A<\/td><td>;<\/td><\/tr><tr><td>D064<\/td><td>DBA2<\/td><td>74<\/td><td>IN A,(0A2H)<\/td><td>; Get current value<\/td><\/tr><tr><td>D066<\/td><td>E6C0<\/td><td>75<\/td><td>AND 192<\/td><td>;<\/td><\/tr><tr><td>D068<\/td><td>80<\/td><td>76<\/td><td>ADD A,B<\/td><td>; Combine values<\/td><\/tr><tr><td>D069<\/td><td>D3A1<\/td><td>77 SNDLP1<\/td><td>OUT (0A1H),A<\/td><td>; Send value<\/td><\/tr><tr><td>D06B<\/td><td>13<\/td><td>78<\/td><td>INC DE<\/td><td>; Increment pointer<\/td><\/tr><tr><td>D06C<\/td><td>18E9<\/td><td>79<\/td><td>JR SOUND<\/td><td>;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>80<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D06E<\/td><td>E1<\/td><td>81 EXIT<\/td><td>POP HL<\/td><td>; Restore pointer<\/td><\/tr><tr><td>D06F<\/td><td>7E<\/td><td>82<\/td><td>LD A,(HL)<\/td><td>; Restore A<\/td><\/tr><tr><td>D070<\/td><td>33<\/td><td>83<\/td><td>INC SP<\/td><td>; Get rid of<\/td><\/tr><tr><td>D071<\/td><td>33<\/td><td>84<\/td><td>INC SP<\/td><td>; Basic return<\/td><\/tr><tr><td>D072<\/td><td>FB<\/td><td>85<\/td><td>EI<\/td><td>;<\/td><\/tr><tr><td>D073<\/td><td>C9<\/td><td>86<\/td><td>RET<\/td><td>;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>87<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D074<\/td><td>117CD0<\/td><td>88 BANG<\/td><td>LD DE,BANG1<\/td><td>; Set pointer<\/td><\/tr><tr><td>D077<\/td><td>CD57D0<\/td><td>89<\/td><td>CALL SOUND<\/td><td>; Call sound routine<\/td><\/tr><tr><td>D07A<\/td><td>18F2<\/td><td>90<\/td><td>JR EXIT<\/td><td>; Exit to Basic<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>91<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D07C<\/td><td>09100208<\/td><td>92 BANG1<\/td><td>DEFB 9,16,2,8,3,5,7,40<\/td><td><\/td><\/tr><tr><td>D080<\/td><td>03050728<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D084<\/td><td>06140C0A<\/td><td>93<\/td><td>DEFB 6,20,12,10,13,0,255,255<\/td><td><\/td><\/tr><tr><td>D088<\/td><td>0D00FFFF<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>94<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D08C<\/td><td>1194D0<\/td><td>95 ZAP<\/td><td>LD DE,ZAP1<\/td><td>; Set pointer<\/td><\/tr><tr><td>D08F<\/td><td>CD57D0<\/td><td>96<\/td><td>CALL SOUND<\/td><td>; Call sound routine<\/td><\/tr><tr><td>D092<\/td><td>18DA<\/td><td>97<\/td><td>JR EXIT<\/td><td>; Exit to Basic<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>98<\/td><td>&nbsp;<\/td><td>;<\/td><\/tr><tr><td>D094<\/td><td>091002C8<\/td><td>99 ZAP1<\/td><td>DEFB 9,16,2,200,3,0,12,6<\/td><td>&nbsp;<\/td><\/tr><tr><td>D098<\/td><td>03000C08<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D09C<\/td><td>07380D04<\/td><td>100<\/td><td>DEFB 7,56,13,4,255,255<\/td><td>&nbsp;<\/td><\/tr><tr><td>D0A0<\/td><td>FFFF<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D0A2<\/td><td>&nbsp;<\/td><td>101 END<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Loader<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>10 CLS:CLEAR 200,&amp;HCFFF:DEFINTA-Z:A=&amp;HD000\n20 READ A$:IF A$ &lt;> \u201c@\u201d THEN POKE A, VAL(\u201c&amp;H\u201d+A$):A=A+1:GOTO 20\n30 PRINT\u201d\u00a0\u00a0INSERT TAPE\/DISK TO SAVE PROGRAM\u201d\n40 PRINT\u201d\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0AND PRESS ANY KEY\u201d\n50 A$=INPUT$(1):PRINT:PRINT \u201c\u00a0\u00a0SAVING ....\u201d\n60 BSAVE\u201dCHECK\u201d,&amp;HD000,A-1\n100 DATA F3,21,0E,D0,22,44,FF,3E,C3,32,43,FF,FB,C9,FE,5B\n110 DATA C0,F3,E5,11,49,D0,06,00,23,1A,FE,00,20,02,18,4E\n120 DATA FE,2E,20,15,33,33,E5,DD,21,53,D0,16,00,58,CB,23\n130 DATA DD,19,DD,6E,00,DD,66,01,E9,4E,13,B9,28,DA,04,E1\n140 DATA E5,1A,13,FE,2E,28,D1,18,F8,42,41,4E,47,2E,5A,41\n150 DATA 50,2E,00,74,D0,8C,D0,1A,FE,FF,C8,D3,A0,13,FE,07\n160 DATA 1A,20,06,47,DB,A2,E6,C0,80,D3,A1,13,18,E9,E1,7E\n170 DATA 33,33,FB,C9,11,7C,D0,CD,57,D0,18,F2,09,10,02,08\n180 DATA 03,05,07,28,06,14,0C,0A,0D,00,FF,FF,11,94,D0,CD\n190 DATA 57,D0,18,DA,09,10,02,C8,03,00,0C,06,07,38,0D,04\n200 DATA FF,FF,@<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Next issue I will cover how to read command line variables and start on the new commands.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Written By:&nbsp;Tony Cruise First Published:&nbsp;Micro\u2019s Gazette \u2013 Issue 000 (November\/December 1988) This issue I will explain about the Hook HGONE, which can be used to add extra commands to your Basic programs.\u00a0\u00a0This eliminates the need to use USR statements, which can be confusing to use for people who are not familiar with machine code.\u00a0\u00a0It also<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[61],"tags":[],"class_list":["post-362","post","type-post","status-publish","format-standard","hentry","category-beyond-basic"],"acf":[],"_links":{"self":[{"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362"}],"version-history":[{"count":1,"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions\/363"}],"wp:attachment":[{"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}