directory.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. program directory;
  2. {$J+}
  3. {$macro on}
  4. {$mode objfpc}
  5. {$goto on}
  6. uses
  7. cmem, ctypes, fat, gccore;
  8. label err;
  9. var
  10. xfb: pcuint32 = nil;
  11. rmode: PGXRModeObj = nil;
  12. MyDir: PDIR;
  13. pent: pdirent;
  14. statbuf: stat;
  15. begin
  16. // Initialise the video system
  17. VIDEO_Init();
  18. // This function initialises the attached controllers
  19. WPAD_Init();
  20. // Obtain the preferred video mode from the system
  21. // This will correspond to the settings in the Wii menu
  22. rmode := VIDEO_GetPreferredMode(nil);
  23. // Allocate memory for the display in the uncached region
  24. xfb := (SYS_AllocateFramebuffer(rmode));
  25. // Initialise the console, required for printf
  26. console_init(xfb,20,20,rmode^.fbWidth,rmode^.xfbHeight,rmode^.fbWidth*VI_DISPLAY_PIX_SZ);
  27. // Set up the video registers with the chosen mode
  28. VIDEO_Configure(rmode);
  29. // Tell the video hardware where our display memory is
  30. VIDEO_SetNextFramebuffer(xfb);
  31. // Make the display visible
  32. VIDEO_SetBlack(FALSE);
  33. // Flush the video register changes to the hardware
  34. VIDEO_Flush();
  35. // Wait for Video setup to complete
  36. VIDEO_WaitVSync();
  37. if (rmode^.viTVMode and VI_NON_INTERLACE) <> 0 then VIDEO_WaitVSync();
  38. // The console understands VT terminal escape codes
  39. // This positions the cursor on row 2, column 0
  40. // we can use variables for this with format codes too
  41. // e.g. printf ("\x1b[%d;%dH", row, column );
  42. printf(#$1b'[2;0H');
  43. if not fatInitDefault() then
  44. begin
  45. printf('fatInitDefault failure: terminating'#10);
  46. goto err;
  47. end;
  48. MyDir := opendir('/');
  49. if MyDir = nil then
  50. begin
  51. printf('opendir() failure; terminating'#10);
  52. goto err;
  53. end;
  54. pent := readdir(MyDir);
  55. while pent <> nil do
  56. begin
  57. _stat(pent^.d_name, statbuf);
  58. if (strcmp('.', pent^.d_name) = 0) or (strcmp('..', pent^.d_name) = 0) then
  59. continue;
  60. if (S_ISDIR(statbuf.st_mode)) then
  61. printf('%s <dir>'#10, pent^.d_name);
  62. if (not (S_ISDIR(statbuf.st_mode))) then
  63. printf('%s %lld'#10, pent^.d_name, statbuf.st_size);
  64. end;
  65. closedir(MyDir);
  66. err:
  67. while true do
  68. begin
  69. // Call WPAD_ScanPads each loop, this reads the latest controller states
  70. WPAD_ScanPads();
  71. // WPAD_ButtonsDown tells us which buttons were pressed in this loop
  72. // this is a "one shot" state which will not fire again until the button has been released
  73. // We return to the launcher application via exit
  74. if ( WPAD_ButtonsDown(0) and WPAD_BUTTON_HOME ) <> 0 then exit;
  75. // Wait for the next frame
  76. VIDEO_WaitVSync();
  77. end;
  78. end.