sub32.asm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ; SUB32
  2. ; TOP of the stack - DEHL
  3. ; Pops operand out of the stack (CALLEE)
  4. ; and returns result in DEHL
  5. ; Operands come reversed => So we swap then using EX (SP), HL
  6. ;
  7. __SUB32:
  8. lda z80_c ;- exx
  9. ldx z80_cp
  10. stx z80_c
  11. sta z80_cp
  12. lda z80_b
  13. ldx z80_bp
  14. stx z80_b
  15. sta z80_bp
  16. lda z80_e
  17. ldx z80_ep
  18. stx z80_e
  19. sta z80_ep
  20. lda z80_d
  21. ldx z80_dp
  22. stx z80_d
  23. sta z80_dp
  24. lda z80_l
  25. ldx z80_lp
  26. stx z80_l
  27. sta z80_lp
  28. lda z80_h
  29. ldx z80_hp
  30. stx z80_h
  31. sta z80_hp
  32. pla ;- pop bc ; Return address
  33. sta z80_b
  34. pla
  35. sta z80_c
  36. lda z80_c ;- exx
  37. ldx z80_cp
  38. stx z80_c
  39. sta z80_cp
  40. lda z80_b
  41. ldx z80_bp
  42. stx z80_b
  43. sta z80_bp
  44. lda z80_e
  45. ldx z80_ep
  46. stx z80_e
  47. sta z80_ep
  48. lda z80_d
  49. ldx z80_dp
  50. stx z80_d
  51. sta z80_dp
  52. lda z80_l
  53. ldx z80_lp
  54. stx z80_l
  55. sta z80_lp
  56. lda z80_h
  57. ldx z80_hp
  58. stx z80_h
  59. sta z80_hp
  60. tsx ;- ex (sp),hl
  61. lda $0103,x
  62. ldy z80_h
  63. sta z80_h
  64. tya
  65. sta $0103,x
  66. lda $0104,x
  67. ldy z80_l
  68. sta z80_l
  69. tya
  70. sta $104,x
  71. pla ;- pop bc
  72. sta z80_b
  73. pla
  74. sta z80_c
  75. ora z80_a ;- or a
  76. lda z80_l ;- sbc hl,bc
  77. sbc z80_c
  78. sta z80_l
  79. lda z80_h
  80. sbc z80_b
  81. sta z80_h
  82. lda z80_e ;- ex_de_hl
  83. ldx z80_l
  84. stx z80_e
  85. sta z80_l
  86. lda z80_d
  87. ldx z80_h
  88. stx z80_d
  89. sta z80_h
  90. tsx ;- ex (sp),hl
  91. lda $0103,x
  92. ldy z80_h
  93. sta z80_h
  94. tya
  95. sta $0103,x
  96. lda $0104,x
  97. ldy z80_l
  98. sta z80_l
  99. tya
  100. sta $104,x
  101. pla ;- pop bc
  102. sta z80_b
  103. pla
  104. sta z80_c
  105. lda z80_l ;- sbc hl,bc
  106. sbc z80_c
  107. sta z80_l
  108. lda z80_h
  109. sbc z80_b
  110. sta z80_h
  111. lda z80_e ;- ex_de_hl
  112. ldx z80_l
  113. stx z80_e
  114. sta z80_l
  115. lda z80_d
  116. ldx z80_h
  117. stx z80_d
  118. sta z80_h
  119. lda z80_c ;- exx
  120. ldx z80_cp
  121. stx z80_c
  122. sta z80_cp
  123. lda z80_b
  124. ldx z80_bp
  125. stx z80_b
  126. sta z80_bp
  127. lda z80_e
  128. ldx z80_ep
  129. stx z80_e
  130. sta z80_ep
  131. lda z80_d
  132. ldx z80_dp
  133. stx z80_d
  134. sta z80_dp
  135. lda z80_l
  136. ldx z80_lp
  137. stx z80_l
  138. sta z80_lp
  139. lda z80_h
  140. ldx z80_hp
  141. stx z80_h
  142. sta z80_hp
  143. lda z80_c ;- push bc ; Put return address
  144. pha
  145. lda z80_b
  146. pha
  147. lda z80_c ;- exx
  148. ldx z80_cp
  149. stx z80_c
  150. sta z80_cp
  151. lda z80_b
  152. ldx z80_bp
  153. stx z80_b
  154. sta z80_bp
  155. lda z80_e
  156. ldx z80_ep
  157. stx z80_e
  158. sta z80_ep
  159. lda z80_d
  160. ldx z80_dp
  161. stx z80_d
  162. sta z80_dp
  163. lda z80_l
  164. ldx z80_lp
  165. stx z80_l
  166. sta z80_lp
  167. lda z80_h
  168. ldx z80_hp
  169. stx z80_h
  170. sta z80_hp
  171. rts ;- ret