*************************************************************** * * * Program AddMessage 1.0 * * Author Kelvin Sherlock * * Date May 1997 * * Compiler Orca/M * * * * Copyright 1997. All Rights reserved. * * * * * *************************************************************** mcopy addmsg.mac copy 13/ainclude/e16.finder copy 13/ainclude/e16.locator * dp stuff during the request handler result gequ $0E reqCode gequ $0C dataIn gequ $08 dataOut gequ $04 Startup start using Globals phb phk plb sta MyID ;;A has ID on entry pha _QDVersion pla and #$0fff cmp #$0307 bcc bad_env ~AcceptRequests #MyStr,MyID,#ReqProc plb rtl bad_env anop ;tell loader to unload us plb lda 4,S bne quit_now ora #$0001 sta 4,S quit_now rtl startup end ************************************* Globals data codeTable anop dc i2'srqGoAway,DoGoAway' dc i2'finderSaysHello,DoHello' dc i2'finderSaysGoodbye,DoGoodbye' dc i2'finderSaysSelectionChanged,DoIconChange' dc i2'finderSaysExtrasChosen,DoExtras' codeTableEnd anop MyStr pstr 'Kelvin~AddMesssage~' FStr pstr 'Apple~Finder~' MTitle pstr 'Add Message' MyMenu dc i2'$8000' dc i2'0' dc c'~' ;apple-tilde dc c'`' dc i2'0' dc i2'0' dc i4'MTitle' MyID ds 2 MenuID ds 2 FindRes ds 20 ;space for finder result Globals end ReqProc start *************************************************************** * This is our request handler * * entry exit * |--------------------| |--------------------| * | result | 14,S | result | * |--------------------| |--------------------| * | request code | 12,S | RTL (3 bytes) | * |--------------------| |- -| * | dataIn | | | * |- -| |--------------------| * | | 8,S sp * |--------------------| * | dataOut | * |- -| * | | 4,S * |--------------------| * | RTL (3 bytes) | * |- -| * | | 1,S * |--------------------| * sp * *************************************************************** using Globals tsc phd ; save old dpage tcd ; set dpage phb phk ; set db plb lda reqCode ldx #codeTableEnd-codeTable-4 next cmp codeTable,x ; are we handling this code? beq dispatch dex dex dex dex bpl next bra QuitNow dispatch anop jsr (codeTable+2,x) ; call the handler * result is prezeroed, so I just restore the old dp and * fix the stack to deny a request QuitNow anop lda $1 ;;fix rtl address sta $0B lda $2 sta $0C plb pld ;;restore dp tsc ;;fix the stack clc adc #10 tcs rtl ReqProc end **************************************************** * * * The following procs are jsr'd to and have the * * direct page set up with Result, DataIn, DataOut, * * and ReqCode. * * * **************************************************** * Procedure DoHello start * our response to FinderSaysHello: Tell Finder to add our menu * using globals pea tellFinderAddToExtras pea stopAfterOne+sendToName pea Fstr|-16 pea Fstr pea MyMenu|-16 pea MyMenu pea FindRes|-16 pea FindRes _SendRequest bcs err lda FindRes+4 ;menuItemId sta MenuID pha _DisableMItem ;for now lda #$8000 sta result ;tell finder we took care of it err anop rts DoHello end * Procedure DoGoodbye start * our response to FinderSaysGoodbye: kill our menu * using Globals pea tellFinderRemoveFromExtras pea stopAfterOne+sendToName pea Fstr|-16 pea Fstr pea 0 lda MenuID pha pea FindRes|-16 pea FindRes _SendRequest stz MenuID lda #$8000 sta result ;tell finder we took care of it rts DoGoodbye end DoExtras start using globals lda dataIn cmp MenuID beq DoWork rts ;if somebody else * * These are the d-page values during this part of the procedure * * msghndl equ 1 ;4 msgptr equ 5 ;4 strptr equ 9 ;4 length equ 13 ;2 count equ 15 ;2 size_of_var equ 16 DoWork anop tsc ;set up a dpage for us sec sbc #size_of_var tcs phd tcd ;get the selected icons pea tellFinderGetSelectedIcons pea stopAfterOne+sendToName pea Fstr|-16 pea Fstr pea 0 pea 0 pea FindRes|-16 pea FindRes _SendRequest ~Hlock FindRes+8 ;lock it lda FindRes+8 ;string list handle sta StrPtr lda FindRes+10 sta StrPtr+2 ldy #2 lda [StrPtr] ;handle ->pointer tax lda [StrPtr],y stx StrPtr sta StrPtr+2 lda [StrPtr] ;check # of items sta count bne foo brl restore ;if no items (not likely) foo anop pha ;space for result pha ~GetHandleSize FindRes+8 pla plx ;hi word (ignored) clc adc #10 ;8 byte header +tail sec sbc count ;w-string has 1 extra byte per pha ;result pha pea 0 ;size of handle pha ;low word of size lda MyID pha pea $0010 ;attributes :nocrossbank pea 0 ;location pea 0 _NewHandle ;new handle for the message plx stx MsgHndl pla sta MsgHndl+2 pha phx _HLock ;lock it ldy #2 ;dereference it lda [MsgHndl] sta MsgPtr lda [MsgHndl],y sta MsgPtr+2 lda MsgPtr clc adc #6 ;offset to type sta MsgPtr lda #0 ;open, not print sta [MsgPtr] inc MsgPtr inc MsgPtr ;now points to first data inc StrPtr ;now points to first member inc StrPtr loop lda [StrPtr] xba ;switch it to a pstring sta [StrPtr] inc StrPtr xba ;back to gsos inc a ;compensate for length byte sta length pei StrPtr+2 ;src pei StrPtr pei MsgPtr+2 ;dest pei MsgPtr pea 0 ;length pei length _BlockMove ldx length txa clc adc StrPtr sta StrPtr txa clc adc MsgPtr sta MsgPtr dec count bne loop lda #0 sta [MsgPtr] ;0 length string = eof ~Hunlock pointer sta dataOut lda [dataIn],y sta dataOut+2 lda [dataOut] ;check # of items beq disable ~EnableMItem MenuID bra leave_DIC disable ~DisableMItem MenuID leave_DIC anop ~DisposeHandle FindRes+8 ;deallocate rts DoIconChange end