summaryrefslogtreecommitdiff
path: root/romstr.py
blob: 112348a2bf97e269f15be8c07432c91a3b442703 (plain)
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
class RomStr(str):
    """ Simple wrapper to prevent a giant rom from being shown on screen
    """

    def length(self):
        """len(self)"""
        return len(self)

    def __repr__(self):
        return "RomStr(too long)"

    def interval(self, offset, length, strings=True, debug=True):
        """returns hex values for the rom starting at offset until offset+length"""
        returnable = [] 
        for byte in self[offset:offset+length]:
            if strings:
                returnable.append(hex(ord(byte)))
            else:
                returnable.append(ord(byte))
        return returnable

    def until(self, offset, byte, strings=True, debug=False):
        """returns hex values from rom starting at offset until the given byte"""
        return self.interval(offset, self.find(chr(byte), offset) - offset, strings=strings)

class AsmList(list):
    """simple wrapper to prevent all asm lines from being shown on screen"""

    def length(self):
        """len(self)"""
        return len(self)

    def __repr__(self):
        return "AsmList(too long)"