readarc.z80 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. out (6),a
  8. adc hl,bc
  9. ; jr c,read_from_Arc_blocks ;if you need this, you probably need a different routine. this will write on page 0.
  10. jp p,read_from_ARC_noboundary
  11. read_from_Arc_blocks = $-ReadArcData+TSA
  12. ;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).
  13. ;We will read in blocks to avoid checking page boundaries
  14. ;To do so, we first read up to 0x8000 - HL bytes
  15. xor a
  16. sbc hl,bc
  17. sub l \ ld l,a
  18. ld a,$80 \ sbc a,h \ ld h,a
  19. ;now we will subtract BC-HL -> BC
  20. ld a,c \ sub l \ ld c,a
  21. ld a,b \ sbc a,h \ ld b,a
  22. push bc
  23. ld b,h
  24. ld c,l
  25. xor a \ sub l \ ld l,a
  26. ld a,$80 \ sbc a,h \ ld h,a
  27. ;now we read the first block
  28. block_loop = $-ReadArcData+TSA
  29. ldir
  30. ;now we increment the page and continue reading from $4000
  31. in a,(6)
  32. inc a
  33. out (6),a
  34. ld h,40h
  35. pop bc
  36. ;if BC<$4000, just LDIR the rest
  37. ld a,b
  38. sub h
  39. jr c,read_from_RAM
  40. ld b,a
  41. push bc
  42. ld b,h
  43. ld c,l
  44. jp block_loop
  45. read_from_ARC_noboundary = $-ReadArcData+TSA
  46. ; or a ;already reset
  47. sbc hl,bc
  48. read_from_RAM:
  49. ldir
  50. in a,(6)
  51. ld b,a
  52. page_restore = $-ReadArcData+TSA+1
  53. ld a,0
  54. out (6),a
  55. ld a,b
  56. ld b,c
  57. ret