gray.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef __GRAY
  2. #define __GRAY
  3. #ifndef KERNEL_NEW
  4. #include <default.h>
  5. #endif
  6. /*===========================================================================*/
  7. /* */
  8. /* GrayScale-Support v3.50 for TIGCC */
  9. /* */
  10. /* compatible with HW1/HW2 on all AMS versions up to 2.05 */
  11. /* */
  12. /* */
  13. /* original implementation: Julien Muchembled (as part of UniversalOS) */
  14. /* NOSTUB and OpenSource version: thomas.nussbaumer@gmx.net (TiCT) */
  15. /* */
  16. /*===========================================================================*/
  17. /*--------------------------------------------------------------------------*/
  18. /* INTERNAL SECTION */
  19. /* */
  20. /* DON'T USE THE INTERNAL VARIABLES DIRECTLY - INSTEAD USE THE MACROS BELOW */
  21. /*--------------------------------------------------------------------------*/
  22. extern void* __L_plane; // pointer to light plane of standard buffer
  23. extern void* __D_plane; // pointer to dark plane of standard buffer
  24. extern void* __L_plane2; // pointer to light plane of dbuffer
  25. extern void* __D_plane2; // pointer to dark plane of dbuffer
  26. extern unsigned short __gray_handle;
  27. extern short __gray_hw_type;
  28. extern unsigned short __gray_dbl_offset; // offset to active grayscale doublebuffer (only values 0 and 8 are allowed)
  29. extern volatile unsigned long __switch_cnt;
  30. extern volatile void *__gray_old_int1_hw1; // old INT1 handler on HW1
  31. extern volatile void *__gray_old_int1_hw2; // old INT1 handler on HW2
  32. extern const char __gray_version[]; // just for internal maintainance
  33. /*--------------------------------------------------------------------------*/
  34. /* PUBLIC SECTION */
  35. /*--------------------------------------------------------------------------*/
  36. /* Begin Auto-Generated Part */
  37. #define GRAYDBUFFER_SIZE 7688
  38. #ifndef __HAVE_Bool
  39. #define __HAVE_Bool
  40. enum Bool{FALSE,TRUE};
  41. #endif
  42. #ifndef __HAVE_INT_HANDLER
  43. #define __HAVE_INT_HANDLER
  44. typedef struct __attribute__((__may_alias__)){short foo;}_DEREF_INT_HANDLER,*INT_HANDLER;
  45. #endif
  46. enum GrayModes{GRAY_OFF=0,GRAY_ON=1,GRAY_HW1=1,GRAY_HW2=1};
  47. enum GrayPlanes{LIGHT_PLANE=0,DARK_PLANE=1};
  48. #define GrayAdjust(x) ((void)(*(volatile unsigned char*)0x600013=128-(signed char)(x)))
  49. #define GrayCheckRunning() (!!__gray_handle)
  50. #define IsGrayMode GrayCheckRunning
  51. #define GrayDBufCleanup() ((void)(__gray_dbl_offset=0,__D_plane2=__D_plane,__L_plane2=__L_plane))
  52. #define GrayDBufGetActiveIdx() (!!__gray_dbl_offset)
  53. #define GrayDBufGetActivePlane(x) (GrayDBufGetPlane(GrayDBufGetActiveIdx(),x))
  54. #define GrayDBufGetHiddenIdx() (!__gray_dbl_offset)
  55. #define GrayDBufGetHiddenPlane(x) (GrayDBufGetPlane(GrayDBufGetHiddenIdx(),x))
  56. #define GrayDBufGetPlane(i,x) ((i)?((x)?__D_plane2:__L_plane2):GrayGetPlane(x))
  57. #define GrayDBufInit(p) ({char*aptr=(char*)((((long)p)+7)&0xfffffff8L);__gray_dbl_offset=0;__D_plane2=aptr;(void)(__L_plane2=aptr+3840);})
  58. #define GrayDBufSetActiveAMSPlane(x) GrayDBufSetAMSPlane(GrayDBufGetActiveIdx(),x)
  59. #define GrayDBufSetActiveIdx(i) ((void)(__gray_dbl_offset=((i)?8:0)))
  60. #define GrayDBufSetActiveIdxSync(i) ((void)(GrayWaitNSwitches(1),GrayDBufSetActiveIdx(i)))
  61. #define GrayDBufSetAMSPlane(i,x) (_rom_call(void,(void*,long),1A2)(GrayDBufGetPlane(i,x),0xEF007F))
  62. #define GrayDBufSetHiddenAMSPlane(x) GrayDBufSetAMSPlane(GrayDBufGetHiddenIdx(),x)
  63. #define GrayDBufToggle() ((void)(__gray_dbl_offset=(__gray_dbl_offset?0:8)))
  64. #define GrayDBufToggleSync() ({short __ishw2=_GrayIsRealHW2();if(__ishw2)GrayWaitNSwitches(1);GrayDBufToggle();if(!__ishw2)GrayWaitNSwitches(1);})
  65. #define GrayGetInt1Handler() ((INT_HANDLER)(__gray_hw_type?__gray_old_int1_hw2:__gray_old_int1_hw1))
  66. #define GetGrayInt1Handler GrayGetInt1Handler
  67. #define GrayGetPlane(x) ((x)?__D_plane:__L_plane)
  68. #define GetPlane GrayGetPlane
  69. #define GrayGetSwitchCount() (__switch_cnt)
  70. #define GetGraySwitchCount GrayGetSwitchCount
  71. #define GrayGetVersionString() ((const char*)__gray_version)
  72. #define GrayMode(x) ((x)?GrayOn():({GrayOff();(short)1;}))
  73. extern void GrayOff(void)__ATTR_LIB_ASM__;
  74. extern short GrayOn(void)__ATTR_LIB_ASM__;
  75. extern void GrayOnThrow(void)__ATTR_LIB_ASM__;
  76. #define GraySetAMSPlane(x) (_rom_call(void,(void*,long),1A2)(GrayGetPlane(x),0xEF007F))
  77. #define SetPlane GraySetAMSPlane
  78. #define GraySetInt1Handler(p) ((void)(__gray_hw_type?((INT_HANDLER)__gray_old_int1_hw2=(p)):((INT_HANDLER)__gray_old_int1_hw1=(p))))
  79. #define SetGrayInt1Handler GraySetInt1Handler
  80. #define GraySetSwitchCount(val) (__switch_cnt=(val))
  81. #define SetGraySwitchCount GraySetSwitchCount
  82. #define GrayWaitNSwitches(n) ({unsigned long __w=__switch_cnt+(n);while(__switch_cnt<__w);})
  83. /* End Auto-Generated Part */
  84. #define _GrayIsRealHW2() (__gray_hw_type)
  85. #endif