1
0
mirror of https://github.com/pevans/erc-c.git synced 2025-07-04 07:23:54 +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

@ -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