{"id":360,"date":"2025-05-17T16:52:21","date_gmt":"2025-05-17T06:52:21","guid":{"rendered":"http:\/\/electricadventures.net\/?p=360"},"modified":"2025-05-17T16:52:21","modified_gmt":"2025-05-17T06:52:21","slug":"beyond-basic-part-2","status":"publish","type":"post","link":"https:\/\/electricadventures.net\/?p=360","title":{"rendered":"Beyond Basic &#8211; Part 2"},"content":{"rendered":"\n<p><strong>Written By:<\/strong>&nbsp;Tony Cruise<\/p>\n\n\n\n<p><strong>First Published:<\/strong>&nbsp;MSX and Spectravideo Computer Forum Vol. 2 No. 11<\/p>\n\n\n\n<p>\u00a0In this section, I will explain how you attach extra commands to ROM routines.<\/p>\n\n\n\n<p>In MSX computers, there are many Hook Jumps provided so that machine code programmers can attach their own routines to most of the basic ROM routines.\u00a0\u00a0Each Hook consists of five memory locations in RAM.\u00a0\u00a0When the computer is first switched on or reset, each of the locations contains the value 201.\u00a0\u00a0This is the decimal value for a RETURN statement in machine code.\u00a0\u00a0Each of the Hooks are jumped to at the start of each of the corresponding ROM routines, so you can insert or eliminate entirely each routine.<\/p>\n\n\n\n<p>To use a Hook, all you have to do is insert your own commands into the five memory locations.&nbsp;&nbsp;This is usually a JUMP instruction to your machine code routine.<\/p>\n\n\n\n<p>Here is an example program that uses the Hook HTIMI.&nbsp;&nbsp;This Hook is jumped to every 1\/50th&nbsp;of a second.<\/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>D000<\/td><td>&nbsp;<\/td><td>1 ORIGIN<\/td><td>ORG 0D000H<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>2 ;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>3 ; PROGRAM TO UPDATE AND DISPLAY A CLOCK<\/td><td><\/td><td><\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>4 ; ON SCREEN 0<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>5 ;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>6 ; LABEL SETTINGS<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>7 HTIMI<\/td><td>EQU 0FD9FH<\/td><td>; Hook Jump \u2013 Timer<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>8 SCRMOD<\/td><td>EQU 0FCAFH<\/td><td>; RAM Storage \u2013 Screen Mode<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>9 SETWRT<\/td><td>EQU 0053H<\/td><td>; ROM Routine \u2013 Set Video Write<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>10 ;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D000<\/td><td>3EC3<\/td><td>11 START:<\/td><td>LD A,0C3H<\/td><td>; Value for JUMP instruction<\/td><\/tr><tr><td>D002<\/td><td>329FFD<\/td><td>12<\/td><td>LD (HTIMI),A<\/td><td>; Load into Hook<\/td><\/tr><tr><td>D005<\/td><td>210CD0<\/td><td>13<\/td><td>LD HL,CUE<\/td><td>; Address to jump to<\/td><\/tr><tr><td>D008<\/td><td>22A0FD<\/td><td>14<\/td><td>LD (HTIMI+1),A<\/td><td>; Load into Hook<\/td><\/tr><tr><td>D00B<\/td><td>C9<\/td><td>15<\/td><td>RET<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>16 ;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D00C<\/td><td>CD14D0<\/td><td>17 CUE:<\/td><td>CALL CLOCK<\/td><td>; Call CLOCK routine<\/td><\/tr><tr><td>D00F<\/td><td>F7<\/td><td>18<\/td><td>RST 030H<\/td><td>; Disk delay routine<\/td><\/tr><tr><td>D010<\/td><td>879C77<\/td><td>19<\/td><td>DEFB 087H,09CH,077H<\/td><td>;-remove if you do not<\/td><\/tr><tr><td>D013<\/td><td>C9<\/td><td>20<\/td><td>&nbsp;<\/td><td>; have a disk drive<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>21 ;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D014<\/td><td>161D0<\/td><td>22 CLOCK:<\/td><td>LD HL,STORE<\/td><td>; Decrease counter<\/td><\/tr><tr><td>D017<\/td><td>7E<\/td><td>23<\/td><td>LD A,(HL)<\/td><td>;<\/td><\/tr><tr><td>D018<\/td><td>3D<\/td><td>24<\/td><td>DEC A<\/td><td>;<\/td><\/tr><tr><td>D019<\/td><td>77<\/td><td>25<\/td><td>LD (HL),A<\/td><td>;<\/td><\/tr><tr><td>D01A<\/td><td>C0<\/td><td>26<\/td><td>RET NZ<\/td><td>; Return if not ZERO<\/td><\/tr><tr><td>D01B<\/td><td>3E33<\/td><td>27<\/td><td>LD A,51<\/td><td>; Set new counter<\/td><\/tr><tr><td>D01D<\/td><td>77<\/td><td>28<\/td><td>LD (HL),A<\/td><td>;<\/td><\/tr><tr><td>D01E<\/td><td>2162D0<\/td><td>29<\/td><td>LD HL,CLKSTR<\/td><td>; Update \u2013 seconds<\/td><\/tr><tr><td>D021<\/td><td>0603<\/td><td>30<\/td><td>LD B,3<\/td><td>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; minutes<\/td><\/tr><tr><td>D023<\/td><td>7E<\/td><td>31 CL1:<\/td><td>LD A,(HL)<\/td><td>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; hours<\/td><\/tr><tr><td>D024<\/td><td>3C<\/td><td>32<\/td><td>INC A<\/td><td>;<\/td><\/tr><tr><td>D025<\/td><td>27<\/td><td>33<\/td><td>DAA<\/td><td>; Decimal addition<\/td><\/tr><tr><td>D026<\/td><td>FE69<\/td><td>34<\/td><td>CP 060H<\/td><td>;<\/td><\/tr><tr><td>D028<\/td><td>3003<\/td><td>35<\/td><td>JR NC,CL2<\/td><td>;<\/td><\/tr><tr><td>D02A<\/td><td>77<\/td><td>36<\/td><td>LD (HL),A<\/td><td>;<\/td><\/tr><tr><td>D02B<\/td><td>1805<\/td><td>37<\/td><td>JR PRTCLK<\/td><td>;<\/td><\/tr><tr><td>D02D<\/td><td>3600<\/td><td>38 CL2:<\/td><td>LD (HL),0<\/td><td>;<\/td><\/tr><tr><td>D02F<\/td><td>23<\/td><td>39<\/td><td>INC HL<\/td><td>;<\/td><\/tr><tr><td>D030<\/td><td>10F1<\/td><td>40<\/td><td>DJNZ CL1<\/td><td>;<\/td><\/tr><tr><td>D032<\/td><td>3AAFFC<\/td><td>41 PRTCLK:<\/td><td>LD A,(SCRMOD)<\/td><td>; Get screen mode<\/td><\/tr><tr><td>D035<\/td><td>3D<\/td><td>42<\/td><td>DEC A<\/td><td>;<\/td><\/tr><tr><td>D036<\/td><td>D0<\/td><td>43<\/td><td>RET NC<\/td><td>; Check for screen 0<\/td><\/tr><tr><td>D037<\/td><td>211F00<\/td><td>44<\/td><td>LD HL,31<\/td><td>;<\/td><\/tr><tr><td>D03A<\/td><td>CD5300<\/td><td>45<\/td><td>CALL SETWRT<\/td><td>; Set screen address<\/td><\/tr><tr><td>D03D<\/td><td>2164D0<\/td><td>46<\/td><td>LD HL,CLKSTR+2<\/td><td>; Set pointer to clock<\/td><\/tr><tr><td>D040<\/td><td>0603<\/td><td>47<\/td><td>LD B,3<\/td><td>; Set counter<\/td><\/tr><tr><td>D042<\/td><td>7E<\/td><td>48 P1:<\/td><td>LD A,(HL)<\/td><td>;<\/td><\/tr><tr><td>D043<\/td><td>27<\/td><td>49<\/td><td>DAA<\/td><td>;<\/td><\/tr><tr><td>D044<\/td><td>F5<\/td><td>50<\/td><td>PUSH AF<\/td><td>; Save value<\/td><\/tr><tr><td>D045<\/td><td>CB3F<\/td><td>51<\/td><td>SRL A<\/td><td>; Get right digit<\/td><\/tr><tr><td>D047<\/td><td>CB3F<\/td><td>52<\/td><td>SRL A<\/td><td>;<\/td><\/tr><tr><td>D049<\/td><td>CB3F<\/td><td>53<\/td><td>SRL A<\/td><td>;<\/td><\/tr><tr><td>D04B<\/td><td>CB3F<\/td><td>54<\/td><td>SRL A<\/td><td>;<\/td><\/tr><tr><td>D04D<\/td><td>C630<\/td><td>55<\/td><td>ADD A,48<\/td><td>; Change to ASCII<\/td><\/tr><tr><td>D04F<\/td><td>D398<\/td><td>56<\/td><td>OUT (098H),A<\/td><td>; Send to screen<\/td><\/tr><tr><td>D051<\/td><td>F1<\/td><td>57<\/td><td>POP AF<\/td><td>; Return value<\/td><\/tr><tr><td>D052<\/td><td>E60F<\/td><td>58<\/td><td>AND 1111B<\/td><td>; Get left digit<\/td><\/tr><tr><td>D054<\/td><td>C630<\/td><td>59<\/td><td>ADD A,48<\/td><td>; Change to ASCII<\/td><\/tr><tr><td>D056<\/td><td>D398<\/td><td>60<\/td><td>OUT (098H),A<\/td><td>; Send to screen<\/td><\/tr><tr><td>D058<\/td><td>3E3A<\/td><td>61<\/td><td>LD A,58<\/td><td>; Value for \u2018:\u2019<\/td><\/tr><tr><td>D05A<\/td><td>2B<\/td><td>62<\/td><td>DEC HL<\/td><td>; Update pointer<\/td><\/tr><tr><td>D05B<\/td><td>05<\/td><td>63<\/td><td>DEC B<\/td><td>; Update counter<\/td><\/tr><tr><td>D05C<\/td><td>C8<\/td><td>64<\/td><td>RET Z<\/td><td>; Return if finished<\/td><\/tr><tr><td>D05D<\/td><td>D398<\/td><td>65<\/td><td>OUT (098H),A<\/td><td>; Send \u2018:\u2019 to screen<\/td><\/tr><tr><td>D05F<\/td><td>18E1<\/td><td>66<\/td><td>JR P1<\/td><td>; Go again<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>67 ;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>&nbsp;<\/td><td>&nbsp;<\/td><td>68 ; DATA STORAGE<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D061<\/td><td>33<\/td><td>69 STORE:DEFB 51<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td>D062<\/td><td>000000<\/td><td>70 CLKSTR:DEFB 0,0,0<\/td><td>&nbsp;<\/td><td><\/td><\/tr><tr><td>D065<\/td><td>&nbsp;<\/td><td>71 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\u201dCLOCK\u201d,&amp;HD000,A-1\n100 DATA 3E,C3,32,9F,FD,21,0C,D0,21,0C,D0,22,A0,FD,C9,CD\n110 DATA 14,D0,F7,87,9C,77,C9,21,61,D0,7E,3D,77,C0,3E,33\n120 DATA 77,21,62,D0,06,03,7E,3C,27,FE,60,30,03,77,18,05\n130 DATA 36,00,23,10,F1,3A,AF,FC,3D,D0,21,1F,00,CD,53,00\n140 DATA 21,64,D0,06,03,7E,27,F5,CB,3F,CB,3F,CB,3F,CB,3F\n150 DATA C6,30,D3,98,F1,E6,0F,C6,30,D3,98,3E,3A,2B,05,C8\n160 DATA D3,98,18,E1,33,00,00,00,@<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>If you do not have a disk drive, change line 110 to -;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>110 DATA 14,D0,00,00,00,00,C9,21,61,D0,7E,3D,77,C0,3E,33<\/code><\/pre>\n\n\n\n<p>This program displays a clock in the top right hand corner of the screen, but only when the computer is in screen mode zero.&nbsp;&nbsp;The first part of the program fills the Hook HTIMI with a jump command pointing to a routine called CUE.&nbsp;&nbsp;This routine calls all the things that are using this Hook.&nbsp;&nbsp;In this case, just the two things are being called, the clock routine, and the routine to turn the disk drive motor off after a certain period of time.&nbsp;&nbsp;If you are not using a disk drive, set the four memory locations to zero.&nbsp;&nbsp;In later articles, I will detail more routines that use this Hook.<\/p>\n\n\n\n<p>The clock routine starts by decreasing the first counter, which was initially set to 51.&nbsp;&nbsp;This counter is to measure the passing of one second (The Hook is called every 1\/50th&nbsp;of a second).&nbsp;&nbsp;Once a second has passed, the clock counters for the hour, minutes and seconds are updated.&nbsp;&nbsp;Then, if the screen mode is set to zero, the clock will be printed out.<\/p>\n\n\n\n<p>In the next section, I will cover another of the Hook jumps called&nbsp;HGONE, and show how new statements can be added to your Basic programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Written By:&nbsp;Tony Cruise First Published:&nbsp;MSX and Spectravideo Computer Forum Vol. 2 No. 11 \u00a0In this section, I will explain how you attach extra commands to ROM routines. In MSX computers, there are many Hook Jumps provided so that machine code programmers can attach their own routines to most of the basic ROM routines.\u00a0\u00a0Each Hook consists<\/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-360","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\/360","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=360"}],"version-history":[{"count":1,"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/electricadventures.net\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions\/361"}],"wp:attachment":[{"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/electricadventures.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}