Romdisk Swapping: Difference between revisions

From dreamcast.wiki
Jump to navigation Jump to search
(Created page with "Author: Lerabot = Introduction = When I started adding things to the ROM disk, I didn't realize that my 10MB+ .elf file would be problematic (i.e. not load) on the Dreamcast....")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
Author: Lerabot
Author: Lerabot/Magnes
 
= Introduction =
= Introduction =
When I started adding things to the ROM disk, I didn't realize that my 10MB+ .elf file would be problematic (i.e. not load) on the Dreamcast.
When I started adding things to the ROM disk, I didn't realize that my 10MB+ .elf file would be problematic (i.e. not load) on the Dreamcast.
Also it's been mentioned in a forum topic that loading a romdisk instead of multiple files would be faster.
Also it's been mentioned in a forum topic that loading a romdisk instead of multiple files would be faster. **Need source**
I also think that it could be a neat way to handle/manage your memory altogether.
I also think that it could be a neat way to handle/manage your memory altogether.
''2020 edit : Removed the GZ compression as it seemed to cause problem with filename longer than a certain length (16 IIRC?)''


= Guide =
= Guide =
== Step 1==
== Organize your assets ==
Organizing the content or your romdisk in multiple folders:
Organize the content or your romdisk in multiple folders:


   /level1
   /level1
Line 14: Line 15:
   /level3
   /level3


== Convert to romdisk ==
In your Makefile, duplicate the usual romdisk generation command but change the romdisk name and directory.
 
This is the usual romdisk command, you can still keep this
<syntaxhighlight lang="bash">$(KOS_GENROMFS) -f romdisk.img -d path/to/romdisk -v</syntaxhighlight>


== Step 2 ==
This is your new romdisk, replace the romdisk_name and romdisk_folder with what you want.
In your Makefile, duplicate the usual romdisk generation command but change the romdisk name and directory.
<syntaxhighlight lang="bash">$(KOS_GENROMFS) -f romdisk_name.img -d path/to/romdisk_folder -v</syntaxhighlight>
I also added GZip compression, however sometimes GZip-ed files fail to load. If thats the case for you then don't bother with GZip.


  romdisk.img:
If I'm using the example from earlier, I could make a "level1" romdisk this way
        $(KOS_GENROMFS) -f romdisk.img -d path/to/romdisk -v              # <- this is the usual romdisk command, you can still keep this
<syntaxhighlight lang="bash">$(KOS_GENROMFS) -f level1.img -d path/to/level -v</syntaxhighlight>
        $(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


''Note:'' the leading whitespace consists of a tab, not spaces.


== Step 3 ==
== Using your romdisk ==
In your code you'll need a way to load those new romdisks, we'll use this  code snippet by ''BlackAura''.
In your code you'll need a way to load those new romdisks, we'll use this  code snippet by ''BlackAura''.
For more info, check this topic [https://dcemulation.org/phpBB/viewtopic.php?f=29&t=68795&hilit=romdisk+feet+of+fury]
For more info, check this topic [https://dcemulation.org/phpBB/viewtopic.php?f=29&t=68795&hilit=romdisk+feet+of+fury]


<syntaxhighlight lang="c">
#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;
  // Allocate memory, read file
  buffer = malloc(length);
  gzread(file, buffer, length);
  gzclose(file);
  // Mount
  fs_romdisk_mount(mountpoint, buffer, 1);
  return 1;
}
</syntaxhighlight>


  #include <kos.h>
''' It is important that your mount point start with a '/' -> "/level1" and not "level1" '''
  #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 load files that are located at "/level1". Example "/level1/spritesheet.png"


You can now unload the romdisk using:
You can unload the romdisk using:
  fs_romdisk_unmount(mountpoint);
<syntaxhighlight lang="c">fs_romdisk_unmount(mountpoint);</syntaxhighlight>




= Usage with a Broadband adapter or dc-ipload =
= Usage with a Broadband adapter or 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'':
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'':
  dc-tool-ip -t dreamcast -c /path/to/project -x program_name.elf
<syntaxhighlight lang="bash">dc-tool-ip -t dreamcast -c /path/to/project -x program_name.elf</syntaxhighlight>


You can now use the function below to access files in the ''/rom'' folder:
You can now use the function below to access files in the ''/rd'' folder:
  mount_romdisk("/pc/romdisk_name.img.gz", "/rom");
<syntaxhighlight lang="c">mount_romdisk("/pc/romdisk_name.img", "/rd");</syntaxhighlight>


Keep in mind that you'll have to switch ''/pc/'' to ''/cd/'' when you burn this to a CD.
Keep in mind that you'll have to switch ''/pc/'' to ''/cd/'' when you burn this to a CD.

Latest revision as of 18:12, 30 May 2020

Author: Lerabot/Magnes

Introduction

When I started adding things to the ROM disk, I didn't realize that my 10MB+ .elf file would be problematic (i.e. not load) on the Dreamcast. Also it's been mentioned in a forum topic that loading a romdisk instead of multiple files would be faster. **Need source** I also think that it could be a neat way to handle/manage your memory altogether.

2020 edit : Removed the GZ compression as it seemed to cause problem with filename longer than a certain length (16 IIRC?)

Guide

Organize your assets

Organize the content or your romdisk in multiple folders:

 /level1
 /level2
 /level3

Convert to romdisk

In your Makefile, duplicate the usual romdisk generation command but change the romdisk name and directory.

This is the usual romdisk command, you can still keep this

$(KOS_GENROMFS) -f romdisk.img -d path/to/romdisk -v

This is your new romdisk, replace the romdisk_name and romdisk_folder with what you want.

$(KOS_GENROMFS) -f romdisk_name.img -d path/to/romdisk_folder -v

If I'm using the example from earlier, I could make a "level1" romdisk this way

$(KOS_GENROMFS) -f level1.img -d path/to/level -v


Using your romdisk

In your code you'll need a way to load those new romdisks, we'll use this code snippet by BlackAura. For more info, check this topic [1]

#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;

  // 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 load files that are located at "/level1". Example "/level1/spritesheet.png"

You can unload the romdisk using:

fs_romdisk_unmount(mountpoint);


Usage with a Broadband adapter or 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:

dc-tool-ip -t dreamcast -c /path/to/project -x program_name.elf

You can now use the function below to access files in the /rd folder:

mount_romdisk("/pc/romdisk_name.img", "/rd");

Keep in mind that you'll have to switch /pc/ to /cd/ when you burn this to a CD.