Homebrew Development

Discussion in '3DS - Homebrew Development and Emulators' started by aliak11, Jan 16, 2014.

  1. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    Thanks, for now though, I'll just leave it out until I can get everything else working....

    On that note, does anyone want to have a look at my latest frodo attempt? So far its up and running, but any attempt to reset the emulated console crashes. citra throws me into an unmapped read32 error loop.

    http://socoder.net/uploads/124/BreadBox_21_08_17.zip

    The issue appears to be caused by TheCPU->AsyncReset() -- called from void C64::Reset(void) in C64.cpp

    For the record, it worked fine in whatever older version of devkitpro I had back in 2016. The TheCPU->AsyncReset() function has not changed at all.
     
    Last edited by spinal_cord, Aug 21, 2017


  2. StackMasher

    StackMasher GBAtemp Regular

    Member
    111
    55
    Nov 29, 2016
    Where do I start learning about libctru
     
  3. nop90

    nop90 GBAtemp Maniac

    Member
    1,406
    2,108
    Jan 11, 2014
    Italy
    Rome
    Search for devkitpro 3ds examples (they are on github) and study the code.
     
  4. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    Can anyone tell me what 'unmapped read32' means in citra? it's the only clue I have as to why my frodo port is crashing.
     
  5. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    This can happen when reading a null pointer or when passing a main memory pointer to the sound or gpu hard which expects memory from "linear". a invalid/corrupt/uninitialize pointer could do this too. Essentially you are attempting to read from a memory range that is not accessible. You have a 4gb address range but far less actual memory.
     
  6. nop90

    nop90 GBAtemp Maniac

    Member
    1,406
    2,108
    Jan 11, 2014
    Italy
    Rome
    It can happen with a stack overflow too.
    With big arrays defined in a function this may happen since the stack is only 32k by defaulr.

    I have often this problem. It happens for example with libmad and libtremor, bit it doesn't happen with rhe same libs to other people.

    I'm trying to understand if it depends on my windows compiling emviroment
     
  7. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    This might take a while...
     
  8. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
  9. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    I haven't figured out exactly what is causing this yet. It appears to be something to do with the emulated floppy drive, but other than that, I'm lost. Fisrt I need to find out what the problem is before I start fixing it.
     
  10. nop90

    nop90 GBAtemp Maniac

    Member
    1,406
    2,108
    Jan 11, 2014
    Italy
    Rome
    Yes, but if you use 1M for stack you havr less ram for you code, and I'm always in short of it in my game ports.

    — Posts automatically merged - Please don't double post! —

    Try tracing the free memory. If the emulated floppy try to allocate 1.44M of space, probably you are consuming all the RAM left. Chech if malloc returns NULL too. Some program can omitt this assuming to run with system with a lot of phisical ram (and maybe vram)
     
  11. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    Yes, it is a trade off. It is an easy way to see if it is the issue though.
    Does this really impact code size? I thought it just used main memory for the stack - maybe that is what you meant though?
     
  12. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    C64 floppys are only 170k

    — Posts automatically merged - Please don't double post! —

    Where abouts would I have to do this exactly?
     
  13. Coto

    Coto GBAtemp Addict

    Member
    2,353
    403
    Jun 4, 2010
    Chile
    just passing by to say:

    are you allocating memory somewhere? what is the memory allocation mechanism used? if malloc, you need to free once unused. The sbrk takes linear memory as source. Otherwise it's returning return (void *) -1; (0xffffffff). Also, if you allocate memory marked as used by other process (MMU level) or simply empty the linear memory, and try to access, it will raise data aborts.

    So basically, check where you are allocating memory, and on exit, make sure to identify the thread that allocated memory, so it is freed.

    also for "unmapped read32", that's a hint for some emulator layer, that says you are trying to access an invalid access as 3DS hardware/emulator so it definitely won't work.
     
  14. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    on an unrelated note, how do I know if I'm running at full clock speed on n3ds? is there something I can set for that?

    [edit]
    I have tracked the cause of the issue to this...
    Code:
                    // set current disk
                    Prefs *prefs = new Prefs(ThePrefs);
                    strcpy(prefs->DrivePath[0], filelist[currentFile]);
                    this->NewPrefs(prefs);
                    ThePrefs = *prefs;
                    delete prefs;
    
    Can anyone see anything wrong with that? because to tell the truth, I'm not 100% sure what it's doing.
     
    Last edited by spinal_cord, Aug 22, 2017
  15. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    As a note there is a region of memory on the 3ds that is referred to by the name "linear". This is different from main memory used by malloc - where linear can be used to describe the memory as sequential. On the 3ds the memory for malloc is referred too as "main".
     
  16. Coto

    Coto GBAtemp Addict

    Member
    2,353
    403
    Jun 4, 2010
    Chile
    But that will still mean Malloc using linear memory. (as of newlib ), that's a requisite. Thus, requiring to be freed to be properly re-allocated later. Otherwise you get an invalid pointer.

    So if either "main" or "linear" memory is used in malloc implementation, those should be linear. If the other is non-linear then a custom allocator, non newlib standard, must be used. And by quickly looking at the ctrulib allocator it is already implemented.
     
  17. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    I have no idea what point your are trying to make.
     
  18. Coto

    Coto GBAtemp Addict

    Member
    2,353
    403
    Jun 4, 2010
    Chile
    basically this:

    The bold part means invalid pointer allocated. Now: If data abort == "main" memory, if no data abort but crashes, could very well be "linear" region address.
    edit: invalid pointer from linear memory comes from not freed memory earlier.

    But yeah, it was an idea.
     
    Last edited by Coto, Aug 22, 2017
  19. spinal_cord

    spinal_cord Knows his stuff

    Member
    3,010
    580
    Jul 21, 2007
    somewhere
    Is there a really basic example of a file selector around somewhere? There's obviously something very wrong with what I'm using.
     
  20. nop90

    nop90 GBAtemp Maniac

    Member
    1,406
    2,108
    Jan 11, 2014
    Italy
    Rome
    If a simple selecor made using the console is ok, look at the code Neopop SDL on my github and gram menu.c and menu.h. But remove the global variable used to check if the emulator is already started.
    There are some option configurator menu. You can delete them or change the structure for your needs. It should be easy to adapt.