| @@ -0,0 +1,44 @@ | |||
| 1 | + | ; VSYNC interrupt demo. | |
| 2 | + | ; The VDP raises its frame flag 60 times a second. With bit 5 of VDP | |
| 3 | + | ; register 1 set it also pulls the CPU's /IRQ low until $8003 is read. | |
| 4 | + | ; The 3 LEDs show bits 4..6 of a frame counter (about 3.75 Hz binary count). | |
| 5 | + | ; | |
| 6 | + | ; The IRQ line is released a little AFTER the status read (it goes through the | |
| 7 | + | ; I2C expander), so the handler can be entered again with bit 7 clear: always | |
| 8 | + | ; test bit 7 of the status and ignore the interrupt when it is clear. | |
| 9 | + | ||
| 10 | + | .setcpu "65C02" | |
| 11 | + | ||
| 12 | + | frames = $0200 | |
| 13 | + | ||
| 14 | + | .org $8100 | |
| 15 | + | entry: | |
| 16 | + | ldx #$ff | |
| 17 | + | txs | |
| 18 | + | stz frames | |
| 19 | + | lda #$e0 ; R1 = $E0: 16K, display on, IRQ enabled | |
| 20 | + | sta $8003 | |
| 21 | + | lda #$81 ; ... write it to register 1 | |
| 22 | + | sta $8003 | |
| 23 | + | cli | |
| 24 | + | loop: | |
| 25 | + | wai ; sleep until the next interrupt | |
| 26 | + | jmp loop | |
| 27 | + | ||
| 28 | + | irq: | |
| 29 | + | pha | |
| 30 | + | lda $8003 ; read status: clears the flag, releases /IRQ | |
| 31 | + | bpl done ; bit 7 clear: spurious, ignore | |
| 32 | + | inc frames | |
| 33 | + | lda frames | |
| 34 | + | lsr | |
| 35 | + | lsr | |
| 36 | + | lsr | |
| 37 | + | lsr | |
| 38 | + | sta $8000 ; LEDs | |
| 39 | + | done: | |
| 40 | + | pla | |
| 41 | + | rti | |
| 42 | + | ||
| 43 | + | .res $FFFA-* | |
| 44 | + | .word entry, entry, irq ; NMI, RESET, IRQ/BRK | |
revised this gist 2 days ago
·
691bfc7
1 file changed, 44 insertions