Release 950319

Sun Mar 19 16:30:20 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)

	* [*/*]
	Implemented a new memory mapping scheme. There's no longer a
	one-to-one mapping between 16-bit and 32-bit pointers. Please see
	file DEVELOPERS-HINTS for technical details.

	* [controls/scroll.c]
	Fixed bug when dragging mouse in horizontal scrollbars.

	* [tools/build.c] [if1632/*.spec]
	Removed support for C callback functions and for re-ordering
	of the 32-bit arguments, as these were never used. This should
	allow a more efficient callback scheme to be implemented.

	* [if1632/olecli.spec]
	Reduced the number of entries to make the 16-bit code fit in 64k.
	This limitation will soon be removed.

	* [loader/ldt.c]
	Rewrote LDT manipulation functions and implemented LDT_GetEntry().

	* [memory/global.c]
	Rewrote Global*() routines to use the new selector allocation
	mechanism.

	* [memory/local.c]
	Rewrote local heap handling to use a Windows-compatible layout
	(not really finished yet).
	Implemented TOOLHELP heap-walking routines.

	* [memory/selector.c]
	Implemented LDT manipulation API functions.

Tue Mar 14 19:50:28 EST 1995 William Magro (wmagro@tc.cornell.edu)

	* [windows/defdlg.c]
	Fixed problem where dialogs closed using the System menu 
        ('Close' item or double click on close box) would
	hang Wine.

Sun Mar 12 14:28:13 1995  Michael Patra <micky@marie.physik.TU-Berlin.DE>

	* [controls/listbox.c]
	Removed most of the statements for sending a notification message
	ListBoxDirectory(), DlgDirSelect(), DlgDirList(): Improved the
	code; Borland's standard file open dialog will work now.
	
	* [misc/main.c], [misc/file.c], [miscemu/int21.c]
	Added support for new command line option "-allowreadonly". If set
	an attempt to open a read only file in write mode will be converted 
	to opening it read only (many programs try to open all files in 
	read/write mode even if they only intend to read it - this might 
	cause a few under problems under an unix-like environment where most 
	files are read only for a "normal" user)

	* [loader/selector.c]
	GetMemoryReference(): Added support for __AHIncr and __AHShift

	* [misc/dos_fs.c]
	DOS_SimplifyPath(): This routine simplifies path names ( e.g., it
	will change "/usr///local/bin/../lib//a" to "/usr/local/lib/a" )
	match(): rewritten
	
	* [objects/text.c]
	TEXT_NextLine(): Removed a bug in the handling of LF's

	* [miscemu/int21.c]
	GetFileDateTime(): Fixed. SetFileDateTime() is still broken.

Sat Mar 11 19:46:19 1995  Martin von Loewis  <loewis@informatik.hu-berlin.de>

	* [controls/menu.c]
	ChangeMenu: defaults to MF_INSERT
	InsertMenu: allow insertion even if position is one after last item

	* [if1632/Imakefile] [if1632/compobj.spec] [if1632/relay.c]
	  [if1632/storage.spec] [include/dlls.h]
	Added stubs for STORAGE.DLL and COMPOBJ.DLL

	* [if1632/user.spec] [windows/message.c]
	InSendMessage: new function

	* [include/neexe.h][include/ne_image.c]
	NE_FixupSegment: fixed handling of additive records

	* [loader/selector.c]
	GetEntryDLLName: return NULL instead of pointer to DLL.0 if not found

	* [loader/signal.c]
	win_fault: Enter debugger on SIGFPE, too

Wed Mar  1 21:47:42 1995  Cameron Heide  (heide@ee.ualberta.ca)

        * [miscemu/int*.c]
        Various minor modifications to the clock tick counter,
        FindFirst/FindNext funcs, and DPB handling.
diff --git a/loader/ne_image.c b/loader/ne_image.c
index 14914b7..0c18f4d 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -12,7 +12,6 @@
 #include <string.h>
 #include <errno.h>
 #include "neexe.h"
-#include "segmem.h"
 #include "dlls.h"
 #include "windows.h"
 #include "arch.h"
@@ -82,20 +81,20 @@
  */
 int NE_FixupSegment(struct w_files *wpnt, int segment_num)
 {
-    struct segment_descriptor_s *selector_table = wpnt->ne->selector_table;
+    WORD *selector_table = wpnt->ne->selector_table;
+    WORD selector, sel, offset;
     struct relocation_entry_s *rep, *rep1;
     struct ne_segment_table_entry_s *seg;
-    struct segment_descriptor_s *sel;
     int status, ordinal, i, n_entries, additive;
     unsigned short *sp;
-    unsigned int selector, address, next_addr;
+    unsigned int address;
     unsigned char dll_name[257], func_name[257];
 
     seg = &wpnt->ne->seg_table[segment_num];
-    sel = &selector_table[segment_num];
+    sel = selector_table[segment_num];
 
-    dprintf_fixup(stddeb, "Segment fixups for %s, segment %d, selector %x\n", 
-                  wpnt->name, segment_num, (int) sel->base_addr >> 16);
+    dprintf_fixup(stddeb, "Segment fixups for %s, segment %d, selector %04x\n", 
+                  wpnt->name, segment_num, sel );
 
     if ((seg->seg_data_offset == 0) ||
 	!(seg->seg_flags & NE_SEGFLAGS_RELOC_DATA))
@@ -128,13 +127,14 @@
 	/*
 	 * Get the target address corresponding to this entry.
 	 */
-	additive = 0;
+
+	/* If additive, there is no target chain list. Instead, add source
+	   and target */
+	additive = rep->relocation_type & NE_RELFLAG_ADDITIVE;
+	rep->relocation_type &= 0x3;
 	
 	switch (rep->relocation_type)
 	{
-	  case NE_RELTYPE_ORDINALADD:
-	    additive = 1;
-	    
 	  case NE_RELTYPE_ORDINAL:
 	    if (NE_GetModuleName(wpnt, rep->target1,
 			      dll_name) == NULL)
@@ -160,9 +160,6 @@
 		   dll_name, ordinal, selector, address);
 	    break;
 	    
-	  case NE_RELTYPE_NAMEADD:
-	    additive = 1;
-	    
 	  case NE_RELTYPE_NAME:
 	    if (NE_GetModuleName(wpnt, rep->target1, dll_name) == NULL) {
 	        fprintf(stderr,"NE_RELTYPE_NAME failed");
@@ -189,7 +186,6 @@
 	    break;
 	    
 	  case NE_RELTYPE_INTERNAL:
-    	  case NE_RELTYPE_INT1:
 	    if (rep->target1 == 0x00ff)
 	    {
 		address  = GetEntryPointFromOrdinal(wpnt, rep->target2);
@@ -198,7 +194,7 @@
 	    }
 	    else
 	    {
-		selector = selector_table[rep->target1-1].selector;
+		selector = selector_table[rep->target1-1];
 		address  = rep->target2;
 	    }
 	    
@@ -206,7 +202,7 @@
 			  i + 1, selector, address);
 	    break;
 
-	  case 7:
+	  case NE_RELTYPE_OSFIXUP:
 	    /* Relocation type 7:
 	     *
 	     *    These appear to be used as fixups for the Windows
@@ -234,69 +230,70 @@
 	    return -1;
 	}
 
-	/*
-	 * Stuff the right size result in.
-	 */
-	sp = (unsigned short *) ((char *) sel->base_addr + rep->offset);
-	if (additive)
-	{
-	    if (FindDLLTable(dll_name) == NULL)
-		additive = 2;
-	    dprintf_fixup(stddeb,
-		   "%d: ADDR TYPE %d,  TYPE %d,  OFFSET %04x,  ",
-		   i + 1, rep->address_type, rep->relocation_type, 
-		   rep->offset);
-	    dprintf_fixup(stddeb,"TARGET %04x %04x\n", 
-		    rep->target1, rep->target2);
-	    dprintf_fixup(stddeb, "    Additive = %d\n", additive);
-	}
-	
+        /* I'm not sure why a DLL entry point fixup could be additive.
+           Old code used to ignore additive if the target is a built-in
+           DLL. This doesn't seem to work for __AHSHIFT */
+        if (additive && FindDLLTable(dll_name) != NULL)
+            dprintf_fixup(stddeb,"Additive for builtin???\n"
+                          "%d: ADDR TYPE %d, TYPE %d, OFFSET %04x, "
+                          "TARGET %04x %04x\n",
+                          i+1, rep->address_type, rep->relocation_type,
+                          rep->offset, rep->target1, rep->target2);
+
+	offset = rep->offset;
+
 	switch (rep->address_type)
 	{
 	  case NE_RADDR_LOWBYTE:
-	    dprintf_fixup(stddeb,"Unhandled address type NE_RADDR_LOWBYTE\n");
-	    return -1;
+            do {
+                sp = PTR_SEG_OFF_TO_LIN( sel, offset );
+                dprintf_fixup(stddeb,"    %04x:%04x:%04x BYTE%s\n",
+                              sel, offset, *sp, additive ? " additive":"");
+                offset = *sp;
+		if(additive)
+                    *(unsigned char*)sp = (unsigned char)(address & 0xFF);
+		else
+                    *(unsigned char*)sp = (unsigned char)((address+offset) & 0xFF);
+            }
+            while (offset != 0xffff && !additive);
+            break;
+
 	  case NE_RADDR_OFFSET16:
 	    do {
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x OFFSET16\n",
-		       (unsigned int) sp >> 16, (int) sp & 0xFFFF, *sp);
-		next_addr = *sp;
+                sp = PTR_SEG_OFF_TO_LIN( sel, offset );
+		dprintf_fixup(stddeb,"    %04x:%04x:%04x OFFSET16%s\n",
+                              sel, offset, *sp, additive ? " additive" : "" );
+		offset = *sp;
 		*sp = (unsigned short) address;
-		if (additive == 2)
-		    *sp += next_addr;
-		sp = (unsigned short *) ((char *) sel->base_addr + next_addr);
+		if (additive) *sp += offset;
 	    } 
-	    while (next_addr != 0xffff && !additive);
-
+	    while (offset != 0xffff && !additive);
 	    break;
 	    
 	  case NE_RADDR_POINTER32:
 	    do {
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x POINTER32\n",
-		       (unsigned int) sp >> 16, (int) sp & 0xFFFF, *sp);
-		next_addr = *sp;
-		*sp     = (unsigned short) address;
-		if (additive == 2)
-		    *sp += next_addr;
-		*(sp+1) = (unsigned short) selector;
-		sp = (unsigned short *) ((char *) sel->base_addr + next_addr);
+                sp = PTR_SEG_OFF_TO_LIN( sel, offset );
+		dprintf_fixup(stddeb,"    %04x:%04x:%04x POINTER32%s\n",
+                              sel, offset, *sp, additive ? " additive" : "" );
+		offset = *sp;
+		*sp    = (unsigned short) address;
+		if (additive) *sp += offset;
+		*(sp+1) = selector;
 	    } 
-	    while (next_addr != 0xffff && !additive);
-
+	    while (offset != 0xffff && !additive);
 	    break;
 	    
 	  case NE_RADDR_SELECTOR:
 	    do {
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x SELECTOR\n",
-		       (unsigned int) sp >> 16, (int) sp & 0xFFFF, *sp);
-		next_addr = *sp;
-		*sp     = (unsigned short) selector;
-		sp = (unsigned short *) ((char *) sel->base_addr + next_addr);
-		if (rep->relocation_type == NE_RELTYPE_INT1) 
-		    break;
+                sp = PTR_SEG_OFF_TO_LIN( sel, offset );
+		dprintf_fixup(stddeb,"    %04x:%04x:%04x SELECTOR%s\n",
+                              sel, offset, *sp, additive ? " additive" : "" );
+		offset = *sp;
+		*sp    = (unsigned short) selector;
+		if(additive)
+                    fprintf(stderr,"Additive selector, please report\n");
 	    } 
-	    while (next_addr != 0xffff && !additive);
-
+	    while (offset != 0xffff && !additive);
 	    break;
 	    
 	  default:
@@ -331,10 +328,10 @@
     WIN_StackSize = wpnt->ne->ne_header->stack_length;
     WIN_HeapSize = wpnt->ne->ne_header->local_heap_length;
 
-    ds_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->auto_data_seg-1].selector;
-    cs_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->cs-1].selector;
+    ds_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->auto_data_seg-1];
+    cs_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->cs-1];
     ip_reg = wpnt->ne->ne_header->ip;
-    ss_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->ss-1].selector;
+    ss_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->ss-1];
     sp_reg = wpnt->ne->ne_header->sp;
 
     return CallToInit16(cs_reg << 16 | ip_reg, ss_reg << 16 | sp_reg, ds_reg);
@@ -358,15 +355,15 @@
   		exit(1);
 	    } else { /* DATA NONE DLL */
 		ds_reg = current_exe->ne->selector_table[
-		        current_exe->ne->ne_header->auto_data_seg-1].selector;
+		        current_exe->ne->ne_header->auto_data_seg-1];
 		cx_reg = 0;
 	    } else { /* DATA SINGLE DLL */
 		    ds_reg = wpnt->ne->selector_table[wpnt->ne->
-					  ne_header->auto_data_seg-1].selector;
+					  ne_header->auto_data_seg-1];
 		    cx_reg = wpnt->ne->ne_header->local_heap_length;
   	    }
   
-  	    cs_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->cs-1].selector;
+  	    cs_reg = wpnt->ne->selector_table[wpnt->ne->ne_header->cs-1];
   	    ip_reg = wpnt->ne->ne_header->ip;
   
             di_reg = wpnt->hinstance;
@@ -423,8 +420,7 @@
         wpnt->hinstance=current_nodata++;
     } else
     wpnt->hinstance = (wpnt->ne->
-		       selector_table[wpnt->ne->ne_header->auto_data_seg-1].
-		       selector);
+		       selector_table[wpnt->ne->ne_header->auto_data_seg-1]);
     if (wpnt->hinstance == 0)
     	wpnt->hinstance = 0xf000;
 #endif