Author Topic: Need a little help with coding for menu  (Read 32696 times)

0 Members and 1 Guest are viewing this topic.

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Need a little help with coding for menu
« on: August 02, 2010, 03:07:12 AM »
I inserted this into main.c at line 1062 to get save and cic info:
Code: [Select]
// get cic and save options
                char cartid[]="AA";
int i=0;
int romcic=2;
int romsave=0;
sprintf(cartid, "%c%c", gTable[bselect].rom[0x1C], gTable[bselect].rom[0x1D]);
// CARD: 0
// 6101: 1
// 6102: 2
// 6103: 3
// 6105: 5
// 6106: 6

//ciclist[0][0] to ciclist[0][16] cart ids of all 6101 games
//ciclist[1][0] to ciclist[1][16] cart ids of all 6103 games
//ciclist[2][0] to ciclist[2][16] cart ids of all 6105 games
//ciclist[3][0] to ciclist[3][16] cart ids of all 6106 games
char *ciclist[4][17] = {
{ "FX", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "TE", "BK", "DY", "NX", "MX", "KJ", "K4", "NB", "KG", "MQ", "PF", "PH", "PO", "PS", "P2", "P3", "AL" },
{ "B7", "FU", "DO", "DP", "JD", "JF", "ZS", "DL", "ZL", "ML", "PD", "", "", "", "", "", "" },
{ "CW", "FZ", "YS", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
};

for (i=0; i<17; i++)
{
if (strcmp(cartid, ciclist[0][i]) == 0)
{
romcic=1;
break;
}
}

for (i=0; i<17; i++)
{
if (strcmp(cartid, ciclist[1][i]) == 0)
{
romcic=3;
break;
}
}

for (i=0; i<17; i++)
{
if (strcmp(cartid, ciclist[2][i]) == 0)
{
romcic=5;
break;
}
}

for (i=0; i<17; i++)
{
if (strcmp(cartid, ciclist[3][i]) == 0)
{
romcic=6;
break;
}
}

// CARD: 0
// SRAM 256: 1
// Flash: 4
// 4Kb Eeprom: 5
// 16Kb Eeprom: 6

//savelist[0][0] to savelist[0][20] cart ids of all 4kb eeprom games 1
//savelist[1][0] to savelist[1][20] cart ids of all 4kb eeprom games 2
//savelist[2][0] to savelist[2][20] cart ids of all 4kb eeprom games 3
//savelist[3][0] to savelist[3][20] cart ids of all 16kb eeprom games
//savelist[4][0] to savelist[4][20] cart ids of all sram games
//savelist[5][0] to savelist[5][20] cart ids of all flash games
char *savelist[6][21] = {
{ "SA", "ER", "BK", "TN", "FH", "MU", "BC", "BH", "BM", "HA", "BV", "BD", "CT", "CH", "XO", "CU", "DY", "DQ", "N6", "JM", "FW" },
{ "KA", "GV", "GE", "GC", "PG", "IJ", "IC", "KI", "K4", "LR", "DU", "KT", "LB", "MW", "ML", "TM", "MI", "MO", "MR", "CR", "EA" },
{ "PW", "SU", "K2", "SV", "FX", "S6", "NA", "SW", "RS", "SC", "SM", "TP", "TJ", "RC", "VL", "VY", "WL", "WR", "WU", "AD", "" },
{ "B7", "FU", "CW", "DO", "DP", "MX", "NX", "NB", "MV", "M8", "PD", "RZ", "EP", "YS", "", "", "", "", "", "", "" },
{ "TE", "FZ", "YW", "ZL", "KG", "MF", "RI", "OB", "RE", "AL", "W2", "WX", "", "", "", "", "", "", "", "", "" },
{ "CC", "JD", "JF", "KJ", "ZS", "DL", "M6", "CK", "MQ", "PN", "PF", "PO", "PS", "P3", "P2", "SQ", "T9", "W4", "", "", "" }
};

for (i=0; i<21; i++)
{
if (strcmp(cartid, savelist[0][i]) == 0)
{
romsave=5;
break;
}
}

for (i=0; i<21; i++)
{
if (strcmp(cartid, savelist[1][i]) == 0)
{
romsave=5;
break;
}
}
for (i=0; i<21; i++)
{
if (strcmp(cartid, savelist[2][i]) == 0)
{
romsave=5;
break;
}
}

for (i=0; i<21; i++)
{
if (strcmp(cartid, savelist[3][i]) == 0)
{
romsave=6;
break;
}
}

for (i=0; i<21; i++)
{
if (strcmp(cartid, savelist[4][i]) == 0)
{
romsave=1;
break;
}
}

for (i=0; i<21; i++)
{
if (strcmp(cartid, savelist[5][i]) == 0)
{
romsave=4;
break;
}
}

// update Tables
gTable[bselect].options[5]=romsave;
gTable[bselect].options[6]=romcic;

But Nintendo does not approve of my coding skills  >:(
Compiler said everything is fine though.

As soon as I press Z to see if it works it locks up.  :'(

Edit: Updated it, now it works I hope  :P
« Last Edit: August 02, 2010, 07:07:33 AM by sanni »

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #1 on: August 02, 2010, 03:25:45 AM »
You forgot something...

Code: [Select]
      char *ciclist[4][17] = {
         { "FX" }, //cartids of all 6101 games

Means one string of "FX", and 16 NULL pointers. You forgot to test for NULL before doing the strcmp in the loops. Trying to use a NULL pointer is the quickest path to hell there is.  ^-^

If you wanted an empty string, you'd need 16 "" to avoid the issue.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #2 on: August 02, 2010, 05:22:58 AM »
Edit: Updated it, now it works for Starfox. But most other games lock up. I need a debugger  ~sm-79.gif~.gif

If it works for some and some others just hang(  O0O ) then probably the configuration is bad   ~sm-69.gif~.gif
Try to put some debug messages to figure out where it hangs....That's the only thing you can do actually  ::sm-12.gif::

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #3 on: August 02, 2010, 05:59:03 AM »
Ok, I now know, that it locks up when searching the savetype while searching for cic seems to be fine.  ~sm-39.gif~
Also the first for loop of the save determination is fine too.

It can only take more hours until I find the faulty line, just commenting it out line by line and see if it locks up  ~sm-62.gif~.gif


Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #4 on: August 02, 2010, 05:59:37 AM »
Ugh - that's such ugly code. I recommend doing it this way:

make one array with the cart ids
search through that array for the id match
if no match, cic = 2 and save = 5
if match, use index into table with cic values and table with save values

That needs only one string table, and two int tables. You only do one search as well. That code would be MUCH easier to debug and maintain.  :D

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #5 on: August 02, 2010, 06:18:59 AM »
I forgot this , in one line. A little , Who cares about a ,  ::sm-05::

Yeah I know the code looks ugly, but it's the first time I used these matrix arrays and stuff like that, so it's ok for now.
« Last Edit: August 02, 2010, 06:23:22 AM by sanni »

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #6 on: August 02, 2010, 06:37:45 AM »
I forgot this , in one line. A little , Who cares about a ,  ::sm-05::

The CPU does.  ~sm-82.gif~.gif

Quote
Yeah I know the code looks ugly, but it's the first time I used these matrix arrays and stuff like that, so it's ok for now.

Just a suggestion for when you feel like cleaning it up. If you did, it might even wind up in the official code.  8)

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #7 on: August 02, 2010, 08:07:33 AM »
Well that would be nice  ;)

Next week I will read more about this stuff:
if match, use index into table with cic values and table with save values
Because right now I have absolutely no glue how to do that. I found the tables I'm using now somewhere in your code and just adjusted them to my needs and filled them with the cart id I extracted out of the roms.
And from there if was just 10h of trial and error, no real coding involved. I'm surprised that it even worked in the end  ::sm-05::

I already got a new project  ~sm-92.gif~.gif

Code: [Select]
// load boxart sprites
    dfs_init(0xB0101000);
int fp = dfs_open("/FX.sprite");
sprite_t *FX = malloc(dfs_size(fp));
dfs_read(FX, 1, dfs_size(fp), fp);
dfs_close(fp);

// Draw boxart sprite
                sprintf(temp, "%c%c", gTable[bselect].rom[0x1C], gTable[bselect].rom[0x1D]);
if (strcmp(temp, "FX") == 0)
graphics_draw_sprite_trans(dcon, 4, 18, FX);

But it would be a lot nicer if I would not need the if:
Code: [Select]
// Draw boxart sprite
                sprintf(temp, "%c%c", gTable[bselect].rom[0x1C], gTable[bselect].rom[0x1D]);
graphics_draw_sprite_trans(dcon, 4, 18, temp);

But of course once again Nintendo does not approve  ~sm-80.gif~.gif
The gcc compiler also does not approve and most likely the rest of the coding world won't approve but it should be possible with a little imagination  ~sm-46.gif~.gif


Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #8 on: August 02, 2010, 08:27:57 AM »
I just meant something like this:

Code: [Select]
char *cartIDs[] = { "FX", .... };
int cicTypes[] = { 1, .... };
int saveTypes[] = { 5, .... };

            for (i=0; NUM_CARTS; i++)
               if (strcmp(cartid, cartIDs[i]) == 0)
                  break;
            if (i == NUM_CARTS)
            {
                // cart not in list
                cic = 2;
                save = 5;
            }
            else
            {
                cic = cicTypes[i];
                save = saveTypes[i];
            }

where NUM_CARTS is the number of entries in the arrays. See how simple and clean that code is? The only real work is making sure the cic and save entries match the proper cartID entry.

As to sprites with libdragon, you need to make the height and width powers of two AND less than 4KBytes in size for hardware drawing, or you need to use the software drawing routine. The hardware sprite drawing is constrained to the size of the texture cache in the RDP, which is 4KB (2KB if you use mipmaps). The software routine draws the sprites manually via the CPU a pixel at a time, so it can be used with any size... but remember that the sprite structure in libdragon uses unsigned bytes for the height and width, so the max size for a sprite is 255x255. Well, it's meant for SPRITES, and if your sprite is larger than that, you should be drawing it another way. :)

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #9 on: August 02, 2010, 05:42:54 PM »
Is there a way to convert this table I made:

Code: [Select]
NAME ID SAVE CIC BOXART
Worms Armageddon AD 5 2 1
Super Smash Bros. AL 1 3 2
Banjo-Tooie B7 6 5 3
Blast Corps BC 5 2 4
Bomberman Hero BD 5 2 5
Body Harvest BH 5 2 6
Banjo-Kazooie BK 5 3 7
Bomberman 64 BM 5 2 8
Bomberman 64: Second Attack BV 5 2 9
Command & Conquer CC 4 2 10
Chopper Attack CH 5 2 11
NBA Courtside 2 featuring Kobe Bryant CK 4 2 12
Penny Racers CR 5 2 13
Chameleon Twist CT 5 2 14
Cruis'n USA CU 5 2 15
Cruis'n World CW 6 6 16
Legend of Zelda: Majora's Mask, The DL 4 5 17
Donkey Kong 64 DO 6 5 18
Donkey Kong 64 DP 6 5 19
Donald Duck: Goin' Quackers DQ 5 2 20
Loony Toons: Duck Dodgers DU 5 2 21
Diddy Kong Racing DY 5 3 22
PGA European Tour EA 5 2 23
Star Wars Episode 1 Racer EP 6 2 24
AeroFighters Assault ER 5 2 25
Bass Hunter 64 FH 5 2 26
Conker's Bad Fur Day FU 6 5 27
F-1 World Grand Prix FW 5 2 28
Star Fox 64 FX 5 1 29
F-Zero X FZ 1 6 30
GT64 Championship Edition GC 5 2 31
GoldenEye 007 GE 5 2 32
Glover GV 5 2 33
Bomberman 64 HA 5 2 34
Indy Racing 2000 IC 5 2 35
Indiana Jones and the Infernal Machine IJ 5 2 36
Jet Force Gemini JD 4 5 37
Jet Force Gemini JF 4 5 38
Earthworm Jim 3D JM 5 2 39
Snowboard Kids 2 K2 5 2 40
Kirby 64: The Crystal Shards K4 5 3 41
Fighters Destiny KA 5 2 42
Major League Baseball featuring Ken Griffey Jr. KG 1 3 43
Killer Instinct Gold KI 5 2 44
Ken Griffey Jr's Slugfest KJ 4 3 45
Mario Kart 64 KT 5 2 46
Mario Party LB 5 2 47
Lode Runner 3D LR 5 2 48
Megaman 64 M6 4 2 49
Mario Tennis M8 6 2 50
Mario Golf MF 1 2 51
Mission: Impossible MI 5 2 52
Mickey's Speedway USA ML 5 5 53
Monopoly MO 5 2 54
Paper Mario MQ 4 3 55
Multi-Racing Championship MR 5 2 56
Big Mountain 2000 MU 5 2 57
Mario Party 3 MV 6 2 58
Mario Party 2 MW 5 2 59
Excitebike 64 MX 6 3 60
Dr. Mario 64 N6 5 2 61
Star Wars Episode 1: Battle for Naboo NA 5 2 62
Kobe Bryant in NBA Courtside NB 6 3 63
Excitebike 64 NX 6 3 64
Ogre Battle 64: Person of Lordly Caliber OB 1 2 65
Pokémon Stadium 2 P2 4 3 66
Pokémon Stadium 2 P3 4 3 67
Perfect Dark PD 6 5 68
Pokémon Snap PF 4 3 69
Hey you, Pikachu! PG 5 2 70
Pokémon Snap PH 4 3 71
Pokémon Puzzle League PN 4 2 72
Pokémon Stadium PO 4 3 73
Pokémon Stadium PS 4 3 74
Pilotwings 64 PW 5 2 75
Top Gear Overdrive RC 5 2 76
Resident Evil 2 RE 1 2 77
New Tetris, The RI 1 2 78
Star Wars: Rogue Squadron RS 5 2 79
Ridge Racer 64 RZ 6 2 80
Star Soldier: Vanishing Earth S6 5 2 81
AeroFighters Assault SA 5 2 82
Starshot Space Circus SC 5 2 83
Super Mario 64 SM 5 2 84
Starcraft 64 SQ 4 2 85
Rocket: Robot on Wheels SU 5 2 86
Space Station Silicon Valley SV 5 2 87
Star Wars: Shadows of the Empire SW 5 2 88
Tigger's Honey Hunt T9 4 2 89
1080º Snowboarding TE 1 3 90
Tom & Jerry in Fists of Furry TJ 5 2 91
Mischief Makers TM 5 2 92
All-Star Tennis '99 TN 5 2 93
Tetrisphere TP 5 2 94
V-Rally Edition '99 VL 5 2 95
V-Rally Edition '99 VY 5 2 96
WCW/NWO Revenge W2 1 2 97
WWF: No Mercy W4 4 2 98
Waialae Country Club: True Golf Classics WL 5 2 99
Wave Race 64 WR 5 2 100
Worms Armageddon WU 5 2 101
WWF: Wrestlemania 2000 WX 1 2 102
Cruis'n Exotica XO 5 2 103
Yoshi's Story YS 6 6 104
Harvest Moon 64 YW 1 2 105
Legend of Zelda: Ocarina of Time, The ZL 1 5 106
Legend of Zelda: Majora's Mask, The ZS 4 5 107


into this format:

Code: [Select]
char *names[] = {"Starfox",....};
char *cartIDs[] = { "FX", .... };
int saveTypes[] = { 5, .... };
int cicTypes[] = { 1, .... };

without typing it manually?
Because that would be exhausting  ~sm-39.gif~

Layout of the Table: NAME/CARTID/ALTERNATE CARTID/SAVE/CIC
ALTERNATE CARTID is when there are two different versions of the same games, like Jet Force Gemini and Jet Force Gemini Kiosk. The have different Cartids, sometimes the same game but from an different region hs also a different id.
« Last Edit: August 03, 2010, 03:03:15 AM by sanni »

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #10 on: August 02, 2010, 07:47:17 PM »
This is how far I am right now:

making array for the boxarts(line 58)
Code: [Select]
sprite_t *boxart[299];

loading boxartsprite sprite into array (879)
Code: [Select]
// load boxart sprites
    dfs_init(0xB0101000);
    int fp = dfs_open("/FX.sprite");
    boxart[0] = malloc(dfs_size(fp));
    dfs_read(boxart[0], 1, dfs_size(fp), fp);
    dfs_close(fp);

main code (1049)
Code: [Select]
if ((gTable[bselect].type == 255))
{
//data arrays
//char *names[] = {"Starfox"};
char *cartIDs[] = {"FX"};
int saveTypes[] = {5};
int cicTypes[] = {1};
int boxartArrayNr[] = {0};

// variables
int NUM_CARTS = 1;
int cic = 2;
int save = 0;
int i=0;
int b= 0;
char cartid[]="AA";

// get cartid
sprintf(cartid, "%c%c", gTable[bselect].rom[0x1C], gTable[bselect].rom[0x1D]);

// search for cartid
for (i=0; NUM_CARTS; i++)
if (strcmp(cartid, cartIDs[i]) == 0)
break;
if (i == NUM_CARTS)
{
// cart not in list
sprintf(temp, "%c%c not in database", gTable[bselect].rom[0x1C], gTable[bselect].rom[0x1D]);
printText(dcon, temp, 4, 17);
cic = 2;
save = 0;
}
else
{
// cart found
b = boxartArrayNr[i];
cic = cicTypes[i];
save = saveTypes[i];
}

// update tables
gTable[bselect].options[5]=save;
gTable[bselect].options[6]=cic;

//draw boxart
graphics_draw_sprite_trans(dcon, 8, 100, boxart[b]);
}

Of course it crashes so i will search for that "," again  ~sm-59.gif~.gif

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #11 on: August 02, 2010, 08:01:54 PM »
Code: [Select]
int boxartArrayNr[] = {0};
b = boxartArrayNr[i];


This : "int boxartArrayNr[] = {0};"
Is the same as doing :
Code: [Select]
int boxartArrayNr = 0;

So , right now , the compiler is doing something like :
Code: [Select]
[4byte long]

ptr = addressOf([4byte long])

b = *(int*)(ptr + i * sizeof(int));

Which when i > 0 it goes out of range.

You should replace it to this :
Code: [Select]
static int boxartArrayNr[NUM_CARTS] = {0};
b = boxartArrayNr[i];

or allocate/free it dynamically.

Same applies for all the arrays you got there

edit : Also , this :  for (i=0; NUM_CARTS; i++) is inf loop  ~sm-75.gif~.gif
Replace it to  for (i=0;i < NUM_CARTS; i++)
...And maybe read some C tutorials  ~sm-70.gif~.gif
« Last Edit: August 02, 2010, 08:08:33 PM by Conle »

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #12 on: August 02, 2010, 09:23:59 PM »
Found the cause for the crashes, apparently you can't just throw 300 sprites(64x64 8kB 16Bit) into the filesystem  ::sm-05::
Seems like there is a limit on how many files you can have in there.

Now it works, I just have to fill the arrays with information and find out how many files you can store in the filesystem. Maybe it supports folders and only like 230 or so files per folder like old computers  ~sm-75.gif~.gif

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #13 on: August 02, 2010, 09:40:20 PM »
Well , lets see..

64w * 64h  * bytes per pixel * 300 / 131072 is about 150Mbit of uncompresed rom data for 16bit textures.
But , you must pad the menu to that size and because of how the bank is configured , you have to set the core to load a 256Mb rom  :P
and of course you must pad the menu to that size ( 150Mbit + 2-3Mb reserved ). (Maybe you also have to setup the alignment also but im not sure
about that).

But the question is ... what's the point of storing so many textures in the .rom section when you can just upload the textures on the psram or ram(and the n64 has enough to store temporary a few at a time) after reading it from the SD cart  ~sm-73.gif~.gif 

If you want textures , do exactly what Sony is doing for PSP/PS3.Read the directory , load as many texture as you can on PSRAM without having to change bank
then while the user is moving through the entries just copy it to the frame buffer & sync rdp(That's the easiest way but not very efficient). And for sure you want them compressed.Maybe use APLIB for that purpose.

« Last Edit: August 02, 2010, 09:45:15 PM by Conle »

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #14 on: August 02, 2010, 10:03:46 PM »



« Last Edit: August 03, 2010, 03:02:00 AM by sanni »