mirror of
https://github.com/pevans/erc-c.git
synced 2024-12-21 08:30:55 +00:00
Add objstore code, tests
This commit is contained in:
parent
fd4b135d5a
commit
4d07bd7640
23
include/objstore.h
Normal file
23
include/objstore.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef _OBJSTORE_H_
|
||||||
|
#define _OBJSTORE_H_
|
||||||
|
|
||||||
|
#include "apple2.mem.h"
|
||||||
|
#include "vm_bits.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char header[4];
|
||||||
|
vm_8bit apple2_disk2_rom[APPLE2_DISK2_ROM_SIZE];
|
||||||
|
vm_8bit apple2_sys_rom[0x4000];
|
||||||
|
vm_8bit apple2_sysfont[APPLE2_SYSFONT_SIZE];
|
||||||
|
} objstore;
|
||||||
|
|
||||||
|
extern int objstore_init();
|
||||||
|
|
||||||
|
#define OBJSTORE_DECL(x) \
|
||||||
|
const vm_8bit *objstore_##x()
|
||||||
|
|
||||||
|
OBJSTORE_DECL(apple2_disk2_rom);
|
||||||
|
OBJSTORE_DECL(apple2_sys_rom);
|
||||||
|
OBJSTORE_DECL(apple2_sysfont);
|
||||||
|
|
||||||
|
#endif
|
@ -13,6 +13,7 @@ set(erc_sources
|
|||||||
mos6502.exec.c
|
mos6502.exec.c
|
||||||
mos6502.loadstor.c
|
mos6502.loadstor.c
|
||||||
mos6502.stat.c
|
mos6502.stat.c
|
||||||
|
objstore.c
|
||||||
option.c
|
option.c
|
||||||
vm_bitfont.c
|
vm_bitfont.c
|
||||||
vm_screen.c
|
vm_screen.c
|
||||||
|
73
src/objstore.c
Normal file
73
src/objstore.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* obj.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include "objstore.h"
|
||||||
|
#include "objstore_data.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is data that we expect to find in the store_data variable that
|
||||||
|
* is defined in objstore_data.h.
|
||||||
|
*/
|
||||||
|
#define HEADER_DATA "hope"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Our object store. Just a simple struct that we pull data out from.
|
||||||
|
*/
|
||||||
|
static objstore store;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function will set up the store variable so that it contains
|
||||||
|
* useful information rather than garbage data from the stack. It does
|
||||||
|
* so with a simply memcpy from store_data directly into store, such
|
||||||
|
* that the store data itself can be aligned for access.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
objstore_init()
|
||||||
|
{
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
// We want to input some bad header data and compare with what
|
||||||
|
// eventually should get put into there by memcmp.
|
||||||
|
store.header[0] = 'h';
|
||||||
|
store.header[1] = 'e';
|
||||||
|
store.header[2] = 'y';
|
||||||
|
store.header[3] = '\0';
|
||||||
|
|
||||||
|
memcpy(&store, store_data, sizeof(store));
|
||||||
|
|
||||||
|
// Test if the header field data is exactly equivalent to that
|
||||||
|
// defined in HEADER_DATA. Note we use memcmp(), because the header
|
||||||
|
// field is an array of just 4 bytes; strcmp() and strncmp() have an
|
||||||
|
// expectation that both pointers will be directed at NUL-terminated
|
||||||
|
// strings, which is _not_ the case for store.header (but,
|
||||||
|
// incidentally, _is_ the case for HEADER_DATA!).
|
||||||
|
cmp = memcmp(store.header, HEADER_DATA,
|
||||||
|
sizeof(store.header) / sizeof(char));
|
||||||
|
|
||||||
|
// If the two areas of memory were not a complete match...
|
||||||
|
if (cmp != 0) {
|
||||||
|
log_critical("Object store initialization failed with bad data");
|
||||||
|
return ERR_BADFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Something to simplify the very simple getter functions we use for
|
||||||
|
* getting data from the object store.
|
||||||
|
*/
|
||||||
|
#define OBJSTORE_DEFN(x) \
|
||||||
|
const vm_8bit *objstore_##x() { return store.x; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note we have an extra semicolon on the end... this is mostly to avoid
|
||||||
|
* screwing up my indent, to be honest. But C will ignore the
|
||||||
|
* semicolons, so all is well.
|
||||||
|
*/
|
||||||
|
OBJSTORE_DEFN(apple2_sys_rom);
|
||||||
|
OBJSTORE_DEFN(apple2_disk2_rom);
|
||||||
|
OBJSTORE_DEFN(apple2_sysfont);
|
9
tests/objstore.c
Normal file
9
tests/objstore.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <criterion/criterion.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "objstore.h"
|
||||||
|
|
||||||
|
Test(objstore, init)
|
||||||
|
{
|
||||||
|
cr_assert_eq(objstore_init(), OK);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user