Howto try small machine code programs in BASIC ?

Hardware Hacking, Programming and Game Solutions/Cheats
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by tormod »

You can transfer values from one register to another with TFR.

I recommend you read the whole Inside the Dragon. It is very well written, and everything you find there is something you eventually would like to know, so it will just save you a lot of time and questions.
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 »

Yes your right, Inside the Dragon is really a good book. I would like to have it in real printed form. But not found it yet on ebay...
Last edited by jedie on Sat Oct 05, 2013 2:37 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
admin
Site Admin
Posts: 410
Joined: Thu Jul 17, 2008 10:22 pm

Re: Howto try small machine code programs in BASIC ?

Post by admin »

I'll keep my eye out for a copy - I can't let mine go - its signed by Duncan Smeed himself !
Simon Hardy
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by tormod »

I snatched mine from Amazon UK some months ago for £4.31 :D Later the dealers smelled the blood and I saw it for several hundred pounds. Now there is one there for £21.87, the same seller also has it on AbeBooks UK.
Last edited by tormod on Sat Oct 05, 2013 3:28 pm, edited 1 time in total.
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 get it for 21€ ;)
... 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 need a little bit help... again :roll:

I created a small BASIC test program to display the CC registers. But doesn't work :roll:

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
70 POKE PA,VAL("&H"+HB$)	' POKE VALUE INTO MEMORY
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 &H5000,A ' SET START VALUE
150 PRINT "A=";A;" VALUE FROM $5000: ";PEEK(&H5000)
160 FOR I = 1 TO 14
170 EXEC LA
180 CC=PEEK(&H5002)
190 PRINT "A=";PEEK(&H5000);" CC=$";HEX$(CC)
200 NEXT I
500 GOTO 120
1000 ' MACHINE CODE IN HEX
1010 DATA B6,50,00		' LDA $5000
1020 DATA 8B,01			' ADDA 1
1030 DATA 1F,A1			' TFR CC,X
1040 DATA BF,50,02		' STX $5002
1050 DATA B7,50,00		' STA $5000
1060 DATA 39			' RTS
10000 DATA END
The assembler code only:

Code: Select all

1010 DATA B6,50,00		' LDA $5000
1020 DATA 8B,01			' ADDA 1
1030 DATA 1F,A1			' TFR CC,X
1040 DATA BF,50,02		' STX $5002
1050 DATA B7,50,00		' STA $5000
I also tried this:

Code: Select all

1030 DATA B6,50,00		' LDA $5000
1040 DATA 8B,01			' ADDA 1
1050 DATA B7,50,00		' STA $5000 ' STORE A TO M
1060 DATA 1F,A0			' TFR CC,D  ' STORE CC IN D
1070 DATA FD,50,02		' STD $5002 ' STORE D TO M
But this makes no sence, because STA will change the CC registers.
So other idea:

Code: Select all

1010 DATA B6,50,00		' LDA $5000
1020 DATA 8B,01			' ADDA 1
1030 DATA 36,01			' PSHU CC TO U STACK
1040 DATA FF,50,01		' STU $5002 ' SAVE CC FROM U TO M
1050 DATA B7,50,00		' STA $5000
1060 DATA 27,01			' PULU CC FROM U STACK
But it seems that i won't get the right CC values in all variants :|

And next question: How apply bitmask operations in BASIC? To get from the HEX value the each flag?
... 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 »

The CC register is 8-bit. The correct code should be as follows.

Code: Select all

TFR CC,A
STA $5002

Code: Select all

LDA $5000 ' Load A from Memory
ADDA #1   ' A=A+1
STA $5000 ' Store A to Memory
TFR CC,B  ' Transfer value of CC to B register
STD $5002 ' Store D (A+B register = D register) to Memory 
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 »

zephyr wrote:The CC register is 8-bit.
:oops:

Thanks!
... 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 »

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?
... 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 »

Have now add a unittest in DragonPy with similar machine code and it seems that it works right: https://github.com/jedie/DragonPy/commi ... a04fcd4ace

I should test it on a real machine ;)
... 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