Beyond Basic - Part 2

Downloads|Programming|Beyond Basic

Written By: Tony Cruise

First Published: MSX and Spectravideo Computer Forum Vol. 2 No. 11

 In 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.  Each Hook consists of five memory locations in RAM.  When the computer is first switched on or reset, each of the locations contains the value 201.  This is the decimal value for a RETURN statement in machine code.  Each 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.

To use a Hook, all you have to do is insert your own commands into the five memory locations.  This is usually a JUMP instruction to your machine code routine.

Here is an example program that uses the Hook HTIMI.  This Hook is jumped to every 1/50th of a second.

Machine Code Program

D000 1 ORIGINORG 0D000H 
  2 ;  

  4 ; ON SCREEN 0  
  5 ;  
  7 HTIMIEQU 0FD9FH; Hook Jump – Timer
  8 SCRMODEQU 0FCAFH; RAM Storage – Screen Mode
  9 SETWRTEQU 0053H; ROM Routine – Set Video Write
  10 ;  
D0003EC311 START:LD A,0C3H; Value for JUMP instruction
D002329FFD12LD (HTIMI),A; Load into Hook
D005210CD013LD HL,CUE; Address to jump to
D00822A0FD14LD (HTIMI+1),A; Load into Hook
  16 ;  
D00CCD14D017 CUE:CALL CLOCK; Call CLOCK routine
D00FF718RST 030H; Disk delay routine
D010879C7719DEFB 087H,09CH,077H;-remove if you do not
D013C920 ; have a disk drive
  21 ;  
D014161D022 CLOCK:LD HL,STORE; Decrease counter
D0177E23LD A,(HL);
D0183D24DEC A;
D0197725LD (HL),A;
D01AC026RET NZ; Return if not ZERO
D01B3E3327LD A,51; Set new counter
D01D7728LD (HL),A;
D01E2162D029LD HL,CLKSTR; Update – seconds
D021060330LD B,3;        - minutes
D0237E31 CL1:LD A,(HL);        - hours
D0243C32INC A;
D0252733DAA; Decimal addition
D026FE6934CP 060H;
D028300335JR NC,CL2;
D02A7736LD (HL),A;
D02B180537JR PRTCLK;
D02D360038 CL2:LD (HL),0;
D02F2339INC HL;
D03010F140DJNZ CL1;
D0323AAFFC41 PRTCLK:LD A,(SCRMOD); Get screen mode
D0353D42DEC A;
D036D043RET NC; Check for screen 0
D037211F0044LD HL,31;
D03ACD530045CALL SETWRT; Set screen address
D03D2164D046LD HL,CLKSTR+2; Set pointer to clock
D040060347LD B,3; Set counter
D0427E48 P1:LD A,(HL);
D044F550PUSH AF; Save value
D045CB3F51SRL A; Get right digit
D047CB3F52SRL A;
D049CB3F53SRL A;
D04DC63055ADD A,48; Change to ASCII
D04FD39856OUT (098H),A; Send to screen
D051F157POP AF; Return value
D052E60F58AND 1111B; Get left digit
D054C63059ADD A,48; Change to ASCII
D056D39860OUT (098H),A; Send to screen
D0583E3A61LD A,58; Value for ‘:’
D05A2B62DEC HL; Update pointer
D05B0563DEC B; Update counter
D05CC864RET Z; Return if finished
D05DD39865OUT (098H),A; Send ‘:’ to screen
D05F18E166JR P1; Go again
  67 ;  
D0613369 STORE:DEFB 51  
D06200000070 CLKSTR:DEFB 0,0,0 
D065 71 END:  

Basic Loader


20 READ A$:IF A$ <> “@” THEN POKE A, VAL(“&H”+A$):A=A+1:GOTO 20




60 BSAVE”CLOCK”,&HD000,A-1

100 DATA 3E,C3,32,9F,FD,21,0C,D0,21,0C,D0,22,A0,FD,C9,CD

110 DATA 14,D0,F7,87,9C,77,C9,21,61,D0,7E,3D,77,C0,3E,33

120 DATA 77,21,62,D0,06,03,7E,3C,27,FE,60,30,03,77,18,05

130 DATA 36,00,23,10,F1,3A,AF,FC,3D,D0,21,1F,00,CD,53,00

140 DATA 21,64,D0,06,03,7E,27,F5,CB,3F,CB,3F,CB,3F,CB,3F

150 DATA C6,30,D3,98,F1,E6,0F,C6,30,D3,98,3E,3A,2B,05,C8

160 DATA D3,98,18,E1,33,00,00,00,@

If you do not have a disk drive, change line 110 to -;

110 DATA 14,D0,00,00,00,00,C9,21,61,D0,7E,3D,77,C0,3E,33

This program displays a clock in the top right hand corner of the screen, but only when the computer is in screen mode zero.  The first part of the program fills the Hook HTIMI with a jump command pointing to a routine called CUE.  This routine calls all the things that are using this Hook.  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.  If you are not using a disk drive, set the four memory locations to zero.  In later articles, I will detail more routines that use this Hook.

The clock routine starts by decreasing the first counter, which was initially set to 51.  This counter is to measure the passing of one second (The Hook is called every 1/50th of a second).  Once a second has passed, the clock counters for the hour, minutes and seconds are updated.  Then, if the screen mode is set to zero, the clock will be printed out.

In the next section, I will cover another of the Hook jumps called HGONE, and show how new statements can be added to your Basic programs.