z80.asm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. ; spectrum stuff
  2. ; adresses
  3. z80_regs equ $00
  4. z80_f equ $00
  5. z80_a equ $01
  6. z80_af equ z80_f
  7. z80_c equ $02
  8. z80_b equ $03
  9. z80_bc equ z80_c
  10. z80_e equ $04
  11. z80_d equ $05
  12. z80_de equ z80_e
  13. z80_l equ $06
  14. z80_h equ $07
  15. z80_hl equ z80_l
  16. z80_ix equ $08
  17. z80_iy equ $0a
  18. z80_fp equ $0c
  19. z80_ap equ $0d
  20. z80_cp equ $0e
  21. z80_bp equ $0f
  22. z80_bcp equ z80_cp
  23. z80_ep equ $10
  24. z80_dp equ $11
  25. z80_dep equ z80_ep
  26. z80_lp equ $12
  27. z80_hp equ $13
  28. z80_hlp equ z80_lp
  29. z80_sp equ $14
  30. z80_reg0 equ $16
  31. z80_reg1 equ $17
  32. z80_reg2 equ $18
  33. z80_reg3 equ $19
  34. z80_reg4 equ $1a
  35. z80_reg5 equ $1b
  36. z80_reg6 equ $1c
  37. z80_reg7 equ $1d
  38. z80_reg8 equ $1e
  39. z80_reg9 equ $1f
  40. _bitmem0 equ $20
  41. _bitmem1 equ $21
  42. _bitmem2 equ $22
  43. _bitmem3 equ $23
  44. _bitmem4 equ $24
  45. _bitmem5 equ $25
  46. _bitmem6 equ $26
  47. _bitmem7 equ $27
  48. z80vm_fetch equ $28 ; 9 bytes
  49. z80_pc equ $29
  50. z80vm_reg0 equ $31
  51. z80vm_reg1 equ $32
  52. z80vm_s equ $33
  53. z80_free_zp equ $38
  54. ; constants
  55. _bitvalue0 equ $01
  56. _bitvalue1 equ $02
  57. _bitvalue2 equ $04
  58. _bitvalue3 equ $08
  59. _bitvalue4 equ $10
  60. _bitvalue5 equ $20
  61. _bitvalue6 equ $40
  62. _bitvalue7 equ $80
  63. _notbitvalue0 equ $fe
  64. _notbitvalue1 equ $fd
  65. _notbitvalue2 equ $fb
  66. _notbitvalue3 equ $f7
  67. _notbitvalue4 equ $ef
  68. _notbitvalue5 equ $df
  69. _notbitvalue6 equ $bf
  70. _notbitvalue7 equ $7f
  71. add_hl_bc:
  72. lda z80_l
  73. clc
  74. adc z80_c
  75. sta z80_l
  76. lda z80_h
  77. adc z80_b
  78. sta z80_h
  79. rts
  80. ;add_hl_sp:
  81. ; lda z80_l
  82. ; clc
  83. ; adc z80_sp
  84. ; sta z80_l
  85. ; lda z80_h
  86. ; adc z80_sp+1
  87. ; sta z80_h
  88. ; rts
  89. add_ix_de:
  90. lda z80_ix
  91. clc
  92. adc z80_e
  93. sta z80_ix
  94. lda z80_ix+1
  95. adc z80_d
  96. sta z80_ix+1
  97. rts
  98. add_ix_bc:
  99. lda z80_ix
  100. clc
  101. adc z80_c
  102. sta z80_ix
  103. lda z80_ix+1
  104. adc z80_b
  105. sta z80_ix+1
  106. rts
  107. add_iy_de:
  108. lda z80_iy
  109. clc
  110. adc z80_e
  111. sta z80_iy
  112. lda z80_iy+1
  113. adc z80_d
  114. sta z80_iy+1
  115. rts
  116. add_hl_de:
  117. clc
  118. adc_hl_de:
  119. lda z80_l
  120. adc z80_e
  121. sta z80_l
  122. lda z80_h
  123. adc z80_d
  124. sta z80_h
  125. rts
  126. ;add_iy_bc:
  127. ; lda z80_iy
  128. ; clc
  129. ; adc z80_c
  130. ; sta z80_iy
  131. ; lda z80_iy+1
  132. ; adc z80_b
  133. ; sta z80_iy+1
  134. ; rts
  135. sbc_hl_de:
  136. lda z80_l
  137. sbc z80_e
  138. sta z80_l
  139. lda z80_h
  140. sbc z80_d
  141. sta z80_h
  142. rts
  143. ;sbc_hl_bc:
  144. ; lda z80_l
  145. ; sbc z80_c
  146. ; sta z80_l
  147. ; lda z80_h
  148. ; sbc z80_b
  149. ; sta z80_h
  150. ; rts
  151. ;cmp_hl_bc:
  152. ; lda z80_l
  153. ; cmp z80_c
  154. ; bne cmp_hl_bc_end
  155. ; lda z80_h
  156. ; cmp z80_b
  157. ;cmp_hl_bc_end:
  158. ; rts
  159. ;cmp_iy_ix:
  160. ; lda z80_iy
  161. ; cmp z80_ix
  162. ; bne cmp_iy_ix_end
  163. ; lda z80_iy+1
  164. ; cmp z80_ix+1
  165. ;cmp_iy_ix_end:
  166. ; rts
  167. dec_hl:
  168. lda z80_l
  169. bne dec_hl_no_dec_h
  170. dec z80_h
  171. dec_hl_no_dec_h:
  172. dec z80_l
  173. rts
  174. ;dec_ix:
  175. ; lda z80_ix
  176. ; bne dec_ix_no_dec_h
  177. ; dec z80_ix+1
  178. ;dec_ix_no_dec_h:
  179. ; dec z80_ix
  180. ; rts
  181. dec_bc:
  182. lda z80_c
  183. bne dec_bc_no_dec_b
  184. dec z80_b
  185. dec_bc_no_dec_b:
  186. dec z80_c
  187. rts
  188. dec_de:
  189. lda z80_e
  190. bne dec_de_no_dec_d
  191. dec z80_d
  192. dec_de_no_dec_d:
  193. dec z80_e
  194. rts
  195. ;dec_sp:
  196. ; lda z80_sp
  197. ; bne dec_sp_no_dec_sp_1
  198. ; dec z80_sp+1
  199. ;dec_sp_no_dec_sp_1:
  200. ; dec z80_sp
  201. ; rts
  202. ex_de_hl:
  203. lda z80_e
  204. ldx z80_l
  205. stx z80_e
  206. sta z80_l
  207. lda z80_d
  208. ldx z80_h
  209. stx z80_d
  210. sta z80_h
  211. rts
  212. ld_hl_de:
  213. lda z80_e
  214. sta z80_l
  215. lda z80_d
  216. sta z80_h
  217. rts
  218. ;exx:
  219. ; ldx #$00
  220. ;exx_loop:
  221. ; lda z80_c,x
  222. ; ldy z80_cp,x
  223. ; sty z80_c,x
  224. ; sta z80_cp,x
  225. ; inx
  226. ; cpx #$06
  227. ; bne exx_loop
  228. ; rts
  229. exx:
  230. lda z80_c
  231. ldx z80_cp
  232. stx z80_c
  233. sta z80_cp
  234. lda z80_b
  235. ldx z80_bp
  236. stx z80_b
  237. sta z80_bp
  238. lda z80_e
  239. ldx z80_ep
  240. stx z80_e
  241. sta z80_ep
  242. lda z80_d
  243. ldx z80_dp
  244. stx z80_d
  245. sta z80_dp
  246. lda z80_l
  247. ldx z80_lp
  248. stx z80_l
  249. sta z80_lp
  250. lda z80_h
  251. ldx z80_hp
  252. stx z80_h
  253. sta z80_hp
  254. rts
  255. ;ex_sp_hl:
  256. ; tsx
  257. ; lda $0103,x
  258. ; ldy z80_h
  259. ; sta z80_h
  260. ; tya
  261. ; sta $0103,x
  262. ; lda $0104,x
  263. ; ldy z80_l
  264. ; sta z80_l
  265. ; tya
  266. ; sta $104,x
  267. ; rts
  268. ldir:
  269. ldy #$00 ;- ldir
  270. ldx z80_b
  271. beq ldir_last_page
  272. ldir_loop:
  273. lda (z80_hl),y
  274. sta (z80_de),y
  275. iny
  276. bne ldir_loop
  277. inc z80_h
  278. inc z80_d
  279. dex
  280. bne ldir_loop
  281. ldir_last_page:
  282. lda z80_c
  283. beq ldir_end
  284. ldir_last_page_loop:
  285. lda (z80_hl),y
  286. sta (z80_de),y
  287. iny
  288. cpy z80_c
  289. bne ldir_last_page_loop
  290. ldir_end:
  291. stx z80_c
  292. stx z80_b
  293. tya
  294. clc
  295. adc z80_l
  296. sta z80_l
  297. bcc *+4
  298. inc z80_h
  299. tya
  300. clc
  301. adc z80_e
  302. sta z80_e
  303. bcc *+4
  304. inc z80_d
  305. rts
  306. lddr:
  307. ldy #$00
  308. lddr_loop:
  309. lda (z80_hl),y
  310. sta (z80_de),y
  311. jsr dec_hl
  312. jsr dec_de
  313. jsr dec_bc
  314. lda z80_b
  315. ora z80_c
  316. bne lddr_loop
  317. rts
  318. ;ei:
  319. ; rts
  320. di:
  321. rts
  322. ;ccf:
  323. ; bcc ccf_setc
  324. ; clc
  325. ; rts
  326. ;ccf_setc:
  327. ; sec
  328. ; rts
  329. ;ld_de_hl
  330. ; lda z80_l
  331. ; sta z80_e
  332. ; lda z80_h
  333. ; sta z80_d
  334. ; rts
  335. z80_init:
  336. ldx #$00
  337. lda #$01
  338. z80_init_loop:
  339. sta _bitmem0,x
  340. inx
  341. asl @
  342. bne z80_init_loop
  343. rts