sts.s 598 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. .define .sts
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! use trp.z
  8. ! object size given by 2-byte integer on
  9. ! top of stack.
  10. ! parameters:
  11. ! on stack
  12. ! checks if #bytes is even or 1,
  13. ! else traps
  14. .sts:
  15. pop ix ! save return address
  16. pop de ! # bytes to transfer
  17. pop hl ! destination address
  18. srl d ! divide de by 2
  19. rr e
  20. jr nc,1f ! see if it was odd
  21. ld a,e ! yes, must be 1
  22. or d
  23. jr nz,.trp.z ! no, error
  24. pop de ! transfer 1 byte,
  25. ! padded with zeroes
  26. ld (hl),e
  27. jp (ix)
  28. 1:
  29. pop bc
  30. ld (hl), c
  31. inc hl
  32. ld (hl),b
  33. inc hl
  34. dec de
  35. ld a,e
  36. or d
  37. jr nz,1b
  38. jp (ix)