TweetFollow Us on Twitter

SCSI Driver
Volume Number:4
Issue Number:2
Column Tag:Forth Forum

A SCSI Driver in Forth

By Jörg Langowski, MacTutor Editorial Board, Grenoble, France

“An experimental SCSI driver in Mach2”

This column almost didn’t make it in time. Believe it or not, but while testing the SCSI driver of this article, my Quantum Q280 gave up. No, read on, it wasn’t the software. (How could it be MY software, anyway?) The interface board let go, and there was my most recent version of the driver, on the disk, inaccessible, me dummy having made no backup for the last 2 days. Left with ‘only’ a 20 MByte Seagate drive, I was going through a non-trivial exercise on how to debug a SCSI driver on the same disk which is used for developing it. You cannot imagine the strange things that can happen when booting from a disk with a partially functioning driver; it sometimes forces you into doing absolute no-nos such as booting from a floppy and attaching the SCSI connector afterwards so you can re-install the driver without getting la bombe immediately. At least, the development cycle is slowed down appreciably, since every other time you’ll have to boot from a floppy.

Anyway, here it is. The listing contains the Forth source of a SCSI driver which is more or less a translation of Apple’s assembly source into Mach2. It is quite long, and I’m not going through all of it in detail, having explained the function of most of the routines in my last column. One added feature is error retry; if a SCSI error happens, the offending command is repeated up to ten times.

The driver takes 50% more space than the assembly version and is about half as fast. So, you may ask, why go through all this trouble? You might have noticed the title ‘An experimental SCSI driver’. The code is meant for you to experiment with, add features - such as better error recognition and correction, multi- volume support, anything you may imagine. Or translate part of the routines into C or assembler. I just felt it was necessary to have a functioning example of a SCSI driver in some ‘higher-level’ language to make changes easier.

From the Forth point of view, I added a number of compiling words and glue routines that may be helpful for you in developing other things.

You already know the words :XDEF, ;XDEF, and XLEN from the Hypercard article. For easier programming of drivers and desk accessories, I now added :DA, ;DA, and DALEN which define the header of a driver, fill in the header after its definition is complete, and return the total length of the driver.

Since the SCSI driver code is jumped to at the beginning, it looks like other definition procedures from the outside, and its definition is therefore embedded between :XDEF and ;XDEF. In its interior, the SCSI driver contains a real DRVR, with is bracketed between :DA and ;DA. You recognize the glue code for the Open, Close, Control, Status and Prime routines at the end of the listing; the glue routines have been simplified by introducing macros for register save/restore and eventual jumps to the JIODone routine.

The Prime routine

Prime is the only one that has to be explained in more detail here since it has been modified with respect to the description given in the last issue. I added an error retry loop, and transfer of the SCSI data in variable size chunks. The code as printed takes 127 sectors on each read or write, that is, any amount of data larger than that will be transferred using several calls to the SCSICommon routine. This has been worked out empirically; larger transfer sizes would not work on the ST225N (which would result in files > 64K not being copied on a Finder copy). Your disk drive may allow larger sizes or need smaller ones; check this out if you like. You might also want to change the Read/Write Extended to a simple Read/Write command, or use a multi-transfer SCSI instruction block. The driver is certainly not generic and might need such adjustments to work on your disk.

SCSI Installation

The installation part has been changed slightly, and you’ll have to replace parts of the installer code given in the last column. First, I changed the device and partition maps such that the driver starts at block 4 and the Macintosh volume partition at block 16. This is where the Apple Hard Disk installation program seems to expect it, therefore you can easily replace this driver with the Apple driver in case of problems, without haveing to reformat the disk. Furthermore, I added a small routine that will install the driver code in the system heap and call it so that it gets installed in the unit table; this is an easy way of testing the driver without writing it to disk. You can even install the same disk that you are using to write the program, in which case you will be left with two drive icons on the desktop, referring to the same disk. For testing, this is OK, only don’t work too much in such an awkward configuration.

I hope this series of two articles has given you some ideas on how to write your own SCSI driver for your particular device. If someone comes up with a good examples for controlling a tape streamer - we’re always open for contributions, as you know.

Feedback Dept.

Someone read my complaints about the missing editor in Mach2; a letter with a disk arrived here recently:

“Dear Mr. Langowski,

I’m afraid I’m not a fan of Forth [Oh JL]. I like the idea of a stack-based language but there’s an impenetrable jargon barrier Besides, I just don’t like typing shifted characters, like #, !, % and so on. So I stay home with Pascal and Assembler.

On the other hand, I always at least glance at your column in MacTutor (as well as every other article that isn’t Mac II- specific). In the October issue, you say, ‘It is a shame that a powerful development system like Mach2 still lacks a reasonable integrated editor. At least multiple windows should be possible My standard development system is Mach2.13 with its editor and Mockwrite, plus Edit under Switcher if required.’ I’m stunned. The idea of using Mockwrite in a development system! The Mach2 editor must be really bad [ It’s not bad for what it does, i.e., has no major bugs; but I admit its features are limited - JL].

I had an editor problem myself, working with TML Pascal. TML won’t really run under the Switcher; it demands too much memory. So if I make a syntax error, I have to transfer to the editor, which means quitting the compiler and launching the editor, fix the error, then quit the editor and re-launch the compiler. Then I can re-compile. Something of a pain, particularly since error-free code is somewhat rare, at least when I’m the coder! [This sounds familiar. JL] My solution: Afterthought, a desk accessory programming editor. Now I fix bugs without leaving the compiler.

My problem is solved, and yours may be as well. I’m sending you a copy of Afterthought. It will open large files (up to 8 Megabytes), two at a time. It has most of the features of MDS Edit - the most significant exception is Replace All. And it’s reasonably fast. At the very least, it is better than Mockwrite!


Clifford Story, Jimmy Mac Software, P.O.Box 957, Murfreesboro, Tennessee 37133.”

Thank you, Clifford, for developing a product that - I guess - many of our readers have been waiting for.

The disk contained the Afterthought desk accessory, its manual, some update notes and examples, a demo version, and a demo version of Idealiner, an idea processor written by the same author. The prices are, by the way, extremely reasonable; $20 for the editor and $40 for the idea processor. To find out more about these products, send mail to the above address, or GEnie mail to CLIFF.

The second editor desk accessory product that I find worth mentioning is JoliWrite, written by Benoît Widemann from Paris, a small (32K limit) text editor that is extremely useful for working with bulletin board services. Often, when you prepare a text off line for a BBS message, you wish to be able to enter the text free-format and then format into lines of so and so many characters, with paragraph indentation and justification if desired. Also, over here it is often necessary to convert accentuated characters from Macintosh into ASCII representation and back, and in general you might wish to be able to remove/add line feeds, clip off numbers from line starts, etc. JoliWrite does all that, and in addition is one of the few products that supports Undo on all operations. By the time you read this, an English translation of JoliWrite (shareware, 120F/US$20) will hopefully be available on the Macintosh section of GEnie.

Listing 1: An experimental SCSI driver
( © 1987 J. Langowski / MacTutor )
only forth definitions
also mac also assembler

    MOVE.L   (A6)+,D0
    BMI.S    @1
    MOVE.L   (A6),D1
    ASL.L    D0,D1
    MOVE.L   D1,(A6)
@1  MOVE.L   (A6),D1
    NEG.L    D0
    ASR.L    D0,D1
    MOVE.L   D1,(A6)

: 4ASCII 0
 4 0 DO 
 8 SCALE 0 WORD 1+ C@ + LOOP

( *** compiler support words for external definitions *** )
: :xdef 
 create -4 allot
 $4EFA w, ( JMP )
 0 w,  ( entry point to be filled later )
 0 ,   ( length of routine to be filled later )
 here 6 - 76543

: ;xdef { branch marker entry | -- }
 marker 76543 <> abort” xdef mismatch”
 entry branch - branch w!
 here branch - 2+ branch 2+ !
: xlen 4 + @ ; ( get length word of external definition )

( *** driver header block *** )

 0 CONSTANT drvrFlags
 2 CONSTANT drvrdelay 
 4 CONSTANT drvrEMask
 6 CONSTANT drvrMenu
 8 CONSTANT drvrOpen
10 CONSTANT drvrPrime
12 CONSTANT drvrCtl
14 CONSTANT drvrStatus
16 CONSTANT drvrClose
18 CONSTANT drvrname
50 CONSTANT DAlength

( *** compiler support words for DA and driver definitions *** )
: :DA 
 create -4 allot
 here 87654 ( start of DA block, and marker )
 54 allot   ( length of block )

: ;DA { DAstart marker Ropen Rprime Rctl Rstatus Rclose
 Rflags Rdelay Remask Rmenu Rname | -- }
 marker 87654 <> abort” DA definition mismatch”
 Ropen  DAStart - DAStart drvrOpen + w!
 Rprime DAStart - DAStart drvrPrime + w!
 Rctl   DAStart - DAStart drvrCtl + w!
 Rstatus  DAStart - DAStart drvrStatus + w!
 Rclose DAStart - DAStart drvrClose + w!
 Rflags DAStart drvrFlags + w!
 Rdelay DAStart drvrDelay + w!
 Remask DAStart drvrEmask + w!
 RMenu  DAStart drvrMenu + w!
 Rname count dup   DAStart drvrName + c!
 DAStart drvrName + 1+ swap 
 dup 31 > if drop 31 then cmove 
 here DAstart -  DAStart DAlength + !
: DAlen DAlength + @ ; ( get length word of external definition )

\ ------------------------------------------------------
\ some macros needed in the driver
\ ------------------------------------------------------

CODE xchg ( exchange word halves on top of stack )
 move.l (a6)+,d1
 swap.w d1
 move.l d1,-(a6)
CODE min
 MOVE.L    (A6)+,D0                            
 CMP.L     (A6),D0                             
 BGE.S     @1        
 MOVE.L    D0,(A6)                             
@1 RTS 

CODE shl ( data #bits )
 MOVE.L (A6)+,D0
 MOVE.L (A6),D1
 LSL.L  D0,D1
 MOVE.L D1,(A6)

CODE shr ( data #bits )
 MOVE.L (A6)+,D0
 MOVE.L (A6),D1
 LSR.L  D0,D1
 MOVE.L D1,(A6)

 MOVE.L (A6)+,D1
 MOVE.L (A6)+,D0
 MOVE.L D0,-(A6)

\ ------------------------------------------------------
\ **** DA glue macros
\ ------------------------------------------------------


CODE DA.prelude
 LINK A6,#-512   ( 512 bytes of local Forth stack )
 MOVEM.L A0-A1,-(A7) ( save registers )
 MOVE.L  A6,A3   ( setup local loop return stack )
 SUBA.L  #256,A3 ( in the low 256 local stack bytes )
 MOVE.L  A0,-(A6)  ( parameter block )
 MOVE.L  A1,-(A6)( device control entry )
 RTS    \ just to indicate the MACHro stops here 

CODE DA.epilogue
 MOVE.L  (A6)+,D0( return code )
 MOVEM.L (A7)+,A0-A1 ( restore registers )

 MOVE.L  (A6)+,D0( return code )
 MOVEM.L (A7)+,A0-A1 ( restore registers )
 move.l JIODone,A0
 movem.l d4-d7/a4-a6,-(a7)
 jsr    (a0)

.trap _newptr,sys,clr$A71E

\ fields of device control entry
 4 CONSTANT dCtlFlags
16 CONSTANT dCtlPosition
20 CONSTANT dCtlStorage
24 CONSTANT dCtlRefNum
26 CONSTANT dCtlCurTicks
30 CONSTANT dCtlWindow
34 CONSTANT dCtlDelay
38 CONSTANT dCtlMenu

\ parameter block constants

0   CONSTANT  qLink\ ptr to next queue entry[long word]
4   CONSTANT  qType\ queue type [word]
6   CONSTANT  ioTrap \ routine trap [word]
7   CONSTANT  ioTrap+1    \ read or write command
8   CONSTANT  ioCmdAddr \ routine address [long word]
12  CONSTANT  ioCompletion\ addr of completion routine
16  CONSTANT  ioResult    \ result code returned here
18  CONSTANT  ioNamePtr \ pointer to file name string
22  CONSTANT  ioVRefNum \ volume reference number
26  CONSTANT  csCode ( type of control call )
28  CONSTANT  csParam( control call parameters )

\ MFS I/O Parameter Block
24 CONSTANT ioRefNum
26 CONSTANT ioVersNum
27 CONSTANT ioPermssn
28 CONSTANT ioMisc
32 CONSTANT ioBuffer
36 CONSTANT ioReqCount
40 CONSTANT ioActCount
44 CONSTANT ioPosMode
46 CONSTANT ioPosOffset
50 CONSTANT IOParamBlkSize

4ascii SDRV constant “sdrv
4ascii TFS1 constant “tfs1

\ Equates
\ My excuses for the format. This has been taken almost
\ ‘as is’ from Apple’s SCSI driver example. - jl -

EQUverChar$34  \ version ‘4’
EQUSCSIZE 10   \ size of SCSI extended command
\ Equates for our storage (pointed to by DCtlStorage)
EQUOffset 0   \ [long] offset of starting sector
EQUMyDQEl Offset+4   
\ [20 bytes] drive queue element (with flags) for this drive
EQUMyDrvNum MyDQEl+20       
 \ [word] drive num (determined by scanning drive queue)
EQUNextAddr MyDrvNum+2      
 \ [long] ptr to current block buffer
EQUTickleFlag  NextAddr+4      
 \ [byte] Do we need to remind the system about this drive?
 \ [byte] Can we use blind reads?
 \ I left this in to keep the format the same. 
 \ We don’t need it since our driver does not read blind. 
EQUSCmd BlindOK+1       
 \ [10 bytes] SCSI extended cmd Block /JL
EQUStatWord SCmd+10         \
  [word] status and message bytes...
 \ [word] ... returned by SCSIComplete

EQUOurIDMsgWord+2  \ [word] our SCSI ID
EQUSCSIPseudo  OurID+2         
 \ [30 bytes] SCSI pseudo-code program 
 \ - three instructions long
EQUSCSIPar1 SCSIPseudo+2  \ first SCSI code paramr (long)
EQUSCSIPar2 SCSIPar1+4  \ 2nd SCSI code parameter (long)
EQUDiskVarLth  SCSIPseudo+(SCSIZE*3) 
 \ length of our locals . . .
EQU DQDrvSize  12
EQU realSizeMyDQEl+DQDrvSize+4

\ equates for CSParam offsets for our special control call
 \ Ptr to SCSI command block
EQUDSCPseudoDSCCmd+4 \ Ptr to SCSI pseudocode (if any          
 bytes to xfer)
EQUDSCBufferDSCPseudo+4 \ Ptr to buffer for transfer (if       
EQUDSCSizeDSCBuffer+4\ Size of transfer, signed (+ if          
 read, - if write)
EQUDSCTicks DSCSize+4\ Tick count we’re willing to wait        
 for completion
EQUDSCCmdSize  DSCTicks+4 \ (word) Size of command block we’re 
 sending (usually 6)
EQU   KillCode 1 
EQUVerifyCode  5
EQUFormatCode  6
EQUIconCode 21
EQU   AccRun65
EQUSCSICode 77      
 \ our own special code (defined above)
EQUControlErr  -1
EQUParamErr -50
EQUnsDrvErr -56
EQUnsVErr -35

 \ to clear bit 5 of high byte in drvrFlags

EQUDiskInsertEvt 7
EQU   SysEvtMask $144
EQU   UTableBase $11C
EQU   DrvQHdr    $308
EQU   QHead $2



\ ______________________________________________
\ The code starts here.
\ ______________________________________________
:XDEF ScsiDisk  
 \ compiles a jump to the install code at the end 
 \ which will be resolved at the end of the definition.
 \ this word provides the driver header structure
\ Q200 Icon, as given by Quantum
\ If you find this ‘snail’ ugly, feel free to change it ...
\  J.L.
header  SCSIIcon        
DC.L $00000000   DC.L $00000000 
DC.L $00000000   DC.L $000FF000        
DC.L $003FFC00   DC.L $00FFFF00 
DC.L $01FFFF80   DC.L $03F81FC0        
DC.L $07E007E0   DC.L $07C003E0 
DC.L $0F8001F0   DC.L $0F0000F0 
DC.L $1F0000F8   DC.L $1E000078 
DC.L $1E000078   DC.L $1E000078 
DC.L $1E000078   DC.L $1E000078 
DC.L $1E000078   DC.L $1F0000F8
DC.L $0F0000F0   DC.L $0F8001F0 
DC.L $07C003E0   DC.L $07E007E0
DC.L $03F80000   DC.L $01FFFFF0 
DC.L $00FFFFF8   DC.L $003FFFF8
DC.L $000FFFF8   DC.L $00000000 
DC.L $00000000   DC.L $00000000

DC.L $00000000   DC.L $00000000 
DC.L $000FF000   DC.L $003FFC00
DC.L $00FFFF00   DC.L $01FFFF80 
DC.L $07FFFFF0   DC.L $03FFFFF8 
DC.L $003FFFFC   DC.L $000FFFFC 
DC.L $00000000   DC.L $00000000
\ Our “Where:” string
        DC.B    11
        DC.B    ‘Q200 (SCSI)’
\ SCSI handler glue routines
CODE SCSIReset ( -- result code )
 CLR.W -(A7)
 MOVE.W #0,-(A7)
 MOVE.W (A7)+,D0
 EXT.L  D0
 MOVE.L D0,-(A6)

CODE SCSIGet ( -- result code )
 CLR.W -(A7)
 MOVE.W #1,-(A7)
 MOVE.W (A7)+,D0
 EXT.L  D0
 MOVE.L D0,-(A6)

CODE SCSISelect ( TargetID -- SCSIErrorResult )
 MOVE.L (A6)+,D0
 CLR.W -(A7)
 MOVE.W D0,-(A7)
 MOVE.W #2,-(A7)
 MOVE.W (A7)+,D0
 EXT.L  D0
 MOVE.L D0,-(A6)

CODE SCSICmd ( buffer count -- SCSIErrorResult )
 MOVE.L (A6)+,D0
 MOVE.L (A6)+,D1
 CLR.W -(A7)
 MOVE.L D1,-(A7)
 MOVE.W D0,-(A7)
 MOVE.W #3,-(A7)
 MOVE.W (A7)+,D0
 EXT.L  D0
 MOVE.L D0,-(A6)

CODE SCSIComplete ( waitTicks mess stat -- SCSIErrorResult )
 CLR.W -(A7)
 MOVE.L (A6)+,-(A7)
 MOVE.L (A6)+,-(A7)
 MOVE.L (A6)+,-(A7)
 MOVE.W #4,-(A7)
 MOVE.W (A7)+,D0
 EXT.L  D0
 MOVE.L D0,-(A6)


\ ----------------------------------------------------
\ main driver routines start here
\ ----------------------------------------------------

: SCSICommon 
 \ written to emulate the SCSICommon 
 \ routine in Apple’s example 
 \ as closely as possible.
 { pseudo cmdblock ourVars ticks bytes cmdsize 
 | writing mess stat -- result }

 SCSIGet 0= IF
 ourVars ourID + w@ 
 SCSISelect 0= IF
 cmdBlock cmdSize SCSICmd 0= bytes AND IF
 pseudo bytes 0< \ bytes <0 if writing
 IF (call) SCSIWrite drop
 ELSE (call) SCSIRead drop THEN
\ Note: Your system may be able to support blind transfers.
\ Here is the place to experiment with such things --
 ticks ^ mess ^ stat SCSIComplete
 0= IF  
 stat $FF AND IF ioErr 
 ( there was an SCSI error )
 ELSE 0 ( successful completion ) THEN
 ELSE ( complete unsuccessful ) ioErr
 ELSE ( select unsuccessful ) ioErr
 ELSE ( get unsuccessful ) ioErr

: DiskClose { parblk dce | -- result }
 0 ( result code = OK ) ;

: diskControl { parblk dce | ourVars -- result }
 dce DCtlStorage + @ -> ourVars    
 parblk csCode + w@
 killCode OF0 ENDOF
 verifyCode OF 0 ENDOF
 formatCode OF 0 ENDOF

 ourVars MyDrvNum + w@ 
 \ check drive # in request
 parblk  IOVRefNum + w@ =  \ the same?
 SysEvtMask w@ IF ( we’re not at boot time )
 MyDrvNum ourVars + w@
 (call) PostEvent drop
 ELSE ( boot time )
 1 ourVars tickleFlag + c!
 ( drive will be remembered after boot )
 ELSE nsDrvErr

 iconCode OF [‘] SCSIIcon parblk csParam + ! 

 accRun OF
 ourVars tickleFlag + c@ 
 ourVars offset + @ 0= not 
 ( we have a good partition )
 MyDrvNum ourVars + w@
 (call) PostEvent drop
 0 dce DCtlDelay + w!
 dce DCtlFlags + dup w@ 
 dNeedTime AND swap w! ( clear flag )
 0 ourVars tickleFlag + c!

 scsiCode OF
 parblk dup DSCPseudo + @
 dup DSCCmd + @
 dup DSCTicks + @
 dup DSCSize + @
 DSCCmdSize + w@

 ( otherwise ) 
: DiskStatus { parblk dce | -- result } statusErr ;

CODE GetSysPtr
 move.l (a6)+,d0
 move.l a0,-(a6)

CODE AddDrv ( dqe refnum drv# | -- )
 move.l (a6)+,d0
 move.l (a6)+,d1
 swap.w d0
 move.w d1,d0
 move.l (a6)+,a0
: DiskOpen { parblk dce | 
 ourVars thisQElem driveNum dqe SCSIprog -- result }

 DiskVarLth GetSysPtr dup 
 \ get memory for local variables 
 -> ourVars dce DCtlStorage + !  
 \ and store pointer to it
 100 5 DO \ find unused drive #
 DrvQHdr QHead + @ -> thisQElem  \ scan queue
 BEGIN thisQElem 0= IF i leave THEN
 \ end of queue? we have a good number
 thisQElem DQDrive + w@
 i <> WHILE
 \ keep scanning as long as # is not in use
 thisQElem ( QLink + ) @ -> thisQElem
 LOOP -> driveNum
 driveNum ourVars myDrvNum + w! 
 \ remember drive # in local vars
\ ( following text taken from Apple’s generic driver )
\ Add a drive to the drive queue. First, some fun facts:
\ The drive queue element starts four bytes before the DQEPtr!
\ These four bytes contain “hardware-locked”, “ejectable”, and
\ “disk-in-place” info.
\ Not As Interesting But Still True: HFS supports volumes 
\ >32MBytes, but since the dqDrvSize field in the DQE is only 
\ a word, the Software Gurus had to resort to bizarre sorcery:
\ If the qType field (formerly unused in DQE’s) is 1, the word
\ following the dqDriveSize field is assumed to be the high-order
\ word of a LongInt block count! (dqDriveSize is still the low-
\ order word). It works even if the size doesn’t require both 
\ words, so we always do it this way.
\ See: Tech Note #36.
 ourVars MyDQEl + 8 over w! 
 \ set non-ejectable and clear the rest
 2+ 0 over w! 2+  -> dqe  
 \ this is the real start of the DQElem
 1 dqe qType + w!\ large vol queue type
 0 dqe dqDrvSize + ! \ no size yet
 0 dqe dQFSID + w! \ normal file system
 dce DCtlRefNum + w@ 
 driveNum AddDrv \ add drive to queue
 \ now set up SCSI pseudo program in driver’s local vars

 ourVars SCSIPseudo +  -> SCSIprog
 scnoinc SCSIprog w!
 scstop  SCSIprog scsize + w!
 0 \ result code = good

: DiskPrime { parblk dce | 
 ourVars sectors bytes start size r/w sect transferred error
  -- result } 

 dce dCtlStorage + @ -> ourVars  \ setup local var pointer
 1 ourVars TickleFlag + c!

 \ convert byte count into number of sectors
 parblk IOReqCount + @ 9 shr $1FFFFF AND -> sectors
 \ convert starting position into sector number
 dce dCtlPosition + @ 9 shr $1FFFFF AND -> start
 ourVars realSize + @ xchg -> size \ get drive size
 start sectors + size 1+ < IF ( valid request )
 0 -> transferred
 ourVars ( offset + ) @ +> start 
 \ offset by start of partition

 parBlk IOTrap+1 + c@ 3 = ( is this a write command? )
 IF  -1 -> r/w $2A00 ( SCSI extended write )
 ELSE 1 -> r/w $2800 ( SCSI extended read ) 
 ourVars SCmd + w! \ put the command away 

 BEGIN ( transfer loop )

\ If you have problems getting the SCSI transfer to work
\ with your particular disk, try changing the number of
\ sectors transferred on each call ( 127 here )
\ or change the read/write extended to a normal read/write.
 \ Note that in that case you’ll have to change the command 
 \ block setup as well. 

 127 sectors min -> sect
 transferred +> start
 parblk IOBuffer + @ transferred 9 shl + 
 ourVars SCSIPar1 + ! 
 sect 9 shl dup -> bytes 
 ourVars SCSIPar2 + !  \ set # of bytes

 start ourVars SCmd + 2+ !
 \ set starting position in command block
 bytes 2/ ourVars SCmd + 6 + !  \ set # of sectors
 IOErr ( preset, if loop with retry is unsuccessful )
 10 0 DO ( retry max 10 times )
 ourVars SCSIPseudo +
 ourVars SCmd +
 ourVars 60 r/w 10
 SCSICommon 0= IF drop 0 leave THEN
 1 (call) sysbeep \ just for debugging, 
 \ beeps if SCSI did not complete successfully
 LOOP -> error
 -127 +> sectors
 sectors 1- 0< 
 UNTIL ( transfer loop )
 error dup 0= IF
 parBlk IOReqCount + @ -> bytes
 bytes parBlk IOActCount + ! 
 \ we transferred the # of bytes requested
 bytes dce DCtlPosition + +!

CODE DrvrInst ( unitNum | -- )
 move.l (a6)+,d0
 not.w  d0
CODE DrvrRem ( unitNum | -- )
 move.l (a6)+,d0
 not.w  d0

CODE openMe ( drvrName | result -- )
 \ allocates a parameter block on the A7 stack and calls
 \ the _open trap. This is easier to do in assembly --
@1 clr.w-(a7)
 dbra d0,@1
 move.l a7,a0
 move.l (a6)+,IONamePtr(a0)
 add.w  #IOParamBlkSize,a7
 move.l d0,-(a6)

: RealInstall 
\ This routine is called by the system boot code with 
\ the SCSI ID of the disk in D5 and a pointer to its
\ partition map in A0. We therefore need some special glue code. 
\ Note that Mach2 allows to do the stack parameter / local
\ variable declaration after this glue code without any problems
 LINK A6,#-512   ( 512 bytes of local Forth stack )
 MOVEM.L A2-A6/D2-D7,-(A7)( save registers )
 MOVE.L  A6,A3   ( setup local loop return stack )
 SUBA.L  #256,A3 ( in the low 256 local stack bytes )
 MOVE.L  A0,-(A6)  ( partition table pointer )
 MOVE.L  D5,-(A6)( SCSI ID )
 { partition ID | unitNum hdce dce ourVars pt -- }

 ID 32 + -> unitNum
 unitNum DrvrInst\ allocate DCE and install it
 unitNum 4 w* UTableBase @ + @ -> hdce \ dce handle
 hdce @ -> dce \ get dce pointer
 [‘] DiskDrvr dce ( DCtlDriver + ) ! 
 \ put pointer to driver into dce  
 [‘] DiskDrvr drvrFlags + w@
 dce DCtlFlags + w!
 \ move driver flags, RAMbase should be cleared
 0 dce DCtlDelay + w!\ no time needed yet
 [‘] DiskDrvr drvrEMask + @
 dce DCtlEMask + ! \ move event mask and menu

 [‘] DiskDrvr drvrName + openMe  \ try to open this driver
 IF ( not OK ) unitNum DrvrRem
    [‘] Scsidisk (call) DisposPtr
    bra @1 \ exit hack. 
 \ This is the Mach2 equivalent of the 
 \ Ugly Goto Statement in Pascal. 
 \ Sorry, but it is so much easier this way...
 hdce @ -> dce 
 \ deref this handle again, may have changed
 dce dCtlStorage + @ -> ourVars
 ID ourVars ourID + w!
 partition IF 
 \ well, we should have a non-NIL partition at least...
 partition ( PDSig + ) w@ PDSigWord = IF
 \ and it should be a Macintosh one. The NEW Apple drivers
 \ have a different sig word and DPM format that you 
 \ might want to take into account here (see text). 
 partition 2+ -> pt
 pt PDFSID + @ ?dup WHILE 
 \ otherwise no good partition found
 “tfs1 = 
 IF ( correct file system ID )
 pt @ ourVars Offset + !
 pt 4 + @ xchg 
 ( long drive size, hi word <-> lo word )
 ourVars realSize + !
 SysEvtMask w@ 0= IF \ we’re booting
 dce dCtlFlags + dup w@ 
 $2000 OR swap w!
 ( set dNeedTime flag )
 1 dce dCtlDelay + w!
 1 ourVars TickleFlag + c!
 12 +> pt
@1 UNLK A2\ which was used for local variables
 MOVEM.L (A7)+,A2-A6/D2-D7( restore registers )
\ we stop here; the rest will be inaccessible junk (4 bytes).

: DrOpen  DA.prelude DiskOpen DA.epilogue ;
: DrClose DA.prelude DiskClose DA.epilogue ;
: DrCtl   DA.prelude DiskControl DA.JIODone  ; 
: DrStatus DA.prelude DiskStatus DA.JIODone ;
: DrPrime DA.prelude DiskPrime DA.JIODone ;

‘ DrOpen ‘ DrPrime ‘ DrCtl ‘ DrStatus ‘ DrClose
$6F00 0 0 0 ( flags delay mask menu )
“ .SCSIfth” ( name, MUST start with a period ) 

‘ RealInstall ;XDEF

\ ----------------------------------------------------
\ The following routines are to be added or replaced in the 
\ installer program from the previous column. Included is an
\ installer that will directly move the Forth code to disk, without
\ going through a resource, and some code to install the driver 
\ in memory for testing without writing it to the disk. The 
\ DDM and DPM definitions have been changed somewhat 
\ to accommodate the larger driver, and to have the partition start 
\ at the same place that Apple’s new SCSI driver expects it (so
\ that you can replace the Forth driver easily by a new Apple 
\ driver in case you are fed up with this hack)
\ Good luck. - JL -
\ ----------------------------------------------------


: create.ddm
 ddm 200 0 fill
 4552 ddm w!
 read.cap ddm 2+ w! ( block size )
  ddm 4 + ! ( # of blocks )
 0 ddm 8 + w! ( device type )
 0 ddm A + w! ( device ID )
 10 ddm C + !  ( first data block )
 1 ddm 10 + w! ( one driver to follow )
 4 ddm 12 + ! ( driver start block )
 A ddm 16 + w! ( driver is 10 blocks long )
 1 ddm 18 + w! ( and runs on Macintosh =1 )
: create.dpm
 dpm 200 0 fill
 5453 dpm w!
 10 dpm 2+ ! ( starting block of partition )
 read.cap drop 10 - dpm 6 + ! ( # of blocks )
 “tfs1 dpm A + !   ( TFS1 signature )
 0 dpm E + !
: read.ddm
 0 read.blk 2+ w! 0 read.blk 4 + c!
 1 read.blk 5 + c!
 120 read.blk myDisk @ ddm 512 doscsi.r
: read.dpm
 0 read.blk 2+ w! 1 read.blk 4 + c!
 1 read.blk 5 + c!
 120 read.blk myDisk @ dpm 512 doscsi.r
: write.ddm
 0 write.blk 2+ w! 0 write.blk 4 + c!
 1 write.blk 5 + c!
 120 write.blk myDisk @ ddm 512 doscsi.w
: write.dpm
 0 write.blk 2+ w! 1 write.blk 4 + c!
 1 write.blk 5 + c!
 120 write.blk myDisk @ dpm 512 doscsi.w
: get.sdrv { | length -- length } 
 [‘] scsidisk dup 
 xlen dup -> length driver.block swap cmove
: write.sdrv { length | sectors }
 0 write.blk 2+ w! 4 write.blk 4 + c!
 length 512 / 1+ dup write.blk 5 + c! -> sectors
 120 write.blk myDisk @ driver.block 
 sectors 512 * doscsi.w
 cr .” Driver written. Stat, Mess = “ . .

: dmp { block# | -- } ( for easy testing of SCSI disk contents )
 0 read.blk 2+ w! block# read.blk 4 + c!
 1 read.blk 5 + c!
 120 read.blk myDisk @ ddm 512 doscsi.r
 ddm 20 dump
.TRAP   _newptr,sys     $A51E
$308 CONSTANT DQHeader

VARIABLE syshp.drvr

: install.driver { | dstart dlength dbytes pointer -- }
 ddm 18 +  @ -> dstart
 ddm 22 + w@ -> dlength
 cr .” Driver starts at sector “ dstart .
 .”  and is “ dlength . .”  sectors long.”
 dlength 512 * -> dbytes
 dstart 256 /mod read.blk 2+ w! read.blk 4 + c!
 dlength read.blk 5 + c!
 120 read.blk myDisk @ driver.block dbytes doscsi.r
 cr .” Driver read; stat, mess = “ . .
 dbytes MOVE.L (A6)+,D0
      _newptr,sys ( get memory block in system heap )
      MOVE.L A0,-(A6)   -> pointer
 IFdriver.block pointer dbytes cmove
 pointer syshp.drvr !
      ELSE .” Not enough system heap for installation.” cr
CODE call.driver
 MOVE.L D5,-(A7)
 MOVE.L (A6)+,D5
 MOVE.L (A6)+,A0
 MOVE.L (A7)+,D5
: mount.scsi
 SysEvtMask @
 0 SysEvtMask !
 syshp.drvr @ dpm myDisk @ call.driver
 SysEvtMask !
: zero.scsi 
 DQHeader qTail + @ dQDrive + w@ ( drive # found )
 cr .” Do you want to zero the directory of drive # “ 
 dup . .”  ? “
 yesno if “ JL’s Hard Disk” call DIZero
 cr .” Result code = “ . cr 
: mount 
 cr .” Looking for SCSI devices...”
 cr .” SCSI drive found at address “ myDisk @ .
 cr show.cap
 cr .” format disk? “ 
 yesno IF 
 cr .” Do you REALLY want to erase this SCSI disk? “
 yesno IF cr .” Reformatting disk... “ 
 create.ddm create.dpm
 cr .” Device and partition descriptor maps written. “
 cr .” Writing driver ... “
: install.mem { | dbytes pointer -- }
 [‘] scsidisk xlen dup -> dbytes
 MOVE.L (A6)+,D0
      _newptr,sys ( get memory block in system heap )
      MOVE.L A0,-(A6)   -> pointer
 IFdriver.block pointer dbytes cmove
 pointer syshp.drvr !
      ELSE .” Not enough system heap for installation.” cr
: mount.mem
 SysEvtMask @
 0 SysEvtMask !
 syshp.drvr @ dpm myDisk @ call.driver
 SysEvtMask !

Community Search:
MacTech Search:

Software Updates via MacUpdate

Tunnelblick 3.7.3 - GUI for OpenVPN.
Tunnelblick is a free, open source graphic user interface for OpenVPN on OS X. It provides easy control of OpenVPN client and/or server connections. It comes as a ready-to-use application with all... Read more
Opera 48.0.2685.50 - High-performance We...
Opera is a fast and secure browser trusted by millions of users. With the intuitive interface, Speed Dial and visual bookmarks for organizing favorite sites, news feature with fresh, relevant content... Read more
Tor Browser Bundle 7.0.7 - Anonymize Web...
The Tor Browser Bundle is an easy-to-use portable package of Tor, Vidalia, Torbutton, and a Firefox fork preconfigured to work together out of the box. It contains a modified copy of Firefox that... Read more
FotoMagico 5.5 - Powerful slideshow crea...
FotoMagico lets you create professional slideshows from your photos and music with just a few, simple mouse clicks. It sports a very clean and intuitive yet powerful user interface. High image... Read more
Adobe Audition CC 2018 11.0.0 - Professi...
Audition 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 Audition customer). Adobe Audition CC 2018 empowers you to create and... Read more
Alfred 3.5.1 - Quick launcher for apps a...
Alfred is an award-winning productivity application for OS X. Alfred saves you time when you search for files online or on your Mac. Be more productive with hotkeys, keywords, and file actions at... Read more
AirRadar 4.0 - $9.95
With AirRadar, scanning for wireless networks is now easier and more personalized! It allows you to scan for open networks and tag them as favourites or filter them out. View detailed network... Read more
DEVONthink Pro 2.9.16 - Knowledge base,...
Save 10% with our exclusive coupon code: MACUPDATE10 DEVONthink Pro is your essential assistant for today's world, where almost everything is digital. From shopping receipts to important research... Read more
ForkLift 3.0.8 Beta - Powerful file mana...
ForkLift is a powerful file manager and ferociously fast FTP client clothed in a clean and versatile UI that offers the combination of absolute simplicity and raw power expected from a well-executed... Read more
Data Rescue 5.0.1 - Powerful hard drive...
Data Rescue’s new and improved features let you scan, search, and recover your files faster than ever before. We have modernized the file-preview capabilities, added new files types to the recovery... 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 »
4 of the best Halloween updates for mobi...
Halloween is certainly one of our favorite times for mobile game updates. Many popular titles celebrate this spooky season with fun festivities that can stretch from one week to even the whole month. As we draw closer and closer to Halloween, we'... | Read more »
Fire Rides guide - how to swing to succe...
It's another day, which means another Voodoo game has come to glue our hands to our mobile phones. Yes, it's been an especially prolific month for this particular mobile publisher, but we're certainly not complaining. Fire Rides is yet another... | Read more »

Price Scanner via

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
2017 3.5GHz 6-Core Mac Pro on sale for $2799,...
B&H Photo has the 2017 3.5GHz 6-Core Mac Pro (MD878LL/A) on sale today for $2799 including free shipping plus NY & NJ sales tax only . Their price is $200 off MSRP. Read more
12″ 1.2GHz Space Gray MacBook on sale for $11...
Amazon has the 2017 12″ 1.2GHz Space Gray Retina MacBook on sale for $100 off MSRP. Shipping is free: 12″ 1.2GHz Space Gray MacBook: $1199.99 $100 off MSRP Read more

Jobs Board

*Apple* Retail - Multiple Positions - Farmin...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Frameworks Engineer, *Apple* Watch - Apple...
Job Summary Join the team that is shaping the future of software development for Apple Watch! As a software engineer on the Apple Watch Frameworks team you will Read more
*Apple* News Product Marketing Mgr., Publish...
Job Summary The Apple News Product Marketing Manager will work closely with a cross-functional group to assist in defining and marketing new features and services. Read more
Fraud Analyst, *Apple* Advertising Platform...
Job Summary Apple Ad Platforms has an opportunity to redefine advertising on mobile devices. Apple reaches hundreds of millions of iPhone, iPod touch, and iPad Read more
*Apple* Information Security - Security Data...
Job Summary This role is responsible for helping to strengthen Apple 's information security posture through the identification and curation of security event data. Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.