Link to editorial & letters    Link to files
Previous disk program notes    Next disk program notes


Title SCREEN$

Disk 22 program notes


                  MACHINE CODE ROUTINES GALORE!                 
                       BY MICHAEL NICHOLAS                      
                                                                
Machine routines can be very useful where  complex  and  lengthy
operations are required. The SAM has  a  superb  basic,  but  is
limited to some extent  by  the  speed  at  which  routines  are
executed. A Machine code routine can be over 8000 times  quicker
than the same routine done in basic.                            
                                                                
Now and again over the past  few  years,  I  have  attempted  to
program some routines in machine code, but haven't got  many  of
them to work, mainly because I havn't set the correct paremeters
and conditions for the routines to work in.                     
                                                                
Here are some simple, yet useful routines which I have done in  
the past few months.                                            
                                                                
Some detailed source is included, to show how they work and to  
show you how simple they are.                                   
                                                                
The machine code routines have basic drivers to  accompany  them
and they are called by using the DEFined PROCedures. The defined
procedures can be merged into your programs.                    
                                                                
CAPITALISING A STRING OR AN AREA IN MEMORY                      
                                                                
COMMAND: CAP 0 : CAPITALISES THE STRING CALLED "SUBJECT$"       
       :                                                        
     OR: CAP 1,MEMORY LOCATION,LENGTH OF AREA TO CAPIALISE      
                                                                
                                                                
EXPLANATION                                                     
                                                                
The "CAP"  command  can  work  in  two  modes,  the  first  mode
capitalises the string SUBJECT$, this string  should  be  filled
with the sentences/words you wish to put into  upper  case.  The
"SUBJECT$"string musn't be more than 31000 bytes long, otherwise
the routine won't operate.                                      
                                                                
                                                                
The second mode capitalises an area in memory which is specified
by you. The LOCATION can be anywhere you like and the characters
from this memory  location  are  all  put  into  uppercase.  The
amount/LENGTH of memory you want to capitalise is determined  by
you and can be upto 31000 bytes.                                
                                                                
APPLICATIONS                                                    
                                                                
Could be useful when searching memory  for  a  word.  The  INSTR
command searches memory for a  word  specified  by  you,  inside
another string, but the command only gives a result if the  word
is exactly the same as the one it is looking for. i.e upper case
and lower case letters must be the same etc. If you  capitalised
the string first then you wouldn't have  this  problem  and  so,
therefore, have a more successful search.                       
                                                                
                                                                
                                                                
                                                                
                                                                
UNCAPITALISING A STRING OR AN AREA OF MEMORY                    
COMMAND: UNCAP 0 : Uncapitalises the string "SUBJECT$"          
       :                                                        
     OR: UNCAP 1,MEMORY LOCATION,LENGTH OF AREA TO UNCAPITALISE 
                                                                
                                                                
EXPLANATION                                                     
                                                                
Works the same way as the CAP command, the applications are much
the same.                                                       
                                                                
                                                                
COUNTING THE WORDS IN A STRING OR AN AREA OF MEMORY             
                                                                
COMMAND: COUNT 0 : Counts the number of words in "SUBJECT$"     
       :                                                        
     OR: COUNT 1,MEMORY LOCATION, LENGTH OF AREA TO COUNT       
                                                                
                                                                
                                                                
EXPLANATION                                                     
This little routine has it's own word counter and each time  the
routine detects  a  space/character  32  and  then  a  different
character, it adds one to it's counter.                         
                                                                
At the end of the routine the defined procedure reads the       
machine codes counter and gives the result in the variable      
called "RESULT".                                                
                                                                
Again this routine has two modes of operation and that's  either
searching the string "SUBJECT$" (MODE 0) or an  area  of  memory
(MODE 1).                                                       
                                                                
APPLICATIONS                                                    
                                                                
Have you ever had to write an essay for  school  and  it's  said
something like 500 words minimum, well this routine  could  save
you from counting each and every word. I'm sure there  are  lots
of other applications but this routine was made specifically for
a word processor.                                               
LAST CHARACTER IN A STRING OR AN AREA IN MEMORY                 
                                                                
COMMAND: LAST 0 ( you guessed it!)                              
       :                                                        
     OR: LAST 1,MEMORY LOCATION,LENGTH OF MEMORY TO SEARCH      
                                                                
EXPLANATION                                                     
                                                                
This routine is probably the fastest out of all the  routines  I
have written. It tells you the LAST character it detected during
the search through the whole area of memory or  string  contents
you specified.                                                  
                                                                
It treats everything as a character except character 32.        
                                                                
The result is given in the variable "RESULT"  when  the  routine
has finished it's search.                                       
                                                                
                                                                
                                                                
APPLICATIONS                                                    
                                                                
Could prove useful where you have a word processor and you  need
to know the last line to print or the number of pages to print. 
                                                                
                                                                
NOTES:                                                          
                                                                
Don't forget to type in LOADMC before using the  routines.  This
defined procedure puts the machine code routines into the memory
location PAGE*16384 - PAGE being a variable in LOAMDMC. You  can
alter PAGE to your requirements if you wish,  though  make  sure
you don't overwrite any ROM,RAM,SCREEN,DOS,MDOS,MBASIC pages.   
                                                                
The SAM basic command called LENGTH could prove very useful when
using these routines. It finds the location of a string  in  the
memory and can tell you the length of  the  entire  string.  The
USER manual doesn't explain this command very well  so  I  shall
explain:                                                        
                                                                
PRINT LENGTH (0,string$() : Where string$ is in the memory.     
PRINT LENGTH (2,string$() : The length of the second part of    
                            the dimenstion of STRING$.          
                                                                
PRINT LENGTH (1,string$)  : The length of the first part of the 
                            dimension of STRING$.               
                                                                
EXAMPLES:                                                       
                                                                
Using length with the CAP command:                              
                                                                
                                                                
LET A$="hELLo evEryBOdY"                                        
LET A=LENGTH (0,A$)  ; FIND LOCATION                            
LET B=LENGTH (1,A$)  ; FIND DIMENSIONS                          
LET C=LENGTH (2,A$)  ;                                          
CAP 1,A,(B*C)        ; CAPITALISE                               
                                                                
NB: USING LENGTH SAVES YOU FROM CREATING ANOTHER STRING         
                                                                
EXAMPLE2: Same as above example but without using LENGTH        
          This is more memory wasteful because another string   
          called SUBJECT$ is created.                           
                                                                
LET A$="heLLo evEryBOdY"   ; get the string you want            
LET SUBJECT$=A$            ; Put it into SUBJECT$               
CAP 0                      ; Capitalise SUBJECT$                
LET A$=SUBJECT$            ; Put capitalised version            
                             of A$ back into A$.                
Thats yer lot, I hope some other people can contribute  to  this
area in SAM programming. Who needs to buy  uttilities  when  you
can make programs and tailor them to your own requirements!     
----------------------------------------------------------------
                                                                
THE WORM  by John McCabe                                        
A variation on the "CENTIPEDE" game, showing just how  fast  Sam
BASIC can run. I particularly like the way the worm turns  in  a
circle and not in the normal right angled way. Full instructions
are given in the program.                                       
----------------------------------------------------------------
INVESTIGATIONS by Ron Fox                                       
An unusual article with examples, on how a computer can be  used
for problem solving. If anyone else has delved into this area of
computing I'm sure that both Ron and the mag would like to  hear
from you.                                                       
----------------------------------------------------------------
                                                                
CROSSWORD by D.A.Lorner                                         
These are becoming a regular feature of  the  mag.  This  is  no
easier than previous ones published, but it gave me an hour or 2
of pleasure. I like the option of having the answers  built  in.
which saves having to wait a month  to  find  out  if  you  were
right!!                                                         
----------------------------------------------------------------
                                                                
D.T.P. FONT by Dave Ison                                        
Dave has used the font designer published in Format and modified
to run on the Sam, to create a new headliner font for P.C.G's   
D.T.P. package, and very nice it is too.                        
----------------------------------------------------------------
DIZZY MAPS by Bob Evans                                         
This month there are no pokes or tips in Bobs section.  This  is
because I thought that I would let you see  all  the  hard  work
that Bob has put into mapping out  the  Dizzy  games.  I  should
think that every Dizzy game ever produced is included.          
                                                                
----------------------------------------------------------------
                                                                
DISC CHECK by Keith Pirie                                       
This one only works with masterbasic installed, but it  is  well
worth it. It gives you an instant view of the current  state  of
your discs, and is very easy to use.                            
                                                                
----------------------------------------------------------------
                                                                
PRIMES by Mike Haine                                            
Another unusual program which deals with prime numbers and their
frquency of occurence.                                          
There is a nice program which shows  graphically  the  differing
ressults given for different groups of numbers.                 
BLACKJACK by Gordon Henderson                                   
A good version of PONTOON, which uses a nice set  of  cards  and
plays well.                                                     
Gordon told me that there was a bug that occasionally  gave  the
same card twice, and he couldn't cure it. I  think  that  I  may
have done, but if after playing you still find  it  there,  both
Gordon and I would like to hear from you with solutions.        
What I did was to put the card  count  variable  into  the  card
printing routine. This means that every time a card is dealt  to
either you or the computer, the card count is  updated. I  think
this has cured the bug, but I may be wrong.                     
                                                                
----------------------------------------------------------------
                                                                
GALLERY by Noel Hathorn                                         
An unusal gallery this issue, in as much  as  all  the  pictures
were done by the same person. I thought that they  were  16  bit
"ports", but I am assured that Noel did them all from scratch.  
----------------------------------------------------------------
                                                                
MUSIC by John Hutchings                                         
John has been playing with the sound machine, and come  up  with
these well known  tunes  (well  all  except  number  2  which  I
couldn't name).                                                 
They are stored on the disc in a compressed form so to use  them
do the following:-                                              
                                                                
1) Load the tune from the menu                                  
2) Press ESC and then "STOPM" plus return                       
3) Save the full code with SAVE "name" CODE 81920,49352         
This will give you a standard Sound Machine file.               
                                                                
----------------------------------------------------------------
                                                                
CONVERT by M.Nicholas                                           
This is one of those programs that you think you will never use,
until you use it. It converts just about  any  imperial  measure
into metric and vice versa.                                     
It's menu driven and very quick and easy to use.                
----------------------------------------------------------------
LEAPING LETTERS by Robin Smith                                  
A couple of DEF PROCs to allow you to add the  little  extra  to
your programs. It puts your message onto the  screen  either  by
shooting the characters up the screen or dropping them down.    
                                                                
Use them as follows:-                                           
LEAP X,Y,X1,A$                                                  
                                                                
X AND Y ARE  THE  START  POSITIONS  OF  YOUR  MESSAGE  IN  PRINT
POSITIONS. X CAN BE UP TO 20, Y 0 TO 31                         
                                                                
X1 IS THE ROW THAT YOU WANT YOUR MESSAGE TO FINISH ON           
                                                                
A$ IS YOUR MESSAGE                                              
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
E.G. If you wanted the message "Hello  Everyone"  to  come  from
line 18 starting at position 3 along and end up on  line  4  you
would put:-                                                     
           LEAP 18,3,4,"Hello Everyone"                         
The PROC FALL works in the same way except that x1 will be lower
that x, because the message falls down the screen.              
If the string is longer than the screen, it  will  automatically
be wrapped around to the start of the next line.                
                                                                
                                                                
-------------------------------E N D----------------------------
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
.                                                               

Link to the top of this document    Link to the main index
Link to editorial & letters    Link to files
Previous disk program notes    Next disk program notes