-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhardware_rom.go
More file actions
60 lines (53 loc) · 1.03 KB
/
hardware_rom.go
File metadata and controls
60 lines (53 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gemu
import (
"reflect"
"unsafe"
)
var romClass = &HardwareClass{
Name: "rom",
Desc: "Embedded ROM",
DevID: 0x17400011,
VerID: 0x0001,
MfgID: 0x12452135,
}
func init() {
RegisterClass(romClass)
}
type ROM struct {
Hardware
Data []uint16
}
func NewRom(romImage string, flip bool) *ROM {
rom := &ROM{}
rom.Class = romClass
storage := defaultStorage
if flip {
storage = NewFlipStorage(storage)
}
if storage.Exists(romImage) {
rom.Data = make([]uint16, storage.Length(romImage)/2)
rawData := []byte{}
bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&rawData))
bytesHeader.Data = uintptr(unsafe.Pointer(&rom.Data[0]))
bytesHeader.Len = len(rom.Data) * 2
bytesHeader.Cap = len(rom.Data) * 2
storage.Read(romImage, 0, rawData)
}
return rom
}
func (R *ROM) HWI(D *DCPU) {
switch D.Reg[0] {
case 0:
D.Mem.LoadMem(R.Data)
D.PC = 0
case 1:
copy(R.Data, D.Mem.GetRaw()[D.Reg[1]:])
}
}
func (R *ROM) Reset() {
if R.Up != nil {
if dcpu, ok := R.Up.(*DCPU); ok {
dcpu.Mem.LoadMem(R.Data)
}
}
}