Howto try small machine code programs in BASIC ?

Hardware Hacking, Programming and Game Solutions/Cheats
Sarah
Posts: 177
Joined: Wed Apr 13, 2011 3:36 pm
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by Sarah »

jedie wrote:But can i print the value (in this case $58 == 88) of accumulator A to screen?
Here are some options:
  • Use a debugger
  • Make a simple routine that outputs the hex value using two ascii characters
  • JSR 38266 outputs the decimal value of D register
Alastair
Posts: 669
Joined: Fri Jul 18, 2008 11:33 pm

Re: Howto try small machine code programs in BASIC ?

Post by Alastair »

The text screen starts at address $400 and ends at address $5FF, so any STA instruction to any address within that range (inclusive) will print the contents A to the screen. Try the following which should output all 256 text mode characters near the middle of the screen, you may omit the delay loop if desired:

Code: Select all

        CLRA
LOOP    STA $4EF        ; Store A at address $4EF
        LDY #$800       ; Delay value, the larger the value the greater the delay
DELAY   LEAY -1,Y       ; Part of the delay loop
        BNE DELAY       ; End of the delay loop
        INCA
        BNE LOOP
Note that the STA ,X+ instruction in the example you gave earlier stores the contents of A to the address value contained in X then increments X. This is used to fill the whole text screen with the contents of A.
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 »

Sarah wrote:Use a debugger
Which one?
... 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 »

tormod wrote:Yes, there is a routine to print the value of D.
Sarah wrote:JSR 38266 outputs the decimal value of D register
I get it:

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 DATA CC,58,58   ' LDD $5858      ; $5858 == 22616
190 DATA BD,95,7A   ' JSR 38266      ; outputs the decimal value of D register
260 DATA 35,92      ' PULS A,X,PC    ; Restore and return
270 DATA END
It display 22616 on screen ;)
... 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
Sarah
Posts: 177
Joined: Wed Apr 13, 2011 3:36 pm
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by Sarah »

Are you doing all your assembly by hand?

You'd surely find it easier to use an assembler like DREAM. It's straightforward to launch (execute) the assembled program within DREAM too. If you have ALLDREAM then it comes with the DREAMBUG debugger built-in, which isn't especially easy to use but can be handy at times.
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 tried ALLDREAM and ", without success. I get always "FULL"

I looked into Dragondata_alldream_manual.pdf and it seems that's very complicated to use, isn't it?

I also tried DskDream for Dragon DOS, but can't LOAD or RUN in XRoar. The emulator hangs.
... 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 »

Coding on the machine, my preferred variant was DOS-Dream (you get DOS, you get an assembler, you don't have to lose any RAM to the assembler, bar your own program text).

Not too complicated, just a little terse as anything that has to fit in such a small space is bound to be.
Sarah
Posts: 177
Joined: Wed Apr 13, 2011 3:36 pm
Contact:

Re: Howto try small machine code programs in BASIC ?

Post by Sarah »

If you're getting FULL when trying to start DREAM then you haven't allocated any/enough memory with CLEAR.

The built-in editor is pretty easy to use IMO; certainly much easier than BASIC. There's not much more you need to know to get started and most of it is on page 27 of the manual. BREAK then A to assemble. BREAK then X to execute or BREAK Q to go back to editing.

If you're assembling by hand you'll surely find the complexity too much trouble before long! ;)
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 »

sixxie wrote:Not too complicated, just a little terse as anything that has to fit in such a small space is bound to be.
Good idea!
... 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:I have tried ALLDREAM and ", without success. I get always "FULL"

I looked into Dragondata_alldream_manual.pdf and it seems that's very complicated to use, isn't it?
There are other assemblers available for the Dragon.

Encoder 09
viewtopic.php?f=7&t=286

Dasm
viewtopic.php?f=7&t=287

viewtopic.php?f=4&t=285&hilit=dasm&start=10#p1799
Post Reply