home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1988 / 09 / krute.lis < prev    next >
File List  |  1988-08-22  |  6KB  |  225 lines

  1. _XCMD and XFCN_
  2. by
  3. Stan Krute
  4.  
  5.  
  6. Listing One
  7.  
  8.  
  9. *--------------------------------------- file information 
  10. *    XCMDandXFCN.a                                    
  11. *    MPW record definitions useful in XCMD and XFCN work                
  12. *    Edited with MPW 2.02                                
  13. *    Compiled under MPW 2.02                                
  14. *    Written and (C)1988 by Stan Krute. All rights reserved.                 
  15. *-----------------------------------------------------------------------
  16.  
  17. ; general array structures
  18.  
  19. Array4L        RECORD    0    ; an array of 4 longs
  20. zero        DS.L    1
  21. one        DS.L    1
  22. two        DS.L    1
  23. three        DS.L    1
  24.         ENDR
  25.             
  26. Array8L        RECORD    0    ; an array of 8 longs
  27. zero        DS.L    1
  28. one        DS.L    1
  29. two        DS.L    1
  30. three        DS.L    1
  31. four        DS.L    1
  32. five        DS.L    1
  33. six        DS.L    1
  34. seven        DS.L    1
  35.         ENDR
  36.                 
  37. Array16L    RECORD    0    ; an array of 16 longs
  38. zero        DS.L    1
  39. one        DS.L    1
  40. two        DS.L    1
  41. three        DS.L    1
  42. four        DS.L    1
  43. five        DS.L    1
  44. six        DS.L    1
  45. seven        DS.L    1
  46. eight        DS.L    1
  47. nine        DS.L    1
  48. ten        DS.L    1
  49. eleven        DS.L    1
  50. twelve        DS.L    1
  51. thirteen    DS.L    1
  52. fourteen    DS.L    1
  53. fifteen        DS.L    1
  54.         ENDR
  55.  
  56. ; an XCmdBlock record
  57.  
  58. XCmdBlock    RECORD 0
  59. paramCount    DS.W    1        ; # of entry parameters 
  60. params        DS    Array16L    ; array of handles to entry parameters
  61. returnValue    DS.L    1        ; handle to a return value
  62. passFlag    DS.W    2        ; boolean: if true, HC passes message on
  63.  
  64. entryPoint    DS.L    1        ; pointer to HyperCard callback function (cbf)    
  65. request        DS.W    1        ; a cbf command code                   
  66. result        DS.W      1        ; HC's answer to a cbf command         
  67. inArgs        DS    Array8L       ; array of arguments in to a cbf command    
  68. outArgs       DS    Array4L        ; array of arguments out from a cbf command 
  69.         ENDR
  70.  
  71.  
  72.  
  73. Listing Two
  74.  
  75.  
  76. # make instructions for the isAlpha XFCN
  77.  
  78. # the object file depends on the assembly language source code file 
  79. isAlpha.a.o    f    isAlpha.a 
  80. # to create the object file, assemble the assembly language source code file
  81.     # the source code file is isAlpha.a
  82.     # we'll send a listing to the file isAlpha.a.lst
  83.     Asm isAlpha.a -l
  84.  
  85. # the resource file depends on the object file
  86. isAlpha        f    isAlpha.a.o
  87. # to create the resource file, link the object file
  88.     # the output file is isAlpha
  89.     # the output file's type is RSRC
  90.     # the output file's creator is RSED
  91.     # the code will be an XFCN resource with ID #990
  92.     # the segment name will be isAlpha, same as the new HyperCard command name
  93.     # the input file is the object file isAlpha.a.o 
  94.     Link -o isAlpha -t RSRC -c RSED -rt XFCN=990 -sn Main=isAlpha isAlpha.a.o  
  95.  
  96.  
  97. Listing Three
  98.  
  99. *--------------------------------------- file information 
  100. *    isAlpha.a                                    
  101. *    Assembly language source code for the HyperCard XFCN isAlpha                
  102. *    Given a character, isAlpha returns the string 'true' 
  103. *       if the character is an uppercase or lowercase letter, the
  104. *       string 'false' if it is not.        
  105. *       A c function prototype might look like this:
  106. *        BOOLEAN_STRING isAlpha(CHAR chSomeChar) ;
  107. *    Edited with MPW 2.02
  108. *    Compiled under MPW 2.02
  109. *    Written and )1988 by Stan Krute. All rights reserved. 
  110. *       No part of this file other files in the project it belongs to, 
  111. *       or the object code the file(s) lead(s) to, may be reproduced, 
  112. *       in any form or by any means, without the express written 
  113. *       permission of the author and copyright holder.        
  114. *-------------------------------------------------------------------    
  115.  
  116.  
  117. *-------------------------------------- include files     
  118.  
  119. ; standard Mac definitions
  120.     INCLUDE     'QuickEqu.a'        ; quickdraw
  121.     INCLUDE     'ToolEqu.a'        ; toolbox
  122.     INCLUDE     'SysEqu.a'        ; system
  123.     INCLUDE     'Traps.a'        ; traps
  124.  
  125. ; our stuff
  126.     INCLUDE     'XCMDandXFCN.a'        ; XCMD and XFCN definitions        
  127.  
  128.  
  129. *------------------------------------------ isAlpha -----------------    
  130.  
  131. ; set local constants
  132. smallBlockSize        SET    6    ; size of a small result block we'll allocate
  133. XCmdPtr            SET    8    ; where we'll find the XCmdPtr after register saving
  134. bytesOfEntryParams    SET    4    ; bytes of entry parameters
  135.  
  136. isAlpha    MAIN    
  137.     ; save a register
  138.     MOVE.L        A2,-(SP)
  139.  
  140.     ; get a small result block, filled with zeroes for cheap 0-terminated strings
  141.     MOVE.L        #smallBlockSize,D0
  142.     _NewHandle     ,CLEAR
  143.  
  144.     ; store the result block's handle as a return value
  145.     MOVE.L        XCmdPtr(SP),A2               ; A2 gets pointer to XCmdBlock
  146.     MOVE.L        A0,XCmdBlock.returnValue(A2)    ; handle to result block
  147.     
  148.     ; point to the result block
  149.     MOVE.L        (A0),A0    
  150.     
  151.     ; get the single entry parameter
  152.     MOVE.L        XCmdBlock.params.zero(A2),A1       ; handle to first entry parameter
  153.     MOVE.L        (A1),A1                ; pointer to first entry parameter
  154.     
  155.     ; clear a data register, and move entry parameter, a character, into it
  156.     CLR.L    D0
  157.     MOVE.B    (A1),D0    
  158.     
  159.     ; now run a series of boundary tests
  160.     ; check against the low bound of upper-casedness
  161.     CMP.B    #'A',D0
  162.     BLT.S    notAlpha    ; less than this, and we're not alphabetical
  163.     
  164.     ; check against the high bound of upper-casedness
  165.     CMP.B    #'Z',D0
  166.     BLE.S    yesAlpha    ; less than or equal to this, and we're upper-case,
  167.                 ; thus alphabetical
  168.     
  169.     ; check against the low bound of lower-casedness
  170.     CMP.B    #'a',D0
  171.     BLT.S    notAlpha    ; less than this, and we're not alphabetical
  172.     
  173.     ; check against the high bound of lower-casedness
  174.     CMP.B    #'z',D0
  175.     BGT.S    notAlpha    ; greater than this, and we're not alphabetical
  176.     
  177. yesAlpha    
  178.     ; we have an upper- or lower-case letter
  179.     ; set result into result block
  180.     MOVE.L    #'true',(A0)
  181.     BRA.S    bye
  182.     
  183. notAlpha    
  184.     ; we have neither an upper- nor a lower-case letter
  185.     ; set result into result block
  186.     MOVE.L    #'fals',(A0)+
  187.     MOVE.B    #'e',(A0)
  188.     
  189. bye    ; tell HyperCard we've handled things
  190.     CLR.W    XCmdBlock.passFlag(A2)
  191.     
  192.     ; restore a register
  193.     MOVE.L    (SP)+,A2
  194.     
  195.     ; move the return address into A0
  196.     MOVE.L     (A7)+,A0
  197.     
  198.     ; jump over entry parameters
  199.     ADD.W    #bytesOfEntryParams,A7
  200.     
  201.     ; puffasmoke and we be gone
  202.     JMP     (A0)
  203.     
  204.     ; end of the procedure
  205.     ENDPROC
  206.     
  207.     ; end of the assembly language source file
  208.  
  209.  
  210.  
  211. Example 1: C rendition of an XCmdBlock data structure
  212.  
  213. #include "Types.r"
  214. resource 'SIZE' (-1, purgeable) {
  215.     dontSaveScreen,
  216.     ignoreSuspendResumeEvents,
  217.     disableOptionSwitch,
  218.     cannotBackground,
  219.     notMultiFinderAware,
  220.     150*1024, /* maximum size 150K */
  221.     150*1024  /* minimum size 150K */
  222.     };
  223.  
  224.  
  225.