* 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 3.1 92/05/25 07:52:42 BAF Exp $
*

*** 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

        xdef    GlobSetByte,@GlobSetByte
        xdef    GlobSetWord,@GlobSetWord
        xdef    GlobSetLong,@GlobSetLong
        xdef    GlobPreMod,@GlobPreMod
        xdef    GlobPostMod,@GlobPostMod

        xref    ResCall

*** 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)
GlobSetByte
@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)
GlobSetWord
@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)
GlobSetLong
@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)
GlobPreMod
@GlobPreMod
        tst.l   -(a0)
        bne.b   GlobPreMod
        ; fall through...
*** 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)
GlobPostMod
@GlobPostMod
        movem.l d2/a2-a3,-(sp)
        move.l  a0,a3
        move.l  a1,d2
        bra.b   \next
\isjmp
        move.l  2(a2),d0
\do
        cmp.l   d0,d2
        beq.b   \next
        move.l  d0,a2
        cmp.w   #$4ef9,(a2)
        beq.b   \isjmp
        move.l  d2,a0
        bsr     ResCall
\next
        move.l  -(a3),d0
        bne.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,@flashywinopenclose
        globmrt @windowsettingsupdate,playervolume,playerspeed
        glob    prefsglob

        end
