Skip to content

Commit

Permalink
update a few stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Mar 1, 2020
1 parent a31d7e8 commit 58e5d09
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 163 deletions.
8 changes: 7 additions & 1 deletion internal/C6502.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CPU6502 struct {

func init() {
OpCodesLookupTable = []Instruction{
{"BRK", BRK, IMM, 7}, {"ORA", ORA, IZX, 6}, {"???", XXX, IMP, 2}, {"???", XXX, IMP, 8}, {"???", NOP, IMP, 3}, {"ORA", ORA, ZP0, 3}, {"ASL", ASL, ZP0, 5}, {"???", XXX, IMP, 5}, {"PHP", PHP, IMP, 3}, {"ORA", ORA, IMM, 2}, {"ASL", ASL, IMP, 2}, {"???", XXX, IMP, 2}, {"???", NOP, IMP, 4}, {"ORA", ORA, ABS, 4}, {"ASL", ASL, ABS, 6}, {"???", XXX, IMP, 6},
{"BRK", BRK, IMM, 7}, {"ORA", ORA, IZX, 6}, {"???", XXX, IMP, 2}, {"???", XXX, IMP, 8}, {"???", NOP, IMP, 3}, {"ORA", ORA, ZP0, 3}, {"ASL", ASL, ZP0, 5}, {"???", XXX, IMP, 5}, {"PHP", PHP, IMP, 3}, {"ORA", ORA, IMM, 2}, {"ASL", ASL, IMP, 2}, {"ANC", PAN, IMM, 2}, {"???", NOP, IMP, 4}, {"ORA", ORA, ABS, 4}, {"ASL", ASL, ABS, 6}, {"???", XXX, IMP, 6},
{"BPL", BPL, REL, 2}, {"ORA", ORA, IZY, 5}, {"???", XXX, IMP, 2}, {"???", XXX, IMP, 8}, {"???", NOP, IMP, 4}, {"ORA", ORA, ZPX, 4}, {"ASL", ASL, ZPX, 6}, {"???", XXX, IMP, 6}, {"CLC", CLC, IMP, 2}, {"ORA", ORA, ABY, 4}, {"???", NOP, IMP, 2}, {"???", XXX, IMP, 7}, {"???", NOP, IMP, 4}, {"ORA", ORA, ABX, 4}, {"ASL", ASL, ABX, 7}, {"???", XXX, IMP, 7},
{"JSR", JSR, ABS, 6}, {"AND", AND, IZX, 6}, {"???", XXX, IMP, 2}, {"???", XXX, IMP, 8}, {"BIT", BIT, ZP0, 3}, {"AND", AND, ZP0, 3}, {"ROL", ROL, ZP0, 5}, {"???", XXX, IMP, 5}, {"PLP", PLP, IMP, 4}, {"AND", AND, IMM, 2}, {"ROL", ROL, IMP, 2}, {"???", XXX, IMP, 2}, {"BIT", BIT, ABS, 4}, {"AND", AND, ABS, 4}, {"ROL", ROL, ABS, 6}, {"???", XXX, IMP, 6},
{"BMI", BMI, REL, 2}, {"AND", AND, IZY, 5}, {"???", XXX, IMP, 2}, {"???", XXX, IMP, 8}, {"???", NOP, IMP, 4}, {"AND", AND, ZPX, 4}, {"ROL", ROL, ZPX, 6}, {"???", XXX, IMP, 6}, {"SEC", SEC, IMP, 2}, {"AND", AND, ABY, 4}, {"???", NOP, IMP, 2}, {"???", XXX, IMP, 7}, {"???", NOP, IMP, 4}, {"AND", AND, ABX, 4}, {"ROL", ROL, ABX, 7}, {"???", XXX, IMP, 7},
Expand Down Expand Up @@ -379,6 +379,12 @@ func XXX(c *CPU6502) byte {
return 0
}

// PAN : Panic code - in place of 0x0B ANC
// ANC : Panic code - illegal op code, its actually something else, but here we use it as PANIC
func PAN(c *CPU6502) byte {
panic("Test Failed")
}

// ADC : Add memory to accumulator with carry
// Function -> A = A + M
// Flags -> C, Z, N, V
Expand Down
36 changes: 0 additions & 36 deletions internal/C6502_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"runtime/debug"
"strconv"
"testing"
)
Expand All @@ -23,41 +22,6 @@ func init() {
cpu.ConnectBus(testBus)
}

func assertNil(t *testing.T, got interface{}) {
if got != nil {
t.Errorf("Expected variable to be: nil")
t.Log(string(debug.Stack()))
}
}

func assertTrue(t *testing.T, got bool) {
if !got {
t.Errorf("Expected variable to be: %t, got: %t", true, got)
t.Log(string(debug.Stack()))
}
}

func assertFalse(t *testing.T, got bool) {
if got {
t.Errorf("Expected variable to be: %t, got: %t", false, got)
t.Log(string(debug.Stack()))
}
}

func assertEqualsB(t *testing.T, expect byte, got byte) {
if expect != got {
t.Errorf("Expected variable to be: %x, got: %x", expect, got)
t.Log(string(debug.Stack()))
}
}

func assertEqualsW(t *testing.T, expect Word, got Word) {
if expect != got {
t.Errorf("Expected variable to be: %x, got: %x", expect, got)
t.Log(string(debug.Stack()))
}
}

func TestReset(t *testing.T) {
cpu := testCPU
cpu.Reset()
Expand Down
4 changes: 3 additions & 1 deletion internal/Cartridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,7 @@ func (c *Cartridge) PPUWrite(address Word, data byte) bool {

// Reset : reset process
func (c *Cartridge) Reset() {
c.mapper.Reset()
if c != nil && c.mapper != nil {
c.mapper.Reset()
}
}
28 changes: 23 additions & 5 deletions internal/Debug.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"time"
)

Expand All @@ -13,18 +14,22 @@ var (
emulationRun = false
residualTime = 0.0
elapsedTime = 0.0
romname = "color_test"
lastUpdate = time.Now()
)

// SetRom : Put a ROM on the memory of the Nes Emulator
func SetRom(rom string) {
nes.InsertCartridge(LoadCartridge(rom))
nes.Reset()
mapAsm = cpu.Disassemble(0x0000, 0xFFFF)
filename := time.Now().Format("2006-01-02_15:04:05")
WriteDisassemble(mapAsm, "../output/disasemble_"+filename+".txt")
}

func init() {
nes = CreateBus(CreateCPU(), CreatePPU())
nes.InsertCartridge(LoadCartridge("../test/roms/" + romname + ".nes"))
cpu = nes.cpu
nes.Reset()
// mapAsm = cpu.Disassemble(0x0000, 0xFFFF)
WriteDisassemble(mapAsm, "../output/"+romname+".txt")
nes.Reset()
}

func tick() {
Expand All @@ -37,3 +42,16 @@ func reset() {
nes.Clock()
}
}

func testCode() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Assert failed:", r)
}
}()
// run Program until it sends the success msg
for {
tick()
fmt.Println(cpu.pc, cpu.a, cpu.x, cpu.y, cpu.opcode, cpu.status, cpu.stkp)
}
}
Loading

0 comments on commit 58e5d09

Please sign in to comment.