Jump to content
wallaby

Arguments not working for stack or bit assignment

Recommended Posts

Is there any trick to setting the stack location to a variable?

 

stack 255 <- works

 

a = 255

stack a <- compiles but doesn't work

 

Same problem with setting bits.

 

if temp1{0} then goto __Somewhere <-- works

 

temp2 = 0

if temp1{temp2} then goto __Somewhere <-- compiles but doesn't work

 

The compiling but not working situation is throwing every time it happens. It seems logical, especially the stack where there are no byte size differences.

 

If I have to do them implicitly, I have to write a ton more code, not to mention use more variables.

Share this post


Link to post
Share on other sites

Speaking of temporary variables, have you looked at this:

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#temp_variables

 

 

And about the DPC+ stack, are you using push and pull:

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#dpc_stack

Share this post


Link to post
Share on other sites

Yep, the stack works fine if you set it to a specific value like 255, or 0, or whatever. But if you set it to a variable, it compiles, but doesn't work. I'll double check that the next problem wasn't masking the stack working.

 

If you check the bit at, for example, a{0} it will work.

But if you set the second part to a variable a{b} it compiles but doesn't appear to work.

Share this post


Link to post
Share on other sites

If you check the bit at, for example, a{0} it will work.

But if you set the second part to a variable a{b} it compiles but doesn't appear to work.

You were using temp1 and temp2 in your post and they are the first temporary variables to be used by bB for other things, so you can't trust them to hold a value for very long. Less trustworthy than temp5 and temp6.

 

For any new bB users reading this, temporary variables are obliterated when drawscreen is called, so they can only be used for quick, temporary jobs. As it says on the bB page, temp variables are generally safest to use in reverse order. That means temp6 is safer than temp5, and temp5 is safer than temp4, etc.

Share this post


Link to post
Share on other sites

Yes, I don't think it's a temporary variable problem. I never use them for longer than a few lines and never persist them across a frame.

Share this post


Link to post
Share on other sites

EDIT: Actually, no. That doesn't work either.

 

You can't assign a stack location with a variable. And you can't assign a bit location with a variable either.

 

Sometimes it looks like it works, but it doesn't. Maybe the bit order is different or something? I'm testing this in the middle of my main application, so it's a bit a of a bear to test it. I can make a simple test program to demonstrate if this is a bug and not the intended functionality. I don't know how bB works under the hood to understand what is happening between "stack 255" and "stack my_variable"

Edited by wallaby

Share this post


Link to post
Share on other sites

EDIT: Actually, no. That doesn't work either.

 

You can't assign a stack location with a variable. And you can't assign a bit location with a variable either.

 

Sometimes it looks like it works, but it doesn't. Maybe the bit order is different or something? I'm testing this in the middle of my main application, so it's a bit a of a bear to test it. I can make a simple test program to demonstrate if this is a bug and not the intended functionality. I don't know how bB works under the hood to understand what is happening between "stack 255" and "stack my_variable"

I haven't used the DPC+ stack, but it should look something like this if you want to save and retrieve the value in the variable a:


   stack 200

   push a



   stack 199

   pull a


Share this post


Link to post
Share on other sites

Right, what I'm talking about is setting the stack location with a variable. To use your example:

stack my_variable

push a

stack my_variable - 1

pull a

Share this post


Link to post
Share on other sites

Oh, now I get it. Yeah, you have to use a number according to whoever typed up the stack info.

 

And about bit operations, yeah, that also requires a number from what I've seen on the bB page.

Share this post


Link to post
Share on other sites

I don't know about the stack

 

 

 

This compiles and (at least in this case) seems to produce the correct code

 
 def testbit = callmacro tb
 
 data bits
  %00000001, %00000010, %00000100, %00001000, %00010000, %00100000, %01000000, %10000000 
end
 
 macro tb
  temp1 = bits[{2}] & {1}
end
 
 testbit f v : if temp1 then b=0

v selects the bit in f

 

not that you need to use def and a macro

they might make it easier to revamp existing code

(I just think it makes prettier code ;) )

Edited by bogax

Share this post


Link to post
Share on other sites

as to the stack

 

it looks like this might work

  def stackv = callmacro _stk
 
  macro _stk
  asm
  clc
  lda {1}
  adc #<STACKbegin
  sta DF7LOW
  lda #$00
  adc #>STACKbegin
  and #$0F
  sta DF7HI
end
end
 
 
 
 stackv a

edit: oops goofed it hopefully fixed now

Edited by bogax

Share this post


Link to post
Share on other sites

I'll try it out!

 

I want to use the stack to store as much information as I can, but not being able to change the stack location dynamically was making it impossible. If I can use the stack location variable as a pointer I can use them effectively like 256 more variables.

 

EDIT: Looks like it's working! I'm going to put it through its paces right now. This greatly improves the utility of the stack in bB, thanks!

Edited by wallaby

Share this post


Link to post
Share on other sites

just for completeness here I've included macros to set and clear bits

 

 

 
 def testbit = callmacro tb
 
 def setbit = callmacro sb
 
 def clearbit = callmacro cb
 
 
 macro tb
  temp1 = bits[{2}] & {1}
end
 
 macro cb
  {1} = (bits[{2}] ^ $FF) & {1}
end
 
 macro sb
  {1} = bits[{2}] | {1}
end
 

Share this post


Link to post
Share on other sites

I'll try it out!

 

I want to use the stack to store as much information as I can, but not being able to change the stack location dynamically was making it impossible. If I can use the stack location variable as a pointer I can use them effectively like 256 more variables.

 

EDIT: Looks like it's working! I'm going to put it through its paces right now. This greatly improves the utility of the stack in bB, thanks!

 

Since you have it working, if you get a chance, can you make a small example program using that so I can adapt it for the bB page? You could use the template on the bB page to save some time:

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#dpc_harmony

Share this post


Link to post
Share on other sites

Yes, I'll make a small one.

 

Does the stack consume processor cycles? I wonder how practical it is to use for active variables. Moving the stack location, and push and pulling often, for example.

  • Like 1

Share this post


Link to post
Share on other sites

Yes, I'll make a small one.

 

Does the stack consume processor cycles? I wonder how practical it is to use for active variables. Moving the stack location, and push and pulling often, for example.

 

Maybe a DPC+ master will have something to say about it.

Share this post


Link to post
Share on other sites

And the answer is...

 

 

I like my BASIC like I like my women!

 

FLAT!!

 

 

(not STACKED..get it?)

 

HA, HAAAAA..

 

 

 

Don't use stacks unless you really, really mean it.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...