*************************************************
***   Simple example program for INI library  ***
***          © 2001 by Basty/Seasons          ***
***   This program demonstrates the powerful  ***
***     save functions of the INI library     ***
***             Assembler version             ***
***    Devpac 3.18 was used for development   ***
*************************************************

	include	"exec/types.i"
	include	"exec/libraries.i"
	include "exec/exec_lib.i"
	include	"libraries/ini_lib.i"

	moveq	#20,d7					* Set FAIL error mark
	moveq	#33,d0					* Version 33.00 of ini.library
	lea	ININame(pc),a1				* Load A1 with ini.library
	move.l	4.w,a6

	jsr	_LVOOpenLibrary(a6)			* Open ini.library

	move.l	d0,_INIBase				* Store ini.library base to INIBase
	beq	OpenINIError				* Exit if error

	lea	DefaultINI(pc),a0			* Load default INI file
	lea	ExampleINI(pc),a1			* Open :Example.INI file
	move.l	#DefaultLen,d0			* Length of it in D0

	CALLINIB	iniOpenDefault		* Open INI file/Create default INI file

	move.l	d0,DefINIFile			* Store loaded iniFile
	beq	CloseINI					* Error -> close everything and end

	move.l	DefINIFile(pc),a0		* Now we want to change the ViewMode in
	lea	Screen1Name(pc),a1			* [Screen1] and write th value 0 in the
	lea	ViewModeName(pc),a2			* form 0x0000

	moveq	#$0,d0					* The value to be written
	moveq	#0,d1					* No flags (case in-sensitive search)
	moveq	#INI_FORMAT_HEX_0X,d2	* Hexadecimal with 0x precedor
	moveq	#4,d3					* Total length is always 4 digits
	moveq	#"0",d4					* Fill with zeroes, i.e.
									* 0x300 becomes 0x0300
	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0		* Now we change the width of the screen
	lea	Screen1Name(pc),a1			* to 320 so we have a lores screen. We
	lea	WidthName(pc),a2			* want standard decimal output without
									* zero preceding.
	move.l	#320,d0					* The value to be written
	moveq	#0,d1					* No flags (case in-sensitive search)
	moveq	#INI_FORMAT_DEC,d2		* Decimal without any precedor
	moveq	#0,d3					* Don't use fixed length
	moveq	#0,d4					* Filler isn't important in this case

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window1Name(pc),a1
	lea	WidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window2Name(pc),a1
	lea	WidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window3Name(pc),a1
	lea	WidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window4Name(pc),a1
	lea	WidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window1Name(pc),a1
	lea	MaxWidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window2Name(pc),a1
	lea	MaxWidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window3Name(pc),a1
	lea	MaxWidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0
	lea	Window4Name(pc),a1
	lea	MaxWidthName(pc),a2

	move.l	#320,d0
	moveq	#0,d1
	moveq	#INI_FORMAT_DEC,d2
	moveq	#0,d3
	moveq	#0,d4

	CALLINI	iniWriteLong

	move.l	DefINIFile(pc),a0		* This time we want to change the screen
	lea	Screen1Name(pc),a1			* title
	lea	TitleName(pc),a2
	lea	NewScrTitle(pc),a3			* The new string to be written

	moveq	#0,d0					* No flags (case in-sensitive search)

	CALLINI	iniWriteStr

	move.l	DefINIFile(pc),a0		* Now we want a new color table
	lea	Screen1Name(pc),a1
	lea	ColorTableName(pc),a2
	lea	NewColorTable(pc),a3		* The new array to be written

	moveq	#16,d0					* 16 entries in color table (hard coded)
	moveq	#0,d1					* No flags (case in-sensitive search)
	moveq	#INI_FORMAT_HEX_0X,d2	* Hexadecimal with 0x precedor
	moveq	#3,d3					* Total length is always 3 digits
	moveq	#"0",d4					* Fill with zeroes, i.e.
									* 0x3 becomes 0x003
	CALLINI	iniWriteWordA

	move.l	DefINIFile(pc),a0		* After we have changed all entries, we
	lea	ExampleINI(pc),a1			* need to store the changed data to disk
	move.l	a1,d1

	move.l	#MODE_NEWFILE,d2		* Overwrite existing file (see DOS)
	
	CALLINI	iniSaveFile

	move.l	DefINIFile(pc),a0
	CALLINI	iniClose				* Close INI file and deallocate memory

	moveq	#0,d7

CloseINI:	move.l	_INIBase(pc),a1
	move.l	4.w,a6

	jsr	_LVOCloseLibrary(a6)		* Close INI library

OpenINIError:	move.l	d7,d0		* Set return code
	rts								* Exit to DOS

_INIBase:	dc.l	0
DefINIFile:	dc.l	0
NewColorTable:	dc.w	$fff,$000,$777,$ccc
	dc.w	$444,$555,$666,$888
	dc.w	$111,$222,$aaa,$333
	dc.w	$999,$ddd,$bbb,$eee
ININame:	ININAME
ExampleINI:	dc.b	':Example.INI',0
DefaultINI:	dc.b	"/* This is an example INI file of the ini.library which",10
	dc.b	"   shows how the INI configuration files can be used. It supports",10
	dc.b	"   multiple accesses. This file is always created if it can't be",10
	dc.b	"   accessed for any reason (usually when it doesn't exists) */",10
	dc.b	10
	dc.b	'  [Screen1]           ; Up to 9 screens are allowed.',10
	dc.b	'  LeftEdge = 0        ; Left edge of screen.',10
	dc.b	'  TopEdge = 0         ; Top edge of screen.',10
	dc.b	'  Width = 640         ; Width of screen.',10
	dc.b	'  Height = 256        ; Height of screen.',10
	dc.b	'  Depth = 4           ; Use 2^Depth colors.',10
	dc.b	'  ViewMode = 0x8000   ; Screen view mode (lores, hires, etc.)',10
	dc.b	'  Title = Example INI Test Screen © 1999 by Basty/Seasons  ; Default title',10
	dc.b	'  ColorTable = 0x000, 0xFFF, 0x777, 0xCCC,  ; Color table entries.',10
	dc.b	'               0x444, 0x555, 0x666, 0x888,  ; There are 2^Depth entries',10
	dc.b	'               0x111, 0x222, 0xAAA, 0x333,  ; required. Further entries',10
	dc.b	'               0x999, 0xDDD, 0xEEE, 0xBBB,  ; will be ignored.',10
	dc.b	10
	dc.b	'* Now we configure the windows to be opened. Please note that the windows',10
	dc.b	"* are assigned using the 'Screen' context item.",10
	dc.b	10
	dc.b	'  [Window1]',10
	dc.b	'  LeftEdge = 0        ; Left edge of window.',10
	dc.b	'  TopEdge = 0         ; Top edge of window.',10
	dc.b	'  Width = 640		 ; Width of window.',10
	dc.b	'  Height = 256		 ; Height of window.',10
	dc.b	'  IDCMP = 0x00020000  ; IDCMP flags of window.',10
	dc.b	'  Flags = 0x0000100F  ; Default window flags.',10
	dc.b	'  Title = Example INI Test Window © 1999 by Basty/Seasons  ; Default title',10
	dc.b	'  Screen = 1          ; Screen to open window on. 0 is workbench screen',10
	dc.b	'  MinWidth = 32',10
	dc.b	'  MinHeight = 32',10
	dc.b	'  MaxWidth = 640',10
	dc.b	'  MaxHeight = 256',10
	dc.b	10
	dc.b	'  [Window2]',10
	dc.b	'  LeftEdge = 0        ; Left edge of window.',10
	dc.b	'  TopEdge = 16        ; Top edge of window.',10
	dc.b	'  Width = 640		 ; Width of window.',10
	dc.b	'  Height = 64		 ; Height of window.',10
	dc.b	'  IDCMP = 0x00020000  ; IDCMP flags of window.',10
	dc.b	'  Flags = 0x0000100F  ; Default window flags.',10
	dc.b	'  Title = Small window #2  ; Default title',10
	dc.b	'  Screen = 1          ; Screen to open window on. 0 is workbench screen',10
	dc.b	'  MinWidth = 32',10
	dc.b	'  MinHeight = 32',10
	dc.b	'  MaxWidth = 640',10
	dc.b	'  MaxHeight = 64',10
	dc.b	10
	dc.b	'  [Window3]',10
	dc.b	'  LeftEdge = 0        ; Left edge of window.',10
	dc.b	'  TopEdge = 80        ; Top edge of window.',10
	dc.b	'  Width = 640		 ; Width of window.',10
	dc.b	'  Height = 64		 ; Height of window.',10
	dc.b	'  IDCMP = 0x00020000  ; IDCMP flags of window.',10
	dc.b	'  Flags = 0x0000100F  ; Default window flags.',10
	dc.b	'  Title = Small window #3  ; Default title',10
	dc.b	'  Screen = 1          ; Screen to open window on. 0 is workbench screen',10
	dc.b	'  MinWidth = 32',10
	dc.b	'  MinHeight = 32',10
	dc.b	'  MaxWidth = 640',10
	dc.b	'  MaxHeight = 64',10
	dc.b	10
	dc.b	'  [Window4]',10
	dc.b	'  LeftEdge = 0        ; Left edge of window.',10
	dc.b	'  TopEdge = 144       ; Top edge of window.',10
	dc.b	'  Width = 640		 ; Width of window.',10
	dc.b	'  Height = 64		 ; Height of window.',10
	dc.b	'  IDCMP = 0x00020000  ; IDCMP flags of window.',10
	dc.b	'  Flags = 0x0000100F  ; Default window flags.',10
	dc.b	'  Title = Small window #4  ; Default title',10
	dc.b	'  Screen = 1          ; Screen to open window on. 0 is workbench screen',10
	dc.b	'  MinWidth = 32',10
	dc.b	'  MinHeight = 32',10
	dc.b	'  MaxWidth = 640',10
	dc.b	'  MaxHeight = 64',10
	dc.b	10
DefaultLen:	equ	*-DefaultINI
Screen1Name:	dc.b	'Screen1',0
Window1Name:	dc.b	'Window1',0
Window2Name:	dc.b	'Window2',0
Window3Name:	dc.b	'Window3',0
Window4Name:	dc.b	'Window4',0
ViewModeName:	dc.b	'ViewMode',0
WidthName:	dc.b	'Width',0
MaxWidthName:	dc.b	'MaxWidth',0
TitleName:	dc.b	'Title',0
ColorTableName:	dc.b	'ColorTable',0
NewScrTitle:	dc.b	'Example INI Test Screen Lo-Res © 2001 by Basty/Seasons',0
