Skip to content

Instantly share code, notes, and snippets.

@jacobmischka
jacobmischka / cpu.c
Created January 31, 2015 23:04
stack
/* --- Stack operations --- */
static void pushb(BYTE val) {
Memory_WriteByte((STACK_ADDR | cpu.SP--), val);
}
static void pushw(WORD val) {
BYTE tmp = (BYTE)(val & 0xFF);
Memory_WriteByte((STACK_ADDR | cpu.SP--), tmp);
tmp = (BYTE)((val & 0xFF00) >> 8);
Memory_WriteByte((STACK_ADDR | cpu.SP--), tmp);
@jacobmischka
jacobmischka / disassembler.i
Created January 31, 2015 23:10
disassemble2
void disassemble2() {
printf("$%04X %02X | A:%02X X:%02X Y:%02X SP:%02X | C:%d Z:%d I:%d D:%d V:%d B:%d N:%d | S: %02X %02X\n",
cpu.operaddr, cpu.operand, cpu.A, cpu.X, cpu.Y, cpu.SP,
GET_FLAG(FLAG_C) != 0, GET_FLAG(FLAG_Z) != 0, GET_FLAG(FLAG_I) != 0, GET_FLAG(FLAG_D) != 0,
GET_FLAG(FLAG_V) != 0, GET_FLAG(FLAG_B) != 0, GET_FLAG(FLAG_N) != 0, Memory_ReadByte(STACK_ADDR | (cpu.SP+1)), Memory_ReadByte(STACK_ADDR | (cpu.SP+2)));
}
test = open("test.log")
nestest = open("nestest.log")
lineCount = 0
for testLine, nestestLine in zip(test, nestest):
if testLine[1:5] != nestestLine[:4]:
print(testLine)
/* Indirect */
static void IND() {
cpu.indoperaddr = Memory_ReadWord(cpu.PC);
if((cpu.indoperaddr & 0x00FF) == 0x00FF){
cpu.operaddr = (WORD)Memory_ReadByte(cpu.indoperaddr) | ((WORD)Memory_ReadByte(cpu.indoperaddr & 0xFF00) << 8);
}
else
cpu.operaddr = Memory_ReadWord(cpu.indoperaddr);
cpu.PC += 2;
/* TODO: Implement bug */
/* Force break */
/* I=1 */
static void BRK() {
cpu.PC++;
pushw(cpu.PC);
pushb(cpu.S);
SET_FLAG(FLAG_I);
if(NMI){
cpu.PC = Memory_ReadWord(0xFFFA);
}
@jacobmischka
jacobmischka / cpu.c
Created February 2, 2015 18:11
interrupt
/* Interrupt functions */
/* TODO: Interrupt hijacking */
void interrupt_IRQ() {
CLEAR_FLAG(FLAG_B);
cpu.PC++;
pushw(cpu.PC);
pushb(cpu.S);
SET_FLAG(FLAG_I);
cpu.PC = Memory_ReadWord(0xFFFE);
}
@jacobmischka
jacobmischka / ppu.c
Created February 8, 2015 05:04
writecontroller
if (cpu.cycles >= 30000) { // "about" 30000 cycles
ppu.controller = val;
ppu.vram_addr_inc = ((val >> 2) & 0x1) ? 1: 32;
ppu.sprite_pattern_addr = ((val >> 3) & 0x1) * 0x1000;
ppu.bg_pattern_addr = ((val >> 4) & 0x1) * 0x1000;
ppu.sprite_height = ((val >> 5) & 0x1) ? 8 : 16;
ppu.nmi_on_vblank = (val >> 7) & 0x1;
// Change scroll latch to match base nametable address
import QtQuick 2.0
Rectangle {
id: oauth
width: 640
height: 480
color: "#ccd6dd"
Text {
id: link
n
dx = -dist*math.cos(-self.cam.rot)
dy = -dist*math.sin(-self.cam.rot)
if self.world:isLand(self.player.x+dx, self.player.y+dy) then
self.cam:move(dx, dy)
self.player:move(dx, dy, "left")
end
elseif key == "s" then
dx = dist*math.sin(self.cam.rot)
dy = dist*math.cos(self.cam.rot)
sdkfj lksdfj lskdj fs