home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / BlitPixie / Headers / BlitPixieAsm.h next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  3.6 KB  |  152 lines  |  [TEXT/CWIE]

  1.  
  2. #ifndef USE_ASSEMBLY
  3. #define USE_ASSEMBLY        1    // set this to zero to never use inline assembly.
  4. #endif
  5.  
  6. #ifndef USE_GENERIC_C
  7. #define USE_GENERIC_C        1    // set this to zero for separate asm files (no generic C)
  8. #endif
  9.  
  10. ///--------------------------------------------------------------------------------------
  11.  
  12. #if   USE_ASSEMBLY && (TARGET_CPU_68K || GENERATING68K)
  13.  
  14. #define USE_68K_ASSEMBLY    1
  15. #define USE_PPC_ASSEMBLY    0
  16. #define USE_X86_ASSEMBLY    0
  17.  
  18. #elif USE_ASSEMBLY && (TARGET_CPU_PPC || GENERATINGPOWERPC)
  19.  
  20. #define USE_68K_ASSEMBLY    0
  21. #define USE_PPC_ASSEMBLY    1
  22. #define USE_X86_ASSEMBLY    0
  23.  
  24. #elif USE_ASSEMBLY && (TARGET_CPU_X86 || defined(_X86_) )
  25.  
  26. #define USE_68K_ASSEMBLY    0
  27. #define USE_PPC_ASSEMBLY    0
  28. #define USE_X86_ASSEMBLY    1
  29.  
  30. #else
  31.  
  32. #define USE_68K_ASSEMBLY    0
  33. #define USE_PPC_ASSEMBLY    0
  34. #define USE_X86_ASSEMBLY    0
  35.  
  36. #endif
  37.  
  38. ///--------------------------------------------------------------------------------------
  39.  
  40. #if USE_ASSEMBLY
  41.  
  42. //    INLINE ASSEMBLY declarations and explanations
  43.  
  44. #if USE_68K_ASSEMBLY    // Motorola 68020+ asm
  45.  
  46. // note: all parameters on stack (A7) , fralloc gives us stack frame (A6) for args and locals
  47. //       compiler generates global refs automatically, using either A4 or A5 (resource vs. app)
  48. //       return value normally in D0/A0 (int vs. ptr)
  49.  
  50. // note: registers D0-D2, A0-A1 are volatile
  51.  
  52. #if __MWERKS__            // Metrowerks CodeWarrior
  53.  
  54. #define ASM_FUNC        asm
  55. #define ASM_BEGIN        machine 68020; fralloc +
  56. #define ASM_END            frfree; RTS
  57. #define ASM_NUM(x)        %(x)
  58.  
  59. #pragma code68020 on
  60.  
  61.     // determine size of an int (is it .L, or .W ?)
  62. #define LONGINTS        __option(fourbyteints)
  63.  
  64. #elif THINK_C            // THINK C
  65.  
  66. #define ASM_FUNC
  67. #define ASM_BEGIN        asm 68020 {
  68. #define ASM_END            }
  69. #define ASM_NUM(x)        #(x)
  70.  
  71. #pragma mc68020
  72.  
  73.     // determine size of an int (is it .L, or .W ?)
  74. #if __option(int_4)
  75. #define LONGINTS        1
  76. #else
  77. #define LONGINTS        0
  78. #endif
  79.  
  80. #else
  81.  
  82. #error Compiler unsupported for inline 68k assembly! (set USE_ASSEMBLY = 0)
  83.  
  84. #endif
  85.  
  86. #elif USE_PPC_ASSEMBLY    // PowerPC asm
  87.  
  88. // note: parameters implicitly in registers (r3-r10), no stack frame needed for args
  89. //         global refs normally through RTOC (don't forget to deref to get the actual value)
  90. //       return value normally in r3
  91.  
  92. // note: registers r0, r3-r12, fp0-fp12, cr0-cr1, cr5-7 are volatile
  93.  
  94. #if __MWERKS__            // Metrowerks CodeWarrior
  95.  
  96. // note:    to avoid CW wasting cycles by storing parameters automatically;
  97. //           declare all parameters as 'register' locally, and never use a stack frame.
  98.  
  99. #pragma warn_unusedarg off        // avoids a warning, using param registers directly
  100.  
  101. #define IF_NOT            0x04    // constant for BO field
  102.  
  103. #define CR_NO            4        // multiplier for BI field no
  104. #define CR_LT            0        // constant for BI field
  105. #define CR_GT            1        // constant for BI field
  106. #define CR_EQ            2        // constant for BI field
  107. #define CR_SO            3        // constant for BI field
  108.  
  109. #if __MWERKS__ > 0x2300        // <-- just guessing the version here, playing it safe
  110. #define ASM_NOFRALLOC    nofralloc
  111. #else
  112. #define ASM_NOFRALLOC    // (nofralloc = old default behaviour)
  113. #endif
  114.  
  115. #define ASM_FUNC        asm
  116. #define ASM_BEGIN        ASM_NOFRALLOC
  117. #define ASM_END            blr
  118. #define ASM_NUM(x)        #(x)
  119.  
  120. #else
  121.  
  122. #error Compiler unsupported for inline PPC assembly! (set USE_ASSEMBLY = 0)
  123.  
  124. #endif
  125.  
  126. #elif USE_X86_ASSEMBLY        // Intel x86 asm
  127.  
  128. // note: all parameters on stack
  129.  
  130. #if __MWERKS__            // Metrowerks CodeWarrior
  131.  
  132. #define ASM_FUNC        
  133. #define ASM_BEGIN        asm {
  134. #define ASM_END            }
  135. #define ASM_NUM(x)        #(x)
  136.  
  137. #else
  138.  
  139. #error Compiler unsupported for inline X86 assembly! (set USE_ASSEMBLY = 0)
  140.  
  141. #endif
  142.  
  143. #else
  144.  
  145. #error Platform unsupported for inline assembly! (set USE_ASSEMBLY = 0)
  146.  
  147. #endif /* USE_***_ASSEMBLY */
  148.  
  149. //    These asm instructions written by Anders F Björklund in 1995-1999.
  150.  
  151. #endif
  152.