1
0
Fork 0
mirror of https://github.com/pnx/m16vm synced 2026-06-16 03:44:55 +02:00

vm/mm.c: convert check_bounds to a macro.

This commit is contained in:
Henrik Hautakoski 2019-04-23 11:12:37 +02:00
parent 77a7c94451
commit 67a272b715
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA

15
vm/mm.c
View file

@ -31,13 +31,12 @@
int16_t* base_addr = NULL;
uint8_t *memory = NULL;
static void check_bounds(uint16_t addr) {
if (addr > MEM_SIZE) {
fprintf(stderr, EXCEPTION_STRING, addr);
exit(1);
#define __check_bounds(addr) \
if ((addr) > MEM_SIZE) { \
fprintf(stderr, EXCEPTION_STRING, addr);\
exit(1); \
}
}
void mm_init() {
@ -56,14 +55,14 @@ void mm_exit() {
void mm_sw(uint16_t addr, int16_t value) {
check_bounds(addr);
__check_bounds(addr);
base_addr[addr] = value;
}
int16_t mm_lw(uint16_t addr) {
check_bounds(addr);
__check_bounds(addr);
return base_addr[addr];
}