From e2c20d23a4856580e1d8eabf2b57a8d6b5d78d0d Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Mon, 4 Feb 2008 11:06:11 -0600
Subject: [PATCH 1/3] add missing use fix dll path on windows

---
 extra/ogg/theora/theora.factor | 2 +-
 extra/ogg/vorbis/vorbis.factor | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/extra/ogg/theora/theora.factor b/extra/ogg/theora/theora.factor
index 0d9748a6f3..48b61b41a3 100644
--- a/extra/ogg/theora/theora.factor
+++ b/extra/ogg/theora/theora.factor
@@ -6,7 +6,7 @@ IN: ogg.theora
 
 <<
 "theora" {
-    { [ win32? ]  [ "libtheora.dll" ] }
+    { [ win32? ]  [ "theora.dll" ] }
     { [ macosx? ] [ "libtheora.0.dylib" ] }
     { [ unix? ]   [ "libtheora.so" ] }
 } cond "cdecl" add-library
diff --git a/extra/ogg/vorbis/vorbis.factor b/extra/ogg/vorbis/vorbis.factor
index 26e917ebf4..170d0ea6ef 100644
--- a/extra/ogg/vorbis/vorbis.factor
+++ b/extra/ogg/vorbis/vorbis.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 !
-USING: kernel system combinators alien alien.syntax ;
+USING: kernel system combinators alien alien.syntax ogg ;
 IN: ogg.vorbis
 
 <<

From bc3bf6b2b4ede72aa4332dd3f7b98cd85f836756 Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Mon, 4 Feb 2008 11:45:53 -0600
Subject: [PATCH 2/3] make factor compile on win64

---
 Makefile                    |  6 +++++-
 vm/Config.windows.nt.x86.32 |  1 +
 vm/Config.windows.nt.x86.64 |  6 ++++--
 vm/os-windows-nt.32.h       |  2 ++
 vm/os-windows-nt.64.h       |  2 ++
 vm/os-windows-nt.c          | 10 +++++-----
 vm/platform.h               |  9 +++++++--
 7 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 vm/os-windows-nt.32.h
 create mode 100644 vm/os-windows-nt.64.h

diff --git a/Makefile b/Makefile
index aad7fe90eb..bd1bf16c74 100755
--- a/Makefile
+++ b/Makefile
@@ -65,6 +65,7 @@ default:
 	@echo "solaris-x86-64"
 	@echo "windows-ce-arm"
 	@echo "windows-nt-x86-32"
+	@echo "windows-nt-x86-64"
 	@echo ""
 	@echo "Additional modifiers:"
 	@echo ""
@@ -125,6 +126,9 @@ solaris-x86-64:
 windows-nt-x86-32:
 	$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.32
 
+windows-nt-x86-64:
+	$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.nt.x86.64
+
 windows-ce-arm:
 	$(MAKE) $(EXECUTABLE) CONFIG=vm/Config.windows.ce.arm
 
@@ -151,7 +155,7 @@ clean:
 	rm -f factor*.dll libfactor*.*
 
 vm/resources.o:
-	windres vm/factor.rs vm/resources.o
+	$(WINDRES) vm/factor.rs vm/resources.o
 
 .c.o:
 	$(CC) -c $(CFLAGS) -o $@ $<
diff --git a/vm/Config.windows.nt.x86.32 b/vm/Config.windows.nt.x86.32
index 9a020a7bc1..603a7200ae 100644
--- a/vm/Config.windows.nt.x86.32
+++ b/vm/Config.windows.nt.x86.32
@@ -1,3 +1,4 @@
 WINDRES=windres
 include vm/Config.windows.nt
 include vm/Config.x86.32
+#error "lolllll"
diff --git a/vm/Config.windows.nt.x86.64 b/vm/Config.windows.nt.x86.64
index 1c30e64096..6d3865c2f4 100644
--- a/vm/Config.windows.nt.x86.64
+++ b/vm/Config.windows.nt.x86.64
@@ -1,4 +1,6 @@
-CC=/k/target/bin/x86_64-pc-mingw32-gcc
+#WIN64_PATH=/k/MinGW/win64/bin
+WIN64_PATH=/cygdrive/k/MinGW/win64/bin/x86_64-pc-mingw32
+CC=$(WIN64_PATH)-gcc.exe
+WINDRES=$(WIN64_PATH)-windres.exe
 include vm/Config.windows.nt
 include vm/Config.x86.64
-WINDRES = /k/target/bin/windres
diff --git a/vm/os-windows-nt.32.h b/vm/os-windows-nt.32.h
new file mode 100644
index 0000000000..9b10671ba0
--- /dev/null
+++ b/vm/os-windows-nt.32.h
@@ -0,0 +1,2 @@
+#define ESP Esp
+#define EIP Eip
diff --git a/vm/os-windows-nt.64.h b/vm/os-windows-nt.64.h
new file mode 100644
index 0000000000..1f61c2335f
--- /dev/null
+++ b/vm/os-windows-nt.64.h
@@ -0,0 +1,2 @@
+#define ESP Rsp
+#define EIP Rip
diff --git a/vm/os-windows-nt.c b/vm/os-windows-nt.c
index e356c2f674..3995b6a35a 100755
--- a/vm/os-windows-nt.c
+++ b/vm/os-windows-nt.c
@@ -57,26 +57,26 @@ long exception_handler(PEXCEPTION_POINTERS pe)
 	PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord;
 	CONTEXT *c = (CONTEXT*)pe->ContextRecord;
 
-	if(in_code_heap_p(c->Eip))
-		signal_callstack_top = (void *)c->Esp;
+	if(in_code_heap_p(c->EIP))
+		signal_callstack_top = (void *)c->ESP;
 	else
 		signal_callstack_top = NULL;
 
 	if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
 	{
 		signal_fault_addr = e->ExceptionInformation[1];
-		c->Eip = (CELL)memory_signal_handler_impl;
+		c->EIP = (CELL)memory_signal_handler_impl;
 	}
 	else if(e->ExceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO
 			|| e->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO)
 	{
 		signal_number = ERROR_DIVIDE_BY_ZERO;
-		c->Eip = (CELL)divide_by_zero_signal_handler_impl;
+		c->EIP = (CELL)divide_by_zero_signal_handler_impl;
 	}
 	else
 	{
 		signal_number = 11;
-		c->Eip = (CELL)misc_signal_handler_impl;
+		c->EIP = (CELL)misc_signal_handler_impl;
 	}
 
 	return EXCEPTION_CONTINUE_EXECUTION;
diff --git a/vm/platform.h b/vm/platform.h
index b0641176bc..66f22bbf96 100644
--- a/vm/platform.h
+++ b/vm/platform.h
@@ -1,11 +1,11 @@
 #if defined(__arm__)
 	#define FACTOR_ARM
+#elif defined(__amd64__) || defined(__x86_64__)
+	#define FACTOR_AMD64
 #elif defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
 	#define FACTOR_X86
 #elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC)
 	#define FACTOR_PPC
-#elif defined(__amd64__) || defined(__x86_64__)
-	#define FACTOR_AMD64
 #else
 	#error "Unsupported architecture"
 #endif
@@ -18,6 +18,11 @@
 	#endif
 
 	#include "os-windows.h"
+	#if defined(FACTOR_AMD64)
+		#include "os-windows-nt.64.h"
+	#elif defined(FACTOR_X86)
+		#include "os-windows-nt.32.h"
+	#endif
 #else
 	#include "os-unix.h"
 

From 87d44252c59f0a7d967157b634f10dc83acce442 Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Mon, 4 Feb 2008 12:30:23 -0600
Subject: [PATCH 3/3] add more dlls to script

---
 misc/factor.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/misc/factor.sh b/misc/factor.sh
index 032b0b3184..02f4c4a542 100755
--- a/misc/factor.sh
+++ b/misc/factor.sh
@@ -233,6 +233,16 @@ maybe_download_dlls() {
                 check_ret wget
                 wget http://factorcode.org/dlls/zlib1.dll
                 check_ret wget
+                wget http://factorcode.org/dlls/OpenAL32.dll
+                check_ret wget
+                wget http://factorcode.org/dlls/alut.dll
+                check_ret wget
+                wget http://factorcode.org/dlls/ogg.dll
+                check_ret wget
+                wget http://factorcode.org/dlls/theora.dll
+                check_ret wget
+                wget http://factorcode.org/dlls/vorbis.dll
+                check_ret wget
                 chmod 777 *.dll
                 check_ret chmod
         fi