;- perhaps start wiping to black already at around 10 seconds in?
;- you wipe to black nicely, can you also wipe FROM black to the logo part?
;- the dots part looks great and is also paced perfectly (also about 10 seconds)
;- the donut stays in view juuust a bit too long, can you time to be about those same 10 seconds? „slightsmile“-Emoticon
;- the bob part next uses a different palette from the previous two parts I guess? Because the Desire logo suddenly changes.
;- make the bob part also last 10 seconds „slightsmile“-Emoticon
;- perhaps flashfade (white -> picture) quickly to title pic
;- timing (about 5 seconds) feels good for the pic
;- same flash fade to vector part if possible?
;- if you can't fade in/out, perhaps move the last two parts offscreen like you do the donut? If that's possible



*		opt h-f+	;Disable ATARI headers, enable fill mode (no memory gaps)
* 80 08 02 00 18 0A 42 53 39 33
* 10 bytes header $80,$08,start hi, start lo, end hi, end lo, magic
SND_TIMER       set 7
NewDirOffset set 410
BlockSize set 1024
LoadFileUser SET 1
NEWHEAD	set 1
EXPLODER	set	1

***************
* simple body of a Lynx-program
*
* New Lynx boot + atari intro
*	NO BLL REQUIRED!!!
****************
		include <hardware.asm>
		include <soundbs.mac>
		include <irq.mac>
		include <help.mac>
		include <if_while.mac>
		include <mikey.mac>
		include <suzy.mac>
		include <debug.mac>
		include <file.mac>
****************
* variables



********************ZEROPAGE***********************

					include <mikey.var>
 BEGIN_ZP
timer		ds 2		;counter gegen zu schnelle Bew.
angle		ds 1 
backup		ds 1
dx2	ds 1 ;dx div 2
dy2	ds 1  ;dy div 2

xreg_save ds 1 ;equ $09
yreg_save ds 1;equ $0a

tmp	ds 2 ;equ $0b ;$0c
tmp2	ds 2 ;equ $0d ;$0e
pointer ds 2 ;	equ $0f ;$10

sx1	ds 1 ;equ $11
sx2	ds 1 ;equ $12
cloc	ds 1 ;equ $13 ;$14

sy1	ds 1 ;equ $16
sy2	ds 1 ;equ $17
screen  ds 1 ;equ $18
angx	ds 2;equ $2d ;$2e
angy	ds 2 ;equ $1c ;$1e
angz	ds 2 ;equ $1a ;$1b
x1	ds 2 ;equ $1f
x2	ds 2 ;equ $20
x3	ds 2 ;equ $21
y1	ds 2 ;equ $22
y2	ds 2 ;equ $23
y3	ds 2 ;equ $24
dx	ds 1 ;equ $25
dy	ds 1 ;equ $26
worldx	ds 2 ;equ $27 ;$28
worldy	ds 2 ;equ $29 ;$2a
worldz	ds 2 ;equ $2b ;$2c
fade_flag ds 1 ;equ $2f
	;*= ty_h+8
T1 	ds 2 ;1,0 ;*+2
T2  	ds 2;1,0 ; *+2
product ds 4 ;1,0,0,0 ;4 ; *+4
xn	ds 2 ; 1,0 ;2 ;*+2
yn	ds 2 ;1,0 ;2 ;*+2
zn	ds 2 ;1,0 ;2 ;*+2
xno	ds 2
yno	ds 2
zno 	ds 2
;matrix temp 
mtmp1	ds 1 ;*+1
mtmp2	ds 1 ;*+1
mtmp3	ds 1 ;*+1
mtmp4	ds 1 ;*+1
mtmp5	ds 1 ;*+1
mtmp6	ds 1 ;*+1
mtmp7	ds 1 ;*+1
mtmp8	ds 1 ;*+1
mtmp9	ds 1 ;*+1
mtmp10	ds 1 ;*+1
mtmp11	ds 1 ;*+1
mtmp12	ds 1 ;*+1
mtmp13	ds 1 ;*+1
mtmp14	ds 1 ;*+1
mtmp15	ds 1 ;*+1
mtmp16	ds 1 ;*+1
mtmp17	ds 1 ;*+1
mtmp18	ds 1 ;*+1
mtmp19	ds 1 ;*+1
mtmp20	ds 1 ;*+1
mat	ds 18 ;1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; 18 ;*+1 ;18 bytes!

sortorder ds 92

demo_state ds 1 ;equ mat+18 ;demo state
demo_state_counter ds 2 ; 0 ;equ demo_state+1

stars_counter   equ mtmp1
a1		equ mtmp3
a2		equ mtmp4
a3		equ mtmp5
a4		equ mtmp6
a5		equ mtmp7
a1bak		equ mtmp8
a2bak		equ mtmp9
a3bak		equ mtmp10
a4bak		equ mtmp11
a5bak		equ mtmp12
i		equ mtmp13
j		equ mtmp14

CurrBlock	equ mtmp11
 IF BlockSize>255 
BlockByte	equ mtmp13
 ELSE
BlockByte	equ mtmp13
 ENDIF

DestPtr		equ angle ;dw 0

irq_vektoren    ds 16

 END_ZP
		include <soundbs.var>
		include <irq.var>
		include <suzy.var>
;		include <file.var>

;ScreenBase	EQU $FC
;ScreenBase2	EQU $FE
********************ZEROPAGE***********************






*********************MEMORY**************************
;lynxed 	equ stars_SCB_buffer
;	ibytes "bokanoid.spr"
;	ibytes "lynx-black.spr"

colbuff		equ $a038
scrn1		EQU $C038
scrn2		EQU $e018

;irq_vectors     ds 16

;stars_SCB_buffer equ $c100



*********************MEMORY**************************


		MACRO SHOW
		LDA	#<\0
		LDY	#>\0
		jsr DrawSpr
		ENDM

		

	run $0400       ; code directly after variables
	jmp Start


add_rh 	dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
add_gh	dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
add_bh	dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
add_rl 	dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
add_gl	dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
add_bl	dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

src_rh		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
src_gh		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
src_bh		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
src_rl		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
src_gl		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
src_bl		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
			
dest_rh		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dest_gh		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dest_bh		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dest_rl		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dest_gl		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
dest_bl		dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0



entry	ds DirEntry.LEN	; space for current entry
	
char_tabl: ds 128	
char_tabh: ds 128
;music
;	include "nordlynx2.asm"
	include "lynxed_msx.asm"


;                align 4
;scrn1         ds 8160
;scrn2         ds 8160



	
text
;
		dc.b "CREDITS   "
		dc.b "          "		
		dc.b "CODE BY   "	
		dc.b "HEAVEN    "
		dc.b "          "		
		dc.b "GRAFICS BY"		
		dc.b "BOKANOID  "		
		dc.b "OZAN ALIEN"		
		dc.b "          "		
		dc.b "MSX TRIACE"		
;
		dc.b "GREETINGS "
		dc.b "AXIS VETO "		
		dc.b "OSWALD    "	
		dc.b "POPMILO   "
		dc.b "SAGE TMR  "		
		dc.b "JAC MIKER "		
		dc.b "REST OF   "		
		dc.b "DESIRE    "		
		dc.b "ESP NILS  "		
		dc.b "THANK YOU "		


*** music
                include <soundbs.inc>
                include <irq.inc>
		include <file.inc>



Start:		sei				;StartUp
		cld
		lda #$80
		trb $fd01
		trb $fd05
		trb $fd09
		trb $fd0d
		trb $fd11
		trb $fd15
		trb $fd19
		trb $fd1d			; disable all timers
		lda #%11101
		sta $fd8c			; disable RX/TX-irq, set to 8E1
		lda $fd81
		sta $fd80			; clear all pending interrupts
		ldx #$ff
		txs				; init stack-pointer
		stz $FFF9

		ldx	#$00			;Clear Zeropage
.clearZP	stz	$00,x
		stz	$100,x
		dex
		bne	.clearZP		

		ldx	#14			;Init Mikey
.\mloop         ldy	.\MikeyInitReg,x
                lda	.\MikeyInitData,x
                sta	$fd00,y
                dex
                bpl	.\mloop
                bra	.\mcont
.\MikeyInitReg  dc.b $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
.\MikeyInitData dc.b $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1A,$0b,$04,$0D,$29
.\mcont         

		ldx	#6			;Init Suzy
.\sloop		ldy	.\SuzyInitReg,x
		lda	.\SuzyInitData,x
		sta	$fc00,y
		dex
		bpl	.\sloop
		bra	.\scont
.\SuzyInitReg   dc.b $28,$2a,$04,$06,$92,$83,$90
.\SuzyInitData  dc.b $7f,$7f,64,64,%00100100,$f3,$01
.\scont
		lda	#$9e			;Framerate=60Hz
		sta	$fd00
		lda	#$29
		sta	$fd93



;blitt logo into colbuff
;                lda #<colbuff		;Screenbase Initialisation
;                sta ScreenBase
;                lda #>colbuff
;                sta ScreenBase+1
;		SHOW desire_logo_SCB

		
                lda #<scrn1			;Screenbase Initialisation
                sta ScreenBase
                ldx #>scrn1
                stx ScreenBase+1
                lda #<scrn2
                sta ScreenBase2
                ldx #>scrn2
                stx ScreenBase2+1
                sta $fd94
                stx $fd95
		lda #<scrn2 ;colbuff
		sta $fc0a
		lda #>scrn2 ;colbuff
		sta $fc0b


		;lda	$FC92
		;ora	#%00010000
		;sta	$FC92



 			
*** music
	INITIRQ irq_vektoren
	 LDA #>$FD00 
	 STA HandyMusic_RegisterRedirectHi ; Set up register redirection high byte
                 jsr SndInit
		 jsr SndPauseOn
             LDAY CHANNEL_0
             ldx #0
             jsr SndStartSound
            LDAY CHANNEL_1
            ldx #1
            jsr SndStartSound
            LDAY CHANNEL_2
            ldx #2
            jsr SndStartSound
            LDAY CHANNEL_3
            ldx #3
            jsr SndStartSound
	    jsr SndPauseOff


;                SETIRQ 0,HBL
               SETIRQ 2,VBL
		cli

;test load
;	lda #<desire_zoom
;	sta DestPtr
;	lda #>desire_zoom
;	sta DestPtr+1
;	lda #2
;	jsr LoadFile


;
.wait09	
;	jsr SwitchBuf
;	SHOW desire_zoom_SCB
;
;	lda timer+1
;	cmp #1
;	bne .wait09

nordlicht_loop
;demo script
	stz timer
	stz timer+1

	ldy #$1f			;Palette
.initpall0		;ldx redir,y
	lda nordpal,y
	sta $FDA0,y
	dey
	bpl .initpall0

.nord1
	jsr SwitchBuf
	SHOW desire_zoom_SCB
	lda dsrz_sizex
	sec
	sbc #8
	sta dsrz_sizex
	lda dsrz_sizex+1
	sbc #0
	sta dsrz_sizex+1
	lda dsrz_sizey
	sec
	sbc #8
	sta dsrz_sizey
	lda dsrz_sizey+1
	sbc #0
	sta dsrz_sizey+1
	lda dsrz_sizex+1
	cmp #1
	bne .nord1
	lda dsrz_sizex
	cmp #8
	bne .nord1
;wait some frames
		
	stz dsr_sizex
	stz dsr_sizey
	lda #1
	sta dsr_sizex+1
	sta dsr_sizey+1

.wait0	
	jsr SwitchBuf
	SHOW desire_zoom_SCB

	lda timer+1
	cmp #2
	bne .wait0

	ldx #15
.fadep0
	lda nordpal,x
	sta src_gh,x
	lda nordpal+16,x
	tay
	and #$f0
	lsr
	lsr
	lsr
	lsr
	sta src_bh,x
	tya
	and #$0f
	sta src_rh,x
	lda #5 ;0
	sta dest_rh,x ;$fda0
	lda #3 ;$03
	sta dest_gh,x
	lda #3 ;$05
	sta dest_bh,x
	dex
	bpl .fadep0
		
	jsr fade_to_palette
	
	jsr SwitchBuf
	SHOW clear_SCB
	inc timer+1
	stz transitioncounter
	lda #1
	sta transitionmode


;	jmp do_lynxed


	jsr do_dots
;	jsr do_transition
	jsr do_obj2
	lda #128
	sta angx
	lda #128
	sta angy
	lda #128
	sta angz
	stz angx+1
	lda #16
	sta angy+1
	lda #1
	sta angz+1
	lda #3
	sta stepzh+1
	dec 
	sta stepxh+1
	dec
	sta stepyh+1
 	ldy	#$1F			;Palette
.pall	;ldx redir,y
	lda	pal,y
	sta	$FDA0,y
	dey
	bpl	.pall

		stz $fda0
		lda #$35
		sta $fdb0
		lda #$03
		sta $fda2
		lda #$58
		sta $fdb2
		lda #$00 
		sta $fda1
		lda #$00 
		sta $fdb1
		lda #$07
		sta $fda3
		lda #$46
		sta $fdb3
		
	stz transitioncounter
	lda #1
	sta transitionmode
	lda #$d0
	sta zoom_object+1

	jsr do_3d
	
;	jsr do_transition
	stz transitioncounter
	lda #1
	sta transitionmode
	jsr do_balls
skip_fx
;	jsr do_lynxed_logo
	stz transitionmode
	lda #1
	sta transitionmode


	LOADFILE #2,lynxed	
	jsr do_lynxed
;	
	jsr SwitchBuf
	SHOW desire_logo_SCB
	jsr SwitchBuf
	SHOW desire_logo_SCB

	ldy #$1F			;Palette
.pal11		
	lda #0 ;dest_rh,y
	sta src_rh,y
	lda #3 ;dest_gh,y
	sta src_gh,y
;	lda dest_bh,y
	sta src_bh,y	

	lda pal,y
	sta dest_gh,y
	lda pal+16,y
	tax
	and #$f0
	lsr
	lsr
	lsr
	lsr
	sta dest_bh,y
	txa
	and #$0f
	sta dest_rh,y
	dey
	bpl	.pal11
	lda #3
	sta dest_gh
	sta dest_bh
	stz dest_rh

	jsr fade_to_palette
	jsr do_obj1
		
	lda #$20
	sta cull_mode
	lda #<culltest_16bit
	sta cull_mode+1
	lda #>culltest_16bit
	sta cull_mode+2				
	lda #$ea ;nop
	sta linemode
	sta linemode+1
	sta linemode+2
	lda #19
	sta duration_3d+1
	inc
	inc
	sta duration_3d2+1
	lda #$d0
	sta zoom_object+1
	lda #$ff
	sta stepzh+1
	lda #0
	sta stepxh+1
	lda #1
	sta stepyh+1
	stz move_3d+1
        lda #<colbuff		;Screenbase Initialisation
        sta ScreenBase
        lda #>colbuff
        sta ScreenBase+1
	lda #1
	sta transitionmode
	lda #3
	sta zoom_in_step+1
	sta zoom_out_step+1
	lda #$b8
	sta transtop+1

	jsr SwitchBuf
	jsr do_3d

	lda #1
	sta transitionmode
	lda #23
	sta duration_3d+1
	inc
	inc
	sta duration_3d2+1
	lda #$d8
	sta zoom_object+1
	lda #$ff
	sta stepzh+1
	lda #0
	sta stepxh+1
	lda #1
	sta stepyh+1
	stz move_3d+1
	
;	lda #$ea
;	sta glenz_flag
;	sta glenz_flag+1
;	sta cull_mode
;	sta cull_mode+1
;	sta cull_mode+2
	lda tri_scb
	ora #6
	sta tri_scb
	lda tri_scb2
	ora #6
	sta tri_scb2
	jsr do_3d
	lda #$d0
	sta tri_scb2
	
	jsr SwitchBuf
	SHOW desire_logo_SCB	
	jsr SwitchBuf
	SHOW desire_logo_SCB	
	
	jsr do_obj2	
	lda #<ballsprite2
	sta ball_spr_adr
	sta ball_adr
	lda #>ballsprite2
	sta ball_spr_adr+1
	sta ball_adr+1
	lda #$88 ;18
	sta zoom_object+1
	lda #64
	sta stepyl+1
	lda #255
	sta stepxl+1
	lda #0
	sta stepzl+1
	lda #-2
	sta stepyh+1
	lda #1
	sta stepxh+1
	lda #-3
	sta stepzh+1
	jsr do_obj3
	lda #$ea
	sta cull_mode
	sta cull_mode+1
	sta cull_mode+2
	lda #$4c
	sta linemode
	lda #<draw_3d_ball
	sta linemode+1
	lda #>draw_3d_ball
	sta linemode+2
	stz next_ball_SCB
	stz next_ball_SCB+1	
	lda #28
	sta duration_3d+1
	inc
	inc
	sta duration_3d2+1
	lda #$4c
	sta draw_object
	lda #<draw_3d_ball
	sta draw_object+1
	lda #>draw_3d_ball
	sta draw_object+2

	ldy #$0f
.pall1111 
	lda dest_rh,y
	sta src_rh,y
	lda dest_gh,y
	sta src_gh,y
	lda dest_bh,y
	sta src_bh,y
	lda palball,y
	sta dest_gh,y
	lda palball+16,y
	tax
	lsr
	lsr
	lsr
	lsr
	sta dest_bh,y
	txa
	and #$0f
	sta dest_rh,y
	dey
	bpl .pall1111
	lda #$03
	sta dest_gh ;$fda0
	sta dest_bh
	stz dest_rh
	jsr fade_to_palette

	lda #2
	sta transitionmode
	stz loop_counter+3 ;move from left to middle	

	jsr do_3d

	jsr chars_init
	jsr do_text_page		
	lda #1 ;1 for chars
	sta textmode
	sta transitionmode
	lda #32
	sta duration_3d+1
	inc
	inc
	sta duration_3d2+1
	lda #<ballsprite3
	sta ball_spr_adr
	sta ball_adr
	lda #>ballsprite3
	sta ball_spr_adr+1
	sta ball_adr+1
	lda #$58 ;18
	sta zoom_object+1

	jsr SwitchBuf
	SHOW desire_logo_SCB	
	jsr SwitchBuf
	SHOW desire_logo_SCB	

	ldy #$0f
.pall1112 
	lda dest_rh,y
	sta src_rh,y
	lda dest_gh,y
	sta src_gh,y
	lda dest_bh,y
	sta src_bh,y
	lda palface,y
	sta dest_gh,y
	lda palface+16,y
	tax
	lsr
	lsr
	lsr
	lsr
	sta dest_bh,y
	txa
	and #$0f
	sta dest_rh,y
	dey
	bpl .pall1112
	lda #$03
	sta dest_gh ;$fda0
	sta dest_bh
	stz dest_rh
	jsr fade_to_palette


	jsr do_obj4
endloop
	jsr do_3d
	lda #1 ;1 for chars
	sta transitionmode
	jsr chars_init
	jsr do_text_page		

	lda #35
	sta duration_3d+1
	inc
	inc
	inc
	sta duration_3d2+1
endloop2
	jsr do_3d

	ldx #15
endloop3 lda dest_rh,x
	sta src_rh,x
	lda dest_gh,x
	sta src_gh,x
	lda dest_bh,x
	sta src_bh,x
	lda #0
	sta dest_rh,x
	sta dest_gh,x
	sta dest_bh,x
	dex
	bpl endloop3	
	jsr fade_to_palette

	LOADFILE #3,lynxed	
	jsr SwitchBuf
	SHOW lynxed_SCB
	jsr SwitchBuf
	
	ldx #15
.end000
	lda svpal,x
	sta dest_gh,x
	lda svpal+16,x
	tay
	and #$f0
	lsr
	lsr
	lsr
	lsr
	sta dest_bh,x
	tya
	and #$0f
	sta dest_rh,x
	lda #0 ;0
	sta src_rh,x ;$fda0
	sta src_gh,x
	sta src_bh,x
	dex
	bpl .end000
	jsr fade_to_palette
	jmp *


textmode dc.b 0	
do_3d
;set camera
	lda #0
	sta worldx
	sta worldx+1
	sta worldy
	lda #0
	sta worldy+1
	lda #0
	sta worldz
	sta worldz+1
		
;	lda #$60 ;rts
;	sta glenz_flag		
.dp		
.frame1	
		;SHOW	dsign_SCB
		jsr	SwitchBuf
		SHOW	desire_logo_SCB ;clear_SCB
		lda tri_scb2
		cmp #$d6
		bne .frame111
		jsr Clearcolbuff
.frame111
;when there is time colbuf must be cleared		lda 
		
		jsr main_demo_loop
		lda textmode
		beq .frame11
		SHOW stars_SCB_buffer ;text char

.frame11	lda timer+1
duration_3d	cmp #8
		bcs .dp2
		lda transitionmode
		cmp #3
		beq .dp
		dec zoom_object+1
		dec zoom_object+1
		lda loop_counter+3
		cmp #$30
		beq .dp3
		lda loop_counter+3
		clc
		adc #4
		sta loop_counter+3
.dp3		
		jmp .dp
.dp2
		lda zoom_object+1
		cmp #$d0
		bcs duration_3d0		
		lda zoom_object+1
		clc
		adc #2
		sta zoom_object+1
		lda loop_counter+3
		cmp #$d8
		beq .dp4
		lda loop_counter+3
		sec
move_3d		sbc #4
		sta loop_counter+3
.dp4		
duration_3d0	lda timer+1
duration_3d2	cmp #9
		bcc .dp
duration_3d3	
;		jsr do_transition_1b
		lda #$30
		sta loop_counter+3
		rts

;lda endpoints+0,y ;xcoo endpoint
; sec
; sbc #28*4  ;middle x
; cmp #$80
; ror
; ror bxaddl,x
; cmp #$80
; ror
; ror bxaddl,x
; cmp #$80
; ror
; ror bxaddl,x  ;diff / 32
; cmp #$80
; ror
; ror bxaddl,x
; cmp #$80
; ror
; ror bxaddl,x
; sta bxaddh,x
calc_fade_steps
	ldx #$0f
.fade00	
	stz add_rl,x
	stz add_bl,x
	stz add_gl,x
	stz add_rh,x
	stz add_bh,x
	stz add_gh,x
	stz src_rl,x
	stz src_gl,x
	stz src_bl,x
	stz dest_rl,x
	stz dest_gl,x
	stz dest_bl,x
	dex
	bpl .fade00
;calc steps
	nop
	nop
	nop
	ldx #$0f
calc_fade0 lda dest_gl,x
	sec
	sbc src_gl,x 
	sta add_gl,x
	lda dest_gh,x
	sbc src_gh,x
.c0	cmp #$80
	ror
	ror add_gl,x
	cmp #$80
	ror
	ror add_gl,x
	cmp #$80
	ror
	ror add_gl,x
	cmp #$80
	ror
	ror add_gl,x
	sta add_gh,x

	dex
	bpl calc_fade0
	
	ldx #$0f
calc_fade1 lda dest_bl,x
	sec
	sbc src_bl,x
	sta add_bl,x
	lda dest_bh,x
	sbc src_bh,x
	cmp #$80
	ror
	ror add_bl,x
	cmp #$80
	ror
	ror add_bl,x
	cmp #$80
	ror
	ror add_bl,x
	cmp #$80
	ror
	ror add_bl,x
	sta add_bh,x
	dex
	bpl calc_fade1
	
	ldx  #$0f
calc_fade2 lda dest_rl,x
	sec
	sbc src_rl,x
	sta add_rl,x
	lda dest_rh,x
	sbc src_rh,x
	cmp #$80
	ror
	ror add_rl,x
	cmp #$80
	ror
	ror add_rl,x
	cmp #$80
	ror
	ror add_rl,x
	cmp #$80
	ror
	ror add_rl,x
	sta add_rh,x
	dex
	bpl calc_fade2
	rts
	
fade_to_palette
	jsr calc_fade_steps
	
	ldx #16
.fadeloop	
	ldy #$0f
.fade4 	lda src_gh,y
	sta $FDA0,y
	lda src_bh,y
	asl
	asl
	asl
	asl
	ora src_rh,y
	sta $fdb0,y
	
	lda src_rl,y
	clc
	adc add_rl,y
	sta src_rl,y
	lda src_rh,y
	adc add_rh,y
	sta src_rh,y
	
	lda src_gl,y
	clc
	adc add_gl,y
	sta src_gl,y
	lda src_gh,y
	adc add_gh,y
	sta src_gh,y
	
	lda src_bl,y
	clc
	adc add_bl,y
	sta src_bl,y
	lda src_bh,y
	adc add_bh,y
	sta src_bh,y
	dey
	bpl .fade4

;	ldy #1
.fadein
	lda timer
	cmp timer
	beq .fadein
	dex
	bpl .fadeloop
	rts
;
;fade_palette_to_black
;	jsr calc_fade_steps
;	ldx #15
;.ff	lda $fda0,x
;	sta fade_g,x
;	lda $fdb0,x
;	pha
;	and #$0f
;	sta fade_r,x
;	pla
;	lsr
;	lsr
;	lsr
;	lsr
;	sta fade_b,x
;	dex
;	bpl .ff
;
;	ldx #15
;.fadeloop2	
;	ldy	#$0f
;.fade40	lda fade_g,y
;	sta $FDA0,y
;	lda fade_b,y
;	asl
;	asl
;	asl
;	asl
;	ora fade_r,y
;	sta $fdb0,y
;	lda fade_rl,y
;	sec
;	sbc add_rl,y
;	sta fade_rl,y
;	lda fade_r,y
;	sbc add_rh,y
;	sta fade_r,y
;	lda fade_gl,y
;	sec
;	sbc add_gl,y
;	sta fade_gl,y
;	lda fade_g,y
;	sbc add_gh,y
;	sta fade_g,y
;	lda fade_bl,y
;	sec
;	sbc add_bl,y
;	sta fade_bl,y
;	lda fade_b,y
;	sbc add_bh,y
;	sta fade_b,y
;	dey
;	bpl .fade40
;	
;;	ldy #1
;.fadeout
;	lda timer
;	cmp timer
;	beq .fadeout
;;	dey
;;	bne .fadeout
;;update fade	
;	dex
;	bne .fadeloop2
;	rts

do_lynxed
	lda fadetable
	sta bokpal+4
	lda fadetable+19
	sta bokpal+4+16
	jsr SwitchBuf	
	SHOW lynxed_SCB
	jsr SwitchBuf
	SHOW lynxed_SCB

	ldx #15
.fadep000
	lda bokpal,x
	sta dest_gh,x
	lda bokpal+16,x
	tay
	and #$f0
	lsr
	lsr
	lsr
	lsr
	sta dest_bh,x
	tya
	and #$0f
	sta dest_rh,x
	lda #0 ;0
	sta src_rh,x ;$fda0
	lda #0 ;$03
	sta src_gh,x
	lda #0 ;$05
	sta src_bh,x
	dex
	bpl .fadep000


	jsr fade_to_palette

wwww
	ldy #3
wwwwww	
	lda timer
	cmp timer
	beq wwwwww
      	dey
      	bne wwwwww

	ldx fadecounter
cycle1	lda fadetable,x
	sta $fda0+4
cycle2	lda fadetable+19,x
	sta $fdb0+4
	inc fadecounter
	lda fadecounter
	cmp #19
	bne wwwww
	stz fadecounter
wwwww
	lda timer+1
	cmp #16
	bcc wwww

	ldx #15
.fadep00
	lda bokpal,x
	sta src_gh,x
	lda bokpal+16,x
	tay
	and #$f0
	lsr
	lsr
	lsr
	lsr
	sta src_bh,x
	tya
	and #$0f
	sta src_rh,x
	lda #0 ;0
	sta dest_rh,x
	lda #3 ;$03
	sta dest_gh,x
	sta dest_bh,x
	dex
	bpl .fadep00

	jsr fade_to_palette
	
	rts
fadecounter dc.b 0
;g,b,r
fadetable:
	dc.b $06,$07,$08,$0A,$0B,$0B,$0A,$08,$07,$06,$06,$07,$08,$0B,$0F,$0B,$08,$07,$06
	dc.b $0e,$0e,$0e,$0f,$0f,$0f,$0f,$0e,$0e,$0e,$0e,$0e,$0e,$4f,$af,$4f,$0e,$0e,$0e
	
do_obj1		
		lda #<max_vertices
		sta max_vert+1
		lda #>max_vertices
		sta max_vert+2
		lda #<max_faces
		sta draw_object+1
		lda #>max_faces
		sta draw_object+2
		lda #<_px_l
		sta rot_objx1+1
		sta rot_objx3+1
		sta rot_objx5+1
		lda #>_px_l
		sta rot_objx1+2
		sta rot_objx3+2
		sta rot_objx5+2
		lda #<_px_h
		sta rot_objx2+1
		sta rot_objx4+1
		sta rot_objx6+1
		lda #>_px_h
		sta rot_objx2+2
		sta rot_objx4+2
		sta rot_objx6+2
		lda #<_py_l
		sta rot_objy1+1
		sta rot_objy3+1
		sta rot_objy5+1
		lda #>_py_l
		sta rot_objy1+2
		sta rot_objy3+2
		sta rot_objy5+2
		lda #<_py_h
		sta rot_objy2+1
		sta rot_objy4+1
		sta rot_objy6+1
		lda #>_py_h
		sta rot_objy2+2
		sta rot_objy4+2
		sta rot_objy6+2
		lda #<_pz_l
		sta rot_objz1+1
		sta rot_objz3+1
		sta rot_objz5+1
		lda #>_pz_l
		sta rot_objz1+2
		sta rot_objz3+2
		sta rot_objz5+2
		lda #<_pz_h
		sta rot_objz2+1
		sta rot_objz4+1
		sta rot_objz6+1
		lda #>_pz_h
		sta rot_objz2+2
		sta rot_objz4+2
		sta rot_objz6+2
		lda #<facetab
		sta face+1
		lda #>facetab
		sta face+2
		lda #<(facetab+1)
		sta face1+1
		lda #>(facetab+1)
		sta face1+2
		lda #<(facetab+2)
		sta face2+1
		lda #>(facetab+2)
		sta face2+2
		rts		
do_obj2		
		lda #<max_vertices2
		sta max_vert+1
		lda #>max_vertices2
		sta max_vert+2
		lda #<max_faces2
		sta draw_object+1
		lda #>max_faces2
		sta draw_object+2

		lda #<_px2_l
		sta rot_objx1+1
		sta rot_objx3+1
		sta rot_objx5+1
		lda #>_px2_l
		sta rot_objx1+2
		sta rot_objx3+2
		sta rot_objx5+2
		lda #<_px2_h
		sta rot_objx2+1
		sta rot_objx4+1
		sta rot_objx6+1
		lda #>_px2_h
		sta rot_objx2+2
		sta rot_objx4+2
		sta rot_objx6+2
		lda #<_py2_l
		sta rot_objy1+1
		sta rot_objy3+1
		sta rot_objy5+1
		lda #>_py2_l
		sta rot_objy1+2
		sta rot_objy3+2
		sta rot_objy5+2
		lda #<_py2_h
		sta rot_objy2+1
		sta rot_objy4+1
		sta rot_objy6+1
		lda #>_py2_h
		sta rot_objy2+2
		sta rot_objy4+2
		sta rot_objy6+2
		lda #<_pz2_l
		sta rot_objz1+1
		sta rot_objz3+1
		sta rot_objz5+1
		lda #>_pz2_l
		sta rot_objz1+2
		sta rot_objz3+2
		sta rot_objz5+2
		lda #<_pz2_h
		sta rot_objz2+1
		sta rot_objz4+1
		sta rot_objz6+1
		lda #>_pz2_h
		sta rot_objz2+2
		sta rot_objz4+2
		sta rot_objz6+2
		lda #<facetab2
		sta face+1
		lda #>facetab2
		sta face+2
		lda #<(facetab2+1)
		sta face1+1
		lda #>(facetab2+1)
		sta face1+2
		lda #<(facetab2+2)
		sta face2+1
		lda #>(facetab2+2)
		sta face2+2
		rts		
do_obj3		
		lda #<max_vertices3
		sta max_vert+1
		lda #>max_vertices3
		sta max_vert+2
;		lda #<max_faces
;		sta draw_object+1
;		lda #>max_faces
;		sta draw_object+2
		lda #<_px3_l
		sta rot_objx1+1
		sta rot_objx3+1
		sta rot_objx5+1
		lda #>_px3_l
		sta rot_objx1+2
		sta rot_objx3+2
		sta rot_objx5+2
		lda #<_px3_h
		sta rot_objx2+1
		sta rot_objx4+1
		sta rot_objx6+1
		lda #>_px3_h
		sta rot_objx2+2
		sta rot_objx4+2
		sta rot_objx6+2
		lda #<_py3_l
		sta rot_objy1+1
		sta rot_objy3+1
		sta rot_objy5+1
		lda #>_py3_l
		sta rot_objy1+2
		sta rot_objy3+2
		sta rot_objy5+2
		lda #<_py3_h
		sta rot_objy2+1
		sta rot_objy4+1
		sta rot_objy6+1
		lda #>_py3_h
		sta rot_objy2+2
		sta rot_objy4+2
		sta rot_objy6+2
		lda #<_pz3_l
		sta rot_objz1+1
		sta rot_objz3+1
		sta rot_objz5+1
		lda #>_pz3_l
		sta rot_objz1+2
		sta rot_objz3+2
		sta rot_objz5+2
		lda #<_pz3_h
		sta rot_objz2+1
		sta rot_objz4+1
		sta rot_objz6+1
		lda #>_pz3_h
		sta rot_objz2+2
		sta rot_objz4+2
		sta rot_objz6+2
;		lda #<facetab
;		sta face+1
;		lda #>facetab
;		sta face+2
;		lda #<(facetab+1)
;		sta face1+1
;		lda #>(facetab+1)
;		sta face1+2
;		lda #<(facetab+2)
;		sta face2+1
;		lda #>(facetab+2)
;		sta face2+2
		rts		
do_obj4		
		lda #<max_vertices4
		sta max_vert+1
		sta vv+1
		sta do_sort_z+1
		lda #>max_vertices4
		sta max_vert+2
		sta vv+2
		sta do_sort_z+2
		
;		lda #<max_faces
;		sta draw_object+1
;		lda #>max_faces
;		sta draw_object+2
		lda #<_px4_l
		sta rot_objx1+1
		sta rot_objx3+1
		sta rot_objx5+1
		lda #>_px4_l
		sta rot_objx1+2
		sta rot_objx3+2
		sta rot_objx5+2
		lda #<_px4_h
		sta rot_objx2+1
		sta rot_objx4+1
		sta rot_objx6+1
		lda #>_px4_h
		sta rot_objx2+2
		sta rot_objx4+2
		sta rot_objx6+2
		lda #<_py4_l
		sta rot_objy1+1
		sta rot_objy3+1
		sta rot_objy5+1
		lda #>_py4_l
		sta rot_objy1+2
		sta rot_objy3+2
		sta rot_objy5+2
		lda #<_py4_h
		sta rot_objy2+1
		sta rot_objy4+1
		sta rot_objy6+1
		lda #>_py4_h
		sta rot_objy2+2
		sta rot_objy4+2
		sta rot_objy6+2
		lda #<_pz4_l
		sta rot_objz1+1
		sta rot_objz3+1
		sta rot_objz5+1
		lda #>_pz4_l
		sta rot_objz1+2
		sta rot_objz3+2
		sta rot_objz5+2
		lda #<_pz4_h
		sta rot_objz2+1
		sta rot_objz4+1
		sta rot_objz6+1
		lda #>_pz4_h
		sta rot_objz2+2
		sta rot_objz4+2
		sta rot_objz6+2
		rts		


SwitchBuf	
.vsync		lda $fd0a
            	bne .vsync
		sei
		ldx ScreenBase
		ldy ScreenBase+1
;		lda tri_scb2
;		cmp #$d6 ;EOR mode activated
;		bne sbskip
;		lda #<colbuff
;		sta ScreenBase
;		lda #>colbuff
;		sta ScreenBase+1
;		SHOW desire_logo_SCB
sbskip
		lda ScreenBase2
		sta ScreenBase
		lda ScreenBase2+1
		sta ScreenBase+1
		stx ScreenBase2
		sty ScreenBase2+1
		stx $fd94
		sty $fd95
		cli
		rts

DrawSpr		sta drawspr_exit0+1 ;pha
		stx drawspr_exit1+1 ;phx
		sty drawspr_exit2+1 ;phy
		sta $fc10
                sty $fc11
                ldx ScreenBase
		ldy ScreenBase+1
		stx $FC08
		sty $FC09
                lda #1
                STA $FC91
                STZ $FD90
.WAIT           STZ $FD91
                bit $fc92
                bne .WAIT
                STZ $FD90
drawspr_exit0 	lda #0
drawspr_exit1	ldx #0
drawspr_exit2	ldy #0
                rts

Clearcolbuff	sta clearspr_exit0+1 ;pha
		stx clearspr_exit1+1 ;phx
		sty clearspr_exit2+1 ;phy
		lda #<clear_SCB
		ldy #>clear_SCB
		sta $fc10
                sty $fc11
                ldx #<colbuff
		ldy #>colbuff
		stx $FC08
		sty $FC09
                lda #1
                STA $FC91
                STZ $FD90
.cWAIT           STZ $FD91
                bit $fc92
                bne .cWAIT
                STZ $FD90
clearspr_exit0 	lda #0
clearspr_exit1	ldx #0
clearspr_exit2	ldy #0
                rts


do_sort_z
;init table
		ldx max_vertices3
sortinit	txa
		sta sortorder,x
		dex
		bpl sortinit

;		ldx #0 ;max_vertices3
;sortinit	txa
;		sta sortorder,x
;		inx
;		cpx max_vertices3
;		bcc sortinit
		lda max_vertices3
		inc
		sta sortcmp+1
		inx
sortloop:       ldy sortorder+1,x
                lda verticesz,y
                ldy sortorder,x
                cmp verticesz,y
                bcc sortskip
                stx sortreload+1
sortswap:       lda sortorder+1,x
                sta sortorder,x
                sty sortorder+1,x
                cpx #$00
                beq sortreload
                dex
                ldy sortorder+1,x
                lda verticesz,y
                ldy sortorder,x
                cmp verticesz,y
                bcs sortswap
sortreload:     ldx #$00
sortskip:       inx
sortcmp:        cpx #0 ;max_vertices3
                bne sortloop
		rts



dotcolortab	dc.b 15,15,15,14,14,14,13,13,13,12,12,12
		dc.b 11,11,11,10,10,10,9,9,9,8,8,8,7,7,7,6,6,6 
dotsyoffset	dc.b 0
do_dots
		
		ldy #$00			;Palette
;		ldx #0
.pall0		;ldx redir,y
;		and #$0f
		lda dest_rh,y
		sta src_rh,y
		lda dest_bh,y
		sta src_bh,y
		lda dest_gh,y
		sta src_gh,y
		tya
		sta dest_rh,y
		sta dest_gh,y
		sta dest_bh,y
;		sta $FDA0,y
;		txa
;		sta $fdb0,y
;		clc
;		adc #$11
;		ora #$70
;		tax
		iny
		cpy #16
		bne .pall0
;bg     :  $00, $35
;logo1:  $03, $58
;logo2:  $07, $46		
;
;		stz $fda0
;		lda #$35
;		sta $fdb0
;		lda #$03
;		sta $fda2
;		lda #$58
;		sta $fdb2
;		lda #$00 
;		sta $fda1
;		lda #$00 
;		sta $fdb1
;		lda #$07
;		sta $fda3
;		lda #$46
;		sta $fdb3
		lda #0
		sta dest_gh
		lda #$03
		sta dest_bh
		lda #$05
		sta dest_rh
		stz dest_gh+1
		stz dest_bh+1
		stz dest_rh+1
		lda #3
		sta dest_gh+2
		lda #5
		sta dest_bh+2
		lda #8
		sta dest_rh+2
		lda #7
		sta dest_gh+3
		lda #4
		sta dest_bh+3
		lda #6
		sta dest_rh+3

		SHOW desire_logo_SCB
		jsr SwitchBuf
		SHOW desire_logo_SCB
		jsr SwitchBuf
		
		jsr fade_to_palette
		

		ldy #0
.dots3		ldx #14
.dots0		lda stars_SCB,x
.dots2		sta stars_SCB_buffer,x
		dex
		bpl .dots0
		lda .dots2+1
		clc
		adc #15
		sta .dots2+1
		bcc .dots1
		inc .dots2+2
.dots1		lda next_stars_SCB
		clc
		adc #15
		sta next_stars_SCB
		bcc .dots4
		inc next_stars_SCB+1	
.dots4		dey
		bne .dots3
dots2::
		ldy #0
.dots3		ldx #14
.dots0		lda stars_SCB,x
.dots2		sta stars_SCB_buffer+256*15,x
		dex
		bpl .dots0
		lda .dots2+1
		clc
		adc #15
		sta .dots2+1
		bcc .dots1
		inc .dots2+2
.dots1		lda next_stars_SCB
		clc
		adc #15
		sta next_stars_SCB
		bcc .dots4
		inc next_stars_SCB+1	
.dots4		dey
		bne .dots3
dots30::
		ldy #217
.dots3		ldx #15
.dots0		lda stars_SCB,x
.dots2		sta stars_SCB_buffer+512*15,x
		dex
		bpl .dots0
		lda .dots2+1
		clc
		adc #15
		sta .dots2+1
		bcc .dots1
		inc .dots2+2
.dots1		lda next_stars_SCB
		clc
		adc #15
		sta next_stars_SCB
		bcc .dots4
		inc next_stars_SCB+1	
.dots4		dey
		bne .dots3
		stz next_stars_SCB+728*15
		stz next_stars_SCB+728*15+1				

;set dots colors
		ldy #27
dotscolor	ldx #27
dotscolor1	lda dotcolortab,y
dotscolorad	sta stars_SCB+11
		lda dotscolorad+1
		clc
		adc #15
		sta dotscolorad+1
		bcc dotscolor0
		inc dotscolorad+2
dotscolor0
		dex
		bne dotscolor1
		dey
		bne dotscolor

		
dotsloop:
;calculate xbuff,ybuff

		lda a1bak
		sta a1
		lda a2bak
		sta a2
		lda a3bak
		sta a3
		ldx #159
.dotloop0	
		ldy a1
		lda sintab2,y
		ldy a2
		clc
		adc sintab2+256,y
		ldy a3
		adc sintab2+512,y
		sta xbuff-1,x
		inc a1
		lda a2
		clc
		adc #2
		sta a2
		lda a3
		clc
		adc #4
		sta a3
		dex
		bne .dotloop0
		inc a1bak
		lda a2bak
		clc
		adc #3
		sta a2bak
		lda a3bak
		clc
		adc #2
		sta a3bak
;ybuff
		lda a4bak
		sta a4
		lda a5bak
		sta a5
		ldx #100
.dotsloop1
		ldy a4
		lda sintab2,y		
		ldy a5
		clc
		adc sintab2+256,y
		sta ybuff,x
		inc a4
		lda a5
		clc
		adc #3
		sta a5
		dex
		bpl .dotsloop1
		inc a4bak
		dec a5bak
		dec a5bak
		
main_dots		
		lda #<stars_x
		sta stars_ad+1
		lda #>stars_x
		sta stars_ad+2
		lda #<stars_y
		sta stars_ad2+1
		lda #>stars_y
		sta stars_ad2+2
		lda #27
		sta j		
main_dots_loop
		lda #27
		sta i
main_dots_loop2
		lda i
		asl
;		asl
		clc
		adc j		
		adc dotsyoffset
		bcs dots_skip
stars_ad	sta stars_x
dots_skip	ldx i
		ldy j
		lda xbuff,x
		clc
		adc ybuff,y
		clc
		adc #51+64
;		sec
;		sbc dotsyoffset
stars_ad2	sta stars_y		
		lda stars_ad+1
		clc
		adc #15
		sta stars_ad+1
		bcc main_dots_loop3
		inc stars_ad+2
main_dots_loop3 lda stars_ad2+1
		clc
		adc #15
		sta stars_ad2+1
		bcc main_dots_loop4
		inc stars_ad2+2
main_dots_loop4
		dec i
		bne main_dots_loop2
		dec j
		bne main_dots_loop
;dotsmoveflag	lda #0
;		bne .dotsmoveskip
;		dec dotsyoffset
;.dotsmoveskip
;		lda dotsmoveflag+1
;		eor #1
;		sta dotsmoveflag+1
		jsr SwitchBuf
		SHOW desire_logo_SCB
		SHOW init_stars_SCB
		lda transitionmode
		cmp #1
		bne dots_cont
		inc dotsyoffset
						
dots_cont	lda timer+1
		cmp #5
		bcs main_dots_loop5
		jmp dotsloop
main_dots_loop5 
		lda #2
		sta transitionmode
		inc dotsyoffset
dots_cont2	lda timer+1
		cmp #6
		bcs dots_exit
		jmp dotsloop	
dots_exit
		rts

do_balls
		ldy	#$1F			;Palette
.ballpall		;ldx redir,y
		lda	ball2pal,y
		sta	$FDA0,y
		dey
		bpl	.ballpall

		stz $fda0
		lda #$35
		sta $fdb0
		lda #$03
		sta $fda2
		lda #$58
		sta $fdb2
		lda #$00 
		sta $fda1
		lda #$00 
		sta $fdb1
		lda #$07
		sta $fda3
		lda #$46
		sta $fdb3


		stz a1bak
		stz a2bak
		stz a3bak
		stz a4bak
		stz a5bak
		
		lda #<ball_SCB
		sta .balls0+1
		lda #>ball_SCB
		sta .balls0+2
		lda #<stars_SCB_buffer
		sta .balls2+1
		lda #>stars_SCB_buffer
		sta .balls2+2
		
		ldy #128
.balls3		ldx #16
.balls0		lda ball_SCB,x ;stars_SCB,x
.balls2		sta stars_SCB_buffer,x
		dex
		bpl .balls0
		lda .balls2+1
		clc
		adc #17
		sta .balls2+1
		bcc .balls1
		inc .balls2+2
.balls1		lda next_ball_SCB
		clc
		adc #17
		sta next_ball_SCB
		bcc .balls4
		inc next_ball_SCB+1	
.balls4		dey
		bne .balls3
		stz stars_SCB_buffer+3+127*17 ;+29
		stz stars_SCB_buffer+4+127*17;+1+29
				
		stz dotsyoffset		
ballsloop:
;calculate xbuff,ybuff
		jsr SwitchBuf

		lda a1bak
		sta a1
		lda a2bak
		sta a2
		lda a3bak
		sta a3
		ldx #159
.ballloop0	
		ldy a1
		lda sintab2,y
		ldy a2
		clc
		adc sintab2+256,y
		ldy a3
		adc sintab2+512,y
		sta xbuff-1,x
		inc a1
		lda a2
		clc
		adc #15 ;2
		sta a2
		lda a3
		clc
		adc #4 
		sta a3
		dex
		bne .ballloop0
		inc a1bak
		lda a2bak
		clc
		adc #1 ;3
		sta a2bak
		lda a3bak
		clc
		adc #2
		sta a3bak
;ybuff
		lda a4bak
		sta a4
		lda a5bak
		sta a5

		ldx #100
.ballloop1
		ldy a4
		lda sintab2,y		
		ldy a5
		clc
		adc sintab2+256,y
		sta ybuff,x
		inc a4
		lda a5
		clc
		adc #7 ;krümmung nach hinten
		sta a5
		dex
		bpl .ballloop1
		inc a4bak
		dec a5bak
		dec a5bak
main_balls		
		
		lda #<(stars_SCB_buffer+7) ;ball_x
		sta balls_ad+1
		lda #>(stars_SCB_buffer+7)
		sta balls_ad+2
		lda #<(stars_SCB_buffer+9) ;ball_y
		sta balls_ad2+1
		lda #>(stars_SCB_buffer+9)
		sta balls_ad2+2
		lda #11
		sta j		
main_balls_loop
		lda #11
		sta i
main_balls_loop2
		lda i
		asl
		asl
		asl
		asl
		adc #48
		adc j
		adc j
balls_ad	sta ball_x
		ldx i
		ldy j
		lda xbuff,x
		clc
		adc ybuff,y
ballsyoffset	adc #0
ball_top	cmp #60-8
		bcs balls_ad2
ball_bottom	cmp #63-8
		bcc balls_ad2
		lda #0
balls_ad2	sta ball_y		
balls_skip	lda balls_ad+1
		clc
		adc #29-12
		sta balls_ad+1
		bcc main_balls_loop3
		inc balls_ad+2
main_balls_loop3 lda balls_ad2+1
		clc
		adc #29-12
		sta balls_ad2+1
		bcc main_balls_loop4
		inc balls_ad2+2
main_balls_loop4
		dec i
		bne main_balls_loop2
		dec j
		bne main_balls_loop
		SHOW desire_logo_SCB
		SHOW init_ball_SCB ;stars_SCB_buffer
		lda timer+1
		cmp #12
		bcs ballsexit		
		lda ball_bottom+1
ccc		cmp #102+64
		bcs kkk
aaa		inc ball_bottom+1
kkk		lda ballsyoffset+1
		cmp #64+32
		bcs kkkk		
bbb		inc ballsyoffset+1
kkkk		jmp ballsloop

ballsexit
		lda timer+1
		cmp #13
		bcs ballsexit3
		lda ball_bottom+1
		cmp #63-8
		bcc ballexit2		
		dec ball_bottom+1
		dec ballsyoffset+1
ballexit2
		jmp ballsloop
ballsexit3
		lda timer
		cmp #$10
		bcc ballexit2

	ldx #15
.ball00
	lda $fda0,x
	sta src_gh,x
	lda $fdb0,x
	tay
	and #$f0
	lsr
	lsr
	lsr
	lsr
	sta src_bh,x
	tya
	and #$0f
	sta src_rh,x
	lda #0 ;0
	sta dest_gh,x ;$fda0
	lda #2
	sta dest_bh,x
	lda #3
	sta dest_rh,x
	dex
	bpl .ball00

	jsr fade_to_palette

		rts


;200 chars on screen for text overlay
;needs init routine to setup and chain all SCBs
chars_init
		lda #<font
		sta i
		lda #>font
		sta j
		ldx #0
.char0000
		lda #<(font+50*33)
		sta char_tabl,x
		lda #>(font+50*33)
		sta char_tabh,x
		inx
		cpx #65
		bne .char0000
.char000
		lda i
		sta char_tabl,x
		lda j
		sta char_tabh,x
		lda i
		clc
		adc #33
		sta i
		lda j
		adc #0
		sta j
		inx
		bpl .char000
	
		lda #<char_SCB
		sta .char0+1
		lda #>char_SCB
		sta .char0+2
		lda #<stars_SCB_buffer
		sta .char2+1
		lda #>stars_SCB_buffer
		sta .char2+2
		lda #<(stars_SCB_buffer+29)
		sta next_char_SCB
		lda #>(stars_SCB_buffer+29)
		sta next_char_SCB+1			
		stz char_x+1
		stz char_y+1
		lda #64+16
		sta char_x	 ; 	dc.w 64+80 
		lda #$50
		sta char_y     	;dc.w $0050

		ldy #10
		lda #72
		sta char_SCB+9
.chars00		
		lda #10
		sta i
		lda #64+16 ;60+72
		sta char_SCB+7
		
.char3		ldx #28
.char0		lda char_SCB,x
.char2		sta stars_SCB_buffer,x
		dex
		bpl .char0
		ldx #0
		lda char_tabl,x
		sta char_SCB+5
		lda char_tabh,x
		sta char_SCB+6
		lda char_SCB+7
		clc
		adc #8
		sta char_SCB+7
		lda .char2+1
		clc
		adc #29
		sta .char2+1
		bcc .char1
		inc .char2+2
.char1		lda next_char_SCB
		clc
		adc #29
		sta next_char_SCB
		bcc .char4
		inc next_char_SCB+1	
.char4		
		dec i
		bne .char3
		lda char_SCB+9
		clc
		adc #8
		sta char_SCB+9
		dey
		bne .chars00
		stz stars_SCB_buffer+100*29+4
		stz stars_SCB_buffer+100*29+5
		rts



;prints a complete page 20x10 chars
do_text_page
		ldy #100
		lda #<(stars_SCB_buffer+5)
		sta textad+1
		lda #>(stars_SCB_buffer+5)
		sta textad+2
		lda #<(stars_SCB_buffer+6)
		sta textad2+1
		lda #>(stars_SCB_buffer+6)
		sta textad2+2
		stz text_counter
text_loop
		ldx text_counter
text_pointer	lda text,x
		tax
		lda char_tabl,x
textad		sta stars_SCB_buffer+5
		lda char_tabh,x
textad2		sta stars_SCB_buffer+6
		lda textad+1
		clc
		adc #29
		sta textad+1
		bcc .text0
		inc textad+2		
.text0		lda textad2+1
		clc
		adc #29
		sta textad2+1
		bcc .text1
		inc textad2+2		
.text1
		inc text_counter
		dey
		bne text_loop

		lda text_pointer+1
		clc
		adc #100
		sta text_pointer+1
		lda text_pointer+2
		adc #0
		sta text_pointer+2

		rts
text_counter	dc.b 0

random        	lda seed
	      	beq doEor
        	asl
	        beq noEor ;if the input was $80, skip the EOR
	        bcc noEor
doEor  		eor #$1d
noEor	  	sta seed
		rts
seed		dc.b $01

fade_col	dc.b 0		

;bouncing square
transitioncounter	dc.b 0
transitionmode dc.b 0
clearsizetabl	dc.b $00,$00,$00,$00
clearsizetabh	dc.b $00,$00,$00,$00

		
		
main_demo_loop
;set camera
	stz worldx
	stz worldx+1
	stz worldy
	stz worldy+1
	stz worldz
	stz worldz+1
	jsr update_scene
	jsr render_scene
	rts
	
update_scene	
loop_counter	ldx #0
	lda #$d0
	sta object_offset
	 lda #0
	 sta worldx
	 sta worldy
	 sta worldz
	lda #$00
	sta worldx+1
	lda #0
	sta worldy+1
zoom_object lda #$70 ;$70 ;$1d for octa... file ;$50 for thetradon
	;sec
	;sbc zoomtab,x
	sta worldz+1
	
;	lda loop_counterl
;	clc
;	adc #128
;	sta loop_counterl
;	bcc move_2
move	inc loop_counter+1
;	lda loop_counter+1
;	cmp #$f0
;	bcc move_2
;	lda #$f0
;	sta loop_counter+1
move_2
	lda angy
	clc
stepyl	adc #$64
	sta angy
	lda angy+1
stepyh	adc #1
;	and #$7f
	sta angy+1

	lda angz
	clc
stepzl	adc #$60
	sta angz
	lda angz+1
stepzh	adc #$ff
	sta angz+1

	lda angx
	clc
stepxl	adc #$a0
	sta angx
	lda angx+1
stepxh	adc #0
	sta angx+1
	rts
loop_counterl dc.b 128
zoom ds 1
object_offset ds 1

	  
render_scene
		jsr makemat ;prepare rotation matrix
;x
;y x M = x*m11+y*m21+z*m31+x*m12+y*m22+z*m32+x*m13+y*23+z*m33
;z

;x'''=x*m00+y*m01+z*m02
;y'''=x*m10+y*m11+z*m12
;z'''=x*m20+y*m21+z*m22
	
;first rotate the normals
	 	;jsr rotate_facenormals


max_vert	ldx max_vertices ;max_vertices ;7 for object 2 ;5 vertices for object 1

rot
;x
rot_objx1	lda _px_l,x
		sta T1
rot_objx2	lda _px_h,x
		sta T1+1
		lda mat+0
		sta T2
		lda mat+9 ;hi
		sta T2+1
		;sec
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		sta xn
	 	lda product+3
	 	sta xn+1
;		jmp *
rot_objy1	lda _py_l,x
		sta T1
rot_objy2	lda _py_h,x
		sta T1+1
	 	
		lda mat+1
		sta T2
		lda mat+9+1 ;hi
		sta T2+1
		;sec ;reuse T1
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		clc
		adc xn
		sta xn
	 	lda product+3
	 	adc xn+1
	 	sta xn+1

rot_objz1	lda _pz_l,x
		sta T1
rot_objz2	lda _pz_h,x
		sta T1+1

		lda mat+2
		sta T2
		lda mat+9+2 ;hi
		sta T2+1
		;sec ;reuse T1
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		clc
		adc xn
		sta xn
	 	lda product+3
	 	adc xn+1
	 	sta xn+1
;y			
;y'''=x*m10+y*m11+z*m12
rot_objx3	lda _px_l,x
		sta T1
rot_objx4	lda _px_h,x
		sta T1+1
		lda mat+3
		sta T2
		lda mat+9+3 ;hi
		sta T2+1
		;sec
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		sta yn
	 	lda product+3
	 	sta yn+1

rot_objy3	lda _py_l,x
		sta T1
rot_objy4	lda _py_h,x
		sta T1+1
	 	
		lda mat+4
		sta T2
		lda mat+9+4 ;hi
		sta T2+1
		;sec ;reuse T1
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		clc
		adc yn
		sta yn
	 	lda product+3
	 	adc yn+1
	 	sta yn+1

rot_objz3	lda _pz_l,x
		sta T1
rot_objz4	lda _pz_h,x
		sta T1+1

		lda mat+5
		sta T2
		lda mat+9+5 ;hi
		sta T2+1
		;sec ;reuse T1
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		clc
		adc yn
		sta yn
	 	lda product+3
	 	adc yn+1
	 	sta yn+1
;
;z'''=x*m20+y*m21+z*m22
rot_objx5	lda _px_l,x
		sta T1
rot_objx6	lda _px_h,x
		sta T1+1
		lda mat+6
		sta T2
		lda mat+9+6 ;hi
		sta T2+1
		;sec
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		sta zn
	 	lda product+3
	 	sta zn+1

rot_objy5	lda _py_l,x
		sta T1
rot_objy6	lda _py_h,x
		sta T1+1
	 	
		lda mat+7
		sta T2
		lda mat+9+7 ;hi
		sta T2+1
		;sec ;reuse T1
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		clc
		adc zn
		sta zn
	 	lda product+3
	 	adc zn+1
	 	sta zn+1

rot_objz5	lda _pz_l,x
		sta T1
rot_objz6	lda _pz_h,x
		sta T1+1

		lda mat+8
		sta T2
		lda mat+9+8 ;hi
		sta T2+1
		;sec ;reuse T1
		;jsr multiply_16bit_signed
		jsr do_math_copo
		lda product+2
		clc
		adc zn
		sta zn
	 	lda product+3
	 	adc zn+1
	 	sta zn+1
;should we store each P''.z?
;		sta verticesx,x
;		sta verticesy,x
		clc
		adc #127
		sta verticesz,x
trans:
	lda worldz+1
	sbc zn+1 ;z'
	tay
;	ldy zn+1
	lda ztabl,y ;faktor
	sta T1
	lda ztabh,y ;faktor
	sta T1+1
	lda xn
	sec
	sbc worldx
	sta T2
	lda xn+1
;	sec
	sbc worldx+1	
	sta T2+1
	;sec
	;jsr multiply_16bit_signed
	jsr do_math_copo
;	lda product+1
;	sta T2
;	lda product+2
;	sta T2+1
;	lda zoom
;	sta T1
;	lda #0
;	sta T1+1
;	jsr do_math_copo
	
	lda product+2
	clc
	;adc #80 ;32+40 ;mx 16+40
	adc object_offset
;	bcc jjj ;overflow
;	lda #0
jjj	sta tx_h,x	;* tx=xn*ztab+80
	lda product+1
	sta tx_l,x
	
	lda worldz+1
	sec
	sbc zn+1 ;z'
	tay
;	ldy zn+1
	lda ztabl,y
	sta T1
	lda ztabh,y
	sta T1+1
	lda yn
;	lda py_l,x
	sta T2
	lda yn+1
;	lda py_h,x
	clc
	adc worldy+1
	sta T2+1
	;sec
	;jsr multiply_16bit_signed
	jsr do_math_copo
;	lda product+1
;	sta T2
;	lda product+2
;	sta T2+1
;	lda zoom
;	sta T1
;	lda #0
;	sta T1+1
;	jsr do_math_copo

	lda product+2
	clc
	adc #51 ;37; ;my+hibyte
;	adc object_offset
	sta ty_h,x	;* ty=yn*ztab+48
	lda product+1
	sta ty_l,x
	dex
	bmi draw_object
	jmp rot
skip0
echo "skip0: %hskip0"
draw_object
	lda max_faces ;#0 ;256-4
	sta face_counter
draw_loop
	ldy face_counter
;	lda _pzno_sign,y
;	bmi .sskip
;	beq .sskip
;when using z-sorted facetab then
;we shuld use a pointer to face struct
;y holds face ID
;so something like ldx sorted_facetab,y
face2	ldx facetab+2,y
	lda tx_l,x
	sta x2
	lda tx_h,x
	sta x2+1
	lda ty_l,x
	sta y2
	lda ty_h,x
	sta y2+1
face1	ldx facetab+1,y
	lda tx_l,x
	sta x3
	lda tx_h,x
	sta x3+1
	lda ty_l,x
	sta y3
	lda ty_h,x
	sta y3+1
face	ldx facetab,y
	lda tx_l,x
	sta x1
	lda tx_h,x
	sta x1+1
	lda ty_l,x
	sta y1
	lda ty_h,x
	sta y1+1
	lda ty_h,x
cull_mode nop ;jsr culltest_16bit
	lda #7 ;line color in wireframe mode
glenz_flag bmi .sskip
	inc
;	inc
	sta polycol	
	ldy tx_h,x
	lda ty_h,x
draw_mode jsr poly_blitter
.sskip	
	lda face_counter
	sec
	sbc #4
	sta face_counter
draw_loop_exit	cmp #252 ;anpassen anhand des POLYS!!!!
	beq .drawexit
	jmp draw_loop
.drawexit
	rts


makemat:
; mat format M_lo(3,3) ;M_hi(3,3) = 9 bytes low, 9 bytes hi
		lda angy+1
		sec
		sbc angz+1
		tax
		clc
		adc angx+1
		sta mtmp1
		
		lda angy+1
		clc
		adc angz+1
		tay
		clc
		adc angx+1
		sta mtmp2
		
		lda sintab_rotl+$c0,x
		sec
		sbc costab_rotl,y
		sta mat+0
		lda sintab_roth+$c0,x
		sbc costab_roth,y
		sta mat+9

		lda sintab_rotl,x
		sec
		sbc sintab_rotl,y
		sta mat+1
		lda sintab_roth,x
		sbc sintab_roth,y
		sta mat+10
				
		ldx angy+1
		lda sintab_rotl,x
		asl
		sta mat+2
		lda sintab_roth,x
		rol
		sta mat+11
		
		lda angx+1
		clc
		adc angz+1
		tax
		sec
		sbc angy+1
		sta mtmp4
		 
		lda angx+1
		sec
		sbc angz+1
		tay
		sec
		sbc angy+1
		sta mtmp3
		
		lda sintab_rotl,x
		sec
		sbc sintab_rotl,y
		sta mtmp5
		lda sintab_roth,x
		sbc sintab_roth,y
		sta mtmp6
		
		lda costab_rotl,x
		clc
		adc costab_rotl,y
		sta mtmp7
		lda costab_roth,x
		adc costab_roth,y
		sta mtmp8
		
		lda costab_rotl,x
		sec
		sbc costab_rotl,y
		sta mtmp9
		lda costab_roth,x
		sbc costab_roth,y
		sta mtmp10
		
		lda angz+1
		sec
		sbc angx+1
		tay
		lda sintab_rotl,y
		sec
		sbc sintab_rotl,x
		sta mtmp11
		lda sintab_roth,y
		sbc sintab_roth,x
		sta mtmp12
		
		ldx mtmp3
		ldy mtmp4
		lda costab_rotl,x
		clc
		adc costab_rotl,y
		sta mtmp13
		lda costab_roth,x
		adc costab_roth,y
		sta mtmp14
		asl
		ror mtmp14
		ror mtmp13
		
		ldx mtmp1
		ldy mtmp2
		lda sintab_rotl,y
		sec
		sbc sintab_rotl,x
		sta mtmp15
		lda sintab_roth,y
		sbc sintab_roth,x
		sta mtmp16
		asl
		ror mtmp16
		ror mtmp15
		
		lda costab_rotl,x
		clc
		adc costab_rotl+1,y
		sta mtmp17
		lda costab_roth,x
		adc costab_roth+1,y
		sta mtmp18
		asl
		ror mtmp18
		lda mtmp17
		ror
		sec
		sbc mtmp13
		tax
		
		lda mtmp18
		sbc mtmp14
		tay
			
		txa
		clc
		adc mtmp5
		sta mat+3
		tya
		adc mtmp6
		sta mat+12

		ldx mtmp3
		ldy mtmp4
		lda sintab_rotl,x
		sec
		sbc sintab_rotl,y
		sta mtmp17
		lda sintab_roth,x
		sbc sintab_roth,y	
		sta mtmp18
		asl
		ror mtmp18
		lda mtmp17
		ror
		clc
		adc mtmp15
		tax
		lda mtmp18
		adc mtmp16
		tay
		txa
		sec
		sbc mtmp7
		sta mat+4
		tya
		sbc mtmp8
		sta mat+13
			
		lda angx+1
		clc
		adc angy+1
		tay
		lda angy+1
		sec
		sbc angx+1
		tax
		lda sintab_rotl,x
		sec
		sbc sintab_rotl,y
		sta mat+5
		lda sintab_roth,x
		sbc sintab_roth,y
		sta mat+14
		
		lda angx+1
		sec
		sbc angy+1
		tax
		lda costab_rotl,x
		clc
		adc costab_rotl,y
		sta mat+8
		lda costab_roth,x
		adc costab_roth,y
		sta mat+17
		
		ldx mtmp1
		ldy mtmp3
		lda sintab_rotl,x
		sec
		sbc sintab_rotl,y
		sta mtmp13
		lda sintab_roth,x
		sbc sintab_roth,y
		sta mtmp14
		asl
		ror mtmp14
		ror mtmp13
		
		lda costab_rotl,x
		sec
		sbc costab_rotl,y
		sta mtmp15
		lda costab_roth,x
		sbc costab_roth,y
		sta mtmp16
		asl
		ror mtmp16
		ror mtmp15
		
		ldx mtmp2
		ldy mtmp4
		lda sintab_rotl,x
		sec
		sbc sintab_rotl+1,y
		sta mtmp19
		lda sintab_roth,x
		sbc sintab_roth+1,y
		sta mtmp20				
		asl
		ror mtmp20
		ror mtmp19
		
		lda mtmp19
		clc
		adc mtmp13
		sta mtmp19
		lda mtmp20
		adc mtmp14
		sta mtmp20
		
		lda mtmp19
		sec
		sbc mtmp9
		sta mat+6
		lda mtmp20
		sbc mtmp10
		sta mat+15
		
		ldx mtmp2
		ldy mtmp4
		lda costab_rotl,y
		sec
		sbc costab_rotl+1,x
		sta mtmp19
		lda costab_roth,y
		sbc costab_roth+1,x
		sta mtmp20
		asl
		ror mtmp20
		lda mtmp19
		ror 
		clc
		adc mtmp15
		tax
		lda mtmp20
		adc mtmp16
		tay
		txa
		clc
		adc mtmp11
		sta mat+7
		tya
		adc mtmp12
		sta mat+16

;matrix spiegeln		
;		ldy #$08
;mml0:	
;		lda mat+9,y
;		asl
;		ror mat+9,y
;		ror mat,y
;
;		sec
;		lda #$00
;		sbc mat,y
;		sta mat+18,y
;
;		lda #$00
;		sbc mat+9,y
;		sta mat+27,y
;
;		dey
;		bpl mml0
		rts




culltest_16bit
;2d cull test
;((x2-x0) * (y3-y0)) - ((x3-x0) * (y2-y0))
;  ((x2-a) * (y3-y)) - ((x3-a) * (y2-y))
;if this value is bigger than 0,your face is visible..
;x1=x0;x2=x1;a=x2

;color=((x2-a)  (y3-y)) - ((x3-a)  (y2-y))

;Beispiel: 80-40 = 40 * 30 - 10*74 = 1200-740 = 560 = sichtbar
;Skaliert: 160-80 = 80*60 - 20*148 =	
	lda x2
	sec
	sbc x1
	sta mtmp1
	lda x2+1
	sbc x1+1
	sta mtmp2 ;x2-x1
	lda y3
	sec
	sbc y1
	sta mtmp3
	lda y3+1
	sec
	sbc y1+1
	sta mtmp4 ;y3-y1
	lda x3
	sec
	sbc x1
	sta mtmp5
	lda x3+1
	sbc x1+1
	sta mtmp6 ;x3-x1
	lda y2
	sec
	sbc y1
	sta mtmp7
	lda y2+1
	sbc y1+1
	sta mtmp8 ;y2-1
;(x2-x1) * (y3-y1)
	lda mtmp1
	sta T1
	lda mtmp2
	sta T1+1
	lda mtmp3
	sta T2
	lda mtmp4
	sta T2+1
	jsr do_math_copo
	lda product+2
	sta mtmp1
	lda product+3
	sta mtmp2
;(x3-1) * (y2-y1)
	lda mtmp5
	sta T1
	lda mtmp6
	sta T1+1
	lda mtmp7
	sta T2
	lda mtmp8
	sta T2+1
	jsr do_math_copo
	lda mtmp1
	sec
	sbc product+2
	sta mtmp3
	lda mtmp2
	sbc product+3
	sta mtmp4
	rts
	


face_counter ds 1


poly_blitter
	sty x1+1
	cmp y3+1
	bcc .sorty
	tax ;y1
	lda x3+1
	sta x1+1
	sty x3+1
	ldy y3+1
	stx y3+1
	tya ;y3
.sorty	sta y1+1
	cmp y2+1
	bcc .sorty2
	tax
	lda y2+1
	sta y1+1
	stx y2+1
;	ldx x1+1
	ldx x1+1
	lda x2+1
	sta x1+1
	stx x2+1
.sorty2	lda y2+1
	cmp y3+1
	bcc .dopoly
	tax
	lda y3+1
	sta y2+1
	stx y3+1
	ldx x2+1
	lda x3+1
	sta x2+1
	stx x3+1
.dopoly
linemode	jmp FLine
* polygon.inc
*
* re-created : 98/01/17
*

***************
* Filled Polygon
* actually only a tri or tetragon
* IN : A - color
*      Y - ptr
****************
*
FPolygon::      
		lda #$a0
                sta $FC92
                lda x1+1
                clc
                adc #96
                sta xx1
                lda #0
                sta xx1+1
                lda y1+1
                clc
                adc #64
                sta yy1
                lda #0
                sta yy1+1
                lda x2+1
                clc
                adc #96
                sta xx2
                lda #0
                sta xx2+1
                lda y2+1
                clc
                adc #64
                sta yy2
                lda #0
                sta yy2+1
                lda x3+1
                clc
                adc #96
                sta xx3
                lda #0
                sta xx3+1
                lda y3+1
                clc
                adc #64
                sta yy3
                lda #0
                sta yy3+1
                jsr triangle
                rts
.fpcolor        ds 1
****************
* Triangle
* (x1,y1),(x2,y2),(x3,y3)
* draw
*        A
*       /\
*      /  \
*     /    \
*  B /      \ B'
*    \       \
*     \_      \
*       \_     \
*         \_    \
*           \_   \
*             \_  \
*               \_ \
*                 \_\
*                     C
*
* two triangles/sprites : 1) ABB' 2) BB'C
*
****************
triangle::
		lda polycol
                sta .tri_scb_color
                sta .tri_scb2_color

*
*
* sort points
*
                CMPWS yy1,yy2
                _IFLT                           ; yy1>yy2 ?
                  SWAP xx1,xx2
                  SWAP yy1,yy2
                _ENDIF
                CMPWS yy1,yy3
                _IFLT
                  SWAP xx1,xx3
                  SWAP yy1,yy3
                _ENDIF
                CMPWS yy2,yy3
                _IFLT
                  SWAP xx2,xx3
                  SWAP yy2,yy3
                _ENDIF

*
                ldy #-1
                sec
                lda yy2
                sbc yy1

                sta MATHE_B
                stz MATHE_B+1

                _IFNE
                  inc
                _ENDIF
                sta .tri_scb_ysize+1
                stz MATHE_A
                stz MATHE_A+1
                sec
                lda xx2
                sbc xx1
                tax
                lda xx2+1
                sbc xx1+1
                bpl .1
                  iny
                  pha
                  txa
                  eor #$ff
                  tax
                  pla
                  eor #$ff
                  inx
                  bne .1
                  inc
.1
                stx MATHE_A+2
                sta MATHE_A+3
                WAITSUZY
                tya
                _IFEQ
                  sec
                  sbc MATHE_D+1
                  tax
                  tya
                  sbc MATHE_D+2
                  dey
                _ELSE
                  ldx MATHE_D+1
                  lda MATHE_D+2
                _ENDIF
                stx tiltAB
                sta tiltAB+1
****************
                sec
                lda yy3
                sbc yy1
                sta MATHE_B
                stz MATHE_B+1
                stz MATHE_A
                stz MATHE_A+1
                sec
                lda xx3
                sbc xx1
                tax
                lda xx3+1
                sbc xx1+1
                bpl .2
                  iny
                  pha
                  txa
                  eor #$ff
                  tax
                  pla
                  eor #$ff
                  inx
                  bne .2
                  inc
.2
                stx MATHE_A+2
                sta MATHE_A+3
                WAITSUZY
                tya
                _IFEQ
                  sec
                  sbc MATHE_D+1
                  tax
                  tya
                  sbc MATHE_D+2
                  dey
                _ELSE
                  ldx MATHE_D+1
                  lda MATHE_D+2
                _ENDIF
                stx tiltAC
                sta tiltAC+1
****************
                sec
                lda yy3
                sbc yy2
                sta MATHE_B
                stz MATHE_B+1

                sta .tri_scb2_ysize+1
                stz MATHE_A
                stz MATHE_A+1
                sec
                lda xx3
                sbc xx2
                tax
                lda xx3+1
                sbc xx2+1
                bpl .3
                  iny
                  pha
                  txa
                  eor #$ff
                  tax
                  pla
                  eor #$ff
                  inx
                  bne .3
                  inc
.3
                stx MATHE_A+2
                sta MATHE_A+3
                WAITSUZY
                tya
                _IFEQ
                  sec
                  sbc MATHE_D+1
                  tax
                  tya
                  sbc MATHE_D+2
                _ELSE
                  ldx MATHE_D+1
                  lda MATHE_D+2
                _ENDIF
                stx tiltBC
                sta tiltBC+1
****************
                MOVE xx1,.tri_scb_x
                MOVE yy1,.tri_scb_y
                MOVE xx3,.tri_scb2_x
                MOVE yy3,.tri_scb2_y
                MOVEI $180,.tri_scb_xsize
                MOVEI $180,.tri_scb2_xsize
****************
                MOVE tiltAC,temp
                CMPWS tiltAC,tiltAB
                _IFLT
                  SWAP tiltAB,tiltAC
                _ENDIF
                SUBW tiltAC,tiltAB,.tri_scb_stretch
                MOVE tiltAC,.tri_scb_tilt
****************
                CMPWS temp,tiltBC
                _IFLT
                  SWAP temp,tiltBC
                _ENDIF
                SUBW temp,tiltBC,.tri_scb2_stretch
                sec
                lda #0
                sbc tiltBC
                sta .tri_scb2_tilt
                lda #0
                sbc tiltBC+1
                sta .tri_scb2_tilt+1
****************
;>                MOVE ScreenBase,$fc08
		
		
                lda .tri_scb_ysize+1
                _IFNE
                  SHOW .tri_scb
                _ELSE
                  lda .tri_scb2_ysize+1
                  _IFNE
                    inc .tri_scb2_ysize+1
                  _ENDIF
                _ENDIF

                lda .tri_scb2_ysize+1
                _IFNE
		SHOW .tri_scb2
                _ENDIF
                rts
tiltAB	ds 2
tiltAC  ds 2
tiltBC  ds 2
temp	ds 2
xx1	ds 2
yy1	ds 2
xx2	ds 2
yy2	ds 2
xx3	ds 2
yy3	ds 2


**************************************************
.trieveron1     dc.b 0
tri_scb
.tri_scb        dc.b %11000000,$80|$30,0
                dc.w 0,.triimage
.tri_scb_x      dc.w 0
.tri_scb_y      dc.w 0
.tri_scb_xsize  dc.w $100
.tri_scb_ysize  dc.w $100
.tri_scb_stretch dc.w 0
.tri_scb_tilt   dc.w 0
.tri_scb_color  dc.b $03

;flipped
.trieveron2         dc.b 0
tri_scb2
.tri_scb2       dc.b $d0,$80|$30,0
                dc.w 0,.triimage
.tri_scb2_x     dc.w 0
.tri_scb2_y     dc.w 0
.tri_scb2_xsize dc.w $100
.tri_scb2_ysize dc.w $100
.tri_scb2_stretch dc.w 0
.tri_scb2_tilt  dc.w 0
.tri_scb2_color dc.b $e
.triimage       dc.b 2,$10,0
****************


*******************
* PLOT X,Y,A
*******************
FLine::
		lda polycol
		sta .dl_scb_color
	        lda #$a0
                sta $FC92
                lda x1+1
                clc
                adc #96
                sta xx1
                lda #0
                sta xx1+1
                lda y1+1
                clc
                adc #64
                sta yy1
                lda #0
                sta yy1+1                    
                lda x2+1
                clc
                adc #96
                sta xx2
                lda #0
                sta xx2+1
                lda y2+1
                clc
                adc #64
                sta yy2
                lda #0
                sta yy2+1
                jsr DrawLine

                lda x2+1
                clc
                adc #96
                sta xx1
                lda #0
                sta xx1+1
                lda y2+1
                clc
                adc #64
                sta yy1
                lda #0
                sta yy1+1                    
                lda x3+1
                clc
                adc #96
                sta xx2
                lda #0
                sta xx2+1
                lda y3+1
                clc
                adc #64
                sta yy2
                lda #0
                sta yy2+1
                jsr DrawLine
                
                lda x1+1
                clc
                adc #96
                sta xx1
                lda #0
                sta xx1+1
                lda y1+1
                clc
                adc #64
                sta yy1
                lda #0
                sta yy1+1                    
                lda x3+1
                clc
                adc #96
                sta xx2
                lda #0
                sta xx2+1
                lda y3+1
                clc
                adc #64
                sta yy2
                lda #0
                sta yy2+1
                jsr DrawLine
                rts

DrawLine
;                sta .dl_scb_color
                stz .dl_scb_xsize
                stz .dl_scb_ysize
                stz .dl_scb_stretch
                stz .dl_scb_stretch+1
                sec
                lda xx2
                sbc xx1
                lda xx2+1
                sbc xx1+1
                bpl .ok
                  SWAP xx2,xx1
                  SWAP yy2,yy1
.ok             lda #%11000000
                sta .dl_scb
                sec
                lda yy2
                sbc yy1
                sta yy2
                lda yy2+1
                sbc yy1+1
                sta yy2+1
                bpl .ok1
                  sec
                  lda #0
                  sbc yy2
                  sta yy2
                  lda #0
                  sbc yy2+1
                  sta yy2+1
                  lda #%11010000
                  sta .dl_scb
.ok1            MOVE xx1,.dl_scb_x
                MOVE yy1,.dl_scb_y

                lda yy2
                inc
                sta .dl_scb_ysize+1
                sta MATHE_B
                stz MATHE_B+1

                stz MATHE_A
                sec
                lda xx2
                sbc xx1
                inc
                sta MATHE_A+2
                stz MATHE_A+3
                WAITSUZY
                MOVE MATHE_D+1,.dl_scb_tilt
                _IFEQ
                  lda #1
                  sta .dl_scb_xsize+1
                _ELSE
                  bit .dl_scb_tilt
                  _IFMI
                    inc
                  _ENDIF
                  sta .dl_scb_xsize+1
                _ENDIF

;>                MOVE ScreenBase,$fc08
                MOVEI .dl_scb,$fc10

                stz $fd90
                lda #1

                STA $FC91
.wait           STZ $FD91
                bit $fc92
                bne .wait
                STZ $FD90
                rts

.dl_scb       dc.b $d0,$80|$30,0
               dc.w 0,.dlimage
.dl_scb_x     dc.w 0
.dl_scb_y     dc.w 0
.dl_scb_xsize dc.w $100
.dl_scb_ysize dc.w $100
.dl_scb_stretch dc.w 0
.dl_scb_tilt  dc.w 0
.dl_scb_color dc.b $e
.dlimage       dc.b 2,$10,0

	  

hline_blitter
;draws a line from x,y to a,y
	sta hline_blitter_exit0+1
	stx hline_blitter_exit1+1
	sty hline_blitter_exit2+1
	stx hline_blitter0+1
	stz hlineposy+1
;length of line in pixel
;a-x = length in pixel
	sec
hline_blitter0 sbc #0
sanity
	sta hlinesizex+1
;	stz hlinesizex
	txa
	clc
	adc #100
	sta hlineposx
	stz hlineposx+1
	tya
	clc
	adc #76
	sta hlineposy
;color
	lda polycol
;	lda #$0b
;	and #$0f
	sta hlinecolor
	SHOW hline_SCB
	
hline_blitter_exit0 lda #0
hline_blitter_exit1 ldx #0
hline_blitter_exit2 ldy #0
	rts



;* Mathe-Register
;* A = C * E
;* A : B = D + R/2
;*
;MATHE_A         EQU $FC60
;MATHE_B         EQU $FC56
;MATHE_C         EQU $FC52
;MATHE_D         EQU $FC52
;MATHE_E         EQU $FC54
;MATHE_AKKU      EQU $FC6C
;MATHE_R         EQU $FC6C
;
;* Atari-definitions for co-pro registers
;MATHD           equ $fc52
;MATHC           equ $fc53
;MATHB           equ $fc54
;MATHA           equ $fc55
;MATHP           equ $fc56
;MATHH           equ $fc60
;MATHG           equ $fc61
;MATHF           equ $fc62
;MATHE           equ $fc63
;MATHM           equ $fc6c
;MATHL           equ $fc6d
;MATHK           equ $fc6e
;MATHJ           equ $fc6f
;
;
;SUZY_BUS_ENABLE EQU $FC90       ; 0 disables Suzy

do_math_copo
	stx xreg_save
	sty yreg_save
	lda #$a0 ;signedmul
	sta $FC92
	
	lda T1
	sta MATHD
	lda T1+1
	sta MATHC
	lda T2
	sta MATHB
	lda T2+1
	sta MATHA
;.wait	lda $fc92 ;WAITSUZY
;	bmi .wait
	WAITSUZY	
	lda MATHH
	sta product
	lda MATHG
	sta product+1
	lda MATHF
	sta product+2
	lda MATHE
	sta product+3

	ldx xreg_save
	ldy yreg_save
	rts


VBL	
	phy
	inc timer
	bne vbl0
	inc timer+1
vbl0
	lda transitionmode
	cmp #1
	bne vbl1
	ldx #3
	ldy transitioncounter
	clc
vbl00
	tya
zoom_in_step	adc #4
	tay
	dex
	bpl vbl00
	inc transitioncounter
	lda transitioncounter
transtop cmp #$e0
	bcc vbl_end
	stz transitioncounter
	lda #3
	sta transitionmode
	bra vbl_end
vbl1
	cmp #2
	bne vbl3
vbl2
	ldx #3
	ldy transitioncounter
vbl20
	tya
	sec
zoom_out_step	sbc #4
	tay
	dex
	bpl vbl20
	dec transitioncounter
	lda transitioncounter
transbottom	cmp #$10
	bcs vbl_end
	lda #3
	sta transitionmode
vbl3
vbl_end	
	ply
	END_IRQ


HBL
	lda barcolor_g
	and #$7f
	ora #$40
	sta $fc04
	lda barcolor_rb
	sta $fdbf
	inc barcolor_g
	lda barcolor_rb
	clc
	adc #$11
	sta barcolor_rb

	END_IRQ
barcolor_g	dc.b $00
barcolor_rb	dc.b $00

;anti-clock
tx_l	ds 128 ;1,0,0,0,0,0,0,0 ;8 ; $30
tx_h	ds 128 ;1,0,0,0,0,0,0,0 ;equ tx_l+8
ty_l	ds 128 ;1,0,0,0,0,0,0,0 ;equ tx_h+8
ty_h	ds 128 ;1,0,0,0,0,0,0,0 ;equ ty_l+8

;will be used for 3d bobs
verticesz ds 128


;do_3d_vectorballs
draw_3d_ball
;first do z-sorting
	jsr do_sort_z
;	stz ball_sizex+1
;	stz ball_sizey+1
;	lda #$c0
;	sta ball_sizex
;	sta ball_sizey
;sortorder has now the faces sorted by z	
vv	lda max_vertices3 ;#0 ;256-4
	sta face_counter
;	lda max_vertices3
;	cmp #72 ;torus source!
;	bcs draw_3d_loop
;	lda timer
;	and #$40
;	beq draw_3d_loop
;	inc max_vertices3
draw_3d_loop
	ldx face_counter
	ldy sortorder,x
;	ldx facetab+2,y
	lda tx_l,y
	sta x2
	lda tx_h,y
	sta x2+1
	lda ty_l,y
	sta y2
	lda ty_h,y
	sta y2+1
;	ldx facetab+1,y
	lda tx_l,y
	sta x3
	lda tx_h,y
	sta x3+1
	lda ty_l,y
	sta y3
	lda ty_h,y
	sta y3+1
;	ldx facetab,y
	lda tx_l,y
	sta x1
	lda tx_h,y
	sta x1+1
	lda ty_l,y
	sta y1
	lda ty_h,y
	sta y1+1
        lda x1+1
         clc
                adc #64+40
                sta xx1
                lda #0
                sta xx1+1
                lda y1+1
                clc
                adc #64
                sta yy1
                lda #0
                sta yy1+1
                lda x2+1
                clc
                adc #64+40
                sta xx2
                lda #0
                sta xx2+1
                lda y2+1
                clc
                adc #64
                sta yy2
                lda #0
                sta yy2+1
                lda x3+1
                clc
                adc #64+40
                sta xx3
                lda #0
                sta xx3+1
                lda y3+1
                clc
                adc #64
                sta yy3
                lda #0
                sta yy3+1

	lda xx1
	sta ball_x
	lda yy1
	sta ball_y
;	lda verticesz,y
;	sta ball_sizex
;	sta ball_sizey
;	stz ball_sizex+1
;	stz ball_sizey+1
	SHOW ball_SCB
	lda xx2
	sta ball_x
	lda yy2
	sta ball_y
;	lda verticesz,y
;	eor #$ff
;	sta ball_sizex
;	sta ball_sizey
	SHOW ball_SCB
	lda xx3
	sta ball_x
	lda yy3
	sta ball_y
;	lda verticesz,y
;	sta ball_sizex
;	sta ball_sizey
	SHOW ball_SCB
	dec face_counter
	bmi .draw_3d_exit
	jmp draw_3d_loop
.draw_3d_exit
	rts	



************PALETTE*************

ddp

	include "bw.pal"
;	include "ball16x16_2.pal"
	include "ball20x20-12c.pal"
	
	include "nordlicht.pal"
	include "ball16x16b.pal"
	include "ball16x16c.pal"
;	include "face16x16.pal"
;	include "bokanoid.pal"
	include "lynx-black.pal"
	include "sv2016.pal"
	
pal3	dc.b $00,$0f,$0e,$0d,$0c,$0b,$0a,$09,$08,$07,$06,$05,$04,$08,$0d,$0f
	dc.b $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$88,$dd,$ff		





******* spritecontrol block

/* SPRCTL0 $FC80 */
#define BPP_4            0xC0
#define BPP_3            0x80
#define BPP_2            0x40
#define BPP_1            0x00
#define HFLIP            0x20
#define VFLIP            0x10
#define TYPE_SHADOW      0x07
#define TYPE_XOR         0x06
#define TYPE_NONCOLL     0x05
#define TYPE_NORMAL      0x04
#define TYPE_BOUNDARY    0x03
#define TYPE_BSHADOW     0x02
#define TYPE_BACKNONCOLL 0x01
#define TYPE_BACKGROUND  0x00

/* SPRCTL1 $FC81 */
#define LITERAL          0x80
#define PACKED           0x00
#define ALGO3            0x40
#define RENONE           0x00
#define REHV             0x10
#define REHVS            0x20
#define REHVST           0x30
#define REUSEPAL         0x08
#define SKIP             0x04
#define DRAWUP           0x02
#define DRAWLEFT         0x01

		align $100
hline_SCB        dc.b %11000100,$80|$30,0
                dc.w 0
               dc.w .triimage
hlineposx      dc.w $0020
hlineposy      dc.w $0020
hlinesizex  dc.w $0100
hlinesizey  dc.w $0100
hlinestretch dc.w $0000
hlinetilt   dc.w $0000
hlinecolor  ;dc.b $04
	dc.b $0c,$de,$f0,$00,$00,$00,$00,$00
		dc.w 0
.triimage       dc.b 2,$10,0
****************
polycol		ds 1


clear_SCB  	dc.b $c0,$80|$30,0
	        dc.w 0 ;stars_SCB_buffer
		dc.w starsPLOTdata
clear_x		dc.w 64
clear_y		dc.w 64
clear_sizex	dc.w 160
clear_sizey	dc.w 102
clear_shift	dc.w $0000
clear_tilt	dc.w 0
clear_color   dc.b $08
		dc.w 0
		  
desire_logo_SCB ;non-collidable sprite
;          dc.b %11000101,%00110000,$00 ;transparent sprite!
	  dc.b %01000001,%10110000,0
          dc.w 0 ;dsign_scb5 ;next spriteblock
dsr_adr   dc.w desire
dsr_x	  dc.w 64+79 ;160 out of screen --> skipped
dsr_y     dc.w $0040+51
dsr_sizex	  dc.w $0001 ;size x
dsr_sizey	  dc.w $0001 ;size y
dsr_stretch	  dc.w $0000 ;$0001
dsr_tilt	  dc.w $0000 ;$FFC0
;          dc.b $bc,$de,$fb,$cd,$ef,$bc,$de,$fb ;palette
	dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
;	dc.b $0A,$FE,$41,$C6,$83,$57,$29,$BD
          dc.w 0 ;end of spriteblock

desire_zoom_SCB ;non-collidable sprite
;          dc.b %11000101,%00110000,$00 ;transparent sprite!
	  dc.b %11000001,%00110000,0
          dc.w 0 ;dsign_scb5 ;next spriteblock
dsrz_adr   dc.w desire_zoom
dsrz_x	  dc.w 64+79 ;160 out of screen --> skipped
dsrz_y     dc.w $0040+51
dsrz_sizex	  dc.w $0900 ;size x
dsrz_sizey	  dc.w $0900 ;size y
dsrz_stretch	  dc.w $0000 ;$0001
dsrz_tilt	  dc.w $0000 ;$FFC0
	dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
          dc.w 0 ;end of spriteblock

lynxed_SCB ;non-collidable sprite
;          dc.b %11000101,%00110000,$00 ;transparent sprite!
	  dc.b %11000001,%00110000,0
          dc.w 0 ;dsign_scb5 ;next spriteblock
lyx_adr   dc.w lynxed
lyx_x	  dc.w 64 ;160 out of screen --> skipped
lyx_y     dc.w 64
lyx_sizex	  dc.w $0100 ;size x
lyx_sizey	  dc.w $0100 ;size y
lyx_stretch	  dc.w $0000 ;$0001
lyx_tilt	  dc.w $0000 ;$FFC0
	dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
          dc.w 0 ;end of spriteblock


			  
;********************
; Redirection Table *
;********************
HandyMusic_Redirect_Volume::		dc.b $20,$28,$30,$38
HandyMusic_Redirect_FeedBackReg::	dc.b $21,$29,$31,$39
HandyMusic_Redirect_DirectVol::		dc.b $22,$2A,$32,$3A
HandyMusic_Redirect_ShiftRegLo::	dc.b $23,$2B,$33,$3B
HandyMusic_Redirect_TimerBack::		dc.b $24,$2C,$34,$3C
HandyMusic_Redirect_TimerCont::		dc.b $25,$2D,$35,$3D
HandyMusic_Redirect_AudioExtra::	dc.b $27,$2F,$37,$3F
HandyMusic_RegisterRedirectHi	dc.b 1 

	

****************
* music file!!!
;  path

		align $100
sintab 		ibytes <sintab160.dat>
sintab2		ibytes <sinplasma.dat>
sintab3		ibytes <sintab64.dat>
		ibytes <sintab64.dat>

xbuff		ds 160
ybuff		ds 102
zoomtab		ibytes <zoomtab.dat>


	align $100
object2	include "sphere64faces32vertices.src"
	include "object5.src"
	
	;include "sphere_bobs.src"
	include "pyramid_bobs.src" ;****
;	include "ball_bobs.src"
	include "wave_bobs.src" ;*****

;	include "object6.src" ;sphere

;	include "torus_bobs.src"
						
	align $0100
sintab_rotl ibytes "sin14bit.dat"
sintab_roth	equ sintab_rotl+$0200
costab_rotl	equ sintab_rotl+$0040
costab_roth	equ sintab_rotl+$0240

ztabl
	ibytes "ztab13l.dat"
ztabh
	ibytes "ztab13h.dat" ;11b


;		align $100

desire	
	ibytes "desire_160x101.spr"
	
ballsprite
;	ibytes "ball16x16_2.spr"
	ibytes "ball20x20-12c.spr"

ballsprite2
	ibytes "ball16x16b.spr"
;	ibytes "ball16x16c.spr"
ballsprite3	ibytes "ball16x16c.spr" ;ibytes "face16x16.spr"		
font	ibytes "c:\jac\wudsn\Workspace\Atari800\Nordlicht2016\data\fontall.spr"

		
; Du kannst zwar irgendwo in einem sprite (textur) anfangen, d.h. die 
; anfangsadresse anpassen, aber du kannst nicht dafuer sorgen, dass nach 
; einer zeile abgebrochen wird.
; Zumindest nicht, ohne vorher, die spritedaten zu modifizieren.

; vereinfacht sehen die daten so aus:

; byte LAENGE in bytes (offset zur naechten Zeile), 0 sprite ende
; bytes[LAENGE (-1?)] spritedaten
; byte LAENGE in bytes (offset zur naechten Zeile), 0 sprite ende
; bytes[LAENGE (-1?)] spritedaten
; byte 0 ; ende

; [21:49:43] Oswald: this is the blitter:
; [21:49:44] Oswald: xstart = spritex
; for y=ystart to yend
 ; xstart=xstart+tilt
 ; hsize=hsize+stretch
 ; for x = xstart to xend
       ; x=x+hsize
  ; next x
; next y
; [21:51:02] Oswald: oh add one line fo plotting..  x,y are in sprite texture
; [21:51:19] Oswald: and everything is 16 bit, hi bytes are pixel
; [21:51:20] Oswald: s
		
char_SCB 	;non-collidable sprite
	  	dc.b %01000101,%10110000,0
next_char_SCB   dc.w stars_SCB_buffer+29
char_adr   	dc.w font+37*33 ;space
char_x	  	dc.w 64+40 
char_y     	dc.w $0050
char_sizex	dc.w $0100 ;size x
char_sizey	dc.w $0100 ;size y
char_stretch	dc.w $0000 ;$0001
char_tilt	dc.w $0000 ;$FFC0
		dc.b $0e,$ef,$44,$44,$44,$44,$44,$44

          	dc.w 0 ;end of spriteblock
init_ball_SCB 	;non-collidable sprite
	  	dc.b %11000101,%10110000,0
		dc.w stars_SCB_buffer
ball_spr_adr 	dc.w ballsprite
	  	dc.w -1 
	     	dc.w -1
		dc.w $0400 ;size x
		dc.w $0400 ;size y
		dc.w $0000 ;$0001
		dc.w $0000 ;$FFC0
		dc.b $04,$56,$78,$9a,$bc,$de,$f0,$00
          	dc.w 0 ;end of spriteblock
	
ball_SCB 	;non-collidable sprite
	  	dc.b %11000101,$98,0
next_ball_SCB   dc.w stars_SCB_buffer+29-12
ball_adr   	dc.w ballsprite
ball_x	  	dc.w 0 
ball_y     	dc.w 0
ball_sizex	dc.w $0100 ;size x
ball_sizey	dc.w $0100 ;size y
;ball_stretch	dc.w $0000 ;$0001
;ball_tilt	dc.w $0000 ;$FFC0
;		dc.b $01,$23,$45,$67,$89,$ab,$cd,$ef
          	dc.w 0 ;end of spriteblock

init_stars_SCB  dc.b $c0,$90,0
	        dc.w stars_SCB_buffer
		dc.w starsPLOTdata
		dc.w -1
		dc.w -1
init_stars_size  dc.w $0200,$0200
stars_color   dc.b $0f
		dc.w 0

  
;generate 729 single plots reuse palette
stars_SCB:
	         dc.b $c0,$80,00
next_stars_SCB   dc.w stars_SCB_buffer+15
	         dc.w starsPLOTdata
stars_x        	 dc.w $0080
stars_y          dc.w $0040
		 dc.b $0f		 
starsPLOTdata     dc.b 2,$10,0
lynxed 
stars_SCB_buffer ;ds (729-106)*15
desire_zoom
	ibytes "nordlicht.spr"

ende	set	*
echo "Ende: %Hende"
codestart set ende-codestart
ECHO "Codesize: %dcodestart"
ende	set $FC00-ende
echo "Free for MOD: %dende"
