home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 073.lha / Arp / arpbase.i < prev    next >
Encoding:
Text File  |  1987-06-02  |  15.5 KB  |  505 lines

  1.     IFND LIBRARIES_ARPBASE_I
  2. LIBRARIES_ARPBASE_I    SET    1
  3. ***********************************************************************
  4. *
  5. *    AmigaDOS Replacement Project -- Library Include File (Assembler)
  6. *
  7. ***********************************************************************
  8. *
  9. *    History:
  10. *
  11. *    Version:    arpbase.i,v 0.40 02/05/87
  12. *
  13. *    Created by:    SDB
  14. *    Revised:    SDB (v 5.00 05/31/87)
  15. *            *---- Added meaningful alert numbers, revised macros,
  16. *            *---- updated ArpBase structure to reflect current state.
  17. *            *---- Added cheath's ASSIGN return codes as equates.
  18. *            *---- plus usual grunt work (revisions, lvo's, etc.)
  19. *            SDB (v6.04)
  20. *            cdh V7.0
  21. *            *---- added IntuiBase and GfxBase to ArpBase
  22. *            sdb V7.2
  23. *            *---- rearranged for more efficient lib code (ouch).
  24. *            *---- DosBase IntuiBase and GfxBase have *all* changed!
  25. *            *---- Few more alert #'s now get returned,
  26. *            *---- new GURU macro replaces provincial MYALERT.
  27. *            sdb v12 newstuff, see docs
  28. *            cdh V14    Added dos.library offsets, everybody moves!
  29. *            cdh V15 Added (volatile!) FindFirst etc offsets
  30. *            cdh V19 Added structs and constants for wildcards
  31. *            cdh V31 Final edit for V1.0 ARP 10/7/87
  32. *
  33. ***********************************************************************
  34. *
  35. *    Copyright (c) 1987, by Scott Ballantyne
  36. *
  37. *    The arp.library, and related code and files may be freely used
  38. *    by supporters of ARP.  Modules in the arp.library may not be
  39. *    extracted for use in independent code, but you are welcome to
  40. *    provide the arp.library with your work and call on it freely.
  41. *
  42. *    You are equally welcome to add new functions, improve the ones
  43. *    within, or suggest additions/removals.
  44. *
  45. *    BCPL programs are not welcome to call on the arp.library.
  46. *    The welcome mat is out to all others.
  47. ***********************************************************************
  48.  
  49.     IFND EXEC_TYPES_I
  50.     INCLUDE "exec/types.i"
  51.     ENDC !EXEC_TYPES_I
  52.  
  53.     IFND EXEC_LIBRARIES_I
  54.     INCLUDE "exec/libraries.i"
  55.     ENDC !EXEC_LIBRARIES_I
  56.  
  57.     IFND EXEC_LISTS_I
  58.     INCLUDE "exec/lists.i"
  59.     ENDC !EXEC_LISTS_I
  60.  
  61.     IFND EXEC_SEMAPHORES_I
  62.     INCLUDE    "exec/semaphores.i"
  63.     ENDC !EXEC_SEMAPHORES_I
  64.  
  65.     IFND LIBRARIES_DOS_I
  66.     INCLUDE "libraries/dos.i"
  67.     ENDC !LIBRARIES_DOS_I
  68.  
  69.  
  70.     STRUCTURE ArpBase,LIB_SIZE    ; Standard library node
  71.         ULONG    SegList        ; pointer to seglist of loaded library
  72.         UBYTE    Flags        ; See definitions below.
  73.         UBYTE    pad
  74.         LONG    AB_reserved    ; ArpLib's use only!!
  75.         CPTR    EnvBase        ; ptr to environment
  76.         ULONG    DosBase        ; Cached DosBase
  77.         ULONG    GfxBase        ; Cached GfxBase
  78.         ULONG    IntuiBase    ; Cached IntuitionBase
  79.         STRUCT    ResLists,MLH_SIZE ; Tracked Resources
  80.         LABEL    ArpLib_Sizeof
  81.  
  82. *--------------- Following is here only for compatibility with MANX,
  83. *--------------- don't use in new code!
  84.  
  85.     STRUCTURE EnvLib,LIB_SIZE    ; fake library for MANX
  86.         CPTR    EnvSpace    ; access only when Forbidden!
  87.         ULONG    EnvSize        ; size of environment
  88.         LABEL    EnvLib_Sizeof
  89.  
  90. *---------- Flags bit definitions
  91. *
  92. * NOTE:  You can check these, but better not change them!
  93. *     It is currently undetermined how these will be set, but they should
  94. *     only be set by the user, or by the startup code.  Possibly we could
  95. *     check for an environment variable.  This is likely to be the best idea.
  96. *
  97. * NOTE FOR THOSE WRITING LIBRARY CODE:
  98. *    Routines which use these flags to decide which escape or wildcards to
  99. *    use default to the BCPL version if neither one is set.  For consistancy,
  100. *    please observe the same convention in your code.
  101. *
  102. *-------------------------------------------------------
  103.  
  104.     BITDEF    ARP,WILD_WORLD,0    ; use Wildcards/escapes like rest of world
  105.     BITDEF    ARP,WILD_BCPL,1        ; use Wildcards/escapes like current dos.
  106.  
  107. *----------- Rest of library style stuff
  108.  
  109. ArpName    MACRO
  110.     dc.b    'arp.library',0
  111.     ds.w    0
  112.     ENDM
  113.  
  114. *---------- Current arp.library version.
  115.  
  116. ArpVersion EQU    31
  117.  
  118. *---------- Arp alert numbers, the cutesy BAD CODE one is gone.
  119. *---------- We will have to get these blessed by Amiga soon, or changed, or whatever.
  120.  
  121. *-------- Alert Object
  122.  
  123. AO_ArpLib    EQU    $00008036
  124.  
  125. *-------- Specific Alerts you can get when opening ArpLib. -----------*
  126. *-------  ONLY ARPLIB can return these, you should construct your own, preferably
  127. *-------  NON dead end alerts, for example, if you can't open ARP:
  128. *-------      MYALERT AG_OpenLib!AO_ArpLib
  129. *---------------------------------------------------------------------*
  130.  
  131. AN_ArpLib    EQU    $03600000
  132. AN_ArpNoMem    EQU    $03610000    ; Arplibrary out of memory.
  133. AN_ArpTaskArray    EQU    $83610001    ; No memory for task array
  134. AN_ArpInputMem    EQU    $03610002    ; No memory for input buffer.
  135. AN_ArpNoMakeEnv    EQU    $83610003    ; No memory for EnvLib
  136.  
  137. AN_ArpNoDOS    EQU    $83630001    ; Can't open DOS library
  138. AN_ArpNoGfx    EQU    $83630002    ; Can't open graphics
  139. AN_ArpNoIntuit    EQU    $83630003    ; Can't open intuition
  140.  
  141. AN_ArpObsFunc    EQU    $03600001    ; Call of obsolete function.
  142. AN_ArpScattered    EQU    $83600002    ; Scatter loading not allowed for lib.
  143. *--------
  144.  
  145. *---------- Tiny ALERT macro, assumes ExecBase is already in A6, also that you
  146. *---------- have nothing important in d7, also that you want to return immediately.
  147.  
  148. GURU    MACRO    * optional alert number
  149.     IFNC    '\1',''
  150.     move.l    #\1,D7
  151.     ENDC
  152.     jmp    _LVOAlert(a6)
  153.     ENDM
  154.  
  155. MYALERT    MACRO * ancient compatibility
  156.     GURU    \1
  157.     ENDM
  158.  
  159. *------------- Library Vector Offsets.
  160.  
  161.  
  162. *
  163. * This macro is used to define the DOS offsets without redefining the symbols-
  164. *    To get the DOS symbols, INCLUDE dos_lib.i
  165. *
  166. LIBSKP    MACRO
  167. COUNT_LIB   SET     COUNT_LIB-LIB_VECTSIZE
  168.     ENDM
  169.  
  170.     LIBINIT
  171.  
  172.     LIBSKP    _LVOOpen
  173.     LIBSKP    _LVOClose
  174.     LIBSKP    _LVORead
  175.     LIBSKP    _LVOWrite
  176.     LIBSKP    _LVOInput
  177.     LIBSKP    _LVOOutput
  178.     LIBSKP    _LVOSeek
  179.     LIBSKP    _LVODeleteFile
  180.     LIBSKP    _LVORename
  181.     LIBSKP    _LVOLock
  182.     LIBSKP    _LVOUnLock
  183.     LIBSKP    _LVODupLock
  184.     LIBSKP    _LVOExamine
  185.     LIBSKP    _LVOExNext
  186.     LIBSKP    _LVOInfo
  187.     LIBSKP    _LVOCreateDir
  188.     LIBSKP    _LVOCurrentDir
  189.     LIBSKP    _LVOIoErr
  190.     LIBSKP    _LVOCreateProc
  191.     LIBSKP    _LVOExit
  192.     LIBSKP    _LVOLoadSeg
  193.     LIBSKP    _LVOUnLoadSeg
  194.     LIBSKP    _LVOGetPacket
  195.     LIBSKP    _LVOQueuePacket
  196.     LIBSKP    _LVODeviceProc
  197.     LIBSKP    _LVOSetComment
  198.     LIBSKP    _LVOSetProtection
  199.     LIBSKP    _LVODateStamp
  200.     LIBSKP    _LVODelay
  201.     LIBSKP    _LVOWaitForChar
  202.     LIBSKP    _LVOParentDir
  203.     LIBSKP    _LVOIsInteractive
  204.     LIBSKP    _LVOExecute
  205. ***
  206.     LIBDEF    _LVOPrintf        ; Print formatted data on current output.
  207.     LIBDEF    _LVOFPrintf        ; Print formatted data on file.
  208.     LIBDEF    _LVOPuts        ; Print string\n on stdout.
  209.     LIBDEF    _LVOReadLine        ; Get a line from stdin.
  210.     LIBDEF    _LVOGADS        ; Get args using template
  211.     LIBDEF    _LVOAtol        ; Convert Ascii to long int.
  212.     LIBDEF    _LVOEscapeString    ; Handle escapes in string.
  213.     LIBDEF    _LVOCheckAbort        ; Check for CNTRL-C
  214.     LIBDEF    _LVOCheckBreak        ; Check for CNTRL c d e or f
  215.     LIBDEF    _LVOGetenv        ; Get value of environment variable
  216.     LIBDEF    _LVOSetenv        ; Set value of environment variable
  217.     LIBDEF    _LVOFileRequest        ; Filename Requester
  218.     LIBDEF    _LVOCloseWindowSafely    ; Closes shared IDCMP window w/o GURU
  219.     LIBDEF    _LVOCreatePort        ; Create a message port
  220.     LIBDEF    _LVODeletePort        ; Delete a message port
  221.     LIBDEF    _LVOSendPacket        ; Send a dos packet
  222.     LIBDEF    _LVOInitStdPacket    ; initialize a standard packet
  223.     LIBDEF    _LVOPathName        ; Return Complete pathname of file/directory.
  224.     LIBDEF    _LVOAssign        ; Assign a logical device name
  225.     LIBDEF    _LVODosAllocMem        ; DOS compatible memory allocator
  226.     LIBDEF    _LVODosFreeMem        ; DOS compatible memory free-er
  227.     LIBDEF    _LVOBtoCStr        ; Copy a BCPL string to C string
  228.     LIBDEF    _LVOCtoBStr        ; Copy a C string to BCPL string
  229.     LIBDEF    _LVOGetDevInfo        ; Get pointer to head of DevInfo
  230.     LIBDEF    _LVOFreeTaskResList    ; Free Tracked resources for this task
  231.     LIBDEF    _LVOArpExit        ; Exit, freeing tracked resources.
  232.     LIBDEF    _LVOArpAlloc        ; Allocate memory with tracking
  233.     LIBDEF    _LVOArpAllocMem        ; Track AllocMem allocation
  234.     LIBDEF    _LVOArpOpen        ; Track open files
  235.     LIBDEF    _LVOArpDupLock        ; Track duped locks
  236.     LIBDEF    _LVOArpLock        ; Track allocated locks
  237.     LIBDEF    _LVORListAlloc        ; Like ArpAlloc for free reslist
  238.     LIBDEF    _LVOFindCLI        ; Get a process given a task number
  239.     LIBDEF    _LVOQSort        ; Quick Sort
  240.  
  241.     LIBDEF    _LVOPatternMatch    ; Match a string with a pattern (wildcards!)
  242.     LIBDEF    _LVOFindFirst        ; Search directory w/wildcards
  243.     LIBDEF    _LVOFindNext        ; Continue search w/wildcards
  244.     LIBDEF    _LVOFreeAnchorChain    ; Free mem from FindFirst/Next
  245.  
  246.     LIBDEF    _LVOCompareLock        ; Compare two disk locks
  247.  
  248.     LIBDEF    _LVOFindTaskResList    ; Find resource list for this task
  249.     LIBDEF    _LVOCreateTaskResList     ; Create a new nested task reslist
  250.     LIBDEF    _LVOFreeResList        ; Free an un-attached reslist
  251.     LIBDEF    _LVOFreeTrackedItem    ; Free a tracked item
  252.     LIBDEF    _LVOGetTracker        ; Get a tracker node
  253.  
  254.     LIBDEF    _LVOGetAccess        ; Lock access to a node
  255.     LIBDEF    _LVOFreeAccess        ; Allow resource to flush if lowmem
  256.  
  257.     LIBDEF    _LVOFreeDAList        ; Free a DosAllocmem list
  258.     LIBDEF    _LVOAddDANode        ; Add a node to a DA list
  259.     LIBDEF    _LVOAddDADevs        ; Add devices to a DA list
  260.  
  261.     LIBDEF    _LVOStrcmp        ; Compare two null-terminated strs
  262.     LIBDEF    _LVOStrncmp        ; Compare up to N chars
  263.     LIBDEF    _LVOToupper        ; Convert to UC
  264.     LIBDEF    _LVOSyncRun        ; Run program as subroutine
  265.  
  266. ***
  267.  
  268. *---------- Return codes you can get from calling Assign:
  269.  
  270. ASSIGN_OK    EQU    0
  271. ASSIGN_NODEV    EQU    1
  272. ASSIGN_FATAL    EQU    2
  273. ASSIGN_CANCEL    EQU    3    ; Can't cancel a VOLUME
  274.  
  275. *--------- Size of buffer you need for ReadLine
  276.  
  277. MaxInputBuf    EQU    256
  278.  
  279. *--------- Input structure for File Requester
  280. FRB_DoWildFunc    equ    7
  281. FRB_DoMsgFunc    equ    6
  282.  
  283. FCHARS    equ    32            ; Directory name sizes
  284. DSIZE    equ    33
  285.  
  286. * SET ALL OTHER FLAGS TO NULL -
  287. *    They will be used in later revs of Arp.library.
  288. *    If you set them non-null, they will do something besides default.
  289. *    You may not be set up for it.
  290.  
  291.     STRUCTURE    FR_struct,0
  292.     APTR    FR_Hail            ; Hailing text
  293.     APTR    FR_Ddef            ; *Filename array (FCHARS+1)
  294.     APTR    FR_Ddir            ; *Directory array (DSIZE+1)
  295.     APTR    FR_Wind            ; Window requesting or NULL
  296.     SHORT    FR_Flags        ; Control. See above. SET TO NULL.
  297.     APTR    FR_WildFunc        ; Func to call for wildcards
  298.     APTR    FR_MsgFunc        ; Func to call with IntuiMessages
  299.  
  300. *---------- Structures and constants used by the wildcard routines
  301.  
  302. P_ANY        EQU    $80
  303. P_SINGLE    EQU    $81
  304. P_ORSTART    EQU    $82
  305. P_ORNEXT    EQU    $83
  306. P_OREND        EQU    $84
  307. P_TAG        EQU    $85
  308. P_TAGEND    EQU    $86
  309. P_NOTCLASS    EQU    $87
  310. P_CLASS        EQU    $88
  311. P_REPBEG    EQU    $89
  312. P_REPEND    EQU    $8A
  313. COMPLEX_BIT    EQU    1
  314. EXAMINE_BIT    EQU    2
  315.  
  316. ERROR_BUFFER_OVERFLOW    EQU    303
  317. ERROR_INTERNAL    EQU    999
  318. ERROR_BREAK    EQU    304
  319. BUFSIZ        EQU    200
  320. DOS_TRUE    EQU    0
  321. DOS_FALSE    EQU    -1
  322. MAXFNAME    EQU    200
  323.  
  324.  
  325. * This is the structure you pass to FindFirst/FindNext.
  326. * In it you can set AP_BREAKBITS to be the bits you want to match
  327. * for break checking while the directory is being searched.
  328. * Also you may allocate a buffer at AP_BUF, the size of which is
  329. * in AP_LENGTH, where the full path name of the current entry will
  330. * be built.  If AP_LENGTH is 0, the path name will not be built.
  331.  STRUCTURE AP,0
  332.     APTR    AP_BASE
  333.     APTR    AP_LAST
  334.     LONG    AP_BREAKBITS
  335.     LONG    AP_FOUNDBREAK
  336.     APTR    AP_LENGTH
  337.     STRUCT    AP_INFO,fib_SIZEOF
  338.     LABEL   AP_BUF
  339.     LABEL   AP_SIZEOF
  340.  
  341.  STRUCTURE AN,0
  342.     APTR    AN_NEXT
  343.     APTR    AN_PRED
  344.     LONG    AN_LOCK
  345.     APTR    AN_INFO
  346.     LONG    AN_STATUS
  347. ;            Text must be longword aligned for passing to dos
  348.     WORD    AN_TEXT        ;Account for
  349.     LABEL   AN_SIZEOF
  350.  
  351.  
  352. * Structure used by AddDANode, AddDADevs, FreeDAList
  353. *    This structure is used to create lists of names,
  354. * which normally are devices, assigns, volumes, files, or directories
  355.  STRUCTURE    DirectoryEntry,0
  356.     LONG    DA_Next
  357.     BYTE    DA_Type
  358.     BYTE    DA_Flags
  359.     LABEL    DA_Stuff
  360.  LABEL    DE_SIZEOF
  361.  
  362. DLB_DEVICES    equ    0
  363. DLB_DISKONLY    equ    1        ; If only DISK devices
  364. DLB_VOLUMES    equ    2
  365. DLB_DIRS    equ    3
  366.  
  367. DLX_FILE    equ    0
  368. DLX_DIR        equ    8
  369. DLX_DEVICE    equ    16
  370.  
  371. DLX_VOLUME    equ    24
  372. DLX_UNMOUNTED    equ    32
  373.  
  374. DLX_ASSIGN    equ    40
  375.  
  376. ************************************************************************
  377. *
  378. * ResLists
  379. *    This list is used to track resources, normally within a Task.
  380. * Each ResList has a single-linked node linking together ResLists;  this
  381. * list is maintained in ArpBase now but ideally would use TC_UserData,
  382. * so the ResList for a task could be found more quickly.  However, there
  383. * must also be a link so ResLists can be maintained in ArpBase, for
  384. * Resource Tracking.  To facilitate this at a later data, we have
  385. * added the ReservedList field, which could be used if ArpBase gets
  386. * burned into ROM.
  387. *
  388. * NOTE: This is a DosAllocMem'd list, with length @-4
  389.     STRUCTURE ArpResList,0
  390.     STRUCT    ARL_node,MLN_SIZE    ; Links these together
  391.     LONG    TaskID
  392.     STRUCT    FirstItem,MLH_SIZE
  393.     APTR    ARL_link        ; For temp removal from task rlist
  394.     LABEL    RL_SIZEOF
  395.  
  396. * Tracked Items
  397. *    Each item in the list has a double-link node which is used to
  398. * attach to the FirstItem list header in a ResList.  All list items are
  399. * based on a simple memory allocation; the generic node is a DosAllocMem'd
  400. * memory block set to all NULL for the control fields.  This makes it very
  401. * easy to track the nodes themselves, in case there is a problem during
  402. * allocation.
  403.     STRUCTURE TrackedResource,0
  404.     STRUCT    TR_Node,MLN_SIZE    ; Double linked pointer
  405.     BYTE    TR_Flags        ; See flag bits below
  406.     BYTE    TR_Lock            ; Used by GetAccess/FreeAccess
  407.     SHORT    TR_ID            ; ID for this item class
  408.     APTR    TR_Stuff        ; Whatever the dude wants to free.
  409.     LONG    TR_Extra        ; Unused now, even to memchunk size
  410.     LABEL    TR_SIZEOF
  411.  
  412. *    The function "GetTracker" will allocate a generic tracking node,
  413. * which is a minimum-sized memory block passed back to the user.
  414. * The pointer the user gets actually points at the TR_Stuff node,
  415. * rather than at the head of the list.  The user-accessible fields are
  416. * below:
  417.     STRUCTURE UserResource,-2
  418.     SHORT    TRU_ID
  419.     APTR    TRU_Stuff
  420.     LONG    TRU_Extra
  421.  
  422. * See discussion of the TRU_Extra field below; it is always allocated
  423. * because the minimum memory grain size is 8 bytes, and this extra
  424. * field actually does not require any extra memory.
  425.  
  426.  
  427. * Tracked Item Types
  428. *    The id types below show the types of resources which may
  429. * be tracked in a resource list.
  430. TRAK_AAMEM    equ    0        ; Default generic (ArpAlloc) element
  431. TRAK_LOCK    equ    1        ; File Lock
  432. TRAK_FILE    equ    2        ; Opened File
  433. TRAK_WINDOW    equ    3        ; Window (see discussion)
  434. TRAK_SCREEN    equ    4        ; Screen
  435. TRAK_LIBRARY    equ    5        ; Opened library
  436. TRAK_DAMEM    equ    6        ; Pointer to DosAllocMem block
  437. TRAK_MEMLIST    equ    7        ; Exec Memlist
  438. TRAK_SEGLIST    equ    8        ; Program Segment List
  439. TRAK_RESLIST    equ    9        ; ARP (nested) ResList
  440. TRAK_MEM    equ    10        ; Memory ptr/length
  441. TRAK_GENERIC    equ    11        ; Generic Element
  442. TRAK_DALIST    equ    12        ; DAlist ( as used by file request )
  443. TRAK_ANCHOR    equ    13        ; Anchor chain
  444. TRACK_MAX    equ    13        ; Anything else is tossed.
  445.  
  446. * For TRAK_GENERIC, you set up a task function to be called when
  447. * an item is freed.  This is very dangerous if not used properly.
  448. * PROGRAMMER BEWARE.  ( If you leave a relist untracked, too bad )
  449.  
  450. TG_FuncAddr    equ    TR_Extra
  451. TG_VALUE    equ    TR_Stuff
  452.  
  453. * For TRAK_WINDOW, set the TW_OTHER field if this window shares a msgport
  454. * and the msgport should not be freed
  455. TW_WINDOW    equ    TR_Extra
  456.  
  457. * NOTE - THINGS IN THIS LIST MUST NOT DEPEND ON THE TASK STILL EXISTING
  458. * Thus, no DeletePort or RemTask.  This is to allow a Flush executable
  459. * to be created which will go throug all of the Tracked list, and for
  460. * tasks that exited improperly, free the resources.
  461.  
  462. * Special Considerations
  463. *    The TR_Lock and TR_Flags bytes have special meaning.  These
  464. * are internally managed fields, which should not be touched by the
  465. * application.
  466. *    The TR_Lock field is managed by GetAccess/FreeAccess.  If
  467. * this field is -1, the resource being tracked may be freed at will
  468. * by the
  469.  
  470. TRB_UNLINK    equ    7        ; Bit for freeing the node
  471. TRB_RELOC    equ    6        ; This element may be relocated!!!
  472.                     ; ( This bit is not used yet )
  473. TRB_MOVED    equ    5        ; Bit set if the item moved.
  474.  
  475. TRV_UNLINK    equ    1<<TRB_UNLINK
  476. TRV_RELOC    equ    1<<TRB_RELOC
  477. **************************************************************************
  478.  
  479. *---------- handy macros
  480.  
  481. LINKEXE    MACRO
  482.     LINKLIB    _LVO\1,4
  483.     ENDM
  484.  
  485. * LINKDOS now uses ArpBase
  486. * CALLDOS was nuked, to reduce confusion
  487.  
  488. LINKDOS    MACRO
  489.     jsr    _LVO\1(a6)
  490.     ENDM
  491.  
  492. CALLEXE    MACRO
  493.     move.l    4,a6
  494.     jsr    _LVO\1(a6)
  495.     ENDM
  496.  
  497. * SYSCALL re-revised for only one arg
  498. *    DosBase should always use ArpBase, or DosBase, in A6
  499.  
  500. SYSCALL    MACRO
  501.     CALLLIB    _LVO\1
  502.     ENDM
  503.  
  504.     ENDC    !LIBRARIES_ARPBASE_I
  505.