fix conditions, add ien flag, improve keyboard, add gpio
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
#define ldi cpu->instr = readmemory(cpu->i); cpu->cycle = 0;
|
||||
#define addf(x,y) { x=(x+y); cpu->cf=x>=256; x&=0xFF; setzf(x); }
|
||||
#define subf(x,y) addf(x,-y);
|
||||
#define cmpf(x,y) { int t=x-y; cpu->cf=(t>=256); setzf(t); }
|
||||
#define cmpf(x,y) { int t=x-y; cpu->cf=(t<0); setzf(t); }
|
||||
#define rol(x,y) x=(x<<y)|(x>>(8-y));
|
||||
#define ror(x,y) x=(x>>y)|(x<<(8-y));
|
||||
#define sra(x,y) x=(x>>y);
|
||||
@@ -80,6 +80,7 @@ struct CPU {
|
||||
int irq;
|
||||
int ifg;
|
||||
int rfg;
|
||||
int ien;
|
||||
int instr;
|
||||
int cycle;
|
||||
int instrpre;
|
||||
@@ -130,14 +131,15 @@ typedef void(*CPUInstruction)(struct CPU* const cpu, struct Memory* const mem);
|
||||
|
||||
#include "instructions_gen.c"
|
||||
|
||||
int TickCPU(struct CPU* const cpu, struct Memory* const mem, const int count, const int countinstrs) {
|
||||
int TickCPU(struct CPU* const cpu, struct Memory* const mem, const int count, const int countinstrs, const int breakaddr) {
|
||||
int i = 0;
|
||||
while(i<count) {
|
||||
if(cpu->irq && !cpu->ifg && cpu->cycle==0) { cpu->instr = 0xF2; }
|
||||
if(cpu->irq && !cpu->ifg && cpu->cycle==0 && cpu->ien) { cpu->instr = 0xF2; }
|
||||
if(cpu->rfg || cpu->ifg || cpu->irq) {
|
||||
CPUInstruction instr = CPUInstructions[cpu->instr][cpu->cycle];
|
||||
if(instr) instr(cpu, mem);
|
||||
if(!countinstrs || cpu->cycle==0) { i++; }
|
||||
if(cpu->i==breakaddr) { i = count; break; }
|
||||
} else { i = count; break; }
|
||||
if(mem->numevents!=0) { break; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user