autoint_fix.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef OSKeyScan
  2. #define OSKeyScan _rom_call(void,(void),298)
  3. #endif
  4. #ifndef OLD_NONTITANIUM_METHOD
  5. void *autoint_fix=0,*autoint_previous=0;
  6. #define MAX_BLOCK1 150
  7. #define MAX_BLOCK2 500
  8. int autoint_fix_block[(MAX_BLOCK1+MAX_BLOCK2)/2];
  9. // !!! DIRTY HACK !!!
  10. // -- but speeds up a whole lot :)
  11. // !!! CAUTION : not tested on AMS3 !!!
  12. void FixAutoint() {
  13. #ifndef PEDROM
  14. autoint_fix=0;
  15. void *v1=GetIntVec(AUTO_INT_1);
  16. autoint_previous=v1;
  17. if (v1>=(void *)0x200000l) {
  18. void *v2=(void *)OSKeyScan;
  19. int l2=(void *)off - v2;
  20. if ((unsigned int)l2>=MAX_BLOCK2) return;
  21. int pos=0;
  22. do {
  23. pos+=2;
  24. if (*(int *)(v1+pos)==0x4e75 || *(int *)(v1+pos)==0x4e73) return;
  25. } while (*(void **)(v1+pos)!=v2);
  26. pos+=4+6; // leave some room for the jmp
  27. if (pos>=MAX_BLOCK1) return;
  28. autoint_fix=autoint_fix_block;
  29. memcpy(autoint_fix,v1,pos);
  30. memcpy(autoint_fix+pos,v2,l2);
  31. *(void **)(autoint_fix+pos-10)=autoint_fix+pos;
  32. *(int *)(autoint_fix+pos-6)=0x4ef9; // jmp abs.l
  33. *(void **)(autoint_fix+pos-4)=v1+pos-6;
  34. int *z=autoint_fix+pos;
  35. while (*z++!=0x58 && l2--);
  36. if (l2>0) *--z=0x10;
  37. SetIntVec(AUTO_INT_1,autoint_fix);
  38. }
  39. #endif
  40. }
  41. void RestoreAutoint() {
  42. #ifndef PEDROM
  43. if (autoint_fix)
  44. SetIntVec(AUTO_INT_1,autoint_previous),autoint_fix=0;
  45. #endif
  46. }
  47. #else
  48. #define IntVec (*(void **)0x40064l)
  49. void *autoint_fix=0,*autoint_previous=0;
  50. // !!! DIRTY HACK !!!
  51. // -- but speeds up a whole lot :)
  52. // !!! CAUTION : not Titanium-compliant !!!
  53. void FixAutoint() {
  54. #ifndef PEDROM
  55. autoint_fix=0;
  56. void *v1=IntVec;
  57. autoint_previous=v1;
  58. if (v1>=(void *)0x200000l) {
  59. void *v2=(void *)OSKeyScan;
  60. int l2=(void *)off - v2;
  61. if ((unsigned int)l2>=500) return;
  62. int pos=0;
  63. do {
  64. pos+=2;
  65. if (*(int *)(v1+pos)==0x4e75) return;
  66. } while (*(void **)(v1+pos)!=v2);
  67. pos+=4+6; // leave some room for the jmp
  68. if (pos>=150) return;
  69. autoint_fix=malloc(pos+l2);
  70. if (!autoint_fix) return;
  71. autoint_fix+=0x40000; // switch to ghost space
  72. memcpy(autoint_fix,v1,pos);
  73. memcpy(autoint_fix+pos,v2,l2);
  74. *(void **)(autoint_fix+pos-10)=autoint_fix+pos;
  75. *(int *)(autoint_fix+pos-6)=0x4ef9; // jmp abs.l
  76. *(void **)(autoint_fix+pos-4)=v1+pos-6;
  77. int *z=autoint_fix+pos;
  78. while (*z++!=0x58 && l2--);
  79. if (l2>0) *--z=0x10;
  80. IntVec=autoint_fix;
  81. }
  82. #endif
  83. }
  84. void RestoreAutoint() {
  85. #ifndef PEDROM
  86. if (autoint_fix)
  87. IntVec=autoint_previous,free(autoint_fix);
  88. #endif
  89. }
  90. #undef IntVec
  91. #endif