TweetFollow Us on Twitter

Jan 94 Tips
Volume Number:10
Issue Number:1
Column Tag:Tips & Tidbits

Tips & Tidbits

By Neil Ticktin, Editor-in-Chief

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Tip Of The Month

The 6-byte Code Resource Stub Trick

Many Macintosh programmers who have debugged a CDEF, LDEF, MDEF, or WDEF know “the 6-byte code resource stub trick.” Its been covered in MacTech Magazine, and the wisdom is often passed along online.

To briefly summarize, instead of burying all the code inside a separate code resource where it can't see the structure of the main program (global variables and functions), the programmer creates a 6-byte code stub. In that stub is one MC68000 jump-absolute instruction (as hex in a resource: 4EF9 0000 0000). The programmer replaces the jump destination address (the trailing 32 bits of 0) at runtime with a function address, then informs the relevant Toolbox manager that it should use the resource to define a control, list, or window. (Using this trick with a menu is similar.) Since code is modified, it's always safest to flush the CPU's instruction cache to avoid confusing (read: crashing) it. Refer to the Apple DSC Technical Note "Cache As Cache Can" for the long story.

Now, instead of reading and understanding the tech note and including relevant compensations in your code, you can use a different code resource stub. This stub still includes the function address, but it uses MC68000 instructions to retrieve the address as data, avoiding the code modification problem. In hex: 2F3A 0004 4E75 0000 0000. The 32 bits of zero are again the address you replace with a function address. A disassembly might read:

/* 1 */
MOVE.L  *+$0006,-(A7); push the DC.L onto the stack for RTS
RTS; jump to the definition function
DC.L  0 ; placeholder for addr of defn function

Since the DC.L never actually runs as code, there's no risk of confusing the cache in the CPU. You can use the following C structure declaration to access the address:

/* 2 */
typedef struct
{
 short  push [2], rts;
 void *addr;
}
tCodeStub, *tCodeStubP, **tCodeStubH;

- Pete Gontier

Berkeley, CA

This column is your opportunity to spread the word about little bits of information that you find out about. These tidbits can be programming related or they can be user tips that are particularly useful to programmers.

MacTech Magazine will pay $25 for every tip used, and $50 for the Tip of the Month. Or you can take your award in orders or subscriptions.

To submit a tip, send in a letter to the magazine. E-mail is our preferred method, but feel free to send something via the US Mail. See page two for all addresses. If you do send snail mail, enclose a printed copy and a disk copy of the letter so that it does not have to be retyped.

Precomputing Static value in constants

The compiler is not always smart enough to precompute static values in your code. Static values are values that stay constant throughout the program and cannot be changed. By use of constants you can help to compile precomputed values. This saves time and space in your program.

For example, the compiler will generate code to compute the value of the next expression at runtime. The code will be larger and slower.

  someValue := 5 * 4 + anotherValue + 90;

But, if you use a constant to compute the static value in the above expression, the compiler will precompute the value and place it in your compiled object code. The code will be smaller and faster as a result. Change the above expression like this:

CONST
  kPrecomputedStaticValue = 5 * 4 + 90;

BEGIN
someValue := kPrecomputedStaticValue + 
       anotherValue;
(* Other code *)

- Marek Hajek

Incline Village, Nevada

Toggle Invisibles Part 2

I read Lee Rimar’s tip "Toggle Invisibles in MPW" in November, 1993 Tips & Tidbits column. I found Mr. Rimar's script useful, and I've modified it to avoid making assumptions about the auto-indent and lock-scroll options. The trick is to use "=~" to match a regular expression against the three-character result of Format, and extract the second character into the ®1 variable (see "help patterns" in MPW). (If you're running out of sensible Command-key combinations, you can use SetKey instead, in MPW 3.3, to set up a function key, keypad key, control key, or whatever.)

AddMenu Edit "Toggle Invisibles/¥" 
  '(evaluate "`Format "{active}" -x a`" =~ /?(?)®1?/ ) > Dev:Null ; 
  if {®1}=="i" ; 
    Format "{Active}" -a I ; 
  else ; 
    Format "{Active}" -a i ; 
  end'

- Dave Lyons

Apple Computer, Inc.

International system Tip

Attention all single-byte developers!! Your software is ugly on double-byte machines! (see screen shot) Why? Because any resource that contains an odd number of text characters has an extra character added to the end (the second byte). Here in Japan, quality is very important and having funky looking characters on every menu and dialog box certainly doesn't convey quality. So what to do?

1. Startup your Mac with a double-byte system disk (check any CD-ROMS you have from Apple for a Japanese "Disk Tools" image.) Don't worry if you can't read Japanese because the menu items and short-cut keys are the same.

2. Launch ResEdit and open your application's resources (also notice ResEdit has the extra characters too! A little sloppy for Apple.)

3. Simply open each of you application's resources and find the foreign characters and backspace over them. Be sure to check everything!! Buttons, dialogs, text strings, etc. If it has text, it is possible there is problems.

4. When your finished, launch your application (while still in Japanese mode) and verify that it looks and runs correctly.

5. Restart your system and you're back to where you were! (Warning: depending upon the version you use, your desktop may be rebuilt on restart)

Even if you don't officially sell your software in Japan, most titles are available as gray market imports (even though the package says in big letters "For Sale in The USA Only".) So take a few minutes to improve your reputation for quality!

- Brett Bibby

Tokyo, Japan

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

WhatsApp 2.2136.10 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Thunderbird 91.1.1 - Email client from M...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
Direct Mail 5.9.1 - Create and send grea...
Direct Mail is an easy-to-use, fully-featured email marketing app purpose-built for macOS. Create, send, and track great looking email campaigns that get results. Start your newsletter by selecting... Read more
LibreOffice 7.2.1.2 - Free, open-source...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
Steam 2.0 - Multiplayer and communicatio...
Steam is a digital distribution, digital rights management, multiplayer and communications platform developed by Valve Corporation. It is used to distribute a large number of games and related media... Read more
Adobe Acrobat DC 21.007.20091 - Powerful...
Acrobat DC is available only as a part of Adobe Creative Cloud, and can only be installed and/or updated through Adobe's Creative Cloud app. Adobe Acrobat DC with Adobe Document Cloud services is... Read more
Carbon Copy Cloner 6.0.3 - Easy-to-use b...
Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more
Adobe Animate 21.0.9 - Animation authori...
Adobe Animate is available as part of Adobe Creative Cloud for as little as $20.99/month (or $9.99/month if you're a previous Flash Professional customer). Adobe Animate (was Flash CC) lets you share... Read more
Vivaldi 4.2.2406.44 - An advanced browse...
Vivaldi is a browser for our friends. We live in our browsers. Choose one that has the features you need, a style that fits and values you can stand by. From the look and feel, to how you interact... Read more
Adobe Acrobat Reader 2021.007.20091 - Vi...
Adobe Acrobat Reader allows users to view PDF documents. You may not know what a PDF file is, but you've probably come across one at some point. PDF files are used by companies and even the IRS to... Read more

Latest Forum Discussions

See All

PUBG New State crosses 40 million pre-re...
PUBG New State has received over 40 million pre-registrations on both Android and iOS, Krafton has recently announced. The futuristic, sci-fi PUBG Mobiletitle is all set to launch later this year, in October. [Read more] | Read more »
A Mere Husk of a Human Being – The Touch...
In this week’s episode of The TouchArcade Show I continue to be more or less out of my mind due to the exhaustion of having a newborn baby. Yes, I’ve been through all this before with our previous child, but somehow this is kicking my ass even worse... | Read more »
TouchArcade Game of the Week: ‘Night in...
I have said this probably dozens of times over the years, but there are tons and tons of cool video games on non-mobile platforms that people gush about all the time, and I always tell myself “I’ll definitely get around to playing that myself on [... | Read more »
SwitchArcade Round-Up: ‘Ni no Kuni II’,...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 17th, 2021. In today’s article, we finish our look at the new games of the week with the Friday releases. Some fairly big games in the list today, like Ni no Kuni II:... | Read more »
‘LEGO Star Wars Battles’ from TT Games a...
Last month, LEGO Star Wars Battles () was revealed for Apple Arcade. | Read more »
COD Mobile: The 5 best SMGs in the game
COD Mobile is often lauded for its vast array of weapons and elaborate customization. With every update, the guns get some kind of nerfs or buffs. Regardless of that, SMGs remain popular with players for close to mid-range combat. [Read more] | Read more »
SEGA Will Reveal a New Mobile RPG at Tok...
A few days ago, there was a bit of buzz around the listing of a new RPG under SEGA / Atlus for Tokyo Game Show 2021. Tokyo Game Show 2021 begins later this month and both SEGA and Atlus will have games and updates to showcase. SEGA will be revealing... | Read more »
‘Castlevania: Grimoire of Souls’ and ‘Te...
This week’s Apple Arcade roundup has updates to four amazing games on the service and the addition of two new games. The first new game is Castlevania: Grimoire of Souls () from Konami. | Read more »
‘Indies’ Lies’ is a New Roguelike Deck B...
For several years, as the popularity of MegaCrit’s roguelike deck-building game Slay the Spire grew amongst PC gamers, lots and lots of mobile gamers hoped that the game would one day arrive on their mobile devices, where it seemed like a natural... | Read more »
‘Steam Highwayman: Smog & Ambuscade’...
Cubus Games have released a number of interesting gamebooks on mobile for a number of years now, including titles such as Heavy Metal Thunder and The Frankenstein Wars. Now at the end of this month they’ll be adding another to their catalogue with a... | Read more »

Price Scanner via MacPrices.net

This is the final week for Apple’s 2021 Back...
Apple’s Back to School promotion for 2021 continues through September 27, 2021, making this the final full week to take advantage of these offers. As part of this promotion, Apple will include one... Read more
Verizon offers $100 discount on Apple’s new 8...
Verizon has Apple’s new 8.3-inch iPad mini and 9th-generation iPad on sale for $100 off MSRP with an Unlimited service plan. Discount is for 64GB and 256GB cellular-enabled models. The $100 sale... Read more
Apple’s new 9th generation iPad and 8.3-inch...
Amazon is offering preorder discounts on Apple’s new 9th generation iPad and 8.3″ iPad mini (64GB WiFi models) ranging up to $40 off MSRP. Delivery is expected starting September 24th: iPad: – 10″... Read more
Xfinity Mobile offers new Apple iPhone 13 mod...
Xfinity Mobile has Apple’s new iPhone 13 family of smartphones on sale and available for preorder for $300 off MSRP for customers opening a new line of service. No trade-in is required. Cost of the... Read more
Verizon offers free Apple iPhone 13 and iPhon...
Verizon is offering an $800 discount on Apple’s new iPhone 13 and $700 discount on the iPhone 13 mini for new and existing customers with a qualified trade-in. Price of the iPhone 13 will be spread... Read more
Apple Product Announcements, As Of Late, Have...
COMMENTARY: 09.17.21 – If you were left feeling a little, “meh” following Apple’s latest product launch, you’re not alone. On Tuesday — in a pre-recorded virtual event dubbed, “California Streaming... Read more
Verizon offers 25% discount on Apple MagSafe...
Verizon has Apple MagSafe Chargers on sale for 25% off MSRP from 9/16/21 to 9/30/21. Verizon service is not required to take advantage of these savings. With the discount, Verizon’s sale prices are... Read more
Verizon offers $1000 discount on new Apple iP...
Verizon is offering a $1000 discount on Apple’s new iPhone 13 Pro and iPhone 13 Pro Max for new and existing customers with a qualified trade-in. Price of the iPhone 13 Pro will be spread over 24 or... Read more
New at AT&T: Apple iPhone 13 and 13 mini...
We’ve already told you about AT&T’s $1000 discounts on the Apple iPhone 13 Pro and iPhone 13 Pro Max. AT&T now has Apple’s new iPhone 13 and iPhone 13 mini discounted to $700 off MSRP for new... Read more
‘Mac Potpourri’ Story On Apple And Folding Sm...
FEATURE: 09.16.21 – A certain writer has been seemingly thrust into the limelight thanks to an article published last month on MacPrices. The article — a commentary on how Apple must “‘flip’ the... Read more

Jobs Board

Geek Squad *Apple* Consultation Professiona...
**829606BR** **Job Title:** Geek Squad Apple Consultation Professional **Job Category:** Store Associates **Store Number or Department:** 001422-Tualatin-Store **Job Read more
Geek Squad Advanced Repair *Apple* Professi...
**831864BR** **Job Title:** Geek Squad Advanced Repair Apple Professional **Job Category:** Store Associates **Store Number or Department:** 000011-Northtown-Store Read more
Geek Squad *Apple* Consultation Professiona...
**831828BR** **Job Title:** Geek Squad Apple Consultation Professional **Job Category:** Store Associates **Store Number or Department:** 000028-Green Bay-Store Read more
Sr Infrastructure Engineer - *Apple* MacInt...
**Sr Infrastructure Engineer - Apple MacIntosh** **Description** At Bank of the West, our people are having a positive impact on the world. We're investing where we Read more
Senior Software Developer - *Apple* (iOS/tv...
**SUMMARY** Hulu's Apple team is seeking an experienced Senior Software Engineer with a passion for mobile applications to join our team in Seattle. Our highly Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.