View Full Version: Skin selector - Maybe a tutorial

meos32 >>Programming >>Skin selector - Maybe a tutorial


vhanla- 05-19-2007
Skin selector - Maybe a tutorial
Today we're going to build a program to apply a skin ( *.skn ) with by selecting and double clicking or just pressing enter, so this programs are recommended to have. - KFM : Kolibri File Manager from Mario79 - and of course a SKIN file (recommended 18Kbytes less in size) I know there is another soft already done for this, but that uses a list where you should put the path for the skins you have. (notice that I'm not understimating that work because that inspired me ) OK: why a skin chooser ? Let's tell you that when you want to change a skin you need to do the following: 1st: start DESKTOP application 2nd: put the correct path to the skin you have IMHO this is a time consuming task 3rd: press LOAD and if you're lucky it will load (maybe a the path was incorrect ). If it didn't work you need to find out the correct location of your file and retry writing the correct path again. :twisted: Ok: now I've seen that KFM ( a file explorer ) has a "kfm.ini" file where you can add associations. So what we need is a program that catches the params passed (path to skin file) and load the file to apply the skin ( sounds fast, doesn't it? ) Ok, let's see which functions to use: - function 48 for appearance - and subfunction 8 to apply skin ( this function only needs a format to open a file, so we don't need to worry about how to open a file ) this is what we need to do to apply a skin: mov eax,48 mov ebx,8 mov ecx, here goes a pointer to the file info to open int 0x40 ; this calls the interrupt to finish If you've noticed, that's the only thing we need to apply. However, we need to pass a parameter, maybe you don't know how to do it.... so in a common kolibri or menuet program it needs a header to recognize and initialize a program... and blah here is the header what we will use use32 org 0x0 db 'MENUET01' ; 8 bytes ID dd 1 ; header version dd START ; points to the start of the program dd I_END ; with this label it gets the size of the program dd 0x100000 ; amount of memory to use dd 0x70000 ; esp dd I_PARAM,0 ; params, icon ; I_PARAM points a location Did you notice that I_PARAM is part of the header? I guess so. So we need to point a location to put the params that the application has been passed. So before loading a skin file we need to figure out if a param has been passed with this code: cmp [I_PARAM], byte 0 jnz ApplySkin ; if there is no params passed just end the prog mov eax,-1 ; this will end the program int 0x40 ApplySkin: . . here oges the function 48 that applies the skin . I_PARAM: times 256 rb 0 ; we reserve a memory area filled with zeroes, so it should change if a param has been passed what left is the fileinfo that needs function 48 to open a file fileinfo: dd 0 ; 0=read a file ---- 8=read file with LBA dd 0 ; offset to read from (lets read from the beggining of the file ) dd max_file_size ; amount to load from the file dd filebuf ; this points to a buffer where we should put the data read dd sysbuf ; this is for system's operation (needs 4096 bytes ) I_PARAM: times 256 rb 0 ; maximum number of characters for a fat32 path length I guess filebuf: rb max_file_size ; the buffer I was talking 'bout sysbuf: times 4096 rb 0 rb 0x40 I use RB instead of DB to use memory instead of HD so our prog won't get bigger in size. :D I added other things that are not intended for the purpose of this tut. However they are commented. Let's see the full source code or if you like yo can see it here coloured http://vhanla.up.md/highlight.php?source=sknsel.asm ; ; Skin Selector v0.1 ; ; author: vhanla ; ; purpose: to pass a file name as a parameter and open it to apply (*.skn) ; ; FILENAME : SKNSEL.ASM ; ; compile with FASM WWIDTH = 400 ; window's width WHEIGHT = 50 ; window's height max_file_size = 20000 ;bytes - because I've seen .skn files with less size use32 org 0x0 db 'MENUET01' ; 8bytes id dd 1 ; header version dd START ; start of code dd I_END ; size of image dd 0x100000 ; memory for app dd 0x70000 ; esp dd I_PARAM,0 ; params and icon START: call draw_window ; I draw it first to show the user this soft worked cmp [I_PARAM],byte 0 ; let's see if a parameter has been passed jnz ApplySkn ; However is necessary to pass a parameter to this soft to get it work ; you can use KFM to handle it, adding the following lines to its ini file ; skn /rd/1/sknsel ; of course you should change the path for this prog or just copy to the RD ; of course there are other softs that can pass params to a prog before launching ; but i prefer KFM it's easily configurable mov eax,-1 int 0x40 ApplySkn: mov eax,48 ; graphic funcs mov ebx,8 ; function for setting a skin mov ecx,fileinfo int 0x40 ; it's not necessary to handle errors since it will not set an invalid skin mov edx,I_PARAM mov esi,255 call draw_text call delay_and_end draw_window: ; lets find out the screen size mov eax,14 ; get screen size int 0x40 ; it will return in EAX as 0xXXXXYYYY X and Y coordinates mov ebx,eax ; copy to EBX which will hold the X coordinates for the window mov ecx,eax ; copy to ECX which will hold the Y coordinates for the window shr ebx,1 ; divide EBX by 2 : 0xXXXXYYYY to 0x0XXXXYYY xor bx,bx ; lets clear XYYY so we get 0x0XXX0000 sub ebx,(WWIDTH/2)*65536 ; subtract half width add ebx,WWIDTH ; add the width shr ecx,1 ; divide by 2 so 0xXXXXYYYY to 0x0XXXXYYY and ecx,0x00000FFF ; clear Xs so we get 0X00000YYY sub cx,WHEIGHT/2; subtract half height shl ecx,16 ; move the resultant to the upper part of ECX : 0xYYYY???? add ecx,WHEIGHT ; we add the height ; now let's draw the centered window mov eax,0 ; draw using EBX and ECX : X+width and Y+height respectively mov edx,0x03ffffff mov esi,0x01000000 mov edi,0x00324032 int 0x40 ret draw_text: mov eax,4 ; writes a text using EDX for string and ESI for length of string mov ebx,12 shl 16 + 32 ; it means 0xXXXXYYYY i.e. the coordinates mov ecx,0x00232323 int 0x40 ret delay_and_end: mov eax,5 ; delay mov ebx,100 int 0x40 mov eax,-1 int 0x40 fileinfo: dd 0 ;read a file dd 0 ;offset to read from dd max_file_size dd filebuf dd sysbuf I_PARAM: times 256 rb 0 ; maximum number of characters for a fat32 path length I guess filebuf: rb max_file_size sysbuf: times 4096 rb 0 rb 0x40 I_END: Okay, I guess that's all... it only lefts to set it up for KFM. Open "kfm.ini" and add the following lines into the <>files_associations part. skn /rd/1/sknsel skn = the file extension to use with sknsel = the program we created, notice it is located in the Ram Drive, you should change it to wherever it is located Save the kfm.ini modified file and restart KFM. Search for a valid skin file and just double clic or press enter on it. :D and that's ALL here a gif to show you how it works. there are a lot of skins out there, I compiled some of them and archived into a file to download: http://vhanla.googlepages.com/skins.rar maybe you're wondering where to get KFM - you can find it in the forum http://meos32.7.forumer.com/viewtopic.php?t=205 or if you like I have a mirror in RAR format : http://vhanla.googlepages.com/kfm044h.rar Okay. Questions are welcome :lol: Thanks 4 Ur attention :D Here is the binary file: http://vhanla.up.md/downloads/sknsel

hidnplayr- 05-20-2007

nice tutorial vhanla, maybe you can next time edit the desktop program so that it parses I_PARAM ;)

Mario79- 05-20-2007

vhanla Congratulate, You done nice work! Thank you that use KFM :-)

RoniX- 05-24-2007

I couldn't change my skins :( that had long pathname and filename I tried using a short path and short filename and it worked!!!... maybe it's because function 58 (without long filename support) is used by function 48 to load the skin. Am I right? If I am, maybe that would be corrected. BTW: Great app for KFM and KFAR, it's a short way to change a skin... ;)

heavyiron- 05-27-2007

RoniX In new revision of kernel it's fixed by diamond. Also you can use kpack for skins. But skin selector from vhanla need some modification to work with it. ; ; Skin Selector v0.1 ; ; author: vhanla ; ; purpose: to pass a file name as a parameter and open it to apply (*.skn) ; ; FILENAME : SKNSEL.ASM ; ; compile with FASM WWIDTH = 400 ; window's width WHEIGHT = 50 ; window's height use32 org 0x0 db 'MENUET01' ; 8bytes id dd 1 ; header version dd START ; start of code dd I_END ; size of image dd 0x1000 ; memory for app dd 0x1000 ; esp dd I_PARAM,0 ; params and icon START: call draw_window ; I draw it first to show the user this soft worked cmp ,byte 0 ; let's see if a parameter has been passed jnz ApplySkn ; However is necessary to pass a parameter to this soft to get it work ; you can use KFM to handle it, adding the following lines to its ini file ; skn /rd/1/sknsel ; of course you should change the path for this prog or just copy to the RD ; of course there are other softs that can pass params to a prog before launching ; but i prefer KFM it's easily configurable or eax,-1 int 0x40 ApplySkn: mov eax,48 ; graphic funcs mov ebx,8 ; function for setting a skin mov ecx,I_PARAM ;!!! int 0x40 ; it's not necessary to handle errors since it will not set an invalid skin mov edx,I_PARAM mov esi,255 call draw_text call delay_and_end draw_window: ; lets find out the screen size mov eax,14 ; get screen size int 0x40 ; it will return in EAX as 0xXXXXYYYY X and Y coordinates mov ebx,eax ; copy to EBX which will hold the X coordinates for the window mov ecx,eax ; copy to ECX which will hold the Y coordinates for the window shr ebx,1 ; divide EBX by 2 : 0xXXXXYYYY to 0x0XXXXYYY xor bx,bx ; lets clear XYYY so we get 0x0XXX0000 sub ebx,(WWIDTH/2)*65536 ; subtract half width add ebx,WWIDTH ; add the width shr ecx,1 ; divide by 2 so 0xXXXXYYYY to 0x0XXXXYYY and ecx,0x00000FFF ; clear Xs so we get 0X00000YYY sub cx,WHEIGHT/2; subtract half height shl ecx,16 ; move the resultant to the upper part of ECX : 0xYYYY???? add ecx,WHEIGHT ; we add the height ; now let's draw the centered window mov eax,0 ; draw using EBX and ECX : X+width and Y+height respectively mov edx,0x03ffffff mov esi,0x01000000 mov edi,0x00324032 int 0x40 ret draw_text: mov eax,4 ; writes a text using EDX for string and ESI for length of string mov ebx,12 shl 16 + 32 ; it means 0xXXXXYYYY i.e. the coordinates mov ecx,0x00232323 int 0x40 ret delay_and_end: mov eax,5 ; delay mov ebx,100 int 0x40 or eax,-1 int 0x40 I_PARAM: times 256 rb 0 ; maximum number of characters for a fat32 path length I guess I_END:

heavyiron- 05-27-2007

Or maybe such variant (without drawing window): ; ; Skin Selector v0.2 ; ; author: vhanla ; ;Filename: sknsel.asm ; ; purpose: to pass a file name as a parameter and open it to apply (*.skn) ; ; compile with FASM use32 org 0x0 db 'MENUET01' ; 8bytes id dd 1 ; header version dd START ; start of code dd I_END ; size of image dd 0x1000 ; memory for app dd 0x1000 ; esp dd I_PARAM,0 ; params and icon START: cmp ,byte 0 ; let's see if a parameter has been passed jnz ApplySkn or eax,-1 int 0x40 ApplySkn: mov eax,48 ; graphic funcs mov ebx,8 ; function for setting a skin mov ecx,I_PARAM ;!!! int 0x40 or eax,-1 int 0x40 I_PARAM: times 512 rb 0 ; maximum number of characters for a fat32 path length I guess I_END:

vhanla- 05-27-2007

:lol: Great!!! Short enough to do the job !!! :P :idea: A variant of it could be added to "desktop" app in order to open the skn file fastly. BTW: The window drawing was only for testing purposes, also this comes from another app I was doing, it is a simple ZipViewer which was idea of rugxulo from http://board.flatassembler.net/topic.php?t=6144 ... this app behaves like this one, i.e. needs a parameter (Zip file) to open it... if you want you can test it, here is the source code http://vhanla.up.md/highlight.php?source=ZipV.asm Regards... :wink:

hidnplayr- 05-28-2007

maybe this ZipV, in combination with @rcher application could make a nice unzipper for kolibrios...

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.