Advertisement
iocoder

cpu.s

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