template.pp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. program template;
  2. {$J+}
  3. {$macro on}
  4. {$mode objfpc}
  5. uses
  6. ctypes, gccore;
  7. type
  8. _gx_rmodeobj2 = packed record
  9. viTVMode : cuint32;
  10. fbWidth : cuint16;
  11. efbHeight : cuint16;
  12. xfbHeight : cuint16;
  13. viXOrigin : cuint16;
  14. viYOrigin : cuint16;
  15. viWidth : cuint16;
  16. viHeight : cuint16;
  17. xfbMode : cuint32;
  18. field_rendering : cuint8;
  19. aa : cuint8;
  20. sample_pattern : array [0..11, 0..1] of cuint8;
  21. vfilter : array [0..6] of cuint8;
  22. end;
  23. var
  24. xfb: pcuint32;
  25. rmode: PGXRModeObj = nil;
  26. pressed: cuint32;
  27. begin
  28. // Initialise the video system
  29. VIDEO_Init();
  30. // This function initialises the attached controllers
  31. WPAD_Init();
  32. // Obtain the preferred video mode from the system
  33. // This will correspond to the settings in the Wii menu
  34. rmode := VIDEO_GetPreferredMode(nil);
  35. // Allocate memory for the display in the uncached region
  36. xfb := MEM_K0_TO_K1(integer(SYS_AllocateFramebuffer(rmode)));
  37. // Initialise the console, required for printf
  38. //console_init(xfb,
  39. console_init(xfb,
  40. 20, 20,
  41. rmode^.fbWidth, rmode^.xfbHeight,
  42. rmode^.fbWidth * VI_DISPLAY_PIX_SZ);
  43. // Set up the video registers with the chosen mode
  44. VIDEO_Configure(rmode);
  45. // Tell the video hardware where our display memory is
  46. VIDEO_SetNextFramebuffer(xfb);
  47. // Make the display visible
  48. VIDEO_SetBlack(FALSE);
  49. // Flush the video register changes to the hardware
  50. VIDEO_Flush();
  51. // Wait for Video setup to complete
  52. VIDEO_WaitVSync();
  53. if (rmode^.viTVMode and VI_NON_INTERLACE)<> 0 then
  54. VIDEO_WaitVSync();
  55. // The console understands VT terminal escape codes
  56. // This positions the cursor on row 2, column 0
  57. // we can use variables for this with format codes too
  58. // e.g. printf ("\x1b[%d;%dH", row, column );
  59. printf(#27'[2;0H');
  60. printf('Hello World!'#10);
  61. iprintf('%d', sizeof(twgpipe));
  62. while true do
  63. begin
  64. // Call WPAD_ScanPads each loop, this reads the latest controller states
  65. WPAD_ScanPads();
  66. // WPAD_ButtonsDown tells us which buttons were pressed in this loop
  67. // this is a "one shot" state which will not fire again until the button has been released
  68. pressed := WPAD_ButtonsDown(0);
  69. // We return to the launcher application via exit
  70. if ( pressed and WPAD_BUTTON_HOME ) <> 0 then
  71. exit;
  72. // Wait for the next frame
  73. VIDEO_WaitVSync();
  74. end;
  75. end.