	.TITLE " -SOURCE FOR La Machine -By Steve Alpert - MODIFIED 12/16/85 FOR ANALOG MAGAZINE"
;
	.OPT OBJ,NO MLIST,NO LIST
	.MACRO OPEN 
;CHANNEL#,MODE,FILESPEC LABEL
;FIRST P1=P1*16
	.IF %0=3
	LDA #%1
	ASL A
	ASL A
	ASL A
	ASL A
	TAX  	;CHANNEL # GOES IN XREG
;
;NOW PUT THE MODE NUMBER INTO
;THE AUX BYTE
;
	LDA #%2
	STA $034A,X 	;ICAX1
	LDA #0
	STA $034B,X
;
;NOW GET THE LOW AND HIGH ADDRESS
;OF THE FILESPEC
;
	LDA # <%3
	STA $0344,X 	;ICBAL
	LDA # >%3
	STA $0345,X 	;ICBAH
;
;INSTALL THE COMMAND AND EXECUTE
;
	LDA #3 	;OPEN
	STA $0342,X 	;ICCOM
	JSR $E456 	;$CIOV
;
;
	.ELSE 
	.ERROR "WRONG # PARMS"
	.ENDIF 
	.ENDM 
;
;
;
	.MACRO CLOSE 
;CHANNEL#
;
	.IF %0=1
	LDA #%1
	ASL A
	ASL A
	ASL A
	ASL A
	TAX 
	LDA #$0C 	;CLOSE CMD
	STA $0342,X
	JSR $E456
;
	.ELSE 
	.ERROR "WRONG #OF PARMS"
	.ENDIF 
	.ENDM 
;
;
;
**************************
	.MACRO MCADD 
	.IF %0=2
	.IF %2<256
	LDA %1
	CLC 
	ADC #%2
	BCC SKIPIT
	INC %1+1
SKIPIT	STA %1
	.ELSE 
	LDA %1
	CLC 
	ADC  <%2
	BCC NOMATH
	INC %1+1
NOMATH	STA %1
	.ENDIF 
	.ELSE 
	.ERROR "*** WRONG # PARMS. - MCADD ***"
	.ENDIF 
	.ENDM 
	; 
****************************
	.MACRO ZERO 
	.IF %0=1
	LDA #0
	STA %1
	.ELSE 
	.ERROR "*** NEED ONE PARAMETER FOR - ZERO ***"
	.ENDIF 
	.ENDM 
;
*****************************
	.MACRO MCINC 
	.IF %0>1
	.ERROR "INK - too many parms."
	.ELSE 
	.IF %0=0
	CLC 
	ADC #1
	.ELSE 
	LDA %1
	CLC 
	ADC #1
	BNE SKIPIT
	INC %1+1
SKIPIT
	STA %1
	.ENDIF 
	.ENDIF 
	.ENDM 
;
*************************
	.MACRO MCDEC 
	.IF %0=0
	SEC 
	SBC #1
	.ELSE 
	.ERROR "*** NO PARMS ALLOWED - MCDEC ***"
	.ENDIF 
	.ENDM 
;
*************************
	.MACRO PAINT 
	.IF %0=4
	LDX #0
	LDY #0
@LOOP	LDA %2,X
	STA (%1),Y
	INX 
	INY 
	CPY %3
	BNE @LOOP
	  MCADD %1,40
	DEC %4
	BNE @LOOP-2
	.ELSE 
	.ERROR "*** MUST BE 4 PARMS, ALPERT! ***"
	.ENDIF 
	.ENDM 
***************************
	.OPT LIST,XREF
** VIDEO EQUATES **
;
SDLSTL	= $0230
STICK0	= $0278
STRIG0	= $0284
COLOR0	= $02C4
COLOR1	= $02C5
COLOR2	= $02C6
COLOR3	= $02C7
COLOR4	= $02C8
SCHBAS	= $02F4
CHBASE	= $D409
COLPF0	= $D016
COLPF1	= $D017
COLPF2	= $D018
COLPF3	= $D019
COLBK	= $D01A
TRIG0	= $D010
WSYNC	= $D40A
NMIEN	= $D40E
ATTRACT	= $4D
DMACTL	= $D400
SDMCTL	= $022F
VDSLST	= $0200
*PM GRAPHICS EQUATES
;
HPOSP0	= $D000
HPOSP1	= $D001
SIZEP0	= $D008
SIZEP1	= $D009
COLPM0	= $D012
COLPM1	= $D013
PCOLR0	= $02C0
PCOLOR1	= $02C1
PRIOR	= $D01B
GPRIOR	= $D01B
PMBASE	= $D407
HITCLR	= $D01E
GRACTL	= $D01D
FRMIND	= $8115
SETVBK	= $E45C
XITVBK	= $E462
STRIG	= $0284
SCRAM	= $F0
TEMP	= $F2
SCREEN	= $F4
PLAYER	= $F6
PACKPNT	= $F6
HARDWARE	= $D018
TEXT	= $D017
POKMSK	= 16
IRQEN	= $D20E
RND	= $D20A
;
	*= $4700
INIT
	LDX #0
?0	LDA DLIST2,X
	STA $8000,X
	INX 
	CPX #32
	BNE ?0
	LDX #0
	LDA #0 	;CLEAR PM
WIPEPM	STA $9422,X 	;DATA BEFORE
	INX  	;STARTING
	BNE WIPEPM 	;AGAIN
	LDA #$70 	;KILL THE
	STA POKMSK 	;BREAK
	STA IRQEN 	;KEY
	LDA #$3E
	STA SDMCTL
	LDA #$42
	STA SCRAM
	STA TEMP
	LDA #$62
	STA SCRAM+1
	STA TEMP+1
	LDA #0
	STA SDLSTL
	LDA #$60
	STA SDLSTL+1
	LDA C1
	STA $02C4
	LDA C2
	STA $02C5
	LDA BAK
	STA $02C8
	LDA C3
	STA $02C6
;
	JSR SETDLI
	JSR CREDIT
	LDX # >FLASH
	LDY # <FLASH
	LDA #7
	JSR SETVBK
;
	;  	I LIKE TO NAME STORAGE ARRAYS
	;  	AFTER MEMBERS OF MY FAMILY.
	LDA # <NANCY
	STA ARRTAB
	LDA # >NANCY
	STA ARRTABHI
	LDA # <ANGELA
	STA ARRTAB+1
	LDA # >ANGELA
	STA ARRTABHI+1
	LDA # <NORTON
	STA ARRTAB+2
	LDA # >NORTON
	STA ARRTABHI+2
	LDA # <ALPERT
	STA ARRTAB+3
	LDA # >ALPERT
	STA ARRTABHI+3
	LDA # <BAGGINS
	STA ARRTAB+4
	LDA # >BAGGINS
	STA ARRTABHI+4
	LDA # <RAFF
	STA ARRTAB+5
	LDA # >RAFF
	STA ARRTABHI+5
	LDA # <BAK
	STA ARRTAB+6
	LDA # >BAK
	STA ARRTABHI+6
;
	LDA # <N1+8
	STA NUMTABLE
	LDA # >N1
	STA NUMTABLE_HI
	LDA # <N2+8
	STA NUMTABLE+1
	LDA # >N2
	STA NUMTABLE_HI+1
	LDA # <N3+8
	STA NUMTABLE+2
	LDA # >N3
	STA NUMTABLE_HI+2
	LDA # <N4+8
	STA NUMTABLE+3
	LDA #$4D
	STA NUMTABLE_HI+3
;
	JMP BIGBOX
;
STARTCOL	.BYTE 2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3
WIDTH	    1
HEIGHT	    1
ACROSS	    1
DOWN	    1
COLUMN	.BYTE 0
PALETTE	.BYTE $55,$AA,$00,$FF
LFTLIN	.BYTE 2
RGTLIN	.BYTE $80
BOXLOCLO	.BYTE $06,$56,$A6,$F6,$0F,$5F,$FC
BOXLOCHI	.BYTE $62,$67,$6C,$71,$62,$67,$71
BOXNUM	    1
;
;
BIGBOX
	LDA #$F2
	STA SCRAM
	LDA #$61
	STA SCRAM+1
	LDA #$02
	STA TEMP
	LDA #$75
	STA TEMP+1
	LDX #2
	LDY #0
LINELOOP
	LDA #$AA
	STA (SCRAM),Y
	STA (TEMP),Y
	INY 
	CPY #16
	BNE LINELOOP
	DEX 
	BEQ SIDES
	  MCADD SCRAM,40
	  MCADD TEMP,40
	LDY #0
	JMP LINELOOP
SIDES
	LDA #$F1
	STA SCRAM
	LDA #$61
	STA SCRAM+1
	LDA #$02
	STA TEMP
	LDA #$62
	STA TEMP+1
*SCRAM IS THE LEFT SIDE
*TEMP IS THE RIGHT SIDE
;
	LDA #124
	STA HEIGHT
	LDY #0
SIDELOOP
	LDA LFTLIN
	STA (SCRAM),Y
	LDA RGTLIN
	STA (TEMP),Y
	DEC HEIGHT
	BEQ OTHERBOXES
	  MCADD SCRAM,40
	  MCADD TEMP,40
	JMP SIDELOOP
;
OTHERBOXES
	LDA #0
	STA BOXNUM
BOXLOOP
	LDA #6
	STA WIDTH
	LDA #32
	STA HEIGHT
	LDX BOXNUM
	LDA BOXLOCLO,X
	STA SCRAM
	LDA BOXLOCHI,X
	STA SCRAM+1
	  PAINT SCRAM,BOXDATA,WIDTH,HEIGHT
	INC BOXNUM
	LDA BOXNUM
	CMP #7
	BNE BOXLOOP
	LDA #0
	STA BOXNUM
;
	JSR CREDIT2
	JSR NUMBERS
	JSR BALL
	JSR PMSET
	LDX #0
	STX PALDEX
	JSR NXTCOLR
	JSR ROTATOR 	;ONLY IN ANALOG VERSION
	JMP JSTICK
;
	.LOCAL 
INTERPRET
	LDX BRICKNUM
	LDA BRICKMAP,X
	STA TEMP
	LDA BRICKMAP_HI,X
	STA TEMP+1
	LDY #0
?0
	LDA (TEMP),Y
	AND MASK,Y
	STA STORAGE,Y
	INY 
	CPY #4
	BNE ?0
	INC BRICKNUM
	LDX BITENUM
	ORA STORAGE+2
	ORA STORAGE+1
	ORA STORAGE
	STA DATABYTE,X
	LDY #0
	INC BITENUM
	INX 
	CPX #120
	BNE INTERPRET
	STY BRICKNUM
	STY BITENUM
	LDX FRAMECNT
	LDA FRMADR,X
	STA SCRAM
	LDA FRMADR_HI,X
	STA SCRAM+1
	LDA #4
	STA WIDTH
	LDA #30
	STA HEIGHT
	  PAINT SCRAM,DATABYTE,WIDTH,HEIGHT
	RTS 
;
*THIS ROUTINE MOVES THE DATA FROM
*THE ARRAY DATABYTE (USED BY	;!!!!!!!! INVERSE CHARS !!!!!!!!
*INTERPRET) TO A ONE OF THE SIX	;!!!!!!!! INVERSE CHARS !!!!!!!!
*STORAGE ARRAYS,NANCY,ANGELA,	;!!!!!!!! INVERSE CHARS !!!!!!!!
*NORTON,ALPERT,BAGGINS,RAFF.	;!!!!!!!! INVERSE CHARS !!!!!!!!
;
SNAPSHOT
	LDX FRAMECNT
	LDA ARRTAB,X
	STA PACKPNT
	LDA ARRTABHI,X
	STA PACKPNT+1
	LDY #0
MLOOP
	LDA DATABYTE,Y
	STA (PACKPNT),Y
	INY 
	CPY #120
	BNE MLOOP
	RTS 
;
;
*THIS SECTION ALLOWS THE CHANGING
*OF THE PALETTE BY JOYSTICK
	.LOCAL 
;
JOYPAL
	LDA #$F4 	;CHANGE COLOR
	STA WDWCOLOR 	;OF TEXT WINDOW TO INDICATE MODE
	LDA #$FF
	STA 754
;
?0	JSR NUMBERS
	LDA 754
	CMP #$FF
	BEQ ?0.5
;   LDA #$FF
;   STA 754
	LDA #4
	STA WDWCOLOR
	RTS 
;
?0.5	LDA STRIG
	BNE ?1
;HERE, TRIG PRESSED
	JSR NXTCOLR
?2	LDA STRIG 	;WAIT FOR RELEASE
	BEQ ?2
;HERE, WE START TESTING FOR
;JOYSTICK MOVEMENT,WHICH CHANGES
;THE COLOR IN USE.
;
?1	LDA STICK0
	CMP #$0F 	;NEUTRAL?
	BEQ ?0 	;YES START AGAIN
;HERE STICK IS MOVED,CHECK VALIDITY
	CMP #14 	;UP,INCREASE HUE
	BNE ?3
	LDX PALDEX
	LDA BAK,X 	;GET CURRENT COLOR
	CLC 
	ADC #16
	BCC ?2.5
	AND #$0F 	;WRAPAROUND
?2.5	JSR COLSET
	JMP ?0
;
;
;HERE IT WAS NOT UP	;!!!!!!!! INVERSE CHARS !!!!!!!!
?3	CMP #13 	;DOWN
	BNE ?4
	LDX PALDEX
	LDA BAK,X
	CLC 
	ADC #$F0 	;-16
	BCS ?3.5
	ORA #$F0 	;WRAPAROUND
?3.5	JSR COLSET
	JMP ?0
;HERE, IT IS NEITHER UP OR DOWN
?4	CMP #7 	;RIGHT
	BNE ?5
	LDX PALDEX
	LDA BAK,X
	PHA 
	AND #$0F
	CMP #14
	BNE ?4.5
	PLA 
	AND #$F0
	JSR COLSET
	JMP ?0
?4.5	ADC #2
	STA STORAGE
	PLA 
	AND #$F0
	ORA STORAGE
	JSR COLSET
	JMP ?0
;
;HERE,IF NOT LEFT THEN NOT VALID
?5	CMP #11 	;LEFT
	BNE ?5.6
	LDX PALDEX
	LDA BAK,X
	PHA 
	AND #$0F
	CMP #0
	BNE ?5.5
	PLA 
	AND #$F0
	ORA #$0E
	JSR COLSET
?5.6	JMP ?0
;
;
?5.5	CLC 
	ADC #$FE 	;-2
	STA STORAGE
	PLA 
	AND #$F0
	ORA STORAGE
	JSR COLSET
	JMP ?0
;
;
	.LOCAL 
;
;
COLSET
	STA BAK,X
	JSR DOPALETTE
?0	LDA STICK0
	CMP #$0F 	;WAIT FOR
	BNE ?0
	RTS 
*THIS ROUTINE, NUMBERS DISPLAYS	;!!!!!!!! INVERSE CHARS !!!!!!!!
*THE COLOR REGISTERS VALUES
*ON THE SCREEN IN HEXADECIMAL.
;
;
;
	.LOCAL 
NUMBERS
	LDY #0
	LDX #3
?0	LDA BAK,X
	PHA 
	AND #$F0
	CLC 
	ROR A
	ROR A
	ROR A
	ROR A
	TAY 
	LDA HEXCHAR,Y
	CLC 
	ADC #$E0 	;-32
	STA LDIGIT
	PLA 
	AND #$0F
	TAY 
	LDA HEXCHAR,Y
	CLC 
	ADC #$E0 	;-32
	STA RDIGIT
	LDA NUMTABLE,X
	STA PACKPNT
	LDA NUMTABLE_HI,X
	STA PACKPNT+1
	LDY #0
	LDA LDIGIT
	STA (PACKPNT),Y
	LDA RDIGIT
	INY 
	STA (PACKPNT),Y
	DEX 
	BPL ?0
;
	RTS 
;
**********************************
*RECALL EXTRACTS AND EXPANDS THE	;!!!!!!!! INVERSE CHARS !!!!!!!!
*DATA WHICH WAS CRUNCHED BY
*INTERPRET, AND MOVES IT TO THE	;!!!!!!!! INVERSE CHARS !!!!!!!!
*SCREEN.
;
RECALL
	LDX FRAMECNT
	LDA ARRTAB,X
	STA PACKPNT
	LDA ARRTABHI,X
	STA PACKPNT+1
	LDA #$42
	STA SCREEN
	STA TEMP
	LDA #$62
	STA SCREEN+1
	STA TEMP+1
	LDA #4
	STA ACROSS
	LDA #30
	STA DOWN
;
ROLL
	LDX #0
	LDY #0
	LDA (PACKPNT),Y
	PHA 
	AND #$C0
	LSR A
	LSR A
	LSR A
	LSR A
	LSR A
	LSR A
	STA STORAGE,X
	INX 
	PLA 
	PHA 
	AND #$30
	LSR A
	LSR A
	LSR A
	LSR A
	STA STORAGE,X
	INX 
	PLA 
	PHA 
	AND #$0C
	LSR A
	LSR A
	STA STORAGE,X
	INX 
	PLA 
	AND #$03
	STA STORAGE,X
	  MCINC PACKPNT
;
	LDX #0
	LDY #0
ZLOOP	LDA STORAGE,X
	TAY 
	LDA BRICKVAL,Y
	STA STORAGE,X
	INX 
	CPX #4
	BNE ZLOOP
;
XPAND	LDA #4
	STA HEIGHT
	LDX #0
	LDY #0
YPAND	LDA STORAGE,X
	STA (SCREEN),Y
	  MCADD SCREEN,40
	DEC HEIGHT
	BNE YPAND
	LDA #4
	STA HEIGHT
	  MCINC TEMP
	STA SCREEN
	LDA TEMP+1
	STA SCREEN+1
	INX 
	CPX #4
	BNE YPAND
;
	DEC ACROSS
	BEQ DROW
	JMP ROLL
DROW	  MCADD TEMP,144
	STA SCREEN
	LDA TEMP+1
	STA SCREEN+1
	LDA #4
	STA ACROSS
	DEC DOWN
	BEQ RETURN
	JMP ROLL
RETURN	RTS 
********************************
;
;
*THIS IS THE TEXT DATA AREA
;
HEADER
	.SBYTE "LA MACHINE                   VERSION 2.0"
	.BYTE 0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.SBYTE " By Steve Alpert  1985"
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
	.BYTE 0,0,0,0,0,0,0,0,0,0
;
	; 
OPTIONS
N1	.SBYTE "  $2C8:      !!!!!!!!!!!!!!   "	;!!!!!!!! SPECIAL CHARS !!!!!!!!
FS1	.SBYTE "6 Frames  "
N2	.SBYTE "  $2C4:      | LA MACHINE |             "	;!!!!!!!! INVERSE CHARS !!!!!!!!
N3	.SBYTE "  $2C5:      | D:         |   "
	.SBYTE "   DELAY  "	;!!!!!!!! INVERSE CHARS !!!!!!!!
N4	.SBYTE "  $2C6:      |Steve Alpert|     "	;!!!!!!!! INVERSE CHARS !!!!!!!!
FS2	.SBYTE "$06 VBC "
	.SBYTE "             !!!!!!!!!!!!!!             "	;!!!!!!!! SPECIAL CHARS !!!!!!!!
	.SBYTE "  Snapshot "
ONOFF
	.SBYTE "ON                           "
;
;
*THIS LITTLE SECTION PROVIDES
*THE OPENING CREDITS AND
*AFTER A COUPLE OF SECONDS, THE
*ROUTINE GOES TO A 6 LINE DISPLAY
;
CREDIT
	LDA # <HEADER
	STA LMS
	LDA # >HEADER
	STA LMS+1
;
	LDA #0 	;SET UP
	STA 20 	;DELAY
	RTS 
;
CREDIT2
TLOOP	LDA 20
	CMP #180 	;IS THE DELAY
	BNE TLOOP 	;3 SEC. YET?
	; 
	LDA # <OPTIONS 	;YES
	STA LMS 	;   PUT OPTIONS
	LDA # >OPTIONS 	;ON SCREEN
	STA LMS+1
	RTS 
;
;
*THIS ROUTINE PUTS AND REMOVES THE
*BALL NEXT TO THE FRAME.
;
BALL	LDX FRAMECNT
	LDA BLOCTN,X
	STA SCREEN
	LDA BLOCTN_HI,X
	STA SCREEN+1
	LDA #1
	STA WIDTH
	LDA #6
	STA HEIGHT
	  PAINT SCREEN,BALLDATA,WIDTH,HEIGHT
	RTS 
;
NOBALL
	LDX FRAMECNT
	LDA BLOCTN,X
	STA SCREEN
	LDA BLOCTN_HI,X
	STA SCREEN+1
	LDA #1
	STA WIDTH
	LDA #6
	STA HEIGHT
	  PAINT SCREEN,NOBALLDATA,WIDTH,HEIGHT
	RTS 
;
;
PMSET
	LDA #0 	;INIT POSITION
	STA ROW
	STA COL
	LDA #$38 	;INIT HORZ
	STA HORZ
	LDA #$90
	STA PMBASE
	LDA #$0E
	STA PCOLR0
;
	LDA #$38 	;INITIAL POSITION
	STA HPOSP0
	LDX #0
	LDA #$F0 	;PLAYER SHAPE
PMS	STA $9422,X
	INX 
	CPX #4
	BNE PMS
;
	LDA #2 	;ENABLE
	STA GRACTL 	;PLAYERS
	STA GPRIOR
	RTS 
;
;
*THIS IS THE JOYSTICK-DRIVEN
*PLAYER ROUTINE USED IN MOVING
*THE BRICK AROUND FOR DOING
*ARTWORK.THE ROUTINES HERE ALSO
*RESPOND TO THE KEYPRESSES.
*EVERYTHING IS CALLED FROM HERE
;
;
	.LOCAL 
NXTFRM	JSR NOBALL
	LDX FRAMECNT
	INX 
	CPX FRAMESYS
	BNE ?0
	LDX #0
?0	STX FRAMECNT
	JSR RECALL
;   JSR INTERPRET
	JSR BALL
;
	.LOCAL 
;
JSTICK
TRIGGER
	LDA KEY
	BEQ NOSV
;HERE, SOME KEY IS PRESSED
	CMP #40 	;R
	BNE ?0
	JSR RECALL
	JSR INTERPRET
	JMP CONTINUE
?0	CMP #54 	;<KEY
	BNE ?1
	JSR MRCLEAN
	LDA SNAPFLAG
	BEQ NOSV
	JSR SNAPSHOT
NOSV	JMP CONTINUE
?1	CMP #45 	;T
	BNE ?2
	LDX SNAPFLAG
	BNE ZERO
	INC SNAPFLAG
	JSR CHGWORD
	JMP CONTINUE
ZERO	LDX #0
	STX SNAPFLAG
	JSR CHGWORD
	JMP CONTINUE
?2
	CMP #$27 	;INV KEY
	BNE ?3
	JSR NXTCOLR 	;SWITCH COLORS
	JMP CONTINUE
?3	CMP #33 	;SPACEBAR
	BEQ NXTFRM
	CMP #21 	;B KEY
	BNE ?4
	JSR WHEELHOUSE
	JMP CONTINUE
?4	CMP #63 	;A KEY
	BNE ?5
	JSR ANIMATOR
	JMP CONTINUE
?5	CMP #58 	;D KEY
	BNE ?5.5
	JSR DODATA
	JMP CONTINUE
?5.5	CMP #11 	;U KEY
	BNE ?6
	JSR DODATA
	JMP CONTINUE
?6	CMP #18 	;C KEY
	BNE ?7
	LDX #$64 	;VIOLET
	STX WDWCOLOR
	JSR COPIER
	LDX #4
	STX WDWCOLOR
	JMP CONTINUE
?7	CMP #62 	;S KEY
	BNE ?8
	LDA #$42 	;RED
	STA WDWCOLOR
	JSR GETSPEC
	LDA #4
	STA WDWCOLOR
	JSR RITEFILE
	JMP CONTINUE
?8	CMP #61 	;G KEY
	BNE ?9
	LDA #$A4 	;BLUE
	STA WDWCOLOR
	JSR GETSPEC
	LDA #4
	STA WDWCOLOR
	JSR READFILE
	JMP CONTINUE
?9	CMP #10 	;P KEY
	BNE ?10
	JSR JOYPAL
	JMP CONTINUE
?10
	CMP #24 	;4 KEY
	BNE ?11
	LDA #4
	JSR SYSTEM
	JMP CONTINUE
?11	CMP #29 	;5 KEY
	BNE ?12
	LDA #5
	JSR SYSTEM
	JMP CONTINUE
?12	CMP #27 	;6 KEY
	BNE ?13
	LDA #6
	JSR SYSTEM
	JMP CONTINUE
?13	CMP #7 	;* KEY
	BNE ?14
	JSR DIRECTORY
	JMP CONTINUE
?14
CONTINUE
	LDA STRIG
	BNE NOPE
;HERE, BUTTON IS PRESSED
;
	LDA ROW
	CLC 
	ROL A
	ROL A
	TAX 
	LDA BRICKMAP_HI,X
	STA SCREEN+1
	LDA BRICKMAP,X
	STA SCREEN
	CLC 
	ADC COL
	BCC ?15
	INC SCREEN+1
?15	STA SCREEN
	LDX #4
	LDY #0
?16	LDA COLINUSE
	STA (SCREEN),Y
	  MCADD SCREEN,40
	DEX 
	BNE ?16
	JSR INTERPRET
	LDA SNAPFLAG 	;0=OFF
	BEQ NOPE 	;1=ON
	JSR SNAPSHOT 	;SAVE WORK
NOPE
	LDX STICK0
	CPX #$0F 	;AT REST?
	BEQ ?17 	;YES,RNR
;HERE, STICK IS MOVING
	CPX #6
	BEQ ?17
	CPX #10
	BEQ ?17
	CPX #5
	BEQ ?17
	CPX #9
	BEQ ?17
;HERE, IT IS A PROPER MOVE
	CPX #14 	;UP?
	BNE NOTUP
	JMP UP
NOTUP	CPX #13 	;DOWN?
	BNE NOTDWN
	JMP DWN
NOTDWN
;HERE, IT IS LEFT OR RIGHT
	CPX #11 	;LEFT?
	BEQ LEFT
;HERE IT IS TO THE RIGHT
	LDA HORZ 	;GET HORZ.
	CLC 
	ADC #4
	TAX 
	CPX RBORDR
	BEQ ?17
	INC COL
	STX HPOSP0 	;MOVE HORZ POS.
	STX HORZ 	;SAVE NEW POS.
	JSR LETGO
?17	JMP TRIGGER
;
LEFT
	LDA HORZ
	CLC 
	ADC #$FC
	CMP LBORDR
	BMI ?17
	TAX 
	DEC COL
	STX HPOSP0
	STX HORZ
	JSR LETGO
?18	JMP TRIGGER
;
UP
*FIRST WE TEST THE BORDER
	LDX ROW
	BEQ ?18
*IF IT IS ZERO WE ARE ALREADY AT
*THE TOP.
	LDA PPOSLO,X
	STA PLAYER
	LDA PPOSHI
	STA PLAYER+1
*FIRST WE WILL WIPE OLD PLAYER
	LDY #0
	LDA #0
WIPEIT	STA (PLAYER),Y
	INY 
	CPY #4
	BNE WIPEIT
*NOW WE ESTABLISH NEW POSITION
*AND DRAW THE PLAYER THERE.
	DEX 
	LDA PPOSLO,X
	STA PLAYER
	LDA PPOSHI
	STA PLAYER+1
	STX ROW 	;SAVE NEW ROW#
;
	LDY #0
	LDA #$F0 	;BRICK SHAPE
DRAWIT
	STA (PLAYER),Y
	INY 
	CPY #4
	BNE DRAWIT
	JSR LETGO
?19	JMP TRIGGER
;
DWN
	LDX ROW
	CPX #29
	BEQ ?19
	LDA PPOSLO,X
	STA PLAYER
	LDA PPOSHI
	STA PLAYER+1
	LDY #0
	LDA #0
WIPE2	STA (PLAYER),Y
	INY 
	CPY #4
	BNE WIPE2
	INX 
	LDA PPOSLO,X
	STA PLAYER
	LDA PPOSHI
	STA PLAYER+1
	STX ROW
;
	LDY #0
	LDA #$F0
DRAW2
	STA (PLAYER),Y
	INY 
	CPY #4
	BNE DRAW2
	JSR LETGO
?20	JMP TRIGGER
;
;
	.LOCAL 
;LETGO  WAITS  FOR THE JOYSTICK TO BE CENTERED AFTER IT HAS MOVED,
;BUT  WILL  ONLY WAIT 8 JIFFIES. THIS ALLOWS CONTINUOUS MOVEMENT.
;
; .LOCAL
;
LETGO	LDA #0
	STA 20
?2	LDA STICK0
	CMP #$0F
	BEQ ?0
?1	LDA 20
	CMP #8
	BEQ ?0
	BNE ?2
	BNE LETGO
?0	RTS 
;
*DRAWS THE COLOR BAR
	.LOCAL 
;
NXTCOLR
	JSR NOBALL2
	LDA #8
	STA DOWN
	LDX PALDEX
	INX 
	CPX #4
	BNE ?0
	LDX #0
?0	STX PALDEX
	JSR BALL2
	LDA #$F2
	STA SCREEN
	LDA #$75
	STA SCREEN+1
;
DOBAR	LDY #0
	LDA BRICKVAL,X
BAR	STA (SCREEN),Y
	INY 
	CPY #16
	BEQ NXTL
	JMP BAR
NXTL	  MCADD SCREEN,40
	DEC DOWN
	BNE DOBAR
	JSR SLOWDOWN
	LDA BRICKVAL,X
	STA COLINUSE
	RTS 
;
SLOWDOWN
	LDA #0
	STA 20
WAIT	LDA 20
	CMP #10
	BNE WAIT
	RTS 
;
*THIS PART TOGGLES THE WORDS ON/OFF ON THE SCREEN.	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.LOCAL 
CHGWORD
	LDA #$FF
	STA 754
	LDA # <ONOFF
	STA SCREEN
	LDA # >ONOFF
	STA SCREEN+1
	LDY #2
	LDA SNAPFLAG
	BEQ PUTOFF
WRITE1
	LDA ON,Y
	STA (SCREEN),Y
	DEY 
	BNE WRITE1
?0	LDA 753
	BNE ?0
	RTS 
;
PUTOFF
	LDA OFF,Y
	STA (SCREEN),Y
	DEY 
	BNE PUTOFF
?1	LDA 753
	BNE ?1
	RTS 
;
;
*SYSTEM SIMPLY CHANGES THE # OF	;!!!!!!!! INVERSE CHARS !!!!!!!!
*FRAMES IN THE SYSTEM AND CYCLES
*THE FRAMECNT BACK TO ZERO TO
*AVOID PROBLEMS.
;
SYSTEM
	PHA 
	JSR NOBALL
	LDX #0
	STX FRAMECNT
	JSR BALL
	PLA 
	STA FRAMESYS
	TAX 
	LDA HEXCHAR,X
	CLC 
	ADC #$E0 	;-32
	STA FS1 	;PUT THE CHARACTER ON SCREEN
	RTS 
;
	.LOCAL 
;
*THIS ROUTINE IS RESPONSIBLE FOR
*THE FLASHING EDIT CURSOR.
*IT ALSO SCANS THE KEYBOARD FOR
*A MEANINGFUL KEYPRESS EACH VBC.	;!!!!!!!! INVERSE CHARS !!!!!!!!
*DEF. VERTICAL BLANK INTERVAL.
;
FLASH
	JSR KEYSCAN
	LDA #$FF
	STA 764
	DEC VBC
	LDX VBC
	BNE OUT
	LDX #20
	STX VBC
	LDA RND
	STA PCOLR0
OUT	JMP XITVBK
;
;
VBC	.BYTE 20
XREG	.BYTE 0
;
KEYSCAN
	LDA 764
	CMP #$FF
	BNE ?0
	LDA #0
	STA KEY
	RTS 
?0
	CMP #54 	;< KEY
	BEQ OK
	CMP #40 	;R KEY
	BEQ OK
	CMP #21 	;B KEY
	BEQ OK
	CMP #45 	;T
	BEQ OK
	CMP #39 	;INVERSE KEY
	BEQ OK
	CMP #33 	;SPACEBAR
	BEQ OK
	CMP #63 	;A KEY
	BEQ OK
	CMP #58 	;D KEY
	BEQ OK
	CMP #11 	;U KEY
	BEQ OK
	CMP #62 	;S KEY
	BEQ OK
	CMP #18 	;C KEY
	BEQ OK
	CMP #61 	;G KEY
	BEQ OK
	CMP #10 	;P KEY
	BEQ OK
	CMP #24 	;4 KEY
	BEQ OK
	CMP #29 	;5 KEY
	BEQ OK
	CMP #27 	;6 KEY
	BEQ OK
	CMP #7 	;* KEY
	BEQ OK
	LDA #0 	;RETURNS A ZERO IF NO VALID PRESS
OK	STA KEY
	RTS 
;
;
*THIS PART OF THE CODE SETS UP THE
*POINTERS AND STUFF FOR DLI'S	;!!!!!!!! INVERSE CHARS !!!!!!!!
*THE DLI IS TO NEEDED TO OBTAIN
*AN INDEPENDANT TEXT DISPLAY ON
*THE BOTTOM OF THE SCREEN.
;
SETDLI
	LDA # <DLI
	STA VDSLST
	LDA # >DLI
	STA VDSLST+1
	LDA #$FF
	STA NMIEN
	RTS 
;
*THIS IS THE ACTUAL DLI ROUTINE
;
DLI
	PHA 
	TXA 
	PHA 
	LDA TXTCOLOR
	LDX WDWCOLOR
	STA WSYNC
	STA TEXT
	STX HARDWARE
	PLA 
	TAX 
	PLA 
	RTI 
;
;
	.LOCAL 
;
* THIS SECTION PROVIDES A DISK
* DIRECTORY ON SCREEN FOR D1
;
DIRECTORY
	JSR WIPE_DIR
	LDA HORZ
	PHA  	;SAVE HORZ POS.
	LDA #0
	STA HPOSP0
	  CLOSE 2
	  OPEN 2,6,ASTERISK
	TYA 
	BMI NOTOPEN
	LDA # <DLIST2
	STA 560
	LDA # >DLIST2
	STA 561
	LDA #$A2 	;BLUE
	STA $02C6 	;GR2 BACKGROUND
	STA $02C8 	;GR2 BORDER
	LDA #$0C 	;BRIGHT WHITE
	STA $02C5 	;GR2 TEXT
	LDA #0
	STA SCRAM 	;SCREEN RAM IS AT
	LDA #$81 	;$8100 (FOR DIRECTORY)
	STA SCRAM+1
	LDA 17
	STA ICBLL,X
	LDA #0
	STA ICBLH,X
	LDA # <DBUFF
	STA ICBAL,X
	LDA # >DBUFF
	STA ICBAH,X
	LDA #5
	STA ICCOM,X
?0	JSR CIOV
	TYA 
	BMI EOF
	JSR CHVERT
;CONVERT INTERNAL CODES INTO SCREEN BYTES AND MOVE DATA TO SCREEN AREA.
	JMP ?0
;
EOF	LDA #$FF
	STA 754
?1	LDA 754
	CMP #$FF
	BEQ ?1
NOTOPEN
	  CLOSE 2
	LDA #0
	STA 560
	LDA #$60
	STA 561
	PLA 
	STA HORZ
	STA HPOSP0
	JSR DOPALETTE
	RTS 
;
	.LOCAL 
CHVERT
	LDY #0
	LDA # <DBUFF
	STA PACKPNT
	LDA # >DBUFF
	STA PACKPNT+1
?0	LDA (PACKPNT),Y
	CLC 
	ADC #$E0 	;-32
	STA (SCRAM),Y
	INY 
	CPY #17
	BNE ?0
	  MCADD SCRAM,20
	RTS 
;
	.LOCAL 
WIPE_DIR
	LDY #0
	STY SCRAM
	LDA #$81
	STA SCRAM+1
?1	LDA #0
?0	STA (SCRAM),Y
	INY 
	BNE ?0
	INC SCRAM+1
	LDA SCRAM+1
	CMP #$85
	BNE ?1
	RTS 
;
;
*THIS ROUTINE WIPES CLEAN THE
*EDIT WINDOW. IT IS STILL RETAINED
*IN STORAGE ARRAYS, THOUGH, IF THE SNAPSHOT IS OFF.	;!!!!!!!! INVERSE CHARS !!!!!!!!
*THE ROUTINE WIPES IT OFF WITH
*THE CURRENT COLOR, SO IT IS ALSO
*A CHEAP FILL ROUTINE.
;
*THE SECOND PART OF THIS SECTION
*OF CODE CONTAIN THE ANIMATORS.
;
;
SPEED	.BYTE 6
;
MRCLEAN
	LDA #120
	STA DOWN2
	LDA #16
	STA ACROSS2
	LDA #$42
	STA SCRAM
	LDA #$62
	STA SCRAM+1
;
REFILL	LDY #0
	LDA COLINUSE
FILL	STA (SCRAM),Y
	INY 
	CPY #16
	BNE FILL
	  MCADD SCRAM,40
	DEC DOWN2
	BNE REFILL
	JSR INTERPRET
	RTS 
;
*THE BIG ANIMATOR.
;
	.LOCAL 
WHEELHOUSE
	LDA #0 	;CURSOR IS
	;  	IRRITATING
	;  	WHEN ANIMATING
	STA HPOSP0 	;SO, MOVE OFFSCREEN
	STA 753
	JSR NOBALL
KCHK	LDA 753
	BEQ ?2
	JMP ?3
;
?2	LDA STRIG
	BNE ?4
	JMP ?3
?4	LDX FRAMECNT
	INX 
	CPX FRAMESYS
	BNE ?1
	LDX #0
?1	STX FRAMECNT
	JSR RECALL
	JMP KCHK
?3	LDA HORZ
	STA HPOSP0
	LDA #0
	STA FRAMECNT
	JSR BALL
	JSR RECALL
?5	LDA STRIG 	;WAIT FOR
	BEQ ?5 	;RELEASE
	RTS 
;
DOWN2	    1
ACROSS2	    2
;
*THE ACTUAL SIZE ANIMATOR
;
	.LOCAL 
ANIMATOR
	JSR NOBALL
	LDA #$FF
	STA 754
	STA HPOSP0
?3	LDA #30
	STA HEIGHT
	LDA #$25
	STA SCREEN
	LDA #$72
	STA SCREEN+1
;
	LDX FRAMECNT
	LDA FRMADR,X
	STA SCRAM
	LDA FRMADR_HI,X
	STA SCRAM+1
;
?2	LDY #0
?1	LDA (SCRAM),Y
	STA (SCREEN),Y
	INY 
	CPY #4
	BNE ?1
;
	  MCADD SCREEN,40
	  MCADD SCRAM,40
	DEC HEIGHT
	BNE ?2
;
;
	JSR REGULATOR
;
	LDX FRAMECNT
	INX 
	CPX FRAMESYS
	BNE ?4
	LDX #0
?4	STX FRAMECNT
;
	LDA STRIG
	BEQ GDAY
	LDA STICK0
	CMP #7 	;RIGHT
	BNE ?10
	JSR QUICKER
;?12 LDA STICK0
;   CMP #7
;   BEQ ?12
	JMP ?3
?10	CMP #11 	;LEFT
	BNE ?0
	JSR SLOWER
;?13 LDA STICK0
;   CMP #11
;   BEQ ?13
	JMP ?3
?0	LDA 754
	CMP #33 	;SPACEBAR
;
	BEQ GDAY
	CMP #55 	;>
	BNE ?7
	JSR QUICKER
	JMP ?3
;
?7	CMP #54 	;<
	BNE ?6
	JSR SLOWER
?6	JMP ?3
;
GDAY	LDA #0
	STA FRAMECNT
	JSR BALL
	JSR RECALL
?99	LDA STRIG
	BEQ ?99
	LDA HORZ
	STA HPOSP0
	RTS 
;
;
*SPEED REGULATOR
;
	.LOCAL 
REGULATOR
	LDA #0
	STA 20
?1	LDA 20
	CMP SPEED
	BNE ?1
	RTS 
;
	.LOCAL 
QUICKER
	LDA SPEED
	CLC 
	ADC #$FF 	;-1
	BNE ?5 	;0 IS MAX SPD
?8	LDA #$0F 	;MINIMUM SPD
?5	STA SPEED
	LDA #$FF
	STA 754
	JSR DISPLAYSPEED
	RTS 
SLOWER
	LDA SPEED
	CLC 
	ADC #1 	;+1
	CMP #$10
	BNE ?5
	LDA #1
	JMP ?5
;
	.LOCAL 
DISPLAYSPEED
*THIS ROUTINE CONVERTS THE CURRENT SPEED # INTO EQUIVALENT SCREEN
*BYTES IN ORDER TO DISPLAY IT ON SCREEN
	LDA SPEED
	AND #$0F 	;ELIM. HI NIBBLE
	TAX 
	LDA HEXCHAR,X
	CLC 
	ADC #$E0 	;-32
	STA FS2+2 	;PUT ON SCREEN
	LDA SPEED
	AND #$F0 	;ELIM. LO NIBBLE
	CLC 
	ROR A 	;MOVE HI NIBBLE
	ROR A 	;TO LO NIBBLE FOR
	ROR A 	;USE AS INDEX
	ROR A 	;INTO SCRN CHAR.
	TAX 
	LDA HEXCHAR,X
	CLC 
	ADC #$E0 	;-32
	STA FS2+1 	;PUT ON SCREEN
?0	LDA STICK0
	CMP #$0F
	BNE ?0
	RTS 
;
*THIS PART OF THE CODE FIGURES OUT
*WHAT THE DATA IS FOR REQUESTED
*FRAME, INCLUDING WITH 3 SHIFTS OF
*2 PIXELS/SHIFT, AND PRINTS IT
*TO THE EPSON PRINTER.
;
;
ICCOM	= $0342
ICBAL	= $0344
ICBAH	= $0345
ICBLL	= $0348
ICBLH	= $0349
ICAX1	= $034A
ICAX2	= $034B
CIOV	= $E456
;
OPERR	LDA #$53 	;PRINTER WON'T OPEN, SO WE'LL OPEN "S:"
	STA PSPEC 	;CHANGES SPEC TO S:
	LDA #0
	STA HPOSP0
	JMP RETRY
;
	.LOCAL 
DODATA	LDX #$50 	;SET OUTPUT SPEC TO "P:"
	STX PSPEC
	LDX #0 	;DEFAULT IS
	STX DFLAG 	;NO SHIFTS
	CMP #11 	;U KEY WAS PRESSED?
	BEQ RETRY
	INC DFLAG 	;NO, D KEY WAS.
RETRY	LDA #$FF
	STA 754
	LDA #0
	STA SHIFTNUM
	LDA #$60
	STA NMIEN
	  CLOSE 1
	  OPEN 1,8,PSPEC 	;OPEN CHANNEL 1 TO DEVICE IN PSPEC
	BMI OPERR 	;WON'T OPEN?
	JSR WIPEXB
	JSR RECALL
	JSR INTERPRET
	JSR SNAPSHOT
	LDA # <DATABYTE
	STA PACKPNT
	LDA # >DATABYTE
	STA PACKPNT+1
DATALOOP	LDX #0
	LDY #0
	STY WIDE
	STY YREG
CHARLOOP	LDY YREG 	;THE STUFF STARTING HERE
	LDA (PACKPNT),Y 	;CONVERTS TH  DATA INTO
	PHA  	;ATARI SCREEN BYTES
	AND #$F0 	;BY BREAKING THE DATA
	LSR A 	;INTO 2 HALVES AND
	LSR A 	;USING THE RESULT AS
	LSR A 	;AN INDEX INTO A TABLE
	LSR A 	;WHICH CONTAIN THE SCREEN BYTES.
	TAY 
	LDA HEXCHAR,Y 	;HEXCHAR IS THE TABLE
	STA LDIGIT,X 	;LeftDIGIT and RightDIGIT ARE STORAGE ARRAYS
	PLA 
	AND #$0F
	TAY 
	LDA HEXCHAR,Y
	STA RDIGIT,X
	INX 
	INC YREG
	INC WIDE
	LDA WIDE
	CMP #4
	BNE CHARLOOP
;
;NOW THE EXTRA (SHIFT) BYTE
;
	LDA #0
	STA WIDE
	STX XREG
	TXA 
	LSR A
	LSR A 	;DIVIDE BY 4
	TAX 
	DEX 
	LDA SHFBITE,X
	PHA 
	AND #$F0
	LSR A
	LSR A
	LSR A
	LSR A
	TAY 
	LDA HEXCHAR,Y
	STA LXDIG,X
	PLA 
	AND #$0F
	TAY 
	LDA HEXCHAR,Y
	STA RXDIG,X
	LDX XREG
	CPX #120
	BNE CHARLOOP
;
;HERE, PRINTOUT AND THEN AFTER
;THAT WE START SHIFTING.
;
	LDA #30 	;THE DATA IS 4 X 30
	STA DOWN
	LDA #4
	STA WIDE
	LDX #$10 	;CHANNEL 1
	LDA # <PHRASE1
	STA ICBAL,X
	LDA # >PHRASE1
	STA ICBAH,X
	LDA #13
	STA ICBLL,X
	LDA #0
	STA ICBLH,X
	LDY FRAMECNT
	LDA HEXCHAR,Y
	STA FRNUM
	LDY SHIFTNUM
	LDA HEXCHAR,Y
	STA SHNUM
	LDA #$0B 	;PUT CHAR
	STA ICCOM,X
	JSR CIOV
	LDA # <PHRASE2
	STA ICBAL,X
	LDA # >PHRASE2
	STA ICBAH,X
	LDA #$0B
	STA ICCOM,X
	JSR CIOV
	LDA #3
	STA ICBLL,X
	LDA # <PBUFF
	STA ICBAL,X
	LDA # >PBUFF
	STA ICBAH,X
	LDY #0
NXTCHR
	LDA LDIGIT,Y
	STA PBUFF
	LDA RDIGIT,Y
	STA PBUFF+1
	INY 
	LDA #32 	;SPACE
	STA PBUFF+2
	TYA  	;BECAUSE CIOV
	PHA  	;ALTERS Y
	LDA #$0B 	;PUTCHAR
	STA ICCOM,X
	JSR CIOV
	PLA 
	TAY 
	DEC WIDE
	BNE NXTCHR
	LDA #4
	STA WIDE
	LDA 754 	;CHECK FOR KEYPRESS
	CMP #$FF
	BEQ ?99 	;KEEP GOING
	JMP ?98 	;EXIT
?99	TYA 
	PHA 
	LSR A
	LSR A 	;DIVIDE BY 4
	TAY 
	DEY 
	LDA LXDIG,Y
	STA PBUFF
	LDA RXDIG,Y
	STA PBUFF+1
	LDA #$9B 	;EOL
	STA PBUFF+2
	LDA #$0B 	;PUTCHAR
	STA ICCOM,X
	JSR CIOV
	PLA 
	TAY 
	DEC DOWN
	BNE NXTCHR
;
;HERE, DONE PRINTING ONCE
	LDA PSPEC 	;IS OUTPUT GOING
	CMP #$53 	;TO SCREEN?
	BNE ?97 	;NO.
	JSR HOLD 	;YES, SO WE STOP UNTIL KEY IS PRESSED
?97	LDA DFLAG 	;<>0=DO SHIFTS
	BEQ ?98 	;0=NO SHIFTS
	INC SHIFTNUM
	LDA SHIFTNUM
	CMP #4
	BNE SHIFTER
?98	LDA #$FF
	STA NMIEN
	  CLOSE 1
	LDA PSPEC
	CMP #$53 	;IF WE WENT TO SCREEN
	BNE ?96 	;WE MUST RESTORE DISPLAY LIST AND PMG.
	PLA  	;POP THE STACK
	PLA  	;AND RESTART
	JMP INIT 	;IS EASIEST
?96	RTS  	;NORMAL EXIT.
	.LOCAL 
SHIFTER	LDA #30
	STA DOWN
	LDA #2
	STA SHFCNT
	LDY #0
	STY YREG
	LDX #0
?0	LDX YREG
	CLC 
	ROR DATABYTE,X
	INX 
	ROR DATABYTE,X
	INX 
	ROR DATABYTE,X
	INX 
	ROR DATABYTE,X
	TYA 
	TAX 
	ROR SHFBITE,X
	DEC SHFCNT
	BNE ?0
	LDA #2
	STA SHFCNT
	INY 
	CPY #30
	BEQ ?1
	TYA 
	ASL A
	ASL A
	STA YREG
	JMP ?0
?1	JMP DATALOOP
WIPEXB
	.LOCAL 
	LDX #0
	TXA 
?0	STA SHFBITE,X
	STA RXDIG,X
	STA LXDIG,X
	INX 
	CPX #30
	BNE ?0
	RTS 
;
	.LOCAL 
;
HOLD	LDA #$FF
	STA 754
?0	LDA 754
	CMP #$FF
	BEQ ?0
	LDA #$FF
	STA 754
	RTS 
;
PSPEC	.BYTE "P:"
PHRASE1	.BYTE $9B,$9B,$9B,"!FRAME# "	;!!!!!!!! SPECIAL CHARS !!!!!!!!
FRNUM	.BYTE 0,$9B
PHRASE2	.BYTE "!SHIFT# "	;!!!!!!!! SPECIAL CHARS !!!!!!!!
SHNUM	.BYTE 0,"   ",$9B
;
DFLAG	    1
YREG	    1
PBUFF	    3
SHFBITE	    30
LXDIG	    30
RXDIG	    30
;
;
;
*THIS IS THE COPIER SECTION. IT
*PERFORMS THE DUPLICATION OF ANY
*FRAME.
;
	.LOCAL 
COPIER	LDA FRAMECNT
	STA FROMFRAME
	STA TOFRAME
	LDA #$FF
	STA 754
?2	LDA 754
	CMP #31 	;1 KEY
	BEQ COPY
	CMP #33 	;SPACE
	BEQ ?4
	CMP #$FF
	BEQ ?2
	JMP ?1
?4	LDA FRAMECNT
	CMP FROMFRAME
	BEQ ?5
	JSR NOBALL
?5	INC FRAMECNT
	LDA FRAMECNT
	CMP FRAMESYS
	BNE ?3
	LDA #0
	STA FRAMECNT
?3	STA TOFRAME
	JSR BALL
	LDA #$FF
	STA 754
	JMP ?2
;
?1	LDA FROMFRAME
	STA FRAMECNT
	CMP TOFRAME
	BEQ ?6
	JSR NOBALL
?6	LDA TOFRAME
	STA FRAMECNT
	JSR BALL
	JSR RECALL
	LDA #$FF
	STA 754
	RTS 
;
COPY
*FIRST, RESTORE THE FRAME#
*WHICH IS THE COPY FROM FRAME.	;!!!!!!!! INVERSE CHARS !!!!!!!!
	LDA FROMFRAME
	TAX  	;RESTORED.
;
*NOW SAVE THE "TO" FRAME#	;!!!!!!!! INVERSE CHARS !!!!!!!!
	LDA FRAMECNT
	STA TOFRAME 	;SAVED.
	STX FRAMECNT
	JSR RECALL 	;CALL UP THE "FROM" DISPLAY	;!!!!!!!! INVERSE CHARS !!!!!!!!
;
*NOW RESTORE THE "TO" FRAME#	;!!!!!!!! INVERSE CHARS !!!!!!!!
	LDA TOFRAME
	TAX 
	STX FRAMECNT
	JSR INTERPRET
*INTERPRET MAKES THE CHANGE FOR US	;!!!!!!!! INVERSE CHARS !!!!!!!!
;
	JSR SNAPSHOT
*AND SNAPSHOT RECORDS IT IN THE ARRAY	;!!!!!!!! INVERSE CHARS !!!!!!!!
;
	JMP ?1
	RTS 
;
;
;
*GETSPEC IS THE ROUTINE THAT
*GETS THE FILESPEC FROM THE
*USER. ALSO THE WRITE ROUTINES
*AND THE READ ROUTINES ARE HERE.
;
;
;
	.LOCAL 
;
GETSPEC
	LDY #8
	LDA #0
?0	STA N3+17,Y 	;WIPE OUT THE
	DEY  	;FILESPEC
	BNE ?0 	;ON SCREEN
;
	.LOCAL 
	LDA #128
	STA N3+17
	  OPEN 2,4,KEYSPEC
	LDY #2
	STY YREG
	LDX #$20 	;CHANNEL 2
	LDA #1 	;MAX RECORD
	STA ICBLL,X
	LDA #0
	STA ICBLH,X
	LDA # <CHBUFF
	STA ICBAL,X
	LDA # >CHBUFF
	STA ICBAH,X
?0	LDA #$07 	;GET CHAR
	STA ICCOM,X
	JSR CIOV
;
;
	LDA CHBUFF
	CMP #$9B 	;RETURN
	BEQ ?1
	CMP #$7E 	;DEL/BACKSP
	BEQ ?2
	CMP #$30
	BMI ?0 	;NOT ACCEPTABLE
	CMP #$5B
	BPL ?0 	;NOT ACCEPTABLE
;HERE IT MAY BE ACCEPTABLE INPUT
	CMP #$3A
	BMI IOK 	;OK, MUST BE 0-9
	CMP #$41
	BMI ?0 	;NOT ACCEPTABLE, MUST BE :-@
;HERE, INPUT OK, SO DISPLAY
;AND PUT INTO FILENAME ARRAY
IOK	LDY YREG
	STA FILENAME,Y
	SEC 
	SBC #$20
	STA N3+15,Y 	;PUT CHAR ON SCREEN
	INC YREG
	LDA YREG
	CMP #11
	BNE ?6
	LDA #10
	STA YREG
?6	LDA #128
	LDY YREG
	STA N3+15,Y
	JMP ?0
?2	LDY YREG
;   LDA #0
;   STA N3+15,Y
	CPY #2
	BEQ ?0
	LDA #0
	STA N3+15,Y
	DEC YREG
	LDY YREG
	LDA #128
	STA N3+15,Y
	JMP ?0
?1	LDY YREG
	STA FILENAME,Y
	LDA #0
	STA N3+15,Y
	RTS 
;
	.LOCAL 
;
RITEFILE
	LDA FILENAME+3
	CMP #$9B
	BEQ ?1
	LDA #$60
	STA NMIEN
	  CLOSE 2
	  OPEN 2,8,FILENAME
	BMI ?3 	;WON'T OPEN?
	LDY #0
	STY YREG
?0	LDA ARRTAB,Y
	STA ICBAL,X
	LDA ARRTABHI,Y
	STA ICBAH,X
	LDA #121 	;READ 120 BYTES AT A TIME
	STA ICBLL,X
	LDA #0
	STA ICBLH,X
	LDA #9 	;PUT RECORD
	STA ICCOM,X
	JSR CIOV
	INC YREG
	LDY YREG
	CPY #7 	;6 FRAMES PLUS PALETTE
	BNE ?0
?3	  CLOSE 2
?1	LDA #$FF
	STA NMIEN
	RTS 
;
	.LOCAL 
;
READFILE
	LDA FILENAME+3
	CMP #$9B
	BEQ ?1
	LDA #$60
	STA NMIEN
	  CLOSE 2
	  OPEN 2,4,FILENAME
	BMI ?2
	LDY #0
	STY YREG
?0	LDA ARRTAB,Y
	STA ICBAL,X
	LDA ARRTABHI,Y
	STA ICBAH,X
	LDA #121
	STA ICBLL,X
	LDA #0
	STA ICBLH,X
	LDA #5 	;GET RECORD
	STA ICCOM,X
	JSR CIOV
	INC YREG
	LDY YREG
	CPY #7 	;6 FRAMES & PALETTE
	BNE ?0
	JSR DOPALETTE
	JSR NUMBERS
	JSR ROTATOR
?2	  CLOSE 2
?1	LDA #$FF
	STA NMIEN
	RTS 
;
	.LOCAL 
ROTATOR
*THE ROTATOR FILLS THE FRAMES
*WITH THE NEWLY GOTTEN DATA
;
	JSR NOBALL
	LDX #0 	;START WITH FRAME0
	STX FRAMECNT
?0	JSR RECALL
	JSR BALL
	JSR INTERPRET
	JSR GDLY 	;DELAY
	JSR NOBALL
	INC FRAMECNT
	LDX FRAMECNT
	CPX #6
	BNE ?0
	JSR NOBALL
	LDX #0
	STX FRAMECNT
	JSR RECALL
	JSR BALL
	RTS 
;
GDLY
	LDY #$FF
?1	DEY 
	BNE ?1
	RTS 
;
*MOVE THE COLOR FROM THE ARRAY
*BYTES TO THE COLOR REGISTERS
*AND ACKNOWLEDGE FRAMESYS, WHICH	;!!!!!!!! INVERSE CHARS !!!!!!!!
*CONTAINS THE # OF FRAMES BEING USED
;
	.LOCAL 
*DOPALETTE INSTALLS THE NEW PALETTE DATA JUST READ IN FROM DISK,	;!!!!!!!! INVERSE CHARS !!!!!!!!
*ADJUSTING THE COLORS, AND SETS
*THE AMOUNT OF FRAMES USED.
;
;
DOPALETTE
	LDA BAK
	STA $02C8
	LDX #0
?0	LDA C1,X
	STA $02C4,X
	INX 
	CPX #3
	BNE ?0
	LDA FRAMESYS
	CMP #4 	;JUST CHECKING. IF THERE ARE
	BMI SIX 	;LESS THAN 4 FRAMES
	CMP #6 	;OR MORE THAN 6, THEN
	BPL SIX 	;WE CORRECT IT.
	JMP ?1
SIX	LDA #6
?1	JSR SYSTEM
	RTS 
;
	.LOCAL 
*THIS ROUTINE, BALL2 MOVES THE	;!!!!!!!! INVERSE CHARS !!!!!!!!
*CONTROL-T CHARACTER AROUND TO
*SHOW WHICH COLOR REGISTER IS
*BE AFFECTED OR USED
;
;
BALL2
?0	JSR BALLMATH
	LDY #0
	LDA #$54 	;CONTROL-T IS THE BALL
	STA (SCREEN),Y
	RTS 
;
*NOBALL ERASES THE BALL	;!!!!!!!! INVERSE CHARS !!!!!!!!
NOBALL2
	LDX PALDEX
	JSR BALLMATH
	LDA #0 	;BLANK ERASES BALL
	LDY #0
	STA (SCREEN),Y
RTS
;
;
	.LOCAL 
BALLMATH
	LDA NUMTABLE_HI,X
	STA SCREEN+1
	LDA NUMTABLE,X
	CLC 
	ADC #3 	;PROVIDE SPACE BETWEEN #'S AND THE BALL
	BCC ?0
	INC SCREEN+1
?0	STA SCREEN
	RTS 
;
;
*HERE ARE NEARLY ALL THE VARIABLES
*AND TABLES IN THE PROGRAM.
;
BOXDATA
	.BYTE $02,$AA,$AA,$AA,$AA,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,0,0,0,0,$80
	.BYTE $02,$AA,$AA,$AA,$AA,$80
;
BRICKMAP
	.BYTE $42,$46,$4A,$4E 	;ROW0
	.BYTE $E2,$E6,$EA,$EE 	;ROW1
	.BYTE $82,$86,$8A,$8E 	;ROW2
	.BYTE $22,$26,$2A,$2E 	;ROW3
	.BYTE $C2,$C6,$CA,$CE 	;ROW4
	.BYTE $62,$66,$6A,$6E 	;ROW5
	.BYTE $02,$06,$0A,$0E 	;ROW6
	.BYTE $A2,$A6,$AA,$AE 	;ROW7
	.BYTE $42,$46,$4A,$4E 	;ROW8
	.BYTE $E2,$E6,$EA,$EE 	;ROW9
	.BYTE $82,$86,$8A,$8E 	;ROW10
	.BYTE $22,$26,$2A,$2E 	;ROW11
	.BYTE $C2,$C6,$CA,$CE 	;ROW12
	.BYTE $62,$66,$6A,$6E 	;ROW13
	.BYTE $02,$06,$0A,$0E 	;ROW14
	.BYTE $A2,$A6,$AA,$AE 	;ROW15
	.BYTE $42,$46,$4A,$4E 	;ROW16
	.BYTE $E2,$E6,$EA,$EE 	;ROW17
	.BYTE $82,$86,$8A,$8E 	;ROW18
	.BYTE $22,$26,$2A,$2E 	;ROW19
	.BYTE $C2,$C6,$CA,$CE 	;ROW20
	.BYTE $62,$66,$6A,$6E 	;ROW21
	.BYTE $02,$06,$0A,$0E 	;ROW22
	.BYTE $A2,$A6,$AA,$AE 	;ROW23
	.BYTE $42,$46,$4A,$4E 	;ROW24
	.BYTE $E2,$E6,$EA,$EE 	;ROW25
	.BYTE $82,$86,$8A,$8E 	;ROW26
	.BYTE $22,$26,$2A,$2E 	;ROW27
	.BYTE $C2,$C6,$CA,$CE 	;ROW28
	.BYTE $62,$66,$6A,$6E 	;ROW29
BRICKMAP_HI
	.BYTE $62,$62,$62,$62 	;ROW0
	.BYTE $62,$62,$62,$62 	;ROW1
	.BYTE $63,$63,$63,$63 	;ROW2
	.BYTE $64,$64,$64,$64 	;ROW3
	.BYTE $64,$64,$64,$64 	;ROW4
	.BYTE $65,$65,$65,$65 	;ROW5
	.BYTE $66,$66,$66,$66 	;ROW6
	.BYTE $66,$66,$66,$66 	;ROW7
	.BYTE $67,$67,$67,$67 	;ROW8
	.BYTE $67,$67,$67,$67 	;ROW9
	.BYTE $68,$68,$68,$68 	;ROW10
	.BYTE $69,$69,$69,$69 	;ROW11
	.BYTE $69,$69,$69,$69 	;ROW12
	.BYTE $6A,$6A,$6A,$6A 	;ROW13
	.BYTE $6B,$6B,$6B,$6B 	;ROW14
	.BYTE $6B,$6B,$6B,$6B 	;ROW15
	.BYTE $6C,$6C,$6C,$6C 	;ROW16
	.BYTE $6C,$6C,$6C,$6C 	;ROW17
	.BYTE $6D,$6D,$6D,$6D 	;ROW18
	.BYTE $6E,$6E,$6E,$6E 	;ROW19
	.BYTE $6E,$6E,$6E,$6E 	;ROW20
	.BYTE $6F,$6F,$6F,$6F 	;ROW21
	.BYTE $70,$70,$70,$70 	;ROW22
	.BYTE $70,$70,$70,$70 	;ROW23
	.BYTE $71,$71,$71,$71 	;ROW24
	.BYTE $71,$71,$71,$71 	;ROW25
	.BYTE $72,$72,$72,$72 	;ROW26
	.BYTE $73,$73,$73,$73 	;ROW27
	.BYTE $73,$73,$73,$73 	;ROW28
	.BYTE $74,$74,$74,$74 	;ROW29
;
PPOSLO	.BYTE $22,$26,$2A,$2E
	.BYTE $32,$36,$3A,$3E
	.BYTE $42,$46,$4A,$4E
	.BYTE $52,$56,$5A,$5E
	.BYTE $62,$66,$6A,$6E
	.BYTE $72,$76,$7A,$7E
	.BYTE $82,$86,$8A,$8E
	.BYTE $92,$96,$9A
;
PPOSHI	.BYTE $94
;
DATABYTE	    120
STORAGE	    4
KEY	.BYTE 0
COLINUSE	.BYTE 0
FRMADR	.BYTE $2F,$7F,$CF,$1F,$38,$88
FRMADR_HI	.BYTE $62,$67,$6C,$72,$62,$67
BLOCTN	.BYTE $BC,$0C,$5C,$AC,$C5,$15
BLOCTN_HI	.BYTE $63,$69,$6E,$73,$63,$69
NUMTABLE	    4
NUMTABLE_HI	    4
SHIFTNUM	    1
ROW	.BYTE 0
COL	.BYTE 0
RBORDR	.BYTE $78
LBORDR	.BYTE $38
HORZ	.BYTE $38
FRAMECNT	.BYTE 0
BRICKNUM	.BYTE 0
MASK	.BYTE $C0,$30,$0C,$03
TXTCOLOR	.BYTE $0A
WDWCOLOR	.BYTE $04
FROMFRAME	    1
TOFRAME	    1
SNAPFLAG	.BYTE 1
BITENUM	.BYTE 0
BRICKVAL	.BYTE $00,$55,$AA,$FF
PALDEX	.BYTE 0
OFF	.SBYTE "OFF"
ON	.SBYTE "ON "
ARRTAB	    7 	;6 FRAMES + PALETTE
ARRTABHI	    7 	;6 FRAMES + PALETTE
SHFCNT	.BYTE 0
BALLDATA
	.BYTE $3C
	.BYTE $FF
	.BYTE $FF
	.BYTE $FF
	.BYTE $FF
	.BYTE $3C
NOBALLDATA
	.BYTE 0,0,0,0,0,0
ASTERISK	.BYTE "D:*.*"
WIDE	    1
LDIGIT	    120
RDIGIT	    120
FILENAME	.BYTE "D:ABCDEFGH"
	    1
CHBUFF	    1
DBUFF	    18
KEYSPEC	.BYTE "K:"
HEXCHAR	.BYTE 48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70
DEC1
;
NANCY	= $4300
ANGELA	= NANCY+120
NORTON	= ANGELA+120
ALPERT	= NORTON+120
BAGGINS	= ALPERT+120
RAFF	= BAGGINS+120
;
BAK	= RAFF+120
C1	= BAK+1
C2	= C1+1
C3	= C2+1
FRAMESYS	= C3+1
;
;
;
	      $6000
DISPLAY_LIST
	.BYTE $70,$70,$70,$4E,$F0,$61
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14
	.BYTE 14,14,14,14,14,14,14,14,14
	.BYTE $4E,$00,$70
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14
	.BYTE 14,14,14,14,14,14,14,14,14,14,14,14,$8E
	.BYTE $42
LMS	.BYTE $00,0,2,2,2,2,2
	.BYTE $41,$00,$60
;
;
DLIST2
	.BYTE $70,$70,$70
	.BYTE $42
	.BYTE $00,$81
	.BYTE 2,2,2,2,2,2,2,2,2,2
	.BYTE 2,2,2,2,2,2,2,2,2,2
	.BYTE 2,2
	.BYTE $41,$00,$80
;
;
