English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 06 August 2011, 04:35   #1
8bitbubsy
Registered User

8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,304
[SAS/C] Making malloc() allocate in fast RAM instead of chip RAM?

How do I do this? I am using SAS/C 6.58 and I'm programming an application that I want to use fast RAM!

My S3M loader seems to just crash in the sample loader...
It managed to allocate all the sample data memory, but somehow after reading X amounts of bytes (quite many too) fread() returns 0 as in no byte read/written to buffer, then the Amiga crash. What the..?
I use the SAS/C "cpr" debugger, and traced through the code and found out that it indeed crashes in the sample load loop, but only in the middle of the reading -- not on first sample etc.

This is weird, it allocates all the sample data (200kB+) but fails in the read/write loop, maybe I need to set some special compiler switches to access over 65535 bytes or to make it fast RAM "compatible"?
8bitbubsy is offline  
Old 06 August 2011, 15:16   #2
Ed Cruse
Registered User
 
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 66
Posts: 351
Quote:
Originally Posted by 8bitbubsy View Post
How do I do this? I am using SAS/C 6.58 and I'm programming an application that I want to use fast RAM!

My S3M loader seems to just crash in the sample loader...
It managed to allocate all the sample data memory, but somehow after reading X amounts of bytes (quite many too) fread() returns 0 as in no byte read/written to buffer, then the Amiga crash. What the..?
I use the SAS/C "cpr" debugger, and traced through the code and found out that it indeed crashes in the sample load loop, but only in the middle of the reading -- not on first sample etc.

This is weird, it allocates all the sample data (200kB+) but fails in the read/write loop, maybe I need to set some special compiler switches to access over 65535 bytes or to make it fast RAM "compatible"?

Malloc() should allocate from fast ram first and then chip ram. If you are getting chip ram then there's probably no chunks of contigous fast ram big enough for the allocation.

I've never had a problem with my SAS/C not going over the 16 bit limit and I don't remember ever having to tell it to.
Ed Cruse is offline  
Old 06 August 2011, 16:15   #3
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,265
Probably an error in your code, but if slowmem and chipmem will not do (though they should) and you must have fastmem, then use AllocMem:

Code:
#include <exec/memory.h>
#include <clib/exec_protos.h>

APTR ptr = AllocMem(1000, MEMF_FAST);

if(ptr != NULL)
  FreeMem(ptr, 1000);
EDIT: this may allocate slowmem too of course since AmigaOS treats them the same, but it does avoid chipmem if you think that's what's causing the error.

Last edited by Leffmann; 06 August 2011 at 22:52.
Leffmann is offline  
Old 07 August 2011, 07:06   #4
8bitbubsy
Registered User

8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,304


I'm such an idiot. You know, endianness on 68k.
I read shorts and ints from a file that was made on DOS, without swapping the nybbles. It all works now.

Also, the 65535 code boundary got fixed by setting CODE=FAR in the compilation option.

Life saver (so slow it's only good to use it in loaders):
Code:
void swap16(unsigned short *data)
{
    *data = (*data >> 8) | (*data << 8);
}

void swap32(unsigned int *data)
{
    *data = (*data >> 24)
    | ((*data << 8) & 0x00FF0000)
    | ((*data >> 8) & 0x0000FF00)
    | (*data << 24);
}

Last edited by 8bitbubsy; 07 August 2011 at 09:50.
8bitbubsy is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
A600 w/ 1MB Chip + 4MB Fast Ram = WHDLoad success rate? Kenan support.Hardware 7 08 May 2013 18:14
Allocating Fast RAM as Chip? Fingerlickin_B support.Hardware 22 20 November 2008 22:15
Could not allocate 'shadow ram'? NovaCoder project.WHDLoad 4 28 August 2008 01:09
32-bit FAST RAM vs. ZII FAST RAM polbit support.Hardware 16 28 January 2007 20:16
Set Chip and Fast RAM in WinUAE nineoc New to Emulation or Amiga scene 17 20 September 2006 09:25

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:23.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06068 seconds with 13 queries