diff --git a/ms213x_patch/asm/asm.sh b/ms213x_patch/asm/asm.sh index f024547..3c5e0db 100755 --- a/ms213x_patch/asm/asm.sh +++ b/ms213x_patch/asm/asm.sh @@ -2,4 +2,6 @@ as31 -Fbin init.asm as31 -Fbin hook.asm as31 -Fbin finishf660.asm as31 -Fbin finishsig.asm +as31 -Fbin vsync.asm as31 -Fbin readinfo.asm +as31 -Fbin readinfo2.asm diff --git a/ms213x_patch/asm/readinfo.asm b/ms213x_patch/asm/readinfo.asm index c7f2956..16388ae 100644 --- a/ms213x_patch/asm/readinfo.asm +++ b/ms213x_patch/asm/readinfo.asm @@ -16,11 +16,12 @@ MOVX A, @DPTR MOV R5, A ; Signal info -INC DPTR +MOV DPTR, #0xf6e9 MOVX A, @DPTR +MOV R6, A ; Frame counter -MOV R6, 0x29 -MOV R7, 0x28 +MOV DPTR, #0x7b16 +MOVX A, @DPTR RET diff --git a/ms213x_patch/asm/readinfo.bin b/ms213x_patch/asm/readinfo.bin index 13682ec..40f8a0d 100644 --- a/ms213x_patch/asm/readinfo.bin +++ b/ms213x_patch/asm/readinfo.bin @@ -1 +1 @@ -{)(" \ No newline at end of file +{{" \ No newline at end of file diff --git a/ms213x_patch/asm/readinfo2.asm b/ms213x_patch/asm/readinfo2.asm new file mode 100644 index 0000000..617fa0c --- /dev/null +++ b/ms213x_patch/asm/readinfo2.asm @@ -0,0 +1,27 @@ +; Resolution info +MOV DPTR, #0xe184 +MOVX A, @DPTR +MOV R2, A + +INC DPTR +MOVX A, @DPTR +MOV R3, A + +MOV DPTR, #0xe18c +MOVX A, @DPTR +MOV R4, A + +INC DPTR +MOVX A, @DPTR +MOV R5, A + +; Signal info +MOV DPTR, #0xf6e9 +MOVX A, @DPTR +MOV R6, A + +; Frame counter +MOV DPTR, #0x7b16 +MOVX A, @DPTR + +RET diff --git a/ms213x_patch/asm/readinfo2.bin b/ms213x_patch/asm/readinfo2.bin new file mode 100644 index 0000000..96d4c95 --- /dev/null +++ b/ms213x_patch/asm/readinfo2.bin @@ -0,0 +1 @@ +{" \ No newline at end of file diff --git a/ms213x_patch/asm/vsync.asm b/ms213x_patch/asm/vsync.asm new file mode 100644 index 0000000..d8c1140 --- /dev/null +++ b/ms213x_patch/asm/vsync.asm @@ -0,0 +1,7 @@ +MOV DPTR, #0x7b16 +MOVX A, @DPTR +INC A +MOVX @DPTR, A + +MOV DPTR, #0xf055 +RET diff --git a/ms213x_patch/asm/vsync.bin b/ms213x_patch/asm/vsync.bin new file mode 100644 index 0000000..596e94b --- /dev/null +++ b/ms213x_patch/asm/vsync.bin @@ -0,0 +1 @@ +{U" \ No newline at end of file diff --git a/ms213x_patch/patch.go b/ms213x_patch/patch.go index 4f5eade..c40328c 100644 --- a/ms213x_patch/patch.go +++ b/ms213x_patch/patch.go @@ -28,9 +28,15 @@ var patchFinishf660 []byte //go:embed asm/finishsig.bin var patchFinishSig []byte +//go:embed asm/vsync.bin +var patchVSYNC []byte + //go:embed asm/readinfo.bin var patchReadInfo []byte +//go:embed asm/readinfo2.bin +var patchReadInfo2 []byte + func (p *patcher) addCode(code []byte) uint16 { offs := len(p.image) p.image = append(p.image, code...) @@ -65,6 +71,11 @@ func (p *patcher) replaceJump(offset, dest uint16) { binary.BigEndian.PutUint16(p.image[offset+1:], dest) } +func (p *patcher) replaceCall(offset, dest uint16) { + p.image[offset] = 0x12 + binary.BigEndian.PutUint16(p.image[offset+1:], dest) +} + func patch(in []byte) ([]byte, error) { /* Check if it is a file we know how to handle */ hash := sha256.Sum256(in) @@ -115,8 +126,12 @@ func patch(in []byte) ([]byte, error) { /* Write signal info to safe place (0x7b14) */ p.replaceJump(0xe9c6, p.addCode(patchFinishSig)) + /* Count frames */ + p.replaceCall(0xb208, p.addCode(patchVSYNC)) + /* Finally, add read results function */ - log.Printf("ReadInfo Offset: %02x", p.addCode(patchReadInfo)) + log.Printf("ReadInfo1 Offset: %02x", p.addCode(patchReadInfo)) + log.Printf("ReadInfo2 Offset: %02x", p.addCode(patchReadInfo2)) return p.image, nil }