home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 #15 / q15.d81 / t.mousemover < prev    next >
Encoding:
Text File  |  1990-01-01  |  17.4 KB  |  333 lines

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