basic_stdin.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. program basic_stdin;
  2. {$J+}
  3. {$macro on}
  4. {$mode objfpc}
  5. uses
  6. cmem, ctypes, gccore;
  7. var
  8. xfb: pcuint32 = nil;
  9. rmode: PGXRModeObj = nil;
  10. quitapp: boolean = false;
  11. key : cchar;
  12. function putchar(__c: longint): longint; cdecl; external;
  13. function getchar:longint;cdecl;external;
  14. procedure keyPress_cb(sym: cchar); cdecl;
  15. begin
  16. if (sym > 31 ) then putchar(sym);
  17. if (sym = 13) then putchar(Ord($10));
  18. if (Ord(sym) = $1b) then quitapp := true;
  19. end;
  20. begin
  21. // Initialise the video system
  22. VIDEO_Init();
  23. // This function initialises the attached controllers
  24. WPAD_Init();
  25. // Obtain the preferred video mode from the system
  26. // This will correspond to the settings in the Wii menu
  27. rmode := VIDEO_GetPreferredMode(nil);
  28. // Allocate memory for the display in the uncached region
  29. xfb := SYS_AllocateFramebuffer(rmode);
  30. // Initialise the console, required for printf
  31. console_init(xfb,20,20,rmode^.fbWidth,rmode^.xfbHeight,rmode^.fbWidth*VI_DISPLAY_PIX_SZ);
  32. // Set up the video registers with the chosen mode
  33. VIDEO_Configure(rmode);
  34. // Tell the video hardware where our display memory is
  35. VIDEO_SetNextFramebuffer(xfb);
  36. // Make the display visible
  37. VIDEO_SetBlack(FALSE);
  38. // Flush the video register changes to the hardware
  39. VIDEO_Flush();
  40. // Wait for Video setup to complete
  41. VIDEO_WaitVSync();
  42. if(rmode^.viTVMode and VI_NON_INTERLACE) <> 0 then VIDEO_WaitVSync();
  43. // The console understands VT terminal escape codes
  44. // This positions the cursor on row 2, column 0
  45. // we can use variables for this with format codes too
  46. // e.g. printf ("\x1b[%d;%dH", row, column );
  47. printf(#$1b'[2;0HHello World!'#10);
  48. if (KEYBOARD_Init(@keyPress_cb) = 0) then
  49. printf('keyboard initialised'#10);
  50. repeat
  51. // Call WPAD_ScanPads each loop, this reads the latest controller states
  52. WPAD_ScanPads();
  53. // WPAD_ButtonsDown tells us which buttons were pressed in this loop
  54. // this is a "one shot" state which will not fire again until the button has been released
  55. key := getchar();
  56. // We return to the launcher application via exit
  57. if ( WPAD_ButtonsDown(0) and WPAD_BUTTON_HOME ) <> 0 then quitapp := true;
  58. // Wait for the next frame
  59. VIDEO_WaitVSync();
  60. until quitapp;
  61. end.