[Vm-dev] [commit][2652] bringing some RISC OS code up to date circa 3.9

commits at squeakvm.org commits at squeakvm.org
Thu Jan 3 03:39:19 UTC 2013


Revision: 2652
Author:   rowledge
Date:     2013-01-02 19:39:18 -0800 (Wed, 02 Jan 2013)
Log Message:
-----------
bringing some RISC OS code up to date circa 3.9

Modified Paths:
--------------
    trunk/platforms/RiscOS/vm/sqArgument.c
    trunk/platforms/RiscOS/vm/sqPlatformSpecific.h
    trunk/platforms/RiscOS/vm/sqRPCEvents.c
    trunk/platforms/RiscOS/vm/sqRPCMain.c
    trunk/platforms/RiscOS/vm/sqRPCWindows.c

Modified: trunk/platforms/RiscOS/vm/sqArgument.c
===================================================================
--- trunk/platforms/RiscOS/vm/sqArgument.c	2013-01-03 02:31:11 UTC (rev 2651)
+++ trunk/platforms/RiscOS/vm/sqArgument.c	2013-01-03 03:39:18 UTC (rev 2652)
@@ -24,7 +24,7 @@
 static char** optionArray;
 int ImageVersionNumber;
 
-static char* nextOption() {
+static char* nextOption(void) {
 	if(opt >= numOptions) return 0;
 	return optionArray[opt++];
 }

Modified: trunk/platforms/RiscOS/vm/sqPlatformSpecific.h
===================================================================
--- trunk/platforms/RiscOS/vm/sqPlatformSpecific.h	2013-01-03 02:31:11 UTC (rev 2651)
+++ trunk/platforms/RiscOS/vm/sqPlatformSpecific.h	2013-01-03 03:39:18 UTC (rev 2652)
@@ -60,34 +60,45 @@
 	dst[num] = 0;\
 }
 
-
-/* undefine this to stop using my MillisecondTimer module and rely upon clock()
- * instead. You lose millisecond precision in the process */
-#define TIMERMOD
-usqInt millisecondValue(void);
-unsigned int microsecondsvalue(void);
 /* undefine clock macros that are implemented as functions */
+/* basic millisecond timer value */
 #undef ioMSecs
-#define ioMSecs()  (sqInt)(millisecondValue())
-#undef ioMicroMSecs
+
+/* less important timer, return mSec values but can be lower actual resolution */
 #undef ioLowResMSecs
-#define ioLowResMSecs() (ioMSecs())
+/* a high-res timer for debugging */
+unsigned int microsecondsvalue(void);
 
+/* define one or other of these to choose the time system in use
+   DRUCKTIMERMOD means using the TimerMod by druck; this is intended for
+   microsecond timers for unixy programs etc
+   HALTIMERMOD means using a combination of Rik Griffin's HALTimer and
+   my MillisecondTimer to keep a runing count of milliseconds
+   Currently HALTimer won't run on a RaspberryPi, so use drucks code */
+#define DRUCKTIMERMOD
+// #define HALTIMERMOD
+
+usqInt millisecondTimerValue(void);
+#define ioMSecs()  (sqInt)(millisecondTimerValue())
+#define ioLowResMSecs() (sqInt)(millisecondTimerValue())
+
+
+
 /* extended fileplugin support */
 extern int dir_DirectoryExists(char *pathString, int pathStringLength);
 extern int dir_FileExists(char *pathString, int pathStringLength);
-extern void dir_SetImageFileType(void); 
+extern void dir_SetImageFileType(void);
 
 /* Debugging support - printf is #def'd to repprint which outputs to
  * a logfile or to !Reporter if it is active
  */
-#ifdef DEBUG 
+#ifdef DEBUG
 #define PRINTF(s)\
 {\
 	printf s;\
 };
 #else
-#define PRINTF(s) 
+#define PRINTF(s)
 #endif
 
 extern int repprintf(const char * format, ...);
@@ -106,7 +117,7 @@
 	struct windowDescriptorBlock * next;
 	wimp_w			handle;
 	int				windowIndex;
-	os_coord		bitmapExtentP; 
+	os_coord		bitmapExtentP;
 	os_box			visibleArea;  // rename to visibleArea
 	int				squeakDisplayDepth;
 	osspriteop_header *	displaySprite; // the sprite pointer
@@ -123,7 +134,7 @@
 
 #define OS2PixX(val) ((val)>>scalingFactor.x)
 #define OS2PixY(val) ((val)>>scalingFactor.y)
- 
+
 #define Pix2OSX(val) ((val)<<scalingFactor.x)
 #define Pix2OSY(val) ((val)<<scalingFactor.y)
 

Modified: trunk/platforms/RiscOS/vm/sqRPCEvents.c
===================================================================
--- trunk/platforms/RiscOS/vm/sqRPCEvents.c	2013-01-03 02:31:11 UTC (rev 2651)
+++ trunk/platforms/RiscOS/vm/sqRPCEvents.c	2013-01-03 03:39:18 UTC (rev 2652)
@@ -7,7 +7,7 @@
 /* OS interface stuff                                                     */
 /**************************************************************************/
 
-/* To recompile this reliably you will need    */           
+/* To recompile this reliably you will need    */
 /* OSLib -  http://ro-oslib.sourceforge.net/   */
 /* Castle/AcornC/C++, the Acorn TCPIPLib       */
 /* and a little luck                           */
@@ -103,7 +103,7 @@
 /* Squeak expects to get kbd modifiers as the top 4bits of the 8bit char code,
  * or as the 2r1111000 bits of the buttons word. RiscOS doesnt give me the
  * modifiers with keypresses, so we have to manually collect them. SQ only
- * seems to care about them when doing primMouseButtons anyway.  
+ * seems to care about them when doing primMouseButtons anyway.
  *	ST bits:  <command><option><control><shift>
  * Notice how Macish this is!
 */
@@ -226,7 +226,7 @@
 /* 0x67 k-enter */ /* 0x0d */ 0
 };
 
- 
+
 /*** Functions ***/
 	 void DisplayPixmap(wimp_draw * wblock);
 extern	 void DisplayModeChanged(void);
@@ -286,7 +286,7 @@
 static windowDescriptorBlock * lastWindow = NULL;
 
 	/* Don't mouse poll more than once every 5 milliseconds */
-	if ( nextMousePollTick > (thisTick = millisecondValue())) return;
+	if ( nextMousePollTick > (thisTick = ioMSecs())) return;
 	nextMousePollTick = thisTick + 5;
 
 	if ( mouseButtonDown || windowActive) {
@@ -315,7 +315,7 @@
 		 * and thisWindow will be 0. At this point we'd like to know the
 		 * window that _was_ active so we can use it instead of thisWindow.
 		 * While buttonDown is true we need to maintain the same window.
-		 * 
+		 *
 		 * It is possible for a MousePoll to hpapen before a leave is processed,
 		 * (ie windowActive is improperly true) so we should check and ignore
 		 * the mouse pos.
@@ -430,7 +430,7 @@
 			UserMessage(&(pollBlock->message)); break;
 		case wimp_USER_MESSAGE_ACKNOWLEDGE	:
 			UserMessage(&(pollBlock->message)); break;
-	} 
+	}
 	return true;
 }
 
@@ -445,14 +445,14 @@
 
 #if 0
 /* this is pretty much obsolete - we can't do microsecond delays and
- * anything longer just slows Squeak down horribly */ 
+ * anything longer just slows Squeak down horribly */
 int HandleEventsWithWait(int microSecondsToDelay) {
 /* use wimp_poll_delay so that we don't return a null before
  * the end of the delay, thus giving some cpu back to everyone else
  * NB - RISC OS uses centi-Seconds for delays etc.
  */
 int pollDelay, nextWakeTick, currentTick;
-extern int getNextWakeupTick(void); 
+extern int getNextWakeupTick(void);
 	pollDelay = microSecondsToDelay /* * CLOCKS_PER_SEC / 1000000 */
 			>> 14 /* will always give small answer, but good enough */;
 	if ( microSecondsToDelay ) {
@@ -516,10 +516,10 @@
  * those times are redundant, throttle it back a little */
 static int nextPollTick = 0;
 unsigned int thisTick;
-	if ( nextPollTick > (thisTick = millisecondValue())) return false;
+	if ( nextPollTick > (thisTick = ioMSecs())) return false;
 	HandleEvents();
 	nextPollTick = thisTick +5;
-	return true; 
+	return true;
 }
 
 /****************************************/
@@ -612,7 +612,7 @@
 		if ((wblock->buttons == wimp_CLICK_SELECT)) {
 		/* select-click on iconbar icon means bring window to front
 		 * - but what if we have multiple windows?  */
-		extern void SetWindowToTop(int windowIndex); 
+		extern void SetWindowToTop(int windowIndex);
 			SetWindowToTop(1);
 			return;
 		}
@@ -621,12 +621,12 @@
 			return;
 		}
 	}
- 
+
 	/* need the window block with this handle */
 	thisWindow = (windowDescriptorBlock *)windowBlockFromHandle(wblock->w);
 	if ( thisWindow
 		&& (wblock->i == (wimp_i)wimp_ICON_WINDOW)) {
-		PRINTF(("\\t buttons %x w: %d\n", wblock->buttons, thisWindow->windowIndex)); 
+		PRINTF(("\\t buttons %x w: %d\n", wblock->buttons, thisWindow->windowIndex));
 		/* claim caret via message_claimentity() iff we
 		 *don't already have it */
 		claimCaret(wblock);
@@ -690,7 +690,7 @@
 		 * if a key maps, replace the keystate with the result
 		 */
 		unsigned int testkey = (dblock->deepkey)
-					>>wimp_DEEPKEY_KEYNUMSHIFT; 
+					>>wimp_DEEPKEY_KEYNUMSHIFT;
 		if ((testkey <= 0x67) && (testkey = keymap[testkey]) )
 			keystate = testkey;
 	} else {
@@ -743,13 +743,13 @@
 		 * can be found in c.sqRPCClipboard>fetchClipboard()
 		 */
 		case message_DATA_REQUEST: receivedDataRequest(wblock);
-								break; 
+								break;
 		case message_DATA_SAVE_ACK: receivedDataSaveAck(wblock);
 								break;
 		/* We _might_ sometime respond to DATA_LOAD & DATA_SAVE
 		 * here in order to allow dropping of text files via the
 		 * DropPlugin
-		 */ 
+		 */
 		default: return;
 	}
 }
@@ -802,21 +802,21 @@
 	evt->modifiers = modifiers;
 	evt->utf32Code = keyValue; /* what Unicode ? */
 	evt->reserved1 = 0;
-	evt->windowIndex = windowIndex; 
+	evt->windowIndex = windowIndex;
 	evt = (sqKeyboardEvent *)EventBufAppendEvent( EventTypeKeyboard);
 	evt->charCode = keyValue;
 	evt->pressCode = EventKeyChar;
 	evt->modifiers = modifiers;
 	evt->utf32Code = keyValue; /* what Unicode ? */
 	evt->reserved1 = 0;
-	evt->windowIndex = windowIndex; 
+	evt->windowIndex = windowIndex;
 	evt = (sqKeyboardEvent *)EventBufAppendEvent( EventTypeKeyboard);
 	evt->charCode = keyValue;
 	evt->pressCode = EventKeyUp;
 	evt->modifiers = modifiers;
 	evt->utf32Code = keyValue; /* what Unicode ? */
 	evt->reserved1 = 0;
-	evt->windowIndex = windowIndex; 
+	evt->windowIndex = windowIndex;
 }
 
 void EventBufAppendMouse( int buttons, int modifiers, int x, int y, int windowIndex) {
@@ -849,7 +849,7 @@
 	evt->value2 = top;
 	evt->value3 = right;
 	evt->value4 = bottom;
-	evt->windowIndex = windowIndex; 
+	evt->windowIndex = windowIndex;
 }
 
 /* key buffer functions to support older images */
@@ -887,7 +887,7 @@
 // 	if (evt->type == EventTypeKeyboard) {
 // 		PRINTF(("\\t key ev(%d) read %c\n", evt->timeStamp, ((sqKeyboardEvent *)evt)->charCode));
 // 	}
-// #endif 
+// #endif
 	return true;
 }
 
@@ -922,7 +922,7 @@
  * in the middle of one already
  */
 	HandleEvents();
-	return true; 
+	return true;
 }
 
 /* older polling state style access - completely unused by images after

Modified: trunk/platforms/RiscOS/vm/sqRPCMain.c
===================================================================
--- trunk/platforms/RiscOS/vm/sqRPCMain.c	2013-01-03 02:31:11 UTC (rev 2651)
+++ trunk/platforms/RiscOS/vm/sqRPCMain.c	2013-01-03 03:39:18 UTC (rev 2652)
@@ -7,7 +7,7 @@
 /* OS interface stuff, commandline option handling and so on              */
 /**************************************************************************/
 
-/* To recompile this reliably you will need    */           
+/* To recompile this reliably you will need    */
 /* OSLib -  http://ro-oslib.sourceforge.net/   */
 /* Castle/AcornC/C++, the Acorn TCPIPLib       */
 /* and a little luck                           */
@@ -45,20 +45,22 @@
 os_error		privateErr;
 char			versionString[20];
 static			FILE *logfile= 0;
+#ifdef HALTIMERMOD
 static			unsigned int *timerValPtr;
+#endif
 
 /* argument handling stuff  -- see c.sqArgument */
 int 			numOptionsVM;
 char			*(vmOptions[MAX_OPTIONS]);
 int 			numOptionsImage;
 char			*(imageOptions[MAX_OPTIONS]);
-            	
+
 int				headlessFlag = 0;
 int				helpMe = 0;
 int				versionMe = 0;
 int				swapMeta = 0;
 int				objectHeadroom = 4*1024*1024;
-char			*windowLabel, *taskNameArg; 
+char			*windowLabel, *taskNameArg;
 int				useDAMemory = 0;
 
 vmArg args[] = {
@@ -68,7 +70,7 @@
 		{ ARG_FLAG,   &useDAMemory, "-useDA" },
 		{ ARG_FLAG,   &swapMeta,  "-swapmeta"},
 		{ ARG_UINT,   &objectHeadroom, "-memory:"},
-		{ ARG_STRING, &windowLabel, "-windowlabel:"}, 
+		{ ARG_STRING, &windowLabel, "-windowlabel:"},
 		{ ARG_STRING, &taskNameArg, "-taskname:"},
 		{ ARG_NONE, NULL, NULL }
 	};
@@ -106,7 +108,7 @@
 		logfile = (FILE *)-1;
 		return 0;
 	}
-	return (int)logfile; 
+	return (int)logfile;
 }
 /* override printf()
  * - see also the #define printf repprintf in sqPlatforSpecific.h
@@ -154,7 +156,7 @@
 }
 
 char*rinkMalloc(size_t size) {
-	printf("\\t rink alloc %d\n", (int)size);
+        PRINTF(("\\t rink alloc %d\n", (int)size));
 	return malloc(size);
 }
 
@@ -166,7 +168,7 @@
 	PRINTF(("\\t platAllocateMemory requesting: %08x\n", amount));
 	/* work out the size of dynamic area allowed to see if we can use a large
 	 * application space allocation. On RISC OS 4 or if Aemulor is running
-	 * on RISC OS 5, we can't. We also have the -useDA cmdline flag */ 
+	 * on RISC OS 5, we can't. We also have the -useDA cmdline flag */
 	if ((e = xos_read_dynamic_area(
 				os_DYNAMIC_AREA_APPLICATION_SPACE,
 				&daBaseAddress,
@@ -208,7 +210,7 @@
 			platReportFatalError(&privateErr);
 			return false;
 		}
-	}  
+	}
 
 	PRINTF(("\\t platAllocateMemory(%d) at %0x\n", amount, (int)daBaseAddress));
 
@@ -219,11 +221,14 @@
 void setTimer(void) {
 /* Initialise the MillisecondTimer value address
 */
-#ifdef TIMERMOD
 _kernel_swi_regs regs;
+#ifdef HALTIMERMOD
 	_kernel_swi(/* MillisecondTimer_Val_Ptr*/ 0x58101, &regs, &regs);
 	timerValPtr = (unsigned int *)(regs.r[0]);
 #endif
+#ifdef DRUCKTIMERMOD
+	_kernel_swi(/* Timer_Start*/ 0x490C0, &regs, &regs);
+#endif
 }
 
 
@@ -314,7 +319,7 @@
 int ioAssertion(void) {
 	return 1;
 }
- 
+
 void exit_function(void) {
 /* do we need to do any special tidy up here ? RiscOS needs to kill the
    pointer bitmap and release the dynamic areas
@@ -333,14 +338,32 @@
 	if ( (int)logfile > 0) fclose( logfile);
 }
 
+usqInt millisecondTimerValue(void) {
+/* return the raw unsigned value of the millsecond time for internal VM use */
+_kernel_swi_regs regs;
+#ifdef DRUCKTIMERMOD
+	_kernel_swi(/* Timer_Value*/ 0x490C2, &regs, &regs);
+	return (usqInt)(regs.r[0] * 1000) + (int)(regs.r[1] / 1000);
+#endif
+#ifdef HALTIMERMOD
+//	_kernel_swi(/* MillisecondTimer_Value */ 0x58100, &regs, &regs);
+//	return (regs.r[0]) ;
+	return (usqIt)*timerValPtr;
+#endif
+}
+
 unsigned int microsecondsvalue(void) {
 /* return the microsecond value (ignoring wrap arounds etc) for debug timer
  * purposes
  */
+#ifdef DRUCKTIMERMOD
 _kernel_swi_regs regs;
 	_kernel_swi(/* Timer_Value*/ 0x490C2, &regs, &regs);
 	return  ((regs.r[0] %1000) * 1000000)   + (int)(regs.r[1]) ;
-
+#endif
+#ifdef HALTIMERMOD
+	return 1000 * millisecondTimerValue();
+#endif
 }
 
 sqInt ioMicroMSecs(void) {
@@ -352,24 +375,14 @@
    in units of milliseconds.) This clock must have enough precision to
    provide accurate timings, and normally isn't called frequently
    enough to slow down the VM. Thus, it can use a more expensive clock
-   than ioMSecs().
+   that ioMSecs().
+   This has to be a separate function because it is involved in the
+   function table in sqVirtualMachine.c
 */
-	return (sqInt)millisecondValue();
-}
+	return millisecondTimerValue();
 
-usqInt millisecondValue(void) {
-/* return the raw unsigned value of the millsecond time for internal VM use */
-#ifdef TIMERMOD
-_kernel_swi_regs regs;
-//	_kernel_swi(/* MillisecondTimer_Value */ 0x58100, &regs, &regs);
-//	return (regs.r[0]) ;
-	return *timerValPtr;
-#else
-	return (clock() * 1000/CLOCKS_PER_SEC);
-#endif
 }
 
-
 sqInt ioSeconds(void) {
 /*	  Unix epoch to Smalltalk epoch conversion.
 	(Date newDay: 1 year: 1970) asSeconds
@@ -602,7 +615,7 @@
 	if ((id < 0) && ( -id < numOptionsVM)) {
 			tmp = vmOptions[-id];
 			if (*tmp) return tmp;
-	} 
+	}
 	if ((id > 1) &&(id <= numOptionsImage)) {
 		// we have an offset of 1 for + ids in
 		// order to accommodate the vmPath at 0
@@ -611,7 +624,7 @@
 	}
 	/* fail the prim to ensure we return nil instead of an empty string */
 	success(false);
-	return ""; 
+	return "";
 }
 
 sqInt attributeSize(sqInt id) {
@@ -646,7 +659,7 @@
 		fclose(f);
 		sprintf(runHelp, "chain:Filer_Run %s%s\n", progname, helpname);
 		system(runHelp);
-	} 
+	}
 }
 
 void versionMessage(char * progname) {

Modified: trunk/platforms/RiscOS/vm/sqRPCWindows.c
===================================================================
--- trunk/platforms/RiscOS/vm/sqRPCWindows.c	2013-01-03 02:31:11 UTC (rev 2651)
+++ trunk/platforms/RiscOS/vm/sqRPCWindows.c	2013-01-03 03:39:18 UTC (rev 2652)
@@ -88,6 +88,8 @@
 /* Display related stuff */
 
 void GetDisplayParameters(void) {
+// Read the screen metrics - size, bits per pixels, pixel<->os unit
+// scaling factors
 int bpp;
 bits junk;
 	/* get the screen size x & y */
@@ -117,26 +119,17 @@
 #endif
 }
 
-int ioIconiseWindow(wimp_message * wblock) {
-/* We received an iconise message. Send the image a message to let it know */
-extern void EventBufAppendWindow( int action, int left, int top, int right, int bottom, int windowIndex);
-windowDescriptorBlock * thisWindow;
-	/* need the window block with this handle */
-	thisWindow = windowBlockFromHandle(((wimp_full_message_iconise *)wblock)->w);
 
-	PRINTF(("\\t Iconise %d\n", thisWindow->windowIndex));
-		EventBufAppendWindow( WindowEventIconise, 0, 0, 0, 0,
-			thisWindow->windowIndex);
-}
-
 void SetDefaultPointer(void) {
-/* setup the pointer buffer for use in the Squeak window */
+/* setup the pointer buffer as shape #2 for use in the Squeak window
+        In theory this ought to be replaced with calls to xwimpspriteop_set_pointer_shape() */
 	xwimp_set_pointer_shape(2, (byte const *)pointerBuffer, 16, 16, 0, 0);
 	/* and then return the pointer to no.1 */
 	xwimp_set_pointer_shape(1, (byte const *)-1, 0, 0, 0, 0);
 }
 
 /* window list management */
+/* we maintain a linked list of windowDescriptorBlocks describing each of the window created and used.*/
 
 windowDescriptorBlock *windowBlockFromIndex(int windowIndex) {
 windowDescriptorBlock *entry;
@@ -234,12 +227,14 @@
 }
 
 /* displaying bitmap related routines  */
+/* we have to do pixel transformations as part of converting from a stupid big-endian Form layout to RISC OSs format */
 
 void reverseNothing(void) {
 /* do nothing, as fast as possible */
 }
 
 void reverse_image_1bpps(void) {
+/* reverse the order of each bit winth the word */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -261,6 +256,7 @@
 }
 
 void reverse_image_2bpps(void) {
+/* swap 2-bit chunks ofwords */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -282,6 +278,7 @@
 }
 
 void reverse_image_4bpps(void) {
+/* swap 4-bit chunks of words */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -313,6 +310,7 @@
 }
 
 void reverse_image_bytes(void)  {
+/* swap byte chunks of words */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -336,6 +334,7 @@
 }
 
 void reverse_image_words(void) {
+/* swap 15-bit chunks out of 16 bit words within the 32-bit word; we askip over the alpha bit assumed in other OSs */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -350,6 +349,7 @@
 				nw = (nw << 5) | (w & 0x1F);
 				w = w >> 5;
 				nw = (nw << 5) | (w & 0x1F);
+                                // shift an extra bit to drop the alpha bit
 				w = w >> 6;
 				nw = (nw << 6) | (w & 0x1F);
 				w = w >> 5;
@@ -363,6 +363,7 @@
 }
 
 void reverse_image_longs(void) {
+/* swap 24-bit chunks out of 32-bit words. Skip the alpha bit assumed in some other OSs */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -384,6 +385,7 @@
 }
 
 void simple_copy_image(void) {
+/* yay - no swapping version for some usages */
 unsigned int * srcPtr, *dstPtr;
 int j;
 	for(j = startY; j < stopY; j += scanLine) {
@@ -398,6 +400,7 @@
 }
 
 void DisplayReverseArea(windowDescriptorBlock * thisWindow, int x0, int y0, int x1, int y1) {
+/* we have to process each pixel in the rectangle */
 int stopX, pixelsPerWord, pixelsPerWordShift;
 #ifdef DEBUG
 unsigned int startTime, stopTime;
@@ -452,13 +455,15 @@
 	thisWindow = (windowDescriptorBlock *)windowBlockFromHandle(wblock->w);
 
 	if ( thisWindow->displaySprite == NULL ) {
-		/* flush the damage rectangles, we're not set up yet */
+                /* there's no window set up yet, so flush the damage rectangles */
 		more = wimp_redraw_window( wblock );
 		while ( more ) {
 			xwimp_get_rectangle (wblock, &more);
 		}
 		return;
 	}
+        /* for each damage region in this window, update the display by writing the rectangle of our displaySprite
+           with the appropriate scaling and pixel translation table. It really ought to be simpler than this */
 	more = wimp_redraw_window( wblock );
 	while ( more ) {
 		PRINTF(("\\t display pixmap l:%d t:%d r:%d b:%d\n", wblock->box.x0, wblock->box.y1, wblock->box.x1, wblock->box.y0));
@@ -562,7 +567,7 @@
 void SetupWindowTitle(void) {
 /* set the root window title string.
  * if the -windowlabel: option was used, the title is the
- * string given; limited to the last WindowTitleLength (150) chars.
+ * string given; if it's too long only the last WindowTitleLength (150) chars are used.
  */
 extern char * windowLabel;
 char * string;
@@ -795,7 +800,7 @@
 				os_DYNAMIC_AREA_APPLICATION_SPACE,
 				neededSize,
 				(byte const*)-1,
-				(bits)128, // stops it being draggable size in taskmanager
+                                os_AREA_NO_USER_DRAG, // stops it being draggable size in taskmanager
 				40*1024*1024, // -1 means 'unlimited'
 				NULL,
 				NULL,
@@ -904,15 +909,10 @@
 
 void BuildWindow(windowDescriptorBlock * thisWindow) {
 /* Do the basic building of a window.
- * if isIndirected, then the title is a pointer to a _global_ var string
- * and the indirected flag must be set.
+ *
+ * Create a window block and set various structures and flags to suit the windowDescriptorBlock
  * Otherwise the title is copied into the literal string in the structure
  */
-/* create a window of width and height, centred on the screen
- * since it is possible that width and height are not possible on the screen
- * we check against the screen metrics and modify, then set the
- * global values as required.
- */
 wimp_window wblock;
 os_error * e;
 wimp_w w;
@@ -936,7 +936,7 @@
 	wblock.flags = wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE
 			| wimp_WINDOW_BOUNDED_ONCE | wimp_WINDOW_IGNORE_XEXTENT
 			| wimp_WINDOW_IGNORE_YEXTENT
-			| thisWindow->attributes;
+                        | thisWindow->attributes; // <--- these are the flags settable from Squeak
 	/* colours */
 	wblock.title_fg = wimp_COLOUR_BLACK;
 	wblock.title_bg = wimp_COLOUR_LIGHT_GREY;
@@ -962,7 +962,9 @@
 	/* minimum window size allowed */
 	wblock.xmin = (short)100;
 	wblock.ymin = (short)100;
-	/* window title - limited to 151 chars by struct defn */
+        /* window title - limited to 151 chars by struct defn
+         * since it is indirected, the title is a pointer to a _global_ var string
+         * and the wimp_ICON_INDIRECTED flag must be set (above).*/
 	wblock.title_data.indirected_text.text =  thisWindow->title;
 	wblock.title_data.indirected_text.validation = (char*)-1;
 	wblock.title_data.indirected_text.size = strlen(thisWindow->title);
@@ -970,12 +972,12 @@
 	wblock.icon_count = 0;
 	/* wblock.icons = (wimp_icon *)NULL;*/
 
-	/* call wimp_createWindow */
+        /* call wimp_create_window to actaully do the deed */
 	if ( (e = xwimp_create_window(&wblock, &w)) != NULL) {
 		platReportFatalError(e);
 		return;
 	}
-	/* save the window handle */
+        /* save the window handle in the windowDescriptorBlock */
 	thisWindow->handle = w;
 
 	/* actually set the window size/position - may modify windowVisibleArea */
@@ -1136,6 +1138,7 @@
 	while(windowListRoot) {
 		DeleteWindow(windowListRoot);
 	}
+        return true;
 }
 
 /* ioShowDisplayOnWindow: similar to ioShowDisplay but adds the int windowIndex
@@ -1296,8 +1299,6 @@
  * origin x/y for the window. Return the actual origin the OS
  * produced in (left<<16 || top) format or -1 for failure, as above */
 windowDescriptorBlock * thisWindow;
-wimp_window_state wblock;
-os_error * e;
 int w,h;
 
 	thisWindow = (windowDescriptorBlock *)windowBlockFromIndex(windowIndex);
@@ -1332,6 +1333,7 @@
 /* ioSetTitleOfWindow: args are int windowIndex, char* newTitle and
  * int size of new title. Fail with -1 if windowIndex is invalid, string is too long for platform etc. Leave previous title in place on failure */
 windowDescriptorBlock * thisWindow;
+os_error *e;
 	thisWindow = (windowDescriptorBlock *)windowBlockFromIndex(windowIndex);
 	if (thisWindow == NULL) {
 		/* seems to be an invalid window index */
@@ -1341,19 +1343,24 @@
 	if ( sizeOfTitle > WindowTitleLength ) {
 		return -1;
 	}
+        PRINTF(( "\\t ioSetWindowTitle: string length & window ID ok\n"));
 
 	/* check the titlebar flag is set */
-	if ((thisWindow->attributes | wimp_WINDOW_TITLE_ICON) == 0 ) {
+        if ((thisWindow->attributes & wimp_WINDOW_TITLE_ICON) == 0 ) {
 		return -1;
 	}
+        PRINTF(( "\\t ioSetWindowTitle: titlebar flag ok\n"));
 
 	/* copy to the window */
 	strncpy(thisWindow->title, newTitle, sizeOfTitle);
 	thisWindow->title[sizeOfTitle] = '\0';
 	/* update the titlebar if the window is built */
 	if (thisWindow->handle) {
-		xwimp_force_redraw_furniture(thisWindow->handle, wimp_FURNITURE_TITLE);
+                if ((e = xwimp_force_redraw_furniture(thisWindow->handle, wimp_FURNITURE_TITLE)) != NULL) {
+                platReportError(e);
+                }
 	}
+        PRINTF(( "\\t ioSetWindowTitle: should be ok\n"));
 	return true;
 }
 
@@ -1568,3 +1575,14 @@
 	}
 }
 
+int ioIconiseWindow(wimp_message * wblock) {
+/* We received an iconise message. Send the image a message to let it know */
+extern void EventBufAppendWindow( int action, int left, int top, int right, int bottom, int windowIndex);
+windowDescriptorBlock * thisWindow;
+        /* find the window block with this OS handle */
+        thisWindow = windowBlockFromHandle(((wimp_full_message_iconise *)wblock)->w);
+
+        PRINTF(("\\t Iconise window: %d\n",thisWindow->windowIndex));
+        EventBufAppendWindow( WindowEventIconise, 0,0,0,0, thisWindow->windowIndex);
+        return true;
+}



More information about the Vm-dev mailing list