;======================================================================================================================
;                         _____                        .__               
;    ___________ ___.__. /  _  \   ____   ____    ____ |__| ____   ____  
;  _/ ___\_  __ <   |  |/  /_\  \_/ __ \ /    \  / ___\|  |/    \_/ __ \ 
;  \  \___|  | \/\___  /    |    \  ___/|   |  \/ /_/  >  |   |  \  ___/ 
;   \___  >__|   / ____\____|__  /\___  >___|  /\___  /|__|___|  /\___  >
;       \/       \/            \/     \/     \//_____/         \/     \/
;
; cryAEngine - a small (assembler) gameengine for the Amiga
;
; GameObjects, LevelPlayfields, Structure with Title,Menu,About and Ingame 
; 
; part of the CHLUDENS.ch project by gamelab.zhdk.ch
; code by rene.bauer AT zhdk.ch
;
; Some Code from  Massimo Bonnucchi
;======================================================================================================================

;======================================================================================================================
; made with and for VisualStudioCode and Amiga-Assembly-Modul 
; (FS-LUAE: Ctrl+w > fast forward)
;======================================================================================================================

;======================================================================================================================
; Features:
;
; Frame with
; - Titlescreen
; - Menuscreen
; - About etc.
; All editable in the BlockLevelEditor
;
; Blocks:
; - LevelField 16x16 Blocks = 20X16 Blocks
; - drawLevel
; - setBlock
; - getBlock (xy)
; - BlockLevelEditor in Processing (Export to your System)
;   Exports .json & .asm (direct integretable)
;
; SmallBlocks (Only Rendering):
; drawSmallBlock
; 
; 
; Text:
; - Integrated Font (16x16 & 8x8)
; - drawBlockText
; - drawText
; 
;======================================================================================================================

; ATTENTION:
; INCBIN ONLY IN C_DATA.s	

; ---------------------
; TITLE-SCREEN
; ---------------------
; Image-Data
; C_DATA.s
; - exported by https://www.stef.be/dpaint/ > Save as > planes
; colors:
; C_COPPER.S
; - exported by https://www.stef.be/dpaint/ > Save as > planes > .palette.xt
; > GenericCols:

; ---------------------
; BLOCKS
; ---------------------
; use Processing-Tool

; ---------------------
; SPRITE
; ---------------------
; use Processing-Tool

; ---------------------
; CODING
; ---------------------
; ATTENTION: DONT USE D7,D6,A7,A& 
; IS SOMEHOW NEEDED BY MUSIC AND MOUSE

; ------------------------------
; 68000 KNOWHOW
; ------------------------------

; 68k online ausprobieren
; https://asm-editor.specy.app/projects/GuILvBB

; CLR.[B/W/L]
; ADD.[B/W/L]
; SUB.[B/W/L]
; MOVE.[B/W/L]
; SWAP.[B/W/L]

; WITHOUT .B/W/L > WORD
; MOVE #4,d0 MEANS MOVE.W #4,d0!!!

; MULTIPLY:
; ROL ETC 
; DIV[U|S] / (int)   W1: RESULT  W2: REST %
; MUL[U|S] * (int)
;
; Data-Register: d0-d7
; Adress-Register: a0-a7
; 
; CMP.[B/W/L]
; BNE/BEQ etc.
;
; UNSIGMED
; BHI.w >
; BCS.w <
;
; SIGNED
; BGT.w >
; BLT.w <
;

;         even
; label:  must be even for 68k!

; DBRA: FOR-NEXT
;    move.l #10
; lab:
;    dbra d0,lab


;
; COPPER - graphic processor binded to crt-raster
;
; If you install a copper list, this will be executed forever! 
; but you can put labels and write direct there !
;
; commands WAIT,MOVE,SKIP
;  
;
; water ... 
;		; data, command
;		; will be always executed
;		DC.W    $9601,$FF00 	; wait for line 150
;		dc.w	$0180,$0fff   ; set color

; ---------------------------------
; GAMEENGINE PRESETS
; ---------------------------------

; debug - no go to black
ModeBlack equ 1 ; debug set to 0

; menu active in menu?
MouseMenuActive equ 0

; ingame
gui_score_x equ 16
gui_hscore_x equ 5

     
; ---------------------------------
; GAMEENGINE DOUBLE BUFFERING
; ---------------------------------

; simple version without bobs: experiment
;
; double-buffering-version:
; idea: change playfield > update playfield-change-map or two! 
;       repaint then before next
;       perhaps a version behind always up to date - render to frontend   
;       1 change     playfield
;       2 change bob remove again           
;


	section	GameCode,CODE_P

;======================================================================================================================
; Startup File
; Makes sure we take control of the OS the proper way
;======================================================================================================================

	include	"lib/startup.s"

;======================================================================================================================
; Which DMAs we will enable
;
; 15	SET/CLR	Set/Clear control bit.
;				Determines if bits written with a 1 get set or cleared
;			    Bits written with a zero are unchanged
; 14	BBUSY	Blitter busy status bit (read only)
; 13	BZERO	Blitter logic zero status bit (read only)
; 12	X	
; 11	X	
; 10	BLTPRI	Blitter DMA priority (also called "blitter nasty" for stealing from CPU)
; 09	DMAEN	Enable all DMA below (also UHRES DMA)
; 08	BPLEN	Bit plane DMA enable
; 07	COPEN	Coprocessor DMA enable
; 06	BLTEN	Blitter DMA enable
; 05	SPREN	Sprite DMA enable
; 04	DSKEN	Disk DMA enable
; 03	AUD3EN	Audio channel 3 DMA enable
; 02	AUD2EN	Audio channel 2 DMA enable
; 01	AUD1EN	Audio channel 1 DMA enable
; 00	AUD0EN	Audio channel 0 DMA enable
;======================================================================================================================

								;5432109876543210
DMASET					equ		%1000001110101111	; Enable Copper, Bitplane DMA, Sprite DMA, Sound DMA

WaitDisk				equ		30		; Defined in Startup.s : Time to wait 50-150 to save/load (50 = 1 second in Pal system)

;======================================================================================================================
; Game Source Files + Data Files
;======================================================================================================================

; Game Constants
		include	"Source/HWConstants.s"
		include	"Source/Constants.s"

; Game Core Files
		include	"Source/Utils.s"
		include	"Source/Player.s"
		include	"Source/Enemies.s"
		include	"Source/GameOver.s"
		include	"Source/Intro.s"
		include	"Source/Hud.s"
		include	"Source/GameCore.s"
		include	"Lib/music.s"

; Game Data Files
		include	"Source/VarTables.s"
		include	"Source/Data.s"

;======================================================================================================================
; Main Program Start
;======================================================================================================================

START:
		;--------------------------------------------------------------------------------------------------------------
		; Saving everything for startup file
		;--------------------------------------------------------------------------------------------------------------

		movem.l	d0-d7/a0-a6,-(SP)

		bsr.w	WaitForRaster

		;--------------------------------------------------------------------------------------------------------------
		; The following is more setup to complete the startup file 
		;--------------------------------------------------------------------------------------------------------------

		; Custom Chips HW Base Address
		lea		$dff000,a5

		; DMA Set / Enable
		move.w	#DMASET,$96(a5)		; DMACON - Enable Bitplane, Copper DMA, Sprties

		; Disable AGA for compatibility
		move.w	#0,$1fc(a5)			; Disable AGA
		move.w	#$c00,$106(a5)		; Disable AGA
		move.w	#$11,$10c(a5)		; Disable AGA

		;--------------------------------------------------------------------------------------------------------------
		; Init Music
		;--------------------------------------------------------------------------------------------------------------

		move.l	#GameScreenBitplanes,d0		; Source Image Address that is the address of Bitplane 1
		lea		GameBitplanePointers,a0		; Bitplane Pointers in the Copper
		moveq.l	#NoOfBpls-1,d1				; Number of Bitplanes
		move.l	#BitplaneSize,d2			; Add the bitplane size to the source start Image Address
		bsr.w	SetBitPlanes				; Set the Bitplane Pointers

;		bsr.w	CheckForJoystickFire

;		bsr.w	mt_init


		; ----------------------
		; BLITTER ENABLING
		; ----------------------
		move.w #$8040,$dff096 ; enable blitter
		; move.w #$87e0,$dff096
		
		;--------------------------------------------------------------------------------------------------------------
		; Init Main Game Screen
		; This only need to be initialised once
		;--------------------------------------------------------------------------------------------------------------

		bsr.w	InitBitPlanes
		bsr.w	InitColours

		;--------------------------------------------------------------------------------------------------------------
		; Init the Intro Screen
		;--------------------------------------------------------------------------------------------------------------


	.Intro:
		; Init the Intro Screen Bitplanes and Colours
		bsr.w	InitIntroScr  ; wird nachträglich gemacht!
		; bsr.w	SetIntroCol	

		;--------------------------------------------------------------------------------------------------------------
		; The following is more setup to complete the startup file 
		;--------------------------------------------------------------------------------------------------------------

		; Custom Chips HW Base Address
		lea		$dff000,a5

		; Init Copper
		move.l	#GenericScreen,$80(a5)	; Point to our copper
		move.w	d0,$88(a5)			; Init our copper

		;--------------------------------------------------------------------------------------------------------------
		; Play Music while we wait for the user to press the fire button
		; and also till the player releases the fire button
		;--------------------------------------------------------------------------------------------------------------

; 		bsr.w	mt_music

	 	; jmp ingame
demoLoop:

		
		add.w #1,updown
		clr.l d0
		move.w updown,d0
		add.w  #1,d0
		move.w d0,updown

		cmp.w #90,updown
		blt   nothingtodo
		move.w #0,updown
nothingtodo:


	;	cmp.l #10,offsetYCounter
	;	blt   offsetYDone
	;	move.l #0,offsetYCounter

		;add.l #1,offsetY
		;cmp.l #30,offsetY
		;blt   offsetYDone
		;move.l #0,offsetY
offsetYDone:

	; bsr.w	WaitForRaster	

;	bsr rainbow


		; display a bob (blitterobject)
		; jsr BlitWait
		; kills the rastereffect!
		; jsr BlitSomething

; w 		=320

ww 		=320

bltx	=20
blty    =0
bltoffs =blty*(ww/8)+bltx/8

; position
bltxd	=20
bltyd    =130
bltoffsd =bltyd*(ww/8)+bltxd/8
; size
bltw	=224/16
blth 	=100
bltskip =(320-224)/8

bcorner  = (blth-1)*(ww/8)+bltw*2-1


		; enable blitter
		move.w #$8040,$dff096 ; enable blitter

		; blitter:
		; mask > shift (scroll) > combine




		; copy whole screen
		; GameScreenBitplanes
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset

		; jmp nocopyscreen

		; copy screen
		lea GameScreenBitplanes,a5
		lea IntroScreen,a4
		; jsr copyScreenDirect

		; some bobs

		move.l #10,d3
allofthem:

		; render a bob with id 
		move.w 	#1,bob1616_id

		move.w  #1,bob1616_x
		move.l d3,d2
		mulu   #4,d2
		add.w   d2,bob1616_x

		move.w updown,d1
	 	add.w  d1,bob1616_x

		move.w  #110,bob1616_y
		add.w   d2,bob1616_y
		move.w updown,d1
		add.w  d1,bob1616_y 
		
		jsr renderBob1616

		dbra d3,allofthem


		bsr rainbow

		jmp demoLoop





; -----------------------
; blitter: bob 16x16 
; -----------------------
		jmp nobobit16

					lea $dff000,a6  ; blitter base 
					move.w #$8040,DMACON(a6) ; enable blitter with offset
					tst DMACONR(a6); $dff002
			.waitblittingbob16:
					btst #6,DMACONR(a6); $dff002
					bne .waitblittingbob16:
					; 1 - destination
					;         3210  
					; sources ABCD
					;         1001
					;         > 9 
					; copy from A pointer to D pointer!
					; move.l #$09000000,BLTCON0(a6);$dff040	mode	
					;          ^^ locial combination
					; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
					; MINDTERM
					;       ABCD  > D 
					;	0	000     0  
					;   1   001		0
					;   2   010		0
					;   3   011		0
					;   4   100 	1
					;   5   101		1
					;   6   110		1
					;   7   111 	1 < first bit
					;               ^ 8 bits
					;               > %111100000 > f0
					;       1001 > combine => 9
					;  
					; several channels
					; > combine to create a new
					; >> A ~ B > D
					; 
					; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
					; add xor...
					;       ABCD  > D 
					;	0	000     0  
					;   1   001		0
					;   2   010		1
					;   3   011		1
					;   4   100 	1
					;   5   101		1
					;   6   110		1
					;   7   111 	1 < first bit
					;   
					;               %11111100 > FC
					;       1101  >>>>> D		
					;               TOTAL DFC 
					;               xor
					; 
					; BOB
					; https://www.youtube.com/watch?v=OLhhgfnNo9A&t=1215s
					; A cloud mask
					; B cloud
					; C destination playfield
					; D destination playfield
					; 1.0
					; xor
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
			;		move.l #$09f00000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					;        ^ shift!   
					; 2.0
					; mask
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
			;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
					; move.l #$01fff000,$dff040	
					; start/ressource	
					; ressource
					lea bob1616_1_mask,a2
			;		lea testblockone,a0		
					lea bob1616_1,a0		
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					; target
					lea IntroScreen,a3	
					; bltyd*(ww/8)+bltxd/8
					add.l #60*40+120/8,a3
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					; same target
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	

					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					; x. end
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		
					; *64 highword: height, lowword: width


					; planet1
					tst DMACONR(a6); $dff002
			.waitblittingbob1116:
					btst #6,DMACONR(a6); $dff002
					bne .waitblittingbob1116
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
					lea bob1616_1_mask,a2
			;		lea testblockdouble,a0		
					lea bob1616_1,a0
					add.l #(16/8+0)*16,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					lea IntroScreen,a3
					add.l #60*40+120/8,a3
					add.l  #40*256,a3	
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	
					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

					; planet1
					tst DMACONR(a6); $dff002
			.waitblittingbob11216:
					btst #6,DMACONR(a6); $dff002
					bne .waitblittingbob11216
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
					lea bob1616_1_mask,a2
			;		lea testblockdouble,a0		
					lea bob1616_1,a0
					add.l #2*(16/8+0)*16,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					lea IntroScreen,a3
					add.l #60*40+120/8,a3
					add.l  #2*40*256,a3	
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	
					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

					; planet1
					tst DMACONR(a6); $dff002
			.waitblittingbob112316:
					btst #6,DMACONR(a6); $dff002
					bne .waitblittingbob112316
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
					lea bob1616_1_mask,a2
			;		lea testblockdouble,a0		
					lea bob1616_1,a0
					add.l #3*(16/8+0)*16,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					lea IntroScreen,a3
					add.l #60*40+120/8,a3
					add.l  #3*40*256,a3	
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	
					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		


nobobit16;
	


		jmp nobobit32

; -----------------------
; blitter: bob 32x32 
; -----------------------

		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		tst DMACONR(a6); $dff002
.waitblittingbob:
		btst #6,DMACONR(a6); $dff002
		bne .waitblittingbob:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
		; add xor...
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		1
		;   3   011		1
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;   
		;               %11111100 > FC
		;       1101  >>>>> D		
		;               TOTAL DFC 
		;               xor
		; 
		; BOB
		; https://www.youtube.com/watch?v=OLhhgfnNo9A&t=1215s
		; A cloud mask
		; B cloud
		; C destination playfield
		; D destination playfield
 		; 1.0
		; xor
		move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
;		move.l #$09f00000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!   
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		; ressource
		lea testmask,a2
;		lea testblockone,a0		
		lea testblockone,a0		
		move.l a2,BLTAPTH(a6); $dff054  ; high & low
		move.l a0,BLTBPTH(a6); $dff054  ; high & low
		; target
		lea IntroScreen,a3	
;		add.l #60*40*256,a3
		move.l a3,BLTCPTH(a6); $dff054  ; high & low
		move.l a3,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #0,BLTAMOD(a6); $dff066
		move.w #0,BLTBMOD(a6); $dff066	

		move.w #(320-32)/8,BLTCMOD(a6)
		move.w #(320-32)/8,BLTDMOD(a6)
		; x. end
		move.w #32*64+32/16,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width


		; planet1
		tst DMACONR(a6); $dff002
.waitblittingbob11:
		btst #6,DMACONR(a6); $dff002
		bne .waitblittingbob11
		move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		lea testmask,a2
;		lea testblockdouble,a0		
		lea testblockone,a0
		add.l #32/8*32,a0
		move.l a2,BLTAPTH(a6); $dff054  ; high & low
		move.l a0,BLTBPTH(a6); $dff054  ; high & low
		lea IntroScreen,a3
		add.l  #40*256,a3	
		move.l a3,BLTCPTH(a6); $dff054  ; high & low
		move.l a3,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #0,BLTBMOD(a6); $dff066	
		move.w #(320-32)/8,BLTCMOD(a6)
		move.w #(320-32)/8,BLTDMOD(a6)
		move.w #32*64+32/16,BLTSIZE(a6) ; $dff058 ; set size		

		; planet1
		tst DMACONR(a6); $dff002
.waitblittingbob112:
		btst #6,DMACONR(a6); $dff002
		bne .waitblittingbob112
		move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		lea testmask,a2
;		lea testblockdouble,a0		
		lea testblockone,a0
		add.l #2*32/8*32,a0
		move.l a2,BLTAPTH(a6); $dff054  ; high & low
		move.l a0,BLTBPTH(a6); $dff054  ; high & low
		lea IntroScreen,a3
		add.l  #2*40*256,a3	
		move.l a3,BLTCPTH(a6); $dff054  ; high & low
		move.l a3,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #0,BLTBMOD(a6); $dff066	
		move.w #(320-32)/8,BLTCMOD(a6)
		move.w #(320-32)/8,BLTDMOD(a6)
		move.w #32*64+32/16,BLTSIZE(a6) ; $dff058 ; set size		

		; planet1
		tst DMACONR(a6); $dff002
.waitblittingbob1123:
		btst #6,DMACONR(a6); $dff002
		bne .waitblittingbob1123
		move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		lea testmask,a2
;		lea testblockdouble,a0		
		lea testblockone,a0
		add.l #3*32/8*32,a0
		move.l a2,BLTAPTH(a6); $dff054  ; high & low
		move.l a0,BLTBPTH(a6); $dff054  ; high & low
		lea IntroScreen,a3
		add.l  #3*40*256,a3	
		move.l a3,BLTCPTH(a6); $dff054  ; high & low
		move.l a3,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #0,BLTBMOD(a6); $dff066	
		move.w #(320-32)/8,BLTCMOD(a6)
		move.w #(320-32)/8,BLTDMOD(a6)
		move.w #32*64+32/16,BLTSIZE(a6) ; $dff058 ; set size		


	
nobobit32:


		jmp noblocks1616

; -----------------------
; blitter: display 16x16 
; -----------------------
; data must be in chipmemory 
; include there!!

; CHAN set up here and only here
; A 	cloud data
; D		destination playfield


pbltskip =(320-32)/16

; LogoData
; 178x67x3

		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		tst DMACONR(a6); $dff002
.waitblitting5:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitting5:
				
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		; move.l #testblock,d0
		move.l #block88,d0 ;-()

		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+90*(ww/8)+12/8,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #0,BLTAMOD(a6); $dff066
		move.w #(320-16)/8,BLTDMOD(a6); $dff066	
		; x. end
		move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

		tst DMACONR(a6); $dff002
.waitblitting57:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitting57:
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		move.l #block88+16*16/8,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+90*(ww/8)+12/8+40*256,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #(320-16)/8,BLTDMOD(a6); $dff066	
		move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

		tst DMACONR(a6); $dff002
.waitblitting571:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitting571:
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		move.l #block88+2*16*16/8,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+90*(ww/8)+12/8+40*256*2,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #(320-16)/8,BLTDMOD(a6); $dff066	
		move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

		tst DMACONR(a6); $dff002
.waitblitting5711:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitting5711:
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		move.l #block88+3*16*16/8,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+90*(ww/8)+12/8+40*256*3,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #(320-16)/8,BLTDMOD(a6); $dff066	
		move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

noblocks1616:

		
	jmp nobobs

; --------------------------
; BOB - BlitObject
; --------------------------
; CHAN set up here and only here
; A 	cloud mask
; B	 	cloud data
; C 	destination playfield
; D		destionation playfield

cloudw = 112
cloudh = 38


		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		tst DMACONR(a6); $dff002
.waitblitting:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitting:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
		; add xor...
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		1
		;   3   011		1
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;   
		;               %11111100 > FC
		;       1101  >>>>> D		
		;               TOTAL DFC 
		;               xor
		; 
		; BOB
		; https://www.youtube.com/watch?v=OLhhgfnNo9A&t=1215s
		; A cloud mask
		; B cloud
		; C destination playfield
		; D destination playfield
 		; 1.0
		; xor
		move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
;		move.l #$09f00000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!   
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		; ressource
		lea CloudMask,a2
		lea Cloud,a0
		move.l a2,BLTAPTH(a6); $dff054  ; high & low
		move.l a0,BLTBPTH(a6); $dff054  ; high & low
		; target
		lea IntroScreen,a3	
		; add.l #1*40*256,a3
		move.l a3,BLTCPTH(a6); $dff054  ; high & low
		move.l a3,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #0,BLTAMOD(a6); $dff066
		move.w #0,BLTBMOD(a6); $dff066	

		; _bltskip =(320-224)/8
	
abcskip =320/8-cloudw/8
; bltskip =(320-224)/8

		move.w #abcskip,BLTCMOD(a6)
		move.w #abcskip,BLTDMOD(a6)
		; x. end
		move.w #cloudh*64+cloudw/16,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width
	

nobobs:

; --------------------------
; SCROLLEN NACH LINKS
; --------------------------
; descending mode
		jmp noscrollingsx

		lea $dff000,a6  ; blitter base 
		move.w #$8440,DMACON(a6) ; enable blitter with offset
		; 0. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptt:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptt:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
	
		move.l #$19f00002,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		;               ^ umgekehrte richtung
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bcorner,d0
;		move.l offsetY,d1 
;		mulu   #40,d1
;		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		; new lower right (umgekehrte richtung!)
		; move.l #IntroScreen+bcorner,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bcorner,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		; move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptt1:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptt1:
	
		move.l #$19f00002,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		;               ^ umgekehrte richtung
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bcorner+40*256,d0
;		move.l offsetY,d1 
;		mulu   #40,d1
;		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		; new lower right (umgekehrte richtung!)
		; move.l #IntroScreen+bcorner,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bcorner+40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		; move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

; 2. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptt12:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptt12:
	
		move.l #$19f00002,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		;               ^ umgekehrte richtung
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bcorner+2*40*256,d0
;		move.l offsetY,d1 
;		mulu   #40,d1
;		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		; new lower right (umgekehrte richtung!)
		; move.l #IntroScreen+bcorner,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bcorner+2*40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		; move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

; 3. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptt123:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptt123:
	
		move.l #$19f00002,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		;               ^ umgekehrte richtung
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bcorner+3*40*256,d0
;		move.l offsetY,d1 
;		mulu   #40,d1
;		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		; new lower right (umgekehrte richtung!)
		; move.l #IntroScreen+bcorner,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bcorner+3*40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		; move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width
noscrollingsx:




		jmp no_xor


; --------------------------
; XR - NOT 100%!!
; --------------------------

		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 0. plane
		tst DMACONR(a6); $dff002
.waitblitxttttpt:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttpt:

		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
		; add xor...
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		1
		;   3   011		1
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;   
		;               %11111100 > FC
		;       1101  >>>>> D		
		;               TOTAL DFC 
		;               xor
		; 
		; extra channel for outline 
 		; 1.0
		; xor
		move.l #$0dfc0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bltoffsd,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptu:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptu:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
		; add xor...
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		1
		;   3   011		1
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;   
		;               %11111100 > FC
		;       1101  >>>>> D		
		;               TOTAL DFC 
		;               xor
		; 
		; extra channel for outline 
 		; 1.0
		; xor
		move.l #$0dfc0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs+40*256,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd+40*256,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bltoffsd+40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

; 2. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptut:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptut:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
		; add xor...
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		1
		;   3   011		1
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;   
		;               %11111100 > FC
		;       1101  >>>>> D		
		;               TOTAL DFC 
		;               xor
		; 
		; extra channel for outline 
 		; 1.0
		; xor
		move.l #$0dfc0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs+2*40*256,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd+2*40*256,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bltoffsd+2*40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

; 3. plane
		tst DMACONR(a6); $dff002
.waitblitxttttptutz:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttptutz:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;  
		; several channels
		; > combine to create a new
		; >> A ~ B > D
		; 
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
		; add xor...
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		1
		;   3   011		1
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;   
		;               %11111100 > FC
		;       1101  >>>>> D		
		;               TOTAL DFC 
		;               xor
		; 
		; extra channel for outline 
 		; 1.0
		; xor
		move.l #$0dfc0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs+3*40*256,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd+3*40*256,BLTBPTH(a6); $dff054  ; high & low
		move.l #IntroScreen+bltoffsd+3*40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTBMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

no_xor:



; --------------------------
; COPY A RECT (SCR TO SCR )
; --------------------------

		jmp scrollframe

		add.l #1,offsetYCounter
		cmp.l #3,offsetYCounter
		blt   offsetYDoneX
		move.l #0,offsetYCounter

		add.l #1,offsetY
		cmp.l #30,offsetY
		blt   offsetYDoneX
		move.l #0,offsetY
offsetYDoneX:

; PLANE 0
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttttp:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttp:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width
; copy with mask 
; PLANE 1
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttttpu:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttpu:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs+40*256*1,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd+40*256,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width
; PLANE 2
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttttpuu:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttpuu:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs+40*256*2,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd+40*256*2,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

; PLANE 3
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttttpuut:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttttpuut:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		; 1.0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs+40*256*3,d0
		move.l offsetY,d1 
		mulu   #40,d1
		add.l  d1,d0
		move.l d0,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffsd+40*256*3,BLTDPTH(a6); $dff054  ; high & low
		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width


scrollframe:





		jmp withmask

		; copy with mask 
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxtttt:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxtttt:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		; 1.0
		move.l #$89f00000,BLTCON0(a6);$dff040	mode	
		;        ^ shift!
		; 2.0
		; mask
		move.l #$ffffffff,BLTAFWM(a6) ; mask 

;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffs,BLTDPTH(a6); $dff054  ; high & low

		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066
	
		; x. end
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

withmask:


		jmp cpwwithmask

		; enable blitter
		move.w #$8040,$dff096 ; enable blitter

		; copy with mask 
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxttt:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxttt:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	

		; mask
		move.l #0,BLTAFWM(a6) ; mask 

;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffs,BLTDPTH(a6); $dff054  ; high & low

		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066
	
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

cpwwithmask:

		jmp copytoitself

		; blit copy something to itself ... 
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitxtt:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitxtt:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://youtu.be/0KhiHOfmeLw?si=f_-YiA0JTOsrJrEx&t=1595
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		move.l #$09f00000,BLTCON0(a6);$dff040	mode	
 
;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040	
		; start/ressource	
		move.l #IntroScreen+bltoffs,BLTAPTH(a6); $dff054  ; high & low
		; target
		move.l #IntroScreen+bltoffs,BLTDPTH(a6); $dff054  ; high & low

		; same target
		move.w #bltskip,BLTAMOD(a6); $dff066
		move.w #bltskip,BLTDMOD(a6); $dff066
	
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

copytoitself:

		; https://www.youtube.com/watch?v=0KhiHOfmeLw&t=5s
		jmp relativeversion_black
		lea $dff000,a6  ; blitter base 
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		; 1. plane
		tst DMACONR(a6); $dff002
.waitblitx:
		btst #6,DMACONR(a6); $dff002
		bne .waitblitx:

		move.l #$01000000,BLTCON0(a6);$dff040	mode	
		; move.l #$01fff000,$dff040		
		move.l #IntroScreen+bltoffs,BLTDPTH(a6); $dff054  ; high & low
		move.w #bltskip,BLTDMOD(a6); $dff066
		move.w #blth*64+bltw,BLTSIZE(a6) ; $dff058 ; set size		

relativeversion_black:

		jmp blackSquare

		; enable blitter
		move.w #$8040,$dff096 ; enable blitter

		; https://www.youtube.com/watch?v=6LQ5xGnG6Fk
		; clear a part of the screen

		; 1. plane
		tst $dff002
waitblitxx:
		btst #14-8,$dff002
		bne waitblitxx:
		move.l #$01000000,$dff040		
		move.l #$01fff000,$dff040		
		move.l #IntroScreen+bltoffs,$dff054
		move.w #bltskip,$dff066
		move.w #blth*64+bltw,$dff058 ; set size

		; 2. plane
		tst $dff002
waitblity:
		btst #14-8,$dff002
		bne waitblity:
		move.l #$01000000,$dff040		
		move.l #$01fff000,$dff040		
		move.l #IntroScreen+40*256+bltoffs,$dff054
		move.w #bltskip,$dff066
		move.w #blth*64+bltw,$dff058 ; set size

		; 3. plane
		tst $dff002
waitblityy:
		btst #14-8,$dff002
		bne waitblityy:
		move.l #$01000000,$dff040		
		move.l #$01fff000,$dff040		
		move.l #IntroScreen+40*256*2+bltoffs,$dff054
		move.w #bltskip,$dff066
		move.w #blth*64+bltw,$dff058 ; set size

		; 4. plane
		tst $dff002
waitblityyz:
		btst #14-8,$dff002
		bne waitblityyz:
		move.l #$01000000,$dff040		
		move.l #$01fff000,$dff040		
		move.l #IntroScreen+40*256*3+bltoffs,$dff054
		move.w #bltskip,$dff066
		move.w #blth*64+bltw,$dff058 ; set size

blackSquare:




		
		; ---------------------------
		; BACK TO AMIGADOS
		; ---------------------------

; movem.l	d0-d7/a0-a6,-(SP)
		movem.l	(SP)+,d0-d7/a0-a6

		rts

	even
cloudx:
	dc.w 0

;======================================================================================================================
; Prints a Character to the screen
;======================================================================================================================

DrawText:
	MOVE.L	StrCodingPtr(PC),A0			; Text Address in a0
	MOVEQ	#0,D2					; Clear d2
	MOVE.B	(A0)+,D2				; Next Char d2
	CMP.B	#$ff,d2					; End of text? ($FF)
	beq.s	XText_Exit				; Yes - Exit
	TST.B	d2						; End of Line? ($00)
	bne.s	XNotEOL					; No Not End Of Line

	ADD.L	#20*7,XBitplanePtr		; Screen is 40 byte wide and the font is 8 bytes high
	ADDQ.L	#1,StrCodingPtr				; Hold the column on the on the screen or where we are on the current line
									; hence reset it to 1 since we are starting a new line
	move.b	(a0)+,d2				; First character on the line skipping 0

XNotEOL:
	SUB.B	#$20,D2					; Subtract 32 from the char ASCII value 
									; so that we can transform for example
									; if it was a space which is $20 to a $00
									; the asterics $21 to $01 etc etc
	LSL.W	#3,D2					; Multiply the same number by 8,
									; since the font is 8 pixels high
	MOVE.L	D2,A2					; move the multiplication result to A2
	ADD.L	#XFont,A2				; Add the value in A2 to the font Base address

	; Display char on bitplanes
	MOVE.L	XBitplanePtr(PC),A3		; Bitplane Address in a3
	MOVE.B	(A2)+,40*0(A3)			; Print Line 1 of char
	MOVE.B	(A2)+,40*1(A3)			; Print Line 2 of char
	MOVE.B	(A2)+,40*2(A3)			; Print Line 3 of char
	MOVE.B	(A2)+,40*3(A3)			; Print Line 4 of char
	MOVE.B	(A2)+,40*4(A3)			; Print Line 5 of char
	MOVE.B	(A2)+,40*5(A3)			; Print Line 6 of char
	MOVE.B	(A2)+,40*6(A3)			; Print Line 7 of char
	MOVE.B	(A2)+,40*7(A3)			; Print Line 8 of char

	ADDQ.L	#1,XBitplanePtr	 		; We need to move 8 bits or 1 byte for next character
	ADDQ.L	#1,StrCodingPtr				; Next character to print

XBitplanePtr:
	dc.l	GameScreenBitplanes

XText_Exit:
	RTS

StrCodingPtr:
	dc.l	StrCoding
StrCoding:
    dc.b    "sq"
    dc.b    $ff

XFont:
	incbin	"gfx/nice.fnt"


;======================================================================================================================
;  demoSCENE
;======================================================================================================================
	even

offsetY: dc.l 0
offsetYCounter: dc.l 0

;======================================================================================================================
;  cryAengine
;======================================================================================================================
	even

gameobjects_no equ 3 //  

gameobject_size equ 18 ; members 
gameobject_size_bytes equ 36 ; gameobject_size * 2 ; word

gameobject_state equ 0
gameobject_x equ 1*2 
gameobject_y equ 2*2 
gameobject_width equ 3*2
gameobject_height equ 4*2 
gameobject_colwidth equ 5*2
gameobject_colheight equ 6*2 
gameobject_type equ 7*2
gameobject_typesub equ 8*2 
gameobject_art equ 9*2   ; 
gameobject_animtype equ 10*2  ; -- represented in a sprite
gameobject_animmin equ 11*2  ; -- represented in a sprite
gameobject_animmax equ 12*2  ; 
gameobject_animind equ 13*2 ;
gameobject_animindold equ 14*2 ;
gameobject_arg equ 15*2 ;
gameobject_behaviour equ 16*2 ;
gameobject_spr equ 17*2  ; -- represented in a sprite

; > update also length of a gameobject ^ up 

; object states 
objectstate_active equ 1
objectstate_inactive equ 0 ; moved to -16,-16 !


; behavior
behavior_standstill equ 0 ; stand still
behavior_mouse_direct equ 1 ; 
behavior_mouse_relative equ 2 ; 

; squarez behaviors
behavior_left equ 3 ; 
behavior_right equ 4 ; 
behavior_up equ 5 ; 
behavior_down equ 6 ; 
behavior_4dir_random equ 7 ; generates left>down and creates 

; holy cube behaviours
behavior_onplatform_left_fall equ 8 ; 
behavior_onplatform_right_fall equ 9 ; 
; avatar
behavior_avatar_bounce_left equ 10
behavior_avatar_bounce_right equ 11
 

; anim 
anim_indold_default equ 42000

atype_noanim equ 0
atype_loop equ 1
atype_once equ 2
atype_once_destroy equ 3

; type
type_neutral equ 0

type_transparent_animind equ 1; transparent

type_avatar equ 1

; avatar_mouse
type_avatar_mouse_atype equ atype_noanim
type_avatar_mouse_animind equ 0 ; anim

; avatar
type_avatar_atype equ atype_loop
type_avatar_animmin equ 8 ; anim
type_avatar_animind equ 9 ; anim
type_avatar_animmax equ 12 ; anim +1



type_bonus equ 2
type_bonus_atype equ atype_loop
type_bonus_animmin equ 16 ; anim
type_bonus_animind equ 17 ; anim
type_bonus_animmax equ 20 ; anim +1

type_enemy equ 3
type_enemy_animmin equ 12 ; anim
type_enemy_animind equ 13 ; anim
type_enemy_animmax equ 15+1 ; anim +1

; sub
type_enemysub_leftright equ 0
type_enemysub_updown equ 1

; ------------------------
; types
; ------------------------
; in a0 pointer to the gameobject
initType:

	cmp.w #type_avatar,gameobject_type(a0)
	bne.w init_nottheavatar
	move.w #atype_loop,gameobject_animtype(a0)
	move.w #type_avatar_animmin,gameobject_animmin(a0)
	move.w #type_avatar_animmin,gameobject_animind(a0)
	move.w #type_avatar_animmax,gameobject_animmax(a0)
	move.w #anim_indold_default,gameobject_animindold(a0)
	move.w #0,gameobject_arg(a0)
	; behavior_avatar_bounce_left
	jmp  end_inittype
init_nottheavatar:

	cmp.w #type_enemy,gameobject_type(a0)
	bne.w init_nottheenemy
	move.w #atype_loop,gameobject_animtype(a0)
	move.w #type_enemy_animmin,gameobject_animmin(a0)
	move.w #type_enemy_animmin,gameobject_animind(a0)
	move.w #type_enemy_animmax,gameobject_animmax(a0)
	move.w #anim_indold_default,gameobject_animindold(a0)
	move.w #behavior_onplatform_left_fall,gameobject_behaviour(a0)
	jmp  end_inittype
init_nottheenemy:


end_inittype:

	rts

; ------------------------
; important vars
; ------------------------
	even
game_state dc.l 0
game_state_sub dc.l 0
game_state_sub_old dc.l 0

state_intro equ 0  ; title too
state_menu equ 1
state_ingame equ 2
state_gameover equ 3

; menu
menupoint_game_state_sub dc.l 1
menupoint_game_state_sub_old dc.l 42

statesub_main equ 0
statesub_story equ 1
statesub_howto equ 2
statesub_play equ 3
statesub_about equ 4 ; or credits
statesub_higscore equ 5

statesub_gameover equ 7
statesub_won equ 8


timer dc.l   0

; for counts timer + 1
timercounter:
	 dc.l 0
timestep:
 dc.l 400


level: 	dc.l 	0
level_old: 	dc.l 	0
level_maxbonus: dc.l 4

parselevel_address: dc.l 1

score: 	dc.l 	1
old_score: dc.l  0
hscore: dc.l 	50
lifes: 	dc.l 	3
health: dc.l 	100

scoredefault: 	dc.l 	0
hscoredefault: dc.l 	100
lifesdefault: 	dc.l 	3
healthdefault: dc.l 	100

animation: dc.l 0
animation_step: dc.l 15 

; on platform
avatar_onplatform:
			dc.w  0

; some bytes to jump ... 
jump_algo:      
    dc.b 0,6,6,5,5,5,5,3,3,3,3,2,2,2,2,2,2,1,1,1,1,0,0,0,0,0,0,0,42
    dc.b 0,6,5,5,3,3,2,2,2,1,1,0,0,0,0,0,0,0,42


; ------------------------
; debug effect
; ------------------------
rainbow: 
		move.w    $DFF006,$DFF180 ; background
		rts

; ------------------------
; gameobjects
; ------------------------
	even
gameobjects:

gameobject0:
	dc.w 1    ; state
	gameobject0_x:
	dc.w 20   ; x
	gameobject0_y:
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 0   ; animind
	dc.w 21000   ; animindold
	dc.w 1   ; arg
	dc.w 0   ; behavior
	dc.w 0   ; spr

gameobject1:
	dc.w 1    ; state
	dc.w 40   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 1   ; animind
	dc.w 21000   ; animindold
	dc.w 2   ; arg
	dc.w 0   ; behavior
	dc.w 1   ; spr

gameobject2:
	dc.w 1    ; state
	dc.w 60   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 2   ; animind
	dc.w 21000   ; animindold
	dc.w 1   ; arg
	dc.w 0   ; behavior
	dc.w 2   ; spr

gameobject3:
	dc.w 1    ; state
	dc.w 80   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 3   ; animind
	dc.w 21000   ; animindold
	dc.w 3   ; arg
	dc.w 0   ; behavior
	dc.w 3   ; spr

gameobject4:
	dc.w 1    ; state
	dc.w 100   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 4   ; animind
	dc.w 21000   ; animindold
	dc.w 1   ; arg
	dc.w 0   ; behavior
	dc.w 4   ; spr

gameobject5:
	dc.w 1    ; state
	dc.w 120   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 5   ; animind
	dc.w 21000   ; animindold
	dc.w 2   ; arg
	dc.w 0   ; behavior
	dc.w 5   ; spr

gameobject6:
	dc.w 1    ; state
	dc.w 140   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 6   ; animind
	dc.w 21000   ; animindold
	dc.w 3   ; arg
	dc.w 0   ; behavior
	dc.w 6   ; spr

gameobject7:
	dc.w 1    ; state
	dc.w 160   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 7   ; animind
	dc.w 21000   ; animindold
	dc.w 1   ; arg
	dc.w 0   ; behavior
	dc.w 7   ; spr

gameobject8:
	dc.w 1    ; state
	dc.w 180   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 0   ; animind
	dc.w 21000   ; animindold
	dc.w 0   ; arg
	dc.w 0   ; behavior
	dc.w 42   ; spr

gameobject9:
	dc.w 1    ; state
	dc.w 200   ; x
	dc.w 100   ; y
	dc.w 16   ; width
	dc.w 16   ; height
	dc.w 16   ; col width
	dc.w 16   ; col height
	dc.w 0   ; type
	dc.w 0   ; typesub
	dc.w 0   ; art
	dc.w 0   ; animtype
	dc.w 0   ; animmin
	dc.w 0   ; animmax
	dc.w 0   ; animind
	dc.w 21000   ; animindold
	dc.w 0   ; arg
	dc.w 0   ; behavior
	dc.w 42   ; spr


	; space for more gameobject

	dcb.w	5*18*2,0

;======================================================================================================================
;  cryAengine: colors
;======================================================================================================================

colorsTitleToBlack:

		IF ModeBlack

		move.l #15,d1
		lea.l GenericColsBase,a0

colsTo:		
		move.w (a0)+,d0
		move.w #$0,(a0)
		move.w (a0)+,d0
		dbra d1,colsTo

		ENDIF

		rts

colorsToBlack:

		IF ModeBlack

		move.l #15,d1
		lea.l InGameColors,a0
colsToB:		
		move.w (a0)+,d0
		move.w #$0,(a0)
		move.w (a0)+,d0
		dbra d1,colsToB

		ENDIF 

		rts		


colorsToGameColors:

		; a list 
		lea.l colors,a0						; Move to A0 since we will work with Address Register

		lea		InGameColors,a1			; Get the Address of where the colours are in the Copper list
		moveq	#15,d1						; Number of Colours
		addq.l	#2,a1							; Add 4 to the Copper list Address
nextcol:
		; move.w	d1,(a1)						; Copy the Word to teh Copper list Address Word
		move.w	(a0),(a1)						; Copy the Word to teh Copper list Address Word
		add.l	#2,a0							; Add 4 to the Copper list Address
		add.l	#4,a1							; Add 4 to the Copper list Address
		dbra	d1,nextcol					; Loop
nocopycolors:

		rts


;======================================================================================================================
;  cryAengine: BOBs und BLOBS (copy into memory and redo)
;======================================================================================================================


BLTDDAT	=0	;result of the last word. used for bob collision detection and 
		;MFM decoding
DMACONR	=2	;bit 14=blitter busy flag

BLTCON0	=$40	;blitter operation setup
BLTCON1	=$42
BLTAFWM	=$44
BLTALWM	=$46

BLTCPTH	=$48	;sources, destination, and size
BLTCPTL	=$4a
BLTBPTH	=$4c
BLTBPTL	=$4e
BLTAPTH	=$50
BLTAPTL	=$52
BLTDPTH	=$54
BLTDPTL	=$56

BLTSIZE	=$58

BLTCON0L=$5a	;ECS/AGA registers
BLTSIZV	=$5c
BLTSIZH	=$5e

BLTCMOD	=$60	;modulos
BLTBMOD	=$62
BLTAMOD	=$64
BLTDMOD	=$66

BLTCDAT	=$70	;data to replace sources
BLTBDAT	=$72
BLTADAT	=$74

DMACON	=$96	;bit 6: enable blitter DMA. bit 10: give blitter priority over
		;the CPU.

BlitWait:
	tst DMACONR(a6)			;for compatibility
waitblit:
	btst #6,DMACONR(a6)
	bne.s waitblit
	rts

; https://www.youtube.com/watch?v=OLhhgfnNo9A

; solve a puzzle
 
w	=320 ; 352?
h	=256



;======================================================================================================================
; cryAEngine: copyScreen
;======================================================================================================================

; ressource
		lea GameScreenBitplanes,a5
		; target
		lea IntroScreen,a4

copyScreenDirect:

		move.l #3,d7
copyscreen_aplanes:
		tst DMACONR(a6); $dff002
.copyscreen:
		btst #6,DMACONR(a6); $dff002
		bne .copyscreen:
		; 1 - destination
		;         3210  
		; sources ABCD
		;         1001
		;         > 9 
		; copy from A pointer to D pointer!
		; move.l #$09000000,BLTCON0(a6);$dff040	mode	
		;          ^^ locial combination
		; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
		; MINDTERM
		;       ABCD  > D 
		;	0	000     0  
		;   1   001		0
		;   2   010		0
		;   3   011		0
		;   4   100 	1
		;   5   101		1
		;   6   110		1
		;   7   111 	1 < first bit
		;               ^ 8 bits
		;               > %111100000 > f0
		;       1001 > combine => 9
		;   A - SOURCE
		;   D - 
		move.l #$09fa0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
		move.l #$ffffffff,BLTAFWM(a6) ; mask 
		move.l a5,BLTAPTH(a6); $dff054  ; high & low
		move.l a4,BLTDPTH(a6); $dff054  ; high & low
		move.w #0,BLTAMOD(a6); $dff066
		move.w #0,BLTDMOD(a6)
		; x. end
		move.w #256*64+320/16,BLTSIZE(a6) ; $dff058 ; set size		
		; *64 highword: height, lowword: width

		; all planes
		add.l #40*256,a5
		add.l #40*256,a4
		dbra d7,copyscreen_aplanes

nocopyscreen:

;======================================================================================================================
;  cryAengine: bobs (part of gameobjects!)
;======================================================================================================================

; resetBobList
;
; RenderBob1616 > add 16x16 bob
; 

; renderAwayBobList
; Start again ...

; render a 16x16 bob
; with id from BOB1616Editor

; screen


		even

bob1616_id:	dc.w 0
bob1616_x:	dc.w 10   
bob1616_y:	dc.W 10  

; screenTarget
screenTarget: dc.w 0 ; 0 or 1/2
					 ; 0 base					 

even

; render bob 1616
renderBob1616:		;d0-d3/a0-a2=x,y,word-width,h,src,dest,mask,BLTCON0+1.l

	movem.l	d0-d7/a0-a6,-(SP)

; https://www.stashofcode.fr/afficher-sprites-et-bobs-sur-amiga-2/





; https://eab.abime.net/showthread.php?t=68011

	
		



		; https://www.stashofcode.fr/afficher-sprites-et-bobs-sur-amiga-2/

DISPLAY_DX=320
DISPLAY_DY=256

DISPLAY_X=$81
DISPLAY_Y=$2C

DISPLAY_DEPTH=4
COPPERLIST=10*4+DISPLAY_DEPTH*2*4+(1<<DISPLAY_DEPTH)*4+4
	;10*4					Configuration de l'affichage
	;DISPLAY_DEPTH*2*4		Adresses des bitplanes
	;(1<<DISPLAY_DEPTH)*4	Palette
	;4						$FFFFFFFE
BOB_X=DISPLAY_DX>>1
BOB_Y=DISPLAY_DY>>1
BOB_DX=16
BOB_DY=16
BOB_DEPTH=DISPLAY_DEPTH
DEBUG=1

		lea $dff000,a5  ; blitter base 
		
		move.w #$8040,DMACON(a6) ; enable blitter with offset
		tst DMACONR(a6); $dff002
.waitbliting1616_b:
		btst #6,DMACONR(a6); $dff002
		bne .waitbliting1616_b:

    moveq #0,d1
	move.w #BOB_X,d0
	subi.w #BOB_DX>>1,d0
	move.w d0,d1
	and.w #$F,d0
	ror.w #4,d0
	move.w d0,BLTCON1(a5)
	or.w #$0FF2,d0
	move.w d0,BLTCON0(a5)
	lsr.w #3,d1
	and.b #$FE,d1
	move.w #BOB_Y,d0
	subi.w #BOB_DY>>1,d0
	mulu #DISPLAY_DEPTH*(DISPLAY_DX>>2),d0
	add.l d1,d0
	;; backBuffer
	move.l #IntroScreen,d1
	add.l d1,d0
	move.w #$FFFF,BLTAFWM(a5)
	move.w #$0000,BLTALWM(a5)
	move.w #-2,BLTAMOD(a5)
	move.w #0,BLTBMOD(a5)
	move.w #(DISPLAY_DX-(BOB_DX+16))>>2,BLTCMOD(a5)
	move.w #(DISPLAY_DX-(BOB_DX+16))>>2,BLTDMOD(a5)
	move.l #bob1616_1,BLTAPTH(a5)
	move.l #bob1616_1_mask,BLTBPTH(a5)
	move.l d0,BLTCPTH(a5)
	move.l d0,BLTDPTH(a5)
;	move.w #(DISPLAY_DEPTH*(BOB_DY<<6))!((BOB_DX+16)>>4),BLTSIZE(a5)

;	move.w #(DISPLAY_DEPTH*(BOB_DY<<6))!((BOB_DX+16)>>4),BLTSIZE(a5)
	move.w #(DISPLAY_DEPTH*(BOB_DY<<6))!((BOB_DX+16)>>4),BLTSIZE(a5)

;	move.w #16*64+1,BLTSIZE(a5)


		
		
		jmp nono

			move.w #$8040,DMACON(a6) ; enable blitter with offset
					tst DMACONR(a6); $dff002
			.waitbliting1616_13:
					btst #6,DMACONR(a6); $dff002
					bne .waitbliting1616_13:


					; 1 - destination
					;         3210  
					; sources ABCD
					;         1001
					;         > 9 
					; copy from A pointer to D pointer!
					; move.l #$09000000,BLTCON0(a6);$dff040	mode	
					;          ^^ locial combination
					; https://www.youtube.com/watch?v=Iuxu3o8FZ-0 
					; MINDTERM
					;       ABCD  > D 
					;	0	000     0  
					;   1   001		0
					;   2   010		0
					;   3   011		0
					;   4   100 	1
					;   5   101		1
					;   6   110		1
					;   7   111 	1 < first bit
					;               ^ 8 bits
					;               > %111100000 > f0
					;       1001 > combine => 9
					;  
					; several channels
					; > combine to create a new
					; >> A ~ B > D
					; 
					; https://www.youtube.com/watch?v=Iuxu3o8FZ-0
					; add xor...
					;       ABCD  > D 
					;	0	000     0  
					;   1   001		0
					;   2   010		1
					;   3   011		1
					;   4   100 	1
					;   5   101		1
					;   6   110		1
					;   7   111 	1 < first bit
					;   
					;               %11111100 > FC
					;       1101  >>>>> D		
					;               TOTAL DFC 
					;               xor
					; 
					; BOB
					; https://www.youtube.com/watch?v=OLhhgfnNo9A&t=1215s
					; A cloud mask
					; B cloud
					; C destination playfield
					; D destination playfield
					; 1.0
					; xor
					move.l #0,d2
					move.w bob1616_x,d2
				
					; move.l #$1fca0000,d2

					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					
					move.l d2,BLTCON0(a6)

			;		move.l #$09f00000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					;        ^ shift!   
					; 2.0
					; mask
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
			;		move.l #$01000000,BLTCON0(a6);$dff040	mode	
					; move.l #$01fff000,$dff040	
					; start/ressource	
					; ressource
					move.l a5,a2
					add.l #4*(16/8+0)*16,a2					
			;		lea testblockone,a0		
					move.l a5,a0
					move.l #bob1616_1_mask,a2 
					move.l #bob1616_1,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					; target
					lea IntroScreen,a3	
					; bltyd*(ww/8)+bltxd/8
					; add.l d6,a3
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					; same target
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	

					move.w #(320-16-16)/8,BLTCMOD(a6)
					move.w #(320-16-16)/8,BLTDMOD(a6)
					; x. end
					move.w #32*64+(16+16)/16,BLTSIZE(a6) ; $dff058 ; set size		
					; *64 highword: height, lowword: width

	jmp nono
					; plane1
					tst DMACONR(a6); $dff002
			.waitbliting1616_1:
					btst #6,DMACONR(a6); $dff002
					bne .waitbliting1616_1
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
					move.l a5,a2
					add.l #4*(16/8+0)*16,a2				
			;		lea testblockdouble,a0		
					move.l a5,a0
					add.l #(16/8+0)*16,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					lea IntroScreen,a3
					add.l d6,a3
					add.l  #40*256,a3	
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	
					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

					; plane2
					tst DMACONR(a6); $dff002
			.waitbliting1616_2:
					btst #6,DMACONR(a6); $dff002
					bne .waitbliting1616_2
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
					move.l a5,a2
					add.l #4*(16/8+0)*16,a2					
			;		lea testblockdouble,a0		
					move.l a5,a0
					add.l #2*(16/8+0)*16,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					lea IntroScreen,a3
					add.l d6,a3
					add.l  #2*40*256,a3	
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	
					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

					; plane3
					tst DMACONR(a6); $dff002
			.waitbliting1616_3:
					btst #6,DMACONR(a6); $dff002
					bne .waitbliting1616_3
					move.l #$0fca0000,BLTCON0(a6);$dff040 mode : combination + XORETC	
					move.l #$ffffffff,BLTAFWM(a6) ; mask 
					move.l a5,a2
					add.l #4*(16/8+0)*16,a2				
			;		lea testblockdouble,a0		
					move.l a5,a0
					add.l #3*(16/8+0)*16,a0
					move.l a2,BLTAPTH(a6); $dff054  ; high & low
					move.l a0,BLTBPTH(a6); $dff054  ; high & low
					lea IntroScreen,a3
					add.l d6,a3
					add.l  #3*40*256,a3	
					move.l a3,BLTCPTH(a6); $dff054  ; high & low
					move.l a3,BLTDPTH(a6); $dff054  ; high & low
					move.w #0,BLTAMOD(a6); $dff066
					move.w #0,BLTBMOD(a6); $dff066	
					move.w #(320-16)/8,BLTCMOD(a6)
					move.w #(320-16)/8,BLTDMOD(a6)
					move.w #16*64+16/16,BLTSIZE(a6) ; $dff058 ; set size		

nono:

		movem.l	(SP)+,d0-d7/a0-a6

notthese:

; 	movem.l (sp)+,d2-d3/d5/a1

	rts

	even



;======================================================================================================================
;  cryAengine: levels
;======================================================================================================================

actualLevelIndex: dc.l 0


; load into the actual level
loadActualLevel:

	lea.l levels,a1
	move.l actualLevelIndex,d0
	cmp.l #0,d0
	beq nocounting_levels
	sub.l #1,d0
adac_counting:
	add.l #20*16+2,a1
	dbra d0,adac_counting 	
nocounting_levels:

;	lea.l levels,a1

	move.l #20*16,d1
	lea.l actualLevel,a2
cp:
	move.b (a1)+,(a2)+
	dbra d1,cp

	rts

	

; draw the actual level
drawLevel:

	move.l #15,d7
	
	lea.l actualLevel,a4

	move.l #0,d5
ly:
	move.w d5,blocky
	move.l #19,d6
	move.l #0,d4
lx:
	move.w d4,blockx
	clr.l  d0
	move.b (a4)+,d0
	move.w d0,blockno
	jsr drawBlockXY
	add.l #1,d4
	dbra d6,lx

	add.l #1,d5	
	dbra d7,ly

	rts


	even

;======================================================================================================================
;  cryAengine: get Level Block (XY) etc
;======================================================================================================================
	even

; input
levelBlockX:
	dc.w 0
levelBlockY:
	dc.w 0

; output
levelBlockIndex:
	dc.w 0

levelBlock16X:
	dc.w 0
levelBlock16XRest:
	dc.w 0

levelBlock16Y:
	dc.w 0
levelBlock16YRest:
	dc.w 0

levelBlockAddress:
	dc.l 0

setLevelBlock:

	lea.l actualLevel,a0
	clr.l d0
	move.w levelBlockY,d0
	mulu.w #20,d0
	clr.l d1
	move.w levelBlockX,d1
	add.w d1,d0
	add.l d0,a0
	clr.l d0
	move.b d0,(a0)

	rts
	
getLevelBlock:

		clr.l d0
		move.w levelBlockX,d0
		divu #16,d0
		move.w d0,levelBlock16X
		swap d0
		move.w d0,levelBlock16XRest

		clr.l d0
		move.w levelBlockY,d0
		divu #16,d0
		move.w d0,levelBlock16Y
		swap d0
		move.w d0,levelBlock16YRest

		; now create the address
		clr.l d0
		move.w levelBlock16Y,d0
		mulu #20,d0
		add.w levelBlock16X,d0

		lea.l actualLevel,a0
		add.l d0,a0

		clr.l d0
		move.b (a0),d0
		move.w d0,levelBlockIndex

		move.l a0,levelBlockAddress

		rts

;======================================================================================================================
;  cryAengine: block animations
;======================================================================================================================

				
activateMousePointer:

	lea.l gameobjects,a0
	move.w #type_avatar_mouse_atype,gameobject_animtype(a0)
	move.w #type_avatar_mouse_animind,gameobject_animind(a0)

	rts

;======================================================================================================================
;  cryAengine: block animations
;======================================================================================================================
; animate actual level 
; one animation 4 blocks
					even
block_anim_index: dc.l 0
block_anim_speed: dc.l 15

block_anim_startblock: dc.l 143 ; -1
block_anim_stopblock: dc.l 160 ;+1

block_bounce_start equ 88
block_bounce_stop equ 95

block_platform_start equ 79
block_platform_stop equ 87

block_collect_start equ 104
block_collect_stop equ 111
block_collect_replace equ 66 


BlockAnimation:

	add.l  #1,block_anim_index
	move.l block_anim_speed,d0
	cmp.l  block_anim_index,d0
	bne no_blockanimation
	move.l #0,block_anim_index	

	move.l #15,d7
	
	lea.l actualLevel,a4

	move.l #0,d5
bly:
	move.w d5,blocky
	move.l #19,d6
	move.l #0,d4
blx:
	move.w d4,blockx
	clr.l  d0
	move.b (a4)+,d0
	
	move.l block_anim_startblock,d1
	cmp.b d0,d1
	bhi.b notimp
	move.l block_anim_stopblock,d1
	cmp.b d0,d1
	bcs.b notimp

	; animate now ...
	add.b #1,d0

	; %4 
	clr.l d1
	move.b d0,d1
	divu #4,d1
	swap d1 ; %
	cmp.w #0,d1
	bne.w not_4
	
	clr.l d0
	move.b -1(a4),d0
	divu #4,d0
	mulu #4,d0
	; move.b #120,d0

not_4: 
	move.b d0,-1(a4)
	move.w d0,blockno
	jsr drawBlockXY



notimp:

	add.l #1,d4
	dbra d6,blx

	add.l #1,d5	
	dbra d7,bly

no_blockanimation:

		rts 

;======================================================================================================================
;  cryAengine: numbers
;======================================================================================================================

number_no: dc.l 0
number_x: dc.l 0
number_y: dc.l 0
number_size: dc.l 2

number_showzero: dc.l 1 ; 1: show 001 or 1

; tmp
number_tmp_x: dc.l 0
number_tmp: dc.l 0

; print it revers    <-startx
drawNumbers:

		move.l number_size,d4
		move.l number_no,number_tmp 
		; move.l #123,number_tmp
		move.l number_y,d0
		move.w d0,blocky
		move.l number_x,number_tmp_x
dn:		

		move.l number_tmp_x,d0
		move.w d0,blockx
		move.l  number_tmp,d3
		divu #10,d3
		clr d0
		move.w d3,d0
		move.l d0,number_tmp
		clr d0
		swap d3
		move.w d3,d0
		add.l #39,d0
		move.w d0,blockno

		jsr drawBlockXY

		cmp.l #0,number_showzero
		bne   nnn
		cmp.l #0,number_tmp
		bne   nnn
		jmp   dna
nnn:

		sub.l #1,number_tmp_x
		dbra d4,dn

dna:    ; for all the false dna metaphorisms

		rts


;======================================================================================================================
;  cryAengine: blocks
;======================================================================================================================
			even
blockx: 	; * 16
	dc.w	5
blocky: 	; * 16
	dc.w    3
blockno:
	dc.w	1	


; drawBlockXY
drawBlockXY:
	; 2**16

	lea.l  blocks,a0
	; add.l  #(2*16)*12,a0 ; (2*16)*4 = 1line (2byte) * 16 *4  planes
	clr.l d0
	move.w blockno,d0
	cmp.w #0,d0
	beq   ncd
	sub.w #1,d0
cd: 
	add.l  #(2*16)*4,a0
	dbra d0,cd
ncd:
	; screen
	lea.l  GameScreenBitplanes,a1

	; + y*16*40
	clr.l d0
	move.w blocky,d0
	cmp.w #0,d0
	beq   yncd
	sub.w #1,d0
ycd: 
	add.l  #40*16,a1
	dbra d0,ycd
yncd:

	; x
	clr.l d0
	move.w blockx,d0
	cmp.w #0,d0
	beq   xncd
	sub.w #1,d0

xcd: 
	add.l  #2,a1
	dbra d0,xcd
xncd:


	; simpler
	move.l  a1,a2 ; backup

	; plane 0 
	move.l #16-1,d0
for_plane0:
	move.b (a0)+,(a1)+
	move.b (a0)+,(a1)+
	add.l #40-2,a1
;	move.b #255,(a1)+
;	move.b #255,(a1)+
;	add.l #20-2,a1
	dbra d0,for_plane0

	move.l a2,a1
	add.l #40*256,a1 ; a line 40b * 256 = screen	
	move.l #16-1,d0
for_plane1:
	move.b (a0)+,(a1)+
	move.b (a0)+,(a1)+
	add.l #40-2,a1
	dbra d0,for_plane1

	move.l a2,a1
	add.l #2*40*256,a1 ; a line 40b * 256 = screen	
	move.l #16-1,d0
for_plane2:
	move.b (a0)+,(a1)+
	move.b (a0)+,(a1)+
	add.l #40-2,a1
	dbra d0,for_plane2

	move.l a2,a1
	add.l #3*40*256,a1 ; a line 40b * 256 = screen	
	move.l #16-1,d0
for_plane3:
	move.b (a0)+,(a1)+
	move.b (a0)+,(a1)+
	add.l #40-2,a1
	dbra d0,for_plane3



	rts


; displayBlock
	even
number: 
	dc.l    1 

; display Block No > 1,2,4,5, 
displayBlockNumber:

		move.l number,d0
		add.l #39,d0	 
		move.w d0,blockno
		jsr drawBlockXY		

		rts

		even


; -------------------------
; texts
; -------------------------

text_menu_main: dc.b "FIGHT FOR THE VECTORS!+DEFEAT THE PIXEL WORLDS!+PRAY TO THE VECTORS!",0

text_menusub_story: dc.b "THE EVIL FORCES OF COUNTER+ENLIGHTENMENT HAVE TAKEN OVER+THE WORLD!++THEIR MAGICIANS RULE WITH+PIXELS. COLOURS AND IMAGES.+THEY HATE ABSTRACTION.+ +STEAL THEIR EYE CANDY+DEATH TO THE PIXELERS!",0

text_menusub_howto: dc.b "TO SAVE THE WORLD FROM THESE+DAEMONS. COLLECT ALL THE+DEVILISH SHINY THINGS. + +USE YOUR POWER TO JUMP.+ + LET YOURSELF BE PUSHED+    BACK AND FORTH.+ + +DONT LET THE DAEMONS+KILL YOU!+ ++THE FEWER CUBES ARE+KILLED, THE BETTER ++BACK TO MENU. PRESS ESC",0

text_menusub_about: dc.b "BASED ON THE IDEA OF NSTOWER.+TURNED INTO A LEVELBASED GAME.++CONTACT: INFO AT LA1N.CH++RELEASE: 2024++DEVELOPMENT:+AMIGA ASSEMBLY WITH CRYAENGINE++CODE.GRAPHICS:T00CG ++LEVELS:T00CG.NULL00.HE02++MUSIC: BORROWED O. KLAEWER++GREETINGS:+R.WERNER SCA DEPECHE HALLER JESPERSON",0

text_gameover: dc.b "GAME OVER",0
 
		even

		even



; ----------------------
; drawBlockText
; ----------------------
; text in a4
;

demo_text: dc.b "CODE FOREVER",0
	even

text_x: dc.w 0
text_y: dc.w 0
text_x_max: dc.w 20

text_tmp_x: dc.w 0
text_tmp_y: dc.w 0

; usage:
; move.w #5,text_x
; move.w #,text_y
; ; move.lw text_x_max
; lea.l demo_text,a4
; jsr drawBlockText

drawBlockText:
	move.w text_x,text_tmp_x
	move.w text_y,text_tmp_y

;	lea.l demo_text,a4
while_text:

	clr.l d0
	move.b (a4),d0
	add.l  #1,a4

	cmp.b #0,d0
	beq.b drawEnd_def

	cmp.b #32,d0
	bne.b n_space
	move.b #12,d0
	jmp   drawNowDirect
n_space:

	sub.b #65,d0
	add.b #13,d0

drawNowDirect:

	move.w text_tmp_x,blockx
	move.w text_tmp_y,blocky
	move.w d0,blockno
	jsr drawBlockXY

	add.w #1,text_tmp_x
	move.w text_x_max,d1
	cmp.w text_tmp_x,d1
	bne.w text_x_maxtttt
	move.w text_x,text_tmp_x
	add.w  #1,text_tmp_y
text_x_maxtttt:

	jmp while_text

drawEnd_def:	

	rts




; ----------------------
; drawSmallBlockText
; ----------------------
; text in a4
;

demo_small_text: dc.b "THE WOLF IS GOING AROUND. HE WEARS A RED CAP",0

	even

; text_x: dc.w 0
; text_y: dc.w 0
; text_x_max: dc.w 20

; text_tmp_x: dc.w 0
; text_tmp_y: dc.w 0

; usage:
; move.w #5,text_x
; move.w #,text_y
; ; move.lw text_x_max
; lea.l demo_text,a4
; jsr drawText

textsmall_x_max: dc.w 40

drawText:

	move.w text_x,text_tmp_x
	move.w text_y,text_tmp_y

;	lea.l demo_text,a4
while_text_small:

	clr.l d0
	move.b (a4),d0
	add.l  #1,a4

	cmp.b #58,d0
	bne.b n_double
	move.b #47,d0
	jmp   drawNowDirect_small
n_double:

; check numbers ... 
	cmp.b #48,d0
	blt.b nonumber
	cmp.b #57,d0
	bgt.b nonumber
	sub.b #48,d0
	add.b #8,d0

	jmp   drawNowDirect_small
nonumber:

	cmp.b #0,d0
	beq drawEnd_def_small

	; return + 
	cmp.b #43,d0 ; 13 return
	bne.b n_returnit
	
	move.w text_x,text_tmp_x
	add.w  #1,text_tmp_y
	; add.l  #1,a4

	jmp   norendering_smtext
n_returnit:


	cmp.b #32,d0
	bne.b n_space_small
	move.b #20,d0
	jmp   drawNowDirect_small
n_space_small:

	cmp.b #46,d0
	bne.b n_bindes
	move.b #18,d0
	jmp   drawNowDirect_small
n_bindes:

	cmp.b #45,d0
	bne.b n_point
	move.b #19,d0
	jmp   drawNowDirect_small
n_point:

	


; 9 / 10

	sub.b #65,d0
	add.b #21,d0

drawNowDirect_small:

	move.w text_tmp_x,smallblockx
	move.w text_tmp_y,smallblocky
	move.w d0,smallblockno
	jsr drawSmallBlockXY 

	add.w #1,text_tmp_x
	move.w textsmall_x_max,d1
	cmp.w text_tmp_x,d1
	bne.w text_x_maxtttt_small
	move.w text_x,text_tmp_x
	add.w  #1,text_tmp_y
text_x_maxtttt_small:

norendering_smtext:

	jmp while_text_small

drawEnd_def_small:	

	rts




;======================================================================================================================
;  cryAengine: draw changing/blinking text intro
;======================================================================================================================


			even
text_title_counter: dc.l 0
text_title_address: dc.l 0

text_title_size equ 31

			even
text_title_screen:
			; length clear
			; overwritting!
			dc.b "  PRODUCED BY CHLUDENS NORTH  ",0
			dc.b "                              ",0
			dc.b "    A VISUAL ABSTRACT GAME    ",0
			dc.b " NOT MANY ABSTRACT GAMES TILL ",0
			dc.b "          TODAY               ",0
			dc.b "                              ",0
			dc.b " GAMEDEV/SIGNER LOVE SETTINGS ",0
			dc.b "   HELPS THEM AND THE GAMERS  ",0
			dc.b "  TO UNDERSTAND GAMEMECHANICS ",0
			dc.b "                              ",0
			dc.b "      PRESS MOUSE BUTTON      ",0
			dc.b "         TO CONTINUE          ",0
			dc.b "                              ",0
			dc.b 42


;======================================================================================================================
;  cryAengine: smallblocks (8x8)
;======================================================================================================================
			even

smallblockx: 	; * 16
	dc.w	5
smallblocky: 	; * 16
	dc.w    3
smallblockno:
	dc.w	1	

smallblockno_big: dc.w 1
smallblockno_rest: dc.w 1

smallblockscreentarget: dc.w 0 ; 0 ingame screen 1: titlescreen

; drawsmallblockxY
drawSmallBlockXY:
	; 2**16

	lea.l  blocks,a0
	; add.l  #(2*16)*12,a0 ; (2*16)*4 = 1line (2byte) * 16 *4  planes

	clr.l d0
	move.w smallblockno,d0
	divu.w #4,d0 
	; 4
	move.w d0,smallblockno_big
	swap d0
	; 4 rest xyz
	move.w d0,smallblockno_rest

	clr.l d0
	move.w smallblockno_big,d0
	cmp.w #0,d0
	beq   s_ncd
	sub.w #1,d0
s_cd: 
	add.l  #(2*16)*4,a0
	dbra d0,s_cd
s_ncd:

	; now add rest
	; 0-3
	; 8 8 8 8 
	; 16 16 16 
	; 320 = 40 * 8bits
	; 20*16
	; 40*8
	; jmp end_cell
	; add rest * 8		
	clr.l d0
	move.w smallblockno_rest,d0
;	mulu.w #8,d0
;	add.l  d0,a0
	; add for 0,1,2,3
	cmp.w #0,d0
	bne cell0
	jmp end_cell
cell0:	
	cmp.w #1,d0
	bne cell1
	add.l #1,a0
	jmp end_cell
cell1:	
	cmp.w #2,d0
	bne cell2
	add.l #8*2,a0
	jmp end_cell
cell2:	
	cmp.w #3,d0
	bne cell3
	add.l #8*2+1,a0
	jmp end_cell
cell3:	


end_cell:
	

	; destination
	; draw to screen
	lea.l  GameScreenBitplanes,a1

	; smallblcokscreentarget
	cmp.w #1,smallblockscreentarget
	bne.w ntt
	lea.l  TitleScreenBitmap,a1
ntt:

	; + y*8*40
	clr.l d0
	move.w smallblocky,d0
	cmp.w #0,d0
	beq   s_yncd
	sub.w #1,d0
s_ycd: 
	add.l  #40*8,a1
	dbra d0,s_ycd
s_yncd:

	; x
	clr.l d0
	move.w smallblockx,d0
	add.l  d0,a1


	; -----------------------
	; now copy it all 
	; -----------------------
	; simpler
	move.l  a1,a2 ; backup

	; plane 0 
	move.l #8-1,d0
s_for_plane0:
	move.b (a0)+,(a1)+
	;move.b #$ff,(a1)+
	add.l #40-1,a1
	add.l #1,a0
	dbra d0,s_for_plane0

;	add.l #1,a0

;
; p0
;  1 2  8+8  
;  3 4  8+8
; + 2*16
;
; p1
;  1 2  8+8  
;  3 4  8+8

; plane 1
	add.l #1*16,a0
	move.l  a2,a1 ; backup
	add.l #40*256,a1
	move.l #8-1,d0
s_for_plane1:
	move.b (a0)+,(a1)+
	;move.b #$ff,(a1)+
	add.l #40-1,a1
	add.l #1,a0
	dbra d0,s_for_plane1	


; plane 2
	add.l #1*16,a0
	move.l  a2,a1 ; backup
	add.l #40*256*2,a1
	move.l #8-1,d0
s_for_plane2:
	move.b (a0)+,(a1)+
	;move.b #$ff,(a1)+
	add.l #40-1,a1
	add.l #1,a0
	dbra d0,s_for_plane2	

; plane 3
	add.l #1*16,a0
	move.l  a2,a1 ; backup
	add.l #40*256*3,a1
	move.l #8-1,d0
s_for_plane3:
	move.b (a0)+,(a1)+
	;move.b #$ff,(a1)+
	add.l #40-1,a1
	add.l #1,a0
	dbra d0,s_for_plane3	








	rts

; ----------------------
; draw changing text
; ----------------------


;======================================================================================================================
;  cryAengine: sprites mode 
;======================================================================================================================

setupSpritesMouseMode:

		lea		sprite0,a2		; Source Address
		lea		Spr0_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		; colors
		lea	sprite0,a3		; Source Address		
		add.l #64,a3 
;		add.l #spritevisualdata_object_bytes,a3
		lea.l spritecolor_01_0,a1 		
		move.w (a3)+,(a1)
		add.l #4,a1
		move.w (a3)+,(a1)
		add.l #4,a1
		move.w (a3)+,(a1)
		add.l #4,a1
		move.w (a3)+,(a1)


		lea		sprite0,a2		; Source Address		
		add.l   #spritevisualdata_object_bytes,a2
		lea		Spr1_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		lea		sprite0,a2		; Source Address
		add.l  #spritevisualdata_object_bytes,a2
		lea		Spr2_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		lea		sprite0,a2		; Source Address
		add.l #spritevisualdata_object_bytes,a2
		lea		Spr3_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		lea		sprite0,a2		; Source Address
		add.l #spritevisualdata_object_bytes,a2
		lea		Spr4_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		lea		sprite0,a2		; Source Address
		add.l   #spritevisualdata_object_bytes,a2
		lea		Spr5_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		lea		sprite0,a2		; Source Address
		add.l   #spritevisualdata_object_bytes,a2
		lea		Spr6_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData

		lea		sprite0,a2		; Source Address
		add.l   #spritevisualdata_object_bytes,a2
		lea		Spr7_Data,a1		; DESTINATION Address
		bsr.w   copyVisualSpriteData



		rts

;======================================================================================================================
;  cryAengine: visual data 
;======================================================================================================================

		lea		sprite0,a2		; Source Address
		lea		Spr0_Data,a1		; DESTINATION Address
		; bsr.w   copyVisualSpriteData

	; image data
	; sprx_data

	copyVisualSpriteData:
		moveq.l	#16,d2					; Sprite Image Data Lenght in Long Words
	XCopyImgSprDatax:
		move.l	(a2)+,(a1)+					; Copy from Source to destination in Long Words
		dbra	d2,XCopyImgSprDatax			; Loop Till we Copy
	rts



;======================================================================================================================
;  cryAengine: game objects
;======================================================================================================================

; disable gameobjects
; - sprite - inactive and will be on -16,-16 (offscreen)

; gets the pointer / address of the object
getGameObject:

		rts

; no more collision, animation, behavior
disableGameObject:

		rts

 		; object state?
;		move.w gameobject_state(a6),d0
;		cmp.w #objectstate_inactive,d0
;		beq.w end_behavior

enableGameObject:

		rts 

;======================================================================================================================
;  cryAengine: WAVE-EFFECT
;======================================================================================================================
	even


WaterEffect:

		; version 1.0 
 	   ; plane 0
  	   lea.l effect_wave,a2
;	   move.l a2,effect_wave_pointer	   
	   lea.l GameScreenBitplanes,a0 ; start screen
	   lea.l GameScreenBitplanes,a1 ; start screen
	   add.l #40*(256-41),a0	   
	   add.l #40*(256-40),a1
	   move.l #38,d1
	   move.l #19,d1
cpy:	
		move.l (a2),d0
		mulu #40,d0
		sub.l d0,a0
	   move.l #19,d2
cpxor: 
		move.w (a0)+,(a1)+
		dbra d2,cpxor
	    sub.l #120,a0
	    add.l #40,a1
		dbra d1,cpy
		; /plane 0

	   ; plane 1
  	   lea.l effect_wave,a2
;	   move.l a2,effect_wave_pointer	   
	   lea.l GameScreenBitplanes,a0 ; start screen
	   lea.l GameScreenBitplanes,a1 ; start screen
	   add.l #40*(256-41),a0	   
	   add.l #40*(256-40),a1
	   add.l #40*256,a0
	   add.l #40*256,a1
	   move.l #38,d1
	   move.l #19,d1
cpy1:	
		move.l (a2),d0
		mulu #40,d0
		sub.l d0,a0
	   move.l #19,d2
cpxor1: 
		move.w (a0)+,(a1)+
		dbra d2,cpxor1
	    sub.l #120,a0
	    add.l #40,a1
		dbra d1,cpy1
		; /plane 1

		; plane 2
  	   lea.l effect_wave,a2
;	   move.l a2,effect_wave_pointer	   
	   lea.l GameScreenBitplanes,a0 ; start screen
	   lea.l GameScreenBitplanes,a1 ; start screen
	   add.l #40*(256-41),a0	   
	   add.l #40*(256-40),a1
	   add.l #80*256,a0
	   add.l #80*256,a1
	   move.l #38,d1
	   move.l #19,d1
cpy2:	
		move.l (a2),d0
		mulu #40,d0
		sub.l d0,a0
	   move.l #19,d2
cpxor2: 
		move.w (a0)+,(a1)+
		dbra d2,cpxor2
	    sub.l #120,a0
	    add.l #40,a1
		dbra d1,cpy2
		; /plane 2
		
	   ; -----------------------
	   ; move waves now
	   ; -----------------------
	   jmp nomore_x
	   add.l #1,effect_water_counter_uber
	   cmp.l #3,effect_water_counter_uber
	   bne effect_water_nolo_ost_tox
	   move.l #0,effect_water_counter_uber	

	   add.l #1,effect_water_counter
	   cmp.l #3,effect_water_counter
	   bne effect_water_nolo_ost
	   move.l #0,effect_water_counter	   
effect_water_nolo_ost:
effect_water_nolo_ost_tox:
nomore_x:


	   lea.l effect_wave,a2
  	   move.l #20,d4
	   move.l #0,d3
wavecontrol:
		move.l  #2,(a2)+
		dbra d4,wavecontrol
effect_water_nolo:

		rts

effect_water_counter: dc.l 0

effect_water_counter_uber: dc.l 0

effect_wave_pointer: dc.l 1

effect_wave: 
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 2
	dc.l 2
	dc.l 1
	dc.l 3
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 4
	dc.l 5
	dc.l 3
	dc.l 3
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 2
	dc.l 2
	dc.l 1
	dc.l 3
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 4
	dc.l 5
	dc.l 3
	dc.l 3
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 2
	dc.l 2
	dc.l 1
	dc.l 3
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 4
	dc.l 5
	dc.l 3
	dc.l 3
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 2
	dc.l 2
	dc.l 1
	dc.l 3
	dc.l 1
	dc.l 2
	dc.l 3
	dc.l 4
	dc.l 5
	dc.l 3
	dc.l 3
	dc.l 2
	dc.l 1
	dc.l 1
	dc.l 2
	dc.l 1
; -----------------------------
; COLORS
; -----------------------------
		even
colors: 
	include	"colors.s"

; -----------------------------
; LEVELS
; -----------------------------
; levels from blockeditor
		even

			 ; buffer
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

		even
actualLevel:

	; demo level 
             dc.b 0,1,2,3,4,5,1,1,4,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,2,4,1,4,1,3,4,1,3,3,3,3,0,5,0,0,0,0
             dc.b 3,5,2,4,1,4,1,3,4,1,1,1,1,3,3,5,0,0,0,0
             dc.b 3,5,2,4,4,4,1,3,4,1,3,3,3,3,0,5,0,0,0,0
             dc.b 4,3,2,3,4,4,1,3,4,1,3,0,0,0,0,5,0,0,0,0
             dc.b 4,3,5,3,3,3,1,3,4,0,3,0,0,0,0,0,0,0,0,0
             dc.b 4,3,1,3,1,1,1,3,4,0,0,0,4,4,4,0,0,0,0,0
             dc.b 3,3,3,3,3,4,4,4,4,0,0,0,0,0,4,4,0,0,0,0
             dc.b 0,3,0,0,0,0,0,3,0,4,4,0,0,0,0,4,0,0,0,0
             dc.b 0,3,0,4,0,0,0,3,0,0,4,0,0,0,0,4,0,0,0,0
             dc.b 0,3,0,4,0,0,4,0,0,0,0,0,0,4,4,0,0,0,0,0
             dc.b 0,0,0,4,0,4,4,0,0,0,0,0,4,4,0,0,0,0,0,0
             dc.b 0,0,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 1,0,0,0,0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0
             dc.b 1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

			 ; buffer
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
             dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0


	even
levels:
	include	"level0.s"
	include	"level1.s"
	include	"level2.s"
	include	"level3.s"
	include	"level4.s"
	include	"level5.s"
	include	"level6.s"
	include	"level7.s"
	include	"level8.s"
	include	"level9.s"
	include	"level10.s"
	include	"level11.s"
	include	"level12.s"
	include	"level13.s"
	include	"level14.s"
	include	"level15.s"
	include	"level16.s"
	include	"level17.s"
;	include	"level18.s"
	include	"level19.s"
	include	"level20.s"
	include	"level21.s"
	include	"level22.s"
	include	"level23.s"
	include	"level24.s"
	include	"level25.s"
	include	"level26.s"



; -----------------------------
; MOUSE HANDLING
; -----------------------------
WaitForMouseUp
xxxx:
		jsr WaitForRaster
		jsr 	mt_music
  	    BTST   #6,$BFE001      ; Test left mouse button
   		BEQ.S   xxxx

		rts

		even 

; -----------------------------
 ; KEYBOARD
 ; -----------------------------

		even
keyPressed:
	dc.w 1

_keyboard:
	movem.l d0-d2,-(sp)

	;Vérifier dans ICR que la requête est bien générée par le CIA A aur l'événement SP (bascule des 8 bits reçus du clavier dans SDR)

	btst #3,$BFED01
	beq _keyboardNotKeyboard

	;Lire les 8 bits dans SDR et détecter s'il s'agit de la pression ou du relâchement d'une touche

	move.b $BFEC01,d0
	btst #0,d0
	bne _keyboardKeyDown
	move.w #$00F0,d1		;Touche relâchée : couleur vert
	bra _keyboardKeyUp
_keyboardKeyDown:
	move.w #$0F00,d1		;Touche pressée : couleur rouge
_keyboardKeyUp:

	;Changer la couleur de fond si la touche pressée est celle attendue (ESC)

	not.b d0
	lsr.b #1,d0

	; key pressed
	clr.l d2
	move.b d0,d2
	move.w d2,keyPressed

	cmpi.b #$45,d0
	bne _keyboardNotESC
	; move.w d1,COLOR00(a5)
	; move.w    $DFF006,$DFF180 ; background
_keyboardNotESC:

	;Acquitter auprès du clavier en maintenant à 0 le signal sur sa ligne KDAT durant 85 us, ce qui s'effectue en positionnant SPMODE à 1 dans CRA ("software must pulse the line low for 85 microseconds to ensure compatibility with all keyboard models" et "the KDAT line is active low [...] a low level (0V) is interpreted as 1"). Pour rappel, une ligne raster, c'est 227,5 cycles de 280 ns, donc 63,7 us, ce qui signifie qu'il faut attendre que le raster ait parcouru deux lignes. Maintenant, ce n'est pas très élégant d'attendre que le raster se balade en se tournant les pouces...

	bset #6,$BFEE01
	
	move.l $DFF004,d0
	lsr.l #8,d0
	and.w #$01FF,d0
	moveq #2-1,d1
_keyboardWait85us:
	move.l $DFF004,d2
	lsr.l #8,d2
	and.w #$01FF,d2
	cmp.w d0,d2
	beq _keyboardWait85us
	move.w d2,d0
	dbf d1,_keyboardWait85us

	bclr #6,$BFEE01

_keyboardNotKeyboard:
	movem.l (sp)+,d0-d2
	rts
 
; -----------------------------
 ; MOUSE CHECK
 ; -----------------------------
	even

; pressed
joystick_Left: 	dc.w 0
joystick_Right: 	dc.w 0
joystick_Down: 	dc.w 0
joystick_Up: 	dc.w 0
joystick_Pressed: dc.w 0

; clicked
joystick_Left_Clicked: 	dc.w 0
joystick_Right_Clicked: 	dc.w 0
joystick_Down_Clicked: 	dc.w 0
joystick_Up_Clicked: 	dc.w 0
joystick_Pressed_Clicked: dc.w 0

; tmp
joystick_Left_old: 	dc.w 0
joystick_Right_old: 	dc.w 0
joystick_Down_old: 	dc.w 0
joystick_Up_old: 	dc.w 0
joystick_Pressed_old: dc.w 0


ReadJoystickDirect:

		move.w #0,joystick_Left_Clicked
		move.w #0,joystick_Right_Clicked
		move.w #0,joystick_Up_Clicked
		move.w #0,joystick_Down_Clicked
		move.w #0,joystick_Pressed_Clicked

		move.w #0,joystick_Left
		move.w #0,joystick_Right
		move.w #0,joystick_Up
		move.w #0,joystick_Down
		move.w #0,joystick_Pressed

		move.w	$dff00c,d3	; Read Joy1dat
		btst.l	#1,d3		; If bit 1 is 1 we move to the Right
		beq.s	j_right		; else check for left
		move.w #1,joystick_Right
j_right:
		btst.l	#9,d3		; If bit 9 is 1 then we so to the left
		beq.s	j_left		; If the bit is 0 then we don't go to the left
		move.w #1,joystick_Left
j_left:

		move.w	d3,d2		; Make a copy of D3 in D2
		lsr.w	#1,d2		; Shift word to the right by 1
		eor.w	d2,d3		; Xor the number
		btst.l	#8,d3		; Is bit 8 set
		beq.s	j_up			; If not check for going down
		move.w #1,joystick_Up
j_up:
		btst.l	#0,d3		; Test if we go Down
		beq.s	j_down		; End Joy routine if not
		move.w #1,joystick_Down

j_down:

		; clicked?

		; check now ...

		cmp.w #0,joystick_Left_old
		bne   cl_left
		cmp.w #1,joystick_Left
		bne   cl_left
		move.w #1,joystick_Left_Clicked
cl_left:		

		cmp.w #0,joystick_Right_old
		bne   cl_right
		cmp.w #1,joystick_Right
		bne   cl_right
		move.w #1,joystick_Right_Clicked
cl_right:		


		cmp.w #0,joystick_Up_old
		bne   cl_up
		cmp.w #1,joystick_Up
		bne   cl_up
		move.w #1,joystick_Up_Clicked
cl_up:

		cmp.w #0,joystick_Down_old
		bne   cl_down
		cmp.w #1,joystick_Down
		bne   cl_down
		move.w #1,joystick_Down_Clicked
cl_down:


		; back in history
		move.w joystick_Left,joystick_Left_old
		move.w joystick_Right,joystick_Right_old
		move.w joystick_Up,joystick_Up_old
		move.w joystick_Down,joystick_Down_old
		move.w joystick_Pressed,joystick_Pressed_old

		rts


; -----------------------------
 ; MOUSE CHECK
 ; -----------------------------
 ; https://www.ikod.se/reading-the-mouse/

XScreenWidth             equ     320
XScreenHeight            equ     256
 
        IFND MouseLimit
                ; 0 = Mouse Limit InActive
                ; 1 = Mouse Limit Active (Default)
MouseLimit                      equ     1
        ENDC
 

ReadMouse:
 
                ; **** SOF Read Mouse Routine ****
         
                movem.l d0-d2/a0-a1,-(sp)
                lea.l   OldDeltaY,a0
                lea.l   $dff00a,a1
 
                moveq   #0,d0
                move.b  (a1),d0         ; Get New Y Mouse
                move.w  (a0),d1         ; Get Old Y Mouse
                move.w  d0,(a0)         ; Save New Y Mouse
                sub.w   d1,d0           ; Delta Y
 
                moveq   #0,d1
                move.b  1(a1),d1        ; Get New X Mouse
                move.w  2(a0),d2        ; Get Old X Mouse
                move.w  d1,2(a0)        ; Save New X Mouse
                sub.w   d2,d1           ; Delta X
                 
                ; **** Check Y Delta ****
 
                cmp.w   #-127,d0
                bge     noUnderFlowY
                move.w  #-255,d2
                sub.w   d0,d2           ; Delta Y = -255 - Delta Y
                bpl     noYPos
                moveq   #0,d2
 
noYPos:        move.w  d2,d0
                bra     rmSkipY
 
noUnderFlowY:  cmp.w   #127,d0
                ble     rmSkipY
                move.w  #255,d2
                sub.w   d0,d2           ; Delta X = 255 - Delta Y
                bmi     noYNeg
                moveq   #0,d2
noYNeg:        move.w  d2,d0
 
rmSkipY:
 
                ; **** Check X Delta ****
 
                cmp.w   #-127,d1
                bge     NoUnderFlowX
                move.w  #-255,d2
                sub.w   d1,d2           ; Delta X = -255 - Delta X
                bpl     noXPos
                moveq   #0,d2
 
noXPos:        move.w  d2,d1
                bra     rmSkipX
 
NoUnderFlowX:  cmp.w   #127,d1
                ble     rmSkipX
                move.w  #255,d2
                sub.w   d1,d2           ; Delta X = 255 - Delta X
                bmi     noXNeg
                moveq   #0,d2
noXNeg:        move.w  d2,d1
 
rmSkipX:
 
                lea.l   MouseY,a0
 
                move.w  (a0),d2         ; D2.W = Old Y Mouse 
                add.w   d0,d2           ; Y Mouse = Y Mouse + Y Delta
 
        IF MouseLimit
                bpl     yPositive
 
                moveq   #0,d2
yPositive:     cmp.w   #XScreenHeight-1,d2      ; Y Mouse > Screen Height?
                ble     yBelow
                move.w  #XScreenHeight-1,d2
yBelow:       
        ENDC
                move.w  d2,(a0)+        ; Save Y Mouse
 
                move.w  (a0),d2         ; D2.W = Old X Mouse
                add.w   d1,d2           ; X Mouse = X Mouse + X Delta
        IF MouseLimit
                bpl     xPositive
 
                moveq   #0,d2
xPositive:     cmp.w   #XScreenWidth-1,d2       ; X Mouse > Screen Width?
                ble     xBelow
                move.w  #XScreenWidth-1,d2
xBelow:       
        ENDC
                move.w  d2,(a0)+
 
                movem.l (sp)+,d0-d2/a0-a1
                rts
 
                ; **** EOF Read Mouse Routine ****
				EVEN
OldDeltaY:      dc.w    0
OldDeltaX:      dc.w    0
MouseY:         dc.w    0
MouseX:         dc.w    0


;======================================================================================================================
;  Chip Data Section
;======================================================================================================================

		include	"Source/C_SpriteStructs.s"
		include	"Source/C_Copper.s"
		include	"Source/C_Data.s"









