mirror of
https://github.com/BertoldVdb/ms-tools.git
synced 2025-12-10 07:44:46 +01:00
Access TVD regs from main loop to avoid concurrent access
This commit is contained in:
parent
e917920a12
commit
a7a959a677
2 changed files with 73 additions and 0 deletions
65
mshal/hal_patch_tvdsafe.go
Normal file
65
mshal/hal_patch_tvdsafe.go
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
package mshal
|
||||||
|
|
||||||
|
type halPatchTVDMemoryRegion struct {
|
||||||
|
hal *HAL
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h halPatchTVDMemoryRegion) GetName() MemoryRegionNameType {
|
||||||
|
return MemoryRegionRegisters2106TVD
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h halPatchTVDMemoryRegion) GetLength() int {
|
||||||
|
return 256
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h halPatchTVDMemoryRegion) GetParent() (MemoryRegion, int) {
|
||||||
|
return nil, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h halPatchTVDMemoryRegion) read(addr int, buf []byte) (int, error) {
|
||||||
|
req := PatchExecFuncRequest{
|
||||||
|
R7_A: uint8(addr),
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.hal.PatchExecFunc(false, 0x3a33, req)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[0] = resp.R7
|
||||||
|
return 1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h halPatchTVDMemoryRegion) write(addr int, buf []byte) (int, error) {
|
||||||
|
req := PatchExecFuncRequest{
|
||||||
|
R5: uint8(buf[0]),
|
||||||
|
R7_A: uint8(addr),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := h.hal.PatchExecFunc(false, 0x3a17, req)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h halPatchTVDMemoryRegion) Access(write bool, addr int, buf []byte) (int, error) {
|
||||||
|
if len(buf) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if write {
|
||||||
|
return h.write(addr, buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
return h.read(addr, buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HAL) patchMakeTVDRegion() MemoryRegion {
|
||||||
|
if !h.patchInstalled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return regionWrapCompleteIO(halPatchTVDMemoryRegion{hal: h})
|
||||||
|
}
|
||||||
|
|
@ -80,6 +80,14 @@ func (h *HAL) MemoryRegionGet(name MemoryRegionNameType) MemoryRegion {
|
||||||
return regionWrapPartial(MemoryRegionUserConfig, h.MemoryRegionGet(MemoryRegionUserRAM), 0x3F0, 0x10)
|
return regionWrapPartial(MemoryRegionUserConfig, h.MemoryRegionGet(MemoryRegionUserRAM), 0x3F0, 0x10)
|
||||||
|
|
||||||
case MemoryRegionRegisters2106TVD:
|
case MemoryRegionRegisters2106TVD:
|
||||||
|
if h.patchInstalled {
|
||||||
|
if h.config.LogFunc != nil {
|
||||||
|
h.config.LogFunc(1, "Using patched TVD access")
|
||||||
|
}
|
||||||
|
|
||||||
|
return h.patchMakeTVDRegion()
|
||||||
|
}
|
||||||
|
|
||||||
return h.memoryRegionRegisters2106TVD()
|
return h.memoryRegionRegisters2106TVD()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue