Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site ark.UUCP Path: utzoo!linus!decvax!ucbvax!ucdavis!lll-crg!gymble!umcp-cs!seismo!mcvax!vu44!botter!ark!gijs From: gijs@ark.UUCP (Gijs Mos) Newsgroups: net.micro.mac Subject: Toolbox action procedures and C Message-ID: <563@ark.UUCP> Date: Thu, 17-Oct-85 22:33:11 EDT Article-I.D.: ark.563 Posted: Thu Oct 17 22:33:11 1985 Date-Received: Mon, 21-Oct-85 05:24:08 EDT Organization: VU Informatica, Amsterdam Lines: 62 (rn crashed. This is a follow-up to some article) Action procedures or functions are called from toolbox trap code. The toolbox has been coded with Lisa Pascal in mind. So it uses the Lisa Pascal procedure/function calling sequence: Reserve space on stack for function result (not done for proc) Push parameters JSR (Push return address) The procedure or function saves the return address, removes parameters and pushes back the return address before returning. The calling sequence for C functions is different. Consular C - as an example - expects its first 7 arguments in D0 - D6. Remaining arguments are pushed on the stack (in reverse order). The function result is in A0 if pointer and in D0 otherwise. The solution is to call your C action function from an assembly routine that converts calling sequences. As an example (again MacC) a piece of code for a scroll control action procedure. DoScrollAction() /* Convert Pascal to C calling sequence and jump to ScrollAction */ { #asm MOVE.L (SP)+,A0 ;Save return address MOVE.W (SP)+,D1 ;partCode EXT.L D1 ;MacC int's are 32 bit MOVE.L (SP)+,D0 ;myControl MOVE.L A0,-(SP) ;Return address back on stack JMP ScrollAction #endasm } ScrollAction( myControl, partCode ) ControlHandle myControl; int partCode; { int value, max, min, page, startCount; startCount = TickCount(); value = GetCtlValue( myControl ); max = GetCtlMax( myControl ); min = GetCtlMin( myControl ); ... Literature: - IM chapter on Programming applications in Assembly Language - Your C compiler's manual Gijs Mos Dept. of Biology Vrije Universiteit Amsterdam {seismo,decvax,philabs}!mcvax!vu44!gijs