瀏覽代碼

--- Merging r16275 into '.':
U rtl/nds/prt09.as
U rtl/nds/cprt07.as
U rtl/nds/cprt09.as
U rtl/nds/sysdir.inc
U rtl/nds/sysutils.pp
U rtl/nds/prt07.as
--- Merging r16275 into 'tests/utils':
G tests/utils
--- Merging r16275 into '.':
U compiler/systems/t_nds.pas
U compiler/systems/t_gba.pas
U packages/libndsfpc/src/nds/ndstypes.inc
U packages/libndsfpc/src/nds/interrupts.inc
U packages/libndsfpc/src/nds/system.inc
U packages/libndsfpc/src/nds/nds.inc
U packages/libndsfpc/src/nds/ndsinclude.inc
U packages/libndsfpc/src/nds/arm9/exceptions.inc
U packages/libndsfpc/src/nds/arm9/input.inc
U packages/libndsfpc/src/nds/arm9/sprite.inc
U packages/libndsfpc/src/nds/arm9/video.inc
U packages/libndsfpc/src/dswifi/inc/dswifi_version.inc
U packages/libndsfpc/examples/audio/maxmod/song_events_example2/song_events_example2.pp
U packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile.fpc
C packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile
G .
--- Merging r16276 into 'tests/utils':
G tests/utils
--- Merging r16276 into '.':
G packages/libndsfpc/src/nds/system.inc
A packages/libndsfpc/src/nds/input.inc
U packages/libndsfpc/src/nds/arm9/background.inc
U packages/libndsfpc/src/nds/arm9/console.inc
G packages/libndsfpc/src/nds/arm9/sprite.inc
G packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile.fpc
G .
--- Merging r16277 into '.':
U rtl/nds/Makefile.fpc
U rtl/nds/system.pp
C rtl/nds/Makefile
--- Merging r16277 into 'tests/utils':
G tests/utils
--- Merging r16277 into '.':
U packages/libndsfpc/src/nds/registers_alt.inc
U packages/libndsfpc/src/nds/memory.inc
U packages/libndsfpc/src/nds/card.inc
U packages/libndsfpc/src/nds/fifomessages.inc
G packages/libndsfpc/src/nds/system.inc
G packages/libndsfpc/src/nds/nds.inc
U packages/libndsfpc/src/nds/debug.inc
G packages/libndsfpc/src/nds/ndsinclude.inc
U packages/libndsfpc/src/nds/fifocommon.inc
U packages/libndsfpc/src/nds/bios.inc
U packages/libndsfpc/src/nds/arm7/serial.inc
U packages/libndsfpc/src/nds/arm7/touch.inc
D packages/libndsfpc/src/nds/linkedlist.inc
D packages/libndsfpc/src/nds/dynamicArray.inc
G packages/libndsfpc/src/nds/arm9/background.inc
A packages/libndsfpc/src/nds/arm9/dynamicArray.inc
U packages/libndsfpc/src/nds/arm9/videoGL.inc
U packages/libndsfpc/src/nds/arm9/pcx.inc
U packages/libndsfpc/src/nds/arm9/keyboard.inc
A packages/libndsfpc/src/nds/arm9/linkedlist.inc
U packages/libndsfpc/src/nds/arm9/decompress.inc
G packages/libndsfpc/src/nds/arm9/sprite.inc
G packages/libndsfpc/src/nds/arm9/video.inc
U packages/libndsfpc/src/nds/timers.inc
U packages/libndsfpc/src/nds7.pp
U packages/libndsfpc/src/nds9.pp
C packages/libndsfpc/Makefile
G .
Summary of conflicts:
Text conflicts: 3

git-svn-id: tags/release_2_4_2@16278 -

marco 15 年之前
父節點
當前提交
fcc061aaee
共有 47 個文件被更改,包括 792 次插入464 次删除
  1. 3 2
      .gitattributes
  2. 10 2
      compiler/systems/t_gba.pas
  3. 14 5
      compiler/systems/t_nds.pas
  4. 1 1
      packages/libndsfpc/Makefile
  5. 2 3
      packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile
  6. 1 2
      packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile.fpc
  7. 2 3
      packages/libndsfpc/examples/audio/maxmod/song_events_example2/song_events_example2.pp
  8. 2 2
      packages/libndsfpc/src/dswifi/inc/dswifi_version.inc
  9. 1 2
      packages/libndsfpc/src/nds/arm7/serial.inc
  10. 2 0
      packages/libndsfpc/src/nds/arm7/touch.inc
  11. 26 7
      packages/libndsfpc/src/nds/arm9/background.inc
  12. 2 1
      packages/libndsfpc/src/nds/arm9/console.inc
  13. 3 3
      packages/libndsfpc/src/nds/arm9/decompress.inc
  14. 6 50
      packages/libndsfpc/src/nds/arm9/dynamicArray.inc
  15. 3 3
      packages/libndsfpc/src/nds/arm9/exceptions.inc
  16. 0 20
      packages/libndsfpc/src/nds/arm9/input.inc
  17. 18 0
      packages/libndsfpc/src/nds/arm9/keyboard.inc
  18. 2 45
      packages/libndsfpc/src/nds/arm9/linkedlist.inc
  19. 1 1
      packages/libndsfpc/src/nds/arm9/pcx.inc
  20. 30 22
      packages/libndsfpc/src/nds/arm9/sprite.inc
  21. 75 9
      packages/libndsfpc/src/nds/arm9/video.inc
  22. 71 6
      packages/libndsfpc/src/nds/arm9/videoGL.inc
  23. 9 7
      packages/libndsfpc/src/nds/bios.inc
  24. 13 17
      packages/libndsfpc/src/nds/card.inc
  25. 1 0
      packages/libndsfpc/src/nds/debug.inc
  26. 3 0
      packages/libndsfpc/src/nds/fifocommon.inc
  27. 2 1
      packages/libndsfpc/src/nds/fifomessages.inc
  28. 65 0
      packages/libndsfpc/src/nds/input.inc
  29. 26 13
      packages/libndsfpc/src/nds/interrupts.inc
  30. 4 4
      packages/libndsfpc/src/nds/memory.inc
  31. 14 4
      packages/libndsfpc/src/nds/nds.inc
  32. 6 6
      packages/libndsfpc/src/nds/ndsinclude.inc
  33. 1 1
      packages/libndsfpc/src/nds/ndstypes.inc
  34. 4 4
      packages/libndsfpc/src/nds/registers_alt.inc
  35. 77 40
      packages/libndsfpc/src/nds/system.inc
  36. 71 52
      packages/libndsfpc/src/nds/timers.inc
  37. 1 1
      packages/libndsfpc/src/nds7.pp
  38. 1 1
      packages/libndsfpc/src/nds9.pp
  39. 60 90
      rtl/nds/Makefile
  40. 1 1
      rtl/nds/Makefile.fpc
  41. 2 1
      rtl/nds/cprt07.as
  42. 12 0
      rtl/nds/cprt09.as
  43. 2 1
      rtl/nds/prt07.as
  44. 12 0
      rtl/nds/prt09.as
  45. 9 6
      rtl/nds/sysdir.inc
  46. 120 24
      rtl/nds/system.pp
  47. 1 1
      rtl/nds/sysutils.pp

+ 3 - 2
.gitattributes

@@ -3551,10 +3551,12 @@ packages/libndsfpc/src/nds/arm9/cache.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/console.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/decompress.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/dldi.inc svneol=native#text/plain
+packages/libndsfpc/src/nds/arm9/dynamicArray.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/exceptions.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/image.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/input.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/keyboard.inc svneol=native#text/plain
+packages/libndsfpc/src/nds/arm9/linkedlist.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/math.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/ndsmotion.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/arm9/pcx.inc svneol=native#text/plain
@@ -3571,14 +3573,13 @@ packages/libndsfpc/src/nds/card.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/debug.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/disc_io.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/dma.inc svneol=native#text/plain
-packages/libndsfpc/src/nds/dynamicArray.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/fifocommon.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/fifomessages.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/helper.inc svneol=native#text/plain
+packages/libndsfpc/src/nds/input.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/interrupts.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/ipc.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/jtypes.inc svneol=native#text/plain
-packages/libndsfpc/src/nds/linkedlist.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/memory.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/nds.inc svneol=native#text/plain
 packages/libndsfpc/src/nds/ndsinclude.inc svneol=native#text/plain

+ 10 - 2
compiler/systems/t_gba.pas

@@ -429,13 +429,21 @@ begin
       add('	__init_lma = __preinit_lma + SIZEOF(.preinit_array);');
       add('');
       add('	PROVIDE (__init_array_start = .);');
-      add('	.init_array     : AT (__init_lma) { KEEP (*(.init_array)) } >iwram');
+      add('	.init_array     : AT (__init_lma)');
+      add('	{');
+      add('		KEEP (*(SORT(.init_array.*)))');
+      add('		KEEP (*(.init_array))');
+      add('	} >iwram');
       add('	PROVIDE (__init_array_end = .);');
       add('	PROVIDE (__fini_array_start = .);');
       add('');
       add('	__fini_lma = __init_lma + SIZEOF(.init_array);');
       add('');
-      add('	.fini_array     : AT (__fini_lma) { KEEP (*(.fini_array)) } >iwram');
+      add('	.fini_array     : AT (__fini_lma)');
+      add('	{');
+      add('		KEEP (*(SORT(.fini_array.*)))');
+      add('		KEEP (*(.fini_array))');
+      add('	} >iwram');
       add('  	PROVIDE (__fini_array_end = .);');
       add('');
       add('	__jcr_lma = __fini_lma + SIZEOF(.fini_array);');

+ 14 - 5
compiler/systems/t_nds.pas

@@ -325,10 +325,18 @@ begin
         add('  .preinit_array     : { KEEP (*(.preinit_array)) } >ewram = 0xff');
         add('  PROVIDE (__preinit_array_end = .);');
         add('  PROVIDE (__init_array_start = .);');
-        add('  .init_array     : { KEEP (*(.init_array)) } >ewram = 0xff');
+        add('  .init_array     :');
+        add('  {');
+        add('       KEEP (*(SORT(.init_array.*)))');
+        add('       KEEP (*(.init_array))');
+        add('  } >ewram = 0xff');        
         add('  PROVIDE (__init_array_end = .);');
         add('  PROVIDE (__fini_array_start = .);');
-        add('  .fini_array     : { KEEP (*(.fini_array)) } >ewram = 0xff');
+        add('  .fini_array     :');
+        add('  {');
+        add('       KEEP (*(.fini_array))');
+        add('       KEEP (*(SORT(.fini_array.*)))');
+        add('  } >ewram = 0xff');
         add('  PROVIDE (__fini_array_end = .);');
         add('');
         add('	.ctors :');
@@ -504,12 +512,13 @@ begin
         add('');
         add('__iwram_start	=	ORIGIN(iwram);');
         add('__iwram_top	=	ORIGIN(iwram)+ LENGTH(iwram);');
-        add('__sp_irq	=	__iwram_top - 0x60;');
+        add('__sp_irq	=	__iwram_top - 0x100;');
         add('__sp_svc	=	__sp_irq - 0x100;');
         add('__sp_usr	=	__sp_svc - 0x100;');
         add('');
-        add('__irq_flags	=	__iwram_top - 8;');
-        add('__irq_vector	=	__iwram_top - 4;');
+        add('__irq_flags	=	0x04000000 - 8;');
+        add('__irq_flagsaux	=	0x04000000 - 0x40;');
+        add('__irq_vector	=	0x04000000 - 4;');
         add('');
         add('SECTIONS');
         add('{');

+ 1 - 1
packages/libndsfpc/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/10/28]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/09/26]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux

+ 2 - 3
packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/10/28]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/12/24]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux
@@ -2539,8 +2539,7 @@ include fpcmake.loc
 endif
 .NOTPARALLEL:
 all: direc fpc_all 
-<<<<<<< .mine=======
->>>>>>> .theirsdirec:
+direc:
 ifneq ($(BUILD), $(CURDIR))
 	$(MKDIR) $(BUILD)
 endif

+ 1 - 2
packages/libndsfpc/examples/audio/maxmod/audio_modes/Makefile.fpc

@@ -32,8 +32,7 @@ GFX_FILES = $(foreach dir,gfx,$(notdir $(wildcard $(dir)/*.png)))
 [rules]
 .NOTPARALLEL:
 all: direc fpc_all 
-<<<<<<< .mine=======
->>>>>>> .theirsdirec:
+direc:
 ifneq ($(BUILD), $(CURDIR))
         $(MKDIR) $(BUILD)
 endif

+ 2 - 3
packages/libndsfpc/examples/audio/maxmod/song_events_example2/song_events_example2.pp

@@ -37,9 +37,8 @@ var
   sprites: array[0..4] of MySprite;
 
 
-<<<<<<< .minefunction myEventHandler(msg, param: mm_word): mm_word;
-=======function myEventHandler(msg, param: mm_word): pmm_word;
->>>>>>> .theirsbegin
+function myEventHandler(msg, param: mm_word): mm_word;
+begin
   case msg of
     MMCB_SONGMESSAGE:	// process song messages
     begin

+ 2 - 2
packages/libndsfpc/src/dswifi/inc/dswifi_version.inc

@@ -2,6 +2,6 @@
 const
   DSWIFI_MAJOR    = 0;
   DSWIFI_MINOR    = 3;
-  DSWIFI_REVISION = 11;
-  DSWIFI_VERSION  = '0.3.11';
+  DSWIFI_REVISION = 12;
+  DSWIFI_VERSION  = '0.3.12';
 {$endif NDS_INTERFACE}

+ 1 - 2
packages/libndsfpc/src/nds/arm7/serial.inc

@@ -117,7 +117,6 @@ procedure readFirmware(address: cuint32; destination: pointer; size: cuint32); c
 {$ifdef NDS_IMPLEMENTATION}
 procedure SerialWaitBusy(); inline;
 begin
-  while (REG_SPICNT^ and SPI_BUSY) <> 0 do 
-    swiDelay(1); 
+  while (REG_SPICNT^ and SPI_BUSY) <> 0 do; 
 end;
 {$endif NDS_IMPLEMENTATION}

+ 2 - 0
packages/libndsfpc/src/nds/arm7/touch.inc

@@ -62,4 +62,6 @@ procedure touchReadXY(var touchPos: touchPosition); cdecl; external;
 
 function touchRead(command: cuint32): cuint16; cdecl; external;
 function touchReadTemperature(t1: pcint; t2: pcint): cuint32;  cdecl; external;
+
+function touchPenDown(): cbool; cdecl; external;
 {$endif NDS_INTERFACE}

+ 26 - 7
packages/libndsfpc/src/nds/arm9/background.inc

@@ -48,10 +48,10 @@ type
   Pbg_scroll = ^bg_scroll;
 
   bg_transform = record
-    xdx: cint16;
-    xdy: cint16;
-    ydx: cint16;
-    ydy: cint16;
+    hdx: cint16;
+    vdx: cint16;
+    hdy: cint16;
+    vdy: cint16;
     dx: cint32;
     dy: cint32;
   end;
@@ -184,7 +184,7 @@ const
   REG_BG1CNT_SUB		: pcuint16 = pointer($400100A);
   REG_BG2CNT_SUB		: pcuint16 = pointer($400100C);
   REG_BG3CNT_SUB		: pcuint16 = pointer($400100E);
-  
+
   REG_BGOFFSETS_SUB	: pcuint16 = pointer($4001010);
   REG_BG0HOFS_SUB		: pcuint16 = pointer($4001010);
   REG_BG0VOFS_SUB		: pcuint16 = pointer($4001012);
@@ -304,6 +304,7 @@ procedure bgShow(id: cint); inline;
 procedure bgHide(id: cint); inline;
 procedure bgSetCenterf(id: cint; x, y: cint32); inline;
 procedure bgSetCenter(id, x, y: cint); inline;
+procedure bgSetAffineMatrixScroll(id, hdx, vdx, hdy, vdy, scrollx, scrolly: cint); inline;
 
 {$endif NDS_INTERFACE}
 
@@ -450,6 +451,7 @@ end;
 
 function bgSetControlBits(id: cint; bits: cuint16): pcuint16; inline;
 begin
+	sassert( (id >= 0) and (id <= 7), 'bgSetControlBits(), id must be the number returned from bgInit or bgInitSub');
   bgControl[id]^ := bgControl[id]^ or bits;
   result := bgControl[id];
 end;  
@@ -541,7 +543,7 @@ end;
 
 function bgGetTileBase(id: cint): cint; inline;
 begin
-  result := (bgControl[id]^ shr TILE_BASE_SHIFT) and 31;
+  result := (bgControl[id]^ shr TILE_BASE_SHIFT) and 15;
 end;
 
 function bgGetMapPtr(id: cint): pcuint16; inline;
@@ -576,7 +578,7 @@ end;
 
 procedure bgScroll(id, dx, dy: cint); inline;
 begin
-  bgSetScrollf(id, dx shl 8, dy shl 8);
+  bgScrollf(id, dx shl 8, dy shl 8);
 end;
 
 procedure bgShow(id: cint); inline;
@@ -608,4 +610,21 @@ begin
   bgSetCenterf(id, x shl 8, y shl 8);
 end;
 
+procedure bgSetAffineMatrixScroll(id, hdx, vdx, hdy, vdy, scrollx, scrolly: cint); inline;
+begin
+  sassert(not bgIsText(id), 'Text Backgrounds have no affine matrix and scroll registers.');
+
+  bgTransform[id]^.hdx := hdx;
+  bgTransform[id]^.vdx := vdx;
+  bgTransform[id]^.hdy := hdy;
+  bgTransform[id]^.vdy := vdy;
+  
+  bgTransform[id]^.dx := scrollx;
+  bgTransform[id]^.dy := scrolly;
+  
+  bgState[id].dirty := false;
+end;
+
+
+
 {$endif NDS_IMPLEMENTATION}

+ 2 - 1
packages/libndsfpc/src/nds/arm9/console.inc

@@ -105,7 +105,8 @@ type
 type
   DebugDevice = integer;
 const
-  DebugDevice_NOCASH: DebugDevice = $01;
+  DebugDevice_NULL: DebugDevice = $0;
+  DebugDevice_NOCASH: DebugDevice = $1;
   DebugDevice_CONSOLE: DebugDevice = $02;
   
 

+ 3 - 3
packages/libndsfpc/src/nds/arm9/decompress.inc

@@ -40,9 +40,9 @@
 
 {$ifdef NDS_INTERFACE}
 
-type
-  getByteCallback = function(source: pcuint8): pcuint8;
-  getHeaderCallback = function(source: pcuint8; dest: pcuint16; arg: cuint32): pcint;
+//type
+//  getByteCallback = function(source: pcuint8): pcuint8;
+//  getHeaderCallback = function(source: pcuint8; dest: pcuint16; arg: cuint32): pcint;
 
 type
   DecompressType = integer;

+ 6 - 50
packages/libndsfpc/src/nds/dynamicArray.inc → packages/libndsfpc/src/nds/arm9/dynamicArray.inc

@@ -1,5 +1,5 @@
 (*
-  $Id$
+  $Id: dynamicArray.inc 13585 2009-08-23 13:57:45Z Legolas $
   ------------------------------------------------------------------------------
   	Copyright (C) 2005
   		Jason Rogers (dovoto)
@@ -42,59 +42,15 @@
 type
   DynamicArray = record 
     data: ppointer;  // pointer to array of void pointers
-    cur_size: integer;    // currently allocated size of the array 
+    cur_size: cuint; // currently allocated size of the array 
   end;
   TDynamicArray = DynamicArray;
   PDynamicArray = ^TDynamicArray;
 
 
-function DynamicArrayInit(v: PDynamicArray; initialSize: integer): pointer; inline;
-procedure DynamicArrayDelete(v: PDynamicArray); inline;
-function DynamicArrayGet(v: PDynamicArray; index: integer): pointer; inline;
-procedure DynamicArraySet(v: PDynamicArray; index: integer; item: pointer); inline;
+function DynamicArrayInit(v: PDynamicArray; initialSize: cuint): pointer; cdecl; external;
+procedure DynamicArrayDelete(v: PDynamicArray); cdecl; external;
+function DynamicArrayGet(v: PDynamicArray; index: cuint): pointer; cdecl; external;
+function DynamicArraySet(v: PDynamicArray; index: cuint; item: pointer): cbool; cdecl; external;
 {$endif NDS_INTERFACE}
 
-
-{$ifdef NDS_IMPLEMENTATION}
-function DynamicArrayInit(v: PDynamicArray; initialSize: integer): pointer; inline;
-begin
-	v^.cur_size := initialSize;
-//  v^.data := malloc(sizeof(pointer) * initialSize);
-	GetMem(v^.data, sizeof(pointer) * initialSize);
-  result := v^.data;
-end;
-
-procedure DynamicArrayDelete(v: PDynamicArray); inline;
-begin
-  if (v^.data) <> nil then
-    free(v^.data);
-end;
-
-function DynamicArrayGet(v: PDynamicArray; index: integer): pointer; inline;
-begin
-	if (index >= v^.cur_size) then
-	begin
-		result := nil;
-		exit;
-	end;
-	result := v^.data + index;
-end;
-
-procedure DynamicArraySet(v: PDynamicArray; index: integer; item: pointer); inline;
-var
-  i: integer;
-begin
-	if (index >= v^.cur_size) then 
-	begin
-		v^.data := ReAllocMem(v^.data, sizeof(pointer) * v^.cur_size * 2);
-		FillChar(pointer(integer(v^.data^^) + v^.cur_size)^, sizeof(pointer) * v^.cur_size, 0);
-		v^.cur_size := v^.cur_size * 2;
-	end;
-	{
-	i := integer(v^.data);
-	i := i + index;
-  pointer(i) := item;
-  }
-  v^.data[index] := item;
-end;
-{$endif NDS_IMPLEMENTATION}

+ 3 - 3
packages/libndsfpc/src/nds/arm9/exceptions.inc

@@ -40,15 +40,15 @@
 
 {$ifdef NDS_INTERFACE}
 const
-  EXCEPTION_VECTOR : ^VoidFunctionPointer = pointer($2FFFD9C);
+  EXCEPTION_VECTOR : ^VoidFn = pointer($2FFFD9C);
 
 var
-  exceptionC: ^VoidFunctionPointer; cvar; external;
+  exceptionC: ^VoidFn; cvar; external;
   exceptionStack: cuint32; cvar; external;
   exceptionRegisters: pcint32; cvar; external;
 
 procedure enterException(); cdecl; external;
-procedure setExceptionHandler(handler: VoidFunctionPointer); cdecl; external;
+procedure setExceptionHandler(handler: VoidFn); cdecl; external;
 procedure defaultExceptionHandler(); cdecl; external;
 
 function getCPSR(): cuint32; cdecl; external;

+ 0 - 20
packages/libndsfpc/src/nds/arm9/input.inc

@@ -39,26 +39,6 @@
 *)
 
 {$ifdef NDS_INTERFACE}
-// Keyboard
-type
-  KEYPAD_BITS = cint;
-const
-//!	Bit values for the keypad buttons.
-  KEY_A      : KEYPAD_BITS = (1 shl 0);  // Keypad A button.
-  KEY_B      : KEYPAD_BITS = (1 shl 1);  // Keypad B button.
-  KEY_SELECT : KEYPAD_BITS = (1 shl 2);  // Keypad SELECT button.
-  KEY_START  : KEYPAD_BITS = (1 shl 3);  // Keypad START button.
-  KEY_RIGHT  : KEYPAD_BITS = (1 shl 4);  // Keypad RIGHT button.
-  KEY_LEFT   : KEYPAD_BITS = (1 shl 5);  // Keypad LEFT button.
-  KEY_UP     : KEYPAD_BITS = (1 shl 6);  // Keypad UP button.
-  KEY_DOWN   : KEYPAD_BITS = (1 shl 7);  // Keypad DOWN button.
-  KEY_R      : KEYPAD_BITS = (1 shl 8);  // Right shoulder button.
-  KEY_L      : KEYPAD_BITS = (1 shl 9);  // Left shoulder button.
-  KEY_X      : KEYPAD_BITS = (1 shl 10); // Keypad X button.
-  KEY_Y      : KEYPAD_BITS = (1 shl 11); // Keypad Y button.
-  KEY_TOUCH  : KEYPAD_BITS = (1 shl 12); // Touchscreen pendown.
-  KEY_LID    : KEYPAD_BITS = (1 shl 13); // Lid state.
-
   
 procedure scanKeys(); cdecl; external;
 

+ 18 - 0
packages/libndsfpc/src/nds/arm9/keyboard.inc

@@ -89,6 +89,24 @@ type
   TKeyboard = Keyboard;
   PKeyboard = ^Keyboard;
 
+type
+  TKeys = cint;
+const
+  NOKEY         : TKeys = -1;
+  DVK_FOLD      : TKeys = -23;
+  DVK_TAB       : TKeys =  9;
+  DVK_BACKSPACE : TKeys =  8;
+  DVK_CAPS      : TKeys = -15;
+  DVK_SHIFT     : TKeys = -14;
+  DVK_SPACE     : TKeys =  32;
+  DVK_MENU      : TKeys = -5;
+  DVK_ENTER     : TKeys =  10;
+  DVK_CTRL      : TKeys = -16;
+  DVK_UP        : TKeys = -17;
+  DVK_RIGHT     : TKeys = -18;
+  DVK_DOWN      : TKeys = -19;
+  DVK_LEFT      : TKeys = -20;
+  DVK_ALT       : TKeys = -26;
 
 function keyboardGetDefault(): PKeyboard; cdecl; external;
 

+ 2 - 45
packages/libndsfpc/src/nds/linkedlist.inc → packages/libndsfpc/src/nds/arm9/linkedlist.inc

@@ -37,51 +37,8 @@ type
   end;
   TLinkedList = LinkedList;
 
-function linkedlistAdd(front: PLinkedList; data: pointer): PLinkedList; inline;
-procedure linkedlistRemove(node: PLinkedList); inline;
+function linkedlistAdd(front: PLinkedList; data: pointer): PLinkedList; cdecl; external;
+procedure linkedlistRemove(node: PLinkedList); cdecl; external;
 
 {$endif NDS_INTERFACE}
 
-
-{$ifdef NDS_IMPLEMENTATION}
-function linkedlistAdd(front: PLinkedList; data: pointer): PLinkedList; inline;
-var
-  node: PLinkedList;
-begin
-	GetMem(node, sizeof(LinkedList));
-
-	node^.prev := nil;
-
-	if (front = nil) then
-	begin	
-		node^.next := nil;
-
-		node^.data := data;
-
-		front := node;
-
-		result := node;
-	end;
-    
-	node^.next := front;
-	
-	front^.prev := node;
-
-	result := node;
-end;
-
-
-procedure linkedlistRemove(node: PLinkedList); inline;
-begin
-	if (node = nil) then exit;
-
-	if (node^.prev <> nil) then
-		node^.prev^.next := node^.next;
-
-	if (node^.next <> nil) then
-		node^.next^.prev := node^.prev;
-
-	FreeMem(node);
-end;
-
-{$endif NDS_IMPLEMENTATION}

+ 1 - 1
packages/libndsfpc/src/nds/arm9/pcx.inc

@@ -61,5 +61,5 @@ type
   PPCXHeader = ^PCXHeader;
 
 
-function loadPCX(pcx: pcuchar; image: PsImage): cint; cdecl; external;
+function loadPCX(const pcx: pcuchar; image: PsImage): cint; cdecl; external;
 {$endif NDS_INTERFACE}

+ 30 - 22
packages/libndsfpc/src/nds/arm9/sprite.inc

@@ -86,7 +86,7 @@ function ATTR2_ALPHA(n: cint): cint; inline;
 
 type 
   ObjBlendMode = (
-    BJMODE_NORMAL    = 0, 
+    OBJMODE_NORMAL   = 0, 
     OBJMODE_BLENDED  = 1,
     OBJMODE_WINDOWED = 2,
     OBJMODE_BITMAP   = 3
@@ -193,9 +193,9 @@ type
     filler1: array [0..2] of cuint16;
     hdx: cint16;
     filler2: array [0..2] of cuint16;
-    hdy: cint16;
-    filler3: array [0..2] of cuint16;
     vdx: cint16;
+    filler3: array [0..2] of cuint16;
+    hdy: cint16;
     filler4: array [0..2] of cuint16;
     vdy: cint16;
   end;
@@ -243,17 +243,17 @@ function SPRITE_SIZE_PIXELS(size: cint): cuint32; inline;
 
 
 type
-  SpriteMapping = integer;
+  TSpriteMapping = integer;
 const
-  SpriteMapping_1D_32     : SpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_32)  or (0 shl 28) or 0;
-  SpriteMapping_1D_64     : SpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_64)  or (1 shl 28) or 1;
-  SpriteMapping_1D_128    : SpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_128) or (2 shl 28) or 2;
-  SpriteMapping_1D_256    : SpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_256) or (3 shl 28) or 3;
-  SpriteMapping_2D        : SpriteMapping = integer(DISPLAY_SPR_2D) or (4 shl 28);
-  SpriteMapping_Bmp_1D_128: SpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_128) or integer(DISPLAY_SPR_1D_BMP) or integer(DISPLAY_SPR_1D_BMP_SIZE_128) or (5 shl 28) or 2;
-  SpriteMapping_Bmp_1D_256: SpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_256) or integer(DISPLAY_SPR_1D_BMP) or integer(DISPLAY_SPR_1D_BMP_SIZE_256) or (6 shl 28) or 3;
-  SpriteMapping_Bmp_2D_128: SpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_128)  or (7 shl 28) or 2;
-  SpriteMapping_Bmp_2D_256: SpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_256)  or (8 shl 28) or 3;
+  SpriteMapping_1D_32     : TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_32)  or (0 shl 28) or 0;
+  SpriteMapping_1D_64     : TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_64)  or (1 shl 28) or 1;
+  SpriteMapping_1D_128    : TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_128) or (2 shl 28) or 2;
+  SpriteMapping_1D_256    : TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_256) or (3 shl 28) or 3;
+  SpriteMapping_2D        : TSpriteMapping = integer(DISPLAY_SPR_2D) or (4 shl 28);
+  SpriteMapping_Bmp_1D_128: TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_128) or integer(DISPLAY_SPR_1D_BMP) or integer(DISPLAY_SPR_1D_BMP_SIZE_128) or (5 shl 28) or 2;
+  SpriteMapping_Bmp_1D_256: TSpriteMapping = integer(DISPLAY_SPR_1D) or integer(DISPLAY_SPR_1D_SIZE_256) or integer(DISPLAY_SPR_1D_BMP) or integer(DISPLAY_SPR_1D_BMP_SIZE_256) or (6 shl 28) or 3;
+  SpriteMapping_Bmp_2D_128: TSpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_128)  or (7 shl 28) or 2;
+  SpriteMapping_Bmp_2D_256: TSpriteMapping = integer(DISPLAY_SPR_2D) or integer(DISPLAY_SPR_2D_BMP_256)  or (8 shl 28) or 3;
 
 type
   SpriteColorFormat = integer;
@@ -275,7 +275,8 @@ type
     gfxOffsetStep: cint; 
     firstFree: cint16;
     allocBuffer: PAllocHeader; 
-    allocBufferSize: cint16; 
+    allocBufferSize: cint16;
+    spriteMapping: TSpriteMapping;     
     case integer of
       0: (
             oamMemory: PSpriteEntry;
@@ -291,7 +292,7 @@ var
   oamMain: OamState; cvar; external;
   oamSub: OamState; cvar; external;  
 
-procedure oamInit(var oam: OamState; mapping: SpriteMapping; extPalette: cbool); cdecl; external;
+procedure oamInit(var oam: OamState; mapping: TSpriteMapping; extPalette: cbool); cdecl; external;
 procedure oamDisable(var oam: OamState); cdecl; external;
 procedure oamEnable(var oam: OamState); cdecl; external;
 function oamGetGfxPtr(var oam: OamState; gfxOffsetIndex: cint): pcuint16; cdecl; external;
@@ -309,13 +310,14 @@ procedure oamSet( var oam: OamState;
                   affineIndex: cint; 
                   sizeDouble, hide, hflip, vflip, mosaic: cbool); cdecl; external;
 procedure oamClear(var oam: OamState; start, count: cint); cdecl; external;
+procedure oamClearSprite(var oam: OamState; index: cint); inline;
 procedure oamUpdate(var oam: OamState); cdecl; external;
 procedure oamRotateScale(var oam: OamState; rotId, angle, sx, sy: cint); cdecl; external;
 procedure oamAffineTransformation(var oam: OamState; rotId, hdx, hdy, vdx, vdy: cint); inline;
 
 function oamCountFragments(var oam: OamState): cint; cdecl; external;
 procedure oamAllocReset(var oam: OamState); cdecl; external;
-function oamGfxPtrToOffset(const offset: pointer): cuint; cdecl; external;
+function oamGfxPtrToOffset(var oam: OamState; const offset: pointer): cuint; cdecl; external;
 {$endif NDS_INTERFACE}
  
 {$ifdef NDS_IMPLEMENTATION}
@@ -366,25 +368,31 @@ end;
 
 procedure oamSetMosaic(dx, dy: cuint); inline;
 begin
-  sassert((dx < 16) and (dy < 16), 'Mosaic range is 0 to 15');
+  sassert((dx < 16) and (dy < 16), 'Mosaic range must be 0 to 15');
   mosaicShadow := ( mosaicShadow and $00ff) or (dx shl 8) or (dy shl 12);
   REG_MOSAIC^ := mosaicShadow;
 end;
 
 procedure oamSetMosaicSub(dx, dy: cuint); inline;
 begin
-  sassert((dx < 16) and (dy < 16), 'Mosaic range is 0 to 15');
+  sassert((dx < 16) and (dy < 16), 'Mosaic range must be 0 to 15');
   mosaicShadowSub := (mosaicShadowSub and $00ff) or (dx shl 8) or (dy shl 12);
   REG_MOSAIC_SUB^ := mosaicShadowSub;
 end;
 
+procedure oamClearSprite(var oam: OamState; index: cint); inline;
+begin
+  sassert( (index >= 0) and (index < SPRITE_COUNT), 'oamClearSprite() index is out of bounds, must be 0-127');
+  oam.oamMemory[index].attribute[0] := ATTR0_DISABLED;
+end;
+
 procedure oamAffineTransformation(var oam: OamState; rotId, hdx, hdy, vdx, vdy: cint); inline;
 begin
   sassert((rotId >= 0) and (rotId < 32), 'oamAffineTransformation() rotId is out of bounds, must be 0-31');
-  oam.oamRotationMemory[rotId].hdx := hdx shr 12;
-  oam.oamRotationMemory[rotId].hdy := hdy shr 12;
-  oam.oamRotationMemory[rotId].vdx := vdx shr 12;
-  oam.oamRotationMemory[rotId].vdy := vdy shr 12;
+  oam.oamRotationMemory[rotId].hdx := hdx;
+  oam.oamRotationMemory[rotId].vdx := vdx;
+  oam.oamRotationMemory[rotId].hdy := hdy;
+  oam.oamRotationMemory[rotId].vdy := vdy;
 end;
 
 

+ 75 - 9
packages/libndsfpc/src/nds/arm9/video.inc

@@ -201,6 +201,10 @@ const
   VRAM_F_MAIN_SPRITE_0x06410000 : VRAM_F_TYPE = 2 or (2 shl 3);
   VRAM_F_MAIN_SPRITE_0x06414000 : VRAM_F_TYPE = 2 or (3 shl 3); 
   VRAM_F_TEX_PALETTE            : VRAM_F_TYPE = 3;
+  VRAM_F_TEX_PALETTE_SLOT0      : VRAM_F_TYPE = 3;
+  VRAM_F_TEX_PALETTE_SLOT1      : VRAM_F_TYPE = 3 or (1 shl 3);
+  VRAM_F_TEX_PALETTE_SLOT4      : VRAM_F_TYPE = 3 or (2 shl 3);
+  VRAM_F_TEX_PALETTE_SLOT5      : VRAM_F_TYPE = 3 or (3 shl 3);
   VRAM_F_BG_EXT_PALETTE         : VRAM_F_TYPE = 4;
   VRAM_F_BG_EXT_PALETTE_SLOT01  : VRAM_F_TYPE = 4 or (0 shl 3);
   VRAM_F_BG_EXT_PALETTE_SLOT23  : VRAM_F_TYPE = 4 or (1 shl 3);
@@ -221,6 +225,10 @@ const
   VRAM_G_MAIN_SPRITE_0x06410000 : VRAM_G_TYPE = 2 or (2 shl 3);
   VRAM_G_MAIN_SPRITE_0x06414000 : VRAM_G_TYPE = 2 or (3 shl 3);    
   VRAM_G_TEX_PALETTE            : VRAM_G_TYPE = 3;
+  VRAM_G_TEX_PALETTE_SLOT0      : VRAM_G_TYPE = 3;
+  VRAM_G_TEX_PALETTE_SLOT1      : VRAM_G_TYPE = 3 or (1 shl 3);
+  VRAM_G_TEX_PALETTE_SLOT4      : VRAM_G_TYPE = 3 or (2 shl 3);
+  VRAM_G_TEX_PALETTE_SLOT5      : VRAM_G_TYPE = 3 or (3 shl 3);
   VRAM_G_BG_EXT_PALETTE         : VRAM_G_TYPE = 4;
   VRAM_G_BG_EXT_PALETTE_SLOT01  : VRAM_G_TYPE = 4 or (0 shl 3);
   VRAM_G_BG_EXT_PALETTE_SLOT23  : VRAM_G_TYPE = 4 or (1 shl 3);  
@@ -254,17 +262,18 @@ var
   VRAM_H_EXT_PALETTE : P_ext_palette absolute VRAM_H;
 
 function vramSetMainBanks(a: VRAM_A_TYPE; b: VRAM_B_TYPE; c: VRAM_C_TYPE; d: VRAM_D_TYPE): cuint32; cdecl; external;
+function vramDefault(): cuint32; cdecl; external;
 procedure vramRestoreMainBanks(vramTemp: cuint32); cdecl; external;
 
-procedure vramSetBankA(a: VRAM_A_TYPE); cdecl; external;
-procedure vramSetBankB(b: VRAM_B_TYPE); cdecl; external;
-procedure vramSetBankC(c: VRAM_C_TYPE); cdecl; external;
-procedure vramSetBankD(d: VRAM_D_TYPE); cdecl; external;
-procedure vramSetBankE(e: VRAM_E_TYPE); cdecl; external;
-procedure vramSetBankF(f: VRAM_F_TYPE); cdecl; external;
-procedure vramSetBankG(g: VRAM_G_TYPE); cdecl; external;
-procedure vramSetBankH(h: VRAM_H_TYPE); cdecl; external;
-procedure vramSetBankI(i: VRAM_I_TYPE); cdecl; external;
+procedure vramSetBankA(a: VRAM_A_TYPE); inline;
+procedure vramSetBankB(b: VRAM_B_TYPE); inline;
+procedure vramSetBankC(c: VRAM_C_TYPE); inline;
+procedure vramSetBankD(d: VRAM_D_TYPE); inline;
+procedure vramSetBankE(e: VRAM_E_TYPE); inline;
+procedure vramSetBankF(f: VRAM_F_TYPE); inline;
+procedure vramSetBankG(g: VRAM_G_TYPE); inline;
+procedure vramSetBankH(h: VRAM_H_TYPE); inline;
+procedure vramSetBankI(i: VRAM_I_TYPE); inline;
 
 const
   REG_DISPCNT       : pcuint32 = pointer($04000000);
@@ -344,6 +353,8 @@ procedure videoBgEnableSub(number: cint); inline;
 procedure videoBgDisable(number: cint); inline;	 	 
 procedure videoBgDisableSub(number: cint); inline;
 procedure setBrightness(screen, level: cint); cdecl; external;
+procedure setBackdropColor(const color: cuint16); inline;
+procedure setBackdropColorSub(const color: cuint16); inline;
 
 const
   REG_MASTER_BRIGHT     : pcuint16 = pointer($0400006C);
@@ -628,4 +639,59 @@ begin
 	GFX_BUSY := GFX_STATUS^ and (1 shl 27) <> 0;
 end;
 
+procedure vramSetBankA(a: VRAM_A_TYPE); inline;
+begin
+  VRAM_A_CR^ := VRAM_ENABLE or a;
+end;
+
+procedure vramSetBankB(b: VRAM_B_TYPE); inline;
+begin
+  VRAM_B_CR^ := VRAM_ENABLE or b;
+end;
+
+procedure vramSetBankC(c: VRAM_C_TYPE); inline;
+begin
+  VRAM_C_CR^ := VRAM_ENABLE or c;
+end;
+
+procedure vramSetBankD(d: VRAM_D_TYPE); inline;
+begin
+  VRAM_D_CR^ := VRAM_ENABLE or d;
+end;
+
+procedure vramSetBankE(e: VRAM_E_TYPE); inline;
+begin
+  VRAM_E_CR^ := VRAM_ENABLE or e;
+end;
+
+procedure vramSetBankF(f: VRAM_F_TYPE); inline;
+begin
+  VRAM_F_CR^ := VRAM_ENABLE or f;
+end;
+
+procedure vramSetBankG(g: VRAM_G_TYPE); inline;
+begin
+  VRAM_G_CR^ := VRAM_ENABLE or g;
+end;
+
+procedure vramSetBankH(h: VRAM_H_TYPE); inline;
+begin
+  VRAM_H_CR^ := VRAM_ENABLE or h;
+end;
+
+procedure vramSetBankI(i: VRAM_I_TYPE); inline;
+begin
+  VRAM_I_CR^ := VRAM_ENABLE or i;
+end;
+
+procedure setBackdropColor(const color: cuint16); inline;
+begin
+  BG_PALETTE[0] := color;
+end;
+
+procedure setBackdropColorSub(const color: cuint16); inline;
+begin
+  BG_PALETTE_SUB[0] := color;
+end;
+
 {$endif NDS_IMPLEMENTATION}

+ 71 - 6
packages/libndsfpc/src/nds/arm9/videoGL.inc

@@ -299,6 +299,10 @@ function FIFO_NOP(): cuint8; inline;
 function FIFO_STATUS(): cuint8; inline;
 function FIFO_COLOR(): cuint8; inline;
 function FIFO_VERTEX16(): cuint8; inline;
+function FIFO_VERTEX10(): cuint8; inline;
+function FIFO_VERTEX_XY(): cuint8; inline;
+function FIFO_VERTEX_XZ(): cuint8; inline;
+function FIFO_VERTEX_YZ(): cuint8; inline;
 function FIFO_TEX_COORD(): cuint8; inline;
 function FIFO_TEX_FORMAT(): cuint8; inline;
 function FIFO_PAL_FORMAT(): cuint8; inline;
@@ -317,7 +321,7 @@ function FIFO_FLUSH(): cuint8; inline;
 function FIFO_VIEWPORT(): cuint8; inline;
 
 procedure glRotatef32i(angle: cint; x, y, z: cint32); cdecl; external;
-function glTexImage2D(target, empty1: cint; _type: GL_TEXTURE_TYPE_ENUM; sizeX, sizeY, empty2, param: cint; texture: pcuint8): cint; cdecl; external;
+function glTexImage2D(target, empty1: cint; _type: GL_TEXTURE_TYPE_ENUM; sizeX, sizeY, empty2, param: cint; texture: pointer): cint; cdecl; external;
 procedure glTexLoadPal(const pal: pcuint16; count: cuint16; addr: cuint32); cdecl; external;
 function gluTexLoadPal(const pal: pcuint16; count: cuint16; format: cuint8): cint; cdecl; external;
 procedure glTexParameter(sizeX, sizeY: cuint8; const addr: pcuint32; mode: GL_TEXTURE_TYPE_ENUM; param: GL_TEXTURE_PARAM_ENUM); cdecl; external;
@@ -348,7 +352,8 @@ procedure glStoreMatrix(index: cint32); inline;
 procedure glScalev(const v: PGLvector); inline;
 procedure glTranslatev(const v: PGLvector) ; inline;
 procedure glTranslate3f32(x, y, z: cint32); inline;
-procedure glScalef32(factor: cint32); inline;
+procedure glTranslatef32(x, y, z: cint32); inline;
+procedure glScalef32(x, y, z: cint32); inline;
 procedure glLight(id: cint; color: rgb; x, y, z: v10); inline;
 procedure glNormal(normal: cuint32); inline;
 procedure glLoadIdentity(); inline;
@@ -360,6 +365,10 @@ procedure glCallList(list: pcuint32); inline;
 procedure glPolyFmt(params: cuint32); inline;
 procedure glEnable(bits: cint); inline;
 procedure glDisable(bits: cint); inline;
+procedure glFogShift(shift: cint); inline;
+procedure glFogOffset(offset: cint); inline; 
+procedure glFogColor(red, green, blue, alpha: cuint8); inline;
+procedure glFogDensity(index, density: cint); inline;
 procedure glLoadMatrix4x4(const m: pm4x4); inline;
 procedure glLoadMatrix4x3(const m: pm4x3); inline;
 procedure glMultMatrix4x4(const m: pm4x4); inline;
@@ -547,6 +556,26 @@ begin
   FIFO_VERTEX16 := REG2ID(GFX_VERTEX16);
 end;
 
+function FIFO_VERTEX10(): cuint8; inline;
+begin
+  FIFO_VERTEX10 := REG2ID(GFX_VERTEX10);
+end;
+
+function FIFO_VERTEX_XY(): cuint8; inline;
+begin
+  FIFO_VERTEX_XY := REG2ID(GFX_VERTEX_XY); 
+end;
+
+function FIFO_VERTEX_XZ(): cuint8; inline;
+begin
+  FIFO_VERTEX_XZ := REG2ID(GFX_VERTEX_XZ); 
+end;
+
+function FIFO_VERTEX_YZ(): cuint8; inline;
+begin
+  FIFO_VERTEX_YZ := REG2ID(GFX_VERTEX_YZ); 
+end;
+
 function FIFO_TEX_COORD(): cuint8; inline;
 begin
   FIFO_TEX_COORD := REG2ID(GFX_TEX_COORD);
@@ -756,17 +785,22 @@ begin
 end;
 
 procedure glTranslate3f32(x, y, z: cint32); inline;
+begin
+  glTranslatef32(x, y, z);
+end;
+
+procedure glTranslatef32(x, y, z: cint32); inline;
 begin
 	MATRIX_TRANSLATE^ := x;
 	MATRIX_TRANSLATE^ := y;
 	MATRIX_TRANSLATE^ := z;
 end;
 
-procedure glScalef32(factor: cint32); inline;
+procedure glScalef32(x, y, z: cint); inline;
 begin
-	MATRIX_SCALE^ := factor;
-	MATRIX_SCALE^ := factor;
-	MATRIX_SCALE^ := factor;
+	MATRIX_SCALE^ := x;
+	MATRIX_SCALE^ := y;
+	MATRIX_SCALE^ := z;
 end;
 
 procedure glLight(id: cint; color: rgb; x, y, z: v10); inline;
@@ -824,7 +858,9 @@ procedure glCallList(list: pcuint32); inline;
 var
   count: cuint32;
 begin
+	sassert(list <> nil, 'glCallList received a null display list pointer');
   count := list^;
+	sassert(count <> 0, 'glCallList received a display list of size 0');
   inc(list);
   DC_FlushRange(list, count*4);
   while ( ((DMA_CR(0)^ and DMA_BUSY) <> 0) or 
@@ -854,6 +890,35 @@ begin
   GFX_CONTROL^ := GFX_CONTROL^ and not bits;
 end;
 
+
+procedure glFogShift(shift: cint); inline;
+begin
+  sassert((shift >= 0) and (shift < 16), 'glFogShift is out of range');
+  GFX_CONTROL^ := (GFX_CONTROL^ and $F0FF) or (shift shl 8);
+end;
+
+procedure glFogOffset(offset: cint); inline; 
+begin
+  sassert((offset >= 0) and (offset < $8000), 'glFogOffset is out of range');
+  GFX_FOG_OFFSET^ := offset;
+end;
+
+procedure glFogColor(red, green, blue, alpha: cuint8); inline;
+begin
+  sassert(red < 32, 'glFogColor red is out of range');
+  sassert(green < 32, 'glFogColor green is out of range');
+  sassert(blue < 32, 'glFogColor blue is out of range');
+  sassert(alpha < 32, 'glFogColor alpha is out of range');
+  GFX_FOG_COLOR^ := RGB15(red, green, blue) or (alpha shl 16);  
+end;
+
+procedure glFogDensity(index, density: cint); inline;
+begin
+  sassert((index >= 0) and (index < 32), 'glFogDensity index is out of range');
+  sassert((index >= 0) and (density < 128), 'glFogDensity density is out of range');
+  GFX_FOG_TABLE[index] := density;  
+end;
+
 procedure glLoadMatrix4x4(const m: pm4x4); inline;
 begin
   MATRIX_LOAD4x4^ := m^.m[0];

+ 9 - 7
packages/libndsfpc/src/nds/bios.inc

@@ -41,16 +41,18 @@
 {$ifdef NDS_INTERFACE}
 
 type
-  TGetSize = function(source: pcuint8;  dest: pcuint16; r2: cuint32): pcint; 
-  TGetResult = function(source: pcuint8): pcint; 
-  TReadByte = function(source: pcuint8): pcuint8; 
-
+  TGetHeaderCallback = function(source: pcuint8;  dest: pcuint16; r2: cuint32): pcint;
+  getHeaderCallback = TGetHeaderCallback;
+  TGetResultCallback = function(source: pcuint8): pcint;
+  getResultCallback = TGetResultCallback; 
+  TGetByteCallback = function(source: pcuint8): pcuint8; 
+  getByteCallback = TGetByteCallback;
 
 type
   DecompressionStream = packed record
-    getSize: TGetSize; 
-    getResult: TGetResult; 
-    readByte: TReadByte; 
+    getSize: TGetHeaderCallback; 
+    getResult: TGetResultCallback; 
+    readByte: TGetByteCallback; 
   end;
   TDecompressionStream = DecompressionStream;
   PDecompressionStream = ^TDecompressionStream;

+ 13 - 17
packages/libndsfpc/src/nds/card.inc

@@ -1,5 +1,4 @@
 (*
-  $Id: card.inc 25 2007-12-10 21:06:46Z p4p3r0 $
   ------------------------------------------------------------------------------
   	Copyright (C) 2005
   		Jason Rogers (dovoto)
@@ -25,29 +24,21 @@
   		distribution.
   ------------------------------------------------------------------------------
     
-    
   Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
   (http://www.freepascal.org)
    
-  Copyright (C) 2006  Francesco Lombardi
-  Check http://sourceforge.net/projects/libndsfpc for updates
-   
   ------------------------------------------------------------------------------
-
-  $Log$
-
 *)
 
 
 {$ifdef NDS_INTERFACE}
 const  
   // Card bus
-  CARD_CR1       : pcuint16 = pointer($040001A0);
-  CARD_CR1H      : pcuint8  = pointer($040001A1);
-  CARD_EEPDATA   : pcuint8  = pointer($040001A2);
-  CARD_CR2       : pcuint32 = pointer($040001A4);
   CARD_COMMAND   : pcuint8  = pointer($040001A8);
-
+  REG_ROMCTRL    : pcuint32 = pointer($040001A4);
+  REG_AUXSPICNT  : pcuint16 = pointer($040001A0);
+  REG_AUXSPICNTH : pcuint8  = pointer($040001A1);
+  REG_AUXSPIDATA : pcuint8  = pointer($040001A2);
   CARD_DATA_RD   : pcuint32 = pointer($04100010);
 
   CARD_1B0       : pcuint32 = pointer($040001B0);
@@ -55,12 +46,17 @@ const
   CARD_1B8       : pcuint16 = pointer($040001B8);
   CARD_1BA       : pcuint16 = pointer($040001BA);
 
-
   CARD_CR1_ENABLE = $80;  // in byte 1, i.e. 0x8000
   CARD_CR1_IRQ    = $40;  // in byte 1, i.e. 0x4000
 
+  // SPI EEPROM COMMANDS
+  EEPROM_WRSR = $01;
+  EEPROM_WRDI = $04;
+  EEPROM_RDSR = $05;
+  EEPROM_WREN = $06;
+  EEPROM_RDID = $9f;
 
-// CARD_CR2 register:
+// ROMCTRL register:
   CARD_ACTIVATE   = (1 shl 31);  // when writing, get the ball rolling
   CARD_WR         = (1 shl 30);
   CARD_nRESET     = (1 shl 29);  // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
@@ -115,9 +111,9 @@ function cardReadID(flags: cuint32): cuint32; cdecl; external;
 procedure cardReadEeprom(address: cuint32;  data: pcuint8;  length: cuint32;  addrtype: cuint32); cdecl; external; 
 procedure cardWriteEeprom(address: cuint32;  data: pcuint8;  length: cuint32;  addrtype: cuint32); cdecl; external; 
 
-function cardEepromReadID(i: cuint8): cuint8; cdecl; external;
+function cardEepromReadID(): cuint32; cdecl; external;
 
-function cardEepromCommand(command: cuint8; address: cuint32): cuint8; cdecl; external;
+function cardEepromCommand(command: cuint8): cuint8; cdecl; external;
 
 function cardEepromGetType({void}): cint; cdecl; external;
 function cardEepromGetSize(): cuint32; cdecl; external;

+ 1 - 0
packages/libndsfpc/src/nds/debug.inc

@@ -40,6 +40,7 @@
 
 {$ifdef NDS_INTERFACE}
 
+procedure nocashWrite(const aMessage: pchar; len: cint); cdecl; external;
 procedure nocashMessage(const aMessage: pchar); cdecl; external;
 
 {$endif NDS_INTERFACE}

+ 3 - 0
packages/libndsfpc/src/nds/fifocommon.inc

@@ -83,6 +83,7 @@ const
   SYS_REQ_TOUCH : FifoSystemCommands = 0;
   SYS_REQ_KEYS  : FifoSystemCommands = 1;
   SYS_REQ_TIME  : FifoSystemCommands = 2;
+  SYS_SET_TIME  : FifoSystemCommands = 3;
 
 type
   FifoPMCommands = integer;
@@ -93,6 +94,8 @@ const
   PM_REQ_SLEEP          : FifoPMCommands = (4 shl 16);
   PM_REQ_SLEEP_DISABLE  : FifoPMCommands = (5 shl 16);
   PM_REQ_SLEEP_ENABLE   : FifoPMCommands = (6 shl 16);
+  PM_REQ_BATTERY        : FifoPMCommands = (7 shl 16);
+  PM_DSI_HACK           : FifoPMCommands = (8 shl 16);
 	
 type
   FifoWifiCommands = integer;

+ 2 - 1
packages/libndsfpc/src/nds/fifomessages.inc

@@ -48,8 +48,8 @@ type
         SundPlay: record
           _type: cuint16;
           data: pointer;
-          loopPoint: cuint16;
           dataSize: cuint16;
+          loopPoint: cuint16;
           freq: cuint16;
           volume: cuint8;
           pan: cuint8;
@@ -63,6 +63,7 @@ type
           dutyCycle: cuint8;
           volume: cuint8;
           pan: cuint8;
+          channel: cuint8;
         end;
       );
       2: (

+ 65 - 0
packages/libndsfpc/src/nds/input.inc

@@ -0,0 +1,65 @@
+(*
+  $Id: input.inc 25 2007-12-10 21:06:46Z p4p3r0 $
+  ------------------------------------------------------------------------------
+  	Copyright (C) 2005
+  		Jason Rogers (dovoto)
+  		Dave Murphy (WinterMute)
+  	
+  	This software is provided 'as-is', without any express or implied
+  	warranty.  In no event will the authors be held liable for any
+  	damages arising from the use of this software.
+  	
+  	Permission is granted to anyone to use this software for any
+  	purpose, including commercial applications, and to alter it and
+  	redistribute it freely, subject to the following restrictions:
+  	
+  	1.	The origin of this software must not be misrepresented; you
+  		must not claim that you wrote the original software. If you use
+  		this software in a product, an acknowledgment in the product
+  		documentation would be appreciated but is not required.
+  	
+  	2.	Altered source versions must be plainly marked as such, and
+  		must not be misrepresented as being the original software.
+  	
+  	3.	This notice may not be removed or altered from any source
+  		distribution.
+  ------------------------------------------------------------------------------
+    
+    
+  Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
+  (http://www.freepascal.org)
+   
+  Copyright (C) 2006  Francesco Lombardi
+  Check http://sourceforge.net/projects/libndsfpc for updates
+   
+  ------------------------------------------------------------------------------
+
+  $Log$
+
+*)
+
+{$ifdef NDS_INTERFACE}
+// Keyboard
+type
+  KEYPAD_BITS = cint;
+const
+//!	Bit values for the keypad buttons.
+  KEY_A      : KEYPAD_BITS = (1 shl 0);  // Keypad A button.
+  KEY_B      : KEYPAD_BITS = (1 shl 1);  // Keypad B button.
+  KEY_SELECT : KEYPAD_BITS = (1 shl 2);  // Keypad SELECT button.
+  KEY_START  : KEYPAD_BITS = (1 shl 3);  // Keypad START button.
+  KEY_RIGHT  : KEYPAD_BITS = (1 shl 4);  // Keypad RIGHT button.
+  KEY_LEFT   : KEYPAD_BITS = (1 shl 5);  // Keypad LEFT button.
+  KEY_UP     : KEYPAD_BITS = (1 shl 6);  // Keypad UP button.
+  KEY_DOWN   : KEYPAD_BITS = (1 shl 7);  // Keypad DOWN button.
+  KEY_R      : KEYPAD_BITS = (1 shl 8);  // Right shoulder button.
+  KEY_L      : KEYPAD_BITS = (1 shl 9);  // Left shoulder button.
+  KEY_X      : KEYPAD_BITS = (1 shl 10); // Keypad X button.
+  KEY_Y      : KEYPAD_BITS = (1 shl 11); // Keypad Y button.
+  KEY_TOUCH  : KEYPAD_BITS = (1 shl 12); // Touchscreen pendown.
+  KEY_LID    : KEYPAD_BITS = (1 shl 13); // Lid state.
+
+  REG_KEYINPUT : pcuint16 = pointer($04000130);
+  REG_KEYCNT   : pcuint16 = pointer($04000132);
+
+{$endif NDS_INTERFACE}

+ 26 - 13
packages/libndsfpc/src/nds/interrupts.inc

@@ -60,15 +60,20 @@ const
   IRQ_IPC_SYNC		    : IRQ_MASK =	(1 shl 16);	  (* IPC sync interrupt mask *)
   IRQ_FIFO_EMPTY		  : IRQ_MASK =	(1 shl 17);	  (* Send FIFO empty interrupt mask *)
   IRQ_FIFO_NOT_EMPTY	: IRQ_MASK =	(1 shl 18);	  (* Receive FIFO empty interrupt mask *)
-  IRQ_CARD			      : IRQ_MASK =	(1 shl 19);	  (* interrupt mask *)
+  IRQ_CARD			      : IRQ_MASK =	(1 shl 19);	  (* interrupt mask DS Card Slot *)
   IRQ_CARD_LINE		    : IRQ_MASK =	(1 shl 20);	  (* interrupt mask *)
   IRQ_GEOMETRY_FIFO   : IRQ_MASK =	(1 shl 21);	  (* geometry FIFO interrupt mask *)
-  IRQ_LID				      : IRQ_MASK =	(1 shl 22);	  (* interrupt mask *)
+  IRQ_LID				      : IRQ_MASK =	(1 shl 22);	  (* interrupt mask hinge *)
   IRQ_SPI				      : IRQ_MASK =	(1 shl 23);	  (* SPI interrupt mask *)
   IRQ_WIFI			      : IRQ_MASK =	(1 shl 24);	  (* WIFI interrupt mask (ARM7)*)
   IRQ_ALL				      : IRQ_MASK =	(not 0);      //$FFFFFF ?
 
 
+type
+  IRQ_MASKSAUX = cuint;
+const
+  IRQ_POWER: IRQ_MASKSAUX = (1 shl 6); (* Power Button interrupt mask (DSi ARM7) *)
+
 function IRQ_TIMER(n: cint): cint; inline;
 
 const
@@ -77,9 +82,11 @@ const
 
 
 const
-  REG_IE	: pcuint32 = pointer($04000210);
-  REG_IF	: pcuint32 = pointer($04000214);
-  REG_IME	: pcuint16 = pointer($04000208);
+  REG_IE	 : pcuint32 = pointer($04000210);
+  REG_AUXIE: pcuint32 = pointer($04000218);
+  REG_IF	 : pcuint32 = pointer($04000214);
+  REG_AUXIF: pcuint32 = pointer($0400021C);
+  REG_IME	 : pcuint32 = pointer($04000208);
 
 type
   IME_VALUE = integer;
@@ -89,7 +96,7 @@ const
 
 
 type
-  TVoidFunctionPointer = procedure of object;
+  TVoidFn = procedure of object;
   
 var
 //  __irq_vector: array [0..0] of VoidFunctionPointer; cvar; external;
@@ -102,10 +109,11 @@ var
 ///  __irq_flags: pcuint32; cvar; external;
   __irq_vector: Pointer; external name '__irq_vector';
   __irq_flags: pcuint32; external name '__irq_flags';
+  __irq_flagsaux: pcuint32; external name '__irq_flagsaux';
 
 
-
-{$define VBLANK_INTR_WAIT_FLAGS := __irq_flags}
+{$define INTR_WAIT_FLAGS := __irq_flags}
+{$define INTR_WAIT_FLAGSAUX := __irq_flagsaux}
 {$define IRQ_HANDLER := __irq_vector}
 
 type
@@ -115,15 +123,20 @@ type
   end;
 
 procedure irqInit(); cdecl; external;
-procedure irqSet(irq: IRQ_MASK; handler: TVoidFunctionPointer); cdecl; external;
-procedure irqSet(irq: IRQ_MASK; handler: pointer); cdecl; external;
-procedure irqClear(irq: IRQ_MASK); cdecl; external;
-procedure irqInitHandler(handler: TVoidFunctionPointer); cdecl; external;
+procedure irqSet(irq: cuint32; handler: TVoidFn); cdecl; external;
+procedure irqSet(irq: cuint32; handler: pointer); cdecl; external;
+procedure irqSetAUX(irq: cuint32; handler: TVoidFn); cdecl; external;
+procedure irqSetAUX(irq: cuint32; handler: pointer); cdecl; external;
+procedure irqClear(irq: cuint32); cdecl; external;
+procedure irqClearAUX(irq: cuint32); cdecl; external;
+procedure irqInitHandler(handler: TVoidFn); cdecl; external;
 procedure irqInitHandler(handler: pointer); cdecl; external;
 procedure irqEnable(irq: cuint32); cdecl; external;
+procedure irqEnableAUX(irq: cuint32); cdecl; external;
 procedure irqDisable(irq: cuint32); cdecl; external;
+procedure irqDisableAUX(irq: cuint32); cdecl; external;
 
-procedure swiIntrWait(waitForSet: cint; flags: cuint32); cdecl; external;
+procedure swiIntrWait(waitForSet: cuint32; flags: cuint32); cdecl; external;
 procedure swiWaitForVBlank(); cdecl; external;
 function enterCriticalSection(): cint; inline;
 procedure leaveCriticalSection(oldIME: cint); inline;

+ 4 - 4
packages/libndsfpc/src/nds/memory.inc

@@ -108,19 +108,19 @@ type
     romversion: cuint8;
     flags: cuint8;                // auto-boot flag
     
-    arm9romSource: cuint32;
+    arm9romOffset: cuint32;
     arm9executeAddress: cuint32;
     arm9destination: cuint32;
     arm9binarySize: cuint32;
     
-    arm7romSource: cuint32;
+    arm7romOffset: cuint32;
     arm7executeAddress: cuint32;
     arm7destination: cuint32;
     arm7binarySize: cuint32;
     
-    filenameSource: cuint32;
+    filenameOffset: cuint32;
     filenameSize: cuint32;
-    fatSource: cuint32;
+    fatOffset: cuint32;
     fatSize: cuint32;
     
     arm9overlaySource: cuint32;

+ 14 - 4
packages/libndsfpc/src/nds/nds.inc

@@ -75,39 +75,49 @@
 
 {$include helper.inc}
 
-{$include jtypes.inc}
+{$include jtypes.inc} // testing...
+{$include ndstypes.inc} // testing...
 {$include bios.inc}
 {$include card.inc}
+{$include debug.inc}
 {$include dma.inc}
 {$include interrupts.inc}
 {$include ipc.inc}
 {$include memory.inc}
 {$include system.inc}
 {$include timers.inc}
+{$include fifocommon.inc}
+{$include touch.inc}
+{$include input.inc}
+
+{$include dynamicArray.inc} // testing...
+{$include linkedlist.inc} // testing...
 
 {$ifdef ARM9}
   {$include arm9/background.inc}
   {$include arm9/boxtest.inc}
   {$include arm9/cache.inc}
   {$include arm9/console.inc}
+  {$include arm9/decompress.inc}
   {$include arm9/exceptions.inc}
   {$include arm9/image.inc}
   {$include arm9/input.inc}
+  {$include arm9/keyboard.inc}
   {$include arm9/math.inc}
   {$include arm9/pcx.inc}
-  { $include nds/arm9/postest.inc}  // da rimuovere
   {$include arm9/rumble.inc}
+  {$include arm9/sassert.inc}
   {$include arm9/sound.inc}
+  {$include arm9/sprite.inc}
   {$include arm9/trig_lut.inc}
-  {$include arm9/ndsmotion.inc}
   {$include arm9/video.inc}
   {$include arm9/videoGL.inc}
-  {$include arm9/sprite.inc}
 {$endif ARM9}
 
 {$ifdef ARM7}
   {$include arm7/audio.inc}
   {$include arm7/clock.inc}
+  {$include arm7/input.inc}  
   {$include arm7/serial.inc}
   {$include arm7/touch.inc}
 {$endif ARM7}

+ 6 - 6
packages/libndsfpc/src/nds/ndsinclude.inc

@@ -1,4 +1,5 @@
 
+
 { $include helper.inc}
 {$include ndstypes.inc}
 {$include bios.inc}
@@ -13,12 +14,12 @@
 {$include fifocommon.inc}
 {$include system.inc}
 {$include timers.inc}
-{$include fifomessages.inc}
-
-{$include linkedlist.inc}
-{$include dynamicArray.inc}
+{$include fifomessages.inc} 
+{$include input.inc} // testing...
  
 {$ifdef ARM9}
+  {$include arm9/dynamicArray.inc}
+  {$include arm9/linkedlist.inc}
   {$include arm9/sassert.inc}
   {$include arm9/background.inc}
   {$include arm9/cache.inc}
@@ -34,8 +35,8 @@
   {$include arm9/trig_lut.inc}
   {$include arm9/video.inc}
   {$include arm9/videoGL.inc}
-  {$include arm9/postest.inc}
   {$include arm9/boxtest.inc}
+  {$include arm9/postest.inc}
   {$include arm9/sprite.inc}
   {$include arm9/decompress.inc}
   {$include arm9/ndsmotion.inc}
@@ -46,6 +47,5 @@
   {$include arm7/clock.inc}
   {$include arm7/input.inc}
   {$include arm7/serial.inc}
-  { $include arm7/system.inc} 
   {$include arm7/touch.inc}
 {$endif ARM7}

+ 1 - 1
packages/libndsfpc/src/nds/ndstypes.inc

@@ -139,7 +139,7 @@ typedef volatile s64          vs64;
 
 
   //IntFn = function: pointer;
-  VoidFunctionPointer = function: pointer; cdecl;
+  VoidFn = function: pointer; cdecl;
   //fp = function: pointer;
 
   IntFn = procedure;

+ 4 - 4
packages/libndsfpc/src/nds/registers_alt.inc

@@ -305,10 +305,10 @@ const
   
   // Card	bus
   
-  REG_CARD_CR1		: pcuint32 = pointer($040001A0);
-  REG_CARD_CR1H		: pcuint8 = pointer($040001A1);
-  REG_CARD_CR2		: pcuint32 = pointer($040001A4);
-  REG_CARD_COMMAND	: pcuint8 = pointer($040001A8);
+  CARD_CR1     = REG_AUXSPICNT;
+  CARD_CR1H    = REG_AUXSPICNTH;
+  CARD_CR2     = REG_ROMCTRL;
+  CARD_EEPDATA = REG_AUXSPIDATA;
   
   REG_CARD_DATA		: pcuint32 = pointer($04100000);
   REG_CARD_DATA_RD	: pcuint32 = pointer($04100010);

+ 77 - 40
packages/libndsfpc/src/nds/system.inc

@@ -55,6 +55,7 @@ const
   REG_VCOUNT		: pcuint16 = pointer($04000006);
   HALT_CR       : pcuint16 = pointer($04000300);
   REG_POWERCNT  : pcuint16 = pointer($04000304);
+  REG_DSIMODE		: pcuint32 = pointer($04004000);  
 
 procedure SetYtrigger(Yvalue: cint); inline;
 
@@ -95,6 +96,9 @@ procedure lcdSwap(); inline;
 procedure lcdMainOnTop(); inline; 
 procedure lcdMainOnBottom(); inline; 
 
+procedure systemShutDown(); inline;
+
+function getBatteryLevel(): cuint32; cdecl; external;
 
 procedure setVectorBase(highVector: cint); cdecl; external;
 
@@ -120,19 +124,20 @@ var
 type
   ARM7_power = cint;
 const
-  POWER_SOUND     : ARM7_power = (1 shl 0);
-  PM_CONTROL_REG  : ARM7_power = 0;
-  PM_BATTERY_REG  : ARM7_power = 1;
-  PM_AMPLIFIER_REG: ARM7_power = 2;
-  PM_READ_REGISTER: ARM7_power = (1 shl 7);
-  PM_AMP_OFFSET   : ARM7_power = 2;
-  PM_GAIN_OFFSET  : ARM7_power = 3;
-  PM_GAIN_20      : ARM7_power = 0;
-  PM_GAIN_40      : ARM7_power = 1;
-  PM_GAIN_80      : ARM7_power = 2;
-  PM_GAIN_160     : ARM7_power = 3;
-  PM_AMP_ON       : ARM7_power = 1;
-  PM_AMP_OFF      : ARM7_power = 0;
+  POWER_SOUND         : ARM7_power = (1 shl 0);
+  PM_CONTROL_REG      : ARM7_power = 0;
+  PM_BATTERY_REG      : ARM7_power = 1;
+  PM_AMPLIFIER_REG    : ARM7_power = 2;
+  PM_READ_REGISTER    : ARM7_power = (1 shl 7);
+  PM_AMP_OFFSET       : ARM7_power = 2;
+  PM_GAIN_OFFSET      : ARM7_power = 3;
+  PM_BACKLIGHT_LEVEL  : ARM7_power = 4;
+  PM_GAIN_20          : ARM7_power = 0;
+  PM_GAIN_40          : ARM7_power = 1;
+  PM_GAIN_80          : ARM7_power = 2;
+  PM_GAIN_160         : ARM7_power = 3;
+  PM_AMP_ON           : ARM7_power = 1;
+  PM_AMP_OFF          : ARM7_power = 0;
 
 function PM_LED_CONTROL(m: cint): cint; inline;
 
@@ -143,12 +148,21 @@ function writePowerManagement(reg, command: cint): cint; cdecl; external;
 
 function readPowerManagement(reg: cint): cint; inline; 
 
-procedure powerOn(bits: PM_Bits); inline;
-procedure powerOff(bits: PM_Bits); inline;
-procedure systemShutDown(); inline;
+procedure powerOn(bits: cint); inline;
+procedure powerOff(bits: cint); inline;
 procedure readUserSettings(); cdecl; external;
+procedure systemShutDown(); cdecl; external;
 {$endif ARM7}
 
+
+type
+  BACKLIGHT_LEVELS = cint;
+const
+	BACKLIGHT_LOW  : BACKLIGHT_LEVELS = 0;
+	BACKLIGHT_MED  : BACKLIGHT_LEVELS = 1;
+	BACKLIGHT_HIGH : BACKLIGHT_LEVELS = 2;
+	BACKLIGHT_MAX  : BACKLIGHT_LEVELS = 3;	
+
 type
   tPERSONAL_DATA = bitpacked record
     RESERVED0: array [0..1] of cuint8;
@@ -186,9 +200,9 @@ type
       gbaScreen: 0..1;
       defaultBrightness: 0..2;
       autoMode: 0..1;
-      RESERVED1: 0..2;
+      RESERVED5: 0..2;
 	    settingsLost: 0..1;	
-	    RESERVED2: 0..6;
+	    RESERVED6: 0..6;
     end;
     RESERVED3: cuint16;
     rtcOffset: cuint32;
@@ -198,10 +212,22 @@ type
   PPERSONAL_DATA = ^tPERSONAL_DATA;
 
 const
-  REG_KEYINPUT	: pcuint16 = pointer($04000130);
-  REG_KEYCNT		: pcuint16 = pointer($04000132);
   PersonalData  : PPERSONAL_DATA = pointer($2FFFC80);
 
+type
+  RTCtime = packed record
+    year: cuint8;        // add 2000 to get 4 digit year
+    month: cuint8;       // 1 to 12
+    day: cuint8;         // 1 to (days in month)
+    weekday: cuint8;     // day of week
+    hours: cuint8;       // 0 to 11 for AM, 52 to 63 for PM
+    minutes: cuint8;     // 0 to 59
+    seconds: cuint8;     // 0 to 59
+//    padding: cuint8;
+  end;
+
+const
+  ARGV_MAGIC = $5f617267;
 
 type 
   ppcchar = ^pcchar;
@@ -211,36 +237,45 @@ type
     length: cint;			    // total length of command line
     argc: integer;
     argv: ppcchar;    
+    dummy: cint;          // internal use
+    host: cuint32;        // internal use, host ip for dslink 
   end;
   Targv = __argv;
   Pargv = ^Targv;
 
 const
   __system_argv: Pargv = pointer($02FFFE70);
-  ARGV_MAGIC = $5f617267;
-  
+
+const
+  BOOTSIG = $62757473746F6F62; // ULL?
+
 
 type
-  RTCtime = packed record
-    year: cuint8;        // add 2000 to get 4 digit year
-    month: cuint8;       // 1 to 12
-    day: cuint8;         // 1 to (days in month)
-    weekday: cuint8;     // day of week
-    hours: cuint8;       // 0 to 11 for AM, 52 to 63 for PM
-    minutes: cuint8;     // 0 to 59
-    seconds: cuint8;     // 0 to 59
-    padding: cuint8;
+  __bootstub = packed record      // packed ?
+    bootsig: 	cuint64;
+    arm9reboot: VoidFn;
+    arm7reboot: VoidFn;
+    bootsize: cuint32;
   end;
 
 
 {$ifdef ARM9}
-procedure memCached(address: pointer); cdecl; external;
-procedure memUncached(address: pointer); cdecl; external;
+//procedure memCached(address: pointer); cdecl; external;
+function memCached(address: pointer): pointer; cdecl; external;
+//procedure memUncached(address: pointer); cdecl; external;
+function memUncached(address: pointer): pointer; cdecl; external;
+procedure resetARM7(address: cuint32); cdecl; external;
 {$endif ARM9}
 
+{$ifdef ARM7}
+procedure resetARM9(address: cuint32); cdecl; external;
+{$endif ARM7}
 
 {$endif NDS_INTERFACE}
 
+
+
+
 {$ifdef NDS_IMPLEMENTATION}
 
 procedure SetYtrigger(Yvalue: cint); inline;
@@ -263,6 +298,12 @@ procedure lcdMainOnBottom(); inline;
 begin
   REG_POWERCNT^ := REG_POWERCNT^ and (not cint(POWER_SWAP_LCDS)); 
 end;
+
+procedure systemShutDown(); inline;
+begin
+  powerOn(PM_SYSTEM_PWR);
+end;
+
 {$endif ARM9}
 
 
@@ -277,20 +318,16 @@ begin
 	result := writePowerManagement(reg or PM_READ_REGISTER, 0);
 end;
 
-procedure powerOn(bits: PM_Bits); inline;
+procedure powerOn(bits: cint); inline;
 begin
 	REG_POWERCNT^ := REG_POWERCNT^ or bits;
 end;
 
-procedure powerOff(bits: PM_Bits); inline;
+procedure powerOff(bits: cint); inline;
 begin
 	REG_POWERCNT^ := REG_POWERCNT^ and not bits;
 end;
-
-procedure systemShutDown(); inline;
-begin
-  powerOn(PM_SYSTEM_PWR);
-end;
 {$endif ARM7}
+
 {$endif NDS_IMPLEMENTATION}
 

+ 71 - 52
packages/libndsfpc/src/nds/timers.inc

@@ -39,27 +39,13 @@
 *)
 
 {$ifdef NDS_INTERFACE}
-type
-  ClockDivider = cint;
-const
-  ClockDivider_1   : ClockDivider = 0;
-  ClockDivider_64  : ClockDivider = 1;
-  ClockDivider_256 : ClockDivider = 2;
-  ClockDivider_1024: ClockDivider = 3;
-
-
-procedure timerStart(channel: cint; divider: ClockDivider; ticks: cuint16; callback: fp); cdecl; external; 
-function timerElapsed(channel: cint): cuint16; cdecl; external;
-
-function timerFreqToTicks_1(freq: cint): cuint16; inline;
-function timerFreqToTicks_64(freq: cint): cuint16; inline;
-function timerFreqToTicks_256(freq: cint): cuint16; inline;
-function timerFreqToTicks_1024(freq: cint): cuint16; inline;
 
-function TIMER_FREQ(n: cint): cint; inline;
-function TIMER_FREQ_64(n: cint): cint; inline;
-function TIMER_FREQ_256(n: cint): cint; inline;
-function TIMER_FREQ_1024(n: cint): cint; inline; 
+const
+  TIMER0_CR   : pcuint16 = pointer($04000102);
+  TIMER1_CR   : pcuint16 = pointer($04000106);
+  TIMER2_CR   : pcuint16 = pointer($0400010A);
+  TIMER3_CR   : pcuint16 = pointer($0400010E);
+function TIMER_CR(n: cint): pcuint16; inline;
 
 const
   TIMER0_DATA    : pcuint16 = pointer($04000100);
@@ -68,70 +54,77 @@ const
   TIMER3_DATA    : pcuint16 = pointer($0400010C);
 function TIMER_DATA(n: cuint): pcuint16; inline;
 
-
 const
-  TIMER0_CR   : pcuint16 = pointer($04000102);
-  TIMER1_CR   : pcuint16 = pointer($04000106);
-  TIMER2_CR   : pcuint16 = pointer($0400010A);
-  TIMER3_CR   : pcuint16 = pointer($0400010E);
-function TIMER_CR(n: cint): pcuint16; inline;
+  BUS_CLOCK = 33513982;
 
 const
   TIMER_ENABLE    = (1 shl 7);
   TIMER_IRQ_REQ   = (1 shl 6);
   TIMER_CASCADE   = (1 shl 2);
+
+
+type
+  ClockDivider = cint;
+const
+  ClockDivider_1   : ClockDivider = 0;
+  ClockDivider_64  : ClockDivider = 1;
+  ClockDivider_256 : ClockDivider = 2;
+  ClockDivider_1024: ClockDivider = 3;
+
+const
   TIMER_DIV_1     = (0);
   TIMER_DIV_64    = (1);
   TIMER_DIV_256   = (2);
   TIMER_DIV_1024  = (3);
 
-procedure timerStop(channel: cint); inline;
-procedure cpuStartTiming(timer: cuint32); cdecl; external;
-function cpuEndTiming(): cuint32; cdecl; external;
-{$endif NDS_INTERFACE}
+function TIMER_FREQ(n: cint): cint; inline;
+function TIMER_FREQ_64(n: cint): cint; inline;
+function TIMER_FREQ_256(n: cint): cint; inline;
+function TIMER_FREQ_1024(n: cint): cint; inline; 
 
 
+procedure timerStart(channel: cint; divider: ClockDivider; ticks: cuint16; callback: fp); cdecl; external; 
+function timerElapsed(channel: cint): cuint16; cdecl; external;
 
-{$ifdef NDS_IMPLEMENTATION}
+function timerTick(timer: cuint): cuint16; inline; 
+function timerPause(timer: cuint): cuint16; cdecl; external;
+procedure timerUnpause(timer: cuint); inline;
 
-function timerFreqToTicks_1(freq: cint): cuint16; inline;
-begin
-  result := -$2000000 div freq;
-end;
+function timerStop(channel: cint): cuint16; cdecl; external;
+procedure cpuStartTiming(timer: cuint32); cdecl; external;
+function cpuGetTiming(): cuint32; cdecl; external;
+function cpuEndTiming(): cuint32; cdecl; external;
 
-function timerFreqToTicks_64(freq: cint): cuint16; inline;
-begin
-  result := (-$2000000 shr 6) div freq;
-end;
 
+function timerFreqToTicks_1(freq: cint): cuint16; inline;
+function timerFreqToTicks_64(freq: cint): cuint16; inline;
 function timerFreqToTicks_256(freq: cint): cuint16; inline;
-begin
-  result := (-$2000000 shr 8) div freq;
-end;
-
 function timerFreqToTicks_1024(freq: cint): cuint16; inline;
-begin
-  result := (-$2000000 shr 10) div freq;
-end;
+
+{$endif NDS_INTERFACE}
+
+
+
+{$ifdef NDS_IMPLEMENTATION}
 
 function TIMER_FREQ(n: cint): cint; inline;
 begin
-  TIMER_FREQ := cint(-$2000000 div (n));
+  TIMER_FREQ := cint(-BUS_CLOCK div (n));
 end;
 	
 function TIMER_FREQ_64(n: cint): cint; inline;
 begin
-  TIMER_FREQ_64 := cint(-($2000000 shr 6) div (n));
+  TIMER_FREQ_64 := cint(-(BUS_CLOCK shr 6) div (n));
 end;
 	
 function TIMER_FREQ_256(n: cint): cint; inline;
 begin
-  TIMER_FREQ_256 := cint(-($2000000 shr 8) div (n));
+  TIMER_FREQ_256 := cint(-(BUS_CLOCK shr 8) div (n));
 end;
 
 function TIMER_FREQ_1024(n: cint): cint; inline; 
 begin
-  TIMER_FREQ_1024 := cint(-($2000000 shr 10) div (n));
+  TIMER_FREQ_1024 := cint(-(BUS_CLOCK shr 10) div (n));
 end;
 
 function TIMER_DATA(n: cuint): pcuint16; inline;
@@ -144,8 +137,34 @@ begin
   TIMER_CR := pcuint16($04000102 + (n shl 2));
 end;
 
-procedure timerStop(channel: cint); inline;
+function timerTick(timer: cuint): cuint16; inline; 
+begin
+	timerTick := TIMER_DATA(timer)^;
+end;
+
+procedure timerUnpause(timer: cuint); inline;
 begin
-  TIMER_CR(channel)^ := TIMER_CR(channel)^ and not TIMER_ENABLE;
+	TIMER_CR(timer)^ := TIMER_CR(timer)^ or TIMER_ENABLE;
 end;
+
+function timerFreqToTicks_1(freq: cint): cuint16; inline;
+begin
+  result := -BUS_CLOCK div freq;
+end;
+
+function timerFreqToTicks_64(freq: cint): cuint16; inline;
+begin
+  result := (-BUS_CLOCK shr 6) div freq;
+end;
+
+function timerFreqToTicks_256(freq: cint): cuint16; inline;
+begin
+  result := (-BUS_CLOCK shr 8) div freq;
+end;
+
+function timerFreqToTicks_1024(freq: cint): cuint16; inline;
+begin
+  result := (-BUS_CLOCK shr 10) div freq;
+end;
+
 {$endif NDS_IMPLEMENTATION}

+ 1 - 1
packages/libndsfpc/src/nds7.pp

@@ -16,8 +16,8 @@ uses
 {$linklib nds7}
 
 {$linklib c}
-{$linklib g}
 {$linklib gcc}
+{$linklib g}
 {$linklib sysbase}
 
 {$define NDS_INTERFACE}

+ 1 - 1
packages/libndsfpc/src/nds9.pp

@@ -16,8 +16,8 @@ uses
 {$linklib nds9}
 
 {$linklib c}
-{$linklib g}
 {$linklib gcc}
+{$linklib g}
 {$linklib sysbase}
 
 

+ 60 - 90
rtl/nds/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/10/28]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/12/31]
 #
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx haiku
 LIMIT83fs = go32v2 os2 emx watcom
@@ -280,184 +280,178 @@ endif
 OBJPASDIR=$(RTL)/objpas
 GRAPHDIR=$(INC)/graph
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
-endif
-ifeq ($(FULL_TARGET),x86_64-solaris)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),avr-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
-endif
-ifeq ($(FULL_TARGET),mipsel-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil lineinfo fgl varutils
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
@@ -582,9 +576,6 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
 endif
-ifeq ($(FULL_TARGET),x86_64-solaris)
-override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
-endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
 endif
@@ -636,9 +627,6 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
 endif
-ifeq ($(FULL_TARGET),mipsel-linux)
-override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
-endif
 override INSTALL_FPCPACKAGE=y
 ifeq ($(FULL_TARGET),i386-linux)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
@@ -763,9 +751,6 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
-ifeq ($(FULL_TARGET),x86_64-solaris)
-override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
-endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
@@ -817,9 +802,6 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
-ifeq ($(FULL_TARGET),mipsel-linux)
-override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
-endif
 ifeq ($(FULL_TARGET),i386-linux)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
@@ -943,9 +925,6 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
-ifeq ($(FULL_TARGET),x86_64-solaris)
-override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
-endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
@@ -997,9 +976,6 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
-ifeq ($(FULL_TARGET),mipsel-linux)
-override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
-endif
 ifdef REQUIRE_UNITSDIR
 override UNITSDIR+=$(REQUIRE_UNITSDIR)
 endif
@@ -2107,9 +2083,6 @@ endif
 ifdef EXEFILES
 override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
 endif
-ifdef CLEAN_PROGRAMS
-override CLEANEXEFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEEXT), $(CLEAN_PROGRAMS)))
-endif
 ifdef CLEAN_UNITS
 override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
 endif
@@ -2156,9 +2129,6 @@ endif
 ifdef CLEANRSTFILES
 	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
 endif
-endif
-ifdef CLEAN_FILES
-	-$(DEL) $(CLEAN_FILES)
 endif
 	-$(DELTREE) units
 	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)

+ 1 - 1
rtl/nds/Makefile.fpc

@@ -12,7 +12,7 @@ units=$(SYSTEMUNIT) objpas macpas strings \
       sysutils \
       classes math typinfo varutils fmtbcd ctypes \
       charset ucomplex getopts matrix \
-      variants types rtlconsts sysconst dateutil lineinfo fgl \
+      variants types rtlconsts sysconst dateutil lineinfo fgl varutils \
 #      exec timer doslib utility hardware inputevent graphics layers \
 # these can be moved to packages later
 #      clipboard datatypes asl ahi tinygl get9 muihelper \

+ 2 - 1
rtl/nds/cprt07.as

@@ -8,7 +8,8 @@
 _start:
 @---------------------------------------------------------------------------------
 	mov	r0, #0x04000000		@ IME = 0;
-	str	r0, [r0, #0x208]
+	mov	r1, #0
+	str	r1, [r0, #0x208]
 
 	mov	r0, #0x12		@ Switch to IRQ Mode
 	msr	cpsr, r0

+ 12 - 0
rtl/nds/cprt09.as

@@ -18,6 +18,18 @@ _start:
 @---------------------------------------------------------------------------------
 	mov	r0, #0x04000000			@ IME = 0;
 	str	r0, [r0, #0x208]
+	
+	@ set sensible stacks to allow bios call
+
+	mov	r0, #0x13		@ Switch to SVC Mode
+	msr	cpsr, r0
+	mov	r1,#0x03000000
+	sub	r1,r1,#0x1000
+	mov	sp,r1
+	mov	r0, #0x1F		@ Switch to System Mode
+	msr	cpsr, r0
+	sub	r1,r1,#0x100
+	mov	sp,r1
 
 	ldr	r3,=__libnds_mpu_setup
 	blx	r3

+ 2 - 1
rtl/nds/prt07.as

@@ -8,7 +8,8 @@
 _start:
 @---------------------------------------------------------------------------------
 	mov	r0, #0x04000000		@ IME = 0;
-	str	r0, [r0, #0x208]
+	mov	r1, #0
+	str	r1, [r0, #0x208]
 
 	mov	r0, #0x12		@ Switch to IRQ Mode
 	msr	cpsr, r0

+ 12 - 0
rtl/nds/prt09.as

@@ -19,6 +19,18 @@ _start:
 	mov	r0, #0x04000000			@ IME = 0;
 	str	r0, [r0, #0x208]
 	
+	@ set sensible stacks to allow bios call
+
+	mov	r0, #0x13		@ Switch to SVC Mode
+	msr	cpsr, r0
+	mov	r1,#0x03000000
+	sub	r1,r1,#0x1000
+	mov	sp,r1
+	mov	r0, #0x1F		@ Switch to System Mode
+	msr	cpsr, r0
+	sub	r1,r1,#0x100
+	mov	sp,r1
+	
 	ldr	r3,=__libnds_mpu_setup
 	blx	r3
 

+ 9 - 6
rtl/nds/sysdir.inc

@@ -19,22 +19,25 @@
 {*****************************************************************************
                            Directory Handling
 *****************************************************************************}
-procedure mkdir(const s: string);[IOCheck];
+procedure mkdir(s: pchar; len: sizeuint);[IOCheck, public, alias : 'FPC_SYS_MKDIR'];
 begin
+  if not assigned(s) or (len=0) or (InOutRes<>0) then exit;
   if FileIODevice.DirIO.DoMkdir <> nil then
-    FileIODevice.DirIO.DoMkdir(s);
+    FileIODevice.DirIO.DoMkdir(strpas(s));
 end;
 
-procedure rmdir(const s: string);[IOCheck];
+procedure rmdir(s: pchar; len: sizeuint);[IOCheck, public, alias : 'FPC_SYS_RMDIR'];
 begin
+  if not assigned(s) or (len=0) then exit;
   if FileIODevice.DirIO.DoRmdir <> nil then
-    FileIODevice.DirIO.DoRmdir(s);
+    FileIODevice.DirIO.DoRmdir(strpas(s));
 end;
 
-procedure chdir(const s: string);[IOCheck];
+procedure chdir(s: pchar; len: sizeuint);[IOCheck, public, alias : 'FPC_SYS_CHDIR'];
 begin
+  if not assigned(s) or (len=0) then exit;
   if FileIODevice.DirIO.DoChdir <> nil then
-    FileIODevice.DirIO.DoChdir(s);
+    FileIODevice.DirIO.DoChdir(strpas(s));
 end;
 
 procedure GetDir(DriveNr: byte; var Dir: ShortString);

+ 120 - 24
rtl/nds/system.pp

@@ -18,6 +18,7 @@ unit System;
 interface
 
 {$define FPC_IS_SYSTEM}
+{$define HAS_CMDLINE}
 {$define FPC_HAS_FEATURE_THREADING}
 {$define FPC_HAS_FEATURE_CONSOLEIO}
 {$define FPC_HAS_FEATURE_COMMANDARGS}
@@ -39,28 +40,27 @@ interface
 const
   LineEnding = #10;
   LFNSupport = true;
-  CtrlZMarksEOF: boolean = false;
   DirectorySeparator = '/';
   DriveSeparator = ':';
   ExtensionSeparator = '.';
-  PathSeparator = ';';
+  PathSeparator = ':';
   AllowDirectorySeparators : set of char = ['\','/'];
   AllowDriveSeparators : set of char = [':'];
-  FileNameCaseSensitive = false;
   maxExitCode = 255;
-  MaxPathLen = 255;
-  AllFilesMask = '*';
 
-  sLineBreak: string[1] = LineEnding;
-  DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
+  MaxPathLen = 1024; // BSDs since 1993, Solaris 10, Darwin
+  AllFilesMask = '*';
 
-  UnusedHandle    = $ffff;
+  UnusedHandle    = -1;
   StdInputHandle  = 0;
   StdOutputHandle = 1;
-  StdErrorHandle  = $ffff;
-
+  StdErrorHandle  = 2;
 
+  FileNameCaseSensitive : boolean = true;
+  CtrlZMarksEOF: boolean = true; (* #26 not considered as end of file *)
 
+  sLineBreak = LineEnding;
+  DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
 
 var
   argc: LongInt = 0;
@@ -70,10 +70,18 @@ var
   fake_heap_end: ^byte; cvar; external;
   irq_vector: integer; external name '__irq_vector';
   
-//procedure AssignDevice(FIOD: Pointer); 
+function get_cmdline:Pchar;
+
+property cmdline:Pchar read get_cmdline;
 
 implementation
 
+const 
+  calculated_cmdline: Pchar = nil;
+  { System limits, POSIX value in parentheses, used for buffer and stack allocation }
+  ARG_MAX  = 65536;   {4096}  { Maximum number of argument size     }
+  PATH_MAX = 1024;    {255}   { Maximum number of bytes in pathname }  
+
 {$define fpc_softfpu_implementation}
 {$i softfpu.pp}
 {$undef fpc_softfpu_implementation}
@@ -148,28 +156,112 @@ begin
   random := (a * value) shr 15;
 end;
 
-{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
-{ number of args }
-function paramcount : longint;
+
+
+Function ParamCount: Longint;
+Begin
+  Paramcount:=argc-1
+End;
+
+
+ { variable where full path and filename and executable is stored }
+ { is setup by the startup of the system unit.                    }
+var
+ execpathstr : shortstring;
+
+function paramstr(l: longint) : string;
+ begin
+   { stricly conforming POSIX applications  }
+   { have the executing filename as argv[0] }
+   if l=0 then
+     begin
+       paramstr := execpathstr;
+     end
+   else
+     paramstr:=strpas(argv[l]);
+ end;
+
+{*****************************************************************************
+                                    cmdline
+*****************************************************************************}
+
+procedure SetupCmdLine;
+var
+  bufsize,
+  len,j,
+  size,i : longint;
+  found  : boolean;
+  buf    : pchar;
+
+  procedure AddBuf;
+  begin
+    reallocmem(calculated_cmdline,size+bufsize);
+    move(buf^,calculated_cmdline[size],bufsize);
+    inc(size,bufsize);
+    bufsize:=0;
+  end;
+
 begin
-  paramcount := 0;
+  if argc<=0 then
+    exit;
+  GetMem(buf,ARG_MAX);
+  size:=0;
+  bufsize:=0;
+  i:=0;
+  while (i<argc) do
+   begin
+     len:=strlen(argv[i]);
+     if len>ARG_MAX-2 then
+      len:=ARG_MAX-2;
+     found:=false;
+     for j:=1 to len do
+      if argv[i][j]=' ' then
+       begin
+         found:=true;
+         break;
+       end;
+     if bufsize+len>=ARG_MAX-2 then
+      AddBuf;
+     if found then
+      begin
+        buf[bufsize]:='"';
+        inc(bufsize);
+      end;
+     move(argv[i]^,buf[bufsize],len);
+     inc(bufsize,len);
+     if found then
+      begin
+        buf[bufsize]:='"';
+        inc(bufsize);
+      end;
+     if i<argc then
+      buf[bufsize]:=' '
+     else
+      buf[bufsize]:=#0;
+     inc(bufsize);
+     inc(i);
+   end;
+  AddBuf;
+  FreeMem(buf,ARG_MAX);
 end;
 
-{ argument number l }
-function paramstr(l : longint) : string;
+function get_cmdline:Pchar;
+
 begin
-  paramstr := '';
+  if calculated_cmdline=nil then
+    setupcmdline;
+  get_cmdline:=calculated_cmdline;
 end;
-{$endif FPC_HAS_FEATURE_COMMANDARGS}
 
-{$ifdef FPC_HAS_FEATURE_TEXTIO}
+
 procedure SysInitStdIO;
 begin
-  OpenStdIO(Input,fmInput,StdInputHandle);
-  OpenStdIO(Output,fmOutput,StdOutputHandle);
-  OpenStdIO(StdOut,fmOutput,StdOutputHandle);
+  OpenStdIO(Input,fmInput,0);
+  OpenStdIO(Output,fmOutput,0);
+  OpenStdIO(ErrOutput,fmOutput,0);
+  OpenStdIO(StdOut,fmOutput,0);
+  OpenStdIO(StdErr,fmOutput,0);
 end;
-{$endif}
 
 
 function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
@@ -189,6 +281,10 @@ begin
 { Setup heap }
   InitHeap;
   SysInitExceptions;
+
+  SetupCmdLine;
+  
+  
 {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
   { Setup stdin, stdout and stderr }
   SysInitStdIO;

+ 1 - 1
rtl/nds/sysutils.pp

@@ -223,7 +223,7 @@ end;
                               Misc Functions
 ****************************************************************************}
 
-procedure Beep;
+Procedure SysBeep;
 begin
 end;