Results 1 to 2 of 2

Thread: InterProcess Communications Unit (IPC)

  1. #1

    InterProcess Communications Unit (IPC)

    Try this one for your Nintendo DS. (should actually be read as "interprocessor" ... ^^)

    Code:
    Unit Talk;
     // (c) 21o6. :)
    {$IFDEF ARM9}{$APPTYPE ARM9}{$ENDIF}
    {$IFDEF ARM7}{$APPTYPE ARM7}{$ENDIF}
    {$MODE OBJFPC}
    
    InterFace
    Type
      DWord = LongInt;
    
    Const
      Tell : ^DWord = Pointer($04000188);
      Told : ^DWord = Pointer($04100000);
    
    Procedure InitTalk;
    Function Listen4Told : Boolean;
    Procedure Wait4Told;
    
    Function CheckSync : Boolean;
    
    Implementation
    Const
      FIFOControl : ^Word = Pointer($04000184);
    
      bFIFONoSend    = 0;
      bFIFOSendFull  = 1 shl 1;
      bFIFOSendIRQ   = 1 shl 2;
      bFIFOSendClear = 1 shl 3;
      bFIFORecTest   = 1 shl 8;
      bFIFORecFull   = 1 shl 9;
      bFIFORecIRQ    = 1 shl 10;
      bFIFOError     = 1 shl 14;
      bFIFOEnable    = 1 shl 15;
    
    Procedure InitTalk;
    Begin
      FIFOControl^ := bFIFOEnable OR bFIFOSendClear;
    End;
    
    Function Listen4Told : Boolean;
    Begin
      If (Boolean(FIFOControl^ AND bFIFORecTest) = False) then
        Listen4Told := True;
    End;
    
    Procedure Wait4Told;
    Begin
      Repeat Until Boolean(FIFOControl^ AND bFIFORecTest) = False;
    End;
    
    Function CheckSync : Boolean;
    Begin
      If (Boolean(FIFOControl^ and bFIFOSendFull) = False) then CheckSync := True
        Else CheckSync := False;
    End;
    
    End.
    It SHOULD work out of the box. I've found my old sources on an HDD i had lying around for ages
    and copied all this stuff to my main HDD.

    You may want to check this site -> http://double.co.nz/nintendo_ds/nds_develop7.html
    to read up about the constants and why it's 04100000 and such. ^^


    How it works:

    You just put Talk into your "uses" and it's done.
    Same unit works for both processors, so there's nothing to care about either.

    i believe the names of the procedures are rather self explanatory,
    or at least understandable after first try.

    Anyway, of course i'll give you an example.

    For the ARM7 CPU:
    Code:
    {$APPTYPE ARM7}
    {$DEFINE ARM7}
    {$MODE OBJFPC}
    Var
      MyEar : longint;
    
    Begin
      InitTalk;
    
      Tell^ := 19;
      
      Wait4Talk;
    
      MyEar := Told^;
    
      Tell^ := MyEar;
    
      While True do;
     End.

    ... and the ARM9:
    Code:
    {$APPTYPE ARM9}
    {$DEFINE ARM9}
    {$MODE OBJFPC}
    
    Begin
      InitTalk;
    
      Repeat Until Told^ = 19;
    
      Tell^ := $2106;
    
      Repeat until Told^ = $2106;
    
      While True do;
     End;

    This should work. It was written a long time ago and i can't even test it now.

    Explanation: (xD)
    7 tells 9 19 while 9 waits to get 19 told by 7, then 9 tells 7 $2106 and starts waiting for it's echo,
    which 7 will tell 9 in a flash after the next few cycles.

    Please remember that you can actually use any memory address for IPC you like,
    as long as you can make sure that both processors can address it
    and that you don't modify any memory you shouldn't. :)

    Tell me if it worked, thanks. :)
    Last edited by 21o6; 05-01-2012 at 11:06 PM.

  2. #2
    Oh and please also note that the examples are not bound to their processors.

    They work the other way round too.

    (i'm missing an EDIT TOPIC button xD)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •