Page 4 of 6

Re: Howto try small machine code programs in BASIC ?

Posted: Fri Oct 04, 2013 9:24 pm
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.

Re: Howto try small machine code programs in BASIC ?

Posted: Sat Oct 05, 2013 10:01 am
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...

Re: Howto try small machine code programs in BASIC ?

Posted: Sat Oct 05, 2013 12:31 pm
by admin
I'll keep my eye out for a copy - I can't let mine go - its signed by Duncan Smeed himself !

Re: Howto try small machine code programs in BASIC ?

Posted: Sat Oct 05, 2013 1:26 pm
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.

Re: Howto try small machine code programs in BASIC ?

Posted: Sat Oct 05, 2013 2:36 pm
by jedie
I get it for 21€ ;)

Re: Howto try small machine code programs in BASIC ?

Posted: Tue Oct 08, 2013 3:15 pm
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?

Re: Howto try small machine code programs in BASIC ?

Posted: Tue Oct 08, 2013 5:33 pm
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 

Re: Howto try small machine code programs in BASIC ?

Posted: Tue Oct 08, 2013 6:48 pm
by jedie
zephyr wrote:The CC register is 8-bit.
:oops:

Thanks!

Re: Howto try small machine code programs in BASIC ?

Posted: Tue Oct 08, 2013 7:35 pm
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?

Re: Howto try small machine code programs in BASIC ?

Posted: Wed Oct 09, 2013 5:07 pm
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 ;)