// Creates a new virtual machine. Updates will be sent to vmUpdateCh. func createVm(vmUpdateCh chan<- vmUpdate) *vm { // Allocate memory. memorySize := 1024 * 64 memory := make([]byte, memorySize) memInit := make([]bool, memorySize) log.Printf("Memory has %d bytes", len(memory)) // Load ROM into memory. romFilename := "roms/model3.rom" rom, err := ioutil.ReadFile(romFilename) if err != nil { panic(err) } log.Printf("ROM has %d bytes", len(rom)) // Copy ROM into memory. copy(memory, rom) // Make a CPU. vm := &vm{ z80: nil, // Set below. memory: memory, memInit: memInit, romSize: uint16(len(rom)), vmUpdateCh: vmUpdateCh, modeImage: 0x80, } vm.z80 = z80.NewZ80(vm, vm) vm.z80.Reset() return vm }
func newSMS(displayLoop DisplayLoop) *SMS { memory := NewMemory() vdp := newVDP(displayLoop) ports := NewPorts() cpu := z80.NewZ80(memory, ports) sms := &SMS{ cpu: cpu, memory: memory, ports: ports, vdp: vdp, joystick: 0xffff, command: make(chan interface{}), } sms.memory.init(cpu) sms.ports.init(sms) return sms }