Examine the following two small programs. The first was written with MPW. The second is the same program written with Fantasm. MPW export Entry_Point[DS] export .Entry_Point[PR] ################################################## MACRO OScall &OSname import &OSname tc &OSname.[TC],&OSname csect .&OSname.[GL] lwz r12,&OSname.[TC](rtoc) # transition vector stw rtoc,$14(sp) # save caller RTOC lwz r0,0(r12) # routine address intransition vector lwz rtoc,4(r12) # get RTOC from transition vector mtctr r0 bctr # jump to callee routine ENDM ################################################## MACRO OS &OSname bl .&OSname.[GL] lwz rtoc,$14(sp) ENDM ################################################## MACRO Debugger li r3,0 tw 31,r0,r0 ENDM ################################################## stk_sz equ $40 qd_sz equ 206 csect .Entry_Point[PR] # start mflr r0 # Get link register stw r0,8(sp) # Store the link register on the stack stwu sp,-stk_sz(sp) # skip over the stack space where the caller # Initialisation lwz r3,qd[TC](rtoc) addic r3,r3,qd_sz-4 OS InitGraf OS InitFonts OS InitWindows OS InitMenus OS TEInit li r3,0 OS InitDialogs OS InitCursor # something to do lwz r3,test1[TC](rtoc) lwz r4,test2[TC](rtoc) li r5,0 # don't use third and fourth parameter li r6,0 OS ParamText li r3,128 # resource ID li r4,0 # no filter procedure OS Alert # bye lwz r0,stk_sz+8(sp) # Get the saved link register mtlr r0 # put saved link register in link register addi sp,sp,stk_sz # Reset the stack pointer li r3,0 # result blr # return via the link register ################################################## csect Entry_Point[DS] dc.l .Entry_Point[PR] dc.l TOC[TC0] dc.l 0 ################################################## csect qd[RW] align 3 ds.b qd_sz # QuickDraw storage string Pstring csect test1[RW] dc.b 'a first test string' csect test2[RW] dc.b 'a second test string' align 3 ################################################## OScall InitGraf OScall InitFonts OScall InitWindows OScall InitMenus OScall TEInit OScall InitDialogs OScall InitCursor OScall Alert OScall ParamText tc Entry_Point[TC],Entry_Point[DS] tc qd[TC],qd[RW] tc test1[TC],test1[RW] tc test2[TC],test2[RW] ################################################## Now, the same program with Fantasm: Fantasm *Simple demo to show structure of Fantasm PowerPC program. includeh LS_PPC_Macros.def *some useful macros includeh general_usage.def *Import general purpose system calls ENTRY *Program starts here. start_up *save all the regs and set up r30 for global la r3,qd(rtoc) *normal QuickDraw init addic r3,r3,206-4 Xcall InitGraf *Init rest of managers Xcall InitFonts *The calls could be replaced with a call Xcall InitWindows *to int_mac Xcall InitMenus Xcall TEInit li r3,0 Xcall InitDialogs Xcall InitCursor **How to use Macsbug (commented out here) * Xcall Debugger **You can also point r3 at a pascal string and call DebugStr lwz r3,test1(rtoc) *param1 lwz r4,test2(rtoc) *param2 li r5,0 *don't use third and fourth parameters li r6,0 Xcall ParamText *set up text for alert box li r3,128 *resource ID of alert li r4,0 *no filter procedure Xcall Alert *show the alert **Bye bye tidy_up ***********************************DATA************************ test1: pstring "Not so bad" align test2: pstring "is it?" align **read/write data goes in BSS. qd: rs.b 206 *206 bytes for QD variables | |