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 »

jedie wrote:Tried this:

Code: Select all

1010 DATA B6,50,00		' LDA $5000
1020 DATA 8B,01			' ADDA 1
1030 DATA 1F,A9			' TFR CC,B
1040 DATA F7,50,01		' STB $5001
1050 DATA B7,50,00		' STA $5000
1060 DATA 39			' RTS
But gets strange behaviour in XRoar.

Now i try to use STD

EDIT: It the 1030 DATA 1F,A9 ' TFR CC,B what brings XRoar into trouble. Maybe a but or my DATA code wrong?
OK, no i used the xroar trace to see what's happens:

Code: Select all

4000| b64500      LDA     $4500               cc=a4 a=00 b=00 dp=00 x=4000 y=8497 u=0000 s=7f21
4003| 8b01        ADDA    #$01                cc=80 a=01 b=00 dp=00 x=4000 y=8497 u=0000 s=7f21
4005| 1fa9        TFR     CC,B                cc=80 a=01 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4007| 0bfd        DEC*    <$fd                cc=88 a=01 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4009| 45          LSRA*                       cc=85 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
400a| 0039        NEG     <$39                cc=89 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
400c| 0000        NEG     <$00                cc=89 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
400e| 0000        NEG     <$00                cc=81 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4010| ffffff      STU     $ffff               cc=85 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4013| ff0000      STU     $0000               cc=85 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4016| 0000        NEG     <$00                cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4018| ffffff      STU     $ffff               cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
401b| ff0000      STU     $0000               cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
401e| 0000        NEG     <$00                cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4020| ffffff      STU     $ffff               cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4023| ff0000      STU     $0000               cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4026| 0000        NEG     <$00                cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4028| ffffff      STU     $ffff               cc=84 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
The TFR CC,B is ok and seems to work. But after this it should come f75001 STB $5001 and not 0bfd DEC* <$fd
The last STU, STU, NEG is a never ending loop.

It's a inserted 0b that's brings everything out of sync:
4005| 1fa9 TFR CC,B cc=80 a=01 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4007| 0bfd DEC* <$fd cc=88 a=01 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
4009| 45 LSRA* cc=85 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
400a| 0039 NEG <$39 cc=89 a=00 b=80 dp=00 x=4000 y=8497 u=0000 s=7f21
I added a test output in the machine loader part:

Code: Select all

65 V=VAL("&H"+HB$)
70 POKE PA,V	                ' POKE VALUE INTO MEMORY
75 PRINT "POKE $";HEX$(V);" AT $";HEX$(PA)
80 PA = PA + 1			' INCREMENT POKE ADDRESS
And yes, i see this line: POKE $B AT $4007 :shock: Why???


The complete .bas:

Code: Select all

10 ' TEST CC REGISTERS
20 LA=&H4000			' LOAD / EXECUTE ADDRESS
25 PRINT "POKE MACHINE CODE TO: $";HEX$(LA)
30 PA = LA			' START ADDRESS FOR POKE
50 READ HB$			' HEX CONSTANTS
60 IF HB$="END" THEN 100
65 V=VAL("&H"+HB$)
70 POKE PA,V	                ' POKE VALUE INTO MEMORY
75 PRINT "POKE $";HEX$(V);" AT $";HEX$(PA)
80 PA = PA + 1			' INCREMENT POKE ADDRESS
90 GOTO 50
100 PRINT "LOADED, END ADDRESS IS: $"; HEX$(PA-1)
110 PRINT
120 INPUT "INPUT 'A' VALUE (DEZ)";A
130 POKE &H4500,A ' SET START VALUE
150 PRINT "A=";A;" VALUE FROM $4500: ";PEEK(&H4500)
160 FOR I = 1 TO 14
170 EXEC LA
180 CC=PEEK(&H4501)
190 PRINT "A=";PEEK(&H4500);" CC=$";HEX$(CC)
200 NEXT I
500 GOTO 120
1000 ' MACHINE CODE IN HEX
1010 DATA B6,45,00		' LDA $4500
1020 DATA 8B,01			' ADDA 1
1030 DATA 1F,A9			' TFR CC,B
1040 DATA FD,45,00		' STD $4500 ; STORE A+B
1060 DATA 39			' RTS
10000 DATA END
Attachments
ass_CC04.bas.JPG
ass_CC04.bas.JPG (54.04 KiB) Viewed 4494 times
Last edited by jedie on Fri Oct 11, 2013 3:41 pm, edited 1 time in total.
... 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 »

Oh!!!

It's this:
1030 DATA 1F,A9 ' TFR CC,B
1040 DATA FD,45,00 ' STD $4500 ; STORE A+B
:o

Comments not striped in DATA ??? Boring :x
... 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 »

OK, now everything is together for the BASIC CC Register programm -> https://github.com/jedie/PyDragon32/tre ... _Registers

Image

Image
... 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
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Howto try small machine code programs in BASIC ?

Post by zephyr »

jedie wrote:Oh!!!

It's this:
1030 DATA 1F,A9 ' TFR CC,B
1040 DATA FD,45,00 ' STD $4500 ; STORE A+B
:o

Comments not striped in DATA ??? Boring :x
The only way to add comments is to add an extra REM line after each data line.

Code: Select all

1030 DATA 1F,A9
1031 ' TFR CC,B
1040 DATA FD,45,00
1041 ' STD $4500 ; STORE A+B
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 »

I have just been made ​​that way. But above the DATA line: https://github.com/jedie/PyDragon32/blo ... as#L46-L56
... 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 »

I add another CC test with INC: https://github.com/jedie/PyDragon32/blo ... CC_INC.bas

Machine code:

Code: Select all

1010 ' CLR B
1020 DATA 5F
1030 ' LDB $11 ; B=$11
1040 DATA C6,11
1050 ' ADDB $1 ; B=B+$1
1060 DATA CB,01
1070 ' INC $4500
1080 DATA 7C,45,00
1090 ' TFR CC,B
1100 DATA 1F,A9
1110 ' STB $4501 ; STORE B
1120 DATA F7,45,01
The initial CLR,LDB,ADDB do i, to clear the CC registers. Because INC does only affect NZV (not the half-carry)

The values i get in XRoar (staring with 250) is not as i excepted. Only NZ changed. V is always 0 but i guess if 0xff INC to 0x00 should set V, isn't it?
Tomorrow i will run on a real dragon to compare...
... 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
sixxie
Posts: 1348
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by sixxie »

As signed values, remember $FF is -1. Incrementing -1 to 0 is not a signed overflow.

Incrementing $7F to $80 (-128) is, however.
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 »

You're right! Thanks!

INC from $7f to $80 result in V=1 in XRoar.

But if i INC $ff (-1) then its wrap around to $0 (dez. 0) so it goes from negative -1 to positive 0 ? Or has 0 no sign?

I would like to run the .bas file on a real Dragon, but PyDC doesn't work, see: viewtopic.php?f=8&t=4231&p=9717#p9717 :cry:
... 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
sixxie
Posts: 1348
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by sixxie »

jedie wrote: But if i INC $ff (-1) then its wrap around to $0 (dez. 0) so it goes from negative -1 to positive 0 ? Or has 0 no sign?
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).
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 »

I rework on a older test with ADDA:

Code: Select all

270 ' MACHINE CODE IN HEX
280 ' LDA $4500
290 DATA B6,45,00
300 ' ADDA 1
310 DATA 8B,01
320 ' TFR CC,B + STD $4502
330 DATA 1F,A9,FD,45,02
340 ' LDA $4500
350 DATA B6,45,00
360 ' ADDA 2
370 DATA 8B,02
380 ' TFR CC,B + STD $4504
390 DATA 1F,A9,FD,45,04
400 ' LDA $4500
410 DATA B6,45,00
420 ' ADDA 3
430 DATA 8B,03
440 ' TFR CC,B + STD $4506
450 DATA 1F,A9,FD,45,06
460 ' LDA $4500
470 DATA B6,45,00
480 ' ADDA 4
490 DATA 8B,04
500 ' TFR CC,B + STD $4508
510 DATA 1F,A9,FD,45,08
520 ' LDA $4500
530 DATA B6,45,00
540 ' ADDA 5
550 DATA 8B,05
560 ' TFR CC,B + STD $450A
570 DATA 1F,A9,FD,45,0A
580 ' LDA $4500
590 DATA B6,45,00
600 ' ADDA 6
610 DATA 8B,06
620 ' TFR CC,B + STD $450C
630 DATA 1F,A9,FD,45,0C
640 ' LDA $4500
650 DATA B6,45,00
660 ' ADDA 7
670 DATA 8B,07
680 ' TFR CC,B + STD $450E
690 DATA 1F,A9,FD,45,0E
700 ' LDA $4500
710 DATA B6,45,00
720 ' ADDA 8
730 DATA 8B,08
740 ' TFR CC,B + STD $4510
750 DATA 1F,A9,FD,45,10
760 ' RTS
770 DATA 39
Source here: https://github.com/jedie/PyDragon32/blo ... C_ADDA.bas

I expected that the carry only set after wrap around from 0xff to 0x0

EDIT: I recreate the XRoar trace for this:

Code: Select all

b777| 6e9f009d    JMP     [$009D]             cc=a0 a=00 b=00 dp=00 x=4000 y=890b u=2039 s=7f33
4000| b64500      LDA     $4500               cc=a8 a=fc b=00 dp=00 x=4000 y=890b u=2039 s=7f33
4003| 8b01        ADDA    #$01                cc=88 a=fd b=00 dp=00 x=4000 y=890b u=2039 s=7f33
4005| 1fa9        TFR     CC,B                cc=88 a=fd b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4007| fd4502      STD     $4502               cc=88 a=fd b=88 dp=00 x=4000 y=890b u=2039 s=7f33
400a| b64500      LDA     $4500               cc=88 a=fc b=88 dp=00 x=4000 y=890b u=2039 s=7f33
400d| 8b02        ADDA    #$02                cc=88 a=fe b=88 dp=00 x=4000 y=890b u=2039 s=7f33
400f| 1fa9        TFR     CC,B                cc=88 a=fe b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4011| fd4504      STD     $4504               cc=88 a=fe b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4014| b64500      LDA     $4500               cc=88 a=fc b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4017| 8b03        ADDA    #$03                cc=88 a=ff b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4019| 1fa9        TFR     CC,B                cc=88 a=ff b=88 dp=00 x=4000 y=890b u=2039 s=7f33
401b| fd4506      STD     $4506               cc=88 a=ff b=88 dp=00 x=4000 y=890b u=2039 s=7f33
401e| b64500      LDA     $4500               cc=88 a=fc b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4021| 8b04        ADDA    #$04                cc=a5 a=00 b=88 dp=00 x=4000 y=890b u=2039 s=7f33
4023| 1fa9        TFR     CC,B                cc=a5 a=00 b=a5 dp=00 x=4000 y=890b u=2039 s=7f33
4025| fd4508      STD     $4508               cc=a1 a=00 b=a5 dp=00 x=4000 y=890b u=2039 s=7f33
4028| b64500      LDA     $4500               cc=a9 a=fc b=a5 dp=00 x=4000 y=890b u=2039 s=7f33
402b| 8b05        ADDA    #$05                cc=a1 a=01 b=a5 dp=00 x=4000 y=890b u=2039 s=7f33
402d| 1fa9        TFR     CC,B                cc=a1 a=01 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
402f| fd450a      STD     $450a               cc=a1 a=01 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4032| b64500      LDA     $4500               cc=a9 a=fc b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4035| 8b06        ADDA    #$06                cc=a1 a=02 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4037| 1fa9        TFR     CC,B                cc=a1 a=02 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4039| fd450c      STD     $450c               cc=a1 a=02 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
403c| b64500      LDA     $4500               cc=a9 a=fc b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
403f| 8b07        ADDA    #$07                cc=a1 a=03 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4041| 1fa9        TFR     CC,B                cc=a1 a=03 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4043| fd450e      STD     $450e               cc=a1 a=03 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4046| b64500      LDA     $4500               cc=a9 a=fc b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4049| 8b08        ADDA    #$08                cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
404b| 1fa9        TFR     CC,B                cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
404d| fd4510      STD     $4510               cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
4050| 39          RTS                         cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f35
84da| 20c3        BRA     $849f               cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f35
849f| bd019a      JSR     $019a               cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f33
019a| 39          RTS                         cc=a1 a=04 b=a1 dp=00 x=4000 y=890b u=2039 s=7f35
Attachments
testCC_ADDA_01.png
testCC_ADDA_01.png (13.52 KiB) Viewed 4449 times
... 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