mirror of
https://github.com/pevans/erc-c.git
synced 2024-11-04 22:09:08 +00:00
Remove the map_mach abstraction in favor of vm_di
This commit is contained in:
parent
8e810e724f
commit
b5fef760b8
@ -2,6 +2,7 @@
|
||||
#define _APPLE2_TESTS_H_
|
||||
|
||||
#include "apple2/apple2.h"
|
||||
#include "vm_di.h"
|
||||
#include "vm_segment.h"
|
||||
|
||||
static apple2 *mach = NULL;
|
||||
@ -10,14 +11,14 @@ static void
|
||||
setup()
|
||||
{
|
||||
mach = apple2_create(100, 100);
|
||||
vm_segment_set_map_machine(mach);
|
||||
vm_di_set(VM_MACHINE, mach);
|
||||
}
|
||||
|
||||
static void
|
||||
teardown()
|
||||
{
|
||||
apple2_free(mach);
|
||||
vm_segment_set_map_machine(NULL);
|
||||
vm_di_set(VM_MACHINE, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -70,9 +70,7 @@ 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_get_map_machine();
|
||||
extern void vm_segment_free(vm_segment *);
|
||||
extern void vm_segment_hexdump(vm_segment *, FILE *, size_t, size_t);
|
||||
extern void vm_segment_set_map_machine(void *);
|
||||
|
||||
#endif
|
||||
|
@ -52,8 +52,6 @@ apple2_mem_map(apple2 *mach, vm_segment *segment)
|
||||
size_t addr;
|
||||
int i, rlen, wlen;
|
||||
|
||||
vm_segment_set_map_machine(mach);
|
||||
|
||||
// Set up all of the bank-switch-related mapping. Well--almost all
|
||||
// of it.
|
||||
apple2_bank_map(segment);
|
||||
|
@ -13,20 +13,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "vm_di.h"
|
||||
#include "vm_segment.h"
|
||||
|
||||
/*
|
||||
* This is sort of regrettable, but we need a machine pointer that we
|
||||
* can pass into the read/write map functions (which will assume to have
|
||||
* access to the machine architecture). The alternative is an update to
|
||||
* a lot more of the codebase to add machine pointers -- void pointers
|
||||
* at that -- which is even uglier.
|
||||
*
|
||||
* FIXME: we might consider a dependency injection container at some
|
||||
* point.
|
||||
*/
|
||||
static void *map_mach = NULL;
|
||||
|
||||
/*
|
||||
* Create a new segment, such that it contains a number of bytes indicated
|
||||
* by `size`.
|
||||
@ -111,6 +100,8 @@ vm_segment_set(vm_segment *segment, size_t index, vm_8bit value)
|
||||
return ERR_OOB;
|
||||
}
|
||||
|
||||
void *map_mach = vm_di_get(VM_MACHINE);
|
||||
|
||||
// Check if we have a write mapper
|
||||
if (segment->write_table[index]) {
|
||||
segment->write_table[index](segment, index, value, map_mach);
|
||||
@ -139,6 +130,8 @@ vm_segment_get(vm_segment *segment, size_t index)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *map_mach = vm_di_get(VM_MACHINE);
|
||||
|
||||
// We may have a read mapper for this address
|
||||
if (segment->read_table[index]) {
|
||||
return segment->read_table[index](segment, index, map_mach);
|
||||
@ -305,24 +298,6 @@ vm_segment_fwrite(vm_segment *seg, FILE *stream, size_t off, size_t len)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Change the internal notion of the machine used by map functions
|
||||
*/
|
||||
void
|
||||
vm_segment_set_map_machine(void *mach)
|
||||
{
|
||||
map_mach = mach;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the map machine
|
||||
*/
|
||||
void *
|
||||
vm_segment_get_map_machine()
|
||||
{
|
||||
return map_mach;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is similar in spirit to the get16 function, but obviously more
|
||||
* practically similar to the set() function. Given a 16-bit value, we
|
||||
|
@ -156,17 +156,6 @@ Test(vm_segment, fread)
|
||||
cr_assert_eq(vm_segment_fread(segment, stream, 0, 123), OK);
|
||||
}
|
||||
|
||||
/* Test(vm_segment, get_map_machine) */
|
||||
Test(vm_segment, set_map_machine)
|
||||
{
|
||||
void *ptr = (void *)123;
|
||||
|
||||
cr_assert_eq(vm_segment_get_map_machine(), NULL);
|
||||
vm_segment_set_map_machine(ptr);
|
||||
cr_assert_eq(vm_segment_get_map_machine(), ptr);
|
||||
vm_segment_set_map_machine(NULL);
|
||||
}
|
||||
|
||||
Test(vm_segment, get16)
|
||||
{
|
||||
vm_segment_set(segment, 0, 0x34);
|
||||
|
Loading…
Reference in New Issue
Block a user