			INCDIR	JPINCLUDE/
			INCLUDE	exec.offs
			INCLUDE	intuition.offs
			INCLUDE	commodities.offs
			INCDIR	INCLUDES/
			INCLUDE	exec/memory.i

Exec_Base		equ	4

Function		equ	_LVOAttachCxObj

			lea	LibraryName(pc),a1
			moveq	#0,d0
			move.l	Exec_Base,a6
			jsr	_LVOOpenLibrary(a6)
			lea	Library_Base(pc),a0
			move.l	d0,(a0)
			beq	Error_OpenLibrary
			lea	IntuitionName(pc),a1
			moveq	#0,d0
			jsr	_LVOOpenLibrary(a6)
			lea	Intuition_Base(pc),a0
			move.l	d0,(a0)
			beq	Error_OpenIntuition

			move.l	#MEMF_PUBLIC,d1
			move.l	#PrgEnd-PrgStart,d0
			jsr	_LVOAllocMem(a6)
			tst.l	d0
			beq	Error_AllocMem

			lea	PrgStart(pc),a0
			move.l	d0,a1

			move.l	#PrgEnd-PrgStart,d1
Move_Code		move.b	(a0)+,(a1)+
			dbf	d1,Move_Code

			move.l	d0,-(sp)
			jsr	_LVOForbid(a6)
			move.l	(sp)+,d0
			move.l	Library_Base(pc),a1
			move.l	#Function,a0
			jsr	_LVOSetFunction(a6)			
			lea	OldAddres(pc),a1
			move.l	d0,(a1)
			jsr	_LVOPermit(a6)
			moveq	#0,d0
			rts

PrgStart		movem.l	d0-d7/a0-a6,-(sp)
			moveq	#0,d5
			moveq	#7,d6
			lea	xd0(pc),a1
			bsr	Loop
			moveq	#7,d6
			lea	xa0(pc),a1
			bsr	Loop
			move.l	Intuition_Base(pc),a6
			move.l 	#0,d0
			lea 	info(pc),a0
			move.l 	#70,d1
			jsr 	_LVODisplayAlert(a6)		
			tst.b	d0
			bne	JJJ

			jsr	_LVOForbid(a6)
			move.l	OldAddres(pc),d0
			move.l	Library_Base(pc),a1
			move.l	#Function,a0
			jsr	_LVOSetFunction(a6)			
			jsr	_LVOPermit(a6)

JJJ			movem.l	(sp)+,d0-d7/a0-a6
			move.l	OldAddres(pc),-(sp)
			rts

Loop			addq	#4,d5
			move.l	(sp,d5.l),d0
			add.l   #8,a1
			move.l  #7,d3
Loop1			move.l  d0,d1
			ror.l   #4,d0
			and.b   #$0f,d1
			move.b  d1,d2
			add.b   #48,d1
			cmp.b   #57,d1
			ble     wzakr
			add.b   #7,d1
wzakr			move.b  d1,-(a1)
			dbf     d3,Loop1
			add.l	#9,a1
			dbf	d6,Loop
			rts

Error_AllocMem		move.l	Intuition_Base(pc),a1
			move.l	Exec_Base,a6
			jsr	_LVOCloseLibrary(a6)
Error_OpenIntuition	move.l	Library_Base(pc),a1
			move.l	Exec_Base,a6
			jsr	_LVOCloseLibrary(a6)
Error_OpenLibrary	moveq	#-1,d0
			rts

Library_Base		dc.l	0
Intuition_Base		dc.l	0
OldAddres		dc.l	0

IntuitionName		dc.b	'intuition.library',0

info			dc.b 	0,$10,12
			dc.b 	'dx- '
xd0			dc.b	'00000000 00000000 00000000 00000000 '
			dc.b	'00000000 00000000 00000000 00000000 '
			dc.b	0,1,0,$10,30
			dc.b	'ax- '
xa0			dc.b	'00000000 00000000 00000000 00000000 '
			dc.b	'00000000 00000000 00000000 00000000 '
			dc.b	0,1,0,$10,40,32
			dc.b	'wejscie (-$cc) '
LibraryName		dc.b	'commodities.library',0
PrgEnd
