Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. ; NESMaker Gamepad / Controller bits
  2. ; 7 - 6 - 5 - 4 - 3 - 2 - 1 - 0
  3. ; | | | | | | | + -- A
  4. ; | | | | | | +------- B
  5. ; | | | | | + ---------- Select
  6. ; | | | | +--------------- Start
  7. ; | | | +------------------- Up
  8. ; | | +----------------------- Down
  9. ; | + -------------------------- Left
  10. ; +------------------------------- Right
  11.  
  12. ; Verified/tested
  13. ; - nesmaker_4_1_5, Basic_NoScroll
  14. ; - This should also work in all previous versions and cores
  15.  
  16. ; How to use
  17. ; ======================
  18. ; Writing code in NESMaker to use the gamepad directly should not be used inside an "Input" script.
  19. ; Input scripts will already be mapped to the gamepad and execute on certain button presses, releases etc.
  20. ; Checking the gamepad directly (like the following examples) is best used in a custom Tile script or
  21. ; the Extra Controller Read script (ExtraInputControl:)
  22.  
  23. ; NOTE: You can check for multiple buttons pressed at the same time, look near the end of this document!
  24.  
  25.  
  26. ; Example A press
  27. ; ==========================================
  28. LDA gamepad
  29. AND #%00000001 ; checking for A button
  30. BNE +
  31. ; A was not pressed, do stuff here then JMP to end
  32. JMP doneAButton
  33. +
  34. ; A was pressed, do some stuff here...
  35.  
  36. doneAButton:
  37. ; NOTE: if this is inside the ExtraInputControl you need to RTS at the very end of the file, Tile scripts don't need RTS
  38. ; ==========================================
  39.  
  40.  
  41.  
  42. ; Example A press - alternate
  43. ; This is smaller code, easier to understand. BUT if you do a lot of stuff
  44. ; when A is pressed the BEQ might not be able to branch, "doneAButton" would be out of range.
  45. ; The remaining examples will not use this alternate version to help avoid those problems.
  46. ; ==========================================
  47. LDA gamepad
  48. AND #%00000001 ; checking for A button
  49. BEQ doneAButton ; A was not pressed, branch to end
  50.  
  51. ; A was pressed, do some stuff here...
  52.  
  53. doneAButton:
  54. ; if inside the ExtraInputControl you need to RTS at the very end, tile scripts dont need RTS
  55. ; ==========================================
  56.  
  57.  
  58.  
  59. ; Example B press
  60. ; ==========================================
  61. LDA gamepad
  62. AND #%00000010 ; checking for B button
  63. BNE +
  64. ; B was not pressed, do stuff here then JMP to end
  65. JMP doneBButton
  66. +
  67. ; B was pressed, do some stuff here...
  68.  
  69. doneBButton:
  70. ; ==========================================
  71.  
  72.  
  73.  
  74. ; Example Select press
  75. ; ==========================================
  76. LDA gamepad
  77. AND #%00000100 ; checking for Select button
  78. BNE +
  79. ; Select was not pressed, do stuff here then JMP to end
  80. JMP doneSelectButton
  81. +
  82. ; Select was pressed, do some stuff here...
  83.  
  84. doneSelectButton:
  85. ; ==========================================
  86.  
  87.  
  88.  
  89. ; Example Start press
  90. ; ==========================================
  91. LDA gamepad
  92. AND #%00001000 ; checking for Start button
  93. BNE +
  94. ; Start was not pressed, do stuff here then JMP to end
  95. JMP doneStartButton
  96. +
  97. ; Start was pressed, do some stuff here...
  98.  
  99. doneStartButton:
  100. ; ==========================================
  101.  
  102.  
  103.  
  104. ; Example Up (d-pad) press
  105. ; ==========================================
  106. LDA gamepad
  107. AND #%00010000 ; checking for Up button
  108. BNE +
  109. ; Up was not pressed, do stuff here then JMP to end
  110. JMP doneUpButton
  111. +
  112. ; Up was pressed, do some stuff here...
  113.  
  114. doneUpButton:
  115. ; ==========================================
  116.  
  117.  
  118.  
  119. ; Example Down (d-pad) press
  120. ; ==========================================
  121. LDA gamepad
  122. AND #%00100000 ; checking for Down button
  123. BNE +
  124. ; Down was not pressed, do stuff here then JMP to end
  125. JMP doneDownButton
  126. +
  127. ; Down was pressed, do some stuff here...
  128.  
  129. doneDownButton:
  130. ; ==========================================
  131.  
  132.  
  133.  
  134. ; Example Left (d-pad) press
  135. ; ==========================================
  136. LDA gamepad
  137. AND #%01000000 ; checking for Left button
  138. BNE +
  139. ; Left was not pressed, do stuff here then JMP to end
  140. JMP doneLeftButton
  141. +
  142. ; Left was pressed, do some stuff here...
  143.  
  144. doneLeftButton:
  145. ; ==========================================
  146.  
  147.  
  148.  
  149. ; Example Right (d-pad) press
  150. ; ==========================================
  151. LDA gamepad
  152. AND #%10000000 ; checking for Right button
  153. BNE +
  154. ; Right was not pressed, do stuff here then JMP to end
  155. JMP doneRightButton
  156. +
  157. ; Right was pressed, do some stuff here...
  158.  
  159. doneRightButton:
  160. ; ==========================================
  161.  
  162.  
  163.  
  164. ; ==================================================================================
  165. ; More examples - multiple buttons
  166. ; ==================================================================================
  167.  
  168. ; Example Any direction (d-pad)
  169. ; ==========================================
  170. LDA gamepad
  171. AND #%11110000 ; checking all d-pad directions
  172. BNE +
  173. ; Nothing on the d-pad was pressed, do stuff here then JMP to end
  174. JMP doneAnyDpad
  175. +
  176. ; At least one of the d-pad buttons was pressed, do some stuff here...
  177.  
  178. doneAnyDpad:
  179. ; ==========================================
  180.  
  181.  
  182.  
  183. ; Example Any button
  184. ; ==========================================
  185. LDA gamepad
  186. AND #%11111111 ; checking all buttons
  187. BNE +
  188. ; Nothing was pressed, do stuff here then JMP to end
  189. JMP doneAnyButton
  190. +
  191. ; At least one button was pressed, do some stuff here...
  192.  
  193. doneAnyButton:
  194. ; ==========================================
  195.  
  196.  
  197.  
  198. ; Example A and B both pressed
  199. ; ==========================================
  200. LDA gamepad
  201. AND #%00000011 ; checking A and B buttons
  202. CMP #%00000011 ; compare to see if both are pressed
  203. BEQ +
  204. ; A and B were not pressed, do stuff here then JMP to end
  205. JMP doneABButtons
  206. +
  207. ; Both A and B buttons were pressed, do some stuff here...
  208.  
  209. doneABButtons:
  210. ; ==========================================
  211.  
  212.  
  213.  
  214. ; Example Only A Button and nothing else
  215. ; ==========================================
  216. LDA gamepad
  217. CMP #%00000001 ; compare to see if only A was pressed
  218. BEQ +
  219. ; A was not pressed, or something else was pressed too. do stuff here then JMP to end
  220. JMP doneOnlyAButton
  221. +
  222. ; Only A was pressed, do some stuff here...
  223.  
  224. doneOnlyAButton:
  225. ; ==========================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement