gbabios.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. This file is part of the Free Component Library (FCL)
  3. Copyright (c) 1999-2002 by the Free Pascal development team
  4. BIOS functions unit for Gameboy Advance
  5. Copyright (c) 2006 by Francesco Lombardi
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *****************************************************************************}
  12. {*****************************************************************************
  13. GBA Bios Functions
  14. *****************************************************************************}
  15. (*
  16. GBA Bios Functions
  17. ------------------
  18. Following infos come from GBATEK, Gameboy Advance Technical Info, that you can
  19. find here: http://nocash.emubase.de/gbatek.htm
  20. GBA Bios includes some useful optimized functions which can be accessed by
  21. SWI. Parameters can be passed to function by r0,r1,r2 and r3 registers; results
  22. are stored in r0,r1 and r3. Unused 'out registers' generally return garbage;
  23. other registers are unchanged.
  24. In ARM mode SWI register are called by:
  25. SWI n * 0x010000
  26. In THUMB mode:
  27. SWI n
  28. SWI Hex Function
  29. --- --- --------
  30. 0 00h SoftReset
  31. 1 01h RegisterRamReset
  32. 2 02h Halt
  33. 3 03h Stop
  34. 4 04h IntrWait
  35. 5 05h VBlankIntrWait
  36. 6 06h Div
  37. 7 07h DivArm
  38. 8 08h Sqrt
  39. 9 09h ArcTan
  40. 10 0Ah ArcTan2
  41. 11 0Bh CpuSet
  42. 12 0Ch CpuFastSet
  43. 13 0Dh -Undoc- ("GetBiosChecksum")
  44. 14 0Eh BgAffineSet
  45. 15 0Fh ObjAffineSet
  46. 16 10h BitUnPack
  47. 17 11h LZ77UnCompWram
  48. 18 12h LZ77UnCompVram
  49. 19 13h HuffUnComp
  50. 20 14h RLUnCompWram
  51. 21 15h RLUnCompVram
  52. 22 16h Diff8bitUnFilterWram
  53. 23 17h Diff8bitUnFilterVram
  54. 24 18h Diff16bitUnFilter
  55. 25 19h SoundBias
  56. 26 1Ah SoundDriverInit
  57. 27 1Bh SoundDriverMode
  58. 28 1Ch SoundDriverMain
  59. 29 1Dh SoundDriverVSync
  60. 30 1Eh SoundChannelClear
  61. 31 1Fh MidiKey2Freq
  62. 32-36 20h-24h -Undoc- (Sound Related ???)
  63. 37 25h MultiBoot
  64. 38 26h -Undoc- ("HardReset")
  65. 39 27h -Undoc- ("CustomHalt")
  66. 40 28h SoundDriverVSyncOff
  67. 41 29h SoundDriverVSyncOn
  68. 42 2Ah -Undoc- ("GetJumpList" for Sound ???)
  69. 43-255 2Bh-FFh -Not used-
  70. Values passed to SWI aren't range-checked, so calling 43-255 will lock-up GBA.
  71. *)
  72. (*
  73. Following defines are intended for future use, when fpc hopefully will handle
  74. both arm and thumb code. I have provided ARM and THUMB funcs, that can be
  75. activated by defines:
  76. {$define __THUMB__}
  77. {$define __ARM__}
  78. At this time I'll force ARM definition in "system.pp"
  79. *)
  80. (* Generic system call !!Does Not Work!!
  81. {$ifdef __THUMB__}
  82. procedure SystemCall(Number: integer); assembler; inline;
  83. asm
  84. SWI r0
  85. end;
  86. {$else}
  87. procedure SystemCall(n: integer); assembler; inline;
  88. asm
  89. MOV R0, R0, LSL #0x10
  90. SWI R0
  91. end;
  92. {$endif}
  93. *)
  94. {$ifdef __THUMB__}
  95. (*=========================
  96. SWI6 Div
  97. Signed Division, r0/r1.
  98. r0 signed 32bit Number
  99. r1 signed 32bit Denom
  100. Return:
  101. r0 Number DIV Denom
  102. =========================*)
  103. function fpc_div_longint(n,z: longint):longint; [public, alias: 'FPC_DIV_LONGINT']; compilerproc; assembler; inline;
  104. asm
  105. swi 6
  106. end;
  107. (*=====================*)
  108. (*=========================
  109. SWI6 DivMod
  110. Signed Division, r0/r1.
  111. r0 signed 32bit Number
  112. r1 signed 32bit Denom
  113. Return:
  114. r1 Number MOD Denom
  115. =========================*)
  116. function fpc_mod_longint(n,z: longint):longint; [public, alias: 'FPC_MOD_LONGINT']; compilerproc; assembler; inline;
  117. asm
  118. swi 6
  119. mov r0, r1
  120. end;
  121. (*=========================*)
  122. {$endif}
  123. {$ifdef __ARM__}
  124. (*=========================
  125. SWI7 DivArm
  126. Signed Division, r1/r0.
  127. r1 signed 32bit Number
  128. r0 signed 32bit Denom
  129. Return:
  130. r0 Number DIV Denom
  131. =========================*)
  132. function fpc_div_longint(n,z: longint):longint; [public, alias: 'FPC_DIV_LONGINT']; compilerproc; assembler; inline;
  133. asm
  134. swi #0x070000
  135. end;
  136. (*=========================*)
  137. (*=========================
  138. SWI7 DivModArm
  139. Signed Division, r1/r0.
  140. r1 signed 32bit Number
  141. r0 signed 32bit Denom
  142. Return:
  143. r1 Number MOD Denom
  144. =========================*)
  145. function fpc_mod_longint(n,z: longint):longint; [public, alias: 'FPC_MOD_LONGINT']; compilerproc; assembler; inline;
  146. asm
  147. swi #0x070000
  148. mov r0, r1
  149. end;
  150. (*=========================*)
  151. {$endif}