ùúùú  ÂÖ ˜MÿŒçÏÿŒçÏÿŒçÏÿŒçÏÿŒçÏÿŒçÏÿŒçÏ; * EXEC *

_Forbid			equ	-132
_AddIntServer		equ	-168
_RemIntServer		equ	-174
_AllocMem		equ	-198
_FreeMem		equ	-210
_FindTask		equ	-294
_SetTaskPri		equ	-300
_AddPort		equ	-354
_RemPort		equ	-360
_GetMsg			equ	-372
_ReplyMsg		equ	-378
_WaitPort		equ	-384
_OldOpenLibrary		equ	-408
_CloseLibrary		equ	-414
_OpenDevice		equ	-444
_CloseDevice		equ	-450
_DoIO			equ	-456
_OpenLibrary		equ	-552
_CopyMem		equ	-624

; * DOS *

_Open			equ	-30
_Close			equ	-36
_Read			equ	-42
_Write			equ	-48
_Lock			equ	-84
_UnLock			equ	-90
_DupLock		equ	-96
_Examine		equ	-102
_CurrentDir		equ	-126
_IOErr			equ	-132
_CreateProc		equ	-138
_Exit			equ	-144
_UnloadSeg		equ	-156
_Delay			equ	-198

; * GRAPHICS *

_Text			equ	-60
_SetFont		equ	-66
_OpenFont		equ	-72
_SetSoftstyle		equ	-90
_WaitBlit		equ	-228
_MoveTo			equ	-240
_WaitTOF		equ	-270
_SetAPen		equ	-342
_SetDrMd		equ	-354
_ScrollRaster		equ	-396
_WaitBOVP		equ	-402
_BltBitMapRastPort	equ	-606

; * INTUITION *

_ClearPointer		equ	-60
_CloseScreen		equ	-66
_CloseWindow		equ	-72
_DisplayBeep		equ	-96
_DrawBorder		equ	-108
_MoveScreen		equ	-162
_MoveWindow		equ	-168
_OpenScreen		equ	-198
_OpenWindow		equ	-204
_SetPointer		equ	-270
_SetWindowTitles	equ	-276
_SizeWindow		equ	-288
_EasyRequestArgs	equ	-588

; * POWERPACKER *

_pploaddata		equ	-30

; * TIMER *

_GetSysTime		equ	-66

WinSizeY		equ	189
WinSizeX		equ	464

TRUE	equ	1
FALSE	equ	0

OBJECT		=TRUE

	section	Something,code

Program:
	move.l	4,a6
	move.l	#dosname,a1		; open DOS
	clr.l	d0
	jsr	_OpenLibrary(a6)
	move.l	d0,dosbase

	move.l	#intname,a1		; open INTUITION
	move.l	#36,d0
	jsr	_OpenLibrary(a6)
	tst.l	d0
	bne.s	int36

	move.b	#34,intver
	move.l	4,a6
	move.l	#intname,a1		; open INTUITION
	clr.l	d0
	jsr	_OpenLibrary(a6)
int36:	move.l	d0,intbase

	move.l	4,a6
	move.l	#gfxname,a1		; open GRAPHICS
	clr.l	d0
	jsr	_OpenLibrary(a6)
	move.l	d0,gfxbase

	move.l	4,a6
	move.l	276(a6),a3
	tst.l	172(a3)			; is this Workbench's message ?

	IF OBJECT=FALSE
	bra.b	fromcli 
	ENDIF
	bne.B	fromCLI 		; if no - jump to fromCLI

fromWB
	lea	92(a3),a0		; get port adress
	jsr	_WaitPort(a6)		; wait for message
	move.l	4.w,a6
	lea	92(a3),a0
	jsr	_GetMsg(a6)		; get message
	move.l	d0,wbmsg		; message address to "wbmsg"

	move.l	wbmsg,a0
	move.l	$24(a0),a0

	move.l	(a0),d1			; get current directory
	move.l	dosbase,a6
	jsr	_CurrentDir(a6)
	jmp	herefromWB

fromcli:
	IF OBJECT

	move.l	4.w,a6
	jsr	-132(a6)
	suba.l	a1,a1
	jsr	_FindTask(a6)
	move.l	d0,a0
	move.l	152(a0),currentdir	; get current dir from process
	jsr	-138(a6)		; structure

	move.l	dosbase,a6
	move.l	currentdir,d1
	jsr	_DupLock(a6)		; copy it
	move.l	d0,currentdir
	
	lea	program,a1
	move.l	-(a1),d3		; get next hunk's address
	clr.l	(a1)			; clear it in hunk list
	move.l	d3,segment
	move.l	#prgname,d1
	move.l	#0,d2
	move.l	#4096,d4
	move.l	dosbase,a6
	jsr	_CreateProc(a6)		; create new process

	clr.l	d0
	rts

prgname:
	dc.b	"Mini Arcanoid",0	; name of process

	section	REALPROG,code		; starting here...      :-)

prg:
	move.l	currentdir,d1
	move.l	dosbase,a6
	jsr	_CurrentDir(a6)		; set current directory
	ENDIF

herefromWB:
	move.l	sp,stack

	bsr.w	randomize

	lea	inputport,a1
	move.l	#portname,10(a1)

	bsr.w	openid

	move.l	4,a6
	moveq	#5,d0			; add vertical blank interrupt
	lea	myinterrupt,a1
	jsr	_AddIntServer(a6)

	bsr.w	loadconfig		; no comments...
	bsr.w	setpri			; set priority

	tst.b	workb			; is this workbench screen
	bne.s	noopcus
	bsr.w	openscreen		; no - open own screen
noopcus:
	move.l	#5,cheatgads

	lea	thisgads,a0
	bsr.w	proc_changeypos		; calculate position of gadgets

	lea	optionsgad,a0
	move.l	#opmove,d0
	move.l	#12,d1
	move.l	#2,d2
	bsr.w	calcgadpos		; and so on...

	move.l	#0,cheatgads
	move.l	gadsposy,oldgadsposy

	bsr.w	loadsamples		; guess !

	bsr.w	loadscores

	bsr.w	initpomoctable		; init multiplications table

	bsr.w	openwindow		; hmmmm....

	bsr.w	rysujpanel		; draw all
	bsr.w	demo			; "UNION PRESENTS"...

poczczekania:
	lea	prefire,a0		; scroll address
	bsr.w	scrollinit		; initialize it

poczdrgad:
	lea	gadgetlist,a0		; draw "START, OPTIONS, JUMP, ABOUT"
	bsr.w	drawgadgets		; gadgets...
czekaj:
	bsr.w	poczrmb			; SLEEP TIME ???
	bsr.w	wf			; wait frame

	lea	prefire,a0		; scroll text
	bsr.w	scrolltext		; scroll it !
	bsr.w	message			; IDCMP messages
	tst.w	key
	beq.w	nokeyp
	tst.b	cheatmode
	bne.w	nokeyp
	move.l	cheattxtadr,a0
	move.w	key,d0
	cmp.b	(a0)+,d0
	bne.w	keynotok
	move.l	a0,cheattxtadr
	tst.b	(a0)
	bne.w	nokeyp
	move.b	#1,cheatmode
	move.l	#5,cheatgads
	move.l	gadsposy,d0
	sub.l	oldgadsposy,d0
	add.l	d0,livy
	add.l	d0,levy
	add.l	d0,stgy
	add.l	d0,ptsy
	add.l	d0,livy-20
	add.l	d0,levy-20
	add.l	d0,stgy-20
	add.l	d0,ptsy-20

	lea	cheatontxt,a0
	bsr.w	scrollinit		; init scroll
	move.w	#380,d7			; 380 frames
	clr.l	wysw_czas		; no message
	move.l	#0,liniaadr
cheatlop:
	bsr.w	scrolltext		; scroll text
	bsr.w	message			; get IDCMP
	bsr.w	wf			; wait frame
	dbf	d7,cheatlop		; come back

	lea	prefire,a0		; scroll address
	bsr.w	scrollinit		; initialize it

keynotok:
	move.l	#cheattxt,cheattxtadr
nokeyp:	lea	gadgetlist,a0
	bsr.w	gadtext			; gadgets routines
	cmp.l	#g_start,a0		; "START" pressed ?
	beq.s	mysz			; yes
	cmp.l	#0,a0			; other button pressed ?
	beq.s	nooption		; no
	lea	menuoptions,a1		; YES !
	bsr.s	options			; action
	bne.w	poczdrgad		; don't restore background ?
	bsr.w	rysujpanel		; restore all
	bsr.w	drawminiarcanoid
	bra.w	poczczekania		; go back
nooption:
	bsr.w	firetestnomsg		; FIRE pressed ?
	btst	#7,firestat
	beq.s	firepressed
	tst.b	ongadget
	bne.w	czekaj
	bsr.w	firetestnomsg
	bne.w	czekaj
firepressed:
	move.w	#0,mouse
	cmp.b	#-1,lastbaton
	bne.s	nieustawmyszy		; mouse or joy controlled game
mysz:	move.w	#1,mouse
nieustawmyszy:
fire:	bsr.w firetest
	beq.s	fire

	bsr.W	gra			; game in progress...

pogrze:					; game OVER !
	move.l	#0,wysw_czas
	move.l	#0,liniaadr
	bra.W	poczczekania		; go back (again !)

wroc:
	move.l	stack,sp
	bsr.w	rysujpanel		; restore window and...
	bsr.w	drawminiarcanoid
	bra.w	poczczekania		; G O  B A C K !

; Text  - a0
; Table - a1

; * Execute option. Input - gadget name. *

options:
	clr.b	optflag
	movem.l	d0-d7/a0-a6,-(sp)
op_loop:
	move.l	(a1)+,a2		; get option's address
	cmp.l	#0,a2
	beq.s	op_end			; that's all !
	move.l	(a1)+,a3		; get option's name
	cmp.l	a0,a2			; so ?
	bne.s	nietaopcja		; :-(
	jsr	(a3)			; that's it !
	bra.s	op_end
nietaopcja:
	bra.s	op_loop			; next, please !
op_end:
	movem.l	(sp)+,d0-d7/a0-a6
	tst.b	optflag			; must I restore window ???
	rts

; * OPTIONS *

m_options:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	#12,scrollspeed		; it's line spacing, REALLY !
	bsr.B	valtogad		; set gadgets
; * Draw all *
	bsr.w	rysujpanel
	lea	optionsgad,a0
	moveq	#5,d0
	moveq	#2,d1
	move.l	#322,d2
	move.l	#145,d3
	bsr.w	drawscrollgad
	bsr.s	optselect		; selection done
	bsr.w	loadsamples		; load samples, if they're not
	movem.l	(sp)+,d0-d7/a0-a6	; loaded
	rts
	
optselect:
	bsr.B	selector		; make selection
	move.l	a0,-(sp)
	bsr.w	seescreen		; update screen changes
	move.l	window,a0
	move.w	4(a0),win_x		; set actual window position
	move.w	6(a0),win_y
	bsr.s	gadtoval		; set values by gadgets
	bsr.b	windowset		; set new window position
	move.l	(sp)+,a0
	cmp.l	#g_save,a0
	bne.s	nosave			; SAVE config ?
	bsr.w	saveconfig		; YEAH !
nosave:
	rts

; * Set window position *

windowset:
	movem.l	a0/d0-d1,-(sp)
	move.w	win_x,d0
	move.w	win_y,d1
	bsr.w	movewindow
	movem.l	(sp)+,a0/d0-d1
	rts

; * Change: values -> gadgets *

valtogad:
	lea	optionstab,a0
	bsr.w	g_setvalues
	rts

; * Change: gadgets -> values

gadtoval:
	lea	optionstab,a0
	bsr.w	g_getvalues
	bsr.w	setpri			; set new priority
	move.l	#channeltable,channeltableadr
	add.l	#4,channeltableadr	; reset sound
	rts

; * Select routine *

selector:
	movem.l	d0-d1,-(sp)
selectloop:
	bsr.w	wf			; wait frame
	bsr.w	message			; get IDCMP
	bsr.w	screenmanaging		; move, size screen
	lea	optionsgad,a0
	bsr.w	gadtext			; gadgets managing
	clr.b	saveask
	cmp.l	#g_ask,g_saveask
	bne.s	nosetsaveask
	move.b	#1,saveask
nosetsaveask:
	cmp.l	#g_center1,a0
	bne.w	nowincentx
	move.l	window,a0
	move.l	#-1,d0
	move.w	6(a0),d1
	bsr.w	movewindow
	suba.l	a0,a0
nowincentx:
	cmp.l	#g_center2,a0
	bne.w	nowincenty
	move.l	window,a0
	move.w	4(a0),d0
	move.l	#-1,d1
	bsr.w	movewindow
	suba.l	a0,a0
nowincenty:
	cmp.l	#g_see,a0		; "SEE" pressed ?
	bne.s	noseescreen		; no
	bsr.w	seescreen		; yes - open/close screen
noseescreen:
	cmp.l	#g_join,a0
	bne.s	nojoin
	bsr.w	join
	suba.l	a0,a0
nojoin:
	cmp.l	#g_hsave,a0
	bne.s	nohsave
	bsr.w	writescores
	suba.l	a0,a0
nohsave:
	cmp.l	#g_hload,a0
	bne.s	nohload
	bsr.w	loadscores
	suba.l	a0,a0
nohload:
	cmp.l	#g_show,a0
	bne.s	noshow

	lea	names,a0
	lea	scores,a1
	lea	levels,a2
	lea	stages,a3
	bsr.w	showhiscore

	suba.l	a0,a0
noshow:
	cmp.l	#g_clear,a0
	bne.s	noclear
	lea	areyousure,a0
	lea	yesnogad,a1
	moveq	#1,d0
	bsr.w	request
	clr.l	lastbutton
	cmp.l	#g_reqno,a0
	beq.s	noclear2
	bsr.w	clearhiscore
noclear2:
	suba.l	a0,a0
noclear:
	cmp.l	#0,a0			; anything pressed ?
	beq.W	selectloop		; no
selend:
	movem.l	(sp)+,d0-d1		; yes - exit
	rts

join:	movem.l	d0-d7/a0-a6,-(sp)
	bsr.w	openreq
	tst.l	d0
	bne.s	reqopened
	lea	reqtoolserr,a0
	lea	okgad,a1
	move.l	#1,d0
	bsr.w	request
	bra.w	join_end
reqopened:
	bsr.w	filerequest		; get scores' file name from requester

	move.l	#1005,d2
	move.l	dosbase,a6
	move.l	a0,d1
	jsr	_Open(a6)		; open it
	tst.l	d0
	beq.b	join_end
	move.l	d0,lock

	move.l	lock,d1
	move.l	#table2,d2
	move.l	#endoftable-table,d3
	move.l	dosbase,a6
	jsr	_Read(a6)		; read file

	move.l	lock,d1
	move.l	dosbase,a6
	jsr	_Close(a6)

	lea	table2,a0
	lea	table,a1
	bsr.b	JoinIt			; join scores

	bsr.w	closereq		; close reqtools

join_end:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

clearhiscore:
	movem.l	d0/d1/a0,-(sp)
	lea	scores,a0
	move.b	#0,d0
	move.l	#names-scores-1,d1
	bsr.w	bytesfill
	lea	names,a0
	move.b	#' ',d0
	move.l	#levels-names-1,d1
	bsr.w	bytesfill
	lea	levels,a0
	move.b	#0,d0
	move.l	#endoftable-levels-1,d1
	bsr.w	bytesfill
	movem.l	(sp)+,d0/d1/a0
	rts

; a0 - adress
; d0 - value
; d1 - number of bytes to fill-1

bytesfill:
	move.b	d0,(a0)+
	dbf	d1,bytesfill
	rts

; a0 - source hiscore table
; a1 - destination

JoinIt:
	move.l	a0,a2
	adda.l	#names-scores,a2
	move.w	#9,d7
ji_loop:
	bsr.b	equalcheck
	tst.l	d0
	beq.s	ji_next
	movem.l	a0/a1/a2/d7,-(sp)
	move.l	a2,d0
	move.l	a1,a2
	move.l	d0,a1
	move.l	(a0),d0
	move.l	levels-table(a0),d1
	move.l	stages-table(a0),d2
	move.l	a2,a0
	adda.l	#names-table,a0
	move.l	a2,a3
	adda.l	#levels-table,a3
	move.l	a2,a4
	adda.l	#stages-table,a4
	bsr.w	movenames
	movem.l	(sp)+,a0/a1/a2/d7
ji_next:
	adda.l	#4,a0
	adda.l	#30,a2
	dbf	d7,ji_loop
	rts

; a0 - score
; a1 - table

; d0 = 0  if equal

equalcheck:
	movem.l	d7/a2,-(sp)
	move.l	a0,a2
	move.l	a1,a3
	moveq	#11,d7
ec_loop:
	subq	#1,d7
	beq.s	ec_end
	move.l	(a2),d0
	cmp.l	(a3)+,d0
	bne.s	ec_loop
	move.l	levels-table-4(a3),d0
	cmp.l	levels-table(a2),d0
	bne.s	ec_loop
	move.l	stages-table-4(a3),d0
	cmp.l	stages-table(a2),d0
	bne.s	ec_loop
	move.l	a3,d1
	sub.l	a1,d1
	sub.l	#4,d1
	move.l	d1,d0
	neg.l	d0
	asr.l	#2,d1
	mulu	#30,d1
	add.l	#names-table,d1
	add.l	d1,d0
	add.l	a0,d0
	add.l	a1,d1
	move.l	d0,a4
	move.l	d1,a5
	move.w	#29,d6
ec_nameloop:
	move.b	(a5)+,d0
	cmp.b	(a4)+,d0
	bne.s	ec_loop
	dbf	d6,ec_nameloop
	movem.l	(sp)+,d7/a2
	moveq	#0,d0
	rts
ec_end:
	movem.l	(sp)+,d7/a2
	moveq	#1,d0
	rts

; * Move/size custom screen *

screenmanaging:
	move.l	g_scrsx,d0
	move.l	g_scrsy,d1
	cmp.l	lastscrsx,d0		; size x changed ?
	bne.s	scrsize			; yes - go to scrsize
	cmp.l	lastscrsy,d1		; size y changed ?
	bne.s	scrsize			; yes - go to scrsize
	tst.b	workb			; is this workbench screen ?
	bne.W	scrmend			; yes - exit

; * Move screen *

	move.l	g_scrx,d0
	move.l	g_scry,d1
	cmp.l	lastscrx,d0		; x position changed ?
	bne.B	scrmove			; yes - move screen
	cmp.l	lastscry,d1		; y position changed ?
	bne.s	scrmove			; yes - move screen
	rts				; come back

; * Size screen *

scrsize:
	move.l	d0,lastscrsx
	move.l	d1,lastscrsy
	tst.b	workb			; is this workbench screen ?
	bne.W	scrmend			; yes - exit
	move.w	d0,scr_sizex
	move.w	d1,scr_sizey
	bsr.w	closewindow		; close main window
	move.w	#WinSizeY,win_sizey	; window size
	bsr.w	closescreen		; close screen, of course
	move.w	g_scrx+2,scr_x		; get new x size
	move.w	g_scry+2,scr_y		; and y size
	bsr.w	openscreen		; open new screen
	bsr.w	openwindow		; and open window
	bsr.w	rysujpanel		; and draw background
	lea	optionsgad,a0
	moveq	#5,d0
	moveq	#2,d1
	move.l	#322,d2
	move.l	#145,d3
	bsr.w	drawscrollgad		; and draw gadgets
	rts

; * Move screen *

; Input: d0 - x position
;	 d1 - y position

scrmove:
	move.l	d0,lastscrx
	move.l	d1,lastscry
	sub.l	#1,d0
	move.l	actscreen,a0
	move.l	intbase,a6
	sub.w	8(a0),d0		; Calculate deltas
	sub.w	10(a0),d1
	jsr	_MoveScreen(a6)		; and jump to system
scrmend:
	rts

; "SEE" pressed

seescreen:
	cmp.l	#g_workbench,g_scrtype	; workbench selected ?
	beq.B	goonwb			; yes
	tst.b	workb			; no; is window opened on workbench ?
	beq.s	noopencustom		; no

; * See custom screen *

	bsr.w	closewindow		; yes - close window
	move.w	#WinSizeY,win_sizey	; window size
	move.w	g_scrx+2,scr_x		; set x,y position...
	move.w	g_scry+2,scr_y
	move.w	g_scrsx+2,scr_sizex	; ...and size
	move.w	g_scrsy+2,scr_sizey
	bsr.w	openscreen		; open custom screen
	bsr.w	openwindow		; and window on it
	bsr.w	rysujpanel		; draw background...
	lea	optionsgad,a0
	moveq	#5,d0
	moveq	#2,d1
	move.l	#322,d2
	move.l	#145,d3
	bsr.w	drawscrollgad		; ...and gadgets
noopencustom:
	suba.l	a0,a0
	rts

; * Go on workbench *

goonwb:
	tst.b	workb			; is this workbench ?
	bne.s	wbRulez			; yes - exit
	bsr.w	closewindow		; no - close window
	move.w	#WinSizeY,win_sizey	; window size
	bsr.w	closescreen		; close custom screen
	move.l	#0,win_screen		; screen address - 0
	move.w	#1,win_type		; screen type - workbench
	bsr.w	openwindow		; open on wb
; * Draw all *
	bsr.w	rysujpanel
	lea	optionsgad,a0
	moveq	#5,d0
	moveq	#2,d1
	move.l	#322,d2
	move.l	#145,d3
	bsr.w	drawscrollgad
wbRulez:
	suba.l	a0,a0
	rts

; * Move window *

; input: d0,d1 - window x,y

movewindow:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	window,a0
	move.l	intbase,a6
	move.l	actscreen,a2
	move.w	$c(a2),d2
	move.w	$e(a2),d3

	tst.w	d0			; window x positive ?
	bpl.s	nomovecenterx		; yes
	move.w	d2,d0			; no - center x
	sub.w	win_sizex,d0
	asr.w	#1,d0
nomovecenterx:
	cmp.w	#-1,d1			; window y positive ?
	bne.s	nomovecentery		; yes
	move.w	d3,d1			; no - center y
	sub.w	win_sizey,d1
	asr.w	#1,d1
nomovecentery:
	sub.w	4(a0),d0		; calculate deltas
	sub.w	6(a0),d1
	jsr	_MoveWindow(a6)		; move window
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - source
; a1 - destination
; d0 - count

; justify: left

; * This procedure copy source ASCII string (value) to destination *
; * It will delete superfluous zeros and move string to left       *

valcopy:
	movem.l	d0-d2/a0-a1,-(sp)
	move.b	#' ',d2
valcop_here:
	move.w	d0,d1
	ext.l	d0
	subq.l	#6,d0
	sub.l	d0,a0
	sub.w	#1,d1
valcopyloop:
	move.b	(a0)+,d0
	cmp.b	d2,d0
	beq.s	val_nwrt
	move.b	d0,(a1)+
	dbf	d1,valcopyloop
	cmp.b	#' ',-(a1)
	bne.s	noinszero
	move.b	#'0',(a1)
	bra.s	noinszero
val_nwrt:
	dbf	d1,valcopyloop
	move.b	#'0',(a1)
noinszero:
	movem.l	(sp)+,d0-d2/a0-a1
	rts

; a0 - source
; a1 - destination
; d0 - count

; justify: right

; * Like above *

valcopy2:
	movem.l	d0-d2/a0-a1,-(sp)
	move.b	#255,d2
	bra.s	valcop_here

; * ERROR *

opt_error:
	bsr.w	flash
	rts

; a0 - options table

; * See: "valtogad" *

g_setvalues:
	movem.l	d0-d7/a0-a6,-(sp)
g_setloop1:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_setloop2
	move.l	(a0)+,a2
	move.l	(a1),(a2)
	bra.s	g_setloop1
g_setloop2:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_setloop3
	move.l	(a0)+,a2
	move.w	(a1),d0
	ext.l	d0
	move.l	d0,(a2)
	bra.s	g_setloop2
g_setloop3:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_nextoptions
	move.l	(a0)+,a2
	move.b	(a1),d0
	ext.w	d0
	ext.l	d0
	move.l	d0,(a2)
	bra.s	g_setloop3
g_nextoptions:
	move.w	#2,d7
g_setloop4:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_opnext
	move.l	(a0)+,d0
	move.l	(A0)+,a2
	move.l	(a0)+,d1
	cmp.w	#2,d7
	beq.s	lop
	cmp.w	#1,d7
	beq.s	wop
	cmp.w	#0,d7
	beq.s	bop
g_setit:
	move.l	d1,(a2)
	bra.s	g_setloop4
	
g_opnext:
	dbf	d7,g_setloop4

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

lop:
	move.l	(a1),d2
	cmp.l	d0,d2
	bne.s	g_setloop4
	bra.s	g_setit

wop:
	move.w	(a1),d2
	cmp.w	d0,d2
	bne.s	g_setloop4
	bra.s	g_setit

bop:
	move.b	(a1),d2
	cmp.b	d0,d2
	bne.s	g_setloop4
	bra.s	g_setit

; a0 - options table

; See: "gadtoval"

g_getvalues:
	movem.l	d0-d7/a0-a6,-(sp)
g_getloop1:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_getloop2
	move.l	(a0)+,a2
	move.l	(a2),(a1)
	bra.s	g_getloop1
g_getloop2:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_getloop3
	move.l	(a0)+,a2
	move.l	(a2),d0
	move.w	d0,(a1)
	bra.s	g_getloop2
g_getloop3:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_getnext
	move.l	(a0)+,a2
	move.l	(a2),d0
	move.b	d0,(a1)
	bra.s	g_getloop3
g_getnext:
	move.w	#2,d7
g_getloop4:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	g_getopnext
	move.l	(a0)+,d0
	move.l	(A0)+,a2
	move.l	(a0)+,d1
	cmp.w	#2,d7
	beq.s	glop
	cmp.w	#1,d7
	beq.s	gwop
	cmp.w	#0,d7
	beq.s	gbop
	
g_getopnext:
	dbf	d7,g_getloop4

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

glop:
	move.l	(a2),d2
	cmp.l	d1,d2
	bne.s	g_getloop4
	move.l	d0,(a1)
	bra.s	g_getloop4

gwop:
	move.l	(a2),d2
	cmp.l	d1,d2
	bne.s	g_getloop4
	move.w	d0,(a1)
	bra.s	g_getloop4

gbop:
	move.l	(a2),d2
	cmp.l	d1,d2
	bne.s	g_getloop4
	move.b	d0,(a1)
	bra.s	g_getloop4

; * "ABOUT" pressed *

m_about:
	move.b	#1,optflag		; don't redraw window
	lea	atext,a0		; text
	lea	okgad,a1		; gadgets
	move.l	#17,d0			; size y - 15 lines
	bsr.w	request			; show requester
	rts

; * "JUMP" pressed *

m_JUMP:
	move.l	intbase,a0
	move.l	$3c(a0),a0		; get first screen
	cmp.l	#0,(a0)			; no second screen ?
	beq.W	m_jumend		; yes - exit

; * Make screen list *

	lea	jumpgads,a1
	lea	screennames,a2
	lea	screenadr,a3
	move.l	#2,d0
m_jumloop:
	cmp.l	actscreen,a0
	beq.s	m_jumnext
	move.l	a0,(a3)+
	move.l	#1,(a1)+
	move.l	#4,(a1)+
	move.l	d0,(a1)+
	move.l	#40*8+4,(a1)+
	move.l	#14,(a1)+
	move.l	a2,(a1)+
	move.l	#0,(a1)+
	move.l	#0,(a1)+
	move.l	#$80000000,(a1)+
	move.b	#1,(a2)+
	move.b	#6,(a2)+
	move.b	#10,(a2)+
	movem.l	a0/a1/d0,-(sp)
	move.l	$16(a0),a0
	move.l	a2,a1
	moveq	#40,d0
	bsr.w	movenulltext
	movem.l	(sp)+,a0/a1/d0
	adda.l	#44,a2
	add.w	#16,d0
m_jumnext:
	move.l	(a0),a0
	cmp.l	#0,a0
	bne.s	m_jumloop

; * Add "GO BACK" gadget

	add.l	#8,d0
	move.l	#1,(a1)+
	move.l	#4+132,(a1)+
	move.l	d0,(a1)+
	move.l	#7*8+4,(a1)+
	move.l	#14,(a1)+
	move.l	#g_goback,(a1)+
	move.l	#0,(a1)+
	move.l	#0,(a1)+
	move.l	#$80000000,(a1)+
	move.l	#0,(a1)+
	add.l	#16,d0

	lea	defwindow,a0		; store main window
	bsr.w	storewindow		; structure

	move.w	#-1,win_x
	move.w	#-1,win_y
	add.w	#4,d0
	move.w	d0,win_sizey
	move.w	#42*8+4,win_sizex
	move.l	#selscr,win_title
	move.l	#$20000+$2+$4+$2000,win_flags
	move.l	#$8,win_idcmpflags
	bsr.w	openwindow		; open new window
	lea	jumpgads,a0
	bsr.w	drawgadgets		; draw gadgets
m_jumsel:
	bsr.w	wfnp			; wait frame
	bsr.w	message			; get IDCMP
	lea	jumpgads,a0
	bsr.w	dogadget		; gadgets managing
	cmp.l	#0,a0			; something pressed ?
	beq.s	m_jumsel		; if no then wait 
	cmp.l	#g_goback,20(a0)	; "GO BACK" pressed ?
	beq.b	m_jumbo			; yes
	move.l	a0,d0			; no - calculate number
	sub.l	#jumpgads,d0		; of selected screen
	divu	#9*4,d0
	asl.l	#2,d0
	bsr.w	closewindow		; close window
	lea	defwindow,a0		; restore main window
	bsr.w	restorewindow		; structure
	bsr.w	closewindow		; close main window
	bsr.w	closescreen		; try to close screen
	lea	screenadr,a0		; get address of
	move.l	(a0,d0.w),win_screen	; selected screen
	move.w	#$f,win_type		; screen type: CUSTOM
	move.w	#WinSizeY,win_sizey	; window size
	bsr.w	openwindow		; open window again
	rts
m_jumbo:
	move.b	#1,optflag		; "GO BACK" pressed:
					; don't restore main window
	bsr.w	dogadget		; release gadget
	bsr.b	waitblit		; wait for blitter and
	bsr.w	closewindow		; close window
	lea	defwindow,a0		; switch to main window
	bsr.w	restorewindow
	rts

; * There's only one screen ! *     :-(

m_jumend:
	move.b	#1,optflag
	bsr.w	flash
	rts

; * Wait for blitter *

waitblit:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	gfxbase,a6
	jsr	_WaitBlit(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; Input
; a0 - source text

; Output
; d0 - maximum chars in line

; * It's self-evident *

maxchars:
	movem.l	d1-d2/a0,-(sp)
	clr.l	d0
	clr.l	d2
maxnext:
	cmp.l	d0,d2
	ble.s	nomax
	move.l	d2,d0
nomax:
	clr.l	d2
maxloop:
	move.b	(a0)+,d1
	beq.s	maxend
	cmp.b	#10,d1
	beq.s	maxnext
	addq	#1,d2
	bra.s	maxloop
maxend:
	cmp.l	d0,d2
	ble.s	nomax2
	move.l	d2,d0
nomax2:
	movem.l	(sp)+,d1-d2/a0
	rts

easystruct:
	dc.l	20
	dc.l	0
	dc.l	tit_req
easy_text:
	dc.l	0
	dc.l	easy_gadgets

easy_gadgets:
	ds.b	80

req_gadgets:
	ds.l	5

intrequest:
	movem.l	d0-d7/a1-a6,-(sp)
	move.l	a0,easy_text
	lea	req_gadgets,a3
	lea	easy_gadgets,a5
	clr.l	d7
ir_gadloop:
	move.l	(a1)+,d0
	beq.s	ir_gadloopend
	move.l	(a1)+,d0
	move.l	(a1)+,d0
	move.l	(a1)+,d0
	move.l	(a1)+,d0
	move.l	(a1)+,a4
	move.l	a4,(a3)+
	move.b	(a4)+,d0
	move.b	(a4)+,d0
	move.b	(a4)+,d0
ir_movetxtloop:
	move.b	(a4)+,d0
	beq.s	ir_movetxtloopend
	move.b	d0,(a5)+
	bra.s	ir_movetxtloop
ir_movetxtloopend:
	move.b	#"|",(a5)+
	add.l	#1,d7
	move.l	(a1)+,d0
	move.l	(a1)+,d0
	move.l	(a1)+,d0
	bra.s	ir_gadloop
ir_gadloopend:
	move.b	#0,-(a5)
	move.l	intbase,a6
	move.l	window,a0
	lea	easystruct,a1
	suba.l	a2,a2
	suba.l	a3,a3
	jsr	_EasyRequestArgs(a6)
	sub.b	#1,d0
	cmp.b	#-1,d0
	bne.s	ir_norm
	move.b	d7,d0
	sub.b	#1,d0
ir_norm:
	add.b	d0,d0
	add.b	d0,d0
	ext.w	d0
	lea	req_gadgets,a0
	move.l	(a0,d0.w),a0
	movem.l	(sp)+,d0-d7/a1-a6
	rts

	dc.l	1,0,0,5*8+4,10,g_retry,0,0,$80000000
	dc.l	1,0,0,6*8+4,10,g_cancel,0,0,$80000000
	dc.l	0


; Input:
; a0 - text
; a1 - gadgets
; d0 - height (in lines)

; Output:
; a0 - gadget

request:
	cmp.b	#36,intver
	beq.w	intrequest
	movem.l	d0-d7/a1-a6,-(sp)
	move.l	scrollspeed,scrolltemp	; store line spacing
	move.l	g_minx,minxtemp		; store scroll region
	move.l	g_miny,minytemp
	move.l	g_maxx,maxxtemp
	move.l	g_maxy,maxytemp
	move.b	#1,scrmask		; scroll only 1 bitplane
	move.l	#8,scrollspeed		; line spacing: 8 pixels
	move.l	a0,-(sp)
	lea	reqwindow,a0		; store main window
	bsr.w	storewindow

	move.l	#$20000+$2+$4+$2000,win_flags	; window flags...
	move.l	#$8+$200000,win_idcmpflags	; ...IDCMP flags...
	move.l	#tit_req,win_title		; ...and title, of course

	move.l	(sp)+,a0

	move.w	#-1,win_x		; center x
	move.w	#-1,win_y		; center y
	asl.l	#3,d0			; calculate y size
	add.w	#3+32,d0
	move.w	d0,win_sizey

	bsr.w	maxchars		; how many chars in line ?
	asl.w	#3,d0			; calculate x size
	add.w	#4*8,d0
	move.w	d0,win_sizex
	bsr.w	openwindow		; open window

	move.l	a1,-(sp)

; * split text to lines *

	lea	reqgads,a1
	move.l	#2+8,d0
reqgloop:
	move.l	#7,(a1)+
	move.l	#2+8,(a1)+
	move.l	d0,(a1)+
	move.l	a0,(a1)+
	move.l	#$80000000,(a1)+
	add.l	#8,d0
reqgtloop:
	move.b	(a0)+,d1
	beq.s	reqgend
	cmp.b	#10,d1
	bne.s	reqgtloop
	bra.s	reqgloop
reqgend:
	move.l	(sp)+,a0
	move.l	#8,d0			; left margin
	move.w	win_sizex,d1
	ext.l	d1
	sub.l	#16+8,d1		; size x
	move.w	win_sizey,d2
	sub.w	#16+8+8,d2
	ext.l	d2			; position y
	bsr.w	spreadgads		; spread gadgets in requester
	move.l	#0,(a1)+
	lea	reqgads,a0
	moveq	#4,d0			; calculate scroll region
	moveq	#4,d1
	move.w	win_sizex,d2
	ext.l	d2
	sub.l	#6,d2
	move.w	win_sizey,d3
	sub.w	addy,d3
	sub.w	#4*8,d3
	ext.l	d3
	bsr.w	drawscrollgad		; draw text & gadgets
reqwfg:	bsr.w	message			; get IDCMP...
	bsr.w	wfnp			; ...and wait for frame (again)
	lea	reqgads,a0
	bsr.w	gadtext
	cmp.l	#0,a0			; wait for gadget
	beq.s	reqwfg
	move.l	a0,-(sp)		; something pressed
	bsr.w	message
	lea	reqgads,a0
	bsr.w	gadtext			; release button
	bsr.w	closewindow		; close window
	lea	reqwindow,a0
	bsr.w	restorewindow		; restore main window
	move.l	(sp)+,a0
	move.l	scrolltemp,scrollspeed	; restore old values
	move.l	minxtemp,g_minx
	move.l	minytemp,g_miny
	move.l	maxxtemp,g_maxx
	move.l	maxytemp,g_maxy
	move.b	#$ff,scrmask
	movem.l	(sp)+,d0-d7/a1-a6	; come
	rts				; back

; * Spread gadgets in the requester window *

; a0 - source gadgets
; a1 - destination gadgets
; d0 - left margin
; d1 - x size
; d2 - y position

spreadgads:
	movem.l	d0-d7/a2-a6,-(sp)
	move.l	a0,-(sp)
	move.l	12(a0),d3
	asr.l	#1,d3
	add.l	d3,d0
	sub.l	d3,d1
	clr.l	d7
sprlop:	bsr.w	nextgadget
	tst.l	(a0)
	beq.s	sprlopend
	addq	#1,d7
	move.l	12(a0),d3
	bra.s	sprlop
sprlopend:
	asr.l	#1,d3
	sub.l	d3,d1
	cmp.l	#0,d7
	bne.s	sprnozero
	move.l	#2,d7
	divu	d7,d1
	ext.l	d1
	add.l	d1,d0
	bra.s	sphere
sprnozero:
	divu	d7,d1
	ext.l	d1
sphere:
	move.l	(sp)+,a0

	clr.l	d4
sprloop:
	move.l	(a0)+,d3
	beq.s	sprend
	move.l	d3,(a1)+
	move.l	(a0)+,d5
	move.l	(a0)+,d6
	move.l	(a0)+,d5
	move.l	(a0)+,d6
	move.l	d4,(a1)
	add.l	d0,(a1)
	asr.l	#1,d5
	sub.l	d5,(a1)+
	asl.l	#1,d5
	add.l	d1,d4
	move.l	d2,(a1)+
	move.l	d5,(a1)+
	move.l	d6,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	bra.s	sprloop
sprend:
	movem.l	(sp)+,d0-d7/a2-a6
	rts

; * Move source to destination *

; a0 - source
; a1 - destination
; d0 - how many chars

movenulltext:
	movem.l	a0/a1/d0,-(sp)
	subq	#1,d0
movetloop:
	move.b	(a0)+,(a1)
	tst.b	(a1)
	beq.s	movetdone
	cmp.b	#10,(a1)+
	beq.s	movetdone
	dbf	d0,movetloop
	move.b	#0,(a1)+
movetdone:
	movem.l	(sp)+,a0/a1/d0
	rts

; * Drag to other screen *

dragging:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.w	drag			; window dragged ?
	beq.b	drag_end		; if no - exit

	move.l	intbase,a0
	move.l	$3c(a0),a0		; get first screen address
searchscreen:
	move.w	$10(a0),d0		; get mouse y
	tst.w	d0			; positive ?
	bpl.s	thisscreen		; yes - that's it !
	move.l	(a0),a0			; no - get next screen address
	cmp.l	#0,a0
	beq.s	drag_end		; no more screens - exit
	bra.s	searchscreen		; check next screen
thisscreen:
	cmp.l	actscreen,a0		; is it actual screen ?
	beq.s	drag_end		; yes - exit

	move.l	$28(a0),a1		; screen font to a1
	move.w	4(a1),d0		; get y size
	add.w	#WinSizeY+3,d0		; add window size

	move.w	$e(a0),d1		; get screen size
	cmp.w	d0,d1			; compare it
	blt.s	drag_err		; screen too small !

	movem.l	d0-d7/a0-a6,-(sp)	; screen OK :->

	bsr.w	closewindow		; close window

	bsr.b	closescreen		; try to close screen

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

	move.l	a0,actscreen		; set new screen address
	move.l	a0,win_screen
	move.w	#$f,win_type		; type: CUSTOM
	move.w	#12,win_y		; position y=12
	move.w	#0,win_sizey		; size y=0 (drag bar only)

	bsr.w	openwindow		; open window

drag_end:
	movem.l	(sp)+,d0-d7/a0-a6
	rts				; return

; * ERROR - cannot jump to this screen ! *

drag_err:
	bsr.w	flash
	bra.s	drag_end

; * This procedure try to close screen *

closescreen:
	movem.l	d0-d7/a0-a6,-(sp)
	move.b	#1,workb		; set workbench flag
	move.l	actscreen,a0
	cmp.l	#0,a0			; nothing to close ?
	beq.s	noclosescreen		; ya !
	tst.l	4(a0)			; get first window
	bne.s	noclosescreen		; cannot close !
	clr.l	actscreen		; no screen
	move.l	intbase,a6
	jsr	_CloseScreen(a6)	; and finally: CLOSE IT !
noclosescreen:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Sleep *

poczrmb:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.b	mousebutton		; ANY button pressed ?
	bne.w	poczend			; no - exit
	bsr.w	rmb			; right mouse button pressed ?
	bne.W	poczend			; no - exit
poczrmlop:
	bsr.w	message			; get IDCMP
	bsr.w	rmb			; right mouse button released ?
	beq.s	poczrmlop		; no - wait
	bsr.w	windowsmall		; go to SLEEP
poczlop:

	moveq	#1,d1
	move.l	dosbase,a6
	jsr	_Delay(a6)		; delay (?)

	bsr.w	message			; get IDCMP

	bsr.w	dragging		; dragged to other screen ?

	bsr.w	rmb			; right mouse button pressed ?
	bne.s	poczlop			; no - wait
poczwlop:
 	bsr.w	message			; get IDCMP
	bsr.w	rmb			; right mouse button released ?
	beq.s	poczwlop		; no - wait
	bsr.w	message			; get IDCMP

	bsr.w	windowbig		; wake up

; * Draw all *

	bsr.w	rysujpanel

	lea	gadgetlist,a0
	bsr.w	drawgadgets

	bsr.s	drawminiarcanoid

; * Find first letter to draw in scroll *

	move.l	scrolladr,a0
	move.w	#38,d1
lettersearch:
	cmp.b	#-1,-(a0)
	beq.s	lettersearch
	cmp.b	#-2,(a0)
	beq.s	lettersearch
	dbf	d1,lettersearch

	move.b	speed,d0
	ext.w	d0
	ext.l	d0
	move.l	#8,d1
	divu	d0,d1
	move.b	d1,licznik

	bsr.w	line			; draw scroll

poczend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * !!! *

drawminiarcanoid:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	arcanoid,a0
	clr.l	d0
	clr.l	d1
	move.l	#75,d3
	move.l	#300,d4
	move.l	#61,d5
	move.l	#10,d2
	bsr.w	rysuj

	lea	mi4,a0
	clr.l	d0
	clr.l	d1
	move.l	#35,d3
	move.l	#76,d4
	move.l	#34,d5
	move.l	#122,d2
	bsr.w	rysuj
	movem.l	(sp)+,d0-d7/a0-a6

	rts

; * Flash screen *

flash:
	tst.b	flash_f			; May I flash ?
	beq.s	flend			; no way, man !
	movem.l	d0-d7/a0-a6,-(sp)	; YEAH !
	move.l	intbase,a6
	suba.l	a0,a0
	jsr	_DisplayBeep(a6)	; BEEEEEEEP !
	movem.l	(sp)+,d0-d7/a0-a6
flend:	rts

; * Load samples *
;        |
;        |
;        V
loadsamples:
	tst.b	sound			; is sound on ?
	beq.W	soend			; no - exit
	tst.b	sampleloaded		; is the samples loaded ?
	bne.W	soend			; yes - exit
	move.b	#1,sampleloaded		; now, they're loaded !
	movem.l	d0-d7/a0-a6,-(sp)

	lea	ppname,a1
	move.l	4,a6
	jsr	_OldOpenLibrary(a6)	; open powerpacker library
	move.l	d0,ppbase

	lea	samples,a0
	lea	samtable,a3
loadloop:
	move.l	(a0),d1			; get sample name
	cmp.l	#-1,d1			; is it the last one ?
	beq.W	loadend			; yes - go to end

	move.l	d1,filename		; store file name...
	
	move.l	a0,tabpos		; ...and position in table

	tst.l	ppbase			; powerpacker.library loaded ?
	beq.s	stdload			; no - go to standard load

; * PowerPacker load *

ppload:
	movem.l	d1-d7/a0-a6,-(sp)
	move.l	filename,a0
	move.l	#2,d0
	move.l	#$0,d1			; CHIP memory
	move.l	#tempaddr,a1
	move.l	#filesize,a2
	suba.l	a3,a3			; powerpacker will get password
	move.l	ppbase,a6
	jsr	_ppLoadData(a6)		; LOAD it !
	movem.l	(sp)+,d1-d7/a0-a6
	tst.l	d0			; error ?
	bne.w	pperr			; ERROR !
	bra.w	jumpherefrompp		; go on

; * Standard load *

stdload:
	move.l	filename,d1
	moveq	#-2,d2
	move.l	dosbase,a6
	jsr	_Lock(a6)		; get lock
	tst.l	d0
	beq.s	lerr
	move.l	d0,d1

	move.l	d1,-(sp)
	move.l	#fileinfoblock,d2	; file info block
	addq.l	#3,d2			; must be longword
	and.l	#$fffffffc,d2		; aligned !
	move.l	d2,fileinfoadr

	move.l	dosbase,a6
	jsr	_Examine(a6)		; examine file
	move.l	fileinfoadr,a0
	move.l	124(a0),filesize	; here's file size !
	move.l	(sp)+,d1

	move.l	dosbase,a6
	jsr	_UnLock(a6)		; unlock file

	move.l	#1005,d2
	move.l	dosbase,a6
	move.l	filename,d1
	jsr	_Open(a6)		; open
	tst.l	d0
	bne.s	norm33
lerr:
	bsr.w	flash			; error
	move.l	tabpos,a0
	move.l	#0,(a0)+		; no sample !
	move.l	#0,(a3)+
	move.w	#0,(a3)+
	move.w	#0,(a3)+
	bra.W	loadloop		; read next
norm33:	move.l	d0,lock

	move.l	filesize,d0
	move.l	#1,d1
	bsr.w	sysalloc		; allocate memory
	move.l	d0,tempaddr

	move.l	tabpos,a0
	move.l	d0,(a0)			; put address in table

	move.l	lock,d1
	move.l	d0,d2
	move.l	filesize,d3
	move.l	dosbase,a6
	jsr	_Read(a6)		; read file

	jsr	_IOErr(a6)		; error check
	tst.l	d0
	bne.w	rwerr

	move.l	lock,d1
	move.l	dosbase,a6
	jsr	_Close(a6)		; close

jumpherefrompp:
	move.l	tempaddr,a0
	bsr.w	analyseiff		; analyse sample
	tst.l	d0			; play rate=0 ?
	beq.w	lerr			; if yes - not an IFF file
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	a0,bodyadr
	move.l	d1,len
	move.l	d1,newlen
	divu	#50,d0			; sample must not be shorter
	cmp.w	d0,d1			; than 1/50 s, because
	bge.s	nochlen			; the program turn sound off
	move.l	d1,newlen		; while vertical blanking
nochlen:
	move.l	#$10002,d1
	move.l	newlen,d0		; allocate memory for
	bsr.w	allocate		; raw sample
	move.l	d0,actaddr

	move.l	bodyadr,a0
	move.l	actaddr,a1
	move.l	len,d0
	move.l	4,a6
	jsr	_CopyMem(a6)		; copy BODY chunk

	move.l	tempaddr,a1
	move.l	filesize,d0
	move.l	4,a6
	jsr	_FreeMem(a6)		; free temporary memory

	movem.l	(sp)+,d0-d7/a0-a6
	move.l	actaddr,(a3)+
	movem.l	d2-d3,-(sp)		; calculate sample period
	move.l	d0,d2
	move.l	#3546895,d3		; value for PAL
	divu	d2,d3
	move.l	d3,d0
	movem.l	(sp)+,d2-d3
	move.w	d0,(A3)+		; all to table
	ror.l	#1,d1
	move.w	d1,(a3)+

nextsample:
	move.l	tabpos,a0
	adda.l	#4,a0

	bra.W	loadloop		; next sample

; * No more samples *

loadend:
	tst.l	ppbase
	beq.s	nooppp
	move.l	ppbase,a1
	move.l	4.w,a6
	jsr	_CloseLibrary(a6)	; close powerpacker.library
	clr.l	ppbase
nooppp:	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Powerpacker load error *

; d0 - error number

pperr:
	cmp.l	#-3,d0
	beq.s	ppmemerr		; not enough memory
	cmp.l	#-5,d0
	beq.s	pppasserr		; wrong password
	cmp.l	#-7,d0
	beq.s	ppunknownpp		; unknown powerpacker version
	bra.w	lerr

; * Not enough memory *

ppmemerr:
	movem.l	d0-d7/a1-a6,-(sp)
	lea	allerrtext,a0
	lea	retryquitgad,a1
	move.l	#1,d0
	bsr.w	request
	cmp.l	#g_quit,a0	
	beq.w	error
	movem.l	(sp)+,d0-d7/a1-a6
	bra.w	ppload

; * Wrong password *

pppasserr:
	movem.l	d0-d7/a1-a6,-(sp)
	lea	wrongpassword,a0
	lea	okgad,a1
	move.l	#1,d0
	bsr.w	request
	movem.l	(sp)+,d0-d7/a1-a6
	bra.w	lerr

; * Unknown version of powerpacker *

ppunknownpp:
	movem.l	d0-d7/a1-a6,-(sp)
	lea	unknownpp,a0
	lea	okgad,a1
	move.l	#2,d0
	bsr.w	request
	movem.l	(sp)+,d0-d7/a1-a6
	bra.w	lerr

; * Read/write error *

rwerr:
	bsr.w	flash
	move.l	filesize,d0
	move.l	tempaddr,a1
	move.l	4.w,a6
	jsr	_FreeMem(a6)
	move.l	tabpos,a0
	move.l	#0,(a0)+
	move.l	#0,(a3)+
	move.w	#0,(a3)+
	move.w	#0,(a3)+
	bra.W	loadloop

; * Set task priority *

setpri:
	movem.l	d0-d7/a0-a6,-(sp)
	suba.l	a1,a1
	move.l	4,a6
	jsr	_FindTask(a6)
	move.l	d0,a1
	move.l	g_pri,d0
	cmp.l	#g_minus,g_prisig
	bne.s	sp_nomin
	neg.l	d0
sp_nomin:
	move.l	4,a6
	jsr	_SetTaskPri(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Allocate memory *

allocate:
	movem.l	d1-d7/a0-a6,-(sp)
	move.l	d0,-(sp)
	bsr.b	sysalloc
	move.l	(sp)+,d1
	move.l	alloctableadr,a0
	move.l	d0,(a0)+
	move.l	d1,(a0)+
	move.l	a0,alloctableadr
	movem.l	(sp)+,d1-d7/a0-a6
	rts	

sysalloc:
	move.l	d0,al_size
	bset	#0,d1
	move.l	d1,al_req
alretry:
	move.l	4.w,a6
	jsr	_AllocMem(a6)
	tst.l	d0
	beq.B	allocerror
	rts

; * Not enough memory *

allocerror:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	allerrtext,a0
	lea	retryquitgad,a1
	move.l	#1,d0
	bsr.w	request
	cmp.l	#g_quit,a0	
	beq.w	error
	movem.l	(sp)+,d0-d7/a0-a6
	move.l	al_size,d0
	move.l	al_req,d1
	bra.s	alretry

; * Deallocate all *

deallocate:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	alloctable,a0
deallocloop:
	move.l	(a0)+,a1
	cmp.l	#0,a1
	beq.s	deallocend
	move.l	(a0)+,d0
	move.l	a0,-(sp)
	move.l	4,a6
	jsr	_FreeMem(a6)
	move.l	(sp)+,a0
	bra.s	deallocloop
deallocend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Highscore entry *

hiscore:
	movem.l	d0-d7/a0-a6,-(sp)

	bsr.w	clearpointer		; normal pointer
	move.l	punkty,d0
	lea	scores,a0
	move.l	36(a0),d1		; get last score
	cmp.l	d1,d0			; if greater than your score
	ble.W	nohisc			; then only show table
	
	move.w	#5,sample
	move.l	#160,position
	bsr.w	playsample

	bsr.w	getname

	tst.l	d0
	beq.s	nohisc

rnok:
	clr.l	d1
	lea	imie,a0			; clear name
	move.w	#29,d7
addspaces:
	move.b	(a0),d0
	tst.b	d0
	bne.s	as_noend
	moveq	#-1,d1
as_noend:
	tst.l	d1
	beq.s	nocl
	move.b	#32,(a0)
nocl:	add.l	#1,a0
	dbf	d7,addspaces

	lea	imie,a1			; name
	lea	names,a0		; stored names
	lea	scores,a2		; high scores
	lea	levels,a3		; stored levels
	lea	stages,a4		; and stages

	move.l	punkty,d0		; your score
	move.l	nrpl,d1			; level number
	move.b	level,d2		; stage number (it's TRUE)
	ext.w	d2
	ext.l	d2
	addq	#1,d2

	bsr.w	movenames		; write to table

	tst.b	savemode
	bne.s	nohisc

	bsr.w	writescores		; write table to disk

nohisc:
	lea	names,a0
	lea	scores,a1
	lea	levels,a2
	lea	stages,a3
	bsr.w	showhiscore		; show scores

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

getname:
	bsr.w	OPENREQ
	tst.l	d0
	beq.s	gn_noreq

	lea	imie,a1
	move.l	#30,d0
	lea	enter,a2
	bsr.w	getstring

	move.l	d0,-(sp)
	bsr.w	CLOSEREQ
	move.l	(sp)+,d0
	rts

gn_noreq:
	lea	defwindow,a0		; store main window
	bsr.w	storewindow

	move.w	#40,win_sizey		; set window parameters
	move.w	#260,win_sizex
	move.l	actscreen,a0
	move.w	$10(a0),win_y
	move.w	$12(a0),win_x
	sub.w	#10,win_y
	sub.w	#130,win_x
	tst.w	win_y
	bpl.s	ok1
	move.w	#0,win_y
ok1:	tst.w	win_x
	bpl.s	ok2
	move.w	#0,win_x
ok2:
	move.l	#enter,win_title
	move.l	#$20000+$2+$4+$2000,win_flags
	bsr.w	openwindow		; open window
	move.l	intbase,a6
	move.l	window,$34(a6)

	lea	imie,a0			; clear name
	clr.b	-1(a0)
	move.w	#29,d7
cleartext:
	move.b	#32,(a0)+
	dbf	d7,cleartext

	lea	namegads,a0
	bsr.w	drawgadgets
	bsr.w	initstring

rnloop:
	bsr.w	wf
	bsr.w	message
	lea	namegads,a0
	bsr.w	gadtext
	cmp.w	#13,key
	beq.s	gn_rnok
	cmp.l	#0,a0
	beq.s	rnloop

	bsr.w	closewindow		; close window
	lea	defwindow,a0		; restore old window
	bsr.w	restorewindow

	moveq	#0,d0
	rts
gn_rnok:
	bsr.w	closewindow		; close window
	lea	defwindow,a0		; restore old window
	bsr.w	restorewindow

	moveq	#-1,d0
	rts


; * Load highscores *

loadscores:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	#hiscorefile,d1
	move.l	#1005,d2
	move.l	dosbase,a6
	jsr	_Open(a6)		; open file
	tst.l	d0
	bne.s	norm
	bsr.w	flash			; no file
	bra.s	ls_end
norm:	move.l	d0,lock

	move.l	lock,d1
	move.l	#scores,d2
	move.l	#endoftable-table,d3
	move.l	dosbase,a6
	jsr	_Read(a6)		; read file

	move.l	lock,d1
	move.l	dosbase,a6
	jsr	_Close(a6)		; close file

ls_end:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Write scores to disk *

writescores:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.b	cheatmode
	beq.s	nocheat
	lea	cheatmodetxt,a0
	lea	okgad,a1
	move.l	#2,d0
	bsr.w	request
	clr.l	lastbutton
	bra.s	comeon2
nocheat:
	tst.b	saveask
	beq.s	writescoresnow
	lea	writescoresask,a0
	lea	yesnogad,a1
	move.l	#1,d0
	bsr.w	request
	clr.l	lastbutton
	cmp.l	#g_reqno,a0
	beq.s	comeon2
writescoresnow:
	move.l	#hiscorefile,d1
	move.l	#1006,d2
	move.l	dosbase,a6
	jsr	_Open(a6)		; open file
	tst.l	d0
	bne.s	norm2
	bsr.w	flash
	bra.s	comeon2
norm2:	move.l	d0,lock

	move.l	lock,d1
	move.l	#scores,d2
	move.l	#endoftable-table,d3
	move.l	dosbase,a6
	jsr	_Write(a6)		; write

	move.l	lock,d1
	move.l	dosbase,a6
	jsr	_Close(a6)		; close

comeon2:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - names
; a1 - scores
; a2 - levels
; a3 - stages

; * Show highscore table *

showhiscore:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	a0,-(sp)
	lea	defwindow,a0
	bsr.w	storewindow		; store main window
	move.w	#122,win_sizey		; set parameters
	move.w	#434,win_sizex
	move.l	actscreen,a0
	move.w	$10(a0),win_y
	move.w	$12(a0),win_x
	sub.w	#217,win_x
	sub.w	#61,win_y
	tst.w	win_y
	bpl.s	ok3
	move.w	#0,win_y
ok3:	tst.w	win_x
	bpl.s	ok4
	move.w	#0,win_x
ok4:
	move.l	#hi,win_title
	move.l	#$20000+$2+$4,win_flags
	move.l	#$8,win_idcmpflags
	bsr.w	openwindow		; open window

	moveq	#1,d0
	moveq	#1,d1
	bsr.w	setsoftstyle		; style - 1
	moveq	#0,d0
	bsr.w	setdrmode		; draw mode - 0
	moveq	#1,d0
	bsr.w	setcolor		; color - 1
	move.w	#5,d0			; position x
	move.w	#11,d1			; position y
	move.w	#hitextend-hitext,d2	; text length
	lea	hitext,a0		; text address
	bsr.w	showtext		; show text
	moveq	#2,d0			; color - 2
	bsr.w	setcolor
	move.w	#4,d0
	move.w	#10,d1
	move.w	#hitextend-hitext,d2
	lea	hitext,a0
	bsr.w	showtext		; show text again
	moveq	#0,d0
	moveq	#1,d1
	bsr.w	setsoftstyle		; style - 0

	move.l	(sp)+,a0
	move.l	#1,nr			; score number

	move.w	#9,d7			; number of scores-1
	move.w	#24,d1			; position y
	move.w	#30,d2			; number of chars
showall:
	cmp.l	#3,nr			; score number 3 or less ?
	bgt.s	nochsty			; no

	move.l	d1,-(sp)		; yes
	moveq	#2,d0
	moveq	#2,d1
	bsr.w	setsoftstyle		; set style to 2
	move.l	(sp)+,d1
	moveq	#1,d0
	bsr.w	setcolor		; set color to 1

	bsr.s	showone			; show score

	move.l	d1,-(sp)
	moveq	#0,d0
	moveq	#2,d1
	bsr.w	setsoftstyle		; set style to 0
	move.l	(sp)+,d1

nochsty:

	moveq	#2,d0
	bsr.w	setcolor		; set color to 2

	bsr.s	showone			; show score
	adda.l	#30,a0			; next name,
	adda.l	#4,a1			; score,
	adda.l	#4,a2			; level,
	adda.l	#4,a3			; stage,
	add.w	#10,d1			; line and
	add.l	#1,nr			; place.
	dbf	d7,showall		; come back
showloop:
	bsr.w	syswait			; wait a bit
	bsr.w	firetest		; fire or lmb pressed ?
	bne.s	showloop		; no - wait
showloop2:
	bsr.w	syswait			; wait a bit
	bsr.w	firetest		; fire or lmb released ?
	beq.s	showloop2		; no - wait

	bsr.w	closewindow		; close window
	lea	defwindow,a0
	bsr.w	restorewindow		; restore old window
	movem.l	(sp)+,d0-d7/a0-a6
	rts				; come back

; * Show one place *

showone:
	move.w	#4*8+5,d0
	move.w	#30,d2			; 30 chars
	bsr.w	showtext		; show name
	move.l	a0,-(sp)

	move.l	(a1),d0
	lea	valbuf,a0
	bsr.w	liczbadoascii		; convert score to ASCII
	move.w	#35*8+5,d0
	move.w	#6,d2			; 6 chars
	bsr.w	showtext		; show it

	move.l	nr,d0
	lea	valbuf,a0
	bsr.w	liczbadoascii		; place to ASCII
	adda.l	#4,a0
	move.w	#5,d0
	move.w	#2,d2			; 2 chars
	bsr.w	showtext		; show place

	lea	kropka,a0		; point
	move.w	#2*8+5,d0
	move.w	#1,d2			; 1 char
	bsr.w	showtext		; show

	move.l	(a2),d0
	lea	valbuf,a0
	bsr.w	liczbadoascii		; level to ASCII
	adda.l	#4,a0
	move.w	#43*8+5+4,d0
	move.w	#2,d2			; 2 chars
	bsr.w	showtext		; show level

	move.l	(a3),d0
	lea	valbuf,a0
	bsr.w	liczbadoascii		; stage to ASCII
	adda.l	#5,a0
	move.w	#50*8+5,d0
	move.w	#1,d2			; 1 char

	bsr.w	showtext		; and show it

	move.l	(sp)+,a0
	rts

; a0 - names
; a1 - name
; a2 - scores
; a3 - levels
; a4 - stages
; d0 - score
; d1 - level
; d2 - stage

; * This procedure put Your name on the right :-) place *

movenames:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	a2,a5
	adda.l	#40,a2			; start from last position
	adda.l	#40,a3
	adda.l	#40,a4
m_loop:
	move.l	-(a2),d3		; get values
	move.l	-(a3),d4
	move.l	-(a4),d5

	cmp.l	d3,d0			; compare to Your score
	ble.s	m_loopend		; so ?!
	move.l	d3,4(a2)
	move.l	d4,4(a3)
	move.l	d5,4(a4)
	bra.s	m_loop			; keep going

m_loopend:				; OK !             :-D
	addq.l	#4,a2			; write Your:
	move.l	d0,(a2)			; score,
	addq.l	#4,a3
	move.l	d1,(a3)			; level,
	addq.l	#4,a4
	move.l	d2,(a4)			; stage.

	adda.l	#40,a5			; how many positions to move ?
	suba.l	a2,a5
	move.l	a5,d7
	asr.l	#2,d7
	mulu	#30,d7
	subq.l	#1,d7
	adda.l	#300,a0
	cmp.l	#-1,d7			; if nothing then
	beq.s	m_end			; exit
m_loop2:
	move.b	-(a0),d0		; move names
	move.b	d0,30(a0)
	dbf	d7,m_loop2

	move.w	#29,d7			; and place Your name here
m_loop3:
	move.b	(a1)+,(a0)+
	dbf	d7,m_loop3
m_end:	movem.l	(sp)+,d0-d7/a0-a6
	rts				; OK !

; a0 - text
; d0 - x
; d1 - y
; d2 - count

; * No comment *

showtext:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	a0/d2,-(sp)
	add.w	addy,d1
	move.l	gfxbase,a6
	move.l	rastport,a1
	jsr	_MoveTo(a6)		; move cursor
	movem.l	(sp)+,a0/d2
	move.l	d2,d0
	move.l	gfxbase,a6
	move.l	rastport,a1
	jsr	_Text(a6)		; print text
	movem.l	(sp)+,d0-d7/a0-a6
	rts

setcolor:
	movem.l	d1-d7/a0-a6,-(sp)
	move.l	actscreen,a1
	cmp.b	#1,$bd(a1)		; one bitplane ?
	bne.s	sts_norm		; if no - set color
	tst.b	d0			; color=0 ?
	beq.s	sts_norm		; if yes - set it
	moveq	#1,d0			; else color=1
sts_norm:
	move.l	gfxbase,a6
	move.l	rastport,a1
	jsr	_SetAPen(a6)		; set color
	movem.l	(sp)+,d1-d7/a0-a6
	rts

setsoftstyle:
	movem.l	d2-d7/a0-a6,-(sp)
	move.l	gfxbase,a6
	move.l	rastport,a1
	jsr	_SetSoftStyle(a6)	
	movem.l	(sp)+,d2-d7/a0-a6
	rts

setdrmode:
	movem.l	d1-d7/a0-a6,-(sp)
	move.l	gfxbase,a6
	move.l	rastport,a1
	jsr	_SetDrMd(a6)	
	movem.l	(sp)+,d1-d7/a0-a6
	rts
	
; ********************
; * Game starts here *
; ********************

gra:
	move.b	#1,pointerflag		; change pointer
	move.b	closeflag1,closeflag2	; close gadget on/off
	move.b	offmouse1,offmouse2	; mouse pointer on/off
	bsr.w	installih
	bsr.w	setpointer
	move.l	g_lev,nrpl		; level 1
	move.l	g_liv,zycia		; balls 3
	move.l	g_pts,punkty		; score 0
	move.b	g_stg+3,level		; stage 0 (that means 1)
	sub.b	#1,level

	lea	bonusy,a0
	move.l	punkty,d0
bonlop:	cmp.l	(a0)+,d0
	bge.s	bonlop
	suba.l	#4,a0
	move.l	a0,bonusyadr

plloop:
	lea	pltab,a0
	move.l	nrpl,d0
	subq.l	#1,d0
	asl.l	#2,d0
	add.l	d0,a0
	move.l	(a0),a0			; get level address
	cmp.l	#0,a0			; last level ?
	bne.W	nost			; no - go to "nost"
	move.l	#1,nrpl			; level 1
	add.b	#1,level		; add 1 to stage
	cmp.b	#2,level		; if stage<=2 then go to "noch"
	ble.w	noch

	move.l	#25,nrpl
	move.b	#2,level
	move.l	zycia,d0
	mulu	#1000,d0
	add.l	d0,punkty
	bsr.w	pokazpunkty
	lea	won,a0
	bsr.w	scrollinit		; init scroll
	move.w	#380,d7			; 380 frames
	clr.l	wysw_czas		; no message
	move.l	#0,liniaadr
wonlop:
	bsr.w	scrolltext		; scroll text
	bsr.w	message			; get IDCMP
	bsr.w	wf			; wait frame
	dbf	d7,wonlop		; come back
	clr.b	closeflag2		; close gadget on
	clr.b	offmouse2		; mouse cursor on
	bsr.w	removeih
	bsr.w	hiscore			; hi score table
	move.w	#50,d7
ov_loop:
	bsr.w	wf			; wait frame
	bsr.w	firetest		; if fire then end
	beq.W	koniec
	dbf	d7,ov_loop		; wait 50 frames
	bra.w	koniec
noch:	lea	alllev,a0		; if stage 1 then set scroll
	cmp.b	#2,level		; address to "alllev"
	bne.s	nolev2			; if stage 2 then set scroll
	lea	alllev2,a0		; address to "alllev2"
nolev2:
	bsr.w	scrollinit		; init scroll
	move.w	#480,d7			; 480 frames
	clr.l	wysw_czas		; no message
	move.l	#0,liniaadr
levlop:
	bsr.w	scrolltext		; scroll text
	bsr.w	message			; get IDCMP
	bsr.w	wf			; wait frame
	dbf	d7,levlop		; come back
	add.l	#3,zycia		; add 3 balls
	move.l	#trzyextra,liniaadr	; show message

	bra.W	plloop			; next level
nost:
	bsr.w	rysujpanel		; draw background
	bsr.w	rysujplansze		; draw level

	move.l	#144,xp			; set stick's x coordinate
	move.w	#144,xmousepos
	move.l	#161,yp			; and y coordinate

	bsr.w	rysujpaletke		; draw stick

gloop:
	move.l	#0,adrl			; no letter
	move.w	#0,klej			; no glue
	move.b	#0,hard			; no hardball

	bsr.w	pokazzycia		; draw balls

	bsr.w	pokazplansze		; draw level number

	bsr.w	pokazpunkty		; draw score

	clr.b	tiltflag
	clr.w	tilt_counter

	bsr.w	pippal			; wait for lmb or fire
	move.l	#$04002,kx		; x speed
	move.l	#$FFFFc002,ky		; y speed
	clr.l	czas
	move.w	#-10,d0
	bsr.W	kula			; GO !
	tst.l	zycia			; last ball ?
	bpl.s	gnext			; if no - next ball
	clr.l	zycia			; else balls=0
	move.l	#over,liniaadr		; print "GAME OVER"
	bsr.w	wf			; wait frame
	clr.b	closeflag2		; close gadget on
	clr.b	offmouse2		; mouse cursor on
	bsr.w	removeih
	bsr.w	hiscore			; hi score table
	move.w	#50,d7
ov_loop2:
	bsr.w	wf			; wait frame
	bsr.w	firetest		; if fire then end
	beq.W	koniec
	dbf	d7,ov_loop2		; wait 50 frames
	bra.W	koniec			; end
gnext:	tst.l	ilkloc			; next level ?
	bgt.W	gloop			; no

	bsr.w	random			; yes
	move.w	rnd,d0			; write random message
	asr.w	#4,d0
	and.w	#%1111111111111100,d0
	lea	nltable,a0
	move.l	(a0,d0.w),liniaadr

	add.l	#1,nrpl			; next level
	bra.W	plloop

; * Write level number *

pokazplansze:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	nrpl,a0			; convert value to 
	lea	cyfra,a1		; addresses of chars
	bsr.w	conv	
	lea	cyfra+16,a1
	move.l	#329,d2
	move.l	#108-4,d3
	move.l	#20,d4
	move.l	#2,d0
	bsr.w	piszcyfre		; write chars
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Write level, balls, score *

pokazwsio:
	bsr.s	pokazplansze		; write level number
	bsr.w	pokazzycia		; write number of balls
	bsr.w	pokazpunkty		; write score
	rts

; * Refresh all *

odswiezwsio:
	bsr.w	wf			; wait frame
	bsr.w	rysujpanel		; draw background
	bsr.s	pokazklocki		; draw bricks
	bsr.s	pokazwsio		; write level, balls, score
	bsr.s	pokazkulke		; draw ball
	bsr.w	rysujpaletke		; draw stick
	bsr.w	rysujliterke		; draw letter
	sub.l	#1,yl			; move letter
	rts

; * Draw bricks *

pokazklocki:
	move.l	a0,-(sp)
	lea	plact,a0		; get actual level
	bsr.w	rysujplansze		; draw it
	move.l	(sp)+,a0
	rts

; * Draw ball *

pokazkulke:
	movem.l	d0-d1,-(sp)
	move.l	xe,d0			; get ball position
	move.l	ye,d1
	bsr.w	rysujkulke		; and draw it
	movem.l	(sp)+,d0-d1
	rts

; * Right mouse button test *

rmb:
	cmp.b	#1,rmbflag
	rts

; a0 - address of free space (60 bytes)

storewindow:
	movem.l	d0-d7/a0-a6,-(sp)
	add.l	#60,a0
	move.l	rastport,a1
	move.l	window,a2
	move.l	win_title,a3
	move.l	win_flags,a4
	move.l	win_idcmpflags,a5
	move.l	win_type,a6
	move.w	win_x,d0
	move.w	win_y,d1
	move.w	win_sizex,d2
	move.w	win_sizey,d3
	move.w	win_minsizex,d4
	move.w	win_minsizey,d5
	move.w	win_maxsizex,d6
	move.w	win_maxsizey,d7
	movem.l	d0-d7/a0-a6,-(a0)
	bsr.w	clearpointer
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - stored window

restorewindow:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d7/a0-a6
	move.l	a1,rastport
	move.l	a2,window
	move.l	a3,win_title
	move.l	a4,win_flags
	move.l	a5,win_idcmpflags
	move.l	a6,win_type
	move.w	d0,win_x
	move.w	d1,win_y
	move.w	d2,win_sizex
	move.w	d3,win_sizey
	move.w	d4,win_minsizex
	move.w	d5,win_minsizey
	move.w	d6,win_maxsizex
	move.w	d7,win_maxsizey
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Sleep *

windowsmall:
	movem.l	d0-d7/a0-a6,-(sp)

	move.l	window,a0
	move.l	intbase,a6
	move.l	#0,d0
	move.l	#-WinSizeY,d1
	add.w	d1,win_sizey
	jsr	_SizeWindow(a6)

	move.l	window,a0
	move.l	#WINNAME,a1
	move.l	#sleep,a2
	move.l	intbase,a6
	jsr	_SetWindowTitles(a6)

;	moveq	#20,d1
;	move.l	dosbase,a6
;	jsr	_Delay(a6)

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

; * Wake up *

windowbig:
	movem.l	d0-d7/a0-a6,-(sp)

	move.l	window,a0
	move.w	6(a0),d0
	move.l	actscreen,a0
	move.w	$e(a0),d1
	add.w	#WinSizeY,d0
	add.w	addy,d0
	sub.w	d0,d1			; must I move window before
	ext.l	d1			; sizing ?
	bpl.s	nomovewindow		; no

	clr.l	d0			; yes - move window
	move.l	intbase,a6
	move.l	window,a0
	jsr	_MoveWindow(a6)

nomovewindow:
	move.l	window,a0
	move.l	intbase,a6
	move.l	#0,d0
	move.l	#WinSizeY,d1
	add.w	d1,win_sizey
	jsr	_SizeWindow(a6)

	move.l	window,a0
	move.l	#WINNAME,a1
	move.l	#fun,a2
	move.l	intbase,a6
	jsr	_SetWindowTitles(a6)

	moveq	#10,d1
	move.l	dosbase,a6
	jsr	_Delay(a6)

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

; * Test right mouse button while playing *

rmbtrap:
	movem.l	d0-d7/a0-a6,-(sp)

	tst.b	mousebutton		; ANY button pressed ?
	bne.w	rmbtrapend		; no - exit
	bsr.w	rmb			; right mouse button pressed ?
	bne.W	rmbtrapend		; no - exit
poczrmbtlop:
	bsr.w	message			; get IDCMP
	bsr.w	rmb			; right mouse button released ?
	beq.s	poczrmbtlop		; no - wait

	bsr.w	windowsmall		; sleep

	tst.b	pauseflag
	bne.s	rmbloop
	bsr.w	clearpointer		; normal pointer
	clr.b	closeflag2		; close gadget active
	clr.b	offmouse2		; mouse on
	bsr.w	removeih

rmbloop:

	moveq	#1,d1
	move.l	dosbase,a6
	jsr	_Delay(a6)		; wait (?)

	bsr.w	message			; get IDCMP

	bsr.w	dragging		; drag test

	bsr.w	rmb			; rmb pressed
	bne.s	rmbloop			; no - wait

poczwrmbtlop:
 	bsr.w	message			; get IDCMP
	bsr.w	rmb			; right mouse button released ?
	beq.s	poczwrmbtlop		; no - wait
	bsr.w	message			; get IDCMP

	bsr.w	windowbig		; yes - wake up
	bsr.w	odswiezwsio		; draw all

	tst.b	pauseflag
	bne.s	rmbtrapend
	
	move.b	closeflag1,closeflag2	; close gadget on/off
	move.b	offmouse1,offmouse2	; mouse pointer on/off
	bsr.w	installih

	bsr.w	setpointer		; show pointer

rmbtrapend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; ******************************
; * REAL game starts from here *
; ******************************

kula:
	bsr.w	joy			; joy/mouse steering
	bsr.w	esc			; ESC pressed ?
	bsr.w	space			; space bar pressed ?
	bsr.w	checkpause
	movem.l	d0-d1,-(sp)
	move.l	xe,d0			; get last coordinates
	move.l	ye,d1
	bsr.w	rysujkulke		; clear ball (xor with the
					; same object)
	movem.l	(sp)+,d0-d1

	move.l	d0,xe			; write new coordinates
	move.l	d1,ye

	bsr.w	rysujkulke		; draw ball
	bsr.w	ruchliterki		; move letter
	bsr.w	literka			; catch letter
	bsr.w	kasujpaletke		; clear stick
	bsr.w	rysujpaletke		; draw stick

	bsr.w	rmbtrap			; sleep time ?

	bsr.w	kolzpal			; collision with stick ?

	bsr.w	message

	move.l	micros,d2
	add.l	d2,czas
	cmp.l	#400000,czas		; time to speed up ?
	blt.s	nzw			; no  :-)

					; yes :-(
	move.l	#0,czas			; clear time
	tst.b	tiltflag
	bne.s	tc_d
	sub.w	#1,tilt_counter
	bpl.s	tc_d
	clr.w	tilt_counter
tc_d:	move.l	#8,d1			; speed up
	move.l	kx,d0
	asr.l	d1,d0
	add.l	d0,kx
	move.l	ky,d0
	asr.l	d1,d0
	add.l	d0,ky

nzw:
	move.l	d0,-(sp)
; * Max speed ? *
	move.l	ky,d0
	cmp.l	#$a000,d0
	blt.s	niep
	move.l	#$a000,ky
niep:	cmp.l	#-$a000,d0
	bgt.s	niemp
	move.l	#-$a000,ky
niemp:	tst.l	d0
	bpl.s	ydod
	neg.l	d0
ydod:	asl.l	#1,d0
	cmp.l	kx,d0
	bge.s	nied
	move.l	d0,kx
nied:	neg.l	d0
	cmp.l	kx,d0
	ble.s	niemd
	move.l	d0,kx
niemd:
	move.l	(sp)+,d0

; * Collision with bricks *
	lea	pomoctable,a5
	move.w	#7,d7			; 8 checks per frame
ilop:	move.l	x,d0			; move ball
	move.l	y,d1
	move.l	kx,d2
	move.l	ky,d3
	move.l	micros,d4
	asr.l	#2,d4
	asr.l	#2,d2
	asr.l	#2,d3
	muls	d4,d2
	muls	d4,d3
	swap	d2
	swap	d3
	ext.l	d2
	ext.l	d3
	muls	#53,d2
	muls	#53,d3
	add.l	d2,d0
	add.l	d3,d1
	move.l	d0,x
	move.l	d1,y
	swap	d0
	swap	d1
	ext.l	d0
	ext.l	d1
; * Bouncing *
	tst.l	kx
	bpl.s	nu
	cmp.w	#1,d0
	bge.s	nu
	neg.l	kx
nu:	tst.l	ky
	bpl.s	nu2
	cmp.w	#2,d1
	bge.s	nu2
	neg.l	ky
nu2:
	tst.l	kx
	bmi.s	bo3
	cmp.w	#309,d0		
	ble.s	bo3			
	neg.l	kx			
bo3:					
	cmp.w	#170,d1			; Player don't catch the ball ?
	ble.s	bo4			; no

	bsr.w	random			; yes
	move.w	rnd,d0			; write random message
	asr.w	#4,d0
	and.w	#%1111111111111100,d0
	lea	lbtable,a0
	move.l	(a0,d0.w),liniaadr
	tst.b	tiltflag
	beq.s	no_t

	move.l	#bye,liniaadr

no_t:
	move.l	xe,d0
	move.l	ye,d1
	bsr.w	rysujkulke		; clear ball
	add.l	#1,yl
	bsr.w	rysujliterke		; clear letter

	sub.l	#1,zycia		; lost life
	move.w	#2,sample		; set sample to number 2
	move.l	xe,position		; set sound position
	add.l	#5,position
	bsr.w	playsample		; play sound
	rts

; * Check collision *

bo4:
	tst.l	ky
	bpl.s	next
	bsr.w	kolizjag		; up
	beq.s	next
	neg.l	ky
next:
	tst.l	ky
	bmi.s	next2
	bsr.w	kolizjad		; down
	beq.s	next2
	neg.l	ky
next2:
	tst.l	kx
	bpl.s	next3
	bsr.w	kolizjal		; left
	beq.s	next3
	neg.l	kx
next3:
	tst.l	kx
	bmi.s	next4
	bsr.w	kolizjap		; right
	beq.s	next4
	neg.l	kx
next4:
	dbf	d7,ilop			; next check

	bsr.w	wf			; wait frame

	tst.l	ilkloc			; next level ?
	bgt.s	niez			; no

	move.l	xe,d0			; yes - clear ball
	move.l	ye,d1
	bsr.w	rysujkulke

	move.l	xp,sxp			; clear stick
	clr.l	xp
	bsr.w	kasujpaletke

	rts				; return

niez:
	bra.w	kula			; game must go on

; * Initialize multiplication table *

initpomoctable:
	movem.l	d0-d1/a0,-(sp)
	clr.l	d0
	lea	pomoctable,a0
i_loop:	move.l	d0,d1
	mulu	#10,d1
	move.b	d1,(a0)+
	addq.l	#1,d0
	cmp.l	#21,d0
	bne.s	i_loop
	movem.l	(sp)+,d0-d1/a0
	rts

; * Display messages *

wyswietlacz:
	movem.l	d0/a0,-(sp)
	move.l	liniaadr,a0
	cmp.l	#0,a0			; any message ?
	beq.s	wysw_here		; no
	tst.l	wysw_czas		; yes - time to clear it ?
	bmi.s	wysw_nocl		; no
	bsr.w	clearstatline		; clear message
wysw_nocl:
	move.l	#150*20000,wysw_czas	; set time
	clr.l	liniaadr		; clear message address
	bsr.w	line			; show message
	movem.l	(sp)+,d0/a0
	rts
wysw_here:
	tst.l	wysw_czas		; test time
	bmi.s	wysw_noop		; time negative - exit
	bne.s	wysw_end		; nothing to do
	bsr.w	clearstatline		; time=0 - clear message
	move.l	#-1,wysw_czas
	bra.s	wysw_noop
wysw_end:
	move.l	micros,d0
	sub.l	d0,wysw_czas		; count down
	tst.l	wysw_czas
	bpl.s	wysw_noop
	move.l	#0,wysw_czas
wysw_noop:
	movem.l	(sp)+,d0/a0
	rts

; * Get IDCMP message *

message:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.w	drag			; no drag
	clr.w	key			; no key
	clr.w	rawkey			; no rawkey

	tst.b	offmouse2
	bne.s	nombchange

	move.b	#1,mousebutton		; no button

nombchange:
	move.l	window,a0
	move.l	86(a0),a0
	move.l	4,a6
	jsr	_GetMsg(a6)		; get message
	tst.l	d0			; any message ?
	beq.w	nm			; no
	move.l	d0,a1

	move.l	20(a1),d2
	move.w	24(a1),code
	cmp.l	#$200000,d2		; key pressed ?
	bne.w	nokey			; no
	move.w	24(a1),key		; yes - get it

nokey:	cmp.l	#1024,d2		; rawkey ?
	bne.s	norawkey		; no
	move.w	24(a1),rawkey		; yes - get rawkey
norawkey:
	move.l	4,a6
	jsr	_ReplyMsg(a6)		; reply message

	cmp.l	#$2000000,d2		; window dragged ?
	bne.s	nodr			; no
	move.w	#1,drag			; yes - set flag
nODR:
	cmp.w	#8,d2			; mouse button pressed ?
	bne.s	nomousebutton		; no
	move.b	#0,mousebutton		; yes - set flag
	cmp.w	#$68,code
	bne.s	nolmbpressed
	move.b	#-1,lastbaton
nolmbpressed:
	cmp.w	#$e8,code
	bne.s	nolmbreleased
	move.b	#1,lastbaton		; pressed, or released ?
nolmbreleased:
	cmp.w	#$69,code
	bne.s	normbpressed
	move.b	#1,rmbflag
normbpressed:
	cmp.w	#$e9,code
	bne.s	normbreleased
	move.b	#0,rmbflag
normbreleased:
nomousebutton:
	tst.b	closeflag2		; close gadget disable ?
	bne.s	nm			; yes - end
	cmp.w	#512,d2			; close gadget pressed ?
	bne.s	nm			; no - exit
	lea	quittext,a0
	lea	yesnogad,a1
	moveq	#1,d0
	bsr.w	request			; show request
	cmp.l	#g_reqyes,a0		; "YES" selected ?
	beq.b	end			; yes, quit game
nm:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

koniec:	rts

powrot:	move.l	stack,sp
	rts

; * Quit game *

end:	move.l	stack,sp		; restore stack
	cmp.b	#1,savemode
	bne.s	end2
	bsr.w	writescores
end2:
	bsr.B	close			; close all

quit:
	IF OBJECT
	move.l	wbmsg,d2
	beq.s	nowb
	move.l	4,a6
	jsr	_Forbid(a6)
	move.l	d2,a1
	move.l	4,a6
	jsr	_ReplyMsg(a6)
	bsr.w	dmaoff			; turn sound off
	clr.l	d0
	rts
nowb:
	ENDIF
	bsr.w	dmaoff			; turn sound off
	IF OBJECT

	move.l	4,a6
	jsr	-132(a6)

	move.l	dosbase,a6
	move.l	currentdir,d1
	jsr	_UnLock(a6)
	move.l	segment,d1
	jsr	_UnloadSeg(a6)
	clr.l	d0

	move.l	4,a6
	jmp	-138(a6)

	ELSE

	rts

	ENDIF

; * Clean up *

close:
	move.l	intbase,a6
	move.l	window,a0
	jsr	_CloseWindow(a6)	; close window

clint:
	move.l	4,a6
	moveq	#5,d0
	lea	myinterrupt,a1
	jsr	_RemIntServer(a6)	; remove interrupt

	bsr.w	closeid
	bsr.w	deallocate		; free memory
	bsr.w	closescreen		; close screen

deverr:
	move.l	intbase,a1
	move.l	4,a6
	jsr	_CloseLibrary(a6)	; close intuition

	tst.l	tmpbitmap
	beq.s	nofreetmpbitmap
	move.l	gfxbase,a6
	move.l	tmpbitmap,a0
	jsr	-924(a6)

nofreetmpbitmap:
	move.l	gfxbase,a1
	move.l	4,a6
	jsr	_CloseLibrary(a6)	; close graphics

	rts

error:
	move.l	stack,sp
	bsr.w	flash
	bsr.s	clint
	bra.W	quit

wf:
	movem.l	d0-d7/a0-a6,-(sp)
	bsr.w	pointer			; set/clear pointer
wfnopo:
	bsr.w	wyswietlacz		; draw messages
	move.l	gfxbase,a6
	jsr	_WaitTOF(a6)		; wait top of frame
	movem.l	(sp)+,d0-d7/a0-a6
	rts


wfnp:
	movem.l	d0-d7/a0-a6,-(sp)
	bra.s	wfnopo	

randomize:
	move.l	intbase,a6
	lea	e_RND,a0
	add.l	#78,a6
	move.b	(a6),(a0)+
	move.b	1(a6),(a0)+
	move.b	(a6),(a0)+
	move.b	1(a6),(a0)+
	move.b	(a6),(a0)+
	move.b	1(a6),(a0)+
	move.b	(a6),(a0)+
	move.b	1(a6),(a0)+
	rts

random:
	move.l	d0,-(sp)

	bsr.w	LongRnd
	and.w	#$FF,d0
	move.w	d0,rnd

	move.l	(sp)+,d0
	rts

firetest:
	bsr.w	message			; get IDCMP
firetestnomsg:
	move.b	$bfe001,firestat	; test joy button
	btst	#7,firestat
	bne.s	fire_here
	rts
fire_here:
	cmp.b	#-1,lastbaton		; test mouse button
	rts

; * Stick and ball *

pippal:
	movem.l	d0-d7/a0-a6,-(sp)
tutaj:
	bsr.w	joy			; mouse or joy test
	move.l	xp,d0
	move.l	yp,d1
	move.l	d0,d2
	move.l	d1,d3
	sub.l	#6,d1
	add.l	#32,d0
	bsr.w	ryspaletki		; draw stick
	bsr.w	rysujkulke		; draw ball on it
	move.l	d0,xe
	move.l	d1,ye
	bsr.w	rmbtrap			; sleep ?
	bsr.w	esc			; esc pressed ?
	bsr.w	checkpause
	bsr.w	wf			; wait frame
	bsr.s	firetest		; fire or lmb pressed ?
	beq.s	tamitu			; yes - exit
	bsr.w	rysujkulke		; no - clear ball...
	bra.s	tutaj			; ...and come back
tamitu:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	#1,d1
	move.l	dosbase,a6
	jsr	_Delay(a6)	
	movem.l	(sp)+,d0-d7/a0-a6
	bsr.w firetest
	beq.s	tamitu			; wait for release button
	bsr.w	rysujkulke		; clear ball
	swap	d0			; set ball position
	move.l	d0,x
	swap	d1
	move.l	d1,y
	move.l	#-10,xe
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Collision test between the ball and stick *

kolzpal:
	movem.l	d0-d7/a0-a6,-(sp)

; * a lot of tests *

	tst.l	ky
	bmi.W	k_end
	move.l	x,d0
	move.l	y,d1
	swap	d0
	swap	d1
	move.l	xp,d2
	move.l	yp,d3

	add.w	#6,d1
	cmp.w	d3,d1
	blt.W	k_end
	sub.w	d3,d1
	cmp.w	#5,d1
	bge.W	k_end

	add.w	#6,d0
	cmp.w	d0,d2
	bgt.W	k_end
	sub.w	#4,d0
	add.w	#64,d2
	cmp.w	d0,d2
	blt.W	k_end

; * Collision detected *

	sub.w	#32,d2
	add.w	#2,d0
	sub.w	d2,d0
	ext.l	d0
	swap	d0
	asr.l	#6,d0

	add.l	d0,kx			; change x
	
	neg.l	ky			; and y speed
	
	move.l	xp,position
	add.l	#32,position
	move.w	#0,sample
	bsr.w	playsample		; make sound

	tst.w	klej			; glue collected ?
	beq.W	nieklej			; no - end

; * Glue routine *

	tst.l	d0
	bne.s	dznz
	move.l	#$200,d0
dznz:	move.l	d0,kx
	move.l	xe,d0
	move.l	ye,d1
	bsr.w	rysujkulke

	move.l	xe,d4
	sub.l	xp,d4
	move.l	yp,d5
	sub.l	ye,d5

kleisie:
	bsr.w	joy
	move.l	xp,d0
	move.l	yp,d1
	move.l	d0,d2
	move.l	d1,d3
	sub.l	d5,d1
	add.l	d4,d0
	bsr.w	ruchliterki
	bsr.w	literka
	bsr.w	kasujpaletke
	bsr.w	rysujpaletke
	bsr.w	rysujkulke
	move.l	d0,xe
	move.l	d1,ye
	bsr.w	rmbtrap
	bsr.w	checkpause
	bsr.w	wf
	bsr.w	esc
	bsr.w firetest
	beq.s	klej_koniec
	bsr.w	rysujkulke
	bra.s	kleisie
klej_koniec:
	bsr.w	ruchliterki
	bsr.w	literka
	bsr.w	wf
	bsr.w firetest
	beq.s	klej_koniec
	swap	d0
	swap	d1
	move.l	d0,x
	move.l	d1,y
	
nieklej:
k_end:
	movem.l	(sp)+,d0-d7/a0-a6
	rts	

; * Mouse pointer set/clear *

pointer:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	window,a0
	move.w	108(a0),d0
	move.w	110(a0),d1
	tst.w	d0
	bmi.s	psta
	tst.w	d1
	bmi.s	psta
	cmp.w	#320,d0
	bge.s	psta
	cmp.w	#180-3,d1
	bge.s	psta
	tst.b	pointerflag
	beq.s	joy_dalej
	clr.b	pointerflag
	bsr.s	setpointer
	bra.s	joy_dalej
psta:
	tst.b	pointerflag
	bne.s	joy_dalej
	move.b	#1,pointerflag
	bsr.s	clearpointer
joy_dalej:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Set mouse pointer *

setpointer:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	mypointer,a1
	tst.b	offmouse2
	beq.s	normpointer
	lea	blankpointer,a1
normpointer:
	move.l	window,a0
	move.l	#5,d0
	move.l	#5,d1
	clr.l	d2
	clr.l	d3
	move.l	intbase,a6
	jsr	_SetPointer(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

soend:	rts

; * Clear mouse pointer *

clearpointer:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	window,a0
	move.l	intbase,a6
	jsr	_ClearPointer(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * PLAY SAMPLE *

playsample:
	tst.b	sound
	beq.s	soend
	movem.l	d0-d7/a0-a6,-(sp)

	move.w	#1,d3

pl_loophere:
	move.w	sample,d0
	lea	samtable,a0
	move.l	channeltableadr,a1
	move.w	(a1)+,d1
	move.w	(a1)+,d2
	tst.w	d1
	bne.s	playnext
	move.l	#channeltable,channeltableadr
	move.l	channeltableadr,a1
	move.w	(A1)+,d1
	move.w	(a1)+,d2
playnext:
	or.w	d2,chn
	
	move.w	d2,$dff096
	lea	$dff000,a2
	asl.w	#3,d0
	tst.l	(a0,d0.w)
	beq.W	playend

	move.l	0(a0,d0.w),0(a2,d1.w)
	move.w	4(a0,d0.w),6(a2,d1.w)
	move.w	6(a0,d0.w),4(a2,d1.w)

	move.w	volume,d0
	tst.b	stereoflag
	beq.s	nochg
	movem.l	d1-d7,-(sp)
	move.l	position,d2
	move.l	spectrum,d4
	sub.l	d2,d4
	cmp.w	#1,d3
	beq.s	p_left
	mulu.w	mix,d2
	divu.w	#100,d2
	add.w	d4,d2
	ext.l	d2
	bra.s	p_right
p_left:
	mulu.w	mix,d4
	divu.w	#100,d4
	add.w	d4,d2
	ext.l	d2
p_right:
	move.l	spectrum,d1
	asl.l	#6,d2
	divu	d1,d2
	mulu	d2,d0
	asr.l	#6,d0
	cmp.w	#64,d0
	ble.s	volgood
	move.w	#64,d0
volgood:
	movem.l	(sp)+,d1-d7
nochg:
	move.w	d0,8(a2,d1.w)
	move.l	a1,channeltableadr

playend:
	tst.b	stereoflag
	beq.s	reallyend
	dbf	d3,pl_loophere

reallyend:
	lea	timeval2,a0
	move.l	timerbase,a6
	jsr	_GetSysTime(a6)
	lea	timeval2,a0
	move.l	(a0),d3
	move.l	4(a0),d4
wcycle:
	lea	timeval2,a0
	move.l	timerbase,a6
	jsr	_GetSysTime(a6)
	sub.l	(a0),d3
	sub.l	4(a0),d4
	neg.l	d3
	neg.l	d4
	tst.l	d4
	bpl.s	wc_nocarry
	add.l	#1000000,d4
	sub.l	#1,d3
wc_nocarry:	
	tst.l	d3
	bne.s	wc_end

	cmp.l	#5000,d4
	bge.s	wc_end
	bra.s	wcycle

wc_end:
	move.w	chn,d2
	bset	#15,d2
	move.w	d2,$dff096

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

timeval2:
	dc.l	0
	dc.l	0

; * Sound DMA on *

dmaon:
	tst.b	sound
	beq.w	soend
	move.w	#%1000000000001111,$dff096
	rts

; * Sound DMA off *

dmaoff:
	tst.b	sound
	beq.W	soend
	move.w	#%0000000000001111,$dff096
	rts

; * Stop sound *

normsample:
	tst.b	sound
	beq.W	soend
	tst.w	chn
	beq.W	hereend
	movem.l	a0-a1/d0-d2,-(sp)
	move.w	chn,d2
	lea	channels,a0
	lea	$dff000,a1
	moveq	#-1,d0
normloop:
	addq	#1,d0
	move.w	(a0)+,d1
	tst.w	d1
	beq.s	normend
	btst	d0,d2
	beq.s	normloop
	move.l	#s_clear,0(a1,d1.w)
	move.w	#1,4(a1,d1.w)
	bra.s	normloop
normend:
	movem.l	(sp)+,a0-a1/d0-d2
hereend:
	clr.w	chn
	rts

; * Analyse IFF 8SVX structure *

; a0.l - iff data

; a0.l - body
; d0.l - rate
; d1.l - len

analyseiff:
	tst.b	sound
	beq.W	soend
	cmp.l	#'FORM',(a0)+
	bne.s	anerror
	move.l	(a0)+,d0
	cmp.l	#'8SVX',(a0)+
	bne.s	anerror
	cmp.l	#'VHDR',(a0)+
	bne.s	anerror
	move.b	19(a0),d0
	cmp.b	#0,d0		
	bne.s	anerror
	move.w	16(a0),d0
loop:
	move.l	(a0)+,d1
	add.l	d1,a0
	cmp.l	#'BODY',(a0)+
	bne.s	loop
	move.l	(a0)+,d1
	and.l	#$0000ffff,d0
	rts

; * Error in IFF file *

anerror:
	move.l	a1,-(sp)
	lea	notifftext,a0
	lea	okgad,a1
	move.l	#1,d0
	bsr.w	request
	move.l	(sp)+,a1
	moveq	#0,d0
	move.l	#0,a0
	rts

; * Joystick control *

joy:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.b	tiltflag
	bne.w	joy_end
	move.l	xp,sxp
	tst.w	mouse
	beq.s	nomouse
	tst.b	offmouse1
	beq.s	mousevis

	move.w	xmousepos,xp+2	
	bra.s	joy_end

mousevis:
	move.l	window,a0
	move.w	108(a0),d0
	sub.w	#32,d0
	ext.l	d0
	move.l	d0,xp

nomouse:
	move.l	jspeed,d1
	move.w	$dff00c,d0
	btst	#9,d0
	beq.s	da1
	sub.l	d1,xp
da1:
	btst	#1,d0
	beq.s	da2
	add.l	d1,xp
da2:	cmp.l	#1,xp
	bge.s	niezm1
	move.l	#1,xp
niezm1:	cmp.l	#255,xp
	ble.s	niezm2
	move.l	#255,xp
niezm2:
joy_end:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; d0 - brick x
; d1 - brick y

; * Clear hit brick, play a sample and start falling of the letter *

kolizja:
	move.w	#1,sample
	move.l	#0,kol
	move.l	d0,position
	add.l	#5,position
	asr.l	#5,d0
	asr.l	#3,d1
	tst.w	d0
	bmi.W	kkend
	tst.w	d1
	bmi.W	kkend
	cmp.w	#20,d1
	bge.W	kkend
	cmp.w	#10,d0
	bge.W	kkend
	movem.l	d0-d1,-(sp)
	move.b	(a5,d1.w),d1
	add.l	d1,d0
	lea	plact,a0
	add.l	d0,a0
	move.b	(a0),d2
	bsr.w	kloc
	beq.W	nokloc
	movem.l	(sp)+,d0-d1
	cmp.b	#2,level
	bne.s	niedrlevel
	tst.b	(a0)
	bmi.w	tamskacz
	cmp.b	#9,d2
	blt.s	k_tu
	neg.b	(a0)
	asl.l	#5,d0
	asl.l	#3,d1
	bsr.w	rysujklocek
	bra.w	tamskacz
niedrlevel:
	cmp.b	#9,d2
	bge.W	tamskacz
k_tu:
	move.w	#4,sample
	neg.b	(a0)
	asl.l	#5,d0
	asl.l	#3,d1
	sub.l	#1,ilkloc
	add.l	#1,punkty
	add.l	d2,punkty

	bsr.w	pokazpunkty

	bsr.w	rysujklocek

	cmp.l	#0,adrl
	bne.w	tuskacz
	bsr.w	random
	move.w	rnd,d2
	asl.w	#2,d2
	lea	litery,a0
	move.l	(a0,d2.w),a0
	cmp.l	#0,a0
	beq.s	tuskacz
	add.l	#12,d0
	move.l	d0,xl
	move.l	d1,yl
	move.l	a0,adrl
	move.l	xl,d2
	move.l	yl,d3
	add.l	#1,d3
	move.l	#8,d5
	tst.b	hardware
	bne.w	rl_hard2
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#8,d4
	move.l	#%01100110,d6
	move.l	gfxbase,a6
	bsr.w	putbitmap	
rl_here:
	add.l	#48,adrl
tuskacz:
	cmp.b	#1,hard
	beq.s	aslkdhwad
tamskacz:
	move.l	#1,kol
	bsr.w	playsample
kkend:
	tst.l	kol
	rts

aslkdhwad:
	bsr.w	playsample
	tst.l	kol
	rts

; * Clear letter *

literka:
	cmp.l	#0,adrl
	bne.s	l_r
	rts
l_r:	movem.l	d0-d7/a0-a6,-(sp)
	move.l	xl,d2
	move.l	yl,d3
	bsr.W	l_lap
	move.l	#%01100110,d6
	move.l	adrl,a0
	cmp.l	#0,a0
	beq.s	l_end
	move.l	#9,d5
	tst.b	hardware
	bne.w	rl_hard
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#8,d4
	move.l	gfxbase,a6
	bsr.w	putbitmap	
l_end:	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Draw letter *

rysujliterke:
	movem.l	d0-d7/a0-a6,-(sp)

	move.l	#%01100110,d6
	move.l	xl,d2
	move.l	yl,d3
	move.l	adrl,a0
	cmp.l	#0,a0
	beq.s	k_he
	sub.l	#48,a0
	move.l	#8,d5
	tst.b	hardware
	bne.s	rl_hard
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#8,d4
	move.l	#8,d5
	move.l	gfxbase,a6
	bsr.w	putbitmap	

k_he:	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Use processor to draw/clear letter *

rl_hard2:
	bsr.b	rl_hard3
	bra.w	rl_here

rl_hard3:
	movem.l	d0-d7/a0-a6,-(sp)
rl_hard:
	bsr.w	bitmap
	bsr.w	addwinpos
	bsr.w	calcvars
	adda.l	#16,a0
	move.w	d5,d6
	sub.w	#1,d6
rl_loop:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a1)
	adda.l	d0,a1
	dbf	d6,rl_loop

	move.w	d5,d6
	sub.w	#1,d6
rl_loop2:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a2)
	adda.l	d0,a2

	dbf	d6,rl_loop2
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Catch letter *

; d2 - letter x
; d3 - letter y

l_lap:	movem.l	d0-d5/d7/a0-a6,-(sp)
	add.l	#8,d3
	cmp.l	yp,d3
	blt.s	la_end
	add.l	#8,d2
	cmp.l	xp,d2
	ble.s	la_end
	sub.l	#72,d2
	cmp.l	xp,d2
	bge.s	la_end
	bsr.s	l_zlap
la_end:
	movem.l	(sp)+,d0-d5/d7/a0-a6
	rts
	
; * What's for dinner ? *

l_zlap:
	move.w	#3,sample
	move.l	xl,position
	add.l	#8,position
	bsr.w	playsample
	clr.b	hard
	move.l	adrl,a2
	bsr.w	rysujliterke
	clr.l	adrl
	sub.l	#48,a2
	cmp.l	#le,a2
	beq.W	lextrazycie
	cmp.l	#lb,a2
	beq.W	lbonus
	cmp.l	#ln,a2
	beq.W	lnastpl
	cmp.l	#ls,a2
	beq.W	lspowolnienie
	cmp.l	#lk,a2
	beq.W	lklej
	cmp.l	#lpyt,a2
	beq.s	lpytajnik
	cmp.l	#lh,a2
	beq.s	lhardball
	rts

; * HARD BALL *

lhardball:
	clr.w	klej
	move.b	#1,hard
	move.l	#haract,liniaadr
	rts

; * ? *

lpytajnik:
	bsr.w	random
	move.w	rnd,d0
	lea	cowylosowane,a0
	add.l	d0,a0
	move.b	(a0),d0
	subq	#1,d0
	beq.B	lextrazycie
	subq	#1,d0
	beq.W	lspowolnienie
	subq	#1,d0
	beq.B	lbonus
	subq	#1,d0
	beq.B	lnastpl
	subq	#1,d0
	beq.W	lklej
	subq	#1,d0
	beq.s	lhardball
	move.l	#nothing,liniaadr
	add.l	#10,punkty
	bsr.w	pokazpunkty
	clr.w	klej
	rts

; * EXTRA LIFE *

lextrazycie:
	move.l	#xtra,liniaadr
	add.l	#10,punkty
	bsr.w	pokazpunkty
	clr.w	klej
	add.l	#1,zycia
	bsr.w	pokazzycia
	rts

; * BONUS *

lbonus:
	move.l	#bonus,liniaadr
	add.l	#60,punkty
	bsr.w	pokazpunkty
	clr.w	klej
	rts

; * NEXT LEVEL *

lnastpl:
	add.l	#10,punkty
	bsr.w	pokazpunkty
	clr.w	klej
	clr.l	ilkloc
	bra.W	koniec

; * SLOW DOWN *

lspowolnienie:
	move.l	#sldown,liniaadr
	add.l	#10,punkty
	bsr.w	pokazpunkty
	clr.w	klej
	move.l	d0,-(sp)
	move.l	ky,d0
	cmp.l	#$4000,d0
	bgt.s	s_zmy
	cmp.l	#-$4000,d0
	blt.s	s_zmy
	bra.s	s_nex
s_zmy:	asr.l	#2,d0
	sub.l	d0,ky
s_nex:	move.l	kx,d0
	cmp.l	#$8000,d0
	bgt.s	s_zmn
	cmp.l	#-$8000,d0
	blt.s	s_zmn
	bra.s	s_exit
	blt.w	s_zmn
s_zmn:	asr.l	#3,d0
	sub.l	d0,kx
s_exit:
	move.l	(sp)+,d0
	rts

; * GLUE *

lklej:
	move.l	#glu,liniaadr
	add.l	#10,punkty
	bsr.B	pokazpunkty
	move.w	#1,klej
	rts

; * Letter falling *

ruchliterki:
	move.l	d0,-(sp)
	move.l	yl,d0
	subq.l	#4,d0
	cmp.l	yp,d0
	bgt.s	rl_k
	addq.l	#5,d0
	move.l	d0,yl
	move.l	(sp)+,d0
	rts
rl_k:
	move.l	(sp)+,d0
	addq.l	#1,yl
	bsr.w	rysujliterke
	move.l	#0,adrl
	rts

nokloc:	movem.l	(sp)+,d0-d1
	tst.l	kol
	rts

; * Extra ball (score bonus) *

zyciowybonus:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	bonusyadr,a0
	move.l	(a0)+,d0
	cmp.l	punkty,d0
	bgt.s	zyboend
	move.l	a0,bonusyadr
	addq.l	#1,zycia
	move.l	#xtra,liniaadr
	bsr.s	pokazzycia
zyboend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Show score *

pokazpunkty:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	punkty,a0
	lea	cyfra,a1
	bsr.w	conv
	lea	cyfra+4,a1
	move.l	#329,d2
	move.l	#24-4,d3
	move.l	#20,d4
	move.l	#5,d0
	bsr.w	piszcyfre
	bsr.w	zyciowybonus
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Show lives * 

pokazzycia:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	zycia,a0
	lea	cyfra,a1
	bsr.w	conv
	lea	cyfra+16,a1
	move.l	#2,d0
	move.l	#329,d2
	move.l	#65-4,d3
	move.l	#20,d4
	bsr.w	piszcyfre
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; IN:  d2 - ascii data
; OUT: d2 - brick's number

kloc:	cmp.b	#32,d2
	beq.s	kniem
	tst.b	d2
	bpl.s	jest
	neg.b	d2
	sub.b	#47,d2
	cmp.b	#8,d2
	bgt.s	khard
	neg.b	d2
	ext.w	d2
	ext.l	d2
	cmp.b	d2,d2
	rts
khard:	sub.b	#41,d2	
	neg.b	d2
	ext.w	d2
	ext.l	d2
	cmp.b	#1,d2
	rts
jest:	sub.b	#47,d2
	cmp.b	#8,d2
	ble.s	nietw
	sub.b	#41,d2	
nietw:	ext.w	d2
	ext.l	d2
kend:	cmp.l	#0,d2
	rts
kniem:	moveq	#0,d2
	tst.l	d2
	rts

; * Show level *

; a0 - level address

rysujplansze:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	#0,ilkloc
	lea	plact,a1
	move.w	#19,d6
rloop1:	move.w	#9,d7
rloop2:
	move.b	(a0)+,d2
	move.b	d2,(a1)+
	bsr.s	kloc
	move.w	#9,d0
	sub.w	d7,d0
	ext.l	d0
	asl.l	#5,d0
	move.w	#19,d1
	sub.w	d6,d1
	ext.l	d1
	asl.l	#3,d1
	tst.l	d2
	bmi.s	niemakloca
	tst.l	d2
	beq.s	niema
	cmp.l	#9,d2
	bge.s	niedoddoilkloc
	add.l	#1,ilkloc
	cmp.b	#1,level
	bge.s	niema
niedoddoilkloc:
	cmp.b	#2,level
	beq.s	niema
	bsr.w	rysujklocek
niema:	dbf	d7,rloop2
	dbf	d6,rloop1		
	movem.l	(sp)+,d0-d7/a0-a6
	rts
niemakloca:
	neg.l	d2
	cmp.l	#9,d2
	bge.s	twardziel
	cmp.b	#0,level
	beq.s	niema
twardziel:
	bsr.w	rysujklocek
	bra.s	niema

; * Draw all *

rysujpanel:
	bsr.w	prawypanel
	bsr.w	pokazzycia
	bsr.w	pokazpunkty
	bsr.w	pokazplansze
	bsr.s	lewypanel
	bsr.s	statusline
	rts

; * Draw left part of the window *

lewypanel:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.l	d0
	clr.l	d1
	move.l	#321,d2
	move.l	#176,d3
	bsr.s	ramka
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Draw status line *

statusline:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.l	d0
	move.l	staty,d1
	move.l	#321,d2
	move.l	#9,d3
	bsr.s	ramka
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Draw standard border *

normborder:
	movem.l	d0-d7/a0-a6,-(sp)
	move.b	#2,col1
	move.b	#1,col2
	move.b	#0,clr
	bra.s	ramere

; * Draw inversed border *

invborder:
	movem.l	d0-d7/a0-a6,-(sp)
	move.b	#1,col1
	move.b	#2,col2
	move.b	#0,clr
	bra.s	ramere

; * Draw border *

ramka:
	movem.l	d0-d7/a0-a6,-(sp)
	move.b	#2,col1
	move.b	#1,col2
	move.b	#1,clr

ramere:
	lea	tab1,a0

	add.w	addy,d1
	addq.l	#4,d0
	move.w	d0,tu1
	move.w	d1,tam1
	move.w	d0,tu2
	move.w	d1,tam2
	sub.w	addy,d1
	subq.l	#4,d0

	move.w	#0,(a0)+
	move.w	d3,(a0)+
	move.w	#0,(a0)+
	move.w	#0,(a0)+
	move.w	d2,(a0)+
	move.w	#0,(a0)+

	move.w	d2,(a0)+
	move.w	#0,(a0)+
	move.w	d2,(a0)+
	move.w	d3,(a0)+
	move.w	#0,(a0)+
	move.w	d3,(a0)+

	move.l	d2,d4
	move.l	d3,d5
	move.l	d0,d2
	move.l	d1,d3

	tst.b	clr
	beq.s	noclr

	lea	panel,a0
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#0,d6
	move.l	gfxbase,a6
	bsr.b	putbitmap

noclr:
	lea	poleramka,a1
	moveq	#0,d0
	moveq	#0,d1
	move.l	rastport,a0
	move.l	intbase,a6
	jsr	_DrawBorder(a6)

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

; * Clear status line *

clearstatline:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	panel,a0
	clr.l	d0
	clr.l	d1
	move.l	#1,d2
	move.l	staty,d3
	addq.l	#1,d3
	move.l	#319,d4
	move.l	#8,d5
	move.l	rastport,a1
	move.l	#0,d6
	move.l	gfxbase,a6
	bsr.b	putbitmap
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Draw object *

; *** a0 - bitmap
; *** a1 - rp
; *** d0 - src x
; *** d1 - src y
; *** d2 - dest x
; *** d3 - dest y
; *** d4 - size x
; *** d5 - size y

putbitmap:
	add.w	#5,d2
	add.w	addy,d3
	move.l	gfxbase,a6
	tst.l	cgfxflag
	beq.s	npbitmap
	tst.l	tmpbitmap
	bne.s	pb_allocated
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	#WinSizeX,d0
	move.l	#WinSizeY,d1
	add.w	addy,d1
	moveq	#2,d2
	moveq	#1,d3
	jsr	-918(a6)
	move.l	d0,tmpbitmap
	movem.l	(sp)+,d0-d7/a0-a6
	tst.l	tmpbitmap
	beq.s	npbitmap
pb_allocated:
	tst.b	d6
	beq.s	clearbitmap
	cmp.b	#%01100110,d6
	bne.s	npbitmap
clearbitmap:
	movem.l	d0-d7/a0-a5,-(sp)
	move.l	tmpbitmap,a1
	moveq	#3,d7
	suba.l	a2,a2
	jsr	-30(a6)
	jsr	_WaitBlit(a6)
	movem.l	(sp)+,d0-d7/a0-a5
	move.l	tmpbitmap,a0
	move.l	d2,d0
	move.l	d3,d1
	move.l	#%11001100,d6
npbitmap:
	jsr	_BltBitMapRastPort(a6)
	jsr	_WaitBlit(a6)
	rts

; * Scroll status line *

; d0 - speed

scrollstatline:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.l	d1
	move.l	#4+4,d2
	move.l	staty,d3
	add.l	#1,d3
	move.l	#319+4,d4
	move.l	staty,d5
	add.l	#8,d5
	bsr.s	scroll
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Scroll raster *

; d0,d1 - dx,dy
; d2,d3 - minx, miny
; d4,d5 - maxx, maxy

scroll:
	movem.l	d0-d7/a0-a6,-(sp)
	add.w	addy,d5
	add.w	addy,d3
	move.l	rastport,a1
	move.l	gfxbase,a6
	jsr	_ScrollRaster(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Draw right part of the window *

prawypanel:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	panel,a0
	clr.l	d0
	clr.l	d1
	move.l	#324,d2
	clr.l	d3
	move.l	rastport,a1
	move.l	#129,d4
	move.l	#187,d5
	move.l	#%11001100,d6
	move.l	gfxbase,a6
	bsr.w	putbitmap	
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; *** d1 - timeout

wait:
wait_loop:
	bsr.w	message
	bsr.s	syswait
	bsr.w	firetestnomsg
	beq.w	wroc
	bsr.w	rmb
	beq.B	d_sleep
	dbf	d1,wait_loop
	rts

syswait:
	movem.l	d0-d7/a0-a6,-(sp)	
	moveq.l	#1,d1
	move.l	dosbase,a6
	jsr	_Delay(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

d_sleep:
	move.l	stack,sp
	bra.W	poczczekania

; * Intro *

demo:
	move.l	#15,d1
	bsr.b	wait

	lea	union,a0
	clr.l	d0
	clr.l	d1
	move.l	#290,d4
	move.l	#70,d5
	move.l	#44,d3
	move.l	#15,d2
	bsr.w	rysuj
	move.l	#15,d1
	bsr.w	wait

	move.l	#150,d3
	move.l	#119,d7
	clr.l	d1
	move.l	#10,d5
demo_loop:
	move.l	#116,d4

	lea	presents,a0
	bsr.w	bitmapcreate
	move.l	#120,d4
	sub.l	d7,d4
	move.l	d7,d2
	add.l	#200,d2
	lea	presents,a0
	bsr.w	rysnob
	bsr.w firetest
	beq.W	wroc
	bsr.w	rmb
	beq.W	d_sleep
	bsr.w	wf
	subq.l	#1,d7
	dbf	d7,demo_loop

	move.w	#49,d7
demo_loop2:
	subq.l	#2,d2
	bsr.w	rysnob
	bsr.w	wf
	dbf	d7,demo_loop2

	moveq.l	#25,d1
	bsr.w	wait

	bsr.w	lewypanel

	lea	arcanoid,a0
	move.l	#75,d3
	move.l	#300,d4
	move.l	#61,d5
	move.l	#10,d2
	clr.l	d0
	clr.l	d1
	bsr.w	rysuj

	lea	mianim,a1
d_animloop:
	move.l	(a1)+,a0
	cmp.l	#0,a0
	beq.s	d_ale
	move.l	#34,d3
	move.l	#76,d4
	move.l	#34,d5
	move.l	#122,d2	
	clr.l	d0
	clr.l	d1
	bsr.w	rysuj
	move.l	#2,d1
	bsr.w	wait
	bra.s	d_animloop
d_ale:
	move.l	#25,d1
	bsr.w	wait
	rts

IECLASS_RAWMOUSE	=2
IECODE_LBUTTON		=104
IECODE_RBUTTON		=105

ie_Class		=4
ie_Code			=6
ie_X			=10
ie_Y			=12

; -------------------------------------------------------------------------

InputHandler:	movem.l	d1-d7/a0-a6,-(sp)

		move.l	a0,a1			; save ptr to first event
ih_Start:
		cmp.b	#IECLASS_RAWMOUSE,ie_Class(a0)
		bne.w	ih_Next			; not a mouse event

		move.w	xmousepos,d0
		add.w	ie_X(a0),d0
		cmp.w	#1,d0
		bge.s	nolim1
		move.w	#1,d0
nolim1:		cmp.w	#255,d0
		ble.s	nolim2
		move.w	#255,d0
nolim2:		move.w	d0,xmousepos

		move.w	ie_Code(a0),d0
		cmp.w	#IECODE_RBUTTON,d0
		beq.s	ih_Next
		cmp.w	#IECODE_RBUTTON+$80,d0
		beq.s	ih_Next

		cmp.w	#IECODE_LBUTTON,d0
		bne.s	nolbp
		move.b	#0,mousebutton
		move.b	#-1,lastbaton
nolbp:
		cmp.w	#IECODE_LBUTTON+$80,d0
		bne.s	nolbr
		move.b	#0,mousebutton
		move.b	#1,lastbaton
nolbr:

		move.b	#0,ie_Class(a0)

ih_Next:	move.l	(a0),a0			; get ptr to next event
		cmp.l	#0,a0			; is there a next event?
		bne.b	ih_Start		; yes, loop again
		move.l	a1,d0			; pass ptr to first event
		movem.l	(sp)+,d1-d7/a0-a6	;   in list to next handler
		rts				; end of interrupt
; -------------------------------------------------------------------------

MP_SIGTASK	=16
MN_REPLYPORT	=14
IND_ADDHANDLER	=9
IND_REMHANDLER	=10
IO_COMMAND	=28
IO_DATA		=40

Openid:		suba.l	a1,a1			; a1 = 0 = find our task
		move.l	4,a6
		jsr	-294(a6)
		lea	InputPort,a1		; reply port for input device
		move.l	d0,MP_SIGTASK(a1)	; signal us when msg received
		move.l	4,a6
		jsr	-354(a6)
		
		lea	InputDevName,a0		; 'input.device'
		lea	InputIOReq,a1		; IOStdReq structure for it
		move.l	#InputPort,MN_REPLYPORT(a1)
		moveq.l	#0,d0			; unit number (n/a)
		moveq.l	#0,d1			; flags (n/a)
		move.l	4,a6
		jsr	-444(a6)

		lea	TimerDevName,a0		; 'input.device'
		lea	TimerIOReq,a1		; IOStdReq structure for it
		move.l	#InputPort,MN_REPLYPORT(a1)
		moveq.l	#0,d0			; unit number (n/a)
		moveq.l	#0,d1			; flags (n/a)
		move.l	4,a6
		jsr	-444(a6)
		lea	TimerIOReq,a1
		move.l	20(a1),timerbase
		rts

; ------------------------------------------------------------------------

installih:
		tst.b	ihinstalled
		bne.w	nop
		tst.b	offmouse1
		beq.w	nop
		tst.w	mouse
		beq.w	nop

		movem.l	d0/d1/a0/a1/a6,-(sp)
		lea	InputIOReq,a1		; input.device io request
		move.w	#IND_ADDHANDLER,IO_COMMAND(a1)
		move.l	#InputInterrupt,IO_DATA(a1)
		move.l	4,a6
		jsr	-456(a6)
		move.b	#1,ihinstalled
		movem.l	(sp)+,d0/d1/a0/a1/a6
				
		rts

removeih:
		tst.b	ihinstalled
		beq.w	nop
		tst.b	offmouse1
		beq.w	nop
		tst.w	mouse
		beq.w	nop

		movem.l	d0/d1/a0/a1/a6,-(sp)
		lea	InputIOReq,a1		
		move.w	#IND_REMHANDLER,IO_COMMAND(a1)
		move.l	#InputInterrupt,IO_DATA(a1)
		move.l	4,a6
		jsr	-456(a6)
		move.b	#0,ihinstalled
		movem.l	(sp)+,d0/d1/a0/a1/a6

		rts

; -------------------------------------------------------------------------

Closeid:
		lea	TimerIOReq,a1		
		move.l	4,a6
		jsr	-450(a6)

		lea	InputIOReq,a1		
		move.l	4,a6
		jsr	-450(a6)

		lea	InputPort,a1		; ptr to the msgport
		move.l	4,a6
		jsr	-360(a6)

		rts				; exit the program

; -------------------------------------------------------------------------

; ************** G A D G E T S  R O U T I N E S **************


; GADGETS

; 1 - standard - x,y,sx,sy,text,image1,image2,$80000000
; 2 - value    - x,y,sx,sy,value,minimum,maximum,$80000000
; 3 - switch   - x,y,sx,sy,default,gadget1,gadget2,...,gadgetn,0,$80000000
; 4 - nop      - x,y,sx,sy,$80000000
; 5 - text     - x,y,textstruct,$80000000
; 6 - select   - x,y,sx,sy,select,text,$80000000
; 7 - text     - x,y,textaddr
; 8 - string   - x,y,sx,sy,buffer,$80000000

; TEXTSTRUCT

; color,x,y,'xxx SOME TEXT xxx',0




; a0 - gadlist
; d0 - min. x
; d1 - min. y
; d2 - max. x
; d3 - max. y

drawscrollgad:

	move.l	d0,g_minx
	move.l	d1,g_miny
	move.l	d2,g_maxx
	move.l	d3,g_maxy
	bsr.s	gad_draw
	rts

; a0 - gadlist

drawgadgets:
	clr.l	g_minx
	clr.l	g_miny
	move.l	#10000,g_maxx
	move.l	#10000,g_maxy
gad_draw:
	move.l	#0,lastbutton
	bsr.w	message
	movem.l	d0-d7/a0-a6,-(sp)
dgloop:
	move.l	(a0),d0		; d0 - gadtype
	tst.l	d0
	beq.s	dgend
	bsr.s	drawgadget
	bsr.s	nextgadget
	bra.s	dgloop
dgend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; in:  a0 - gadget
; out: a0 - next gadget

nextgadget:
	move.l	d0,-(sp)
seloop:
	move.l	(a0)+,d0
	cmp.l	#$80000000,d0
	bne.s	seloop
	move.l	(sp)+,d0
	rts

; a0 - gadget

drawgadget:
	bsr.w	specgad
	beq.s	drawalways
	move.l	g_miny,d3
	move.l	g_maxy,d5
	cmp.l	8(a0),d3
	bgt.s	drawg_end
	cmp.l	8(a0),d5
	ble.s	drawg_end
drawalways:
	move.l	(A0)+,d0
	subq	#1,d0
	beq.W	dgonoff
	subq	#1,d0
	beq.W	dgval
	subq	#1,d0
	beq.s	dgswitch
	subq	#1,d0
	beq.s	dgnop
	subq	#1,d0
	beq.s	dgtextonly
	subq	#1,d0
	beq.s	dgselect
	subq	#1,d0
	beq.s	dgtext
	subq	#1,d0
	beq.w	dgstring
drawg_end:
	rts

dgswitch:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	move.l	(a0)+,a0
	bsr.w	showtextstruct
	movem.l	(sp)+,d0-d7/a0-a6
	rts
dgnop:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dgtext:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d1
	move.l	(a0)+,a0
	movem.l	d0-d1,-(sp)
	moveq	#1,d0
	bsr.w	setcolor
	movem.l	(sp)+,d0-d1
	add.l	#6,d0
	bsr.w	analysetext
	bsr.w	showtext
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dgtextonly:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d1
	move.l	(a0)+,a0
	bsr.w	showtextstruct
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dgselect
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	move.l	(a0)+,d4
	tst.l	d4
	beq.s	nosel
	bsr.w	invborder
nosel:	move.l	(a0)+,a0
	bsr.w	showtextstruct
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dgstring:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	add.l	#1,d0
	add.l	#1,d1
	add.l	#-2,d2
	add.l	#-2,d3
	bsr.w	invborder
	move.l	(a0)+,a0
	sub.l	d0,d2
	asr.l	#3,d2
	add.l	#5,d0
	add.l	#7,d1
	bsr.w	showtext
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dgval:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	add.l	#1,d0
	add.l	#1,d1
	add.l	#-2,d2
	add.l	#-2,d3
	bsr.w	invborder
	move.l	(a0)+,d4
	bsr.s	showvalue
	movem.l	(sp)+,d0-d7/a0-a6
	rts

clearvaltext:
	movem.l	a1/d0,-(sp)
	lea	g_valtext,a1
	moveq	#99,d0
clvallopa:
	move.b	#' ',(a1)+
	dbf	d0,clvallopa
	movem.l	(sp)+,a1/d0
	rts

; d0,d1,d2,d3 - x,y,sx,sy
; d4 - value

showvalue:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	d0-d1,-(sp)	
	move.l	#0,d0
	bsr.w	setdrmode
	ext.l	d2
	asr.l	#3,d2
	ext.l	d4
	move.l	d4,d0
	bsr.s	clearvaltext
	lea	valbuf,a0
	bsr.w	liczbadoascii
	lea	g_valtext,a1
	move.l	d2,d0
	bsr.w	valcopy
	lea	g_val,a0
	movem.l	(sp)+,d0-d1
	bsr.s	showtextstruct
	movem.l	(sp)+,d0-d7/a0-a6
	rts

dgonoff:
	movem.l	d0-d7/a0-a6,-(sp)
	cmp.l	#0,16(a0)
	beq.s	notext
	bsr.s	showtextgad
	bra.s	dgonoffend
notext:
	movem.l	(a0)+,d2-d6
	move.l	(a0)+,a0
	clr.l	d0
	clr.l	d1
	bsr.w	rysuj
dgonoffend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - text structure
; d0 - x
; d1 - y

showtextstruct:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	d0-d1,-(sp)
	move.b	(a0)+,d0
	ext.w	d0
	ext.l	d0
	bsr.w	setcolor
	movem.l	(sp)+,d0-d1
	move.b	(a0)+,d2
	move.b	(a0)+,d3
	ext.w	d2
	ext.w	d3
	ext.l	d2
	ext.l	d3
	add.l	d2,d0
	add.l	d3,d1
	bsr.s	analysetext
	bsr.w	showtext
	movem.l	(sp)+,d0-d7/a0-a6
	rts

showtextgad:
	movem.l	d0-d7/a0-a6,-(sp)
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	move.l	(a0)+,a0
	bsr.s	showtextstruct
	movem.l	(sp)+,d0-d7/a0-a6
	rts

analysetext:
	movem.l	a0/d0,-(sp)
	clr.l	d2
atloop:
	move.b	(a0)+,d0
	tst.b	d0
	beq.s	atend
	cmp.b	#10,d0
	beq.s	atend
	addq.l	#1,d2
	bra.s	atloop
atend:	movem.l	(sp)+,a0/d0
	rts

gadtext:
	bsr.w	dogadget
	cmp.l	#0,a0
	beq.s	nogadtext
	move.l	20(a0),a0
nogadtext:
	rts

; a0 - gadgets

proc_changeypos:
	movem.l	a0/d0,-(sp)
	clr.l	d0
proc_cloop:
	tst.l	(a0)
	beq.s	proc_cend
	add.l	8(a0),d0
	move.l	d0,8(a0)
	bsr.w	nextgadget
	bra.s	proc_cloop
proc_cend:
	movem.l	(sp)+,a0/d0
	rts

; a0 - gadlist
; d0 - abs. pos
; d1 - line feed
; d2 - line move

calcgadpos:
	movem.l	a0/d0-d2,-(sp)
calcgadloop:
	move.l	(a0),d3
	tst.l	d3
	beq.s	calcgadend
	move.l	8(a0),d3
	add.l	d0,d3
	muls	d1,d3
	add.l	d2,d3
	move.l	d3,8(a0)
	bsr.w	nextgadget
	bra.s	calcgadloop
calcgadend:
	movem.l	(sp)+,a0/d0-d2
	rts

; a0 - gadlist

g_scrolldown:
	move.l	a0,-(sp)
	move.l	g_miny,d3
	move.l	g_maxy,d5
g_scrolluptestloop:
	move.l	#0,d2
	bsr.w	specgad
	beq.s	g_scrollhere
	movem.l	(a0)+,d0-d2
	tst.l	d0
	beq.s	g_scrollend
g_scrollhere:
	bsr.w	nextgadget
	cmp.l	d2,d5
	bgt.s	g_scrolluptestloop
	move.l	(sp),a0
	move.l	scrollspeed,d1
	neg.l	d1
	bsr.s	g_doscroll

g_scrollend:
	move.l	(sp)+,a0
	rts

g_scrollup:
	move.l	a0,-(sp)
	move.l	g_miny,d3
	move.l	g_maxy,d5
g_scrolldowntestloop:
	movem.l	(a0)+,d0-d2
	tst.l	d0
	beq.s	g_scrollend
	bsr.w	nextgadget
	cmp.l	d2,d3
	ble.s	g_scrolldowntestloop
	move.l	(sp),a0
	move.l	scrollspeed,d1
	bsr.s	g_doscroll
	bra.s	g_scrollend

; d0 - mask

setwrmask:
	move.l	a0,-(sp)
	move.l	rastport,a0
	move.b	d0,24(a0)
	move.l	(sp)+,a0
	rts

; a0 - gadlist
; d1 - dy

g_doscroll:
	move.b	scrmask,d0
	bsr.b	setwrmask
	move.l	d1,-(sp)
	move.l	d1,d7
	moveq	#-2,d1
	tst.w	d7
	bpl.s	g_doscrplus
	moveq	#2,d1
	neg.w	d7
g_doscrplus:
	asr.w	#1,d7
	sub.w	#2,d7
	moveq	#0,d0
	move.l	g_minx,d2
	move.l	g_miny,d3
	move.l	g_maxx,d4
	move.l	g_maxy,d5
g_doscrollloop:
	bsr.w	scroll
	bsr.w	wfnp
	dbf	d7,g_doscrollloop
	bsr.w	scroll
	move.l	(sp)+,d1

g_movegadpositions:
	move.l	(a0),d0
	beq.s	g_doscrollend
	bsr.w	specgad
	beq.s	g_doscrollhere
	move.l	8(a0),d0
	add.l	d1,8(a0)
	cmp.l	d3,d0
	blt.s	g_gaddraw
	cmp.l	d5,d0
	bgt.s	g_gaddraw
g_doscrollhere:
	bsr.w	nextgadget
	bra.s	g_movegadpositions
g_doscrollend:
	move.b	#$ff,d0
	bsr.b	setwrmask
	rts

g_gaddraw:
	bsr.w	drawgadget
	bra.s	g_doscrollhere

; a0 - gadlist

; a0 - gadaddr

dogadget:
	movem.l	d0-d7/a1-a6,-(sp)
	move.l	a0,actualgadgetlist
	bsr.w	gad_keys
	tst.b	mousebutton
	bne.s	nobutton
	tst.b	lastbaton
	bpl.s	dogaddal
	bsr.w	cursoff
dogaddal:
	move.l	a0,-(sp)
	move.l	window,a0
	move.w	108(a0),d0
	move.w	110(a0),d1
	move.l	(sp)+,a0
	ext.l	d0
	ext.l	d1
	clr.b	ongadget
	bsr.w	clickdetect
	tst.b	d0
	beq.s	dgnogad
	tst.b	lastbaton
	bpl.W	dgaction
	move.l	a0,lastbutton
	bsr.s	gadgetdown
	movem.l	(sp)+,d0-d7/a1-a6
	rts
nobutton:
	tst.b	lastbaton
	bmi.W	pressed
dgnogad:
	tst.l	lastbutton
	beq.s	reallynogad
	move.l	lastbutton,a0
	moveq	#3,d1
	move.l	(a0),d0
	bsr.s	gadfunctions
reallynogad:
	suba.l	a0,a0
	clr.l	lastbutton
	movem.l	(sp)+,d0-d7/a1-a6
	rts

gadgetdown:
	move.l	(a0),d0
	move.l	#1,d1
	bsr.s	gadfunctions
	suba.l	a0,a0
	rts

; d0 - no
; d1 - function

gadfunctions:
	movem.l	d0-d2/a1/a6,-(sp)
	lea	gadfunctable,a1
func_loop:
	move.l	(a1),d2
	tst.l	d2
	beq.s	func_end
	cmp.l	d2,d0
	beq.s	func_yeah
	adda.l	#4*5,a1
	bra.s	func_loop
func_yeah:
	asl.l	#2,d1
	move.l	(a1,d1.w),a6
	jsr	(a6)
func_end:
	movem.l	(sp)+,d0-d2/a1/a6
	rts

gad_nop:
	suba.l	a0,a0
	rts

cursoff:
	tst.b	stringflag
	beq.s	cursoffend
	clr.b	stringflag
	move.l	a0,-(sp)
	move.l	valadr,a0
	bsr.w	drawgadget
	move.l	(sp)+,a0
cursoffend:
	rts

valgadcalc:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.b	REALstring
	bne.s	strgadc
	lea	g_valtext,a0
	bsr.w	asciidoliczba
	move.l	valadr,a0
	move.l	d0,20(a0)
	cmp.l	24(a0),d0
	blt.s	writemin
	cmp.l	28(a0),d0
	bgt.s	writemax
	movem.l	(sp)+,d0-d7/a0-a6
	rts

strgadc:
	lea	g_valtext,a0
	move.l	buf,a1
	move.l	strlen,d7
	sub.l	#1,d7
	move.b	howmanychars+3,-1(a1)
strgadcloop:
	move.b	(a0)+,(a1)+
	dbf	d7,strgadcloop
	movem.l	(sp)+,d0-d7/a0-a6
	rts

writemin:
	move.l	24(a0),20(a0)
	bsr.w	flash
	movem.l	(sp)+,d0-d7/a0-a6
	rts	
writemax:
	move.l	28(a0),20(a0)
	bsr.w	flash
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - gadget

InitString:
	move.b	#1,REALstring
	move.b	#1,stringflag
	bsr.b	putsetvars
	move.l	#0,curspos
	move.l	d0,cursx
	add.l	#1,cursx
	move.l	d1,cursy
	bsr.w	drawcursor
	move.l	buf,a0
	lea	g_valtext,a1
	move.l	strlen,d7
	subq	#1,d7
	clr.l	howmanychars
	move.b	-1(a0),howmanychars+3
initloop:
	move.b	(a0)+,(a1)+
	dbf	d7,initloop
	rts

putsetvars:
	move.l	4(a0),d0
	move.l	8(a0),d1
	move.l	12(a0),d4
	move.l	16(a0),d5
	move.l	d5,h
	add.l	d0,d4
	add.l	d1,d5
	add.l	#2,d0
	add.l	#2,d1
	sub.l	#2,d4
	sub.l	#2,d5
	move.l	d0,cursminx
	move.l	d4,cursmaxx
	sub.l	#8,cursmaxx
	move.l	cursmaxx,strlen
	sub.l	d0,strlen
	move.l	strlen,d6
	asr.l	#3,d6
	move.l	d6,strlen
	move.b	#1,stringflag
	move.l	a0,valadr
	move.l	20(a0),val
	move.l	20(a0),buf
	move.l	24(a0),valmin
	move.l	28(a0),valmax
	rts

putcursor2:
	move.b	#1,REALstring
	bra.s	puthere
putcursor:
	clr.b	REALstring
puthere:
	bsr.w	putsetvars
	move.l	window,a1
	move.w	108(a1),d2
	move.w	110(a1),d3
	ext.l	d2
	ext.l	d3
	cmp.l	d0,d2
	blt.W	putend
	cmp.l	d1,d3
	blt.W	putend
	cmp.l	d4,d2
	bge.W	putend
	cmp.l	d5,d3
	bge.W	putend
	sub.l	d2,d0
	sub.l	d3,d1
	neg.l	d0
	neg.l	d1
	and.l	#$fffffff8,d0
	and.l	#$fffffff8,d1
	move.l	d0,d6
	asr.l	#3,d6
	move.l	d6,curspos
	add.l	#2,d0
	add.l	#2,d1
	add.l	4(a0),d0
	add.l	8(a0),d1
	move.l	d0,cursx
	move.l	d1,cursy

	lea	cursorbmp,a0

	tst.b	REALstring
	bne.b	Rsrout

	move.l	valadr,a0
	move.l	12(a0),d2
	sub.l	#4,d2
	asr.l	#3,d2
	bsr.w	clearvaltext
	lea	valbuf,a0
	move.l	val,d0
	bsr.w	liczbadoascii
	lea	g_valtext,a1
	move.l	d2,d0
	bsr.w	valcopy

	move.l	strlen,d7
	lea	g_valtext,a1
	clr.l	d0
pc_charcalc:
	cmp.b	#' ',(a1)+
	beq.s	pc_nchar
	addq	#1,d0
	dbf	d7,pc_charcalc
pc_nchar:
	move.l	d0,howmanychars
pc_continue:
	move.l	curspos,d1
pc_putverify
	cmp.l	d1,d0
	bge.s	putOK
	subq.l	#1,d1
	sub.l	#8,cursx
	bra.s	pc_putverify

putOK:
	move.l	d1,curspos
	bsr.w	drawcursor
putend:
	suba.l	a0,a0
	rts

Rsrout:
	move.l	buf,a0
	lea	g_valtext,a1
	move.l	strlen,d7
	subq	#1,d7
	clr.l	howmanychars
	move.b	-1(a0),howmanychars+3
rsroutlop:
	move.b	(a0)+,(a1)+
	dbf	d7,rsroutlop
	move.l	howmanychars,d0
	bra.s	pc_continue

gad_keys:
	tst.b	stringflag
	beq.s	gad_keysend
	tst.b	REALstring
	bne.s	gad_allkeys
	cmp.w	#'0',key
	blt.s	gadk_end
	cmp.w	#'9',key
	bgt.s	gadk_end
	bra.w	insval
gadk_end:
	cmp.w	#79,rawkey
	beq.W	cursleft
	cmp.w	#78,rawkey
	beq.W	cursright
	cmp.w	#8,key
	beq.W	k_backspace
	cmp.w	#127,key
	beq.W	k_delete
	cmp.w	#13,key
	beq.B	k_ENTER
	cmp.w	#0,key
	beq.s	k_nokey
	bsr.w	flash
k_nokey:
gad_keysend:
	rts

gad_allkeys:
	cmp.w	#8,key
	beq.s	gadk_end
	cmp.w	#127,key
	beq.s	gadk_end
	cmp.w	#13,key
	beq.s	gadk_end
	cmp.w	#0,key
	beq.s	gadk_end
	move.l	curspos,d1
	subq	#1,d1
	lea	g_valtext,a0
	move.b	(a0,d1.w),d1
	move.w	key,d0
	bra.s	insval

k_ENTER:
	bsr.w	valgadcalc
	bsr.w	cursoff
	rts

insval:
	movem.l	a0/d0-d5,-(sp)
	move.l	curspos,d0
	move.w	key,d2
	move.l	strlen,d1
	cmp.l	howmanychars,d1
	beq.s	insend
	add.l	#1,howmanychars
	lea	g_valtext,a0
	bsr.w	inschar
	moveq	#-8,d0
	moveq	#0,d1
	move.l	cursmaxx,d4
	move.l	cursy,d3
	move.l	cursx,d2
	move.l	d3,d5
	add.l	h,d5
	subq	#4,d5
	addq	#4,d2
	add.l	#4+8,d4
	bsr.w	scroll
	add.l	#1,curspos
	move.l	cursx,d0
	move.l	cursy,d1
	moveq	#1,d2
	lea	g_lettertext,a0
	move.b	key+1,(A0)
	lea	g_letter,a0
	bsr.w	showtextstruct
	add.l	#8,cursx
	movem.l	(sp)+,a0/d0-d5
	rts

insend:
	bsr.w	flash
	movem.l	(sp)+,a0/d0-d5
	rts

k_backspace:
	cmp.l	#0,curspos
	beq.b	curs_nomove
	movem.l	d0-d7/a0-a6,-(sp)
	sub.l	#1,curspos

	move.l	curspos,d0
	move.l	strlen,d1
	lea	g_valtext,a0
	bsr.w	delchar
	moveq	#8,d0
	moveq	#0,d1
	move.l	cursmaxx,d4
	sub.l	#8,cursx
	move.l	cursx,d2
	move.l	cursy,d3
	move.l	d3,d5
	add.l	h,d5
	subq	#4,d5
	addq	#4,d2
	add.l	#4+8,d4
	bsr.w	scroll
	sub.l	#1,howmanychars
	
	movem.l	(sp)+,d0-d7/a0-a6
	rts

curs_nomove:
	bsr.w	flash
	rts

k_delete:
	cmp.l	#0,howmanychars
	beq.s	curs_nomove
	movem.l	d0-d7/a0-a6,-(sp)
	moveq	#8,d0
	moveq	#0,d1
	move.l	cursmaxx,d4
	move.l	cursy,d3
	move.l	cursx,d2
	move.l	d3,d5
	add.l	h,d5
	subq	#4,d5
	addq	#4,d2
	add.l	#4+8,d4
	bsr.w	scroll
	bsr.w	drawcursor
	move.l	curspos,d0
	move.l	strlen,d1
	lea	g_valtext,a0
	bsr.s	delchar
	sub.l	#1,howmanychars
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - string
; d0 - char number
; d1 - len

delchar:
	movem.l	a1/d2,-(sp)
	moveq	#-1,d2
	move.l	a0,a1
	sub.w	#2,d1
delcharloop:
	addq	#1,d2
	cmp.w	d2,d0
	beq.s	delcharloop
	move.b	(a0,d2.w),(a1)+
	dbf	d1,delcharloop
	move.b	#' ',(a1)+
	movem.l	(sp)+,a1/d2
	rts

; a0 - string
; d0 - char number
; d1 - len
; d2 - char

inschar:
	MOVEM.L	a0-a1/d0-d2,-(sp)
	move.l	a0,a1
	subq	#1,d1
	cmp.w	d1,d0
	beq.s	ins_ert
inscharloop:
	move.b	0(a0,d1.w),1(a0,d1.w)
	subq	#1,d1
	cmp.w	d1,d0
	bne.s	inscharloop
	move.b	0(a0,d1.w),1(a0,d1.w)
ins_ert:
	move.b	d2,(a0,d1.w)
	MOVEM.L	(sp)+,a0-a1/d0-d2
	rts


; d0,d1 - dx,dy
; d2,d3 - minx, miny
; d4,d5 - maxx, maxy

cursright:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.b	stringflag
	beq.W	cursend

	move.l	curspos,d0
	cmp.l	howmanychars,d0
	beq.w	cursmoveend
	clr.l	d0
	clr.l	d1
	move.l	cursx,d2
	cmp.l	cursmaxx,d2
	bge.W	cursmoveend
	add.l	#8,cursx
	move.l	cursy,d3
	moveq	#16,d4
	move.l	h,d5
	subq	#3,d5
	move.l	#%01011010,d6
	lea	cursormovebmp,a0
	bsr.w	rysop
	add.l	#1,curspos
	movem.l	(sp)+,d0-d7/a0-a6
	rts

drawcursor:
	clr.l	d0
	clr.l	d1
	move.l	cursx,d2
	move.l	cursy,d3
	moveq	#8,d4
	move.l	h,d5
	subq	#3,d5
	move.l	#%01011010,d6
	lea	cursorbmp,a0
	bsr.w	rysop
	rts

cursleft:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.b	stringflag
	beq.s	cursend

	clr.l	d0
	clr.l	d1
	move.l	cursx,d2
	cmp.l	cursminx,d2
	ble.s	cursmoveend
	sub.l	#8,d2
	sub.l	#8,cursx
	move.l	cursy,d3
	moveq	#16,d4
	move.l	h,d5
	subq	#3,d5
	move.l	#%01011010,d6
	lea	cursormovebmp,a0
	bsr.w	rysop
	sub.l	#1,curspos
	movem.l	(sp)+,d0-d7/a0-a6
	rts
cursmoveend:
	bsr.w	flash
cursend:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

invertonoff:
	cmp.b	#1,invonoff
	beq.s	noinvonoff
	move.b	#1,invonoff
	bsr.w	invertgad
noinvonoff:
	move.l	actualgadgetlist,a0
	move.l	lastbutton,a1
	move.l	24(a1),a1
	cmp.l	#g_up,a1
	beq.W	g_scrollup
	cmp.l	#g_down,a1
	beq.W	g_scrolldown
	suba.l	a0,a0
	rts

normalfr:
	move.l	(a0)+,d0
	movem.l	(a0)+,d0-d3
	bsr.w	normborder
	rts
invertfr:
	move.l	(a0)+,d0
	movem.l	(a0)+,d0-d3
	bsr.w	invborder
	rts

switchgad:
	move.l	(a0)+,d0
	movem.l	(a0)+,d0-d3
	bsr.w	ramka
	move.l	(a0)+,a1
	move.l	a0,-(sp)
swi_loop:
	move.l	(a0)+,a2
	cmp.l	a1,a2
	bne.s	swi_loop
	move.l	(a0)+,a0
	cmp.l	#0,a0
	beq.s	swi_restart
	move.l	(sp)+,a1
	move.l	a0,-(a1)
	bsr.w	showtextstruct
	suba.l	a0,a0
	rts
swi_restart:
	move.l	(sp)+,a1
	move.l	(a1),a0
	move.l	(a1),-(a1)
	bsr.w	showtextstruct
	suba.l	a0,a0
	rts

selgad:
	bsr.w	normalgad
	rts

dgaction:
	cmp.l	lastbutton,a0
	bne.s	noaction
	move.l	#4,d1
	move.l	(a0),d0
	bsr.w	gadfunctions
	movem.l	(sp)+,d0-d7/a1-a6
	rts
noaction:
	suba.l	a0,a0
	movem.l	(sp)+,d0-d7/a1-a6
	rts

pressed:
	move.l	window,a0
	move.w	108(a0),d0
	move.w	110(a0),d1
	ext.l	d0
	ext.l	d1
	move.l	lastbutton,a0
	bsr.w	clickdetect
	move.l	a0,a1
	move.l	lastbutton,a0
	cmp.l	a0,a1
	bne.s	holdnogad
	move.l	(a0),d0
	move.l	#2,d1
	bsr.w	gadfunctions
	movem.l	(sp)+,d0-d7/a1-a6
	suba.l	a0,a0
	rts
holdnogad:
	move.l	(a0),d0
	move.l	#3,d1
	bsr.w	gadfunctions
	suba.l	a0,a0
	movem.l	(sp)+,d0-d7/a1-a6
	rts

invertgad:
	movem.l	d0-d7/a0-a6,-(sp)
	cmp.l	#0,20(a0)
	bne.s	invertframe
	clr.l	d0
	clr.l	d1
	move.l	04(a0),d2
	move.l	08(a0),d3
	move.l	12(a0),d4
	move.l	16(a0),d5
	move.l	28(a0),a0
	bsr.w	rysuj
	movem.l	(sp)+,d0-d7/a0-a6
	rts
invertframe:
	move.l	04(a0),d0
	move.l	08(a0),d1
	move.l	12(a0),d2
	move.l	16(a0),d3
	bsr.w	invborder
	movem.l	(sp)+,d0-d7/a0-a6
	rts

normalgad:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.b	invonoff
	cmp.l	#0,20(a0)
	bne.s	normframe
	clr.l	d0
	clr.l	d1
	move.l	04(a0),d2
	move.l	08(a0),d3
	move.l	12(a0),d4
	move.l	16(a0),d5
	move.l	24(a0),a0
	bsr.w	rysuj
	movem.l	(sp)+,d0-d7/a0-a6
	rts
normframe:
	move.l	04(a0),d0
	move.l	08(a0),d1
	move.l	12(a0),d2
	move.l	16(a0),d3
	bsr.w	normborder
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - gadget

; Z = 1 when it's the special gadget
; Z = 0 when it isn't

specgad:
	movem.l	d0/a1-a2,-(sp)
	lea	specialgadgets,a1
sgloop:
	move.l	(a1)+,a2
	move.l	(a1)+,d0
	beq.s	sgend
	cmp.l	(a0,d0.w),a2
	bne.s	sgloop
	movem.l	(sp)+,d0/a1-a2
	tst.b	sg_zero
	rts
sgend:
	movem.l	(sp)+,d0/a1-a2
	tst.b	sg_jeden
	rts

; a0 - gadlist
; d0,d1 - x,y

; d0 - 0:False  1:True
; a0 - gadget

clickdetect:
	movem.l	d2-d6/a3-a4,-(sp)
	suba.l	a3,a3
cdloop:
	tst.l	(a0)
	beq.s	cdend
	bsr.b	specgad
	beq.s	cdhere
	move.l	g_miny,d3
	move.l	g_maxy,d5
	cmp.l	d1,d3
	bgt.s	cdnex
	cmp.l	d1,d5
	ble.s	cdnex
cdhere:
	move.l	a0,a4
	movem.l	(a0)+,d2-d6
	suba.l	#20,a0
	tst.l	d2
	beq.s	cdend
	bsr.w	nextgadget
	cmp.l	#5,d2
	beq.s	cdloop
	cmp.l	#7,d2
	beq.s	cdloop
	add.l	d3,d5
	add.l	d4,d6
	cmp.l	d3,d0
	blt.s	cdloop
	cmp.l	d4,d1
	blt.s	cdloop
	cmp.l	d5,d0
	bgt.s	cdloop
	cmp.l	d6,d1
	bgt.s	cdloop

	cmp.l	#4,d2
	beq.s	gadnop

	move.l	a4,a0
	move.l	#1,a3
	move.b	#1,ongadget
cdend:
	move.l	a3,d0
	movem.l	(sp)+,d2-d6/a3-a4
	rts

gadnop:	move.b	#1,ongadget
	bra.w	cdloop

cdnex:	bsr.w	nextgadget
	bra.w	cdloop

; ******************** end of gadgets routines *********************

; * Open screen *

openscreen:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.b	workb
	lea	textattr,a0
	move.l	gfxbase,a6
	jsr	_OpenFont(a6)
	move.l	d0,screen_font
sopenretry:
	move.l	intbase,a6
	lea	newscreen,a0
	jsr	_OpenScreen(a6)
	tst.l	d0
	beq.B	screrror
	move.l	d0,actscreen
	move.l	d0,win_screen
	move.w	#$f,win_type

	move.l	actscreen,a0
	lea	$2c(a0),a0
	lea	colors,a1
	moveq	#4,d0
	move.l	gfxbase,a6
	jsr	-192(a6)

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

; * Error - can't open screen *

screrror:
	lea	screrrtext,a0
	lea	retrycancelgad,a1
	moveq	#3,d0
	bsr.w	request
	cmp.l	#g_retry,a0
	beq.s	sopenretry
	move.l	#0,actscreen
	move.l	#0,win_screen
	move.w	#1,win_type
	move.b	#1,workb
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; a0 - scrolltext

scrollinit:
	clr.b	licznik
	move.l	a0,scrolladr
	bsr.w	clearstatline
	move.l	scrolladr,a0
	rts

; * Scroll status line *

; a0 - text

scrolltext:
	movem.l	a1/d0-d3,-(sp)
	move.l	scrolladr,a1
	move.b	(a1),d0
	cmp.b	#-1,d0
	beq.s	scr_end
	tst.b	licznik
	bne.s	scroll_only
	move.b	speed,d0
	ext.w	d0
	ext.l	d0
	move.l	#8,d1
	divu	d0,d1
	move.b	d1,licznik
scr_tu:
	move.b	(a1)+,d0
	tst.b	d0
	bne.s	nores
	move.l	a0,a1
	bra.s	scr_tu
nores:	cmp.b	#-2,d0
	bne.s	nospeedchange
	move.b	(a1)+,speed
	bra.s	scr_tu
nospeedchange:
	move.l	#308,d2
	move.l	staty,d3
	addq.l	#1,d3
	bsr.s	char
scroll_only:
	sub.b	#1,licznik
	move.b	speed,d0
	ext.w	d0
	ext.l	d0
	bsr.w	scrollstatline
	move.l	a1,scrolladr
	movem.l	(sp)+,a1/d0-d3
	rts

scr_end:
	addq	#1,a1
	move.l	a1,scrolladr
	movem.l	(sp)+,a1/d0-d3
	rts


; * Draw line *

; a0 - line address

line:
	movem.l	a0/d2-d3/d7,-(sp)
	move.l	#4,d2
	move.l	staty,d3
	addq.l	#1,d3
	move.w	#38,d7
l_loop:	move.b	(a0)+,d0
	cmp.b	#-1,d0
	beq.s	l_loop
	cmp.b	#-2,d0
	beq.s	l_loop
	bsr.s	char
	addq	#8,d2
	dbf	d7,l_loop
	movem.l	(sp)+,a0/d2-d3/d7
	rts

; * Draw letter in status line *

; d0 - ascii code
; d2 - x
; d3 - y

char:
	cmp.b	#32,d0
	bne.s	char_nosp
	rts
char_nosp:
	movem.l	a0/d0-d5,-(sp)
	and.w	#$ff,d0
	lea	chartable,a0
	move.b	(a0,d0.w),d0
	lea	alphabet,a0
	and.l	#$ff,d0
	mulu	#11,d0
	add.l	#1,d0
	move.l	#1,d1
	move.l	#8,d4
	move.l	#8,d5
	move.w	#70,szer
	move.w	#10,wys
	move.l	a0,adres1b
	move.l	a0,adres2b
	add.l	#700,adres2b
	bsr.s	rysnob
	movem.l	(sp)+,a0/d0-d5
	rts

; ***************** DRAW ROUTINE **********************
; *** a0 - object
; *** d0 - move x
; *** d1 - move y
; *** d2 - x
; *** d3 - y
; *** d4 - size x
; *** d5 - size y
; *****************************************************
rysuj:
	move.l	#%11001100,d6

; *****************************************************
; *** d6 - operation
; *****************************************************

rysop:
	bsr.s	bitmapcreate
rysdal:	movem.l	d0-d7/a0-a6,-(sp)
	lea	bitmapstruct,a0
	move.l	rastport,a1
	move.l	gfxbase,a6
	bsr.w	putbitmap
	movem.l	(sp)+,d0-d7/a0-a6
	rts

rysnob:
	move.l	#%11001100,d6
	bra.s	rysdal

bitmapcreate:
	movem.l	a0/d4-d6,-(sp)
	move.w	d4,d6
	add.w	#15,d6
	asr.w	#3,d6
	and.w	#$fffe,d6
	move.w	d6,szer
	move.w	d5,wys
	move.l	a0,adres1b
	mulu	d5,d6
	ext.l	d6
	add.l	d6,a0
	move.l	a0,adres2b
	movem.l	(sp)+,a0/d4-d6
	rts

; * Draw string *

; a0 - string
; d0 - length
; d2 - x pos
; d3 - y pos
; d4 - add x

piszcyfre:
	movem.l	d0-d7/a0-a6,-(sp)
	subq.l	#1,d0
p_next:	move.l	(a1)+,a0
	movem.l	d0-d4/a1,-(sp)
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#19,d4
	move.l	#17,d5
	move.l	#%11001100,d6	
	move.l	gfxbase,a6
	bsr.w	putbitmap
	movem.l	(sp)+,d0-d4/a1
	add.l	d4,d2
	dbf	d0,p_next
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Draw brick *

; d0-x
; d1-y
; d2-brick's number

rysujklocek:
	movem.l	d0-d7/a0-a6,-(sp)
        addq	#1,d1
	lea	tablicaklockow,a0
	sub.l	#1,d2
	asl.l	#2,d2
	add.l	d2,a0
	move.l	(a0),a0
	move.l	d0,d2
	move.l	d1,d3
	tst.b	hardware
	bne.w	rysklohard
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#32,d4
	move.l	#8,d5
	move.l	#%01100110,d6
	move.l	gfxbase,a6
	bsr.w	putbitmap
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Analyse bitmap *
; out: a1, a2 - bitplanes, d0 - modulo

bitmap:
	move.l	actscreen,a1
	add.l	#$c0,a1
	move.w	-8(a1),d0
	move.l	4(a1),a2
	move.l	0(a1),a1
	ext.l	d0
	rts

; * Add window position *

; in:  d2,d3 - x, y pos
; out: d2,d3 - x+winx+addx, y+winy+addy

addwinpos:
	move.l	a0,-(sp)
	move.l	window,a0
	add.w	4(a0),d2
	add.w	6(a0),d3
	add.w	addy,d3
	add.w	#4,d2
	ext.l	d2
	ext.l	d3
	move.l	(sp)+,a0

	rts

; * Convert *
;in:  d0 - mod, d2 - x, d3 - y, a1 - plane1, a2 - plane2
;out: a1,a2 - plane+y*mod+(x/16)&$fffe
;     d2 - rot. x
;     d3 - y*40
;     d4 - x/16&$fffe

calcvars:
	mulu	d0,d3
	adda.l	d3,a1
	adda.l	d3,a2
	move.l	d2,d4
	asr.w	#3,d4
	and.l	#$fffe,d4
	adda.l	d4,a1
	adda.l	d4,a2
	and.l	#$f,d2
	eor.l	#$f,d2
	rts

; * Draw brick (using processor)

rysklohard:
	bsr.b	bitmap
	bsr.b	addwinpos
	bsr.b	calcvars
	adda.l	#16,a0
	move.w	#7,d6
rkh_loop:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a1)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,2(a1)
	adda.l	d0,a1
	dbf	d6,rkh_loop

	move.w	#7,d6
rkh_loop2:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a2)

	moveq	#0,d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,2(a2)
	adda.l	d0,a2

	dbf	d6,rkh_loop2
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Detect collision *

; up
kolizjag:
	movem.l	d0-d6/a0/a1/a6,-(sp)
	sub.l	#2,d1
	add.l	#7,d0
	bsr.w	kolizja
	movem.l	(sp)+,d0-d6/a0/a1/a6
	tst.l	kol
	rts
; down
kolizjad:
	movem.l	d0-d6/a0/a1/a6,-(sp)
	add.l	#4,d1
	add.l	#7,d0
	bsr.w	kolizja
	movem.l	(sp)+,d0-d6/a0/a1/a6
	tst.l	kol
	rts
; left
kolizjal:
	movem.l	d0-d6/a0/a1/a6,-(sp)
	add.l	#3,d0
	add.l	#1,d1
	bsr.w	kolizja
	movem.l	(sp)+,d0-d6/a0/a1/a6
	tst.l	kol
	rts
; right
kolizjap:
	movem.l	d0-d6/a0/a1/a6,-(sp)
	add.l	#10,d0
	add.l	#1,d1
	bsr.w	kolizja
	movem.l	(sp)+,d0-d6/a0/a1/a6
	tst.l	kol
	rts

; * Load configuration *

loadconfig:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	#configname,d1
	move.l	#1005,d2
	move.l	dosbase,a6
	jsr	_Open(a6)
	tst.l	d0
	beq.s	lc_nofile
	move.l	d0,-(sp)
	move.l	d0,d1
	move.l	#configfile,d2
	move.l	#configfileend-configfile,d3
	move.l	dosbase,a6
	jsr	_Read(a6)
	move.l	dosbase,a6
	jsr	_IOErr(a6)
	tst.l	d0
	bne.s	lc_loaderr
	move.l	(sp)+,d1
	move.l	dosbase,a6
	jsr	_Close(a6)
	bsr.w	ConfigFileToOptions
lc_nofile:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Load error *

lc_loaderr:
	move.l	(sp)+,d1
	move.l	dosbase,a6
	jsr	_Close(a6)
	bsr.w	flash
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Escape key test *

esc:	cmp.w	#27,key
	bne.s	noesc
	bsr.w	clearpointer		; if esc pressed then set
	move.l	stack,sp		; standard pointer, clear
	clr.b	closeflag2		; variables, and stop game
	clr.b	offmouse2
	bsr.w	removeih
	bra.w	pogrze
noesc:	rts

space:
	cmp.w	#32,key
	bne.s	nospace
	move.l	d0,-(sp)
	clr.w	key
	bsr.w	random
	move.w	rnd,d0
	ext.w	d0
	ext.l	d0
	asl.l	#8,d0
	add.l	d0,kx
	move.w	tilt_counter,d0
	add.w	#10,d0
	move.w	d0,tilt_counter
	cmp.w	#25,d0
	bgt.s	tilt
	cmp.w	#15,d0
	bgt.s	tilt_warning
	move.l	(sp)+,d0
nospace:
	rts

tilt_warning:
	move.w	#6,sample
	move.l	#160,position
	bsr.w	playsample
	move.l	#tiltwtxt,liniaadr
	move.l	(sp)+,d0
	rts

tilt:
	move.w	#7,sample
	move.l	#160,position
	bsr.w	playsample
	move.l	#tilttxt,liniaadr
	move.b	#1,tiltflag
	move.l	(sp)+,d0
	rts

p_time:	dc.l	0
p_vis:	dc.l	0

checkpause:
	movem.l	d0-d7/a0-a6,-(sp)
	cmp.w	#80,key
	beq.s	dopause
	cmp.w	#112,key
	beq.s	dopause
	tst.b	autopauseflag
	bne.s	noautopause
	move.l	window,d0
	move.l	intbase,a6
	cmp.l	52(a6),d0
	bne.s	dopause
	move.l	actscreen,d0
	cmp.l	56(a6),d0
	bne.s	dopause
noautopause:
	movem.l	(sp)+,d0-d7/a0-a6
	rts
dopause:
	move.b	#1,pauseflag
	move.l	#1,p_vis
	move.l	#0,p_time
	
	bsr.w	clearpointer		; normal pointer
	clr.b	closeflag2		; close gadget active
	clr.b	offmouse2		; mouse on
	bsr.w	removeih

	move.w	#0,key
dp_loop:
	move.l	dosbase,a6
	move.l	#1,d1
	jsr	_Delay(a6)

	sub.l	#1,p_time
	tst.l	p_time
	bpl.s	p_nc

	move.l	#20,p_time

	tst.l	p_vis
	beq.s	notvis

	move.l	#0,p_vis
	move.l	#PAUSE,liniaadr
	bsr.w	wyswietlacz		; draw messages
	bra.s	p_nc

notvis:
	move.l	#1,p_vis
	move.l	#0,liniaadr
	clr.l	wysw_czas
	bsr.w	wyswietlacz		; draw messages

p_nc:

	bsr.w	message
	bsr.w	rmbtrap
	tst.w	key
	beq.s	dp_loop

	move.b	closeflag1,closeflag2	; close gadget on/off
	move.b	offmouse1,offmouse2	; mouse pointer on/off
	bsr.w	installih

	bsr.w	setpointer		; show pointer

	move.b	#0,pauseflag

	move.l	#0,liniaadr
	clr.l	wysw_czas
	bsr.w	wyswietlacz		; draw messages

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

	rts

; * Clear old stick and draw it again *

ryspaletki:
	move.l	d0,-(sp)
	move.l	xp,d0
	cmp.l	sxp,d0
	beq.s	pal_end
	bsr.s	kasujpaletke
	bsr.s	rysujpaletke
pal_end:
	move.l	(sp)+,d0
	rts

; * Clear stick *

kasujpaletke:
	movem.l	d0-d7/a0-a6,-(sp)

	move.l	sxp,d2
	bra.s	kasp

; * Draw stick *

rysujpaletke:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	xp,d2
kasp:
	lea	paletka,a0
	move.l	yp,d3
	tst.b	hardware
	bne.s	rphard
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#64,d4
	move.l	#6,d5
	move.l	#%01100110,d6
	move.l	gfxbase,a6
	bsr.w	putbitmap

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

; * Use processor *

rphard:
	bsr.w	bitmap
	bsr.w	addwinpos
	bsr.w	calcvars
	adda.l	#16,a0
	move.w	#5,d6
rph_loop:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a1)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,2(a1)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,4(a1)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,6(a1)

	adda.l	d0,a1
	dbf	d6,rph_loop

	move.w	#5,d6
rph_loop2:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a2)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,2(a2)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,4(a2)

	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,6(a2)

	adda.l	d0,a2

	dbf	d6,rph_loop2
	movem.l	(sp)+,d0-d7/a0-a6
	rts


; * Draw ball *

; d0-x
; d1-y

rysujkulke:
	cmp.w	#-10,d0
	bne.s	rysujk
	rts
rysujk:	movem.l	d0-d7/a0-a6,-(sp)
	move.l	d0,d2
	move.l	d1,d3
	lea	kulkabitmap,a0
	tst.b	hardware
	bne.s	rkhard
	clr.l	d0
	clr.l	d1
	move.l	rastport,a1
	move.l	#10,d4
	move.l	#6,d5
	move.l	#%01100110,d6
	move.l	gfxbase,a6
	bsr.w	putbitmap
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Use processor to draw ball *

rkhard:
	bsr.w	bitmap
	bsr.w	addwinpos
	bsr.w	calcvars
	adda.l	#16,a0
	move.w	#5,d6
rk_loop:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a1)
	adda.l	d0,a1
	dbf	d6,rk_loop
	adda.l	#4,a0

	move.w	#5,d6
rk_loop2:
	clr.l	d1
	move.w	(a0)+,d1
	lsl.l	d2,d1
	eor.l	d1,(a2)
	adda.l	d0,a2

	dbf	d6,rk_loop2
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Open window *

openwindow:
	movem.l	d0-d3/a0,-(sp)

	move.w	win_sizey,d0
	move.w	win_sizex,d1
	move.w	win_y,d2
	move.w	win_x,d3

	move.w	#1,win_sizex
	move.w	#1,win_sizey
	move.w	#1,win_y
	move.w	#1,win_x

	bsr.w	open_window
	bsr.w	closewindow

	add.w	addy,d0
	move.w	d0,win_sizey
	move.w	d1,win_sizex
	move.w	d2,win_y
	move.w	d3,win_x

	move.w	win_y,d0
	move.l	actscreen,a0
	tst.w	d0
	bpl.s	nocentery
	move.w	$e(a0),d1
	move.w	win_sizey,d0
	asr.w	#1,d0
	asr.w	#1,d1
	sub.w	d0,d1
	move.w	d1,win_y
nocentery:
	move.w	win_y,d0
	move.w	$e(a0),d1
	add.w	win_sizey,d0
	cmp.w	d0,d1
	bge.s	nomove
	sub.w	win_sizey,d1
	move.w	d1,win_y

nomove:
	move.w	win_x,d0
	tst.w	d0
	bpl.s	nocenterx
	move.w	$c(a0),d1
	move.w	win_sizex,d0
	asr.w	#1,d0
	asr.w	#1,d1
	sub.w	d0,d1
	move.w	d1,win_x
nocenterx:
	move.w	win_x,d0
	move.w	$c(a0),d1
	add.w	win_sizex,d0
	cmp.w	d0,d1
	bge.s	nomove2
	sub.w	win_sizex,d1
	move.w	d1,win_x
nomove2:
	bsr.s	open_window

	move.w	d2,win_y
	move.w	d3,win_x

	movem.l	(sp)+,d0-d3/a0
	rts

open_window:
	movem.l	d0-d7/a0-a6,-(sp)
ow_retry:
	move.l	intbase,a6
	lea	newwindow,a0
	jsr	_OpenWindow(a6)
	move.l	d0,window
	tst.l	d0
	beq.W	winerr

	move.l	window,a0
	move.l	$2e(a0),actscreen
	move.l	actscreen,rt_scr

	move.l	window,a0
	move.l	$32(a0),a0
	move.l	a0,rastport

	moveq	#0,d0
	move.l	d0,cgfxflag

	lea	cgfxname,a1
	move.l	4,a6
	jsr	-408(a6)
	tst.l	d0
	beq.s	nocgfx

	move.l	d0,-(sp)
	move.l	d0,a6
	move.l	rastport,a0
	move.l	4(a0),a0
	move.l	#$80000008,d1
	jsr	-96(a6)
	tst.l	d0
	beq.s	nocgfxbitmap

	move.l	rastport,a0
	move.l	4(a0),a0
	move.l	#$80000004,d1
	jsr	-96(a6)
	tst.l	d0
	beq.s	nocgfxbitmap

	moveq	#-1,d0
	move.l	d0,cgfxflag

nocgfxbitmap:
	move.l	(sp)+,a1
	move.l	4,a6
	jsr	-414(a6)

nocgfx:
	lea	textattr,a0
	move.l	gfxbase,a6
	jsr	_OpenFont(a6)
	tst.l	d0
	beq.W	error

	move.l	gfxbase,a6
	move.l	d0,a0	
	move.l	rastport,a1
	jsr	_SetFont(a6)

	move.l	actscreen,a0
	move.l	$28(a0),a0
	move.w	4(a0),addy
	add.w	#3,addy

	move.l	actscreen,a0
	move.l	intbase,a6
	jsr	-252(a6)

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

; * Can't open ! *

winerr:
	cmp.l	#tit_req,win_title
	beq.B	requesterror
	lea	winerrtext,a0
	lea	retryquitgad,a1
	move.l	#2,d0
	bsr.w	request
	cmp.l	#g_retry,a0
	beq.W	ow_retry
	
requesterror:
	lea	defwindow,a0
	bsr.w	restorewindow
	bra.w	error

; * Close window *

closewindow:
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	intbase,a6
	move.l	window,a0
	jsr	_CloseWindow(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Convert value to ascii *

; d0 - number
; a0 - ascii buffer

liczbadoascii:
	movem.l	d0-d7/a0-a6,-(sp)
	clr.w	znaczniczek
	move.l	a0,a1
	move.l	d0,d1
	lea	dzielonko,a3
	moveq.l	#5,d0
	move.b	#' ',(a1)
	cmp.l	#99999,d1
	ble.s	wlproc2
	move.b	#'1',(a1)
wlproc2:
	add.l	#1,a1
	subq	#1,d0
c_loop2:
	move.l	d1,d2
	move.l	(a3)+,d3
	divu	d3,d2
	ext.l	d2
	tst.w	d2
	bne.s	nz2
	tst.w	znaczniczek
	bne.s	nz2
	move.b	#' ',(a1)+
	dbf	d0,c_loop2
	movem.l	(sp)+,d0-d7/a0-a6
	rts

nz2:	move.w	#1,znaczniczek
	mulu	d2,d3
	add.l	#48,d2
	move.b	d2,(a1)+
	sub.l	d3,d1
	dbf	d0,c_loop2
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Save config *

saveconfig:
	movem.l	d0-d7/a0-a6,-(sp)
	bsr.w	OptionsToConfigFile
	move.l	#configname,d1
	move.l	#1006,d2
	move.l	dosbase,a6
	jsr	_Open(a6)
	move.l	d0,-(sp)
	tst.l	d0
	beq.s	sc_saveerror2
	move.l	d0,d1
	move.l	#configfile,d2
	move.l	#configfileend-configfile,d3
	move.l	dosbase,a6
	jsr	_Write(a6)
	jsr	_IOErr(a6)
	tst.l	d0
	bne.s	sc_saveerror
	move.l	(sp)+,d1
	move.l	dosbase,a6
	jsr	_Close(a6)
	movem.l	(sp)+,d0-d7/a0-a6
	rts
; * Error *
sc_saveerror:
	move.l	(sp)+,d1
	move.l	dosbase,a6
	jsr	_Close(a6)
	bsr.w	flash
	movem.l	(sp)+,d0-d7/a0-a6
	rts
sc_saveerror2:
	move.l	(sp)+,d1
	bsr.w	flash
	movem.l	(sp)+,d0-d7/a0-a6
	rts

; * Set variables by config file *

configfiletooptions:
	lea	configtable,a0
	lea	configfile,a1
cfto_loop:
	move.l	(a1)+,d0	
	move.l	(a0)+,a2
	cmp.l	#0,a2
	beq.s	cfto_end
	move.l	(a0)+,d1
	cmp.l	#'long',d1
	beq.s	cfto_l
	cmp.l	#'word',d1
	beq.s	cfto_w
	move.b	d0,(a2)
	bra.s	cfto_loop
cfto_end:
	rts
cfto_w:	move.w	d0,(A2)
	bra.s	cfto_loop
cfto_l:	move.l	d0,(A2)
	bra.s	cfto_loop

; * Convert variables to config file *

optionstoconfigfile:
	lea	configtable,a1
	lea	configfile,a0
otcf_loop:
	move.l	(a1)+,a2
	cmp.l	#0,a2
	beq.s	otcf_end
	move.l	(a1)+,d0
	cmp.l	#'long',d0
	beq.s	otcf_l
	cmp.l	#'word',d0
	beq.s	otcf_w
	move.b	(a2),d1
	ext.w	d1
	ext.l	d1
	move.l	d1,(a0)+
	bra.s	otcf_loop
otcf_end:
	rts
otcf_w:
	move.w	(a2),d1
	ext.l	d1
	move.l	d1,(a0)+
	bra.s	otcf_loop
otcf_l:
	move.l	(a2),(a0)+
	bra.s	otcf_loop

flon:	move.b	#1,flash_f
	rts
floff:	move.b	#0,flash_f
	rts

; * Convert ascii to value *

; a0 - ascii
; d0 - value

asciidoliczba:
	movem.l	a1/d1-d2,-(sp)
asloop:
	move.b	(a0)+,d0
	tst.b	d0
	beq.s	aserr
	cmp.b	#',',d0
	beq.s	aserr
	cmp.b	#'0',d0
	blt.s	asloop
	cmp.b	#'9',d0
	bgt.s	asloop
	suba.l	#1,a0
asloop2:
	move.b	(a0)+,d0
	tst.b	d0
	beq.s	aslicz
	cmp.b	#'0',d0
	blt.s	aslicz
	cmp.b	#'9',d0
	bgt.s	aslicz
	bra.s	asloop2
aslicz:	move.l	a0,-(sp)
	suba.l	#1,a0
	lea	mnozonko,a1
	clr.l	d0
	clr.l	d1
asconv:
	move.b	-(a0),d1
	cmp.b	#'-',d1
	beq.s	ascneg
	sub.b	#'0',d1
	tst.b	d1
	bmi.s	ascend
	cmp.b	#10,d1
	bge.s	ascend
	move.l	(a1)+,d2
	ext.w	d1
	ext.l	d1
	mulu	d1,d2
	add.l	d2,d0
	bra.s	asconv
ascend:	move.l	(sp)+,a0
asend:	movem.l	(sp)+,a1/d1-d2
	rts
aserr:	move.l	#$80000000,d0
	movem.l	(sp)+,a1/d1-d2
	rts
	
ascneg:	neg.l	d0
	bra.s	ascend

; a0 - value
; a1 - adresses table

conv:	
	move.l	(a0),d1
	lea	cyfry,a2
	lea	dzielonko,a3
	moveq.l	#5,d0
	move.l	#c0,(a1)
	cmp.l	#99999,d1
	ble.s	wlproc
	move.l	#c1,(a1)
wlproc:	add.l	#4,a1
	subq	#1,d0
c_loop:	move.l	d1,d2
	move.l	(a3)+,d3
	divu	d3,d2
	ext.l	d2
	tst.w	d2
	bne.s	nz
	move.l	#c0,(a1)+
	dbf	d0,c_loop
	rts

nz:	mulu	d2,d3
	asl.w	#2,d2
	move.l	(a2,d2.w),(a1)+
	sub.l	d3,d1
	dbf	d0,c_loop
	rts

; * Window on Workbench *
setwb:
	move.b	#1,workb
	rts
; * Window on other screen *
clrwb:
	clr.b	workb
	rts

; * Mono sound *
smono:	move.b	#1,sound
	clr.b	stereoflag
	rts
; * Stereo sound *
sstereo:
	move.b	#1,sound
	move.b	#1,stereoflag
	rts
; * No sound *
soff:
	move.b	#0,sound
	rts

; * Close gadget activated *
clon:	move.b	#0,closeflag1
	rts
; * Close gadget disactivated *
cloff:	move.b	#1,closeflag1
	rts
; * Mouse pointer visible *
mon:
	move.b	#0,offmouse1
	rts
; * Mouse pointer invisible *
moff:	move.b	#1,offmouse1
	rts

; * NOTHING *
nop:	rts

; * Interrupt routine *
IntProg:
	bsr.w	normsample
	movem.l	a0/a1/d0/d1/d2/d3/a6,-(sp)
	lea	timeval,a0
	move.l	(a0),d2
	move.l	4(a0),d3
	move.l	timerbase,a6
	jsr	_GetSysTime(a6)
	tst.l	d2
	bne.s	noinit
	tst.l	d3
	beq.s	init
noinit:
	sub.l	(a0),d2
	sub.l	4(a0),d3
	neg.l	d2
	neg.l	d3
	tst.l	d3
	bpl.s	nocarry
	add.l	#1000000,d3
	sub.l	#1,d2
nocarry:	
	tst.l	d2
	bne.s	init
	move.l	d2,secs
	move.l	d3,micros
init:
	movem.l	(sp)+,a0/a1/d0/d1/d2/d3/a6
	lea	$dff000,a6
	clr.l	d0
	rts

secs:	dc.l	0
micros:	dc.l	0

timeval:
	dc.l	0	;secs
	dc.l	0	;micros

rtAllocRequestA		=-30
rtFreeRequest		=-36
rtFreeReqBuffer		=-42
rtChangeReqAttrA	=-48
rtFileRequestA		=-54
rtFreeFileList		=-60
rtEZRequestA		=-66
rtGetStringA		=-72
rtGetLongA		=-78
rtInternalGetPasswordA	=-84
rtInternalEnterPasswordA=-90
rtFontRequestA		=-96
rtPaletteRequestA	=-102
rtReqHandlerA		=-108
rtSetWaitPointer	=-114
rtGetVScreenSize	=-120
rtSetReqPosition	=-126
rtSpread		=-132
rtScreenToFrontSafely	=-138

RT_FILEREQ		=0
RT_REQINFO		=1
RT_FONTREQ		=2
CALL_HANDLER		=$80000000

RT_TagBase		=$80000000
RT_Window		=(RT_TagBase+1)
RT_IDCMPFlags		=(RT_TagBase+2)
RT_ReqPos		=(RT_TagBase+3)
RT_LeftOffset		=(RT_TagBase+4)
RT_TopOffset		=(RT_TagBase+5)
RT_PubScrName		=(RT_TagBase+6)
RT_Screen		=(RT_TagBase+7)
RT_ReqHandler		=(RT_TagBase+8)
RT_DefaultFont		=(RT_TagBase+9)
RT_WaitPointer		=(RT_TagBase+10)
RTEZ_ReqTitle		=(RT_TagBase+20)
RTEZ_Flags		=(RT_TagBase+22)
RTEZ_DefaultResponse	=(RT_TagBase+23)
RTGL_Min		=(RT_TagBase+30)
RTGL_Max		=(RT_TagBase+31)
RTGL_Width		=(RT_TagBase+32)
RTGL_ShowDefault	=(RT_TagBase+33)
RTGS_Width		=RTGL_Width
RTGS_AllowEmpty		=(RT_TagBase+80)
RTFI_Flags		=(RT_TagBase+40)
RTFI_Height		=(RT_TagBase+41)
RTFI_OkText		=(RT_TagBase+42)
RTFO_Flags              =RTFI_FLAGS
RTFO_Height		=RTFI_Height
RTFO_OkText             =RTFI_OkText
RTFO_SampleHeight	=(RT_TagBase+60)
RTFO_MinHeight		=(RT_TagBase+61)
RTFO_MaxHeight		=(RT_TagBase+62)
RTFI_Dir		=(RT_TagBase+50)
RTFI_MatchPat		=(RT_TagBase+51)
RTFI_AddEntry		=(RT_TagBase+52)
RTFI_RemoveEntry	=(RT_TagBase+53)
RTFO_FontName		=(RT_TagBase+63)
RTFO_FontHeight		=(RT_TagBase+64)
RTFO_FontStyle		=(RT_TagBase+65)
RTFO_FontFlags		=(RT_TagBase+66)
RTPA_Color		=(RT_TagBase+70)
RTRH_EndRequest		=(RT_TagBase+60)

REQPOS_POINTER          =0
REQPOS_CENTERWIN        =1
REQPOS_CENTERSCR	=2
REQPOS_TOPLEFTWIN	=3
REQPOS_TOPLEFTSCR	=4
REQ_CANCEL		=0
REQ_OK			=1

FREQF_MULTISELECT	=$1
FREQF_SAVE		=$2
FREQF_NOBUFFER		=$4
FREQF_NOFILES		=$8
FREQF_PATGAD            =$10
FREQF_FIXEDWIDTH        =$20
FREQF_COLORFONTS	=$40
FREQF_CHANGEPALETTE	=$80
FREQF_LEAVEPALETTE	=$100
FREQF_SCALE		=$200
FREQF_STYLE		=$400
FREQF_DOWILDFUNC	=$800
FREQF_SELECTDIRS	=$1000

EZREQF_NORETURNKEY	=1
EZREQF_LAMIGAQUAL	=2
EZREQF_CENTERTEXT	=4

REQHOOK_WILDFILE	=0
REQHOOK_WILDFONT	=1


rtfis_ReqPos		=$00
rtfis_LeftOffset	=$04
rtfis_TopOffset		=$06
rtfis_Flags		=$08
rtfis_Hook		=$0C
rtfis_Dir		=$10
rtfis_MatchPat		=$14
rtfis_DefaultFont	=$18
rtfis_WaitPointer	=$1C

rtfos_ReqPos		=$00
rtfos_LeftOffset	=$04
rtfos_TopOffset		=$06
rtfos_Flags		=$08
rtfos_Hook		=$0C
rtfos_Attr		=$10
rtfos_DefaultFont	=$18
rtfos_WaitPointer	=$1C

rtfls_Next		=$00
rtfls_StrLen		=$04
rtfls_Name		=$08

MLN			=$00
h_Entry			=$08
h_SubEntry		=$0C
h_Data			=$10

exec			=4
oldoplib		=-408
closelib		=-414

OPENREQ
	MOVE.L	EXEC,A6
	LEA	REQNAME,A1
	JSR	OLDOPLIB(A6)
	MOVE.L	D0,REQBASE
	RTS
CLOSEREQ:
	MOVE.L	EXEC,A6
	MOVE.L	REQBASE,A1
	JSR	CLOSELIB(A6)
	rts

fileREQUEST:
	MOVE.L	REQBASE,A6
	MOVE.L	#rt_filereq,D0
	MOVE.L	#ZERO,A0
	JSR	rtAllocRequestA(A6)
	TST.L	D0
	BEq.W	error

	MOVE.L	D0,REQfile

	move.l	reqfile,A1
	lea	addtag,a0
	move.l	reqbase,a6
	jsr	rtchangereqattra(a6)
	move.l	reqfile,A1
	MOVE.L	#Nazwa,A2
	MOVE.L	#Tytul,A3
	MOVE.L	#TAGLIST,A0
	JSR	rtFileRequestA(A6)
;--------------------------------------------------------------;
	move.l	ReqFile,a0
	move.l	rtfis_Dir(a0),a0
	lea	string,a1
	lea	directory,a3
	move.b	(a0)+,d0
	move.b	d0,(a3)+
	tst.b	d0
	beq.s	req_nx
	move.b	d0,(a1)+
req_lop:
	move.b	(a0)+,d0
	move.b	d0,(a1)+
	move.b	d0,(a3)+
	tst.b	d0
	bne.s	req_lop
	subq	#1,a1
	cmp.b	#':',-1(a1)
	beq.s	req_nx
	move.b	#'/',(a1)+
req_nx:	move.b	(a2)+,d0
	move.b	d0,(a1)+
	tst.b	d0
	bne.s	req_nx
	bsr.b	freereq
	lea	string,a0
	rts

freereq:
	MOVE.L	REQfile,A1
	move.l	reqbase,a6
	JSR	rtFreeRequest(A6)
rtend	RTS


; a1 - buffer
; d0 - buffer size
; a2 - title

getstring:
	MOVE.L	REQBASE,A6	;!!! A6 !!! NIE UZYWAC
	move.l	#0,a3
	MOVE.L	#TAGLIST,A0
	JSR	rtGetStringA(A6)
	rts

;=========================
; RandomSeed(seed)
;             d0
;=========================
RandomSeed:
        ADD.L   D0,D1        ;   user seed in d0 (d1 too)
        MOVEM.L D0/D1,e_RND
; drops through to the main random function (not user callable)
LongRnd:
        MOVEM.L D1-D3,-(SP)
        MOVEM.L e_RND(pc),D0/D1    ;   D0=LSB's, D1=MSB's of random number
        ANDI.B  #$0E,D0      ;   ensure upper 59 bits are an...
        ORI.B   #$20,D0      ;   ...odd binary number
        MOVE.L  D0,D2
        MOVE.L  D1,D3
        ADD.L   D2,D2        ;   accounts for 1 of 17 left shifts
        ADDX.L  D3,D3        ;   [D2/D3] = RND*2
        ADD.L   D2,D0
        ADDX.L  D3,D1        ;   [D0/D1] = RND*3
        SWAP    D3           ;   shift [D2/D3] additional 16 times
        SWAP    D2
        MOVE.W  D2,D3
        CLR.W   D2
        ADD.L   D2,D0        ;   add to [D0/D1]
        ADDX.L  D3,D1
        MOVEM.L D0/D1,e_RND    ;   save for next time through
        MOVE.L  D1,D0        ;   most random part to D0
        MOVEM.L (SP)+,D1-D3
        RTS

e_RND:
	Dc.L    $87625342
	dc.l	$01847105            ;   random number

;******************************************************************
;***                          LEVELS                           ****
;******************************************************************

; 0-3: soft bricks from dark grey to light grey
; 4-7: soft bricks from dark blue to light blue
; a-d: hard bricks from dark grey to light grey
; e-h: hard bricks from dark blue to light blue

	section	levels,data

pl1:
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'0000000000'
	dc.b	'1111111111'
	dc.b	'2222222222'
	dc.b	'3333333333'
	dc.b	'4444444444'
	dc.b	'5555555555'
	dc.b	'6666666666'
	dc.b	'7777777777'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl2:
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	' 12344321 '
	dc.b	' 45677654 '
	dc.b	' 567ff765 '
	dc.b	' 567ff765 '
	dc.b	' 45677654 '
	dc.b	' 12344321 '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '

pl3:
	dc.b	'          '
	dc.b	'    00    '
	dc.b	'   0110   '
	dc.b	'   0110   '
	dc.b	'  011110  '
	dc.b	'  011110  '
	dc.b	' 022  220 '
	dc.b	' 0 f  f 0 '
	dc.b	' 0      0 '
	dc.b	' 0  bb  0 '
	dc.b	' 0      0 '
	dc.b	'  0d  d0  '
	dc.b	'  0 dd 0  '
	dc.b	'  01  10  '
	dc.b	'   0110   '
	dc.b	'    00    '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl4:
	dc.b	'          '
	dc.b	'76543210  '
	dc.b	'6543210   '
	dc.b	'543210    '
	dc.b	'43210     '
	dc.b	'3210      '
	dc.b	'210       '
	dc.b	'10        '
	dc.b	'0         '
	dc.b	'          '
	dc.b	'abcd  efgh'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '

pl5:
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	' 444444 a '
	dc.b	' 555555 b '
	dc.b	' 666666 c '
	dc.b	' 555555 d '
	dc.b	' 444444 e '
	dc.b	' 111111 f '
	dc.b	' 222222 g '
	dc.b	' 333333 a '
	dc.b	' 222222 b '
	dc.b	' 111111 c '
	dc.b	' 777777 d '
	dc.b	'        e '
	dc.b	'fffffffff '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '

pl6:
	dc.b	'7012345670'
	dc.b	'6  123  67'
	dc.b	'5 7 12 4 6'
	dc.b	'4 6 01 3 5'
	dc.b	'3 5 70 2 4'
	dc.b	'2 4 67 1 3'
	dc.b	'1  456  12'
	dc.b	'0 2345 701'
	dc.b	'7 1234 670'
	dc.b	'6 0123 567'
	dc.b	'5 7012 456'
	dc.b	'4567012345'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '

pl7:
	dc.b	'3   aa   4'
	dc.b	'23  dd  45'
	dc.b	'23  hh  45'
	dc.b	'123 ee 456'
	dc.b	'123    456'
	dc.b	'0123  4567'
	dc.b	'0123  4567'
	dc.b	' 01234567 '
	dc.b	' 01234567 '
	dc.b	'  012567  '
	dc.b	'  012567  '
	dc.b	'   0167   '
	dc.b	'   0167   '
	dc.b	'    07    '
	dc.b	'    07    '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '

pl8:
	dc.b	'00  11  22'
	dc.b	'00  11  22'
	dc.b	'00  11  22'
	dc.b	'  cc  aa  '
	dc.b	'  cc  aa  '
	dc.b	'  cc  aa  '
	dc.b	'33  44  55'
	dc.b	'33  44  55'
	dc.b	'33  44  55'
	dc.b	'  ff  dd  '
	dc.b	'  ff  dd  '
	dc.b	'  ff  dd  '
	dc.b	'66  77  00'
	dc.b	'66  77  00'
	dc.b	'66  77  00'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl9:
	dc.b	'00      aa'
	dc.b	'00      aa'
	dc.b	' 11       '
	dc.b	' 11       '
	dc.b	'  22      '
	dc.b	'  22      '
	dc.b	'   33     '
	dc.b	'   33     '
	dc.b	'    44    '
	dc.b	'    44    '
	dc.b	'     55   '
	dc.b	'     55   '
	dc.b	'      66  '
	dc.b	'      66  '
	dc.b	'       77 '
	dc.b	'       77 '
	dc.b	'aa      00'
	dc.b	'aa      00'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl10:
	dc.b	'6000000006'
	dc.b	'0        0'
	dc.b	'0 111111 0'
	dc.b	'0 12cc21 0'
	dc.b	'0 12cc21 0'
	dc.b	'0 111111 0'
	dc.b	'0        0'
	dc.b	'6000000006'
	dc.b	'          '
	dc.b	'7333333337'
	dc.b	'3        3'
	dc.b	'3 444444 3'
	dc.b	'3 45ff54 3'
	dc.b	'3 45ff54 3'
	dc.b	'3 444444 3'
	dc.b	'3        3'
	dc.b	'7333333337'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl11:
	dc.b	'ffffffffff'
	dc.b	'b        b'
	dc.b	'b        b'
	dc.b	'b0123210 b'
	dc.b	'bbbbbbbb1b'
	dc.b    'b        b'
	dc.b    'b        b'
	dc.b	'b 4567654b'
	dc.b	'b1bbbbbbbb'
	dc.b	'b        b'
	dc.b	'b        b'
	dc.b	'b0123210 b'
	dc.b	'bbbbbbbb1b'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl12:
	dc.b	'          '
	dc.b	'          '
	dc.b	' d d  d d '
	dc.b	' c c  c c '
	dc.b	' b7b  b7b '
	dc.b	' aaa  aaa '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'   d55d   '
	dc.b	'   c66c   '
	dc.b	'   b77b   '
	dc.b	'   aaaa   '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl13:
	dc.b	'          '
	dc.b	'    00    '
	dc.b	'   1111   '
	dc.b	'  112211  '
	dc.b	' 11222211 '
	dc.b	'1122332211'
	dc.b	'1234554321'
	dc.b	'4567007654'
	dc.b	'4567  7654'
	dc.b	'4567  7654'
	dc.b	'4567007654'
	dc.b	'1234554321'
	dc.b	'1122332211'
	dc.b	' 11222211 '
	dc.b	'  112211  '
	dc.b	'   1111   '
	dc.b	'    00    '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl14:
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	' aaaaeeee '
	dc.b	' a77ae33e '
	dc.b	' b66bf22f '
	dc.b	' c55cg11g '
	dc.b	' d44dh00h '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '

pl15:
	dc.b	'0101010101'
	dc.b	'1212121212'
	dc.b	'2323232323'
	dc.b	'3434343434'
	dc.b	'4545454545'
	dc.b	'5656565656'
	dc.b	'6767676767'
	dc.b	'0101010101'
	dc.b	'1212121212'
	dc.b	'2323232323'
	dc.b	'3434343434'
	dc.b	'4545454545'
	dc.b	'5656565656'
	dc.b	'6767676767'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl16:
	dc.b	'          '
	dc.b	'          '
	dc.b	'   a  a   '
	dc.b	'   a  a   '
	dc.b	'  aa  aa  '
	dc.b	'  aa  aa  '
	dc.b	' bbb  bbb '
	dc.b	' bbb11bbb '
	dc.b	' cc1221cc '
	dc.b	' c126621c '
	dc.b	' c126621c '
	dc.b	' ddd66ddd '
	dc.b	'  dddddd  '
	dc.b	'    dd    '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl17:
	dc.b	'0000000000'
	dc.b	'1111111111'
	dc.b	' cccccccc '
	dc.b	' cccccccc '
	dc.b	'3333333333'
	dc.b	'4444444444'
	dc.b	' ffffffff '
	dc.b	' ffffffff '
	dc.b	'6666666666'
	dc.b	'7777777777'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl18:
	dc.b	'          '
	dc.b	'4444444444'
	dc.b	'5555555555'
	dc.b	'          '
	dc.b	' aa  aaaa '
	dc.b	'bbb bb  bb'
	dc.b	' cc cc  cc'
	dc.b	' dd  dddd '
	dc.b	' ee ee  ee'
	dc.b	' ff ff  ff'
	dc.b	' gg  gggg '
	dc.b	'          '
	dc.b	'6666666666'
	dc.b	'7777777777'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl19:
	dc.b	'aaaaaaaaaa'
	dc.b	'aabbccbbaa'
	dc.b	'aabbccbbaa'
	dc.b	'aaaaaaaaaa'
	dc.b	'7777  7777'
	dc.b	'7777  7777'
	dc.b	'666    666'
	dc.b	'666    666'
	dc.b	'55      55'
	dc.b	'55      55'
	dc.b	'4        4'
	dc.b	'4        4'
	dc.b	'3        3'
	dc.b	'3        3'
	dc.b	'22      22'
	dc.b	'22      22'
	dc.b	'111    111'
	dc.b	'111    111'
	dc.b	'0000  0000'
	dc.b	'0000  0000'
pl20:
	dc.b	'0        1'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'    45    '
	dc.b	'    67    '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'2        3'
pl21:
	dc.b	'000111222 '
	dc.b	'0a01b12c2 '
	dc.b	'030141252 '
	dc.b	'3d34e45f5 '
	dc.b	'363474    '
	dc.b	'6g67h7    '
	dc.b	'666777    '
	dc.b	'    666777'
	dc.b	'    6g67h7'
	dc.b	'    363474'
	dc.b	' 3d34e45f5'
	dc.b	' 030141252'
	dc.b	' 0a01b12c2'
	dc.b	' 000111222'
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl22:
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'4a3b2c1d0e'
	dc.b	'  7f6g5h  '
	dc.b	'  7f6g5h  '
	dc.b	'  7f6g5h  '
	dc.b	'  7f6g5h  '
	dc.b	'  7f6g5h  '
	dc.b	'  7f6g5h  '
	dc.b	'  7f6g5h  '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl23:
	dc.b	'b         '
	dc.b	'b         '
	dc.b	'b1111111b '
	dc.b	'b1111111b '
	dc.b	'b1111111b '
	dc.b	'b1111111b '
	dc.b	'b1111111b '
	dc.b	'b1111111b '
	dc.b	'b1111111b '
	dc.b	'h777h777h '
	dc.b	'g666g666g '
	dc.b	'f555f555f '
	dc.b	'e444e444e '
	dc.b	'd333d333d '
	dc.b	'c222c222c '
	dc.b	'b1b1b1b1b '
	dc.b	'a0a0a0a0a '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl24:
	dc.b	'0        0'
	dc.b	'eeee  eeee'
	dc.b	'          '
	dc.b	' hhhhhhhh '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
	dc.b	'          '
pl25:
	dc.b	'0  0  0  0'
	dc.b	'1  1  1  1'
	dc.b	'2  2  2  2'
	dc.b	'3  3  3333'
	dc.b	'4  4  4444'
	dc.b	'5  5  5  5'
	dc.b	'6666  6  6'
	dc.b	' 77   7  7'
	dc.b	'          '
	dc.b	'    aa    '
	dc.b	'    bb    '
	dc.b	'    cc    '
	dc.b	'    dd    '
	dc.b	'    ee    '
	dc.b	'    ff    '
	dc.b	'          '
	dc.b	'          '
	dc.b	'    gg    '
	dc.b	'    hh    '
	dc.b	'          '
	dc.b	'          '

; *******************************************

	section datas,data

colors:
	dc.w	$AAA,$000,$fff,$68b

; * Options *

; dc.l    Gadget address, routine address

MenuOptions:
	dc.l	g_options,m_options
	dc.l	g_about,m_about
	dc.l	g_JUMP,m_JUMP
	dc.l	0

	even

actscreen:
	dc.l	0			; actual screen address

textattr:
	dc.l	topazfont		; font
	dc.w	8
	dc.b	0
	dc.b	0

level:
	dc.b	0			; level number

	even

tabpos:
	dc.l	0

	even

g_goback:
	dc.b	1,6,10,'GO BACK',0
waitframe:
	dc.b	1

	even

topazfont:
	dc.b	'topaz.font',0		; font name

hitext:
	dc.b	'    Name                            Score Level Stage'
hitextend:

	even

hiscorefile:
	dc.b	'S:MiniArcanoidHiScoreTable',0

	even

alwayszero:
	dc.l	0

optionstab:
; .l -> .l

	dc.l	jspeed,g_joyspeed
	dc.l	0

; .w -> .l

	dc.l	scr_x,g_scrx,scr_y,g_scry
	dc.l	scr_sizex,g_scrsx,scr_sizey,g_scrsy
	dc.l	scr_sizex,lastscrsx,scr_sizey,lastscrsy
	dc.l	volume,g_vol
	dc.l	mix,g_mixval
	dc.l	win_sizex,g_scrsxmin
	dc.l	win_sizey,g_scrsymin
	dc.l	0

; .b -> .l

	dc.l	0

; .l -> option

	dc.l	0

; .w -> option

	dc.l	0

; .b -> option

	dc.l	workb,1,g_scrtype,g_workbench
	dc.l	workb,0,g_scrtype,g_custom
	dc.l	flash_f,1,g_flash,g_flashscr
	dc.l	flash_f,0,g_flash,g_noflash
	dc.l	sound,1,g_soundop,g_mono
	dc.l	sound,1,g_soundop,g_stereo
	dc.l	stereoflag,0,g_soundop,g_mono
	dc.l	stereoflag,1,g_soundop,g_stereo
	dc.l	sound,0,g_soundop,g_soff
	dc.l	closeflag1,0,g_close,g_activated
	dc.l	closeflag1,1,g_close,g_disactivated
	dc.l	offmouse1,0,g_mouse,g_on
	dc.l	offmouse1,1,g_mouse,g_off
	dc.l	prisig,0,g_prisig,g_plus
	dc.l	prisig,1,g_prisig,g_minus
	dc.l	hardware,0,g_scrop,g_system
	dc.l	hardware,1,g_scrop,g_hardware
	dc.l	savemode,0,g_savemode,g_ingame
	dc.l	savemode,1,g_savemode,g_onexit
	dc.l	savemode,2,g_savemode,g_manual
	dc.l	saveask,0,g_saveask,g_dontask
	dc.l	saveask,1,g_saveask,g_ask
	dc.l	autopauseflag,0,g_autopause,g_on
	dc.l	autopauseflag,1,g_autopause,g_off
	dc.l	0

workb:
	dc.b	1
prisig:
	dc.b	0
hardware:
	dc.b	0
savemode:
	dc.b	0
saveask:
	dc.b	0
intver:
	dc.b	36
autopauseflag:
	dc.b	0

	even

g_minx:	dc.l	0
g_miny:	dc.l	0
g_maxx:	dc.l	0
g_maxy:	dc.l	0

configname:
	dc.b	'S:MiniArcanoid.config',0

configtable:
	dc.l	jspeed,'long'
	dc.l	g_pri,'long'
	dc.l	win_x,'word'
	dc.l	win_y,'word'
	dc.l	scr_x,'word'
	dc.l	scr_y,'word'
	dc.l	scr_sizex,'word'
	dc.l	scr_sizey,'word'
	dc.l	volume,'word'
	dc.l	mix,'word'
	dc.l	prisig,'byte'
	dc.l	sound,'byte'
	dc.l	stereoflag,'byte'
	dc.l	closeflag1,'byte'
	dc.l	offmouse1,'byte'
	dc.l	empty,'byte'
	dc.l	workb,'byte'
	dc.l	flash_f,'byte'
	dc.l	hardware,'byte'
	dc.l	savemode,'byte'
	dc.l	saveask,'byte'
	dc.l	autopauseflag,'byte'
	dc.l	0

empty:
	dc.l	0

conftend:

opmove	equ	2

; * OPTIONS GADGETS *

optionsgad:
	dc.l	1,4,13-opmove,3*8+4,10,g_use,0,0,$80000000
	dc.l	1,265+8,13-opmove,4*8+4,10,g_save,0,0,$80000000
	dc.l	1,104+4-10,13-opmove,21,11,0,g_up,g_uppressed,$80000000
	dc.l	1,184+4-10,13-opmove,21,11,0,g_down,g_downpressed,$80000000

; at y pos - change from last value (it starts at 0)

thisgads:

; line -2

	dc.l	5,113
gadsposy:
	dc.l	-2,g_gameoptions,$80000000

; next line
	dc.l	5,4,2,g_priority,$80000000
	dc.l	2,20*8+4,0,4*8+4,10
g_pri:	dc.l	10,0,127,$80000000
	dc.l	3,18*8+4,0,1*8+4,10
g_prisig:
	dc.l	g_plus,g_plus,g_minus,0,$80000000

; next line

	dc.l	5,4,2,g_winpos,$80000000
	dc.l	1,18*8+4,0,6*8+4,10,g_center1,0,0,$80000000
	dc.l	1,25*8+4,0,6*8+4,10,g_center2,0,0,$80000000

; next line

	dc.l	5,4,1,g_screenpos,$80000000
	dc.l	2,18*8+4,0,4*8+4,10
g_scrx:	dc.l	0,0,999,$80000000
	dc.l	2,23*8+4,0,4*8+4,10
g_scry:	dc.l	0,0,999,$80000000

; next line

	dc.l	5,4,1,g_screensize,$80000000
	dc.l	2,18*8+4,0,4*8+4,10
g_scrsx:
	dc.l	0
g_scrsxmin:
	dc.l	0,640,$80000000
	dc.l	2,23*8+4,0,4*8+4,10
g_scrsy:
	dc.l	0
g_scrsymin:
	dc.l	0,256,$80000000

; next line

	dc.l	1,35*8,1,4*8+4,10,g_see,0,0,$80000000
	dc.l	5,4,0,g_screentype,$80000000
	dc.l	3,18*8+4,0,9*8+4,10
g_scrtype:
	dc.l	g_workbench,g_workbench,g_custom,0,$80000000

; next line

	dc.l	5,4,1,g_whenerror,$80000000
	dc.l	3,18*8+4,0,12*8+4,10
g_flash:
	dc.l	g_flashscr,g_flashscr,g_noflash,0,$80000000

; next line

	dc.l	5,4,1,g_sound,$80000000
	dc.l	3,18*8+4,0,6*8+4,10
g_soundop:
	dc.l	g_stereo,g_soff,g_mono,g_stereo,0,$80000000
; next line

	dc.l	5,4,1,g_volume,$80000000
	dc.l	2,18*8+4,0,3*8+4,10
g_vol:	dc.l	0,0,64,$80000000

; next line

	dc.l	5,4,1,g_mix,$80000000
	dc.l	2,18*8+4,0,4*8+4,10
g_mixval:
	dc.l	0,0,100,$80000000	

; next line

	dc.l	5,4,1,g_autopausetxt,$80000000
	dc.l	3,18*8+4,0,3*8+4,10
g_autopause:
	dc.l	g_on,g_on,g_off,0,$80000000


; next line

	dc.l	5,4,1,g_while,$80000000

; next line

	dc.l	5,4,1,g_closegad,$80000000
	dc.l	3,27*8+4,0,12*8+2,10
g_close:
	dc.l	g_activated,g_activated,g_disactivated,0,$80000000

; next line

	dc.l	5,4,1,g_andmouse,$80000000
	dc.l	3,27*8+4,0,3*8+4,10
g_mouse:
	dc.l	g_off,g_on,g_off,0,$80000000

; next line
	dc.l	5,4,1,g_screenop,$80000000
	dc.l	3,27*8+4,0,6*8+4,10
g_scrop:
	dc.l	g_system,g_system,g_hardware,0,$80000000

; next line

	dc.l	5,4,1,g_joysen,$80000000
	dc.l	2,27*8+4,0,3*8+4,10
g_joyspeed:
	dc.l	0,-99,99,$80000000

; next line

	dc.l	5,4,2,g_hiscore,$80000000
	dc.l	1,12*8+4,0,5*8+4,10,g_clear,0,0,$80000000
	dc.l	1,18*8+4,0,4*8+4,10,g_join,0,0,$80000000
	dc.l	1,23*8+4,0,4*8+4,10,g_show,0,0,$80000000
	dc.l	1,28*8+4,0,4*8+4,10,g_hload,0,0,$80000000
	dc.l	1,33*8+4,0,4*8+4,10,g_hsave,0,0,$80000000

; next line

	dc.l	5,4,1,g_hisave,$80000000
	dc.l	3,12*8+4,0,7*8+4,10
g_savemode:
	dc.l	g_ingame,g_ingame,g_onexit,g_manual,0,$80000000
	dc.l	3,20*8+4,0,9*8+4,10
g_saveask:
	dc.l	g_dontask,g_ask,g_dontask,0,$80000000

cheatgads:
	dc.l	0      ; <- This should be 5 in cheat mode

; next line
; cheat mode gadgets

	dc.l	4,3,g_lives,$80000000
	dc.l	2,10*8+4
livy:	dc.l	0,3*8+4,10
g_liv:	dc.l	3,0,99,$80000000

	dc.l	5,20*8+4,0,g_level,$80000000
	dc.l	2,30*8+4
levy:	dc.l	0,3*8+4,10
g_lev:	dc.l	1,1,25,$80000000

; next line

	dc.l	5,4,1,g_stage,$80000000
	dc.l	2,10*8+4
stgy:	dc.l	0,3*8+4,10
g_stg:	dc.l	1,1,3,$80000000

	dc.l	5,20*8+4,0,g_points,$80000000
	dc.l	2,30*8+4
ptsy:	dc.l	0,6*8+4,10
g_pts:	dc.l	0,0,30000,$80000000
	dc.l	0

;	dc.b	color,x,y,'text',0

g_autopausetxt:
	dc.b	2,6,8,'Auto pause:',0
g_hiscore:
	dc.b	2,6,8,'Hiscores:',0
g_hisave:
	dc.b	2,6,8,'    save:',0
g_ingame:
	dc.b	1,6,8,'IN GAME',0
g_onexit:
	dc.b	1,6,8,'ON EXIT',0
g_manual:
	dc.b	1,10,8,'MANUAL',0
g_ask:
	dc.b	1,6,8,'   ASK',0
g_dontask:
	dc.b	1,6,8,"DON'T ASK",0
g_clear:
	dc.b	1,6,8,'CLEAR',0
g_join:
	dc.b	1,6,8,'JOIN',0
g_hsave:
	dc.b	1,6,8,'SAVE',0
g_hload:
	dc.b	1,6,8,'LOAD',0
g_show:
	dc.b	1,6,8,'SHOW',0
g_screenop:
	dc.b	2,6,8,'Screen rendering:',0
g_hardware:
	dc.b	1,6,8,'DIRECT',0
g_system:
	dc.b	1,6,8,'SYSTEM',0
g_plus:
	dc.b	1,6,8,'+',0
g_minus:
	dc.b	1,6,8,'-',0
g_priority:
	dc.b	2,6,8,'Priority:',0
g_flashscr:
	dc.b	1,6,8,'FLASH SCREEN',0
g_noflash:
	dc.b	1,10,8,"DON'T FLASH",0
g_use:
	dc.b	1,6,8,'USE',0
g_save:
	dc.b	1,6,8,'SAVE',0
g_gameoptions:
	dc.b	2,6,8,'Game options',0
g_volume:
	dc.b	2,6,8,'Sound volume:',0
g_mix:
	dc.b	2,6,8,'Channel mixing:        %',0
g_see:
	dc.b	1,6,8,'TEST',0
g_stereo:
	dc.b	1,6,8,'STEREO',0
g_mono:
	dc.b	1,6,8,' MONO ',0
g_soff:
	dc.b	1,10,8,' OFF',0
g_workbench:
	dc.b	1,6,8,'WORKBENCH',0
g_custom:
	dc.b	1,10,8,' CUSTOM',0
g_1:
	dc.b	1,6,8,'1',0
g_2:
	dc.b	1,6,8,'2',0
g_valx:
	dc.b	1,6,8,' 0000',0
g_valy:
	dc.b	1,6,8,' 0000',0
g_center1:
	dc.b	1,6,8,'X AXIS',0
g_center2:
	dc.b	1,6,8,'Y AXIS',0
g_screenpos:
	dc.b	2,6,8,'Screen position:',0
g_winpos:
	dc.b	2,6,8,'Centre window:',0
g_screensize:
	dc.b	2,6,8,'Screen size:',0
g_whenerror:
	dc.b	2,6,8,'At error:',0
g_screentype:
	dc.b	2,6,8,'Screen type:',0
g_while:
	dc.b	2,6,8,'While playing',0
g_closegad:
	dc.b	2,6,8,'       the close gadget is ',0
g_andmouse:
	dc.b	2,6,8,'  and the mouse pointer is     .',0
g_joysen:
	dc.b	2,6,8,'Joystick sensitivity:',0
g_sound:
	dc.b	2,6,8,'Sound:',0
g_disactivated:
	dc.b	1,6,8,'DISACTIVATED',0
g_activated:
	dc.b	1,10,8,' ACTIVATED',0
g_off:
	dc.b	1,6,8,'OFF',0
g_on:
	dc.b	1,10,8,'ON',0
g_ok:	dc.b	1,6,8,'OK',0
g_cancel:
	dc.b	1,6,8,'CANCEL',0
g_val:
	dc.b	1,5,7
g_valtext:
	blk.b	100,32
g_lives:
	dc.b	2,6,8,'LIVES: ',0
g_level:
	dc.b	2,6,8,'LEVEL: ',0
g_stage:
	dc.b	2,6,8,'STAGE: ',0
g_points:
	dc.b	2,6,8,'POINTS:',0

	even

; ************************** LETTERS *******************************

litery:
	dc.l	lb,lb,lb,lb
	dc.l	le
	dc.l	ls,ls,ls,ls,ls,ls,ls,ls
	dc.l	lh,lh,lh,lh
	dc.l	ln,ln,ln
	dc.l	lk,lk,lk,lk,lk,lk,lk,lk
	dc.l	lpyt,lpyt,lpyt,lpyt,lpyt,lpyt,lpyt,lpyt
	dc.l	lpyt,lpyt,lpyt,lpyt
lit_end:
	ds.b	1024-(lit_end-litery)

;*******************************************************************

sample1:
	dc.b	"stick.snd",0 ; stick
sample2:
	dc.b	"hardbrick.snd",0 ; hard brick
sample3:
	dc.b	"lost.snd",0 ; lost ball
sample4:
	dc.b	"letter.snd",0 ; catch letter
sample5:
	dc.b	"brick.snd",0 ; brick
sample6:
	dc.b	"applause.snd",0 ; hiscore entry
sample7:
	dc.b	"tiltwarning.snd",0
sample8:
	dc.b	"tilt.snd",0
	even

samples:
	dc.l	sample1
	dc.l	sample2
	dc.l	sample3
	dc.l	sample4
	dc.l	sample5
	dc.l	sample6
	dc.l	sample7
	dc.l	sample8
	dc.l	-1

samtable:

; adress.l rate.w len.w

sam1:	ds.w	4
sam2:	ds.w	4
sam3:	ds.w	4
sam4:	ds.w	4
sam5:	ds.w	4
sam6:	ds.w	4
sam7:	ds.w	4
sam8:	ds.w	4

;******************************************************************

; * LEVEl TABLE *

pltab:	dc.l	pl1,pl2,pl3,pl4,pl5,pl6,pl7,pl8,pl9,pl10,pl11,pl12
	dc.l	pl13,pl14,pl15,pl16,pl17,pl18,pl19,pl20
	dc.l	pl21,pl22,pl23,pl24,pl25,0

stereoflag:
	dc.b	1	;TRUE
closeflag1:
	dc.b	1
closeflag2:
	dc.b	0

	even

znaczniczek:
	dc.w	0
oldgadsposy:
	dc.l	0

cyfra:	ds.l	6


; * Bonus lives *
bonusy:
	dc.l	2000,4000
	dc.l	6000,8000,10000,12000,14000,16000,18000
	dc.l	20000,25000,30000,35000,40000,45000,50000
	dc.l	$7fffffff

bonusyadr:
	dc.l	bonusy

xp:	dc.l	0
yp:	dc.l	0

rastport:
	dc.l	0
cgfxflag:
	dc.l	0

	
intname:
	dc.b	'intuition.library',0
	even
intbase:
	dc.l	0
dosname:
	dc.b	'dos.library',0
	even
dosbase:
	dc.l	0
currentdir:
	dc.l	0
gfxname:
	dc.b	'graphics.library',0
cgfxname:
	dc.b	'cybergraphics.library',0
	even
gfxbase:
	dc.l	0
staty:	dc.l	177

; * New window structure *

newwindow:
win_x:	dc.w	-1
win_y:	dc.w	-1
win_sizex:
	dc.w	WinSizeX
win_sizey:
	dc.w	WinSizeY
	dc.b	0
	dc.b	1
win_idcmpflags:
	dc.l	512+8+$2000000+$200000+$400
win_flags:
	dc.l	2+4+8+$10000
	dc.l	0
	dc.l	0
win_title:
	dc.l	WINNAME
win_screen:
	dc.l	0
	dc.l	0
win_minsizex:
	dc.w	0
win_minsizey:
	dc.w	0
win_maxsizex:
	dc.w	463
win_maxsizey:
	dc.w	10
win_type:
	dc.w	1

window:	dc.l	0

winname:
	dc.b	'MiniArcanoid v2.9a. All work done by PP/UNION.    ',0

	dc.b	'$VER: MiniArcanoid 2.9a (07.07.98)',0

	even
x:	dc.l	$a00000
y:	dc.l	$960000
kx:	dc.l	$010000
ky:	dc.l	$FFFf0000

; * Bricks table *

tablicaklockow:
	dc.l	kl1,kl2,kl3,kl4,kl5,kl6,kl7,kl8
	dc.l	tkl1,tkl2,tkl3,tkl4,tkl5,tkl6,tkl7,tkl8

kursor:	dc.l	$00000000

; * New screen structure *

newscreen:
scr_x:	dc.w	88
scr_y:	dc.w	0
scr_sizex:
	dc.w	464
scr_sizey:
	dc.w	212
	dc.w	2
	dc.b	0,1
	dc.w	$8000
	dc.w	$f
screen_font:
	dc.l	0
	dc.l	screentitle
	dc.l	0
	dc.l	0

screentitle:
	dc.b	'Mini Arcanoid Screen',0

	even

cyfry:	dc.l	c0,c1,c2,c3,c4,c5,c6,c7,c8,c9

dzielonko:
	dc.l	10000,1000,100,10,1
mnozonko:
	dc.l	1,10,100,1000,10000

lastxpos:
	dc.w	-10000
lastypos:
	dc.w	-10000
lastscrx:
	dc.l	-10000
lastscry:
	dc.l	-10000
lastscrsx:
	dc.l	-10000
lastscrsy:
	dc.l	-10000

winerrtext:
	dc.b	'         Cannot open window !',10
	dc.b	'Not enough memory or too small screen.'
	dc.b	0

	even

cheatmodetxt:
	dc.b	' Sorry, but scores saving',10
	dc.b	'is disabled in cheat mode!',0

writescoresask:
	dc.b	'Do you want to save hiscores ?',0

	even

retryquitgad:
	dc.l	1,0,0,5*8+4,10,g_retry,0,0,$80000000
	dc.l	1,0,0,4*8+4,10,g_quit,0,0,$80000000
	dc.l	0

g_quit:
	dc.b	1,6,8,'QUIT',0
g_retry:
	dc.b	1,6,8,'RETRY',0

	even

flash_f:
	dc.b	1

	even

kol:	dc.l	0
sxp:	dc.l	0

speed:	dc.b	2
	even
licznik:
	dc.w	0

scrolladr:
	dc.l	0
pustalinia:
	dc.b	'                                        '

mianim:	dc.l	mi1,mi2,mi3,mi4,mi5,mi6,mi5,mi4,0

	even

atext:	dc.b	"MiniArcanoid version 2.9a",10
	dc.b	"written by Piotr Pawlow (PP/UNION)",10
	dc.b	10
	dc.b	"A little Arkanoid clone for the Workbench",10
	dc.b	10
	dc.b	10
	dc.b	"If you want to contact me, write to:",10
	dc.b	10
	dc.b	"Piotr Pawlow",10
	dc.b	"ul.Lewartowskiego 12 m 46",10
	dc.b	"00-185 Warszawa",10
	dc.b	"Poland",10
	dc.b	10
	dc.b	"EMail: pp@cs.com.pl",10
	dc.b	10
	dc.b	10
	dc.b	"For more info read the documentation"
	dc.b	0

chartable:
	blk.b	33,42	; 32
	dc.b	26,42,42,42,42,42,46,41,43,49,45,39,40,38,48 ;47
	dc.b	37,28,29,30,31,32,33,34,35,36 ; 57
	dc.b	44,42,42,42,42 ; 62
	dc.b	27,42 ; 64
	dc.b	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ; 79
	dc.b	16,17,18,19,20,21,22,23,24,25 ; 90
	blk.b	103,42 ; 193
	dc.b	47 ; 194
	blk.b	61,42 ; 255


	even

cheattxtadr:
	dc.l	cheattxt

cheattxt:
	dc.b	"I'm your Master.",0

cheatontxt:
	dc.b	-2,2
	dc.b	'  WELCOME MY LORD !    YOUR WISH IS MY COMMAND.  '
	dc.b	'                                        '
	dc.b	'                                        '
	dc.b	0
alllev:
	dc.b	-2,2
	dc.b	'  CONGRATULATIONS !   YOU CLEARED ALL LEVELS.  '
	dc.b	'NOW BUILD IT !'
	dc.b	'                                        '
	dc.b	'                                        '
	dc.b	0
alllev2:
	dc.b	-2,2
	dc.b	'  CONGRATULATIONS !   YOU DONE IT AGAIN !   '
	dc.b	'NOW MORE INVISIBLE BRICKS.'
	dc.b	'                                        '
	dc.b	'                                        '
	dc.b	0
won:
	dc.b	-2,2
	dc.b	'  CONGRATULATIONS!    YOU WON !              '
	dc.b	'                                        '
	dc.b	'                                        '
	dc.b	0


prefire:
	dc.b	-2,8,' PRESS FIRE OR LEFT MOUSE BUTTON   '
	blk.b	200,-1
	dc.b	-2,2
	dc.b	'     THIS GAME IS IN 100 PERCENT PURE ASSEMBLER CODE, '
	DC.B	"IT'S WRITTEN AND ASSEMBLED IN TRASH'M-ONE.  "
	dc.b	'                                       '
	dc.b	-2,8
	DC.B	"   GREETS FLY TO:                                     "
	dc.b	-2,2
	DC.B	" IREK P, KULFON, HALI, TOM, SNOOPY, MR ROOT, DOCENT,"
	dc.b	" AND EVERYONE WE HAVE FORGOTTEN...       PC SUXX!"
	DC.B	"         ENJOY !                          "
	DC.B	0

	even

PAUSE:		DC.B    '          *** GAME PAUSED ***           '
XTRA:		DC.B	'              EXTRA BALL!               '
BONUS:		DC.B	'            BONUS - 50 PTS.             '
LOST:		DC.B	'              WATCH OUT !               '
NEXTL:		DC.B	'             NEXT LEVEL...              '
SHIT:		DC.B	'               OH, SHIT!                '
MIS:		DC.B	"                SUCKER!                 "
GOOD:		DC.B	'              GOOD WORK !               '
CUP:		DC.B	'         NEXT LEVEL COMING UP...        '
YEAH:		DC.B	'                 YEAH!                  '
OVER:		DC.B	'            !! GAME OVER !!             '
BYE:		DC.B	'                 BYE !                  '
SLDOWN:		DC.B	'               SLOW DOWN                '
GLU:		DC.B	'                 GLUE                   '
NOTHING:	DC.B	'                NOTHING                 '
HARACT:		DC.B	'          HARD BALL ACTIVATED           '
tiltwtxt:	DC.B	'            TILT WARNING !!!            '
tilttxt:	DC.B	'              *** TILT ***              '
trzyextra:	DC.B	'            EXTRA 3 BALLS !             '          

	EVEN

screrrtext:
	dc.b	'Cannot open custom screen!',10
	dc.b	'Select RETRY to try again,',10
	dc.b	' or CANCEL to open on WB.'
	dc.b	0

	even

retrycancelgad:
	dc.l	1,0,0,5*8+4,10,g_retry,0,0,$80000000
	dc.l	1,0,0,6*8+4,10,g_cancel,0,0,$80000000
	dc.l	0

gadgetlist:
	dc.l	4,329,125,119,58,$80000000
	dc.l	1,342,130,92,10,g_start,0,0,$80000000
	dc.l	1,342,142,92,10,g_options,0,0,$80000000
	dc.l	1,342,154,92,10,g_jump,0,0,$80000000
	dc.l	1,342,166,92,10,g_about,0,0,$80000000
	dc.l	0


g_start:
	dc.b	1,6,8,'   START',0
g_options:
	dc.b	1,6,8,'  OPTIONS',0
g_jump:
	dc.b	1,6,8,'  JUMP TO',0
g_about:
	dc.b	1,6,8,'   ABOUT',0

Namegads:
	dc.l	8,4,5,30*8+4,11,imie,$80000000
	dc.l	1,101,20,6*8+4,11,g_cancel,0,0,$80000000
	dc.l	0

sg_zero:
	dc.b	0
sg_jeden:
	dc.b	1

lastbaton:
	dc.b	1

	even

specialgadgets:
	dc.l	g_ok,20,g_use,20,g_save,20,g_up,24,g_down,24
	dc.l	g_retry,20,g_cancel,20,g_quit,20
	dc.l	g_reqyes,20,g_reqno,20
	dc.l	0,0

cursminx:
	dc.l	0
cursmaxx:
	dc.l	0
cursx:	dc.l	0
cursy:	dc.l	0
stringflag:
	dc.b	0

	even

g_letter:
	dc.b	1,6-2,8-2

g_lettertext:
	dc.b	0,0

	even

valadr:
	dc.l	0
val:
	dc.l	0
valmin:
	dc.l	0
valmax:
	dc.l	0
curspos:
	dc.l	0	; cursor position in string gadget
strlen:
	dc.l	0	; length of string gadget
howmanychars:
	dc.l	0	; length of text in string gadget

gadfunctable:
	dc.l	3,invertfr,invertfr,normalfr,switchgad
	dc.l	1,invertgad,invertonoff,normalgad,selgad
	dc.l	2,putcursor,gad_nop,gad_nop,gad_nop
	dc.l	8,putcursor2,gad_nop,gad_nop,gad_nop
	dc.l	0

bitmapstruct:
szer:	dc.w	2
wys:	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
adres1b:
	dc.l	0
adres2b:
	dc.l	0

tmpbitmap:
	dc.l	0

poleramka:
tu1:	dc.w	0
tam1:	dc.w	0
col1:	dc.b	2,0
	dc.b	0
	dc.b	3
	dc.l	tab1
	dc.l	poleramka2
poleramka2:
tu2:	dc.w	0
tam2:	dc.w	0
col2:	dc.b	1,0
	dc.b	0
	dc.b	3
	dc.l	tab2
	dc.l	0

tab1:
	ds.w	6
tab2:
	ds.w	6

	even

klej:	dc.w	0

cowylosowane:
	blk.b	4,1		;live
	blk.b	60,2		;slow down
	blk.b	22,3		;bonus
	blk.b	8,4		;next level
	blk.b	60,5		;glue
	blk.b	15,6		;hard ball
wylos_end:
	ds.b	256-(wylos_end-cowylosowane)
				;nothing

	even

hard:	dc.w	0

notifftext:
	dc.b	'Not an IFF sample !'
	dc.b	0

	even

okgad:	dc.l	1,0,0,2*8+4,10,g_ok,0,0,$80000000
	dc.l	0

offmouse1:
	dc.b	1
offmouse2:
	dc.b	0
pointerflag:
	dc.b	1

	even

channeltableadr:
	dc.l	channeltable+4
channeltable:
	dc.w	$a0,1,$b0,2,$d0,8,$c0,4,0

volume:	dc.w	64

sound:	dc.b	1

	even

spectrum:
	dc.l	320
position:
	dc.l	0
mix:
	dc.w	5

mouse:	dc.w	0

pointerchanges:
	dc.b	0

	even

firestat:
	dc.w	0

rnd:	dc.w	0

punkty:	dc.l	0
czas:	dc.l	0
nrpl:	dc.l	0
zycia:	dc.l	0
ilkloc:	dc.l	0
scr:	dc.l	0
wbmsg:	dc.l	0
stack:	dc.l	0
adrl:	dc.l	0
xl:	dc.l	0
yl:	dc.l	0

xe:	dc.l	0
ye:	dc.l	0

h:	dc.l	0

myinterrupt:

; * Node

	dc.l	0	; Succ
	dc.l	0	; Prev
	dc.b	5	; Type
	dc.b	0	; Pri
	dc.l	IName	; Name

	dc.l	0	; is_Data
	dc.l	IntProg	; is_Code

IName:
	dc.b	'MA Interrupt',0


portname:
	dc.b	'MA Port',0

InputDevName:
	dc.b	'input.device',0
	even
TimerDevName:
	dc.b	'timer.device',0
	even

InputInterrupt:
	dc.l	0,0
	dc.b	2,52		
	dc.l	InputInterruptName,0,InputHandler
InputInterruptName:
	dc.b	'MA mouse reader',0
	even

quittext:
	dc.b	'Do you really want to quit ?'
	dc.b	0

	even

yesnogad:
	dc.l	1,0,0,3*8+4,10,g_reqyes,0,0,$80000000
	dc.l	1,0,0,2*8+4,10,g_reqno,0,0,$80000000
	dc.l	0

g_reqyes:
	dc.b	1,6,8,'YES',0
g_reqno:
	dc.b	1,6,8,'NO',0

	even

rawkey:	dc.w	0

segment:
	dc.l	0
cos:	dc.l	0
key:	dc.w	0

drag:	dc.w	0
drag_x:
	dc.w	0
drag_y:
	dc.w	0
mousebutton:
	dc.w	1
xmousepos:
	dc.w	0

wysw_czas:
	dc.l	0
liniaadr:
	dc.l	0

pomoctable:
	ds.b	21

	even

addy:	dc.w	0



; * Random messages *
lbtable:
	dc.l	shit,lost,mis,bye
nltable:
	dc.l	NEXTL,GOOD,CUP,YEAH



fun:	dc.b	'Have some fun !',0

	even

sleep:	dc.b	"*** I'm sleeping ! ***",0

	even

defwindow:
	ds.b	60
reqwindow:
	ds.b	60

	dc.b	0
imie:	ds.b	29
imie_end:
	dc.b	0

	even

	dc.l	$7fffffff
table:
scores:	ds.l	11
names:	blk.b	330,32
levels:	ds.l	11
stages:	ds.l	11
endoftable:

table2:
	ds.l	11
	blk.b	330,32
	ds.l	11
	ds.l	11

imieadr:
	dc.l	0
imieendadr:
	dc.l	0
imielen:
	dc.l	0
textx:
	dc.l	0
texty:
	dc.l	0

nr:	dc.l	0

valbuf:
	blk.b	6,32

kropka:
	dc.b	'.'

hi:
	dc.b	'Hiscore table.',0

	even

alloctableadr:
	dc.l	alloctable
fileinfoadr:
	dc.l	0

filesize:
	dc.l	0

allerrtext:
	dc.b	'       Not enough memory.',10
	dc.b	'Free some and select RETRY.'
	dc.b	0

REALstring:
	dc.b	0

	even

buf:
	dc.l	0
filename:
	dc.l	0
len:
	dc.l	0
newlen:
	dc.l	0
tempaddr:
	dc.l	0
actaddr:
	dc.l	0
newsize:
	dc.l	0
bodyadr:
	dc.l	0
al_size:
	dc.l	0
al_req:
	dc.l	0

reqtoolserr:
	dc.b	'reqtools.library not found !',0

wrongpassword:
	dc.b	'Wrong password !',10
	dc.b	0
unknownpp:
	dc.b	'File is packed with unknown',10
	dc.b	' version of Power Packer !',10
	dc.b	0
areyousure:
	dc.b	'Are You sure ?',0

sampleloaded:
	dc.b	0

ppname:
	dc.b	'powerpacker.library',0

	even

ppbase:
	dc.l	0

enter:
	dc.b	'Enter Your name.',0
	even

lock:	dc.l	0

selscr:
	dc.b	'Select screen...',0

	even

tit_req:
	dc.b	'Info...',0

	even

scrollspeed:
	dc.l	0

scrolltemp:
	dc.l	0
minxtemp:
	dc.l	0
minytemp:
	dc.l	0
maxxtemp:
	dc.l	0
maxytemp:
	dc.l	0

optflag:
	dc.b	0

	even

sample:
	dc.w	0

channels:
	dc.w	$a0,$b0,$c0,$d0,0
chn:	dc.w	0

clr:	dc.b	0
	even

actualgadgetlist:
	dc.l	0

lastbutton:
	dc.l	0

jspeed:
	dc.l	10
scrmask:
	dc.b	$ff
invonoff:
	dc.b	0
cheatmode:
	dc.b	0

	even

code:	dc.w	0

;==========================================================================;

ZERO:	DC.L	0,0

REQbase	dc.l	0
REQfile	DC.L	0
REQname	dc.b	'reqtools.library',0
	even

		;-----dla FILE REQUESTER-------;
TagList	DC.L	RT_ReqPos,REQPOS_centerscr
	dc.l	RT_Screen
rt_scr:	dc.l	0
	DC.L	RTFI_Flags,FREQF_PATGAD
	DC.L	RTFI_Height,1000
	dc.l	rtgl_width,320
	dc.l	RTgs_Width,320
	DC.L	RTFI_Dir,4
	dc.l	$80000000+100
	dc.l	0,0
addtag:
	dc.l	rtfi_matchpat,pattern
	dc.l	rtfi_dir,directory
	dc.l	0,0

tytul:	dc.b	'Select hiscore file',0

ongadget:
	dc.b	0

	even

; **********************************************
; ***                GRAPHICS                ***    
; **********************************************

	section	gfx,data_c

	cnop	0,8
s_clear:
	ds.l	1

	cnop	0,8
termos:
	incbin	"Termos16y.228.24.raw"
	cnop	0,8
of:
	incbin	"Of58y.48.28.raw"
	cnop	0,8
union:
	incbin	"Union290x70.raw"

	cnop	0,8
cursormovebmp:
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111

	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111
	dc.w	%1111111111111111

	cnop	0,8
cursorbmp:
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000

	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	dc.w	%1111111100000000
	
mypointer:
	dc.w	0,0
	dc.w	%1111000000000000,%1111100000000000
	dc.w	%1110000000000000,%1001000000000000
	dc.w	%1100000000000000,%1010000000000000
	dc.w	%1000000000000000,%1100000000000000
	dc.w	%0000000000000000,%1000000000000000

blankpointer:
	dc.w	0,0
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000

	cnop	0,8
presents:
	incbin	"Presents116*10.raw"

	cnop	0,8
alphabet:
	incbin	"chars.raw"

	cnop	0,8
arcanoid:
	incbin	"Arcanoid72y.300.59.raw"
	cnop	0,8
mi1:	incbin	"Mini40y.76.34.1.raw"
	cnop	0,8
mi2:	incbin	"Mini40y.76.34.2.raw"
	cnop	0,8
mi3:	incbin	"Mini40y.76.34.3.raw"
	cnop	0,8
mi4:	incbin	"Mini40y.76.34.4.raw"
	cnop	0,8
mi5:	incbin	"Mini40y.76.34.5.raw"
	cnop	0,8
mi6:	incbin	"Mini40y.76.34.6.raw"

paletka:
	dc.w	8
	dc.w	6
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	pal
	dc.l	pal+48

	cnop	0,8
pal:	incbin	"Paletka.raw"

kaspal:
	dc.w	0
	dc.w	6
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kp
	dc.l	kp+48

	cnop	0,8
kp:	ds.b	96

kulkabitmap:
	dc.w	2
	dc.w	6
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kulka
	dc.l	kulka+16

	cnop	0,8
kulka:	incbin	"Kulka.raw"

kl1:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl1d
	dc.l	kl1d+32

	cnop	0,8
kl1d:	incbin	"k1.raw"

kl2:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl2d
	dc.l	kl2d+32

	cnop	0,8
kl2d:	incbin	"k2.raw"

kl3:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl3d
	dc.l	kl3d+32

	cnop	0,8
kl3d:	incbin	"k3.raw"

kl4:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl4d
	dc.l	kl4d+32

	cnop	0,8
kl4d:	incbin	"k4.raw"

kl5:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl5d
	dc.l	kl5d+32

	cnop	0,8
kl5d:	incbin	"k5.raw"

kl6:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl6d
	dc.l	kl6d+32

	cnop	0,8
kl6d:	incbin	"k6.raw"

kl7:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl7d
	dc.l	kl7d+32

	cnop	0,8
kl7d:	incbin	"k7.raw"

kl8:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	kl8d
	dc.l	kl8d+32

	cnop	0,8
kl8d:	incbin	"k8.raw"

tkl1:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl1d
	dc.l	tkl1d+32

	cnop	0,8
tkl1d:	incbin	"t1.raw"

tkl2:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl2d
	dc.l	tkl2d+32

	cnop	0,8
tkl2d:	incbin	"t2.raw"

tkl3:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl3d
	dc.l	tkl3d+32

	cnop	0,8
tkl3d:	incbin	"t3.raw"

tkl4:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl4d
	dc.l	tkl4d+32

	cnop	0,8
tkl4d:	incbin	"t4.raw"

tkl5:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl5d
	dc.l	tkl5d+32

	cnop	0,8
tkl5d:	incbin	"t5.raw"

tkl6:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl6d
	dc.l	tkl6d+32

	cnop	0,8
tkl6d:	incbin	"t6.raw"

tkl7:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl7d
	dc.l	tkl7d+32

	cnop	0,8
tkl7d:	incbin	"t7.raw"

tkl8:
	dc.w	4
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	tkl8d
	dc.l	tkl8d+32

	cnop	0,8
tkl8d:	incbin	"t8.raw"

	cnop	0,8
g_up:
	incbin	"up.raw"
	cnop	0,8
g_down:
	incbin	"down.raw"
	cnop	0,8
g_uppressed:
	incbin	"uppressed.raw"
	cnop	0,8
g_downpressed:
	incbin	"downpressed.raw"

c0:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c0r
	dc.l	c0r+68

	cnop	0,8
c0r:	incbin	"0.raw"

c1:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c1r
	dc.l	c1r+68

	cnop	0,8
c1r:	incbin	"1.raw"

c2:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c2r
	dc.l	c2r+68

	cnop	0,8
c2r:	incbin	"2.raw"

c3:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c3r
	dc.l	c3r+68

	cnop	0,8
c3r:	incbin	"3.raw"

c4:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c4r
	dc.l	c4r+68

	cnop	0,8
c4r:	incbin	"4.raw"

c5:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c5r
	dc.l	c5r+68

	cnop	0,8
c5r:	incbin	"5.raw"

c6:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c6r
	dc.l	c6r+68

	cnop	0,8
c6r:	incbin	"6.raw"

c7:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c7r
	dc.l	c7r+68

	cnop	0,8
c7r:	incbin	"7.raw"

c8:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c8r
	dc.l	c8r+68

	cnop	0,8
c8r:	incbin	"8.raw"

c9:	dc.w	4
	dc.w	17
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	c9r
	dc.l	c9r+68

	cnop	0,8
c9r:	incbin	"9.raw"

panel:	dc.w	18
	dc.w	194
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	pan
	dc.l	pan+3384

	cnop	0,8
pan:	incbin	"panel.129.188.raw"

	cnop	0,8
lh:
	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lh+16
	dc.l	lh+32
	incbin	"h.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lh+64
	dc.l	lh+82
	incbin	"hx.raw"

	cnop	0,8
le:
	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	le+16
	dc.l	le+16+16
	incbin	"e.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	le+64
	dc.l	le+82
	incbin	"ex.raw"

	cnop	0,8
lb:
	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lb+16
	dc.l	lb+16+16
	incbin	"b.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lb+64
	dc.l	lb+82
	incbin	"bx.raw"

	cnop	0,8
ln:	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	ln+16
	dc.l	ln+16+16
	incbin	"n.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	ln+64
	dc.l	ln+82
	incbin	"nx.raw"

	cnop	0,8
ls:	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	ls+16
	dc.l	ls+16+16
	incbin	"s.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	ls+64
	dc.l	ls+82
	incbin	"sx.raw"

	cnop	0,8
lk:	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lk+16
	dc.l	lk+16+16
	incbin	"g.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lk+64
	dc.l	lk+82
	incbin	"gx.raw"

	cnop	0,8
lpyt:	dc.w	2
	dc.w	8
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lpyt+16
	dc.l	lpyt+16+16
	incbin	"?.raw"
	dc.w	2
	dc.w	9
	dc.b	0
	dc.b	2
	dc.w	0
	dc.l	lpyt+64
	dc.l	lpyt+82
	incbin	"?x.raw"

; *****************************************
; ***             WORK SPACE            ***
; *****************************************

	section	free,bss

reqgads:
	ds.b	5*150*4-9*20*4-44*20-20*4
jumpgads:
	ds.l	9*20
screennames:
	ds.b	44*20
screenadr:
	ds.l	20
nazwa:
	ds.b	128
string:
	ds.b	256

; * Copy of actual level *
plact:
	ds.b	210

fileinfoblock:
	ds.b	260
	ds.w	0

configfile:
	ds.b	(conftend-configtable-2)/2

	even

configfileend:

InputIOReq:	ds.b	48
TimerIOReq:	ds.b	48
InputPort:	ds.b	34
ihinstalled:	ds.b	1
Exit:		ds.b	1
rmbflag:	ds.b	1
pauseflag:	ds.b	1
tiltflag:	ds.b	1
	even

timerbase:	ds.l	1
tilt_counter:	ds.w	1

alloctable:
	ds.l	40
pattern:
	ds.b	128
directory:
	ds.b	128
