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.

Coding > Problems with new fastloader..

#20864 - BeeWarloc - Tue May 18, 2004 9:15 pm

Hi... I wrote a new fastloader for a linker application I'm coding (xupload)..
But it won't load all roms, some will run, and some will not. I think it has something to do with the state the gameboy is in when I jump back to the ROM..

Anyone know what's appropriate to do before jumping to 0x02000000?


Code:

/* a very simple fastloader created for xupload */
/* to compile this file crt0.s needs to have interrupts disabled */


#include <mygba.h>

extern void __FarProcedure (void (*ptr)(), ...);  // Reference to routine in crt0.S
void fastloader() MEM_FUNC_IN_IWRAM;

#define RCNT_PTR ((u16 *)0x04000134)
#define SIOCNT_PTR ((u16 *)0x4000128)
#define SIODATA32L_PTR ((u16 *)0x4000120)
#define SIODATA32H_PTR ((u16 *)0x4000122)
#define SIODATA32_PTR ((u32 *)0x04000120)

MULTIBOOT

/*********************************************************************************
 * Program entry point
 ********************************************************************************/

void fastloader() {
    u32 counter = 0, size;
    u32 *ewram = (u32 *)0x02000000;

   *RCNT_PTR = 0x0;
   *SIOCNT_PTR = 0x02 | 0x80 | 0x1000;

   *SIODATA32_PTR = 0xABADBABE;

   while(1) {
        if(!(*SIOCNT_PTR & 0x80)) {
            *SIOCNT_PTR |= 0x80;
            if(*SIODATA32_PTR == 0xB0B0DEAD)
                break;
            *SIODATA32_PTR = 0xABADBABE;
            *SIOCNT_PTR |= 0x02 | 0x80;
        }
   }

   *SIODATA32_PTR = 0x12652395;
   *SIOCNT_PTR |= 0x02 | 0x80;

   while(1) {
        if(!(*SIOCNT_PTR & 0x80)) {
            *SIOCNT_PTR |= 0x80;
            break;
        }
   }

   size = *SIODATA32_PTR / sizeof(u32);
   *SIODATA32_PTR = size;
   *SIOCNT_PTR |= 0x02 | 0x80;

   while(1) {
        if(!(*SIOCNT_PTR & 0x80)) {
            *SIOCNT_PTR |= 0x80; //?
            ewram[counter] = *SIODATA32_PTR;
            *SIODATA32_PTR = counter;
            counter++;
            if(counter >= size)
                break;
            *SIOCNT_PTR |= 0x02 | 0x80;
        }
   }

   __FarProcedure((void *)0x02000000);
}

int main(void)
{
    fastloader();
    return 0;
}




(yeah I know it probably should have been coded in asm, but with a stripped crt0.s and only -lgcc it compiles to ca 700 bytes including header, which is tolerable)

#20867 - poslundc - Tue May 18, 2004 9:25 pm

BeeWarloc wrote:
Hi... I wrote a new fastloader for a linker application I'm coding (xupload)..
But it won't load all roms, some will run, and some will not.


This may be pointing out the obvious, but you do realize that this will only work with roms compiled for multiboot support, right? Conventional roms won't work with it.

Dan.

#20871 - tepples - Tue May 18, 2004 9:48 pm

Do all programs compiled for multiboot work, or do only those under a given size work?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#20877 - BeeWarloc - Tue May 18, 2004 11:16 pm

poslundc wrote:
BeeWarloc wrote:
Hi... I wrote a new fastloader for a linker application I'm coding (xupload)..
But it won't load all roms, some will run, and some will not.


This may be pointing out the obvious, but you do realize that this will only work with roms compiled for multiboot support, right? Conventional roms won't work with it.

Dan.


Yes, I realize that..

Tepples: Yes all programs compiled for multiboot _should_ work, the size is transferred before the program.. however, there are some var initialization stuff that i don't get..

#20878 - BeeWarloc - Tue May 18, 2004 11:25 pm

Tepples: I think I misunderstood your question..

Since there only 256kB of ewram available, the max size will be 256kB.. I guess theoretically I could add support for writing another (32kB - loader size - stack size) bytes of data into iwram, but for this you would have to have a custom compiled binary (made with a modified linker script and crt0.s or something like that)..

If you need anything more than that you would have to write some rom flash code too, and have a flash cart..

#20894 - BeeWarloc - Wed May 19, 2004 10:02 am

Hi, I just got it to work..

I had to call the RegisterRamReset bios function, then jump to 0x02000000 (I found out this looking at the pogoshell source, which I ripped a few lines from):

(Just called this end of fastload(), instead of the __FarProcedure call)

Code:

    .SECTION   .iwram

   .ALIGN
   .CODE 32

   .GLOBAL    reset_func

reset_func:
   mov   r0,#0xfc      @reset all execept RAM
   swi   #0x010000
   ldr   r0, =0x02000000
   bx   r0
reset_end:



   .ALIGN
   .POOL
   .END



Now I get a 256kB rom to chainload in 7-8 seconds from my xupload utility which is a big improvement..
(if anyone wants the code, just say so, and I will post it)

Code:

> xupload f wws.mb

Found interface \\?\usb#vid_4542&pid_4144#5&308a5c96&0&1#{606377c1-2270-11d4-bfd
8-00207812f5d5}
Read 26 bytes from 0x222000 DIOC
00 00 1C 00 76 6B 06 00 04 00 00 80 01 00 00 00
04 00 00 00 01 00 00 00 4C 69
multibooting fastloader..
Read 880 bytes
   192 mb_index
mb_index: 256
mb_index: 512
mb_index: 768
6491 <> 6491
fastloading wws.mb
Read 198520 bytes
Warning: pads mb from 198520 to  262144
burst 0
stream transfer returned 00, retlength 65536 size 65536
burst 10000
stream transfer returned 00, retlength 65536 size 65536
burst 20000
stream transfer returned 00, retlength 65536 size 65536
burst 30000
stream transfer returned 00, retlength 65536 size 65536

#20929 - tepples - Thu May 20, 2004 3:53 am

BeeWarloc wrote:
Tepples: I think I misunderstood your question

For the record, my question was could you run all multiboot programs, even TOD (160 KB) and Panel de Pon (200 KB), or did it work only for programs smaller than 32 KB, 64 KB, or 128 KB?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#20941 - BeeWarloc - Thu May 20, 2004 9:44 am

Yes it runs all multiboot programs up to 256kB..