GUIDE : romdisk swapping

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

GUIDE : romdisk swapping

Post by lerabot »

I've been messing with this today and figured that it might be interesting for others

WHY DO ROMDISK SWAP?
when I started adding things to the rom disk, I didn't realize that my 10mb+ .elf file would be problematic (ie : not load) on the dreamcast. also,
it's been mentionned in other topic that loading the romdisk and not multiple files would be faster. I also think that it could be a neat way to handle/manage your memory altogether.

HOW-TO

1 - organize the content or your romdisk in folders

Code: Select all

/level1
/level2
/level3
2 - in your makefile, duplicate the usual romdisk command but change the romdisk name and directory. i also added gzip compression.

Code: Select all

romdisk.img:
        $(KOS_GENROMFS) -f romdisk.img -d path/to/romdisk -v                                 # <- this is the usual romdisk command, you can still keep this
        $(KOS_GENROMFS) -f romdisk_name.img -d path/to/romdisk_folder -v           # <- this is your new romdisk, replace the romdisk_name and romdisk_folder with what you want.
        $(KOS_GENROMFS) -f level1.img -d path/to/level -v                                         # <- if I'm using the exemple from earlier, I could make a "level1" romdisk this way
        gzip -f -9 romdisk_name.img                                                                               # <-make sure you add all your new romdisk names here
3 - in your code you'll need a way to load those new romdisks, we'll use this good code snippet BlackAura gave us a while ago. for more info, check this topic : viewtopic.php?f=29&t=68795&hilit=romdisk+feet+of+fury

Code: Select all

#include <kos.h>
#include <zlib/zlib.h>

// Thanks BlackAura ;)
int mount_romdisk(char *filename, char *mountpoint)
{
    void *buffer;
    int length = zlib_getlength(filename);

    // Check failure
    if(length == 0)
        return 0;

    // Open file
    gzFile file = gzopen(filename, "rb");
    if(!file)
        return 0;

    // Allocate memory, read file
    buffer = malloc(length);
    gzread(file, buffer, length);
    gzclose(file);

    // Mount
    fs_romdisk_mount(mountpoint, buffer, 1);
    return 1;
}
it is important that your mount point start with a '/' -> "/level1" and not "level1"

you can now unload the romdisk using :

Code: Select all

fs_romdisk_unmount(mountpoint);
HOW-TO USE WITH BBA / DC-IPLOAD
in order to use these new romdisk, you need to enable /pc redirection in your dc-tool, update your dc-tool command to use -c

Code: Select all

dc-tool-ip -t dreamcast -c /path/to/project  -x program_name.elf
you can now use the function below to acces files in the /rom folder

Code: Select all

mount_romdisk("/pc/romdisk_name.img.gz", "/rom");
keep in mind that you'll have to switch /pc/ to /cd/ when you'll end up burning this to a CD.

PLEASE LET ME KNOW IF SOMETHING IS WRONG/ NOT OPTIMIZED! (also, thanks Quzar for the help on IRC)
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: GUIDE : romdisk swapping

Post by bogglez »

Added to the wiki: http://dcemulation.org/?title=Romdisk_Swapping
Is your other guide ready btw or are you still making modifications?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: GUIDE : romdisk swapping

Post by lerabot »

Thanks man! I'll look at the other tutorial this weekend.
Post Reply