* MultiPlayer
* Copyright (C) 1992 Bryan Ford
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* I (the author of MultiPlayer) can be contacted on the Internet at
* "bryan.ford@m.cc.utah.edu".  See "Player.doc" for other addresses.
*
* $Id: globals.asm,v 4.2 92/06/21 11:14:16 BAF Exp Locker: BAF $
*

        include "bry/macros.i"

*** Globals macros
defrefs macro
        ifnc    '','\1'
        defrefs \2,\3,\4,\5,\6,\7,\8,\9,\10
        xref    \1
        dc.l    \1
        endc
        endm

globmrt macro   ; routine1,routine2,...
        defrefs \1,\2,\3,\4,\5,\6,\7,\8,\9,\10
        endm

globrt  macro   ; routine1,routine2,...
        cnop    0,4
        dc.l    0
        defrefs \1,\2,\3,\4,\5,\6,\7,\8,\9,\10
        endm

glob    macro   ; name
        xdef    \1,_\1
\1:
_\1:
        endm    ; Define actual variable right afterwards...

globb   macro   ; name,value,routine1,routine2,...
        glob    \1
        dc.b    \2
        endm

globw   macro   ; name,value,routine1,routine2,...
        glob    \1
        dc.w    \2
        endm

globl   macro   ; name,value,routine1,routine2,...
        glob    \1
        dc.l    \2
        endm

globu   macro   ; name,value,routine1,routine2,...
        glob    \1
        ds.b    \2
        endm

        code    text

*** GlobSetByte - Set a byte global, calling the PreMod and PostMod routines
* a0 = Pointer to byte global
* d0 = New value for global
* a1 = Pointer to routine NOT to call (or 0 to call all routines)
        xdef    GlobSetByte,_GlobSetByte
_GlobSetByte
        move.l  4(sp),a0
        move.l  8(sp),d0
        move.l  12(sp),a1
GlobSetByte
        movem.l d0/a0-a1,-(sp)
        bsr.b   GlobPreMod
        movem.l (sp)+,d0/a0-a1
        move.b  d0,(a0)
        bra.b   GlobPostMod

*** GlobSetWord - Set a word global, calling the PreMod and PostMod routines
* a0 = Pointer to word global
* d0 = New value for global
* a1 = Pointer to routine NOT to call (or 0 to call all routines)
        xdef    GlobSetWord,_GlobSetWord
_GlobSetWord
        move.l  4(sp),a0
        move.l  8(sp),d0
        move.l  12(sp),a1
GlobSetWord
        movem.l d0/a0-a1,-(sp)
        bsr.b   GlobPreMod
        movem.l (sp)+,d0/a0-a1
        move.w  d0,(a0)
        bra.b   GlobPostMod

*** GlobSetLong - Set a longword global, calling the PreMod and PostMod routines
* a0 = Pointer to longword global
* d0 = New value for global
* a1 = Pointer to routine NOT to call (or 0 to call all routines)
        xdef    GlobSetLong,_GlobSetLong
_GlobSetLong
        move.l  4(sp),a0
        move.l  8(sp),d0
        move.l  12(sp),a1
GlobSetLong
        movem.l d0/a0-a1,-(sp)
        bsr.b   GlobPreMod
        movem.l (sp)+,d0/a0-a1
        move.l  d0,(a0)
        bra.b   GlobPostMod

*** GlobPreMod - Call the appropriate set of routines before modifying a global
* a0 = Pointer to global variable
* a1 = Pointer to routine NOT to call (or 0 to call all routines)
        xdef    GlobPreMod,_GlobPreMod
_GlobPreMod
        move.l  4(sp),a0
        move.l  8(sp),a1
GlobPreMod
        tst.l   -(a0)
        bne.b   GlobPreMod
        bra.b   GlobPostMod

*** GlobPostMod - Call the appropriate set of routines after a global has been modified
* a0 = Pointer to global variable
* a1 = Pointer to routine NOT to call (or 0 to call all routines)
        xdef    GlobPostMod,_GlobPostMod
_GlobPostMod
        move.l  4(sp),a0
        move.l  8(sp),a1
GlobPostMod
        movem.l d2/a2-a3,-(sp)
        move.l  a0,a3
        move.l  a1,d2
        bra.b   \next
\do
        cmp.l   d0,d2
        beq.b   \next
        move.l  d0,a2
        move.l  d2,a0
        jsr     (a2)
\next
        move.l  -(a3),d0
        bnz.b   \do
        movem.l (sp)+,d2/a2-a3
        rts

        data    __MERGED

        globrt  _progwinlistdetach
        globrt  _progwinlistattach
        glob    modlist
        dc.l    modlist+4
        dc.l    0
        dc.l    modlist

        globrt
        globrt  _programcurmodchanged,_settingswinupdate,_windowsettingsupdate
        globu   curmod,4

        globrt
        globrt  _programcurmodchanged,_settingswinupdate,_windowsettingsupdate,_progwinselmod
        globu   selmod,4

        globrt
        globrt  playervolume,_programsettingschanged
        globw   volume,-1               ; Module volume 0-100, -1 if disabled
        globw   balance,0               ; Module balance -50-50

        globrt
        globrt  playerspeed,_programsettingschanged
        globw   speed,0                 ; Module speed, 10-200, 50=normal, 0 if disabled

        globrt
        globrt  _programsettingschanged
        globb   modflags,0              ; Copy of ModNode.flags

* filter: -1=disabled, 0=module, 1=off, 2=on
        globrt
        globrt  ptfilter,_programsettingschanged
        globb   filter,-1

* prefsglob - Triggered any time the preferences are changed
        globrt
        globrt  _prefswinupdate,_mainprefschanged,_gui_flashywinopenclose
        globmrt _windowsettingsupdate,playervolume,playerspeed
        glob    prefsglob

        end
