home *** CD-ROM | disk | FTP | other *** search
/ Millennium Time Capsule / AC2000.BIN / disks / ac5_disk / kp_ejp / ejp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-21  |  7.8 KB  |  303 lines

  1. /*
  2. **    ejp.h
  3. **    =====
  4. **
  5. **    By Xav
  6. **    ======
  7. **
  8. **
  9. **    Definitions and functions to make it easier and clearer to read the 
  10. **    enhanced joystick ports
  11. **
  12. **    Includes definitions for:-
  13. **
  14. **        + Joypads
  15. **
  16. **
  17. **
  18. **    And functions to:-
  19. **
  20. **        + Read joypad A
  21. **        + Store the current joypad positions as the "old" positions
  22. **
  23. */
  24.  
  25. /*
  26. **    Include header files
  27. */
  28.  
  29. #include <osbind.h>                /* Contains Super()    */
  30. #include <stdlib.h>                /* Contains NULL        */
  31. #include "masks.h"
  32. #include "ejp_defs.h"
  33.  
  34.  
  35. /*
  36. ** Function prototypes
  37. */
  38.  
  39. void read_joypadA (struct JOYPAD *joypad_A);
  40. void store_old_positions(struct JOYPAD *joyp_struct);
  41.  
  42.  
  43.  
  44. /*
  45. **    Define the button names: FIRE_A_B is fire button A for port B
  46. */
  47.  
  48. #define    PAUSE_A                0xFFFE    /*    Bit 0  clear    */
  49. #define FIRE_A_A            0xFFFD    /*    Bit 1  clear    */
  50. #define    PAUSE_B                0xFFFB    /*    Bit 2  clear    */
  51. #define FIRE_A_B            0xFFF7    /*    Bit 3  clear    */
  52.  
  53. #define    FIRE_B_A            0xFFFD    /*    Bit 1  clear    */
  54. #define    FIRE_B_B            0xFFF7    /*    Bit 3  clear    */
  55.  
  56. #define    FIRE_C_A            0xFFFD    /*    Bit 1  clear    */
  57. #define    FIRE_C_B            0xFFF7    /*    Bit 3  clear    */
  58.  
  59. #define OPTION_A            0xFFFD    /*    Bit 1  clear    */
  60. #define OPTION_B            0xFFF7    /*    Bit 3  clear    */
  61.  
  62. #define    UP_A                    0xFEFF    /*    Bit 8  clear    */
  63. #define DOWN_A                0xFDFF    /*    Bit 9  clear    */
  64. #define    LEFT_A                0xFBFF    /*    Bit 10 clear    */
  65. #define    RIGHT_A                0xF7FF    /*    Bit 11 clear    */
  66. #define    UP_B                    0xEFFF    /*    Bit 12 clear    */
  67. #define    DOWN_B                0xDFFF    /*    Bit 13 clear    */
  68. #define LEFT_B                0xBFFF    /*    Bit 14 clear    */
  69. #define    RIGHT_B                0x7FFF    /*    Bit 15 clear    */
  70.  
  71. #define    KEYPAD_STAR_A    0xFEFF    /*    Bit 8  clear    */
  72. #define KEYPAD_7_A        0xFDFF    /*    Bit 9  clear    */
  73. #define    KEYPAD_4_A        0xFBFF    /*    Bit 10 clear    */
  74. #define    KEYPAD_1_A        0xF7FF    /*    Bit 11 clear    */
  75. #define    KEYPAD_STAR_B    0xEFFF    /*    Bit 12 clear    */
  76. #define    KEYPAD_7_B        0xDFFF    /*    Bit 13 clear    */
  77. #define KEYPAD_4_B        0xBFFF    /*    Bit 14 clear    */
  78. #define    KEYPAD_1_B        0x7FFF    /*    Bit 15 clear    */
  79.  
  80. #define    KEYPAD_0_A        0xFEFF    /*    Bit 8  clear    */
  81. #define KEYPAD_8_A        0xFDFF    /*    Bit 9  clear    */
  82. #define    KEYPAD_5_A        0xFBFF    /*    Bit 10 clear    */
  83. #define    KEYPAD_2_A        0xF7FF    /*    Bit 11 clear    */
  84. #define    KEYPAD_0_B        0xEFFF    /*    Bit 12 clear    */
  85. #define    KEYPAD_8_B        0xDFFF    /*    Bit 13 clear    */
  86. #define KEYPAD_5_B        0xBFFF    /*    Bit 14 clear    */
  87. #define    KEYPAD_2_B        0x7FFF    /*    Bit 15 clear    */
  88.  
  89. #define    KEYPAD_HASH_A    0xFEFF    /*    Bit 8  clear    */
  90. #define KEYPAD_9_A        0xFDFF    /*    Bit 9  clear    */
  91. #define    KEYPAD_6_A        0xFBFF    /*    Bit 10 clear    */
  92. #define    KEYPAD_3_A        0xF7FF    /*    Bit 11 clear    */
  93. #define    KEYPAD_HASH_B    0xEFFF    /*    Bit 12 clear    */
  94. #define    KEYPAD_9_B        0xDFFF    /*    Bit 13 clear    */
  95. #define KEYPAD_6_B        0xBFFF    /*    Bit 14 clear    */
  96. #define    KEYPAD_3_B        0x7FFF    /*    Bit 15 clear    */
  97.  
  98.  
  99.  
  100. /*
  101. **    Joypad returns are boolean, so define TRUE and FALSE
  102. */
  103.  
  104. #define TRUE    1
  105. #define FALSE    0
  106.  
  107.  
  108. /**********************************************************
  109. **
  110. **    Functions begin here
  111. **
  112. **    Current functions are:-
  113. **
  114. **        + read_joypadA();
  115. **        + store_old_positions();
  116. **
  117. */
  118.  
  119.  
  120. /*
  121. **    read_joypadA(struct JOYPAD *joypad_A);
  122. **
  123. **    Reads joypad A once and fills in the JOYPAD
  124. **    structure, ready for the main program to read.
  125. */
  126.  
  127. void read_joypadA(struct JOYPAD *joypad_A)
  128. {
  129.     void *stack_address;
  130.     short *mask_address = (short *)0xFF9202;
  131.     short *firebuttons = (short *)0xFF9200;
  132.     short *keypad = (short *)0xFF9202;
  133.     unsigned long firebuttons_pressed;
  134.     unsigned long keypad_pressed;    
  135.     
  136.     
  137.     /*
  138.     **    First store the existing positions as the "old" ones
  139.     */
  140.  
  141.     store_old_positions(joypad_A);
  142.  
  143.     /*
  144.     **    Read group 1 (up, down, left, right, pause, fire A)
  145.     */
  146.  
  147.     /* Supervisor mode    */    
  148.     stack_address = Super(NULL);
  149.  
  150.         /* Write the mask    */
  151.         *mask_address = PORTA_GROUP1;
  152.         
  153.         /* Read the results    */
  154.         firebuttons_pressed = *firebuttons;
  155.         keypad_pressed = *keypad;            
  156.     
  157.     /* Back into user mode    */
  158.     Super(stack_address);
  159.     
  160.     
  161.     /* Now just assign a TRUE to each element of the structure if
  162.             the appropriate button is being pressed    */
  163.         
  164.     if(~(keypad_pressed | UP_A)) joypad_A->UP = TRUE; 
  165.         else joypad_A->UP = FALSE;
  166.     
  167.     if(~(keypad_pressed | DOWN_A)) joypad_A->DOWN = TRUE;
  168.         else joypad_A->DOWN = FALSE;
  169.     
  170.     if(~(keypad_pressed | LEFT_A)) joypad_A->LEFT = TRUE;
  171.         else joypad_A->LEFT = FALSE;
  172.     
  173.     if(~(keypad_pressed | RIGHT_A)) joypad_A->RIGHT = TRUE;
  174.         else joypad_A->RIGHT = FALSE;
  175.  
  176.     if(~(firebuttons_pressed | PAUSE_A)) joypad_A->PAUSE = TRUE;
  177.         else joypad_A->PAUSE = FALSE;
  178.             
  179.     if(~(firebuttons_pressed | FIRE_A_A)) joypad_A->FIRE_A = TRUE;
  180.         else joypad_A->FIRE_A = FALSE;
  181.         
  182.  
  183.     /*
  184.     **    Read group 2 (*, 7, 4, 1, fire B)
  185.     */
  186.  
  187.     stack_address = Super(NULL);
  188.     
  189.         *mask_address = PORTA_GROUP2;
  190.         firebuttons_pressed = *firebuttons;
  191.         keypad_pressed = *keypad;            
  192.     
  193.     Super(stack_address);
  194.     
  195.     
  196.     if(~(keypad_pressed | KEYPAD_STAR_A)) joypad_A->NUMPAD_STAR = TRUE; 
  197.         else joypad_A->NUMPAD_STAR = FALSE;
  198.  
  199.     if(~(keypad_pressed | KEYPAD_7_A)) joypad_A->NUMPAD_7 = TRUE;
  200.         else joypad_A->NUMPAD_7 = FALSE;
  201.     
  202.     if(~(keypad_pressed | KEYPAD_4_A)) joypad_A->NUMPAD_4 = TRUE;
  203.         else joypad_A->NUMPAD_4 = FALSE;
  204.     
  205.     if(~(keypad_pressed | KEYPAD_1_A)) joypad_A->NUMPAD_1 = TRUE;
  206.         else joypad_A->NUMPAD_1 = FALSE;
  207.             
  208.     if(~(firebuttons_pressed | FIRE_B_A)) joypad_A->FIRE_B = TRUE;
  209.         else joypad_A->FIRE_B = FALSE;
  210.  
  211.  
  212.  
  213.     /*
  214.     **    Read group 3 (0, 8, 5, 2, fire C)
  215.     */
  216.  
  217.     stack_address = Super(NULL);
  218.     
  219.         *mask_address = PORTA_GROUP3;
  220.         firebuttons_pressed = *firebuttons;
  221.         keypad_pressed = *keypad;            
  222.     
  223.     Super(stack_address);
  224.     
  225.     
  226.     if(~(keypad_pressed | KEYPAD_0_A)) joypad_A->NUMPAD_0 = TRUE; 
  227.         else joypad_A->NUMPAD_0 = FALSE;
  228.  
  229.     if(~(keypad_pressed | KEYPAD_8_A)) joypad_A->NUMPAD_8 = TRUE;
  230.         else joypad_A->NUMPAD_8 = FALSE;
  231.     
  232.     if(~(keypad_pressed | KEYPAD_5_A)) joypad_A->NUMPAD_5 = TRUE;
  233.         else joypad_A->NUMPAD_5 = FALSE;
  234.     
  235.     if(~(keypad_pressed | KEYPAD_2_A)) joypad_A->NUMPAD_2 = TRUE;
  236.         else joypad_A->NUMPAD_2 = FALSE;
  237.  
  238.     if(~(firebuttons_pressed | FIRE_C_A)) joypad_A->FIRE_C = TRUE;
  239.         else joypad_A->FIRE_C = FALSE;
  240.         
  241.         
  242.     /*
  243.     **    Read group 4 (#, 9, 6, 3, Option)
  244.     */
  245.  
  246.     stack_address = Super(NULL);
  247.     
  248.         *mask_address = PORTA_GROUP4;
  249.         firebuttons_pressed = *firebuttons;
  250.         keypad_pressed = *keypad;            
  251.     
  252.     Super(stack_address);
  253.     
  254.     
  255.     if(~(keypad_pressed | KEYPAD_HASH_A)) joypad_A->NUMPAD_HASH = TRUE; 
  256.         else joypad_A->NUMPAD_HASH = FALSE;
  257.  
  258.     if(~(keypad_pressed | KEYPAD_9_A)) joypad_A->NUMPAD_9 = TRUE;
  259.         else joypad_A->NUMPAD_9 = FALSE;
  260.     
  261.     if(~(keypad_pressed | KEYPAD_6_A)) joypad_A->NUMPAD_6 = TRUE;
  262.         else joypad_A->NUMPAD_6 = FALSE;
  263.     
  264.     if(~(keypad_pressed | KEYPAD_3_A)) joypad_A->NUMPAD_3 = TRUE;
  265.         else joypad_A->NUMPAD_3 = FALSE;
  266.  
  267.     if(~(firebuttons_pressed | OPTION_A)) joypad_A->OPTION = TRUE;
  268.         else joypad_A->OPTION = FALSE;
  269.  
  270.     return;
  271. }
  272.  
  273.  
  274. /*
  275. **    void store_old_positions(struct JOYPAD *joyp_struct)
  276. */
  277.  
  278. void store_old_positions(struct JOYPAD *joyp_struct)
  279. {
  280.     joyp_struct->OLD_UP = joyp_struct->UP;
  281.     joyp_struct->OLD_DOWN = joyp_struct->DOWN;
  282.     joyp_struct->OLD_LEFT = joyp_struct->LEFT;
  283.     joyp_struct->OLD_RIGHT = joyp_struct->RIGHT;
  284.     joyp_struct->OLD_FIRE_A = joyp_struct->FIRE_A;
  285.     joyp_struct->OLD_FIRE_B = joyp_struct->FIRE_B;
  286.     joyp_struct->OLD_FIRE_C = joyp_struct->FIRE_C;
  287.     joyp_struct->OLD_PAUSE = joyp_struct->PAUSE;
  288.     joyp_struct->OLD_OPTION = joyp_struct->OPTION;
  289.     joyp_struct->OLD_NUMPAD_0 = joyp_struct->NUMPAD_0;
  290.     joyp_struct->OLD_NUMPAD_1 = joyp_struct->NUMPAD_1;
  291.     joyp_struct->OLD_NUMPAD_2 = joyp_struct->NUMPAD_2;
  292.     joyp_struct->OLD_NUMPAD_3 = joyp_struct->NUMPAD_3;
  293.     joyp_struct->OLD_NUMPAD_4 = joyp_struct->NUMPAD_4;
  294.     joyp_struct->OLD_NUMPAD_5 = joyp_struct->NUMPAD_5; 
  295.     joyp_struct->OLD_NUMPAD_6 = joyp_struct->NUMPAD_6;
  296.     joyp_struct->OLD_NUMPAD_7 = joyp_struct->NUMPAD_7;
  297.     joyp_struct->OLD_NUMPAD_8 = joyp_struct->NUMPAD_8;
  298.     joyp_struct->OLD_NUMPAD_9 = joyp_struct->NUMPAD_9;
  299.     joyp_struct->OLD_NUMPAD_STAR = joyp_struct->NUMPAD_STAR;
  300.     joyp_struct->OLD_NUMPAD_HASH = joyp_struct->NUMPAD_HASH;
  301.  
  302.     return;
  303. }