ùúùú                                        ;
;
;Create New Dictonary 4-4-96 Jarosîaw Paruzel.
;program ten doîancza wyrazy dodatkowej biblioteki 'ort_lib1' do
;biblioteki gîównej 'ort_lib'
;tak utworzona nowa biblioteka zapisywana jest nastëpnie w ramdysku
;skât naleûy jâ przenoieôê na dyskietkë.
;
;
;Procedury Biblioteki Exec
;
_LVOOpenLibrary		equ	-552
_LVOCloseLibrary		equ	-414
_LVOAllocMem		equ	-198
_LVOFreeMem		equ	-210
_LVOAvailMem		equ	-$D8
_LVOWait			equ	-$13e
_LVOWaitPort		equ	-384
_LVOGetMsg		equ	-372
_LVOReplyMsg		equ	-378
_LVOFindTask		equ	-$126
_LVOForbid		equ	-$084
_LVOPermit		equ	-$08a
;
ThisTask		equ	276
pr_CLI			equ	$ac
;
MEMF_PUBLIC		equ	1
MEMF_CHIP		equ	2
MEMF_FAST		equ	4
MEMF_CLEAR		equ	$10000
MEMF_LARGEST		equ	$20000

;
;Procedury Biblioteki Dos
;
_LVOOpen			equ	-30
_LVOClose		equ	-36
_LVORead			equ	-42
_LVOWrite		equ	-48
_LVOOutPut		equ	-60
_LVOSeek			equ	-66
_LVODelay		equ	-198


; Predefined Amiga DOS global constants

DOSTRUE	      EQU     -1
DOSFALSE      EQU      0

; Mode parameter to Open()
MODE_OLDFILE	     EQU   1005	  ; Open existing file read/write
;				  ; positioned at beginning of file.
MODE_NEWFILE	     EQU   1006	  ; Open freshly created file (delete
;				  ; old file) read/write
MODE_READWRITE	     EQU   1004	  ; Open old file w/shared lock,
;				  ; creates file if doesn't exist.

; Relative position to Seek() 
OFFSET_BEGINNING     EQU   -1	  ; relative to Beginning Of File 
OFFSET_CURRENT	     EQU    0	  ; relative to Current file position 
OFFSET_END	     EQU    1	  ; relative to End Of File    

OFFSET_BEGINING	    EQU	  OFFSET_BEGINNING     ; Ancient compatibility

BITSPERBYTE	     EQU   8
BYTESPERLONG	     EQU   4
BITSPERLONG	     EQU   32
MAXINT		     EQU   $7FFFFFFF
MININT		     EQU   $80000000

; Passed as type to Lock() 
SHARED_LOCK	     EQU   -2	; File is readable by others 
ACCESS_READ	     EQU   -2	; Synonym
EXCLUSIVE_LOCK	     EQU   -1	; No other access allowed    
ACCESS_WRITE	     EQU   -1	; Synonym

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

Exec_Base		equ	4

dos_base		equ	4
fileHd			equ	8
Offset			equ	12
StartData		equ	16
EndData			equ	20
StartData1		equ	24
EndData1		equ	28
Tabl			equ	32
Conbase			equ	36
ConBase1		equ	40
SortTabela		equ	44


			move.l	#60000,d0
			move.l	#MEMF_CHIP+MEMF_CLEAR,d1
			bsr.W	AllocMemory
			beq.W	Error_AllocMem
			move.l	d0,a5
			clr.l	Offset(a5)

			lea	SortTabela(a5),a1
			lea	AsciiTabela(pc),a0
			moveq	#0,d0
			moveq	#0,d1
Sort_Loop		addq.l	#1,d0
			move.b	(a0)+,d1
			beq.s	EndSort
			move.b	d0,(a1,d1.w)
			bra.s	Sort_Loop

EndSort			move.l	Exec_Base,a6
			lea	Dos_Name(pc),a1
			moveq	#0,d0
			jsr	_LVOOpenLibrary(a6)
			move.l	d0,dos_base(a5)
			beq.W	Error_OpLib
			move.l	d0,a6
			jsr	_LVOOutPut(a6)
			move.l	d0,conbase(a5)		
			bne.s	ConOpen
			lea	ConSole(pc),a0
			move.l	a0,d1
			move.l	#MODE_NEWFILE,d2
			jsr	_LVOOpen(a6)
			move.l	d0,Conbase1(a5)
ConOpen			lea	LoadFile(pc),a1
			bsr.W	WriteText
			lea	file_name(pc),a1
			bsr.W	WriteLNText
			bsr.W	OpenAndRead
			beq.W	Error_OpenFile
			movem.l	a1/d0,-(sp)
			addq.l	#4,a1
			bsr.W	FindZero			
			move.l	a1,-(sp)
			bsr.W	FindZero
			move.l	a1,-(sp)
			lea	LoadFile(pc),a1
			bsr.W	WriteText
			move.l	(sp)+,a1
			bsr.W	WriteLNText
			bsr.W	OpenAndRead
			movem.l	a1/d0,-(sp)
			addq.l	#4,d0
			move.l	d0,offset(a5)
			lea	LoadFile(pc),a1
			bsr.W	WriteText
			move.l	8(sp),a1
			bsr.W	WriteLNText
			bsr.W	OpenAndRead
			beq.W	Error_OpenFile2
			movem.l	a1/d0,-(sp)
			add.l	a1,d0
			move.l	d0,EndData(a5)
			move.l	a1,Tabl(a5)
			add.l	(a1),a1
			move.l	a1,StartData(a5)
			movem.l	8(sp),a1/d0
			tst.l	d0
			beq.s	No_AddWords
			move.l	a1,StartData1(a5)
			add.l	a1,d0
			move.l	d0,EndData1(a5)			
			
			bsr.W	AddWords

No_AddWords		moveq	#0,d1

			lea	SortTabela(a5),a1
			move.l	a1,a2
			addq.l	#4,a1
			move.l	startData(a5),a0
			move.l	a0,d2
			addq.l	#1,d2
FindCAZ			cmp.l	EndData(a5),a0
			bge.s	EndCreateArray
			tst.b	(a0)+
			bne.s	FindCAZ
			moveq	#0,d0
			move.b	(a0),d0
			lsl.w	#8,d0
			move.b	1(a0),d0
			beq.s	zero			
			lsl.l	#8,d0
			move.b	2(a0),d0
			bra.s	zero1
zero			lsl.l	#8,d0
zero1			and.l	#$dfdfdf,d0

			cmp.l	d1,d0
			beq.s	FindCAZ
			move.l	d0,d1
			move.l	d0,(a1)+
			move.l	a0,(a1)
			sub.l	d2,(a1)+
			bra.s	FindCAZ
EndCreateArray		clr.l	(a1)+
			move.l	a0,(a1)
			sub.l	d2,(a1)+
					
			sub.l	a2,a1
			move.l	a1,(a2)	
			lea	SaveFile(pc),a1

			bsr.W	WriteLNText
			lea	filex(pc),a1			
			move.l	a1,d1
			move.l	#MODE_NEWFILE,d2
			bsr.W	OpenFile
			move.l	d0,FileHd(a5)
			beq.s	err_OpFilex

			lea	SortTabela(a5),a1
			move.l	a1,d2
			move.l	(a1),d3
			bsr.W	WriteFile
			move.l	StartData(a5),d2
			move.l	EndData(a5),d3
			sub.l	d2,d3
			bsr.W	WriteFile
			bsr.W	CloseFile			


err_OpFilex		movem.l	(sp)+,a1/d0
			add.l	Offset(a5),d0
			move.l	Exec_Base,a6
			jsr	_LVOFreeMem(a6)

Error_OpenFile2		movem.l	(sp)+,a1/d0
			tst.l	d0
			beq.s	Error_OpenFile1
			move.l	Exec_Base,a6
			jsr	_LVOFreeMem(a6)

Error_OpenFile1		addq.l	#4,sp
			movem.l	(sp)+,a1/d0
			move.l	Exec_Base,a6
			jsr	_LVOFreeMem(a6)

Error_OpenFile		tst.l	conbase1(a5)
			beq.s	Not_OpenCon
			move.l	dos_base(a5),a6
			move.l	#50*5,d1
			jsr	_LVODelay(a6)
			move.l	ConBase1(a5),d1
			jsr	_LVOClose(a6)

Not_OpenCon		move.l	Exec_Base,a6
			move.l	dos_base(a5),a1
			jsr	_LVOCloseLibrary(a6)
			move.l	a5,a1
			move.l	#60000,d0
			move.l	Exec_Base,a6
			jsr	_LVOFreeMem(a6)

Error_AllocMem		moveq	#1,d0
Error_OpLib		subq.l	#1,d0
;			movem.l	StartData1(a5),a0/a1
			rts

FindZero		tst.b	(a1)+
			bne.s	FindZero
			rts

;
;a1 - filename
;rezultat a1 - adress , d0 - dîugoôê 0 gdy bîâd
;
OpenAndRead		move.l	a1,d1
			move.l	#MODE_OLDFILE,d2
			bsr.s	OpenFile
			move.l	d0,FileHd(a5)
			beq.s	err_OpFile
			moveq	#OFFSET_END,d3
			bsr.W	SeekFile
			bmi.s	err_seek
			moveq	#OFFSET_BEGINNING,d3
			bsr.W	SeekFile
			bmi.s	err_seek		
			beq.s	err_Seek
			move.l	d0,-(sp)
			add.l	offset(a5),d0
			move.l	#MEMF_CHIP,d1
			bsr.W	AllocMemory
			move.l	(sp)+,d3
			move.l	d0,d2
			beq.s	err_Seek
			move.l	d2,-(sp)
			move.l	d3,-(sp)
			bsr.s	ReadFile
			movem.l	(sp),a1/d1
			cmp.l	d0,d1
			bne.s	err_Read
			bsr.s	CloseFile		
			movem.l	(sp)+,a1/d0
			tst.l	d0
			rts

err_Read		addq.l	#8,sp
			move.l	d1,d0
			move.l	Exec_Base,a6
			jsr	_LVOFreeMem(a6)
err_Seek		bsr.s	CloseFile
err_OpFile		moveq	#0,d0
			rts
;
OpenFile		move.l	d1,-(sp)
			movea.l	dos_base(a5),a6
			jsr	_LVOOpen(a6)
			tst.l	d0
			bne.s	OpenFileOk
			lea	TextOpenFile(pc),a1
			bsr.s	WriteText
			move.l	(sp),a1
			bsr.s	WriteText
			lea	TextError(pc),a1
			bsr.s	WriteLnText			
OpenFileOk		addq.l	#4,sp
			rts

CloseFile		move.l	filehd(a5),d1
			movea.l	dos_base(a5),a6
			jmp	_LVOClose(a6)

ReadFile		move.l	d3,-(sp)
			move.l	filehd(a5),d1
			movea.l	dos_base(a5),a6
			jsr	_LVORead(a6)
			cmp.l	(sp),d0
			beq.s	ReadFileOk
			lea	TextReadError(pc),a1
			bsr.s	WriteLnText			
ReadFileOk		addq.l	#4,sp
			rts

WriteFile		move.l	d3,-(sp)
			move.l	filehd(a5),d1
			move.l	dos_Base(a5),a6
			jsr	_LVOWrite(a6)
			cmp.l	(sp),d0
			beq.s	WriteFileOk
			lea	TextWriteError(pc),a1
			bsr.s	WriteLnText			
WriteFileOk		addq.l	#4,sp
			rts

SeekFile		move.l	filehd(a5),d1
			moveq	#0,d2
			movea.l	dos_base(a5),a6
			jsr	_LVOSeek(a6)
			tst.l	d0
			rts

WriteLnText		bsr.s	WriteText
			movem.l	d0-d7/a0-a6,-(sp)
			lea	LNText(pc),a1
			bra.s	WriteText1
			

WriteText		movem.l	d0-d7/a0-a6,-(sp)
WriteText1		move.l	conbase(a5),d1
			add.l	Conbase1(a5),d1
			beq.s	No_WriteText
			move.l	a1,d2
			moveq	#-1,d3
GetSizeString		addq.l	#1,d3
			tst.b	(a1)+
			bne.s	GetSizeString
			move.l	dos_Base(a5),a6
			jsr	_LVOWrite(a6)
No_WriteText		movem.l	(sp)+,d0-d7/a0-a6
			rts

AllocMemory		movea.l	Exec_base,a6
			jsr	_LVOAllocmem(a6)
			tst.l	d0
			rts
;
AddWords		move.l	startData1(a5),a1
			move.l	a1,a3
			moveq	#-1,d7
SumWords		cmp.l	EndData1(a5),a3
			bge.s	EndSumWords
			tst.b	(a3)+
			bne.s	SumWords
			addq.l	#1,d7
			bra.s	SumWords
EndSumWords		lea	SortTabela(a5),a3
FindSZero		cmp.l	EndData1(a5),a1
			bge.W	EndAddWords
			tst.b	(a1)+
			bne.s	FindSZero

			move.l	a1,a2
			moveq	#0,d0
			move.l	#$ffffff,d3
			moveq	#2,d2
Loop			move.b	(a2)+,d0
			beq.s	Star
			cmp.b	#'*',d0
			beq.s	Star
			cmp.b	#'?',d0
			beq.s	Star
			lsl.l	#8,d0
			dbf	d2,loop
			lsr.l	#8,d0
			bra.s	Fxxa
star			addq.l	#1,d2
			lsl.l	#3,d2
			lsl.l	d2,d3
			subq.l	#8,d2
			lsl.l	d2,d0
			and.l	d3,d0
			
Fxxa			and.l	#$dfdfdf,d0
			move.l	tabl(a5),a0
			addq.l	#4,a0
fxxal			move.l	(a0)+,d2
			beq.s	FindSZero1
			addq.l	#4,a0
			and.l	d3,d2
			cmp.l	d2,d0
			bne.s	Fxxal
			subq.l	#4,a0
			move.l	(a0),a0
			add.l	StartData(a5),a0
FindSZero1		cmp.l	EndData(a5),a0
			bge.s	FindSZero
			tst.b	(a0)+
			bne.s	FindSZero1
			movem.l	a0/a1,-(sp)

			moveq	#0,d4
			moveq	#0,d5
sort_loop3		move.b	(a1)+,d4
			andi.b	#223,d4
			move.b	$00(a3,d4.w),d5
			move.b	(a0)+,d4		
			andi.b	#223,d4
			cmp.b	$00(a3,d4.w),d5
			beq.s	sort_loop3				
			bhi.s	sort_omin

			movem.l	(sp),a0/a1
			moveq	#0,d0
Add1			addq.l	#1,d0
			tst.b	-1(a1,d0.w)
			bne.s	Add1
			add.l	d0,EndData(a5)
			move.l	EndData(a5),a2
			move.l	a2,a1
			sub.l	d0,a1
			addq.l	#1,a1
			addq.l	#1,a2
MoveWords		move.b	-(a1),-(a2)
			cmp.l	a0,a1
			bgt.s	MoveWords
			move.l	d7,d0
			subq.l	#1,d7
			lea	digits(pc),a0
			move.l	a0,a1
			bsr.s	LongToAscii
			move.b	#' ',(a0)+
			clr.b	(a0)+
			bsr.W	WriteText
			movem.l	(sp),a0/a1
			bsr.W	WriteLNText
CopyWord		move.b	(a1)+,(a0)+
			bne.s	CopyWord
			movem.l	(sp)+,a0/a1
			bra.W	FindSZero
			
sort_omin		movem.l	(sp)+,a0/a1
			bra.s	FindSZero1

EndAddWords		rts

;
;Zamiana dîugiej liczby na ciag ASCII
;A0 -Poczatek 10 bajtowego bufora
;d0 -Liczba do konwersji
;
LONGTOASCII		movem.l	d1-d4,-(sp)
			move.l	#1000000000,d2
			moveq	#0,d4
LONGTOASCII_Loop	move.l	d2,d1
			bsr.s	UDIVMOD32
			tst.l	d4
			bne.s	DIGITZERO
			tst.l	d0
			beq.s	NODIGITZERO
			moveq	#1,d4
DIGITZERO		move.b	d0,(a0)
			add.b	#'0',(a0)+
NODIGITZERO		move.l	d2,d0
			move.l	d1,d3
			moveq	#10,d1
			bsr.s	UDIVMOD32
			move.l	d0,d2
			move.l	d3,d0
			tst.l	d2
			bne.s	LONGTOASCII_Loop
			tst.l	d4
			bne.s	NOZero
			move.b	#'0',(a0)+
NOZero			movem.l	(sp)+,d1-d4
			rts
;
;UDIVMOD32
;D0-DIVINDEND,D1-DIVISOR
;
UDIVMOD32
lbC00002C		MOVE.L	D3,-(SP)
			CMPI.L	#$FFFF,D1
			BHI.s	lbC000052
			MOVE.L	D1,D3
			SWAP	D0
			MOVE.W	D0,D3
			BEQ.s	lbC000042
			DIVU.W	D1,D3
			MOVE.W	D3,D0
lbC000042		SWAP	D0
			MOVE.W	D0,D3
			DIVU.W	D1,D3
			MOVE.W	D3,D0
			SWAP	D3
			MOVE.W	D3,D1
			MOVE.L	(SP)+,D3
			RTS

lbC000052		MOVE.L	D2,-(SP)
			MOVE.L	D1,D3
			MOVE.L	D0,D1
			CLR.W	D1
			SWAP	D1
			SWAP	D0
			CLR.W	D0
			MOVEQ	#15,D2
lbC000062		ADD.L	D0,D0
			ADDX.L	D1,D1
			CMP.L	D1,D3
			BHI.s	lbC00006E
			SUB.L	D3,D1
			ADDQ.W	#1,D0
lbC00006E		DBRA	D2,lbC000062
			MOVEM.L	(SP)+,D2/D3
			RTS
			
;
Dos_Name		dc.b	'dos.library',0
File_Name		dc.b	's:orto_pref',0

AsciiTabela		dc.b	'AaÂâBbCcÊêDdEeËëFfGgHhIiJjKkLlÎîMmNn'
			dc.b	'ÏïOoÓóPpQqRrSsÔôTtUuVvWwXxYyZzÚúÛû',0
TextOpenFile		dc.b	'  Open File -> ',0
TextReadError		dc.b	'  Read Error !',0
TextWriteError		dc.b	'  Write Error !',0  
TextError		dc.b	' Error !',0
LoadFile		dc.b	'Load File -> ',0
SaveFile		dc.b	'Save File -> '
filex			dc.b	'ram:ort_lib',0

console			dc.b	'CON:0/0/640/100/Create New Dictonary V1.0 by Jaroslaw Paruzel',0
lnText			dc.b	$0a,0
Digits			blk.b	11,0
