view emulator/mem.h @ 14:2b8eb2c86602

Major update to assembler design, now handles labels proper. Next step unit test Added boot procedure and experimental function look up table to emulator Started implementing operations tested SET and CLR operations with success
author james <jb302@eecs.qmul.ac.uk>
date Wed, 29 Jan 2014 20:11:07 +0000
parents e9dc055a0f8b
children a542cd390efd
line wrap: on
line source
/*  mem.h
 *  emultor memory structure and access function definitions  */
#ifndef MEM_H
#define MEM_H

/* data types
 *  - 8 bit BYTE
 *  - 16 bit WIDE */
typedef unsigned char BYTE;
typedef unsigned short WIDE;

/* current opcode */
BYTE op;

/* emulator memory
 *  - registers
 *  - 64kB 16-bit main memory */

struct
registers {
    /* 16 bit registers */
    WIDE PC;
    /* DPTR */
    BYTE DPH;
    BYTE DPL;
    /* SP */
    BYTE SPH;
    BYTE SPL;
    /*  8 bit registers
     *   bank 0: R[0x00 - 0x02]
     *   bank 1: R[0x03 - 0x06] */ 
    BYTE R[0x06];
    BYTE A;

    /* 7 6 5  4 3 2  1 0
     * C Z AC P S OV IE BS */
    BYTE flags;
    
} registers;

BYTE
memory[0x10000];

/* memory access function definitions
 *  - fetch() returns BYTE
 *  - read_mem(WIDE) returns BYTE
 *  - write_mem(WIDE, BYTE)
 *  - get_R(BYTE, BOOL) returns BYTE
 *  - set_R(BYTE, BOOL, BYTE)
 *  - get_DPTR() returns WIDE
 *  - set_DPTR(WIDE)
 *  - get_SP() returns WIDE
 *  - set_SP(WIDE) */

BYTE
fetch(void);

BYTE
read_mem(WIDE addr);

void
write_mem(WIDE addr, BYTE data);

BYTE
get_R(BYTE reg, _Bool bank);

void
set_R(BYTE reg, _Bool bank, BYTE data);

WIDE
get_DPTR(void);

void
set_DPTR(WIDE data);

WIDE
get_SP(void);

void
set_SP(WIDE data);

#endif