
 1000  * DIV16 DEMO
 1010  *SAVE DIV16 DEMO SOURCE
 1020  *--------------------------------
 1030  * DEMO OF BRUN'ING A ML PROG
 1040  * USING DIV16
 1050  *
 1060  * DOS IS DISCONNECTED
 1070  * TO ALLOW I/O WITHOUT
 1080  * DISRUPTING PROPER RETURN
 1090  *--------------------------------
 1100          .OP 65802
 1110          .OR $6A00
 1120  *--------------------------------
 1130  COUT1   .EQ $FDF0    SCREEN OUTPUT
 1140  KEYIN   .EQ $FD1B    KEYBOARD INPUT
 1150  *--------------------------------
 1160  AL      .EQ 0
 1170  AH      .EQ 1
 1180  BL      .EQ 2
 1190  BH      .EQ 3
 1200  DFLG    .EQ 4        DELIMITER FLAG
 1210  GETLN1  .EQ $FD6F    INPUT LINE TO BUFFER
 1220  PRNTAX  .EQ $F941    OUTPUT A,X AS HEX
 1230  COUT    .EQ $FDED    OUTPUT A AS CHAR
 1240  CROUT   .EQ $FD8E    OUTPUT CR
 1250  *--------------------------------
 1260  DEMO
 1270          LDX #0       BEFORE ANY I/O,
 1280  .10     LDA $36,X     DISCONNECT DOS
 1290          PHA           BY PUSHING $36.39
 1300          LDA PTRS,X    ONTO STACK,
 1310          STA $36,X     & REPLACING
 1320          INX           WITH COUT1/KEYIN
 1330          CPX #4 
 1340          BNE .10
 1350   
 1360          JSR CROUT
 1370  .20     JSR GETLN1   INPUT LINE TO BUFFER
 1380          JSR HEXVALS  EXTRACT HEX VALUES
 1390          CPY #1       IF NULL LINE,
 1400          BEQ .80         THEN EXIT
 1410          JSR PROG     DIVIDE
 1420          LDA BH
 1430          LDX BL
 1440          JSR PRNTAX   DISP QUOTIENT
 1450          LDA #","
 1460          JSR COUT     DISP ','
 1470          LDA AH
 1480          LDX AL
 1490          JSR PRNTAX   DISP REMAINDER
 1500          JSR CROUT
 1510          JMP .20
 1520    
 1530  .80     LDX #3       RECONNECT DOS
 1540  .90     PLA           BY PULLING 
 1550          STA $36,X     $36.39 FROM
 1560          DEX           THE STACK.
 1570          BPL .90
 1580          RTS
 1590  *--------------------------------
 1600  * REPLACEMENT I/O POINTERS
 1610  *--------------------------------
 1620  PTRS    .DA COUT1,KEYIN
 1630    
 1640  *--------------------------------
 1650  * READ TWO HEX 16-BIT WORDS
 1660  * FROM INPUT BUFFER. (AFTER WOZ)
 1670  *--------------------------------
 1680  BUFF    .EQ $200
 1690  *--------------------------------
 1700  HEXVALS
 1710          LDY #0       CLEAR BUFFER INDEX
 1720          STY DFLG     CLEAR DELIMITER FLAG
 1730  .10     LDA #0       CLEAR A
 1740          STA AL
 1750          STA AH
 1760  .20     LDA BUFF,Y   GET CHAR FROM BUFFER
 1770          INY
 1780          CMP #$8D     = CR ?
 1790          BNE .30
 1800          RTS
 1810    
 1820  .30     EOR #$B0     CONVERT ASCII TO HEX
 1830          CMP #$0A
 1840          BCC .40      IF 0-9
 1850          ADC #$88
 1860          CMP #$FA
 1870          BCS .40      IF A-F
 1880          LDA DFLG     ELSE ASSUME
 1890          BNE .10       CHAR IS
 1900          LDA AL        A DELIMITER
 1910          STA BL       MOVE A TO B
 1920          LDA AH        IF NOT REPEATED
 1930          STA BH        DELIMITER
 1940          DEC DFLG     SET DELIMITER FLAG
 1950          JMP .10
 1960   
 1970  .40     ASL          SHIFT NIBBLE
 1980          ASL           TO LEFT HAND 
 1990          ASL           SIDE.
 2000          ASL
 2010          LDX #4       & ROL INTO MEMORY
 2020  .50     ASL
 2030          ROL AL
 2040          ROL AH
 2050          DEX
 2060          BNE .50
 2070          STX DFLG     CLEAR DELIMITER FLAG
 2080          JMP .20
 2090  *--------------------------------
 2100  * SUBROUTINE
 2110  *--------------------------------
 2120  PROG    .IN BUTTERILL'S DIVIDE

