1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-21 08:30:55 +00:00

Add function to return 16-bit value from a segment address

This commit is contained in:
Peter Evans 2018-01-05 16:14:51 -06:00
parent c6799db689
commit 70516a7f91
2 changed files with 18 additions and 0 deletions

View File

@ -59,6 +59,7 @@ extern int vm_segment_fread(vm_segment *, FILE *, size_t, size_t);
extern int vm_segment_read_map(vm_segment *, size_t, vm_segment_read_fn);
extern int vm_segment_set(vm_segment *, size_t, vm_8bit);
extern int vm_segment_write_map(vm_segment *, size_t, vm_segment_write_fn);
extern vm_16bit vm_segment_get16(vm_segment *, size_t);
extern vm_8bit vm_segment_get(vm_segment *, size_t);
extern vm_segment *vm_segment_create(size_t);
extern void vm_segment_free(vm_segment *);

View File

@ -146,6 +146,23 @@ vm_segment_get(vm_segment *segment, size_t index)
return segment->memory[index];
}
/*
* Return a 16-bit value from a given address. This will read the byte
* at addr and the byte at addr+1, then fit those into a two-byte
* variable such that addr contains the most significant byte and addr+1
* contains the least significant byte.
*/
vm_16bit
vm_segment_get16(vm_segment *segment, size_t addr)
{
vm_16bit msb, lsb;
msb = (vm_16bit)vm_segment_get(segment, addr);
lsb = (vm_16bit)vm_segment_get(segment, addr+1);
return (msb << 8) | lsb;
}
/*
* Copy a set of bytes from `src` (at `src_index`) to `dest` (at
* `dest_index`), such that the range is `length` bytes long. Note that