home *** CD-ROM | disk | FTP | other *** search
/ UpTime Volume 2 #8 / utv2n8s1.d64 / tricks < prev    next >
Text File  |  2022-08-28  |  12KB  |  271 lines

  1. @@
  2.  
  3.  
  4.             Tips & Tricks
  5.  
  6.        Volume Two, Number Eight
  7.  
  8.    Copyright 1989 by Jon Perregaux
  9.          All Rights Reserved
  10.  
  11.  
  12.              Published by
  13.       Softdisk Publishing, Inc.
  14.  
  15.  
  16.  
  17. %cMouse Basics n' Other Stuff
  18.  
  19.      This month we offer some tips for BASIC programmers, a little insight on a little-known CP/M feature and a valuable collection of handy 1351 mouse tips & tricks.
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. 1. DISPOSING NEXT
  28.  
  29.      FOR/NEXT loops have only one drawback: there is no way to abort a loop in progress without leaving it "hanging."  BASIC 7.0 on the C128 uses an EXIT command as a way out for DO/LOOP but no such command exists for FOR/NEXT.  But by its very nature, the FOR/NEXT loop is easy to abort.  Just set the index variable equal to the end-of-loop value and use a single NEXT command to close the loop.  In English, that translates to "make the computer stop counting by telling it it's done counting."  It works rather well and looks something like this:
  30.  
  31. 10 FOR X = 1 TO 10000
  32. 20 PRINT X
  33. 30 GET X$
  34. 40 IF X$<>"" THEN X=10000 : NEXT : PRINT "ABORTED FOR/NEXT LOOP!": END
  35. 50 NEXT : PRINT "LOOP COMPLETE"
  36.  
  37.      Keyboard input is checked in line 40.  If the user presses any key, the loop will be terminated.  The "X=10000 : NEXT" works like an imaginary "DISPOSE NEXT" command.  The loop is immediately stopped.
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. 2. CP/M'S BUILT-IN "KEYFIG"
  48.  
  49.      There is a utility program on the CP/M 3.0 boot disk called KEYFIG.  This nifty program lets you redefine any key on the C128 keyboard to whatever you like: strings of text, control characters, color changes, etc.  It is a little known fact that CP/M 3.0 has a built-in KEYFIG feature that can be used whenever you see the disk drive letter prompt.  Detailed instructions on how to use it can be called up by inserting the CP/M boot disk and typing "HELP KEYFIG FOR{$e4}EXPERTS" at the system prompt.  The underline character is generated by pressing the back-arrow key just below ESC.
  50.  
  51.      The built-in KEYFIG feature allows editing in either string format or hexadecimal.  Keys that may be edited as strings are HELP and the eight function keys.  Strangely enough, the RUN key cannot be redefined with a string as in 128-mode.
  52.  
  53.      The following keys must be pressed in order to enter either of the two editing modes prior to selecting a key to edit:
  54.  
  55. String edit mode:
  56. CONTROL + RIGHT SHIFT + RIGHT ARROW
  57.  
  58. Hexadecimal edit mode:
  59. CONTROL + RIGHT SHIFT + LEFT ARROW
  60.  
  61.      Hexadecimal mode is for changing the character codes generated from the C128 keyboard.  Any key which generates a character or control code may be edited in this fashion.
  62.  
  63.      String edit mode is for the function keys and HELP.  In string edit mode there are ways to insert and delete text and move the cursor left and right.  The methods used are rather clumsy but do work...
  64.  
  65.  
  66. Move cursor left:
  67. CONTROL + RIGHT SHIFT + LEFT ARROW
  68.  
  69. Move cursor right:
  70. CONTROL + RIGHT SHIFT + RIGHT ARROW
  71.  
  72. Insert spaces for text:
  73. CONTROL + RIGHT SHIFT + PLUS KEY
  74.  
  75. Delete characters:
  76. CONTROL + RIGHT SHIFT + MINUS KEY
  77.  
  78. Accept string & return to CP/M prompt:
  79. CONTROL + RIGHT SHIFT + RETURN
  80.  
  81.  
  82. 3. IT'S NOTHING, REALLY
  83.  
  84.      Commodore 128 BASIC handles null strings a little better than C64 BASIC.  Using the ASC() function on an empty string in C64 BASIC will result in an ?ILLEGAL QUANTITY ERROR while C128 BASIC returns a value of 0.
  85.  
  86.      The difference between a null string and an empty string is not often clearly understood.  A null string has a valid character value of zero (as in X$=CHR$(0), for example) while an empty string contains NO characters (X$="").
  87.  
  88.      When retrieving single bytes of data from a disk file using GET# in C64 BASIC, it is necessary to use a special technique in case any zero-byte characters are retrieved.  Because of the way GET# works, zero-byte characters are inputted as empty strings, not CHR$(0)'s.  Line 40 in the following program demonstrates one way to handle empty strings:
  89.  
  90. %c10 OPEN 2,8,2, "0:FILENAME,P,R"
  91. %c20 FOR X = 1 TO 254            
  92. %c30 GET#2, X$                   
  93. %c40 PRINT ASC( X$ + CHR$(0) )   
  94. %c50 NEXT                        
  95. %c60 CLOSE 2                     
  96.  
  97.      With C128 BASIC, the "+CHR$(0)" in line 40 is not needed because of BASIC 7.0's improved ASC() function.  Alternate ways of trapping empty strings are:
  98.  
  99. %c1) X$=X$+CHR$(0)
  100. %c2) IF X$="" THEN X$=CHR$(0)
  101.  
  102.  
  103.  
  104. 4. OF MICE AND MEN
  105.  
  106.      Unlike a joystick, Commodore's 1351 proportional mouse is very difficult to program unless you are a machine language expert.  Realizing that most of us mere humans would have no idea how to use the mouse in our own programs, Commodore provided a useful demo disk with the device.  In true Commodore tradition, though, details on using the mouse are still rather sketchy.  Here are some tips on how to use the mouse drivers provided on the 1351 demo disk.
  107.  
  108.      First of all, let's identify the two files we are most interested in.  The mouse driver designed for use in 64-mode is called "M1351.64.BIN" and loads into memory location 49152 ($C000).  The 128-mode version is called "M1351.128.BIN" and loads into location 6144 ($1800).
  109.  
  110.      The beauty of these particular mouse drivers is that they can support either control port.  Both drivers use sprite #0.  The other seven are undisturbed.
  111.  
  112.      There are a few drawbacks.  The biggest is that there are no programmable boundaries for the moving sprite.  It can be moved completely off-screen; it will even "wrap" around to the other side!  Another drawback is that while the driver is installed, things slow down ever-so-slightly.  This is more noticable on the C128.
  113.  
  114.      Finally, there is no "joystick driver" supplied for performing the same sprite-moving activities as the mouse.  If you want your program to offer a choice to the user in case he/she has no mouse, the routine will have to be written from scratch.  Commodore has provided source code for both drivers on the demo disk, however, and this can be built upon.  The C64 version is saved as "M1351.64.SRC" and the C128 version is called "M1351.128.SRC".  Both are SEQ files and, unfortunately, are not compatible with some assemblers.
  115.  
  116.      To activate the C64 mouse driver, first load it into memory.  In a BASIC program, this can be done like this:
  117.  
  118. %c10 IF X=0 THEN X=1 : LOAD"M1351.64.BIN",8,1
  119.  
  120.      Next, we have to install the mouse driver.  The program hooks into your computer's regular interrupt schedule, which is performed 60 times per second.  So in addition to normal housekeeping tasks, your C64 will also update the position of sprite #0 based on coordinates received from the mouse.  This scheme allows BASIC programs and other routines to run at the same time as the mouse driver.  In a very general sense, your computer will be "multitasking."
  121.  
  122.      The mouse driver wedge has two "kick start" SYS addresses that correspond to each of the two control ports.  You may use either one, although port #2 is recommended because port #1 often interferes with the keyboard.  This is also true on the C128.
  123.  
  124.      To install the mouse driver in control port #1 use:
  125.  
  126. %cSYS 49152
  127.  
  128.      To install the mouse driver in control port #2 use:
  129.  
  130. %cSYS 49155
  131.  
  132.      Once installed, the only way to switch ports is to use the disable feature.  Here it is:
  133.  
  134. %cSYS 49158
  135.  
  136.      This shuts off the mouse driver, leaving sprite #0 hanging motionless on the screen.  When the mouse driver is disabled, it can be restarted again with either of the two SYS enable commands.
  137.  
  138.      The mouse driver does NOT automatically turn on sprite #0.  This must be done by your program.  Use this command to turn on sprite #0 without affecting the others:
  139.  
  140. %cPOKE 53269, PEEK (53269) OR 1
  141.  
  142.      Conversely, to turn off sprite #0 without affecting the others use:
  143.  
  144. %cPOKE 53269, PEEK (53269) AND 254
  145.  
  146.      In 128-mode, things are only slightly different.  In a BASIC program, load the mouse driver file into BANK 0 memory with this command:
  147.  
  148. %c10 BLOAD "M1351.128.BIN",B0
  149.  
  150.      Once loaded, the driver may be installed in one of two ways.
  151.  
  152.      To install the mouse driver in control port #1 use:
  153.  
  154. %cSYS 6144
  155.  
  156.      To install the mouse driver in control port #2 use:
  157.  
  158. %cSYS 6147
  159.  
  160.      To disable the mouse driver