1
0
mirror of https://github.com/ariejan/i6502.git synced 2024-11-05 10:04:42 +00:00
i6502/i6502.go

70 lines
1.2 KiB
Go
Raw Normal View History

2014-08-07 07:15:41 +00:00
/*
i6502 is a software emulator of my i6502 home-built computer. It uses
the 65C02 microprocessor, 32kB RAM and 16kB ROM.
*/
package main
import (
"fmt"
"github.com/ariejan/i6502/bus"
"github.com/ariejan/i6502/cpu"
"github.com/ariejan/i6502/memory"
"os"
"os/signal"
)
func main() {
os.Exit(mainReturningStatus())
}
func mainReturningStatus() int {
// 32kB RAM
ram := memory.CreateRam()
// 16kB ROM, filled from file
rom, err := memory.LoadRomFromFile("rom/test.rom")
if err != nil {
panic(err)
}
// 16-bit address bus
bus, _ := bus.CreateBus()
bus.Attach(ram, "32kB RAM", 0x0000)
bus.Attach(rom, "16kB ROM", 0xC000)
fmt.Println(bus)
exitChan := make(chan int, 0)
cpu := &cpu.Cpu{Bus: bus, ExitChan: exitChan}
cpu.Reset()
go func() {
for {
cpu.Step()
}
}()
var (
sig os.Signal
exitStatus int
)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
select {
case exitStatus = <-exitChan:
// Okay, handle the rest of the code
case sig = <-sigChan:
fmt.Println("\nGot signal: ", sig)
exitStatus = 1
}
fmt.Println(cpu)
fmt.Println("Dumping RAM into `core` file")
ram.Dump("core")
return exitStatus
}