65816info.txt 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762
  1. A 65816 Primer
  2. [----------------------------------------------------------]
  3. No republication or redistribution of the following is permitted without
  4. the authors express written consent.
  5. Table of Contents
  6. ------------------------------------------------------------------------
  7. i Preface
  8. 1.00 Introduction
  9. 2.00 New 65816 Instructions
  10. 3.00 65816 Native Mode Programming Model
  11. 3.01 Native Mode Processor Status Register
  12. 3.10 Native Mode Registers
  13. 3.11 Accumulator:
  14. 3.12 X,Y Index Registers
  15. 3.13 Direct Page Register (D)
  16. 3.14 Stack Pointer (S)
  17. 3.15 Program Bank Register (PBR)
  18. 3.16 Data Bank Register (DBR)
  19. 3.20 Status Register
  20. 3.21 Emulation Bit E: Hidden Bit
  21. 3.22 Sixteen BIT User Registers
  22. 3.23 Index Register Select
  23. 3.24 Accumulator/Memory Select
  24. 3.30 Setting Status Register Bits
  25. 4.00 65816 Emulation Mode Programming Model
  26. 4.10 Emulation Mode Registers
  27. 5.00 Relocating the Stack and Direct Page
  28. 6.00 Addressing Modes
  29. 6.10 New 65816 Specific Addressing Modes
  30. 6.20 Addressing Mode Descriptions
  31. 7.00 Interrupts
  32. 7.10 Hardware Vectors
  33. Appendix A: 65816 Instruction Set
  34. Appendix B: Composite Instruction List
  35. Appendix C: IC Pinouts
  36. Disclaimer:
  37. Some of the following information was referenced with various documents and
  38. public documentation available for the Apple IIGS computer system and the
  39. Super NES game console system via the world wide web and other user group
  40. publications. No claim is made or intended against any copyrighted
  41. information that may be contained within this document. The main
  42. sub-content that could be construed as a copyright infringement, would be
  43. the usage of mnemonic tables and the similarity of programming models.
  44. Although these tables were built specifically for this project, it is
  45. unclear what the legal status of mnemonic information is at present. Brett
  46. Tabke 1997
  47. This document is intended to aid those programming the 65816 Processor from
  48. The Western Design Center. This chip is the basis for the Apple IIGS, the
  49. Creative Micro Designs SuperCPU addon cartridge for the Commodore 64 & 128,
  50. and the Super NES game console that are all based around the 65816 micro
  51. processor.
  52. ------------------------------------------------------------------------
  53. Preface
  54. This document was pulled from several chapters of book project I had
  55. started. I'd intended to publish a small booklet on programming the CMD
  56. Super CPU cartridge detailing the operation of the 65816 - however, I have
  57. been unable to acquire a release to republish some critical information.
  58. So, the following is a few chapters that I feel are worthy of public
  59. disclosure and distribution.
  60. HTML Conversion Notes
  61. This document was originally in IBM CG/ANSI format and the conversion to
  62. HTML was marginal. Even with the file being fairly generic text, four
  63. different browsers rendered it differently. Lynx 2.7 and Lynx 2.6 will not
  64. render it the same - I tried to strike a happy medium - your mileage may
  65. vary.
  66. TOC
  67. [ Image Jet ]
  68. ------------------------------------------------------------------------
  69. 1.00 Introduction
  70. -----------------
  71. Welcome to the world of 65816 programming. The 65816 is an advanced upgrade
  72. to the vintage 6502 Central Processing Unit. The main new features include
  73. full 24 bit addressing for direct memory access of up to 16 megabytes.
  74. Additionally, the 65816 offers full 6502 emulation, new addressing modes,
  75. full 16 bit user registers, and dozens of new instructions.
  76. If you have been a 6502 programmer for long, the advantages of the 65816
  77. will become clear very quick. Regardless of CPU operating speed (mhz) a the
  78. 65816 will operate a bit faster simply by the nature of the 16 bit user
  79. registers. By using 16 bit registers for operations such as addition and
  80. subtraction the 65816 also offers the programmer a substantial speed
  81. increase.
  82. The following document is not meant as a definitive guide to programming
  83. the 65816, but rather a primer for those who are familiar with the 6502 and
  84. wish to find the new 65816 (good) stuff.
  85. The 65816 offers two primary modes of operation, Native 65816 Mode and 6502
  86. emulation mode. The default power-up status of the processor is in 6502
  87. emulation mode. Other than correcting a few bugs in the 6502, emulation
  88. mode "looks and feels" just like a 6502.
  89. There are a few notable differences between the 65816's emulation mode and
  90. the original 6502. The 6502 opcodes that were unimplemented, are now
  91. available as additional instructions on the 65816, thus they will not
  92. produce the results they do on a stock NMOS 6502 CPU. The 65816 implements
  93. ALL of the available 256 opcodes, whether in emulation or Native mode.
  94. Also different between a 6502 and emulation mode is that the indirect jump
  95. JMP ($XXXX) bug that caused the processor to retrieve the wrong data when
  96. the low byte was $xx has been fixed.
  97. While in emulation mode, the 65816's Direct (zero) Page register is set for
  98. zero. The Stack pointer high byte is set for one (just as a 6502). The
  99. Program and Data Bank Registers are initialized to zero. Timing of all
  100. instructions is identical.
  101. While in Native mode, the processor has full access to the 16 megabyte
  102. address space via 24 bit addressing. Native mode also makes available
  103. several new and extended processor registers. The 65816 has the ability to
  104. relocate the Stack and Zero Page any where within the first 64k bank of
  105. memory. For old Commodore 128 programmers, this will sound suspiciously
  106. like the 128's Memory Management Units ability to relocate zero page and
  107. the stack also - so it will be old hat from the start. (On a side note, it
  108. will be interesting to program on CMD's Super CPU 128 - which will give you
  109. a Relocatable Relocatable Zero Page and Stack. hmmm ;)
  110. Native mode also opens up the world of 16 bit user registers. The
  111. accumulator may be 8 or 16 bits and the XY index registers may also be 8 or
  112. 16 bits. The accumulator maybe seen in terms of two 8 bit registers with
  113. one accessible and the other hidden, or as a full 16 bit register. While
  114. the accumulator is set for 16 bits, memory is also treated in 16 bit (2
  115. byte) fashion.
  116. Two other new registers are the Data Bank Register and the Program Bank
  117. register. The Program Bank Register functionally extends the program
  118. counter out to 24 bits, while the Data Bank register allows code flow
  119. control to branch or jump to points outside of the 6502's 64k address
  120. space.
  121. Lastly, while in Native mode the status register of the 65816 includes
  122. several new bits. The old BRK bit is no longer needed as the 65816 has a
  123. BRK hardware vector. The BRK bit is now replaced with the X bit to select
  124. either 8 or 16 bit index registers. However while in emulation mode, the
  125. BRK bit is still there. The old "reserved" bit 5 of the status register is
  126. replaced with the 16/8 bit accumulator/memory select bit. There is also a
  127. hidden emulation bit that is only accessible by exchanging it will the
  128. carry flag.
  129. Here is a run down of some of the new fun stuff:
  130. * XYA registers can be 16 or 8 bits wide.
  131. * Wow, two actual Block Move Memory instructions.
  132. * New push/pull instructions phx,plx,phy,ply.
  133. * New xfer instructions tyx,txy.
  134. * Set or Reset any memory bit without loading the accumulator.
  135. * INC and DEC the accumulator.
  136. * JSR indirect, Branch Always, or Branch Long to 64k.
  137. * Zero Page has been renamed to Direct Page. Like many strange things,
  138. this will be totally confusing at first. The only thing you can do is,
  139. "get over it and get on with it".
  140. TOC
  141. 2.00 New 65816 Instructions:
  142. ----------------------------
  143. There are some new instructions worthy of short detail:
  144. New transfer instructions include:
  145. TXY,TYX xfer between x and y.
  146. TCD,TCD xfer between the accumulator and direct page pointer(D).
  147. TCS,TSC xfer between the accumulator and stack pointer(S).
  148. XBA exchange the low 8 bits (a) and the high 8 bits
  149. of the accumulator.
  150. XCE exchange the contents of the emulation bit (E) with
  151. the contents of the carry flag (C).
  152. New Stack pushes and pulls:
  153. PHX,PHY,PLX,PLY push and pull the XY index registers.
  154. PHB,PLB to push/pull the data bank register.
  155. PHK to push the program bank register (no pull present)
  156. PHD,PLD to push/pull the direct page register.
  157. PEA to push effect absolute address.
  158. PEI to push effective indirect address.
  159. PER to push effective relative address.
  160. Misc:
  161. MVN Move block in negative direction.
  162. MVP Move block in positive direction.
  163. STZ Store a zero to any location.
  164. BRA Branch always.
  165. BRL Branch to any address in bank 0 (64k).
  166. RTL Return Long. Pulls one more byte. (pc bank byte)
  167. As you can see, there is plenty new to digest. The remainder of this
  168. document will assume prior 6502 knowledge. Lets go.
  169. TOC
  170. ------------------------------------------------------------------------
  171. ==========================================
  172. 3.00 65816 Native Mode Programming Model
  173. ==========================================
  174. ------------------------------------------------------------------------
  175. Bits:23 15 7 0
  176. /--------------------l-------------------\
  177. IAccumulator (B) (A or C) Accumulator (A)I
  178. \--------------------I-------------------/
  179. /--------------------------\
  180. I Data Bank Register (DBR) I
  181. \--------------------------/
  182. /--------------------l-------------------\
  183. I X Index I Register (X) I
  184. \--------------------I-------------------/
  185. /--------------------l-------------------\
  186. I Y Index I Register (Y) I
  187. \--------------------I-------------------/
  188. ---------------------------/--------------------l-------------------\
  189. | 0 0 0 0 0 0 0 0 I Direct I Page Pointer (D) I
  190. ---------------------------\--------------------I-------------------/
  191. ---------------------------/--------------------l-------------------\
  192. | 0 0 0 0 0 0 0 0 I Stack I Pointer (S) I
  193. ---------------------------\--------------------I-------------------/
  194. /---------------------------l--------------------l-------------------\
  195. IProgram Bank Register(PBR) I Program I Counter (PC) I
  196. \---------------------------I--------------------I-------------------/
  197. ===================================
  198. 3.01 Processor Status Register (P)
  199. ===================================
  200. Bits 7 6 5 4 3 2 1 0
  201. /---\
  202. I e --- Emulation 0 = Native Mode
  203. /---l---l---l---l---l---l---+---I
  204. I n I v I m I x I d I i I z I c I
  205. \-l-I-l-I-l-I-l-I-l-I-l-I-l-I-l-/
  206. I I I I I I I \-------- Carry 1 = Carry
  207. I I I I I I \------------- Zero 1 = Result Zero
  208. I I I I I \---------- IRQ Disable 1 = Disabled
  209. I I I I \------------- Decimal Mode 1 = Decimal, 0 = Binary
  210. I I I \-------- Index Register Select 1 = 8-bit, 0 = 16-bit
  211. I I \-------- Memory/Accumulator Select 1 = 8-bit, 0 = 16 bit
  212. I \----------------------------- Overflow 1 = Overflow
  213. \--------------------------------- Negative 1 = Negative
  214. 65816 Native Mode Programming Model
  215. TOC
  216. ======================================
  217. 3.10 Native Mode Registers
  218. ======================================
  219. 3.11 Accumulator
  220. -----------------
  221. Although shown as a 16 bit register, it may be either 16 or 8 depending on
  222. the status of bit 5 (memory/accumulator select) of the status register bit
  223. designated M.
  224. When in 8 bit mode (M=1) then the accessible low order 8 bit accumulator is
  225. designated as A and the hidden but exchangeable is designated B. When in
  226. full 16 bit accumulator mode (M=0) then the accumulator is designated as C.
  227. 3.12 X,Y Index Registers
  228. -------------------------
  229. The X and Y index registers are 8 or 16 bit selectable. When status
  230. register bit 4 designated X is set to 1 then 8 bit registers are selected.
  231. When set to 0 then 16 bit registers are selected.
  232. TOC
  233. 3.13 Direct Page Register (D)
  234. ------------------------------
  235. This register is formerly known as Zero Page. The Direct Page pointer
  236. specifies where in the first bank of 64k Direct Page (zero page) will be
  237. located. The Direct Page may be moved to ANY location within Bank 0.
  238. The Bank byte (bits 16-23) is shown in a dashed line to represent the fact
  239. that the Direct Page is always located within bank 0.
  240. 3.14 Stack Pointer (S):
  241. -----------------------
  242. Like the Direct (zero) Page Pointer, the Stack is now totally relocatable
  243. within Bank 0 (first 64k) of memory. The Bank byte (bits 16-23) is shown in
  244. a dashed line to represent the fact that the Stack is always located within
  245. bank 0. While in Native Mode the stack is not restricted to 256 bytes in
  246. length.
  247. while in emulation mode (e=1) the stack is located at page 1.
  248. TOC
  249. 3.15 Program Bank Register (PBR):
  250. ---------------------------------
  251. Much like the DBR below, the Program Bank Register is used to specify
  252. address's above and beyond the 6502 64k limit. The PBR is referred to as
  253. the Bank Byte or the highest 8 bits of the Program Counter. Flow control
  254. instructions such as JSR and JMP, may jump to full 23 bit address's. The
  255. PBR is used to specify the highest order 8 bits of the effective address.
  256. However; relative branches do not roll out of the current bank. Branch
  257. commands that branch across $FFFF roll back into the current bank. Also;
  258. program segments may not cross bank boundaries - the program counter goes
  259. from $FFFF to $0000 during such and occurrence.
  260. 3.16 Data Bank Register (DBR):
  261. ------------------------------
  262. Certain addressing modes take advantage of the 65816's ability to address
  263. up to 16meg of data. Those modes that retrieve and store data to absolute
  264. 16 meg/(24 bit address's use the DBR as the top 8 bits of the effective
  265. address. The DBR is also referred to as the Data Bank Byte. The term Bank
  266. Byte is used so that High Byte still refers to bits 8-15 of a given
  267. location or register.
  268. When indexed addressing mode branch across 64k bank boundaries, DBR is
  269. temporarily incremented.
  270. TOC
  271. 3.20 Status Register
  272. =====================
  273. The status register bits 7,6,3,2,1,0 (nvdizc) function the same as the 6502
  274. status register bits.
  275. The B break bit is no longer needed to detect a BRK. Instead a new hardware
  276. vector has been implemented to direct code flow to a OS ROM handler in the
  277. same way as an IRQ. However, while in emulation mode (E=1) BRK and the B
  278. bit work as a 6502 does.
  279. 3.21 Emulation Bit E: Hidden Bit
  280. --------------------------------
  281. The emulation status bit E specifies whether the processor is in 6502
  282. emulation mode or Native 65816 mode. 1=emulation. The processor powers up
  283. in default 6502 emulation mode. When in 6502 emulation mode, the processor
  284. is functionally a 6502. With the exceptions of un implemented opcodes, all
  285. other opcodes perform identically to their true 6502 counter parts. In
  286. emulation mode, the stack is defined as page one, direct page is defined as
  287. page zero, and the Data Bank and Program Bank bytes are set to zero. The
  288. additional 65816 opcodes are also available in emulation mode.
  289. The emulation status bit is a hidden or phantom bit that is not directly
  290. set, tested, or cleared. Therefore, a new instruction is used to exchange
  291. the values of the carry bit and the emulation bit (XCE:eXchange Carry with
  292. emulation bit). After exchanging, the carry can be tested to determine the
  293. previous status of the E bit.
  294. To switch to Native Mode use the following:
  295. clc ;clear carry to zero.
  296. xce ;exchange (swap) carry with the emulation bit.
  297. To return to Emulation mode:
  298. sec ;set carry to one.
  299. xce ;exchange (swap) carry with the emulation bit.
  300. TOC
  301. 3.22 Sixteen BIT User Registers
  302. --------------------------------
  303. The main advantage of the 65816 over the 6502 is that the Accumulator and
  304. the XY index registers can be toggle between 8 and 16 bits wide. The width
  305. of the Accumulator and the XY registers are independently selectable. Thus
  306. you may select any combination of either:
  307. 16 bit accum. m=0 - 16 bit XY regs x=0
  308. 16 bit accum. m=0 - 8 bit XY regs x=1
  309. 8 bit accum. m=1 - 16 bit XY regs x=0
  310. 8 bit accum. m=1 - 8 bit XY regs x=1
  311. When the accumulator is switched from or to 16 bits, the high order byte is
  312. retained in either direction.
  313. When the XY registers are switched from 16 bits to 8 bits, the high byte
  314. (bits 8-15) are lost. When switching the XY registers to 16 bits, the high
  315. byte becomes a zero.
  316. TOC
  317. 3.23 Status Bit 4 X: Index Register Select
  318. -------------------------------------------
  319. Bit 4 of the status register selects either 8 bit or 16 bit XY index
  320. register operation. When x=1 (8 bit), the XY registers function identically
  321. to the 6502 index registers.
  322. When x=0 (16 bit), both the X and Y registers become 16 bits wide. All
  323. operations involving the X and Y registers act on all 16 bits of the index
  324. register.
  325. When switching from 8 to 16 or 16 to 8 bit index register, the high byte of
  326. either X or Y will be come zero.
  327. While in emulation mode (E=1) bit 4 is the B BRK flag bit.
  328. TOC
  329. 3.24 Status Bit 5: Accumulator/Memory Select
  330. ---------------------------------------------
  331. Bit 5 specifies whether the accumulator will be treated as an 8 bit or 16
  332. bit register. When in 16 bit mode (m=0) all operations involving the
  333. accumulator will act upon 16 bits of data. Such as, when in 16 bit mode, a
  334. standard load (lda $1000) will load the load by ($1000) in the low order 8
  335. bits of the accumulator and load ($1001) into the high order of the
  336. accumulator.
  337. When switching the accumulator from 16 to 8 or from 8 to 16 bits, the high
  338. byte is perfectly retained. While in 8 bit mode, the high byte of the
  339. accumulator (B) maybe exchanged with the low byte with the XBA instruction.
  340. While in emulation mode, bit 5 is not present.
  341. TOC
  342. 3.30 Setting Status Register Bits
  343. ----------------------------------
  344. Two new instructions have been added to 65816 Native mode to set and reset
  345. bits of the status register. The two instructions are SEP (set processor
  346. status bits) and REP (reset processor status bits). They both use a single
  347. byte operand to specify which bits should be set or reset. For example to
  348. set bit 4 of the status register to 1 for 8 bit registers:
  349. SEP #%00010000 ;set bit 4.
  350. Or to clear bit 4 for 16 bit XY index registers:
  351. REP #%00010000 ;reset (clear) bit 4.
  352. You may set or reset more than 1 bit at a time. For example, to set both 16
  353. bit accumulator/memory and 16 bit XY registers use the following:
  354. REP #%00110000 ;set 16 bit accum/xy registers.
  355. ------------------------------------------------------------------------
  356. =============================================
  357. 4.00 65816 Emulation Mode Programming Model I
  358. =============================================
  359. ------------------------------------------------------------------------
  360. Bits:23 15 7 0
  361. --------------------l-------------------\
  362. |Accumulator (B) (C) Accumulator (A)I
  363. --------------------I-------------------/
  364. /--------------------------\
  365. I Data Bank Register (DBR) I
  366. \--------------------------/
  367. /-------------------\
  368. I X Index Register I
  369. \-------------------/
  370. /-------------------\
  371. I Y Index Register I
  372. \-------------------/
  373. ---------------------------l--------------------l-------------------\
  374. | 0 0 0 0 0 0 0 0 I Direct I Page Pointer (D) I
  375. ---------------------------I--------------------I-------------------/
  376. ---------------------------l--------------------l-------------------\
  377. | 0 0 0 0 0 0 0 0 I 0 0 0 0 0 0 0 1 I Stack Pointer (S) I
  378. ---------------------------I--------------------I-------------------/
  379. /---------------------------l--------------------l-------------------\
  380. IProgram Bank Register(PBR) I Program I Counter (PC) I
  381. \---------------------------I--------------------I-------------------/
  382. 4.10 Emulation Mode Registers
  383. =============================
  384. TOC
  385. Emulation Mode Processor Status Register (P)
  386. --------------------------------------------
  387. Bits 7 6 5 4 3 2 1 0
  388. /---\
  389. I e --- Emulation 1 = 6502 Emulation Mode
  390. /---l---l---l---l---l---l---+---I
  391. I n I v I I b I d I i I z I c I
  392. \-l-I-l-I---I-l-I-l-I-l-I-l-I-l-/
  393. I I I I I I \-------- Carry 1 = Carry
  394. I I I I I \------------- Zero 1 = Result Zero
  395. I I I I \---------- IRQ Disable 1 = Disabled
  396. I I I \------------- Decimal Mode 1 = Decimal, 0 = Binary
  397. I I \------------ Break Instruction 1 = BRK caused IRQ
  398. I I
  399. I \----------------------------- Overflow 1 = Overflow
  400. \--------------------------------- Negative 1 = Negative
  401. 65816 Emulation Mode Programming Model.
  402. TOC
  403. The above 6502 emulation mode Programming Model shows some interesting
  404. features of the 65816 while in emulation mode. Even though 16 bit index
  405. registers are not available in emulation mode, you can still do the
  406. following:
  407. * Relocate Direct Page.
  408. * Use the stack addressing modes.
  409. * Swap the lower A accumulator with the hidden B accumulator.
  410. * The Program and Data Bank Registers can be changed.
  411. * Use the new instructions.
  412. Things lost or changed in Emulation mode verses Native mode:
  413. * The ability to use 16 bit user registers. The M and X bits of the
  414. status register are returned to their 6502 form.
  415. * The utility of the Block Move instructions. Block Move instructions
  416. use the index registers to specify the source and destination
  417. address's of a move - with only 8 bits available in emulation mode,
  418. you can only move data within zero page because the high byte will
  419. always be zero.
  420. * Zero page addressing "wraps" in emulation mode, whereas in Native mode
  421. it rolls into the next page.
  422. * The stack pointer is ALWAYS on page one.
  423. When switching from emulation to native mode the processor replaces the B
  424. BREAK flag and bit 5 with the 65816 M and X flags, and sets them to one.
  425. This leaves the index registers and accumulator/memory into 8 bit mode
  426. (which is the same as emulation mode). The remaining bits in the status
  427. register are unchanged. The stack pointer remains at page one.
  428. When switching from native mode into emulation mode; the M and X status
  429. register bit disappear, putting the accumulator and index registers at 8
  430. bit. The X and Y low bytes are retained, but the high bytes are lost. The
  431. accumulator low and high bytes are retained. (of course the high byte is
  432. hidden but accessible with the XBA instruction). The stack pointer is
  433. returned to eights bits with the high byte forced to one and the high byte
  434. is lost.
  435. I think that after you work with the 65816 in emulation mode you will
  436. realize that it is not about what you lose over native mode, but how much
  437. you gain over a 6502. The fact that all of the extra opcodes and
  438. instructions are still available even in emulation mode, makes for a
  439. powerful processor even without the 16 bit registers.
  440. ------------------------------------------------------------------------
  441. TOC
  442. 5.00 Relocating the Stack and Direct Page:
  443. ------------------------------------------
  444. On power-up, the Stack is set to page one and the direct page (Zero Page)
  445. to page zero. When in emulation mode (E=1) the Stack is initialized to Page
  446. one, and Zero page is initialized to Page zero to emulate the default
  447. status of the 6502.
  448. Relocating the Direct Page (formerly known as Zero Page) is accomplished by
  449. use of the PLD:pull direct page instruction.
  450. LDA #$5900 ; lda with immediate 16 bit data.
  451. PHA ; on the stack with 16 bits.
  452. PLD ; pull it back into the direct page register.
  453. Always keep in mind that PLD pulls 16 bits (2 bytes) off the stack. You may
  454. also use the TCD:transfer C register to Direct page register. (the C
  455. register refers to the Accumulator as 16 bits)
  456. LDA #$5900 ; load 16 bit accum with immediate 16 bit data.
  457. TCD ; transfer accum to direct page register.
  458. Although you generally will want to keep Direct Page starting on an even
  459. 256 page boundary (low byte zero), you can specify a low byte address at
  460. any 1-255 value. However all of the Direct Page (zero page) addressing
  461. modes will add one clock cycle to the execution time if the low byte of the
  462. direct page register is other than zero.
  463. While in emulation mode, a direct page addressing mode where the index
  464. rolls out of direct page will wrap around to the beginning of the direct
  465. page, just as a 6502 does. For example:
  466. LDX #$2C
  467. LDA ($E0,X)
  468. Would yield an effective address of $0C and not $10C.
  469. While in Native mode, a direct page addressing mode where the index rolls
  470. out of direct page will wrap into the next page of memory. Using the
  471. example from above would yield the expected $10C effect address.
  472. For those old Commodore 128 programmers, the concept of a relocatable
  473. Direct Page is nothing new - we've been tweaking it on the MMU for years.
  474. However; relocating zero page to something other than a page boundary has
  475. some strong implications for the right style of code.
  476. The power behind changing the direct page, is the same as 6502 zero page
  477. addressing has always been. You can save bytes by using direct page
  478. addressing (zero page) modes and acquire faster execution times as well. It
  479. will take some time to find the best ways to program with a relocated
  480. direct page, but once mastered, you wont get along with out.
  481. TOC
  482. ------------------------------------------------------------------------
  483. ------------------------------------------------------------------------
  484. =======================
  485. 6.00 Addressing Modes
  486. =======================
  487. All 6502 and 65C02 addressing modes and opcodes are supported in 65816
  488. Native mode. Nine other new addressing modes are also supported in both
  489. emulation and Native mode. However; there are a few notable addressing
  490. differences between 816 Native mode and its 6502 counter part.
  491. While in emulation mode there is no page wraparound when using Zero Page
  492. Indexed addressing from a base address+index that "rolls over" $FF. While
  493. in Native 65816 mode indexes can be 16 bits, so if the base address+index
  494. rolls over into the next page the proper effective address in generated.
  495. With 16 bit index registers, a direct page addressing mode where indexing
  496. rolls over $FFFF the effective address roll back into the current bank not
  497. into the next bank (ie:lda $20,x where x is $FFFF will result in an
  498. effective address of $1F).
  499. When using absolute indexed addressing where the base address is $FF01 to
  500. $FFFF an index value that would cause the eFFective address to roll over
  501. $FFFF would result in the next ram bank being accessed. Whereas on a 6502
  502. there would be a wrap around into zero page.
  503. Remember that when index registers are 16 bit, that absolute indexed X or
  504. absolute indexed Y can now reach up to a full 64k! (ie: lda $6000,y where
  505. y=$2000 would result in an effective address of $8000).
  506. The 85618 also fixed the 6502 indirect JMP bug. A JMP ($12FF) now yields
  507. the proper address of $12FF-$1300.
  508. TOC
  509. 6.10 New 65816 Specific Addressing Modes:
  510. -----------------------------------------
  511. New Mode Name Example
  512. -------------------------------------------------------
  513. Program Counter Relative Long BRL $1234
  514. Stack Relative LDA 15,S
  515. Stack Relative Indirect Indexed Y LDA (9,S),Y
  516. Block Move MVP 0,0
  517. Absolute Long LDA $123456
  518. Absolute Long Indexed X LDA $123456,X
  519. Absolute Indexed Indirect JMP ($1234,X)
  520. Absolute Indirect Long JMP [$1234]
  521. Direct Page Indirect LDA ($12)
  522. Direct Page Indirect Long LDA [$12]
  523. Direct Page Indirect Long Indexed Y LDA [$77],Y
  524. 6.20 Addressing Mode Descriptions
  525. ----------------------------------
  526. Program Counter Relative Long: BRL #$44
  527. Program Counter Relative Long extends the range of the branch instructions
  528. from the standard -127/+128 to 64k (+32767/-32768). Thus; the operand of
  529. the BRL branch command is 16 bits. This address mode will help enormously
  530. when writing relocatable code.
  531. Stack Relative: LDA 7,S
  532. Stack Relative addressing uses the Stack Pointer as a base address and then
  533. adds the one byte user supplied operand as an offset into the stack. The S
  534. specifies that this mode is Stack addressing via the stack pointer.
  535. When using Stack Relative Addressing you should keep in mind that the Stack
  536. Pointer will always point to the NEXT available spot on the stack. Thus, an
  537. operand of one will retrieve the last item pushed onto the stack. An
  538. operand of zero maybe useful to get another copy of the last thing PULLED
  539. off the stack - but, of course, if an interrupt hits, then you would be in
  540. trouble as the stack is manipulated via the interrupt routine.
  541. Stack Relative Indirect Indexed Y: LDA ($22,S),Y
  542. This addressing mode, locates and indirect address that points to the base
  543. data located elsewhere (same as zero page indirect indexed). This two byte
  544. instruction starts with the current location of the stack, then adds the
  545. first operand, and finally adds in the Y index as and offset.
  546. The value of this addressing mode is that suppose you have an address you
  547. pushed onto the stack, by using this mode you can easily reach to where the
  548. data was located.
  549. 10 LDY #0
  550. 20 LDA (1,S),Y ; get the address 16 bits
  551. 30 TAX ; save it in x
  552. 40 LDY #2
  553. 50 LDA (1,S),Y ; get a second address
  554. In the example above, we start with the current stack pointer location as
  555. the base address. In line 20 we load from an offset of one (1,S) and then
  556. add in the offset to give the effective address. The above assumes we are
  557. in 16 bit index and 16 bit accumulator mode.
  558. Block Move: MVP 0,0
  559. This is a major new addressing mode used by two instructions on the 65816.
  560. The two new instructions Block Move Positive and Block Move Negative can
  561. move up to 64K of data from one memory location to another. To setup a
  562. move, the accumulator is loaded with the number of bytes to copy, the X
  563. register is loaded with source address, and the Y register holds the
  564. destination address. Then issue the Block move instruction and data is
  565. moved at 7 cycles per byte.
  566. Absolute Long: LDA $123456
  567. Absolute Long is used to locate any data within the 16 bit address space of
  568. the 65816. The operand is three bytes (24 bits long). The main usage of
  569. this addressing mode is to temporarily override the contents of the DBR
  570. Data Bank Register for the execution of the single instruction. If standard
  571. absolute addressing is used, then the bank byte is concatenated to the
  572. address from the DBR.
  573. Absolute Long Indexed X: LDA $123456,X
  574. Absolute Long Indexed starts with the base operand and then adds the X
  575. index value to create an effective address. This is the same as 6502
  576. Absolute Indexed X, except the base operand is 24 bits wide. Note that the
  577. actual order of bytes is Opcode, low byte, high byte, bank byte and that it
  578. is up to the assembler to arrange the bytes in this order.
  579. Absolute Indexed Indirect JMP ($1234,X)
  580. Absolute Indexed Indirect is a three byte instruction that creates the
  581. effective address by starting with the specified operand and then adding in
  582. the index value. Old 6502 programmers will recognize the following command
  583. lookup and execute example:
  584. SEC
  585. SBC "0" ; subtract ascii zero off accumulator.
  586. ASL ; times two into a table.
  587. TAX ; into x as offset into word table.
  588. LDA TABLE,X ; get command address byte.
  589. STA PTR ; save in indirect pointer.
  590. LDA TABLE+1,X ; get table command address high byte.
  591. STA PTR+1 ; save in pointer high byte.
  592. JMP (PTR) ; jump to command.
  593. TABLE .WORD RUT1,RUT2,RUT3,...
  594. PTR .BYTE 0,0
  595. Using Absolute Indexed Indirect addressing it could be written in half the
  596. bytes and cycles:
  597. SEC
  598. SBC "0" ; subtract ascii zero off accumulator.
  599. ASL ; times two into a table.
  600. TAX ; into x as index into word table.
  601. JMP (TABLE,X) ; jump to command.
  602. TABLE .WORD RUT1,RUT2,RUT3,...
  603. A JMP Indexed Indirect [JMP ($1234,x)] assumes that the operand address is
  604. in the current program bank. A JMP indirect [JMP ($1234)] assumes that the
  605. operand address is in BANK ZERO.
  606. Absolute Indirect Long JMP [$1234]
  607. This addressing mode will form and effective address from the location
  608. pointed to by the operand.
  609. Direct Page Indirect LDA ($12)
  610. This instruction is two bytes long. The operand points to a 16 bit Direct
  611. Page (zero page) pointer that will form the effective address. For example,
  612. if the Direct Page pointer is $70, then the low byte with come from $70,
  613. and the high byte from $71, and the Bank Byte from $72. The bank byte will
  614. be the current data bank register.
  615. Direct Page Indirect Long LDA [$12]
  616. This instruction is two bytes long. The operand points to a 24 bit Direct
  617. Page (zero page) pointer that will form the effective address. For example,
  618. if the Direct Page pointer is $70, then the low byte with come from $70,
  619. the high byte from $71, and the Bank Byte from $72. The bank byte will
  620. temporarily override the data bank register.
  621. Direct Page Indirect Long Indexed Y LDA [$77],Y
  622. This instruction in two bytes long and allows you to temporarily reach into
  623. any memory bank. The operand is a direct page (zero page) pointer. The
  624. address located at the direct page offset is three bytes long. First is the
  625. low byte, then high byte, followed by the bank byte of the base effect
  626. address. The Y index register is then added to this three byte destination
  627. address to form the effective address. Square brackets are used to denote
  628. that the address is a full 24 bit address and not a simple 16 bit address.
  629. TOC
  630. ------------------------------------------------------------------------
  631. 7.00 Interrupts
  632. ---------------
  633. There are some quirks to 65816 interrupts that you should consider. If you
  634. are going to be writing native 65816 code you should give some
  635. consideration to how your interrupt routine is going to be handled. If you
  636. have written custom a IRQ routine that assumes Native mode, then your
  637. considerations are minor. However, if you are writing Native mode 65816
  638. code with 16 bit accumulator and/or 16 bit index registers, and you are
  639. using a stock kernal IRQ that assumes emulation mode, then you must do some
  640. coding to handle the discrepancies. In 6502 emulation mode, and IRQ pushes
  641. the program counter high, then pc low, and finally the status register on
  642. to the stack. When in Native mode an IRQ starts by stacking the following:
  643. Program Counter Bank (PBR)
  644. Program Counter High
  645. Program Counter Low
  646. Status Register
  647. Next; the status register decimal mode bit (d) is cleared (setting binary
  648. mode), and the IRQ flag is set (non NMI only). Finally, the program bank
  649. (PBR) is set to zero and the 65816 jumps through the IRQ hardware vector.
  650. The implications are that if the 65816 is running in emulation mode in a
  651. ram bank other than Bank zero, then the program bank is going to be lost
  652. (not good). There are two solutions to the problem. One is never to run in
  653. emulation mode outside of Ram Bank zero. Second; you could save off the
  654. current program bank value somewhere in Ram before running in emulation
  655. mode beyond Bank Zero.
  656. One thing that is unclear at this point, is if the CMD Super CPU can even
  657. handle a Native Mode IRQ. Native Mode features a new hardware vector table:
  658. TOC
  659. 7.10 Hardware Vectors:
  660. ----------------------
  661. Native Mode 6502 Emulation Mode
  662. -----------------------------------------
  663. IRQ $FFEE-$FFEF IRQ/BRK $FFFE-$FFFF
  664. RESET $FFFC-$FFFD
  665. NMI $FFEA-$FFEB NMI $FFFA-$FFFB
  666. ABORT $FFE8-$FFE9 ABORT $FFF8-$FFF9
  667. BRK $FFE6-$FFE7
  668. COP $FFE5-$FFE6 COP $FFF4-$FFF5
  669. Notice that there is a separate BRK vector for Native mode, and no need to
  670. poll bit 5 for the brk flag. However when running in emulation mode,
  671. remember that bit 5 is still the BRK flag, and your IRQ will still need to
  672. check for the source of the IRQ.
  673. While in Native mode, a BRK instruction is two bytes. The Zero BRK opcode
  674. followed by an optional "signature" byte. This way, you can detect what BRK
  675. caused the vector to be taken for multiple BRK's while debugging.
  676. COP is for a coprocessor interrupt. (see the instruction COP)
  677. Notice in Native mode where the IRQ vector destinations are...hmm
  678. When an IRQ is triggered, the current instruction is completed before the
  679. interrupt is processed. This "interrupt latency" may be up to 7 clock
  680. cycles. If you are running a time critical IRQ you may want to examine the
  681. WAI:wait for interrupt instruction whereby you can stop the processor until
  682. and interrupt occurs.
  683. The ABORT vector listed above is taken when the 65816's Abort pin is pulled
  684. low. This pin is only available on the 65816.
  685. TOC
  686. ------------------------------------------------------------------------
  687. ------------------------------------------------------------------------
  688. ================================
  689. Appendix A: 65816 Instruction Set
  690. ================================
  691. ------------------------------------------------------------------------
  692. ------------------------------------------------------------------------
  693. Syntax Conventions:
  694. addr two byte address.
  695. addr/const two byte value: either an address or a constant.
  696. const one- or two-byte constant.
  697. destbk 64k bank to which string will be moved.
  698. dp one-byte direct page offset (6502 zero page).
  699. label label of code in same 64K bank as instruction.
  700. long three-byte address (includes bank byte)
  701. nearlabel label of code close enough to instruction to be
  702. reachable by a one-byte signed offset.
  703. sr one-byte stack relative offset.
  704. srcebk 64k bank from which string will be moved.
  705. Flags
  706. Bits 76543210
  707. nvmxdizc
  708. e
  709. n - negative.
  710. v - overflow.
  711. m - 8/16 memory/accumulator.
  712. x - 8/16 bit index registers.
  713. d - decimal mode.
  714. i - irq enable disable.
  715. z - zero result.
  716. c - carry.
  717. e - emulation.
  718. ------------------------------------------------------------------------
  719. ADC Add with carry.
  720. When using 16 bit accumulator mode, as expected, a carry will be properly
  721. rolled over from bit 7 to bit 8 when generated by the operation. (ie: $FF+4
  722. = $0103 with 1 in high byte an 3 in low byte of the accumulator.) Thus
  723. carry need only be cleared when the low order bytes are added. Manual
  724. checking for carry above bit 15 will still have to be done just as when in
  725. 8 bit accumulator mode.
  726. When in 16 bit mode, the low-order bits are located in the effective
  727. address, and the high order bits are located in the effective address plus
  728. one.
  729. Flags Altered nv----zc
  730. n Set if most-significant bit of result is set.
  731. v Set if signed overflow.
  732. z Set if result is zero.
  733. c Set if overflow.
  734. Addressing Mode Syntax Opcode Bytes Cycles Ref
  735. ----------------------------------------------------------------------
  736. Immediate ADC #const 69 2* 2 | 1
  737. Absolute ADC addr 6D 3 4 | 1
  738. Absolute Long ADC long 6F 4 5 | 1
  739. Direct Page ADC dp 65 2 3 | 1,2
  740. Direct Page Indirect ADC (dp) 72 2 5 | 1,2
  741. Direct Page Indirect Long ADC [dp] 67 2 6 | 1,2
  742. Absolute Indexed,X ADC addr,X 7D 3 4 | 1,3
  743. Absolute Long Indexed,X ADC long,X 7F 4 5 | 1
  744. Absolute Indexed,Y ADC addr,Y 79 3 4 | 1,3
  745. Direct Page Indexed,X ADC dp,X 75 2 4 | 1,2
  746. DP Indexed Indirect,X ADC (dp,X) 61 2 6 | 1,2
  747. DP Indirect Indexed,Y ADC (dp),Y 71 2 5 | 1,2,3
  748. DP Indirect Long Indexed,Y ADC [dp],Y 77 2 6 | 1,2
  749. Stack Relative ADC sr,S 63 2 4 | 1
  750. SR Indirect Indexed,Y ADC (sr,S),Y 73 2 7 | 1
  751. -----------------------------------------------------------------------
  752. * Add 1 byte if m=0 (16-bit memory/accumulator).
  753. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  754. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  755. 3 Add 1 cycle if adding index crosses a page boundary.
  756. AND And Accumulator with Memory
  757. Logically ANDs the data located at the effective address
  758. specified by the operand and the accumulator.
  759. If in 16 bit accumulator mode (m=0) Data ANDed from memory is
  760. 16 bits wide, the low byte is the effective address and the high
  761. byte is the effective address+1.
  762. Flags Altered n-----z-
  763. n Set if most significant bit of result is set.
  764. z Set if result of and is zero.
  765. Addressing Mode Syntax Opcode Bytes Cycles Ref
  766. ----------------------------------------------------------------------
  767. Immediate AND #const 29 2* 2 | 1
  768. Absolute AND addr 2D 3 4 | 1
  769. Absolute Long AND long 2F 4 5 | 1
  770. Direct Page AND dp 25 2 3 | 1,2
  771. Direct Page Indirect AND (dp) 32 2 5 | 1,2
  772. DP Indirect Long AND [dp] 27 2 6 | 1,2
  773. Absolute Indexed,X AND addr,X 3D 3 4 | 1,3
  774. Absolute Long Indexed,X AND long,X 3F 4 5 | 1
  775. Absolute Indexed,Y AND addr,Y 39 3 4 | 1,3
  776. Direct Page Indexed,X AND dp,X 35 2 4 | 1,2
  777. DP Indexed Indirect,X AND (dp,X) 21 2 6 | 1,2
  778. DP Indirect Indexed,Y AND (dp),Y 31 2 5 | 1,2,3
  779. DP Indirect Long Indexed,Y AND [dp],Y 37 2 6 | 1,2
  780. Stack Relative (SR) AND sr,S 23 2 4 | 1
  781. SR Indirect Indexed,Y AND (sr,S),Y 33 2 7 | 1
  782. ----------------------------------------------------------------------
  783. * Add 1 byte if m=0 (16-bit memory/accumulator).
  784. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  785. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  786. 3 Add 1 cycle if adding index crosses a page boundary.
  787. ASL Arithmetic Shift Left
  788. Shifts all bits left with most significant bit moving into the
  789. carry flag. If in 16 bit accumulator mode (m=0), data shifted
  790. is 16 bits.
  791. Flags Altered n-----zc
  792. n Set if most significant bit of result is set.
  793. z Set if result is zero.
  794. c High bit (7 or 15) is moved into carry.
  795. Addressing Mode Syntax Opcode Bytes Cycles Ref
  796. ----------------------------------------------------------------------
  797. Accumulator ASL a 0A 1 2 |
  798. Absolute ASL addr 0E 3 6 | 1
  799. Direct Page ASL dp 06 2 5 | 1,2
  800. Absolute Indexed,X ASL addr,X 1E 3 7 | 1
  801. Direct Page Indexed,X ASL dp,X 16 2 6 | 1,2
  802. ----------------------------------------------------------------------
  803. 1 Add 2 cycles if m=0 (16-bit memory/accumulator).
  804. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  805. TOC
  806. Branching Instructions:
  807. -----------------------
  808. The following branch instructions work identically to a 6502 - therefore,
  809. no indepth discussion will be presented.
  810. Branching commands do not affect any status register flags. The single byte
  811. operand range is +128 to -127.
  812. BCC Branch Carry Clear alias BLT Branch Less Than.
  813. BCS Branch Carry Set alias BGE Branch Greater Than or Equal.
  814. BEQ Branch Equal
  815. BNE Branch Not Equal
  816. BMI Branch Result Minus
  817. BPL Branch Result Positive
  818. BVC Branch Overflow Clear
  819. BVS Branch Overflow Set
  820. Addressing Mode Syntax Opcode Bytes Cycles Ref
  821. ----------------------------------------------------------------------
  822. Program Counter Relative BCC near 90 2 2 | 1,2
  823. Program Counter Relative BCS near B0 2 2 | 1,2
  824. Program Counter Relative BEQ near F0 2 2 | 1,2
  825. Program Counter Relative BNE near D0 2 2 | 1,2
  826. Program Counter Relative BMI near 30 2 2 | 1,2
  827. Program Counter Relative BPL near 10 2 2 | 1,2
  828. Program Counter Relative BVC near 50 2 2 | 1,2
  829. Program Counter Relative BVS near 70 2 2 | 1,2
  830. ----------------------------------------------------------------------
  831. 1 Add 1 cycle if branch is taken.
  832. 2 Add 1 more cycle if in 6502 emulation mode (e=1).
  833. TOC
  834. New Branch Instructions:
  835. ------------------------
  836. BRA Branch Always
  837. Branch always takes the operand branch without regard for the current state
  838. of the status register. The single byte operand range is +128 to -127. This
  839. instruction and the following BRL instruction ease the task of writing
  840. relocatable code.
  841. Addressing Mode Syntax Opcode Bytes Cycles Ref
  842. ----------------------------------------------------------------------
  843. Program Counter Relative BRA near 80 2 3 | 1
  844. ----------------------------------------------------------------------
  845. 2 Add 1 more cycle if in 6502 emulation mode (e=1).
  846. BRL Branch Always Long
  847. Same as BRA, but the operand is 2 bytes giving the instruction a 64k range.
  848. This instruction is similar to the JMP command, with the advantage being
  849. that JMP is and absolute address and BRL is a relative address.
  850. No flags are affected.
  851. Addressing Mode Syntax Opcode Bytes Cycles
  852. -----------------------------------------------------------------
  853. Program Counter Relative Long BRL $xxxx 82 3 4
  854. -----------------------------------------------------------------
  855. BIT Test Memory Bits against Accumulator
  856. The 65816 provides 3 new addressing modes for the old standard BIT
  857. instruction. The only true difference is that when the processor is in 16
  858. bit mode, the top two bits xfered to the status register will come from
  859. bits 14 and 15. When in 8 bit mode bits 6 and 7 are xfered to the status
  860. register.
  861. Flags affected nv----z- (Other than immediate addressing).
  862. ------z- (Immediate addressing only).
  863. n Takes value of most significant bit of memory data.
  864. v Takes value from bit 6 or 14 of memory data.
  865. z Set if logical AND of mem and acc is zero.
  866. Addressing Mode Syntax Opcode Bytes Cycles Ref
  867. ----------------------------------------------------------------------
  868. Immediate BIT #const 89 2* 2 | 1
  869. Absolute BIT addr 2C 3 4 | 1
  870. Direct Page BIT dp 24 2 3 | 1,2
  871. Absolute Indexed,X BIT addr,X 3C 3 4 | 1,3
  872. Direct Page Indexed,X BIT dp,X 34 2 4 | 1,2
  873. ----------------------------------------------------------------------
  874. * Add 1 byte if m=0 (16-bit memory/accumulator).
  875. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  876. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  877. 3 Add 1 cycle if adding index crosses a page boundary.
  878. BRK Software Break
  879. While in native 65816 mode, BRK is unaffected by the I interrupt disable
  880. flag. Additionally, you may now pass a one byte signature byte to indicate
  881. which BRK instruction caused the BRK to be preformed.
  882. The new BRK handler includes a Hardware Vector- thus, it is no longer
  883. required to check for the BRK bit flag via the IRQ.
  884. When a BRK is performed in 65816 Native mode:
  885. * the program counter bank register is pushed onto stack.
  886. * the program counter is incremented by two and pushed on the stack.
  887. * the status register is pushed onto the stack
  888. * the interrupt disable flag is set.
  889. * the decimal mode flag is cleared.
  890. * the program bank register is cleared to zero.
  891. * the program counter is loaded from the break vector at $FFE6-$FFE7.
  892. While in 6502 emulation mode, (e=1) a BRK is preformed true to it's 6502
  893. forerunner (b flag set, status pushed onto stack, SEI and IRQ performed.).
  894. Addressing Mode Syntax Opcode Bytes Cycles Ref
  895. ----------------------------------------------------------------------
  896. Stack/Interrupt BRK 00 2* 7 | 1
  897. ----------------------------------------------------------------------
  898. * BRK is one byte, but program counter value pushed onto stack is
  899. incremented by 2 allowing for optional signature byte.
  900. 1 Add one cycle for 65816 native mode (e=0).
  901. Status Register Setting and Clearing:
  902. -------------------------------------
  903. The following status set and reset instructions operate the same in 65816
  904. native mode and 6502 emulation mode.
  905. CLC Clear carry flag.
  906. CLD Clear decimal flag.
  907. CLI Clear interrupt flag.
  908. CLV Clear overflow flag.
  909. SEC Set carry flag.
  910. SED Set decimal flag.
  911. SEI Set interrupt flag.
  912. Flags
  913. Addressing Mode nvmxdizc Syntax Opcode Bytes Cycles
  914. ----------------------------------------------------------------------
  915. Implied -------0 CLC 18 1 2
  916. Implied ----0--- CLD D8 1 2
  917. Implied -----0-- CLI 58 1 2
  918. Implied -0------ CLV B8 1 2
  919. Implied -------1 SEC 38 1 2
  920. Implied ----1--- SED F8 1 2
  921. Implied -----1-- SEI 78 1 2
  922. ----------------------------------------------------------------------
  923. TOC
  924. CMP Compare Accumulator with Memory
  925. For the most part, this instruction works the same in 6502 emulation mode
  926. and 65816 mode.
  927. While in 16 bit accumulator mode the low byte of the compare will come from
  928. the effective address and the high byte from the effective address plus
  929. one.
  930. Flags Altered n-----zc
  931. n Set if most significant bit of result is set.
  932. z Set if result is zero.
  933. c Set if no borrow was required. Acc => memory.
  934. C=0 if borrow required Acc < memory.
  935. Addressing Mode Syntax Opcode Bytes Cycles Ref
  936. ----------------------------------------------------------------------
  937. Immediate CMP #const C9 2* 2 | 1
  938. Absolute CMP addr CD 3 4 | 1
  939. Absolute Long CMP long CF 4 5 | 1
  940. Direct Page CMP dp C5 2 3 | 1,2
  941. Direct Page Indirect CMP (dp) D2 2 5 | 1,2
  942. Direct Page Indirect Long CMP [dp] C7 2 6 | 1,2
  943. Absolute Indexed,X CMP addr,X DD 3 4 | 1,3
  944. Absolute Long Indexed,X CMP long,X DF 2 7 | 1
  945. Absolute Indexed,Y CMP addr,Y D9 3 4 | 1,3
  946. Direct Page Indexed,X CMP dp,X D5 2 4 | 1,2
  947. DP Indexed Indirect,X CMP (dp,X) C1 2 6 | 1,2
  948. DP Indirect Indexed,Y CMP (dp),Y D1 2 5 | 1,2,3
  949. DP Indirect Long Indexed,Y CMP [dp],Y D7 2 6 | 1,2
  950. Stack Relative (SR) CMP sr,S C3 2 4 | 1
  951. SR Indirect Indexed,Y CMP (sr,S),Y D3 2 7 | 1
  952. ----------------------------------------------------------------------
  953. * Add 1 byte if m=0 (16-bit memory/accumulator).
  954. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  955. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  956. 3 Add 1 cycle if adding index crosses a page boundary.
  957. COP Coprocessor Empowerment
  958. COP cause a software interrupt through a separate COP hardware vector. The
  959. vector is to be located at $FFF$-$FFF5. In 6502 emulation mode:
  960. * The program counter is incremented by 2 and pushed on stack.
  961. * The status register is pushed onto the stack.
  962. * The interrupt status bit is set.
  963. * The program counter is loaded with the hardware vector.
  964. * The decimal flag is cleared.
  965. In Native mode:
  966. * The PC bank register is pushed onto stack.
  967. * The PC is incremented by two and pushed onto stack.
  968. * The status register is pushed onto stack.
  969. * The interrupt status flag is set.
  970. * The program bank register is cleared to zero.
  971. * The PC is loaded with the hardware vector.
  972. * The decimal flag is cleared after COP executed.
  973. Flags Altered ----di--
  974. d decimal mode flag is reset to zero.
  975. i Interrupt disable is set.
  976. Addressing Mode Syntax Opcode Bytes Cycles Ref
  977. ----------------------------------------------------------------------
  978. Stack/Interrupt COP const 02 2** 7 | 1
  979. ----------------------------------------------------------------------
  980. * COP is a 1 byte instruction, but the PC in incremented by to and
  981. pushed onto stack, allowing for an optional signature byte.
  982. 1 Add 1 cycle for 65816/65802 native mode (e=0)
  983. CPX Compare X Index register with Memory
  984. CPX functions the same as a 6502. The only notable exception is to remember
  985. that when in 16 bit index register mode (x=0) that date/memory will be 16
  986. bits wide. The low order byte will come from the the effect address and the
  987. high order byte from the effective address plus one.
  988. Flags Altered n-----zc
  989. n Set if most significant bit of result is set.
  990. z Set if result is zero.
  991. c Set if no borrow was required ( X >= memory).
  992. Cleared if borrow required (X < memory).
  993. Addressing Mode Syntax Opcode Bytes Cycles Ref
  994. ----------------------------------------------------------------------
  995. Immediate CPX #const E0 2* 2 | 1
  996. Absolute CPX addr EC 3 4 | 1
  997. Direct Page CPX dp E4 2 3 | 1,2
  998. ----------------------------------------------------------------------
  999. * Add 1 byte if m=0 (16-bit index registers).
  1000. 1 Add 1 cycle if x=0 (16-bit index registers).
  1001. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1002. CPY Compare Y Index register with Memory
  1003. CPY functions the same as a 6502. The only notable exception is to remember
  1004. that when in 16 bit index register mode (x=0) that date/memory will be 16
  1005. bits wide. The low order byte will come from the the effect address and the
  1006. high order byte from the effective address plus one.
  1007. Flags Altered n-----zc
  1008. n Set if most significant bit of result is set.
  1009. z Set if result is zero.
  1010. c Set if no borrow was required ( Y >= memory).
  1011. Cleared if borrow required (Y < memory).
  1012. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1013. ----------------------------------------------------------------------
  1014. Immediate CPY #const C0 2* 2 | 1
  1015. Absolute CPY addr CC 3 4 | 1
  1016. Direct Page CPY dp C4 2 3 | 1,2
  1017. ----------------------------------------------------------------------
  1018. * Add 1 byte if m=0 (16-bit index registers).
  1019. 1 Add 1 cycle if x=0 (16-bit index registers).
  1020. 2 Add 1 cycle if low byte of Direct Page register is <> 0.
  1021. DEC Decrement Memory
  1022. DEC also works nearly the same as a 6502 mode. When in 16 bit
  1023. accumulator/memory mode (m=0) data altered will be 16 bits wide with
  1024. automatic underflow from high byte to low byte. The low order byte will
  1025. come from the the effect address and the high order byte from the effective
  1026. address plus one.
  1027. Flags Altered n-----z-
  1028. n Set if most significant bit of result is set.
  1029. z Set if result is zero.
  1030. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1031. ----------------------------------------------------------------------
  1032. Accumulator DEC A 3A 1 2 |
  1033. Alias: DEA
  1034. Absolute DEC addr CE 3 6 | 1
  1035. Direct Page DEC dp C6 2 5 | 1,2
  1036. Absolute Indexed,X DEC addr,X DE 3 7 | 1
  1037. Direct Page Indexed,X DEC dp,X D6 2 6 | 1,2
  1038. ----------------------------------------------------------------------
  1039. 1 Add 2 cycles if m=0 (16-bit memory/accumulator).
  1040. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1041. DEX, DEY Decrement Index Registers
  1042. Both instructions operate just as a 6502. When in 16 bit index register
  1043. mode, the register will be treated as 16 bits wide.
  1044. Flags Altered n-----z-
  1045. n Set if most significant bit of result is set.
  1046. z Set if result is zero.
  1047. Addressing Mode Syntax Opcode Bytes Cycles
  1048. ----------------------------------------------------------------------
  1049. Implied DEX CA 1 2
  1050. Implied DEY 88 1 2
  1051. ----------------------------------------------------------------------
  1052. EOR Exclusive-OR Accumulator with Memory
  1053. Another instruction that operates just as a 6502, only new addressing
  1054. modes. When in 16 bit memory/accumulator mode data is 16 bits wide - as
  1055. usual the low byte will come from the effective address and the high byte
  1056. from the effective address plus one.
  1057. Flags Altered n-----z-
  1058. n Set if most significant bit of result is set.
  1059. z Set if result is zero.
  1060. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1061. ----------------------------------------------------------------------
  1062. Immediate EOR #const 49 2* 2 | 1
  1063. Absolute EOR addr 4D 3 4 | 1
  1064. Absolute Long EOR long 4F 4 5 | 1
  1065. Direct Page EOR dp 45 2 3 | 1,2
  1066. Direct Page Indirect EOR (dp) 52 2 5 | 1,2
  1067. Direct Page Indirect Long EOR [dp] 47 2 6 | 1,2
  1068. Absolute Indexed,X EOR addr,X 5D 3 4 | 1,3
  1069. Absolute Long Indexed,X EOR long,X 5F 4 5 | 1
  1070. Absolute Indexed,Y EOR addr,Y 59 3 4 | 1,3
  1071. Direct Page Indexed,X EOR dp,X 55 2 4 | 1,2
  1072. DP Indexed Indirect,X EOR (dp,X) 41 2 6 | 1,2
  1073. DP Indirect Indexed,Y EOR (dp),Y 51 2 5 | 1,2,3
  1074. DP Indirect Long Indexed,Y EOR [dp],Y 57 2 6 | 1,2
  1075. Stack Relative (SR) EOR sr,S 43 2 4 | 1
  1076. SR Indirect Indexed,Y EOR (sr,S),Y 53 2 7 | 7
  1077. ----------------------------------------------------------------------
  1078. * Add 1 byte if m=0 (16-bit memory/accumulator).
  1079. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  1080. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1081. 3 Add 1 cycle if adding index crosses a page boundary.
  1082. INC Increment Data
  1083. Also operates just as the 6502 INC instruction. When in 16 bit
  1084. memory/accumulator mode (m=0) data acted upon is 16 bits wide.
  1085. One new addressing mode is Accumulator addressing that will increment the
  1086. Accumulator.
  1087. Flags Altered n-----z-
  1088. n Set if most significant bit of result is set.
  1089. z Set if result is zero.
  1090. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1091. ----------------------------------------------------------------------
  1092. Accumulator INC a 1A 1 2 |
  1093. Alias: INA
  1094. Absolute INC addr EE 3 6 | 1
  1095. Direct Page INC dp E6 2 5 | 1,2
  1096. Absolute Indexed,X INC addr,X FE 3 7 | 1
  1097. Direct Page Indexed,X INC dp,X F6 2 6 | 1,2
  1098. ----------------------------------------------------------------------
  1099. 1 Add 2 cycles if m=0 (16-bit memory/accumulator).
  1100. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1101. INX, INY Increment Index Registers
  1102. Both instructions operate just as a 6502. When in 16 bit index register
  1103. mode, the register will be treated as 16 bits wide.
  1104. Flags Altered n-----z-
  1105. n Set if most significant bit of result is set.
  1106. z Set if result is zero.
  1107. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1108. ----------------------------------------------------------------------
  1109. Implied INX E8 1 2 |
  1110. Implied INY C8 1 2 |
  1111. ----------------------------------------------------------------------
  1112. JMP Jump to New Location
  1113. JMP transfers control to the operand address. If a long jump is executed
  1114. the program counter bank register is loaded with the third byte of the
  1115. target address.
  1116. The 65816 Designers also specify that an assembler could possibly use JML
  1117. in place of a JMP Long instruction, and also JML [adr] for Absolute
  1118. indirect long.
  1119. Flags Affected:--------
  1120. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1121. ----------------------------------------------------------------------
  1122. Absolute JMP addr 4C 3 3 |
  1123. Absolute Indirect JMP (addr) 6C 3 5 | 1
  1124. Absolute Indexed Indirect JMP (addr,X) 7C 3 6 |
  1125. Absolute Long JMP long 5C 4 4 |
  1126. Alias: JML long
  1127. Absolute Indirect Long JMP [addr] DC 3 6 |
  1128. Alias: JML [addr]
  1129. ----------------------------------------------------------------------
  1130. 1 6502: If low byte of addr is $FF (ie: addr is $xxFF) yields
  1131. incorrect result.
  1132. JSR, JSL Jump to Subroutine (gosub)
  1133. JSR works just as a 6502 with the new addressing modes available. If an
  1134. absolute address is coded by the assembler that is less than $FFFF then a
  1135. standard JSR is used, else if it is greater than $FFFF then absolute long
  1136. addressing is used. A standard JSR gosubs to the the routine in the current
  1137. program bank.
  1138. JSR can also use Indexed Indirect addressing. (see section on addressing
  1139. modes for an example.)
  1140. JML is a four byte instruction that will JSR to a subroutine located in any
  1141. bank. When executed the current program counter bank is pushed onto the
  1142. stack before the program counter high/low bytes.
  1143. Flags Affected: --------
  1144. Addressing Mode Syntax Opcode Bytes Cycles
  1145. ----------------------------------------------------------------------
  1146. Absolute Long JSL long 22 4 8
  1147. Alais: JSR long
  1148. Absolute JSR addr 20 3 6
  1149. Absolute Indexed Indirect JSR (addr,X) FC 3 8
  1150. ----------------------------------------------------------------------
  1151. LDA Load the Accumulator with Memory
  1152. LDA is nearly identical to the standard 6502 LDA instruction. New features
  1153. are the implementation of the new addressing modes. While the status
  1154. register is set for 16 bit memory/accumulator mode (m=0), data loaded is 16
  1155. bits wide with the load byte coming from the effective address and the high
  1156. byte of the accumulator coming from the effective address plus one.
  1157. Flags affected n-----z-
  1158. n Takes value of most significant bit of memory data.
  1159. z Set if data loaded is zero.
  1160. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1161. ----------------------------------------------------------------------
  1162. Immediate LDA #const A9 2* 2 | 1
  1163. Absolute LDA addr AD 3 4 | 1
  1164. Absolute Long LDA long AF 4 5 | 1,2
  1165. Direct Page LDA dp A5 2 3 | 1,2
  1166. Direct Page Indirect LDA (dp) B2 2 5 | 1,2
  1167. Direct Page Indirect Long LDA [dp] A7 2 6 | 1,2
  1168. Absolute Indexed,X LDA addr,X BD 3 4 | 1,3
  1169. Absolute Long Indexed,X LDA long,X BF 4 5 | 1
  1170. Absolute Indexed,Y LDA addr,Y B9 3 4 | 1,3
  1171. Direct Page Indexed,X LDA dp,X B5 2 4 | 1,2
  1172. DP Indexed Indirect,X LDA (dp,X) A1 2 6 | 1,2
  1173. DP Indirect Indexed,Y LDA (dp),Y B1 2 5 | 1,2,3
  1174. DP Indirect Long Indexed,Y LDA [dp],Y B7 2 6 | 1,2
  1175. Stack Relative (SR) LDA sr,S A3 2 4 | 1
  1176. SR Indirect Indexed,Y LDA (sr,S),Y B3 2 7 | 1
  1177. ----------------------------------------------------------------------
  1178. * Add 1 byte if m=0 (16-bit memory/accumulator).
  1179. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  1180. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1181. 3 Add 1 cycle if adding index crosses a page boundary.
  1182. LDX Load X Register from Memory
  1183. LDX is identical to a stock 6502.
  1184. The only new feature to remember is that when in 16 bit index register mode
  1185. (x=0) that data will be 16 bits wide. The X register low byte will come
  1186. from the effective address and the high byte from the effective address
  1187. plus one.
  1188. Flags affected n-----z-
  1189. n Takes value of most significant bit of memory data.
  1190. z Set if data loaded is zero.
  1191. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1192. ----------------------------------------------------------------------
  1193. Immediate LDX #const A2 2* 2 | 1
  1194. Absolute LDX addr AE 3 4 | 1
  1195. Direct Page LDX dp A6 2 3 | 1,2
  1196. Absolute Indexed,Y LDX addr,Y BE 3 4 | 1,3
  1197. DP Indexed,Y LDX dp,Y B6 2 4 | 1,2
  1198. ----------------------------------------------------------------------
  1199. * Add 1 byte if m=0 (16-bit index registers).
  1200. 1 Add 1 cycle if x=0 (16-bit index registers).
  1201. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1202. 3 Add 1 cycle if indexing crosses page boundary.
  1203. LDY Load Y Register from Memory
  1204. LDY is identical to a stock 6502.
  1205. The only new diversion is to remember that when in 16 bit index register
  1206. mode (x=0) that data will be 16 bits wide. The Y register low byte will
  1207. come from the effective address and the high byte from the effective
  1208. address plus one.
  1209. Flags affected n-----z-
  1210. n Takes value of most significant bit of memory data.
  1211. z Set if data loaded is zero.
  1212. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1213. ----------------------------------------------------------------------
  1214. Immediate LDY #const A0 2* 2 | 1
  1215. Absolute LDY addr AC 3 4 | 1
  1216. Direct Page LDY dp A4 2 3 | 1,2
  1217. Absolute Indexed,X LDY addr,X BC 3 4 | 1,3
  1218. Direct Page Indexed,X LDY dp,X B4 2 4 | 1,2
  1219. ----------------------------------------------------------------------
  1220. * Add 1 byte if m=0 (16-bit index registers).
  1221. 1 Add 1 cycle if x=0 (16-bit index registers).
  1222. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1223. 3 Add 1 cycle if indexing crosses page boundary.
  1224. LSR Logical Shift Right.
  1225. Yet another instruction unchanged from the standard 6502 instruction set.
  1226. 16 bit mode (m=0) data shifted will be 16 bits wide.
  1227. Flags Altered n-----zc
  1228. n Cleared.
  1229. z Set if result is zero.
  1230. c Bit zero becomes new carry.
  1231. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1232. ----------------------------------------------------------------------
  1233. Accumulator LSR a 4A 1 2 |
  1234. Absolute LSR addr 4E 3 6 | 1
  1235. Direct Page LSR dp 46 2 5 | 1,2
  1236. Absolute Indexed,X LSR addr,X 5E 3 7 | 1
  1237. Direct Page Indexed,X LSR dp,X 56 2 6 | 1,2
  1238. ----------------------------------------------------------------------
  1239. 1 Add 2 cycles if m=0 (16-bit memory/accumulator).
  1240. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1241. Block Move Instructions
  1242. =======================
  1243. MVP Move Positive destination > source
  1244. MVN Move Negative destination < source
  1245. This instruction is new 65816 only. MVN and MVP move data from memory
  1246. location to memory location without user intervention.
  1247. Two instructions are necessary so that as the data is being moved in a
  1248. negative direction it will not overwrite itself.
  1249. The source address for the move is taken from the X register. The
  1250. destination address for the move is taken for the Y register. The 16 bit
  1251. length of the move is taken from the Accumulator regardless of the m flag
  1252. setting. This value should be one less than the actual length of the move
  1253. (ie a=$0000 and one byte will be moved).
  1254. The two operand bytes specify the source bank of 64k and the destination
  1255. bank of 64k. The assembler order of the operand bytes is source,
  1256. destination - however, the actual binary output code will be the MVN or MVP
  1257. opcode followed byte the destination bank byte and the source bank byte.
  1258. MVN Move Negative is used when the source address is greater than the
  1259. destination address, or conversely when the destination range is lower than
  1260. the source range.
  1261. The MVN instruction uses the X and Y registers to denote the bottom
  1262. (beginning) address of the two memory segments to be moved. With MVN the
  1263. data is moved from the source in X to the destination in Y, then the X and
  1264. Y registers are are incremented and the accumulator decremented until the
  1265. accumulator underflows to $FFFF.
  1266. MVP Move Positive is used with the source address is less than the
  1267. destination, or conversely when the destination range is higher in memory
  1268. than the source range.
  1269. The MVP instruction uses the X and Y registers to denote the top address of
  1270. the two blocks of memory. The data is moved from the source in X to the
  1271. address in Y and then the XY and accumulator registers are decremented
  1272. until the accumulator underflows to $FFFF.
  1273. If the index registers are set for 8 bit mode (x=1) or the processor is set
  1274. for 6502 emulation mode, then the data moved will be in page zero only
  1275. because the high bytes will default to zero.
  1276. To reduce code length it is very easy to setup the move instructions in a
  1277. subroutine, then use dynamically modified code to exchange the MVN and MVP
  1278. opcodes on-the-fly.
  1279. Status register flags are NOT affect by the move instructions.
  1280. Addressing Mode Syntax Opcode Bytes Cycles
  1281. ----------------------------------------------------------------------
  1282. Block Move MVN src,dest 54 3 *
  1283. Block Move MVP src,dest 44 3 *
  1284. ----------------------------------------------------------------------
  1285. * 7 cycles each byte moved.
  1286. TOC
  1287. NOP No Operation.
  1288. Same as 6502. No flags are affected with NOP.
  1289. Addressing Mode Syntax Opcode Bytes Cycles
  1290. ----------------------------------------------------------------------
  1291. Implied NOP EA 1 2
  1292. ----------------------------------------------------------------------
  1293. ORA OR Accumulator with Memory.
  1294. Same function as 6502 ORA with new addressing modes.
  1295. When in 16 bit memory/accumulator mode (m=0) data acted upon is 16 bits
  1296. wide. The low byte is the effective address and the high byte is the
  1297. effective address plus one.
  1298. Flags Affected: n-----z-
  1299. n Set if most significant bit of result is set.
  1300. z Set if result is zero.
  1301. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1302. ----------------------------------------------------------------------
  1303. Immediate ORA #const 09 2* 2 | 1
  1304. Absolute ORA addr 0D 3 4 | 1
  1305. Absolute Long ORA long 0F 4 5 | 1
  1306. Direct Page ORA dp 05 2 3 | 1,2
  1307. Direct Page Indirect ORA (dp) 12 2 5 | 1,2
  1308. Direct Page Indirect Long ORA [dp] 07 2 6 | 1,2
  1309. Absolute Indexed,X ORA addr,X 1D 3 4 | 1,3
  1310. Absolute Long Indexed,X ORA long,X 1F 4 5 | 1
  1311. Absolute Indexed,Y ORA addr,Y 19 3 4 | 1,3
  1312. Direct Page Indexed,X ORA dp,X 15 2 4 | 1,2
  1313. DP Indexed Indirect,X ORA (dp,X) 01 2 6 | 1,2
  1314. DP Indirect Indexed,Y ORA (dp),Y 11 2 5 | 1,2,3
  1315. DP Indirect Long Indexed,Y ORA [dp],Y 17 2 6 | 1,2
  1316. Stack Relative (SR) ORA sr,S 03 2 4 | 1
  1317. SR Indirect Indexed,Y ORA (sr,S),Y 13 2 7 | 1
  1318. ----------------------------------------------------------------------
  1319. * Add 1 byte if m=0 (16-bit memory/accumulator).
  1320. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  1321. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1322. 3 Add 1 cycle if adding index crosses a page boundary.
  1323. PEA Push Effective Absolute Address
  1324. PEA pushes the sixteen-bit operand onto the stack. The stack pointer is
  1325. decremented by two. No flags are affected. Unlike other instructions that
  1326. use similar assembler notations, PEA pushes the value of the operands onto
  1327. the stack, NOT the data located at an effective address. A more appropriate
  1328. name should have been to push Immediate data onto the stack - it is unclear
  1329. why this discrepancy exists.
  1330. For example:
  1331. PEA $1234
  1332. Pushes a #$12 and then a #$34 onto the stack.
  1333. Addressing Mode Syntax Opcode Bytes Cycles
  1334. ----------------------------------------------------------------------
  1335. Stack (Absolute) PEA addr F4 3 5
  1336. ----------------------------------------------------------------------
  1337. PEI Push Effective Indirect Address
  1338. This 65816 instruction pushes the address of the effective address onto the
  1339. stack. This instruction always pushes 16 bits of data onto the stack
  1340. without regard for the settings of the x and m status bits.
  1341. The address of the effective address plus one is pushed on the stack first
  1342. and then the address of the effective address is pushed on second.
  1343. For example: suppose $5678 is stored at location $21/$22 in standard low
  1344. byte/high byte format, then a
  1345. PEI ($21)
  1346. would get the $5678 from $21/$22 and push it onto the stack.
  1347. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1348. ----------------------------------------------------------------------
  1349. Stack (Direct Page Indirect) PEI (dp) D4 2 6 | 1
  1350. ----------------------------------------------------------------------
  1351. 1 Add 1 cycle if low byte of direct page is <>0.
  1352. PER Push effective PC Relative Indirect Address
  1353. This instruction takes the program counter and adds the 16 bit operand and
  1354. pushes the resulting 16 bits onto the stack. The destination address must
  1355. be located within the current bank of 64k memory. The value of the program
  1356. counter used in the calculation is the address of the NEXT instruction
  1357. following the PER and two operand bytes.
  1358. The result high byte is pushed first, followed by the low byte of the
  1359. result.
  1360. Because this instruction uses a relative offset for the operand, it can aid
  1361. in writing relocatable code. One could envision pushing an unknown run-time
  1362. address onto the stack with PER and then pulling the address off to
  1363. determine the programs run time origin.
  1364. Another use of this instruction could be to push a return address onto the
  1365. stack for 6502 pha:pha:rts style coding
  1366. Addressing Mode Syntax Opcode Bytes Cycles
  1367. ----------------------------------------------------------------------
  1368. Stack (PC Relative Long) PER label 62 3 6
  1369. ----------------------------------------------------------------------
  1370. Push, Pull APXY Instructions
  1371. PHA,PHP,PLA,PLP are unchanged from their 6502 forerunners. The only notable
  1372. difference is that 16 bits will be pushed on when in accumulator/memory
  1373. (m=0) mode and a PHA or PLA is executed (PHP/PLP only operate on 8 bits).
  1374. New push and pull stack instructions include PHY,PLY,PHX,PLX. These four
  1375. new instructions push and pull the index registers on and off the stack.
  1376. When the status register is set to 16 bit index register mode (x=0), the
  1377. pull and push index registers will operate on 16 bits when the status
  1378. register x is set to 0.
  1379. Addressing Mode Flags Syntax Opcode Bytes Cycles
  1380. ----------------------------------------------------------------------
  1381. Stack (Push) -------- PHA 48 1 3 | 1
  1382. Stack (Push) -------- PHP 08 1 3 |
  1383. Stack (Push) -------- PHX DA 1 3 | 2
  1384. Stack (Push) -------- PHY 5A 1 3 | 2
  1385. Stack (Pull) n-----z- PLA 68 1 4 | 1
  1386. Stack (Pull) nvmxdizc PLP 28 1 4 |
  1387. Stack (Pull) n-----z- PLX FA 1 4 | 2
  1388. Stack (Pull) n-----z- PLY 7A 1 4 | 2
  1389. ----------------------------------------------------------------------
  1390. 1 Add 1 cycle if 16 bit accumulator/memory mode (m=0).
  1391. 2 Add 1 cycle if 16 bit index registers (x=0).
  1392. Push, Pull Bank Registers
  1393. PHB Pushes the 8 bit contents of the data bank register on the stack.
  1394. PHD Pushes the 16 bit contents of the direct page register on stack.
  1395. The high byte is pushed first, followed by the low byte.
  1396. PHK Pushes the 8 bit contents of the program bank register on stack.
  1397. PLB Pulls a byte off the stack into the data bank register. This is the
  1398. only instruction that can directly change the data bank register.
  1399. PLD Pulls a sixteen bit value off stack into the direct page register. The
  1400. low byte is pulled first, followed by the high byte.
  1401. Pulled Flags Affected by pull instructions:
  1402. n Set if most significant bit of value pulled is set.
  1403. z Set if value pulled is zero.
  1404. Addressing Mode Flags Syntax Opcode Bytes Cycles
  1405. ----------------------------------------------------------------------
  1406. Stack (Push) PHB 8B 1 3
  1407. Stack (Push) PHD 0B 1 4
  1408. Stack (Push) PHK 4B 1 3
  1409. Stack (Pull) n-----z- PLB AB 1 4
  1410. Stack (Pull) n-----z- PLD 2B 1 5
  1411. ----------------------------------------------------------------------
  1412. REP Reset Status Bits.
  1413. REP is a new 65816 instruction. When used, it will reset (clear) the bits
  1414. specified by the 1 byte immediate value.
  1415. For Example to clear bit 5 of the status register:
  1416. REP #%00100000 ;clear bit 5.
  1417. or to clear multiple bits:
  1418. REP #%10110000 ;clear 7,5 and 4.
  1419. Any combination is acceptable.
  1420. To set a bit, see SEP.
  1421. Flags affected: nvmxdizc
  1422. All flags that have an operand bit set are cleared.
  1423. Other flags are not affected.
  1424. Addressing Mode Syntax Opcode Bytes Cycles
  1425. ----------------------------------------------------------------------
  1426. Immediate REP #const C2 2 3
  1427. ----------------------------------------------------------------------
  1428. ROL Rotate Memory or Accumulator Left
  1429. ROL works same as the 6502 ROL instruction.
  1430. When in 16 bit accumulator/memory mode (m=0) Data rotated is 16 bits wide
  1431. with the former bit 15 becoming the new carry. - the low-order bits are
  1432. located in the effective address, and the high order bits are located in
  1433. the effective address plus one.
  1434. Flags affected: n-----zc
  1435. n Set if most significant bit of result is set.
  1436. z Set if result is zero.
  1437. c The high bit (7 or 15) becomes the new carry.
  1438. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1439. ----------------------------------------------------------------------
  1440. Accumulator ROL A 2A 1 2 |
  1441. Absolute ROL addr 2E 3 6 | 1
  1442. Direct Page ROL dp 26 2 5 | 1,2
  1443. Absolute Indexed,X ROL addr,X 3E 3 7 | 1
  1444. Direct Page Indexed,X ROL dp,X 36 2 6 | 1,2
  1445. ----------------------------------------------------------------------
  1446. 1 Add 2 cycles if 16 bit memory accumulator mode (m=0).
  1447. 2 Add 1 cycle if direct page pointer is <>0.
  1448. ROR Rotate Memory or Accumulator Right.
  1449. Works as 6502 ROR expected.
  1450. When in 16 bit memory/accumulator mode (m=0) data rotated will be 16 bits
  1451. wide, plus the carry - the low-order bits are located in the effective
  1452. address, and the high order bits are located in the effective address plus
  1453. one.
  1454. Flags affected: n-----zc
  1455. n Set if most significant bit of result is set.
  1456. z Set if result is zero.
  1457. c Low bit becomes the new carry.
  1458. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1459. ----------------------------------------------------------------------
  1460. Accumulator ROR a 6A 1 2 |
  1461. Absolute ROR addr 6E 3 6 | 1
  1462. Direct Page ROR dp 66 2 5 | 1,2
  1463. Absolute Indexed,X ROR addr,X 7E 3 7 | 1
  1464. Direct Page Indexed,X ROR dp,X 76 2 6 | 1,2
  1465. ----------------------------------------------------------------------
  1466. 1 Add 2 cycles if 16 bit memory accumulator mode (m=0).
  1467. 2 Add 1 cycle if direct page pointer is <>0.
  1468. RTI Return from Interrupt
  1469. While in 6502 emulation mode (e=1) RTI is handled the same as a stock 6502.
  1470. While in native 65816 mode (e=0) RTI also pulls the program bank register
  1471. byte off of the stack. Since this extra byte is present, it is essential
  1472. that the RTI be executed in the same mode (e=?) that the processor was in
  1473. when the interrupt was executed.
  1474. Flags Affected: The status register is pulled from the stack,
  1475. therefore all flags are affected.
  1476. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1477. ----------------------------------------------------------------------
  1478. Stack (RTI) RTI 40 1 6 | 1
  1479. ----------------------------------------------------------------------
  1480. 1 add 1 cycle if 65816 native mode.
  1481. RTL Return from Subroutine Long
  1482. RTL works similar to an RTS but it also pulls the program bank register off
  1483. of the stack. This instruction should be used in conjunction with the JSR
  1484. long instruction or by a setup routine that also pushes the program bank
  1485. onto the stack. RTL pulls 24 bits off of the stack. First the two bytes of
  1486. the program counter low/high are pulled and incremented, then the program
  1487. bank register is pulled.
  1488. No Flags are affected by RTL.
  1489. TOC
  1490. Addressing Mode Syntax Opcode Bytes Cycles
  1491. ----------------------------------------------------------------------
  1492. Stack (RTL) RTL 6B 1 6
  1493. ----------------------------------------------------------------------
  1494. RTS Return from Subroutine
  1495. Same as the 6502 instruction. No flags are affected.
  1496. One interesting use of RTS is to push a return address on the stack and
  1497. then execute it via RTS. In order to use this type of coding the address
  1498. pushed onto the stack must be one less than the actual routine address
  1499. because when pulled back off, the processor automatically inc's the program
  1500. counter before continuing. While in Native mode with 16 bit
  1501. accumulator/memory set, this can easily be accomplished by:
  1502. DEC A ; dec 16 be accum. or DEA.
  1503. PHA ; push 16 bit return adr on stack.
  1504. RTS ; return to execute the instruction.
  1505. Addressing Mode Syntax Opcode Bytes Cycles
  1506. ----------------------------------------------------------------------
  1507. Stack (RTS) RTS 60 1 6
  1508. ----------------------------------------------------------------------
  1509. SBC Subtract from Accumulator
  1510. SBC also works just a a 6502. Again the only difference is a few new
  1511. addressing modes, and the fact that data maybe worked in a 16 bit
  1512. accumulator or 16 bit memory location.
  1513. SBC and ADC when used in 16 bit memory/accumulator mode greatly enhance the
  1514. overall utility of the 65816. A programmer can easily see how much faster
  1515. addition and subtraction routines could be performed while operating on 16
  1516. bits instead of 8.
  1517. Flags Altered nv----zc
  1518. n Set if most-significant bit of result is set.
  1519. v Set if signed overflow.
  1520. z Set if result is zero.
  1521. c Set if unsigned borrow not required.
  1522. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1523. ----------------------------------------------------------------------
  1524. Immediate SBC #const E9 2* 2 | 1
  1525. Absolute SBC addr ED 3 4 | 1
  1526. Absolute Long SBC long EF 4 5 | 1
  1527. Direct Page SBC dp E5 2 3 | 1,2
  1528. Direct Page Indirect SBC (dp) F2 2 5 | 1,2
  1529. Direct Page Indirect Long SBC [dp] E7 2 6 | 1,2
  1530. Absolute Indexed,X SBC addr,X FD 3 4 | 1,3
  1531. Absolute Long Indexed,X SBC long,X FF 4 5 | 1
  1532. Absolute Indexed,Y SBC addr,Y F9 3 4 | 1,3
  1533. Direct Page Indexed,X SBC dp,X F5 2 4 | 1,2
  1534. DP Indexed Indirect,X SBC (dp,X) E1 2 6 | 1,2
  1535. DP Indirect Indexed,Y SBC (dp),Y F1 2 5 | 1,2,3
  1536. DP Indirect Long Indexed,Y SBC [dp],Y F7 2 6 | 1,2
  1537. Stack Relative (SR) SBC sr,S E3 2 4 | 1
  1538. SR Indirect Indexed,Y SBC (sr,S),Y F3 2 7 | 1
  1539. ----------------------------------------------------------------------
  1540. * Add 1 byte if m=0 (16-bit memory/accumulator).
  1541. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  1542. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1543. 3 Add 1 cycle if adding index crosses a page boundary.
  1544. SEP Set Status Bits
  1545. SEP is a new 65816 instruction. When used, it will set the bits specified
  1546. by the 1 byte immediate value.
  1547. This is the only means of setting the M and X status register bits.
  1548. For Example to set bit 5 of the status register:
  1549. SEP #%00100000 ;set bit 5.
  1550. or to clear multiple bits:
  1551. SEP #%10110000 ;set bits 7,5 and 4.
  1552. Any combination is acceptable.
  1553. To reset a bit, see REP.
  1554. Flags affected: nvmxdizc
  1555. All flags that have an operand bit set are set.
  1556. Other flags are not affected.
  1557. Addressing Mode Syntax Opcode Bytes Cycles
  1558. ----------------------------------------------------------------------
  1559. Immediate SEP #const E2 2 3
  1560. ----------------------------------------------------------------------
  1561. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1562. ----------------------------------------------------------------------
  1563. Absolute STA addr 8D 3 4 | 1
  1564. Absolute Long STA long 8F 4 5 | 1
  1565. Direct Page STA dp 85 2 3 | 1,2
  1566. Direct Page Indirect STA (dp) 92 2 5 | 1,2
  1567. Direct Page Indirect Long STA [dp] 87 2 6 | 1,2
  1568. Absolute Indexed,X STA addr,X 9D 3 5 | 1
  1569. Absolute Long Indexed,X STA long,X 9F 4 5 | 1
  1570. Absolute Indexed,Y STA addr,Y 99 3 5 | 1
  1571. Direct Page Indexed,X STA dp,X 95 2 4 | 1,2
  1572. DP Indexed Indirect,X STA (dp,X) 81 2 6 | 1,2
  1573. DP Indirect Indexed,Y STA (dp),Y 91 2 6 | 1,2
  1574. DP Indirect Long Indexed,Y STA [dp],Y 97 2 6 | 1,2
  1575. Stack Relative (SR) STA sr,S 83 2 4 | 1
  1576. SR Indirect Indexed,Y STA (sr,S),Y 93 2 7 | 1
  1577. ----------------------------------------------------------------------
  1578. * Add 1 byte if m=0 (16-bit memory/accumulator).
  1579. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  1580. 2 Add 1 cycle if low byte of Direct Page register is <>0.
  1581. STP Stop the Processor
  1582. STP shuts the processor down until a hardware reset. It is used in some
  1583. systems to put the processor to sleep and reduce power consumption. There
  1584. is a RESet B pin on some 65816 processors that allow for the usage of this
  1585. instruction.
  1586. Addressing Mode Syntax Opcode Bytes Cycles
  1587. ----------------------------------------------------------------------
  1588. Implied STP DB 1 3
  1589. ----------------------------------------------------------------------
  1590. STX Store X Register to Memory
  1591. Another the same as 6502 mode.
  1592. Only exception is that when set for 16 bit index registers (x=0) data
  1593. stored will be 16 bits wide. Low 8 bits of Y will be stored to the
  1594. effective address and the high byte to the effective address plus one.
  1595. No flags are affected by STX.
  1596. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1597. ----------------------------------------------------------------------
  1598. Absolute STX addr 8E 3 4 | 1
  1599. Direct Page STX dp 86 2 3 | 1,2
  1600. Direct Page Indexed,Y STX dp,y 96 2 4 | 1,2
  1601. ----------------------------------------------------------------------
  1602. 1 Add 1 cycle if 16 bit index registers (x=0)
  1603. 2 Add 1 more cycle if low byte of Direct Page is <>0.
  1604. STY Store Y Register to Memory
  1605. Same as 6502 mode.
  1606. Only exception is that when set for 16 bit index registers (x=0) data
  1607. stored will be 16 bits wide. Low 8 bits of Y will be stored to the
  1608. effective address and the high byte to the effective address plus one.
  1609. No flags are affected by STY.
  1610. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1611. ----------------------------------------------------------------------
  1612. Absolute STY addr 8C 3 4 | 1
  1613. Direct Page STY dp 84 2 3 | 1,2
  1614. Direct Page Indexed,X STY dp,X 94 2 4 | 1,2
  1615. ----------------------------------------------------------------------
  1616. 1 Add 1 cycle if 16 bit index registers (x=0)
  1617. 2 Add 1 more cycle if low byte of Direct Page is <>0.
  1618. STZ Store Zero byte to Memory
  1619. A new instruction of the 65816. STZ stores a zero byte to the destination
  1620. address. When in 8 bit accumulator/memory mode (m=1) one byte is stored at
  1621. the effective address. While in 16 bit memory/accumulator mode (m=0) a zero
  1622. is stored to the effective address and to the effective address plus one.
  1623. No flags are affected.
  1624. This instruction could be defined as a replacement for stock 6502 code as:
  1625. lda #0
  1626. sta $xxxx
  1627. The perky thing about STZ is that the accumulator is unchanged and the
  1628. status register is also unchanged.
  1629. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1630. ----------------------------------------------------------------------
  1631. Absolute STZ addr 9C 3 4 | 1
  1632. Direct Page STZ dp 64 2 3 | 1,2
  1633. Absolute Indexed,X STZ addr,X 9E 3 5 | 1
  1634. Direct Page Indexed,X STZ dp,X 74 2 4 | 1,2
  1635. ----------------------------------------------------------------------
  1636. 1 Add 1 cycle if 16 bit index registers (x=0)
  1637. 2 Add 1 more cycle if low byte of Direct Page is <>0.
  1638. Register Transfer Instructions:
  1639. TAX,TXA,TAY,TYA,TSX,TXS transfer instructions transfer bytes between the
  1640. processor registers.
  1641. TAX: Transfer accumulator to X index register.
  1642. TAY: Transfer accumulator to Y index register.
  1643. TYA: Transfer Y index register to the accumulator.
  1644. TXA: Transfer X index register to the accumulator.
  1645. TSX: Transfer Stack pointer to the X index register.
  1646. TXS: Transfer X index register to the Stack pointer.
  1647. Two new register transfer instructions are TXY to transfer directly from
  1648. the X register into the Y register and TYX to transfer from Y register to X
  1649. register.
  1650. Because the accumulator and index registers can be set for either 8 or 16
  1651. bits independently, the width of the transfer is determined by the
  1652. destination register. The following table shows the possible combinations:
  1653. 8 bit acc to 8 bit index regs. (m=1,x=1) 8 bits transferred.
  1654. 8 bit acc,to 16 bit index regs (m=1, x=0), 16 bits are transferred.
  1655. The hidden high order accumulator byte becomes the
  1656. X or Y high byte.
  1657. 16 bit index regs to 8 bit acc (m=1, x=0), 8 bits are transferred.
  1658. The hidden high order accumulator byte is not
  1659. affected and the previous values remain.
  1660. 8 bit index regs to 16 bit acc (m=0, x=1), Two bytes
  1661. transferred with the high byte being zero.
  1662. 16 bit acc to 8 bit index regs (m=0, x=1), Only the low byte of the
  1663. accumulator is transferred to the index register.
  1664. 16 bit acc to 16 bit index regs (m=0, x=0) 16 bits transferred.
  1665. 16 bit stack pointer to 8 bit X register. Only the low byte
  1666. address is transferred.
  1667. 8 bit X reg to 16 bit stack pointer, sets stack high byte to zero.
  1668. Flags Affected: n-----z-
  1669. n Set if most significant bit of transfer value
  1670. is set.
  1671. z Set if transferred value is zero.
  1672. Addressing Mode Syntax Opcode Bytes Cycles
  1673. ----------------------------------------------------------------------
  1674. Implied TAX AA 1 2
  1675. Implied TAY A8 1 2
  1676. Implied TXA 8A 1 2
  1677. Implied TYA 98 1 2
  1678. Implied TSX BA 1 2
  1679. Implied TXS 9A 1 2
  1680. Implied TXY 9B 1 2
  1681. Implied TYX BB 1 2
  1682. ----------------------------------------------------------------------
  1683. Direct Page Instructions:
  1684. =========================
  1685. Two new 65816 instructions are used to exchange data between the
  1686. accumulator and the Direct Page Register.
  1687. TCD Transfer Accumulator to Direct Page Register.
  1688. TDC Transfer Direct Page Register to Accumulator.
  1689. TCD transfers a 16 bit value from the accumulator into the direct (zero
  1690. page) pointer. A full 16 bits is transferred regardless of the 16/8 bit
  1691. setting (m) of the accumulator.
  1692. The C in TCD is used to specify that the accumulator is referenced as C
  1693. when it is 16 bits wide (low byte being A and high byte being B).
  1694. TDC transfers from the Direct Page register into the full 16 bit
  1695. accumulator without regard for the setting of status bit m.
  1696. Some assemblers also allow TAD or TDA for the mnemonics.
  1697. Flags Affected: n-----z-
  1698. n Set if most significant bit of transfer value
  1699. is set.
  1700. z Set if transferred value is zero.
  1701. Addressing Mode Syntax Opcode Bytes Cycles
  1702. ----------------------------------------------------------------------
  1703. Implied TCD 5B 1 2
  1704. Alais: TAD
  1705. Implied TDC 7B 1 2
  1706. Alais: TDA
  1707. ----------------------------------------------------------------------
  1708. TCS Transfer Accumulator to Stack Pointer
  1709. TCS transfers a full 16 bits to the stack pointer without regard for the
  1710. setting of status bit m.
  1711. As with TCD and TDC the C in TCS refers to the accumulator as a full 16
  1712. bits.
  1713. The mnemonic TAS, transfer a to stack pointer, is used by some assemblers.
  1714. While in 6502 emulation mode only the eight-bit A accumulator value is
  1715. transferred because the stack is always located at page 1 on a 6502 TCS and
  1716. TXS are the only two instructions that alter the stack pointer register.
  1717. No flags are affected by TCS.
  1718. Addressing Mode Syntax Opcode Bytes Cycles
  1719. ----------------------------------------------------------------------
  1720. Implied TCS 1B 1 2
  1721. Alais: TAS
  1722. ----------------------------------------------------------------------
  1723. TSC Transfer Stack Pointer to Accumulator
  1724. TSC transfers a full 16 bits of the stack pointer to the 16 bit accumulator
  1725. without regard for the setting of status bit m.
  1726. As with TCD and TDC the C in TSC refers to the accumulator as a full 16
  1727. bits.
  1728. The mnemonic TSA, transfer a to stack pointer, is used by some assemblers.
  1729. While in 6502 emulation mode a one will be transferred to the hidden B
  1730. (upper 8 bits) accumulator because the stack is always located at page one
  1731. in 6502 mode.
  1732. Flags Affected: n-----z-
  1733. n Set if most significant bit of transfer value
  1734. is set.
  1735. z Set if transferred value is zero.
  1736. Addressing Mode Syntax Opcode Bytes Cycles
  1737. ----------------------------------------------------------------------
  1738. Implied TSC 3B 1 2
  1739. Alais: TSA
  1740. ----------------------------------------------------------------------
  1741. TRB Test and Reset Memory Bits
  1742. ------------------------------
  1743. TRB performs a logical AND of the accumulator's compliment and the
  1744. effective address - data is then rewritten back to the specified address.
  1745. This clears each memory bit that has a corresponding bit set in the
  1746. accumulator, leaving all other memory bits unchanged.
  1747. To put it another way - TRB flips or inverts the accumulator value and then
  1748. AND's that value with memory operand and stores the result back to the
  1749. effective address.
  1750. While is 16 bit accumulator mode (m=0) data is operated on in the expected
  1751. 16 bit fashion. The low byte of the operation is at the effective address
  1752. and the high byte at the effective address plus one.
  1753. Flags Affected: ------z-
  1754. z Set if memory value AND'ed with accumulator
  1755. value is zero.
  1756. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1757. ----------------------------------------------------------------------
  1758. Absolute TRB addr 1C 3 6 | 1
  1759. Direct Page TRB dp 14 2 5 | 1,2
  1760. ----------------------------------------------------------------------
  1761. 1 Add 2 cycles if 16 bit memory/accumulator mode (m=0)
  1762. 2 Add 1 cycle if direct page register low byte is <>0.
  1763. TSB Test and Set Memory Bits
  1764. ----------------------------
  1765. TSB logically OR's the accumulator and the data at the effective address.
  1766. This effectively sets a bit at the memory location for each bit set in the
  1767. accumulator.
  1768. While is 16 bit accumulator mode (m=0) data is operated on in the expected
  1769. 16 bit fashion. The low byte of the operation is at the effective address
  1770. and the high byte at the effective address plus one.
  1771. The status register zero flag is set after the accumulator is AND'd with
  1772. the memory value. (same as the BIT instruction).
  1773. Flags Affected: ------z-
  1774. z Set if memory value AND'ed with accumulator
  1775. value is zero.
  1776. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1777. ----------------------------------------------------------------------
  1778. Absolute TSB addr 0C 3 6 | 1
  1779. Direct Page TSB dp 04 2 5 | 1,2
  1780. ----------------------------------------------------------------------
  1781. 1 Add 2 cycles if 16 bit memory/accumulator mode (m=0)
  1782. 2 Add 1 cycle if direct page register low byte is <>0.
  1783. WAI Wait for Interrupt
  1784. ----------------------
  1785. WAI suspends operations until and external hardware interrupt is generated.
  1786. Power consumption by the processor is also reduced. If the disable
  1787. interrupt flag (i=1) is set and an IRQ is pending before the execution of
  1788. the WAI, then the WAIT is terminated and execution continues with the next
  1789. instruction.
  1790. No flags are affected by WAI.
  1791. Addressing Mode Syntax Opcode Bytes Cycles
  1792. ----------------------------------------------------------------------
  1793. Implied WAI CB 1 3
  1794. ----------------------------------------------------------------------
  1795. WDM Reserved for Future Expansion
  1796. ---------------------------------
  1797. WDM is the first byte of a multi-byte instruction set to be used in future
  1798. versions of the processor.
  1799. At current WDM is treated like a NOP no operation.
  1800. This instruction should NOT be used in current versions of the processor.
  1801. WDM: William D. Mensch, JR. (65816 designer).
  1802. Addressing Mode Syntax Opcode Bytes Cycles Ref
  1803. ----------------------------------------------------------------------
  1804. WDM 42 2
  1805. ----------------------------------------------------------------------
  1806. XBA Exchange B and A Accumulators
  1807. ---------------------------------
  1808. XBA exchanges the low eight bits of the accumulator (A) with the high order
  1809. 8 bits of the accumulator (B). This operation has no regard for the setting
  1810. of the status bit M.
  1811. This instruction will also work in 6502 emulation mode.
  1812. XBA can be used to save a temp copy of the low accumulator in the upper
  1813. accumulator. It is also good when in 16 bit mode to invert a low and high
  1814. byte value.
  1815. XBA is the only instruction that can access the upper 8 bits of the
  1816. accumulator in emulation mode.
  1817. Some assemblers will also accept SWA (swap) for a mnemonic.
  1818. Flags Affected: n------z-
  1819. n Set if the most significant bit of the new
  1820. value in the low order 8 bits (A) of the
  1821. accumulator is set. (former bit 15)
  1822. z Set if new value of the lower order 8 bit
  1823. accumulator (A) is zero.
  1824. Addressing Mode Syntax Opcode Bytes Cycles
  1825. ----------------------------------------------------------------------
  1826. Implied XBA EB 1 3
  1827. Alais: SWA
  1828. ----------------------------------------------------------------------
  1829. XCE Exchange Carry and Emulation Bits
  1830. -------------------------------------
  1831. XCE exchanges (swaps) the value in the E emulation bit and the C carry
  1832. flag. This is the only means to access the E emulation bit.
  1833. To set emulation mode:
  1834. sec ;set carry.
  1835. xce ;exchange carry and emulation bits.
  1836. To set native mode:
  1837. clc ;clear carry
  1838. xce ;exchange carry and e bit.
  1839. e
  1840. Flags Affected --mx/b---c
  1841. e from previous carry flag.
  1842. c from previous emulation flag.
  1843. m native mode flag only. switching to native
  1844. 65816 mode sets to one.
  1845. x x is a native mode flag only.
  1846. b brk is an emulation 6502 flag only. it is set
  1847. to 1 to become the x flag in native mode
  1848. Addressing Mode Syntax Opcode Bytes Cycles
  1849. ----------------------------------------------------------------------
  1850. Implied XCE FB 1 2
  1851. ----------------------------------------------------------------------
  1852. TOC
  1853. ------------------------------------------------------------------------
  1854. Appendix B:Composite Instruction List
  1855. ------------------------------------------------------------------------
  1856. ------------------------------------------------------------------------
  1857. Opcode Mnemonic Addressing Mode Bytes Cycles| Reference
  1858. =====================================================================
  1859. 00 BRK Stack/Interrupt 2** 7 | 9
  1860. 01 ORA DP Indexed Indirect,X 2 6 | 1,2
  1861. 02 COP Stack/Interrupt 2** 7 | 9
  1862. 03 ORA Stack Relative 2 4 | 1
  1863. 04 TSB Direct Page 2 5 | 2,5
  1864. 05 ORA Direct Page 2 3 | 1,2
  1865. 06 ASL Direct Page 2 5 | 2,5
  1866. 07 ORA Direct Page Indirect Long 2 6 | 1,2
  1867. 08 PHP Stack (Push) 1 3 |
  1868. 09 ORA Immediate 2* 2 | 1
  1869. 0A ASL Accumulator 1 2 |
  1870. 0B PHD Stack (Push) 1 4 |
  1871. 0C TSB Absolute 3 6 | 5
  1872. 0D ORA Absolute 3 4 | 1
  1873. 0E ASL Absolute 3 6 | 5
  1874. 0F ORA Absolute Long 4 5 | 1
  1875. 10 BPL Program Counter Relative 2 2 | 7,8
  1876. 11 ORA DP Indirect Indexed,Y 2 5 | 1,2,3
  1877. 12 ORA Direct Page Indirect 2 5 | 1,2
  1878. 13 ORA SR Indirect Indexed,Y 2 7 | 1
  1879. 14 TRB Direct Page 2 5 | 2,5
  1880. 15 ORA Direct Page Indexed,X 2 4 | 1,2
  1881. 16 ASL Direct Page Indexed,X 2 6 | 2,5
  1882. 17 ORA DP Indirect Long Indexed,Y 2 6 | 1,2
  1883. 18 CLC Implied 1 2 |
  1884. 19 ORA Absolute Indexed,Y 3 4 | 1,3
  1885. 1A INC Accumulator (INA) 1 2 |
  1886. 1B TCS Implied 1 2 |
  1887. 1C TRB Absolute 3 6 | 5
  1888. 1D ORA Absolute Indexed,X 3 4 | 1,3
  1889. 1E ASL Absolute Indexed,X 3 7 | 5,6
  1890. 1F ORA Absolute Long Indexed,X 4 5 | 1
  1891. 20 JSR Absolute 3 6 |
  1892. 21 AND DP Indexed Indirect,X 2 6 | 1,2
  1893. 22 JSR Absolute Long 4 8 |
  1894. 23 AND Stack Relative 2 4 | 1
  1895. 24 BIT Direct Page 2 3 | 1,2
  1896. 25 AND Direct Page 2 3 | 1,2
  1897. 26 ROL Direct Page 2 5 | 2,5
  1898. 27 AND Direct Page Indirect Long 2 6 | 1,2
  1899. 28 PLP Stack (Pull) 1 4 |
  1900. 29 AND Immediate 2* 2 | 1
  1901. 2A ROL Accumulator 1 2 |
  1902. 2B PLD Stack (Pull) 1 5 |
  1903. 2C BIT Absolute 3 4 | 1
  1904. 2D AND Absolute 3 4 | 1
  1905. 2E ROL Absolute 3 6 | 5
  1906. 2F AND Absolute Long 4 5 | 1
  1907. 30 BMI Program Counter Relative 2 2 | 7,8
  1908. 31 AND DP Indirect Indexed,Y 2 5 | 1,2,3
  1909. 32 AND Direct Page Indirect 2 5 | 1,1
  1910. 33 AND SR Indirect Indexed,Y 2 7 | 1
  1911. 34 BIT Direct Page Indexed,X 2 4 | 1,2
  1912. 35 AND Direct Page Indexed,X 2 4 | 1,2
  1913. 36 ROL Direct Page Indexed,X 2 6 | 2,5
  1914. 37 AND DP Indirect Long Indexed,Y 2 6 | 1,2
  1915. 38 SEC Implied 1 2 |
  1916. 39 AND Absolute Indexed,Y 3 4 | 1,3
  1917. 3A DEC Accumulator 1 2 |
  1918. 3B TSC Implied 1 2 |
  1919. 3C BIT Absolute Indexed,X 3 4 | 1,3
  1920. 3D AND Absolute Indexed,X 3 4 | 1,3
  1921. 3E ROL Absolute Indexed,X 3 7 | 5,6
  1922. 3F AND Absolute Long Indexed,X 4 5 | 1
  1923. 40 RTI Stack/RTI 1 6 | 9
  1924. 41 EOR DP Indexed Indirect,X 2 6 | 1,2
  1925. 42 WDM 2|16 |
  1926. 43 EOR Stack Relative 2 4 | 1
  1927. 44 MVP Block Move 3 | 13
  1928. 45 EOR Direct Page 2 3 | 1,2
  1929. 46 LSR Direct Page 2 5 | 2,5
  1930. 47 EOR Direct Page Indirect Long 2 6 | 1,2
  1931. 48 PHA Stack (Push) 1 3 | 1
  1932. 49 EOR Immediate 2* 2 | 1
  1933. 4A LSR Accumulator 1 2 |
  1934. 4B PHK Stack (Push) 1 3 |
  1935. 4C JMP Absolute 3 3 |
  1936. 4D EOR Absolute 3 4 | 1
  1937. 4E LSR Absolute 3 6 | 5
  1938. 4F EOR Absolute Long 4 5 | 1
  1939. 50 BVC Program Counter Relative 2 2 | 7,8
  1940. 51 EOR DP Indirect Indexed,Y 2 5 | 1,2,3
  1941. 52 EOR Direct Page Indirect 2 5 | 1,2
  1942. 53 EOR SR Indirect Indexed,Y 2 7 | 1
  1943. 54 MVN Block Move 3 | 13
  1944. 55 EOR Direct Page Indexed,X 2 4 | 1,2
  1945. 56 LSR Direct Page Indexed,X 2 6 | 2,5
  1946. 57 EOR DP Indirect Long Indexed,Y 2 6 | 1,2
  1947. 58 CLI Implied 1 2 |
  1948. 59 EOR Absolute Indexed,Y 3 4 | 1,3
  1949. 5A PHY Stack (Push) 1 3 | 10
  1950. 5B TCD Implied 1 2 |
  1951. 5C JMP Absolute Long 4 4 |
  1952. 5D EOR Absolute Indexed,X 3 4 | 1,3
  1953. 5E LSR Absolute Indexed,X 3 7 | 5,6
  1954. 5F EOR Absolute Long Indexed,X 4 5 | 1
  1955. 60 RTS Stack (RTS) 1 6 |
  1956. 61 ADC DP Indexed Indirect,X 2 6 | 1,2,4
  1957. 62 PER Stack (PC Relative Long) 3 6 |
  1958. 63 ADC Stack Relative 2 4 | 1,4
  1959. 64 STZ Direct Page 2 3 | 1,2
  1960. 65 ADC Direct Page 2 3 | 1,2,4
  1961. 66 ROR Direct Page 2 5 | 1
  1962. 67 ADC Direct Page Indirect Long 2 6 | 1,4
  1963. 68 PLA Stack (Pull) 1 4 | 1
  1964. 69 ADC Immediate 2* 2 | 1,4
  1965. 6A ROR Accumulator 1 2 |
  1966. 6B RTL Stack (RTL) 1 6 |
  1967. 6C JMP Absolute Indirect 3 5 | 11,12
  1968. 6D ADC Absolute 3 4 | 1,4
  1969. 6E ROR Absolute 3 6 | 5
  1970. 6F ADC Absolute Long 4 5 | 1,4
  1971. 70 BVS Program Counter Relative 2 2 | 7,8
  1972. 71 ADC DP Indirect Indexed,Y 2 5 | 1,2,3,4
  1973. 72 ADC Direct Page Indirect 2 5 | 1,2,4
  1974. 73 ADC SR Indirect Indexed,Y 2 7 | 1,4
  1975. 74 STZ Direct Page Indexed,X 2 4 | 1,2
  1976. 75 ADC Direct Page Indexed,X 2 4 | 1,2,4
  1977. 76 ROR Direct Page Indexed,X 2 6 | 2,5
  1978. 77 ADC DP Indirect Long Indexed,Y 2 6 | 1,2,4
  1979. 78 SEI Implied 1 2 |
  1980. 79 ADC Absolute Indexed,Y 3 4 | 1,3,4
  1981. 7A PLY Stack (Pull) 1 4 | 10
  1982. 7B TDC Implied 1 2 |
  1983. 7C JMP Absolute Indexed Indirect 3 6 |
  1984. 7D ADC Absolute Indexed,X 3 4 | 1,3,4
  1985. 7E ROR Absolute Indexed,X 3 7 | 5,6
  1986. 7F ADC Absolute Long Indexed,X 4 5 | 1,4
  1987. 80 BRA Program Counter Relative 2 3 | 8
  1988. 81 STA DP Indexed Indirect,X 2 6 | 1,2
  1989. 82 BRL Program Counter Relative Long 3 4 |
  1990. 83 STA Stack Relative 2 4 | 1
  1991. 84 STY Direct Page 2 3 | 2,10
  1992. 85 STA Direct Page 2 3 | 1,2
  1993. 86 STX Direct Page 2 3 | 2,10
  1994. 87 STA Direct Page Indirect Long 2 6 | 1,2
  1995. 88 DEY Implied 1 2 |
  1996. 89 BIT Immediate 2* 2 | 1
  1997. 8A TXA Implied 1 2 |
  1998. 8B PHB Stack (Push) 1 3 |
  1999. 8C STY Absolute 3 4 | 10
  2000. 8D STA Absolute 3 4 | 1
  2001. 8E STX Absolute 3 4 | 10
  2002. 8F STA Absolute Long 4 5 | 1
  2003. 90 BCC Program Counter Relative 2 2 | 7,8
  2004. 91 STA DP Indirect Indexed,Y 2 6 | 1,2
  2005. 92 STA Direct Page Indirect 2 5 | 1,2
  2006. 93 STA SR Indirect Indexed,Y 2 7 | 1
  2007. 94 STY Direct Page Indexed,X 2 4 | 2,10
  2008. 95 STA Direct Page Indexed,X 2 4 | 1,2
  2009. 96 STX Direct Page Indexed,Y 2 4 | 2,10
  2010. 97 STA DP Indirect Long Indexed,Y 2 6 | 1,2
  2011. 98 TYA Implied 1 2 |
  2012. 99 STA Absolute Indexed,Y 3 5 | 1
  2013. 9A TXS Implied 1 2 |
  2014. 9B TXY Implied 1 2 |
  2015. 9C STZ Absolute 3 4 | 1
  2016. 9D STA Absolute Indexed,X 3 5 | 1
  2017. 9E STZ Absolute Indexed,X 3 5 | 1
  2018. 9F STA Absolute Long Indexed,X 4 5 | 1
  2019. A0 LDY Immediate 2+ 2 | 10
  2020. A1 LDA DP Indexed Indirect,X 2 6 | 1,2
  2021. A2 LDX Immediate 2+ 2 | 10
  2022. A3 LDA Stack Relative 2 4 | 1
  2023. A4 LDY Direct Page 2 3 | 2,10
  2024. A5 LDA Direct Page 2 3 | 1,2
  2025. A6 LDX Direct Page 2 3 | 2,10
  2026. A7 LDA Direct Page Indirect Long 2 6 | 1,2
  2027. A8 TAY Implied 1 2 |
  2028. A9 LDA Immediate 2* 2 | 1
  2029. AA TAX Implied 1 2 |
  2030. AB PLB Stack (Pull) 1 4 |
  2031. AC LDY Absolute 3 4 | 10
  2032. AD LDA Absolute 3 4 | 1
  2033. AE LDX Absolute 3 4 | 10
  2034. AF LDA Absolute Long 4 5 | 1
  2035. B0 BCS Program Counter Relative 2 2 | 7,8
  2036. B1 LDA DP Indirect Indexed,Y 2 5 | 1,2,3
  2037. B2 LDA Direct Page Indirect 2 5 | 1,2
  2038. B3 LDA SR Indirect Indexed,Y 2 7 | 1
  2039. B4 LDY Direct Page Indexed,X 2 4 | 2,10
  2040. B5 LDA Direct Page Indexed,X 2 4 | 1,2
  2041. B6 LDX DP Indexed,Y 2 4 | 2,10
  2042. B7 LDA DP Indirect Long Indexed,Y 2 6 | 1,2
  2043. B8 CLV Implied 1 2 |
  2044. B9 LDA Absolute Indexed,Y 3 4 | 1,3
  2045. BA TSX Implied 1 2 |
  2046. BB TYX Implied 1 2 |
  2047. BC LDY Absolute Indexed,X 3 4 | 3,10
  2048. BD LDA Absolute Indexed,X 3 4 | 1,3
  2049. BE LDX Absolute Indexed,Y 3 4 | 3,10
  2050. BF LDA Absolute Long Indexed,X 4 5 | 1
  2051. C0 CPY Immediate 2+ 2 | 10
  2052. C1 CMP DP Indexed Indirect,X 2 6 | 1,2
  2053. C2 REP Immediate 2 3 |
  2054. C3 CMP Stack Relative 2 4 | 1
  2055. C4 CPY Direct Page 2 3 | 2,10
  2056. C5 CMP Direct Page 2 3 | 1,2
  2057. C6 DEC Direct Page 2 5 | 2,5
  2058. C7 CMP Direct Page Indirect Long 2 6 | 1,2
  2059. C8 INY Implied 1 2 |
  2060. C9 CMP Immediate 2* 2 | 1
  2061. CA DEX Implied 1 2 |
  2062. CB WAI Implied 1 3 | 15
  2063. CC CPY Absolute 3 4 | 10
  2064. CD CMP Absolute 3 4 | 1
  2065. CE DEC Absolute 3 6 | 5
  2066. CF CMP Absolute Long 4 5 | 1
  2067. D0 BNE Program Counter Relative 2 2 | 7,8
  2068. D1 CMP DP Indirect Indexed,Y 2 5 | 1,2,3
  2069. D2 CMP Direct Page Indirect 2 5 | 1,2
  2070. D3 CMP SR Indirect Indexed,Y 2 7 | 1
  2071. D4 PEI Stack (Direct Page Indirect) 2 6 | 2
  2072. D5 CMP Direct Page Indexed,X 2 4 | 1,2
  2073. D6 DEC Direct Page Indexed,X 2 6 | 2,5
  2074. D7 CMP DP Indirect Long Indexed,Y 2 6 | 1,2
  2075. D8 CLD Implied 1 2 |
  2076. D9 CMP Absolute Indexed,Y 3 4 | 1,3
  2077. DA PHX Stack (Push) 1 3 | 10
  2078. DB STP Implied 1 3 | 14
  2079. DC JMP Absolute Indirect Long 3 6 |
  2080. DD CMP Absolute Indexed,X 3 4 | 1,3
  2081. DE DEC Absolute Indexed,X 3 7 | 5,6
  2082. DF CMP Absolute Long Indexed,X 4 5 | 1
  2083. E0 CPX Immediate 2+ 2 | 10
  2084. E1 SBC DP Indexed Indirect,X 2 6 | 1,2,4
  2085. E2 SEP Immediate 2 3 |
  2086. E3 SBC Stack Relative 2 4 | 1,4
  2087. E4 CPX Direct Page 2 3 | 2,10
  2088. E5 SBC Direct Page 2 3 | 1,2,4
  2089. E6 INC Direct Page 2 5 |
  2090. E7 SBC Direct Page Indirect Long 2 6 | 1,2,4
  2091. E8 INX Implied 1 2 |
  2092. E9 SBC Immediate 2* 2 |
  2093. EA NOP Implied 1 2 |
  2094. EB XBA Implied 1 3 |
  2095. EC CPX Absolute 3 4 | 10
  2096. ED SBC Absolute 3 4 | 1,4
  2097. EE INC Absolute 3 6 | 5
  2098. EF SBC Absolute Long 4 5 | 1,4
  2099. F0 BEQ Program Counter Relative 2 2 | 7,8
  2100. F1 SBC DP Indirect Indexed,Y 2 5 | 1,2,3,4
  2101. F2 SBC Direct Page Indirect 2 5 | 1,2,4
  2102. F3 SBC SR Indirect Indexed,Y 2 7 | 1,4
  2103. F4 PEA Stack (Absolute) 3 5 |
  2104. F5 SBC Direct Page Indexed,X 2 4 | 1,2,4
  2105. F6 INC Direct Page Indexed,X 2 6 | 2,5
  2106. F7 SBC DP Indirect Long Indexed,Y 2 6 | 1,2,4
  2107. F8 SED Implied 1 2 |
  2108. F9 SBC Absolute Indexed,Y 3 4 | 1,3,4
  2109. FA PLX Stack (Pull) 1 4 | 10
  2110. FB XCE Implied 1 2 |
  2111. FC JSR Absolute Indexed Indirect 3 8 |
  2112. FD SBC Absolute Indexed,X 3 4 | 1,3,4
  2113. FE INC Absolute Indexed,X 3 7 | 5,6
  2114. FF SBC Absolute Long Indexed,X 4 5 | 1,4
  2115. =====================================================================
  2116. * Add 1 if m=0 (16 bit memory/accumulator).
  2117. ** Opcode is 1 byte, but program counter value pushed onto stack is
  2118. incremented by 2 allowing for optional signature byte.
  2119. + Add 1 byte if x=0 (16-bit index registers).
  2120. 1 Add 1 cycle if m=0 (16-bit memory/accumulator).
  2121. 2 Add 1 cycle if low bye of Direct Page (zero page) register
  2122. is other than zero (DL<>0).
  2123. 3 Add 1 cycle if adding index crosses a page boundary.
  2124. 4 Add 1 cycle if CPU is 65C02 and d=1 (decimal mode. 65C02 only).
  2125. 5 Add 2 cycles if m=0 (16-bit memory/accumulator).
  2126. 6 Subtract 1 cycle if CPU is 65C02 and no page boundary crossed.
  2127. 7 Add 1 cycle if branch is taken.
  2128. 8 Add 1 more cycle if branch taken crosses page boundary on 6502,
  2129. 65C02, or 65816/65082's emulation mode (e=1).
  2130. 9 Add 1 cycle for 65802/65816 native mode (e=0).
  2131. 10 Add 1 cycle if x=0 (16-bit index registers).
  2132. 11 Add 1 cycle if CPU is 65C02.
  2133. 12 6502: if low byte of operand is $FF (ie. operand is $xxFF): yields
  2134. incorrect result.
  2135. 13 7 cycles per byte moved.
  2136. 14 Uses 3 cycles to shut the processor down; additional cycles are
  2137. required by reset to restart CPU.
  2138. 15 Uses 3 cycles to shut the processor down; additional cycles are
  2139. required by interrupt to restart it.
  2140. 16 Byte and cycle counts subject to change in future processors which
  2141. expand WDM into 2-byte opcode portions of instructions of varying
  2142. lengths.
  2143. TOC
  2144. ------------------------------------------------------------------------
  2145. ========================================================================
  2146. ------------------------------------------------------------------------
  2147. =====================
  2148. Appendix C: IC Pinouts
  2149. =====================
  2150. /=============\ /=============\
  2151. VP I1 40I RES Vss I1 40I RES
  2152. RDY I2 39I VDA RDY I2 39I o2 (OUT)
  2153. ABORT I3 38I M/X o1 (OUT) I3 38I SO
  2154. IRQ I4 37I o2 (IN) IRQ I4 37I o2 (IN)
  2155. ML I5 36I BE NC I5 36I NC
  2156. NMI I6 35I E NMI I6 35I NC
  2157. VPA I7 34I R/W SYNC I7 34I R/W
  2158. VDD I8 33I D0/BA0 Vdd I8 33I D0
  2159. A0 I9 W65C816 32I D1/BA1 A0 I9 6502 32I D1
  2160. A1 I10 31I D2/BA2 A1 I10 31I D2
  2161. A2 I11 30I D3/BA3 A2 I11 30I D3
  2162. A3 I12 29I D4/BA4 A3 I12 29I D4
  2163. A4 I13 28I D5/BA5 A4 I13 28I D5
  2164. A5 I14 27I D6/BA6 A5 I14 27I D6
  2165. A6 I15 26I D7/BA7 A6 I15 26I D7
  2166. A7 I16 25I A15 A7 I16 25I A15
  2167. A8 I17 24I A14 A8 I17 24I A14
  2168. A9 I18 23I A13 A9 I18 23I A13
  2169. A10 I19 22I A12 A10 I19 22I A12
  2170. A11 I20 21I Vss A11 I20 21I Vss
  2171. \=============/ \=============/
  2172. Notes:
  2173. ML: Memory Lock line (pin 5) is asserted low during the execution of
  2174. the read-modify-write (asl,dec,inc,lsr,rol,ror,trb, and tsb
  2175. instructions to inform other ics that the bus may not be claimed
  2176. yet.
  2177. VP: Vector Pull is asserted whenever any of the hardware vector
  2178. address's are being accessed during an IRQ.
  2179. Abort: An input. When asserted caused the current instruction to be
  2180. aborted.
  2181. VPA/VDA. Valid Program Address and Valid Data Address. These two
  2182. signals extend on the 6502 SYNC line - to better handle
  2183. DMA schemes.
  2184. VPA VDA
  2185. 0 0 -Internal Operation
  2186. 0 1 -Valid program address
  2187. 1 0 -Valid data address
  2188. 1 1 -Opcode fetch
  2189. M/X: Memory and Index lines. These signals are multiplexed on pin
  2190. 38. M is available during phase zero and X during Phase one.
  2191. These two signals reflect the contents of the status register
  2192. m and x flags, allowing other devices to decode opcode fetches.
  2193. E: Emulation pin. This signal reflects the state of the processors
  2194. emulation bit (E).
  2195. TOC
  2196. ------------------------------------------------------------------------
  2197. ===================================================================
  2198. 44 PIN PLCC Pinout.
  2199. A
  2200. B
  2201. O R 0
  2202. M I R R V V E V M 2
  2203. L R T D P S S D / I B
  2204. B Q B Y B S B A X N E
  2205. /----I---I---I---I---I---I---I---I---I---I-\
  2206. / 6 5 4 3 2 1 44 43 42 41 40 I
  2207. NMIB I 7 39 - E
  2208. VPA I 8 38 - R/WB
  2209. VDD I 9 37 - VDD
  2210. A0 I 10 36 - D0/BA0
  2211. A1 I 11 35 - D1/BA1
  2212. VSS I 12 W65C816S 34 - D2/BA2
  2213. A2 I 13 33 - D3/BA3
  2214. A3 I 14 32 - D4/BA4
  2215. A4 I 15 31 - D5/BA5
  2216. A5 I 16 30 - D6/BA6
  2217. A6 I 17 29 - D7/BA7
  2218. I 18 19 20 21 22 23 24 25 26 27 28 I
  2219. \--l---l---l---l---l---l---l---l---l---l---l-/
  2220. A A A A A V V A A A A
  2221. 7 8 9 1 1 S S 1 1 1 1
  2222. 0 1 S S 2 3 4 5
  2223. 44 pin W65C816S PLCC Pinout
  2224. TOC
  2225. -----------------------------------------------------
  2226. Send Email
  2227. Last updated on: Tuesday, 23-Dec-1997 23:51:46 CST 92