los.s 607 B

123456789101112131415161718192021222324252627282930313233343536
  1. .define .los
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. .los:
  8. pop ix ! save return address
  9. pop de ! number of bytes to transfer
  10. pop hl ! address of lowest byte
  11. add hl,de
  12. dec hl ! address of highest byte
  13. srl d ! divide de by 2
  14. rr e
  15. jr nc,1f ! see if de was odd
  16. ld a,e ! yes, then it must be 1
  17. or d
  18. jr nz,.trp.z ! no, error
  19. ld e,(hl) ! pack 1 byte into integer
  20. push de
  21. jp (ix) ! return
  22. 1:
  23. ld b,(hl) ! get 2 bytes
  24. dec hl
  25. ld c,(hl)
  26. dec hl
  27. push bc ! put them on stack, most
  28. ! significant byte first
  29. dec de
  30. ld a,d
  31. or e
  32. jr nz,1b ! done ?
  33. jp (ix) ! yes, return