; v_scan 6502 assembler subroutine for

; Optical Character Recognition

; Robin Broad

; This program inputs 16 bits of data from the data stream

; and displays the resulting two bytes on the screen

; Trigger pulse on CA1, data bit on PRA0

; data stored in byte1(bottom of image) and byte 2

;

        .OR $0800       program origin

DDRA    .EQ $C403       data direction register

DDRB    .EQ $C402

PRA     .EQ $C401       peripheral register

PRB     .EQ $C400

PCR     .EQ $C40C       peripheral control register

IFR     .EQ $C40D       interrupt flag register

BYTE1   .EQ $1000       bottom half of image

BYTE2   .EQ $1001       top half of image

PRBYTE  .EQ $FDDA       prints contents of accumulator A on the screen

CROUT   .EQ $FD8E       sends a carriage return to the screen

;

START   LDA #$01        IFR1 will be set by 0 to 1 transition

        STA PCR

        LDA #$00        PRA0(data) and PRA1(spare) inputs

        STA DDRA

        LDA #$FF

        STA DDRB        B-side all outputs

VSCAN   LDA PRA         dummy read makes sure that the flag is clear

        LDX #$10        data bit counter set to 16

        LDA #$02        look for CA1 interrupt flag

WAIT    BIT IFR         (Z flag is set to zero if they are not the same)

        BEQ WAIT        wait for the CA1 transition

BTREAD  LDA PRA         look at the data lines

        LSR             put the data bit into the carry flag

        ROL BYTE2       shift the data into the LHS of the two bytes

        ROL BYTE1

        DEX             decrement counter

        BNE BTREAD      branch back unril 16 bits have been read in

        JSR CROUT       carriage return on screen

        LDA BYTE1       displays the answer for byte1 on the screen

        JSR PRBYTE              

        LDA BYTE2       diplays byte2 on the screen

        JSR PRBYTE

        BCC VSCAN       repeat the process forever

        BCS VSCAN

 

; Robin Broad: 6502 assembler