home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / c_transf.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  4.9 KB  |  195 lines

  1. 18-Jun-88 14:46:20-MDT,5220;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:46:12 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22698; Sat, 18 Jun 88 14:46:14 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24821; Sat, 18 Jun 88 14:46:10 MDT
  8. Date: Sat, 18 Jun 88 14:46:10 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182046.AA24821@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: Transfer.c
  13.  
  14. /*
  15.  
  16. Transfer Function written in Megamax C  by N. Fukaya  August 31, 1986
  17.  
  18.  
  19. This is a self-contained source code that implements the Transfer action.
  20. When called, it displays a standard get file dialog with files of type
  21. APPL for selection.  If the user cancels, it'll return to the caller
  22. immediately.  If the user selects an application, a SetVol is done on
  23. the vRefNum or the WDRefNum.  Regardless of the result of the SetVol
  24. operation, CallerHook is called with the result code in D0.  Upon return
  25. from CallerHook, it'll test D0.  If D0 is zero, it'll execute a Launch
  26. to the selected application.  If D0 is nonzero, it'll return to the
  27. caller immediately.  Registers D0 and A0 are used by this function
  28. without care.
  29.  
  30. CallerHook is specified below as a dummy function.  It may be replaced by
  31. any processing that is felt appropriate.  For example, it could display
  32. a dialog informing the user that an error occurred or do the necessary
  33. cleanup before Launch is executed if there were no errors.
  34.  
  35. -------------------------------------------------------------------------
  36. This source is not copyrighted.
  37. You do not owe me anything should you wish to use or modify this source.
  38. I would appreciate it if you do not turn around and sell this to an
  39. uninformed soul.  However, there's nothing I can do about it if you're
  40. that
  41.      low.
  42. But really, this isn't worth paying for is it?
  43. ( If you would pay for this, I have a solar energy idea for Seattle... )
  44. -------------------------------------------------------------------------
  45.  
  46.  
  47. ***** Notes to Megamax Users:
  48.  
  49.   This function has been compiled and tested using the Beta 3.0 release.
  50. It should compile without any problems with version 2.1b release.
  51.  
  52.  
  53. ***** Notes to Non-Megamax Users:
  54.  
  55.   As with most C compilers, Megamax C allows inline assembly.  Some of
  56. the nicer features have been exploited for readability's sake.
  57.  
  58. - Inline assembly starts with the keyword 'asm' and a '{'.  It ends
  59.   with a closing '}'.
  60.  
  61. - The C function declaration like
  62.  
  63.   transfer()
  64.   {
  65.     SFReply       Reply;
  66.     ParamBlockRec PBRec;
  67.     .
  68.     . C and inline assembly instructions
  69.     .
  70.   }
  71.   
  72.   are replaced by
  73.   
  74.   LINK A6, #-TempVarSize
  75.   .
  76.   . Compiled C and inline assembly instructions
  77.   .
  78.   UNLK A6
  79.   RTS
  80.  
  81. - #define statements work within inline assembly.  Thus Launch is replaced
  82.   by DC.W 0xA9F2, etc.
  83.   
  84. - Declared temporary (automatic) C variables are accessed by name within
  85.   inline assembly as offsets from A6.  Thus a statement like
  86.   
  87.   MOVE.B  Reply.good(A6), D0
  88.   
  89.   is replaced by
  90.   
  91.   MOVE.B  -74(A6), D0
  92.  
  93.  
  94. Finally, I would appreciate comments from you, really.
  95.  
  96.                                  Enjoy,    Nobuo Fukaya
  97.                                            (72777,772 on Compuserve)
  98. */
  99.  
  100.  
  101. typedef short BOOLEAN;
  102. typedef char  OSType[4];
  103. typedef int   INTEGER;
  104. typedef char  STRING;
  105.  
  106. typedef struct {
  107.   BOOLEAN good;
  108.   BOOLEAN copy;
  109.   OSType  fType;
  110.   INTEGER vRefNum;
  111.   INTEGER version;
  112.   STRING  fName[64]; } SFReply;
  113.  
  114. typedef long int  LongInt;
  115. typedef char      *StringPtr;
  116. typedef char      *Ptr;
  117. typedef char      *QElemPtr;
  118. typedef int       (*ProcPtr)();
  119. typedef int       OSErr;
  120.  
  121. typedef struct {
  122.   QElemPtr qLink;
  123.   INTEGER   qType;
  124.   INTEGER   ioTrap;
  125.   Ptr       ioCmdAddr;
  126.   ProcPtr   ioCompletion;
  127.   INTEGER   ioResult;
  128.   StringPtr ioNamePtr;
  129.   INTEGER   ioVRefNum;
  130.   LongInt   filler2;
  131.   INTEGER   ioVolIndex;
  132.   LongInt   ioVCrDate;
  133.   LongInt   ioVLsBkUp;
  134.   INTEGER   ioVAtrb;
  135.   INTEGER   ioVNmFls;
  136.   INTEGER   ioVDirSt;
  137.   INTEGER   ioVBlLn;
  138.   INTEGER   ioVNmAlBlks;
  139.   LongInt   ioVAlBlkSiz;
  140.   LongInt   ioVClpSiz;
  141.   INTEGER   ioAlBlSt;
  142.   LongInt   ioVNxtFNum;
  143.   INTEGER   ioVFrBlk;    } ParamBlockRec;
  144.  
  145.  
  146. #define SFGet_Position #0x460050
  147. #define SFGetFile      DC.W 0xA9EA
  148. #define PBSetVol       DC.W 0xA215
  149. #define Launch         DC.W 0xA9F2
  150.  
  151. extern int CallerHook();
  152.  
  153. transfer()
  154. {
  155.   SFReply       Reply;
  156.   ParamBlockRec PBRec;
  157.  
  158.   asm {
  159.     MOVE.L  SFGet_Position, -(A7)
  160.     CLR.L   -(A7)
  161.     CLR.L   -(A7)
  162.     MOVE.W  #1, -(A7)
  163.     PEA     TYPE(PC)
  164.     CLR.L   -(A7)
  165.     PEA     Reply(A6)
  166.     MOVE.W  #2, -(A7)
  167.     SFGetFile
  168.     MOVE.B  Reply.good(A6), D0
  169.     BEQ.S   DONE(PC)
  170.     CLR.L   PBRec.ioNamePtr(A6)
  171.     MOVE.W  Reply.vRefNum(A6), PBRec.ioVRefNum(A6)
  172.     LEA     PBRec(A6), A0
  173.     PBSetVol
  174.     JSR     CallerHook(PC)
  175.     TST.W   D0
  176.     BNE.S   DONE(PC)
  177.     LEA     Reply.fName(A6), A0
  178.     MOVE.L  A0, Reply.vRefNum(A6)
  179.     LEA     Reply.vRefNum(A6), A0
  180.     Launch
  181.   DONE:
  182.   }
  183. }
  184.  
  185. asm {
  186. TYPE: DC.B 'A'
  187.       DC.B 'P'
  188.       DC.B 'P'
  189.       DC.B 'L'
  190. }
  191.  
  192. int CallerHook()
  193. {
  194. }
  195.