sneakthief Posted March 31, 2007 Report Share Posted March 31, 2007 First of all, I've carefully read through the "Multidimensional Array" thread. But I'm not sure if it applies to my situation....I have to create a series of ~50 different one-dimensional arrays, each containing about 20 elements (instead of just a multidimensional array, due to the 255 array-element limit) Based on the code below, what's the best way to load the contents of one of these arrays (into current_array) by passing an argument (array_number) to a function (LoadArray)? const char array1[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] const char array2[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ... const char array50[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ////////////////////////////////////////////////////////////// // This function loads a sequence based on the // argument that's passed to it ////////////////////////////////////////////////////////////// void LoadArray(unsigned char array_number) { unsigned char i; for (i = 0; i < 20; i++) { current_array[i] = array1[i]; } } Or is there a totally different way of doing this?thanks! Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 1, 2007 Report Share Posted April 1, 2007 First of all, I've carefully read through the "Multidimensional Array" thread. But I'm not sure if it applies to my situation....Fortunately not :)I *think* you could use pointer to the array? Quote Link to comment Share on other sites More sharing options...
sneakthief Posted April 2, 2007 Author Report Share Posted April 2, 2007 i've read a dozen function pointer tutorials and i can't seem to figure out how to address a different array depending on the variable passed to the function....because i'm such a dumbass and don't know how to elegantly access them in C, i had to make a conditional statement (aka switch) with 50 separate cases. so when a song is loaded, it has to manually go through each case to see if it's the right song so it can load the appropriate array... instead of somehow passing a variable from a function to load the right array. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 2, 2007 Report Share Posted April 2, 2007 Well maybe you're not a dumbass after all... SDCC should have converted your switch statement into a jumptable, just like TK does it in ASM ;)That said, I haven't seen them, TK's implementation may be more optimised (probably, knowing TK) so maybe you could use inline ASM and use his jumptable macros.50 elements is a lot though, it'll be a long table of course.Did you actually try the multidimensional arrays? I tell ya what, I'd really like to finish this once and for all. When today's snapshot build of SDCC is released, I'm gonna make a bare app that just boots, populates a 512k multidimensional array, and then dumps it via sysex. Let's find out what's up with this :) Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 2, 2007 Report Share Posted April 2, 2007 Yup, works like a charm. Try it :)I even got the array to start on 0x0FF (bad) and end at 0x300 (bad) and it still works like a charm. I can't seem to break it any more :DYou're going to want to grab sdcc snapshot 4732. You freaks on Mac on *nix can grab yours from http://sdcc.sourceforge.net/snapshots/ :) Quote Link to comment Share on other sites More sharing options...
sneakthief Posted April 2, 2007 Author Report Share Posted April 2, 2007 re. your array experiment - please tell me the results if you get a chance to do this! re. multidimensional arrays - these are equally frustrating because each array can only have 255 elements - because my arrays have 20 items, this means i can only have 10 dimensions per array before they break. so if i'm already breaking it up into groups of 10, why not make the retrieval algorithm easier and simply break it up into 50 separate arrays.i'm eventually going to use a bankstick to hold all my arrays, but for the moment this is working ok. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 2, 2007 Report Share Posted April 2, 2007 re. your array experiment - please tell me the results if you get a chance to do this! re. multidimensional arrays - these are equally frustrating because each array can only have 255 elements - because my arrays have 20 items, this means i can only have 10 dimensions per array before they break. Ahh I don't think so bud :) I just made array[512], filled it with bytes >0 in the init loop, and then dumpd it via sysex to make sure it was all correct, and it was. If you like I'll attach the code but it's just a few for loops, nothing special.Just tried it with array[8][64] too and it's sweet as.Give it a go :D Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 2, 2007 Report Share Posted April 2, 2007 Do you have a 4620?Anyhow here's some code:edit: Darn I lost some textOK... just rename the txt file to .lkr. write these files over a skeleton, compile and upload. Edit2: Oh yeh. What you'll see is a bunch of sysex messages, with bytes in pairs, incrementing from 1-64 (decimal)+number of the row (the offset is so I could be sure they were all different), separated by 0x32 (just for me to have something to 'search and replace' when I was checking) You can see where I've remarked out the SECTION in the linker and the #pragma in the main.c. If you unremthose, you can force it to use certain memory banks. All work OK :)project.txtmain.cproject.txtmain.c Quote Link to comment Share on other sites More sharing options...
sneakthief Posted April 2, 2007 Author Report Share Posted April 2, 2007 Hey just thinking... 50x20 chars is mare ram than this thing has...Do you have a 4620?i'm using a 4520 for now.these are program constants so it's not in the ram. anyhow, all of my sequences are loading and the data shows up and is transmitting correctly :)i'll try out your code! thx for sharing it here :) Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 2, 2007 Report Share Posted April 2, 2007 i'm using a 4520 for now.Heh never tried one :)Ignore my comment about the ram, I dunno what I was thinking ? Quote Link to comment Share on other sites More sharing options...
sneakthief Posted April 2, 2007 Author Report Share Posted April 2, 2007 oops, i meant 452! must have typed that because i have a 4620 and 4520 sitting next to my pc right now ;) 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.