Jump to content

Photo

Arguments not working for stack or bit assignment


16 replies to this topic

#1 wallaby OFFLINE  

wallaby

    Chopper Commander

  • 100 posts

Posted Sun Sep 4, 2016 11:33 PM

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.



#2 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,180 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Mon Sep 5, 2016 12:08 AM

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



#3 wallaby OFFLINE  

wallaby

    Chopper Commander

  • Topic Starter
  • 100 posts

Posted Mon Sep 5, 2016 12:16 AM

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.



#4 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,180 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Mon Sep 5, 2016 12:29 AM

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.



#5 wallaby OFFLINE  

wallaby

    Chopper Commander

  • Topic Starter
  • 100 posts

Posted Mon Sep 5, 2016 1:00 AM

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.



#6 wallaby OFFLINE  

wallaby

    Chopper Commander

  • Topic Starter
  • 100 posts

Posted Mon Sep 5, 2016 1:15 AM

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, Mon Sep 5, 2016 1:24 AM.


#7 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,180 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Mon Sep 5, 2016 1:43 AM

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

 



#8 wallaby OFFLINE  

wallaby

    Chopper Commander

  • Topic Starter
  • 100 posts

Posted Mon Sep 5, 2016 3:08 AM

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


#9 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,180 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Mon Sep 5, 2016 3:20 AM

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.

#10 bogax OFFLINE  

bogax

    Dragonstomper

  • 710 posts

Posted Mon Sep 5, 2016 11:28 AM

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, Mon Sep 5, 2016 11:32 AM.


#11 bogax OFFLINE  

bogax

    Dragonstomper

  • 710 posts

Posted Mon Sep 5, 2016 11:53 AM

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, Mon Sep 5, 2016 12:16 PM.


#12 wallaby OFFLINE  

wallaby

    Chopper Commander

  • Topic Starter
  • 100 posts

Posted Mon Sep 5, 2016 5:29 PM

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, Mon Sep 5, 2016 5:34 PM.


#13 bogax OFFLINE  

bogax

    Dragonstomper

  • 710 posts

Posted Mon Sep 5, 2016 7:58 PM

 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
 


#14 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,180 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Mon Sep 5, 2016 10:56 PM

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



#15 wallaby OFFLINE  

wallaby

    Chopper Commander

  • Topic Starter
  • 100 posts

Posted Tue Sep 6, 2016 8:06 PM

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.



#16 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,180 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Sep 6, 2016 9:36 PM

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.



#17 Papa OFFLINE  

Papa

    Dragonstomper

  • 751 posts

Posted Fri Sep 16, 2016 9:15 AM

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.






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users