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 »

Ok, then we have ALLDREAM, DOSDREAM, Encoder 09 and Dasm... Which is the best for starting?
... 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:Ok, then we have ALLDREAM, DOSDREAM, Encoder 09 and Dasm... Which is the best for starting?
I suggest you try them all, and use the one that you prefer.
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, i must evaluate all :?

Here a hand made test code, that doesn't output the expected value:

Code: Select all

10 ' MACHINE CODE LOADER
20 READ LA  ' LA = LOAD ADDRESS (START OF PROGRAM)
30 READ EA  ' EA = ADDRESS OF FIRST INSTRUCTION
40 PA = EA  'TO BE EXECUTED
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 ADDRESS
90 GOTO 50
100 PRINT "AUTORUN WITH EXEC";EA;":"
105 PRINT "-------------------------------"
110 EXEC EA ' AUTORUN
114 PRINT
115 PRINT "-------------------------------"
120 PRINT "END ADDRESS:"; PA-1
130 PRINT "RUN AGAIN WITH EXEC";EA
149 ' LOAD ADDRESS:
150 DATA 20001
159 ' EXECUTE ADDRESS:
160 DATA 20001
165 ' MACHINE CODE IN HEX
170 DATA 34,12      ' PSHS A,X       ; Save registers A, X
180 ' TEST CODE START
190 DATA 0x86, 0x12 ' LDA $12
200 DATA 0xC6, 0x34 ' LDB $34
210 DATA 0xB7, 0x06, 0x00 ' STA 0x0600 (extended) ($0600-1dff = Available graphics pages w/o DOS)
220 DATA 0xF7, 0x06, 0x01 ' STB 0x0601 (extended)
230 DATA 0xFC, 0x06, 0x00 ' LDD 0x0600 (extended)
240 ' TEST CODE END
1000 DATA BD,95,7A   ' JSR 38266      ; outputs the decimal value of D register
1010 DATA 35,92      ' PULS A,X,PC    ; Restore and return
1020 DATA END
The test assembler code is:

Code: Select all

LDA $12
LDB $34
STA 0x0600
STB 0x0601
LDD 0x0600
I expected that the code makes this:
set A = $12 and B = $34
store A & B to $0600, so that 12 34 will be stored
load $0600 -> D will be set to $1234
Display D -> 4660 (dez == $1234)

I have expected that 4660 will be output by JSR 38266 but it will output noting :(

btw. exists there a way to display the hex code instead of decimal value ?
Can i display the hex code of A or B registers or only from D ?
... 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
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 »

jedie wrote:btw. exists there a way to display the hex code instead of decimal value ?
Can i display the hex code of A or B registers or only from D ?
I explained this to you a few pages back :roll:

EDIT: Sorry, I explained A/B decimal output, not hex. See the M/L monitor example in Inside the Dragon for such routines.
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Howto try small machine code programs in BASIC ?

Post by zephyr »

Just tried your test code with Encoder 09 and it works perfectly (as I expected).

Code: Select all

EXEC
4660
OK
LIST
10         ORG     $5000
20         LDA     #$12
30         LDB     #$34
40         STA     $0600
50         STB     $0601
60         LDD     $0600
70         JSR     38266
80         RTS


5000 8612     LDA   #$12
5002 C634     LDB   #$34
5004 B70600   STA   $0600
5007 F70601   STB   $0601
500A FC0600   LDD   $0600
500D BD957A   JSR   $957A
5010 39       RTS

Code: Select all

OK
EXEC
4660
OK
LIST
10         ORG     $5000
20         LDD     #$1234
30         STD     $0600
40         JSR     $957A
50         RTS
OK


5000 CC1234   LDD   #$1234
5003 FD0600   STD   $0600
5006 BD957A   JSR   $957A
5009 39       RTS
Alastair
Posts: 669
Joined: Fri Jul 18, 2008 11:33 pm

Re: Howto try small machine code programs in BASIC ?

Post by Alastair »

Code: Select all

LDA #$12
LDB #$34
STA $600
STB $601
LDD $600
JSR 38266
Works in DASM too.
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: btw. exists there a way to display the hex code instead of decimal value ?
Look here.
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:
jedie wrote: btw. exists there a way to display the hex code instead of decimal value ?
Look here.
Thanks!

Other idea beside this: save the value to display into memory and peek it from memory in BASIC and convert/ print it...

In my example i use $0600 is it a good location?
... 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 cleanup the test programm a little bit:

Code: Select all

10 ' MACHINE CODE LOADER
20 READ LA					' 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 "END ADDRESS IS: $"; HEX$(PA-1)
110 PRINT
120 PRINT "AUTORUN WITH 'EXEC &H"; HEX$(LA) ;"'"
130 PRINT "-------------------------------"
140 EXEC LA					' AUTORUN
150 PRINT
160 PRINT "-------------------------------"
170 PRINT "RUN AGAIN WITH 'EXEC &H"; HEX$(LA) ;"'"
180 ' LOAD AND EXECUTE ADDRESS:
190 DATA &H4000
200 ' MACHINE CODE IN HEX
210 DATA CC,12,34		' LDD $1234		; $5858 == 22616
220 DATA BD,95,7A		' JSR 38266		; OUTPUT D REGISTER
230 DATA 39			' RTS
1000 DATA END
... 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 i have a test code for SUBA:

Code: Select all

10 SA=&H5000				' VALUE STORAGE ADDRESS
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 POKE SA,5 ' SET START VALUE
130 PRINT "START VALUE FROM $";HEX$(SA);": $";HEX$(PEEK(SA))
150 EXEC LA
160 PRINT "VALUE FROM $";HEX$(SA);": $";HEX$(PEEK(SA))
200 PRINT "ANY KEY FOR LOOP OR 'Q' FOR QUIT"
210 A$=INKEY$:IF A$="" THEN 210
220 IF A$<>"Q" THEN GOTO 150
1000 ' MACHINE CODE IN HEX
1030 DATA B6,50,00		' LDA $5000
1040 DATA 80,01			' SUBA 1
1050 DATA B7,50,00		' STA $5000
1060 DATA 39			' RTS
10000 DATA END
Now i will see, how to display the CC registers.

EDIT: Hm. There is no way to store or get the CC value, isn't it?

EDIT2: Maybe it can do this: Save CC on stack and PEEK it from there???
... 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