•  Back 
  •  MagiC Mac specifics 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help page 
  •  Show info about hypertext 
  •  View a new file 
Topic       : TOS - The Operating System
Author      : 
Version     : tos.hyp (December 19, 2008)
Subject     : Programmieren/Atari
Nodes       : 3010
Index Size  : 93790
HCP-Version : 5
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : Title
@help       : 
@options    : +g -i -s +x +zz -t4
@width      : 70
View Ref-File12.1.6  Exceptions under MagiC Mac                                 TOS

As on a real Atari, an Atari program running under MagiC Mac can use 
the exception vectors, namely divert them. Actually the program may 
use only the exception vectors between $0 and $400 for this, not those 
to which the VBR points (because that points elsewhere!). Those who do 
not adhere to this may run into difficulties with later versions of 
MagiC Mac. Programs that use the PMMU, e.g. OUTSIDE can not run under 
MagiC Mac.

The following Atari interrupts are simulated by the kernel at present:

   . $070: Autovector interupt Level 4 (VBL)

   . $114: MFP interrupt 5 (200 Hz system timer)

   . $118: MFP interrupt 6 (IKBD). Actually only the event of key 
     presses and mouse movements is simulated here, i.e. the interrupt 
     handler obtains the specific type of the event in some other way 
     than on the Atari.

Due to the Mac hardware, however, the interrupts may appear with 
different priorities; consequently the interrupt mask of the SR has 
other values to that on an Atari in some circumstances. The vector at 
$400 (etv_timer) will also be jumped to by the MagiC OS, of course, as 
a subroutine of the interrupt handler for MFP interrupt 5, in just the 
same way as on an original Atari.

Likewise a program that would like to experience mouse or keyboard 
events can use the BIOS function Kbdvbase to hook itself into the 
event vectors in exactly the same way as on the Atari.

Another important note about interrupts: So that the keyboard, mouse 
and timer work properly on a Mac, the interrupt mask (in CPU register 
SR) must always be zero. On an Atari, on the other hand, it normally 
stands at three. Programs containing code such as MOVE #$2300,SR for 
instance, would put a Macintosh into a sleep state, which only a reset 
can remedy. Those who want to alter the interrupt mask only 
occasionally should do it this way (works equally well on an Atari and 
Mac):

  MOVE SR,-(a7)    ; Store old SR
  ORI  #$0700,SR   ; Block all interrupts for a critical access
  ...
  MOVE (a7)+,SR    ; At end, restore old SR

Those who definitely want to return the computer to its basic state 
should not use MOVE #$2300,SR but better MOVE #$2000,SR. On the Atari 
the SR will then be increased to $2300 just before the HBL interrupt 
routine. In this way the same code achieves te same result on both 
machines.

If interrupt or other asynchronous routines are installed by means of 
MacOS functions and then these functions are to switch from the Mac- 
mode to the Atari-mode, then several things need to be heeded, which 
are described in greater detail below:

   . Setting of a semaphore (see intrLock/intrUnlock)

   . Query whether an Atari-mode switch is even possible at the time 
     (see atariModePossible)

   . Deinstallation of the routine at the termination of MagiC Mac 
     (see macAppSwitch)

   . Before switching into the Atari-mode one must ensure that the 
     stack pointer (SP) lies within the Atari address space, since 
     otherwise a double bus error arises and the CPU will come to a 
     standstill

     Note: First: It may be that the call of the routine by the MacOS 
     occurs at a time when another Mac application is running, in 
     which case the current stack is not that of MagiC Mac. Second: 
     With the 68k machines, in Atari-mode only the address space of 
     the 2 TPAs, the lowest 32 kB, if necessary the I/O area as well 
     as the area of the MagiC Mac application is visible; other memory 
     of MacOS and other Mac applications is blanked out, and only bus 
     errors will arise if access is attempted. To sum up: To make sure 
     that the SP lies in the Atari address space when switching into 
     the Atari MMU mode, one must previously reserve a stack area for 
     this and then use that. To ensure that the stack is large enough 
     (1-2 kB are clearly not enough!) one should heed the cookie value 
     minStackSize!

   . Always switch to supervisor-mode before 'modeAtari' is called 
     (else it won't run under virtual memory). The following code is 
     suggested for this:

                  clr     d0
                  move    sr,d0
                  btst    #13,d0
                  bne     ok1
                  moveq   #8,d0        ;   Enter supervisor-mode
                  dc.w    $A08D        ;   _DebugUtil
            ok1:
                  move    d0,-(a7)     ;   Save the old mode
 
                  ; Here now modeAtari ... Call modeMac etc.
 
                  move.w  (a7)+,sr     ;   Restore old mode

   . Mac subroutines may only alter the registers d0-d2/a0/a1 as a 
     rule, though not (as often usual on the Atari), a2!

See also: Program launch and TPA   Reset-vector   System variables