        TITLE   '5204 EPROM BURNING ROUTINE'
;
;  THIS PROGRAM DRIVES THE 5204 PROGRAMMER CIRCUIT DESCRIBED
;  IN THE SEPTEMBER 1977 ISSUE OF KILOBAUD MAGAZINE ARTICLE BY
;  JOHN LAABS.  IT IS MORE-OR-LESS A TRANSLATION OF THE PROGRAM
;  THAT APPEARED IN THE ARTICLE, WITH A FEW CHANGES (MOST
;  NOTEABLY THE CHANGE FROM MOS TECHNOLOGY 6502 ASSEMBLY LAN-
;  GUAGE TO INTEL 8080 ASSEMBLY LANGUAGE.
;
;  THIS VERSION DOES NOT PROVIDE FOR THE ENTRY OF AN ADDRESS
;  WITHIN THE EPROM TO BEGIN PROGRAMMING.
;
;
;  DOUGLAS H. QUEBBEMAN
;  2235 LOMBARDY DRIVE
;  JEFFERSONVILLE IN 47130
;  (812) 945-9525
;
;
;
        TITLE   'MACRO DEFINITIONS'
;
;
;  MACRO TO PULSE THE SPECIFIED SIGNAL.
;
PULSE   MACRO   BITS
        MVI     A,BITS
        OUT     PBOUT
        MVI     A,OFF     ;RESTORE ALL BITS TO THEIR 'OFF' VALUE
        OUT     PBOUT
        ENDM
;
;
;  MACRO TO CONTROL THE PGM (PROGRAM) PULSE.
;
PGM     MACRO   SWITCH
        MVI     A,SWITCH
        OUT     PBOUT   ;SEND TO PROM BURNER PORT
        ENDM
;
;
;  MACRO TO DELAY FOR A WHILE.
;  ARGUMENT MUST BE DEFINED IN PROGRAM.
;
DELAY   MACRO   TIME
        MVI     A,TIME/100
DEO DISPLAY MEMO B,12
TLOOP:  MOV     C,B
TIM180: DCR     C
        JNZ     TIM180
        DCR     A
        JNZ     TLOOP
        ENDM
;
;
;  MACRO TO DO DOUBLE SUBTRACTION
;  ON 16-BIT INSIGNED INTEGERS.
;
;  MINU IS MINUEND ADDRESS.
;  SUBT IS SUBTRAHEND LOCATION.
;
;  RESULT IS GENERATED IN REGISTERS H&L.
;
;  REGISTERS USED:
;  H&L, D&E, ACCUMULATOR. CARRY ALTERED.
;
DSUB    MACRO   MINU,SUBT
        LHLD    MINU
        PUSH    H       ;SET UP PARAMETERS
        LHLD    SUBT
        POP     D
        MOV     A,E
        SUB     L       ;LOW ORDER DIFFERENCE
        MOV     L,A
        MOV     A,D
        SBB     H       ;HIGH ORDER DIFFERENCE
        MOV     H,A     ;VALUE IN H&L
        ENDM
;
;
        TITLE   'INITIALIZTION SECTION'
;
;  THIS PROGRAM IS USED AS A SOLOS CUSTOM COMMAND.
;  THE FORMAT IS:
;     BURN ADR1 ADR2 #CY
;
;  WHERE ADR1 AND ADR2 ARE THE STARTING AND ENDING ADDRESSES
;  OF MEMORY TO PROGRAM INTO THE 5204 (<=512) AND #CY IS THE
;  NUMBER OF TIMES TO PROGRAM THE CHIP.
;  32 TIMES IS A RECOMMENDED MINIMUM.
;
;
        ORG     0CA00H
;
;
BURN:   CALL    SCONV   ;GET START ADDRESS
        SHLD    LOWER
        CALL    SCONV   ;GET END ADDRESS
        SHLD    UPPER
        CALL    PSCAN   ;GET # OF TIMES TO PROGRAM
        STA     CYCLE
        DSUB    UPPER,LOWER
        INX     H       ;LENGTH = (END-START) + 1
        MOV     A,H     ;CHECK IF H&L > 512 (5204 PROM CAPACITY)
        CPI     2
        JC      LENOK   ;IF H<2 THEN LENGTH IS OK.
        JNZ     ERR1    ;IF H>2 THEN ERROR
        MOV     A,L     ;HI BYTE OK, CHECK LO BYTE
        ORA     A
        JNZ     ERR1
LENOK   EQU     $
        SHLD    LENGT
;
        TITLE   'MAIN LOOP'
;
;  MAIN LOOP.
;
GO:     CALL    CRLF
        LDA     CYCLE   ;GET CURRENT CYCLE
        CALL    HBOUT   ;PRINT IT WITH A <SPACE>
        CALL    CRLF
        PULSE   ACLR AND DCLR
;
        LHLD    LOWER
        XCHG            ;DATA POINTER TO D&E
        LHLD    LENGT   ;CODE LENGTH TO H&L
;
;
;  HERE, WE WOULD SEND THE STARTING ADDRESS WITHIN THE EPROM
;  TO THE PROGRAMMER (IF THIS OPTION WERE UP).
;
CLADR:  PULSE   ACLK    ;INCREMENT ADDRESS
;
        PULSE   DCLR    ;RESET DATA COUNTER
;
        LDAX    D       ;GET NEXT DATA BYTE
        CMA             ;COMPLEMENT IT
        MOV     C,A     ;PUT IN C FOR COUNT-DOWN
DLOOP:  MOV     A,C
        ORA     A       ;DONE ?
        JZ      D10MS   ;YUP
        PULSE   DCLK    ;CLOCK A DATA BIT OUT TO THE COUNTER
        DCR     C       ;DECREMENT BIT COUNT
        JMP     DLOOP   ;AND CLOCK OUT THE NEXT BIT
;
D10MS:  DELAY   @10MS   ;DELAY 10 MS
;
        PGM     ON      ;TURN ON PGM PULSE
;
        DELAY   @03MS   ;DELAY 3 MS
;
        PGM     OFF     ;TURN PGM PULSE OFF
;
        DCX     H
        INX     D       ;INCREMENT DATA POINTER
        MOV     A,H     ;HAVE WE DONE ALL BYTES?
        ORA     L
        JNZ     CLADR   ;DO NEXT ADDRESS IF NOT DONE
        LDA     CYCLE   ;ANY CYCLES LEFT ?
        DCR     A
        RZ              ;RETURN TO SYSTEM WHEN THROUGH
        STA     CYCLE   ;STORE NEW CYCLE COUNT
        JMP     GO      ;AND DO NEXT CYCLE
;
;
ERR1:   CALL    CRLF
        LXI     H,ERMS1
        MVI     D,MSLN1
        CALL    NLOOP
        RET
;
        TITLE   'CONSTANTS, DATA DEFINITIONS AND STORAGE'
;
;
;  CONSTANTS, DATA DEFINITIONS, AND STORAGE.
;
CYCLE:  DS      1       ;NUMBER OF CYCLES TO PROGRAM
LOWER:  DS      2       ;START OF MEMORY TO 'BURN'
UPPER:  DS      2       ;END OF SAME
LENGT:  DS      2       ;CODE LENGTH
;
ERMS1:  DB      '?BUMTLG BURN MEMORY > 512'
MSLN1   EQU     25
;
PBOUT   EQU     0FDH    ;PROGRAMMER PORT
;
;  PROGRAMMER PORT BIT DEFINITIONS
;
ACLR    EQU     12H
DCLR    EQU     18H
ACLK    EQU     14H
DCLK    EQU     11H
;
ON      EQU     0AH     ;ON VALUE FOR PGM PULSE
OFF     EQU     1AH     ;OFF VALUE FOR PGM PULSE
;
@100US  EQU     100     ;100 MICRO-SECOND DELAY
@10MS   EQU     100*(@100US)
@03MS   EQU     30*(@100US)
;
SCONV   EQU     0C33AH
PSCAN   EQU     0C310H
CRLF    EQU     0C2F9H
HBOUT   EQU     0C3EDH
NLOOP   EQU     0C56AH
;
        END
