platform.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* MegaZeux
  2. *
  3. * Copyright (C) 2009 Alistair John Strachan <alistair@devzero.co.uk>
  4. * Copyright (C) 2007-2009 Kevin Vance <kvance@kvance.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdarg.h>
  21. #include "platform.h"
  22. #include "../../src/platform.h"
  23. #undef main
  24. #include "../../src/util.h"
  25. #include "../../src/event.h"
  26. #include "../../src/error.h"
  27. #include "../../src/graphics.h"
  28. #include <unistd.h>
  29. #include <stdio.h>
  30. #include <3ds.h>
  31. #include <citro3d.h>
  32. #include "keyboard.h"
  33. static u8 isNot2DS;
  34. FILE *popen(const char *command, const char *type)
  35. {
  36. return NULL;
  37. }
  38. int pclose(FILE *stream)
  39. {
  40. return 0;
  41. }
  42. void delay(Uint32 ms)
  43. {
  44. if(ms > 0)
  45. {
  46. svcSleepThread(1e6 * ms);
  47. }
  48. }
  49. boolean ctr_is_2d(void)
  50. {
  51. return isNot2DS == 0;
  52. }
  53. Uint32 get_ticks(void)
  54. {
  55. return (Uint32)osGetTime();
  56. }
  57. boolean platform_init(void)
  58. {
  59. cfguInit();
  60. romfsInit();
  61. osSetSpeedupEnable(1);
  62. APT_SetAppCpuTimeLimit(80);
  63. gfxInitDefault();
  64. gfxSet3D(false);
  65. C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
  66. CFGU_GetModelNintendo2DS(&isNot2DS);
  67. return true;
  68. }
  69. void platform_quit(void)
  70. {
  71. C3D_Fini();
  72. gfxExit();
  73. romfsExit();
  74. cfguExit();
  75. }
  76. void initialize_joysticks(void)
  77. {
  78. // stub - hardcoded
  79. }
  80. void real_warp_mouse(int x, int y)
  81. {
  82. // Since we can't warp a touchscreen stylus, focus there instead.
  83. focus_pixel(x, y);
  84. }
  85. #ifdef CONFIG_CHECK_ALLOC
  86. static void out_of_linear_memory_check(void *p, const char *file, int line)
  87. {
  88. char msgbuf[128];
  89. if(!p)
  90. {
  91. snprintf(msgbuf, sizeof(msgbuf), "Out of linear memory in %s:%d",
  92. file, line);
  93. msgbuf[sizeof(msgbuf)-1] = '\0';
  94. error(msgbuf, 2, 4, 0);
  95. }
  96. }
  97. void *check_linearAlloc(size_t size, size_t alignment, const char *file,
  98. int line)
  99. {
  100. void *result = linearMemAlign(size, alignment);
  101. out_of_linear_memory_check(result, file, line);
  102. return result;
  103. }
  104. #endif
  105. /**
  106. * argv[0] will either not exist (cia) or be the location of the 3dsx.
  107. * For the cia case we can't really do anything, so assume a SHAREDIR
  108. * startup location.
  109. */
  110. int main(int argc, char *argv[])
  111. {
  112. static char _argv0[] = SHAREDIR "/mzxrun.3dsx";
  113. static char *_argv[] = { _argv0 };
  114. if(argc < 1 || argv == NULL || argv[0] == NULL)
  115. {
  116. iprintf("argv[0]: not found.\n"
  117. "using '%s'\n"
  118. "WARNING: Use of a loader that supports argv[0] is recommended.\n",
  119. _argv0);
  120. chdir(SHAREDIR);
  121. real_main(1, _argv);
  122. }
  123. else
  124. {
  125. iprintf("argv[0]: '%s'\n", argv[0]);
  126. real_main(argc, argv);
  127. }
  128. return 0;
  129. }