cpct_disableFirmware

Disables Amstrad CPC firmware, preventing it from being executed at every CPU interrupt.

C Definition

u16 cpct_disableFirmware ()

Assembly call

call cpct_disableFirmware_asm

Return value

<u16>Present interrupt handler code (normally, pointer to firmware ROM code).  This value should be stored to restore it later, if required.

Details

Disables the firmware modifying the interrupt vector at memory location 0x38.  Normally, firmware routines are called and executed at every interrupt and the ROM entry point is stored at 0x38 (a 16-bit address where the firmware code starts).  This function substitutes the 2 bytes located at 0x38 by 0xC9FB, (0xFB = EI, 0xC9 = RET), which basically does nothing at each interruption (restores interrupts and returns).

Before inserting 0xC9FB at 0x38, the 2 bytes lying there are saved into DE.  These 2 bytes are returned to the caller, to let them be stored and restored later on, if normal firmware operation (or previous interrupt handler) is required.  cpct_reenableFirmware may be used for this restoring operation.

Disabling the firmware is useful for several reasons

  • Firmware code gets executed 6 times per frame (1 at each interrupt) when is active.  If you turn it off, you win CPU clock cycles for your program, because firmware will not execute anymore.
  • Most of CPCtelera’s functions talk directly to hardware, no to firmware.  They are faster, but they do not change firmware variables.  As a result, firmware can revert changes made by CPCtelera’s functions when active.  For instance, if you change to video mode 0 using CPCtelera’s functions, firmware will see that the video mode is different from what it should be (attending to its own variables) and will change it again to 1.  This happens with video modes and palette values mainly.
  • Also, firmware uses part of the RAM to store its variables (from 0xA6FC to 0xBFFF).  If you accidentaly overwrite anything there with firmware being active, unpredictable things will happen, even hanging the computer.  Moreover, disabling firmware lets you use this part of the RAM for your own uses.

Destroyed Register values

HL

Required memory

16 bytes

Time Measures

Case | microSecs (us) | CPU Cycles
--------------------------------------
Any  |      22        |     88
--------------------------------------

Credits

This function was coded copying and modifying cpc_disableFirmware from CPCRSLib by Raul Simarro.

Disables Amstrad CPC firmware, preventing it from being executed at every CPU interrupt.
Reenables previously disabled Amstrad CPC firmware.
Close