set.s 781 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. .define Set
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine creates a set of n (n <= 256) bytes.
  8. ! In this set a certain bit, which number is in registerpair AX,
  9. ! is set. The rest is zero.
  10. Set:
  11. stx ARTH ! save bitnumber (lowbyte)
  12. sta ARTH+1 ! save bitnumber (highbyte)
  13. jsr Zer ! create n zerobytes
  14. lda ARTH
  15. and #0x07 ! n mod 8 (bitnumber in byte)
  16. tax
  17. lda #1
  18. cpx #0
  19. beq 2f
  20. 1: asl a ! set bit (n mod 8)
  21. dex
  22. bne 1b
  23. 2: sta ARTH+2
  24. ldx #3
  25. 1: lsr ARTH+1 ! shiftright n 3 times (= n div 8)
  26. ror ARTH ! this is the bytenumber
  27. dex
  28. bne 1b
  29. ldy ARTH ! load bytenumber
  30. lda SP+1
  31. ldx SP+2
  32. stx ADDR ! address of set (lowbyte)
  33. sta ADDR+1 ! address of set (highbyte)
  34. lda ARTH+2 ! get bit
  35. sta (ADDR),y ! store byte with bit on
  36. rts