read.s 762 B

12345678910111213141516171819202122232425262728293031323334353637
  1. .define Mread
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine reads characters from the standard input.
  8. ! It ignores the filedes.
  9. ! It reads atmost 255 characters. So the runtime system must
  10. ! provide a way of dealing with this.
  11. ! The subroutine RDCH is a special one provided by the BBC
  12. ! microcomputer.
  13. Mread:
  14. jsr Pop ! ignore filedescriptor
  15. jsr Pop ! bufptr
  16. stx ADDR ! address of character buffer (lowbyte)
  17. sta ADDR+1 ! address of character buffer (highbyte)
  18. jsr Pop ! number of characters
  19. ldy #0 ! <= 255
  20. inx
  21. 1: jsr RDCH ! read a character from the current inputstream
  22. bcs 8f
  23. sta (ADDR),y
  24. iny
  25. dex
  26. bne 1b
  27. 8: tya
  28. tax
  29. lda #0
  30. jsr Push ! number of characters red.
  31. tax ! report a succesfull read.
  32. rts