+Random Terrain Posted September 27, 2010 Share Posted September 27, 2010 Short term workaround... macro set_hi_nibble asm lda {1} and #$0f sta {1} lda {2} asl asl asl asl ora {1} sta {1} end end It works! If it's OK with you and SeaGtGruff, I'll use this on the bB page instead of the other thing. Quote Link to comment Share on other sites More sharing options...
RevEng Posted September 27, 2010 Share Posted September 27, 2010 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.) 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
bogax Posted September 27, 2010 Share Posted September 27, 2010 (edited) 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 September 27, 2010 by bogax Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 27, 2010 Share Posted September 27, 2010 (edited) 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 September 27, 2010 by Random Terrain Quote Link to comment Share on other sites More sharing options...
bogax Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment Share on other sites More sharing options...
bogax Posted September 28, 2010 Share Posted September 28, 2010 Finally installed bB 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 Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted September 28, 2010 Author Share Posted September 28, 2010 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! Thanks, bogax! RT, you'd better update your page! Michael Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted September 28, 2010 Author Share Posted September 28, 2010 (edited) 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 September 28, 2010 by SeaGtGruff Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 28, 2010 Share Posted September 28, 2010 See if this looks OK: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#nybblemacrodef Thanks. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted September 29, 2010 Author Share Posted September 29, 2010 See if this looks OK: I didn't scrutinize it in slow motion with a magnifying glass, but it looked okay when I gave it a quick read. Michael 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted September 29, 2010 Share Posted September 29, 2010 See if this looks OK: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#nybblemacrodef Thanks. It might be worth pointing out that there's a reason for using eg *4*4 instead of *16 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 30, 2010 Share Posted September 30, 2010 It might be worth pointing out that there's a reasonfor using eg *4*4 instead of *16 Thanks. It's because 4 looks like a pretty sail on a sailboat, right? Quote Link to comment Share on other sites More sharing options...
STGraves Posted May 28, 2015 Share Posted May 28, 2015 (edited) 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 May 28, 2015 by STGraves 1 Quote Link to comment Share on other sites More sharing options...
freshbrood Posted April 2 Share Posted April 2 (edited) 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 April 2 by freshbrood Variables are rolling over from 0 to 15 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted April 3 Share Posted April 3 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 1 Quote Link to comment Share on other sites More sharing options...
freshbrood Posted April 3 Share Posted April 3 (edited) 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 April 3 by freshbrood Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.