gray.h 5.4 KB

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