Author Topic: Look Up Tables in HuC?  (Read 1879 times)

DarkKobold

  • Hero Member
  • *****
  • Posts: 1200
Look Up Tables in HuC?
« on: February 26, 2016, 06:09:33 AM »
Hi everyone -
   I'm reaching a roadblock in my code, as I'm going to need arrays of constant chars longer than 255. I'm sure there is a good way to do LUTs, bu I have no idea how. Any advice would be great!
Hey, you.

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: Look Up Tables in HuC?
« Reply #1 on: February 26, 2016, 02:07:20 PM »
Can you describe what you're doing in a little more detail?

Are you looking for an explanation of what a LUT is, or, how to do one in HuC?

The problem with HuC is that arrays suck, so you would be doing this all in assembly.
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

elmer

  • Hero Member
  • *****
  • Posts: 2153
Re: Look Up Tables in HuC?
« Reply #2 on: February 26, 2016, 03:24:14 PM »
Can you describe what you're doing in a little more detail?

Are you looking for an explanation of what a LUT is, or, how to do one in HuC?

The problem with HuC is that arrays suck, so you would be doing this all in assembly.

Thank you ...  thank you ... thank you Arkhan.  8)

I'd love to be able to help, but I don't have the background knowledge with HuC that you have.

However far Dark Kobold and Gredler get with this ... they have my absolute respect as fellow "developers" that are trying to create something.

I'm so happy to see their progress and to read their posts.  :D

DarkKobold

  • Hero Member
  • *****
  • Posts: 1200
Re: Look Up Tables in HuC?
« Reply #3 on: February 27, 2016, 05:02:02 PM »
Can you describe what you're doing in a little more detail?

Are you looking for an explanation of what a LUT is, or, how to do one in HuC?

The problem with HuC is that arrays suck, so you would be doing this all in assembly.

Yeah, that was my fear. For patterns, I'm doing this:

Quote
const char drop_pattern_x[] =  {20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 190, 160, 130, 100, 70, 40, 
                                   20, 220, 40,  180, 60, 160, 80, 140, 100, 120, 110, 100, 120, 80, 140, 60, 160, 40, 180, 20, 220,
                                     90, 110, 130,  30, 50, 70, 150, 170, 190, 210, 90, 110, 130, 150, 170 ,190, 30, 50, 70,
                                     10, 74, 138, 202, 220, 156, 92, 28, 10, 74, 138, 202, 220, 156, 92, 28, 10, 74, 138, 202, 220, 156, 92, 28,
                                     40, 200, 140, 20, 120, 60, 180, 220, 100, 170, 150, 10, 190, 30, 80, 90, 210, 50, 110, 160, 70, 130,                                    
                                     10, 220, 70, 40, 100, 60, 120, 80, 140, 100, 160, 120, 180, 140, 200, 160, 220, 140, 200, 120, 180, 100, 160, 80, 140, 60, 120, 80, 140, 100, 160, 80, 140, 60, 120, 40, 100, 20, 80};                                                                  

const char drop_pattern_data[] =  {17, 0, 21, 17, 19, 38, 24, 57, 22, 81, 37, 103}; 

drop_pattern_data serves as my look-up table - Pattern length, offset, pattern length, offset, pattern length, offset, etc.

Yeah, its hackish, but because I can't write assembly inline, I couldn't think of a better way.

However, once you hit the 255 length, this becomes even more ridiculous. I'm wondering if there is a better way to do this sort of Look-up table. 
Hey, you.

TheOldMan

  • Hero Member
  • *****
  • Posts: 958
Re: Look Up Tables in HuC?
« Reply #4 on: February 27, 2016, 08:30:17 PM »
Quote
const char drop_pattern_data[] =  {17, 0, 21, 17, 19, 38, 24, 57, 22, 81, 37, 103};

Split that into 2 arrays; one for offset, one for length. Not a big deal, really...

Quote
const char drop_pattern_x[] =  {20,.....

This one is a 'problem'. One nice thing to know is that HuC create initialized data in order. So, if you
start with d_p_d[], then define d_p_d1[], they should be consecutive in memory. So, if you go past the end of the first array, you should get values from the second....
The catch there is making sure the data doesn't cross a page boundary :(

personally, i'd make a c function that returned the value you need (or sets a global variable) based on an index. Then you can use #asm/#endasm in the function to do it in assembler. A bit slower than direct access via an index register, but able to handle more than 256 bytes via a simple addition

Or you could try something like

char *p;
p=d_p_d+ix;
var = *p;

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: Look Up Tables in HuC?
« Reply #5 on: February 27, 2016, 09:59:24 PM »
You could try loading your "data" array with the address where each pattern starts, so then when you access the pattern you can grab the address and dereference it.

You still need to keep track of the length, though.  So:

drop_pattern_addr[] = {addresses,of,stuff}
drop_pattern_len[] = {length of each pattern}

then you'd just grab each (in assembly), and be ready to barf through it.

To setup the addresses, you could either:

1) Define each pattern in its own const array, and then const int* drop_pattern_addr[] = {first, second, third, etc};

2) leave it as is, and use the length array at run time to plow through the table and build the address array when the game loads up.  It's not like that's going to be hard, or impactful to performance since it'd happen once.

You'd just be like...  (its 6am, this might make no sense)

Code: [Select]
int offset = 0;
for(i = 0; i < drop_pattern_len's length; i++)
{
      drop_pattern_addr[i] = &drop_pattern_x[offset];
      offset += drop_pattern_len[i];
}
now you have where they all start at, so you can do all the things and the stuffs.
« Last Edit: February 27, 2016, 10:02:25 PM by Arkhan »
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

Gredler

  • Guest
Re: Look Up Tables in HuC?
« Reply #6 on: February 28, 2016, 07:22:54 AM »
Thanks for the positivity and help guys, it's really appreciated. I'm trying to get a grasp on the programming side, even a surface level understanding so that I can parse it for changing art and music stuff at one point, but man you guys sound like wizards.



Sorry DK, but this is so far above my head it makes me remember why I'm stranded on art island haha - good luck!

nodtveidt

  • Guest
Re: Look Up Tables in HuC?
« Reply #7 on: February 28, 2016, 08:42:27 AM »
That which you believe to be over your head will always be over your head as long as you believe it to be there. When you don't allow yourself to believe that you cannot understand, you can open your mind to understanding. Attitude is everything.

Gredler

  • Guest
Re: Look Up Tables in HuC?
« Reply #8 on: February 28, 2016, 10:10:10 AM »
That which you believe to be over your head will always be over your head as long as you believe it to be there. When you don't allow yourself to believe that you cannot understand, you can open your mind to understanding. Attitude is everything.

Thank you wise sensai. On second look a lot of it does make more sense when I slow down and try to relate it to the higher level languages I am familiar with, the for loop makes sense, beyond that I am very lost - I need to just start coding some basic stuff. I made it through hello world and went on to squirrel and then haven't touched code outside of mml since then. It really is fun, but the stuff discussed here is daunting hahaha thanks for the encouragement, someday grelder with code something!

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: Look Up Tables in HuC?
« Reply #9 on: February 28, 2016, 03:14:49 PM »
Do you know how pointers/addresses work?

If not, just dig up a basic C tutorial on that to explain.   It should make sense.
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

Gredler

  • Guest
Re: Look Up Tables in HuC?
« Reply #10 on: February 29, 2016, 03:55:33 AM »
Do you know how pointers/addresses work?

If not, just dig up a basic C tutorial on that to explain.   It should make sense.
No, I can only assume what pointers/addresses are. I have a basic understanding of c#, MEL, GS script, etc. Scripting is the way I would define my coding ability, I can read and modify code, and setup then plug in functions, but have not done any memory management or much data handling at all.

Thanks for the specific suggestion, that is super helpful. I have not done any tutorials or study on c yet, just the hello world tut on obeybrews site , but now I have something to read while at work - thank you sir it's really appreciated
« Last Edit: February 29, 2016, 04:00:26 AM by Gredler »

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: Look Up Tables in HuC?
« Reply #11 on: March 03, 2016, 06:24:16 AM »
Oh.  Yeah, if you don't understand pointers/addresses, you're going to have a real punch-in-the-dicktip kind of time with HuC once you start trying to optimize using assembly...

lol.  Hopefully the tutorials help.   The stuff isn't hard.  It's just necessary stuff.

[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

Bernie

  • Guest
Re: Look Up Tables in HuC?
« Reply #12 on: March 03, 2016, 07:48:03 AM »
NONE of this makes sense to me....  I am just glad someone is making more HB for the PCE.  :)

DarkKobold

  • Hero Member
  • *****
  • Posts: 1200
Re: Look Up Tables in HuC?
« Reply #13 on: March 21, 2016, 10:31:39 AM »

Code: [Select]
int offset = 0;
for(i = 0; i < drop_pattern_len's length; i++)
{
      drop_pattern_addr[i] = &drop_pattern_x[offset];
      offset += drop_pattern_len[i];
}
now you have where they all start at, so you can do all the things and the stuffs.

Thanks, this one makes the most sense to me. Plus it has the bonus of no asm.
Hey, you.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Look Up Tables in HuC?
« Reply #14 on: April 02, 2016, 02:27:53 PM »
I've worked with array access in HuC and have made fast access functions to help with this kind of problem. This stuff was trivial for me a couple of years back, but I'm sure I can jump right back into it.

 Is your problem speed? Or size limitation? Or both? I'm pretty limited on time right now, but if you're serious about this then PM me and I'll make time to help you with some custom made functions for your HuC project.