•  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.7  Clean programming                                          TOS

Even if the specific implementation of MagiC Mac is not of interest to 
every Atari programmer, there are some basic rules that one should 
adhere to on the Atari level to be as certain as possible that the 
programs can run also under MagiC Mac. Here the following points can 
be mentioned, amongst others:

   . Self-modifying code
     When code (also applies for XBRA vectors) is altered, it is 
     imperative that the CPU cache is purged. Although by testing one 
     can ascertain whether this is not necessary on a 68020 with its 
     small cache, one can never be certain: On the Mac there is a 68k 
     emulator for the PowerPC machines that simulates a 68020, which, 
     first, has a larger cache than a real 68020 (inclusive of a data 
     cache which is otherwise present only with the 68030), and second 
     also compiles the code into PowerPC code.

     If the code of an Atari program is then changed, the emulator can 
     only recognize this is a command for cache purging is executed. 
     Equally, a cache purge is necessay as a rule with the 68040/60 
     CPUs! Here is the code with which the whole cache is purged in 
     such cases:

      Prozessor  Code

      68020/30
                       MOVE  CACR,D
                       ORI.W #$0808,D0
                       MOVE  D0,CACR
                 or also like this:
                       DC.W  $4E7A,$0002,$0040,$0808,$4E7B,$0002
      68040/60
                       NOP
                       CPUSHA DC/IC
                 or:
                       DC.W   $4E71,$F4F8

     The processor type should be obtained for this by inspection of 
     the _CPU cookie.

   . Blocking interrupts
     If the interrupts have to be bloked for a short time, then never 
     set the SR afterwards to the fixed value $2300, but save the old 
     SR if possible before the blocking (say onto the stack) and then 
     load it back again afterwards. If it is imperative that a reset 
     of the SR is to take place irrerspective of the old SR, then set 
     the interrupt mask to zero and not to three, so for instance MOVE 
     #$2000,SR instead of MOVE #$2300,SR. The Atari operating system 
     then automatically looks after converting the mask value to 3, 
     while the mask remains on 0 for the Mac; because otherwise 
     nothing works any more.

   . Hardware accesses
     Before programming certain hardware registers directly (e.g. the 
     Centronics port for printing), one should check the _MCH cookie. 
     If its value is $FFFFFFFF (dec. -1), then it means that no Atari 
     hardware is present (so that the program is running on the 
     Macintosh, for instance) and therefore one shouldn't even try to 
     access the hardware since there may well be RAM there, which of 
     course may not be altered by such accesses.

   . Supervisor-mode
     Since multitasking operating systems such as MultiTOS and MagiC 
     have came into use, no program should arbitrarily change the 
     supervisor stack pointer, say to obtain a larger stack, as this 
     could lead to incalculable system crashes (on the PCI Macs, for 
     instance, a very large supervisor stack is required: at least 8 
     MB, but in some circumstances even 24 MB - only the operating 
     system can know this and install it correctly). Important: To get 
     into the supervisor-mode, never use the GEMDOS function Super, 
     but use Supexec from the BIOS instead. Only Supexec can ensure 
     that a sufficiently large supervisor stack will be used.

See also:
Programming guidelines   Style guidelines   XBRA procedure