Release 941227
[wine/multimedia.git] / DEVELOPERS-HINTS
blobecca5a0563a9df5c13c863f978dd02a9526916ea
1 This is intend to be a document to help new developers get started.
2 Existing developers should feel free to add there comments.
4 SUBMITTING YOUR WORK:
6 Submissions of code for inclussion into Wine should be sent to
7 wine-new@amscons.com (Bob Amstadt).  You MUST provide a suitable
8 ChangeLog entry for any work that you submit.  I prefer new code
9 to be submitted as unified diffs (diff -u) off of the latest release.  
10 Releases are every Tuesday evening (approximately 17:00 PST or 
11 Wednesday 01:00 GMT).
13 MEMORY AND SEGMENTS:
15 NE (Win16) executables consist of multiple segments.  The Wine loader
16 loads each segment into a unique location the Wine processes memory
17 and assigns a selector to that segment.  To make address conversion
18 simpler, Wine loads the segments in such a way that the segmented
19 address (16:16) is stored in memory the same way as the 32-bit linear
20 address.  For example, the segmented address 1237:89AB can be at the
21 address 0x123789AB in the Wine process space.
23 This also implies that a Win16 program cannot access any arbitrary
24 memory location.  If a pointer needs to be returned to a Win16 program,
25 then the memory block must be allocated using either GlobalAlloc()
26 or HEAP_Alloc().  The HEAP_* functions are faster than the Global*
27 functions but are only capable of managing a 64k memory block.  The
28 HEAP_* functions are used to implement local heaps.  Wine should
29 never call Local* functions.  These functions are reserved for use
30 by Win16 programs only!
32 The following code fragment should be used to establish a new Wine
33 local heap:
35         #include "heap.h"
37         #define MY_HEAP_SIZE    0x10000         /* Must be <= 64k */
39         int MyHeapHandle;
40         void *MyHeapBase;
41         MDESC *MyHeap;
43                 ...
45         int InitMyHeap()
46         {
47             MyHeapHandle = GlobalAlloc(GMEM_FIXED, MY_HEAP_SIZE);
48             if (MyHeapHandle == 0)
49                 return -1;
50             MyHeapBase = GlobalLock(MyHeapHandle);
51             HEAP_Init(&MyHeap, MyHeapBase, MY_HEAP_SIZE);
52             return 0;
53         }
55 Memory blocks greater than 64 kilobytes in length must be allocated
56 using GlobalAlloc().  Because of our special memory mapping, GlobalLock()
57 cannot be used to obtain the address of a linearly accessible memory
58 block that is greater than 64kB in length.  Instead GlobalLinearLock()
59 should be used.  The inverse function GlobalLinearUnlock() must be 
60 called before the block can be freed with GlobalFree().
62 API ENTRY POINTS:
64 Because Win16 programs use a 16-bit stack and because they can only
65 call 16:16 addressed functions, all API entry points must be at low
66 address offsets and must have the arguments translated and moved to
67 Wines 32-bit stack.  This task is handled by the code in the "if1632"
68 directory.  To define a new API entry point handler you must place a
69 new entry in the appropriate API specification file.  These files are
70 named *.spec.  For example, the API specification file for the USER DLL
71 is contained in the file user.spec.  These entries are processed by
72 the "build" program to create dll_*.s and dll_tab_*.c.  The dll_*.s
73 files contain the entry point code for each API call, and the dll_tab_*.s
74 files contain tables used by relay.c to translate arguments and transfer
75 control to the proper handler.  The format of the *.spec files is
76 documented in the file "tools/build-spec.txt".
78 REGISTER FUNCTIONS:
80 Some functions are defined as type "register" in the DLL specification files.
81 Inorder to return values in the registers to the WIN16 program, the handler
82 function must exit by calling ReturnFromRegisterFunc().  Look at the function
83 DOS3Call() for an example of how this works.
85 DEBUG MESSAGES:
87 To display a message only during debugging, you normally write something
88 like this:
90 #ifdef DEBUG_WIN
91         printf("abc...");
92 #endif
94 You can write this shorter (and better) in this way:
96         dprintf_win(stddeb,"abc...");
98 All symbols of the form dprintf_xxxx are macros defined in include/debug.h .
99 The macro-definitions are generated by the shell-script tools/make_debug. It
100 scans the source code for symbols of this forms and puts the necessary
101 macro definitions in include/debug.h and include/stddebug.h . These macros
102 test for the symbol DEBUG_XXXX (e.g. dprintf_win refers to DEBUG_WIN) being 
103 defined and thus decided whether to actually display the text. If you want
104 to enable specific types of messages, simply put the corresponding
105 #define DEBUG_XXXX in include/stddebug.h . If you want to enable or disable
106 a specific type of message in just one c-source-file, put the corresponding 
107 #define DEBUG_XXXX or #undefine DEBUG_XXXX between #include<stddebug.h> and
108 #include <debug.h> in that specific file. In addition you can change the 
109 types of displayed messages by supplying the "-debugmsg" option to Wine. 
110 If your debugging code is more complex than just printf, you can use the
111 symbols debugging_XXX as well. These are true when XXX is enabled, either
112 permanent or in the command line. So instead of writing
114 #ifdef DEBUG_WIN
115         DumpSomeStructure(&str);
116 #endif
118 write
119         if(debugging_win)DumpSomeStructure(&str);
120 Don't worry about the inefficiency of the test. If it is permanently 
121 disabled (thus debugging_win is 0 at compile time), the compiler will 
122 eliminate the dead code.
124 The file handle "stddeb" is intended for displaying standard informational
125 messages, whereas "stdnimp" is intended for displaying messages concerning
126 not yet implemented functions.
128 You have to start tools/make_debug only if you introduced a new macro,
129 e.g.  dprintf_win32s - not if you just changed one of the #define
130 DEBUG_XXX's in include/stddebug.h or in a specific file.