Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.1 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "bios.h"
  2. #include "../../core/base/basicTypes.h"
  3. #include "syscallnr.h"
  4. #define sps2_bios_sc_in0_out0( CALL ) __asm__ __volatile__( "li $3, " ZSTR(CALL) " \nsyscall \nnop \n" )
  5. #define sps2_bios_sc_in1_out0( CALL, ARG0 ) __asm__ __volatile__( "li $3, " ZSTR(CALL) " \nori $4, %0, 0 \nsyscall \nnop \n" :: "r" (ARG0) )
  6. #define sps2_bios_sc_in2_out0( CALL, ARG0, ARG1 ) __asm__ __volatile__( "li $3, " ZSTR(CALL) " \nori $4, %0, 0 \nori $5, %0, 0 \nsyscall \nnop \n" :: "r" (ARG0), "r" (ARG1) )
  7. #define sps2_bios_sc_in3_out0( CALL, ARG0, ARG1, ARG2 ) __asm__ __volatile__( "li $3, " ZSTR(CALL) " \nori $4, %0, 0 \nori $5, %1, 0 \nori $6, %2, 0 \nsyscall \nnop \n" :: "r" (ARG0), "r" (ARG1), "r" (ARG2) )
  8. #define sps2_bios_sc_in4_out0( CALL, ARG0, ARG1, ARG2, ARG2 ) __asm__ __volatile__( "li $3, " ZSTR(CALL) " \nori $4, %0, 0 \nori $5, %1, 0 \nori $6, %2, 0 \nori $7, %3, 0 \nsyscall \nnop \n" :: "r" (ARG0), "r" (ARG1), "r" (ARG2), "r" (ARG3) )
  9. #define sps2_bios_sc_in0_out1( CALL, RVAL0 ) __asm__ __volatile__( "li $3, " ZSTR(CALL) " \nsyscall \nnop \n" : "r=" (ARG0) )
  10. #define ZSTR( X ) #X
  11. void sps2_ee_reset( uint32_t init_bitfield ){
  12. sps2_bios_sc_in1_out0( __NR_ResetEE, init_bitfield );
  13. };
  14. void sps2_gs_set_mode( uint32_t interlace, uint32_t mode, uint32_t field ){
  15. sps2_bios_sc_in3_out0( __NR_SetGsCrt, interlace, mode, field );
  16. };
  17. void sps2_exit( void ){
  18. sps2_bios_sc_in0_out0( __NR__Exit );
  19. };
  20. void sps2_load_exec( const char *fileName, uint32_t argc, char **argv ){
  21. sps2_bios_sc_in3_out0( __NR__LoadExecPS2, fileName, argc, argv );
  22. };
  23. void sps2_mem_exec( void *ptr, uint32_t gp_paramu, int32_t argc, char **argv ){
  24. sps2_bios_sc_in4_out0( __NR__ExecPS2, address, gp_paramu, argc, argv );
  25. };
  26. void sps2_set_sbus_int_handler( uint32_t int_id, (*handler)(unsigned int int_id) ){
  27. sps2_bios_sc_in2_out0( __NR_AddIntcHandler, int_id, handler );
  28. };
  29. void sps2_del_sbus_int_handler( uint32_t int_id ){
  30. sps2_bios_sc_in1_out0( __NR_RemoveSbusIntcHandler, int_id );
  31. };
  32. //Returns int ?? what purpose ?
  33. void sps2_trig_iop_int( uint32_t int_id ){
  34. sps2_bios_sc_in1_out0( __NR_Interrupt2Iop, int_id );
  35. };
  36. // Info obtained from:
  37. // - Gustavo Scotti (gustavo@scotti.com)
  38. // - Marcus R. Brown (mrbrown@0xd6.org)
  39. // - Herben (?) - Video mode information.
  40. // - Loser (?) - More video mode information.
  41. // - Hiryu (?) - Even more video mode information.
  42. /*
  43. void gs_setmode(int interlace, int mode, int field) {
  44. __asm__ __volatile__(
  45. "li $3, 0x02 \n" // Specify the syscall. (reg 3)
  46. "add $4, $0, %0 \n" // Specify the arguments. (regs 4 - 11)
  47. "add $5, $0, %1 \n" //
  48. "add $6, $0, %2 \n" //
  49. "syscall \n" // Perform the syscall.
  50. "nop \n" //
  51. :
  52. : "r" (interlace), "r" (mode), "r" (field)
  53. );
  54. };
  55. */
  56. __asm__ (
  57. ".set push\n"
  58. ".set noreorder\n"
  59. ".text\n"
  60. ".align 4\n"
  61. ".globl __syscall\n"
  62. ".type __syscall,@function\n"
  63. ".ent __syscall,0\n"
  64. "__syscall:\n"
  65. "\tmfc0 $2, $12\n\t" // Move From System Control Coprocessor GPR[$2] <- CPR[0,$12]
  66. "andi $2, $2, 0x18\n\t" // AND IMIDIATE GRP[$2] = 0x18 & GPR[$2]
  67. "beqz $2, _kMode\n\t" // if GPR[$2] == 0 -> _KMode
  68. "slt $2, $3, $0\n\t" // if ( GPR[$3] < GPR[$0] ) GPR[$2] = 1 else GPR[$2] = 0
  69. "syscall\n\t" // real syscal
  70. "jr $31\n\t" // sets GPR[$31] tp a PC .... goto address in GPR[$31]
  71. "nop\n"
  72. "_kMode:\n\t"
  73. "subu $26, $0, $3\n\t"
  74. "movn $3, $26, $2\n\t"
  75. "sll $3, $3, 2\n\t"
  76. "lui $26, 0x8000\n\t"
  77. "lhu $2, 0x02F0($26)\n\t"
  78. "sll $2, $2, 16\n\t"
  79. "lh $26, 0x02F8($26)\n\t"
  80. "add $2, $26\n\t"
  81. "addu $3, $2\n\t"
  82. "lw $26, 0x00($3)\n\t"
  83. "jr $26\n\t"
  84. "nop\n"
  85. ".end __syscall\n"
  86. ".size __syscall,.-__syscall\n"
  87. ".set pop\n"
  88. );