;PT3 means Port T bit 3
PTT   equ  $0240
DDRT  equ  $0242
PTP   equ  $0258
DDRP  equ  $025A

      org  $2000
Count rmb  2
SIZE  equ 8
PTTbuf  rmb SIZE
Pt rmb 2
Last  rmb  1

      org  $4000
main  lds  #$4000
      movw #0,Count
      ldx #PTTbuf
      stx  Pt
      ldaa #$FF
      staa Last
      bset DDRP,#$80 ;PP7 heartbeat
      ldaa #$04
      staa DDRT   ;PT3 input PT2 output
      cli
      org *
loop  ldaa PTT    ;all 8 bits of PTT
      anda #$08   ;Bit 3 is In
      eora #$08   ;Bit3 is not(In)
      lsra        ;Bit2 is not(In)
      staa PTT
      bsr  Dump
      ldaa PTP
      eora #$80
      staa PTP
      ldx  Count
      inx
      stx  Count
      bra  loop
Dump  ldx Pt
      cpx #PTTbuf+SIZE
      beq No
      ldaa PTT
      cmpa Last
      beq  No ;if changed
      staa 1,x+
      stx  Pt
      staa Last
No    rts
      org  $fffe
      fdb  main   ;reset vector