home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 13
/
AACD13.ISO
/
AACD
/
Programming
/
ini_library
/
Examples
/
src
/
Asm
/
INI_Example.s
Wrap
Text File
|
1999-03-26
|
21KB
|
625 lines
*************************************************
*** Complex example program for INI library ***
*** © 1999 by Basty/Seasons ***
*** This program demonstrates the powerful ***
*** 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/dosextens.i"
include "libraries/ini_lib.i"
include "intuition/screens.i"
include "intuition/intuition.i"
include "intuition/intuitionbase.i"
include "intuition/intuition_lib.i"
include "graphics/graphics_lib.i"
include "graphics/rastport.i"
moveq #20,d7 * Set FAIL error mark
moveq #31,d0 * Version 31.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
moveq #0,d0 * Any version of intuition.library
lea IntName(pc),a1 * Load A1 with intuition.library
jsr _LVOOpenLibrary(a6) * Open intuition.library
move.l d0,_IntBase * Store intuition.library base to IntBase
moveq #0,d0 * Any version of graphics.library
lea GfxName(pc),a1 * Load A1 with graphics.library
jsr _LVOOpenLibrary(a6) * Open graphics.library
move.l d0,_GfxBase * Store graphics.library base to GfxBase
move.l _IntBase(pc),a0 * Get first screen (WB screen)
move.l ib_FirstScreen(a0),WBScreen+8
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
moveq #1,d6 * Start with first screen
LoopReadScr: lea ScreenNum(pc),a0 * Store to screen number
move.l d6,d0 * Current screen number
moveq #INI_FORMAT_DEC,d1 * Use standard decimal format
moveq #0,d2 * No given length, as long as the string
* becomes.
moveq #" ",d3 * Use SPACE character as zero separator
CALLINIB iniIntToStr * Convert screen number
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Find the context
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniFindContext * Search for context
tst.l d0 * Found?
beq LoopReadScrDone * No -> end of search
move.l d0,CurrentContext * Store current ContextStr
lea NewScreenStr(pc),a5 * NewScreen structure to A5
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea LeftEdgeName(pc),a2 * Get left edge value
moveq #0,d0 * Default left edge is 0
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,(a5) * Store left edge into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea TopEdgeName(pc),a2 * Get top edge value
moveq #0,d0 * Default top edge is 0
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_TopEdge(a5) * Store top edge into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea WidthName(pc),a2 * Get width value
move.l #640,d0 * Default width is 640
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_Width(a5) * Store width into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea HeightName(pc),a2 * Get height value
move.l #256,d0 * Default height is 256
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_Height(a5) * Store height into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea DepthName(pc),a2 * Get depth value
moveq #4,d0 * Default depth is 4
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_Depth(a5) * Store depth into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea ViewModesName(pc),a2 * Get view mode value
move.l #$8000,d0 * Default view modes are 0x8000
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,ns_ViewModes(a5) * Store view mode into screen structure
move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea TitleName(pc),a2 * Get screen title
lea DefaultScrTitle(pc),a3 * Default screen title
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniReadStr
move.l d0,ns_DefaultTitle(a5) * Store title into screen structure
moveq #256/4-1,d0 * Copy all 256 default colors to
moveq #0,d1 * updated color table
lea DefaultColTab(pc),a0
lea ScrColorTable(pc),a1
CopyDefColTabLoop: move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
dbra d0,CopyDefColTabLoop
move.w ns_Depth(a5),d0 * Calculate number of colors
moveq #1,d5 * store 1 color
lsl.b d0,d5 * multiply with 2^depth
bne.s NotGreater * if lesser than 256 colors -> jump
move.w #$100,d5 * set to 256 colors
NotGreater: move.l DefINIFile(pc),a0
lea ScreenContext(pc),a1 * Get current screen context name
lea ColorTableName(pc),a2 * Get color table context item name
lea ScrColorTable(pc),a3 * Get array pointer
move.l d5,d0 * Number of entries to read
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadWordA * Read color table array
moveq #24,d0 * We need 24 bytes of storage buffer for
* each screen we open.
CALLINI iniAllocPMem * Allocate it using ini.library
tst.l d0 * Test if error
bne.s AllocScrOk * No -> continue
move.l ns_DefaultTitle(a5),a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
bra CloseINI * Close INI file
AllocScrOk: lea Screens(pc),a0 * Add the structure to the screen list
move.l d0,a1
move.l 4.w,a6
jsr _LVOAddTail(a6) * Use exec AddTail() for this
move.l a5,a0 * Now we want to open the screen
move.l _IntBase(pc),a6 * We need intuition.library for this
jsr _LVOOpenScreen(a6) * Open the screen
move.l Screens+MLH_TAILPRED(pc),a0 * Get last screen structure added
addq.l #MLN_SIZE,a0
move.l d0,(a0)+ * Store the screen for later reuse
move.l a0,(a0) * Initialize node list of windows
move.l a0,MLH_TAILPRED(a0) * Currently there are none.
addq.l #4,(a0)
tst.l d0 * Check if screen open error
bne.s AllocScrOk2 * No -> continue
move.l ns_DefaultTitle(a5),a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
bra CloseINI
AllocScrOk2: move.l d0,a0
move.l d5,d0 * Read color map
lea sc_ViewPort(a0),a0 * Screen->ViewPort
lea ScrColorTable(pc),a1 * Load colors
move.l _GfxBase(pc),a6 * We need graphics.library
jsr _LVOLoadRGB4(a6) * Load color table
addq.l #1,d6 * Increment screen counter
bra LoopReadScr
LoopReadScrDone: moveq #1,d6 * Start with first window
LoopReadWin: lea WindowNum(pc),a0 * Store to window number
move.l d6,d0 * Current window number
moveq #INI_FORMAT_DEC,d1 * Use standard decimal format
moveq #0,d2 * No given length, as long as the string
* becomes.
moveq #" ",d3 * Use SPACE character as zero separator
CALLINIB iniIntToStr * Convert window number
addq.l #1,d6 * Next window
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Find the context
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniFindContext * Search for context
tst.l d0 * Found?
beq LoopReadWinDone * No -> end of search
move.l d0,CurrentContext * Store current ContextStr
lea NewWindowStr(pc),a5 * NewWindow structure to A5
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea LeftEdgeName(pc),a2 * Get left edge value
moveq #0,d0 * Default left edge is 0
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,(a5) * Store left edge into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea TopEdgeName(pc),a2 * Get top edge value
moveq #0,d0 * Default top edge is 0
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_TopEdge(a5) * Store top edge into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea WidthName(pc),a2 * Get width value
move.l #640,d0 * Default width is 640
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_Width(a5) * Store width into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea HeightName(pc),a2 * Get height value
move.l #256,d0 * Default height is 256
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_Height(a5) * Store height into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea IDCMPName(pc),a2 * Get IDCMP value
move.l #$20000,d0 * Default IDCMP flags are 0x00020000
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.l d0,nw_IDCMPFlags(a5) * Store IDCMP into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea FlagsName(pc),a2 * Get flags value
move.l #$100f,d0 * Default flags are 0x0000100F
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.l d0,nw_Flags(a5) * Store flags into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea TitleName(pc),a2 * Get title name
lea DefaultWinTitle(pc),a3 * Default window title
moveq #0,d0 * No flags (case insensitive search)
CALLINI iniReadStr
move.l d0,nw_Title(a5) * Store title into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea MinWidthName(pc),a2 * Get minium width value
moveq #32,d0 * Default mininum width is 32
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_MinWidth(a5) * Store min width into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea MaxWidthName(pc),a2 * Get max width value
move.l #640,d0 * Default maximum width is 640
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_MaxWidth(a5) * Store max width into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea MinHeightName(pc),a2 * Get mininum height value
moveq #32,d0 * Default mininum height is 32
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_MinHeight(a5) * Store min height into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea MaxHeightName(pc),a2 * Get maximum height value
move.l #256,d0 * Default maximum height is 256
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
move.w d0,nw_MaxHeight(a5) * Store max height into window structure
move.l DefINIFile(pc),a0
lea WindowContext(pc),a1 * Get current window context name
lea ScreenName(pc),a2 * Get screen number value
moveq #1,d0 * Default number is 1
moveq #0,d1 * No flags (case insensitive search)
CALLINI iniReadLong
lea Screens(pc),a0 * Find screen list
FindScreenLoop: move.l (a0),a0 * Next screen
tst.l (a0) * End of list?
beq LoopReadWin * Yes -> next window
subq.l #1,d0 * Decrease counter
bcc.s FindScreenLoop * Not zero? -> continue
move.l 8(a0),nw_Screen(a5) * Copy screen pointer
move.l a0,a2
moveq #12,d0 * We need 12 bytes of storage buffer for
* each window we open.
CALLINI iniAllocPMem * Allocate it using ini.library
tst.l d0 * Test if error
bne.s AllocWinOk * No -> continue
move.l nw_Title(a5),a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
bra.s CloseINI * Close resources
AllocWinOk: lea 12(a2),a0 * Add the structure to the window list
move.l d0,a1
move.l 4.w,a6
jsr _LVOAddTail(a6) * Use exec AddTail() for this
move.l a5,a0 * Now we want to open the window
move.l _IntBase(pc),a6 * We need intuition.library for this
jsr _LVOOpenWindow(a6) * Open the window
tst.l d0 * Check if window error
bne.s AllocWinOk2 * No -> continue
move.l nw_Title(a5),a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
bra.s CloseINI * Close resources
AllocWinOk2: move.l MLH_TAILPRED+12(a2),a0 * Get last window pointer
move.l d0,8(a0) * Store current window pointer
bra LoopReadWin * Read next window
LoopReadWinDone: btst #6,$bfe001 * Wait for mouse button
bne.s LoopReadWinDone
moveq #0,d7 * Set no error mark
CloseINI: lea Screens(pc),a2 * We want to deallocate all screens
ScreenCloseLoop: move.l (a2),a3 * Next screen
tst.l (a3) * Have we reached last entry?
beq ScreenCloseDone * Yes -> done
lea 12(a3),a4 * Get window pointers
move.l (a4),d6
WindowCloseLoop: move.l d6,a4 * Get next window pointer
tst.l (a4) * Test if last.
beq.s WindowCloseDone * Yes -> done
move.l 8(a4),d0 * Get window to close
beq.s SkipCloseWin * No window opened -> skip
move.l d0,a0
move.l wd_Title(a0),d2 * Save window title
move.l _IntBase(pc),a6 * intuition.library
jsr _LVOCloseWindow(a6) * Close the damn window!
move.l d2,a0
CALLINIB iniFreeNameStr * Deallocate title name string
SkipCloseWin: move.l (a4),d6 * Get next window pointer
moveq #12,d0 * Deallocate 12 bytes
move.l a4,a1 * Deallocate window structure
CALLINIB iniFreePMem * Deallocate memory using ini.library
bra.s WindowCloseLoop * Free next window
WindowCloseDone: move.l a3,a1 * Remove node entry before dealloc
move.l 4.w,a6 * exec.library
jsr _LVORemove(a6) * Remove it!
move.l 8(a3),d0 * Get screen pointer
beq.s NoScrPtr * No -> skip
cmp.l WBScreen+8(pc),d0 * Is WB screen?
beq.s ScreenCloseLoop * Don't close it!
move.l d0,a0
move.l sc_Title(a0),d2 * Save screen title string for dealloc
move.l _IntBase(pc),a6 * We need intuition.library
jsr _LVOCloseScreen(a6) * Close the screen
move.l d2,a0 * Deallocate title string (don't forget!)
CALLINIB iniFreeNameStr * Deallocate name string
NoScrPtr: moveq #24,d0 * Deallocate screen storage buffer
move.l a3,a1
CALLINIB iniFreePMem * Use iniFreePMem() to deallocate
bra ScreenCloseLoop * Deallocate next entry
ScreenCloseDone: move.l DefINIFile(pc),a0
CALLINIB iniClose * Close INI file and deallocate memory
move.l _GfxBase(pc),a1
move.l 4.w,a6
jsr _LVOCloseLibrary(a6) * Close graphics.library
move.l _IntBase(pc),a1
move.l 4.w,a6
jsr _LVOCloseLibrary(a6) * Close intuition.library
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
_IntBase: dc.l 0
_GfxBase: dc.l 0
DefINIFile: dc.l 0
CurrentContext: dc.l 0
ScrColorTable: ds.w 256
DefaultColTab: dc.w $000,$fff,$777,$ccc
dc.w $444,$555,$666,$888
dc.w $111,$222,$aaa,$333
dc.w $999,$ddd,$eee,$bbb
ds.w 240
Screens: dc.l WBScreen * Initialize nodes automatically
dc.l 0
dc.l WBScreen
WBScreen: dc.l Screens+4
dc.l Screens
dc.l 0
WBScrWin: dc.l WBScrWin+4
dc.l 0
dc.l WBScrWin
NewScreenStr: dc.w 0,0,640,256
dc.w 4
dc.b 1,0
dc.w $8000
dc.w CUSTOMSCREEN
dc.l 0
dc.l 0
dc.l 0
dc.l 0
NewWindowStr: dc.w 0,0,640,256
dc.b 1,0
dc.l $200
dc.l $100f
dc.l 0
dc.l 0
dc.l 0
dc.l 0
dc.l 0
dc.w 0,0,640,256
dc.w CUSTOMSCREEN
ININame: ININAME
IntName: dc.b 'intuition.library',0
GfxName: dc.b 'graphics.library',0
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
ScreenContext: dc.b 'Screen'
ScreenNum: ds.b 10
WindowContext: dc.b 'Window'
WindowNum: ds.b 10
LeftEdgeName: dc.b 'LeftEdge',0
TopEdgeName: dc.b 'TopEdge',0
WidthName: dc.b 'Width',0
HeightName: dc.b 'Height',0
DepthName: dc.b 'Depth',0
ViewModesName: dc.b 'ViewMode',0
TitleName: dc.b 'Title',0
ColorTableName: dc.b 'ColorTable',0
IDCMPName: dc.b 'IDCMP',0
FlagsName: dc.b 'Flags',0
ScreenName: dc.b 'Screen',0
MinWidthName: dc.b 'MinWidth',0
MinHeightName: dc.b 'MinHeight',0
MaxWidthName: dc.b 'MaxWidth',0
MaxHeightName: dc.b 'MaxHeight',0
DefaultScrTitle: dc.b 'Example INI Test Screen © 1999 by Basty/Seasons',0
DefaultWinTitle: dc.b 'Example INI Test Window © 1999 by Basty/Seasons',0