Jump to content
Sign in to follow this  
Gemintronic

Can't get inline asm to work..

Recommended Posts

SeaGtGruff tried to explain how different assembly kernels can be use via gosub and inline asm code. As an experiment I tried to gosub an asm example on Random Terrains web-site and it will not go. What is poor, confused TheLoon doing wrong?

 

 

 rem Compiler options

set smartbranching on
set kernel_options no_blank_lines

rem Declare constants

playfield:
................................
.XXX..XX..X..X.XX..X.X.XXX.X..X.
.X..X.X.X.X..X.X.X.XX..X...XX.X.
.X..X.XX..X..X.X.X.X.X.XX..X.XX.
.XXXX.X.X..XX..X.X.X.X.XXX.X..X.
................................
...XXX...XX...XX..XXX..XXX.XX...
...X..X.X..X.X..X.X..X.X...X.X..
...XXX..X..X.X..X.XXX..XX..XX...
...X.....XX...XX..X....XXX.X.X..
................................
end

draw_title

drawscreen
if joy0fire then gosub pfclear
goto draw_title

pfclear
 asm
 ldx #47
 lda #0
playfieldclear
 sta
 playfield,x
 dex
 bne playfieldclear
end
return

Share this post


Link to post
Share on other sites

It worked! Random Terrain might and to update his awesome pages. Batari to the rescue!!

 

I have to say, I get the feeling that one of the original intentions of Batari BASIC was to ease people into assembly. My initial reaction is that, if BASIC is a better, more understandable tool then assembly is unnecessary.

 

My new view is that assembly doesn't always have to be incomprehensible or incompatible with BASIC. Batari and people making mini kernels like RevEng are slowly broadening my horizons on the subject.

Share this post


Link to post
Share on other sites

I have to say, I get the feeling that one of the original intentions of Batari BASIC was to ease people into assembly.

You are exactly right. If you read the README.txt file that came with the first release of batari Basic (version 0.1), it started out as follows:

 

Atari 2600 BASIC Compiler   By Fred Quimby
__________________________________________

First and foremost: Why did I do this?

Answer: Atari 2600 BASIC is intended as a beginner's platform so that one may become accustomed to the intricacies of the system.  Although Atari 2600 BASIC is a viable development platform on its own, its real purpose is as a stepping stone toward 2600 programming using assembly language.

(Yes, I still have versions 0.1, 0.2, 0.3, 0.35, and 0.99 of batari Basic archived on my computer, as well as various in-between versions from 0.99 to 1.0. And yes, at first Fred called it "Atari 2600 BASIC," before everybody convinced him to call it "batari Basic.")

 

Michael

Share this post


Link to post
Share on other sites

draw_title

drawscreen
if joy0fire then gosub pfclear
goto draw_title

pfclear
 asm
 ldx #47
 lda #0
playfieldclear
 sta
 playfield,x
 dex
 bne playfieldclear
end
return

Although batari already solved your problem, I want to point out something about mixing inline assembly routines with batari Basic routines.

 

When you compile a batari Basic program, the batari Basic compiler adds a dot in front of each batari Basic line label, but it leaves any line labels between "asm" and "end" unaltered. For example, consider the following:

 

myroutine
  asm
  ; bunch of assembly code here
anotherlabel
  ; some more assembly code here
end
  return

When you compile the program, the "myroutine" label will end up being called ".myroutine" in the compiled assembly listing, but "anotherlabel" will be left as just "anotherlabel" (i.e., without a leading period).

 

This won't affect your "gosub," because you would just type "gosub myroutine," which will be compiled into "jsr .myroutine" (i.e., the dot will be added for you.

 

But if you want an instruction within your inline assembly code to call or jump to a batari Basic line label, you'll need to include the leading dot manually, as in the following example:

 

loop
  drawscreen
  if joy0fire then goto myroutine
  rem * Notice that I changed the "gosub" to a "goto"
  goto loop

myroutine
  asm
  ; bunch of assembly code here
  cpx something
  beq anotherlabel
  ; some more assembly code here
anotherlabel
  ; yet more assembly code here
  dex
  bne .myroutine
  jmp .loop
end

Both "loop" and "myroutine" are line labels in the batari Basic code. When the batari Basic compiler compiles the batari Basic code into its equivalent assembly code, "loop" will be changed to ".loop," "goto loop" will be changed to "jmp .loop," "myroutine" will be changed to ".myroutine," and "goto myroutine" will be changed to "jmp .myroutine."

 

On the other hand, "anotherlabel" is inside the inline assembly code, so it will be left as "anotherlabel."

 

Therefore, if you want to branch or "jmp" or "jsr" to either "loop" or "myroutine" from within your inline assembly code, you need to reference them as ".loop" and ".myroutine," as shown above.

 

But if you want to branch or "jmp" or "jsr" to "anotherlabel" from within your inline assembly code, you need to reference it as just "anotherlabel," as shown above.

 

Michael

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...