gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Saving to slot-1

#121880 - FRuMMaGe - Thu Mar 15, 2007 1:07 pm

I'm new to programming and i've made a basic paint program. it would really help me if I could save my pictures, preffereably to slot-1 as I have an R4.

Is there a way to save the current VRAM bank in the form of a bitmap?

#121894 - Diddl - Thu Mar 15, 2007 2:20 pm

you can save as a normal game cartridge does. most cartridges produce a .sav file while saving.

better way is to use libfat. you can save your picture as a normal file on your TF card in your R4. simply use fopen() fwrite() fclose() like any other c-Program.

#121895 - Quirky - Thu Mar 15, 2007 2:26 pm

Also, there is a screenshot function available that stores the current main screen to a given VRAM bank.

Code:

  vramSetBankB(VRAM_B_LCD);
  const int mode   = 0;  // source A (main screen)
  const int source = 0; // 1 for 3D
  const int dst    = 1;           // A = 0, B = 1, C = 2, D = 3
  DISP_CAPTURE =
    DCAP_ENABLE      |  // Enable/Busy flag
    DCAP_MODE(mode)  |  // Capture mode    (0=Source A, 1=Source B, 2/3=Sources A+B blended)
    DCAP_DST(0)      |  // VRAM Write Offset (0=00000h, 0=08000h, 0=10000h, 0=18000h)
    DCAP_SRC(source) |  // Source A          (0=Graphics Screen BG+3D+OBJ, 1=3D Screen
    DCAP_SIZE(3)     |  // Capture Size      (0=128x128, 1=256x64, 2=256x128, 3=256x192 dots)
    DCAP_OFFSET(0)   |  // VRAM Read Offset  (0=00000h, 0=08000h, 0=10000h, 0=18000h)
    DCAP_BANK(dst)   |  // VRAM Write Block  (0..3 = VRAM A..D) (VRAM must be allocated to LCDC)
    DCAP_A(16)       |  // Bland ignored if capture mode is 0 or 1
    DCAP_B(0);
  // this may block forever on broken emulators...
  while (DISP_CAPTURE & DCAP_ENABLE) {
    swiWaitForVBlank();
  }


Now you can read from bank B.
Code:

for (int i = 0; i < 192*256;i++)
{
   u16 pixel = VRAM_B[i];
   // do stuff with pixel
}


Might be useful if you use palettes or 3D or other hardware gfx features. The data is "photographed" in ARGB bitmap format in the chosen bank.

#121931 - FRuMMaGe - Thu Mar 15, 2007 9:02 pm

Do I need PAlib for this? I'm currently using just libnds.h

#121932 - HyperHacker - Thu Mar 15, 2007 9:06 pm

You don't need PAlib for anything. It's just an alternative.
_________________
I'm a PSP hacker now, but I still <3 DS.

#122005 - FRuMMaGe - Fri Mar 16, 2007 11:18 am

Thanks for the help!

One more question though, how can I use this to capture just a certain part of the screen? I have a pallette taking up the first 28 pixels of the screen.

#122901 - FRuMMaGe - Fri Mar 23, 2007 11:47 am

FRuMMaGe wrote:
Thanks for the help!

One more question though, how can I use this to capture just a certain part of the screen? I have a pallette taking up the first 28 pixels of the screen.


Hello?

#122909 - OOPMan - Fri Mar 23, 2007 1:15 pm

Erm, just capture and then discard the first 28 pixels before saving?
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#122911 - FRuMMaGe - Fri Mar 23, 2007 1:40 pm

I'm new at this. Exactly how do I implement this code in the context of saving a picture?

#123013 - Noda - Sat Mar 24, 2007 3:32 pm

Diddl wrote:
you can save as a normal game cartridge does. most cartridges produce a .sav file while saving.
.


any hints on how to do this? I'm very interested in doing this! thanks

#123014 - Sektor - Sat Mar 24, 2007 3:43 pm

I wouldn't recommend saving to EEPROM since if someone has an original DS game in slot-1, it could erase their save. Many slot-1 devices don't have a normal EEPROM either, so they would fail with homebrew.
_________________
GTAMP.com/DS

#123023 - Diddl - Sat Mar 24, 2007 6:07 pm

Noda wrote:
Diddl wrote:
you can save as a normal game cartridge does. most cartridges produce a .sav file while saving.
.


any hints on how to do this? I'm very interested in doing this! thanks


it's already solved in rein17a source code. you can find it simply. rein17 is an application which can copy save area of slot 1 card to a file and vice versa. it works with all kind of saves (EEPROM, Flash, all sizes).

Sektor is right, you only should do it if homebrew is started from slot 1. if homebrew is started from slot 2 and in slot 1 is any card it could overwrite anything.

#123228 - FRuMMaGe - Mon Mar 26, 2007 9:10 am

Diddl wrote:
Noda wrote:
Diddl wrote:
you can save as a normal game cartridge does. most cartridges produce a .sav file while saving.
.


any hints on how to do this? I'm very interested in doing this! thanks


it's already solved in rein17a source code. you can find it simply. rein17 is an application which can copy save area of slot 1 card to a file and vice versa. it works with all kind of saves (EEPROM, Flash, all sizes).

Sektor is right, you only should do it if homebrew is started from slot 1. if homebrew is started from slot 2 and in slot 1 is any card it could overwrite anything.


Is there a way to determine which slot the user is booting from, then save accordingly?

#123238 - Diddl - Mon Mar 26, 2007 11:46 am

you cannot determine from which slot program has booted, but you can use libfat to determine if a slot 2 is inserted and accessable. and you can use libfat to determine if a slot 1 is inserted and accessable.

if slot 1 is accessable by libfat it is not a game cartridge ==> use slot 1.

#123246 - Noda - Mon Mar 26, 2007 2:24 pm

Sektor wrote:
I wouldn't recommend saving to EEPROM since if someone has an original DS game in slot-1, it could erase their save. Many slot-1 devices don't have a normal EEPROM either, so they would fail with homebrew.


but a lot of flashcard produce a .sav instead of saving to EEPROM, but you may be right this should be used only on slot1 cards. But if we want compatibility for this, is it possible to patch the homebrew like any regular game to redirect the EEPROM save to a .sav file for slot2 cards?

It could be nice to have a standard way for stroring game saves.