Advertisement
NovaYoshi

6502 dumb additions

Apr 1st, 2014
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.01 KB | None | 0 0
  1. Stuff I would add to the 65C02:
  2.  
  3. S16 - Switch into modified SWEET16 mode ( described in another section )
  4.  
  5. USX - Use X for the next instruction instead of A
  6. USY - Use Y for the next instruction instead of A
  7. USZ - Use a zeropage location for the next instruction instead of A
  8.  
  9. DJL zz bb - Decrement zeropage location "zz" and branch to "bb"
  10.  
  11. ASL X - X shift left
  12. LSR X - X shift right
  13. ROL X - X rotate left
  14. ROR X - X rotate right
  15.  
  16. ASL Y - Y shift left
  17. LSR Y - Y shift right
  18. ROL Y - Y rotate left
  19. ROR Y - Y rotate right
  20.  
  21. RND - set A to a random number from 0 to 255
  22. RND #ii - set A to a random number from 0 to "#ii"
  23. RND zp - set A to a random number from 0 to "zp"
  24.  
  25. NOZ - invert zero flag
  26.  
  27. SET x,A - set bit X in accumulator
  28. RES x,A - reset bit X in accumulator
  29. TST x,A - test bit X in accumulator
  30. SZF x,A - copy zero flag to bit X in accumulator
  31.  
  32. TST A - set status flags as if A were the result of a calculation
  33. TST X - set status flags as if X were the result of a calculation
  34. TST Y - set status flags as if Y were the result of a calculation
  35.  
  36. -SWEET16-----------------------------------------------------------------------------------
  37. uses first 32 bytes of memory for its registers
  38.  
  39. R0 - accumulator
  40. R12 - subroutine return stack
  41. R13 - compare instruction results
  42. R14 - prior result (status register)
  43. R15 - program counter
  44.  
  45. Register OPS-
  46.  
  47. 1n SET Rn Constant (Set)
  48. 2n LD Rn (Load)
  49. 3n ST Rn (Store)
  50. 4n LD @Rn (Load Indirect)
  51. 5n ST @Rn (Store Indirect)
  52. 6n LDD @Rn (Load Double Indirect)
  53. 7n STD @Rn (Store Double Indirect)
  54. 8n POP @Rn (Pop Indirect)
  55. 9n STP @Rn (Store POP Indirect)
  56. An ADD Rn (Add)
  57. Bn SUB Rn (Sub)
  58. Cn POPD @Rn (Pop Double Indirect)
  59. Dn CPR Rn (Compare)
  60. En INR Rn (Increment)
  61. Fn DCR Rn (Decrement)
  62.  
  63. Non-register OPS-
  64.  
  65. 00 RTN (Return to 6502 mode)
  66. 01 BR ea (Branch always)
  67. 02 BNC ea (Branch if No Carry)
  68. 03 BC ea (Branch if Carry)
  69. 04 BP ea (Branch if Plus)
  70. 05 BM ea (Branch if Minus)
  71. 06 BZ ea (Branch if Zero)
  72. 07 BNZ ea (Branch if NonZero)
  73. 08 BM1 ea (Branch if Minus 1)
  74. 09 BNM1 ea (Branch if Not Minus 1)
  75. 0A BK (Break)
  76. 0B RS (Return from Subroutine)
  77. 0C BS ea (Branch to Subroutine)
  78. 0D (Unassigned)
  79. 0E (Unassigned)
  80. 0F (Unassigned)
  81.  
  82. -SWEET16-opcodes-(detail)-----------------------------------------------------------------
  83.  
  84. 1n SET Rn Constant (Set)
  85. The 2-byte constant is loaded into Rn (n=0 to F, Hex) and branch conditions set accordingly. The carry is cleared.
  86.  
  87. 2n LD Rn (Load)
  88. The ACC (R0) is loaded from Rn and branch conditions set according to the data transferred. The carry is cleared and contents of Rn are not disturbed.
  89.  
  90. 3n ST Rn (Store)
  91. The ACC is stored into Rn and branch conditions set according to the data transferred. The carry is cleared and the ACC contents are not disturbed.
  92.  
  93. 4n LD @Rn (Load Indirect)
  94. The low-order ACC byte is loaded from the memory location whose address resides in Rn and the high-order ACC byte is cleared. Branch conditions reflect the final ACC contents which will always be positive and never minus 1. The carry is cleared. After the transfer, Rn is incremented by 1.
  95.  
  96. 5n ST @Rn (Store Indirect)
  97. The low-order ACC byte is stored into the memory location whose address resides in Rn. Branch conditions reflect the 2-byte ACC contents. The carry is cleared. After the transfer Rn is incremented by 1.
  98.  
  99. 6n LDD @Rn (Load Double Indirect)
  100. The low order ACC byte is loaded from memory location whose address resides in Rn, and Rn is then incremented by 1. The high order ACC byte is loaded from the memory location whose address resides in the incremented Rn, and Rn is again incremented by 1. Branch conditions reflect the final ACC contents. The carry is cleared.
  101.  
  102. 7n STD @Rn (Store Double Indirect)
  103. The low-order ACC byte is stored into memory location whose address resides in Rn, and Rn is the incremented by 1. The high-order ACC byte is stored into the memory location whose address resides in the incremented Rn, and Rn is again incremented by 1. Branch conditions reflect the ACC contents which are not disturbed. The carry is cleared.
  104.  
  105. 8n POP @Rn (Pop Indirect)
  106. The low-order ACC byte is loaded from the memory location whose address resides in Rn after Rn is decremented by 1, and the high order ACC byte is cleared. Branch conditions reflect the final 2-byte ACC contents which will always be positive and never minus one. The carry is cleared. Because Rn is decremented prior to loading the ACC, single byte stacks may be implemented with the ST @Rn and POP @Rn ops (Rn is the stack pointer).
  107.  
  108. 9n STP @Rn (Store POP Indirect)
  109. The low-order ACC byte is stored into the memory location whose address resides in Rn after Rn is decremented by 1. Branch conditions will reflect the 2-byte ACC contents which are not modified. STP @Rn and POP @Rn are used together to move data blocks beginning at the greatest address and working down. Additionally, single-byte stacks may be implemented with the STP @Rn ops.
  110.  
  111. An ADD Rn (Add)
  112. The contents of Rn are added to the contents of ACC (R0), and the low-order 16 bits of the sum restored in ACC. the 17th sum bit becomes the carry and the other branch conditions reflect the final ACC contents.
  113.  
  114. Bn SUB Rn (Sub)
  115. The contents of Rn are subtracted from the ACC contents by performing a two's complement addition:
  116. ACC = ACC + Rn + 1
  117. The low order 16 bits of the subtraction are restored in the ACC, the 17th sum bit becomes the carry and other branch conditions reflect the final ACC contents. If the 16-bit unsigned ACC contents are greater than or equal to the 16-bit unsigned Rn contents, then the carry is set, otherwise it is cleared. Rn is not disturbed.
  118.  
  119. Cn POPD @Rn (Pop Double Indirect)
  120. Rn is decremented by 1 and the high-order ACC byte is loaded from the memory location whose address now resides in Rn. Rn is again decremented by 1 and the low-order ACC byte is loaded from the corresponding memory location. Branch conditions reflect the final ACC contents. The carry is cleared. Because Rn is decremented prior to loading each of the ACC halves, double-byte stacks may be implemented with the STD @Rn and POPD @Rn ops (Rn is the stack pointer).
  121.  
  122. Dn CPR Rn (Compare)
  123. The ACC (R0) contents are compared to Rn by performing the 16 bit binary subtraction ACC-Rn and storing the low order 16 difference bits in R13 for subsequent branch tests. If the 16 bit unsigned ACC contents are greater than or equal to the 16 bit unsigned Rn contents, then the carry is set, otherwise it is cleared. No other registers, including ACC and Rn, are disturbed.
  124.  
  125. En INR Rn (Increment)
  126. The contents of Rn are incremented by 1. The carry is cleared and other branch conditions reflect the incremented value.
  127.  
  128. Fn DCR Rn (Decrement)
  129. The contents of Rn are decremented by 1. The carry is cleared and other branch conditions reflect the decremented value.
  130.  
  131. 00 RTN (Return to 6502 mode)
  132.  
  133. 01 BR ea (Branch always)
  134. An effective address (ea) is calculated by adding the signed displacement byte (d) to the PC. The PC contains the address of the instruction immediately following the BR, or the address of the BR op plus 2. The displacement is a signed two's complement value from -128 to +127. Branch conditions are not changed.
  135. NOTE: The effective address calculation is identical to that for 6502 relative branches. The Hex add & Subtract features of the APPLE ][ monitor may be used to calculate displacements.
  136.  
  137. 02 BNC ea (Branch if No Carry)
  138. A branch to the effective address is taken only is the carry is clear, otherwise execution resumes as normal with the next instruction. Branch conditions are not changed.
  139.  
  140. 03 BC ea (Branch if Carry)
  141. A branch is effected only if the carry is set. Branch conditions are not changed.
  142.  
  143. 04 BP ea (Branch if Plus)
  144. A branch is effected only if the prior 'result' (or most recently transferred dat) was positive. Branch conditions are not changed.
  145.  
  146. 05 BM ea (Branch if Minus)
  147. A branch is effected only if prior 'result' was minus (negative, MSB = 1). Branch conditions are not changed.
  148.  
  149. 06 BZ ea (Branch if Zero)
  150. A Branch is effected only if the prior 'result' was zero. Branch conditions are not changed.
  151.  
  152. 07 BNZ ea (Branch if NonZero)
  153. A branch is effected only if the priot 'result' was non-zero Branch conditions are not changed.
  154.  
  155. 08 BM1 ea (Branch if Minus 1)
  156. A branch is effected only if the prior 'result' was minus one ($FFFF Hex). Branch conditions are not changed.
  157.  
  158. 09 BNM1 ea (Branch if Not Minus 1)
  159. A branch effected only if the prior 'result' was not minus 1. Branch conditions are not changed.
  160.  
  161. 0A BK (Break)
  162. A 6502 BRK (break) instruction is executed. SWEET 16 may be re-entered non destructively at SW16d after correcting the stack pointer to its value prior to executing the BRK.
  163.  
  164. 0B RS (Return from Subroutine)
  165. RS terminates execution of a SWEET 16 subroutine and returns to the SWEET 16 calling program which resumes execution (in SWEET 16 mode). R12, which is the SWEET 16 subroutine return stack pointer, is decremented twice. Branch conditions are not changed.
  166.  
  167. 0C BS ea (Branch to Subroutine)
  168. A branch to the effective address (PC + 2 + d) is taken and execution is resumed in SWEET 16 mode. The current PC is pushed onto a SWEET 16 subroutine return address stack whose pointer is R12, and R12 is incremented by 2. The carry is cleared and branch conditions set to indicate the current ACC contents.
  169.  
  170. 0D (Escape code)
  171.  
  172. 0E (Switch into $0D prefix mode, where every opcode acts as if it has the prefix)
  173.  
  174. 0F (Unassigned)
  175.  
  176. -0D-opcodes------------------------------
  177. 0D 00 - 0D 0C - Same as normal 01-0C
  178. 0D 0D END - End prefix mode, if on
  179. 0D 0E -
  180. 0D 0F -
  181.  
  182. 0D 10 ASL r0 - Shift accumulator left
  183. 0D 11 LSR r0 - Shift accumulator right
  184. 0D 12 EX r0, r1 - exchange r0 and r1
  185. 0D 13 xx xx JP xxxx - BR to 16bit constant
  186. 0D 14 JS r0 - BS to location in r0
  187. 0D 15 xx xx JS xxxx - BS to 16bit constant
  188. 0D 16 -
  189. 0D 17 -
  190. 0D 18 -
  191. 0D 19 -
  192. 0D 1A -
  193. 0D 1B -
  194. 0D 1C -
  195. 0D 1D -
  196. 0D 1E -
  197. 0D 1F -
  198.  
  199. 0D 2x zz zz LD [Mem], rX - Store register from memory
  200. 0D 3x zz zz LD rX, [Mem] - Load register from memory
  201. 0D 4x zz zz EX rX, [Mem] - Swap register with memory
  202.  
  203. 0D 50 xy MOV rX, rY - Copy rY to rX
  204. 0D 51 xy EX rX, rY - Swap rX with rY
  205. 0D 52 xy CMP rX, rY - Compare rX with rY
  206. 0D 53 xy -
  207.  
  208. 0D 54 xy PUSH rX, rY - Push rX to stack @rY
  209. 0D 55 xy POP rX, rY - Pop stack @rY and store to rX
  210. 0D 56 xy ASL rX, # - Shift rX left by constant
  211. 0D 47 xy LSR rX, # - Shift rY right by constant
  212.  
  213. 0D 48 xy ADD rX, rY - Increase rX by rY
  214. 0D 49 xy SUB rX, rY - Decrease rX by rY
  215. 0D 4A xy MUL rX, rY - Multiply rX by rY
  216. 0D 4B xy DIV rX, rY - Divide rX by rY
  217.  
  218. 0D 4C xy MOD rX, rY - Divide rX by rY and store the remainder
  219. 0D 4D xy AND rX, rY - AND rX with rY
  220. 0D 4E xy OR rX, rY - OR rX with rY
  221. 0D 4F xy XOR rX, rY - XOR rX with rY
  222.  
  223. 0D 5z xy - Like "0d 5z xy" except rY is indirect
  224. 0D 6x xy - Like "0d 5z xy" except rX is indirect
  225. 0D 7x xy - Like "0d 5z xy" except both rX and rY are indirect
  226.  
  227. 0D 9x RRR rX - Redirect result into register rX instead of the destination
  228. 0D 9x RRR @rX - ( Same except indirect )
  229. 0D Ax CRR rX - Copy result into register rX as well as in the destination
  230. 0D Bx CRR @rX - ( Same except indirect)
  231. ( The $0D prefix is implied for the next opcode following one of these four, but if
  232. followed by $00, then the effects will apply to the opcode after the $00 )
  233.  
  234. 0D Cx yyyy SET rX, yyyy - Set rX to constant yyyy
  235. 0D Dw -
  236. 0D Ex -
  237. 0D Fx -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement