TweetFollow Us on Twitter

May 97 Tips

Volume Number: 13 (1997)
Issue Number: 5
Column Tag: Tips & Tidbits

Tips & Tidbits

By Steve Sisak

File Manager Tip

If you've got a program, such as a compiler, which creates a temporary file, writes and reads from it, and then no longer needs the data, don't just close it and delete it; doing so usually causes the temporary data to be written to disk. Before closing it, call SetEOF(fRefNum, 0); This tells the disk cache that none of the data associated with the file need ever be written.

Jorg Brown
brown@connectix.com

Running m68k Codes "Compiled-in" (embedded) in a PowerPC Program

Here is a tip I bumped into recently. I wanted to run a sequence of m68k instructions (actually, to perform a system trap) on a PowerMac. Usually, this is a trivial task: compile the code in the 68k universe (for example, with in-line assembly supported by many m68k C/C++ compilers). From within a PowerPC application, one can call PowerPC glue code to the trap, which is probably present in the ‘InterfaceLib'.

Unfortunately, neither of these easy options would apply in my case: I only have a PowerPC compiler (I don't have disk space to install both 68k and PowerPC parts of the CodeWarrior). The trap I wanted to call (_ReadXPRam), is not an "official" one, thus there is no glue code for it in PowerPC libraries. Nevertheless, I found an easy way to run a sequence of 68k codes "compiled in" a PowerPC executable, and pass data in and out. By the way, this is working code that prints the contents of the xPRAM (more on xPRAM can be found at http://pobox.com/~oleg/ftp/xPRAM.html).

// Printing out the contents of the xPRAM
// The trick is that _ReadXPRam/_WriteXPRam traps are available only
// from within 68K universe. So, if this code runs in the PowerPC mode,
// we've got to switch universes before running M68K code sequences...

#include <stdio.h>
#include <MixedMode.h>

    // This is
    //    CLR.L   D0             address would be 0
    //    MOVE.W    $4(A7),D0    size -> lo word of d0
    //    SWAP  D0      size -> hi word of d0
    //    MOVEA.L  6(A7),A0where -> A0
    //    _ReadXPRam
    //    MOVEA.L (A7)+,A0 standard PASCAL epilogue
    //    ADDQ.W  #$6,A7
    //    JMP    (A0)
    //    RTS
    // This is a sequence of M68K instructions; unfortunately,
    // a PowerMac compiler doesn't understand them. So we've
    // got to assemble by hand <sigh>
    //
    // BTW, to write into xPRAM, replace 0xA051 in the sequence
    // below with 0xA052
    //pascal void read_extended_PRAM(char * where, const short size) =

static short read_extended_PRAM []=
{ 0x4280, 0x302F, 0x0004, 0x206F, 0x006, 0x4840, 0xA051, 0x205F, 0x5C4F, 
0x4ED0  };

#define COMP_NORET_2(name, a1, a2) \
 name##_procinfo = kPascalStackBased \
 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(a1)))     \
 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(a2)))

#define RD_ALLOC(routine) static RoutineDescriptor       \
 routine##_RD = BUILD_ROUTINE_DESCRIPTOR                 \
 (routine##_procinfo, routine)

enum {
  COMP_NORET_2(read_extended_PRAM,char *,const short)
};

void main(void)
{
  unsigned char whole_xPRAM_buffer[256];
  UniversalProcPtr u_read_extended_PRAM = 
   NewRoutineDescriptor((long (*)())read_extended_PRAM,
        read_extended_PRAM_procinfo,
        kM68kISA);
  CallUniversalProc(u_read_extended_PRAM,
  read_extended_PRAM_procinfo,
    whole_xPRAM_buffer,
  sizeof(whole_xPRAM_buffer));
  DisposeRoutineDescriptor(u_read_extended_PRAM);
 
  printf("\ncontents of the xPRAM\n");
  for(register int i=0; i<sizeof(whole_xPRAM_buffer); i+=16)
  {
    printf("\n%04x  ",i);
    for(register int j=0; j<16; j++)
   printf("%s%02x", j%4 == 0 ? " " : "", 
 whole_xPRAM_buffer[i+j]);
  }
}

Oleg Kiselyov
oleg@pobox.com

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Tomb of the Mask guide - How to increase...
Tomb of the Mask is a great endless arcade game from Happymagenta in which quick reflexes and a persistent attitude can go a long way toward earning a top score. Check out these tips to see if you can give yourself an edge on the leaderboards. [... | Read more »
Smooth Operator! (Games)
Smooth Operator! 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Smooth Operator is a weird, weird two-player kissing game. Squeeze in for 2 player fun on a single iPad, creating awkward... | Read more »
Sinless: Remastered (Games)
Sinless: Remastered 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: | Read more »
_PRISM Guide - How to solve those puzzle...
_PRISM is a rather delightful puzzle game that’s been tailor made for touch screens. While part of the fun is figuring things out as you go along, we thought we’d offer you a helping hand at getting in the right mindset. Don’t worry about messing... | Read more »
Set off on an adventure through the Cand...
Like match three puzzlers? If so, Jelly Blast, the innovative iOS and Android game which launched last year, is worth a look. Jelly Blast sees you head off on an epic adventure through the Candy Kingdom with your friends Lily, Mr. Hare, and Mr.... | Read more »
Ellipsis - Touch. Explore. Survive. (...
Ellipsis - Touch. Explore. Survive. 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: | Read more »
Ys Chronicles II (Games)
Ys Chronicles II 1.0.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.0 (iTunes) Description: After a hard fight to recover the six sacred books in Ys Chronicles I, Adol is back for a sequel! | Read more »
FINAL FANTASY Ⅸ (Games)
FINAL FANTASY Ⅸ 1.0.4 Device: iOS Universal Category: Games Price: $16.99, Version: 1.0.4 (iTunes) Description: ==========●Special sale price for the FINAL FANTASY IX release! ●20% off from February 10 to February 21, 2016... | Read more »
Tennis Club Story (Games)
Tennis Club Story 1.03 Device: iOS Universal Category: Games Price: $4.99, Version: 1.03 (iTunes) Description: Aim for the ace position of tennis club prestige in this simulation! Your leadership decides if players make it to the big... | Read more »
Juggernaut Wars guide - How to use skill...
Juggernaut Warsis a brand new auto-RPG on iOS and Android that challenges you to build a team of heroes, send them out into various different missions to defeat waves of heroes, and level them up to increase their power. The actual combat itself... | Read more »

Price Scanner via MacPrices.net

Sale! B&H Photo offers 12-inch Retina Mac...
B&H Photo has 12″ Retina MacBooks on sale for $300 off MSRP for a limited time. Shipping is free, and B&H charges NY tax only: - 12″ 1.1GHz Gray Retina MacBook: $999 $300 off MSRP - 12″ 1.... Read more
App Annie Reveals Future of the App Economy:...
App Annie, a San Francisco based mobile app data and insights platform, has launched its first comprehensive app economy forecast. This new offering will provide brands, agencies, investors and app... Read more
Apple restocks Certified Refurbished Mac mini...
Apple has restocked Certified Refurbished 2014 Mac minis, with models available starting at $419. Apple’s one-year warranty is included with each mini, and shipping is free: - 1.4GHz Mac mini: $419 $... Read more
What iPad Pro Still Needs To Make It Truly Pr...
I love my iPad Air 2. So much that I’m grudgingly willing to put up with its compromises and limitations as a production tool in order to take advantage of its virtues. However, since a computer for... Read more
21-inch 3.1GHz 4K on sale for $1399, $100 off...
B&H Photo has the 21″ 3.1GHz 4K iMac on sale $1399 for a limited time. Shipping is free, and B&H charges NY sales tax only. Their price is $100 off MSRP: - 21″ 3.1GHz 4K iMac (MK452LL/A): $... Read more
Apple price trackers, updated continuously
Scan our Apple Price Trackers for the latest information on sales, bundles, and availability on systems from Apple’s authorized internet/catalog resellers. We update the trackers continuously: - 15″... Read more
Save up to $240 with Apple Certified Refurbis...
Apple is now offering Certified Refurbished 12″ Retina MacBooks for up to $240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free. The... Read more
Apple refurbished 13-inch Retina MacBook Pros...
Apple has Certified Refurbished 13″ Retina MacBook Pros available for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and shipping is free: - 13″ 2.7GHz... Read more
Apple refurbished Time Capsules available for...
Apple has certified refurbished Time Capsules available for $120 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $179, $120 off - 3TB... Read more
13-inch 2.5GHz MacBook Pro (refurbished) avai...
Apple has Certified Refurbished 13″ 2.5GHz MacBook Pros available for $829, or $270 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros... Read more

Jobs Board

Infrastructure Engineer - *Apple* /Mac - Rem...
…part of a team Requires proven problem solving skills Preferred Additional: Apple Certified System Administrator (ACSA) Apple Certified Technical Coordinator (ACTC) Read more
Lead Engineer - *Apple* OSX & Hardware...
Lead Engineer - Apple OSX & Hardware **Job ID:** 3125919 **Full/Part\-Time:** Full\-time **Regular/Temporary:** Regular **Listed:** 2016\-02\-10 **Location:** Cary, Read more
Simply Mac *Apple* Specialist- Service Repa...
Simply Mac is the largest premier retailer of Apple products in the nation. In order to support our growing customer base, we are currently looking for a driven Read more
Infrastructure Engineer - *Apple* /Mac - Rem...
…part of a team Requires proven problem solving skills Preferred Additional: Apple Certified System Administrator (ACSA) Apple Certified Technical Coordinator (ACTC) Read more
Lead Engineer - *Apple* OSX & Hardware...
Lead Engineer - Apple OSX & Hardware **Job ID:** 3125919 **Full/Part\-Time:** Full\-time **Regular/Temporary:** Regular **Listed:** 2016\-02\-10 **Location:** Cary, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.