home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / tech / graphics.txt < prev    next >
Text File  |  1985-04-15  |  11KB  |  286 lines

  1. - -------------------------------------------------------------------------
  2. The Macintosh Standard Graphics Protocol
  3. ----------------------------------------
  4. By Scott Watson (CompuServe 73176,61)
  5.  
  6.  
  7.  
  8. The Macintosh Standard Graphics Protocol is an attempt to standardize (or
  9. at least provide a common subset of functions) the rapidly growing desire
  10. to send QuickDraw graphics over a modem.  This protocol has been con-
  11. structed with several essential properties in mind:
  12.  
  13. 1) It must give access to the most frequently used QuickDraw routines.
  14. 2) It must have the least amount of overhead necessary to reduce the lag
  15.    between transmission and actual display on the user's terminal.
  16. 3) It must be error checked and acknowledged by the recipient to prevent
  17.    a line spike from causing a system crash due to execution of QuickDraw
  18.    routines with erroneously received parameters.
  19. 4) It must be easily implemented in any communications program, must not
  20.    be language specific (as long as the QuickDraw routines used are
  21.    accessable through a given language), and it must be small enough to
  22.    be constructed as an unloadable segment for when it's not in use.
  23. 5) It must be completely transparent to the user (no confusing "options"
  24.    or necessary commands for the user to become entangled with), and must
  25.    be completely controllable by the host.
  26. 6) It must allow transmission of the user's mouse cursor when the mouse
  27.    button is pressed to allow 2-way real time graphics functions.
  28. 7) There must be no need to document the protocol in your users' manual.
  29.  
  30.  
  31. Acceptance of this standard will ensure that your program will be
  32. compatible with the other programs that have adopted this standard, and
  33. will work with the Lazarus BBS program soon to be released from The
  34. FreeSoft Company.  This program will appear as a local Macintosh appli-
  35. cation (mouse buttons, graphics, animation, dialog boxes, etc.) to the
  36. user of your program once connected.  To foster the acceptance of this
  37. graphics standard, we will distribute the BBS program at low or no cost,
  38. provide a debugging host to those trying to implement this protocol,
  39. and make this standard public domain.
  40.  
  41. Although it is a public domain protocol, I would feel grateful if you
  42. would make mention of me as the creator of the protocol in your users'
  43. manual should you make mention of it.
  44.  
  45.  
  46. Overview
  47. --------
  48. Throughout these specs, we will refer to two different machines, the host
  49. is the computer running a BBS or similar program.  The remote is the 
  50. computer running your communications program.  All numbers are given
  51. in decimal.
  52.  
  53. In a TTY or other textual information mode, the remote should constantly
  54. trap the receipt of an ASCII code 26.  Once this occurs, you need to trap
  55. for the following characters in order: 16,04, and 12.  These are called
  56. the signiture bytes.  When you receive these bytes in that order, you are
  57. to immediately enter the graphics mode and send out a Type 45 packet
  58. (Acknowledge Graphics On).  If you don't receive the above sequence within
  59. three seconds of receiving the ASCII code 26, consider the 26 to be a
  60. fluke and return to your textual processing.
  61.  
  62. The host should ensure that there has been at least 1 second of silence
  63. on the line before sending the signiture bytes.
  64.  
  65. What Happens When You Enter The Graphics Mode
  66. ---------------------------------------------
  67. There is only one flag you need to keep track of while in the graphics
  68. mode - whether or not the host wants to allow the remote to send Type
  69. 49 packets (MouseDown Report).  When you initially enter the graphics
  70. mode, this flag is reset so that MouseDown events are not reported over
  71. the modem.
  72.  
  73. Updates are not allowed either, so it is imperative that you disable any
  74. menu choices or other actions that would botch the display while in the
  75. graphics mode.  Actually, you are given a great deal of freedom of what
  76. you can do while in the graphics mode, as long as you are capable of
  77. restoring the screen yourself after it's been botched by a Desk Accessory
  78. or other function.
  79.  
  80. There is a failsafe in case the remote should lose carrier while in the
  81. graphics mode.  Your program should look for the user to type COMMAND-X,
  82. and exit the graphics mode if it is in operation.  It's recommended that
  83. you don't document this, rather, let the host do it immediately upon
  84. receiving the Type 45 packet from the remote.  Since the host can cause
  85. your program to jump back and forth between the graphics and textual
  86. modes, you don't lose any of the capabilities of your software, such as
  87. file transfers, desk accessories, etc. that would otherwise botch the
  88. screen.
  89.  
  90. Upon entering the graphics mode, you should display a type 1 (modal
  91. dialog or alert appearance) style window using the rectangle:
  92. 30,10,330,503.  This window takes up nearly all of the screen below the
  93. menu bar, cannot be moved, removed, or sized through user mouse control.
  94. In other words, it's awfully hard to screw up as long as you pay attention
  95. to the above requirements.  The above rectangle is important as M.S.G.P.
  96. commands are assumed to operate in that area only.
  97.  
  98. There is an exception to the above.  The command types between 100
  99. and 255 are reserved for your use.  If you have special needs for the
  100. graphics mode, such as setting up a MacPaint-type drawing interface, you
  101. could use one of the special commands to set up the window using different
  102. coordinates, leaving room for tools and other information.  However, when
  103. your program is a remote, it has to have the ability to use the above
  104. coordinates as a default.
  105.  
  106. Now we've entered the graphics mode, drawn our window, and sent back the
  107. Type 45 packet.  What's next?
  108.  
  109. Data Flow
  110. ---------
  111. Data flow is nothing more than an exchange of packets and acknowledgements,
  112. much like the XMODEM protocol.  However, since this is an interactive
  113. mode, there is no timeouts waiting for the next packet, and packet exchange
  114. is actually in two directions.
  115.  
  116. A packet is variable length, and is in the following general format:
  117.  
  118. SOP/LEN/COM/DAT/DAT/DAT/DAT.../CHK
  119.  
  120. SOP - Start of packet byte (arbitrarily set as ASCII code 3)  The remote
  121. continually looks for an ASCII 3, and can assume any other characters are
  122. line spikes.
  123.  
  124. LEN - The number of bytes following, not including the checksum.
  125.  
  126. COM - The packet command type (these are numbered from 1 to 50 and are
  127. explained below.
  128.  
  129. DAT - The data, which will be used as the parameters for the command.
  130.  
  131. CHK - The checksum, which is the sum of the LEN, COM and DAT bytes,
  132. logically ANDed with 127.
  133.  
  134. After receiving a complete packet, the remote should send either an
  135. ACK (ASCII code 6) if the checksum matches, or a NAK (ASCII code 21) if
  136. it doesn't.  You should set a timeout of 3 seconds to receive the full
  137. packet once the SOP has been received, and then automatically NAK the
  138. packet if it never comes through.  You send the ACK after the command is
  139. actually executed, to allow further parameter error checking if desired.
  140.  
  141. The host will continue to re-send NAKed packets until an ACK is received.
  142.  
  143. All DAT bytes are assumed to be unsigned (0 - 255).  Integers are sent
  144. with the most significant byte first.  All parameters are sent in the
  145. same order as is documented in the QuickDraw section of Inside Macintosh.
  146. The only exception is the Scroll command, which differs slightly from
  147. the QuickDraw ScrollRect function as documented below.
  148.  
  149.  
  150. The Command Types and Their QuickDraw Functions
  151. -----------------------------------------------
  152.  
  153. 1) SetCursor
  154. 2) HideCursor
  155. 3) ShowCursor
  156. 4) ObscureCursor
  157. 5) LineTo
  158. 6) Line
  159. 7) BackPat
  160. 8) PenSize
  161. 9) PenMode
  162. 10) Move
  163. 11) PenNormal
  164. 12) MoveTo
  165. 13) PenPat
  166. 14) HidePen
  167. 15) ShowPen
  168. 16) TextFont
  169. 17) TextFace
  170. 18) TextMode
  171. 19) TextSize
  172. 20) DrawChar
  173. 21) DrawString
  174. 22) FrameRect
  175. 23) PaintRect
  176. 24) EraseRect
  177. 25) InvertRect
  178. 26) FillRect
  179. 27) FrameOval
  180. 28) PaintOval
  181. 29) EraseOval
  182. 30) InvertOval
  183. 31) FillOval
  184. 32) FrameRoundRect
  185. 33) PaintRoundRect
  186. 34) EraseRoundRect
  187. 35) InvertRoundRect
  188. 36) FillRoundRect
  189. 37) FrameArc
  190. 38) PaintArc
  191. 39) EraseArc
  192. 40) InvertArc
  193. 41) FillArc
  194. 50) InitCursor
  195.  
  196. Non-QuickDraw Packets
  197. ---------------------
  198. 42) reserved for future use.
  199. 43) MouseEnable (no parameters) - When you receive this packet set the
  200. mouse flag so that any MouseDown event in the graphics window will send
  201. a Type 49 packet.
  202. 44) MouseDisable (no parameters) - Reset your mouse flag so that no
  203. MouseDown events are reported to the host.
  204. 45) AcknowledgeGraphicsOn (no parameters) - send this as soon as you enter
  205. the graphics mode to let the host know you have responded to the
  206. signiture bytes and are ready for M.S.G.P. commands.
  207. 46) reserved for future use.
  208. 47) Scroll(therect: Rect; X,Y:INTEGERS) - This is just like the ScrollRect
  209. function in QuickDraw, except that the region handle is not sent.  If the
  210. most significant bytes of X or Y is non-zero, the least significant bytes
  211. are deemed to be negative.
  212. 48) Exit Graphics Mode (no parameters) - This is your signal from the host
  213. to return to your TTY or textual mode.
  214. 49) MouseReport(X,Y:INTEGERS) - convert the global coordinates of the
  215. MouseDown event in the graphics window to local coordinates.  Remember,
  216. your mouse flag must have been set through a Type 43 command before you
  217. would send this packet type.
  218.  
  219. Types 100-255: Not currently part of this protocol and reserved for use
  220. with your program communicating with like programs.
  221.  
  222.  
  223. A Typical Session
  224. -----------------
  225. The following are the actual bytes SENT by the host and remote.  My
  226. comments are in parentheses.  The numbers are in decimal.
  227.  
  228. Host: 26,16,4,12
  229. (The host sends the signiture bytes)
  230. Remote: 3,1,45,46
  231. (The remote acknowledges with a Type 45 packet)
  232.  
  233. Host: 3,5,12,0,25,0,25,67
  234. (The Host sends a MoveTo(25,25) packet (Type 12))
  235. Remote: 6
  236. (The Remote ACKS the packet)
  237.  
  238. Host 3,3,16,0,0,19
  239. (The Host sends a TextFont(0) packet (Type 16))
  240. Remote: 6
  241.  
  242. Host: 3,3,19,0,12,34
  243. (The Host sends a TextSize(12) packet)
  244. Remote: 6
  245.  
  246. Host: 3,7,21,5,72,69,76,76,79,21
  247. (The Host sends a DrawString("\005HELLO") packet. Notice that whenever
  248. parameters would be a pointer for an actual QuickDraw call, the actual
  249. bytes pointed to would be sent in an M.S.G.P. packet.  Remember that a 
  250. Pascal string starts out with a byte indicating it's length).
  251. Remote: 6
  252.  
  253. Host: 3,5,22,0,200,0,200,1,34,1,34,113
  254. (This is a FrameRect(200,200,290,290) packet)
  255. Remote: 21
  256. (Remote's didn't get the right checksum and NAKs it!)
  257.  
  258. Host: 3,5,22,0,200,0,200,1,34,1,34,113
  259. Remote: 6
  260. (OK, now the remote got it right)
  261.  
  262. Host: 3,9,13,119,137,143,143,119,152,248,248,51
  263. (This is a PenPat packet with one of the patterns in the Control Panel
  264. Desk Accessory)
  265. Remote: 6
  266.  
  267. Host: 3,1,43,44
  268. (The host enables the remote's mouse)
  269. Remote: 6
  270.  
  271. (the remote now presses his mouse button with the cursor pointing at
  272. local coordinates X=24, Y=100)
  273. Remote: 3,5,49,0,24,0,100,50
  274. Host: 6
  275. (The host should always ACK a Type 49 packet as long as the checksum is
  276. correct, even if the mousepress was not in a valid area - just ignore it)
  277.  
  278.  
  279. Keyboard
  280. --------
  281. The keyboard is supported at all times for the remote.  The host can
  282. choose to simply ignore keypresses, or deal with them as appropriate.
  283. Control characters are not a part of this protocol, as handshaking is
  284. not relevant with proper host construction, and the COMMAND-X keypress
  285. is withheld for remote use to exit the graphics mode.
  286.