~groovestomp/gsnes

85e494661af3862ec2f0c9d77df6ce9bdfcde828 — GrooveStomp 1 year, 6 months ago 8e7b491
Working input and fixed a bug in ADC()
5 files changed, 39 insertions(+), 8 deletions(-)

M Makefile
M bus.c
M bus.h
M cpu.c
M main.c
M Makefile => Makefile +2 -2
@@ 1,8 1,8 @@
#******************************************************************************
# File: Makefile
# Created: 2019-10-16
# Updated: 2019-10-16
# Author: Aaron Oman
# Updated: 2019-12-03
# Copyright (c) 2019 Aaron Oman (GrooveStomp)
# Notice: Creative Commons Attribution 4.0 International License (CC-BY 4.0)
#******************************************************************************
CC       = /usr/bin/gcc

M bus.c => bus.c +14 -1
@@ 4,7 4,7 @@

  File: bus.c
  Created: 2019-10-16
  Updated: 2019-11-30
  Updated: 2019-12-06
  Author: Aaron Oman
  Notice: GNU AGPLv3 License



@@ 28,6 28,8 @@ struct bus {
        struct cart *cart;
        uint8_t *cpuRam; // Dummy RAM for prototyping
        uint32_t tickCount;
        struct controller controllers[2];
        uint8_t controllerSnapshot[2];
};

struct bus *BusInit(struct cpu *cpu, struct ppu *ppu) {


@@ 43,6 45,8 @@ struct bus *BusInit(struct cpu *cpu, struct ppu *ppu) {

        bus->cpu = cpu;
        bus->ppu = ppu;
        bus->controllerSnapshot[0] = 0x00;
        bus->controllerSnapshot[1] = 0x00;

        return bus;
}


@@ 67,6 71,8 @@ void BusWrite(struct bus *bus, uint16_t addr, uint8_t data) {
                bus->cpuRam[addr & 0x07FF] = data;
        } else if (addr >= 0x2000 && addr <= 0x3FFF) {
                PpuWriteViaCpu(bus->ppu, addr & 0x0007, data);
        } else if (addr >= 0x4016 && addr <= 0x4017) {
                bus->controllerSnapshot[addr & 0x0001] = bus->controllers[addr & 0x0001].input;
        }
}



@@ 81,6 87,9 @@ uint8_t BusRead(struct bus *bus, uint16_t addr, bool readOnly) {
        } else if (addr >= 0x2000 && addr <= 0x3FFF) {
                // PPU address range, mirrored every 8.
                data = PpuReadViaCpu(bus->ppu, addr & 0x0007, readOnly);
        } else if (addr >= 0x4016 && addr <= 0x4017) {
                data = (bus->controllerSnapshot[addr & 0x0001] & 0x80) > 0;
                bus->controllerSnapshot[addr & 0x0001] <<= 1;
        }

        return data;


@@ 112,3 121,7 @@ void BusTick(struct bus *bus) {

        bus->tickCount++;
}

struct controller *BusGetControllers(struct bus *bus) {
        return &bus->controllers;
}

M bus.h => bus.h +8 -1
@@ 4,7 4,7 @@

  File: bus.h
  Created: 2019-10-16
  Updated: 2019-11-30
  Updated: 2019-12-06
  Author: Aaron Oman
  Notice: GNU AGPLv3 License



@@ 25,6 25,10 @@ struct bus;
struct ppu;
struct cart;

struct controller {
        uint8_t input;
};

struct bus *
BusInit(struct cpu *cpu, struct ppu *ppu);



@@ 54,4 58,7 @@ BusTick(struct bus *bus);
void
BusAttachCart(struct bus *bus, struct cart *cart);

struct controller *
BusGetControllers(struct bus *bus);

#endif // BUS_VERSION

M cpu.c => cpu.c +2 -2
@@ 5,7 5,7 @@

  File: cpu.c
  Created: 2019-10-16
  Updated: 2019-12-01
  Updated: 2019-12-06
  Author: Aaron Oman
  Notice: GNU AGPLv3 License



@@ 515,7 515,7 @@ uint8_t ADC(struct cpu *cpu) {
        SetFlag(cpu, Z, (tmp & 0x00FF) == 0);

        // The signed Overflow flag
        SetFlag(cpu, V, (~((uint16_t)cpu->a ^ (uint16_t)fetched) & ((uint16_t)cpu->a ^ (uint16_t)tmp)) & 0x0000);
        SetFlag(cpu, V, (~((uint16_t)cpu->a ^ (uint16_t)fetched) & ((uint16_t)cpu->a ^ (uint16_t)tmp)) & 0x0080);

        SetFlag(cpu, N, tmp & 0x80);


M main.c => main.c +13 -2
@@ 4,7 4,7 @@

  File: main.c
  Created: 2019-10-31
  Updated: 2019-11-29
  Updated: 2019-12-06
  Author: Aaron Oman
  Notice: GNU AGPLv3 License



@@ 178,7 178,7 @@ int main(int argc, char **argv) {
        BusReset(bus);

        // Disassemble
        struct disassembly *disassembly = DisassemblyInit(cpu, 0x0000, 0xFFFF);
        struct disassembly *disassembly = DisassemblyInit(cpu, 0x0010, 0x0030);

        struct timespec frameEnd;
        struct timespec frameStart;


@@ 199,6 199,17 @@ int main(int argc, char **argv) {
                InputProcess(input);
                isRunning = !InputIsQuitRequested(input);

                struct controller *controllers = BusGetControllers(bus);
                controllers[0].input = 0x00;
                controllers[0].input |= InputGetKey(input, KEY_X).held ? 0x80 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_Z).held ? 0x40 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_A).held ? 0x20 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_S).held ? 0x10 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_UP).held ? 0x08 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_DOWN).held ? 0x04 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_LEFT).held ? 0x02 : 0x00;
                controllers[0].input |= InputGetKey(input, KEY_RIGHT).held ? 0x01 : 0x00;

                if (InputGetKey(input, KEY_SPACE).pressed) isEmulating = !isEmulating;
                if (InputGetKey(input, KEY_R).pressed) BusReset(bus);
                if (InputGetKey(input, KEY_P).pressed) {