Ben Eater 6502 Kit — Day 22

in Project HOPElast year


The interrupt requests are meant to be shared between several advanced devices. The breadboard 65C02 computer has only one of those: The 65C22 VIA (versatile interface adapter). First we need to attach a button to the VIA and connect to VIAs IRQ-Out with the CPUs IRQ-In. I'll add a 2nd button and keep the NMI button for now:

2nd interrupt button.

Next we need a new IRQ handler. I'm going to write the the program in expandable way that multiple IRQs can be handled. Resulting in another over engineered software.

;   Increment Counter
.proc     Inc_Counter
    INC  Counter   ; 16 bit increment
    BNE  Exit
    INC  Counter + 1
Exit:     RTS

;   NMI (non-maskable interrupt) handler
.proc     Do_NMI
    JSR  Inc_Counter  ; just increment the counter

;   Handle interrupts from VIA
.proc     Do_VIA_IRQ
    LDA  #%00000010  ; Check CA1 interrupt.
    BZE  Next   ; Interrupt wasn't CA1, check next
    JSR  Inc_Counter  ; increment the counter
    BIT  VIA::ORA  ; Clear CA1 interrupt

Next:     PLA     ; No more interrupt sources to check.

;   IRQ (interrupt request) hander
.proc     Do_IRQ
    BPL  Next   ; Interrupt wasn't from VIA, check next
Next:     RTI     ; No more interrupt sources to check.

I first check if the IRQ originates from the VIA, using the BIT operation, and if so call a subroutine for VIA IRQs. I use a subroutine as branch commands can only jump 127 addresses forward and as the program get's more complex I would need to change to JMPs instead.

The VIA itself also has several interrupt sources to next I check if the IRQ came from them CA1 line. The BIT operation can check bit 6 and 7 without the accumulator for bit 1 I need to load the accumulator with the bit I wish to test.

And here the IRQ handler in stunning action.

All wired up and running

This is the last one in the series. Ben Eater went on to creating the worlds worse graphic card. Very interesting watch but too much for me to build.

You find the source code for the program with makefile, linker configuration file, include files and assembler source code on GitLab: 6502Tutorial — Kit/Interrupt/IRQ



Congratulations @krischik! You received a personal badge!

Happy Hive Birthday! You are on the Hive blockchain for 3 years!

You can view your badges on your board and compare yourself to others in the Ranking

Do not miss the last post from @hivebuzz:

The Hive Gamification Proposal #2