home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / apple2 / 17857 < prev    next >
Encoding:
Internet Message Format  |  1992-07-24  |  4.8 KB

  1. Path: sparky!uunet!usc!wupost!waikato.ac.nz!comp.vuw.ac.nz!actrix!David.Empson
  2. Newsgroups: comp.sys.apple2
  3. Subject: Re: PS to mousetext & hyperc
  4. Message-ID: <1992Jul24.134358.3132@actrix.gen.nz>
  5. From: David.Empson@bbs.actrix.gen.nz
  6. Date: Fri, 24 Jul 1992 13:43:58 GMT
  7. Sender: David.Empson@actrix.gen.nz (David Empson)
  8. References: <9207231157.AA10723@aitgw.ge.com>
  9. Organization: Actrix Information Exchange
  10. Lines: 135
  11.  
  12. In article <9207231157.AA10723@aitgw.ge.com> TEFFTA@TSENGR.dnet.ge.com (Andrew Tefft) writes:
  13. >
  14. > [snip]
  15. > The next obvious question is "how can I tell if a character on the screen
  16. > is mousetext?" 
  17. > One would need this if they were going to print a pointer-type mouse cursor,
  18. > since they would need to restore the character they obliterated after moving
  19. > the pointer, and mousetext would probably be used in such displays.
  20. > It seems that there must be some way to preserve the mousetext-ness of
  21. > characters on the screen, since mousetext stays mousetext when the screen
  22. > scrolls... so there must also be some way to query the mousetext-ness
  23. > of a character on the screen, too, no?
  24.  
  25. How do you intend to read characters directly off the screen?  There is
  26. no way to do this using the 80-column firmware.  As far as I know,
  27. you'll have to access the screen yourself.  You'll therefore need a
  28. routine that calculates the address of a screen character, including
  29. handling switching between page 1 and 2 for 80-column mode.
  30.  
  31. The following code is (roughly) how you might implement a mouse cursor
  32. in ORCA/C on the IIgs.  You should be able to adapt this to Hyper C
  33. without much trouble (the screen addressing is identical).
  34.  
  35. E-Mail me if you have any questions. 
  36.  
  37. You may have difficulty understanding open_screen and close_screen
  38. unless you understand how the text screen is addressed.
  39.  
  40. I'm assuming that HyperC will only access a single byte when a
  41. character pointer is dereferenced.  If it always accesses two bytes,
  42. and discards the high byte, then the soft-switch accesses won't work.
  43.  
  44. To use the routines, make an initial call to init_mouse(), then to
  45. show_mouse(), hide_mouse() and move_mouse() as appropriate.
  46. No routines in your own program should call open_screen() or
  47. close_screen(), but other routines may call peek_screen() and
  48. poke_screen().
  49.  
  50. IMPORTANT: make sure the mouse is hidden before you output any text to
  51. the screen (or use an input routine), or it may cause the old
  52. characters to reappear when the mouse moves.
  53.  
  54. Another point: all of these routines deal with X coordinates in the
  55. range 0 to 79 and Y coordinates in the range 0 to 23.  Using X or Y
  56. values outside these ranges could trash memory at random.  Don't try it!
  57. If HyperC normally uses 1 to 80 and 1 to 24, you'll need to make some
  58. changes to these routines.
  59.  
  60. /********************  Mouse cursor handling routines  ****************/
  61.  
  62. static int mouse_visible;    /* TRUE if mouse cursor is on screen */
  63. static int mouse_x, mouse_y;    /* mouse cursor coordinates */
  64. static int oldchar;        /* the character "under" the cursor */
  65.  
  66. /* These four macros define the soft-switches used to control the
  67.    80-column display. */
  68. #define    PAGE1        *((char *)0xC054)
  69. #define    PAGE2        *((char *)0xC055)
  70. #define    ON_80STORE    *((char *)0xC001)
  71. #define    OFF_80STORE    *((char *)0xC000)
  72.  
  73. #define    SCREEN        0x0400
  74.  
  75. static char *open_screen(int x, int y) {
  76.     int base, dummy;
  77.     /* Calculate base address of the line */
  78.     base = SCREEN + (y >> 3) * 0x28 + (y & 7) * 0x80;
  79.     /* Enable 80-column store and select the appropriate page */
  80.     ON_80STORE = 0;        /* Must WRITE */
  81.     if (x & 1)    /* Least significant bit set, i.e. ODD number */
  82.         dummy = PAGE1;    /* odd columns: main memory (page 1) */
  83.     else
  84.         dummy = PAGE2;    /* even columns: aux memory (page 2) */
  85.     /* Return the address of the character */
  86.     return (char *)(base + (y >> 1));
  87. }
  88.  
  89. static void close_screen(void) {
  90.     int dummy;
  91.     dummy = PAGE1;        /* Reselect page 1 (just in case) */
  92.     OFF_80STORE = 0;    /* Turn off 80-column store */
  93. }
  94.  
  95. int peek_screen(int x, int y) {
  96.     int ch;
  97.     ch = *open_screen(x, y);
  98.     close_screen();
  99.     return ch;
  100. }
  101.  
  102. void poke_screen(int x, int y, int ch) {
  103.     *open_screen(x, y) = ch;
  104.     close_screen();
  105. }
  106.  
  107. void hide_mouse(void) {
  108.     if (mouse_visible) {
  109.         poke_screen(mouse_x, mouse_y, oldchar);
  110.         mouse_visible = FALSE;
  111.     }
  112. }
  113.  
  114. void show_mouse(void) {
  115.     if (!mouse_visible) {
  116.         oldchar = peek_screen(mouse_x, mouse_y);
  117.         poke_screen(mouse_x, mouse_y, 0x42);    /* Mouse arrow */
  118.         mouse_visible = TRUE;
  119.     }
  120. }
  121.  
  122. void move_mouse(int x, int y) {
  123.     int old_visible;
  124.     old_visible = mouse_visible;
  125.     if (old_visible)
  126.         hide_mouse();
  127.     mouse_x = x;
  128.     mouse_y = y;
  129.     if (old_visible)
  130.         show_mouse();
  131. }
  132.  
  133. void init_mouse(void) {
  134.     /* I'm assuming you've already initialized the mouse hardware,
  135.        clamping, etc. */
  136.     mouse_visible = FALSE;
  137.     mouse_x = mouse_y = 0;
  138. }
  139. -- 
  140. David Empson
  141.  
  142. Internet: David.Empson@bbs.actrix.gen.nz    EMPSON_D@kosmos.wcc.govt.nz
  143. Snail mail: P.O. Box 27-103, Wellington, New Zealand
  144.