mirror of
https://github.com/trudnai/Steve2.git
synced 2024-10-31 14:06:04 +00:00
64 lines
1.8 KiB
C
64 lines
1.8 KiB
C
//
|
|
// main.c
|
|
// 6502
|
|
//
|
|
// Created by Tamas Rudnai on 7/14/19.
|
|
// Copyright © 2019 GameAlloy. All rights reserved.
|
|
//
|
|
|
|
|
|
#ifndef __6502_INSTR_ARITHMETIC_H__
|
|
#define __6502_INSTR_ARITHMETIC_H__
|
|
|
|
#include "common.h"
|
|
|
|
/**
|
|
ADC Add Memory to Accumulator with Carry
|
|
|
|
A + M + C -> A, C N Z C I D V
|
|
+ + + - - +
|
|
|
|
addressing assembler opc bytes cyles
|
|
--------------------------------------------
|
|
immidiate ADC #oper 69 2 2
|
|
zeropage ADC oper 65 2 3
|
|
zeropage,X ADC oper,X 75 2 4
|
|
absolute ADC oper 6D 3 4
|
|
absolute,X ADC oper,X 7D 3 4*
|
|
absolute,Y ADC oper,Y 79 3 4*
|
|
(indirect,X) ADC (oper,X) 61 2 6
|
|
(indirect),Y ADC (oper),Y 71 2 5*
|
|
**/
|
|
static inline void ADC( uint8_t imm ) {
|
|
dbgPrintf("ADC ");
|
|
m6502.A += imm + m6502.flags.C;
|
|
set_flags_NZCV( m6502.A );
|
|
}
|
|
|
|
/**
|
|
SBC Subtract Memory from Accumulator with Borrow
|
|
|
|
A - M - C -> A N Z C I D V
|
|
+ + + - - +
|
|
|
|
addressing assembler opc bytes cyles
|
|
--------------------------------------------
|
|
immidiate SBC #oper E9 2 2
|
|
zeropage SBC oper E5 2 3
|
|
zeropage,X SBC oper,X F5 2 4
|
|
absolute SBC oper ED 3 4
|
|
absolute,X SBC oper,X FD 3 4*
|
|
absolute,Y SBC oper,Y F9 3 4*
|
|
(indirect,X) SBC (oper,X) E1 2 6
|
|
(indirect),Y SBC (oper),Y F1 2 5*
|
|
**/
|
|
static inline void SBC( uint8_t imm ) {
|
|
int tmp = (int)m6502.A - imm - m6502.flags.C;
|
|
dbgPrintf("SBC A:%02X - i:%02X - C:%u = %02X", m6502.A, imm, m6502.flags.C, tmp);
|
|
m6502.A = (uint8_t)tmp;
|
|
set_flags_NZCV( tmp );
|
|
}
|
|
|
|
#endif // __6502_INSTR_ARITHMETIC_H__
|
|
|