TweetFollow Us on Twitter

Switcher
Volume Number:3
Issue Number:5
Column Tag:Forth Forum

Background Processing Under Switcher

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

Switcher is the closest thing to a multiprocessing system on the Macintosh (not counting Servant, a fully functional version of which has not seen the light of day as I write this, or Finder 6.0 which Apple is rumored to be developing). It is not really multiprocessing, since an application that is running in one partition of Switcher is put to sleep when you switch to another one. True multiprocessing is not easy to achieve on the Mac because it lacks memory management hardware (this, of course, has changed with the Mac II).

Switcher does support some background processing, however. The problem is that the application has to cooperate to allow background tasks to run. There is no way (no easy way, at least) that Switcher could interrupt a running application and transfer control to another one. It is the application itself that has to draw a clear line between foreground and background tasks, setting up pieces of its code to be run in the background that will by themselves transfer control back to Switcher.

This is very similar to the way multiprocessing is achieved in the various Forth and Forth-based systems that you've been reading about in this column. In those systems, tasks have to be cooperative and transfer control back to the task switcher at convenient points in their code (through words like PAUSE in MacForth and Mach2).

A Macintosh application under Switcher contains one interface point where control may be transferred to another task: the GetNextEvent routine. In fact, Switcher will only switch tasks on a call to GetNextEvent (when a switch request has been made).

It is at this point where background processing can take place. Every time an application calls GetNextEvent, Switcher will not only check whether you clicked the mouse on the double arrow or issued a keyboard command to initiate switching, but also check whether any of the installed applications contain background tasks that have to be run while they are inactive.

Such a background task routine may be a short piece of code that checks whether a character has come in from the serial port and stores it away in a file, or vice versa output from a file to a serial line. It may also run some ongoing calculations, collect data from an instrument, etc. It should return not too late after it has been called, in order not to cause too much slowing down of the active application. The backgound task will be part of an application installed under Switcher, where the task setup is done by the active part of the application and the task takes over when the application becomes inactive.

I'm sure none of you will be able to write a background task from these very general remarks. So how does one actually do it? A very useful document to read at this point is Inside Switcher (available through APDA). This document takes the same holistic approach as Inside Macintosh in that it requires you to understand all of it before you can make sense of the first paragraph (or nearly so), but otherwise gives a very good account about the things to observe when writing applications that are to run under Switcher.

First, lets look at the way task information is stored in Switcher. There is one global variable, SwitcherGlobals ($282), which contains a pointer to the beginning of the Switcher global variable area in the system heap. The structure of this area is described in Inside Switcher, and I'll shortly summarize it here.

The example listing contains the definitions for the Switcher tables. Each application is contained in a designated piece of memory, called a world, which is pointed to by one of the world pointers at the beginning of the Switcher globals. An application's world starts with an 18-byte header, followed by the application stack and heap area. The last 32K of a world are reserved for use by Switcher.

The header of a Switcher world contains in sequence:

- PSRPtr, a handle to the process state record of the application (explained later),

- a 2-byte flag field,

- BkgdProc, a pointer to a background procedure. Each installed application may have one BkgdProc associated with it, and Switcher calls them in sequence whenever a null event is fetched from the event queue. If this pointer is NIL, nothing is executed.

- SavScrBits, a handle to the part of memory that contains the saved screen bitmap of the application. If this is =0, the screen is not being saved.

- DAPtr, a window pointer to a virtual desk accessory that the Switcher uses for Clipboard conversion. (This procedure is explained in Inside Switcher, and I won't go into details here).

So all we'll have to do to execute a background routine under Switcher is to store a valid pointer to the routine in the BkgdProc field of the world header. Then Switcher will jump to that routine on each null event and probably come up with a beautiful bomb display unless the routine to execute is either extremely simple (such as RTS) or we have taken further precautions.

Ideally, we'd like to write the background task in Forth and execute it in our Forth system's world. To do this, you need some interface to the Forth code that can be jumped to directly and returns via an RTS. In Mach2, the Forth code itself has those properties, since it is subroutine threaded. In the case of MacForth (for example), we'll have to store the address of the routine's code field in the BkgdProc field of the Switcher world, and make sure the code returns via an RTS (and not through the Forth system's NEXT routine). The example program is in Mach2, but MacForth users will easily be able to adapt the code to their system following these principles. NEON users will have to define the background routine using :proc and ;proc, the words provided for defining routines whose addresses may be passed as parameters to toolbox traps.

The problem with executing a background task written in Forth using the surrounding support of the Forth system is of course that all existing Forth systems depend heavily on a set of registers in which parameter stack, return stack, user area pointers, loop indices, etc. are kept. The status of the registers, however, is completely undefined when Switcher calls the background routine. Therefore, the simple approach described above must fail.

In order to properly execute a background routine from outside, we have to do what is known as context switching, meaning that a) the register file has to be restored to the values used by the Forth system, and b) any system global variables that are used by the Forth system have to be restored as well. All this is done automatically by Switcher on switching applications, but not when calling a background task; that would be much too much overhead.

The full context switching is effected by Switcher through the information stored in the process state record of the application. This table is pointed to by the handle PSRPtr mentioned above. Its first four bytes contain its total size, followed by a copy of many of the low-memory globals used by the application. The location of important ones among them is given in Listing 1. Notice that StkLowPt and HeapEnd are contained here, these variables being consulted by the 'stack sniffer' to determine whether to display a System Error 28.

What interests us most here is that the last four bytes of the process state record contain the value of the stack pointer left behind when control was transferred to another application. The last thing saved on that stack before switching are registers A0-A6 and D0-D7, through a MOVEM.L A0-A6/D0-D7, -(A7).

Therefore, restoring A7 to the value left behind and then popping the other registers off the stack will leave us with a register set equal to the one left behind on switching. But... trying to do so is almost certain to get you a number 28 bomb, because A7 it totally out of line with the actual contents of StkLowPt and HeapEnd. There is an excellent chance that the stack sniffer will notice this and bang. The method I chose in the glue routine for calling background procedures is to use A0 as a temporary stack pointer and restore the registers from there. Since I do not change StkLowPt and HeapEnd, A7 must stay the same as well, so the A7 stack of the calling application is used for the background routine. This really doesn't make a big difference, as long as your routine doesn't do funny things with JSR return addresses left on the stack.

After the registers have been restored, of course, they're all valid for the context of the background task (including A5).

How does a background task know which Switcher world it is contained in (we need to know this to find the process state record and get the stack pointer)? Lets look at the example listing again at this point. I have provided a couple of words that are useful when running under Switcher. isSwitcher looks at the SwitcherGlobals pointer; if it is positive (i.e. the pointer is valid), Switcher is installed. Worlds will display the names of all installed applications. The way this is done is by looking at all of the eight world pointers, access the process state record for each application and display the string starting at PSR+344. This is where a copy of the system global AppName is kept. The general layout of the global variable space in the PSR can be seen from the listing; not all of the system globals are transferred on switching, but the variables for Quickdraw, Toolbox and the Segment Loader (starting at $800 in the 'real world') are saved consecutively starting at PSR+72.

ActiveWorld# displays the number of the world that the active application (Mach2, in this case) is currently running in. This routine gives interesting information, but is useless for code in a background routine to determine whether it is active or not (because we still don't know which application contains the background routine). Inside Switcher gives a recommendation: store the value of ApplZone (global $2AA) in variable space in your program when the application is initialized (storeApplZone does this), and later compare this saved value with the current value (IamActive is provided for this purpose).

I hope you're well enough 'primed' with some aspects of Switcher now so that we may continue with the actual problem of the day, installation of a Forth-written background routine that performs some useful task.

The routine that Switcher executes will be a glue routine that makes sure the register file is ok, calls the Forth routine that has to be executed, then restores the registers and returns to Switcher.

Switcher passes one parameter to the background routine, the task's WorldPtr in register A1. The glue routine first determines whether the application that contains the task is active or not. If the application is active, the process state record may be invalid (it is updated only when the application becomes inactive); therefore the actual background task will be skipped over in that case.

If the application is inactive, the glue routine gets the PSRPtr from the world header and restores the register file as described above. Then, control is passed to the background task. On return, everything is restored.

The background task in the example will open a text file and do a draft quality print (ASCII mode) on the Imagewriter. The program is adapted (rather heavily adapted) from an example given by Palo Alto Shipping on their demonstration disk. The original program was meant to print a file as a background task under Mach2, and therefore contained PAUSEs and async I/O calls. These features are not really needed here and have been removed. In fact, they're dangerous for what we are doing for the following reason:

It is not really possible to jump into the context of the Forth system by just restoring all registers and expecting everything else to behave. The problem is with the low memory system globals, which would have to be updated, too. It seems that anything that contains a PAUSE will bomb. One of the reasons for that might be that transfer will be given to other Mach2 tasks that try to write to the screen, and that is a no-no for background tasks according to Inside Switcher.

The other Forth routines, notably those which are called by offsetting from A5 or going through a jump table, will execute normally from the background. Macintalk will bomb; anything that requires calls to the Segment Loader, probably, too (I haven't tried this).

The printing routine, then, does the following: From the foreground, a file to print is selected. Then the background task is installed; when the application becomes inactive, it will start to read the file in 512-byte chunks and dump it on the printer. Meanwhile, you will be able to use other applications under Switcher. However: 512 byte blocks are really too large to make the other programs run smoothly. I haven't changed the block size in the example, but it is an easy matter to do so; it might even be better to transfer only one character on each call of the background task. Anyway, the example does illustrate the point, and you'll be able to install other background processes this way (and/or translate the whole thing to NEON or MacForth).

After a file has been printed, the SFGetFile dialog comes up again (in the foreground), and you can select another one. Cancelling the dialog will remove the printing routine from the Switcher worlds.

Concluding remarks

There is a lot more to be said about Switcher: how to access one application's variables from another program, how to deal with VBL routines and asynchronous I/O, how to switch automatically from within a program, clipboard conversion, suspend/resume events, etc. etc. But I cannot repeat Inside Switcher here, so I'd strongly suggest you to get a copy from APDA in case these subjects are of any interest to you.

Last time I had promised to give some more hints about DA programming from Forth; we'll put that off for a later column.

There is one last comment I have to make concerning the eternal MacForth vs. The Other Forths issue. I happen to use Mach2 for the examples in my column; this shouldn't be viewed as a bias on the part of MacTutor or myself for one particular system. It is just that I prefer to become familiar with one development system rather than trying to cover everything. I try to keep the Forth code quite generic, to facilitate translation into other dialects, or use assembler. Since (I hope) this column is also read by people who develop in other languages, it is also important to stay rather close to the toolbox, which Mach2 happens to do. Combine this with an assembler syntax which conforms to the Motorola syntax, and the code should be easily translatable into C or Pascal as well.

I realize that there are many of you readers out there who do a lot of development in other Forth dialects. As you know, I always welcome contributions by readers to add some variety to this column. So if you have an interesting example in MacForth, Mach2, MasterForth or another Forth, or NEON, by all means write it up and send it to me (directly to my address given in the masthead).

We're hoping to hear from you. Until next month, happy threading.

Listing 1: Switcher background printing example
( Forth background applications under Switcher )
( Feb 1987 J. Langowski / MacTutor )
( raw printing example adopted from Mach2 example disk )
( for background printing under Switcher )

only forth also assembler also mac 
HEX

( =============== File System Equates ============= )


1CONSTANT fsRdPerm ( read-only)
2CONSTANT fsWrPerm ( write-only)
3CONSTANT fsRdWrPerm ( read-write)

0CONSTANT fsAtMark
1CONSTANT fsFromStart
2CONSTANT fsFromLEOF
3CONSTANT fsFromMark

3CONSTANT stdFile

0CONSTANT    rGood
6CONSTANT    rVolume
ACONSTANT    rName

CCONSTANT ioCompletion
10 CONSTANT ioResult
12 CONSTANT ioFileName
16 CONSTANT ioVRefNum
18 CONSTANT ioRefNum
1A CONSTANT ioFileType
1B CONSTANT ioPermssn
1C CONSTANT ioMisc
20 CONSTANT ioBuffer
24 CONSTANT ioReqCount
28 CONSTANT ioActCount
2C CONSTANT ioPosMode
2E CONSTANT ioPosOffset

FFD9  CONSTANT PastEOF 
 ( error code -39. used in file read operations )  
DECIMAL
HEADER  typeList
 DC.B 'TEXT'

HEADER  sfReplyA
 DC.B 0 ( good )
 DC.B 0 ( copy   pg.25 PackSF )
 DC.B 'TEXT'( fType )
 DC.W 0 ( vRefNum )
 DC.W 0 ( version )
 DCB.B  64,0( fName [string 63] )  
HEADER  PortBOut
 DC.B 5
 DC.B '.Bout'
 
( ====  Various Imagewriter commands ======= )

( Top-Of-Form    CTRL-L   $0C  )
( Software Reset ESC C    $1B $63  )
( LF's after CR'sESC D @ CTRL-@ $1B  $44 $80 $00  )
( No LF's after CR's ESC Z @ CTRL-@ $1B      $5A $80 $00  )
( cancels all unprinted   CTRL-X   $18  )

HEADER AddLFs  
 DC.B $1B
 DC.B $44
 DC.B $80
 DC.B $00
 
HEADER AddTabs 
 DC.B $1B
 DC.B $28
 DC.B '008,016,024,032,040,048,056,064'
 
HEADER FormFeed
 DC.B $0C
 
DECIMAL
LABEL CRCounter
 DS.L 1
 
LABEL LeavePrintFlag
 DS.W 1
 
LABEL MyBuffer
 DS.B 512
 
LABEL FilePBlock
 DS.B 50
 
LABEL PrintPBlock
 DS.B 50
 

( These are the old routines )
( given by Palo Alto Shipping in the Mach 2.0 examples. )
( Since it's all in assembler, we can be sure that no calls )
( are made to the multitasking system which would interfere )
( with our background processing )

( ====  Get File Info ====== )

( Ask for the file to be converted)

CODE GetFInfo
 MOVE.W #80,-(A7)( where.h )
 MOVE.W #50,-(A7)( where.v )
 CLR.L  -(A7)    ( prompt not used )
 CLR.L  -(A7)    ( we don't need filter )
 MOVE.W #1,-(A7) ( look for 1 type )
 PEA    typeList ( pointer to typeList )
 CLR.L  -(A7)    ( no dlgHook )
 PEA    sfReplyA ( push address of reply record)
 MOVE.W #2,-(A7) ( for SFGetFile )
 _Pack3 ( call package )
 LEA    sfReplyA,A0( Point to sfReply )
 TST.B  rGood(A0)(If cancel was clicked, return)
 BEQ.S  @2
 
( Open the source file)

 LEA    filePBlock,A1( Point to param block )
 CLR.L  ioCompletion(A1)  ( No completion routine )
 PEA    rName(A0)( Point to file name )
 MOVE.L (A7)+,ioFileName(A1)
 ( Store pointer in diskPBlock)
 MOVE.W rVolume(A0),ioVRefNum(A1) 
 ( Store vRefNum in diskPBlock)
 CLR.B  ioFileType(A1)  ( Must set file type = 0 )
 MOVE.B #fsRdPerm,ioPermssn(A1) 
 ( Open for read only )
 CLR.L  ioMisc(A1) ( Use system buffer  )
 MOVE.L A1,A0    ( A0 points to diskPBlock  )
 _Open  ( Open the file )
 TST.B  D0
 BNE.S  @1
 MOVE.W 24(A0),22(A0)
 ( move ioRefNum into position)
 MOVE.W #1,44(A0)( ioPosMode from beginning)
 CLR.L  46(A0)   ( ioPosOffset of 0)
 _SetFPos ( this will reset the file)
 LEA  CRCounter,A0
 CLR.L  (A0)
 RTS
@1 MOVE.W #1,-(A7)
 _SysBEEP
@2 _ExitToShell
END-CODE


( ***** Initialize Port B  ***** )

CODE InitPortB ( SerOpenBOut) 
 LEA    PrintPBlock,A0  ( Head of PBBlock)  
 CLR.L  $C(A0)   ( No completion routine )
 LEA    PortBOut,A1( ioNamePtr )
 MOVE.L A1,$12(A0) 
 MOVE.B #0,$1B(A0) ( Ask for all permission )
 MOVE.W #-9,$18(A0)( ioRefNum )
 _Open

( SerRstBOut)  
 LEA    PrintPBlock,A0  ( Head of block )
 MOVE.W #-9,$18(A0)( ioRefNum  )
 MOVE.W #$0008,$1A(A0)  ( Control number )
 MOVE.W #$CC0A,$1C(A0)  
 ( 9600 Baud,8d,2s,no parity )
 _Control
 
( Configure)
 LEA    PrintPBlock,A0
 CLR.L  12(A0)   ( ioCompletion )
 LEA    AddLFs,A1
 MOVE.L A1,32(A0)( ioBuffer  )
 MOVE.L #4,36(A0)( ioReqCount )
 _Write
 LEA    PrintPBlock,A0
 CLR.L  12(A0)   ( ioCompletion )
 LEA    AddTabs,A1
 MOVE.L A1,32(A0)( ioBuffer )
 MOVE.L #34,36(A0) ( ioReqCount )
 _Write
 
( ClrLeaveFlag)  
 LEA    LeavePrintFlag,A0
 CLR.W  (A0)
 RTS
END-CODE
 
 
( ====   Read a block from the file ======= )

CODE ReadBlock
 LEA  FilePBlock,A0
 CLR.L  12(A0)   ( ioCompletion)
 LEA    MyBuffer,A1
 MOVE.L A1,32(A0)( ioBuffer)
 MOVE.L #512,36(A0)( ioReqCount)
 CLR.W  44(A0) ( ioPosMode, from current mark)
 _Read 
 
@3 CMPI.L #512,40(A0)( ioActCount )
 BEQ.S  @2
 
 LEA    LeavePrintFlag,A1
 MOVE.W #$FF,(A1)
@2 RTS
END-CODE


( ***** Put in the page breaks ***** )

( Search thru MyBuffer for CR's -> $0D. 
  In place of every 60th one, I will insert a $0C, 
  which, when sent to an Imagewriter, will generate a form feed.  )

CODE PutPageBreaks
 LEA    FilePBlock,A0
 MOVE.L 40(A0),D0( ioActCount  )
 LEA    MyBuffer,A1
 LEA    CRCounter,A0
 CLR.L  D1
@1 CMPI.B #$0D,0(A1,D1) (  carriage returns )
 BEQ.S  @2
@3 ADDQ.L #1,D1  ( increment address offset )
 SUBQ.L #1,D0  ( decrement byte counter )
 BNE.S  @1
 RTS    ( ***** this is the exit point *** )
 
@2 ADDQ.L #1,(A0)
 CMPI.L #60,(A0)
 BNE.S  @3( if this is the 60th CR )
 
 MOVE.B #$0C,0(A1,D1)( then insert a FF char  )
 CLR.L  (A0)( and reset the crcounter )
 BRA.S  @3
END-CODE
 
 
( *****  Write out a block to port B ***** )

CODE WriteBlock
 LEA  PrintPBlock,A0
 CLR.L  12(A0)   ( ioCompletion)
 LEA  MyBuffer,A1
 MOVE.L A1,32(A0)( ioBuffer)
 LEA  FilePBlock,A1
 MOVE.L 40(A1),36(A0)
 ( move ActCount into ReqCount)
 _Write 
 RTS
END-CODE
 
( *****   Feed the final form feed  ***** )

CODE DoFormFeed
 LEA  PrintPBlock,A0
 CLR.L  12(A0)   ( ioCompletion )
 LEA  FormFeed,A1
 MOVE.L A1,32(A0)( ioBuffer )
 MOVE.L #1,36(A0)( ioReqCount)
 _Write
 RTS
END-CODE
 
( ***** Close the file ***** )

CODE ClFile
 LEA    FilePBlock,A0
 CLR.L  12(A0) ( ioCompletion)
 _Close ( ioRefNum should still be there)
 RTS
END-CODE
 
( *****  Main Thing ***** )
: Print.bkg
 LeavePrintFlag W@ 0=
 IF   ( 5 call sysbeep )  ( for testing )
 ReadBlock( read a block in from file )
 PutPageBreaks ( insert form feeds every 60 lines)
 WriteBlock ( write the block to port B )
 THEN
;

( **** globals )
HEX
282 CONSTANT SwitcherGlobals
286 CONSTANT MemToSwitch
2AA CONSTANT ApplZone
910 CONSTANT CurApName
DECIMAL

( **** Switcher globals )
 0 CONSTANT World0 ( pointer )
 4 CONSTANT World1 ( pointer )
 8 CONSTANT World2 ( pointer )
12 CONSTANT World3 ( pointer )
16 CONSTANT World4 ( pointer )
20 CONSTANT World5 ( pointer )
24 CONSTANT World6 ( pointer )
28 CONSTANT World7 ( pointer )
32 CONSTANT HostTask ( pointer )
36 CONSTANT TheTask( pointer )
40 CONSTANT Flags( word )
50 CONSTANT ArrowEnable ( byte )
51 CONSTANT ClipConvert ( byte )
52 CONSTANT Hibernation ( word )
54 CONSTANT MainZone ( pointer )
58 CONSTANT CoreTable( 6 LongInts )
90 CONSTANT NextTask ( pointer )
96 CONSTANT SwitcherName  ( Str255 )

( **** structure of a world )
 0 CONSTANT PSRPtr ( pointer to PSR )
 4 CONSTANT WorldFlags  ( word )
 6 CONSTANT BkgdProc ( pointer to background routine )
10 CONSTANT SavScrBits  ( pointer to saved Screenbits )
14 CONSTANT DAPtr( pointer to virtual DA )
18 CONSTANT StackHeap( stack & heap starts here... )

( **** Switcher process state record )
 0 CONSTANT Size ( LongInt : PSR size )
 4 CONSTANT myMonkey ( word )
 6 CONSTANT MemTop ( address of end of RAM for this process)
10 CONSTANT BufPtr ( address of end of jump table )
14 CONSTANT StkLowPt ( lowest stack address )
18 CONSTANT HeapEnd( address of top of heap )
22 CONSTANT TheZone( address of current heap zone )
26 CONSTANT ApplLimit( application heap limit )
30 CONSTANT SEvtEnb( 4 bytes )
34 CONSTANT MyApplZone  ( application heap zone )
38 CONSTANT MinStack
72 CONSTANT GrafBegin
332 CONSTANT MyA5( hex 14C )
344 CONSTANT MyName
836 CONSTANT DefVCBPtr  ( pointer to default VCB )

( **** event record structure )
 0 CONSTANT      what     ( Integer )
 2 CONSTANT      message  ( LongInt )
 6 CONSTANT      when     ( LongInt ) 
10 CONSTANT      where    ( Point )
14 CONSTANT      modifiers  ( Integer )

VARIABLE thisApplZone ( for intermediate storage )

( **** definitions )

: =string { aStr bStr | -- flag }
 aStr count 65536 * bStr count rot + swap
 call CmpString 0=
;

: isSwitcher SwitcherGlobals @ 0> ;

: Worlds { | SwGl -- }
 SwitcherGlobals @ -> SwGl 
 SwGl 0> 
 IF
 8 0 DO
 I 4 * SwGl + @ ?dup ( world # i non-NIL ? )
 IF 
 cr ." World No." i . ." : "
 @ @ MyName + count type 
 THEN
 LOOP
 THEN
;

: ActiveWorld# { | SwGl wn -- world number }
 SwitcherGlobals @ -> SwGl
 -1 -> wn 
 SwGl 0> 
 IF
 8 0 DO 
 I 4 * SwGl + @ ?dup ( world # i non-NIL ? )
 IF 
 @ @ MyApplZone + @ ApplZone @ =
 IF I -> wn leave THEN
 THEN
 LOOP
 THEN
 wn
;

( this routine should be called immediately after launch )
( or in any case before a background routine is installed )
: storeApplZone ApplZone @ thisApplZone ! ;

: IamActive thisApplZone @ ApplZone @ = ;

HEADER tempA7    DC.L 0
HEADER myWorld   DC.L 0
HEADER myPSRPtr  DC.L 0

CODE Bkg.glue
 MOVE.W   SR,-(A7)
 MOVEM.L  D0-D7/A0-A6,-(A7)
 LEA    tempA7,A0
 MOVE.L   A7,(A0)
 LEA    myWorld,A0
 MOVE.L   A1,(A0)
 MOVE.L   (A1),A1( PSRPtr -> A1 )
 LEA    myPSRPtr,A0
 MOVE.L   (A1),(A0)
 LEA    SwitcherGlobals,A0
 MOVE.L   (A0),A0
 CMPA.L theTask(A0),A1
 BEQ.S  @1
 ( we're active, so don't execute background )
 MOVE.L   (A1),A1( start of PSR )
 MOVE.L   (A1),A0( size of PSR )
 ADDA.L   A1,A0  
 SUBQ.L   #4,A0  (left stack pointer behind here)
 MOVE.L   (A0),A0
 MOVEM.L  (A0)+,D0-D7/A0-A6  
 ( restore MACH2 register set, except A7 )
 LEA    myPSRPtr,A0
 MOVE.L   (A0),A1   
 ( just in case the background routine needs it )

 JSR    print.bkg

@1 LEA  tempA7,A0
 MOVE.L   (A0),A7
 MOVEM.L  (A7)+,D0-D7/A0-A6
 MOVE.W   (A7)+,SR
 RTS
END-CODE MACH


1000 6000 BACKGROUND printer
 
: initBkg
 IamActive IF
 GetFInfo ( open file to print, exit if cancel )
 ['] Bkg.Glue
 SwitcherGlobals @ ActiveWorld# 4 * + @
 BkgdProc +
 !
 InitPortB
 THEN
;

: rmvBkg
 IamActive IF
 0
 SwitcherGlobals @ ActiveWorld# 4 * + @
 BkgdProc +
 !
 THEN
;

: startme
 storeapplzone
 BEGIN
 initbkg
 BEGIN PAUSE LeavePrintFlag w@ UNTIL
 rmvbkg
 AGAIN
;

: backgo ACTIVATE startme ;

: main  printer BUILD
 printer backgo
;
 
(  turnkey main backprint 
 would now create the background printing application. )
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Jump into one of Volkswagen's most...
We spoke about PUBG Mobile yesterday and their Esports development, so it is a little early to revisit them, but we have to because this is just too amusing. Someone needs to tell Krafton that PUBG Mobile is a massive title because out of all the... | Read more »
PUBG Mobile will be releasing more ways...
The emergence of Esports is perhaps one of the best things to happen in gaming. It shows our little hobby can be a serious thing, gets more people intrigued, and allows players to use their skills to earn money. And on that last point, PUBG Mobile... | Read more »
Genshin Impact 5.1 launches October 9th...
If you played version 5.0 of Genshin Impact, you would probably be a bit bummed by the lack of a Pyro version of the Traveller. Well, annoyingly HoYo has stopped short of officially announcing them in 5.1 outside a possible sighting in livestream... | Read more »
A Phoenix from the Ashes – The TouchArca...
Hello! We are still in a transitional phase of moving the podcast entirely to our Patreon, but in the meantime the only way we can get the show’s feed pushed out to where it needs to go is to post it to the website. However, the wheels are in motion... | Read more »
Race with the power of the gods as KartR...
I have mentioned it before, somewhere in the aether, but I love mythology. Primarily Norse, but I will take whatever you have. Recently KartRider Rush+ took on the Arthurian legends, a great piece of British mythology, and now they have moved on... | Read more »
Tackle some terrifying bosses in a new g...
Blue Archive has recently released its latest update, packed with quite an arsenal of content. Named Rowdy and Cheery, you will take part in an all-new game mode, recruit two new students, and follow the team's adventures in Hyakkiyako. [Read... | Read more »
Embrace a peaceful life in Middle-Earth...
The Lord of the Rings series shows us what happens to enterprising Hobbits such as Frodo, Bilbo, Sam, Merry and Pippin if they don’t stay in their lane and decide to leave the Shire. It looks bloody dangerous, which is why September 23rd is an... | Read more »
Athena Crisis launches on all platforms...
Athena Crisis is a game I have been following during its development, and not just because of its brilliant marketing genius of letting you play a level on the webpage. Well for me, and I assume many of you, the wait is over as Athena Crisis has... | Read more »
Victrix Pro BFG Tekken 8 Rage Art Editio...
For our last full controller review on TouchArcade, I’ve been using the Victrix Pro BFG Tekken 8 Rage Art Edition for PC and PlayStation across my Steam Deck, PS5, and PS4 Pro for over a month now. | Read more »
Matchday Champions celebrates early acce...
Since colossally shooting themselves in the foot with a bazooka and fumbling their deal with EA Sports, FIFA is no doubt scrambling for other games to plaster its name on to cover the financial blackhole they made themselves. Enter Matchday, with... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra available today at Apple fo...
Apple has several Certified Refurbished Apple Watch Ultra models available in their online store for $589, or $210 off original MSRP. Each Watch includes Apple’s standard one-year warranty, a new... Read more
Amazon is offering coupons worth up to $109 o...
Amazon is offering clippable coupons worth up to $109 off MSRP on certain Silver and Blue M3-powered 24″ iMacs, each including free shipping. With the coupons, these iMacs are $150-$200 off Apple’s... Read more
Amazon is offering coupons to take up to $50...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for up to $110 off MSRP, each including free delivery. Prices are valid after free coupons available on each mini’s product page, detailed... Read more
Use your Education discount to take up to $10...
Need a new Apple iPad? If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $100 off the... Read more
Apple has 15-inch M2 MacBook Airs available f...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
Mac Studio with M2 Max CPU on sale for $1749,...
B&H Photo has the standard-configuration Mac Studio model with Apple’s M2 Max CPU in stock today and on sale for $250 off MSRP, now $1749 (12-Core CPU and 32GB RAM/512GB SSD). B&H offers... Read more
Save up to $260 on a 15-inch M3 MacBook Pro w...
Apple has Certified Refurbished 15″ M3 MacBook Airs in stock today starting at only $1099 and ranging up to $260 off MSRP. These are the cheapest M3-powered 15″ MacBook Airs for sale today at Apple.... Read more
Apple has 16-inch M3 Pro MacBook Pro in stock...
Apple has a full line of 16″ M3 Pro MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $440 off MSRP. Each model features a new outer case, shipping is free, and an... Read more
Apple M2 Mac minis on sale for $120-$200 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $110-$200 off MSRP this weekend, each including free delivery: – Mac mini M2/256GB SSD: $469, save $130 – Mac mini M2/512GB SSD: $689.... Read more
Clearance 9th-generation iPads are in stock t...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on clearance sale for starting at only $199 on their online store for a limited time. Sale prices for online orders only, in-store prices may vary... Read more

Jobs Board

Senior Mobile Engineer-Android/ *Apple* - Ge...
…Trust/Other Required:** NACI (T1) **Job Family:** Systems Engineering **Skills:** Apple Devices,Device Management,Mobile Device Management (MDM) **Experience:** 10 + Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Full Time (80 hrs/pay period) Evenings General Summary Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.