  NOLIST

*
* system.i - bm2detach support stuff...module specific constants, macros, etc
*            *** This file copyright 1991 by Anthon Pang ***
*


*
* Symbols controlling conditional assembly
*      Comment them out to turn disable code production...
*      changing the value is simply not enough.
*
DETACH  SET 1   ; CLI detaching code
SAVEDIR SET 1   ; (complements DETACH) find current directory before detaching


*
* Constants
*
; exec.library LVO offsets
FindTask     equ -$0126
OpenLibrary  equ -$0228
CloseLibrary equ -$019e
Forbid       equ -$0084
Permit       equ -$008a
ReplyMsg     equ -$017a
WaitPort     equ -$0180
GetMsg       equ -$0174
AllocMem     equ -$00c6
FreeMem      equ -$00d2

; dos.library LVO offsets
Open       equ -$001e
Close      equ -$0024
CurrentDir equ -$007e
DupLock    equ -$0060
UnLock     equ -$005a
CreateProc equ -$008a
Input      equ -$0036
Output     equ -$003c

; structure offsets           ; structure
prCLI             equ $00ac ; Process (CLI for this process)
prStackSize       equ $0084 ; Process (stack size in bytes)
prMsgPort         equ $005c ; Process (also, size of Task)
prConsoleTask     equ $00a4 ; Process (console handler process)
prSegList         equ $0080 ; Process (array of seg lists used)
fhType            equ $0008 ; FileHandle (port to do PutMsg to)
wbArgPtr          equ $0024 ; WBStartup (arguments to WB launched process)
waLock            equ $0000 ; WBArg (lock descriptor (BPTR))
waName            equ $0004 ; WBArg (name of WB launched process)
Task_tcNode_lnPri equ $0009 ; Task (node priority => task priority)
Task_tcMemEntry   equ $004a ; Task (allocated memory)
cliCommandName    equ $0010 ; CommandLineInterface (name of current command)
cliDefaultStack   equ $0034 ; CommandLineInterface (stack size in longwords)
cliModule         equ $003c ; CommandLineInterface (seglist of current command)
ml_numEntries     equ $000e ; MemList (number of MemEntry's in structure)
ml_ME             equ $0010 ; MemList (first MemEntry)
lhTail            equ $0004 ; List (field value is always NIL)
lnPred            equ $0004 ; Node (ptr to previous node in list)

; other constants
LIBRARY_MINIMUM equ $0021     ; KS 1.2 (v33)
FAIL            equ $0014     ; complete/severe/fatal error
ModeOldFile     equ $000003ed ; read/write


*
* Macro(s)
*
; generic code to open library
;   assumes <Register> loaded with pointer to _LVOOpenLibrary(a6)
;   example: lea _LVOOpenLibrary(a6),a2
Open_Library MACRO <Lib_Name>,<Lib_Base>,<Register>
                              ; example
     moveq   #$00,d0
     lea     \1(pc),a1        ; lea MathFFPName(pc),a1
     jsr     (\3)             ; jsr (a2)
     move.l  d0,\2(a4)        ; move.l d0,Sys_MathBase(a4)

  ENDM

* Glue code for single long parameter procedure call (Long1 : d0)
SINGLE_PARAM_STUB MACRO <Procedure_Name>,<LVO>
    PARAMETER_LIST 4,0  ; FYI: this offset is not used
    END_PARAMETER_LIST

    PROCEDURE_CODE \1
      move.l  (a7)+,d1                  ; get return address
      move.l  (a7),d0                   ; get Long1
      move.l  d1,(a7)                   ; store return address
      movea.l MODULE_BASE+Sys_MathBase(pc),a6
      jmp     \2(a6)                    ; call library routine
  ENDM

* Glue code for single long parameter procedure call (Long1 : d0, Long2 : d1)
* Long1, Long2 pushed on to stack in that order when this stub called
DOUBLE_PARAM_STUB MACRO <Procedure_Name>,<LVO>
    PARAMETER_LIST 4,0   ; FYI: these offsets are not used
    END_PARAMETER_LIST

    PROCEDURE_CODE \1
      move.l  (a7)+,a0                  ; get return address
      move.l  (a7)+,d1                  ; get Long1
      move.l  (a7),d0                   ; get Long2
      move.l  a0,(a7)                   ; store return address
      movea.l MODULE_BASE+Sys_MathBase(pc),a6
      jmp     \2(a6)                    ; call library routine
  ENDM

  LIST
