Index: kernel/forth.c
===================================================================
--- kernel/forth.c	(revision 1041)
+++ kernel/forth.c	(working copy)
@@ -1157,6 +1157,12 @@
 {
 	const ucell b = POP();
 	const ducell a = DPOP();
+	
+	if (b == 0) { // can't divide by zero
+            PUSH(0);
+	    DPUSH(0);
+            return;
+	}
 #ifdef NEED_FAKE_INT128_T
         if (a.hi != 0) {
             fprintf(stderr, "mudivmod called (0x%016llx %016llx / 0x%016llx)\n",
@@ -1610,6 +1616,20 @@
 	memset(src, value, count);
 }
 
+/*
+ *  filll       ( addr len byte -- )
+ */
+static void filll(void)
+{
+    ucell value = POP();
+	ucell count = POP();
+	ucell *dest = (ucell *)cell2pointer(POP());
+	
+	int i;
+	for (i = 0; i <= count / 4; i++) {
+	    dest[i] = value;	
+	}
+}
 
 /*
  *  unaligned-w@  ( addr -- w )
@@ -1963,4 +1983,5 @@
     do_encode_file,         /* $encode-file */
     do_debug_xt,            /* (debug  */
     do_debug_off,           /* (debug-off) */
+    filll                   /* filll */
 };
Index: kernel/bootstrap.c
===================================================================
--- kernel/bootstrap.c	(revision 1041)
+++ kernel/bootstrap.c	(working copy)
@@ -89,7 +89,7 @@
 	"here", "here!", "dobranch", "do?branch", "unaligned-w@",
 	"unaligned-w!", "unaligned-l@", "unaligned-l!", "ioc@", "iow@",
 	"iol@", "ioc!", "iow!", "iol!", "i", "j", "call", "sys-debug",
-	"$include", "$encode-file", "(debug", "(debug-off)"
+	"$include", "$encode-file", "(debug", "(debug-off)", "filll"
 };
 
 /*
Index: forth/admin/iocontrol.fs
===================================================================
--- forth/admin/iocontrol.fs	(revision 1041)
+++ forth/admin/iocontrol.fs	(working copy)
@@ -80,6 +80,7 @@
 ;
 
 : io-emit ( char -- )
+  stdout @ 0= if drop exit then \ make sure stdout pointer is not null
   io-out-char c!
   io-out-char 1 " write" stdout @ $call-method drop
 ;
Index: forth/bootstrap/bootstrap.fs
===================================================================
--- forth/bootstrap/bootstrap.fs	(revision 1041)
+++ forth/bootstrap/bootstrap.fs	(working copy)
@@ -1413,10 +1413,135 @@
   here last @ , latest !            \ write backlink and set latest
  ;
 
+\ 
+\ Defer required by BootX
+\ 
 
+defer spin
+
+\ 
+\ Local Variables (Apple specific)
+\ 
+
+\ 
+: has-locals ( -- true/false )
+  skipws
+  ib >in @ + c@ 7b <>
+  if false exit then
+  ib >in @ + 1+ c@ 20 >
+  if false exit then
+
+  true
+ ;
+
+: comp-str-char ( str len char -- true/false )
+  swap 1 <> if 2drop false exit then
+  swap c@ <> if false exit then
+  true
+ ;
+
+variable locals_wordlist
+variable locals_state \ 0 - reading args
+                      \ 1 - ;
+                      \ 2 - reading vars
+: read-locals ( -- addr0 .. addrN addrCount )
+  has-locals
+  not if 0 false exit then \ no locals
+
+  0 locals_state !
+  0 >r
+
+  s" get-current" $find drop execute
+  s" wordlist" $find drop execute
+  dup locals_wordlist !
+  s" set-current" $find drop execute
+
+  parse-word 2drop \ ditch the {
+
+  begin
+    parse-word
+
+    2dup 3b comp-str-char \ check for ;
+    if 1 locals_state ! then
+
+    2dup 7d comp-str-char \ check for }
+    not
+  while
+    locals_state @ 1 <> if \ the ; is not a local variable so ignore it
+      header
+
+      locals_state @ 0= if \ only save the address if it is an arg
+        r>
+        here na1+ >r
+        1+ >r
+      then
+
+      3 , 0 ,
+      reveal
+    else \ if we hit a ; then move to next state
+      2drop
+      2 locals_state !
+    then
+  repeat
+
+  2drop
+
+  s" set-current" $find drop execute
+
+  r> 0
+  begin
+    2dup
+    >
+  while
+    r> -rot
+    1+
+  repeat
+
+  drop
+
+  true
+ ;
+
+: begin-locals ( addr0 .. addrN count hasLocals -- )
+  not if drop exit then
+
+  dup 0> if
+    0 do
+      ['] (lit) , , ['] ! ,
+    loop
+  else drop then
+
+  s" get-order" $find drop execute
+  locals_wordlist @
+  swap 1+
+  s" set-order" $find drop execute
+ ;
+
+: end-locals ( -- )
+  locals_wordlist @ 0= if exit then
+
+  0 locals_wordlist !
+
+  s" get-order" $find drop execute
+  swap drop 1-
+  s" set-order" $find drop execute
+ ;
+
+: -> parse-word $find drop na1+
+  ['] (lit) , , ['] ! ,
+ ; immediate
+
+\ 
+\ 7.3.9.1 Defining words
+\ 
+
 : :
-  parse-word header
-  1 , ]
+  parse-word >r >r
+  read-locals
+  r> r> header
+  1 ,
+  begin-locals
+  ]
   ;
 
 : :noname 
@@ -1426,6 +1551,7 @@
   ;
 
 : ;
+  end-locals
   ['] (semis) , reveal ['] [ execute
   ; immediate
 
Index: fs/hfsplus/hfsp_volume.c
===================================================================
--- fs/hfsplus/hfsp_volume.c	(revision 1041)
+++ fs/hfsplus/hfsp_volume.c	(working copy)
@@ -302,7 +302,7 @@
 	os_read(fd, vol, 2, HFSP_BLOCKSZ_BITS);
 
 	if (__be16_to_cpu(vol[0]) == HFS_VOLHEAD_SIG &&
-		__be16_to_cpu(vol[0x7c]) == HFSP_VOLHEAD_SIG) {
+		__be16_to_cpu(vol[0x3e]) == HFSP_VOLHEAD_SIG) {
 		ret = -1;
 	} else if (__be16_to_cpu(vol[0]) == HFSP_VOLHEAD_SIG) {
 		ret = -1;
Index: arch/ppc/qemu/init.c
===================================================================
--- arch/ppc/qemu/init.c	(revision 1041)
+++ arch/ppc/qemu/init.c	(working copy)
@@ -250,12 +250,14 @@
     push_str("icache-block-size");
     fword("property");
 
-    PUSH(fw_cfg_read_i32(FW_CFG_PPC_TBFREQ));
+    /* XXX - Mac OS X needs valid values for timebase-frequency and clock-frequency
+       for scheduling to work. These are just temporary values and shouldn't be hardcoded here. */
+    PUSH(16600000);
     fword("encode-int");
     push_str("timebase-frequency");
     fword("property");
 
-    PUSH(fw_cfg_read_i32(FW_CFG_PPC_CPUFREQ));
+    PUSH(266000000);
     fword("encode-int");
     push_str("clock-frequency");
     fword("property");
Index: packages/video.c
===================================================================
--- packages/video.c	(revision 1041)
+++ packages/video.c	(working copy)
@@ -281,6 +281,42 @@
 	fill_rect( color_ind, x, y, w, h );
 }
 
+static void
+video_draw_rect( void )
+{
+	int h = POP();
+	int w = POP();
+	int y = POP();
+	int x = POP();
+	unsigned char* img = (unsigned char*)cell2pointer(POP());
+	char *pp;
+
+ 	if (!video.has_video || x < 0 || y < 0 || w <= 0 || h <= 0 ||
+		x + w > video.fb.w || y + h > video.fb.h)
+		return;
+
+	pp = (char*)video.fb.mphys + video.fb.rb * y;
+	for( ; h--; pp += video.fb.rb ) {
+		int ww = w;
+		
+		if( video.fb.depth == 24 || video.fb.depth == 32 ) {
+			unsigned long *p = (unsigned long*)pp + x;
+			while( ww-- )
+				*p++ = get_color(*img++);
+		} else if( video.fb.depth == 16 || video.fb.depth == 15 ) {
+			unsigned short *p = (unsigned short*)pp + x;
+			while( ww-- )
+				*p++ = get_color(*img++);
+		} else {
+                        char *p = (char *)((unsigned short*)pp + x);
+
+			while( ww-- )
+				*p++ = get_color(*img++);
+		}
+	}
+
+}
+
 /* ( addr len -- actual ) */
 static void
 video_write(void)
@@ -299,6 +335,7 @@
 	{"dimensions",		video_dimensions	},
 	{"set-colors",		video_set_colors	},
 	{"fill-rectangle",	video_fill_rect		},
+	{"draw-rectangle",	video_draw_rect		},
 	{"color!",		video_color_bang	},
 	{"write",		video_write		},
 };
@@ -332,6 +369,9 @@
 	video.has_video = 1;
 	video.pal = malloc( 256 * sizeof(unsigned long) );
 
+	PUSH(video.fb.mphys);
+	feval("to frame-buffer-adr");
+
 #ifdef CONFIG_PPC
         s = (video.fb.mphys & 0xfff);
         size = ((video.fb.h * video.fb.rb + s) + 0xfff) & ~0xfff;
Index: packages/mac-parts.c
===================================================================
--- packages/mac-parts.c	(revision 1041)
+++ packages/mac-parts.c	(working copy)
@@ -165,9 +165,12 @@
 		for (parnum = 1; parnum <= __be32_to_cpu(par.pmMapBlkCnt); parnum++) {
 			SEEK( bs * parnum );
 			READ( &par, sizeof(par) );
-			if( __be16_to_cpu(par.pmSig) != DESC_PART_SIGNATURE ||
-                            !__be32_to_cpu(par.pmPartBlkCnt) )
+			if( __be16_to_cpu(par.pmSig) != DESC_PART_SIGNATURE) {
 				break;
+			}
+			if ( !__be32_to_cpu(par.pmPartBlkCnt) ) {
+				continue; /* Just a void partition, ignore it. */
+			}
 
 			DPRINTF("found partition type: %s with status %x\n", par.pmPartType, __be32_to_cpu(par.pmPartStatus));
 
@@ -200,15 +203,26 @@
 
 	} else {
 		/* Another partition was explicitly requested */
-		SEEK( bs * parnum );
-		READ( &par, sizeof(par) );
+		
+		/* We have to find the first valid partition corresponding to the given number.
+		   This is because Apple sometimes includes a bunch of extra partitions that
+		   BootX expects to be ignored */
+		while (parnum < par.pmMapBlkCnt) {
+			SEEK( bs * parnum );
+			READ( &par, sizeof(par) );
 
-		if( (__be32_to_cpu(par.pmPartStatus) & kPartitionAUXIsValid) &&
-			    (__be32_to_cpu(par.pmPartStatus) & kPartitionAUXIsAllocated) &&
-			    (__be32_to_cpu(par.pmPartStatus) & kPartitionAUXIsReadable) ) {
+			/* Check if valid, also device driver partitions are expected to be ignored */
+			if( (__be32_to_cpu(par.pmPartStatus) & kPartitionAUXIsValid) &&
+				    (__be32_to_cpu(par.pmPartStatus) & kPartitionAUXIsAllocated) &&
+				    (__be32_to_cpu(par.pmPartStatus) & kPartitionAUXIsReadable) && 
+				    !(__be32_to_cpu(par.pmPartStatus) & kPartitionIsRealDeviceDriver)) {
 
-			offs = (long long)__be32_to_cpu(par.pmPyPartStart) * bs;
-			size = (long long)__be32_to_cpu(par.pmPartBlkCnt) * bs;
+				offs = (long long)__be32_to_cpu(par.pmPyPartStart) * bs;
+				size = (long long)__be32_to_cpu(par.pmPartBlkCnt) * bs;
+				break;
+			}
+
+			parnum++;
 		}
 	}
 
Index: drivers/adb_kbd.c
===================================================================
--- drivers/adb_kbd.c	(revision 1041)
+++ drivers/adb_kbd.c	(working copy)
@@ -43,10 +43,13 @@
 
 static void keyboard_read(void);
 
+static void keyboard_get_key_map(void);
+
 NODE_METHODS( keyboard ) = {
 	{ "open",		keyboard_open		},
 	{ "close",		keyboard_close		},
 	{ "read",               keyboard_read		},
+	{ "get-key-map",	keyboard_get_key_map	},
 };
 
 /* VT100 escape sequences */
@@ -566,3 +569,18 @@
 	}
 	PUSH(i);
 }
+
+static unsigned char fake_keymap[32] = {
+	0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 
+};
+
+static void keyboard_get_key_map(void)
+{
+	/* This is a bit of a hack since BootX requires a get-key-map word.
+	   In the future this should be changed to give the actual current keymap, 
+	   but since this only effects keyboard input in BootX it isn't a priority. */
+	PUSH( (int)fake_keymap );
+}
