Skip to content

Instantly share code, notes, and snippets.

@tom-seddon
Created May 15, 2018 00:06
Show Gist options
  • Save tom-seddon/42933d406df9b9512327b25ae735360d to your computer and use it in GitHub Desktop.
Save tom-seddon/42933d406df9b9512327b25ae735360d to your computer and use it in GitHub Desktop.
b2 6502 simulator snippet
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Read/Absolute
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
static void T1_R_ABS(M6502 *);
static void T2_R_ABS(M6502 *);
static void T3_R_ABS(M6502 *);
static void T0_R_ABS(M6502 *s) {
/* T0 phase 2 */
/* (decode - already done) */
/* T1 phase 1 */
s->abus.w=s->pc.w++;
s->read=M6502ReadType_Instruction;
s->tfn=&T1_R_ABS;
}
static void T1_R_ABS(M6502 *s) {
/* T1 phase 2 */
s->ad.b.l=s->dbus;
/* T2 phase 1 */
s->abus.w=s->pc.w++;
s->read=M6502ReadType_Instruction;
s->tfn=&T2_R_ABS;
}
static void T2_R_ABS(M6502 *s) {
/* T2 phase 2 */
s->ad.b.h=s->dbus;
/* T3 phase 1 */
s->abus.w=s->ad.w;
s->read=M6502ReadType_Data;
s->tfn=&T3_R_ABS;
CheckForInterrupts(s);
}
static void T3_R_ABS(M6502 *s) {
/* T3 phase 2 */
s->data=s->dbus;
(*s->ifn)(s);
#ifdef _DEBUG
s->ifn=NULL;
#endif
/* T0 phase 1 */
M6502_NextInstruction(s);
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Read/Indirect,X
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
static void T1_R_INX(M6502 *);
static void T2_R_INX(M6502 *);
static void T3_R_INX(M6502 *);
static void T4_R_INX(M6502 *);
static void T5_R_INX(M6502 *);
static void T0_R_INX(M6502 *s) {
/* T0 phase 2 */
/* (decode - already done) */
/* T1 phase 1 */
s->abus.w=s->pc.w++;
s->read=M6502ReadType_Instruction;
s->tfn=&T1_R_INX;
}
static void T1_R_INX(M6502 *s) {
/* T1 phase 2 */
s->ia.b.l=s->dbus;
/* T2 phase 1 */
s->abus.w=s->ia.b.l;
s->read=M6502ReadType_Uninteresting;
s->tfn=&T2_R_INX;
}
static void T2_R_INX(M6502 *s) {
/* T2 phase 2 */
s->data=s->dbus;
/* T3 phase 1 */
s->abus.w=(uint8_t)(s->ia.b.l+s->x);
s->read=M6502ReadType_Address;
s->tfn=&T3_R_INX;
}
static void T3_R_INX(M6502 *s) {
/* T3 phase 2 */
s->ad.b.l=s->dbus;
/* T4 phase 1 */
s->abus.w=(uint8_t)(s->ia.b.l+s->x+1);
s->read=M6502ReadType_Address;
s->tfn=&T4_R_INX;
}
static void T4_R_INX(M6502 *s) {
/* T4 phase 2 */
s->ad.b.h=s->dbus;
/* T5 phase 1 */
s->abus.w=s->ad.w;
s->read=M6502ReadType_Data;
s->tfn=&T5_R_INX;
CheckForInterrupts(s);
}
static void T5_R_INX(M6502 *s) {
/* T5 phase 2 */
s->data=s->dbus;
(*s->ifn)(s);
#ifdef _DEBUG
s->ifn=NULL;
#endif
/* T0 phase 1 */
M6502_NextInstruction(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment