Jump to content
IGNORED

Macros


SeaGtGruff

Recommended Posts

It's fine by me, though it should probably be replaced by my first suggestion (that didn't work) if the power-of-two thing is fixed.

 

I'll report it in the bug thread later today.

 

You might also want to make a note on your bB page that you can't use any commands that use a library inside a macro, within a bankswitched game. (pf* commands, multiplying by numbers that aren't powers of two, etc.)

  • Like 1
Link to comment
Share on other sites

You might also want to make a note on your bB page that you can't use any commands that use a library inside a macro, within a bankswitched game. (pf* commands, multiplying by numbers that aren't powers of two, etc.)

OK, thanks. I'll do that later this afternoon when I get back. Sure is nice to get this fixed so quickly. Now I can get back to working on my program. :thumbsup:

Link to comment
Share on other sites

I'm getting lost.

 

Here's an excerpt of the code from:

 

http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#nybblemethis

 

 

  rem  ****************************************************************
  rem  *  Reusable macros for nybble variables. 
  rem  *

  macro set_lo_nibble
  {1}={1}&$F0
  {1}={1}|({2}&$0F)
end

  macro set_hi_nibble
asm
  lda {1}
  and #$0f
  sta {1}
  lda {2}
  asl
  asl
  asl
  asl
  ora {1}
  sta {1}
end
end


  rem  ****************************************************************
  rem  *  One variable is split into two thanks to 
  rem  *  macro and def.
  rem  *

  def PEEK_Game_Level=a&$0F
  def POKE_Game_Level=callmacro set_lo_nibble a

  def PEEK_Hit_Points=a/16
  def POKE_Hit_Points=callmacro set_hi_nibble a

 

That looks to me like set_lo_nibble and set_hi_nibble both want

two parameters and are both only being passed one,

am I missing something?

 

 

If you use exclusive or to swap in nibbles

you'll only get the bit's you mask for,

So I'd (re)write RevEng's code like this:

 

  macro set_hi_nibble
asm
  lda {2}
  asl
  asl
  asl
  asl
  eor {1}
  and #$F0
  eor {1}
  sta {1}
end
end

 

It might even be possible to write something that

swapped different nibbles depending on a parameter

(I haven't tryed, didn't seem worth it)

 

 

I haven't figured out when and where bBasic will choke

on complex expressions.

If bBasic fails to recognize powers of 2 greaer than 3,

would something like this work (again using an xor swap)

 

(1)=(2)*4*4^(1)&$F0^(1)

 

(I don't know how many parentheses you'd have to stick in

there to get the order of execution right or if that would

make bBasic choke)

Edited by bogax
Link to comment
Share on other sites

I'm getting lost.

If you just want to use the nybble variables, you don't need to know the details.

 

Here's a simple example that just gives a nybble variable the value of five:

 

POKE_My_Variable 5

 

 

Here's an example that increases it by one:

 

temp5 = (PEEK_My_Variable) + 1 : POKE_My_Variable temp5

 

 

POKE and PEEK is all you have to know.

Edited by Random Terrain
Link to comment
Share on other sites

 

Here's a simple example that just gives a nybble variable the value of five:

 

POKE_My_Variable 5

 

Oh, OK, I get it

 

def is a simple substitution so that that expands to something like:

 

callmacro set_lo_nibble a 5

 

The def statement supplies the first parameter and you supply the

second where you invoke the def'd name.

Link to comment
Share on other sites

Finally installed bB :P

 

macro set_hi_nibble
{1}=(({2}*4*4^{1})&$F0)^{1}
end

 

Compiles just as one would hope

 

.L00 ;  macro set_hi_nibble

MAC set_hi_nibble

.L01 ;  {1} =  (  ( {2} * 4 * 4 ^ {1} )  & $F0 )  ^ {1}

; complex statement detected
LDA {2}
asl
asl
asl
asl
EOR {1}
AND #$F0
EOR {1}
STA {1}
ENDM

Link to comment
Share on other sites

  macro set_hi_nibble
  {1}=(({2}*4*4^{1})&$F0)^{1}
end

Holy crap, that's awesome! So the new-and-improved macros and defs would look like this:

 

  macro set_lo_nibble
  {1}=(({2}^{1})&$0F)^{1}
end

  macro set_hi_nibble
  {1}=(({2}*4*4^{1})&$F0)^{1}
end

  def PEEK_game_level=a&$0F
  def POKE_game_level=callmacro set_lo_nibble a

  def PEEK_hit_points=a/4/4
  def POKE_hit_points=callmacro set_hi_nibble a

No need to include div_mul.asm, and it automatically keeps the POKEs within the legal values of 0 to 15! icon_lust.gif

 

Thanks, bogax! icon_thumbsup.gif

 

RT, you'd better update your page! icon_mrgreen.gif

 

Michael

 

 

 

Link to comment
Share on other sites

Here's a slight revision to the defs that use dims for the variable names-- in case it's easier than remembering which letters to use:

 

  macro set_lo_nibble
  {1}=(({2}^{1})&$0F)^{1}
end

  macro set_hi_nibble
  {1}=(({2}*4*4^{1})&$F0)^{1}
end

  dim game_level=a
  dim hit_points=a
  dim moose_tracks=b
  dim rabbit_ears=b
  dim saucer_speed=c
  dim something_else=c

  def PEEK_game_level=game_level&$0F
  def POKE_game_level=callmacro set_lo_nibble game_level

  def PEEK_hit_points=hit_points/4/4
  def POKE_hit_points=callmacro set_hi_nibble hit_points

  def PEEK_moose_tracks=moose_tracks&$0F
  def POKE_moose_tracks=callmacro set_lo_nibble moose_tracks

  def PEEK_rabbit_ears=rabbit_ears/4/4
  def POKE_rabbit_ears=callmacro set_hi_nibble rabbit_ears

  def PEEK_saucer_speed=saucer_speed&$0F
  def POKE_saucer_speed=callmacro set_lo_nibble saucer_speed

  def PEEK_something_else=something_else/4/4
  def POKE_something_else=callmacro set_hi_nibble something_else

Of course, you still need to remember whether a given nibble variable uses the lo nibble or the hi nibble, and use the correct defs for that type of nibble variable.

 

For a lo nibble variable:

 

dim lonibblevariable=x

def PEEK_lonibblevariable=lonibblevariable&$0F

def POKE_lonibblevariable=callmacro set_lo_nibble lonibblevariable

 

For a hi nibble variable:

 

dim hinibblevariable=y

def PEEK_hinibblevariable=hinibblevariable/4/4

def POKE_hinibblevariable=callmacro set_hi_nibble hinibblevariable

 

Michael

Edited by SeaGtGruff
Link to comment
Share on other sites

  • 4 years later...

Ok, which is the one to be used to call the variable "a" on the code in this example

 

def PEEK_Game_Level=a&$0F

def POKE_Game_Level=callmacro set_lo_nibble a

 

Peek or poke?

Or can I call directly _Game_Level on the code?

Edited by STGraves
  • Like 1
Link to comment
Share on other sites

  • 7 years later...

Edit: I was wrong, please disregard what I asked before this edit. 

 

So from what I gather, PEEK is the "read" and POKE is the "write", is that correct?

 

Example: If I want to split the m variable in 2, calling one _M0 and the other _M1, would I read it as:

 

  if PEEK_M1 = 10 then goto __Label

 

And write it as

 

  POKE_M1 10

 

Without the use of the = sign? Is this correct? So far in testing it all seems to work. 

Edited by freshbrood
Variables are rolling over from 0 to 15
Link to comment
Share on other sites

I started BASIC programming after systems that used PEEK and POKE heavily.  So, the terminology is awkward for me brains.

 

You might think about re-naming your defines to keep things straight in your head.


 

 def read_mapx=mapxy&$0F
 def write_mapx=callmacro _Set_Lo_Nibble mapxy

 def read_mapy=mapxy/4/4
 def write_mapy=callmacro _Set_Hi_Nibble mapxy

 

  • Thanks 1
Link to comment
Share on other sites

Gem I appreciate your responses but a more direct answer would help me better. I get confused easily myself. 

 

(Yes, that's pretty much how they work/no, not exactly etc..) I'm assuming it's yes then, I understand it correctly. 

 

(Also still trying to get an answer on if x is dedicated to use in MASE)

 

As a non coder-coder I actually appreciate using the proper terms as they may help me learn other "proper" languages. 

 

Thanks again. 

 

Edited by freshbrood
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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