Example #1
0
def setup():
    pj = job.Job(mem_setup(), "HP6626")

    cpu = mc6809.mc6809()
    return pj, cpu
Example #2
0
def example():
    cx = mc6809.mc6809()
    cx.m.map(
        mem.Stackup((FILENAMES[0], ), nextto=__file__),
        0x0000,
    )
    cx.m.map(
        mem.Stackup((FILENAMES[1], ), nextto=__file__),
        0xe000,
    )

    s = 0
    for a in range(0x0000, 0x2000, 2):
        s += cx.m.bu16(a)
    print("SUM 0x0000-0x1fff = 0x%x" % s)

    s = 0
    for a in range(0xe000, 0x10000, 2):
        s += cx.m.bu16(a)
    print("SUM 0xe000-0xffff = 0x%x" % s)

    cx.add_ins(our_desc, our_ins)

    for a, b in SYMBOLS.items():
        cx.m.set_label(a, b)

    gpu = hp1345a.hp1345a()

    cx.vectors(which=("RST", "NMI", "SWI", "IRQ", "FIRQ", "SWI2"))

    if True:
        # screen texts
        a = 0xd95
        while a < 0xf4d:
            z = Scrtxt(cx.m, a)
            a = z.hi

        Scrtxt(cx.m, 0x01db)
        Scrtxt(cx.m, 0xea56)
        Scrtxt(cx.m, 0xea6a)
        Scrtxt(cx.m, 0xea7d)
        Scrtxt(cx.m, 0xee37)
        Scrtxt(cx.m, 0xee51)
        Scrtxt(cx.m, 0xfa6d)

    if True:
        n = 0
        c = {}
        while cx.m.bu16(0xfd0 + n):
            y = data.Txt(cx.m, 0xfd0 + n, 0xfd0 + n + 2, align=1)
            ta = 0x1062 + n
            t = cx.m.bu16(ta)
            z = data.Codeptr(cx.m, ta, ta + 2, t)
            z.lcmt += y.txt
            cx.disass(t)
            if t not in c:
                c[t] = []
            if y.txt not in CMDS:
                print("Undoc command", y.txt)
                CMDS[y.txt] = [t, "???"]
            else:
                CMDS[y.txt][0] = t
            c[t].append(y.txt)
            n += 2
        for i in c:
            c[i].sort()
            cx.m.set_label(i, "CMD_" + "_".join(c[i]))

        for i in CMDS:
            c = CMDS[i]
            if c[0] == 0:
                print(i, "CMD not implemented (" + c[1] + ")")
                continue
            if c[1][0] == "?":
                print(i, "CMD not documented (%s)" % c[1][1:])
            cx.m.set_block_comment(c[0], " COMMAND " + i + " - " + c[1])

    if True:
        for a in (0x129d, 0x17e3, 0x181e, 0xe0e3, 0xee7e):
            w = cx.m[a + 1] + 1
            t = cx.m.bu16(a + 4)
            for i in range(w):
                d = cx.m.bu16(t)
                data.Codeptr(cx.m, t, t + 2, d)
                cx.disass(d)
                t += 2

    if True:
        # Random strings
        ttab(cx.m, 0xf019, 0xf03b)
        ttab(cx.m, 0xf1d1, 0xf25c)
        ttab(cx.m, 0xf412, 0xf44c)
        ttab(cx.m, 0xefd7, 0xeff7)

    if True:
        a = 0xf56e
        while cx.m[a]:
            y = data.Txt(cx.m, a, a + 6, label=False, align=1)
            a = y.hi

    if True:
        for a in range(0xf811, 0xf825, 2):
            #d = cx.m.bu16(a)
            cx.codeptr(a)
            #cx.disass(d)

    if True:
        # HP1345 testpatterns
        cx.m.set_label(0xfbed, "IMG_PIKES_PEAK")
        cx.m.set_label(0xfd41, "IMG_FOCUS")
        for a0 in (0xfbed, 0xfd41):
            a = a0
            data.Const(cx.m, a, a + 2, func=cx.m.bu16, fmt="0x%x", size=2)
            l = cx.m.bu16(a)
            a += 2
            hp1345_render.svg(cx.m, a, a + l * 2)
            while l > 0:
                gpu.disass(a, cx.m)
                a += 2
                l -= 1

    if True:
        # No idea, possibly length error in IMG_FOCUS ?
        data.Const(cx.m, 0xff17, 0xff19, fmt="0x%04x", func=cx.m.bu16, size=2)

    if True:
        # Special character handling
        b = 0xf75b
        c = 0xf778
        cx.m.set_label(b, "CHR_TBL_KEY")
        cx.m.set_label(c, "CHR_TBL_PTR")
        data.Const(cx.m, b, c, fmt="0x%x")
        a = c
        while b < c:
            p = cx.m.bu16(a)
            y = data.Dataptr(cx.m, a, a + 2, p)
            cx.m.set_label(p, "CHR_TBL_%02x" % cx.m[b])
            while True:
                z = data.Const(cx.m,
                               p,
                               p + 2,
                               func=cx.m.bu16,
                               fmt="0x%x",
                               size=2)
                if cx.m[p + 1] & 0x80:
                    break
                p += 2
            b += 1
            a += 2

    # Stuff not accessed from anywhere

    cx.disass(0xe5a1)
    cx.m.set_block_comment(0xe5a1, "Unused ROM checksum code")
    cx.m.set_block_comment(0xe5a1, "NB: Expects low rom at 0xc000")

    cx.disass(0x1acf)
    cx.disass(0xebf0)

    cx.m.set_block_comment(0x003b9, "Outputs $0x0c - Term (not comma)")
    cx.m.set_block_comment(0x003b9, "Outputs $0x12 - Error")
    cx.m.set_block_comment(0x003b9, "Outputs $0x1a = 0")
    cx.m.set_block_comment(0x003b9, "Outputs $0x1b - Digits")
    cx.m.set_block_comment(0x003b9, "Outputs $0x1f - Decimals")
    cx.m.set_block_comment(0x003b9, "Outputs $0x27 - Negative")
    cx.m.set_block_comment(0x003b9, "Outputs $0x31+32 - Number")
    cx.m.set_block_comment(0xf895, "Set reset, clear interrupt, Clr reset")

    return NAME, (cx.m, )
Example #3
0
			i = keys.get(pj.m[a])
			j = keys.get(pj.m[a + 1])
			y.lcmt += "%8s | %-8s\n" % (i, j)

#######################################################################

for pg in (0,1,2,3,4):

	pj,m = setup(pg)

	romsum(pj)

	# decompile.setup(pj)

	# cpu = decompile.mc6809a()
	cpu = mc6809.mc6809()

	hints(pj, cpu)

	symb(pj, cpu)

	if pj.pg == 4:
		lexer(pj)
		cpu.vectors()

	# decompile.analyse(pj, cpu)

	str_len_args(pj, 0xd8a5, 3, 2)
	str_len_args(pj, 0x9ffe, 1, 2)
	error_arg(pj, 0xc3fe, 1, errors)
	num_arg(pj, 0xd37d, 1)
Example #4
0
def example():
    m = mem.ByteMem(0x8000, 0x10000)
    for i in open(fwd + "06626-80005-REV-A-00-04.hex"):
        j = i.split()
        m[int(j[0],16)] = int(j[1],16)

    cx = mc6809.mc6809()
    cx.m.map(m, 0x8000, offset=0x8000)

    for i, j in SYMBOLS.items():
        cx.m.set_label(i, j)

    cx.vectors(which=("RST", "NMI", "SWI", "IRQ", "FIRQ"))

    token = {
        1:    '?',
        2:    'end',
        3:    'sep',
        4:    'number',
        6:    'string',
    }

    err = {
    }

    #        6624        6626
    kbd_tbl = {
        0x01:    [ '9',        '9' ],
        0x02:    [ '.',        '.' ],
        0x03:    [ 'enter',    'enter' ],
        0x04:    [ '6',        '6' ],

        0x05:    [ 'meter',    'range' ],
        0x06:    [ 'rcl',    'rcl' ],
        0x07:    [ 'unmask',    'ocp' ],
        0x08:    [ 'addr',    'addr' ],

        0x09:    [ '7',        '7' ],
        0x0a:    [ '0',        '0' ],
        0x0b:    [ '2',        '2' ],
        0x0c:    [ '4',        '4' ],

        0x0d:    [ 'output>',    'output>' ],
        0x0e:    [ 'on_off',    'on_off' ],
        0x0f:    [ '1',        '1' ],
        0x10:    [ 'vset',    'vset' ],

        0x11:    [ None,        None ],
        0x12:    [ 'sto',    'sto' ],
        0x13:    [ 'err',    'err' ],
        0x14:    [ 'lcl',    'lcl' ],

        0x15:    [ 'ovset',    'V_up' ],
        0x16:    [ 'fault',    'reset' ],
        0x17:    [ 'ocp',    'I_up' ],
        0x18:    [ 'dly',    'ovset' ],

        0x19:    [ '<output',    '<output' ],
        0x1a:    [ 'ocrst',    'I_dn' ],
        0x1b:    [ 'iset',    'iset' ],
        0x1c:    [ 'ovrst',    'V_dn' ],

        0x1d:    [ '8',        '8' ],
        0x1e:    [ 'backsp',    'backsp' ],
        0x1f:    [ '3',        '3' ],
        0x20:    [ '5',        '5' ],
    }

    for i in range(1,33):
        s = "%02x" % i
        a = cx.m[0x87f0+i-1]
        b = cx.m[0x87d0+i-1]
        s += "   "
        s += " %x" % a
        s += " %04x" % cx.m.bu16(0x87b2 + a * 2)
        s += " %-10s" % kbd_tbl[i][0]
        s += "   "
        s += " %x" % b
        s += " %04x" % cx.m.bu16(0x87b2 + b * 2)
        s += " %-10s" % kbd_tbl[i][1]
        print(s)

    def softlbl(a, n):
        cx.m.set_label(a, n)

    data.Const(cx.m, 0x8000, 0x8002)

    cx.m.set_label(0xd472, "chan_ptr")
    for a in range(0xd472, 0xd47a, 2):
        data.Dataptr(cx.m, a, a + 2, cx.m.bu16(a))

    for a,b in (
        (0x8002, 0x802a),
        ):
        y = data.Txt(cx.m, a, b, align=1)

    for a in (
        0x827b,
        0x849b,
        0x84a7,
        0x84b3,
        0x84bf,
        0x84cb,
        0x84d7,
        0xbcb1,
        0xbcbd,
        0xbcc9,
        0xc255,
        0xcf01,
        0xd262,
        ):
        y = data.Txt(cx.m, a, a + 12, align=1)

    for a in (
        0xa183,
        0xa186,
        0xa18f,
        0xa198,
        0xaffe,
        ):
        y = data.Txt(cx.m, a, pfx=1, align=1)

    cx.m.set_label(0x8ec2, "ERROR_TEXTS")
    n = 0
    for a in range(0x8ec2, 0x9036, 12):
        y = data.Txt(cx.m, a, a + 12, align=1, label=False)
        err[n] = y.txt
        n += 1

    a = 0xa225
    nn = 7
    while a < 0xa370:
        b = cx.m[a]
        if b == 0:
            break
        y = data.Txt(cx.m, a, pfx=1, align=1, label=False)
        token[nn] = y.txt
        a = y.hi
        nn += 1

    print("NN", nn)

    for a in range(0x87d0, 0x8810, 8):
        data.Const(cx.m, a, a + 8)

    def t1(a, l):
        cx.m.set_label(a, l)
        while True:
            data.Const(cx.m, a, a + 1)
            if cx.m[a] == 0:
                return;
            a += 1
            y = data.Txt(cx.m, a, align=1, label=False)
            a = y.hi
            cx.codeptr(a)
            z = cx.m.bu16(a)
            if False:
                # XXX: doesn't work for ERROR
                print("XXX %04x" % (z-3), y.txt)
                cx.disass(z - 3)
            cx.m.set_label(z, "func_" + y.txt)
            a += 2

    t1(0x8824, "HP6626_func_01_key")
    t1(0x8860, "HP6624_func_01_key")

    n = 1
    for a in range(0x87b4, 0x87d0, 2):
        x = cx.m.bu16(a)
        softlbl(x, "key_%02x_%04x" % (n, x))
        n += 1
        cx.codeptr(a)

    n = 1

    for a in range(0xa5d3, 0xa687, 2):
        x = cx.m.bu16(a)
        softlbl(x, "cmd_%02x_%04x" % (n,x))
        n += 1
        cx.codeptr(a)

    class tt_5(data.Data):
        def __init__(self, asp, lo):
            hi = lo + 4
            super().__init__(asp, lo, hi, "tt_5")

        def render(self):
            s = ".TT5\t"
            t = self.aspace[self.lo]
            if t in token:
                s += (token[t] + ", ").ljust(8)
            else:
                s += "T%02x, " % t
            s += "0x%02x, " % self.aspace[self.lo + 1]
            w = self.aspace.bu16(self.lo + 2)
            s += self.aspace.adr(w)
            return s

    tt5s = {}

    def tt5(a, f, l = None, ex = 0):
        if l == None:
            l = []
        cx.m.set_label(a, "tt5_%04x" % a)
        while True:
            ll = list(l)
            if cx.m[a] == 0:
                if not cx.m.occupied(a):
                    data.Const(cx.m, a, a + 1)
                break
            t = cx.m[a]
            if t in token:
                ll.append(token[t])
            else:
                ll.append("T%02x" % t)
            e = cx.m[a + 1]
            if e != 0:
                ex = f + e * 2
                z = cx.m.bu16(ex)
                # print("%04x" % a, "%04x" % z, "A %02x" % e, ll)
                cx.m.set_label(z, "cmd_" + "_".join(ll))
            if a not in tt5s:
                tt5s[a] = tt_5(cx.m, a)
            x = cx.m.bu16(a + 2)
            if x != 0:
                tt5(x, f, ll, ex)
            else:
                #print("%04x" % a, ll, "%04x" % ex)
                for y in cx.m.find(ex):
                    y.lcmt += " ".join(ll) + "\n"
                #print(y)

            a += 4

    tt5(0xa3a2, 0xa5d1)

    for a in range(0xb7ac, 0xb7c4, 2):
        data.Const(cx.m, a, a + 2)


    # Task or coroutine table
    for a in range(0xce62, 0xce80, 6):
        data.Dataptr(cx.m, a, a + 2, cx.m.bu16(a))
        z = cx.m.bu16(a + 2)
        softlbl(z, "task_%04x" % z)
        cx.codeptr(a + 2)
        data.Dataptr(cx.m, a + 4, a + 6, cx.m.bu16(a + 4))


    if True:
        cx.disass(0x8631)
        cx.disass(0x8b64)
        cx.disass(0x8d6d)
        cx.disass(0x8d76)
        cx.disass(0x8e84)
        cx.disass(0x8e87)
        cx.disass(0xab5c)
        cx.disass(0xc7a2)
        cx.disass(0xc7ad)
        cx.disass(0xc7b8)
        cx.disass(0xc7c5)
        cx.disass(0xc7d9)
        cx.disass(0xc7e6)
        cx.disass(0xc7fc)
        cx.disass(0xc809)
        cx.disass(0xc814)
        cx.disass(0xc821)
        cx.disass(0xc835)
        cx.disass(0xc842)
        cx.disass(0xc84b)
        cx.disass(0xcf0d)
        cx.disass(0xc855)
        cx.disass(0xd3b8)
        cx.disass(0xd3f8)

    if True:
        # See above in t1
        cx.disass(0x8b03)
        cx.disass(0x8b14)
        cx.disass(0x8b25)
        cx.disass(0x8b36)
        cx.disass(0x8b44)
        cx.disass(0x8b65)
        cx.disass(0x8b78)
        cx.disass(0x8b86)
        cx.disass(0x8b91)


    ##############

    def fp_val(cx, lo, hi):
        e = cx.m.s8(hi - 1)
        m = 0
        i = 0
        a = hi - 2
        while a >= lo:
            m |= cx.m[a] << i
            i += 8
            a -= 1
        m *= 10 ** e
        return m

    class fp(data.Data):
        def __init__(self, cx, lo, hi):
            super().__init__(cx.m, lo, hi, "fp")
            self.val = fp_val(cx, lo, hi)

        def render(self):
            return ".FP\t%g" % self.val

    class tt_2(data.Data):
        def __init__(self, cx, lo):
            hi = lo + 5 + cx.m[lo + 4] * 4
            super().__init__(cx.m, lo, hi, "tt_2")

        def render(self):
            s = ".TT2\t{\n"
            w = self.aspace.bu16(self.lo + 0)
            s += "\t.next = " + self.aspace.adr(w) + "\n"
            s += "\t.model = %4d\n" % self.aspace.bu16(self.lo + 2)
            n = self.aspace[self.lo + 4]
            s += "\t.outputs = %d\n" % n
            a = self.lo + 5
            for i in range(n):
                w = self.aspace.bu16(a)
                s += "\t.out1[%d] = " % i + self.aspace.adr(w) + "\n"
                a += 2
                w = self.aspace.bu16(a)
                s += "\t.out2[%d] = " % i + self.aspace.adr(w) + "\n"
                a += 2
            return s + "\t}"

    class tt_output1(data.Data):
        def __init__(self, cx, lo):
            hi = lo + 39
            super().__init__(cx.m, lo, hi, "tt_output1")
            self.compact = True

        def render(self):
            s = ".OUTPUT1\t"
            a = self.lo
            f = [ "%4.1f", "%4.1f", "%6.3f", "%6.3f", "%4.1f"]
            for i in range(5):
                s += "0x%04x, " % self.aspace.bu16(a)
                a += 2
                s += (f[i] + ", ") % fp_val(cx, a, a + 4)
                a += 4
            for i in range(3):
                s += "%5.2f, " % fp_val(cx, a, a + 3)
                a += 3
            return s[:-2]

    class tt_output2(data.Data):
        def __init__(self, cx, lo):
            hi = lo + 44
            super().__init__(cx.m, lo, hi, "tt_output2")
            self.compact = True

        def render(self):
            s = ".OUTPUT2\t"
            a = self.lo
            f = [ "%4.1f", "%4.1f", "%6.3f", "%6.3f", "%4.1f",
                "%5.3f", "%4.1f"]
            for i in range(7):
                s += "0x%04x, " % self.aspace.bu16(a)
                a += 2
                s += (f[i] + ", ") % fp_val(cx, a, a + 4)
                a += 4
            s += "0x%04x" % self.aspace.bu16(a)
            return s

    tt = {}

    def tt3_1(a):
        if a in tt:
            return
        tt[a] = True
        tt_output1(cx, a)

    def tt3_2(a):
        if a in tt:
            return
        tt[a] = True
        tt_output2(cx, a)
        return
        softlbl(a, "tt3_2_%04x" % a)
        while True:
            if cx.m[a + 2] > 2:
                break
            data.Const(cx.m, a, a+2, fmt="0x%02x")
            fp(cx, a + 2, a + 6)
            a += 6
        data.Const(cx.m, a, a+2, fmt="0x%02x")

    a = 0xb39c
    while a:
        cx.m.set_label(a, "tt2_%04x" % a)
        x = cx.m.bu16(a)
        if x == 0:
            data.Dataptr(cx.m, a, a + 2, x)
            break
        y = tt_2(cx, a);
        a = x
        continue
        data.Const(cx.m, a + 2, a + 4, fmt="%d")
        data.Const(cx.m, a + 4, a + 5)
        y = cx.m[a + 4]
        a += 5
        for i in range(y * 2):
            z = cx.m.bu16(a)
            tt3_1(z)
            data.Dataptr(cx.m, a, a + 2, z)
            a += 2
            z = cx.m.bu16(a)
            tt3_2(z)
            data.Dataptr(cx.m, a, a + 2, z)
            a += 2
        a = x

    ##############
    for a in range(0xb437, 0xb46e, 5):
        cx.m.set_label(a, "tt1_%04x" % a)
        data.Const(cx.m, a, a+1)
        z = cx.m.bu16(a + 1)
        data.Dataptr(cx.m, a + 1, a + 3, z)
        tt3_1(z)
        z = cx.m.bu16(a + 3)
        data.Dataptr(cx.m, a + 3, a + 5, z)
        tt3_2(z)

    #############
    # Add comment with error message

    for i in cx.m:
        if i.tag != "mc6809":
            continue
        if i.dstadr != 0x91d7:
            continue
        j = list(cx.m.find(hi=i.lo))
        if len(j) != 1:
            continue
        j=j[0]
        x = cx.m[j.lo]
        if x != 0x86:
            continue
        y = cx.m[j.lo + 1]
        j.lcmt += "Error: " + err[y] + "\n"

    #############
    # discover.Discover(cx)
    return NAME, (cx.m,)
Example #5
0
def setup():
	pj = job.Job(mem_setup(), "HP1347A_proto")

	cpu = mc6809.mc6809()
	return pj, cpu
Example #6
0
			j[0].mne="ldd__"
			u = pj.m.bu16(j[0].lo + 1)
			v = pj.m.bu16(u)
			j[0].mne="ldd__%d" % v
			data.Const(pj, u, u + 1)
			data.Const(pj, u + 1, u + 2)

#######################################################################

for pg in (0,1,2,3,4):

	pj,m = setup(pg)

	romsum(pj)

	cpu = mc6809.mc6809()

	hints(pj, cpu)

	symb(pj, cpu)

	if pj.pg == 4:
		lexer(pj)
		cpu.vectors(pj)

	while pj.run():
		pass

	while do_switch():
		continue