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.

C/C++ > rom loader

#4551 - Mega386 - Thu Apr 03, 2003 7:07 am

ive been thinking it would be kindof cool to make an operating system for the gba but i cant seem to figure out how to execute another rom on the cartridge after one program has started running. if anyone has any clue on how to do this please help.

#4552 - tepples - Thu Apr 03, 2003 7:29 am

Mega386 wrote:
i cant seem to figure out how to execute another rom on the cartridge after one program has started running

Somebody has already done this, and it's called PogoShell.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#4607 - phonymike - Fri Apr 04, 2003 9:23 am

Below is code taken from GBA Flinker 1.72 source. It is the code to "unlock" visoly carts. I found that my carts only need the WriteRepeat (0x987654, 0x5354, 1) to get unlocked, though older carts may need all of these writes.

Code:
void WriteRepeat (u32 addr, u16 data, u16 count){
  u16 i;
  for (i=0; i<count; i++)
   *(vu16 *)(0x8000000 + (addr << 1)) = data;
}

void VisolyModePreamble (void){
  WriteRepeat (0x987654, 0x5354, 1);
  WriteRepeat (0x12345, 0x1234, 500);
  WriteRepeat (0x7654, 0x5354, 1);
  WriteRepeat (0x12345, 0x5354, 1);
  WriteRepeat (0x12345, 0x5678, 500);
  WriteRepeat (0x987654, 0x5354, 1);
  WriteRepeat (0x12345, 0x5354, 1);
  WriteRepeat (0x765400, 0x5678, 1);
  WriteRepeat (0x13450, 0x1234, 1);
  WriteRepeat (0x12345, 0xABCD, 500);
  WriteRepeat (0x987654, 0x5354, 1);
}


After you execute that, you then need to write a value to a location in the visoly cart (0x96B592E) which is the (converted) address in the cart that you want to be mapped to 0x8000000. The code below will convert an address to the correct bits. The resolution of the cart is 32KB (0x8000) so you can't have any location smaller than 0x8000. So below, you can set ROM_ADDRESS to 0x8000 or 0x8008000 for the next bank (the 0x8000000 gets cut off in the conversion, so you can leave it off or leave it in.) The conversion code below works for carts up to 256Mb (32MB.)

Code:
*(u16*)0x96B592E = (((ROM_ADDRESS>>15) & 0x7F)<<3) | (((ROM_ADDRESS>>15) & 0x380)>>7);


or if you prefer assembly :)

Code:
   mov   r0,r0,lsr #15   ;chop off zeros
   and   r1,r0,#0x7F   ;mask for < 4MB
   and   r0,r0,#0x380   ;mask for >= 4MB

   mov   r1,r1,lsl #3   ;align < 4MB reg for visoly cart
   mov   r0,r0,lsr #7   ;align >= 4MB reg for visoly cart

   orr   r0,r0,r1   ;combine the bits, r0 = visoly register value

   ldr   r1,=0x96B592E   ;address where bank setting is written to
   str   r0,[r1]      ;set the cartridge to specified rom address

   mov   r0,#0x08   ;setting for swi 0 (clear all ram)
   swi   0x1000      ;clear ram
   swi   0


For more info on the visoly cart registers check out this document. Also check out this site for more GBA hardware info.

#4698 - Mega386 - Mon Apr 07, 2003 7:06 am

Thanks alot phonymike.

#4727 - Malefactor - Mon Apr 07, 2003 11:52 pm

what kind of OS you thinkin about?
_________________
[Images not permitted - Click here to view it]