    .equ BUTTONS, 0xff200050
    .equ LOW_DISPLAYS, 0xff200020
    .equ HIGH_DISPLAYS, 0xff200030
    .global _start
    .text
_start:
    li s0, LOW_DISPLAYS
    li s1, BUTTONS
    la s2, patterns
    li s3, 0                  # Initial byte
    li s4, 0                  # Pause flag
    li t0, 15
    sw t0, 12(s1)             # Clear any old captured key edges.
    li t0, HIGH_DISPLAYS
    sw zero, 0(t0)
display:
    andi t0, s3, 15
    srli t1, s3, 4
    add t0, s2, t0
    add t1, s2, t1
    lbu t2, 0(t0)
    lbu t3, 0(t1)
    slli t3, t3, 8
    or t2, t2, t3
    sw t2, 0(s0)
    li t4, 20000000           # Delay-loop iterations
wait_interval:
    addi t4, t4, -1
    bnez t4, wait_interval
    lw t0, 12(s1)
    andi t0, t0, 15
    beqz t0, advance
    sw t0, 12(s1)             # Acknowledge only observed edge bits.
    xori s4, s4, 1
advance:
    bnez s4, display
    addi s3, s3, 1
    andi s3, s3, 15           # TODO: retain a full byte.
    j display

    .section .rodata
patterns:
    .byte 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07
    .byte 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
