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
MemoryAccessevent is triggered withMemoryAccessEventArgs.EventTypeequal toBeforeMemoryReadandValueequal to FFh. The code handling the event has the opportunity to setMemoryAccessEventArgs.CancelMemoryAccessto true and/or change the value. - If the configured memory access mode for the affected address is
ReadAndWriteorReadOnly, and theCancelMemoryAccessproperty 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
MemoryAccessevent is triggered withMemoryAccessEventArgs.EventTypeequal toAfterMemoryRead. The code handling the event has the opportunity to change the value. - The value in
MemoryAccessEventArgs.Valueis assumed to be the obtained value and is processed appropriately.
As for the operations performed for a memory write, they are the following:
- The
MemoryAccessevent is triggered withMemoryAccessEventArgs.EventTypeequal toBeforeMemoryWrite. The code listening the event has the opportunity to either change the value to be written or setMemoryAccessEventArgs.CancelMemoryAccessto true. - If the configured memory access mode for the affected address is
ReadAndWriteorWriteOnly, and theCancelMemoryAccessproperty of the event has not been set to true, the value set on the previous step is written toMemory[address]. - The
MemoryAccessevent is triggered withMemoryAccessEventArgs.EventTypeequal 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.