You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

78 lines
2.1 KiB

#pragma once
#include <stdint.h>
#include <stdlib.h>
void hexdump(const void *d, size_t datalen);
#define DISPLAY_WIDTH_BYTES 8
#define DISPLAY_WIDTH_BITS 64
#define DISPLAY_HEIGHT_BYTES 4
#define DISPLAY_HEIGHT_BITS 32
struct display {
uint8_t *buffer;
uint8_t width;
uint8_t height;
int buffser_size;
};
struct emu_value {
uint8_t pad[0x27];
uint16_t program_counter;
uint16_t pointer_register;
uint8_t registers[16];
uint8_t extended_display_mode;
uint8_t delay_timer;
uint8_t sound_timer;
uint8_t font[80];
uint16_t stack[160];
uint8_t stack_top;
uint8_t unused;
};
typedef union {
uint8_t all_memory[0x1000];
struct {
union {
struct emu_value values;
uint8_t reserved_memory[0x200];
};
uint8_t main_memory[0xE00];
};
} chip_memory;
typedef struct {
chip_memory memory;
struct display display;
struct emu_value *value;
uint8_t display_pad1[4];
uint8_t display_buffer[(2 * DISPLAY_WIDTH_BYTES) // max columns
* (2 * DISPLAY_HEIGHT_BITS)]; // max rows
uint8_t display_pad2[4];
// struct emu_value reserved;
} emu_state;
void initialize(emu_state *state);
void print_display(struct display *display);
void loop(emu_state *state);
extern int chip_errored;
#define info(str) \
do { \
printf("INFO %s:%d %s\n", __FILE__, __LINE__, str); \
} while (0)
#define warn(str) \
do { \
printf("WARN %s:%d %s\n", __FILE__, __LINE__, str); \
} while (0)
#define error(str) \
do { \
printf("ERRO %s:%d %s\n", __FILE__, __LINE__, str); \
chip_errored = 1; \
} while (0)