v6502
The MOS 6502 Virtual Machine and Toolchain Infrastructure
Typedefs | Functions
Memory Access

Typedefs

typedef uint8_t() v6502_readFunction(struct _v6502_memory *memory, uint16_t offset, int trap, void *context)
 The function prototype for memory mapped accessors to be used by external virtual hardware.
 

Functions

int v6502_map (v6502_memory *memory, uint16_t start, size_t size, v6502_readFunction *read, v6502_writeFunction *write, void *context)
 Map an address in v6502_memory. More...
 
uint8_t v6502_read (v6502_memory *memory, uint16_t offset, int trap)
 Read a byte from v6502_memory. More...
 
void v6502_write (v6502_memory *memory, uint16_t offset, uint8_t value)
 Write a byte to v6502_memory. More...
 
v6502_mappedRangev6502_mappedRangeForOffset (v6502_memory *memory, uint16_t offset)
 Locate a v6502_mappedRange inside of v6502_memory, if it exists. More...
 
int8_t v6502_signedValueOfByte (uint8_t byte)
 Convert a raw byte to its signed value.
 
uint8_t v6502_byteValueOfSigned (int8_t i)
 Convert a signed value to its raw byte.
 

Detailed Description

Function Documentation

◆ v6502_map()

int v6502_map ( v6502_memory memory,
uint16_t  start,
size_t  size,
v6502_readFunction read,
v6502_writeFunction write,
void *  context 
)

Map an address in v6502_memory.

This works by registering an v6502_memoryAccessor as the handler for that range of v6502_memory. Anytime an access is made to that range of memory, the v6502_memoryAccessor is called instead, and is expected to return a byte ready for access. When this function is called, it is also assumed that an access is actually going to happen, which means it is safe to use calls to your callback as trap signals. This function returns YES if the mapping succeedsm, and NO if it fails. It is highly reccomended that you assert, or at least check the return code.

◆ v6502_mappedRangeForOffset()

v6502_mappedRange* v6502_mappedRangeForOffset ( v6502_memory memory,
uint16_t  offset 
)

Locate a v6502_mappedRange inside of v6502_memory, if it exists.

This function is the slow brute force way (the original implementation) of looking up v6502_mappedRange's for a given address. This function should never be hit if map caching is enabled.

A notable side effect of the joined mapping system is that a given range can only ever be mapped once. This means, for example, that you can't map 0xA000 through 0xB000 only for reading, and then follow it up with a map of 0xA700 through 0xB700 only for writing. It is still possible to achieve this behavior, but three map calls would be required.

◆ v6502_read()

uint8_t v6502_read ( v6502_memory memory,
uint16_t  offset,
int  trap 
)

Read a byte from v6502_memory.

All accesses made by the v6502_cpu should travel through these functions, so that they respect any hardware memory mapping. The trap argument should always be YES when accessed by the CPU, and always NO when accessed by any virtual hardware outside the CPU, or any VM construct (such as logging/introspection mechanisms.)

◆ v6502_write()

void v6502_write ( v6502_memory memory,
uint16_t  offset,
uint8_t  value 
)

Write a byte to v6502_memory.

All accesses made by the v6502_cpu should travel through these functions, so that they respect any hardware memory mapping.