rem: FreeMem( location, size ); printf( "Out of memory!\n" );
add: pd->m_ChipFreq = 3579545;
context: AllocPUH( void ){  struct PUHData* pd      = NULL;  struct GfxBase* gfxbase = NULL;  if( MMUBase == NULL )  {    printf( "MMUBase not initialized!\n" );    return NULL;  }  if( AHIBase == NULL )  {    printf( "AHIBase not initialized!\n" );    return NULL;  }  gfxbase = (struct GfxBase*) OpenLibrary( GRAPHICSNAME, 39 );    if( GetMMUType() == MUTYPE_NONE )  {    printf( "This program requires an MMU.\n" );  }  else  {    struct MMUContext* uctx;    struct MMUContext* sctx;    struct MMUContext* ctxs[ 3 ];    void*              location;    ULONG              page_size;    ULONG              size;    // Get default and supervisor contexts    uctx = DefaultContext();    sctx = SuperContext( uctx );    ctxs[ 0 ] = uctx;    ctxs[ 1 ] = sctx;    ctxs[ 2 ] = NULL;    page_size = max( GetPageSize( uctx ), GetPageSize( sctx ) );    // Allocate memory for the re-mapped registers    size = ( ( 0x200 - 1 ) / page_size + 1 ) * page_size;    location = AllocAligned( size,                              MEMF_PUBLIC | MEMF_CLEAR,                             page_size );    if( location == NULL )    {      printf( "Out of memory!\n" );    }    else    {      pd = (struct PUHData*) AllocVec( sizeof( struct PUHData ),                                       MEMF_PUBLIC | MEMF_CLEAR );      if( pd == NULL )      {        FreeMem( location, size );        printf( "Out of memory!\n" );      }      else      {        void* rom_start    = NULL;        ULONG rom_size     = NULL;        // Get location of Kickstart ROM          rom_size  = *( (ULONG*) ( ROMEND - MAGIC_ROMEND ) );        rom_start = ( (UBYTE*) ROMEND ) - rom_size;        pd->m_Active               = FALSE;        pd->m_AudioMode            = AHI_INVALID_ID;        pd->m_SoundFunc.h_Entry    = (ULONG(*)(void)) PUHSoundFunc;        pd->m_SoundFunc.h_Data     = pd;        if( gfxbase != NULL &&             ( gfxbase->DisplayFlags & REALLY_PAL ) == 0 )        {          // NTSC          pd->m_ChipFreq = 3579545;        }        else        {          // PAL          pd->m_ChipFreq = 3546895;        }#ifdef TEST_MODE        pd->m_Intercepted          = location;        pd->m_Custom               = (void*) 0xdff000;#else        pd->m_Intercepted          = (void*) 0xdff000;        pd->m_Custom               = location;#endif        pd->m_UserContext          = uctx;                pd->m_SuperContext         = sctx;        pd->m_UserException        = NULL;                pd->m_SuperException       = NULL;        pd->m_ROM                  = rom_start;        pd->m_ROMShadowBuffer      = NULL;        pd->m_CustomShadowBuffer   = location;        pd->m_ROMSize              = rom_size;        pd->m_CustomSize           = size;        pd->m_SoftInt.is_Node.ln_Type = NT_INTERRUPT;        pd->m_SoftInt.is_Node.ln_Pri  = 32;        pd->m_SoftInt.is_Node.ln_Name = "NallePUH Level 4 emulation";        pd->m_SoftInt.is_Data         = pd;        pd->m_SoftInt.is_Code         = (void(*)(void)) PUHSoftInt;      }    }  }  CloseLibrary( (struct Library*) gfxbase );  return pd;}