; midi/midibase.i

; midi.library MidiBase & related definitions (not for the casual midi user)

	ifnd	MIDI_MIDIBASE_I
MIDI_MIDIBASE_I set 1

	ifnd	EXEC_LIBRARIES_I
	include "exec/libraries.i"
	endc

	ifnd	EXEC_SEMAPHORES_I
	include "exec/semaphores.i"
	endc

	ifnd	LIBRARIES_DOS_I
	include "libraries/dos.i"
	endc

	ifnd	MIDI_MIDI_I
	include "midi/midi.i"
	endc


    STRUCTURE	MidiBase,LIB_SIZE	; Library Base
	STRUCT	ml_SourceList,LH_SIZE	    ; Source List
	STRUCT	ml_DestList,LH_SIZE	    ; Dest List

	STRUCT	ml_ListSemaphore,SS_SIZE    ; locks source/dest lists - blocks Src & Dst list management
					    ; (locked when LockBase is called)
	STRUCT	ml_RouteSemaphore,SS_SIZE   ; locks routes - blocks msg routing & RPList management in Src & Dst
	ULONG	ml_SegList		    ; Segment List for the library
	APTR	ml_SysBase		    ; SysBase
	APTR	ml_DosBase		    ; DosBase
	STRUCT	ml_SignalList,MLH_SIZE	    ; list of MListSignal's
	STRUCT	ml_PacketPool,MLH_SIZE	    ; memory pool
	UWORD	ml_RouteCount		    ; total number of MRoutes open

	LABEL	sizeof_MidiBase


    STRUCTURE	MTaskInfo,0 ; Task info structure for Resident Nodes
	APTR	ti_Name 	; Process Name
	WORD	ti_Pri		; Process Priority
	APTR	ti_Entry	; Entry point
	UWORD	ti_Stack	; Stack Size

	UWORD	ti_Sources	; source count
	APTR	ti_SourceList	; source list
	UWORD	ti_Dests	; dest count
	APTR	ti_DestList	; dest list

	STRUCT	ti_Semaphore,SS_SIZE	; signal semaphore for locking this task

	UWORD	ti_UsageCount
	APTR	ti_TaskPort	; task's MsgPort
	BPTR	ti_Segment	; BPTR pointer to tasks segment
	LABEL	sizeof_MTaskInfo


    STRUCTURE	MNodeInfo,0 ; Resident Node info structure
	APTR	ni_Name 	; Node Name
	APTR	ni_Image	; Node Image
	APTR	ni_Node 	; Node pointer
	LABEL	sizeof_MNodeInfo


	; packet array

PA_PACKETS     equ 256
PA_BITMAPSIZE  equ PA_PACKETS/8 	; must be divisible by 4

    STRUCTURE	PacketArray,MLN_SIZE
	STRUCT	pa_BitMap,PA_BITMAPSIZE 		; availability bit map
	STRUCT	pa_Packets,PA_PACKETS*sizeof_MidiPacket ; array of MidiPackets
	LABEL	sizeof_PacketArray

mp_PacketArray	equ LN_NAME		; points to PacketArray that contains this MidiPacket
mp_PacketIndex	equ MN_LENGTH		; index (not offset) of MidiPacket w/i PacketArray

; pa_Packets are allocated from low to high address.
; ExecMsg in each packet gets used as follows:
;	LN_NAME points to PacketArray in which MidiPacket exists
;	MN_LENGTH contains index (not offset) of Packet w/i PacketArray

; pa_BitMap bytes are allocated from low to high address, bits are allocated
; right to left (everything proceeds in a low to high addressing order).

; pa_BitMap[0], bit #0 corresponds to pa_Packets[0]
; pa_BitMap[31], bit #7 corresponds to pa_Packet[255]

; bits in BitMap contain 1 for available, 0 for in use

	endc
