Various bug fixes to assembler, added more data pointers.
This commit is contained in:
+21
-1
@@ -8,6 +8,24 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// How many Data Pointers the CPU has. The instructions that name one take a full
|
||||
// byte to do it, so the encoding would allow up to 256. The limit here is the size
|
||||
// of the register file and the cost of saving pointers across a CALL, not the
|
||||
// instruction format. Must be a power of two, so that the selector can be masked
|
||||
// down to a valid pointer.
|
||||
#define DATA_POINTERS 4
|
||||
|
||||
// How many Data Pointers survive a CALL. The low numbered pointers are saved and
|
||||
// restored around a subroutine; the rest are left alone, so a subroutine can use
|
||||
// one to hand a pointer back to its caller the way Q hands back a byte. This is
|
||||
// deliberately independent of DATA_POINTERS: adding more pointers should not make
|
||||
// every CALL more expensive.
|
||||
#define PRESERVED_DATA_POINTERS 3
|
||||
|
||||
#if PRESERVED_DATA_POINTERS > DATA_POINTERS
|
||||
#error "Cannot preserve more Data Pointers than the CPU has."
|
||||
#endif
|
||||
|
||||
// The struct containing the CPU registers.
|
||||
typedef struct {
|
||||
uint8_t A;
|
||||
@@ -15,7 +33,7 @@ typedef struct {
|
||||
uint8_t Q;
|
||||
uint8_t Status;
|
||||
uint16_t ProgramCounter;
|
||||
uint16_t DataPointer;
|
||||
uint16_t DataPointer[DATA_POINTERS];
|
||||
uint16_t StackPointer;
|
||||
uint8_t *Program;
|
||||
uint8_t *Data;
|
||||
@@ -25,4 +43,6 @@ uint8_t executeOperation(uint8_t instruction, CPURegisters *cpu);
|
||||
|
||||
void initializeCPU(CPURegisters *cpu, uint8_t *programMemory, uint8_t *dataMemory);
|
||||
|
||||
void stepCPU(CPURegisters *cpu);
|
||||
|
||||
#endif // CPU_H
|
||||
|
||||
Reference in New Issue
Block a user