Posted in Programming

Amiga Nostalgia: The differences between Forbid() and Disable()

For example on Commodore 64 one can use absolute memory addresses somewhat freely; it is sufficient to know the memory map of C64. But on Amiga the case is completely different, because Amiga has multitasking operating system.

As it comes to allocating memory, even if one programs ”hard coded” program, that is: A program that overrides the operation of the operating system and use use directly Amiga’s hardware (Amiga has few co-processors), one can’t assume, that one can ”steal” memory anywhere one wants. In other words one can’t use absolute memory addressing and put one’s data anywhere one wants, because when the user closes the program, the whole multitasking environment can be ”broken”: There can be ”garbage” on the screen or some programs may have crashed, because the ”hard coded” program may have written its own data instead of the data on previously running programs in multitasking environment.

Still, on Amiga there is one absolute memory address, that every programmer in practice must use to get anything done when using the OS, namely address 4. From that memory address one gets so called execbase, that is necessary to call any system routines.

In order to make ”hard coded” program run faster on an Amiga it is practically necessary to stop the operation of the operating system (on an Amiga the OS routines are in ROM, though there are libraries, that are loaded (”opened” by the language of the programmer) to RAM that add more functionality to the OS). There are two ways to do that: To call OS’s Forbid() or Disable().

Image courtesy of jesadaphorn at
Image courtesy of jesadaphorn at

Using Forbid() is ”nice” way to stop the operation of the operating system, it forbids the task swapping of the OS, that is: All the programs on the background on the OS are stopped, until Wait() routine is called (or some of the Intuition library’s routines). Of course, when one codes “hard coded” program, one probably doesn’t use OS’s Wait(), but one’s own code using directly the hardware. When exiting ”hard coded” program, the programmer must now call Permit() in order to make the OS continue its tasks normally.

A way to get ”hard coded” program to run even faster, is to use Disable(), but that is quite naughty way to stop OS considering that the user may have a lot of programs and tasks running on the OS. Disable() stops the interruptions of the OS on the background, that is: The running of all the programs and also the interruption routines of them are stopped.

Wait() routine allows interruptions regardless of Disable(), but returns the ”disabled state” after the CPU has finished the Wait() routine. Though, again in ”hard coded” programs, the programmer doesn’t probably use Wait(), but one’s own code to wait for something using directly the hardware.

If Disable() has been used, in the end of the program, one must use Enable() in order to get the OS functioning again. But if the programmer has used Disable(), there is no way to guarantee that even after Enable(), the OS is functioning normally as it was before executing the ”hard coded” program.

Still, there are some speed critical things or things where OS must be stopped for just a ”short” time on Amiga, where Disable() may be the only way to get a program working properly. Now, because Disable() ”forbids” interruption requests of the OS by setting Paula’s (a co-processor) INTENA register’s bit 14, it’s also a question of how long Disable() has stopped the OS; the longer the Disable() has stopped the OS, the more uncertain it is, that the OS is working completely – if at all – normally after Enable(). Usually the interruptions of the OS should not be stopped for over 250 microseconds at once.