home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / ctkit11.zip / CTKIT11.DOC < prev    next >
Text File  |  1992-04-06  |  22KB  |  534 lines

  1. The Crunchterm Programming Kit v1.1
  2. Brought to you by Crunchware!
  3.  
  4. BBSENDU.DOC:  Writing Doors with Crunchterm Support
  5.  
  6. Introduction
  7.  
  8.      This is a brief text file which will hopefully make it a
  9. little easier to understand just how to write a door that
  10. supports Crunchterm.  Writing a game that supports graphics can
  11. be complicated enough in itself, but writing one that works over
  12. a modem is even worse.  This package attempts to make the process
  13. easier by doing some of the nitty-gritty work for you.
  14.      Included in this package are several Turbo Pascal v5.5
  15. units, but the only one that it is necessary to be concerned with
  16. is BBSENDU.  The other units act only as support for BBSENDU,
  17. although they too may be worth modifying once you've figured out
  18. how they work.
  19.      The scary thing is that this is a "brief" text file.  Hope
  20. you can figure it out.
  21.  
  22. Well, What Do You Do?
  23.  
  24.      To get started with Crunchterm support, all you have to do
  25. is include BBSENDU as one of the units in your program.  Below is
  26. a description of the major commands in BBSENDU which may be
  27. necessary or helpful.
  28.      It may be helpful to clarify some terminology first. 
  29. "Door," or chain, is a program, like Crunch League Football and
  30. all other programs which support Crunchterm, meant specially to
  31. be run as a subprogram from a BBS.  "Local" refers to the
  32. computer on which the program you are writing will be running. 
  33. In most cases, that would also be the computer running a BBS. 
  34. "Remote" refers to a computer which has called the BBS and has
  35. selected to run the program.  
  36.      NOTE: Any of the following functions that have anything to
  37. do with input and output automatically determine where to act. 
  38. For example, if the program is only being run locally, the
  39. procedures will only do stuff with the local computer.  If it's
  40. only running remotely, the program'll only send commands over the
  41. modem for Crunchterm to interpret on the other side.  If the
  42. program is running on both ends, believe it or not, the program
  43. does both those things.
  44.  
  45. Function KeyPressed: boolean;
  46.  
  47.      Equivalent of crt's KeyPressed.  It must be a leftover from
  48. the days when BBSENDU didn't use the crt unit.
  49.  
  50. Function KeyCheck: boolean;
  51.  
  52.      Like KeyPressed, except it also checks the COM port to see
  53. if a character is waiting there.  If, of course, either local or
  54. remote play has been disabled, KeyCheck will not check that
  55. location.
  56.  
  57. Procedure MakeTime (var T: longint; var D: word);
  58.  
  59.      Used by a couple other procedures, MakeTime enters the
  60. number of seconds that have passed in the current day in T and
  61. the day of the week in D.
  62.  
  63. Procedure SendStr(s: string);
  64.  
  65.      Equivalent of Write in TP, although you must supply only one
  66. string of characters.  So with a setup like this:
  67.  
  68. var
  69.    butthead: integer;
  70.    name, ts: string;
  71.  
  72. you'd have to do something like:
  73.  
  74. ...
  75. Str(butthead,ts);
  76. Write (name+', your butthead quotient is '+ts+'.');
  77.  
  78.      It might help to write a function that performs the same
  79. things as Str.  I use one, but it seems I didn't include it in
  80. BBSENDU.
  81.  
  82. Procedure SendLine(s: string);
  83.  
  84.      Just like SendStr except adds a carriage return and line
  85. feed at the end of the string.
  86.  
  87. Procedure ExitProg;
  88.  
  89.      Returns to graphics mode, closes the modem connection
  90. (EXTREMELY IMPORTANT) and Halts.  Be sure to call this as the
  91. last thing in your program instead of a plain old Halt.
  92.  
  93. Function WaitForChar: char;
  94.  
  95.      Like crt's readkey except that it allows for modem input as
  96. well.  It also tells the program to abort if no key has been
  97. pressed during the last predefined number of minutes (in the
  98. variable WaitMin).  Also, any time the procedure is idling, a
  99. person on the local computer can press F10 to make the program
  100. abort immediately.  As it is now, the program doesn't save
  101. anything when aborted, so you might want to make some
  102. modifications here.  Note that F10 will work even when the
  103. program is only running for the remote computer.
  104.  
  105. Procedure RdLn (var s; l: byte);
  106.  
  107.      Read a string, s, of maximum length l and stick a carriage
  108. return at the end.  Works in graphics and text modes.
  109. Procedure Initialize;
  110.  
  111.      BBSENDU has one major procedure, Initialize, which sets up
  112. all the necessary modem connections.  It requires, however, that
  113. the name of a chain information file from one of several BBS
  114. selections be supplied as the first parameter of the command line
  115. to the program.  It is for that reason that Crunch League
  116. Football requires "FB %1" in WWIV, which WWIV in turn converts to
  117. "FB \WWIV\CHAIN.TXT."  Initialize, when called by your program,
  118. will try to open the file named in the first parameter and, if it
  119. recognizes the file type, loads the necessary information about
  120. the current user's name, COM port, and baud rate.  If you have
  121. some other way of supplying information necessary for the program
  122. to connect with the modem, you may opt to modify Initialize to
  123. work some other way.  It is important, however, to somehow
  124. establish a connection with the COM port before you try to do
  125. ANYTHING else.
  126.      Initialize also supplies the current user's name in the
  127. variable PName and more detailed information about the user if
  128. the current BBS is WWIV.
  129.  
  130. Procedure SendCommand (R: byte; ComStr, ExStr: string);
  131.  
  132.      This is the procedure that determines where to send
  133. "Crunchterm" commands (i.e., specially coded strings which
  134. Crunchterm decodes and follows) you have given the computer.  If
  135. you're connected to a remote computer, it sends the necessary
  136. codes over the modem.  If you're displaying locally, it performs
  137. the command in CodeStr locally too.  You would rarely, if ever,
  138. call this procedure itself.  Usually you would call one of the
  139. procedures listed below which in turn creates the necessary
  140. strings for SendCommand and calls it.
  141.      In order to use any of the procedures that use SendCommand,
  142. Crunchterm must be active on the remote end.  Before you do
  143. anything else, use TestResp (see below) to make sure the other
  144. end has Crunchterm.  Otherwise, the remote computer will have no
  145. idea what to do with these bizarre characters it's receiving over
  146. the modem.
  147.  
  148. Procedure PutPic(num: byte; x, y: word; how: byte);
  149.  
  150.      Equivalent of the unit Graph's PutImage except that you must
  151. refer to a picture number rather than variable name.  Stored both
  152. locally and in Crunchterm at the other end, are 200 slots (which
  153. are really just pointer variables) for graphics.  These must be
  154. loaded from data files or GetPic-ed earlier in the program. 
  155. Refer to LoadPic and GetPic for a clearer idea of what's going
  156. on.
  157.  
  158. Procedure LoadPic(num: byte; place, length: word; fn: string);
  159.  
  160.      Load a picture from a data file available where the program
  161. is being run.  If, for example, you want to be able to load a
  162. picture from MAIN.CT, it must be located both on the local
  163. computer and on any remote computer that runs the program.  Num
  164. specifies the slot in memory where you want to load the picture
  165. (1-200).  Place specifies the byte location (starting at 0 in the
  166. file) of the picture you want to load, and Length specifies its
  167. length in bytes.  Fn is the name of the file from which you wish
  168. to load the picture.  Note that when you pass a blank Fn,
  169. Crunchterm will assume you want to load a picture from the file
  170. you most recently loaded from.  That way, you can save a few
  171. extra bytes for each graphic you load, and that can come in handy
  172. when you've got 70 or so.  Just make sure you specify the proper
  173. file name the first time you load a graphic.
  174.      One important thing:  The graphic you load must be stored in
  175. bit-map format.  (It can actually be in a slightly compressed
  176. format that I used for CLFB, but it'd probably just confuse you
  177. more to try to mess with that.  You'll note that there's a file
  178. called SCStuff.PAS whose function is to decode the compressed
  179. format.  If you feel adventurous, you can try to figure out how
  180. that compression works.  Maybe I'll be able to release a utility
  181. that'll actually do the conversion for you someday.)
  182.      I'm distributing in the Crunchterm Programming Kit a utility
  183. which I found useful called CTFILE.  CTFILE allows you to create
  184. and edit CT files just like MAIN.CT and CLFB.CT.  CT files are
  185. composed of several chunks of data which were at one time
  186. separate files.  If you've got fifty 100-byte files, you can
  187. combine them into one 5000-byte file.  In .INF files, CTFILE
  188. stores the information that you'll need for such procedures as
  189. LoadPic and LoadSong.  I've also included MAIN.CT and MAIN.INF
  190. (.INF files are used by CTFILE but don't need to be distributed
  191. with your program) as a demonstration.  Valid commands for CTFILE
  192. are as follows:
  193.  
  194. A: Add file to the end of the current list.
  195. D: Delete one of the chunks of data in the file.
  196. N: Write a new description of one of the chunks of data.
  197. R: Replace a chunk of data in the middle of the .CT file with a
  198. new file.
  199. Q: Quit and save.
  200.  
  201. When you run CTFILE, be sure not to include the .CT extension at
  202. the file name prompt.  It's pretty confusing at first.  Using
  203. bit-mapped graphics really is the hardest thing to get used to
  204. with Crunchterm, but it isn't really that bad once you get used
  205. to it.
  206.  
  207. Procedure DoText(x, y: word; tx: string);
  208.  
  209.      Displays a string at the specified coordinates, either in
  210. text or graphics modes.  X and y in text mode simply must be in
  211. the range 1-80 and 1-25, while they designate pixel locations in
  212. graphics modes.
  213.  
  214. Procedure GrInfo(var gd, gm: word);
  215.  
  216.      Returns the maximum graphical capability of the active
  217. computers.  If, for example, the remote computer has VGA while
  218. the local has only CGA, GrInfo will return gd equal to 1 and gm
  219. equal to 3.  Refer to your TP docs to understand what the gd and
  220. gm codes mean.
  221.  
  222. Procedure InitGr(d, m: word);
  223.  
  224.      Just like InitGraph.  Note the all the video drivers have
  225. been compiled into the unit rdrivers, so you don't have to
  226. specify a path to the BGI files.  That also makes it unnecessary
  227. to distribute BGI files with your program.
  228.  
  229. Procedure ScreenPage (apage, vpage: byte);
  230.  
  231.      In EGA and VGA modes, change the virtual page of the
  232. graphics mode you're in.  Check out SetVisualPage and
  233. SetActivePage in your TP documentation.
  234.  
  235. Procedure DoLine (x1, y1, x2, y2: word; color: byte);
  236.  
  237.      Just like Line in Graph except color will change the current
  238. active color to itself (take a look at SetFg...).
  239.  
  240. Procedure DoCircle (x, y, rad: word; color: byte);
  241.  
  242.      Like Circle in Graph.  Color has the same effect here as in
  243. DoLine.
  244.  
  245. Procedure DoRect (x1, y1, x2, y2: word; color: byte);
  246.  
  247.      Duh.  "Rect," maybe that has something to do with drawing a
  248. rectangle.
  249.  
  250. Function TestResp: boolean;
  251.  
  252.      TestResp sends a special code over the modem to the remote
  253. terminal.  If Crunchterm is running on that terminal, TestResp
  254. will return true.  Otherwise, it will return false.  You pretty
  255. much always want to use the expression: 
  256.  
  257. ...
  258. CTOn := TestResp;
  259. ...
  260.  
  261. where CTOn is a global variable found in BBSENDU.  CTOn must be
  262. true anyways for any Crunchterm commands to have any effect.
  263.  
  264. Function MemFree: longint;
  265.  
  266.      Memory available in the remote computer unless you're only
  267. playing locally, in which case, it returns the memory free in the
  268. local computer.
  269.  
  270. Procedure LeaveCT;
  271.      Send the command (if you're connected to a remote computer)
  272. to have the remote computer exit Crunchterm.  You'd usually do
  273. this at the end of the program.
  274.  
  275. Procedure ClearScr;
  276.  
  277.      Clear the screen, either in text or graphics mode.
  278.  
  279. Procedure SetCol (fore, back: byte);
  280.  
  281.      In text mode, set the color that text will be displayed in
  282. (Check your TP documentation for color codes).  In graphics mode,
  283. SetCol sets the foreground color for anything that will be
  284. displayed and the whole background is set to back.
  285.  
  286. Procedure InLineXY(len: byte; x, y: word; var thestring: string);
  287.  
  288.      Input a string at coordinates (x,y) of maximum length len. 
  289. X and y are units corresponding either to graphics or text mode.
  290.  
  291. Procedure FillStyle (pattern, color: word);
  292.  
  293.      Just like SetFillStyle in Graph.
  294.  
  295. Procedure GetPic (num: byte; x1, y1, x2, y2: word);
  296.  
  297.      Similar to GetImage in Graph, although, as with PutPic and
  298. LoadPic, you must specify a picture number rather than variable
  299. name.
  300.  
  301. Procedure DefSeries(Ser,Step,Command,ExNum: byte;StrStr: string);
  302.  
  303.      If you've got an extensive series of Crunchterm commands
  304. that you use frequently, you can speed up the process by defining
  305. a series of commands on the remote computer.  To do it, you must
  306. first execute a Crunchterm "SendCommand" command with the
  307. variable Stringing set to true.  Any command that is called will
  308. then have its code saved in the global variable StrungStr.  You
  309. can then send StrungStr, the command number (which you can find
  310. in BBSENDU's source), and if necessary the number of an extra
  311. string.  See DefExStr for more on that.  There can be three
  312. series containing up to nine commands each.  This procedure can
  313. be helpful at times, but don't kill yourself worrying about
  314. trying to get it to work.  The number of steps in the series will
  315. be defined by the Step number of the last command you define. 
  316. Thus you would normally want to define the series in the order it
  317. happens.
  318.  
  319. Procedure DoSeries (Ser: byte);
  320.  
  321.      Perform a predefined series of commands (see above), 1-3.
  322.  
  323. Procedure DefExStr (num: byte; exstr: string);
  324.  
  325.      If a command in a series needs a string--for example,
  326. DoText--you can define and extra string for use with DefSeries.
  327.  
  328. Procedure SetGD(gd: byte);
  329.  
  330.      This may seem a little bizarre, but bear with me.  The
  331. conversion procedure I wrote needs to know the graphics mode that
  332. the picture it is uncompressing is for.  If, however, you want to
  333. convert pictures before you've entered graphics mode, you need to
  334. specify the graphics mode in gd for that.  In other words, this
  335. command is pretty darn useless.  Unless you have pictures stored
  336. in that compressed format.
  337.  
  338. Procedure LoadSong (SongNum: byte; Place: word; FN: string);
  339.  
  340.      Works much like LoadPic, although songs must always be the
  341. same size and format.  Don't ask me why.  I'm just too lazy to
  342. make it easier to use.  Anyways, songs are stored in a format
  343. found in CTSOUNDU.  You might recognize the note/octave format
  344. from TP samples.  It's a little confusing at first, but MAIN.CT
  345. begins with 10 "sound effects," including the theme to CLFB. 
  346. Each song is 150 bytes long, so to load the first song from
  347. MAIN.CT, you'd call LoadSong(1,0,'MAIN.CT');  (the second would
  348. be LoadSong(1,150,'MAIN.CT'), etc.)  That'll load the song into
  349. the first song slot.  I believe there are ten slots available in
  350. memory.
  351.  
  352. Procedure DoSong (SongNum: byte);
  353.  
  354.      Play a song that you've loaded in the background as you do
  355. something else.  Pretty nifty as long as it doesn't conflict with
  356. some other memory resident thing.  But sound can be disabled with
  357. /Q.  It was a pain to figure out, so enjoy.  Maybe I'll figure
  358. out how an Adlib card works someday.
  359.  
  360. Procedure DefAnim (Flm, Frame, PicN: byte; pause, x, y: word;
  361. Way: byte);
  362.  
  363.      Even with pretty short commands, animation can be slow with
  364. Crunchterm.  This works sort of like DefSeries, except only with
  365. pictures.  You can define Flm 1-30 and each can have up to 10
  366. frames.  Pause is the number of milliseconds to wait before
  367. displaying the next frame.  Way is the way the picture is
  368. displayed (eg. "NormalPut" or "NotPut" or "OrPut" in TP dialect).
  369.  
  370. Procedure ShowAnim (Flm: byte; AuxX, AuxY: word);
  371.  
  372.      ShowAnim displays a film with the defined X and Y relative
  373. to AuxX and AuxY.  So if a picture in the film is defied to be at
  374. (10,20) and you call ShowAnim(..,20,20), the picture will appear
  375. at (30,40).
  376.  
  377. Procedure TextStyle (Size, font: word);
  378.  
  379.      Sorta like SetTextStyle in TP, although you can't turn text
  380. sideways, and the only fonts you can use are Default and Triplex
  381. (0 and 1, I think).  If you'd like me to compile in some others,
  382. please tell me.  You can always distribute a .CHR file with your
  383. program, and Crunchterm'll find it if it's in the proper
  384. directory.
  385.  
  386. Procedure FillCircle (x, y, rad: word);
  387.  
  388.      Draw a filled circle in the current pattern, etc.
  389.  
  390. Procedure FillBar (x1, y1, x2, y2: word);
  391.  
  392.      Draw a bar, filled with whatever pattern you've defined.
  393.  
  394. Procedure FillFlood (x, y: word; BorderCol: byte);
  395.  
  396.      Just like TP's FloodFill.  I must just be dyslexic.
  397.  
  398. Procedure DefNote (Song, Note, l, n, o: byte);
  399.  
  400.      Aha!  If you don't feel like using 150 bytes for a two note
  401. sound effect, you can define notes individually.  I think there
  402. are ten songs.  Fifty notes each.  L is the length of the note in
  403. milliseconds and n and o correspond to the codes defined in the
  404. TP music demo.
  405.  
  406. Procedure ChPalette(ColorNum: word; Color: shortint);
  407.  
  408.      If you're in an EGA mode, you can edit your palette.  I
  409. believe there's a Graph command much like this.
  410.  
  411. Procedure DoArc (x, y, stangle, endangle, rad: word);
  412.  
  413.      Draw a segment of a circle.  I think there's a TP command
  414. like this too.
  415.  
  416. Procedure VirtWind (x1, y1, x2, y2: word; Clip: boolean);
  417.  
  418.      Believe it or not, I think there's a TP command equivalent
  419. to this sucker as well.  Just sets up a virtual window to act as
  420. the whole screen.  
  421.  
  422. Procedure HighLight (x1, y1, x2, y2: word);
  423.  
  424.      Inverts (i.e. white to black and black to white) a section
  425. of the screen.  This is great for bar menus and stuff.  You've
  426. probably seen this command in action many times in CLFB.
  427.  
  428. Procedure UnHighLight;
  429.  
  430.      Uninverts the section of the screen that has been most
  431. recently HighLighted.  Note that you could just call HighLight a
  432. second time to unhighlight, but this command saves sending 8
  433. extra bytes over the modem.
  434.  
  435. Procedure DefScroll (x1, y1, x2, y2, scramt: word);
  436.  
  437. Define a section of the screen that you want to scroll up and
  438. down.  The x coordinates may have to be divisible by eight.  I'm
  439. not quite sure.  ScrAmt is the number of pixels that the section
  440. will scroll on each call.
  441.  
  442. Procedure ScrollUp;
  443.  
  444.      Scroll up ScrAmt pixels in the predefined area (see above).
  445.  
  446. Procedure ScrollDown;
  447.  
  448.      Scroll down (see above).
  449.  
  450. Procedure SetFg (fore: byte);
  451.  
  452.      Just like SetColor except only for the foreground.  Helpful
  453. especially in graphics mode because it saves a byte when you'd
  454. rarely want to change the background color.
  455.  
  456.      Whew!  That's it for BBSENDU's commands.  Hope you can
  457. figure it all out.  Once you get the hang of things, you might
  458. wonder what some of those global variables are there for.  Well,
  459. to explain some of them...
  460.  
  461. (From BBSENDU.PAS...)
  462.  
  463. var
  464.    ComStr, The string where various CT commands assemble codes
  465.    lastpress,  Used by WaitForChar to hang up if a key hasn't
  466. been pressed for a while.
  467.    TrueUK, If CHAIN.TXT is used, the value of a person's upload K
  468. credit on the BBS according to CHAIN.TXT.
  469.    lastd, The last day of the week when a key was pressed.  Don't
  470. worry about it.
  471.    WaitMin, Number of minutes the program'll wait for a key to be
  472. pressed.
  473.    BaudRate, Duh.
  474.    ComPort, Another toughy.
  475.    FillPat, FillCol, Used by FillStyle.
  476.    UserNum, If it's WWIV, the user number found in CHAIN.TXT
  477.    stringing, Whether or not you're defining strings for
  478. DefSeries.
  479.    SysAllowed, If true, display locally.
  480.    ModemOn, If true, display remotely.
  481.    Local, If the last character input was local.
  482.    DoTimeCheck, Whether or not TLim means anything.
  483.    CTOn, Whether or not Crunchterm has been detected, I think.
  484.    SoundOn, True if sound is allowed.
  485.    StrungStr, Used with DefSeries.
  486.    PName, User name read in from the door info file.
  487.    BBSName, The name of the BBS read in from the door info file.
  488.    DataDir, the location of the directory holding USER.LST on a
  489. WWIV board.
  490.    TrueSL, Sec Level read from CHAIN.TXT on a WWIV BBS.
  491.    BkCol, FgCol, Current color settings.
  492.    Ver, No real use until we hit newer versions of CT.
  493.    TrueGold, WWIV gold (if CHAIN.TXT has been read).
  494.    DLim, Day of the week when time will run out.
  495.  
  496.      With this package, I included a short program (CTDEMO.PAS)
  497. which demonstrates some of the basic functions of Crunchterm-
  498. supporting programs.  That should give you a basic idea exactly
  499. how to use some of the basic commands descirbed above.
  500.  
  501. That Better Be It!
  502.  
  503.      So there you have it:  How to write a Crunchterm-supporting
  504. program in a nutshell.  Have fun.  If you've got any questions
  505. please contact me...
  506.  
  507. Stephen V. David
  508. 6030 Fort Hunt Road
  509. Alexandria, VA  22307
  510.  
  511. or Infinity #27 on Lankhmar BBS (703 360-4973), #27 @ 7309
  512. WWIVNet, or #80 @ 17310 WWIVLink.
  513.      Whenever I get a new version of Crunchterm out, I'll be sure
  514. to release a new version of this kit to use with it.   Be on the
  515. lookout for an update one of these days.  It should be pretty
  516. easy to upgrade.  All you'll have to do will be recompile your
  517. program with the new BBSENDU and implement any nifty new commands
  518. (if there are any... :)...).
  519.      This Programming Kit is public domain, and I don't endorse
  520. anything written with it and am not responsible for any nasty
  521. thing that some idiot might want to use it for.  If you like it
  522. and DO use it for a legitimate program, I'd love to hear about
  523. it.  If you get rich using it, please remember the poor
  524. programmer who helped you along the way.  Thanks for any
  525. contributions, but I don't require a fee for using this stuff.
  526.      I hope this gets people started writing some more graphical
  527. on-liners.  Enjoy!
  528.  
  529. << Addendum by Joel Slovacek: >>
  530.  
  531. The files *.TP6 are TPU files for TP 6.0.  The other .TPUs are for 5.5.
  532. The Pascal files are *not* included, but if it is important, they can be
  533. transported in a second file.
  534.