Author Topic: Get first/second byte of r-variable easily  (Read 5486 times)

0 Members and 1 Guest are viewing this topic.

Offline defmenge

  • LV3 Member (Next: 100)
  • ***
  • Posts: 40
  • Rating: +5/-0
    • View Profile
Get first/second byte of r-variable easily
« on: June 16, 2011, 10:31:34 am »
I know this is a quite noobish question, but is there an easy way to access the first/last 8 bits of a parameter passed to a subroutine without using {°r2} and {°r2+1}? The reason I need this is that I use 2-byte-variables for position data in my DROD8x project, 1st byte is for X, 2nd is for Y, and using {°r2} and {°r2+1} (with both r2 and r3) several times in a line gets pretty confusing as the project's complexity increases. I'm pretty sure that people had to be able to do this somehow before "°" was introduced to Axe, and it doesn't look like the most optimized way of accessing the bytes.

Thanks in advance,
Defmenge.
Spoiler For DROD8x:
Status: Pre-Alpha "ROACHIE" - Progress: 20%
[=====] Graphics: 100% (full greyscale tileset)
[==== ] Tilemapping: 80% (maps load successfully, additional tile data not implemented yet)
[=    ] Storage formats: 20% (planned: segmentable holds, composed of levels, made of up to [presumably] 8x8 rooms)
[==   ] Monsters: 40% (roaches and roach queen AI working; planned: eyes, wubbas, golems and possibly more)
[     ] Gameplay Elements: 0% (walls and floors only)
[     ] GUI: 0% (very bare in-game GUI)
[=    ] Editor: 20% (integrated basic editor)
Project is currently on hold due to lots of homework and tests.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Get first/second byte of r-variable easily
« Reply #1 on: June 16, 2011, 10:34:56 am »
I answer with some code:
Code: [Select]
r1 → {L1}^r (radians r)
Now the first byte is stored in {L1} and the second in {L1+1}

Correct me if I'm wrong.

I'm not a nerd but I pretend:

Offline defmenge

  • LV3 Member (Next: 100)
  • ***
  • Posts: 40
  • Rating: +5/-0
    • View Profile
Re: Get first/second byte of r-variable easily
« Reply #2 on: June 16, 2011, 10:44:15 am »
Thank you for the fast reply.

So I guess there is no built-in command for easily accessing the bytes then; the reason I asked this question was that I thought there would be some weird undocumented command for easily doing that, like "{r1r}", or something similar. Actually, my code for the roach AI (which did not work right) became so complicated that I had no other choice but to rewrite it from scratch. Now I'm using the method you described, which does seem to make it easier to read and edit the code, thanks. :)
« Last Edit: June 16, 2011, 10:44:42 am by defmenge »
Spoiler For DROD8x:
Status: Pre-Alpha "ROACHIE" - Progress: 20%
[=====] Graphics: 100% (full greyscale tileset)
[==== ] Tilemapping: 80% (maps load successfully, additional tile data not implemented yet)
[=    ] Storage formats: 20% (planned: segmentable holds, composed of levels, made of up to [presumably] 8x8 rooms)
[==   ] Monsters: 40% (roaches and roach queen AI working; planned: eyes, wubbas, golems and possibly more)
[     ] Gameplay Elements: 0% (walls and floors only)
[     ] GUI: 0% (very bare in-game GUI)
[=    ] Editor: 20% (integrated basic editor)
Project is currently on hold due to lots of homework and tests.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Get first/second byte of r-variable easily
« Reply #3 on: June 16, 2011, 10:45:28 am »
to avoid confusion at your side in the future: all commands are documented.
Also, have you introduced yourself?
« Last Edit: June 16, 2011, 10:45:52 am by aeTIos »
I'm not a nerd but I pretend:

Ashbad

  • Guest
Re: Get first/second byte of r-variable easily
« Reply #4 on: June 16, 2011, 10:46:23 am »
I answer with some code:
Code: [Select]
r1 → {L1}^r (radians r)
Now the first byte is stored in {L1} and the second in {L1+1}

Correct me if I'm wrong.



Right, but make sure you remember that one radian denoted little endian, to do big endian you would denote two radians.

Offline defmenge

  • LV3 Member (Next: 100)
  • ***
  • Posts: 40
  • Rating: +5/-0
    • View Profile
Re: Get first/second byte of r-variable easily
« Reply #5 on: June 16, 2011, 10:52:42 am »
to avoid confusion at your side in the future: all commands are documented.
Also, have you introduced yourself?

You're probably right about the commands, but I've seen some undocumented functions, such as "sub(" returning a value to the caller of the function. The Axe manual/reference only covers the fact that you can call a subroutine with it, but not that (and how) it can return something.
And I haven't really introduced myself because I have no idea what to write about myself ^^'.
Spoiler For DROD8x:
Status: Pre-Alpha "ROACHIE" - Progress: 20%
[=====] Graphics: 100% (full greyscale tileset)
[==== ] Tilemapping: 80% (maps load successfully, additional tile data not implemented yet)
[=    ] Storage formats: 20% (planned: segmentable holds, composed of levels, made of up to [presumably] 8x8 rooms)
[==   ] Monsters: 40% (roaches and roach queen AI working; planned: eyes, wubbas, golems and possibly more)
[     ] Gameplay Elements: 0% (walls and floors only)
[     ] GUI: 0% (very bare in-game GUI)
[=    ] Editor: 20% (integrated basic editor)
Project is currently on hold due to lots of homework and tests.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: Get first/second byte of r-variable easily
« Reply #6 on: June 16, 2011, 11:18:26 am »
It is strongly discouraged that you not use these undocumented features for the fact that they most likely change. 
The value it is "returning" is just whatever was left in register HL at the time.  Since it is an undocumented (and most likely unintentional) feature, further optimizations to the routines may use HL differently. 
ld a, 0
ld a, a

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Get first/second byte of r-variable easily
« Reply #7 on: June 16, 2011, 11:48:16 am »
It is strongly discouraged that you not use these undocumented features for the fact that they most likely change. 
The value it is "returning" is just whatever was left in register HL at the time.  Since it is an undocumented (and most likely unintentional) feature, further optimizations to the routines may use HL differently. 
That feature is very intentional.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline yrinfish

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 138
  • Rating: +8/-0
  • Zark, I'm not dead
    • View Profile
    • yrinthings
Re: Get first/second byte of r-variable easily
« Reply #8 on: June 16, 2011, 11:52:49 am »
Yes, and not using it would be really #$^%%$ thing to do!!

(I'd have to rewrite all my programs, for example)

And even if it was unintentional, it is too useful to remove!
I need help with Random (x86 Happy), pm me if you want to help :D
LOOK IN MY SPOILER, MY SIG IS UPDATED (almost) EVERY DAY
Spoiler For MiniTale:
No mini competition please, teamwork is better :D
I suggest we do not use "MiniCraft" as the name:
Notch has asked us to not do that.
It will get changed to "MiniTale"
@Hayleia, you don't _have to_ organize :P
THIS POST IS IN MY SIG TOO

Details
Language: Axe
Platform: TI 83+

Things we'll need to do/make
Draw the sprites saintrunner is working on this
A save file format.
A level generator.
A Tilemapper.
Some sort of AI.
Crafting system.

People on it (AFAIK)
annoyingcalc
saintrunner
Hayleia (your avatar is really cool btw)
epic7
Blue Raven
yrinfish

Useful info
For those who are going to work on this
General Program Structure
Spoiler For Spoiler:

:.Sprite Data
:.Other Data
:
:.Main menu
:.Option Start Game->init
:.Option How To Play->help
:.Option About->crdt
:
:.BEGIN init
:.Save file is present?
:.yes->strt
:.no->lgen
:.END init
:
:.BEGIN lgen
:.Make appvar appvMCSAVE
:.create 7 levels
:.edit for sky, mines, deep mines, nether
:.END lgen
:
:.BEGIN strt

~~~~ working on this ~~~~

Tiles
Spoiler For Spoiler:
Wheat
Water
Tree
Stone
Stairs
Sapling
Sand
Rock
Ore
Lava
InfiniteFall
Hole
HardRock
Grass
Flower
Farm
Dirt
Cloud
CloudCactus
Cactus

Biomes
Spoiler For Spoiler:
--Sky
Cloud
--Surface
Forest
Meadow
Plains
Cliffs
Mountain
Desert
Ocean
--Underground
Mines
Deep Mines
Nether

Items
Spoiler For Spoiler:
--Tools
Pick
Axe
Hoe
Shovel
--Weapon
Sword
--Utilities
Pow Glove
Workbench
Furnace
Lantern
Anvil
Oven
Chest
--Resources
Apple
Bread
Cloth
Slime
Wood
Seeds
Wheat
Acorn
Cactus
Flower
Cloud
Dirt
Stone
Sand
Coal
Iron Ore
Gold Ore
Gem
Glass
Iron
Gold
Spoiler For More...:
Spoiler For About me:

No, I didn't lie!!


quotes:HERE

And even more:


[07:53:14] <+Frey> Y'know, when people descend from my heavens , they're never Chuck Norris
[07:53:55] <+Frey> I usually get another catgirl or an angel pops down for a visit
[07:54:06] <+Frey> Some angels are really nice
[07:54:33] <+Frey> Some are into the whole "scare the locals" bit
[07:54:54] <+Frey> And some just absent minded
[07:55:38] * +david_ has nothing to do
[07:55:40] <+Frey> It's the absentminded ones you gotta look out for, because the'yre the ones that forget they're 40ft tall
[07:56:04] <+Frey> They're also the ones that forget about social taboos, like nudity
[07:56:28] <+Frey> Have you ever tryed to explain to an angel...anything?
[07:56:45] <+Frey> They don't listenunless they want to
[07:57:16] <+Frey> And don't learn unless they think they don't know
[07:57:51] <+Frey> Except for the nice ones, they're nice
[07:59:27] <+OmnomIRC> (O)<yrinfish> lol
[07:59:32] <+Frey> And they're all so pretty!
[07:59:38] <+Frey> It's ridiculous
[07:59:44] <+OmnomIRC> (O)<yrinfish> I hate PUSHES, THEY HAUNT ME
[08:00:06] <+Frey> Want an angel to come over and exorcise them?
[08:00:36] <+OmnomIRC> (O)<yrinfish> or, more specific: the fact that sometimes, happy outputs: pushes != pops
[08:00:47] <+OmnomIRC> (O)<yrinfish> I know why
[08:01:01] <+OmnomIRC> (O)<yrinfish> and I can solve it by adding a lookahead
[08:01:10] <+OmnomIRC> (O)<yrinfish> But I don't want to
[08:01:24] <+OmnomIRC> (O)<yrinfish> but continue your story
[08:01:35] <+OmnomIRC> (O)<yrinfish> lol
[08:03:13] <+Frey> Ok, so one day, I was walking to the school bus, and, long story short, got my life saved by an angel
[08:03:27] <+Frey> This one was a scary one
[08:03:42] <+Frey> Same height/age as me
[08:04:14] <+Frey> OMG She was the scariest person I had ever met
[08:04:28] <+Frey> She made the entire football team pee their pants
[08:04:43] <+Frey> I was so glad she was on my side
[08:05:04] <+Frey> Right up until she tryed to enter the bathroom with me
[08:05:37] <+OmnomIRC> (O)<yrinfish> lool
[08:05:45] <+Frey> After a muchness of arguing, I finally got through to her
[08:05:56] <+Patrick-D> is this a rap song?
[08:06:06] <+OmnomIRC> (O)<aeTIos> idk
[08:06:09] <+Frey> She tap danced outside my stall the entire time, though
[08:10:04] <+Frey> She was in all my classes too, which was weird, especially as they were all advanced courses and she joined in the middle of the semester
[08:10:28] <+Frey> Even the teachers were scared of her
[08:10:45] <+Frey> Note that she was gorgeous
[08:12:09] <+Frey> So, this angel and I, we managed to stop the apocalypse
[08:12:48] <+Frey> And she kissed me before going back,
[08:13:08] <+Frey> To heaven, but as it turns out that kiss sealed her to Earth
[08:13:47] <+Frey> We still don't know what to do


lol:

[11:30:53] <DThought> <OmnomIRC> (O)<yrinfish> 2 guests are looking at my topic
[11:30:53] <DThought> <OmnomIRC> (O)<yrinfish> I wonder who they are
[11:30:53] <DThought> <OmnomIRC> (O)<yrinfish> where they live
[11:30:53] <DThought> <OmnomIRC> (O)<yrinfish> how old they are
[11:30:55] <DThought> <OmnomIRC> (O)<yrinfish> What kind of jokes they make
[11:30:57] <DThought> <OmnomIRC> (O)<yrinfish> but it surprises me that theyre looking at my topic
[11:31:01] * DThought smacks yrinfish for stalking
[11:31:08] <yrinfish> lool
[11:31:14] <DThought> Whoa, why'd it include all the newlines?
[11:31:23] * calc84maniac  smacks DThought for talking
[11:31:28] * calc84maniac  runs

Crisps:

<OmnomIRC> (O)* Keoni29  Eating crisps
<OmnomIRC> (O)* yrinfish  asks keoni some
<OmnomIRC> (O)<Keoni29> 7$ shipping please
<OmnomIRC> (O)* yrinfish  gives
<OmnomIRC> (O)<Keoni29> It will arrive in 3 days
<OmnomIRC> (O)<yrinfish> Thank you
<OmnomIRC> (O)* Keoni29  Wonders if he wants some dip
<OmnomIRC> (O)<yrinfish> chili please
<OmnomIRC> (O)<Qwerty.55> Adobe, last time I updated one of your products, the changes broke half of the documents using it.
<OmnomIRC> (O)<Keoni29> :(
<OmnomIRC> (O)<Qwerty.55> Why the hell would I update anything else from you?
<OmnomIRC> (O)* yrinfish  kicks adobe
<OmnomIRC> (O)* yrinfish  runs
<OmnomIRC> (O)* Qwerty.55  runs with him
<OmnomIRC> (O)<Keoni29> I have guacamole :S
<OmnomIRC> (O)<Keoni29> I have guacamole :S
<OmnomIRC> (O)* yrinfish  likes that too
<OmnomIRC> (O)* Keoni29  yay
<OmnomIRC> (O)* yrinfish
<OmnomIRC> (O)<Keoni29> http://www.tinyurl.com/guacamole.jar
<OmnomIRC> (O)<Keoni29> :3
<OmnomIRC> (O)<yrinfish> 404
<OmnomIRC> (O)<yrinfish> no foooooooooooooooooooooooouwaaaaaaaaaaaaaaaaahnd
<OmnomIRC> (O)<Keoni29> <3 no shit
<OmnomIRC> (O)<Keoni29> You cant download jars of guacamole
<OmnomIRC> (O)<Keoni29> I have an idea!
<OmnomIRC> (O)<yrinfish> loool
<yrinfish> that came too late ;)
<OmnomIRC> (O)<Qwerty.55> Actually, I just realized why Adobe's update breaks everything.
<yrinfish> tell me
<yrinfish> again too late
<OmnomIRC> (O)<Keoni29> Buy yourself some :3
<yrinfish> that was to keoni
<yrinfish> lOLoL
<yrinfish> :D
<OmnomIRC> (O)<Qwerty.55> It's a security update and if you can't run anything, you obviously can't get infected by anything in those documents.
<OmnomIRC> (O)<Keoni29> Then I pay one dip
<OmnomIRC> (O)<Keoni29> Do you have paypal?
<OmnomIRC> (O)<Keoni29> :S
<OmnomIRC> (O)<yrinfish> nope
<OmnomIRC> (O)<yrinfish> lol
<OmnomIRC> (O)<yrinfish> hm, I could get some crisps
<OmnomIRC> (O)<yrinfish> it is too late to do that here
<OmnomIRC> (O)<yrinfish> main europe
* jkag ([email protected]) has joined #omnimaga
* Netbot45 gives voice to jkag
<OmnomIRC> (O)<yrinfish> MUSIC YAY
<OmnomIRC> (O)<Keoni29> Well the shops are closed here too
<OmnomIRC> (O)<Keoni29> 21:45
<OmnomIRC> (O)<yrinfish> where?
<OmnomIRC> (O)<Keoni29> Gwt+0
<OmnomIRC> (O)<Keoni29> The netherlands
<OmnomIRC> (O)<yrinfish> huh? loool
<OmnomIRC> (O)<yrinfish> hallo keoni, hoe gaat het? continue in english please
<OmnomIRC> (O)<Keoni29> :S
<OmnomIRC> (O)<yrinfish> really stupid dutch sentence^

Languages:
1308401677 <yrinfish> I'm dutch
1308401679 <yrinfish> lol
1308401687 <p2> Oh.
1308401702 <yrinfish> So I need to learn german
1308401705 <yrinfish> and french
1308401712 <yrinfish> and English
1308401717 <yrinfish> and Dutch
1308401724 <yrinfish> and Greek
1308401728 <yrinfish> and Latin
1308401739 <p2> I must learn french and English.
1308401739 <yrinfish> and Spanish
1308401749 <Spyro543> Y=sin(x+yrinfish)*>9000
NOTE: these are all the languages I have chosen to learn!
Spoiler For Info:

Spoiler For Projects:
Happy    [.---------] A C-like programming language for the z80 in js. REWRITING THE WHOLE THING, GOOD IDEAS NEEDED
DionJump [======----] Paused, but there is an update
Corona   [----------] Not enough time... If you need inspiration?
LGETC    [======----] getchar() LUT, useful and not too big. Waits for keyboard input and returns ASCII char

Spoiler For yrinthings tools:
stringLength Get the length in pixels of a small-font string.
safeText Html-ify a piece of text.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Get first/second byte of r-variable easily
« Reply #9 on: June 16, 2011, 12:56:53 pm »
I dont think he'll remove it. just because it'll break 1 out of 2 optimizations...
I'm not a nerd but I pretend:

Ashbad

  • Guest
Re: Get first/second byte of r-variable easily
« Reply #10 on: June 16, 2011, 12:59:04 pm »
Yeah, it is very intentional and getting rid of that will really screw up the rest of the parser.  It's very useful for using lambdas and procs in Axe.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Get first/second byte of r-variable easily
« Reply #11 on: June 16, 2011, 01:00:45 pm »
explain lambda and procs (I know what a lambda is, but that isnt meant here I think)
I'm not a nerd but I pretend:

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Get first/second byte of r-variable easily
« Reply #12 on: June 17, 2011, 05:05:42 am »
To answer the original question:

Code: [Select]
r1/256
r1^256

The top one gets the high 8 bits and the bottom one gets the low 8 bits.  Although {or1+1} is slightly more efficient than r1/256 currently, but it could eventually auto-optimize in later versions.
« Last Edit: June 17, 2011, 05:06:48 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Get first/second byte of r-variable easily
« Reply #13 on: June 17, 2011, 05:40:57 am »
As nice as it is to use HL, when you need to pass parameters back, chances are you'll end up storing it in a variable at some point. If you define a specific set of variables to be used for parameter passing, then your subroutine is no different than an object in OO language.
« Last Edit: June 17, 2011, 05:41:33 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ