Howto try small machine code programs in BASIC ?

Hardware Hacking, Programming and Game Solutions/Cheats
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by jedie »

Sorry for my long line :oops: Thanks for your patience :)
sixxie wrote:It's just that a signed 2's complement 8-bit integer can hold values -128 to +127. If an addition's result exceeds that range, that's an overflow. The sign is a separate issue (and indeed, in 2's complement 0 is considered positive).
OK, i think i understand it a little bit more.

But i need some explicit examples. :oops:

e.g.: (pseudo code):

Code: Select all

A = 0
while True:
    HNZVC = 0 # Clear CC flags
    ADDA #1
In which case are HNZVC set?

In DragonPy i made this:

Code: Select all

        self.cpu_test_run(start=0x1000, end=None, mem=[
            0x86, 0x0, # LDA #0
        ])
        for i in xrange(256):
            self.cpu_test_run(start=0x1000, end=None, mem=[
                0x5f, # CLR B
                0x1f, 0x9a, # TFR B,CC
                0x8B, 0x01, # ADDA #1
            ])
            print i, self.cpu.cc.get_info
Now in DragonPy theses flags are set:
H set if A == 16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,0
N is set if A between 128 - 255
Z is only set if A == 0
V is only set if A == 128
C is only set on A == 0 (in the 256 iteration where A wrap around: 0xff+1 = 0x0)

I Updated my testCC_ADDA.bas and these values are exactly the same with it in XRoar: https://github.com/jedie/PyDragon32/blo ... C_ADDA.bas
testCC_ADDA 02a.PNG
testCC_ADDA 02a.PNG (8.39 KiB) Viewed 2433 times
testCC_ADDA 02b.PNG
testCC_ADDA 02b.PNG (10.1 KiB) Viewed 2433 times
testCC_ADDA 02c.PNG
testCC_ADDA 02c.PNG (10.37 KiB) Viewed 2433 times
Now i would like to so the same with SUBA, INCA and DECA...
ADDA and INCA should set the same CC values, except H and C, isn't it?
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by jedie »

jedie wrote:H set if A == 16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,0
N is set if A between 128 - 255
Z is only set if A == 0
V is only set if A == 128
C is only set on A == 0 (in the 256 iteration where A wrap around: 0xff+1 = 0x0)
With this information i have now the first working CC unittest test committed: https://github.com/jedie/DragonPy/commi ... a332390766

And this should i have for SUB, INC, DEC and maybe for other Instruction, too.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by jedie »

Next test program is with SUBA: https://github.com/jedie/PyDragon32/com ... 0dd718b33a

Results:
N is set if A between 128 - 255
Z is only set if A == 0
C is set if SUB $00 to $ff
V ist set if SUB $80 to $7f

H is never set. The spec says it's "undefined". What does it exactly mean? What if H was set in a previous OP?

EDIT: Unittests are a very good idea: Bugfix SUB a and add unittests: https://github.com/jedie/DragonPy/commi ... b85763fb12
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by jedie »

The specs say that TST affected NZ and that V set to 0:
Set the N (negative) and Z (zero) bits according to the contents of
accumulator A or B, and clear the V (overflow) bit.

"HNZVC": -aa0-
Somewhere i found this:
The MC6800 processor clears the C (carry) bit.
That's confusing. C should be not affected.

XRoar does this:

Code: Select all

        CLR_NZV;
        SET_NZ8(in);
see: https://github.com/jedie/XRoar/blob/880 ... #L167-L168

So XRoar will clear V and C but will update them...

EDIT: Wrong copy&paste. Corrected the XRoar code.
Create a CC test .bas with TST: https://github.com/jedie/PyDragon32/com ... 46ec7a488e
XRoar does only set N and Z.
Everything fine ;)
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
Post Reply