@@ -8,9 +8,11 @@ import (
88 "strings"
99 "testing"
1010
11+ chip8arch "github.com/retroenv/retrodisasm/internal/arch/chip8"
1112 "github.com/retroenv/retrodisasm/internal/arch/m6502"
1213 "github.com/retroenv/retrodisasm/internal/assembler"
1314 "github.com/retroenv/retrodisasm/internal/assembler/ca65"
15+ "github.com/retroenv/retrodisasm/internal/assembler/retroasm"
1416 "github.com/retroenv/retrodisasm/internal/options"
1517 "github.com/retroenv/retrogolib/arch"
1618 "github.com/retroenv/retrogolib/arch/system/nes/cartridge"
@@ -19,6 +21,24 @@ import (
1921 "github.com/retroenv/retrogolib/log"
2022)
2123
24+ func TestDisasmChip8BranchReferenceOperands (t * testing.T ) {
25+ input := []byte {
26+ 0xa2 , 0x08 , // ld I, $208
27+ 0xb2 , 0x0a , // jp V0, $20a
28+ 0x00 , 0x00 ,
29+ 0x00 , 0x00 ,
30+ 0x12 , 0x34 , // labeled data referenced by ld I
31+ 0x00 , 0xee , // labeled ret target referenced by jp V0
32+ }
33+
34+ output := runChip8Disasm (t , input )
35+
36+ assert .True (t , strings .Contains (output , "ld I, _label_0208" ))
37+ assert .True (t , strings .Contains (output , "jp V0, _label_020a" ))
38+ assert .False (t , strings .Contains (output , "ld _label_0208" ))
39+ assert .False (t , strings .Contains (output , "jp _label_020a" ))
40+ }
41+
2242func TestDisasmZeroDataReference (t * testing.T ) {
2343 input := []byte {
2444 0xad , 0x20 , 0x80 , // lda a:$8020
@@ -524,6 +544,36 @@ func testProgram(t *testing.T, opts options.Disassembler, cart *cartridge.Cartri
524544 return disasm
525545}
526546
547+ func runChip8Disasm (t * testing.T , input []byte ) string {
548+ t .Helper ()
549+
550+ opts := options .NewDisassembler (assembler .Retroasm , string (arch .CHIP8System ))
551+ opts .OffsetComments = false
552+ opts .HexComments = false
553+
554+ cart := cartridge .New ()
555+ cart .PRG = make ([]byte , len (input ))
556+ copy (cart .PRG , input )
557+
558+ logger := log .NewTestLogger (t )
559+ disasm , err := New (logger , chip8arch .New (), cart , opts , retroasm .New )
560+ assert .NoError (t , err )
561+
562+ var buffer bytes.Buffer
563+ writer := bufio .NewWriter (& buffer )
564+
565+ newBankWriter := func (_ string ) (io.WriteCloser , error ) {
566+ return nopWriteCloser {writer }, nil
567+ }
568+
569+ app , err := disasm .Process (context .Background (), writer , newBankWriter )
570+ assert .NoError (t , err )
571+ assert .True (t , app != nil , "app should not be nil" )
572+ assert .NoError (t , writer .Flush ())
573+
574+ return trimStringList (buffer .String ())
575+ }
576+
527577func trimStringList (s string ) string {
528578 sl := strings .Split (s , "\n " )
529579 for i , s := range sl {
0 commit comments