readarc.z80 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;RAM: 21+21n
  2. ;ARC, but no boundary: 114+21n
  3. ;Arc, on two pages: 21n+269
  4. ;Arc, on three pages: 21n+355
  5. or a
  6. jp z,ReadRAM ;different routine in the App
  7. bit 7,h
  8. jp nz,ReadRAM ;different routine in the App
  9. out (6),a
  10. adc hl,bc
  11. ; jr c,read_from_Arc_blocks ;if you need this, you probably need a different routine. this will write on page 0.
  12. jp p,read_from_ARC_noboundary
  13. read_from_Arc_blocks = $-ReadArcData+TSA
  14. ;If we make it here, we know that we cross a page boundary (or in one case, we just reach it and need to return on the next page).
  15. ;We will read in blocks to avoid checking page boundaries
  16. ;To do so, we first read up to 0x8000 - HL bytes
  17. xor a
  18. sbc hl,bc
  19. sub l \ ld l,a
  20. ld a,$80 \ sbc a,h \ ld h,a
  21. ;now we will subtract BC-HL -> BC
  22. ld a,c \ sub l \ ld c,a
  23. ld a,b \ sbc a,h \ ld b,a
  24. push bc
  25. ld b,h
  26. ld c,l
  27. xor a \ sub l \ ld l,a
  28. ld a,$80 \ sbc a,h \ ld h,a
  29. ;now we read the first block
  30. block_loop = $-ReadArcData+TSA
  31. ldir
  32. ;now we increment the page and continue reading from $4000
  33. in a,(6)
  34. inc a
  35. out (6),a
  36. ld h,40h
  37. pop bc
  38. ;if BC<$4000, just LDIR the rest
  39. ld a,b
  40. sub h
  41. jr c,read_from_RAM
  42. ld b,a
  43. push bc
  44. ld b,h
  45. ld c,l
  46. jp block_loop
  47. read_from_ARC_noboundary = $-ReadArcData+TSA
  48. ; or a ;already reset
  49. sbc hl,bc
  50. read_from_RAM:
  51. ldir
  52. in a,(6)
  53. ld b,a
  54. page_restore = $-ReadArcData+TSA+1
  55. ld a,0
  56. out (6),a
  57. ld a,b
  58. ld b,c
  59. ret