TweetFollow Us on Twitter

Technical Questions 2.1
Volume Number:2
Issue Number:1
Column Tag:Ask Prof. Mac

Readers Technical Questions

By Steve Brecher, Software Supply, MacTutor Contributing Editor


Q. It's widely rumored that Apple is going to offer an upgrade that includes a "SCSI port." What's that?

A. At this writing Apple has made no announcements about such an upgrade, but assuming that the rumors are true let's talk about SCSI. This is just a background briefing -- if the Mac does get a SCSI connection, the only programmers who will need to be concerned with its details are those who write device driver and other low-level software to talk to the SCSI devices that attach to the Mac.

SCSI stands for Small Computer Systems Interface and is usually pronounced as "scuzzy." It is a standard 8-bit-wide data bus that is increasingly popular in the industry for connecting peripheral devices to each other and to host computers.

SCSI is an enhancement and standardization of SASI (Shugart Associates Systems Interface), a disk controller interface which was originated by Shugart, the disk drive manufacturer, in the late '70s and widely used. SASI was submitted to ANSI (American National Standards Institute) for official standardization. In the process its name was changed to drop the association with a particular vendor, and protocols were added to enable multiple hosts to coexist on the bus, to allow peripherals to release the bus during their execution of long processes and then reconnect with the host which issued the command, and to add commands oriented to devices other than disks (e.g., tape drives).

The basic purpose of SCSI, like that of other buses (S100, VME, Qbus, Multibus, etc.) is to connect devices whose manufacturers may never have heard of one another so that the devices can send data back and forth in a coordinated way. SCSI specifies both the electrical aspects of the connection and a communication protocol. Up to 8 devices (peripheral controllers and/or computers) can be connected to a SCSI bus.

The bus consists of 8 data lines ("wires"), one data parity line, and 9 control signal lines. (For reasons best known to the hardware folks, a 50-line cable is usually used for SCSI interconnections.) Data transfer is asynchronous -- that means that an explicit control signal handshake protocol is used to coordinate the transfer of each byte (as opposed to synchronous, which means that the communicating devices use a common clock signal to pace data transfers).

The maximum SCSI data transfer rate is more than 1MByte/sec -- thus fast peripherals will have to wait for the Mac rather than vice-versa. The Mac, lacking DMA (Direct Memory Access), cannot transfer more than about 0.5Mbyte/sec into and out of RAM, because each byte transferred (recall that SCSI is an 8-bit-wide data bus) requires at least one CPU instruction and two 68000 bus accessess -- data source and destination -- in addition to the access for the instruction fetch. That's not counting any additional instructions such as for loop control.

A typical SCSI bus system is shown in Figure 1. This is a single-host system -- only one computer -- which allows the computer to drive the peripherals connected to the bus. The illustration shows only two peripherals, but there could be up to 7 (the host is one of the up to 8 devices that can attach to the bus).

The host adapter in the computer interfaces between the SCSI bus and the CPU. CPUs like the 68000 which use memory-mapped I/O would communicate with the host adapter by writing to or reading from fixed addresses -- just as the Mac communicates with its serial and diskette hardware at fixed addresses.

The bus allows any one pair of devices connected to it to be in communication at a given time. One of the devices (usually the computer) is the Initiator and the other (usually a peripheral) is the Target. The Initiator obtains use of the bus, and selects a Target; the Target responds to indicate it is selected, and then the two devices have exclusive use of the bus until they release it The Initiator sends commands to the Target, and the Target executes them. The set of possible commands includes Read (send data to me), Write (take the following data), Format (a disk), Rewind (a tape drive), etc.

SCSI peripheral controllers are fairly intelligent. For example, to read from a disk device, the Initiator (computer) need specify only a logical block address (a relative data block offset) and the number of blocks. The target controller then translates this into a low-level disk location (cylinder, head, sector). Historically, driver software in the computer has been responsible for such translation to low-level terms, because that's all that "dumb" disk controllers were able to understand. In addition to making things simpler for the host computer device driver software, this kind of controller intelligence allows a higher degree of device-independence -- the same way that a high-level programming language allows CPU-independence.

Soft Coding

Q. "ELL" on Delphi notes that Apple often warns against "hard-coding" constants such as screen and memory sizes into programs, but some example programs from Apple seem to include such constants nonetheless.

A. Do as they say, not as they do. Any program that's going to be used more than once (or farther into the future than five minutes) should be defensively programmed to assume that anything about its environment that might change, will change. Even today a program might be run on machines varying in memory size from 128K to 2MB, and varying in screen size from the Mac's screen to the XL's.

Handling an arbitrary screen size can be difficult with respect to multiple windows which contain many elements and which have been designed to look pretty. But that's no excuse for avaoiding simple measures, such as calculating at run time instead of hard-coding the positions of a window which should be centered.

To get the lazy started, I've provided in Figure 2 a couple of routines to vertically and horizontally center a rectangle. The code is trivial, but it illustrates the use of a couple of macros discussed in the next question.

In those cases in which constants must be used, they should be defined mnemonically (e.g., using EQU in assembler or Const in Pascal). That makes them easy to identify and change.


Q. I haven't seen many macros used in the assembly programs I've looked at. Could you give some examples of macro usage?

A. I have a file of macro definitions that I incorporate into most programs using the MDS Asm Include facility. The file is shown in Figure 3.

The first set of macros compensates for an MDS bug which generates incorrect results for some comparison operators. For example, instead of

If A<B

which doesn't work properly, I use the macro .LT.:

If A .LT. B

(I stole the substance of these comparison macros from the TMON user area source code.)

The second and most elaborate set of macros is used to avoid errors in stack addressing for a routine's arguments, result, and temporaries. Figure 4 shows an example of how this set of macros is used.

The Assume macro is useful for explicitly stating assumptions made by the code (usually relating to the value of an offset which is defined in an Equ file, or to the adjacency of values accessed with autoincrement or autodecrement addressing). For example, the code in Figure 2 contains:

  Assume   top=0
 Add        (A0),D0

Coding top(A0) wastes a word if top=0; including the Assume macro in this case makes clear what is going on (as well as protecting the program from undetected error should the offset of "top" ever change).

The various Push and Pop macros reduce the amount of typing required to code pushes and pops of the A7 stack as well as making the program easier to read (at least to my eye).

The BitDefinitions and Bit macros make it easy to define mnemonic values for bit numbers and masks which are used with flag bytes and hardware registers. Coding

 BitDefinitions   InterruptFlags
 Bit                  OneSec
 Bit                  VertBlank
 Bit                  KbdRdy

is the equivalent of coding

 OneSecBit      Equ 0
 OneSecMask      Equ 1
 VertBlankBit   Equ 1
 VertBlankMask   Equ 2
 KbdRdyBit      Equ 2
 KbdRdyMask      Equ 4


Q. Bill Bynum of Williamsburg, VA noticed that both Inside Macintosh and the June '85 issue of MacTutor (p. 45) indicate that the spExtra field of a grafPort record is a word, while in the MDS file QuickEqu.Txt, it's shown as a long (Pascal data type "fixed"). There is a corresponding discrepancy in the total size of a grafPort.

A. When in doubt, always go by the Equ files -- they're used by the folks at Apple who write systems software.

SpExtra is 4 bytes long, and a grafPort is 108 bytes long. Theoretically spExtra is of "fixed" data type, i.e., a 32-bit value with an implicit binary point in the middle. This implies that that spaces can be extended by a fractional number of pixels. However, in the current ROM QuickDraw effectively uses only the high-order word of spExtra. That's why the SpaceExtra trap works with an integer argument as it's documented in IM . QuickDraw moves a long argument from the stack to the field in the grafPort. Since the caller pushed only a word argument, the low-order word of the spExtra field in the grafPort will be whatever word happened to be above the caller's word argument on the stack. But since the low-order word doesn't really affect QuickDraw's calculations, all is well.

Figure 2 Source Code
 IncludeMacros ;see Figure 3

MBarHt  Equ 20 ;vertical size of menu bar
; procedure VertCenterRect(VAR myRect: rect)
; Adjust the top and bottom of the rect so that the rect is
; vertically centered in the desktop area for current
; screen size.
 StackFrame NotLinked
 Arg    myRect,Long
 Move.L (A5),A0  ;addr of QuickDraw globals
 Move screenBits+bounds+bottom(A0),D0 
 ;vertical size of screen
 Move.L myRect(SP),A0;addr of caller's rect
 Move bottom(A0),D1;D1 = bottom of caller's rect
 Sub  D1,D0 ;D0 = old bottom margin
 Assume top=0  ;(macro)
 Add  (A0),D0  ;+ old top margin, D0 = total 
 ;vertical margin
 Lsr  #1,D0 ;D0 = 1/2 of the vert space 
 ;not used by rect
 Add  #MbarHt/2,D0 ;adjust for menubar, D0 = 
 ;new top of rect
 Sub  (A0),D1  ;D1 = vertical size of rect
 Move D0,(A0)  ;set new top
 Add  D1,D0 ;new bottom = top + size
 Move D0,bottom(A0);set new bottom
 Return ;(macro)
; procedure HorzCenterRect(VAR myRect: rect)
; Adjust the left and right of the rect so that the rect is
; horizontally centered for current screen size.
 StackFrame NotLinked
 Arg    myRect,Long
 Move.L (A5),A0  ;addr of QuickDraw globals
 Move screenBits+bounds+right(A0),D0 
 ;D0 = horz size of screen
 Move.L myRect(SP),A0;addr of caller's rect
 Move right(A0),D1 ;D1 = right of caller's rect
 Lea  left(A0),A0;point to left coordinate 
 ;of rect
 Sub  D1,D0 ;D0 = old right margin
 Add  (A0),D0  ;+ old left margin, D0 = 
 ;total horz margin
 Lsr  #1,D0 ;D0 = 1/2 of the horz space 
 ;not used by rect
 Sub  (A0),D1  ;D1 = horizontal size of rect
 Move D0,(A0)  ;set new left
 Add  D1,D0 ;new right = left + size
 Move D0,right-left(A0)   ;set new right
 Return ;(macro)
Figure 3
; Macros.Asm -- General purpose MDS macros

; Macros to work around MDS Asm comparison reversal bug
If 1<0  ;if bug is present
 Macro  .LT. = > |
 Macro  .LE. = >=  |
 Macro  .GT. = < |
 Macro  .GE. = <=  |
Else    ;if bug is not present
 Macro  .LT. = < |
 Macro  .LE. = <=  |
 Macro  .GT. = > |
 Macro  .GE. = >=  |

; Subroutine stack frame definition macros
; Usage:
;StackFrame Linked ;if A6 link to be used
;StackFrame <anything else> ;if no A6 link to be used
;Arg    ArgN,ArgNLen ;last arg pushed by caller
;Arg    Arg1,Arg1Len ;first arg pushed by caller
;Result ResultName,ResultLen
;Local  Local1,Local1Len
;Local  LocalN,LocalNLen
;Link   A6,#-LocalsSize ;if StackFrame Linked
; Notes:
; StackFrame is required.  Each of the other types of 
; macro invocations is optional, but if present their 
;relative ordering must be as shown.
; Arguments (Arg macro invocations) must appear in 
; the reverse of the order in which the caller pushes 
; the arguments.
; ResultLen is ignored, but provided for documentary 
; purposes.

Macro StackFrame Type =
 If'{Type}' = 'Linked'
 ..RtnAddr..Set  4
 ..ArgOffs..Set  8
 ..RtnAddr..Set  0
 ..ArgOffs..Set  4
 ..ArgsSz.. Set  0
 LocalsSize Set  0

Macro Arg Name,Len =
 {Name} Set ..ArgOffs..
 ..ArgOffs..Set  {Name}+{Len}+({Len}&1)
 ..ArgsSz.. Set  ..ArgOffs..-..RtnAddr..-4

Macro ResultName,Len =
 {Name} Set ..ArgOffs..

Macro Local Name,Len =
 {Name} Set 0-LocalsSize-{Len}-({Len}&1)
 LocalsSize Set  0-{Name}

Macro Return =
 If..RtnAddr.. =4
 Unlk   A6
 If..ArgsSz..  <>0
 Move.L (SP)+,A0 ;return addr
 If..ArgsSz..  .LE. 8
 AddQ   #..ArgsSz..,SP
 Lea    ..ArgsSz..(SP),SP
 Jmp    (A0)

; Define standard lengths
Byte  Equ 1      ;same affect as Word
 ; use for declarative purpose
Word  Equ 2
Long  Equ 4

; Macros to push and pop stack
Macro Pop.B Dest =
 If   '{Dest}'   <> ''
 Move.B (SP)+,{Dest}
 Tst.B  (SP)+  ;pop and set condition codes 
 ;per Boolean

Macro Pop Dest =
 If   '{Dest}'   <> ''
 Move.W (SP)+,{Dest}
 AddQ #2,SP

Macro Pop.L Dest =
 If   '{Dest}'   <> ''
 Move.L (SP)+,{Dest}
 AddQ #4,SP

Macro Push.BSrc =
 Move.B {Src},-(SP)

Macro PushSrc =
 Move.W {Src},-(SP)

Macro Push.LSrc =
 Move.L {Src},-(SP)

Macro PushM Regs =
Macro PushM.L  Regs =

Macro PopMRegs =

Macro PopM.LRegs =

; Macro to make an assertion about an assumed condition
Macro Assume Cond =
 If   {Cond}
 Assumption error -- {Cond}
; Macros to decare bits and masks
; Usage
;BitDefinitions ID ;setup -- ID is documentary only 
;Bit  Name1 ;Defines Name1bit=0, Name1mask=1
;Bit  NameN ;Defines NameNbit=N, NameNmask=1<<N
Macro BitDefinitions ID
 .BitNbr. Set  0
Macro Bit Name =
 {Name}bitEqu  .BitNbr.
 {Name}mask Equ  1<<{Name}bit
 .BitNbr. Set  {Name}bit+1
Figure 4
; Function CanGetInfo(vRefNum, DirID: integer; FileNamePtr: 
 Ptr): boolean
; Calls _HGetFileInfo (HFS version) if DirID<>0, 
; otherwise _GetFileInfo.
; Returns true if the trap result is noErr.
ioHFQElSize Equ  $6C         ;size of HFS parameter block
ioDirID Equ $30          ;offset of DirID
 StackFrame Linked
 Arg    FileNamePtr,long
 Arg    DirID,word
 Arg    vRefNum,word
 Result Flag,byte
 Local  ioPB,ioHFQElSize
 Link A6,#-LocalsSize
 Lea  ioPB(A6),A0;addr of parameter block
 Move.L FileNamePtr(A6),ioFileName(A0)
 Move vRefNum(A6),ioVRefNum(A0)
 Clr.B  ioFVersNum(A0)  ;version number always 0
 Clr  ioFDirIndex(A0);not an indexed call
 Move DirID(A6),D0 ;HFS?
 Bne.S  @0;yes
 _GetFileInfo    ;no
 Bra.S  @1
@0 Move D0,ioDirID(A0)
@1 Assume noErr=0
 Seq  Flag(A6)   ;set result

Community Search:
MacTech Search:

Software Updates via MacUpdate

GraphicConverter 10.5.1 - $39.95
GraphicConverter is an all-purpose image-editing program that can import 200 different graphic-based formats, edit the image, and export it to any of 80 available file formats. The high-end editing... Read more
Delicious Library 3.7 - Import, browse a...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
Adobe Animate CC 2017 - Anima...
Animate CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous Flash Professional customer). Animate CC 2018 (was Flash CC) lets you... Read more
Adobe After Effects CC 2018 15.0 - Creat...
After Effects CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous After Effects customer). The new, more connected After Effects CC... Read more
Adobe Premiere Pro CC 2018 12.0.0 - Digi...
Premiere Pro CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous Premiere Pro customer). Adobe Premiere Pro CC 2018 lets you edit... Read more
Alarm Clock Pro 10.3 - $19.95
Alarm Clock Pro isn't just an ordinary alarm clock. Use it to wake you up in the morning, send and compose e-mails, remind you of appointments, randomize the iTunes selection, control an internet... Read more
Adobe Lightroom 20170919-1412-ccb76bd] -...
Adobe Lightroom is available as part of Adobe Creative Cloud for as little as $9.99/month bundled with Photoshop CC as part of the photography package. Lightroom 6 is also available for purchase as a... Read more
Adobe Illustrator CC 2018 22.0.0 - Profe...
Illustrator CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous Illustrator customer). Adobe Illustrator CC 2018 is the industry... Read more
Hopper Disassembler 4.3.0- - Binary disa...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more
Adobe InDesign CC 2018 - Prof...
InDesign CC 2018 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous InDesign customer). Adobe InDesign CC 2018 is part of Creative Cloud.... Read more

ICEY (Games)
ICEY 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: ICEY is a 2D side-scrolling action game. As you follow the narrator's omnipresent voice, you will see through ICEY's eyes and learn the... | Read more »
The best new games we played this week -...
We've made it, folks. Another weekend is upon us. It's time to sit back and relax with the best new releases of the week. Puzzles, strategy RPGs, and arcade games abound this week. There's a lot of quality stuff to unpack this week, so let's hop... | Read more »
Wheels of Aurelia (Games)
Wheels of Aurelia 1.0.1 Device: iOS Universal Category: Games Price: $3.99, Version: 1.0.1 (iTunes) Description: | Read more »
Halcyon 6: Starbase Commander guide - ti...
Halcyon 6 is a well-loved indie RPG with stellar tactical combat and some pretty good writing, too. It's now landed on the App Store, so mobile fans, if you're itching for a good intergalactic adventure, here's your game. Being a strategy RPG, the... | Read more »
Game of Thrones: Conquest guide - how to...
Fans of base building games might be excited to know that yet another entry in the genre has materialized - Game of Thrones: Conquest. Yes, you can now join the many kingdoms of the famed book series, or create your own, as you try to conquer... | Read more »
Halcyon 6: Starbase Commander (Games)
Halcyon 6: Starbase Commander Device: iOS Universal Category: Games Price: $6.99, Version: (iTunes) Description: An epic space strategy RPG with base building, deep tactical combat, crew management, alien diplomacy,... | Read more »
Legacy of Discord celebrates its 1 year...
It’s been a thrilling first year for fans of Legacy of Discord, the stunning PvP dungeon-crawling ARPG from YOOZOO Games, and now it’s time to celebrate the game’s first anniversary. The developers are amping up the festivities with some exciting... | Read more »
3 reasons to play Thunder Armada - the n...
The bygone days of the Battleship board game might have past, but naval combat simulators still find an audience on mobile. Thunder Armada is Chinese developer Chyogames latest entry into the genre, drawing inspiration from the explosive exchanges... | Read more »
Experience a full 3D fantasy MMORPG, as...
Those hoping to sink their teeth into a meaty hack and slash RPG that encourages you to fight with others might want to check out EZFun’s new Eternity Guardians. Available to download for iOS and Android, Eternity Guardians is an MMORPG that lets... | Read more »
Warhammer Quest 2 (Games)
Warhammer Quest 2 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: Dungeon adventures in the Warhammer World are back! | Read more »

Price Scanner via

12″ iPad Pros on sale for $50 off MSRP, no ta...
Adorama has 12″ iPad Pros on sale today for $50 off MSRP. Shipping is free, and Adorama charges sales tax in NY & NJ only: – 12″ 64GB iPad Pro: $749, save $50 – 12″ 256GB iPad Pro: $899, save $50... Read more
9″ iPads on sale for $30 off, starting at $29...
MacMall has 9″ iPads on sale for $30 off including free shipping: – 9″ 32GB iPad: $299 – 9″ 128GB iPad: $399 Read more
Apple restocks full line of refurbished 13″ M...
Apple has restocked a full line of Apple Certified Refurbished 2017 13″ MacBook Pros for $200-$300 off MSRP. A standard Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
13″ 3.1GHz/256GB MacBook Pro on sale for $167...
Amazon has the 2017 13″ 3.1GHz/256GB Space Gray MacBook Pro on sale today for $121 off MSRP including free shipping: – 13″ 3.1GHz/256GB Space Gray MacBook Pro (MPXV2LL/A): $1678 $121 off MSRP Keep an... Read more
13″ MacBook Pros on sale for up to $120 off M...
B&H Photo has 2017 13″ MacBook Pros in stock today and on sale for up to $120 off MSRP, each including free shipping plus NY & NJ sales tax only: – 13-inch 2.3GHz/128GB Space Gray MacBook... Read more
15″ MacBook Pros on sale for up to $200 off M...
B&H Photo has 15″ MacBook Pros on sale for up to $200 off MSRP. Shipping is free, and B&H charges sales tax in NY & NJ only: – 15″ 2.8GHz MacBook Pro Space Gray (MPTR2LL/A): $2249, $150... Read more
Roundup of Apple Certified Refurbished iMacs,...
Apple has a full line of Certified Refurbished 2017 21″ and 27″ iMacs available starting at $1019 and ranging up to $350 off original MSRP. Apple’s one-year warranty is standard, and shipping is free... Read more
Sale! 27″ 3.8GHz 5K iMac for $2098, save $201...
Amazon has the 27″ 3.8GHz 5K iMac (MNED2LL/A) on sale today for $2098 including free shipping. Their price is $201 off MSRP, and it’s the lowest price available for this model (Apple’s $1949... Read more
Sale! 10″ Apple WiFi iPad Pros for up to $100...
B&H Photo has 10.5″ WiFi iPad Pros in stock today and on sale for $50-$100 off MSRP. Each iPad includes free shipping, and B&H charges sales tax in NY & NJ only: – 10.5″ 64GB iPad Pro: $... Read more
Apple iMacs on sale for up to $130 off MSRP w...
B&H Photo has 21-inch and 27-inch iMacs in stock and on sale for up to $130 off MSRP including free shipping. B&H charges sales tax in NY & NJ only: – 27″ 3.8GHz iMac (MNED2LL/A): $2179 $... Read more

Jobs Board

Engineering Manager, *Apple* Retail Enginee...
# Engineering Manager, Apple Retail Engineering Job Number: 58139948 Santa Clara Valley, California, United States Posted: 20-Oct-2017 Weekly Hours: 40.00 **Job Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Commerce Engineer, *Apple* Media Products -...
Commerce Engineer, Apple Media Products (New York City) Job Number: 113028813New York City, New York, United StatesPosted: Sep. 20, 2017Weekly Hours: 40.00 Job Read more
US- *Apple* Store Leader Program - Apple (Un...
US- Apple Store Leader Program Job Number: VariousUnited StatesPosted: Oct. 19, 2017Retail Store Job Summary Learn and grow as you explore the art of leadership at Read more
Product Manager - *Apple* Pay on the *Appl...
Job Summary Apple is looking for a talented product manager to drive the expansion of Apple Pay on the Apple Online Store. This position includes a unique Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.