*       Make standard Cookie Jar
*       (c) 1991 Mathew Lodge

_p_cookies equ  $5A0            Cookie jar pointer

dos     equ     1
xbios   equ     14

Pterm0  equ     $00
Cconws  equ     $09
Ptermres equ    $31

Supexec equ     38


start:
        bra     GO

standard_jar:
        dc.l    '_CPU',0
        dc.l    '_VDO',0
        dc.l    '_SND',1
        dc.l    '_MCH',0
        dc.l    0,8
        dc.l    0,0
        dc.l    0,0
        dc.l    0,0

GO:
        move.l  a7,a5
        move.l  #stack,sp       Set up our stack
        move.l  4(a5),basepage  Get address of basepage
        pea     inst_jar
        move.w  #Supexec,-(sp)
        trap    #xbios          Execute routine in super mode
        addq.l  #6,sp

        tst.w   success         Jar installed?
        beq     TSR             Terminate and Stay Resident

        move.w  #Pterm0,-(sp)   Otherwise, normal termination
        trap    #1

TSR     move.l  basepage,d0     Address of basepage
        move.l  #GO,d1          End of resident data
        sub.l   d0,d1           Calculate size of resident block
        move.l  d1,-(sp)        The amount of memory to save
        move.w  #Ptermres,-(sp)
        trap    #dos            Terminate and Stay Resident

inst_jar:
        move.l  _p_cookies,d0
        bne     already_jar     Jar installed?
        move.l  #standard_jar,_p_cookies       Install jar
        clr.w   success         Indicate success
        rts

already_jar:
        lea     already_jarm,a1 Jar installed message
        bsr     print_stg
        move.w  #1,success      Unsuccessful
        rts
        
print_stg:
        move.l  a1,-(sp)
        move.w  #Cconws,-(sp)   Print to screen
        trap    #dos
        addq.l  #6,sp
        rts

        cnop    0,4             Word align     
basepage:
        ds.l    1
success ds.w    1

already_jarm:
        dc.b    'Cookie Jar already installed',13,10,0
        
        ds.l    99
stack   ds.l    1

        END
