The following is the chain of operations performed by IZ80Processor whenever memory is read, either because opcodes are being fetched or as part of the processing of an instruction.
- The
MemoryAccess
event is triggered withMemoryAccessEventArgs.EventType
equal toBeforeMemoryRead
andValue
equal to FFh. The code handling the event has the opportunity to setMemoryAccessEventArgs.CancelMemoryAccess
to true and/or change the value. - If the configured memory access mode for the affected address is
ReadAndWrite
orReadOnly
, and theCancelMemoryAccess
property of the event has not been set to true, the value is read by accessingMemory[address]
. Otherwise, the value set on the previous step is used as if it was actually obtained from memory. - The
MemoryAccess
event is triggered withMemoryAccessEventArgs.EventType
equal toAfterMemoryRead
. The code handling the event has the opportunity to change the value. - The value in
MemoryAccessEventArgs.Value
is assumed to be the obtained value and is processed appropriately.
As for the operations performed for a memory write, they are the following:
- The
MemoryAccess
event is triggered withMemoryAccessEventArgs.EventType
equal toBeforeMemoryWrite
. The code listening the event has the opportunity to either change the value to be written or setMemoryAccessEventArgs.CancelMemoryAccess
to true. - If the configured memory access mode for the affected address is
ReadAndWrite
orWriteOnly
, and theCancelMemoryAccess
property of the event has not been set to true, the value set on the previous step is written toMemory[address]
. - The
MemoryAccess
event is triggered withMemoryAccessEventArgs.EventType
equal toAfterMemoryWrite
.
The code of the processor class takes care of the extra wait states needed for timing purposes.
The flow for accessing I/O ports is similar, but PortsSpace
is used instead of Memory
and the 'Port' members of MemoryAccessEventArgs.EventType
are used instead of the 'Memory' members.
Note that MemoryAccessEventArgs inherits from ProcessorEventArgs, which defines the LocalUserState
property. This property is propagated from the 'before' event to the 'after' event and can be used by the events handling code at its convenience.