Advertisement
iocoder

cpu.s

Jan 20th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.92 KB | None | 0 0
  1. #
  2. # +----------------------------------------------------------+
  3. # | +------------------------------------------------------+ |
  4. # | | NES Over MIPS Emulator. | |
  5. # | | -> 6502 CPU Emulation Code. | |
  6. # | +------------------------------------------------------+ |
  7. # +----------------------------------------------------------+
  8. #
  9. # This file is part of Quafios 2.0.1 source code.
  10. # Copyright (C) 2016 Mostafa Abd El-Aziz Mohamed.
  11. #
  12. # This program is free software: you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation, either version 3 of the License, or
  15. # (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with Quafios. If not, see <http://www.gnu.org/licenses/>.
  24. #
  25. # Visit http://www.quafios.com/ for contact information.
  26. #
  27.  
  28. .include "common.inc"
  29. .global cpu_cycle, reset, instr
  30. .set debug_enabled, 0
  31. .set count_enabled, 0
  32.  
  33. ## REGISTER MAP:
  34. ## -------------
  35. ## s0: pc
  36. ## s1: a
  37. ## s2: x
  38. ## s3: y
  39. ## s4: p
  40. ## s6: mar
  41. ## s7: s
  42. ## s5: base1
  43. ## s8: base2
  44. ## t6: '1'
  45. ## t5: &read_instr
  46.  
  47. # set zero/negative flags macro
  48. .macro zeron reg
  49. andi $s4, $s4, 0x7D
  50. sltu $t2, \reg, $t6 # t2 = reg<1 ? 1:0
  51. sll $t2, $t2, 1
  52. or $s4, $s4, $t2
  53. andi $t2, \reg, 0x80
  54. or $s4, $s4, $t2
  55. .endm
  56.  
  57. ###################################################
  58. # SECTION: TEXT #
  59. ###################################################
  60.  
  61. .text
  62.  
  63. ################################################
  64. # cpu_cycle #
  65. # ---------------------------------------------#
  66. # Summary: CPU cycle begins here. #
  67. # ---------------------------------------------#
  68. # Called by: <entry> or <instr> #
  69. # ---------------------------------------------#
  70. # Next call: <isr>, debug, or fetch #
  71. ################################################
  72.  
  73. cpu_cycle:
  74. # next three lines are used to count no. of instr. per loop
  75. .if count_enabled
  76. lui $t0, 0x1E00
  77. ori $t1, $0, 1
  78. sh $t1, 0xFF8*2($t0)
  79. .endif
  80. # reset?
  81. # j reset
  82. # NMI?
  83. # j nmi
  84. # interrupt, interrupts enabled?
  85. # j irq
  86. # debug?
  87. .if debug_enabled
  88. j debug
  89. .endif
  90. # none of the above, just fetch next instruction
  91.  
  92. ################################################
  93. # fetch #
  94. # ---------------------------------------------#
  95. # Summary: Fetch next instruction and increase #
  96. # PC register by 1. #
  97. # ---------------------------------------------#
  98. # Called by: cpu_cycle or <isr> #
  99. # ---------------------------------------------#
  100. # Next call: <address> #
  101. ################################################
  102.  
  103. # note: fetch must follow cpu_cycle routine code.
  104.  
  105. fetch:
  106. # fetch opcode
  107. move $a0, $s0
  108. addiu $s0, $s0, 1
  109. jalr $t5
  110. # jump to addressing mode routine
  111. sll $v0, $v0, 3
  112. addu $v0, $v0, $s5
  113. lw $t2, %lo(__instr)+4($v0)
  114. lw $t3, %lo(__instr)($v0) # placed in delay slot of jr
  115. jr $t2
  116.  
  117. ################################################
  118. # reset #
  119. # ---------------------------------------------#
  120. # Summary: CPU RESET procedure. #
  121. # ---------------------------------------------#
  122. # Called by: cpu_cycle #
  123. # ---------------------------------------------#
  124. # Next call: fetch #
  125. ################################################
  126.  
  127. reset:
  128. # initialize reserved registers
  129. lui $s5, %hi(base1)
  130. addiu $s5, $s5, %lo(base1)
  131. lui $s8, %hi(base2)
  132. addiu $s8, $s8, %lo(base2)
  133. ori $t6, $0, 1
  134. lui $t5, %hi(rom_instr)
  135. addiu $t5, $t5, %lo(rom_instr)
  136. # read reset vector [PC=ROM[0xFFFC]+(ROM[0xFFFD]<<8)]
  137. ori $a0, $0, 0xFFFC
  138. jal mem_read
  139. move $s0, $v0
  140. ori $a0, $0, 0xFFFD
  141. jal mem_read
  142. sll $v0, $v0, 8
  143. addu $s0, $s0, $v0
  144. j fetch
  145.  
  146. ################################################
  147. # debug #
  148. # ---------------------------------------------#
  149. # Summary: Print CPU state and disassemble #
  150. # running instructions for debugging. #
  151. # ---------------------------------------------#
  152. # Called by: cpu_cycle #
  153. # ---------------------------------------------#
  154. # Next call: fetch #
  155. ################################################
  156.  
  157. .if debug_enabled
  158. debug:
  159. # print cpu state if debugging is enabled
  160. pusha
  161. lui $t0, %hi(cur_step)
  162. lw $t1, %lo(cur_step)($t0)
  163. beq $t1, $0, 1f
  164. ls $a0, "| MAR=$%4x | A=$%2x, X=$%2x, "
  165. move $a1, $s6
  166. move $a2, $s1
  167. move $a3, $s2
  168. bios printf
  169. ls $a0, "Y=$%2x, S=$%2x, P=$%2x\n"
  170. move $a1, $s3
  171. move $a2, $s7
  172. move $a3, $s4
  173. bios printf
  174. #bios getc
  175. # enough simulation for today?
  176. 1: lui $t0, 0x0000
  177. ori $t0, $t0, 0x8000
  178. bne $t0, $t1, 2f
  179. j .
  180. # get instruction name
  181. 2: move $a0, $s0
  182. jal mem_read
  183. lui $t0, %hi(str)
  184. sll $t1, $v0, 3
  185. addu $t0, $t0, $t1
  186. lw $a2, %lo(str)($t0)
  187. lw $t2, %lo(str)+4($t0)
  188. # PC shall be printed, too.
  189. move $a1, $s0
  190. # load format string
  191. ls $a0, "$%4x | %s "
  192. # now print
  193. bios printf
  194. # load two bytes following PC
  195. addiu $a0, $s0, 1
  196. jal mem_read
  197. move $t1, $v0
  198. addiu $a0, $s0, 2
  199. jal mem_read
  200. move $a2, $t1
  201. move $a1, $v0
  202. # get format string for addressing mode
  203. move $a0, $t2
  204. # now print
  205. bios printf
  206. # increase cur_step
  207. lui $t0, %hi(cur_step)
  208. lw $t1, %lo(cur_step)($t0)
  209. addiu $t1, $t1, 1
  210. sw $t1, %lo(cur_step)($t0)
  211. popa
  212. j fetch
  213. .endif
  214.  
  215. ################################################
  216. # imm #
  217. # ---------------------------------------------#
  218. # Summary: Immediate addressing mode. #
  219. # ---------------------------------------------#
  220. # Called by: fetch #
  221. # ---------------------------------------------#
  222. # Next call: <instr> #
  223. ################################################
  224.  
  225. imm:
  226. # immediate
  227. move $v0, $v1
  228. addiu $s0, $s0, 1
  229. # jump to instruction code
  230. jr $t3
  231.  
  232. ################################################
  233. # abs #
  234. # ---------------------------------------------#
  235. # Summary: Absolute addressing mode. #
  236. # ---------------------------------------------#
  237. # Called by: fetch #
  238. # ---------------------------------------------#
  239. # Next call: <instr> #
  240. ################################################
  241.  
  242. abs:
  243. # absolute address
  244. addiu $s0, $s0, 2
  245. move $s6, $a1
  246. # jump to instruction code
  247. jr $t3
  248.  
  249. ################################################
  250. # zp #
  251. # ---------------------------------------------#
  252. # Summary: Zero page addressing mode. #
  253. # ---------------------------------------------#
  254. # Called by: fetch #
  255. # ---------------------------------------------#
  256. # Next call: <instr> #
  257. ################################################
  258.  
  259. zp:
  260. # zero page address
  261. move $s6, $v1
  262. addiu $s0, $s0, 1
  263. # jump to instruction code
  264. jr $t3
  265.  
  266. ################################################
  267. # acc #
  268. # ---------------------------------------------#
  269. # Summary: Accumulator addressing mode. #
  270. # ---------------------------------------------#
  271. # Called by: fetch #
  272. # ---------------------------------------------#
  273. # Next call: <instr> #
  274. ################################################
  275.  
  276. acc:
  277. # accumulator
  278. addiu $s6, $0, -1
  279. move $v0, $s1
  280. # jump to instruction code
  281. jr $t3
  282.  
  283. ################################################
  284. # imp #
  285. # ---------------------------------------------#
  286. # Summary: Implied addressing mode. #
  287. # ---------------------------------------------#
  288. # Called by: fetch #
  289. # ---------------------------------------------#
  290. # Next call: <instr> #
  291. ################################################
  292.  
  293. imp:
  294. # implied addressing
  295. nop
  296. # jump to instruction code
  297. jr $t3
  298.  
  299. ################################################
  300. # idir #
  301. # ---------------------------------------------#
  302. # Summary: Indexed indirect addressing mode. #
  303. # ---------------------------------------------#
  304. # Called by: fetch #
  305. # ---------------------------------------------#
  306. # Next call: <instr> #
  307. ################################################
  308.  
  309. idir:
  310. # indexed indirect (ind, x)
  311. addiu $s0, $s0, 1
  312. # v1 contains second byte of instruction. Add to X.
  313. addu $v1, $v1, $s2
  314. andi $a0, $v1, 0xFF
  315. # now a0 points to a memory location in page zero holding the address
  316. jal ram_read2
  317. move $s6, $v0
  318. # jump to instruction code
  319. jr $t3
  320.  
  321. ################################################
  322. # dind #
  323. # ---------------------------------------------#
  324. # Summary: Indirect indexed addressing mode. #
  325. # ---------------------------------------------#
  326. # Called by: fetch #
  327. # ---------------------------------------------#
  328. # Next call: <instr> #
  329. ################################################
  330.  
  331. dind:
  332. # indirect indexed (ind), Y
  333. addiu $s0, $s0, 1
  334. # v1 contains second byte of instruction. This byte points
  335. # to a memory location in page zero holding the base address.
  336. move $a0, $v1
  337. jal ram_read2
  338. # add Y, store in MAR
  339. addu $s6, $v0, $s3
  340. # jump to instruction code
  341. jr $t3
  342.  
  343. ################################################
  344. # izx #
  345. # ---------------------------------------------#
  346. # Summary: X-indexed zero page addressing #
  347. # mode. #
  348. # ---------------------------------------------#
  349. # Called by: fetch #
  350. # ---------------------------------------------#
  351. # Next call: <instr> #
  352. ################################################
  353.  
  354. izx:
  355. # zero page indexed by X 'zr, X'
  356. addiu $s0, $s0, 1
  357. addu $s6, $s2, $v1
  358. andi $s6, $s6, 0xFF
  359. # jump to instruction code
  360. jr $t3
  361.  
  362. ################################################
  363. # iax #
  364. # ---------------------------------------------#
  365. # Summary: X-indexed absolute addressing mode. #
  366. # ---------------------------------------------#
  367. # Called by: fetch #
  368. # ---------------------------------------------#
  369. # Next call: <instr> #
  370. ################################################
  371.  
  372. iax:
  373. # indexed absolute X 'Abs, X'
  374. addiu $s0, $s0, 2
  375. addu $s6, $a1, $s2
  376. andi $s6, $s6, 0xFFFF
  377. # jump to instruction code
  378. jr $t3
  379.  
  380. ################################################
  381. # iay #
  382. # ---------------------------------------------#
  383. # Summary: Y-indexed absolute addressing mode. #
  384. # ---------------------------------------------#
  385. # Called by: fetch #
  386. # ---------------------------------------------#
  387. # Next call: <instr> #
  388. ################################################
  389.  
  390. iay:
  391. # indexed absolute Y 'Abs, Y'
  392. addiu $s0, $s0, 2
  393. addu $s6, $a1, $s3
  394. andi $s6, $s6, 0xFFFF
  395. # jump to instruction code
  396. jr $t3
  397.  
  398. ################################################
  399. # rel #
  400. # ---------------------------------------------#
  401. # Summary: Relative addressing mode. #
  402. # ---------------------------------------------#
  403. # Called by: fetch #
  404. # ---------------------------------------------#
  405. # Next call: <instr> #
  406. ################################################
  407.  
  408. rel:
  409. # relative addressing
  410. # v1 contains second byte of instruction. sign extend the byte
  411. sll $v1, $v1, 24
  412. sra $v1, $v1, 24
  413. andi $v1, $v1, 0xFFFF
  414. addu $s0, $s0, $v1
  415. # next cycle
  416. j cpu_cycle
  417.  
  418. ################################################
  419. # absd #
  420. # ---------------------------------------------#
  421. # Summary: Absolute indirect addressing mode. #
  422. # ---------------------------------------------#
  423. # Called by: fetch #
  424. # ---------------------------------------------#
  425. # Next call: <instr> #
  426. ################################################
  427.  
  428. absd:
  429. # absolute indirect
  430. addiu $s0, $s0, 2
  431. move $a0, $a1
  432. jal mem_read2
  433. # only one instruction is absd: jmp
  434. move $s6, $v0
  435. jr $t3
  436.  
  437. ################################################
  438. # izy #
  439. # ---------------------------------------------#
  440. # Summary: Y-indexed zero page addressing #
  441. # mode. #
  442. # ---------------------------------------------#
  443. # Called by: fetch #
  444. # ---------------------------------------------#
  445. # Next call: <instr> #
  446. ################################################
  447.  
  448. izy:
  449. # zero page indexed by Y 'zr, Y'
  450. addiu $s0, $s0, 1
  451. addu $s6, $s3, $v1
  452. andi $s6, $s6, 0xFF
  453. # jump to instruction code
  454. jr $t3
  455.  
  456. ################################################
  457. # adc #
  458. # ---------------------------------------------#
  459. # Summary: 6502 add with carry instruction. #
  460. # ---------------------------------------------#
  461. # Called by: <addr> #
  462. # ---------------------------------------------#
  463. # Next call: cpu_cycle #
  464. ################################################
  465.  
  466. adc:
  467. # perform memory read
  468. move $a0, $s6
  469. jal mem_read
  470. # load previous carry
  471. adc_imm:
  472. # get previous carry
  473. andi $t1, $s4, 1
  474. # reset P flags
  475. andi $s4, $s4, 0x3C
  476. # add to accumulator
  477. add $s1, $s1, $t1
  478. add $s1, $s1, $v0
  479. # store carry in P
  480. srl $t2, $s1, 8
  481. or $s4, $s4, $t2
  482. # make sure there are no extra bits in accumulator
  483. andi $s1, $s1, 0xFF
  484. # store zero and N flag
  485. zeron $s1
  486. # fetch next instruction
  487. j cpu_cycle
  488.  
  489. ################################################
  490. # and #
  491. # ---------------------------------------------#
  492. # Summary: 6502 bitwise and instruction. #
  493. # ---------------------------------------------#
  494. # Called by: <addr> #
  495. # ---------------------------------------------#
  496. # Next call: cpu_cycle #
  497. ################################################
  498.  
  499. and:
  500. # perform memory read
  501. move $a0, $s6
  502. jal mem_read
  503. # and with A
  504. and_imm:
  505. and $s1, $s1, $v0
  506. # store zero and N flag
  507. zeron $s1
  508. # fetch next instruction
  509. j cpu_cycle
  510.  
  511. ################################################
  512. # asl #
  513. # ---------------------------------------------#
  514. # Summary: 6502 shift left instruction. #
  515. # ---------------------------------------------#
  516. # Called by: <addr> #
  517. # ---------------------------------------------#
  518. # Next call: cpu_cycle #
  519. ################################################
  520.  
  521. asl:
  522. # perform memory read
  523. move $a0, $s6
  524. jal mem_read
  525. # store higher bit in carry
  526. srl $t1, $v0, 7
  527. and $t1, $t1, 1
  528. and $s4, $s4, 0xFE
  529. or $s4, $s4, $t1
  530. # now shift left by 1
  531. sll $t1, $v0, 1
  532. andi $t1, $t1, 0xFF
  533. # store result in memory
  534. move $a0, $s6
  535. move $a1, $t1
  536. jal mem_write
  537. # store zero and N flag
  538. zeron $t1
  539. # fetch next instruction
  540. j cpu_cycle
  541.  
  542. asl_acc:
  543. # store higher bit in carry
  544. srl $t1, $v0, 7
  545. and $t1, $t1, 1
  546. and $s4, $s4, 0xFE
  547. or $s4, $s4, $t1
  548. # now shift left by 1
  549. sll $t1, $v0, 1
  550. andi $t1, $t1, 0xFF
  551. # store result in accumulator
  552. move $s1, $t1
  553. # store zero and N flag
  554. zeron $t1
  555. # fetch next instruction
  556. j cpu_cycle
  557.  
  558. ################################################
  559. # bcc #
  560. # ---------------------------------------------#
  561. # Summary: 6502 branch if carry clear. #
  562. # ---------------------------------------------#
  563. # Called by: <addr> #
  564. # ---------------------------------------------#
  565. # Next call: cpu_cycle #
  566. ################################################
  567.  
  568. bcc:
  569. # branch on carry clear
  570. addiu $s0, $s0, 1
  571. andi $t0, $s4, 0x01
  572. bne $t0, $0, cpu_cycle
  573. j rel
  574.  
  575. ################################################
  576. # bcs #
  577. # ---------------------------------------------#
  578. # Summary: 6502 branch if carry set. #
  579. # ---------------------------------------------#
  580. # Called by: <addr> #
  581. # ---------------------------------------------#
  582. # Next call: cpu_cycle #
  583. ################################################
  584.  
  585. bcs:
  586. # branch on carry set
  587. addiu $s0, $s0, 1
  588. andi $t0, $s4, 0x01
  589. beq $t0, $0, cpu_cycle
  590. j rel
  591.  
  592. ################################################
  593. # beq #
  594. # ---------------------------------------------#
  595. # Summary: 6502 branch if zero set. #
  596. # ---------------------------------------------#
  597. # Called by: <addr> #
  598. # ---------------------------------------------#
  599. # Next call: cpu_cycle #
  600. ################################################
  601.  
  602. beq:
  603. # branch on zero set
  604. addiu $s0, $s0, 1
  605. andi $t0, $s4, 0x02
  606. beq $t0, $0, cpu_cycle
  607. j rel
  608.  
  609. ################################################
  610. # bit #
  611. # ---------------------------------------------#
  612. # Summary: 6502 bit instruction. #
  613. # ---------------------------------------------#
  614. # Called by: <addr> #
  615. # ---------------------------------------------#
  616. # Next call: cpu_cycle #
  617. ################################################
  618.  
  619. bit:
  620. # fetch next instruction
  621. j cpu_cycle
  622.  
  623. ################################################
  624. # bmi #
  625. # ---------------------------------------------#
  626. # Summary: 6502 branch if negative set. #
  627. # ---------------------------------------------#
  628. # Called by: <addr> #
  629. # ---------------------------------------------#
  630. # Next call: cpu_cycle #
  631. ################################################
  632.  
  633. bmi:
  634. # branch on negative set
  635. addiu $s0, $s0, 1
  636. andi $t0, $s4, 0x80
  637. beq $t0, $0, cpu_cycle
  638. j rel
  639.  
  640. ################################################
  641. # bne #
  642. # ---------------------------------------------#
  643. # Summary: 6502 branch if zero clear. #
  644. # ---------------------------------------------#
  645. # Called by: <addr> #
  646. # ---------------------------------------------#
  647. # Next call: cpu_cycle #
  648. ################################################
  649.  
  650. bne:
  651. # branch on zero clear
  652. addiu $s0, $s0, 1
  653. andi $t0, $s4, 0x02
  654. bne $t0, $0, cpu_cycle
  655. j rel
  656.  
  657. ################################################
  658. # bpl #
  659. # ---------------------------------------------#
  660. # Summary: 6502 branch if negative clear. #
  661. # ---------------------------------------------#
  662. # Called by: <addr> #
  663. # ---------------------------------------------#
  664. # Next call: cpu_cycle #
  665. ################################################
  666.  
  667. bpl:
  668. # branch on negative clear
  669. addiu $s0, $s0, 1
  670. andi $t0, $s4, 0x80
  671. bne $t0, $0, cpu_cycle
  672. j rel
  673.  
  674. ################################################
  675. # brk #
  676. # ---------------------------------------------#
  677. # Summary: 6502 break instruction. #
  678. # ---------------------------------------------#
  679. # Called by: <addr> #
  680. # ---------------------------------------------#
  681. # Next call: cpu_cycle #
  682. ################################################
  683.  
  684. brk:
  685. # fetch next instruction
  686. j cpu_cycle
  687.  
  688. ################################################
  689. # bvc #
  690. # ---------------------------------------------#
  691. # Summary: 6502 branch if overflow clear #
  692. # ---------------------------------------------#
  693. # Called by: <addr> #
  694. # ---------------------------------------------#
  695. # Next call: cpu_cycle #
  696. ################################################
  697.  
  698. bvc:
  699. # branch on overflow clear
  700. addiu $s0, $s0, 1
  701. andi $t0, $s4, 0x40
  702. bne $t0, $0, cpu_cycle
  703. j rel
  704.  
  705. ################################################
  706. # bvs #
  707. # ---------------------------------------------#
  708. # Summary: 6502 branch if overflow set #
  709. # ---------------------------------------------#
  710. # Called by: <addr> #
  711. # ---------------------------------------------#
  712. # Next call: cpu_cycle #
  713. ################################################
  714.  
  715. bvs:
  716. # branch on overflow set
  717. addiu $s0, $s0, 1
  718. andi $t0, $s4, 0x40
  719. beq $t0, $0, cpu_cycle
  720. j rel
  721.  
  722. ################################################
  723. # clc #
  724. # ---------------------------------------------#
  725. # Summary: 6502 clear carry instruction. #
  726. # ---------------------------------------------#
  727. # Called by: <addr> #
  728. # ---------------------------------------------#
  729. # Next call: cpu_cycle #
  730. ################################################
  731.  
  732. clc:
  733. # clear carry flag
  734. andi $s4, $s4, 0xFE
  735. # fetch next instruction
  736. j cpu_cycle
  737.  
  738. ################################################
  739. # cld #
  740. # ---------------------------------------------#
  741. # Summary: 6502 clear decimal instruction. #
  742. # ---------------------------------------------#
  743. # Called by: <addr> #
  744. # ---------------------------------------------#
  745. # Next call: cpu_cycle #
  746. ################################################
  747.  
  748. cld:
  749. # clear decimal-mode flag
  750. andi $s4, $s4, 0xF7
  751. # fetch next instruction
  752. j cpu_cycle
  753.  
  754. ################################################
  755. # cli #
  756. # ---------------------------------------------#
  757. # Summary: 6502 clear interrupt instruction. #
  758. # ---------------------------------------------#
  759. # Called by: <addr> #
  760. # ---------------------------------------------#
  761. # Next call: cpu_cycle #
  762. ################################################
  763.  
  764. cli:
  765. # clear interrupt flag
  766. andi $s4, $s4, 0xFB
  767. # fetch next instruction
  768. j cpu_cycle
  769.  
  770. ################################################
  771. # clv #
  772. # ---------------------------------------------#
  773. # Summary: 6502 clear overflow instruction. #
  774. # ---------------------------------------------#
  775. # Called by: <addr> #
  776. # ---------------------------------------------#
  777. # Next call: cpu_cycle #
  778. ################################################
  779.  
  780. clv:
  781. # clear overflow flag
  782. andi $s4, $s4, 0xBF
  783. # fetch next instruction
  784. j cpu_cycle
  785.  
  786. ################################################
  787. # cmp #
  788. # ---------------------------------------------#
  789. # Summary: 6502 compare A instruction. #
  790. # ---------------------------------------------#
  791. # Called by: <addr> #
  792. # ---------------------------------------------#
  793. # Next call: cpu_cycle #
  794. ################################################
  795.  
  796. cmp:
  797. # perform memory read
  798. move $a0, $s6
  799. jal mem_read
  800. # subtract M from A
  801. cmp_imm:
  802. subu $t1, $s1, $v0
  803. # reset P flags
  804. andi $s4, $s4, 0x3C
  805. # store borrow (carry complement) in P
  806. srl $t2, $t1, 8
  807. andi $t2, $t2, 1
  808. xor $t2, $t2, 1
  809. or $s4, $s4, $t2
  810. # make sure no extra bits in result
  811. andi $t1, $t1, 0xFF
  812. # store zero and N flag
  813. zeron $t1
  814. # fetch next instruction
  815. j cpu_cycle
  816.  
  817. ################################################
  818. # cpx #
  819. # ---------------------------------------------#
  820. # Summary: 6502 compare X instruction. #
  821. # ---------------------------------------------#
  822. # Called by: <addr> #
  823. # ---------------------------------------------#
  824. # Next call: cpu_cycle #
  825. ################################################
  826.  
  827. cpx:
  828. # perform memory read
  829. move $a0, $s6
  830. jal mem_read
  831. # subtract M from X
  832. cpx_imm:
  833. subu $t1, $s2, $v0
  834. # reset P flags
  835. andi $s4, $s4, 0x3C
  836. # store borrow (carry complement) in P
  837. srl $t2, $t1, 8
  838. andi $t2, $t2, 1
  839. xor $t2, $t2, 1
  840. or $s4, $s4, $t2
  841. # make sure no extra bits in result
  842. andi $t1, $t1, 0xFF
  843. # store zero and N flag
  844. zeron $t1
  845. # fetch next instruction
  846. j cpu_cycle
  847.  
  848. ################################################
  849. # cpy #
  850. # ---------------------------------------------#
  851. # Summary: 6502 compare Y instruction. #
  852. # ---------------------------------------------#
  853. # Called by: <addr> #
  854. # ---------------------------------------------#
  855. # Next call: cpu_cycle #
  856. ################################################
  857.  
  858. cpy:
  859. # perform memory read
  860. move $a0, $s6
  861. jal mem_read
  862. # subtract M from Y
  863. cpy_imm:
  864. subu $t1, $s3, $v0
  865. # reset P flags
  866. andi $s4, $s4, 0x3C
  867. # store borrow (carry complement) in P
  868. srl $t2, $t1, 8
  869. andi $t2, $t2, 1
  870. xor $t2, $t2, 1
  871. or $s4, $s4, $t2
  872. # make sure no extra bits in result
  873. andi $t1, $t1, 0xFF
  874. # store zero and N flag
  875. zeron $t1
  876. # fetch next instruction
  877. j cpu_cycle
  878.  
  879. ################################################
  880. # dec #
  881. # ---------------------------------------------#
  882. # Summary: 6502 decrement instruction. #
  883. # ---------------------------------------------#
  884. # Called by: <addr> #
  885. # ---------------------------------------------#
  886. # Next call: cpu_cycle #
  887. ################################################
  888.  
  889. dec:
  890. # perform memory read
  891. move $a0, $s6
  892. jal mem_read
  893. # decrease the byte
  894. addiu $t1, $v0, -1
  895. andi $t1, $t1, 0xFF
  896. # perform memory write
  897. move $a0, $s6
  898. move $a1, $t1
  899. jal mem_write
  900. # store zero and N flag
  901. zeron $t1
  902. # fetch next instruction
  903. j cpu_cycle
  904.  
  905. ################################################
  906. # dex #
  907. # ---------------------------------------------#
  908. # Summary: 6502 X decrement instruction. #
  909. # ---------------------------------------------#
  910. # Called by: <addr> #
  911. # ---------------------------------------------#
  912. # Next call: cpu_cycle #
  913. ################################################
  914.  
  915. dex:
  916. # decrease X
  917. addiu $s2, $s2, -1
  918. andi $s2, $s2, 0xFF
  919. # store zero and N flag
  920. zeron $s2
  921. # fetch next instruction
  922. j cpu_cycle
  923.  
  924. ################################################
  925. # dey #
  926. # ---------------------------------------------#
  927. # Summary: 6502 Y decrement instruction. #
  928. # ---------------------------------------------#
  929. # Called by: <addr> #
  930. # ---------------------------------------------#
  931. # Next call: cpu_cycle #
  932. ################################################
  933.  
  934. dey:
  935. # decrease Y
  936. addiu $s3, $s3, -1
  937. andi $s3, $s3, 0xFF
  938. # store zero and N flag
  939. zeron $s3
  940. # fetch next instruction
  941. j cpu_cycle
  942.  
  943. ################################################
  944. # eor #
  945. # ---------------------------------------------#
  946. # Summary: 6502 exclusive or instruction. #
  947. # ---------------------------------------------#
  948. # Called by: <addr> #
  949. # ---------------------------------------------#
  950. # Next call: cpu_cycle #
  951. ################################################
  952.  
  953. eor:
  954. # perform memory read
  955. move $a0, $s6
  956. jal mem_read
  957. eor_imm:
  958. # xor with A
  959. xor $s1, $s1, $v0
  960. # store zero and N flag
  961. zeron $s1
  962. # fetch next instruction
  963. j cpu_cycle
  964.  
  965. ################################################
  966. # inc #
  967. # ---------------------------------------------#
  968. # Summary: 6502 increment instruction. #
  969. # ---------------------------------------------#
  970. # Called by: <addr> #
  971. # ---------------------------------------------#
  972. # Next call: cpu_cycle #
  973. ################################################
  974.  
  975. inc:
  976. # perform memory read
  977. move $a0, $s6
  978. jal mem_read
  979. # increase the byte
  980. addiu $t1, $v0, 1
  981. andi $t1, $t1, 0xFF
  982. # perform memory write
  983. move $a0, $s6
  984. move $a1, $t1
  985. jal mem_write
  986. # store zero and N flag
  987. zeron $t1
  988. # fetch next instruction
  989. j cpu_cycle
  990.  
  991. ################################################
  992. # inx #
  993. # ---------------------------------------------#
  994. # Summary: 6502 X-increment instruction. #
  995. # ---------------------------------------------#
  996. # Called by: <addr> #
  997. # ---------------------------------------------#
  998. # Next call: cpu_cycle #
  999. ################################################
  1000.  
  1001. inx:
  1002. # increase X
  1003. addiu $s2, $s2, 1
  1004. andi $s2, $s2, 0xFF
  1005. # store zero and N flag
  1006. zeron $s2
  1007. # fetch next instruction
  1008. j cpu_cycle
  1009.  
  1010. ################################################
  1011. # iny #
  1012. # ---------------------------------------------#
  1013. # Summary: 6502 Y-increment instruction. #
  1014. # ---------------------------------------------#
  1015. # Called by: <addr> #
  1016. # ---------------------------------------------#
  1017. # Next call: cpu_cycle #
  1018. ################################################
  1019.  
  1020. iny:
  1021. # increase Y
  1022. addiu $s3, $s3, 1
  1023. andi $s3, $s3, 0xFF
  1024. # store zero and N flag
  1025. zeron $s3
  1026. # fetch next instruction
  1027. j cpu_cycle
  1028.  
  1029. ################################################
  1030. # jmp #
  1031. # ---------------------------------------------#
  1032. # Summary: 6502 jump instruction. #
  1033. # ---------------------------------------------#
  1034. # Called by: <addr> #
  1035. # ---------------------------------------------#
  1036. # Next call: cpu_cycle #
  1037. ################################################
  1038.  
  1039. jmp:
  1040. # move MAR into PC
  1041. move $s0, $s6
  1042. # reset t5
  1043. srl $t0, $s0, 11
  1044. andi $t0, $t0, 28
  1045. addu $t5, $s5, $t0
  1046. lw $t5, %lo(__instr_routines)($t5)
  1047. # fetch next instruction
  1048. j cpu_cycle
  1049.  
  1050. ################################################
  1051. # jsr #
  1052. # ---------------------------------------------#
  1053. # Summary: 6502 jump subroutine instruction. #
  1054. # ---------------------------------------------#
  1055. # Called by: <addr> #
  1056. # ---------------------------------------------#
  1057. # Next call: cpu_cycle #
  1058. ################################################
  1059.  
  1060. jsr:
  1061. # push PC
  1062. addiu $a0, $s7, 0x0FF
  1063. move $a1, $s0
  1064. jal ram_write2
  1065. # decrease stack ptr
  1066. addiu $s7, $s7, -2
  1067. andi $s7, $s7, 0xFF
  1068. # jmp to new location
  1069. move $s0, $s6
  1070. # reset t5
  1071. srl $t0, $s0, 11
  1072. andi $t0, $t0, 28
  1073. addu $t5, $s5, $t0
  1074. lw $t5, %lo(__instr_routines)($t5)
  1075. # fetch next instruction
  1076. j cpu_cycle
  1077.  
  1078. ################################################
  1079. # lda #
  1080. # ---------------------------------------------#
  1081. # Summary: 6502 load A instruction. #
  1082. # ---------------------------------------------#
  1083. # Called by: <addr> #
  1084. # ---------------------------------------------#
  1085. # Next call: cpu_cycle #
  1086. ################################################
  1087.  
  1088. lda:
  1089. # perform memory read
  1090. move $a0, $s6
  1091. jal mem_read
  1092. # load result into X
  1093. lda_imm:
  1094. move $s1, $v0
  1095. # store zero and N flag
  1096. zeron $s1
  1097. # fetch next instruction
  1098. j cpu_cycle
  1099.  
  1100. ################################################
  1101. # ldx #
  1102. # ---------------------------------------------#
  1103. # Summary: 6502 load X instruction. #
  1104. # ---------------------------------------------#
  1105. # Called by: <addr> #
  1106. # ---------------------------------------------#
  1107. # Next call: cpu_cycle #
  1108. ################################################
  1109.  
  1110. ldx:
  1111. # perform memory read
  1112. move $a0, $s6
  1113. jal mem_read
  1114. # load result into X
  1115. ldx_imm:
  1116. move $s2, $v0
  1117. # store zero and N flag
  1118. zeron $s2
  1119. # fetch next instruction
  1120. j cpu_cycle
  1121.  
  1122. ################################################
  1123. # ldy #
  1124. # ---------------------------------------------#
  1125. # Summary: 6502 load Y instruction. #
  1126. # ---------------------------------------------#
  1127. # Called by: <addr> #
  1128. # ---------------------------------------------#
  1129. # Next call: cpu_cycle #
  1130. ################################################
  1131.  
  1132. ldy:
  1133. # perform memory read
  1134. move $a0, $s6
  1135. jal mem_read
  1136. # load result into X
  1137. ldy_imm:
  1138. move $s3, $v0
  1139. # store zero and N flag
  1140. zeron $s3
  1141. # fetch next instruction
  1142. j cpu_cycle
  1143.  
  1144. ################################################
  1145. # lsr #
  1146. # ---------------------------------------------#
  1147. # Summary: 6502 shift right instruction. #
  1148. # ---------------------------------------------#
  1149. # Called by: <addr> #
  1150. # ---------------------------------------------#
  1151. # Next call: cpu_cycle #
  1152. ################################################
  1153.  
  1154. lsr:
  1155. # perform memory read
  1156. move $a0, $s6
  1157. jal mem_read
  1158. # store lower bit in carry
  1159. and $t1, $v0, 1
  1160. and $s4, $s4, 0xFE
  1161. or $s4, $s4, $t1
  1162. # now shift right by 1
  1163. srl $t1, $v0, 1
  1164. andi $t1, $t1, 0x7F
  1165. # store result in memory
  1166. move $a0, $s6
  1167. move $a1, $t1
  1168. jal mem_write
  1169. # store zero and N flag
  1170. zeron $t1
  1171. # fetch next instruction
  1172. j cpu_cycle
  1173.  
  1174. lsr_acc:
  1175. # store lower bit in carry
  1176. and $t1, $v0, 1
  1177. and $s4, $s4, 0xFE
  1178. or $s4, $s4, $t1
  1179. # now shift right by 1
  1180. srl $t1, $v0, 1
  1181. andi $t1, $t1, 0x7F
  1182. # store result in memory
  1183. move $s1, $t1
  1184. # store zero and N flag
  1185. zeron $t1
  1186. # fetch next instruction
  1187. j cpu_cycle
  1188.  
  1189. ################################################
  1190. # nop #
  1191. # ---------------------------------------------#
  1192. # Summary: 6502 no-operation instruction. #
  1193. # ---------------------------------------------#
  1194. # Called by: <addr> #
  1195. # ---------------------------------------------#
  1196. # Next call: cpu_cycle #
  1197. ################################################
  1198.  
  1199. nop:
  1200. # fetch next instruction
  1201. j cpu_cycle
  1202.  
  1203. ################################################
  1204. # ora #
  1205. # ---------------------------------------------#
  1206. # Summary: 6502 inclusive or instruction. #
  1207. # ---------------------------------------------#
  1208. # Called by: <addr> #
  1209. # ---------------------------------------------#
  1210. # Next call: cpu_cycle #
  1211. ################################################
  1212.  
  1213. ora:
  1214. # perform memory read
  1215. move $a0, $s6
  1216. jal mem_read
  1217. ora_imm:
  1218. # or with A
  1219. or $s1, $s1, $v0
  1220. # store zero and N flag
  1221. zeron $s1
  1222. # fetch next instruction
  1223. j cpu_cycle
  1224.  
  1225. ################################################
  1226. # pha #
  1227. # ---------------------------------------------#
  1228. # Summary: 6502 push A instruction. #
  1229. # ---------------------------------------------#
  1230. # Called by: <addr> #
  1231. # ---------------------------------------------#
  1232. # Next call: cpu_cycle #
  1233. ################################################
  1234.  
  1235. pha:
  1236. # push A
  1237. addiu $a0, $s7, 0x100
  1238. move $a1, $s1
  1239. jal ram_write
  1240. addiu $s7, $s7, -1
  1241. andi $s7, $s7, 0xFF
  1242. # fetch next instruction
  1243. j cpu_cycle
  1244.  
  1245. ################################################
  1246. # php #
  1247. # ---------------------------------------------#
  1248. # Summary: 6502 push P instruction. #
  1249. # ---------------------------------------------#
  1250. # Called by: <addr> #
  1251. # ---------------------------------------------#
  1252. # Next call: cpu_cycle #
  1253. ################################################
  1254.  
  1255. php:
  1256. # push P
  1257. addiu $a0, $s7, 0x100
  1258. move $a1, $s4
  1259. jal ram_write
  1260. addiu $s7, $s7, -1
  1261. andi $s7, $s7, 0xFF
  1262. # fetch next instruction
  1263. j cpu_cycle
  1264.  
  1265. ################################################
  1266. # pla #
  1267. # ---------------------------------------------#
  1268. # Summary: 6502 pull A instruction. #
  1269. # ---------------------------------------------#
  1270. # Called by: <addr> #
  1271. # ---------------------------------------------#
  1272. # Next call: cpu_cycle #
  1273. ################################################
  1274.  
  1275. pla:
  1276. # pull A
  1277. addiu $s7, $s7, 1
  1278. andi $s7, $s7, 0xFF
  1279. addiu $a0, $s7, 0x100
  1280. jal ram_read
  1281. move $s1, $v0
  1282. # store zero and N flag
  1283. zeron $s1
  1284. # fetch next instruction
  1285. j cpu_cycle
  1286.  
  1287. ################################################
  1288. # plp #
  1289. # ---------------------------------------------#
  1290. # Summary: 6502 pull P instruction. #
  1291. # ---------------------------------------------#
  1292. # Called by: <addr> #
  1293. # ---------------------------------------------#
  1294. # Next call: cpu_cycle #
  1295. ################################################
  1296.  
  1297. plp:
  1298. # pull A
  1299. addiu $s7, $s7, 1
  1300. andi $s7, $s7, 0xFF
  1301. addiu $a0, $s7, 0x100
  1302. jal ram_read
  1303. move $s4, $v0
  1304. # fetch next instruction
  1305. j cpu_cycle
  1306.  
  1307. ################################################
  1308. # rol #
  1309. # ---------------------------------------------#
  1310. # Summary: 6502 rotate left instruction. #
  1311. # ---------------------------------------------#
  1312. # Called by: <addr> #
  1313. # ---------------------------------------------#
  1314. # Next call: cpu_cycle #
  1315. ################################################
  1316.  
  1317. rol:
  1318. # perform memory read
  1319. move $a0, $s6
  1320. jal mem_read
  1321. # shift left and insert carry
  1322. sll $t1, $v0, 1
  1323. and $t2, $s4, 1
  1324. or $t1, $t1, $t2
  1325. andi $t1, $t1, 0xFF
  1326. # store higher bit in carry
  1327. srl $t2, $v0, 7
  1328. and $t2, $t2, 1
  1329. and $s4, $s4, 0xFE
  1330. or $s4, $s4, $t2
  1331. # store result in memory
  1332. move $a0, $s6
  1333. move $a1, $t1
  1334. jal mem_write
  1335. # store zero and N flag
  1336. zeron $t1
  1337. # fetch next instruction
  1338. j cpu_cycle
  1339.  
  1340. rol_acc:
  1341. # shift left and insert carry
  1342. sll $t1, $v0, 1
  1343. and $t2, $s4, 1
  1344. or $t1, $t1, $t2
  1345. andi $t1, $t1, 0xFF
  1346. # store higher bit in carry
  1347. srl $t2, $v0, 7
  1348. and $t2, $t2, 1
  1349. and $s4, $s4, 0xFE
  1350. or $s4, $s4, $t2
  1351. # store result in memory
  1352. move $s1, $t1
  1353. # store zero and N flag
  1354. zeron $t1
  1355. # fetch next instruction
  1356. j cpu_cycle
  1357.  
  1358. ################################################
  1359. # ror #
  1360. # ---------------------------------------------#
  1361. # Summary: 6502 rotate right instruction. #
  1362. # ---------------------------------------------#
  1363. # Called by: <addr> #
  1364. # ---------------------------------------------#
  1365. # Next call: cpu_cycle #
  1366. ################################################
  1367.  
  1368. ror:
  1369. # perform memory read
  1370. move $a0, $s6
  1371. jal mem_read
  1372. # shift right and insert carry
  1373. srl $t1, $v0, 1
  1374. and $t2, $s4, 1
  1375. sll $t2, $t2, 7
  1376. or $t1, $t1, $t2
  1377. andi $t1, $t1, 0xFF
  1378. # store lower bit in carry
  1379. and $t2, $v0, 1
  1380. and $s4, $s4, 0xFE
  1381. or $s4, $s4, $t2
  1382. # store result in memory
  1383. move $a0, $s6
  1384. move $a1, $t1
  1385. jal mem_write
  1386. # store zero and N flag
  1387. zeron $t1
  1388. # fetch next instruction
  1389. j cpu_cycle
  1390.  
  1391. ror_acc:
  1392. # shift right and insert carry
  1393. srl $t1, $v0, 1
  1394. and $t2, $s4, 1
  1395. sll $t2, $t2, 7
  1396. or $t1, $t1, $t2
  1397. andi $t1, $t1, 0xFF
  1398. # store lower bit in carry
  1399. and $t2, $v0, 1
  1400. and $s4, $s4, 0xFE
  1401. or $s4, $s4, $t2
  1402. # store result in memory
  1403. move $s1, $t1
  1404. # store zero and N flag
  1405. zeron $t1
  1406. # fetch next instruction
  1407. j cpu_cycle
  1408.  
  1409. ################################################
  1410. # rti #
  1411. # ---------------------------------------------#
  1412. # Summary: 6502 return from interrupt. #
  1413. # ---------------------------------------------#
  1414. # Called by: <addr> #
  1415. # ---------------------------------------------#
  1416. # Next call: cpu_cycle #
  1417. ################################################
  1418.  
  1419. rti:
  1420. # fetch next instruction
  1421. j cpu_cycle
  1422.  
  1423. ################################################
  1424. # rts #
  1425. # ---------------------------------------------#
  1426. # Summary: 6502 return from subroutine. #
  1427. # ---------------------------------------------#
  1428. # Called by: <addr> #
  1429. # ---------------------------------------------#
  1430. # Next call: cpu_cycle #
  1431. ################################################
  1432.  
  1433. rts:
  1434. # pull PC
  1435. addiu $a0, $s7, 0x101
  1436. addiu $s7, $s7, 2
  1437. jal ram_read2
  1438. move $s0, $v0
  1439. # reset t5
  1440. srl $t0, $s0, 11
  1441. andi $t0, $t0, 28
  1442. addu $t5, $s5, $t0
  1443. lw $t5, %lo(__instr_routines)($t5)
  1444. # fetch next instruction
  1445. j cpu_cycle
  1446.  
  1447. ################################################
  1448. # sbc #
  1449. # ---------------------------------------------#
  1450. # Summary: 6502 sub with carry instruction. #
  1451. # ---------------------------------------------#
  1452. # Called by: <addr> #
  1453. # ---------------------------------------------#
  1454. # Next call: cpu_cycle #
  1455. ################################################
  1456.  
  1457. sbc:
  1458. # perform memory read
  1459. move $a0, $s6
  1460. jal mem_read
  1461. # load previous not carry (borrow)
  1462. sbc_imm:
  1463. andi $t1, $s4, 1
  1464. xor $t1, $t1, 1
  1465. # add borrow to M, sub result from A
  1466. add $t1, $t1, $v0
  1467. sub $s1, $s1, $t1
  1468. # reset P flags
  1469. andi $s4, $s4, 0x3C
  1470. # store not borrow (carry) in P
  1471. srl $t2, $s1, 8
  1472. and $t2, $t2, 1
  1473. xor $t2, $t2, 1
  1474. or $s4, $s4, $t2
  1475. # make sure no extra bits in accumulator
  1476. andi $s1, $s1, 0xFF
  1477. # store zero and N flag
  1478. zeron $s1
  1479. # fetch next instruction
  1480. j cpu_cycle
  1481.  
  1482. ################################################
  1483. # sec #
  1484. # ---------------------------------------------#
  1485. # Summary: 6502 set carry instruction. #
  1486. # ---------------------------------------------#
  1487. # Called by: <addr> #
  1488. # ---------------------------------------------#
  1489. # Next call: cpu_cycle #
  1490. ################################################
  1491.  
  1492. sec:
  1493. # set carry flag
  1494. ori $s4, $s4, 0x01
  1495. # fetch next instruction
  1496. j cpu_cycle
  1497.  
  1498. ################################################
  1499. # sed #
  1500. # ---------------------------------------------#
  1501. # Summary: 6502 set decimal instruction. #
  1502. # ---------------------------------------------#
  1503. # Called by: <addr> #
  1504. # ---------------------------------------------#
  1505. # Next call: cpu_cycle #
  1506. ################################################
  1507.  
  1508. sed:
  1509. # set decimal-mode flag
  1510. ori $s4, $s4, 0x08
  1511. # fetch next instruction
  1512. j cpu_cycle
  1513.  
  1514. ################################################
  1515. # sei #
  1516. # ---------------------------------------------#
  1517. # Summary: 6502 set interrupt instruction. #
  1518. # ---------------------------------------------#
  1519. # Called by: <addr> #
  1520. # ---------------------------------------------#
  1521. # Next call: cpu_cycle #
  1522. ################################################
  1523.  
  1524. sei:
  1525. # set decimal-mode flag
  1526. ori $s4, $s4, 0x04
  1527. # fetch next instruction
  1528. j cpu_cycle
  1529.  
  1530. ################################################
  1531. # sta #
  1532. # ---------------------------------------------#
  1533. # Summary: 6502 store A instruction. #
  1534. # ---------------------------------------------#
  1535. # Called by: <addr> #
  1536. # ---------------------------------------------#
  1537. # Next call: cpu_cycle #
  1538. ################################################
  1539.  
  1540. sta:
  1541. # write A to memory
  1542. move $a0, $s6
  1543. move $a1, $s1
  1544. jal mem_write
  1545. # fetch next instruction
  1546. j cpu_cycle
  1547.  
  1548. ################################################
  1549. # stx #
  1550. # ---------------------------------------------#
  1551. # Summary: 6502 store X instruction. #
  1552. # ---------------------------------------------#
  1553. # Called by: <addr> #
  1554. # ---------------------------------------------#
  1555. # Next call: cpu_cycle #
  1556. ################################################
  1557.  
  1558. stx:
  1559. # write X to memory
  1560. move $a0, $s6
  1561. move $a1, $s2
  1562. jal mem_write
  1563. # fetch next instruction
  1564. j cpu_cycle
  1565.  
  1566. ################################################
  1567. # sty #
  1568. # ---------------------------------------------#
  1569. # Summary: 6502 store Y instruction. #
  1570. # ---------------------------------------------#
  1571. # Called by: <addr> #
  1572. # ---------------------------------------------#
  1573. # Next call: cpu_cycle #
  1574. ################################################
  1575.  
  1576. sty:
  1577. # write Y to memory
  1578. move $a0, $s6
  1579. move $a1, $s3
  1580. jal mem_write
  1581. # fetch next instruction
  1582. j cpu_cycle
  1583.  
  1584. ################################################
  1585. # tax #
  1586. # ---------------------------------------------#
  1587. # Summary: 6502 transfer A to X instruction. #
  1588. # ---------------------------------------------#
  1589. # Called by: <addr> #
  1590. # ---------------------------------------------#
  1591. # Next call: cpu_cycle #
  1592. ################################################
  1593.  
  1594. tax:
  1595. # load A into X
  1596. move $s2, $s1
  1597. # store zero and N flag
  1598. zeron $s2
  1599. # fetch next instruction
  1600. j cpu_cycle
  1601.  
  1602. ################################################
  1603. # tay #
  1604. # ---------------------------------------------#
  1605. # Summary: 6502 transfer A to Y instruction. #
  1606. # ---------------------------------------------#
  1607. # Called by: <addr> #
  1608. # ---------------------------------------------#
  1609. # Next call: cpu_cycle #
  1610. ################################################
  1611.  
  1612. tay:
  1613. # load A into Y
  1614. move $s3, $s1
  1615. # store zero and N flag
  1616. zeron $s3
  1617. # fetch next instruction
  1618. j cpu_cycle
  1619.  
  1620. ################################################
  1621. # tsx #
  1622. # ---------------------------------------------#
  1623. # Summary: 6502 transfer S to X instruction. #
  1624. # ---------------------------------------------#
  1625. # Called by: <addr> #
  1626. # ---------------------------------------------#
  1627. # Next call: cpu_cycle #
  1628. ################################################
  1629.  
  1630. tsx:
  1631. # load S into X
  1632. move $s2, $s7
  1633. # store zero and N flag
  1634. zeron $s2
  1635. # fetch next instruction
  1636. j cpu_cycle
  1637.  
  1638. ################################################
  1639. # txa #
  1640. # ---------------------------------------------#
  1641. # Summary: 6502 transfer X to A instruction. #
  1642. # ---------------------------------------------#
  1643. # Called by: <addr> #
  1644. # ---------------------------------------------#
  1645. # Next call: cpu_cycle #
  1646. ################################################
  1647.  
  1648. txa:
  1649. # load X into A
  1650. move $s1, $s2
  1651. # store zero and N flag
  1652. zeron $s1
  1653. # fetch next instruction
  1654. j cpu_cycle
  1655.  
  1656. ################################################
  1657. # txs #
  1658. # ---------------------------------------------#
  1659. # Summary: 6502 transfer X to S instruction. #
  1660. # ---------------------------------------------#
  1661. # Called by: <addr> #
  1662. # ---------------------------------------------#
  1663. # Next call: cpu_cycle #
  1664. ################################################
  1665.  
  1666. txs:
  1667. # load X into S
  1668. move $s7, $s2
  1669. # fetch next instruction
  1670. j cpu_cycle
  1671.  
  1672. ################################################
  1673. # tya #
  1674. # ---------------------------------------------#
  1675. # Summary: 6502 transfer Y to A instruction. #
  1676. # ---------------------------------------------#
  1677. # Called by: <addr> #
  1678. # ---------------------------------------------#
  1679. # Next call: cpu_cycle #
  1680. ################################################
  1681.  
  1682. tya:
  1683. # load Y into A
  1684. move $s1, $s3
  1685. # store zero and N flag
  1686. zeron $s1
  1687. # fetch next instruction
  1688. j cpu_cycle
  1689.  
  1690. ###################################################
  1691. # SECTION: RODATA #
  1692. ###################################################
  1693.  
  1694. .section "rodata", "a"
  1695.  
  1696. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1697. # instruction names (for debugging/disassembling)
  1698. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1699.  
  1700. .if debug_enabled
  1701. _adc: .string "adc"
  1702. _and: .string "and"
  1703. _asl: .string "asl"
  1704. _bcc: .string "bcc"
  1705. _bcs: .string "bcs"
  1706. _beq: .string "beq"
  1707. _bit: .string "bit"
  1708. _bmi: .string "bmi"
  1709. _bne: .string "bne"
  1710. _bpl: .string "bpl"
  1711. _brk: .string "brk"
  1712. _bvc: .string "bvc"
  1713. _bvs: .string "bvs"
  1714. _clc: .string "clc"
  1715. _cld: .string "cld"
  1716. _cli: .string "cli"
  1717. _clv: .string "clv"
  1718. _cmp: .string "cmp"
  1719. _cpx: .string "cpx"
  1720. _cpy: .string "cpy"
  1721. _dec: .string "dec"
  1722. _dex: .string "dex"
  1723. _dey: .string "dey"
  1724. _eor: .string "eor"
  1725. _inc: .string "inc"
  1726. _inx: .string "inx"
  1727. _iny: .string "iny"
  1728. _jmp: .string "jmp"
  1729. _jsr: .string "jsr"
  1730. _lda: .string "lda"
  1731. _ldx: .string "ldx"
  1732. _ldy: .string "ldy"
  1733. _lsr: .string "lsr"
  1734. _nop: .string "nop"
  1735. _ora: .string "ora"
  1736. _pha: .string "pha"
  1737. _php: .string "php"
  1738. _pla: .string "pla"
  1739. _plp: .string "plp"
  1740. _rol: .string "rol"
  1741. _ror: .string "ror"
  1742. _rti: .string "rti"
  1743. _rts: .string "rts"
  1744. _sbc: .string "sbc"
  1745. _sec: .string "sec"
  1746. _sed: .string "sed"
  1747. _sei: .string "sei"
  1748. _sta: .string "sta"
  1749. _stx: .string "stx"
  1750. _sty: .string "sty"
  1751. _tax: .string "tax"
  1752. _tay: .string "tay"
  1753. _tsx: .string "tsx"
  1754. _txa: .string "txa"
  1755. _txs: .string "txs"
  1756. _tya: .string "tya"
  1757. .endif
  1758.  
  1759. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1760. # instruction formats (for debugging/disassembling)
  1761. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1762.  
  1763. .if debug_enabled
  1764. _imm: .string "#$%0X%2X "
  1765. _abs: .string "$%2X%2X "
  1766. _zp: .string "$%0X%2X "
  1767. _acc: .string " "
  1768. _imp: .string " "
  1769. _idir: .string "idir "
  1770. _dind: .string "($%0X%2X),y "
  1771. _izx: .string "izx "
  1772. _iax: .string "$%2X%2X,x "
  1773. _iay: .string "$%2X%2X,y "
  1774. _rel: .string "$%0X%2X "
  1775. _absd: .string "absd "
  1776. _izy: .string "izy "
  1777. .endif
  1778.  
  1779. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1780. # pointers to instruction routines and addressing mode routines
  1781. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  1782.  
  1783. instr:
  1784. /* $00 */ .word brk, brk
  1785. /* $01 */ .word ora, idir
  1786. /* $02 */ .word 0, 0
  1787. /* $03 */ .word 0, 0
  1788. /* $04 */ .word 0, 0
  1789. /* $05 */ .word ora, zp
  1790. /* $06 */ .word asl, zp
  1791. /* $07 */ .word 0, 0
  1792. /* $08 */ .word php, php
  1793. /* $09 */ .word ora_imm, imm
  1794. /* $0A */ .word asl_acc, acc
  1795. /* $0B */ .word 0, 0
  1796. /* $0C */ .word 0, 0
  1797. /* $0D */ .word ora, abs
  1798. /* $0E */ .word asl, abs
  1799. /* $0F */ .word 0, 0
  1800. /* $10 */ .word bpl, bpl
  1801. /* $11 */ .word ora, dind
  1802. /* $12 */ .word 0, 0
  1803. /* $13 */ .word 0, 0
  1804. /* $14 */ .word 0, 0
  1805. /* $15 */ .word ora, izx
  1806. /* $16 */ .word asl, izx
  1807. /* $17 */ .word 0, 0
  1808. /* $18 */ .word clc, clc
  1809. /* $19 */ .word ora, iay
  1810. /* $1A */ .word 0, 0
  1811. /* $1B */ .word 0, 0
  1812. /* $1C */ .word 0, 0
  1813. /* $1D */ .word ora, iax
  1814. /* $1E */ .word asl, iax
  1815. /* $1F */ .word 0, 0
  1816. /* $20 */ .word jsr, abs
  1817. /* $21 */ .word and, idir
  1818. /* $22 */ .word 0, 0
  1819. /* $23 */ .word 0, 0
  1820. /* $24 */ .word bit, zp
  1821. /* $25 */ .word and, zp
  1822. /* $26 */ .word rol, zp
  1823. /* $27 */ .word 0, 0
  1824. /* $28 */ .word plp, plp
  1825. /* $29 */ .word and_imm, imm
  1826. /* $2A */ .word rol_acc, acc
  1827. /* $2B */ .word 0, 0
  1828. /* $2C */ .word bit, abs
  1829. /* $2D */ .word and, abs
  1830. /* $2E */ .word rol, abs
  1831. /* $2F */ .word 0, 0
  1832. /* $30 */ .word bmi, bmi
  1833. /* $31 */ .word and, dind
  1834. /* $32 */ .word 0, 0
  1835. /* $33 */ .word 0, 0
  1836. /* $34 */ .word 0, 0
  1837. /* $35 */ .word and, izx
  1838. /* $36 */ .word rol, izx
  1839. /* $37 */ .word 0, 0
  1840. /* $38 */ .word sec, sec
  1841. /* $39 */ .word and, iay
  1842. /* $3A */ .word 0, 0
  1843. /* $3B */ .word 0, 0
  1844. /* $3C */ .word 0, 0
  1845. /* $3D */ .word and, iax
  1846. /* $3E */ .word rol, iax
  1847. /* $3F */ .word 0, 0
  1848. /* $40 */ .word rti, rti
  1849. /* $41 */ .word eor, idir
  1850. /* $42 */ .word 0, 0
  1851. /* $43 */ .word 0, 0
  1852. /* $44 */ .word 0, 0
  1853. /* $45 */ .word eor, zp
  1854. /* $46 */ .word lsr, zp
  1855. /* $47 */ .word 0, 0
  1856. /* $48 */ .word pha, pha
  1857. /* $49 */ .word eor_imm, imm
  1858. /* $4A */ .word lsr_acc, acc
  1859. /* $4B */ .word 0, 0
  1860. /* $4C */ .word jmp, abs
  1861. /* $4D */ .word eor, abs
  1862. /* $4E */ .word lsr, abs
  1863. /* $4F */ .word 0, 0
  1864. /* $50 */ .word bvc, bvc
  1865. /* $51 */ .word eor, dind
  1866. /* $52 */ .word 0, 0
  1867. /* $53 */ .word 0, 0
  1868. /* $54 */ .word 0, 0
  1869. /* $55 */ .word eor, izx
  1870. /* $56 */ .word lsr, izx
  1871. /* $57 */ .word 0, 0
  1872. /* $58 */ .word cli, cli
  1873. /* $59 */ .word eor, iay
  1874. /* $5A */ .word 0, 0
  1875. /* $5B */ .word 0, 0
  1876. /* $5C */ .word 0, 0
  1877. /* $5D */ .word eor, iax
  1878. /* $5E */ .word lsr, iax
  1879. /* $5F */ .word 0, 0
  1880. /* $60 */ .word rts, rts
  1881. /* $61 */ .word adc, idir
  1882. /* $62 */ .word 0, 0
  1883. /* $63 */ .word 0, 0
  1884. /* $64 */ .word 0, 0
  1885. /* $65 */ .word adc, zp
  1886. /* $66 */ .word ror, zp
  1887. /* $67 */ .word 0, 0
  1888. /* $68 */ .word pla, pla
  1889. /* $69 */ .word adc_imm, imm
  1890. /* $6A */ .word ror_acc, acc
  1891. /* $6B */ .word 0, 0
  1892. /* $6C */ .word jmp, absd
  1893. /* $6D */ .word adc, abs
  1894. /* $6E */ .word ror, abs
  1895. /* $6F */ .word 0, 0
  1896. /* $70 */ .word bvs, bvs
  1897. /* $71 */ .word adc, dind
  1898. /* $72 */ .word 0, 0
  1899. /* $73 */ .word 0, 0
  1900. /* $74 */ .word 0, 0
  1901. /* $75 */ .word adc, izx
  1902. /* $76 */ .word ror, izx
  1903. /* $77 */ .word 0, 0
  1904. /* $78 */ .word sei, sei
  1905. /* $79 */ .word adc, iay
  1906. /* $7A */ .word 0, 0
  1907. /* $7B */ .word 0, 0
  1908. /* $7C */ .word 0, 0
  1909. /* $7D */ .word adc, iax
  1910. /* $7E */ .word ror, iax
  1911. /* $7F */ .word 0, 0
  1912. /* $80 */ .word 0, 0
  1913. /* $81 */ .word sta, idir
  1914. /* $82 */ .word 0, 0
  1915. /* $83 */ .word 0, 0
  1916. /* $84 */ .word sty, zp
  1917. /* $85 */ .word sta, zp
  1918. /* $86 */ .word stx, zp
  1919. /* $87 */ .word 0, 0
  1920. /* $88 */ .word dey, dey
  1921. /* $89 */ .word 0, 0
  1922. /* $8A */ .word txa, txa
  1923. /* $8B */ .word 0, 0
  1924. /* $8C */ .word sty, abs
  1925. /* $8D */ .word sta, abs
  1926. /* $8E */ .word stx, abs
  1927. /* $8F */ .word 0, 0
  1928. /* $90 */ .word bcc, bcc
  1929. /* $91 */ .word sta, dind
  1930. /* $92 */ .word 0, 0
  1931. /* $93 */ .word 0, 0
  1932. /* $94 */ .word sty, izx
  1933. /* $95 */ .word sta, izx
  1934. /* $96 */ .word stx, izy
  1935. /* $97 */ .word 0, 0
  1936. /* $98 */ .word tya, tya
  1937. /* $99 */ .word sta, iay
  1938. /* $9A */ .word txs, txs
  1939. /* $9B */ .word 0, 0
  1940. /* $9C */ .word 0, 0
  1941. /* $9D */ .word sta, iax
  1942. /* $9E */ .word 0, 0
  1943. /* $9F */ .word 0, 0
  1944. /* $A0 */ .word ldy_imm, imm
  1945. /* $A1 */ .word lda, idir
  1946. /* $A2 */ .word ldx_imm, imm
  1947. /* $A3 */ .word 0, 0
  1948. /* $A4 */ .word ldy, zp
  1949. /* $A5 */ .word lda, zp
  1950. /* $A6 */ .word ldx, zp
  1951. /* $A7 */ .word 0, 0
  1952. /* $A8 */ .word tay, tay
  1953. /* $A9 */ .word lda_imm, imm
  1954. /* $AA */ .word tax, tax
  1955. /* $AB */ .word 0, 0
  1956. /* $AC */ .word ldy, abs
  1957. /* $AD */ .word lda, abs
  1958. /* $AE */ .word ldx, abs
  1959. /* $AF */ .word 0, 0
  1960. /* $B0 */ .word bcs, bcs
  1961. /* $B1 */ .word lda, dind
  1962. /* $B2 */ .word 0, 0
  1963. /* $B3 */ .word 0, 0
  1964. /* $B4 */ .word ldy, izx
  1965. /* $B5 */ .word lda, izx
  1966. /* $B6 */ .word ldx, izy
  1967. /* $B7 */ .word 0, 0
  1968. /* $B8 */ .word clv, clv
  1969. /* $B9 */ .word lda, iay
  1970. /* $BA */ .word tsx, tsx
  1971. /* $BB */ .word 0, 0
  1972. /* $BC */ .word ldy, iax
  1973. /* $BD */ .word lda, iax
  1974. /* $BE */ .word ldx, iay
  1975. /* $BF */ .word 0, 0
  1976. /* $C0 */ .word cpy_imm, imm
  1977. /* $C1 */ .word cmp, idir
  1978. /* $C2 */ .word 0, 0
  1979. /* $C3 */ .word 0, 0
  1980. /* $C4 */ .word cpy, zp
  1981. /* $C5 */ .word cmp, zp
  1982. /* $C6 */ .word dec, zp
  1983. /* $C7 */ .word 0, 0
  1984. /* $C8 */ .word iny, iny
  1985. /* $C9 */ .word cmp_imm, imm
  1986. /* $CA */ .word dex, dex
  1987. /* $CB */ .word 0, 0
  1988. /* $CC */ .word cpy, abs
  1989. /* $CD */ .word cmp, abs
  1990. /* $CE */ .word dec, abs
  1991. /* $CF */ .word 0, 0
  1992. /* $D0 */ .word bne, bne
  1993. /* $D1 */ .word cmp, dind
  1994. /* $D2 */ .word 0, 0
  1995. /* $D3 */ .word 0, 0
  1996. /* $D4 */ .word 0, 0
  1997. /* $D5 */ .word cmp, izx
  1998. /* $D6 */ .word dec, izx
  1999. /* $D7 */ .word 0, 0
  2000. /* $D8 */ .word cld, cld
  2001. /* $D9 */ .word cmp, iay
  2002. /* $DA */ .word 0, 0
  2003. /* $DB */ .word 0, 0
  2004. /* $DC */ .word 0, 0
  2005. /* $DD */ .word cmp, iax
  2006. /* $DE */ .word dec, iax
  2007. /* $DF */ .word 0, 0
  2008. /* $E0 */ .word cpx_imm, imm
  2009. /* $E1 */ .word sbc, idir
  2010. /* $E2 */ .word 0, 0
  2011. /* $E3 */ .word 0, 0
  2012. /* $E4 */ .word cpx, zp
  2013. /* $E5 */ .word sbc, zp
  2014. /* $E6 */ .word inc, zp
  2015. /* $E7 */ .word 0, 0
  2016. /* $E8 */ .word inx, inx
  2017. /* $E9 */ .word sbc_imm, imm
  2018. /* $EA */ .word nop, nop
  2019. /* $EB */ .word 0, 0
  2020. /* $EC */ .word cpx, abs
  2021. /* $ED */ .word sbc, abs
  2022. /* $EE */ .word inc, abs
  2023. /* $EF */ .word 0, 0
  2024. /* $F0 */ .word beq, beq
  2025. /* $F1 */ .word sbc, dind
  2026. /* $F2 */ .word 0, 0
  2027. /* $F3 */ .word 0, 0
  2028. /* $F4 */ .word 0, 0
  2029. /* $F5 */ .word sbc, izx
  2030. /* $F6 */ .word inc, izx
  2031. /* $F7 */ .word 0, 0
  2032. /* $F8 */ .word sed, sed
  2033. /* $F9 */ .word sbc, iay
  2034. /* $FA */ .word 0, 0
  2035. /* $FB */ .word 0, 0
  2036. /* $FC */ .word 0, 0
  2037. /* $FD */ .word sbc, iax
  2038. /* $FE */ .word inc, iax
  2039. /* $FF */ .word 0, 0
  2040.  
  2041. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2042. # pointers to rodata strings (to print instructions on debugging)
  2043. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2044.  
  2045. .if debug_enabled
  2046. str:
  2047. /* $00 */ .word _brk, _imp
  2048. /* $01 */ .word _ora, _idir
  2049. /* $02 */ .word 0, 0
  2050. /* $03 */ .word 0, 0
  2051. /* $04 */ .word 0, 0
  2052. /* $05 */ .word _ora, _zp
  2053. /* $06 */ .word _asl, _zp
  2054. /* $07 */ .word 0, 0
  2055. /* $08 */ .word _php, _imp
  2056. /* $09 */ .word _ora, _imm
  2057. /* $0A */ .word _asl, _acc
  2058. /* $0B */ .word 0, 0
  2059. /* $0C */ .word 0, 0
  2060. /* $0D */ .word _ora, _abs
  2061. /* $0E */ .word _asl, _abs
  2062. /* $0F */ .word 0, 0
  2063. /* $10 */ .word _bpl, _rel
  2064. /* $11 */ .word _ora, _dind
  2065. /* $12 */ .word 0, 0
  2066. /* $13 */ .word 0, 0
  2067. /* $14 */ .word 0, 0
  2068. /* $15 */ .word _ora, _izx
  2069. /* $16 */ .word _asl, _izx
  2070. /* $17 */ .word 0, 0
  2071. /* $18 */ .word _clc, _imp
  2072. /* $19 */ .word _ora, _iay
  2073. /* $1A */ .word 0, 0
  2074. /* $1B */ .word 0, 0
  2075. /* $1C */ .word 0, 0
  2076. /* $1D */ .word _ora, _iax
  2077. /* $1E */ .word _asl, _iax
  2078. /* $1F */ .word 0, 0
  2079. /* $20 */ .word _jsr, _abs
  2080. /* $21 */ .word _and, _idir
  2081. /* $22 */ .word 0, 0
  2082. /* $23 */ .word 0, 0
  2083. /* $24 */ .word _bit, _zp
  2084. /* $25 */ .word _and, _zp
  2085. /* $26 */ .word _rol, _zp
  2086. /* $27 */ .word 0, 0
  2087. /* $28 */ .word _plp, _imp
  2088. /* $29 */ .word _and, _imm
  2089. /* $2A */ .word _rol, _acc
  2090. /* $2B */ .word 0, 0
  2091. /* $2C */ .word _bit, _abs
  2092. /* $2D */ .word _and, _abs
  2093. /* $2E */ .word _rol, _abs
  2094. /* $2F */ .word 0, 0
  2095. /* $30 */ .word _bmi, _rel
  2096. /* $31 */ .word _and, _dind
  2097. /* $32 */ .word 0, 0
  2098. /* $33 */ .word 0, 0
  2099. /* $34 */ .word 0, 0
  2100. /* $35 */ .word _and, _izx
  2101. /* $36 */ .word _rol, _izx
  2102. /* $37 */ .word 0, 0
  2103. /* $38 */ .word _sec, _imp
  2104. /* $39 */ .word _and, _iay
  2105. /* $3A */ .word 0, 0
  2106. /* $3B */ .word 0, 0
  2107. /* $3C */ .word 0, 0
  2108. /* $3D */ .word _and, _iax
  2109. /* $3E */ .word _rol, _iax
  2110. /* $3F */ .word 0, 0
  2111. /* $40 */ .word _rti, _imp
  2112. /* $41 */ .word _eor, _idir
  2113. /* $42 */ .word 0, 0
  2114. /* $43 */ .word 0, 0
  2115. /* $44 */ .word 0, 0
  2116. /* $45 */ .word _eor, _zp
  2117. /* $46 */ .word _lsr, _zp
  2118. /* $47 */ .word 0, 0
  2119. /* $48 */ .word _pha, _imp
  2120. /* $49 */ .word _eor, _imm
  2121. /* $4A */ .word _lsr, _acc
  2122. /* $4B */ .word 0, 0
  2123. /* $4C */ .word _jmp, _abs
  2124. /* $4D */ .word _eor, _abs
  2125. /* $4E */ .word _lsr, _abs
  2126. /* $4F */ .word 0, 0
  2127. /* $50 */ .word _bvc, _rel
  2128. /* $51 */ .word _eor, _dind
  2129. /* $52 */ .word 0, 0
  2130. /* $53 */ .word 0, 0
  2131. /* $54 */ .word 0, 0
  2132. /* $55 */ .word _eor, _izx
  2133. /* $56 */ .word _lsr, _izx
  2134. /* $57 */ .word 0, 0
  2135. /* $58 */ .word _cli, _imp
  2136. /* $59 */ .word _eor, _iay
  2137. /* $5A */ .word 0, 0
  2138. /* $5B */ .word 0, 0
  2139. /* $5C */ .word 0, 0
  2140. /* $5D */ .word _eor, _iax
  2141. /* $5E */ .word _lsr, _iax
  2142. /* $5F */ .word 0, 0
  2143. /* $60 */ .word _rts, _imp
  2144. /* $61 */ .word _adc, _idir
  2145. /* $62 */ .word 0, 0
  2146. /* $63 */ .word 0, 0
  2147. /* $64 */ .word 0, 0
  2148. /* $65 */ .word _adc, _zp
  2149. /* $66 */ .word _ror, _zp
  2150. /* $67 */ .word 0, 0
  2151. /* $68 */ .word _pla, _imp
  2152. /* $69 */ .word _adc, _imm
  2153. /* $6A */ .word _ror, _acc
  2154. /* $6B */ .word 0, 0
  2155. /* $6C */ .word _jmp, _absd
  2156. /* $6D */ .word _adc, _abs
  2157. /* $6E */ .word _ror, _abs
  2158. /* $6F */ .word 0, 0
  2159. /* $70 */ .word _bvs, _rel
  2160. /* $71 */ .word _adc, _dind
  2161. /* $72 */ .word 0, 0
  2162. /* $73 */ .word 0, 0
  2163. /* $74 */ .word 0, 0
  2164. /* $75 */ .word _adc, _izx
  2165. /* $76 */ .word _ror, _izx
  2166. /* $77 */ .word 0, 0
  2167. /* $78 */ .word _sei, _imp
  2168. /* $79 */ .word _adc, _iay
  2169. /* $7A */ .word 0, 0
  2170. /* $7B */ .word 0, 0
  2171. /* $7C */ .word 0, 0
  2172. /* $7D */ .word _adc, _iax
  2173. /* $7E */ .word _ror, _iax
  2174. /* $7F */ .word 0, 0
  2175. /* $80 */ .word 0, 0
  2176. /* $81 */ .word _sta, _idir
  2177. /* $82 */ .word 0, 0
  2178. /* $83 */ .word 0, 0
  2179. /* $84 */ .word _sty, _zp
  2180. /* $85 */ .word _sta, _zp
  2181. /* $86 */ .word _stx, _zp
  2182. /* $87 */ .word 0, 0
  2183. /* $88 */ .word _dey, _imp
  2184. /* $89 */ .word 0, 0
  2185. /* $8A */ .word _txa, _imp
  2186. /* $8B */ .word 0, 0
  2187. /* $8C */ .word _sty, _abs
  2188. /* $8D */ .word _sta, _abs
  2189. /* $8E */ .word _stx, _abs
  2190. /* $8F */ .word 0, 0
  2191. /* $90 */ .word _bcc, _rel
  2192. /* $91 */ .word _sta, _dind
  2193. /* $92 */ .word 0, 0
  2194. /* $93 */ .word 0, 0
  2195. /* $94 */ .word _sty, _izx
  2196. /* $95 */ .word _sta, _izx
  2197. /* $96 */ .word _stx, _izy
  2198. /* $97 */ .word 0, 0
  2199. /* $98 */ .word _tya, _imp
  2200. /* $99 */ .word _sta, _iay
  2201. /* $9A */ .word _txs, _imp
  2202. /* $9B */ .word 0, 0
  2203. /* $9C */ .word 0, 0
  2204. /* $9D */ .word _sta, _iax
  2205. /* $9E */ .word 0, 0
  2206. /* $9F */ .word 0, 0
  2207. /* $A0 */ .word _ldy, _imm
  2208. /* $A1 */ .word _lda, _idir
  2209. /* $A2 */ .word _ldx, _imm
  2210. /* $A3 */ .word 0, 0
  2211. /* $A4 */ .word _ldy, _zp
  2212. /* $A5 */ .word _lda, _zp
  2213. /* $A6 */ .word _ldx, _zp
  2214. /* $A7 */ .word 0, 0
  2215. /* $A8 */ .word _tay, _imp
  2216. /* $A9 */ .word _lda, _imm
  2217. /* $AA */ .word _tax, _imp
  2218. /* $AB */ .word 0, 0
  2219. /* $AC */ .word _ldy, _abs
  2220. /* $AD */ .word _lda, _abs
  2221. /* $AE */ .word _ldx, _abs
  2222. /* $AF */ .word 0, 0
  2223. /* $B0 */ .word _bcs, _rel
  2224. /* $B1 */ .word _lda, _dind
  2225. /* $B2 */ .word 0, 0
  2226. /* $B3 */ .word 0, 0
  2227. /* $B4 */ .word _ldy, _izx
  2228. /* $B5 */ .word _lda, _izx
  2229. /* $B6 */ .word _ldx, _izy
  2230. /* $B7 */ .word 0, 0
  2231. /* $B8 */ .word _clv, _imp
  2232. /* $B9 */ .word _lda, _iay
  2233. /* $BA */ .word _tsx, _imp
  2234. /* $BB */ .word 0, 0
  2235. /* $BC */ .word _ldy, _iax
  2236. /* $BD */ .word _lda, _iax
  2237. /* $BE */ .word _ldx, _iay
  2238. /* $BF */ .word 0, 0
  2239. /* $C0 */ .word _cpy, _imm
  2240. /* $C1 */ .word _cmp, _idir
  2241. /* $C2 */ .word 0, 0
  2242. /* $C3 */ .word 0, 0
  2243. /* $C4 */ .word _cpy, _zp
  2244. /* $C5 */ .word _cmp, _zp
  2245. /* $C6 */ .word _dec, _zp
  2246. /* $C7 */ .word 0, 0
  2247. /* $C8 */ .word _iny, _imp
  2248. /* $C9 */ .word _cmp, _imm
  2249. /* $CA */ .word _dex, _imp
  2250. /* $CB */ .word 0, 0
  2251. /* $CC */ .word _cpy, _abs
  2252. /* $CD */ .word _cmp, _abs
  2253. /* $CE */ .word _dec, _abs
  2254. /* $CF */ .word 0, 0
  2255. /* $D0 */ .word _bne, _rel
  2256. /* $D1 */ .word _cmp, _dind
  2257. /* $D2 */ .word 0, 0
  2258. /* $D3 */ .word 0, 0
  2259. /* $D4 */ .word 0, 0
  2260. /* $D5 */ .word _cmp, _izx
  2261. /* $D6 */ .word _dec, _izx
  2262. /* $D7 */ .word 0, 0
  2263. /* $D8 */ .word _cld, _imp
  2264. /* $D9 */ .word _cmp, _iay
  2265. /* $DA */ .word 0, 0
  2266. /* $DB */ .word 0, 0
  2267. /* $DC */ .word 0, 0
  2268. /* $DD */ .word _cmp, _iax
  2269. /* $DE */ .word _dec, _iax
  2270. /* $DF */ .word 0, 0
  2271. /* $E0 */ .word _cpx, _imm
  2272. /* $E1 */ .word _sbc, _idir
  2273. /* $E2 */ .word 0, 0
  2274. /* $E3 */ .word 0, 0
  2275. /* $E4 */ .word _cpx, _zp
  2276. /* $E5 */ .word _sbc, _zp
  2277. /* $E6 */ .word _inc, _zp
  2278. /* $E7 */ .word 0, 0
  2279. /* $E8 */ .word _inx, _imp
  2280. /* $E9 */ .word _sbc, _imm
  2281. /* $EA */ .word _nop, _imp
  2282. /* $EB */ .word 0, 0
  2283. /* $EC */ .word _cpx, _abs
  2284. /* $ED */ .word _sbc, _abs
  2285. /* $EE */ .word _inc, _abs
  2286. /* $EF */ .word 0, 0
  2287. /* $F0 */ .word _beq, _rel
  2288. /* $F1 */ .word _sbc, _dind
  2289. /* $F2 */ .word 0, 0
  2290. /* $F3 */ .word 0, 0
  2291. /* $F4 */ .word 0, 0
  2292. /* $F5 */ .word _sbc, _izx
  2293. /* $F6 */ .word _inc, _izx
  2294. /* $F7 */ .word 0, 0
  2295. /* $F8 */ .word _sed, _imp
  2296. /* $F9 */ .word _sbc, _iay
  2297. /* $FA */ .word 0, 0
  2298. /* $FB */ .word 0, 0
  2299. /* $FC */ .word 0, 0
  2300. /* $FD */ .word _sbc, _iax
  2301. /* $FE */ .word _inc, _iax
  2302. /* $FF */ .word 0, 0
  2303. .endif
  2304.  
  2305. ###################################################
  2306. # SECTION: DATA #
  2307. ###################################################
  2308.  
  2309. .data
  2310.  
  2311. # >>>>>>>>>>>>>>>>>>
  2312. # debugger variables
  2313. # >>>>>>>>>>>>>>>>>>
  2314.  
  2315. .if debug_enabled
  2316. cur_step: .word 0
  2317. .endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement