DSTwo programming tips

Discussion in 'Supercard SDK' started by asiekierka, Jan 2, 2011.

Jan 2, 2011

DSTwo programming tips by asiekierka at 11:11 AM (4,093 Views / 1 Likes) 5 replies

  1. asiekierka
    OP

    Newcomer asiekierka Advanced Member

    Joined:
    Sep 26, 2007
    Messages:
    83
    Location:
    Poland
    Country:
    Poland
    Hello. This is a small list of tips for DSTwo programmers. Seeing as the SDK is not the best, you may need them.

    1. You really should include ds2_malloc.h if you use malloc() and others.
    Why? Because by default it'll use the GCC standard libraries, which have a broken malloc(). ds2_malloc.h adds the DSTwo-specific malloc functions.
    A similar situation is to include fs_api.h if you use fopen()...

    2. stat() does not exist.
    Workaround: Use opendir()/closedir() and readdir_ex() to get the stat data.

    3. For directory functions, the directory should be "fat:/", "fat:/dir0" or "fat:" and not "fat:/dir0/"

    If you know any other tips, feel free to mention them here!
     
    Margen67 likes this.
  2. spinal_cord

    Member spinal_cord Knows his stuff

    Joined:
    Jul 21, 2007
    Messages:
    2,871
    Location:
    somewhere
    Country:
    United Kingdom
    Don't forget the CPU speed settings as calculated by BassAceGold -

    speed 0 - 120 mhz
    speed 1 - 120 mhz
    speed 2 - freezes, couldn't get a clock speed
    speed 3 - 144 mhz
    speed 4 - 192 mhz
    speed 5 - 204 mhz -unstable, freezes in actual use but somehow survived my loop to get a reading
    speed 6 - 240 mhz
    speed 7 - 264 mhz -unstable, really low performance
    speed 8 - 288 mhz
    speed 9 - 300 mhz
    speed 10 - 336 mhz
    speed 11 - 360 mhz
    speed 12 - 384 mhz
    speed 13 - 396 mhz

    Quite handy to know.
     
    Margen67 likes this.
  3. Jaylen

    Newcomer Jaylen Member

    Joined:
    Mar 14, 2009
    Messages:
    41
    Location:
    Michigan, USA
    Country:
    United States
    if speeds 2, 5, and 7 are problematic speeds, does the performance actually lower as you go up?
    it says that speed 7 has low performance, so does that get inherited as you go up, or by some weird anomaly it actually works again as you go up?

    i thought 360Mhz was the official clock speed...can you overclock it?
     
  4. BassAceGold

    Member BassAceGold Testicles

    Joined:
    Aug 14, 2006
    Messages:
    494
    Country:
    Canada
    It is just some weird issue with the clock speeds, they do not affect the other speeds. However results could vary on hardware.

    360mhz is the most widely used clock speed in the Supercard plugins but 396 is the highest it can go with no issues.
     
    Margen67 likes this.
  5. Rydian

    Member Rydian Resident Furvert™

    Joined:
    Feb 4, 2010
    Messages:
    27,883
    Location:
    Cave Entrance, Watching Cyan Write Letters
    Country:
    United States
    Margen67 likes this.
  6. Pate

    Member Pate GBAtemp Regular

    Joined:
    Dec 23, 2010
    Messages:
    108
    Country:
    Finland
    Sorry about my blog being so disorganized regarding the DSTwo SDK info..

    About the CPU speeds, the first level 0 seems to work somewhat strangely. In the SDK demo program (and in BAG's list) the speed is 120MHz, however in my DS2x86 the speed gets set to 60MHz when using speed level 0. I also hacked together a small ASM code to return the current CPU speed as an integer, using the same method as the stupid printf_clock() function uses.

    Code:
    ÂÂÂÂ//------
    ÂÂÂÂ// Called from the C code. Get the current CPU speed in MHz.
    ÂÂÂÂ//------
    ÂÂÂÂ.globalÂÂÂÂGetCPUSpeed
    ÂÂÂÂ.typeÂÂÂÂGetCPUSpeed,@function
    GetCPUSpeed:
    ÂÂÂÂlaÂÂÂÂa0, printf_clockÂÂÂÂÂÂÂÂ// Get address of the function
    ÂÂÂÂlhuÂÂÂÂa1, 0(a0)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ// High halfword of the "_pllout" variable address
    ÂÂÂÂlhÂÂÂÂa0, 4(a0)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ// a0 = signed low halfword of the "_pllout" address
    ÂÂÂÂsllÂÂÂÂa1, 16
    ÂÂÂÂadduÂÂÂÂa1, a0
    ÂÂÂÂlwÂÂÂÂa1, 4(a1)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ// a1 = _pllout value
    ÂÂÂÂluiÂÂÂÂv0, 0x431b
    ÂÂÂÂoriÂÂÂÂv0, v0, 0xde83
    ÂÂÂÂmultuÂÂÂÂa1, v0ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
    ÂÂÂÂmfhiÂÂÂÂv0
    ÂÂÂÂsrlÂÂÂÂv0, v0, 0x12
    ÂÂÂÂjrÂÂÂÂra
    Pate
     
    Margen67 likes this.

Share This Page