\************************************************
\* ELITE<A>
\************************************************

LOMEM=&3D70
C_A%=&F40
W%=&7200
L%=&1128
HIMEM=W%
\Z=0
D%=&563A
WP=&D40
K%=&900
LS%=WP-1
QQ18=&400
T%=&300

NOST=18
NOSH=12
COPS=2
SH3=COPS
CYL=7
THG=6
SST=8
MSL=9
AST=10
OIL=11
TGL=12
ESC=13
NI%=36
POW=15
B=&30
FF=&FF

OSWRCH=&FFEE
OSBYTE=&FFF4
OSWORD=&FFF1
OSFILE=&FFDD
SCLI=&FFF7
VIA=&FE40
USVIA=VIA
IRQ1V=&204
VSCAN=57

XX21=D%
ZP=0
X=128
Y=96

\\ ZERO PAGE
org ZP
.RAND   skip 4  ;=FNZT(4)
.TRTB%  skip 2  ;	skip 2	;=FNZ2
.T1	    skip 1	;=FNZ
.SC	    skip 2	;=FNZ2
SCH=SC+1
.XX16   skip 18 ;=FNZT(18)
.P      skip 3  ;=FNZT(3)
.XX0	skip 2	;=FNZ2
.INF	skip 2	;=FNZ2
.V	    skip 2	;=FNZ2
.XX	    skip 2	;=FNZ2
.YY	    skip 2	;=FNZ2
.SUNX	skip 2	;=FNZ2
.BETA	skip 1	;=FNZ
.BET1	skip 1	;=FNZ
.XC	    skip 1	;=FNZ
.YC	    skip 1	;=FNZ
.QQ22	skip 2	;=FNZ2
.ECMA	skip 1	;=FNZ
.XX15   skip 6  ;=FNZT(6)
.XX12   skip 6  ;=FNZT(6)

X1=XX15
Y1=X1+1
X2=Y1+1
Y2=X2+1

.K      skip 4  ;=FNZT(4)
.KL     skip 16 ;=FNZT(16)
.LAS	skip 1	;=FNZ
.MSTG	skip 1	;=FNZ

f0=&20
f1=&71
f2=&72
f3=&73
f4=&14
f5=&74
f6=&75
f7=&16
f8=&76
f9=&77
KY1=KL+1
KY2=KL+2
KY3=KL+3
KY4=KL+4
KY5=KL+5
KY6=KL+6
KY7=KL+7
KY12=KL+8
KY13=KL+9
KY14=KL+10
KY15=KL+11
KY16=KL+12
KY17=KL+13
KY18=KL+14
KY19=KL+15

.INWK   skip NI%  ;=FNZT(NI%)
XX19=INWK+33
XX1=INWK
.LSP	skip 1	;=FNZ
.QQ15   skip 6  ;=FNZT(6)
.XX18   skip 9  ;=FNZT(9)
QQ17=XX18
QQ19=QQ17+1
K5=XX18
K6=K5+4
.ALP1	skip 1	;=FNZ
.ALP2	skip 2	;=FNZ2
.BET2	skip 2	;=FNZ2
.DELTA	skip 1	;=FNZ
.DELT4	skip 2	;=FNZ2
.U	    skip 1	;=FNZ
.Q	    skip 1	;=FNZ
.R	    skip 1	;=FNZ
.S	    skip 1	;=FNZ
.XSAV	skip 1	;=FNZ
.YSAV	skip 1	;=FNZ
.XX17	skip 1	;=FNZ
.QQ11	skip 1	;=FNZ
.ZZ	    skip 1	;=FNZ
.XX13	skip 1	;=FNZ
.MCNT	skip 1	;=FNZ
.DL	    skip 1	;=FNZ
.TYPE	skip 1	;=FNZ
.JSTX	skip 1	;=FNZ
.JSTY	skip 1	;=FNZ
.ALPHA	skip 1	;=FNZ
.QQ12	skip 1	;=FNZ
.TGT	skip 1	;=FNZ
.SWAP	skip 1	;=FNZ
.COL	skip 1	;=FNZ
.FLAG	skip 1	;=FNZ
.CNT	skip 1	;=FNZ
.CNT2	skip 1	;=FNZ
.STP	skip 1	;=FNZ
.XX4	skip 1	;=FNZ
.XX20	skip 1	;=FNZ
.XX14	skip 1	;=FNZ
.RAT	skip 1	;=FNZ
.RAT2	skip 1	;=FNZ
.K2     skip 4  ;=FNZT(4)

PRINT "ZERO PAGE VARIABLES FROM ",~ZP," to ",~P%

;IFZ=4THENZ=6ELSEZ=4

\\ WORKSPACE at WP=&D40
org WP
.FRIN   skip NOSH+1 ;=FNWT(NOSH+1)
.MANY   skip 14 ;=FNWT(14)
SSPR=MANY+SST
.ECMP   skip 1  ;=FNW
.MJ     skip 1  ;=FNW
CABTMP=MANY
.LAS2   skip 1  ;=FNW
.MSAR   skip 1  ;=FNW
.VIEW   skip 1  ;=FNW
.LASCT  skip 1 ;=FNW
.GNTMP  skip 1 ;=FNW
.HFX    skip 1  ;=FNW
.EV     skip 1  ;=FNW
.DLY    skip 1  ;=FNW
.de     skip 1  ;=FNW
T=&D1
XX2=&D2
K3=XX2
K4=K3+14

.LSO    skip 192    ;=FNWT(192)
LSX=LSO
.LSX2   skip 78 ;=FNWT(78)
.LSY2   skip 78 ;=FNWT(78)
.SY     skip NOST+1 ;=FNWT(NOST+1)
.SYL    skip NOST+1 ;=FNWT(NOST+1)
.SZ     skip NOST+1 ;=FNWT(NOST+1)
.SZL    skip NOST+1 ;=FNWT(NOST+1)

.XSAV2  skip 1;=FNW
.YSAV2  skip 1;=FNW

.MCH    skip 1  ;=FNWFNW

.FSH    skip 1  ;=FNW
.ASH	skip 1	;=FNW
.ENERGY	skip 1	;=FNW
\\REMFF
.LASX	skip 1	;=FNW
.LASY	skip 1	;=FNW
.COMX	skip 1	;=FNW
.COMY	skip 1	;=FNW
.QQ24	skip 1	;=FNW
.QQ25	skip 1	;=FNW
.QQ28	skip 1	;=FNW
.QQ29	skip 1	;=FNW
.gov	skip 1	;=FNW
.tek	skip 1	;=FNW
.SLSP   skip 2  ;=FNW2
.XX24	skip 1	;=FNW
.ALTIT	skip 1	;=FNW
VEC=&7FFE
svn=&7FFD

.QQ2    skip 6  ;=FNWT(6)
.QQ3	skip 1	;=FNW
.QQ4	skip 1	;=FNW
.QQ5	skip 1	;=FNW
.QQ6    skip 2  ;=FNW2
.QQ7    skip 2  ;=FNW2
.QQ8    skip 2  ;=FNW2
.QQ9	skip 1	;=FNW
.QQ10	skip 1	;=FNW
.NOSTM	skip 1	;=FNW

PRINT "WP WORKSPACE FROM ",~WP," to ",~P%

\\ WORKSPACE at T%=&300
ORG T%
.TP	    skip 1	;=FNTP
.QQ0	skip 1	;=FNTP
.QQ1	skip 1	;=FNTP
.QQ21   skip 6  ;=FNTPT(6)
.CASH   skip 4  ;=FNTPT(4)
.QQ14	skip 1	;=FNTP
.COK	skip 1	;=FNTP
.GCNT	skip 1	;=FNTP
.LASER  skip 6  ;=FNTPT(6)
.CRGO	skip 1	;=FNTP
.QQ20   skip 17 ;=FNTPT(17)
.ECM	skip 1	;=FNTP
.BST	skip 1	;=FNTP
.BOMB	skip 1	;=FNTP
.ENGY	skip 1	;=FNTP
.DKCMP	skip 1	;=FNTP
.GHYP	skip 1	;=FNTP
.ESCP   skip 5  ;=FNTPT(5)
.NOMSL	skip 1	;=FNTP
.FIST	skip 1	;=FNTP
.AVL    skip 17 ;=FNTPT(17)
.QQ26	skip 1	;=FNTP
.TALLY  skip 2  ;=FNTPT(2)
.SVC    skip 3  ;=FNTPT(3)

NT%=SVC+2-TP    ;NT%=SVC+2-TP

SX=P%   ; T%
SXL=SX+NOST+1
XX3=256
\\REM&70

PRINT "T% WORKSPACE FROM ",~T%," to ",~P%," possibly ",~SXL

\ ZP allocations
\DEFFNZ=FNZT(1)
\DEFFNZ2=FNZT(2)
\DEFFNZT(N%)
\ZP=ZP+N%
\=ZP-N%

\ WP allocations
\DEFFNW=FNWT(1)
\DEFFNW2=FNWT(2)
\DEFFNWT(N%)
\WP=WP+N%
\=WP-N%

\ T% allocations
\DEFFNTP=FNTPT(1)
\DEFFNTPT(N%)
\T%=T%+N%
\=T%-N%

;P%=C%
;O%=W%
ORG C_A%
H_A%=L%           ;+P%-C% as P%=C% above
GUARD &6000       ; Screen buffer starts here

\[OPTZ

.S%
 EQUW TT170       ; entry point for Elite game
 EQUW TT26        ; WRCHV
 EQUW IRQ1        ; IRQ1V
 EQUW BR1         ; BRKV

.COMC brk
.DNOIZ brk
.DAMP brk
.DJD brk
.PATG brk
.FLH brk
.JSTGY brk
.JSTE brk
.JSTK brk

.M%
 LDA K%
 STA RAND
 LDX JSTX
 JSR cntr
 JSR cntr
 TXA
 EOR #128
 TAY
 AND #128
 STA ALP2
 STX JSTX
 EOR #128
 STA ALP2+1
 TYA
 BPL P%+7
 EOR #FF
 CLC
 ADC #1
 LSR A
 LSR A
 CMP #8
 BCS P%+4
 LSR A
 CLC
 STA ALP1
 ORA ALP2
 STA ALPHA

 LDX JSTY
 JSR cntr
 TXA
 EOR #128
 TAY
 AND #128
 STX JSTY
 STA BET2+1
 EOR #128
 STA BET2
 TYA
 BPL P%+4
 EOR #FF
 ADC #4
 LSR A
 LSR A
 LSR A
 LSR A
 CMP #3
 BCS P%+3
 LSR A
 STA BET1
 ORA BET2
 STA BETA

 LDA KY2
 BEQ MA17
 LDA DELTA
 CMP #40
 BCS MA17
 INC DELTA

.MA17
 LDA KY1
 BEQ MA4
 DEC DELTA
 BNE MA4
 INC DELTA

.MA4
 LDA KY15
 AND NOMSL
 BEQ MA20
 LDY #&EE
 JSR ABORT
 LDA #40
 JSR NOISE

.MA31
 LDA #0
 STA MSAR

.MA20
 LDA MSTG
 BPL MA25
 LDA KY14
 BEQ MA25
 LDX NOMSL
 BEQ MA25
 STA MSAR
 LDY #&E0
 JSR MSBAR

.MA25
 LDA KY16
 BEQ MA24
 LDA MSTG
 BMI MA64
 JSR FRMIS

.MA24
 LDA KY12
 BEQ MA76
 ASL BOMB

.MA76
 LDA KY13
 AND ESCP
 BEQ P%+5
 JMP ESCAPE
 LDA KY18
 BEQ P%+5
 JSR WARP
 LDA KY17
 AND ECM
 BEQ MA64
 LDA ECMA
 BNE MA64
 DEC ECMP
 JSR ECBLB2

.MA64
 LDA KY19
 AND DKCMP
 AND SSPR
 BEQ MA68
 LDA K%+NI%+32
 BMI MA68
 JMP GOIN

.MA68
 LDA #0
 STA LAS
 STA DELT4
 LDA DELTA
 LSR A
 ROR DELT4
 LSR A
 ROR DELT4
 STA DELT4+1

 LDA LASCT
 BNE MA3
 LDA KY7
 BEQ MA3
 LDA GNTMP
 CMP #242
 BCS MA3
 LDX VIEW
 LDA LASER,X
 BEQ MA3
 PHA
 AND #127
 STA LAS
 STA LAS2
 LDA #0
 JSR NOISE
 JSR LASLI
 PLA
 BPL ma1
 LDA #0

.ma1
 AND #&FA
 STA LASCT

.MA3
 LDX #0

.MAL1
 STX XSAV
 LDA FRIN,X
 BNE P%+5
 JMP MA18
 STA TYPE
 JSR GINF

 LDY #(NI%-1)

.MAL2
 LDA (INF),Y
 STA INWK,Y
 DEY
 BPL MAL2
 LDA TYPE
 BMI MA21
 ASL A
 TAY
 LDA XX21-2,Y
 STA XX0
 LDA XX21-1,Y
 STA XX0+1

 LDA BOMB
 BPL MA21
 CPY #2*SST
 BEQ MA21
 LDA INWK+31
 AND #32
 BNE MA21
 LDA INWK+31
 ORA #128
 STA INWK+31
 JSR EXNO2

.MA21
 JSR MVEIT
 LDY #(NI%-1)

.MAL3
 LDA INWK,Y
 STA (INF),Y
 DEY
 BPL MAL3

 LDA INWK+31
 AND #&A0
 JSR MAS4
 BNE MA65
 LDA INWK
 ORA INWK+3
 ORA INWK+6
 BMI MA65
 LDX TYPE
 BMI MA65
 CPX #SST
 BEQ ISDK
 AND #&C0
 BNE MA65
 CPX #MSL
 BEQ MA65

 CPX #OIL
 BCS P%+5
 JMP MA58
 LDA BST
 AND INWK+5
 BPL MA58
 LDA #3
 CPX #TGL
 BCC oily
 BNE slvy2
 LDA #16
 BNE slvy2

.oily
 JSR DORND
 AND #7

.slvy2
 STA QQ29
 LDA #1
 JSR tnpr
 LDY #78
 BCS MA59
 LDY QQ29
 ADC QQ20,Y
 STA QQ20,Y
 TYA
 ADC #208
 JSR MESS

 JMP MA60

.MA65
 JMP MA26

.ISDK
 LDA K%+NI%+32
 BMI MA62
 LDA INWK+14
 CMP #&D6
 BCC MA62
 JSR SPS4
 LDA XX15+2
 BMI MA62
 CMP #89
 BCC MA62
 LDA INWK+16
 AND #&7F
 CMP #80
 BCC MA62

.GOIN
 LDA #0
 STA QQ22+1
 LDA #8
 JSR LAUN
 JSR RES4
 JMP BAY

.MA62
 LDA DELTA
 CMP #5
 BCC MA67
 JMP DEATH

.MA59
 JSR EXNO3

.MA60
 ASL INWK+31
 SEC
 ROR INWK+31

.MA61
 BNE MA26

.MA67
 LDA #1
 STA DELTA
 LDA #5
 BNE MA63

.MA58
 ASL INWK+31
 SEC
 ROR INWK+31
 LDA INWK+35
 SEC
 ROR A

.MA63
 JSR OOPS
 JSR EXNO3

.MA26
 LDA QQ11
 BNE MA15
 JSR PLUT

 JSR HITCH
 BCC MA8
 LDA MSAR
 BEQ MA47
 JSR BEEP
 LDX XSAV
 LDY #&E
 JSR ABORT2

.MA47
 LDA LAS
 BEQ MA8
 LDX #15
 JSR EXNO
 LDA INWK+35
 SEC
 SBC LAS
 BCS MA14

 LDA TYPE
 CMP #SST
 BEQ MA14+2
 LDA INWK+31
 ORA #128
 STA INWK+31
 BCS MA8
 JSR DORND
 BPL oh
 LDY #0
 AND (XX0),Y
 STA CNT

.um
 BEQ oh
 LDX #OIL
 LDA #0
 JSR SFS1
 DEC CNT
 BPL um

.oh
 JSR EXNO2

.MA14
 STA INWK+35
 LDA TYPE
 JSR ANGRY

.MA8
 JSR LL9

.MA15
 LDY #35
 LDA INWK+35
 STA (INF),Y

 LDA INWK+31
 BPL MAC1
 AND #&20
 BEQ NBOUN
 LDA TYPE
 CMP #COPS
 BNE q2
 LDA FIST
 ORA #64
 STA FIST

.q2
 LDA DLY
 ORA MJ
 BNE KS1S
 LDY #10
 LDA (XX0),Y
 BEQ KS1S
 TAX
 INY
 LDA (XX0),Y
 TAY
 JSR MCASH
 LDA #0
 JSR MESS

.KS1S
 JMP KS1

.NBOUN

.MAC1
 LDA TYPE
 BMI MA27
 JSR FAROF
 BCC KS1S

.MA27
 LDY #31
 LDA INWK+31
 STA (INF),Y
 LDX XSAV
 INX
 JMP MAL1

.MA18
 LDA BOMB
 BPL MA77
 ASL BOMB
 JSR WSCAN
 LDA #&30
 STA &FE21

.MA77
 LDA MCNT
 AND #7
 BNE MA22
 LDX ENERGY
 BPL b
 LDX ASH
 JSR SHD
 STX ASH
 LDX FSH
 JSR SHD
 STX FSH

.b
 SEC
 LDA ENGY
 ADC ENERGY
 BCS P%+5
 STA ENERGY

 LDA MJ
 BNE MA23S
 LDA MCNT
 AND #31
 BNE MA93
 LDA SSPR
 BNE MA23S
 TAY
 JSR MAS2
 BNE MA23S

 LDX #28

.MAL4
 LDA K%,X
 STA INWK,X
 DEX
 BPL MAL4
 INX
 LDY #9
 JSR MAS1
 BNE MA23S
 LDX #3
 LDY #11
 JSR MAS1
 BNE MA23S
 LDX #6
 LDY #13
 JSR MAS1
 BNE MA23S

 LDA #&C0
 JSR FAROF2
 BCC MA23S

 LDA QQ11
 BNE P%+5\!
 JSR WPLS
 JSR NWSPS

.MA23S
 JMP MA23

.MA22
 LDA MJ
 BNE MA23
 LDA MCNT
 AND #31

.MA93
 CMP #10
 BNE MA29
 LDA #50
 CMP ENERGY
 BCC P%+6
 ASL A
 JSR MESS
 LDY #FF
 STY ALTIT
 INY
 JSR m
 BNE MA23
 JSR MAS3
 BCS MA23
 SBC #&24
 BCC MA28
 STA R
 JSR LL5
 LDA Q
 STA ALTIT
 BNE MA23

.MA28
 JMP DEATH

.MA29
 CMP #20
 BNE MA23
 LDA #30
 STA CABTMP
 LDA SSPR
 BNE MA23
 LDY #NI%
 JSR MAS2
 BNE MA23
 JSR MAS3
 EOR #FF
 ADC #30
 STA CABTMP
 BCS MA28

 CMP #&E0
 BCC MA23
 LDA BST
 BEQ MA23
 LDA DELT4+1
 LSR A
 ADC QQ14
 CMP #70
 BCC P%+4
 LDA #70
 STA QQ14
 LDA #160
 JSR MESS

.MA23
 LDA LAS2
 BEQ MA16
 LDA LASCT
 CMP #8
 BCS MA16
 JSR LASLI2
 LDA #0
 STA LAS2

.MA16
 LDA ECMP
 BEQ MA69
 JSR DENGY
 BEQ MA70

.MA69
 LDA ECMA
 BEQ MA66
 DEC ECMA
 BNE MA66

.MA70
 JSR ECMOF

.MA66
 LDA QQ11
 BNE MA9
 JMP STARS

.MAS1
 LDA INWK,Y
 ASL A
 STA K+1
 LDA INWK+1,Y
 ROL A
 STA K+2
 LDA #0
 ROR A
 STA K+3
 JSR MVT3
 STA INWK+2,X
 LDY K+1
 STY INWK,X
 LDY K+2
 STY INWK+1,X
 AND #127

.MA9
 RTS

.m
 LDA #0

.MAS2
 ORA K%+2,Y
 ORA K%+5,Y
 ORA K%+8,Y
 AND #127
 RTS

.MAS3
 LDA K%+1,Y
 JSR SQUA2
 STA R
 LDA K%+4,Y
 JSR SQUA2
 ADC R
 BCS MA30
 STA R
 LDA K%+7,Y
 JSR SQUA2
 ADC R
 BCC P%+4

.MA30
 LDA #FF
 RTS

.MVEIT
 LDA INWK+31
 AND #&A0
 BNE MV30

 LDA MCNT
 EOR XSAV
 AND #15
 BNE MV3
 JSR TIDY

.MV3
 LDX TYPE
 BPL P%+5
 JMP MV40
 LDA INWK+32
 BPL MV30
 CPX #MSL
 BEQ MV26

 LDA MCNT
 EOR XSAV
 AND #7
 BNE MV30

.MV26
 JSR TACTICS

.MV30
 JSR SCAN

 LDA INWK+27
 ASL A
 ASL A
 STA Q
 LDA INWK+10
 AND #127
 JSR FMLTU
 STA R
 LDA INWK+10
 LDX #0
 JSR MVT1-2

 LDA INWK+12
 AND #127
 JSR FMLTU
 STA R
 LDA INWK+12
 LDX #3
 JSR MVT1-2
 LDA INWK+14
 AND #127
 JSR FMLTU
 STA R
 LDA INWK+14
 LDX #6
 JSR MVT1-2

 LDA INWK+27
 CLC
 ADC INWK+28
 BPL P%+4
 LDA #0
 LDY #15
 CMP (XX0),Y
 BCC P%+4
 LDA (XX0),Y
 STA INWK+27

 LDA #0
 STA INWK+28

 LDX ALP1
 LDA INWK
 EOR #FF
 STA P
 LDA INWK+1
 JSR MLTU2-2
 STA P+2
 LDA ALP2+1
 EOR INWK+2
 LDX #3
 JSR MVT6

 STA K2+3
 LDA P+1
 STA K2+1
 EOR #FF
 STA P
 LDA P+2
 STA K2+2\K2=Y-aX

 LDX BET1
 JSR MLTU2-2
 STA P+2
 LDA K2+3
 EOR BET2
 LDX #6
 JSR MVT6
 STA INWK+8
 LDA P+1
 STA INWK+6
 EOR #FF
 STA P
 LDA P+2
 STA INWK+7\Z=Z+bK2

 JSR MLTU2
 STA P+2
 LDA K2+3
 STA INWK+5
 EOR BET2
 EOR INWK+8
 BPL MV43
 LDA P+1
 ADC K2+1
 STA INWK+3
 LDA P+2
 ADC K2+2
 STA INWK+4
 JMP MV44

.MV43
 LDA K2+1
 SBC P+1
 STA INWK+3
 LDA K2+2
 SBC P+2
 STA INWK+4
 BCS MV44
 LDA #1
 SBC INWK+3
 STA INWK+3
 LDA #0
 SBC INWK+4
 STA INWK+4
 LDA INWK+5
 EOR #128
 STA INWK+5

.MV44
\Y=K2-bZ
 LDX ALP1
 LDA INWK+3
 EOR #FF
 STA P
 LDA INWK+4
 JSR MLTU2-2
 STA P+2
 LDA ALP2
 EOR INWK+5
 LDX #0
 JSR MVT6
 STA INWK+2
 LDA P+2
 STA INWK+1
 LDA P+1
 STA INWK\X=X+aY

.MV45
 LDA DELTA
 STA R
 LDA #128
 LDX #6
 JSR MVT1
 LDA TYPE
 AND #&81
 CMP #&81
 BNE P%+3
 RTS \Z=Z-d

 LDY #9
 JSR MVS4
 LDY #15
 JSR MVS4
 LDY #21
 JSR MVS4
 LDA INWK+30
 AND #128
 STA RAT2
 LDA INWK+30
 AND #127
 BEQ MV8
 CMP #127
 SBC #0
 ORA RAT2
 STA INWK+30

 LDX #15
 LDY #9
 JSR MVS5
 LDX #17
 LDY #11
 JSR MVS5
 LDX #19
 LDY #13
 JSR MVS5

.MV8
 LDA INWK+29
 AND #128
 STA RAT2
 LDA INWK+29
 AND #127
 BEQ MV5
 CMP #127
 SBC #0
 ORA RAT2
 STA INWK+29

 LDX #15
 LDY #21
 JSR MVS5
 LDX #17
 LDY #23
 JSR MVS5
 LDX #19
 LDY #25
 JSR MVS5

.MV5
 LDA INWK+31
 AND #&A0
 BNE MVD1
 LDA INWK+31
 ORA #16
 STA INWK+31
 JMP SCAN

.MVD1
 LDA INWK+31
 AND #&EF
 STA INWK+31
 RTS

 AND #128

.MVT1
 ASL A
 STA S
 LDA #0
 ROR A
 STA T
 LSR S
 EOR INWK+2,X
 BMI MV10
 LDA R
 ADC INWK,X
 STA INWK,X
 LDA S
 ADC INWK+1,X
 STA INWK+1,X
 LDA INWK+2,X
 ADC #0
 ORA T
 STA INWK+2,X
 RTS

.MV10
 LDA INWK,X
 SEC
 SBC R
 STA INWK,X
 LDA INWK+1,X
 SBC S
 STA INWK+1,X
 LDA INWK+2,X
 AND #127
 SBC #0
 ORA #128
 EOR T
 STA INWK+2,X
 BCS MV11

 LDA #1
 SBC INWK,X
 STA INWK,X
 LDA #0
 SBC INWK+1,X
 STA INWK+1,X
 LDA #0
 SBC INWK+2,X
 AND #127
 ORA T
 STA INWK+2,X

.MV11
 RTS

.MVT3
 LDA K+3
 STA S
 AND #128
 STA T
 EOR INWK+2,X
 BMI MV13
 LDA K+1
 CLC
 ADC INWK,X
 STA K+1
 LDA K+2
 ADC INWK+1,X
 STA K+2
 LDA K+3
 ADC INWK+2,X
 AND #127
 ORA T
 STA K+3
 RTS

.MV13
 LDA S
 AND #127
 STA S
 LDA INWK,X
 SEC
 SBC K+1
 STA K+1
 LDA INWK+1,X
 SBC K+2
 STA K+2
 LDA INWK+2,X
 AND #127
 SBC S
 ORA #128
 EOR T
 STA K+3
 BCS MV14

 LDA #1
 SBC K+1
 STA K+1
 LDA #0
 SBC K+2
 STA K+2
 LDA #0
 SBC K+3
 AND #127
 ORA T
 STA K+3

.MV14
 RTS

.MVS4
 LDA ALPHA
 STA Q
 LDX INWK+2,Y
 STX R
 LDX INWK+3,Y
 STX S
 LDX INWK,Y
 STX P
 LDA INWK+1,Y
 EOR #128
 JSR MAD
 STA INWK+3,Y
 STX INWK+2,Y
 STX P \Y=Y-aX

 LDX INWK,Y
 STX R
 LDX INWK+1,Y
 STX S
 LDA INWK+3,Y
 JSR MAD
 STA INWK+1,Y
 STX INWK,Y
 STX P \X=X+aY

 LDA BETA
 STA Q
 LDX INWK+2,Y
 STX R
 LDX INWK+3,Y
 STX S
 LDX INWK+4,Y
 STX P
 LDA INWK+5,Y
 EOR #128
 JSR MAD
 STA INWK+3,Y
 STX INWK+2,Y
 STX P\Y=Y-bZ

 LDX INWK+4,Y
 STX R
 LDX INWK+5,Y
 STX S
 LDA INWK+3,Y
 JSR MAD
 STA INWK+5,Y
 STX INWK+4,Y
 RTS\Z=Z+bY

.MVS5
 LDA INWK+1,X
 AND #127
 LSR A
 STA T
 LDA INWK,X
 SEC
 SBC T
 STA R
 LDA INWK+1,X
 SBC #0
 STA S
 LDA INWK,Y
 STA P
 LDA INWK+1,Y
 AND #128
 STA T
 LDA INWK+1,Y
 AND #127
 LSR A
 ROR P
 LSR A
 ROR P
 LSR A
 ROR P
 LSR A
 ROR P
 ORA T
 EOR RAT2
 STX Q
 JSR ADD
 STA K+1
 STX K

 LDX Q
 LDA INWK+1,Y
 AND #127
 LSR A
 STA T
 LDA INWK,Y
 SEC
 SBC T
 STA R
 LDA INWK+1,Y
 SBC #0
 STA S
 LDA INWK,X
 STA P
 LDA INWK+1,X
 AND #128
 STA T
 LDA INWK+1,X
 AND #127
 LSR A
 ROR P
 LSR A
 ROR P
 LSR A
 ROR P
 LSR A
 ROR P
 ORA T
 EOR #128
 EOR RAT2

 STX Q
 JSR ADD
 STA INWK+1,Y
 STX INWK,Y
 LDX Q
 LDA K
 STA INWK,X
 LDA K+1
 STA INWK+1,X
 RTS

.MVT6
 TAY
 EOR INWK+2,X
 BMI MV50
 LDA P+1
 CLC
 ADC INWK,X
 STA P+1
 LDA P+2
 ADC INWK+1,X
 STA P+2
 TYA
 RTS

.MV50
 LDA INWK,X
 SEC
 SBC P+1
 STA P+1
 LDA INWK+1,X
 SBC P+2
 STA P+2
 BCC MV51
 TYA
 EOR #128
 RTS

.MV51
 LDA #1
 SBC P+1
 STA P+1
 LDA #0
 SBC P+2
 STA P+2
 TYA
 RTS

.MV40
 LDA ALPHA
 EOR #128
 STA Q
 LDA INWK
 STA P
 LDA INWK+1
 STA P+1
 LDA INWK+2
 JSR MULT3
 LDX #3
 JSR MVT3\K=Y-aX

 LDA K+1
 STA K2+1
 STA P
 LDA K+2
 STA K2+2
 STA P+1
 LDA BETA
 STA Q
 LDA K+3
 STA K2+3
 JSR MULT3
 LDX #6
 JSR MVT3
 LDA K+1
 STA P
 STA INWK+6
 LDA K+2
 STA P+1
 STA INWK+7
 LDA K+3
 STA INWK+8\Z=Z+bK2

 EOR #128
 JSR MULT3
 LDA K+3
 AND #128
 STA T
 EOR K2+3
 BMI MV1

 LDA K
\CLC
 ADC K2
 LDA K+1
 ADC K2+1
 STA INWK+3
 LDA K+2
 ADC K2+2
 STA INWK+4
 LDA K+3
 ADC K2+3
 JMP MV2

.MV1
 LDA K
 SEC
 SBC K2
 LDA K+1
 SBC K2+1
 STA INWK+3
 LDA K+2
 SBC K2+2
 STA INWK+4
 LDA K2+3
 AND #127
 STA P
 LDA K+3
 AND #127
 SBC P
 STA P
 BCS MV2

 LDA #1
 SBC INWK+3
 STA INWK+3
 LDA #0
 SBC INWK+4
 STA INWK+4
 LDA #0
 SBC P
 ORA #128

.MV2
 EOR T
 STA INWK+5\Y=K2-bZ

 LDA ALPHA
 STA Q
 LDA INWK+3
 STA P
 LDA INWK+4
 STA P+1
 LDA INWK+5
 JSR MULT3
 LDX #0
 JSR MVT3
 LDA K+1
 STA INWK
 LDA K+2
 STA INWK+1
 LDA K+3
 STA INWK+2\X=X+aY

 JMP MV45
\\]

;IFZ>4OSCLI"S.ELTA "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%
;PRINT "S.ELTA ",~W%," ",~O%," ",~L%," ",~H%

PRINT "ELITE<A>"
PRINT "ASSEMBLE AT W%=", ~C_A%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_A%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_A%

PRINT "S.ELTA ",~C_A%," ",~P%," ",~L%," ",~H_A%
SAVE "output/ELTA.bin", C_A%, P%, L%
PRINT "A d,";

\************************************************
\* ELITE<B>
\************************************************

;O%=W%
C_B%=P%
H_B%=L%+P%-C_A%
Q%=FALSE
J%=P%

\[OPTZ

.NA%
 EQUS "JAMESON"
 EQUB 13
 EQUB 0

 EQUB 20\QQ0
 EQUB 173\QQ1
 EQUD &2485A4A\QQ21
 EQUW &B753 \Base seed
;EQUD(((&E8030000)AND(NOTQ%))+((&CA9A3B)ANDQ%))\CASH,&80969800
IF Q%
 EQUD &CA9A3B
ELSE
 EQUD &E8030000
ENDIF
 EQUB 70 ;fuel
 EQUB 0 ;COK-UP
 EQUB 0 ;GALACTIC COUNT
 EQUB POW+(128 ANDQ%)
 EQUB (POW+128)ANDQ%
 EQUB 0
 EQUB 0
 EQUW 0 ;LASER
 EQUB 22+(15 ANDQ%) \37 CRGO
 EQUD 0
 EQUD 0
 EQUD 0
 EQUD 0
 EQUB 0\crgo
 EQUB Q% ;ECM
 EQUB Q% ;BST
 EQUB Q% AND 127 ;BOMB
 EQUB Q% AND 1 ;ENGY++
 EQUB Q% ;DCK COMP
 EQUB Q% ;GHYP
 EQUB Q% ;ESCP
 EQUD FALSE ;EXPAND
 EQUB 3+(Q%AND1) ;MISSILES
 EQUB FALSE ;FIST
 EQUB 16
 EQUB 15
 EQUB 17
 EQUB 0
 EQUB 3
 EQUB 28
 EQUB 14
 EQUW 0
 EQUB 10
 EQUB 0
 EQUB 17
 EQUB 58
 EQUB 7
 EQUB 9
 EQUB 8
 EQUB 0
 EQUB 0 ;QQ26
 EQUW 0 ;TALLY
 EQUB 128 ;SVC

PRINT "NT%=", ~NT%
PRINT "J%=", ~J%

IF 0        ; CHECKSUM PERFORMED IN BCFS.PY SCRIPT
CH%=NT%-2
CY%=0
FORI%,CH%+J%,1+J%,-1
CH%=CH%+CY%+(I%?7)
CY%=(CH%>255)AND1
CH%=CH%MOD256
CH%=CH%EOR(I%?8)
NEXT
ELSE
CH%=&92     ; HARDCODED CHECKSUM FOR BUILD
ENDIF

.CHK2
 EQUB CH% EOR &A9

.CHK
 EQUB CH%

.UNIV
FORI%,0,12
;!O%=K%+I%*NI%
;O%=O%+2
;P%=P%+2
 EQUW  K%+I%*NI%
NEXT

.TWOS
 EQUD &10204080
 EQUD &01020408

.TWOS2
 EQUD &183060C0
 EQUD &0303060C

.CTWOS
 EQUD &11224488
 EQUB &88

.LL30

.LOIN
 STY YSAV

 LDA #128
 STA S
 ASL A
 STA SWAP
 LDA X2
 SBC X1
 BCS LI1
 EOR #FF
 ADC #1
 SEC

.LI1
 STA P

 LDA Y2
 SBC Y1
 BCS LI2
 EOR #FF
 ADC #1

.LI2
 STA Q
 CMP P
 BCC STPX
 JMP STPY

.STPX
 LDX X1
 CPX X2
 BCC LI3
 DEC SWAP
 LDA X2
 STA X1
 STX X2
 TAX
 LDA Y2
 LDY Y1
 STA Y1
 STY Y2

.LI3
 LDA Y1
 LSR A
 LSR A
 LSR A
 ORA #&60
 STA SCH
 LDA Y1
 AND #7
 TAY
 TXA
 AND #&F8
 STA SC

 TXA
 AND #7
 TAX
 LDA TWOS,X
 STA R

 LDA Q
 LDX #254
 STX Q

.LIL1
 ASL A
 BCS LI4
 CMP P
 BCC LI5

.LI4
 SBC P
 SEC

.LI5
 ROL Q
 BCS LIL1

 LDX P
 INX
 LDA Y2
 SBC Y1
 BCS DOWN

 LDA SWAP
 BNE LI6
 DEX

.LIL2
 LDA R
 EOR (SC),Y
 STA (SC),Y

.LI6
 LSR R
 BCC LI7
 ROR R
 LDA SC
 ADC #8
 STA SC

.LI7
 LDA S
 ADC Q
 STA S
 BCC LIC2
 DEY
 BPL LIC2
 DEC SCH
 LDY #7

.LIC2
 DEX
 BNE LIL2
 LDY YSAV
 RTS

.DOWN
 LDA SWAP
 BEQ LI9
 DEX

.LIL3
 LDA R
 EOR (SC),Y
 STA (SC),Y

.LI9
 LSR R
 BCC LI10
 ROR R
 LDA SC
 ADC #8
 STA SC

.LI10
 LDA S
 ADC Q
 STA S
 BCC LIC3
 INY
 CPY #8
 BNE LIC3
 INC SCH
 LDY #0

.LIC3
 DEX
 BNE LIL3
 LDY YSAV
 RTS

.STPY
 LDY Y1
 TYA
 LDX X1
 CPY Y2
 BCS LI15
 DEC SWAP
 LDA X2
 STA X1
 STX X2
 TAX
 LDA Y2
 STA Y1
 STY Y2
 TAY

.LI15
 LSR A
 LSR A
 LSR A
 ORA #&60
 STA SCH
 TXA
 AND #&F8
 STA SC

 TXA
 AND #7
 TAX
 LDA TWOS,X
 STA R
 LDA Y1
 AND #7
 TAY

 LDA P
 LDX #1
 STX P

.LIL4
 ASL A
 BCS LI13
 CMP Q
 BCC LI14

.LI13
 SBC Q
 SEC

.LI14
 ROL P
 BCC LIL4
 LDX Q
 INX
 LDA X2
 SBC X1
 BCC LFT

 CLC
 LDA SWAP
 BEQ LI17
 DEX

.LIL5
 LDA R
 EOR (SC),Y
 STA (SC),Y

.LI17
 DEY
 BPL LI16
 DEC SCH
 LDY #7

.LI16
 LDA S
 ADC P
 STA S
 BCC LIC5
 LSR R
 BCC LIC5
 ROR R
 LDA SC
 ADC #8
 STA SC

.LIC5
 DEX
 BNE LIL5
 LDY YSAV
 RTS

.LFT
 LDA SWAP
 BEQ LI18
 DEX

.LIL6
 LDA R
 EOR (SC),Y
 STA (SC),Y

.LI18
 DEY
 BPL LI19
 DEC SCH
 LDY #7

.LI19
 LDA S
 ADC P
 STA S
 BCC LIC6

 ASL R
 BCC LIC6
 ROL R
 LDA SC
 SBC #7
 STA SC
 CLC

.LIC6
 DEX
 BNE LIL6
 LDY YSAV

.HL6
 RTS

.NLIN3
 JSR TT27

.NLIN4
 LDA #19
 BNE NLIN2

.NLIN
 LDA #23
 INC YC

.NLIN2
 STA Y1
 LDX #2
 STX X1
 LDX #254
 STX X2
 BNE HLOIN

.HLOIN2
 JSR EDGES
 STY Y1
 LDA #0
 STA LSO,Y

.HLOIN
 STY YSAV
 LDX X1
 CPX X2
 BEQ HL6
 BCC HL5
 LDA X2
 STA X1
 STX X2
 TAX

.HL5
 DEC X2

 LDA Y1
 LSR A
 LSR A
 LSR A
 ORA #&60
 STA SCH
 LDA Y1
 AND #7
 STA SC
 TXA
 AND #&F8
 TAY

.HL1
 TXA
 AND #&F8
 STA T
 LDA X2
 AND #&F8
 SEC
 SBC T
 BEQ HL2
 LSR A
 LSR A
 LSR A
 STA R

 LDA X1
 AND #7
 TAX
 LDA TWFR,X
 EOR (SC),Y
 STA (SC),Y
 TYA
 ADC #8
 TAY
 LDX R
 DEX
 BEQ HL3

 CLC

.HLL1
 LDA #FF
 EOR (SC),Y
 STA (SC),Y
 TYA
 ADC #8
 TAY
 DEX
 BNE HLL1

.HL3
 LDA X2
 AND #7
 TAX
 LDA TWFL,X
 EOR (SC),Y
 STA (SC),Y
 LDY YSAV
 RTS

.HL2
 LDA X1
 AND #7
 TAX
 LDA TWFR,X
 STA T
 LDA X2
 AND #7
 TAX
 LDA TWFL,X
 AND T
 EOR (SC),Y
 STA (SC),Y
 LDY YSAV
 RTS

.TWFL
 EQUD &F0E0C080
 EQUW &FCF8
 EQUB &FE

.TWFR
 EQUD &1F3F7FFF
 EQUD &0103070F

.PX3
 LDA TWOS,X
 EOR (SC),Y
 STA (SC),Y
 LDY T1
 RTS

.PIX1
 JSR ADD
 STA YY+1
 TXA
 STA SYL,Y

.PIXEL2
 LDA X1
 BPL PX1
 EOR #&7F
 CLC
 ADC #1

.PX1
 EOR #128
 TAX
 LDA Y1
 AND #127
 CMP #96
 BCS PX4
 LDA Y1
 BPL PX2
 EOR #&7F
 ADC #1

.PX2
 STA T
 LDA #97
 SBC T

.PIXEL
 STY T1
 TAY
 LSR A
 LSR A
 LSR A
 ORA #&60
 STA SCH
 TXA
 AND #&F8
 STA SC
 TYA
 AND #7
 TAY
 TXA
 AND #7
 TAX

 LDA ZZ
 CMP #&90
 BCS PX3
 LDA TWOS2,X
 EOR (SC),Y
 STA (SC),Y
 LDA ZZ
 CMP #&50
 BCS PX13
 DEY
 BPL PX14
 LDY #1

.PX14
 LDA TWOS2,X
 EOR (SC),Y
 STA (SC),Y

.PX13
 LDY T1

.PX4
 RTS

.BLINE
 TXA
 ADC K4
 STA K6+2
 LDA K4+1
 ADC T
 STA K6+3

 LDA FLAG
 BEQ BL1
 INC FLAG

.BL5
 LDY LSP
 LDA #FF
 CMP LSY2-1,Y
 BEQ BL7
 STA LSY2,Y
 INC LSP
 BNE BL7

.BL1
 LDA K5
 STA XX15
 LDA K5+1
 STA XX15+1

 LDA K5+2
 STA XX15+2
 LDA K5+3
 STA XX15+3

 LDA K6
 STA XX15+4
 LDA K6+1
 STA XX15+5

 LDA K6+2
 STA XX12
 LDA K6+3
 STA XX12+1

 JSR LL145
 BCS BL5
 LDA SWAP
 BEQ BL9
 LDA X1
 LDY X2
 STA X2
 STY X1
 LDA Y1
 LDY Y2
 STA Y2
 STY Y1
.BL9

 LDY LSP
 LDA LSY2-1,Y
 CMP #FF
 BNE BL8
 LDA X1
 STA LSX2,Y
 LDA Y1
 STA LSY2,Y
 INY

.BL8
 LDA X2
 STA LSX2,Y
 LDA Y2
 STA LSY2,Y
 INY
 STY LSP
 JSR LOIN

 LDA XX13
 BNE BL5

.BL7
 LDA K6
 STA K5
 LDA K6+1
 STA K5+1
 LDA K6+2
 STA K5+2
 LDA K6+3
 STA K5+3
 LDA CNT
 CLC
 ADC STP
 STA CNT
 RTS

.FLIP \LDAMJ\BNEFLIP-1
 LDY NOSTM

.FLL1
 LDX SY,Y
 LDA SX,Y
 STA Y1
 STA SY,Y
 TXA
 STA X1
 STA SX,Y
 LDA SZ,Y
 STA ZZ
 JSR PIXEL2
 DEY
 BNE FLL1
 RTS

.STARS \LDA#FF
\STACOL
 LDX VIEW
 BEQ STARS1
 DEX
 BNE ST11
 JMP STARS6

.ST11
 JMP STARS2

.STARS1
 LDY NOSTM

.STL1
 JSR DV42
 LDA R
 LSR P
 ROR A
 LSR P
 ROR A
 ORA #1
 STA Q

 LDA SZL,Y
 SBC DELT4
 STA SZL,Y
 LDA SZ,Y
 STA ZZ
 SBC DELT4+1
 STA SZ,Y

 JSR MLU1
 STA YY+1
 LDA P
 ADC SYL,Y
 STA YY
 STA R
 LDA Y1
 ADC YY+1
 STA YY+1
 STA S

 LDA SX,Y
 STA X1
 JSR MLU2
 STA XX+1
 LDA P
 ADC SXL,Y
 STA XX
 LDA X1
 ADC XX+1
 STA XX+1

 EOR ALP2+1
 JSR MLS1
 JSR ADD
 STA YY+1
 STX YY

 EOR ALP2
 JSR MLS2
 JSR ADD
 STA XX+1
 STX XX

 LDX BET1
 LDA YY+1
 EOR BET2+1
 JSR MULTS-2
 STA Q
 JSR MUT2
 ASL P
 ROL A
 STA T
 LDA #0
 ROR A
 ORA T
 JSR ADD
 STA XX+1
 TXA
 STA SXL,Y

 LDA YY
 STA R
 LDA YY+1
 STA S
\JSRMADSTASSTXR
 LDA #0
 STA P
 LDA BETA
 EOR #128

 JSR PIX1
 LDA XX+1
 STA X1
 STA SX,Y
 AND #127
 CMP #120
 BCS KILL1
 LDA YY+1
 STA SY,Y
 STA Y1
 AND #127
 CMP #120
 BCS KILL1

 LDA SZ,Y
 CMP #16
 BCC KILL1
 STA ZZ

.STC1
 JSR PIXEL2
 DEY
 BEQ P%+5
 JMP STL1
 RTS

.KILL1
 JSR DORND
 ORA #4
 STA Y1
 STA SY,Y
 JSR DORND
 ORA #8
 STA X1
 STA SX,Y
 JSR DORND
 ORA #&90
 STA SZ,Y
 STA ZZ
 LDA Y1
 JMP STC1

.STARS6

 LDY NOSTM

.STL6
 JSR DV42
 LDA R
 LSR P
 ROR A
 LSR P
 ROR A
 ORA #1
 STA Q

 LDA SX,Y
 STA X1
 JSR MLU2
 STA XX+1
 LDA SXL,Y
 SBC P
 STA XX
 LDA X1
 SBC XX+1
 STA XX+1

 JSR MLU1
 STA YY+1
 LDA SYL,Y
 SBC P
 STA YY
 STA R
 LDA Y1
 SBC YY+1
 STA YY+1
 STA S

 LDA SZL,Y
 ADC DELT4
 STA SZL,Y
 LDA SZ,Y
 STA ZZ
 ADC DELT4+1
 STA SZ,Y

 LDA XX+1
 EOR ALP2
 JSR MLS1
 JSR ADD
 STA YY+1
 STX YY

 EOR ALP2+1
 JSR MLS2
 JSR ADD
 STA XX+1
 STX XX

 LDA YY+1
 EOR BET2+1
 LDX BET1
 JSR MULTS-2
 STA Q
 LDA XX+1
 STA S
 EOR #128
 JSR MUT1
 ASL P
 ROL A
 STA T
 LDA #0
 ROR A
 ORA T
 JSR ADD
 STA XX+1
 TXA
 STA SXL,Y

 LDA YY
 STA R
 LDA YY+1
 STA S
\EOR#128
\JSRMADSTASSTXR
 LDA #0
 STA P
 LDA BETA

 JSR PIX1
 LDA XX+1
 STA X1
 STA SX,Y
 LDA YY+1
 STA SY,Y
 STA Y1
 AND #127
 CMP #110
 BCS KILL6

 LDA SZ,Y
 CMP #160
 BCS KILL6
 STA ZZ

.STC6
 JSR PIXEL2
 DEY
 BEQ ST3
 JMP STL6

.ST3
 RTS

.KILL6
 JSR DORND
 AND #127
 ADC #10
 STA SZ,Y
 STA ZZ
 LSR A
 BCS ST4
 LSR A
 LDA #&FC
 ROR A
 STA X1
 STA SX,Y
 JSR DORND
 STA Y1
 STA SY,Y
 JMP STC6

.ST4
 JSR DORND
 STA X1
 STA SX,Y
 LSR A
 LDA #230
 ROR A
 STA Y1
 STA SY,Y
 BNE STC6

.PRXS
 EQUW 1
 EQUW 300
 EQUW 4000
 EQUW 6000
 EQUW 4000
 EQUW 10000
 EQUW 5250
 EQUW 10000
 EQUW 9000
 EQUW 15000
 EQUW 10000
 EQUW 50000

.st4
 LDX #9
 CMP #25
 BCS st3
 DEX
 CMP #10
 BCS st3
 DEX
 CMP #2
 BCS st3
 DEX
 BNE st3

.STATUS
 LDA #8
 JSR TT66
 JSR TT111
 LDA #7
 STA XC
 LDA #126
 JSR NLIN3
 LDA #15
 LDY QQ12
 BNE st6
 LDA #230
 LDY MANY+AST
 LDX FRIN+2,Y
 BEQ st6
 LDY ENERGY
 CPY #128
 ADC #1

.st6
 JSR plf
 LDA #125
 JSR spc
 LDA #19
 LDY FIST
 BEQ st5
 CPY #50
 ADC #1

.st5
 JSR plf
 LDA #16

 JSR spc
 LDA TALLY+1
 BNE st4
 TAX
 LDA TALLY
 LSR A
 LSR A
 INX
 LSR A
 BNE P%-2

.st3
 TXA
 CLC
 ADC #21
 JSR plf

 LDA #18
 JSR plf2
 LDA CRGO
 CMP #26
 BCC P%+7
 LDA #&6B
 JSR plf2
 LDA BST
 BEQ P%+7
 LDA #111
 JSR plf2
 LDA ECM
 BEQ P%+7
 LDA #&6C
 JSR plf2
 LDA #113
 STA XX4

.stqv
 TAY
 LDX BOMB-113,Y
 BEQ P%+5
 JSR plf2
 INC XX4
 LDA XX4
 CMP #117
 BCC stqv

 LDX #0

.st
 STX CNT
 LDY LASER,X
 BEQ st1
 TXA
 CLC
 ADC #96
 JSR spc
 LDA #103
 LDX CNT
 LDY LASER,X
 BPL P%+4
 LDA #104
 JSR plf2

.st1
 LDX CNT
 INX
 CPX #4
 BCC st
 RTS

.plf2
 JSR plf
 LDX #6
 STX XC
 RTS

.TENS
 EQUD &E87648

.pr2
 LDA #3
 LDY #0

.TT11
 STA U
 LDA #0
 STA K
 STA K+1
 STY K+2
 STX K+3

.BPRNT
 LDX #11
 STX T
 PHP
 BCC TT30
 DEC T
 DEC U

.TT30
 LDA #11
 SEC
 STA XX17
 SBC U
 STA U
 INC U
 LDY #0
 STY S
 JMP TT36

.TT35
 ASL K+3
 ROL K+2
 ROL K+1
 ROL K
 ROL S
 LDX #3

.tt35
 LDA K,X
 STA XX15,X
 DEX
 BPL tt35
 LDA S
 STA XX15+4

 ASL K+3
 ROL K+2
 ROL K+1
 ROL K
 ROL S
 ASL K+3
 ROL K+2
 ROL K+1
 ROL K
 ROL S
 CLC
 LDX #3
.tt36 LDAK,X
 ADC XX15,X
 STA K,X
 DEX
 BPL tt36
 LDA XX15+4
 ADC S
 STA S

 LDY #0
.TT36 LDX#3
 SEC
.tt37 LDAK,X
 SBC TENS,X
 STA XX15,X
 DEX
 BPL tt37
 LDA S
 SBC #23
 STA XX15+4

 BCC TT37
 LDX #3
.tt38 LDAXX15,X
 STA K,X
 DEX
 BPL tt38
 LDA XX15+4
 STA S
 INY
 JMP TT36

.TT37
 TYA
 BNE TT32
 LDA T
 BEQ TT32
 DEC U
 BPL TT34
 LDA #32
 BNE tt34

.TT32
 LDY #0
 STY T
 CLC
 ADC #B

.tt34
 JSR TT26

.TT34
 DEC T
 BPL P%+4
 INC T
 DEC XX17
 BMI RR3+1 \!!
 BNE P%+10
 PLP
 BCC P%+7
 LDA #&2E
 JSR TT26
 JMP TT35

.BELL
 LDA #7

.TT26 \PRINT
 STA K3
 STY YSAV2
 STX XSAV2
 LDY QQ17
 CPY #FF
 BEQ RR4

 CMP #7
 BEQ R5
 CMP #32
 BCS RR1
 CMP #10
 BEQ RRX1
 LDX #1
 STX XC

.RRX1
 INC YC
 BNE RR4

.RR1
\LDX#(K3 MOD256)
\INX
\STXP+1
\DEX
\LDY#(K3 DIV256)
\STYP+2\LDA#10\JSROSWORD
 TAY
 LDX #&BF
 ASL A
 ASL A
 BCC P%+4
 LDX #&C1
 ASL A
 BCC P%+3
 INX
 STA P+1
 STX P+2

 LDA XC
 ASL A
 ASL A
 ASL A
 STA SC
 LDA YC
 CPY #&7F
 BNE RR2
 DEC XC
 ADC #&5E
 TAX
 LDY #&F8
 JSR ZES2
 BEQ RR4

.RR2
 INC XC
\LDAYC
 CMP #24
 BCC RR3
 JSR TTX66
 JMP RR4

.RR3
 ORA #&60

.RREN
 STA SC+1
 LDY #7

.RRL1
 LDA (P+1),Y
 EOR (SC),Y
 STA (SC),Y
 DEY
 BPL RRL1

.RR4
 LDY YSAV2
 LDX XSAV2
 LDA K3
 CLC

.rT9
 RTS

.R5
 JSR BEEP
 JMP RR4

.DIALS
 LDA #&D0
 STA SC
 LDA #&78
 STA SC+1
 JSR PZW
 STX K+1
 STA K
 LDA #14
 STA T1
 LDA DELTA
\LSRA
 JSR DIL-1

 LDA #0
 STA R
 STA P
 LDA #8
 STA S
 LDA ALP1
 LSR A
 LSR A
 ORA ALP2
 EOR #128
 JSR ADD
 JSR DIL2
 LDA BETA
 LDX BET1
 BEQ P%+4
 SBC #1
 JSR ADD
 JSR DIL2

 LDA MCNT
 AND #3
 BNE rT9
 LDY #0
 JSR PZW
 STX K
 STA K+1
 LDX #3
 STX T1
.DLL23 STYXX12,X
 DEX
 BPL DLL23
 LDX #3
 LDA ENERGY
 LSR A
 LSR A
 STA Q

.DLL24
 SEC
 SBC #16
 BCC DLL26
 STA Q
 LDA #16
 STA XX12,X
 LDA Q
 DEX
 BPL DLL24
 BMI DLL9

.DLL26
 LDA Q
 STA XX12,X

.DLL9
 LDA XX12,Y
 STY P
 JSR DIL
 LDY P
 INY
 CPY #4
 BNE DLL9

 LDA #&78
 STA SC+1
 LDA #16
\"�<80<
 STA SC
 LDA FSH
 JSR DILX
 LDA ASH
 JSR DILX
 LDA QQ14
 JSR DILX+2

 JSR PZW
 STX K+1
 STA K
 LDX #11
 STX T1
 LDA CABTMP
 JSR DILX
 LDA GNTMP
 JSR DILX

 LDA #&F0
 STA T1
 STA K+1
 LDA ALTIT
 JSR DILX
 JMP COMPAS

.PZW
 LDX #&F0
 LDA MCNT
 AND #8
 AND FLH
 BEQ P%+4
 TXA
 EQUB &2C
 LDA #15
 RTS

.DILX
 LSR A
 LSR A
 LSR A
 LSR A

.DIL
 STA Q
 LDX #FF
 STX R
 CMP T1
 BCS DL30
 LDA K+1
 BNE DL31

.DL30
 LDA K

.DL31
 STA COL
 LDY #2
 LDX #3

.DL1
 LDA Q
 CMP #4
 BCC DL2
 SBC #4
 STA Q
 LDA R

.DL5
 AND COL
 STA (SC),Y
 INY
 STA (SC),Y
 INY
 STA (SC),Y
 TYA
 CLC
 ADC #6
 TAY
 DEX
 BMI DL6
 BPL DL1

.DL2
 EOR #3
 STA Q
 LDA R

.DL3
 ASL A
 AND #239
 DEC Q
 BPL DL3
 PHA
 LDA #0
 STA R
 LDA #99
 STA Q
 PLA
 JMP DL5

.DL6
 INC SC+1

.DL9
 RTS

.DIL2
 LDY #1
 STA Q

.DLL10
 SEC
 LDA Q
 SBC #4
 BCS DLL11
 LDA #FF
 LDX Q
 STA Q
 LDA CTWOS,X
 AND #&F0
 BNE DLL12

.DLL11
 STA Q
 LDA #0

.DLL12
 STA (SC),Y
 INY
 STA (SC),Y
 INY
 STA (SC),Y
 INY
 STA (SC),Y
 TYA
 CLC
 ADC #5
 TAY
 CPY #30
 BCC DLL10
 INC SC+1
 RTS

.TVT1
 EQUD &8494C4D4
\TVT2
 EQUD &A5B5E5F5
 EQUD &26366676
 EQUD &A1B1F1E1
\TVT3
 EQUD &A0B0E0F0
 EQUD &8090C0D0
 EQUD &27376777

.LINSCN
 LDA #30
 STA DL
 STA USVIA+4
 LDA #VSCAN
 STA USVIA+5
 LDA HFX
 BNE VNT1
 LDA #8
 STA &FE20
.VNT3
 LDA TVT1+16,Y
 STA &FE21
 DEY
 BPL VNT3
 LDA LASCT
 BEQ P%+5
 DEC LASCT
\VNT4
 LDA svn
 BNE jvec
 PLA
 TAY
 LDA &FE41
 LDA &FC
 RTI

.IRQ1
 TYA
 PHA
 LDY #11
 LDA #2
 BIT VIA+&D
 BNE LINSCN
 BVC jvec
 ASL A\4
 STA &FE20
 LDA ESCP
 BNE VNT1
\VNT2
 LDA TVT1,Y
 STA &FE21
 DEY
 BPL P%-7

.jvec
 PLA
 TAY
 JMP (VEC)

.VNT1
 LDY #7
 LDA TVT1+8,Y
 STA &FE21
 DEY
 BPL VNT1+2
 BMI jvec

.ESCAPE
 LDA MJ
 PHA
 JSR RES2
 LDX #CYL
 STX TYPE
 JSR FRS1
 LDA #8
 STA INWK+27
 LDA #&C2
 STA INWK+30
 LSR A
 STA INWK+32

.ESL1
 JSR MVEIT
 JSR LL9
 DEC INWK+32
 BNE ESL1
 JSR SCAN
 JSR RESET
 PLA
 BEQ P%+5
 JMP DEATH
 LDX #16

.ESL2
 STA QQ20,X
 DEX
 BPL ESL2
 STA FIST
 STA ESCP
 LDA #70
 STA QQ14
 JMP BAY

;IFZ>4OSCLI("S.ELTB "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%)
;PRINT "S.ELTB ",~W%," ",~O%," ",~L%," ",~H_B%

PRINT "ELITE<B>"
PRINT "ASSEMBLE AT W%=", ~C_B%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_B%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_B%

PRINT "S.ELTB ",~C_B%," ",~P%," ",~L%," ",~H_B%
SAVE "output/ELTB.bin", C_B%, P%, L%
PRINT "B done,";

\************************************************
\* ELITE<C>
\************************************************

;O%=W%
;H%=L%+P%-C%
C_C%=P%
H_C%=L%+P%-C_A%

\[OPTZ

.TA34
 LDA #0
 JSR MAS4
 BEQ P%+5
 JMP TA21
 JSR TA87+3
 JSR EXNO3
 LDA #250
 JMP OOPS

.TA18
\msl
 LDA ECMA
 BNE TA35
 LDA INWK+32
 ASL A
 BMI TA34
 LSR A

 TAX
 LDA UNIV,X
 STA V
 LDA UNIV+1,X
 STA V+1
 LDY #2
 JSR TAS1
 LDY #5
 JSR TAS1
 LDY #8
 JSR TAS1

 LDA K3+2
 ORA K3+5
 ORA K3+8
 AND #127
 ORA K3+1
 ORA K3+4
 ORA K3+7
 BNE TA64

 LDA INWK+32
 CMP #&82
 BEQ TA35
 LDY #31
 LDA (V),Y
 BIT M32+1
 BNE TA35
 ORA #128
 STA (V),Y

.TA35
 LDA INWK
 ORA INWK+3
 ORA INWK+6
 BNE TA87
 LDA #80
 JSR OOPS

.TA87
 JSR EXNO2
 ASL INWK+31
 SEC
 ROR INWK+31

.TA1
 RTS

.TA64
 JSR DORND
 CMP #16
 BCS TA19

.M32
 LDY #32
 LDA (V),Y
 LSR A
 BCC TA19
 JMP ECBLB2

.TACTICS
 CPX #MSL
 BEQ TA18
 CPX #ESC
 BNE P%+8
 JSR SPS1
 JMP TA15
 CPX #SST
 BNE TA13
 JSR DORND
 CMP #140
 BCC TA14-1
 LDA MANY+SH3
 CMP #4
 BCS TA14-1
 LDX #COPS
 LDA #&F1
 JMP SFS1

.TA13
 CPX #TGL
 BNE TA14
 LDA MANY+THG
 BNE TA14
 LSR INWK+32
 ASL INWK+32
 LSR INWK+27
 RTS

.TA14
 CPX #CYL
 BCS TA62
 CPX #COPS
 BEQ TA62
 LDA SSPR
 BEQ TA62
 LDA INWK+32
 AND #129
 STA INWK+32

.TA62
 LDY #14
 LDA INWK+35
 CMP (XX0),Y
 BCS TA21
 INC INWK+35

.TA21
 LDX #8

.TAL1
 LDA INWK,X
 STA K3,X
 DEX
 BPL TAL1

.TA19
 JSR TAS2\XX15=r~96

 LDY #10
 JSR TAS3
 STA CNT
 LDA TYPE
 CMP #MSL
 BNE P%+5
 JMP TA20
 JSR DORND
 CMP #250
 BCC TA7
 JSR DORND
 ORA #&68
 STA INWK+29

.TA7
\VRol
 LDY #14
 LDA (XX0),Y
 LSR A
 CMP INWK+35
 BCC TA3
 LSR A
 LSR A
 CMP INWK+35
 BCC ta3
 JSR DORND
 CMP #230
 BCC ta3
 LDA TYPE
 CMP #THG
 BEQ ta3
 LDA #0
 STA INWK+32
 JMP SESCP

.ta3
 LDA INWK+31
 AND #7
 BEQ TA3
 STA T
 JSR DORND
 AND #31
 CMP T
 BCS TA3
 LDA ECMA
 BNE TA3
 DEC INWK+31
 LDA TYPE
 CMP #THG
 BNE TA16
 LDX #TGL
 LDA INWK+32
 JMP SFS1

.TA16
 JMP SFRMIS

.TA3
 LDA #0
 JSR MAS4
 AND #&E0
 BNE TA4
 LDX CNT
 CPX #160
 BCC TA4
 LDA INWK+31
 ORA #64
 STA INWK+31
 CPX #163
 BCC TA4

 LDY #19
 LDA (XX0),Y
 LSR A
 JSR OOPS
 DEC INWK+28
 LDA ECMA
 BNE TA10
 LDA #8
 JMP NOISE
\frLs

.TA4
 LDA INWK+7
 CMP #3
 BCS TA5
 LDA INWK+1
 ORA INWK+4
 AND #&FE
 BEQ TA15

.TA5
 JSR DORND
 ORA #128
 CMP INWK+32
 BCS TA15

.TA20
 LDA XX15
 EOR #128
 STA XX15
 LDA XX15+1
 EOR #128
 STA XX15+1
 LDA XX15+2
 EOR #128
 STA XX15+2
 LDA CNT
 EOR #128
 STA CNT

.TA15
\^XX15
 LDY #16
 JSR TAS3
 EOR #128
 AND #128
 ORA #3
 STA INWK+30

 LDA INWK+29
 AND #127
 CMP #16
 BCS TA6

 LDY #22
 JSR TAS3
 EOR INWK+30
 AND #128
 EOR #&85
 STA INWK+29

.TA6
 LDA CNT
 BMI TA9
 CMP #22
 BCC TA9
 LDA #3
 STA INWK+28
 RTS

.TA9
 AND #127
 CMP #18
 BCC TA10
 LDA #FF
 LDX TYPE
 CPX #MSL
 BNE P%+3
 ASL A
 STA INWK+28

.TA10
 RTS

.TAS1
 LDA (V),Y
 EOR #128
 STA K+3
 DEY
 LDA (V),Y
 STA K+2
 DEY
 LDA (V),Y
 STA K+1
 STY U
 LDX U
 JSR MVT3
 LDY U

 STA K3+2,X
 LDA K+2
 STA K3+1,X
 LDA K+1
 STA K3,X
 RTS

.HITCH
 CLC
 LDA INWK+8
 BNE HI1
 LDA TYPE
 BMI HI1
 LDA INWK+31
 AND #32
 ORA INWK+1
 ORA INWK+4
 BNE HI1

 LDA INWK
 JSR SQUA2
 STA S
 LDA P
 STA R

 LDA INWK+3
 JSR SQUA2
 TAX
 LDA P
 ADC R
 STA R
 TXA
 ADC S
 BCS FR1-2
 STA S
 LDY #2
 LDA (XX0),Y
 CMP S
 BNE HI1
 DEY
 LDA (XX0),Y
 CMP R

.HI1
 RTS

.FRS1
 JSR ZINF
 LDA #28
 STA INWK+3
 LSR A
 STA INWK+6
 LDA #128
 STA INWK+5
 LDA MSTG
 ASL A
 ORA #128
 STA INWK+32

.fq1
 LDA #96
 STA INWK+14
 ORA #128
 STA INWK+22
 LDA DELTA
 ROL A
 STA INWK+27
 TXA
 JMP NWSHP

.FRMIS
 LDX #MSL
 JSR FRS1
 BCC FR1
 LDX MSTG
 JSR GINF
 LDA FRIN,X
 JSR ANGRY
 LDY #0
 JSR ABORT
 DEC NOMSL
 LDA #48
 JMP NOISE

.ANGRY
 CMP #SST
 BEQ AN2
 BCS HI1
 CMP #CYL
 BNE P%+5
 JSR AN2
 LDY #32
 LDA (INF),Y
 BEQ HI1
 ORA #128
 STA (INF),Y
 LDY #28
 LDA #2
 STA (INF),Y
 ASL A
 LDY #30
 STA (INF),Y
 RTS

.AN2
 ASL K%+NI%+32
 SEC
 ROR K%+NI%+32
 CLC
 RTS

.FR1
 LDA #201
 JMP MESS

.SESCP
 LDX #ESC
 LDA #&FE

.SFS1
 STA T1
 LDA XX0
 PHA
 LDA XX0+1
 PHA
 LDA INF
 PHA
 LDA INF+1
 PHA
 LDY #NI%-1

.FRL2
 LDA INWK,Y
 STA XX3,Y
 LDA (INF),Y
 STA INWK,Y
 DEY
 BPL FRL2

 LDA TYPE
 CMP #SST
 BNE rx
 TXA
 PHA
 LDA #32
 STA INWK+27
 LDX #0
 LDA INWK+10
 JSR SFS2
 LDX #3
 LDA INWK+12
 JSR SFS2
 LDX #6
 LDA INWK+14
 JSR SFS2
 PLA
 TAX

.rx
 LDA T1
 STA INWK+32
 LSR INWK+29
 ASL INWK+29
 TXA
 CMP #OIL
 BNE NOIL
 JSR DORND
 ASL A
 STA INWK+30
 TXA
 AND #15
 STA INWK+27
 LDA #FF
 ROR A
 STA INWK+29
 LDA #OIL

.NOIL
 JSR NWSHP

 PLA
 STA INF+1
 PLA
 STA INF
 LDX #NI%-1

.FRL3
 LDA XX3,X
 STA INWK,X
 DEX
 BPL FRL3
 PLA
 STA XX0+1
 PLA
 STA XX0
 RTS

.SFS2
 ASL A
 STA R
 LDA #0
 ROR A
 JMP MVT1

.LL164
 LDA #56
 JSR NOISE
 LDA #1
 STA HFX
 LDA #4
 JSR HFS2
 DEC HFX
 RTS

.LAUN
 LDA #48
 JSR NOISE
 LDA #8

.HFS2
 STA STP
 JSR TTX66
 JSR HFS1

.HFS1
 LDA #128
 STA K3
 LDX #Y
 STX K4
 ASL A
 STA XX4
 STA K3+1
 STA K4+1

.HFL5
 JSR HFL1
 INC XX4
 LDX XX4
 CPX #8
 BNE HFL5
 RTS

.HFL1
 LDA XX4
 AND #7
 CLC
 ADC #8
 STA K

.HFL2
 LDA #1
 STA LSP
 JSR CIRCLE2
 ASL K
 BCS HF8
 LDA K
 CMP #160
 BCC HFL2

.HF8
 RTS

.STARS2
 LDA #0
 CPX #2
 ROR A
 STA RAT
 EOR #128
 STA RAT2
 JSR ST2

 LDY NOSTM

.STL2
 LDA SZ,Y
 STA ZZ
 LSR A
 LSR A
 LSR A
 JSR DV41
 LDA P
 EOR RAT2
 STA S
 LDA SXL,Y
 STA P
 LDA SX,Y
 STA X1
 JSR ADD

 STA S
 STX R
 LDA SY,Y
 STA Y1
 EOR BET2
 LDX BET1
 JSR MULTS-2
 JSR ADD
 STX XX
 STA XX+1

 LDX SYL,Y
 STX R
 LDX Y1
 STX S
 LDX BET1
 EOR BET2+1
 JSR MULTS-2
 JSR ADD
 STX YY
 STA YY+1

 LDX ALP1
 EOR ALP2
 JSR MULTS-2
 STA Q
 LDA XX
 STA R
 LDA XX+1
 STA S
 EOR #128
 JSR MAD
 STA XX+1
 TXA
 STA SXL,Y

 LDA YY
 STA R
 LDA YY+1
 STA S
 JSR MAD
 STA S
 STX R
 LDA #0
 STA P
 LDA ALPHA

 JSR PIX1
 LDA XX+1
 STA SX,Y
 STA X1

 AND #127
 CMP #116
 BCS KILL2
 LDA YY+1
 STA SY,Y
 STA Y1
 AND #127
 CMP #116
 BCS ST5

.STC2
 JSR PIXEL2
 DEY
 BEQ ST2
 JMP STL2

.ST2
 LDA ALPHA
 EOR RAT
 STA ALPHA
 LDA ALP2
 EOR RAT
 STA ALP2
 EOR #128
 STA ALP2+1
 LDA BET2
 EOR RAT
 STA BET2
 EOR #128
 STA BET2+1
 RTS

.KILL2
 JSR DORND
 STA Y1
 STA SY,Y
 LDA #115
 ORA RAT
 STA X1
 STA SX,Y
 BNE STF1

.ST5
 JSR DORND
 STA X1
 STA SX,Y
 LDA #110
 ORA ALP2+1
 STA Y1
 STA SY,Y

.STF1
 JSR DORND
 ORA #8
 STA ZZ
 STA SZ,Y
 BNE STC2

.SNE
FORI%,0,31
N=ABS(SIN(I%/64*2*PI))
;IFN>=1 I%?O%=FF
;ELSEI%?O%=INT(256*N+.5)
IF N>=1
    EQUB FF
ELSE
    EQUB INT(256*N+.5)
ENDIF
NEXT

;O%=O%+32
;P%=P%+32

.MU5
 STA K
 STA K+1
 STA K+2
 STA K+3
 CLC
 RTS

.MULT3
\K(4)=AP(2)*Q
 STA R
 AND #127
 STA K+2
 LDA Q
 AND #127
 BEQ MU5
 SEC
 SBC #1
 STA T
 LDA P+1
 LSR K+2
 ROR A
 STA K+1
 LDA P
 ROR A
 STA K
 LDA #0
 LDX #24

.MUL2
 BCC P%+4
 ADC T
 ROR A
 ROR K+2
 ROR K+1
 ROR K
 DEX
 BNE MUL2
 STA T
 LDA R
 EOR Q
 AND #128
 ORA T
 STA K+3
 RTS

.MLS2
 LDX XX
 STX R
 LDX XX+1
 STX S

.MLS1
 LDX ALP1
 STX P

.MULTS
\AP=A*P(P+<32)
 TAX
 AND #128
 STA T
 TXA
 AND #127
 BEQ MU6
 TAX
 DEX
 STX T1
 LDA #0

 LSR P
 BCC P%+4
 ADC T1
 ROR A
 ROR P
 BCC P%+4
 ADC T1
 ROR A
 ROR P
 BCC P%+4
 ADC T1
 ROR A
 ROR P
 BCC P%+4
 ADC T1
 ROR A
 ROR P
 BCC P%+4
 ADC T1
 ROR A
 ROR P

 LSR A
 ROR P
 LSR A
 ROR P
 LSR A
 ROR P
 ORA T
 RTS

.SQUA
\AP=A*ApresQ
 AND #127

.SQUA2
 STA P
 TAX
 BNE MU11

.MU1
 CLC
 STX P
 TXA
 RTS

.MLU1
 LDA SY,Y
 STA Y1

.MLU2
 AND #127
 STA P

.MULTU
\AP=P*Qunsg
 LDX Q
 BEQ MU1

.MU11
 DEX
 STX T
 LDA #0
 LDX #8
 LSR P
{
.MUL6
 BCC P%+4
 ADC T
 ROR A
 ROR P
 DEX
 BNE MUL6
 RTS
}

.MU6
 STA P+1
 STA P
 RTS

.FMLTU2
 AND #31
 TAX
 LDA SNE,X
 STA Q
 LDA K

.FMLTU
\A=A*Q/256unsg
 EOR #FF
 SEC
 ROR A
 STA P
 LDA #0

.MUL3
 BCS MU7
 ADC Q
 ROR A
 LSR P
 BNE MUL3
 RTS

.MU7
 LSR A
 LSR P
 BNE MUL3
 RTS

 LDX Q
 BEQ MU1
 DEX
 STX T
 LDA #0
 LDX #8
 LSR P
{
.MUL6
 BCC P%+4
 ADC T
 ROR A
 ROR P
 DEX
 BNE MUL6
 RTS
}

 STX Q

.MLTU2
\AP(2)=AP*Qunsg(EORP)
 EOR #FF
 LSR A
 STA P+1
 LDA #0
 LDX #16
 ROR P

.MUL7
 BCS MU21
 ADC Q
 ROR A
 ROR P+1
 ROR P
 DEX
 BNE MUL7
 RTS

.MU21
 LSR A
 ROR P+1
 ROR P
 DEX
 BNE MUL7
 RTS

.MUT3
 LDX ALP1
 STX P

.MUT2
 LDX XX+1
 STX S

.MUT1
 LDX XX
 STX R

.MULT1
\AP=Q*A
 TAX
 AND #127
 LSR A
 STA P
 TXA
 EOR Q
 AND #128
 STA T
 LDA Q
 AND #127
 BEQ mu10
 TAX
 DEX
 STX T1
 LDA #0
 LDX #7

.MUL4
 BCC P%+4
 ADC T1
 ROR A
 ROR P
 DEX
 BNE MUL4
 LSR A
 ROR P
 ORA T
 RTS

.mu10
 STA P
 RTS

.MULT12
 JSR MULT1
 STA S
 LDA P
 STA R
 RTS

.TAS3
 LDX INWK,Y
 STX Q
 LDA XX15
 JSR MULT12
 LDX INWK+2,Y
 STX Q
 LDA XX15+1
 JSR MAD
 STA S
 STX R

 LDX INWK+4,Y
 STX Q
 LDA XX15+2

.MAD
 JSR MULT1

.ADD
\AX=AP+SR
 STA T1
 AND #128
 STA T
 EOR S
 BMI MU8
 LDA R
 CLC
 ADC P
 TAX
 LDA S
 ADC T1
 ORA T
 RTS

.MU8
 LDA S
 AND #127
 STA U
 LDA P
 SEC
 SBC R
 TAX
 LDA T1
 AND #127
 SBC U
 BCS MU9
 STA U
 TXA
 EOR #FF
 ADC #1
 TAX
 LDA #0
 SBC U
 ORA #128

.MU9
 EOR T
 RTS

\DVIDT(A=AP/Q)inF

.TIS1
 STX Q
 EOR #128
 JSR MAD

.DVID96
\A=A/96
 TAX
 AND #128
 STA T
 TXA
 AND #127
 LDX #254
 STX T1

.DVL3
 ASL A
 CMP #96
 BCC DV4
 SBC #96

.DV4
 ROL T1
 BCS DVL3
 LDA T1
 ORA T
 RTS

.DV42
 LDA SZ,Y

.DV41
 STA Q
 LDA DELTA

.DVID4
\P-R=A/Qunsg
 LDX #8
 ASL A
 STA P
 LDA #0

.DVL4
 ROL A
 BCS DV8
 CMP Q
 BCC DV5

.DV8
 SBC Q
 SEC

.DV5
 ROL P
 DEX
 BNE DVL4
 JMP LL28+4

.DVID3B2
 STA P+2
 LDA INWK+6
 STA Q
 LDA INWK+7
 STA R
 LDA INWK+8
 STA S

.DVID3B
\K+1(3)-K=P(3)/SRQaprx
 LDA P
 ORA #1
 STA P
 LDA P+2
 EOR S
 AND #128
 STA T
 LDY #0
 LDA P+2
 AND #127

.DVL9
 CMP #&40
 BCS DV14
 ASL P
 ROL P+1
 ROL A
 INY
 BNE DVL9

.DV14
 STA P+2
 LDA S
 AND #127
 BMI DV9

.DVL6
 DEY
 ASL Q
 ROL R
 ROL A
 BPL DVL6

.DV9
 STA Q
 LDA #254
 STA R
 LDA P+2
 JSR LL31

 LDA #0
 STA K+1
 STA K+2
 STA K+3
 TYA
 BPL DV12
 LDA R

.DVL8
 ASL A
 ROL K+1
 ROL K+2
 ROL K+3
 INY
 BNE DVL8
 STA K
 LDA K+3
 ORA T
 STA K+3
 RTS

.DV13
 LDA R
 STA K
 LDA T
 STA K+3
 RTS

.DV12
 BEQ DV13
 LDA R

.DVL10
 LSR A
 DEY
 BNE DVL10
 STA K
 LDA T
 STA K+3
 RTS

.cntr
 LDA DAMP
 BNE RE1
 TXA
 BPL BUMP
 DEX
 BMI RE1

.BUMP
 INX
 BNE RE1

.REDU
 DEX
 BEQ BUMP

.RE1
 RTS

.BUMP2
 STA T
 TXA
 CLC
 ADC T
 TAX
 BCC RE2
 LDX #FF

.RE2
 BPL RE3+2
 LDA T
 RTS

.REDU2
 STA T
 TXA
 SEC
 SBC T
 TAX
 BCS RE3
 LDX #1

.RE3
 BPL RE2+2
 LDA DJD
 BNE RE2+2
 LDX #128
 BMI RE2+2

.ARCTAN
\A=TAN-1(P/Q)
 LDA P
 EOR Q
 STA T1
 LDA Q
 BEQ AR2
 ASL A
 STA Q
 LDA P
 ASL A
 CMP Q
 BCS AR1
 JSR ARS1
 SEC

.AR4
 LDX T1
 BMI AR3
 RTS

.AR1
 LDX Q
 STA Q
 STX P
 TXA
 JSR ARS1
 STA T
 LDA #64
 SBC T
 BCS AR4

.AR2
 LDA #63
 RTS

.AR3
 STA T
 LDA #128
\SEC
 SBC T
 RTS

.ARS1
 JSR LL28
 LDA R
 LSR A
 LSR A
 LSR A
 TAX
 LDA ACT,X
 RTS

.ACT
FOR I%,0,31
;I%?O%=INT(128/PI*ATN(I%/32)+.5)
 EQUB  INT(128/PI*ATN(I%/32)+.5)
NEXT
;P%=P%+32
;O%=O%+32

.WARP
 LDA MANY+AST
 CLC
 ADC MANY+ESC
 CLC         ; NOT IN ELITEC.TXT but is in ELITE SOURCE IMAGE

 ADC MANY+OIL
 TAX
 LDA FRIN+2,X
 ORA SSPR
 ORA MJ
 BNE WA1
 LDY K%+8
 BMI WA3
 TAY
 JSR MAS2
;LSRA
;BEQWA1
 CMP  #2
 BCC  WA1     ; NOT IN ELITEC.TXT but is in ELITE SOURCE IMAGE

.WA3
 LDY K%+NI%+8
 BMI WA2
 LDY #NI%
 JSR m
;LSRA
;BEQWA1
 CMP  #2
 BCC  WA1     ; NOT IN ELITEC.TXT but is in ELITE SOURCE IMAGE

.WA2
 LDA #&81
 STA S
 STA R
 STA P
 LDA K%+8
 JSR ADD
 STA K%+8
 LDA K%+NI%+8
 JSR ADD
 STA K%+NI%+8

 LDA #1
 STA QQ11
 STA MCNT
 LSR A
 STA EV
 LDX VIEW
 JMP LOOK1

.WA1
 LDA #40
 JMP NOISE

.LASLI
 JSR DORND
 AND #7
 ADC #Y-4
 STA LASY
 JSR DORND
 AND #7
 ADC #X-4
 STA LASX
 LDA GNTMP
 ADC #8
 STA GNTMP
 JSR DENGY

.LASLI2
 LDA QQ11
 BNE PU1-1
 LDA #32
 LDY #224
 JSR las
 LDA #48
 LDY #208

.las
 STA X2
 LDA LASX
 STA X1
 LDA LASY
 STA Y1
 LDA #2*Y-1
 STA Y2
 JSR LOIN
 LDA LASX
 STA X1
 LDA LASY
 STA Y1
 STY X2
 LDA #2*Y-1
 STA Y2
 JMP LOIN

.PLUT
 LDX VIEW
 BNE PU1
 RTS

.PU1
 DEX
 BNE PU2

 LDA INWK+2
 EOR #128
 STA INWK+2
 LDA INWK+8
 EOR #128
 STA INWK+8
 LDA INWK+10
 EOR #128
 STA INWK+10
 LDA INWK+14
 EOR #128
 STA INWK+14
 LDA INWK+16
 EOR #128
 STA INWK+16

 LDA INWK+20
 EOR #128
 STA INWK+20
 LDA INWK+22
 EOR #128
 STA INWK+22
 LDA INWK+26
 EOR #128
 STA INWK+26
 RTS

.PU2
 LDA #0
 CPX #2
 ROR A
 STA RAT2
 EOR #128
 STA RAT

 LDA INWK
 LDX INWK+6
 STA INWK+6
 STX INWK
 LDA INWK+1
 LDX INWK+7
 STA INWK+7
 STX INWK+1
 LDA INWK+2
 EOR RAT
 TAX
 LDA INWK+8
 EOR RAT2
 STA INWK+2
 STX INWK+8

 LDY #9
 JSR PUS1

 LDY #15
 JSR PUS1

 LDY #21

.PUS1
 LDA INWK,Y
 LDX INWK+4,Y
 STA INWK+4,Y
 STX INWK,Y
 LDA INWK+1,Y
 EOR RAT
 TAX
 LDA INWK+5,Y
 EOR RAT2
 STA INWK+1,Y
 STX INWK+5,Y

.LO2
 RTS

.LQ
 STX VIEW
 JSR TT66
 JSR SIGHT
 JMP NWSTARS

.LOOK1
 LDA #0
 LDY QQ11
 BNE LQ
 CPX VIEW
 BEQ LO2
 STX VIEW
 JSR TT66
 JSR FLIP
 JSR WPSHPS

.SIGHT
 LDY VIEW
 LDA LASER,Y
 BEQ LO2
 LDA #128
 STA QQ19
 LDA #Y-24
 STA QQ19+1
 LDA #20
 STA QQ19+2
 JSR TT15
 LDA #10
 STA QQ19+2
 JMP TT15

 LDA #1

.TT66
 STA QQ11

.TTX66
 LDA #128
 STA QQ17
 ASL A
 STA LASCT            ; is LAS2 in ELITEC.TXT
 STA DLY
 STA de
 LDX #&60

.BOL1
 JSR ZES1
 INX
 CPX #&78
 BNE BOL1

 LDX QQ22+1
 BEQ BOX
 JSR ee3

.BOX
 LDY #1
 STY YC
 LDA QQ11
 BNE tt66
 LDY #11
 STY XC
 LDA VIEW
 ORA #&60
 JSR TT27
 JSR TT162
 LDA #175
 JSR TT27

.tt66
 LDX #0
 STX X1
 STX Y1
 STX QQ17
 DEX
 STX X2
 JSR HLOIN

 LDA #2
 STA X1
 STA X2
 JSR BOS2

.BOS2
 JSR BOS1

.BOS1
 LDA #0
 STA Y1
 LDA #2*Y-1
 STA Y2
 DEC X1
 DEC X2
 JMP LOIN

 LDY #2
 EQUB &2C

.DEL8
 LDY #8

.DELAY
 JSR WSCAN
 DEY
 BNE DELAY
 RTS

.hm
 JSR TT103
 JSR TT111
 JSR TT103
 LDA QQ11
 BEQ SC5

.CLYNS
 LDA #20
 STA YC
 LDA #&75
 STA SC+1
 LDA #7
 STA SC
 JSR TT67
 LDA #0
 JSR LYN
 INC SC+1
 JSR LYN
 INC SC+1
 INY
 STY XC

.LYN
 LDY #233

.EE2
 STA (SC),Y
 DEY
 BNE EE2

.SC5
 RTS

.SCAN
 LDA INWK+31
 AND #16
 BEQ SC5
 LDA TYPE
 BMI SC5
 LDX #FF
\CMP#TGL
\BEQSC49
 CMP #MSL
 BNE P%+4
 LDX #&F0
\CMP#AST
\BCCP%+4
\LDX#&F
\SC49
 STX COL
 LDA INWK+1
 ORA INWK+4
 ORA INWK+7
 AND #&C0
 BNE SC5

 LDA INWK+1
 CLC
 LDX INWK+2
 BPL SC2
 EOR #FF
 ADC #1

.SC2
 ADC #123
 STA X1

 LDA INWK+7
 LSR A
 LSR A
 CLC
 LDX INWK+8
 BPL SC3
 EOR #FF
 SEC

.SC3
 ADC #35
 EOR #FF
 STA SC

 LDA INWK+4
 LSR A
 CLC
 LDX INWK+5
 BMI SCD6
 EOR #FF
 SEC

.SCD6
 ADC SC
 BPL ld246
 CMP #194
 BCS P%+4
 LDA #194
 CMP #247
 BCC P%+4

.ld246
 LDA #246
 STA Y1
 SEC
 SBC SC
 PHP
\BCSSC48
\EOR#FF
\ADC#1
.SC48
 PHA
 JSR CPIX4
 LDA CTWOS+1,X
 AND COL
 STA X1
 PLA
 PLP
 TAX
 BEQ RTS
 BCC RTS+1

.VLL1
 DEY
 BPL VL1
 LDY #7
 DEC SC+1
.VL1
 LDA X1
 EOR (SC),Y
 STA (SC),Y
 DEX
 BNE VLL1
.RTS
 RTS

 INY
 CPY #8
 BNE P%+6
 LDY #0
 INC SC+1

.VLL2
 INY
 CPY #8
 BNE VL2
 LDY #0
 INC SC+1

.VL2
 LDA X1
 EOR (SC),Y
 STA (SC),Y
 INX
 BNE VLL2
 RTS

.WSCAN
 LDA #0
 STA DL
 LDA DL
 BEQ P%-2
 RTS

;IFZ>4OSCLI("S.ELTC "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%)

PRINT "ELITE<C>"
PRINT "ASSEMBLE AT W%=", ~C_C%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_C%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_C%

PRINT "S.ELTC ",~C_C%," ",~P%," ",~L%," ",~H_C%
SAVE "output/ELTC.bin", C_C%, P%, L%

PRINT "C d,";

\************************************************
\* ELITE<D>
\************************************************

;H%=L%+P%-C%
;O%=W%
C_D%=P%
H_D%=L%+P%-C_A%

\[OPTZ

.tnpr
pha
 LDX #12
 CPX QQ29
 BCC kg

.Tml
 ADC QQ20,X
 DEX
 BPL Tml
 CMP CRGO
pla
 RTS

.kg
 LDY QQ29
 ADC QQ20,Y
cmp#200
pla
rts

.TT20
 JSR P%+3
 JSR P%+3

.TT54
 LDA QQ15
 CLC
 ADC QQ15+2
 TAX
 LDA QQ15+1
 ADC QQ15+3
 TAY

 LDA QQ15+2
 STA QQ15
 LDA QQ15+3
 STA QQ15+1
 LDA QQ15+5
 STA QQ15+3
 LDA QQ15+4
 STA QQ15+2
 CLC
 TXA
 ADC QQ15+2
 STA QQ15+4
 TYA
 ADC QQ15+3
 STA QQ15+5
 RTS

.TT146
 LDA QQ8
 ORA QQ8+1
 BNE TT63
 INC YC
 RTS

.TT63
 LDA #191
 JSR TT68

 LDX QQ8
 LDY QQ8+1
 SEC
 JSR pr5
 LDA #195

.TT60
 JSR TT27

.TTX69
 INC YC

.TT69
 LDA #128
 STA QQ17

.TT67
 LDA #13
 JMP TT27

.TT70
 LDA #173
 JSR TT27
 JMP TT72

.spc
 JSR TT27
 JMP TT162

.TT25
\ DATA
 JSR TT66-2
 LDA #9
 STA XC
 LDA #163
 JSR TT27
 JSR NLIN
 JSR TTX69
 INC YC
 JSR TT146
 LDA #194

 JSR TT68
 LDA QQ3
 CLC
 ADC #1
 LSR A
 CMP #2
 BEQ TT70
 LDA QQ3
 BCC TT71

 SBC #5
 CLC

.TT71
 ADC #170
 JSR TT27

.TT72
 LDA QQ3
 LSR A
 LSR A
 CLC
 ADC #168
 JSR TT60
 LDA #162
 JSR TT68
 LDA QQ4
 CLC
 ADC #177
 JSR TT60
 LDA #196
 JSR TT68

 LDX QQ5
 INX
 CLC
 JSR pr2
 JSR TTX69
 LDA #192
 JSR TT68
 SEC
 LDX QQ6
 JSR pr2
 LDA #198
 JSR TT60
 LDA #&28
 JSR TT27
 LDA QQ15+4
 BMI TT75
 LDA #188
 JSR TT27
 JMP TT76

.TT75
 LDA QQ15+5
 LSR A
 LSR A
 PHA
 AND #7
 CMP #3
 BCS TT205
 ADC #227
 JSR spc

.TT205
 PLA
 LSR A
 LSR A
 LSR A
 CMP #6
 BCS TT206
 ADC #230
 JSR spc

.TT206
 LDA QQ15+3
 EOR QQ15+1
 AND #7

 STA QQ19
 CMP #6
 BCS TT207
 ADC #236
 JSR spc

.TT207
 LDA QQ15+5
 AND #3
 CLC
 ADC QQ19
 AND #7
 ADC #242
 JSR TT27

.TT76
 LDA #&53
 JSR TT27
 LDA #&29
 JSR TT60

 LDA #193
 JSR TT68
 LDX QQ7
 LDY QQ7+1
 JSR pr6
 JSR TT162
 LDA #0
 STA QQ17
 LDA #&4D
 JSR TT27
 LDA #226
 JSR TT60
 LDA #250
 JSR TT68
 LDA QQ15+5
 LDX QQ15+3
 AND #15
 CLC
 ADC #11
 TAY

 JSR pr5
 JSR TT162
 LDA #&6B
 JSR TT26
 LDA #&6D
 JMP TT26

.TT24
 LDA QQ15+1
 AND #7
 STA QQ3
 LDA QQ15+2
 LSR A
 LSR A
 LSR A
 AND #7
 STA QQ4
 LSR A
 BNE TT77
 LDA QQ3
 ORA #2
 STA QQ3

.TT77
 LDA QQ3
 EOR #7
 CLC
 STA QQ5
 LDA QQ15+3
 AND #3
 ADC QQ5
 STA QQ5

 LDA QQ4
 LSR A
 ADC QQ5
 STA QQ5
 ASL A
 ASL A
 ADC QQ3
 ADC QQ4
 ADC #1
 STA QQ6
 LDA QQ3
 EOR #7
 ADC #3
 STA P
 LDA QQ4
 ADC #4
 STA Q
 JSR MULTU
 LDA QQ6
 STA Q
 JSR MULTU
 ASL P
 ROL A
 ASL P
 ROL A
 ASL P
 ROL A
 STA QQ7+1
 LDA P
 STA QQ7
 RTS

.TT22
\Lng Sc
 LDA #64
 JSR TT66
 LDA #7
 STA XC
 JSR TT81
 LDA #199
 JSR TT27
 JSR NLIN
 LDA #152
 JSR NLIN2
 JSR TT14

 LDX #0
.TT83
 STX XSAV
 LDX QQ15+3
 LDY QQ15+4
 TYA
 ORA #&50
 STA ZZ

 LDA QQ15+1
 LSR A
 CLC
 ADC #24
 STA XX15+1
 JSR PIXEL
 JSR TT20
 LDX XSAV
 INX
 BNE TT83
 LDA QQ9
 STA QQ19
 LDA QQ10
 LSR A
 STA QQ19+1
 LDA #4
 STA QQ19+2

.TT15
 LDA #24
 LDX QQ11
 BPL P%+4
 LDA #0
 STA QQ19+5
 LDA QQ19
 SEC
 SBC QQ19+2
 BCS TT84
 LDA #0

.TT84
 STA XX15
 LDA QQ19
 CLC
 ADC QQ19+2
 BCC P%+4
 LDA #FF
 STA XX15+2

 LDA QQ19+1
 CLC
 ADC QQ19+5
 STA XX15+1
 JSR HLOIN
 LDA QQ19+1
 SEC
 SBC QQ19+2
 BCS TT86
 LDA #0

.TT86
 CLC
 ADC QQ19+5
 STA XX15+1
 LDA QQ19+1
 CLC
 ADC QQ19+2
 ADC QQ19+5
 CMP #152
 BCC TT87

 LDX QQ11
 BMI TT87
 LDA #151

.TT87
 STA XX15+3
 LDA QQ19
 STA XX15
 STA XX15+2
 JMP LL30

.TT126
 LDA #104
 STA QQ19
 LDA #90
 STA QQ19+1
 LDA #16
 STA QQ19+2
 JSR TT15
 LDA QQ14
 STA K
 JMP TT128

.TT14
\Crcl/+
 LDA QQ11
 BMI TT126
 LDA QQ14
 LSR A
 LSR A
 STA K
 LDA QQ0
 STA QQ19
 LDA QQ1
 LSR A
 STA QQ19+1
 LDA #7
 STA QQ19+2
 JSR TT15
 LDA QQ19+1
 CLC
 ADC #24
 STA QQ19+1

.TT128
 LDA QQ19
 STA K3
 LDA QQ19+1
 STA K4
 LDX #0
 STX K4+1
 STX K3+1
\STXLSX
 INX
 STX LSP
 LDX #2
 STX STP

 JSR CIRCLE2
\LDA#FFSTALSX
 RTS

.TT219
\Buy
\LDA#2
 JSR TT66-2
 JSR TT163
 LDA #128
 STA QQ17
\JSRFLKB
 LDA #0
 STA QQ29

.TT220
 JSR TT151
 LDA QQ25
 BNE TT224
 JMP TT222

.TQ4
 LDY #176

.Tc
 JSR TT162
 TYA
 JSR prq

.TTX224
 JSR dn2

.TT224
 JSR CLYNS
 LDA #204
 JSR TT27
 LDA QQ29
 CLC
 ADC #208
 JSR TT27
 LDA #&2F
 JSR TT27
 JSR TT152
 LDA #&3F
 JSR TT27
 JSR TT67
 LDX #0
 STX R
 LDX #12
 STX T1

\.TT223     ; DUPLICATE LABEL?

 JSR gnum
 BCS TQ4
 STA P
 JSR tnpr
 LDY #206
 BCS Tc
 LDA QQ24
 STA Q
 JSR GCASH
 JSR LCASH
 LDY #197
 BCC Tc

 LDY QQ29
 LDA R
 PHA
 CLC
 ADC QQ20,Y
 STA QQ20,Y
 LDA AVL,Y
 SEC
 SBC R
 STA AVL,Y
 PLA
 BEQ TT222
 JSR dn

.TT222
 LDA QQ29
 CLC
 ADC #5
 STA YC
 LDA #0
 STA XC
 INC QQ29
 LDA QQ29
 CMP #17
 BCS BAY2
 JMP TT220

.BAY2
 LDA #f9
 JMP FRCE

.gnum
 LDX #0
 STX R
 LDX #12
 STX T1

.TT223
 JSR TT217
 STA Q
 SEC
 SBC #&30
 BCC OUT
 CMP #10
 BCS BAY2
 STA S
 LDA R
 CMP #26
 BCS OUT
 ASL A
 STA T
 ASL A
 ASL A
 ADC T
 ADC S
 STA R
 CMP QQ25
 BEQ TT226
 BCS OUT

.TT226
 LDA Q
 JSR TT26
 DEC T1
 BNE TT223

.OUT
 LDA R
 RTS

.TT208
\Sel
 LDA #4
 JSR TT66
 LDA #4
 STA YC
 STA XC
\JSRFLKB
 LDA #205
 JSR TT27
 LDA #206
 JSR TT68

.TT210
\Crgo
 LDY #0

.TT211
 STY QQ29
 LDX QQ20,Y
 BEQ TT212

 TYA
 ASL A
 ASL A
 TAY
 LDA QQ23+1,Y
 STA QQ19+1

 TXA
 PHA
 JSR TT69
 CLC
 LDA QQ29
 ADC #208

 JSR TT27
 LDA #14
 STA XC
 PLA
 TAX
 CLC
 JSR pr2
 JSR TT152

 LDA QQ11
 CMP #4
 BNE TT212
 LDA #205
 JSR TT214

 BCC TT212
 LDA QQ29
 LDX #255
 STX QQ17
 JSR TT151

 LDY QQ29
 LDA QQ20,Y
 STA P
 LDA QQ24
 STA Q
 JSR GCASH
 JSR MCASH

 LDA #0
 LDY QQ29
 STA QQ20,Y
 STA QQ17

.TT212
 LDY QQ29
 INY
 CPY #17
 BCS P%+5
 JMP TT211
 LDA QQ11
 CMP #4
 BNE P%+8
 JSR dn2
 JMP BAY2
 RTS

.TT213
\Invntry
 LDA #8
 JSR TT66
 LDA #11
 STA XC
 LDA #164
 JSR TT60
 JSR NLIN4
 JSR fwl

 LDA CRGO
 CMP #26
 BCC P%+7
 LDA #&6B
 JSR TT27
 JMP TT210

.TT214
 PHA
 JSR TT162
 PLA

.TT221
 JSR TT27
 LDA #225
 JSR TT27

 JSR TT217
 ORA #32
 CMP #&79
 BEQ TT218
 LDA #&6E
 JMP TT26

.TT218
 JSR TT26
 SEC
 RTS

.TT16
 TXA
 PHA
 DEY
 TYA
 EOR #255
 PHA
 JSR WSCAN
 JSR TT103
 PLA
 STA QQ19+3

 LDA QQ10
 JSR TT123
 LDA QQ19+4
 STA QQ10
 STA QQ19+1
 PLA

 STA QQ19+3
 LDA QQ9
 JSR TT123
 LDA QQ19+4
 STA QQ9
 STA QQ19

.TT103
 LDA QQ11
 BEQ TT180
 BMI TT105
 LDA QQ9
 STA QQ19
 LDA QQ10
 LSR A
 STA QQ19+1
 LDA #4
 STA QQ19+2
 JMP TT15

.TT123
 STA QQ19+4
 CLC
 ADC QQ19+3
 LDX QQ19+3
 BMI TT124
 BCC TT125
 RTS

.TT124
 BCC TT180

.TT125
 STA QQ19+4

.TT180
 RTS

.TT105
 LDA QQ9
 SEC
 SBC QQ0
 CMP #38
 BCC TT179
 CMP #230
 BCC TT180

.TT179
 ASL A
 ASL A
 CLC
 ADC #104
 STA QQ19

 LDA QQ10
 SEC
 SBC QQ1
 CMP #38
 BCC P%+6
 CMP #220
 BCC TT180

 ASL A
 CLC
 ADC #90
 STA QQ19+1
 LDA #8
 STA QQ19+2
 JMP TT15

.TT23
\ShrtSc
 LDA #128
 JSR TT66
 LDA #7
 STA XC
 LDA #190
 JSR NLIN3
 JSR TT14
 JSR TT103
 JSR TT81

 LDA #0
 STA XX20
 LDX #24

.EE3
 STA INWK,X
 DEX
 BPL EE3

.TT182
 LDA QQ15+3
 SEC
 SBC QQ0
 BCS TT184
 EOR #FF
 ADC #1

.TT184
 CMP #20
 BCS TT187
 LDA QQ15+1
 SEC
 SBC QQ1
 BCS TT186
 EOR #FF
 ADC #1

.TT186
 CMP #38
 BCS TT187

 LDA QQ15+3
 SEC
 SBC QQ0
 ASL A
 ASL A
 ADC #104
 STA XX12
 LSR A
 LSR A
 LSR A
 STA XC
 INC XC
 LDA QQ15+1
 SEC
 SBC QQ1
 ASL A
 ADC #90
 STA K4
 LSR A
 LSR A
 LSR A

 TAY
 LDX INWK,Y
 BEQ EE4
 INY
 LDX INWK,Y
 BEQ EE4
 DEY
 DEY
 LDX INWK,Y
 BNE ee1

.EE4
 STY YC
 CPY #3
 BCC TT187
 DEX
 STX INWK,Y

 LDA #128
 STA QQ17
 JSR cpl

.ee1
\bigstars
 LDA #0
 STA K3+1
 STA K4+1
 STA K+1
 LDA XX12
 STA K3
 LDA QQ15+5
 AND #1
 ADC #2
 STA K
 JSR FLFLLS
 JSR SUN
 JSR FLFLLS

.TT187
 JSR TT20
 INC XX20
 BEQ TT111-1
 JMP TT182

.TT81
 LDX #5
 LDA QQ21,X
 STA QQ15,X
 DEX
 BPL TT81+2
 RTS

.TT111
 JSR TT81
 LDY #127
 STY T
 LDA #0
 STA U

.TT130
 LDA QQ15+3
 SEC
 SBC QQ9
 BCS TT132
 EOR #FF
 ADC #1

.TT132
 LSR A
 STA S
 LDA QQ15+1
 SEC
 SBC QQ10
 BCS TT134
 EOR #FF
 ADC #1

.TT134
 LSR A
 CLC
 ADC S
 CMP T
 BCS TT135

 STA T
 LDX #5

.TT136
 LDA QQ15,X
 STA QQ19,X
 DEX
 BPL TT136

.TT135
 JSR TT20
 INC U
 BNE TT130
 LDX #5

.TT137
 LDA QQ19,X
 STA QQ15,X
 DEX

 BPL TT137
 LDA QQ15+1
 STA QQ10
 LDA QQ15+3
 STA QQ9

 SEC
 SBC QQ0
 BCS TT139
 EOR #FF
 ADC #1

.TT139
 JSR SQUA2
 STA K+1
 LDA P
 STA K
 LDA QQ10

 SEC
 SBC QQ1
 BCS TT141
 EOR #FF
 ADC #1

.TT141
 LSR A
 JSR SQUA2
 PHA
 LDA P
 CLC
 ADC K

 STA Q
 PLA
 ADC K+1
 STA R
 JSR LL5
 LDA Q
 ASL A
 LDX #0
 STX QQ8+1
 ROL QQ8+1
 ASL A
 ROL QQ8+1
 STA QQ8
 JMP TT24

.hy6
 JSR CLYNS
 LDA #15
 STA XC
 JMP TT27

.hyp
 LDA QQ12
 BNE hy6
 LDA QQ22+1
 BNE zZ+1
 JSR CTRL
 BMI Ghy

 JSR hm
 LDA QQ8
 ORA QQ8+1
 BEQ zZ+1
 LDA #7
 STA XC
 LDA #23
 STA YC
 LDA #0
 STA QQ17
 LDA #189
 JSR TT27
 LDA QQ8+1
 BNE TT147
 LDA QQ14
 CMP QQ8
 BCC TT147

 LDA #&2D
 JSR TT27
 JSR cpl

.wW
 LDA #15
 STA QQ22+1
 STA QQ22
 TAX
 JMP ee3\hy5 RTS

.Ghy
;JSRTT111       ; is in ELITED.TXT but not in ELITE SOURCE IMAGE
 LDX GHYP
 BEQ hy5
 INX
 STX QQ8
 STX QQ8+1
 STX GHYP
 STX FIST
 JSR wW
 LDX #5
 INC GCNT
 LDA GCNT
 AND #7
 STA GCNT

.G1
 LDA QQ21,X
 ASL A
 ROL QQ21,X
 DEX
 BPL G1
\JSRDORND

.zZ
 LDA #&60
 STA QQ9
 STA QQ10
 JSR TT110
 LDA #116
 JSR MESS

.jmp
 LDA QQ9
 STA QQ0
 LDA QQ10
 STA QQ1

.hy5
 RTS

.ee3
 LDY #1
 STY YC
 DEY
 STY XC

.pr6
 CLC

.pr5
 LDA #5
 JMP TT11

.TT147
 LDA #202

.prq
 JSR TT27
 LDA #&3F
 JMP TT27

.TT151
\Pmk-A
 PHA
 STA QQ19+4
 ASL A
 ASL A
 STA QQ19
 LDA #1
 STA XC
 PLA
 ADC #208

 JSR TT27
 LDA #14
 STA XC
 LDX QQ19
 LDA QQ23+1,X
 STA QQ19+1
 LDA QQ26
 AND QQ23+3,X
 CLC
 ADC QQ23,X
 STA QQ24
 JSR TT152

 JSR var
 LDA QQ19+1
 BMI TT155
 LDA QQ24
 ADC QQ19+3
 JMP TT156

.TT155
 LDA QQ24
 SEC
 SBC QQ19+3

.TT156
 STA QQ24
 STA P
 LDA #0
 JSR GC2

 SEC
 JSR pr5
 LDY QQ19+4
 LDA #5
 LDX AVL,Y
 STX QQ25

 CLC
 BEQ TT172
 JSR pr2+2
 JMP TT152

.TT172
 LDA XC
 ADC #4
 STA XC
 LDA #&2D
 BNE TT162+2

.TT152
 LDA QQ19+1
 AND #96
 BEQ TT160
 CMP #32
 BEQ TT161

 JSR TT16a

.TT162
 LDA #32
 JMP TT27

.TT160
 LDA #&74
 JSR TT26
 BCC TT162

.TT161
 LDA #&6B
 JSR TT26

.TT16a
 LDA #&67
 JMP TT26

.TT163
 LDA #17
 STA XC
 LDA #FF
 BNE TT162+2

.TT167
\MktP
 LDA #16
 JSR TT66
 LDA #5
 STA XC
 LDA #167
 JSR NLIN3
 LDA #3
 STA YC
 JSR TT163
 LDA #0
 STA QQ29

.TT168
 LDX #128
 STX QQ17
 JSR TT151
 INC YC

 INC QQ29
 LDA QQ29
 CMP #17
 BCC TT168
 RTS

.var
 LDA QQ19+1
 AND #31
 LDY QQ28
 STA QQ19+2
 CLC
 LDA #0
 STA AVL+16

.TT153
 DEY
 BMI TT154
 ADC QQ19+2
 JMP TT153

.TT154
 STA QQ19+3
 RTS

.hyp1
 JSR TT111
 JSR jmp
 LDX #5

.TT112
 LDA QQ15,X
 STA QQ2,X
 DEX
 BPL TT112
 INX
 STX EV
 LDA QQ3
 STA QQ28
 LDA QQ5
 STA tek
 LDA QQ4
 STA gov
 RTS

.GVL
 JSR DORND
 STA QQ26
 LDX #0
 STX XX4

.hy9
 LDA QQ23+1,X
 STA QQ19+1
 JSR var
 LDA QQ23+3,X
 AND QQ26
 CLC
 ADC QQ23+2,X
 LDY QQ19+1
 BMI TT157
 SEC
 SBC QQ19+3
 JMP TT158

.TT157
 CLC
 ADC QQ19+3

.TT158
 BPL TT159
 LDA #0

.TT159
 LDY XX4
 AND #63
 STA AVL,Y
 INY
 TYA
 STA XX4
 ASL A
 ASL A
 TAX
 CMP #63
 BCC hy9

.hyR
 RTS

.GTHG
 JSR Ze
 LDA #FF
 STA INWK+32
 LDA #THG
 JSR NWSHP
 LDA #TGL
 JMP NWSHP

.ptg
 LSR COK
 SEC
 ROL COK

.MJP
\LDA#1
 JSR TT66-2
 JSR LL164
 JSR RES2
 STY MJ

.MJP1
 JSR GTHG
 LDA #3
 CMP MANY+THG
 BCS MJP1
 STA NOSTM
 LDX #0
 JSR LOOK1
 LDA QQ1
 EOR #31
 STA QQ1
 RTS

.TT18
\HSPC
 LDA QQ14
 SEC
 SBC QQ8
 STA QQ14
 LDA QQ11
 BNE ee5
 JSR TT66
 JSR LL164

.ee5
 JSR CTRL
 AND PATG
 BMI ptg
 JSR DORND
 CMP #253
 BCS MJP\JSRTT111
 JSR hyp1+3
 JSR GVL
 JSR RES2
 JSR SOLAR

 LDA QQ11
 AND #63
 BNE hyR
 JSR TTX66
 LDA QQ11
 BNE TT114
 INC QQ11

.TT110
 LDX QQ12
 BEQ NLUNCH
 JSR LAUN
 JSR RES2
 JSR TT111
 INC INWK+8
 JSR SOS1
 LDA #128
 STA INWK+8
 INC INWK+7
 JSR NWSPS
 LDA #12
 STA DELTA
 JSR BAD
 ORA FIST
 STA FIST

.NLUNCH
 LDX #0
 STX QQ12
 JMP LOOK1

.TT114
 BMI TT115
 JMP TT22

.TT115
 JMP TT23

.LCASH
 STX T1
 LDA CASH+3
 SEC
 SBC T1
 STA CASH+3
 STY T1
 LDA CASH+2
 SBC T1
 STA CASH+2
 LDA CASH+1
 SBC #0
 STA CASH+1
 LDA CASH
 SBC #0
 STA CASH
 BCS TT113

.MCASH
 TXA
 CLC
 ADC CASH+3
 STA CASH+3
 TYA
 ADC CASH+2
 STA CASH+2
 LDA CASH+1
 ADC #0
 STA CASH+1
 LDA CASH
 ADC #0
 STA CASH
 CLC

.TT113
 RTS

.GCASH
 JSR MULTU

.GC2
 ASL P
 ROL A
 ASL P
 ROL A
 TAY
 LDX P
 RTS

.bay
 JMP BAY

.EQSHP
 JSR DIALS
 LDA #32
 JSR TT66
 LDA #12
 STA XC
 LDA #207
 JSR spc
 LDA #185
 JSR NLIN3
 LDA #128
 STA QQ17
 INC YC
 LDA tek
 CLC
 ADC #3
 CMP #12
 BCC P%+4
 LDA #12
 STA Q
 STA QQ25
 INC Q
 LDA #70
 SEC
 SBC QQ14
 ASL A
 STA PRXS

 LDX #1

.EQL1
 STX XX13
 JSR TT67
 LDX XX13
 CLC
 JSR pr2
 JSR TT162
 LDA XX13
 CLC
 ADC #&68
 JSR TT27
 LDA XX13
 JSR prx-3
 SEC
 LDA #25
 STA XC
 LDA #6
 JSR TT11
 LDX XX13
 INX
 CPX Q
 BCC EQL1

 JSR CLYNS
 LDA #127
 JSR prq
 JSR gnum
beqbay
bcsbay
 SBC #0
 LDX #2
 STX XC
 INC YC
 PHA
 JSR eq
 PLA
 BNE et0
 STA MCNT
 LDX #70
 STX QQ14

.et0
 CMP #1
 BNE et1
 LDX NOMSL
 INX
 LDY #&75
 CPX #5
 BCS pres

 STX NOMSL
 JSR msblob

.et1
 LDY #&6B
 CMP #2
 BNE et2
 LDX #37
 CPX CRGO
 BEQ pres
 STX CRGO

.et2
 CMP #3
 BNE et3
 INY
 LDX ECM
 BNE pres
 DEC ECM

.et3
 CMP #4
 BNE et4
 JSR qv
 LDA #4
 LDY LASER,X
 BEQ ed4

.ed7
 LDY #187
 BNE pres

.ed4
 LDA #POW
 STA LASER,X
 LDA #4

.et4
 CMP #5
 BNE et5
 JSR qv
 STX T1
 LDA #5
 LDY LASER,X
 BEQ ed5
\BPLP%+4
 BMI ed7
 LDA #4
 JSR prx
 JSR MCASH

.ed5
 LDA #POW+128
 LDX T1
 STA LASER,X

.et5
 LDY #&6F
 CMP #6
 BNE et6
 LDX BST
 BEQ ed9

.pres
 STY K
 JSR prx
 JSR MCASH
 LDA K
 JSR spc
 LDA #31
 JSR TT27

.err
 JSR dn2
 JMP BAY

.ed9
 DEC BST

.et6
 INY
 CMP #7
 BNE et7
 LDX ESCP
 BNE pres
 DEC ESCP

.et7
 INY
 CMP #8
 BNE et8
 LDX BOMB
 BNE pres
 LDX #&7F
 STX BOMB

.et8
 INY
 CMP #9
 BNE etA
 LDX ENGY
 BNE pres
 INC ENGY

.etA
 INY
 CMP #10
 BNE etB
 LDX DKCMP
 BNE pres
 DEC DKCMP

.etB
 INY
 CMP #11
 BNE et9
 LDX GHYP
 BNE pres
 DEC GHYP

.et9
 JSR dn
 JMP EQSHP

.dn
 JSR TT162
 LDA #119
 JSR spc

.dn2
 JSR BEEP
 LDY #50
 JMP DELAY

.eq
 JSR prx
 JSR LCASH
 BCS c
 LDA #197
 JSR prq
 JMP err
 SEC
 SBC #1

.prx
 ASL A
 TAY
 LDX PRXS,Y
 LDA PRXS+1,Y
 TAY

.c
 RTS

.qv
 LDY #16
 STY YC

.qv1
 LDX #12
 STX XC
 TYA
 CLC
 ADC #B-16
 JSR spc
 LDA YC
 CLC
 ADC #&50
 JSR TT27
 INC YC
 LDY YC
 CPY #20
 BCC qv1

.qv3
 JSR CLYNS

.qv2
 LDA #175
 JSR prq
 JSR TT217
 SEC
 SBC #&30
 CMP #4
 BCS qv3
 TAX
 RTS

;IFZ>4OSCLI("S.ELTD "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%)

PRINT "ELITE<D>"
PRINT "ASSEMBLE AT W%=", ~C_D%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_D%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_D%

PRINT "S.ELTD ",~C_D%," ",~P%," ",~L%," ",~H_D%
SAVE "output/ELTD.bin", C_D%, P%, L%

PRINT "D d,";

\************************************************
\* ELITE<E>
\************************************************

;H%=L%+P%-C%
;O%=W%
C_E%=P%
H_E%=L%+P%-C_A%

\[OPTZ

MAPCHAR '(', '('EOR&A4
MAPCHAR 'C', 'C'EOR&A4
MAPCHAR ')', ')'EOR&A4
MAPCHAR 'B', 'B'EOR&A4
MAPCHAR 'e', 'e'EOR&A4
MAPCHAR 'l', 'l'EOR&A4
MAPCHAR '/', '/'EOR&A4
MAPCHAR 'r', 'r'EOR&A4
MAPCHAR 'a', 'a'EOR&A4
MAPCHAR 'b', 'b'EOR&A4
MAPCHAR 'n', 'n'EOR&A4
MAPCHAR '1', '1'EOR&A4
MAPCHAR '9', '9'EOR&A4
MAPCHAR '8', '8'EOR&A4
MAPCHAR '4', '4'EOR&A4

.BDOLLAR
 EQUS  "(C)Bell/Braben1984"

MAPCHAR '(', '('
MAPCHAR 'C', 'C'
MAPCHAR ')', ')'
MAPCHAR 'B', 'B'
MAPCHAR 'e', 'e'
MAPCHAR 'l', 'l'
MAPCHAR '/', '/'
MAPCHAR 'r', 'r'
MAPCHAR 'a', 'a'
MAPCHAR 'b', 'b'
MAPCHAR 'n', 'n'
MAPCHAR '1', '1'
MAPCHAR '9', '9'
MAPCHAR '8', '8'
MAPCHAR '4', '4'

.cpl
 LDX #5

.TT53
 LDA QQ15,X
 STA QQ19,X
 DEX
 BPL TT53
 LDY #3
 BIT QQ15
BVSP%+3
 DEY
 STY T

.TT55
 LDA QQ15+5
 AND #31
 BEQ P%+7
 ORA #128
 JSR TT27
 JSR TT54
 DEC T
 BPL TT55
 LDX #5

.TT56
 LDA QQ19,X
 STA QQ15,X
 DEX
 BPL TT56
 RTS

.cmn
 LDY #0

.QUL4
 LDA NA%,Y
 CMP #13
 BEQ ypl-1
 JSR TT26
 INY
 BNE QUL4
 RTS

.ypl
 LDA MJ
 BNE cmn-1
 JSR TT62
 JSR cpl

.TT62
 LDX #5

.TT78
 LDA QQ15,X
 LDY QQ2,X
 STA QQ2,X
 STY QQ15,X
 DEX
 BPL TT78
 RTS

.tal
 CLC
 LDX GCNT
 INX
 JMP pr2

.fwl
 LDA #105
 JSR TT68
 LDX QQ14
 SEC
 JSR pr2
 LDA #195
 JSR plf

.PCASH
 LDA #119
 BNE TT27

.csh
 LDX #3

.pc1
 LDA CASH,X
 STA K,X
 DEX
 BPL pc1
 LDA #9
 STA U
 SEC
 JSR BPRNT
 LDA #226

.plf
 JSR TT27
 JMP TT67

.TT68
 JSR TT27

.TT73
 LDA #&3A

.TT27
 TAX
 BEQ csh
 BMI TT43
 DEX
 BEQ tal
 DEX
 BEQ ypl
dex
bneP%+5
 JMP cpl
dex
beqcmn
dex
beqfwl
dex
bneP%+7
 LDA #128
 STA QQ17
 RTS
 DEX
 DEX
 BNE P%+5
 STX QQ17
 RTS
dex
beqcrlf
 CMP #&60
 BCS ex
 CMP #14
 BCC P%+6
 CMP #32
 BCC qw
 LDX QQ17

 BEQ TT74
 BMI TT41
 BIT QQ17
BVSTT46

.TT42
 CMP #65
 BCC TT44
 CMP #&5B
 BCS TT44
 ADC #32

.TT44
 JMP TT26

.TT41
 BIT QQ17
BVSTT45
 CMP #65
 BCC TT74
 PHA
 TXA
 ORA #64
 STA QQ17
 PLA
 BNE TT44

.qw
 ADC #114
 BNE ex

.crlf
 LDA #21
 STA XC
 BNE TT73

.TT45
 CPX #FF
 BEQ TT48
 CMP #65
 BCS TT42

.TT46
 PHA
 TXA
 AND #191
 STA QQ17
 PLA

.TT74
 JMP TT26

.TT43
 CMP #160
 BCS TT47
 AND #127
 ASL A
 TAY
 LDA QQ16,Y

 JSR TT27
 LDA QQ16+1,Y
 CMP #63
 BEQ TT48
 JMP TT27

.TT47
 SBC #160

.ex
 TAX
 LDA #(QQ18 MOD256)
 STA V
 LDA #(QQ18 DIV256)
 STA V+1
 LDY #0
 TXA
 BEQ TT50

.TT51
 LDA (V),Y
 BEQ TT49
 INY
 BNE TT51
 INC V+1
 BNE TT51

.TT49
 INY
 BNE TT59
 INC V+1

.TT59
 DEX
 BNE TT51

.TT50
 TYA
 PHA
 LDA V+1
 PHA
 LDA (V),Y
 EOR #35

 JSR TT27
 PLA
 STA V+1
 PLA
 TAY
 INY
 BNE P%+4
 INC V+1
 LDA (V),Y
 BNE TT50

.TT48
 RTS

.EX2
 LDA INWK+31
 ORA #&A0
 STA INWK+31
 RTS

.DOEXP
 LDA INWK+31
 AND #64
 BEQ P%+5
 JSR PTCLS
 LDA INWK+6
 STA T
 LDA INWK+7
 CMP #&20
 BCC P%+6
 LDA #&FE
 BNE yy
 ASL T
 ROL A
 ASL T
 ROL A
 SEC
 ROL A
.yy STAQ
 LDY #1
 LDA (XX19),Y
 ADC #4
 BCS EX2

 STA (XX19),Y
 JSR DVID4
 LDA P
 CMP #&1C
 BCC P%+6
 LDA #&FE
 BNE  LABEL_1
 ASL R
 ROL A
 ASL R
 ROL A
 ASL R
 ROL A

.LABEL_1
 DEY
 STA (XX19),Y
 LDA INWK+31
 AND #&BF
 STA INWK+31
 AND #8
 BEQ TT48

 LDY #2
 LDA (XX19),Y
 TAY
.EXL1
 LDA XX3-7,Y
 STA (XX19),Y
 DEY
 CPY #6
 BNE EXL1
 LDA INWK+31
 ORA #64
 STA INWK+31

.PTCLS
 LDY #0
 LDA (XX19),Y
 STA Q
 INY
 LDA (XX19),Y
 BPL P%+4
 EOR #FF
 LSR A
 LSR A
 LSR A
 ORA #1
 STA U
 INY
 LDA (XX19),Y
 STA TGT
 LDA RAND+1
 PHA

 LDY #6
.EXL5
 LDX #3

.EXL3
 INY
 LDA (XX19),Y
 STA K3,X
 DEX
 BPL EXL3
 STY CNT
 LDY #2

.EXL2
 INY
 LDA (XX19),Y
 EOR CNT
;STARAND-3,Y
 STA &FFFD,Y
 CPY #6
 BNE EXL2
 LDY U

.EXL4
 JSR DORND2
 STA ZZ
 LDA K3+1
 STA R
 LDA K3
 JSR EXS1
 BNE EX11
 CPX #2*Y-1
 BCS EX11
 STX Y1
 LDA K3+3
 STA R
 LDA K3+2
 JSR EXS1
 BNE EX4
 LDA Y1
 JSR PIXEL

.EX4
 DEY
 BPL EXL4
 LDY CNT
 CPY TGT
 BCC EXL5

 PLA
 STA RAND+1
 LDA K%+6
 STA RAND+3
 RTS

.EX11
 JSR DORND2
 JMP EX4

.EXS1
 STA S
 JSR DORND2
 ROL A
 BCS EX5
 JSR FMLTU
 ADC R
 TAX
 LDA S
 ADC #0
 RTS

.EX5
 JSR FMLTU
 STA T
 LDA R
 SBC T
 TAX
 LDA S
 SBC #0
 RTS

.SOS1
 JSR msblob
 LDA #127
 STA INWK+29
 STA INWK+30
 LDA tek
 AND #2
 ORA #128
 JMP NWSHP

.SOLAR
 LSR FIST
 JSR ZINF
 LDA QQ15+1
 AND #7
 ADC #6
 LSR A
 STA INWK+8
 ROR A
 STA INWK+2
 STA INWK+5

 JSR SOS1
 LDA QQ15+3
 AND #7
 ORA #129
 STA INWK+8
 LDA QQ15+5
 AND #3
 STA INWK+2
 STA INWK+1
 LDA #0
 STA INWK+29
 STA INWK+30
 LDA #&81
 JSR NWSHP

.NWSTARS
 LDA QQ11
\ORAMJ
 BNE WPSHPS

.nWq
 LDY NOSTM

.SAL4
 JSR DORND
 ORA #8
 STA SZ,Y
 STA ZZ
 JSR DORND
 STA SX,Y
 STA X1
 JSR DORND
 STA SY,Y
 STA Y1
 JSR PIXEL2
 DEY
 BNE SAL4

.WPSHPS
 LDX #0

.WSL1
 LDA FRIN,X
 BEQ WS2
 BMI WS1
 STA TYPE
 JSR GINF
 LDY #31

.WSL2
 LDA (INF),Y
 STA INWK,Y
 DEY
 BPL WSL2
 STX XSAV
 JSR SCAN
 LDX XSAV
 LDY #31
 LDA (INF),Y
 AND #&A7
 STA (INF),Y

.WS1
 INX
 BNE WSL1

.WS2
 LDX #FF
 STX LSX2
 STX LSY2

.FLFLLS
 LDY #2*Y-1
 LDA #0

.SAL6
 STA LSO,Y
 DEY
 BNE SAL6
 DEY
 STY LSX
 RTS

.DET1
 LDA #6
 SEI
 STA &FE00
 STX &FE01
 CLI
 RTS

 DEX
 RTS

.SHD
 INX
 BEQ SHD-2

.DENGY
 DEC ENERGY
 PHP
 BNE P%+5
 INC ENERGY
 PLP
 RTS

.COMPAS
 JSR DOT
 LDA SSPR
 BNE SP1
 JSR SPS1
 JMP SP2

.SPS2
 ASL A
 TAX
 LDA #0
 ROR A
 TAY
 LDA #20 \14
 STA Q
 TXA
 JSR DVID4
 LDX P

 TYA
 BMI LL163
 LDY #0
 RTS

.LL163
 LDY #FF
 TXA
 EOR #FF
 TAX
 INX
 RTS

.SPS4
 LDX #8

.SPL1
 LDA K%+NI%,X
 STA K3,X
 DEX
 BPL SPL1
 JMP TAS2

.SP1
 JSR SPS4

.SP2
 LDA XX15
 JSR SPS2
 TXA
 ADC #195\X-1
 STA COMX
 LDA XX15+1
 JSR SPS2
 STX T
 LDA #204
 SBC T
 STA COMY

 LDA #&F0
 LDX XX15+2
 BPL P%+4
 LDA #FF
 STA COMC

.DOT
 LDA COMY
 STA Y1
 LDA COMX
 STA X1
 LDA COMC
 STA COL
 CMP #&F0
 BNE CPIX2

.CPIX4
 JSR CPIX2
 DEC Y1

.CPIX2
 LDA Y1

\.CPIX
 TAY
 LSR A
 LSR A
 LSR A
 ORA #&60
 STA SCH
 LDA X1
 AND #&F8
 STA SC
 TYA
 AND #7
 TAY
 LDA X1
 AND #6
 LSR A
 TAX
 LDA CTWOS,X
 AND COL
 EOR (SC),Y
 STA (SC),Y

 LDA CTWOS+1,X
 BPL CP1
 LDA SC
 ADC #8
 STA SC
 LDA CTWOS+1,X

.CP1
 AND COL
 EOR (SC),Y
 STA (SC),Y
 RTS

.OOPS
 STA T
 LDY #8
 LDX #0
 LDA (INF),Y
 BMI OO1
 LDA FSH
 SBC T
 BCC OO2
 STA FSH
 RTS

.OO2
\LDX#0
 STX FSH
 BCC OO3

.OO1
 LDA ASH
 SBC T
 BCC OO5
 STA ASH
 RTS

.OO5
\LDX#0
 STX ASH

.OO3
 ADC ENERGY
 STA ENERGY
 BEQ P%+4
 BCS P%+5
 JMP DEATH
 JSR EXNO3
 JMP OUCH

.SPS3
 LDA K%+1,X
 STA K3,X
 LDA K%+2,X
 TAY
 AND #127
 STA K3+1,X
 TYA
 AND #128
 STA K3+2,X
 RTS

.GINF
 TXA
 ASL A
 TAY
 LDA UNIV,Y
 STA INF
 LDA UNIV+1,Y
 STA INF+1
 RTS

.NWSPS
 JSR SPBLB
 LDX #1
 STX INWK+32
 DEX
 STX INWK+30
\STXINWK+31
 STX FRIN+1
 DEX
 STX INWK+29
 LDX #10
 JSR NwS1
 JSR NwS1
 JSR NwS1

 LDA #(LSO MOD256)
 STA INWK+33
 LDA #(LSO DIV256)
 STA INWK+34
 LDA #SST

.NWSHP
 STA T
 LDX #0

.NWL1
 LDA FRIN,X
 BEQ NW1
 INX
 CPX #NOSH
 BCC NWL1

.NW3
 CLC
 RTS

.NW1
 JSR GINF
 LDA T
 BMI NW2
 ASL A
 TAY
 LDA XX21-2,Y
 STA XX0
 LDA XX21-1,Y
 STA XX0+1
 CPY #2*SST
 BEQ NW6
 LDY #5
 LDA (XX0),Y
 STA T1
 LDA SLSP
 SEC
 SBC T1
 STA INWK+33
 LDA SLSP+1
 SBC #0
 STA INWK+34

 LDA INWK+33
\SEC
 SBC INF
 TAY
 LDA INWK+34
 SBC INF+1
 BCC NW3+1
 BNE NW4
 CPY #NI%
 BCC NW3+1

.NW4
 LDA INWK+33
 STA SLSP
 LDA INWK+34
 STA SLSP+1

.NW6
 LDY #14
 LDA (XX0),Y
 STA INWK+35
 LDY #19
 LDA (XX0),Y
 AND #7
 STA INWK+31

 LDA T

.NW2
 STA FRIN,X
 TAX
 BMI P%+5
 INC MANY,X
 LDY #(NI%-1)

.NWL3
 LDA INWK,Y
 STA (INF),Y
 DEY
 BPL NWL3
 SEC
 RTS

.NwS1
 LDA INWK,X
 EOR #128
 STA INWK,X
 INX
 INX
 RTS

.ABORT
 LDX #FF

.ABORT2
 STX MSTG
 LDX NOMSL
 JSR MSBAR
 STY MSAR
 RTS

.ECBLB2
 LDA #32
 STA ECMA
 ASL A
 JSR NOISE

.ECBLB
 LDA #7*8
\" <<120<"
 LDX #(ECBT MOD256)
 LDY #(ECBT DIV256)
 BNE BULB-2

.SPBLB
 LDA #24*8
\"�<<128<"
 LDX #(SPBT MOD256)
 LDY #(SPBT DIV256)

.BULB
 STA SC
 STX P+1
 STY P+2
 LDA #&7D
 JMP RREN

.ECBT
 EQUW &E0E0
 EQUB &80

.SPBT
 EQUD &E080E0E0
 EQUD &E0E020E0

.MSBAR
 TXA
 ASL A
 ASL A
 ASL A
 STA T
 LDA #49\113
 SBC T
 STA SC
 LDA #&7E
 STA SCH
 TYA
 LDY #5

.MBL1
 STA (SC),Y
 DEY
 BNE MBL1
 RTS

.PROJ
 LDA INWK
 STA P
 LDA INWK+1
 STA P+1
 LDA INWK+2
 JSR PLS6
 BCS PL2-1
 LDA K
 ADC #X
 STA K3
 TXA
 ADC #0
 STA K3+1

 LDA INWK+3
 STA P
 LDA INWK+4
 STA P+1
 LDA INWK+5
 EOR #128
 JSR PLS6
 BCS PL2-1
 LDA K
 ADC #Y
 STA K4
 TXA
 ADC #0
 STA K4+1
 CLC
 RTS

.PL2
 LDA TYPE
 LSR A
 BCS P%+5
 JMP WPLS2
 JMP WPLS

.PLANET
 LDA INWK+8
 BMI PL2
 CMP #48
 BCS PL2
 ORA INWK+7
 BEQ PL2
 JSR PROJ
 BCS PL2

 LDA #96
 STA P+1
 LDA #0
 STA P
 JSR DVID3B2
 LDA K+1
 BEQ PL82
 LDA #&F8
 STA K

.PL82
 LDA TYPE
 LSR A
 BCC PL9
 JMP SUN

.PL9
 JSR WPLS2
 JSR CIRCLE
 BCS PL20
 LDA K+1
 BEQ PL25

.PL20
 RTS

.PL25
 LDA TYPE
 CMP #&80
 BNE PL26
 LDA K
 CMP #6
 BCC PL20
 LDA INWK+14
 EOR #128
 STA P
 LDA INWK+20
 JSR PLS4
 LDX #9
 JSR PLS1
 STA K2
 STY XX16
 JSR PLS1
 STA K2+1
 STY XX16+1
 LDX #15
 JSR PLS5

 JSR PLS2
 LDA INWK+14
 EOR #128
 STA P
 LDA INWK+26
 JSR PLS4

 LDX #21
 JSR PLS5
 JMP PLS2

.PL26
\crtr
 LDA INWK+20
 BMI PL20

 LDX #15
 JSR PLS3
 CLC
 ADC K3
 STA K3
 TYA
 ADC K3+1
 STA K3+1
 JSR PLS3
 STA P
 LDA K4
 SEC
 SBC P
 STA K4
 STY P
 LDA K4+1
 SBC P
 STA K4+1

 LDX #9
 JSR PLS1
 LSR A
 STA K2
 STY XX16
 JSR PLS1
 LSR A
 STA K2+1
 STY XX16+1

 LDX #21
 JSR PLS1
 LSR A
 STA K2+2
 STY XX16+2
 JSR PLS1
 LSR A
 STA K2+3
 STY XX16+3

 LDA #64
 STA TGT
 LDA #0
 STA CNT2
 JMP PLS22

.PLS1
 LDA INWK,X
 STA P
 LDA INWK+1,X
 AND #127
 STA P+1
 LDA INWK+1,X
 AND #128

 JSR DVID3B2
 LDA K
 LDY K+1
 BEQ P%+4
 LDA #&FE
 LDY K+3
 INX
 INX
 RTS

.PLS2
 LDA #31
 STA TGT

.PLS22
 LDX #0
 STX CNT
 DEX
 STX FLAG

.PLL4
 LDA CNT2
 AND #31
 TAX
 LDA SNE,X
 STA Q
 LDA K2+2
 JSR FMLTU
 STA R
 LDA K2+3
 JSR FMLTU
 STA K
 LDX CNT2
 CPX #33
 LDA #0
 ROR A
 STA XX16+5

 LDA CNT2
 CLC
 ADC #16
 AND #31
 TAX
 LDA SNE,X
 STA Q
 LDA K2+1
 JSR FMLTU
 STA K+2
 LDA K2
 JSR FMLTU
 STA P
 LDA CNT2
 ADC #15
 AND #63
 CMP #33
 LDA #0
 ROR A
 STA XX16+4

 LDA XX16+5
 EOR XX16+2
 STA S
 LDA XX16+4
 EOR XX16
 JSR ADD
 STA T
 BPL PL42
 TXA
 EOR #FF
 CLC
 ADC #1
 TAX
 LDA T
 EOR #&7F
 ADC #0
 STA T

.PL42
 TXA
 ADC K3
 STA K6
 LDA T
 ADC K3+1
 STA K6+1

 LDA K
 STA R
 LDA XX16+5
 EOR XX16+3
 STA S
 LDA K+2
 STA P
 LDA XX16+4
 EOR XX16+1
 JSR ADD
 EOR #128
 STA T
 BPL PL43
 TXA
 EOR #FF
 CLC
 ADC #1
 TAX
 LDA T
 EOR #&7F
 ADC #0
 STA T

.PL43
 JSR BLINE
 CMP TGT
 BEQ P%+4
 BCS PL40
 LDA CNT2
 CLC
 ADC STP
 AND #63
 STA CNT2
 JMP PLL4

.PL40
 RTS

 JMP WPLS

.PLF3
 TXA
 EOR #FF
 CLC
 ADC #1
 TAX

.PLF17
 LDA #FF
 JMP PLF5

.SUN
 LDA #1
 STA LSX
 JSR CHKON
 BCS PLF3-3
 LDA #0
 LDX K
 CPX #&60
 ROL A
 CPX #&28
 ROL A
 CPX #&10
 ROL A

.PLF18
 STA CNT
 LDA #2*Y-1
 LDX P+2
 BNE PLF2
 CMP P+1
 BCC PLF2
 LDA P+1
 BNE PLF2
 LDA #1

.PLF2
 STA TGT

 LDA #2*Y-1
 SEC
 SBC K4
 TAX
 LDA #0
 SBC K4+1
 BMI PLF3
 BNE PLF4
 INX
 DEX
 BEQ PLF17
 CPX K
 BCC PLF5

.PLF4
 LDX K
 LDA #0

.PLF5
 STX V
 STA V+1

 LDA K
 JSR SQUA2
 STA K2+1
 LDA P
 STA K2
 LDY #2*Y-1
 LDA SUNX
 STA YY
 LDA SUNX+1
 STA YY+1

.PLFL2
 CPY TGT
 BEQ PLFL
 LDA LSO,Y
 BEQ PLF13
 JSR HLOIN2

.PLF13
 DEY
 BNE PLFL2

.PLFL
 LDA V
 JSR SQUA2
 STA T
 LDA K2
 SEC
 SBC P
 STA Q
 LDA K2+1
 SBC T
 STA R
 STY Y1
 JSR LL5
 LDY Y1
 JSR DORND
 AND CNT
 CLC
 ADC Q
 BCC PLF44
 LDA #FF

.PLF44
 LDX LSO,Y
 STA LSO,Y
 BEQ PLF11
 LDA SUNX
 STA YY
 LDA SUNX+1
 STA YY+1
 TXA
 JSR EDGES
 LDA X1
 STA XX
 LDA X2
 STA XX+1

 LDA K3
 STA YY
 LDA K3+1
 STA YY+1
 LDA LSO,Y
 JSR EDGES
 BCS PLF23
 LDA X2
 LDX XX
 STX X2
 STA XX
 JSR HLOIN

.PLF23
 LDA XX
 STA X1
 LDA XX+1
 STA X2

.PLF16
 JSR HLOIN

.PLF6
 DEY
 BEQ PLF8
 LDA V+1
 BNE PLF10
 DEC V
 BNE PLFL
 DEC V+1

.PLFLS
 JMP PLFL

.PLF11
 LDX K3
 STX YY
 LDX K3+1
 STX YY+1
 JSR EDGES
 BCC PLF16
 LDA #0
 STA LSO,Y
 BEQ PLF6

.PLF10
 LDX V
 INX
 STX V
 CPX K
 BCC PLFLS
 BEQ PLFLS
 LDA SUNX
 STA YY
 LDA SUNX+1
 STA YY+1

.PLFL3
 LDA LSO,Y
 BEQ PLF9
 JSR HLOIN2

.PLF9
 DEY
 BNE PLFL3

.PLF8
 CLC
 LDA K3
 STA SUNX
 LDA K3+1
 STA SUNX+1

.RTS2
 RTS

.CIRCLE
 JSR CHKON
 BCS RTS2

 LDA #0
 STA LSX2

 LDX K
 LDA #8
 CPX #8
 BCC PL89
 LSR A
 CPX #60
 BCC PL89
 LSR A

.PL89
 STA STP

.CIRCLE2
 LDX #FF
 STX FLAG
 INX
 STX CNT

.PLL3
 LDA CNT
 JSR FMLTU2
 LDX #0
 STX T
 LDX CNT
 CPX #33
 BCC PL37
 EOR #FF
 ADC #0
 TAX
 LDA #FF
 ADC #0
 STA T
 TXA
 CLC

.PL37
 ADC K3
 STA K6
 LDA K3+1
 ADC T
 STA K6+1

 LDA CNT
 CLC
 ADC #16
 JSR FMLTU2
 TAX
 LDA #0
 STA T
 LDA CNT
 ADC #15
 AND #63
 CMP #33
 BCC PL38
 TXA
 EOR #FF
 ADC #0
 TAX
 LDA #FF
 ADC #0
 STA T
 CLC

.PL38
 JSR BLINE
 CMP #65
 BCS P%+5
 JMP PLL3
 CLC
 RTS

.WPLS2
 LDY LSX2
 BNE WP1

.WPL1
 CPY LSP
 BCS WP1
 LDA LSY2,Y
 CMP #FF
 BEQ WP2
 STA Y2
 LDA LSX2,Y
 STA X2
 JSR LOIN
 INY
 LDA SWAP
 BNE WPL1

 LDA X2
 STA X1
 LDA Y2
 STA Y1
 JMP WPL1

.WP2
 INY
 LDA LSX2,Y
 STA X1
 LDA LSY2,Y
 STA Y1
 INY
 JMP WPL1

.WP1
 LDA #1
 STA LSP
 LDA #FF
 STA LSX2
 RTS

.WPLS
 LDA LSX
 BMI WPLS-1
 LDA SUNX
 STA YY
 LDA SUNX+1
 STA YY+1
 LDY #2*Y-1

.WPL2
 LDA LSO,Y
 BEQ P%+5
 JSR HLOIN2
 DEY
 BNE WPL2
 DEY
 STY LSX
 RTS

.EDGES
 STA T
 CLC
 ADC YY
 STA X2
 LDA YY+1
 ADC #0
 BMI ED1
 BEQ P%+6
 LDA #254
 STA X2

 LDA YY
 SEC
 SBC T
 STA X1
 LDA YY+1
 SBC #0
 BNE ED3
 CLC
 RTS

.ED3
 BPL ED1
 LDA #2
 STA X1
 CLC
 RTS

.ED1
 LDA #0
 STA LSO,Y
 SEC
 RTS

.CHKON
 LDA K3
 CLC
 ADC K
 LDA K3+1
 ADC #0
 BMI PL21
 LDA K3
 SEC
 SBC K
 LDA K3+1
 SBC #0
 BMI PL31
 BNE PL21

.PL31
 LDA K4
 CLC
 ADC K
 STA P+1
 LDA K4+1
 ADC #0
 BMI PL21
 STA P+2
 LDA K4
 SEC
 SBC K
 TAX
 LDA K4+1
 SBC #0
 BMI PL44
 BNE PL21
 CPX #2*Y-1
 RTS

.PL21
 SEC
 RTS

.PLS3
 JSR PLS1
 STA P
 LDA #222
 STA Q
 STX U
 JSR MULTU
 LDX U
 LDY K+3
 BPL PL12
 EOR #FF
 CLC
 ADC #1
 BEQ PL12
 LDY #FF
 RTS

.PL12
 LDY #0
 RTS

.PLS4
 STA Q
 JSR ARCTAN
 LDX INWK+14
 BMI P%+4
 EOR #128
 LSR A
 LSR A
 STA CNT2
 RTS

.PLS5
 JSR PLS1
 STA K2+2
 STY XX16+2
 JSR PLS1
 STA K2+3
 STY XX16+3
 RTS

.PLS6
 JSR DVID3B2
 LDA K+3
 AND #127
 ORA K+2
 BNE PL21
 LDX K+1
 CPX #4
 BCS PL6
 LDA K+3
\CLC
 BPL PL6
 LDA K
 EOR #FF
 ADC #1
 STA K
 TXA
 EOR #FF
 ADC #0
 TAX

.PL44
 CLC

.PL6
 RTS

.TT17
 JSR DOKEY
 LDA JSTK
 BEQ TJ1
 LDA JSTX
 EOR #FF
 JSR TJS1
 TYA
 TAX

 LDA JSTY

.TJS1
 TAY
 LDA #0
 CPY #&10
 SBC #0
\CPY#&20SBC#0
 CPY #&40
 SBC #0
 CPY #&C0
 ADC #0
 CPY #&E0
 ADC #0
\CPY#&F0ADC#0

 TAY
 LDA KL
 RTS

.TJ1
 LDA KL
 LDX #0
 LDY #0
 CMP #&19
 BNE P%+3
 DEX
 CMP #&79
 BNE P%+3
 INX
 CMP #&39
 BNE P%+3
 INY
 CMP #&29
 BNE P%+3
 DEY
 RTS

.ping
 LDX #1

.pl1
 LDA QQ0,X
 STA QQ9,X
 DEX
 BPL pl1
 RTS

;IFZ>4OSCLI("S.ELTE "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%)

PRINT "ELITE<E>"
PRINT "ASSEMBLE AT W%=", ~C_E%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_E%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_E%

PRINT "S.ELTE ",~C_E%," ",~P%," ",~L%," ",~H_E%
SAVE "output/ELTE.bin", C_E%, P%, L%

PRINT "E e,";

\************************************************
\* ELITE<F>
\************************************************

;H%=L%+P%-C%
;O%=W%
C_F%=P%
H_F%=L%+P%-C_A%

\[OPTZ

.KS3
 LDA P
 STA SLSP
 LDA P+1
 STA SLSP+1
 RTS

.KS1
 LDX XSAV
 JSR KILLSHP
 LDX XSAV
 JMP MAL1

.KS4
 JSR ZINF
 JSR FLFLLS
 STA FRIN+1
 STA SSPR
 JSR SPBLB
 LDA #6
 STA INWK+5
 LDA #&81
 JMP NWSHP

.KS2
 LDX #FF

.KSL4
 INX
 LDA FRIN,X
 BEQ KS3
 CMP #MSL
 BNE KSL4
 TXA
 ASL A
 TAY
 LDA UNIV,Y
 STA SC
 LDA UNIV+1,Y
 STA SC+1

 LDY #32
 LDA (SC),Y
 BPL KSL4
 AND #&7F
 LSR A
 CMP XX4
 BCC KSL4
 BEQ KS6
 SBC #1
 ASL A
 ORA #128
 STA (SC),Y
 BNE KSL4

.KS6
 LDA #0
 STA (SC),Y
 BEQ KSL4

.KILLSHP
 STX XX4
;CPXMSTG
 LDA  MSTG            ; NOT IN ELITEF.TXT but is in ELITE SOURCE IMAGE
 CMP  XX4             ; NOT IN ELITEF.TXT but is in ELITE SOURCE IMAGE
 BNE KS5 \<<**
 LDY #&EE
 JSR ABORT
 LDA #200
 JSR MESS

.KS5
 LDY XX4
 LDX FRIN,Y
 CPX #SST
 BEQ KS4
 DEC MANY,X
 LDX XX4

 LDY #5
 LDA (XX0),Y
 LDY #33
 CLC
 ADC (INF),Y
 STA P
 INY
 LDA (INF),Y
 ADC #0
 STA P+1

.KSL1
 INX
 LDA FRIN,X
 STA FRIN-1,X
 BEQ KS2
 ASL A
 TAY
 LDA XX21-2,Y
 STA SC
 LDA XX21-1,Y
 STA SC+1
 LDY #5
 LDA (SC),Y
 STA T
 LDA P
 SEC
 SBC T
 STA P
 LDA P+1
 SBC #0
 STA P+1

 TXA
 ASL A
 TAY
 LDA UNIV,Y
 STA SC
 LDA UNIV+1,Y
 STA SC+1
 LDY #35
 LDA (SC),Y
 STA (INF),Y
 DEY

 LDA (SC),Y
 STA K+1
 LDA P+1
 STA (INF),Y
 DEY
 LDA (SC),Y
 STA K
 LDA P
 STA (INF),Y
 DEY

.KSL2
 LDA (SC),Y
 STA (INF),Y
 DEY
 BPL KSL2
 LDA SC
 STA INF
 LDA SC+1
 STA INF+1

 LDY T
.KSL3
 DEY
 LDA (K),Y
 STA (P),Y
 TYA
 BNE KSL3
 BEQ KSL1

.SFX
 EQUS  &12,&01,&00,&10   ;FNS("12010010")
 EQUS  &12,&02,&2C,&08    ;FNS("12022C08")
 EQUS  &11,&03,&F0,&18    ;FNS("1103F018")
 EQUS  &10,&F1,&07,&1A    ;FNS("10F1071A")

 EQUS  &03,&F1,&BC,&01    ;FNS("03F1BC01")
 EQUS  &13,&F4,&0C,&08    ;FNS("13F40C08")
 EQUS  &10,&F1,&06,&0C    ;FNS("10F1060C")
 EQUS  &10,&02,&60,&10    ;FNS("10026010") HYP
 EQUS  &13,&04,&C2,&FF    ;FNS("1304C2FF")
 EQUS  &13,&00,&00,&00    ;FNS("13000000")

.RESET \"�<<<<"
 JSR ZERO
 LDX #6

.SAL3
 STA BETA,X
 DEX
 BPL SAL3
 STX QQ12

.RES4
 LDA #FF
 LDX #2

.REL5
 STA FSH,X
 DEX
 BPL REL5

.RES2
 LDA #NOST
 STA NOSTM
 LDX #FF
 STX LSX2
 STX LSY2
 STX MSTG
 LDA #128
 STA JSTY
 STA ALP2
 STA BET2
 ASL A
 STA ALP2+1
 STA BET2+1
 STA MCNT
 LDA #3
 STA DELTA
 STA ALPHA
 STA ALP1

 LDA SSPR
 BEQ P%+5
 JSR SPBLB
 LDA ECMA
 BEQ yu
 JSR ECMOF

.yu
 JSR WPSHPS
 JSR ZERO
 LDA #(LS%MOD256)
 STA SLSP
 LDA #(LS%DIV256)
 STA SLSP+1
 JSR DIALS

.ZINF
 LDY #NI%-1
 LDA #0

.ZI1
 STA INWK,Y
 DEY
 BPL ZI1
 LDA #96
 STA INWK+18
 STA INWK+22
 ORA #128
 STA INWK+14
 RTS

.msblob
 LDX #4

.ss
 CPX NOMSL
 BEQ SAL8
 LDY #0
 JSR MSBAR
 DEX
 BNE ss
 RTS

.SAL8
 LDY #&EE
 JSR MSBAR
 DEX
 BNE SAL8
 RTS

.me2
 LDA MCH
 JSR MESS
 LDA #0
 STA DLY
 JMP me3

.Ze
 JSR ZINF
 JSR DORND
 STA T1
 AND #128
 STA INWK+2
 TXA
 AND #128
 STA INWK+5
 LDA #32
 STA INWK+1
 STA INWK+4
 STA INWK+7
 TXA
 CMP #245
 ROL A
 ORA #&C0
 STA INWK+32

.DORND2
 CLC

.DORND
 LDA RAND
 ROL A
 TAX
 ADC RAND+2
 STA RAND
 STX RAND+2
 LDA RAND+1
 TAX
 ADC RAND+3
 STA RAND+1
 STX RAND+3
 RTS

.MTT4
 LSR A
 STA INWK+32
 STA INWK+29
 ROL INWK+31
 AND #31
 ORA #16
 STA INWK+27
 LDA #CYL
 JSR NWSHP

.TT100
 JSR M%
 DEC DLY
 BEQ me2
 BPL me3
 INC DLY

.me3
 DEC MCNT
 BEQ P%+5

.ytq
 JMP MLOOP
 LDA MJ
 BNE ytq

 JSR DORND
 CMP #35
 BCS MTT1
 LDA MANY+AST
 CMP #3
 BCS MTT1
 JSR ZINF
 LDA #38
 STA INWK+7
 JSR DORND
 STA INWK
 STX INWK+3
 AND #128
 STA INWK+2
 TXA
 AND #128
 STA INWK+5
 ROL INWK+1
 ROL INWK+1

 JSR DORND
BVSMTT4
 ORA #&6F
 STA INWK+29
 LDA SSPR
 BNE MTT1
 TXA
 BCS MTT2
 AND #31
 ORA #16
 STA INWK+27
 BCC MTT3

.MTT2
 ORA #127
 STA INWK+30

.MTT3
 JSR DORND
 CMP #5
 LDA #AST
 BCS P%+4
 LDA #OIL
 JSR NWSHP

.MTT1
 LDA SSPR
 BNE MLOOP
 JSR BAD
 ASL A
 LDX MANY+COPS
 BEQ P%+5
 ORA FIST
 STA T
 JSR Ze
 CMP T
 BCS P%+7
 LDA #COPS
 JSR NWSHP
 LDA MANY+COPS
 BNE MLOOP
 DEC EV
 BPL MLOOP
 INC EV
 JSR DORND
 LDY gov
 BEQ  LABEL_2
 CMP #90
 BCS MLOOP
 AND #7
 CMP gov
 BCC MLOOP

.LABEL_2
 JSR Ze
 CMP #200
 BCS mt1
 INC EV
 AND #3
 ADC #3
 TAY
 TXA
 CMP #200
 ROL A
 ORA #&C0
 CPY #6
 BEQ tha
 STA INWK+32
 TYA
 JSR NWSHP

.mj1
 JMP MLOOP

.mt1
 AND #3
 STA EV
 STA XX13

.mt3
 JSR DORND
 AND #3
 ORA #1
 JSR NWSHP

 DEC XX13
 BPL mt3

.MLOOP
 LDA #1
 STA VIA+&E
 LDX #FF
TXS
 LDX GNTMP
 BEQ EE20
 DEC GNTMP

.EE20
 JSR DIALS
 LDA QQ11
 BEQ P%+11
 AND PATG
 LSR A
 BCS P%+5
 JSR DELAY-5

 JSR TT17

.FRCE
 JSR TT102
 LDA QQ12
 BNE MLOOP
 JMP TT100

.tha
 JSR DORND
 CMP #200
 BCC P%+5
 JSR GTHG
 JMP MLOOP

.TT102
 CMP #f8
 BNE P%+5
 JMP STATUS
 CMP #f4
 BNE P%+5
 JMP TT22
 CMP #f5
 BNE P%+5
 JMP TT23
 CMP #f6
 BNE TT92
 JSR TT111
 JMP TT25

.TT92
 CMP #f9
 BNE P%+5
 JMP TT213
 CMP #f7
 BNE P%+5
 JMP TT167
 CMP #f0
 BNE fvw
 JMP TT110

.fvw
 BIT QQ12

 BPL INSP
 CMP #f3
 BNE P%+5
 JMP EQSHP
 CMP #f1
 BNE P%+5
 JMP TT219
 CMP #&47
 BNE P%+5
 JMP SVE

 CMP #f2
 BNE  LABEL_3
 JMP TT208

.INSP
 CMP #&71
 BCC  LABEL_3
 CMP #&74
 BCS  LABEL_3
 AND #3
 TAX
 JMP LOOK1

.LABEL_3
 CMP #&54
 BNE P%+5
 JMP hyp
 CMP #&32
 BEQ T95
 STA T1
 LDA QQ11
 AND #192
 BEQ TT107
 LDA QQ22+1
 BNE TT107
 LDA T1
 CMP #&36
 BNE ee2
 JSR TT103
 JSR ping

 JSR TT103

.ee2
 JSR TT16

.TT107
 LDA QQ22+1
 BEQ t95
 DEC QQ22
 BNE t95
 LDX QQ22+1
 DEX
 JSR ee3
 LDA #5
 STA QQ22
 LDX QQ22+1
 JSR ee3
 DEC QQ22+1
 BNE t95
 JMP TT18

.t95
 RTS

.T95
 LDA QQ11
 AND #192
 BEQ t95
 JSR hm
 STA QQ17
 JSR cpl
 LDA #128
 STA QQ17
 LDA #1
 STA XC
 INC YC
 JMP TT146

.BAD
 LDA QQ20+3
 CLC
 ADC QQ20+6
 ASL A
 ADC QQ20+10
 RTS

.FAROF
 LDA #&E0

.FAROF2
 CMP INWK+1
 BCC MA34
 CMP INWK+4
 BCC MA34
 CMP INWK+7

.MA34
 RTS

.MAS4
 ORA INWK+1
 ORA INWK+4
 ORA INWK+7
 RTS

.DEATH
 JSR EXNO3
 JSR RES2
 ASL DELTA
 ASL DELTA
 LDX #24
 JSR DET1
 JSR TT66
 JSR BOX
 JSR nWq
 LDA #12
 STA YC
 STA XC
 LDA #146
 JSR ex

.D1
 JSR Ze
 LSR A
 LSR A
 STA INWK
 LDY #0
 STY QQ11
 STY INWK+1
 STY INWK+4
 STY INWK+7
 STY INWK+32
 DEY
 STY MCNT
 STY LASCT
 EOR #42

 STA INWK+3
 ORA #80
 STA INWK+6
 TXA
 AND #&8F
 STA INWK+29

 ROR A
 AND #&87
 STA INWK+30
 PHP
 LDX #OIL
 JSR fq1
 PLP
 LDA #0
 ROR A
 LDY #31
 STA (INF),Y
 LDA FRIN+3
 BEQ D1
 JSR U%
 STA DELTA

.D2
 JSR M%
 LDA LASCT
 BNE D2
 LDX #31
 JSR DET1

.DEATH2
 JSR RES2

\ *****************************************************************************
\ * Entry point for Elite game code
\ *****************************************************************************

.TT170
 LDX #FF
 TXS

.BR1
 LDX #3
 STX XC
 JSR FX200
 LDX #CYL
 LDA #128
 JSR TITLE
 CMP #&44
 BNE QU5
\BR1 LDX#3STXXCJSRFX200LDA#1JSRTT66JSRFLKB

\LDA#14JSRTT214BCCQU5
 JSR GTNME
 JSR LOD
 JSR TRNME
 JSR TTX66

.QU5
\JSRTTX66
 LDX #NT%

.QUL1
 LDA NA%+7,X
 STA TP-1,X
 DEX
 BNE QUL1
 STX QQ11
 JSR CHECK
 CMP CHK
 BNE P%-6
 EOR #&A9
 TAX
 LDA COK
 CPX CHK2
 BEQ tZ
 ORA #128

.tZ
 ORA #2
 STA COK
 JSR msblob
 LDA #147
 LDX #3
 JSR TITLE
 JSR ping
 JSR hyp1

.BAY
 LDA #FF
 STA QQ12
 LDA #f8
 JMP FRCE

.TITLE
 PHA
 STX TYPE
 JSR RESET
 LDA #1
 JSR TT66
 DEC QQ11
 LDA #96
 STA INWK+14

\LSRA
 STA INWK+7
 LDX #127
 STX INWK+29
 STX INWK+30
 INX
 STX QQ17

 LDA TYPE
 JSR NWSHP

 LDY #6
 STY XC
 JSR DELAY
 LDA #30
 JSR plf
 LDY #6
 STY XC
 INC YC
 LDA PATG
 BEQ awe
 LDA #254
 JSR TT27

.awe
 JSR CLYNS
 STY DELTA
 STY JSTK
 PLA
 JSR ex
 LDA #148
 LDX #7
 STX XC
 JSR ex

.TLL2
 LDA INWK+7
 CMP #1
 BEQ TL1
 DEC INWK+7

.TL1
 JSR MVEIT
 LDA #128
 STA INWK+6
 ASL A
 STA INWK
 STA INWK+3
 JSR LL9
 DEC MCNT
 LDA &FE40
 AND #16
\TAX
 BEQ TL2
 JSR RDKEY
 BEQ TLL2
 RTS

.TL2
 DEC JSTK
 RTS

.CHECK
 LDX #NT%-2
 CLC
 TXA

.QUL2
 ADC NA%+7,X
 EOR NA%+8,X
 DEX
 BNE QUL2
 RTS

.TRNME
 LDX #7

.GTL1
 LDA INWK,X
 STA NA%,X
 DEX
 BPL GTL1

.TR1
 LDX #7

.GTL2
 LDA NA%,X
 STA INWK,X
 DEX
 BPL GTL2
 RTS

.GTNME
 LDA #1
 JSR TT66
 LDA #123
 JSR TT27
 JSR DEL8
 LDA #&81
 STA VIA+&E
 LDA #15
 TAX
 JSR OSBYTE
 LDX #(RLINE MOD256)
 LDY #(RLINE DIV256)
 LDA #0
 JSR OSWORD\LDA#1STAVIA+&E
 BCS TR1
 TYA
 BEQ TR1
 JMP TT67

.RLINE
 EQUW INWK
 EQUB 7
 EQUB 33
 EQUB &7A

.ZERO
 LDX #&D

.ZEL
 JSR ZES1
 DEX
 CPX #9
 BNE ZEL

.ZES1
 LDY #0
 STY SC

.ZES2
 LDA #0
 STX SC+1

.ZEL1
 STA (SC),Y
 INY
 BNE ZEL1
 RTS

.SVE
 JSR GTNME
 JSR TRNME
 JSR ZERO
 LSR SVC
 LDX #NT%

.SVL1
 LDA TP,X
 STA &B00,X
 STA NA%+8,X
 DEX
 BPL SVL1
 JSR CHECK
 STA CHK
 PHA
 ORA #128
 STA K
 EOR COK
 STA K+2
 EOR CASH+2
 STA K+1
 EOR #&5A
 EOR TALLY+1
 STA K+3
 JSR BPRNT
 JSR TT67
 JSR TT67
 PLA
 STA &B00+NT%
 EOR #&A9

 STA CHK2
 STA &AFF+NT%
 LDY #&B
 STY &C0B
 INY
 STY &C0F

 LDA #&81
 STA VIA+&E
 INC svn
 LDA #0
 JSR QUS1
 LDX #0\STXVIA+&EDEX
 STX svn
 JMP BAY

.QUS1
 LDX #INWK
 STX &C00
 LDX #0
 JMP OSFILE

.LOD
 LDX #2
 JSR FX200
 JSR ZERO
 LDY #&B
 STY &C03
 INC &C0B
 INY
 LDA #FF
 JSR QUS1
 LDA &B00
 BMI SPS1+1
 LDX #NT%

.LOL1
 LDA &B00,X
 STA NA%+8,X
 DEX
 BPL LOL1
 LDX #3

.FX200
\MOS
 LDY #0
 LDA #200
 JMP OSBYTE

 RTS

.SPS1
 LDX #0
 JSR SPS3
 LDX #3
 JSR SPS3
 LDX #6
 JSR SPS3

.TAS2
 LDA K3
 ORA K3+3
 ORA K3+6
 ORA #1
 STA K3+9
 LDA K3+1
 ORA K3+4
 ORA K3+7

.TAL2
 ASL K3+9
 ROL A
 BCS TA2
 ASL K3
 ROL K3+1
 ASL K3+3
 ROL K3+4
 ASL K3+6
 ROL K3+7
 BCC TAL2

.TA2
 LDA K3+1
 LSR A
 ORA K3+2
 STA XX15
 LDA K3+4
 LSR A
 ORA K3+5
 STA XX15+1
 LDA K3+7
 LSR A
 ORA K3+8
 STA XX15+2

.NORM
 LDA XX15
 JSR SQUA
 STA R
 LDA P
 STA Q
 LDA XX15+1
 JSR SQUA
 STA T
 LDA P
 ADC Q
 STA Q
 LDA T
 ADC R
 STA R
 LDA XX15+2
 JSR SQUA
 STA T
 LDA P
 ADC Q
 STA Q
 LDA T
 ADC R
 STA R

 JSR LL5

 LDA XX15
 JSR TIS2
 STA XX15 \*96/Q

 LDA XX15+1
 JSR TIS2
 STA XX15+1

 LDA XX15+2
 JSR TIS2
 STA XX15+2

.NO1
 RTS

.RDKEY
\OSBYTE7A
 LDX #16
.Rd1
 JSR DKS4
 BMI Rd2
 INX
 BPL Rd1
 TXA

.Rd2
 EOR #128
 TAX
 RTS

.ECMOF
 LDA #0
 STA ECMA
 STA ECMP
 JSR ECBLB
 LDA #72
 BNE NOISE

.EXNO3
 LDA #16
 JSR NOISE
 LDA #24
 BNE NOISE

.SFRMIS
 LDX #MSL
 JSR SFS1-2
 BCC NO1
 LDA #&78
 JSR MESS
 LDA #48
 BNE NOISE

.EXNO2
 INC TALLY
 BNE EXNO-2
 INC TALLY+1
 LDA #101
 JSR MESS
 LDX #7 \15

.EXNO
 STX T
 LDA #24
 JSR NOS1
 LDA INWK+7
 LSR A
 LSR A
 AND T
 ORA #&F1
 STA XX16+2
 JSR NO3
 LDA #16

 EQUB &2C

.BEEP
 LDA #32

.NOISE
 JSR NOS1

.NO3
 LDX DNOIZ
 BNE NO1
 LDX #(XX16 MOD256)
 LDY #(XX16 DIV256)
 LDA #7
 JMP OSWORD

.NOS1
 LSR A
 ADC #3
 TAY
 LDX #7

.NOL1
 LDA #0
 STA XX16,X
 DEX
 LDA SFX,Y
 STA XX16,X
 DEY
 DEX
 BPL NOL1

.KYTB
 RTS

 EQUB &E8
 EQUB &E2
 EQUB &E6
 EQUB &E7
 EQUB &C2
 EQUB &D1
 EQUB &C1
 EQUD &35237060
 EQUW &2265
 EQUB &45
 EQUB &52 \? <>XSA.FBRLtabescTUMEJC

.DKS1
 LDX KYTB,Y
 JSR DKS4
 BPL DKS2-1
 LDX #FF
 STX KL,Y
 RTS

.CTRL
 LDX #1

.DKS4
 LDA #3
 SEI
 STA &FE40
 LDA #&7F
 STA &FE43
 STX &FE4F
 LDX &FE4F
 LDA #&B
 STA &FE40
 CLI
 TXA
 RTS

.DKS2
 LDA #&80
 JSR OSBYTE
 TYA
 EOR JSTE
 RTS

.DKS3
 STY T
 CPX T
 BNE Dk3
 LDA DAMP-&40,X
 EOR #FF
 STA DAMP-&40,X
 JSR BELL
 JSR DELAY
 LDY T

.Dk3
 RTS

.DKJ1
 LDY #1
 JSR DKS1
 INY
 JSR DKS1

 LDA &FE40
 TAX
 AND #16
 EOR #16
 STA KL+7
 LDX #1
 JSR DKS2
 ORA #1
 STA JSTX
 LDX #2
 JSR DKS2
 EOR JSTGY
 STA JSTY
 JMP DK4

.U%
 LDA #0
 LDY #15

.DKL3
 STA KL,Y
 DEY
 BNE DKL3
 RTS

.DOKEY
 JSR U%
 LDA JSTK
 BNE DKJ1

 LDY #7
.DKL2
 JSR DKS1
 DEY
 BNE DKL2

 LDX JSTX
 LDA #7
 LDY KL+3
 BEQ P%+5
 JSR BUMP2
 LDY KL+4
 BEQ P%+5
 JSR REDU2
 STX JSTX

 ASL A
 LDX JSTY
 LDY KL+5
 BEQ P%+5
 JSR REDU2
 LDY KL+6
 BEQ P%+5
 JSR BUMP2
 STX JSTY

.DK4
 JSR RDKEY
 STX KL
 CPX #&69
 BNE DK2

.FREEZE
 JSR WSCAN
 JSR RDKEY
 CPX #&51
 BNE DK6
 LDA #0
 STA DNOIZ

.DK6
 LDY #&40

.DKL4
 JSR DKS3
 INY
 CPY #&47
 BNE DKL4

.DK55
 CPX #&10
 BNE DK7
 STX DNOIZ

.DK7
 CPX #&70
 BNE P%+5
 JMP DEATH2
 CPX #&59
 BNE FREEZE

.DK2
 LDA QQ11
 BNE DK5
 LDY #15
 LDA #FF

.DKL1
 LDX KYTB,Y
 CPX KL
 BNE DK1
 STA KL,Y

.DK1
 DEY
 CPY #7
 BNE DKL1

.DK5
 RTS

.TT217
 STY YSAV

.t
 JSR DELAY-5
 JSR RDKEY
 BNE t

.t2
 JSR RDKEY
 BEQ t2
 TAY
 LDA (TRTB%),Y
 LDY YSAV
 TAX

.out
 RTS

.me1
 STX DLY
 PHA
 LDA MCH
 JSR mes9
 PLA
 EQUB &2C

.ou2
 lda #108
 EQUB &2C

.ou3
 lda #111

.MESS
 LDX #0
 STX QQ17
 LDY #9
 STY XC
 LDY #22
 STY YC
 CPX DLY
 BNE me1
 STY DLY
 STA MCH

.mes9
 JSR TT27
 LSR de
 BCC out
 LDA #253
 JMP TT27

.OUCH
 JSR DORND
 BMI out
 CPX #22
 BCS out
 LDA QQ20,X
 BEQ out
 LDA DLY
 BNE out
 LDY #3
 STY de
 STA QQ20,X
 CPX #17
 BCS ou1
 TXA
 ADC #208
 BNE MESS

.ou1
 BEQ ou2
 CPX #18
 BEQ ou3
 TXA
 ADC #113-20
 BNE MESS

.QQ16
 EQUS "ALLEXEGEZACEBISOUSESARMAINDIREA?ERATENBERALAVETIEDORQUANTEISRION"

.QQ23
\Prxs
 EQUD &1068213
 EQUD &30A8114
 EQUD &7028341\Food

 EQUD &1FE28528
 EQUD &FFB8553
 EQUD &33608C4
 EQUD  &78081DEB \slvs..

 EQUD &3380E9A
 EQUD &7280675
 EQUD &1F11014E
 EQUD &71D0D7C \comps

 EQUD &3FDC89B0
 EQUD &03358120
 EQUD &742A161
 EQUD &1F37A2AB \pltnm

 EQUD &FFAC12D
 EQUD &7C00F35 \Gms.

.TI2
 TYA
 LDY #2
 JSR TIS3
 STA INWK+20\Uz=-(FxUx+FyUy)/Fz
 JMP TI3

.TI1
 TAX
 LDA XX15+1
 AND #&60
 BEQ TI2
 LDA #2
 JSR TIS3
 STA INWK+18
 JMP TI3

.TIDY
 LDA INWK+10
 STA XX15
 LDA INWK+12
 STA XX15+1
 LDA INWK+14
 STA XX15+2
 JSR NORM
 LDA XX15
 STA INWK+10
 LDA XX15+1
 STA INWK+12
 LDA XX15+2
 STA INWK+14

 LDY #4
 LDA XX15
 AND #&60
 BEQ TI1
 LDX #2
 LDA #0
 JSR TIS3
 STA INWK+16

.TI3
 LDA INWK+16
 STA XX15
 LDA INWK+18
 STA XX15+1
 LDA INWK+20
 STA XX15+2
 JSR NORM
 LDA XX15
 STA INWK+16
 LDA XX15+1
 STA INWK+18
 LDA XX15+2
 STA INWK+20

 LDA INWK+12
 STA Q
 LDA INWK+20
 JSR MULT12
 LDX INWK+14
 LDA INWK+18
 JSR TIS1
 EOR #128
 STA INWK+22

 LDA INWK+16
 JSR MULT12
 LDX INWK+10
 LDA INWK+20
 JSR TIS1
 EOR #128
 STA INWK+24

 LDA INWK+18
 JSR MULT12
 LDX INWK+12
 LDA INWK+16
 JSR TIS1
 EOR #128
 STA INWK+26 \FxU/96(LHS)

 LDA #0
 LDX #14

.TIL1
 STA INWK+9,X
 DEX
 DEX
 BPL TIL1
 RTS

.TIS2
 TAY
 AND #127
 CMP Q
 BCS TI4
 LDX #254
 STX T

.TIL2
 ASL A
 CMP Q
 BCC P%+4
 SBC Q
 ROL T
 BCS TIL2
 LDA T

 LSR A
 LSR A
 STA T
 LSR A
 ADC T
 STA T
 TYA
 AND #128
 ORA T
 RTS

.TI4
 TYA
 AND #128
 ORA #96
 RTS

.TIS3
 STA P+2
 LDA INWK+10,X
 STA Q
 LDA INWK+16,X
 JSR MULT12
 LDX INWK+10,Y
 STX Q
 LDA INWK+16,Y
 JSR MAD

 STX P
 LDY P+2
 LDX INWK+10,Y
 STX Q
 EOR #128

.DVIDT
\A=AP/Q
 STA P+1
 EOR Q
 AND #128
 STA T
 LDA #0
 LDX #16
 ASL P
 ROL P+1
 ASL Q
 LSR Q

.DVL2
 ROL A
 CMP Q
 BCC P%+4
 SBC Q
 ROL P
 ROL P+1
 DEX
 BNE DVL2
 LDA P
 ORA T
 RTS


;OSCLI("S.ELTF "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%)

PRINT "ELITE<F>"
PRINT "ASSEMBLE AT W%=", ~C_F%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_F%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_F%

PRINT "S.ELTF ",~C_F%," ",~P%," ",~L%," ",~H_F%
SAVE "output/ELTF.bin", C_F%, P%, L%

PRINT "F d,";

;DEFFNS(A$)
;N%=LEN(A$)DIV2
;FORI%=0TON%-1
;I%?O%=EVAL("&"+MID$(A$,2*I%+1,2))
;NEXT
;P%=P%+N%
;O%=O%+N%
;=""

\************************************************
\* ELITE<G>
\************************************************

;H%=L%+P%-C%
;O%=W%
C_G%=P%
H_G%=L%+P%-C_A%

\[OPTZ

.SHPPT
 JSR EE51
 JSR PROJ
 ORA K3+1
 BNE nono
 LDA K4
 CMP #Y*2-2
 BCS nono
 LDY #2
 jsr Shpt
 ldy #6
 lda K4
 ADC #1
 jsr Shpt
 LDA #8
 ORA XX1+31
 STA XX1+31
 LDA #8
 JMP LL81+2
 PLA
 PLA

.nono
 lda #&F7
 and XX1+31
 sta XX1+31
 RTS

.Shpt
 STA (XX19),Y
 iny
 iny
 STA (XX19),Y
 LDA K3
 DEY
 STA (XX19),Y
 ADC #3
 BCS nono-2
 dey
 dey
 STA (XX19),Y
 rts

.LL5
\2BSQRT Q=SQR(RQ)
 LDY R
 LDA Q
 STA S
 LDX #0
 STX Q
 LDA #8
 STA T

.LL6
 CPX Q
 BCC LL7
 BNE LL8
 CPY #&40
 BCC LL7

.LL8
 TYA
 SBC #&40
 TAY
 TXA
 SBC Q
 TAX

.LL7
 ROL Q
 ASL S
 TYA
 ROL A
 TAY
 TXA
 ROL A
 TAX
 ASL S
 TYA
 ROL A
 TAY
 TXA
 ROL A
 TAX
 DEC T
 BNE LL6
 RTS

.LL28
\BFRDIV R=A*256/Q
 CMP Q
 BCS LL2
 LDX #254
 STX R

.LL31
 ASL A
 BCS LL29
 CMP Q
 BCC P%+4
 SBC Q
 ROL R
 BCS LL31
 RTS

.LL29
 SBC Q
 SEC
 ROL R
 BCS LL31
 RTS

.LL2
 LDA #FF
 STA R
 RTS

.LL38
\BADD(S)A=R+Q(SA)
 EOR S
 BMI LL39
 LDA Q
 CLC
 ADC R
 RTS

.LL39
 LDA R
 SEC
 SBC Q

 BCC P%+4
 CLC
 RTS
 PHA
 LDA S
 EOR #128
 STA S
 PLA
 EOR #255
 ADC #1
 RTS

.LL51
\XX12=XX15.XX16
 LDX #0
 LDY #0

.ll51
 LDA XX15
 STA Q
 LDA XX16,X
 JSR FMLTU
 STA T
 LDA XX15+1
 EOR XX16+1,X
 STA S
 LDA XX15+2

 STA Q
 LDA XX16+2,X
 JSR FMLTU
 STA Q
 LDA T
 STA R
 LDA XX15+3

 EOR XX16+3,X
 JSR LL38
 STA T
 LDA XX15+4
 STA Q
 LDA XX16+4,X
 JSR FMLTU
 STA Q
 LDA T
 STA R
 LDA XX15+5
 EOR XX16+5,X

 JSR LL38
 STA XX12,Y
 LDA S
 STA XX12+1,Y
 INY
 INY
 TXA
 CLC
 ADC #6
 TAX
 CMP #17
 BCC ll51
 RTS

.LL25
 JMP PLANET

.LL9
\ ENTRY
 LDA TYPE
 BMI LL25

 LDA #31
 STA XX4
 LDA #32
 BIT XX1+31
 BNE EE28

 BPL EE28
 ORA XX1+31
 AND #&3F
 STA XX1+31
 LDA #0
 LDY #28
 STA (INF),Y
 LDY #30
 STA (INF),Y
 JSR EE51
 LDY #1
 LDA #18
 STA (XX19),Y
 LDY #7
 LDA (XX0),Y
 LDY #2
 STA (XX19),Y

\LDAXX1+32
\AND#&7F
\STAXX1+32

.EE55
 INY
 JSR DORND
 STA (XX19),Y
 CPY #6
 BNE EE55

.EE28
 LDA XX1+8

.EE49
 BPL LL10

.LL14
 LDA XX1+31
 AND #32
 BEQ EE51
 LDA XX1+31
 AND #&F7
 STA XX1+31
 JMP DOEXP

.EE51
 LDA #8
 BIT XX1+31
 BEQ LL10-1
 EOR XX1+31
 STA XX1+31
 JMP LL155

\LL24
 RTS

.LL10
 LDA XX1+7
 CMP #&C0
 BCS LL14
 LDA XX1
 CMP XX1+6
 LDA XX1+1
 SBC XX1+7
 BCS LL14
 LDA XX1+3
 CMP XX1+6
 LDA XX1+4
 SBC XX1+7
 BCS LL14

 LDY #6
 LDA (XX0),Y
 TAX
 LDA #255
 STA XX3,X
 STA XX3+1,X

 LDA XX1+6
 STA T
 LDA XX1+7
 LSR A
 ROR T
 LSR A
 ROR T
 LSR A
 ROR T
 LSR A
 BNE LL13
 LDA T
 ROR A
 LSR A
 LSR A
 LSR A
 STA XX4

 BPL LL17

.LL13
 LDY #13
 LDA (XX0),Y
 CMP XX1+7
 BCS LL17
 LDA #32
 AND XX1+31
 BNE LL17
 JMP SHPPT

.LL17
 LDX #5

.LL15
 LDA XX1+21,X
 STA XX16,X
 LDA XX1+15,X
 STA XX16+6,X
 LDA XX1+9,X
 STA XX16+12,X
 DEX
 BPL LL15

 LDA #197 \NORM
 STA Q
 LDY #16

.LL21
 LDA XX16,Y
 ASL A
 LDA XX16+1,Y

 ROL A
 JSR LL28
 LDX R
 STX XX16,Y
 DEY
 DEY
 BPL LL21

 LDX #8

.ll91
 LDA XX1,X
 STA XX18,X
 DEX
 BPL ll91

 LDA #255
 STA XX2+15

 LDY #12
 LDA XX1+31
 AND #32
 BEQ EE29
 LDA (XX0),Y
 LSR A
 LSR A
 TAX
 LDA #FF

.EE30
 STA XX2,X
 DEX
 BPL EE30
 INX
 STX XX4

.LL41
 JMP LL42

.EE29
 LDA (XX0),Y
 BEQ LL41
 STA XX20

\DtProd^XX2

 LDY #18
 LDA (XX0),Y
 TAX
 LDA XX18+7

.LL90
 TAY
 BEQ LL91
 INX
 LSR XX18+4
 ROR XX18+3
 LSR XX18+1
 ROR XX18
 LSR A
 ROR XX18+6
 TAY
 BNE LL90+3

.LL91
 STX XX17
 LDA XX18+8

 STA XX15+5
 LDA XX18
 STA XX15
 LDA XX18+2
 STA XX15+1
 LDA XX18+3
 STA XX15+2
 LDA XX18+5
 STA XX15+3
 LDA XX18+6
 STA XX15+4
 JSR LL51
 LDA XX12
 STA XX18
 LDA XX12+1
 STA XX18+2
 LDA XX12+2

 STA XX18+3
 LDA XX12+3
 STA XX18+5
 LDA XX12+4
 STA XX18+6
 LDA XX12+5
 STA XX18+8

 LDY #4
 LDA (XX0),Y
 CLC
 ADC XX0
 STA V
 LDY #17
 LDA (XX0),Y
 ADC XX0+1
 STA V+1
 LDY #0

.LL86
 LDA (V),Y
 STA XX12+1
 AND #31
 CMP XX4
 BCS LL87

 TYA
 LSR A
 LSR A
 TAX
 LDA #255
 STA XX2,X
 TYA
 ADC #4

 TAY
 JMP LL88

.LL87
 LDA XX12+1
 ASL A
 STA XX12+3
 ASL A
 STA XX12+5

 INY
 LDA (V),Y
 STA XX12
 INY
 LDA (V),Y
 STA XX12+2
 INY
 LDA (V),Y

 STA XX12+4
 LDX XX17
 CPX #4
 BCC LL92

.LL143 
\Face offset<<PV
 LDA XX18
 STA XX15
 LDA XX18+2
 STA XX15+1
 LDA XX18+3
 STA XX15+2
 LDA XX18+5
 STA XX15+3
 LDA XX18+6
 STA XX15+4
 LDA XX18+8
 STA XX15+5

 JMP LL89

.ovflw
 LSR XX18
 LSR XX18+6
 LSR XX18+3
 LDX #1

.LL92
 LDA XX12
 STA XX15
 LDA XX12+2
 STA XX15+2
 LDA XX12+4

.LL93
 DEX
 BMI LL94
 LSR XX15
 LSR XX15+2
 LSR A
 DEX
 BPL LL93+3

.LL94
 STA R
 LDA XX12+5
 STA S
 LDA XX18+6
 STA Q
 LDA XX18+8
 JSR LL38
 BCS ovflw

 STA XX15+4
 LDA S
 STA XX15+5

 LDA XX15
 STA R
 LDA XX12+1
 STA S

 LDA XX18
 STA Q
 LDA XX18+2
 JSR LL38
 BCS ovflw
 STA XX15
 LDA S
 STA XX15+1

 LDA XX15+2
 STA R
 LDA XX12+3
 STA S
 LDA XX18+3
 STA Q
 LDA XX18+5

 JSR LL38
 BCS ovflw
 STA XX15+2
 LDA S
 STA XX15+3

.LL89
 LDA XX12
 STA Q
 LDA XX15
 JSR FMLTU
 STA T
 LDA XX12+1

 EOR XX15+1
 STA S
 LDA XX12+2
 STA Q
 LDA XX15+2
 JSR FMLTU
 STA Q

 LDA T
 STA R
 LDA XX12+3
 EOR XX15+3
 JSR LL38
 STA T
 LDA XX12+4

 STA Q
 LDA XX15+4
 JSR FMLTU
 STA Q
 LDA T
 STA R
 LDA XX15+5

 EOR XX12+5
 JSR LL38
 PHA
 TYA
 LSR A
 LSR A
 TAX
 PLA

 BIT S
 BMI P%+4
 LDA #0
 STA XX2,X
 INY

.LL88
 CPY XX20
 BCS LL42
 JMP LL86

.LL42
\DO nodeX-Ycoords
\TrnspMat
 LDY XX16+2
 LDX XX16+3
 LDA XX16+6
 STA XX16+2
 LDA XX16+7
 STA XX16+3
 STY XX16+6
 STX XX16+7

 LDY XX16+4
 LDX XX16+5
 LDA XX16+12
 STA XX16+4
 LDA XX16+13

 STA XX16+5
 STY XX16+12
 STX XX16+13

 LDY XX16+10
 LDX XX16+11
 LDA XX16+14
 STA XX16+10
 LDA XX16+15

 STA XX16+11
 STY XX16+14
 STX XX16+15

 LDY #8
 LDA (XX0),Y
 STA XX20

 LDA XX0
 CLC
 ADC #20
 STA V
 LDA XX0+1
 ADC #0
 STA V+1
 LDY #0
 STY CNT

.LL48
 STY XX17
 LDA (V),Y
 STA XX15
 INY
 LDA (V),Y
 STA XX15+2
 INY

 LDA (V),Y
 STA XX15+4
 INY
 LDA (V),Y
 STA T
 AND #31
 CMP XX4
 BCC LL49-3
 INY
 LDA (V),Y
 STA P
 AND #15
 TAX
 LDA XX2,X

 BNE LL49
 LDA P
 LSR A
 LSR A
 LSR A
 LSR A
 TAX
 LDA XX2,X
 BNE LL49
 INY
 LDA (V),Y
 STA P
 AND #15
 TAX
 LDA XX2,X
 BNE LL49
 LDA P
 LSR A
 LSR A
 LSR A
 LSR A
 TAX
 LDA XX2,X
 BNE LL49
 JMP LL50

\"��

.LL49
 LDA T
 STA XX15+1
 ASL A
 STA XX15+3
 ASL A
 STA XX15+5

 JSR LL51
 LDA XX1+2
 STA XX15+2
 EOR XX12+1
 BMI LL52
 CLC
 LDA XX12

 ADC XX1
 STA XX15
 LDA XX1+1
 ADC #0
 STA XX15+1
 JMP LL53

.LL52
 LDA XX1
 SEC
 SBC XX12
 STA XX15
 LDA XX1+1
 SBC #0
 STA XX15+1

 BCS LL53
 EOR #FF
 STA XX15+1
 LDA #1
 SBC XX15
 STA XX15

 BCC P%+4
 INC XX15+1
 LDA XX15+2
 EOR #128
 STA XX15+2

.LL53
 LDA XX1+5
 STA XX15+5
 EOR XX12+3
 BMI LL54
 CLC
 LDA XX12+2

 ADC XX1+3
 STA XX15+3
 LDA XX1+4
 ADC #0
 STA XX15+4
 JMP LL55

.LL54
 LDA XX1+3
 SEC
 SBC XX12+2
 STA XX15+3
 LDA XX1+4
 SBC #0

 STA XX15+4
 BCS LL55
 EOR #255
 STA XX15+4
 LDA XX15+3
 EOR #255
 ADC #1

 STA XX15+3
 LDA XX15+5
 EOR #128
 STA XX15+5
 BCC LL55
 INC XX15+4

.LL55
 LDA XX12+5
 BMI LL56
 LDA XX12+4
 CLC
 ADC XX1+6
 STA T

 LDA XX1+7
 ADC #0
 STA U
 JMP LL57

.LL61
 LDX Q
 BEQ LL84
 LDX #0

.LL63
 LSR A
 INX
 CMP Q
 BCS LL63

 STX S
 JSR LL28
 LDX S
 LDA R

.LL64
 ASL A
 ROL U
 BMI LL84
 DEX
 BNE LL64
 STA R
 RTS

.LL84
 LDA #50
 STA R
 STA U
 RTS

.LL62
 LDA #128
 SEC
 SBC R
 STA XX3,X
 INX
 LDA #0
 SBC U
 STA XX3,X
 JMP LL66

.LL56
 LDA XX1+6
 SEC
 SBC XX12+4
 STA T
 LDA XX1+7
 SBC #0
 STA U

 BCC LL140
 BNE LL57
 LDA T
 CMP #4
 BCS LL57

.LL140
 LDA #0
 STA U

 LDA #4
 STA T

.LL57
 LDA U
 ORA XX15+1
 ORA XX15+4
 BEQ LL60
 LSR XX15+1
 ROR XX15
 LSR XX15+4
 ROR XX15+3
 LSR U
 ROR T
 JMP LL57

.LL60
 LDA T
 STA Q
 LDA XX15
 CMP Q
 BCC LL69
 JSR LL61
 JMP LL65

.LL69
 JSR LL28

.LL65
 LDX CNT
 LDA XX15+2
 BMI LL62
 LDA R

 CLC
 ADC #128
 STA XX3,X
 INX
 LDA U
 ADC #0
 STA XX3,X

.LL66
 TXA
 PHA
 LDA #0
 STA U
 LDA T
 STA Q
 LDA XX15+3
 CMP Q
 BCC LL67

 JSR LL61
 JMP LL68

.LL70
 LDA #Y
 CLC
 ADC R
 STA XX3,X
 INX

 LDA #0
 ADC U
 STA XX3,X
 JMP LL50

.LL67
 JSR LL28

.LL68
 PLA
 TAX
 INX
 LDA XX15+5
 BMI LL70
 LDA #Y

 SEC
 SBC R
 STA XX3,X
 INX
 LDA #0
 SBC U
 STA XX3,X

.LL50
 CLC
 LDA CNT
 ADC #4
 STA CNT
 LDA XX17
 ADC #6
 TAY
 BCS LL72

\"��

 CMP XX20
 BCS LL72
 JMP LL48

.LL72
 LDA XX1+31
 AND #32
 BEQ EE31
 LDA XX1+31
 ORA #8
 STA XX1+31
 JMP DOEXP

.EE31
 LDA #8
 BIT XX1+31
 BEQ LL74
 JSR LL155
 LDA #8

.LL74
 ORA XX1+31
 STA XX1+31

 LDY #9
 LDA (XX0),Y
 STA XX20

 LDY #0
 STY U
 STY XX17
 INC U
 BIT XX1+31
 BVC LL170
 LDA XX1+31
 AND #&BF
 STA XX1+31

 LDY #6
 LDA (XX0),Y
 TAY
 LDX XX3,Y
 STX XX15
 INX
 BEQ LL170
 LDX XX3+1,Y
 STX XX15+1
 INX
 BEQ LL170
 LDX XX3+2,Y
 STX XX15+2

 LDX XX3+3,Y
 STX XX15+3
 LDA #0
 STA XX15+4
 STA XX15+5
 STA XX12+1
 LDA XX1+6
 STA XX12

 LDA XX1+2
 BPL P%+4
 DEC XX15+4
 JSR LL145
 BCS LL170
 LDY U

 LDA XX15
 STA (XX19),Y
 INY
 LDA XX15+1
 STA (XX19),Y
 INY
 LDA XX15+2
 STA (XX19),Y
 INY
 LDA XX15+3
 STA (XX19),Y
 INY
 STY U

.LL170
\ Calculate new lines
 LDY #3
 CLC
 LDA (XX0),Y
 ADC XX0

 STA V
 LDY #16
 LDA (XX0),Y
 ADC XX0+1
 STA V+1
 LDY #5
 LDA (XX0),Y
 STA T1
 LDY XX17

.LL75
 LDA (V),Y
 CMP XX4
 BCC LL78

 INY
 LDA (V),Y
 INY
 STA P
 AND #15
 TAX
 LDA XX2,X
 BNE LL79
 LDA P
 LSR A
 LSR A
 LSR A
 LSR A
 TAX

\"��

 LDA XX2,X
 BEQ LL78

.LL79
 LDA (V),Y
 TAX
 INY
 LDA (V),Y
 STA Q
 LDA XX3+1,X
 STA XX15+1
 LDA XX3,X
 STA XX15

 LDA XX3+2,X
 STA XX15+2
 LDA XX3+3,X
 STA XX15+3
 LDX Q
 LDA XX3,X

 STA XX15+4
 LDA XX3+3,X
 STA XX12+1
 LDA XX3+2,X
 STA XX12

 LDA XX3+1,X
 STA XX15+5
 JSR LL147
 BCS LL78

.LL80
 LDY U
 LDA XX15
 STA (XX19),Y
 INY
 LDA XX15+1

 STA (XX19),Y
 INY
 LDA XX15+2
 STA (XX19),Y
 INY
 LDA XX15+3

 STA (XX19),Y
 INY
 STY U
 CPY T1
 BCS LL81

.LL78
 INC XX17
 LDY XX17
 CPY XX20
 BCS LL81
 LDY #0
 LDA V
 ADC #4

\"��

 STA V
 BCC ll81
 INC V+1

.ll81
 JMP LL75

.LL81
 LDA U
 LDY #0
 STA (XX19),Y

.LL155
\ CLEAR LINEstr
 LDY #0
 LDA (XX19),Y
 STA XX20
 CMP #4
 BCC LL118-1
 INY

.LL27
 LDA (XX19),Y
 STA XX15
 INY
 LDA (XX19),Y
 STA XX15+1

 INY
 LDA (XX19),Y
 STA XX15+2
 INY
 LDA (XX19),Y
 STA XX15+3

 JSR LL30
 INY
 CPY XX20
 BCC LL27
\LL82

 RTS

.LL118
\move XX15,XX15+2 to screen-grad.XX12+2
 LDA XX15+1
 BPL LL119
 STA S
 JSR LL120  \ X1<0

 TXA
 CLC
 ADC XX15+2
 STA XX15+2
 TYA
 ADC XX15+3
 STA XX15+3

 LDA #0
 STA XX15
 STA XX15+1
 TAX

.LL119
 BEQ LL134
 STA S
 DEC S
 JSR LL120 \ X1>255

 TXA
 CLC
 ADC XX15+2
 STA XX15+2
 TYA
 ADC XX15+3
 STA XX15+3

 LDX #FF
 STX XX15
 INX
 STX XX15+1

.LL134
 LDA XX15+3
 BPL LL135
 STA S
 LDA XX15+2
 STA R   \ Y1<0

 JSR LL123
 TXA
 CLC
 ADC XX15
 STA XX15
 TYA
 ADC XX15+1
 STA XX15+1

 LDA #0
 STA XX15+2
 STA XX15+3

.LL135
\BNELL139
 LDA XX15+2
 SEC
 SBC #Y*2
 STA R     \ Y1>191

 LDA XX15+3
 SBC #0
 STA S
 BCC LL136

.LL139
 JSR LL123
 TXA
 CLC
 ADC XX15

 STA XX15
 TYA
 ADC XX15+1
 STA XX15+1
 LDA #Y*2-1
 STA XX15+2
 LDA #0
 STA XX15+3

.LL136
 RTS

\ YX=SR*M/256

.LL120
 LDA XX15
 STA R

\.LL120
 JSR LL129
 PHA
 LDX T
 BNE LL121

.LL122
 LDA #0
 TAX
 TAY
 LSR S
 ROR R
 ASL Q
 BCC LL126

.LL125
 TXA
 CLC

 ADC R
 TAX
 TYA
 ADC S
 TAY

.LL126
 LSR S
 ROR R
 ASL Q
 BCS LL125

 BNE LL126
 PLA
 BPL LL133
 RTS

\ YX=SR*256/M (M=grad.)

.LL123
 JSR LL129
 PHA
 LDX T
 BNE LL122

.LL121
 LDA #255
 TAY
 ASL A
 TAX

.LL130
 ASL R
 ROL S
 LDA S
 BCS LL131

 CMP Q
 BCC LL132

.LL131
 SBC Q
 STA S
 LDA R
 SBC #0
 STA R
 SEC

.LL132
 TXA
 ROL A
 TAX
 TYA
 ROL A
 TAY
 BCS LL130
 PLA
 BMI LL128

.LL133
 TXA
 EOR #FF
\CLC
 ADC #1
 TAX
 TYA
 EOR #FF
 ADC #0
 TAY

.LL128
 RTS

.LL129
 LDX XX12+2
 STX Q
 LDA S
 BPL LL127
 LDA #0
 SEC
 SBC R
 STA R
 LDA S
 PHA
 EOR #255
 ADC #0
 STA S
 PLA

.LL127
 EOR XX12+3
 RTS

.LL145
\CLIP
 LDA #0
 STA SWAP

 LDA XX15+5

.LL147
 LDX #Y*2-1
 ORA XX12+1
 BNE LL107
 CPX XX12

 BCC LL107
 LDX #0

.LL107
 STX XX13
 LDA XX15+1
 ORA XX15+3
 BNE LL83

 LDA #Y*2-1
 CMP XX15+2
 BCC LL83

 LDA XX13
 BNE LL108

.LL146
 LDA XX15+2
 STA XX15+1
 LDA XX15+4
 STA XX15+2
 LDA XX12
 STA XX15+3
 CLC
 RTS

.LL109
 SEC
 RTS

.LL108
 LSR XX13

.LL83
 LDA XX13
 BPL LL115

 LDA XX15+1
 AND XX15+5
 BMI LL109
 LDA XX15+3
 AND XX12+1
 BMI LL109

 LDX XX15+1
 DEX
 TXA
 LDX XX15+5
 DEX
 STX XX12+2
 ORA XX12+2

 BPL LL109
 LDA XX15+2
 CMP #Y*2
 LDA XX15+3
 SBC #0
 STA XX12+2

 LDA XX12
 CMP #Y*2
 LDA XX12+1
 SBC #0
 ORA XX12+2
 BPL LL109

.LL115
 TYA
 PHA
 LDA XX15+4
 SEC
 SBC XX15
 STA XX12+2
 LDA XX15+5

 SBC XX15+1
 STA XX12+3
 LDA XX12
 SEC
 SBC XX15+2
 STA XX12+4

 LDA XX12+1
 SBC XX15+3
 STA XX12+5
 EOR XX12+3
 STA S

 LDA XX12+5
 BPL LL110
 LDA #0
 SEC
 SBC XX12+4
 STA XX12+4
 LDA #0
 SBC XX12+5
 STA XX12+5

.LL110
 LDA XX12+3
 BPL LL111
 SEC
 LDA #0
 SBC XX12+2
 STA XX12+2
 LDA #0
 SBC XX12+3

\GETgrad

.LL111
 TAX
 BNE LL112
 LDX XX12+5
 BEQ LL113

.LL112
 LSR A
 ROR XX12+2

 LSR XX12+5
 ROR XX12+4
 JMP LL111

.LL113
 STX T
 LDA XX12+2

 CMP XX12+4
 BCC LL114
 STA Q
 LDA XX12+4
 JSR LL28

 \ Use Y/X grad.

 JMP LL116

.LL114
 LDA XX12+4
 STA Q
 LDA XX12+2
 JSR LL28

 \ Use X/Y grad.

 DEC T

.LL116
 LDA R
 STA XX12+2
 LDA S
 STA XX12+3

 LDA XX13
 BEQ LL138
 BPL LLX117

.LL138
 JSR LL118
 LDA XX13
 BPL LL124

.LL117
 LDA XX15+1
 ORA XX15+3
 BNE LL137
 LDA XX15+2
 CMP #Y*2
 BCS LL137

.LLX117
 LDX XX15
 LDA XX15+4
 STA XX15
 STX XX15+4
 LDA XX15+5

 LDX XX15+1
 STX XX15+5
 STA XX15+1
 LDX XX15+2
 LDA XX12
 STA XX15+2

 STX XX12
 LDA XX12+1
 LDX XX15+3
 STX XX12+1
 STA XX15+3
 JSR LL118

 DEC SWAP

.LL124
 PLA
 TAY
 JMP LL146

.LL137
 PLA
 TAY
 SEC
 RTS

F%=P%

;OSCLI("SAVE ELTG "+STR$~W%+" "+STR$~O%+" "+STR$~L%+" "+STR$~H%)

PRINT "ELITE<G>"
PRINT "ASSEMBLE AT W%=", ~C_G%
PRINT "P%=",~P%
PRINT "CODE SIZE=", ~(P%-C_G%)
PRINT "EXECUTE AT L%=", ~L%
PRINT "RELOAD AT H%=", ~H_G%

PRINT "S.ELTG ",~C_G%," ",~P%," ",~L%," ",~H_G%
SAVE "output/ELTG.bin", C_G%, P%, L%

PRINT ~C_A%, ~F%, ~S%, ~(D%-F%)
PRINT "G d."
