Advertisement
Guest User

Untitled

a guest
Apr 12th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 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 variables
  13. MODE = $0300
  14. HOLD = $0301
  15. COUNT = $0302
  16.  
  17. .org $8000
  18.  
  19. reset:
  20. sei ;disable interrupts
  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 continuous mode
  28.  
  29. lda #%11000000
  30. sta IER ; enable timer 1 interrupts
  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 interrupts
  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. rti
  51. irq:
  52. pha
  53. bit HOLD
  54. bne slow ; jump to slow if HOLD is not zero
  55.  
  56. lda COUNT ; load count into a register
  57.  
  58. bit MODE
  59. bmi invert ; jump to invert if MODE bit 7 is a 1
  60.  
  61. inc ; increment the counter
  62. jmp finish
  63.  
  64. invert:
  65. dec ; decrement the counter
  66.  
  67. finish:
  68. beq switch ; if the counter is now 0, jump to switch
  69. sta PORTA ; output the counter to port A LEDs
  70. sta COUNT ; save new counter value
  71. jmp exit_irq_hold
  72.  
  73. switch:
  74. sta COUNT ; save counter without outputting
  75. lda #%10000000
  76. eor MODE ; flip bit 7 of MODE
  77. sta MODE ; save new MODE value
  78.  
  79. exit_irq_hold:
  80. lda #$02
  81. sta HOLD ; save a 2 into HOLD
  82. jmp exit_irq
  83.  
  84. slow:
  85. dec HOLD ; decrement HOLD
  86.  
  87. exit_irq:
  88. bit T1CL ; read timer 1 counter low to clear interrupt
  89. pla
  90. rti ; return from interrupt
  91.  
  92. .org $FFFA
  93. .word nmi
  94. .word reset
  95. .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement