freesci-develop
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freesci-develop] r1586 - in freesci/branches/glutton: . src/engine src/


From: freesci
Subject: [freesci-develop] r1586 - in freesci/branches/glutton: . src/engine src/include
Date: Sat, 25 Nov 2006 15:30:35 +0100

Author: skovmanden
Date: 2006-11-25 15:30:24 +0100 (Sat, 25 Nov 2006)
New Revision: 1586

Modified:
   freesci/branches/glutton/ChangeLog
   freesci/branches/glutton/src/engine/kstring.c
   freesci/branches/glutton/src/include/vm_types.h
Log:
Implement support for the array handling style used by the SCI MCyc
class. This is most obvious in the SQ4 floppy intro, but use of the
class has been spotted elsewhere also.

To simplify the above, I have standardized on a single reg_t
representation. The "new" representation used to be an #ifdef used on
some platforms. I can't see why the old default should be preferable,
and it seems to work with a variety of games. If anyone has
objections, don't hesitate to say so.

Lars



Modified: freesci/branches/glutton/ChangeLog
===================================================================
--- freesci/branches/glutton/ChangeLog  2006-11-25 00:00:48 UTC (rev 1585)
+++ freesci/branches/glutton/ChangeLog  2006-11-25 14:30:24 UTC (rev 1586)
@@ -1,3 +1,11 @@
+2006-11-25  Lars Skovlund  <address@hidden>
+
+       * src/engine/vm_types.h: Standardize on a single reg_t
+       representation on all platforms.
+
+       * src/engine/kstring.c (kStrAt): Implement support for SQ4 using
+       this call to handle arrays.
+
 2006-11-24  Lars Skovlund  <address@hidden>
 
        * engine/game.c: Make the picture port selected on startup.

Modified: freesci/branches/glutton/src/engine/kstring.c
===================================================================
--- freesci/branches/glutton/src/engine/kstring.c       2006-11-25 00:00:48 UTC 
(rev 1585)
+++ freesci/branches/glutton/src/engine/kstring.c       2006-11-25 14:30:24 UTC 
(rev 1586)
@@ -425,10 +425,32 @@
 }
 
 
+int save_str_offset; /* Referenced externally from vm.c */
+
+/* Simple heuristic to work around array handling peculiarity in SQ4:
+It uses StrAt() to read the individual elements, so we must determine
+whether a string is really a string or an array. */
+int is_print_str(char *str)
+{
+       int printable = 0;
+       int len = strlen(str);
+       
+       if (len == 0) return 1;
+
+       while (*str)
+       {
+               if (isprint(*str)) printable++;
+               str++;
+       }
+
+       return ((float) printable / (float) len >= 0.5);
+}
+
 reg_t
 kStrAt(state_t *s, int funct_nr, int argc, reg_t *argv)
 {
        unsigned char *dest = (unsigned char *) 
kernel_dereference_bulk_pointer(s, argv[0], 0);
+       reg_t *dest2;
 
        if (!dest) {
                SCIkdebug(SCIkWARNING, "Attempt to StrAt at invalid pointer 
"PREG"!\n",
@@ -436,7 +458,16 @@
                return NULL_REG;
        }
 
-       dest += KP_UINT(argv[1]);
+       if (!is_print_str(dest)) /* SQ4 array handling detected */
+       {
+#ifndef WORDS_BIGENDIAN
+               int odd = KP_UINT(argv[1]) & 1;
+#else
+               int odd = !(KP_UINT(argv[1]) & 1);
+#endif
+               dest2 = ((reg_t *) dest)+(KP_UINT(argv[1])/2);
+               dest = ((char *) (&dest2->offset))+odd;
+       } else dest += KP_UINT(argv[1]);
 
        s->r_acc = make_reg(0, *dest);
 

Modified: freesci/branches/glutton/src/include/vm_types.h
===================================================================
--- freesci/branches/glutton/src/include/vm_types.h     2006-11-25 00:00:48 UTC 
(rev 1585)
+++ freesci/branches/glutton/src/include/vm_types.h     2006-11-25 14:30:24 UTC 
(rev 1586)
@@ -36,18 +36,10 @@
 
 struct _state; /* engine.h */
 
-#if defined(S_SPLINT_S) || defined(_MSC_VER) || defined(__DECC)
-/* Can't deal with packed notation for these types */
 typedef struct {
        guint16 segment;
        guint16 offset;
 } reg_t;
-#else
-typedef struct {
-       seg_id_t segment        : SCI_SEG_SIZE;
-       unsigned int offset     : SCI_REG_SIZE;
-} reg_t;
-#endif
 
 #define PREG "%04x:%04x"
 #define PRINT_REG(r) (0xffff) & (unsigned) (r).segment, (unsigned) (r).offset





reply via email to

[Prev in Thread] Current Thread [Next in Thread]