Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; set VIA address
- PORTB = $6000
- PORTA = $6001
- DDRB = $6002
- DDRA = $6003
- T1CL = $6004
- T1CH = $6005
- ACR = $600B
- IFR = $600D
- IER = $600E
- ; define variables
- MODE = $0300
- HOLD = $0301
- COUNT = $0302
- .org $8000
- reset:
- sei ;disable interrupts
- lda #$FF
- sta DDRB ; set all port b pins to output
- sta DDRA ; set all port a pins to output
- lda #%01000000
- sta ACR ; enable timer 1 continuous mode
- lda #%11000000
- sta IER ; enable timer 1 interrupts
- stz HOLD ; set hold to 0
- stz MODE ; set mode to 0
- lda #$01
- sta COUNT ; set count to 1
- sta PORTA ; set port a to output 1
- cli ; enable interrupts
- lda #$FF
- sta T1CL ; load timer 1 counter low with 255
- sta T1CH ; load timer 1 counter high with 255, and start the count
- loop:
- ; do nothing loop
- jmp loop
- nmi:
- rti
- irq:
- pha
- bit HOLD
- bne slow ; jump to slow if HOLD is not zero
- lda COUNT ; load count into a register
- bit MODE
- bmi invert ; jump to invert if MODE bit 7 is a 1
- inc ; increment the counter
- jmp finish
- invert:
- dec ; decrement the counter
- finish:
- beq switch ; if the counter is now 0, jump to switch
- sta PORTA ; output the counter to port A LEDs
- sta COUNT ; save new counter value
- jmp exit_irq_hold
- switch:
- sta COUNT ; save counter without outputting
- lda #%10000000
- eor MODE ; flip bit 7 of MODE
- sta MODE ; save new MODE value
- exit_irq_hold:
- lda #$02
- sta HOLD ; save a 2 into HOLD
- jmp exit_irq
- slow:
- dec HOLD ; decrement HOLD
- exit_irq:
- bit T1CL ; read timer 1 counter low to clear interrupt
- pla
- rti ; return from interrupt
- .org $FFFA
- .word nmi
- .word reset
- .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement