Advertisement
Guest User

Untitled

a guest
Apr 12th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. ; set VIA address
  2. PORTB = $6000
  3. PORTA = $6001
  4. DDRB = $6002
  5. DDRA = $6003
  6. T1CL = $6004
  7. T1CH = $6005
  8. ACR = $600B
  9. IFR = $600D
  10. IER = $600E
  11.  
  12. ; define varuables
  13. MODE = $0300
  14. HOLD = $0301
  15. COUNT = $0302
  16.  
  17. .org $8000
  18.  
  19. reset:
  20. sei ;disable interrups
  21.  
  22. lda #$FF
  23. sta DDRB ; set all port b pins to output
  24. sta DDRA ; set all port a pins to output
  25.  
  26. lda #%01000000
  27. sta ACR ; enable timer 1 continuious mode
  28.  
  29. lda #%11000000
  30. sta IER ; enable timer 1 interrups
  31.  
  32. stz HOLD ; set hold to 0
  33. stz MODE ; set mode to 0
  34.  
  35. lda #$01
  36. sta COUNT ; set count to 1
  37. sta PORTA ; set port a to output 1
  38.  
  39. cli ; enable interrups
  40.  
  41. lda #$FF
  42. sta T1CL ; load timer 1 counter low with 255
  43. sta T1CH ; load timer 1 counter high with 255, and start the count
  44.  
  45. loop:
  46. ; do nothing loop
  47. jmp loop
  48.  
  49. nmi:
  50. irq:
  51. bit HOLD
  52. bne slow ; jump to slow if HOLD is not zero
  53.  
  54. lda COUNT ; load count into a register
  55.  
  56. bit MODE
  57. bmi invert ; jump to invert if MODE bit 7 is a 1
  58.  
  59. inc ; incrment the counter
  60. jmp finish
  61.  
  62. invert:
  63. dec ; decroment the counter
  64.  
  65. finish
  66. beq switch ; if the counter is now 0, jump to switch
  67. sta PORTA ; output the counter to port A LEDs
  68. sta COUNT ; save new counter value
  69. jmp exit_irq_hold
  70.  
  71. switch:
  72. sta COUNT ; save counter without outputing
  73. lda #%10000000
  74. eor MODE ; flip bit 7 of MODE
  75. sta MODE ; save new MODE value
  76.  
  77. exit_irq_hold:
  78. lda #$02
  79. sta HOLD ; save a 2 into HOLD
  80. jmp exit_irq
  81.  
  82. slow:
  83. dec HOLD ; decrment HOLD
  84.  
  85. exit_irq:
  86. bit T1CL ; read timer 1 counter low to clear interrupt
  87. rti ; return from interrupt
  88.  
  89. .org $FFFA
  90. .word nmi
  91. .word reset
  92. .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement