inn.s 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. .define Inn
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine checks if a certain bit is set in a set
  8. ! of n bytes on top of the stack.
  9. Inn:
  10. stx ARTH ! save bit number (lowbyte)
  11. sta ARTH+1 ! save bit number (highbyte)
  12. and #0x80
  13. beq 1f
  14. lda #0 ! bit number is negative
  15. sta ARTH+2 ! make it zero
  16. beq 3f
  17. 1: txa
  18. and #0x07 ! get bit number mod 8
  19. tax
  20. lda #1
  21. cpx #0 ! bit number = 0
  22. beq 2f ! no shifting to right place
  23. 1: asl a ! shift left until bit is in place
  24. dex
  25. bne 1b
  26. 2: sta ARTH+2 ! bit is one in place
  27. ldx #3
  28. 1: lsr ARTH+1 ! shift left 3 times bit number (highbyte)
  29. ror ARTH ! shift left 3 times bit number (lowbyte)
  30. dex ! this is bit number div 8
  31. bne 1b ! which is byte number
  32. 3: lda SP+1
  33. ldx SP+2
  34. stx ADDR ! address of the set (lowbyte)
  35. sta ADDR+1 ! address of the set (highbyte)
  36. iny
  37. tya
  38. bne 2f
  39. inc SP+1
  40. 2: clc ! remove the set
  41. adc SP+2
  42. sta SP+2 ! new stackpointer (lowbyte)
  43. lda #0
  44. adc SP+1
  45. sta SP+1 ! new stackpointer (highbyte)
  46. ldy ARTH
  47. lda (ADDR),y ! load the byte in A
  48. bit ARTH+2 ! test bit
  49. bne 1f
  50. 3: lda #0 ! bit is zero
  51. tax
  52. rts
  53. 1: lda #0 ! bit is one
  54. ldx #1
  55. rts