*--------------------------------
*              IMAGER
*
*
* IMAGER PRODUCES A HARDCOPY
* IMAGE OF THE APPLE II HIRES
* SCREEN ON APPLE'S IMAGEWRITER
* PRINTER.
*
* PRINTER CARD CAN BE A SUPER SERIAL CARD,
*  OR THE SERIAL PORT OF
* THE APPLE ///.
*
* POKE ZERO-PAGE BYTE 06 WITH SLOT
* NUMBER.  SLOT IS ADJUSTED TO 1
* IF BYTE 6 = 0, 7 IF >7.
*
* SET ZERO-PAGE BYTE 07 TO ONE OF
* THE FOLLOWING VALUES BEFORE EACH
* SCREENDUMP UTILITY CALL:
*   0 - SINGLE-SIZE, WHITE-ON-BLACK
*   1 - BLACK-ON-WHITE
*   2 - DOUBLE-SIZE, WHITE-ON-BLACK
*   3 - BLACK-ON-WHITE
*
*   BIT 0 - WHITE-ON-BLACK/BLACK-ON-WHITE
*   BIT 1 - SINGLE/DOUBLE-SIZED PICTURE
* NOTE THAT BITS ARE ROTATED
*  --> B1,B0 BECOME B7,B6 FOR BIT TEST
*
*   APG, APPLE COMPUTER - AUGUST 1984
*    - R. HOIBERG & M. HELLER
*
*
*--------------------------------
*
*
* ZERO-PAGE DATA -
SLOT EQU 06 ;PARALLEL CARD SLOT
XFRFLGS EQU 07 ; THIS IS THE PARAMETER BYTE...
; THIS CONTAINS THE SIZE/INVERT PRINT OPTIONS
GCHAR EQU 06 ;APPLE DMP GRAPHICS CHAR (1X8 CELL)
BITMASK EQU 08 ;MASKS OFF ALL BUT DESIGNATED BIT IN GR BYTE
TEMP EQU 09 ; DOUBLE-SIZE FLIP-FLOP, NON-ZERO WHEN THE
; BYTE JUST PRINTED ONLY CONTAINS THE TOP
; HALF OF A 1H BY 8V PIXEL AREA.
CSWL EQU $36
WARMSTART EQU $3D0
VDOSIO EQU $BE34
DOSIO EQU $03EA
HINDEX EQU $1B ; THIS COUNTS THE HI-RES VERTICAL BLOCKS AS
; THEY ARE PRINTED (A VERTICAL BLOCK IS
; 7 DOTS (1 BYTE) WIDE BY 8 DOTS TALL).
TBLINDEX EQU $1C ; A POINTER TO THE ADDRESS IN THE TABLE WHICH
; CONTAINS THE BASE ADDRESS OF THE HORIZONTAL
; BLOCK BEING PRINTED (HORZ. BLOCK IS 280 DOTS
; WIDE BY 8 DOTS TALL - BASE ADDRESS IS
; ADDRESS OF UPPER-LEFTMOST DOT).
LASTEMP EQU $CF ; STORES THE VALUE OF TEMP AT THE END OF EVERY
; PRINTER LINE, SO WE HAVE IT LATER
HBASE EQU $19 ; 2-BYTES ($19,$1A) HOLD LOW AND HI BYTES OF
; HI-RES ROW BASE ADDRESS
PPSTAT EQU $C084 ;ADDR OF PARALLEL PRINTER STATUS BYTE
PPDATA EQU $C080 ;ADDR OF PARALLEL PRINTER DATA BYTE
OUTL EQU $FA
OUTH EQU $FB
OFFSET EQU $FC
FINISHED EQU $FF
SIGBYTES EQU $FE *AND $FF
COMBYTE EQU $E74C
BYTE EQU $E74F
SSCDATA EQU $C088
SSCSTAT EQU $C089
SW1 EQU $C081
SSCCOMM EQU $C08A
SSCCONT EQU $C08B
VIDOFF EQU $CFFF ; 80-COL CARD VECTOR
OUTPRT EQU $FE95
SETVID EQU $FE93
APP3ID EQU $FA68
COUT EQU $FDED
SIGBYTE EQU $C00B
;
SIGBYTE2 EQU $C00C
*
*                     >>> CONSTANTS <<<
*
*
HNDXMAX EQU $28 ;$28 BYTES PER HI-RES SCREEN ROW
;
; DMP CONTROL CHARACTERS -
NUL EQU $00 ;1ST XMIT CHAR IN CASE PTR POWERED ON
LF EQU $0A ;LINEFEED
CR EQU $0D ;CARRAIGE RETURN
ESC EQU $1B ;ASCII 'ESCAPE' CHAR
ASCII1 EQU $31
ASCII6 EQU $36
ASCIIA EQU $41 ;ESC A FOR 1/6" LF
ASCIID EQU $44 ;ESC D N1 N0  TO OPEN DIP SWITCH
ASCIIF EQU $46 ;ESC F nnnn FOR ABSOLUTE CURSOR ADDRESSING
ASCIIG EQU $47 ;ESC G nnnn FOR DOT GRAPHICS COLUMNS
ASCIIn EQU $6E ;ESC n FOR EXTENDED (9 CPI) PRINTING
ASCIIT EQU $54 ;ESC T NN FOR NN/144" LF
*
 ORG $1B00
 JMP GrafBas ;ENTRY POINT FOR APPLESOFT BASIC
 JMP GrafML ;MACHINE LANGUAGE ENTRY POINT
;Y REGISTER CONTAINS SLOT
;X REGISTER CONTAINS OPTION
HINDEXL DS 1 ; VT. BLK. OF LEFT SIDE OF IMAGE
HINDEXR DS 1 ; VT. BLK. OF RIGHT SIDE OF IMAGE
PRFLG DS 1 ; MSB SET WHEN PRINTING, CLEAR WHEN SCANNING
BINL DS 1 ; USED BY HEXDEC ROUTINE
BINH DS 1 ; USED BY HEXDEC ROUTINE
MYBUF DS 4 ; USED BY HEXDEC, BKTODOTS ROUTINES
*
GrafML EQU *
 LDA #0
 STA VIDOFF ; RELEASE 80-COL CARD USE OF C800-CA00
 JSR FINDTYPE
 LDA #ESC ; SET UP LEFT-TO-RIGHT PRINTING ONLY
 JSR OUTPUT
 LDA #'>'
 JSR OUTPUT
*                              ;SET UP STATUS AND DATA ADDRESSES
 LDA XFRFLGS ;ADJUST XFROPTION BITS FOR EASIER TESTING
 ROR  ;C:=WHITE-ON-BLACK/BLACK-ON-WHITE
 ROR  ;C:=SINGLE/DOUBLE SIZE
 ROR
 AND #$C0 ;RESET REMAINING BITS
 STA XFRFLGS ;B7,B6:=B1,B0
;
; CLEAR PRINTER BUFFER
 LDA #CR ;CLEAR BUFFER FOR GRAPHICS CHARS
 JSR OUTPUT
;
 LDA #ESC ; SET EXTENDED (9 CPI) MODE FOR 72 DPI
 JSR OUTPUT ; HORIZONTAL RESOLUTION.
 LDA #ASCIIn
 JSR OUTPUT
 LDA #ESC ; ESC T 1 6 --> SET VERTICAL LINE FEED FOR
 JSR OUTPUT ; 16/144", FOR 72 DPI VERTICAL RESOLUTION.
 LDA #ASCIIT
 JSR OUTPUT
 LDA #ASCII1
 JSR OUTPUT
 LDA #ASCII6
 JSR OUTPUT
;
 LDA #0
 STA TBLINDEX ; INTIALIZE TABLE INDEX TO TOP OF SCREEN
 STA LASTEMP ; INITIALIZE LAST FLIP-FLOP STATUS TO ZERO.
;
; FOR EVERY ROW -
NEWLINE LDA #0
 STA HINDEX ;INIT HIRES ROW BYTE COUNTER
 STA PRFLG ; INITIALIZE PRFLG TO SCAN RATHER THAN PRINT
 LDA #$FF ; INITIALIZE LEFT SIDE OF IMAGE MARKER
 STA HINDEXL
NEWVTBLK LDA #1
 STA BITMASK ;INIT TO MASK OUT ALL BUT BYTE'S
; LEFT-MOST PIXEL
NEWCLMN LDA LASTEMP
NEWCLM2 STA TEMP ; RESTORE TEMP FROM END OF LAST LINE - TELLS
; WHERE WE ARE IN PRESENT SCREEN BYTE
; (AT BEGINNING OF NEW, OR MIDDLE OF LAST).
NEWBYTE LDY TBLINDEX ; GET THE TABLE OFFSET...
 LDA TABLE,Y ; FETCH LOW-ORDER HBASE
 STA HBASE ; STORE IT
 LDA TABLE+1,Y ; FETCH HI-ORDER HBASE
 LDX LASTEMP ; CHECK IF IN MIDDLE OF 1 BY 8 PIXEL BLOCK?
 BEQ NEWBYT0 ; NO, WE DON'T ALTER HI-ORDER HBASE
 CLC  ; YES, IN MIDDLE, SO ADD $10 TO HI-ORDER HBASE
 ADC #$10 ;     SO WE START READING FROM RIGHT PLACE.
NEWBYT0 STA HBASE+1 ; STORE THE HBASE
NEWBYT1 LDA #0
 STA GCHAR ; CLEAR THE BYTE WE'LL SEND TO PRINTER
 LDX #8 ; IF REGULAR SIZE, THERE ARE 8 SCREEN DOTS
 BIT XFRFLGS ; IN EVERY PRINTER BYTE. IF DOUBLE SIZE, THERE
 BPL NEWBIT ; ARE ONLY 4 DOTS/PRINTER BYTE.
 LDX #4
NEWBIT LDY HINDEX ; GET MEM GRAPHICS BYTE INTO ACC, AND STRIP
 LDA (HBASE),Y ; OFF ALL BITS EXCEPT THE ONE CORRESPONDING
 AND BITMASK ; TO DOT WE'RE CHECKING...
 CMP #1 ;C:=1 IF GR BUFFER BIT IS ON
 ROR GCHAR ; PUT CARRY INTO BYTE WE'LL SEND TO PRINTER
 BIT XFRFLGS
 BPL NEWBIT1
 CMP #1 ; REPEAT BIT IF DOUBLE SIZE...
 ROR GCHAR
NEWBIT1 DEX  ; ANOTHER SCRN DOT MOVED INTO GCHAR
NEXTBIT TXA
 BEQ NEXTBYTE ; GCHAR FILLED, SEND AND MOVE ON!
NXTBIT1 LDA HBASE+1 ; GET HIGH-ORDER HIRES ROW BASE
 CLC
 ADC #4 ; ADD 4, SO WE'LL POINT AT NEXT ROW
 STA HBASE+1 ; PUT NEW ROW BASE BACK
 JMP NEWBIT ; GO BACK AND GET NEXT PIXEL DOWN
NEXTBYTE LDA GCHAR
 BIT XFRFLGS
 BVS NXBYT0
 EOR #$FF ; INVERT GR BYTE IF PARAMATER TELLS US TO
 STA GCHAR
NXBYT0 BIT PRFLG ; ARE WE PRINTING, OR JUST SCANNING?
 BPL GOSCAN ; IF SCANNING, GO TO SCAN ROUTINE...
 JSR OUTPUT ; OTHERWISE PRINT THE GR BYTE
 JMP NXTBYTRT
GOSCAN JMP PICSCAN ; SCANNING, JUMP TO CHAR SCAN ROUTINE
NXTBYTRT BIT XFRFLGS ; IF WE'RE DOING REGULAR SIZE, WE DON'T
 BPL NXTBYT2D ; HAVE TO MESS WITH THE FLIP-FLOP...
 BIT PRFLG ; IF NOT PRINTING, DON'T BOTHER SENDING TWICE
 BPL NXTBYT2
 LDA GCHAR
 JSR OUTPUT ; DOUBLE SIZE, SEND COLUMN AGAIN...
NXTBYT2 LDA TEMP ; FOR DOUBLE SIZE, WE XOR THE FLIP-FLOP - IT
 EOR #1 ; BECOMES ONE IF MIDWAY THROUGH 1x8 PIXEL
 STA TEMP ; BLOCK, OR ZERO IF ALL THROUGH WITH BLOCK.
NXTBYT2D ASL BITMASK ; NOW WE'LL MOVE ONE PIXEL OVER ON SCREEN
 BIT BITMASK
 BMI NXTBYT3 ; IF WE'VE DONE 7 BITS ACROSS, GO START ON NEXT
; VERTICAL BLOCK (7 PIXELS H BY 8 BITS V).
 JMP NEWCLMN ; IF NOT, START ON NEXT COLUMN OF BITS OVER.
NXTBYT3 INC HINDEX
 BIT PRFLG
 BMI NXTBYT3A
 JMP LINENDT ; SCAN ROUTINE HAS OWN LINE END TEST...
NXTBYT3A LDY HINDEX ; NEXT ONE (7 PIXELS TO THE RIGHT)...
 CPY HINDEXR ; ARE WE AT RIGHT SIDE OF IMAGE?
 BCC DONXTBLK ; NOT DONE WITH LINE, DO NEXT BLK OVER...
 BEQ DONXTBLK
 JMP DONELINE
DONXTBLK JMP NEWVTBLK
DONELINE LDA #CR ; FINISHED A PRINTER LINE, SO...
 JSR OUTPUT ; LET'S SEND A CARRIAGE RETURN
 LDA #LF
 JSR OUTPUT ; AND A LINEFEED TO THE IMAGEWRITER.
 LDA TEMP ; STORE THE SIZE FLIP-FLOP SO WE KNOW WHERE
 STA LASTEMP ; TO START READING FOR NEXT LINE.
; HORZ. BLOCK IS 280H BY 8V
 BEQ NXTBYT5 ; IF NOT IN MIDDLE OF HORZ. BLOCK, WE
; INCREMENT THE TABLE POINTER TO NEXT BLOCK.
 JMP NEWLINE ; DO NEXT LINE, STARTING IN MIDDLE OF BLOCK.
NXTBYT5 LDA TBLINDEX ; GET LAST TABLE POINTER TO HBASE ADDRESS.
 CLC
 ADC #$02 ; MOVE POINTER TO POINT AT HBASE OF NEXT
; 280H BY 8V BLOCK DOWN ON SCREEN.
 CMP #$30 ; THERE ARE 24 SUCH BLOCKS (24*2=48=$30)
 BNE NXTBYT6 ; IF DONE, TIDY UP AND RETURN CONTROL TO DOS...
 JMP FINI
NXTBYT6 STA TBLINDEX ; PUT NEW TABLE INDEX BACK
 JMP NEWLINE ; NOT DONE, START NEW LINE
;
PICSCAN EQU * ; GBYTE SCAN ROUTINE TO FIND IMAGE EDGES
FINDLFT BIT HINDEXL ; FOUND LEFT SIDE OF IMAGE YET?
 BPL FINDRGT ; IF YES, WE ARE TO LOOK FOR RIGHT SIDE...
 LDA GCHAR ; SEE IF LEFT SIDE BEGINS HERE.
 BNE FINDLFT1 ; IF NOT, TEST FOR END OF LINE...
 JMP NXTBYTRT
FINDLFT1 LDA HINDEX ; IF IT DOES, WE SET HINDEXL TO VT BLOCK
 STA HINDEXL ;  NUMBER WE ARE SCANNING.
 JMP FINDRGT1
FINDRGT LDA GCHAR ; SEE IF THIS IS POSSIBLE RIGHT EDGE OF IMAGE.
 BEQ FINDRGT2 ; IF NOT, TEST FOR END OF LINE...
FINDRGT1 LDA HINDEX ; IF YES, STORE VT BLOCK NUMBER IN HINDEXR.
 STA HINDEXR
FINDRGT2 JMP NXTBYTRT
LINENDT LDA HINDEX ; CHECK TO SEE IF WE'RE AT END OF SCREEN ROW?
 CMP #HNDXMAX ;  (40 BLOCKS ACROSS SCREEN)
 BEQ PRTRCMDS ; IF YES, WE MUST TEST FURTHER...
 JMP NEWVTBLK ; NO, THEN CONTINUE SCANNING LINE
PRTRCMDS BIT HINDEXL ; DID WE EVER FIND LEFT EDGE OF IMAGE?
 BMI DONELINE ; NO, JUST SEND CR/LF AND START NEXT LINE...
 LDA HINDEXL ; HERE WE CONVERT BLOCK NUMBER INTO THE
 JSR BKTODOTS ;  NUMBER OF DOTS TO TAB OVER...
 LDY #4 ; NOW CONVERT HEX NUMBER OF DOTS IN THE
 JSR HEXDEC ;  ASCII DECIMAL EQUIVALENT OF HEX NUMBERS...
 LDA #ESC ; SEND PRINTER ESC F N3 N2 N1 N0
 JSR OUTPUT ;  WHICH TELLS SCRIBE TO MOVE N3N2N1N0 DOTS
 LDA #ASCIIF ;  OVER FROM LEFT MARGIN.
 JSR OUTPUT
 JSR OUTBUFF ; SEND N3 N2 N1 N0 TO PRINTER...
 LDA HINDEXR ; NOW TELL SCRIBE HOW MANY COLUMNS TO PRINT.
 SEC
 SBC HINDEXL ; GET DIFFERENCE BETWEEN RIGHT AND LEFT SIDES.
 CLC
 ADC #1 ; ADD 1, SINCE WE SHOULD PRINT AT LEAST 1 BLK.
 JSR BKTODOTS ; CONVERT TO NUMBER OF COLUMNS TO PRINT
 LDY #4 ; NOW OBTAIN ASCII DECIMAL EQUIVALENT...
 JSR HEXDEC
 LDA #ESC ; SEND SCRIBE ESC C N3N2N1N0 FOR N3N2N1N0
 JSR OUTPUT ;  COLUMNS OF HI-RES OUTPUT TO FOLLOW.
 LDA #ASCIIG
 JSR OUTPUT
 JSR OUTBUFF ; SEND N3N2N1N0
 LDA #$FF ; NOW SET PRFLG SO WE'LL ACTUALLY PRINT
 STA PRFLG ;  ON OUR NEXT SCAN THROUGH LINE
 LDA HINDEXL ; SET UP HINDEX SO SCAN STARTS AT LEFT EDGE
 STA HINDEX ;  OF IMAGE.
 JMP NEWVTBLK ; AND BEGIN PRINT SCAN...
;
BKTODOTS EQU * ; CONVERTS VT BLK NO. TO NUMBER OF DOTS
;  VT BLK NO. IS PASSED IN ACCUMULATOR.
; RETURNS X=HIGH, A=LOW OF NUMBER OF DOTS.
 STA MYBUF+1 ; STORE NUMBER OF VT. BLK.
 LDX #0
 STX MYBUF ; CLEAR HI-ORDER BYTE OF RESULT
 ASL  ; WE MULTIPLE BLK. NUMBER BY 7 (7 PIXELS
 ASL ;  ACROSS FOR EACH BLOCK) BY MULTIPLYING
 ASL  ;  BY 8 AND SUBTRACTING ONCE.
 ROL MYBUF ;  MULTIPLYING HI BYTE TOO...
 SEC
 SBC MYBUF+1 ; SUBTRACT VT BLK NO. ONCE (8*A-A=7A)
 BCS BKTODOT1 ; IF NO UNDERFLOW, DON'T WORRY ABOUT HI BYTE
 DEC MYBUF ; UNDERFLOW - SO BORROW ONE FROM HI BYTE
BKTODOT1 BIT XFRFLGS ; IF DOUBLE-SIZE, WE HAVE TO DOUBLE THE
 BPL BKTODOT2 ;  NUMBER OF DOTS YET AGAIN...
 ASL
 ROL MYBUF
BKTODOT2 LDX MYBUF ; RETURN HI BYTE IN X REGISTER
 RTS
;
OUTBUFF EQU * ; SENDS 4 ASCII CHARS TO PRINTER STORED IN MYBUF
 LDA #0
 STA BINL
OUTBUF1 LDX BINL
 CPX #4
 BEQ OUTBUF2
 LDA MYBUF,X
 JSR OUTPUT
 INC BINL
 JMP OUTBUF1
OUTBUF2 RTS
HEXDEC EQU * ; CONVERTS 16-BIT HEX NUMBER TO ASCII CODES
;  FOR DECIMAL EQUIVALENT.  A=LOW BYTE,
;  X=HI BYTE OF NUMBER TO CONVERT, AND
;  Y=NUMBER OF CHARS TO MAKE (WE WANT 4).
; OUTPUT IS STORED IN MYBUF, LAST CHAR FIRST.
 STA BINL
 STX BINH
HDLOOP LDX #16+1 ; 16 BITS FIRST TIME DO NOTHING
 LDA #0
 CLC  ; C=0 SO FIRST ROL LEAVES A=0
DV10LOOP ROL
 CMP #10
 BCC DV10LT ; BRANCH IF <
 SBC #10 ; C=1 FROM CMP AND LEFT SET
DV10LT ROL BINL
 ROL BINH
 DEX
 BNE DV10LOOP
 ORA #'0' ;MAKE ASCII
 STA MYBUF-1,Y
 DEY
 BNE HDLOOP
 RTS
;
;
;
; SCREEN DUMP COMPLETED -
FINI STA XFRFLGS ;RESTORE USER XFR OPTION
 LDA #ESC
 JSR OUTPUT
 LDA #ASCIIA
 JSR OUTPUT
 LDA #CR
 JSR OUTPUT
 LDA #LF
 JSR OUTPUT
 LDA #ESC
 JSR OUTPUT
 LDA #ASCIID
 JSR OUTPUT
 LDA #NUL
 JSR OUTPUT
 LDA #$20
 JSR OUTPUT
 LDA OFFSET
 LSR
 LSR
 LSR
 LSR
 TAY
 LDA $7F8,Y ;THIS TURNS AUTO LINE FEEDS
 AND #$EF ;BACK ON THE SUPER SERIAL CARD
 ORA #$01
 STA $7F8,Y
 JSR DOSCONN
 RTS
*
OUTPUT EQU * ;THIS HANDLES OUTPUT FOR SELECTED CARD
 LDY OFFSET ;THIS IS FOR PASCAL 1 PROTOCOL
 LDX SIGBYTES+1 ;SAME HERE....
 JMP (OUTL) ;BRIDGE FOR JSR OUTPUT
*
PPOUT EQU * ;MARK THE SPOT HERE
 STA PPDATA,Y ;STORE IT IN THE DATA PORT
NOTRDY LDA PPSTAT,Y ;GET THE PARALLEL STATUS REGISTER
 AND #$80 ;CHECK TO SEE IF IT'S BUSY
 BEQ NOTRDY ;WAIT HERE IF IT IS
 RTS  ;AND RETURN
*
FINDTYPE EQU * ;SUBROUTINE TO FIND THE INTERFACE CARD
 TYA  ;GET SLOT FROM Y REGISTER
 STA SLOT ;STORE IT FOR A MOMENT
 ASL  ;SHIFT IT 4 TIMES
 ASL
 ASL
 ASL  ;
 STA OFFSET ;STORE IT FOR LATER USE
 STX XFRFLGS ;X REGISTER CONTAINS THE PRINT OPTION
 LDA #$00 ;
 STA SIGBYTES ;SET UP ZERO PAGE FOR CALCULATION
 LDA SLOT ;GET THE SLOT AGAIN
 AND #$07 ;ONLY NEED THE LAST THREE BITS
 ORA #$C0 ;MAKE THE HIGH BYTE OF CN00
 STA SIGBYTES+1 ;STORE IT THE HIGH BYTE OF CN00
 LDY #5 ;LOOKING FOR PASCAL 1 PROTOCOL
 LDA (SIGBYTES),Y ;CHECK BYTE CN05 FOR PASCAL 1
 CMP #$38 ;CHECK #1
 BNE PARAPNT
 LDY #7 ;CHECK BYTE CN07 FOR PASCAL 1
 LDA (SIGBYTES),Y ;
 CMP #$18 ;CHECK #2
 BNE PARAPNT
 LDY #$B ;CHECK THE GENERIC SIGBYTE
 LDA (SIGBYTES),Y ;DOING IT
 CMP #$01 ;CHECK #3
 BEQ PASCAL1 ;LOOKS LIKE PASCAL 1 TO ME....
 BNE PARAPNT
PASCAL1 EQU *
 LDY #$0D ;GET THE INITILIZATION OFFSET
 LDA (SIGBYTES),Y ;DOING THE TASK....
 STA OUTL ;PUT IT IN THE LOWER HOOK BYTE..
 LDA SIGBYTES+1 ;GET THE HIGH BYTE OF CN00
 STA OUTH ;PUT IT IN THE HIGH HOOK BYTE..
 JSR OUTPUT ;TURN THE CARD ON...
 LDY #$F ;GET THE WRITE OFFSET BYTE..
 LDA (SIGBYTES),Y ;WORKING AGAIN....
 STA OUTL ;PUT IT AT THE LOWER HOOK BYTE
 LDY #$0C ;CHECK THE DEVICE SIGBYTE
 LDA (SIGBYTES),Y ;HO HUM
 CMP #$31 ;IS IT A SSC CARD?
 BNE RETURN ;NO START THE PROGRAM
 LDA #$9 ;TURN OFF THE COMMAND BYTE
 JSR OUTPUT ;HERE WE GO....
 LDA #'Z' ;ZAP THE MUTHA..
 JSR OUTPUT ;SEND IT TO THE CARD...
 LDA #CR ;DONT FORGET THIS, MANY HEADACHES!!
 JSR OUTPUT ;OUTPUT IT
RETURN RTS  ;RETURN TO CALLER
*
PARAPNT EQU *
 LDY #$A ;THIS IS AS GOOD A PLACE AS ANY TO
 LDA (SIGBYTES),Y ;IDENTIFY THE APPLE PARALLEL INTERFACE
 CMP #$20 ;
 BNE APPLE3 ;
 INY  ;
 LDA (SIGBYTES),Y ;BYTES ARE: CN0A $20, CN0B $58 CN0B $FF
 CMP #$58
 BNE APPLE3
 INY
 LDA (SIGBYTES),Y
 CMP #$FF
 BNE APPLE3
 LDA #>PPOUT ;LOCATION OF THE PARALLEL INTERFACE OUTPUTT
 STA OUTL ;ROUTINE LOCATED SOMEWHERE IN THE PROGRAM
 LDA #<PPOUT ;
 STA OUTH ;
 RTS
 EOR #$10
 AND #$70
 BNE LOOP2
 PLA
 STA $C0F0
 RTS
*
APPLE3 EQU *
 LDA APP3ID
 CMP #$C0
 BNE TROUBLE
 LDY #$B
 LDA (SIGBYTES),Y
 CMP #$08
 BNE TROUBLE
 INY
 LDA (SIGBYTES),Y
 CMP #$48
 BNE TROUBLE
 LDA #7
 JSR OUTPRT
 LDA #0
 JSR COUT
 JSR SETVID
 LDA #THREEOUT
 STA OUTL
 LDA #<THREEOUT
 STA OUTH
 RTS
*
THREEOUT EQU *
 PHA
LOOP2 LDA $C0F1
 EOR #$10
 AND #$70
 BNE LOOP2
 PLA
 STA $C0F0
 RTS
*
TROUBLE EQU *
 LDA #$FF
 STA OFFSET
 PLA
 PLA
 RTS
GrafBas EQU *
 JSR COMBYTE ;USE THE TXTPTR TO GET THE SLOT NUMBER
 TXA
 PHA ;STORE IT ON THE STACK FOR NOW
 JSR COMBYTE ;GET THE PRINT OPTION
;RETURNED IN THE X REGISTER
 PLA ;GET THE SLOT NUMBER BACK
 TAY ;TRANSFER TO THE Y REGISTER
 JMP GrafML ;ALREADY FOR THE MACHINE LANG ENTRY POINT
*
DOSCONN LDA WARMSTART
 CMP #$4C
 BNE DOSHOOK
 LDA WARMSTART+1
 BNE DOSHOOK
 LDA WARMSTART+2
 CMP #$BE
 BNE DOSHOOK
PRODOSIO LDY #$03
L016 LDA VDOSIO,Y
 STA CSWL,Y
 DEY
 BPL L016
 RTS
DOSHOOK JSR DOSIO
 RTS
TABLE DW $2000,$2080 ;THESE ARE HIRES BASE ADDRESSES
 DW $2100,$2180 ;FOR EACH SET OF EIGHT HIRES ROWS
 DW $2200,$2280
 DW $2300,$2380
 DW $2028,$20A8
 DW $2128,$21A8
 DW $2228,$22A8
 DW $2328,$23A8
 DW $2050,$20D0
 DW $2150,$21D0
 DW $2250,$22D0
 DW $2350,$23D0
