home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 #32 / q32side2.d64 / t.mouse80 < prev    next >
Encoding:
Text File  |  1992-01-01  |  16.4 KB  |  317 lines

  1.  
  2.  
  3.                               M O U S E    8 0
  4.  
  5.                     Program and Text by Maurice Randall
  6.  
  7.  
  8.      MOUSE 80 is a device driver for the Commodore 1351 mouse or
  9. compatibles.  It is designed to be used with the 128 in 80 column 'text
  10. mode' only.  This driver will fill a void that most people do not realize
  11. existed.  The 1351 mouse has been around for a while now, and there are
  12. mouse drivers for it.  The demo disk that comes with the mouse has an
  13. assortment of drivers for the 64 mode and the 128 mode, but the 128 mode
  14. driver is only for 40-column use.  It makes use of a sprite for the pointer
  15. that is visible on the screen.  Sprites are not available on the 80-column
  16. screen.  Sprites are easily simulated on the 128's 80-column graphic
  17. screen, but then you are limited to creating 'graphic text'.  GEOS works
  18. this way, and GEOS is an excellent system, but there is still a need for
  19. applications written to use the 128's native text mode.
  20.  
  21.      What makes this driver different is the fact that it moves the pointer
  22. about the text screen smoothly.  There have been other mouse drivers for
  23. the 80-column text screen, but these move the mouse pointer around the
  24. screen a full character at a time.  They work fine, but the smoothness of
  25. movement isn't there.  The only smooth mouse pointer I'm aware of for the
  26. 128 is incorporated into the Pocket Series software from Digital Solutions.
  27. But their mouse routines are not available to the public.  Therefore, I
  28. have designed MOUSE 80 so that other software developers might make use of
  29. the 1351 mouse with a smooth moving pointer in their programs.  Any new
  30. development for the 128 should definitely make use of the new hardware that
  31. is available, and MOUSE 80 will help give a more professional appearance to
  32. the program.
  33.  
  34.      MOUSE 80 can be used with a BASIC or ML program.  It uses a jump table
  35. to call its routines and you can also read or change various variables that
  36. are used by MOUSE 80.
  37.  
  38.      To use MOUSE 80, you would include the following statement in a BASIC
  39. loader:
  40.  
  41.  bload"mouse80.o"onu(dv)      where dv is the current drive number
  42.  
  43.  NOTE: For card games use "c80c-mouse.2300" and set MO = 8960.
  44.  
  45.      Once your main program begins, you can use the various jump addresses
  46. and variables locations to initially install the mouse wedge into the IRQ
  47. interrupt sequence, turn the mouse pointer on and off, or to find or set
  48. the pointer on the screen.  You can locate the pointer according to its
  49. pixel location.  You can also confine the mouse to a defined region or
  50. 'window'.  You can tell if either button is being pressed.  You can also
  51. instruct MOUSE 80 to set up a jump address for the application to call if
  52. one of the buttons is pressed.
  53.  
  54.      If you don't like the looks of the mouse pointer, you can change its
  55. appearance by altering the eight bytes that make up its picture.
  56.  
  57.      There are four graphic characters from the upper/lower case set that
  58. are used by MOUSE 80.  If you need to use these characters, you can choose
  59. any other four characters instead.  It would be a very rare program that
  60. would have to use each of the 512 characters that are available.
  61.  
  62.      Whenever you are accessing the screen, you should 'hide' the mouse
  63. pointer to prevent garbage from appearing on the screen.  The 80-column VDC
  64. chip is very touchy, and does not like the mouse when the screen is
  65. scrolling, or if you are typing characters into the same location that the
  66. mouse is occupying.  So, just call 'HIDEMOUS' before any screen access and
  67. call 'SHOWMOUS' when finished.  When the mouse is hidden, the pointer is
  68. not displayed, but movement is still possible.  So, you could use this to
  69. your advantage for various things such as menus.  As the mouse is moved up
  70. and down, you could highlight the menu item that is being pointed at, much
  71. like what is usually done with the CRSR keys.  If you call the routine,
  72. 'STOPMOUS', then the pointer is not only hidden, but its location also is
  73. not updated.  It will remain frozen in the spot it was in when the routine
  74. was called.  The buttons are still active so that you can still check for
  75. either button being pressed.  Either 'SHOWMOUS' or 'HIDEMOUS' will then
  76. make the mouse active again.  'HIDEMOUS' will leave the pointer hidden.
  77.  
  78.      The following is a list of available routines and variables along with
  79. their locations in memory:
  80.  
  81.  Name      BASIC          Description
  82.  ------------------------------------------------------
  83.  
  84.  INSTALL   MO+0       Initially installs the mouse wedge
  85.  REMOVE    MO+3       Removes mouse wedge from the system.
  86.  HIDEMOUS  MO+6       Hides the pointer from view.
  87.  SHOWMOUS  MO+9       Displays the pointer on the screen.
  88.  STOPMOUS  MO+12      Stops the mouse and hides it.
  89.  CKSTATUS  MO+15      Check location of mouse on screen.
  90.  USERJUMP  MO+18      User callable according to buttons.
  91.  
  92. (Locations $1315-$1317 are not used.  They are reserved for future use.)
  93.  
  94.      There are a number of variables that may be read or set.  Here is a
  95. listing of those variables, their location offset in relation to the
  96. starting address and a brief description.
  97.  
  98. The following bytes define the region in which to confine the mouse
  99. pointer. The default settings are for the entire screen.
  100.  
  101.  LTXLIMIT         +24,25         Left border (lsb,msb) (0-319)
  102.  UPYLIMIT         +26            Upper border (0-199)
  103.  RTXLIMIT         +27,28         Right border (lsb,msb) (0-319)
  104.  LOYLIMIT         +29            Lower border (0-199)
  105.  
  106. The following locations define the present location of the mouse.  These
  107. are best checked by machine language.  When using BASIC, the mouse could
  108. move between the time it takes to check the X position and the Y position.
  109.  
  110.  XCHAR            +30            Column location of the mouse.
  111.  YCHAR            +31            Row location of the mouse.
  112.  CXPOS            +32,33         Horizontal pixel location of the mouse.
  113.  CYPOS            +34            Vertical pixel location of the mouse
  114.  
  115. From BASIC, (or ML) you could check these locations after accessing the
  116. routine called 'CKSTATUS'.  The exact location of the mouse when 'CKSTATUS'
  117. is accessed is saved here until the next time the routine is accessed.
  118.  
  119.  BXCHAR           +35            Column location.
  120.  BYCHAR           +36            Row location.
  121.  BCXPOS           +37,38         Horizontal pixel location.
  122.  BCYPOS           +39            Vertical pixel location.
  123.  
  124. These next two locations may be set in order to place the mouse pointer at
  125. a specific location on the screen.  'SETXPOS' should be set to a two-byte
  126. value ranging from 0-319, and 'SETYPOS' should be 0-199.  Always POKE the
  127. value into SETXPOS+1 last, because after MOUSE 80 checks these bytes, bit 7
  128. of SETXPOS+1 will be set which makes MOUSE 80 ignore these values.  If you
  129. were to set this location before the other three (from BASIC), they would
  130. most likely be read before you are done setting the other bytes and so the
  131. mouse would not be placed in the desired location.  From machine language,
  132. it is not a problem since you can disable the interrupts first.
  133.  
  134.  SETXPOS          +40,41         Place pointer at this X location.
  135.  SETYPOS          +42            Place pointer at this Y location.
  136.  LTBUTTON         +43            Current status of left button.
  137.  RTBUTTON         +44            Current status of right button.
  138.  LTCHECK          +45            Latched status of left button.
  139.  RTCHECK          +46            Latched status of right button.
  140.  
  141. These next four bytes are used as user defined addresses that may be called
  142. in machine language whenever a button is pressed.  They are described in
  143. better detail later.
  144.  
  145.  LTADDR           +47,48         Address for left button.
  146.  RTADDR           +49,50         Address for right button.
  147.  LTINT            +51,52         Interrupt address.
  148.  RTINT            +53,54         Interrupt address.
  149.  
  150.  MSEPORT          +55            Active joystick port (1 or 2)
  151.  MOUSEPIC         +56-63         This is the picture of the pointer.
  152.  
  153. These next four bytes designate the screencodes of the characters that will
  154. be used for the mouse pointer.  You may use the default characters or
  155. change these bytes to select different characters.  If you should happen to
  156. use a character that is displayed elsewhere on the screen, then the mouse
  157. pointer will appear at that location also.  This may not be too desirable,
  158. but could possibly be used for a special effect.
  159.  
  160.  ULCORNER         +64            Character that is used for upper left.
  161.                                     (Default is ASCII 113)
  162.  URCORNER         +65            Character that is used for upper right.
  163.                                     (Default is ASCII 114)
  164.  LLCORNER         +66            Character that is used for lower left.
  165.                                     (Default is ASCII 115)
  166.  LRCORNER         +67            Character that is used for lower right.
  167.                                     (Default is ASCII 116)
  168.  
  169. And these four bytes are the attribute bytes for the characters that are to
  170. be redefined.  The default setting for each one is $80, which would select
  171. the character from the upper/lower case set.  Set the locations to $00 if
  172. you wish to use characters from the uppercase/graphics set.
  173.  
  174.  ULMSATTR         +68            Attribute byte for upper left.
  175.  URMSATTR         +69            Attribute byte for upper right.
  176.  LLMSATTR         +70            Attribute byte for lower left.
  177.  LRMSATTR         +71            Attribute byte for lower right.
  178.  
  179.  
  180.      The mouse picture located at 'MOUSEPIC' is made up of eight bytes.
  181. These eight bytes and their values look like this:
  182.  
  183.  BYTE     BINARY      HEXADECIMAL  DECIMAL
  184.  -------------------------------------------
  185.  byte 0   11000000    $C0          192
  186.  byte 1   11111000    $F8          248
  187.  byte 2   11111110    $FE          254
  188.  byte 3   11111000    $F8          248
  189.  byte 4   10011100    $9C          156
  190.  byte 5   00001110    $0E           14
  191.  byte 6   00000111    $07            7
  192.  byte 7   00000000    $00            0
  193.  
  194.      If you study the 'ones' in the binary representation, you will see the
  195. picture of the mouse.  By changing these eight bytes, you can change the
  196. appearance of the mouse pointer.
  197.  
  198.      One thing to keep in mind whenever you are making reference to the
  199. mouse location in the horizontal axis, is that the mouse is moved two
  200. pixels at a time, horizontally.  Even though there are 640 pixels on the X-
  201. axis, the mouse will be referenced at points ranging from 0 to 319.  So, if
  202. the mouse is at location 100, it is actually sitting at pixel 200 on the
  203. screen.
  204.  
  205.      You can have MOUSE 80 set up a user callable jump address in the jump
  206. table according to the values placed at LTADDR and RTADDR.  For instance,
  207. if you place a two-byte value at LTADDR, it will be transferred to MOUSE
  208. 80's jump table at MO+18 whenever the left button is pressed.   You may
  209. then JSR MO+18 to your own routine.   If you place a two-byte address at
  210. LTINT, then that address will be called by MOUSE 80 during the interrupt
  211. sequence whenever the left button is pressed.  The address at MO+18 is not
  212. affected by the setting at LTINT.  LTINT is transferred to an internal
  213. location within MOUSE 80.  MOUSE 80 calls this routine for you whenever the
  214. button is pressed.  To block either of these features, simply zero out the
  215. locations.  The same idea applies for RTADDR and RTINT and the right
  216. button.  By using this feature, you never have to check the status of the
  217. buttons yourself.
  218.  
  219.      If you do need to check the buttons, there is more than one way to do
  220. it.  You can test the location at 'LTBUTTON'.  If bit 7 is set or if the
  221. location contains any value greater than 127, then this means that the left
  222. button is being pressed.  If the location contains any value greater than
  223. zero, then the button was pressed sometime during the last eight interrupt
  224. sequences.  Bit 7 always represents the button's status for the most recent
  225. interrupt, bit 6 for the previous one and so forth on down to bit 0.  So,
  226. if bit 3 at 'LTBUTTON' is 'off', then the left button was not pressed 5
  227. interrupts ago.  By allowing you to read the status of the button for a
  228. period of eight interrupts, you might be able to catch a button press even
  229. after the user lets up on the button.  'RTBUTTON' contains the status for
  230. the right button.
  231.  
  232.  
  233.      For the curious, here is how MOUSE 80 works.  It is really quite
  234. simple when you think about it.  First of all, the 80-column text screen is
  235. just that, a text screen.  Graphics are not possible, which means that we
  236. cannot address individual pixel locations.  We have to address character
  237. locations, so we are limited to displaying objects (or characters) in a
  238. matrix that is 80 columns wide and 25 rows high.  So, whenever you see what
  239. looks like graphics on the text screen, you are seeing either the graphic
  240. characters that Commodore has provided us or you are seeing redefined
  241. characters that are being displayed about the screen. MOUSE 80 uses four
  242. redefined characters and so it actually occupies four character locations
  243. on the screen at all times.  The four locations are always attached to each
  244. other in a matrix that is two characters wide and two characters high.
  245. Reference is always made to the upper left character.  For instance, if the
  246. mouse is located at column 0 and row 0, it is occupying the following four
  247. locations:
  248.  
  249.  column 0, row 0 column 0, row 1 column 1, row 0 column 1, row 1
  250.  
  251.      Now, to get the mouse displayed on the screen, MOUSE 80 creates its
  252. own little bitmap in memory.  Once it knows where it is located on the
  253. screen, it then determines where within this bitmap that it should be
  254. located.  For instance, if the mouse is at the upper left of the screen, it
  255. would be at column 0 and row 0.  Let's say that the actual pixel location
  256. of the mouse is at pixel 3 horizontally and pixel 5 vertically. These
  257. locations fall within the upper left character location of the screen.  Now
  258. we draw the mouse pointer in our own little bitmap at position 3 on the X
  259. axis and position 5 on the Y axis.  The bitmap is 16 pixels by 16 pixels
  260. but we keep the entire mouse picture within the bitmap and we keep the
  261. upper left pixel of the mouse within the upper left quarter of the bitmap.
  262. This means that the X coordinate can be from 0-7 and the Y coordinate can
  263. be from 0-6. (Remember, the x coordinates move two pixels at a time).
  264.  
  265.      Now that we have drawn the mouse into the bitmap, it is time to fetch
  266. the character definitions from the four locations that the  mouse is
  267. occupying on the screen.  First the character from column 0, row 0 is
  268. fetched and drawn to the upper left quarter of the bitmap.  Each bit when
  269. drawn is actually EOR'D with the picture of the mouse.  The remaining three
  270. characters are then drawn in the other three quarters of the bitmap in the
  271. same manner.  By Exclusive ORing each bit with the mouse picture, the mouse
  272. and the character are each visible.  If bits that are 'on' are overlapping
  273. each other, then the bits will be 'off'.  This makes the mouse visible if
  274. the character it passes over should be a solid block.
  275.  
  276.      Now that our little bitmap is completely drawn, we send each quarter
  277. of it to the four different character definitions that MOUSE 80 uses for
  278. its pointer.  Then it is drawn to the screen by sending those four
  279. characters to the screen.  Each time the mouse moves, this bitmap is
  280. redrawn.  So the effect of a smooth moving mouse is not through the use of
  281. sprites or graphics, but actually through the use of four redefined
  282. characters.
  283.  
  284.      This is why you must call 'HIDEMOUS' or 'STOPMOUS' before any screen
  285. access in the area that the pointer is, or if the entire screen is going to
  286. scroll.  These routines will remove the mouse picture from the screen, and
  287. replace the actual characters that should be residing in the four locations
  288. of the screen where the mouse is.
  289.  
  290.  Things to remember:
  291.  
  292. * Call 'INSTALL' to initially install the mouse.  'INSTALL' initializes
  293. numerous variables, so you must set any desired variables after this call.
  294. 'INSTALL' leaves the mouse in a frozen and hidden state.
  295.  
  296. * Call 'SHOWMOUS' to make the pointer visible and active.
  297.  
  298. * Call 'HIDEMOUS' or 'STOPMOUS' during any screen activity in the area of
  299. the mouse.
  300.  
  301. * 'HIDEMOUS' leaves the mouse active, but makes it invisible.
  302.  
  303. * 'STOPMOUS' makes the mouse invisible and also freezes its position.
  304.  
  305. * 'X' coordinates range from 0-319 because the mouse is moved two pixels at
  306. a time horizontally.
  307.  
  308. * Call 'REMOVE' to remove MOUSE 80 from the IRQ sequence before ending your
  309. application.  'REMOVE' calls 'STOPMOUS' and then resets the IRQ vector to
  310. its original state.
  311.  
  312.      MOUSE 80 should open up a whole new avenue of professional appearing
  313. applications for the 128.
  314.  
  315.                           \\\\\ RETURN - Menu \\\\\
  316.  
  317.