1600 |
1599 |
1601 val := 0. |
1600 val := 0. |
1602 bigEndian ifTrue:[ |
1601 bigEndian ifTrue:[ |
1603 highByte := (self at:index). |
1602 highByte := (self at:index). |
1604 index to:index+n-1 do:[:i | |
1603 index to:index+n-1 do:[:i | |
1605 val := (val<<8) + (self at:i) |
1604 val := (val<<8) + (self byteAt:i) |
1606 ] |
1605 ] |
1607 ] ifFalse:[ |
1606 ] ifFalse:[ |
1608 highByte := (self at:index+n-1). |
1607 highByte := (self at:index+n-1). |
1609 index+n-1 to:index by:-1 do:[:i | |
1608 index+n-1 to:index by:-1 do:[:i | |
1610 val := (val<<8) + (self at:i) |
1609 val := (val<<8) + (self byteAt:i) |
1611 ] |
1610 ] |
1612 ]. |
1611 ]. |
1613 (highByte bitTest:16r80) ifTrue:[ |
1612 (highByte bitTest:16r80) ifTrue:[ |
1614 ^ val - (1 bitShift:(n*8)) |
1613 ^ val - (1 bitShift:(n*8)) |
1615 ]. |
1614 ]. |
1739 " |
1738 " |
1740 |
1739 |
1741 "Modified (comment): / 26-09-2011 / 11:57:36 / cg" |
1740 "Modified (comment): / 26-09-2011 / 11:57:36 / cg" |
1742 ! |
1741 ! |
1743 |
1742 |
1744 signedByteAt:index |
1743 byteAt:byteIndex |
1745 "return the byte at index as a signed 8 bit value in the range -128..+127. |
1744 "return the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
1746 The index is a smalltalk index (i.e. 1-based). |
1745 The index is a smalltalk index (i.e. 1-based)." |
1747 This may be worth a primitive." |
1746 |
1748 |
1747 %{ |
1749 ^ (self at:index) signExtendedByteValue |
1748 if (__isSmallInteger(byteIndex)) { |
1750 |
1749 unsigned char *cp; |
1751 " |
1750 INT sz; |
1752 |b| |
1751 |
1753 b := ByteArray new:2. |
1752 __fetchBytePointerAndSize__(self, &cp, &sz); |
|
1753 if (cp) { |
|
1754 unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1755 char ch; |
|
1756 |
|
1757 if (idx < sz) { |
|
1758 ch = cp[idx] & 0xFF; |
|
1759 RETURN (__mkSmallInteger( ch )); |
|
1760 } |
|
1761 } |
|
1762 } |
|
1763 %}. |
|
1764 |
|
1765 ^ self at:byteIndex |
|
1766 |
|
1767 " |
|
1768 |b| |
|
1769 b := ByteArray new:3. |
1754 b at:1 put:16rFF. |
1770 b at:1 put:16rFF. |
1755 b at:2 put:16r7F. |
1771 b at:2 put:16r7F. |
1756 b signedByteAt:1 |
1772 b at:3 put:16r80. |
|
1773 b byteAt:1. |
|
1774 b byteAt:2. |
|
1775 b byteAt:3. |
1757 " |
1776 " |
1758 |
1777 |
1759 "Modified: / 01-07-1996 / 21:13:53 / cg" |
1778 "Modified: / 01-07-1996 / 21:13:53 / cg" |
1760 "Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
1779 "Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
1761 ! |
1780 ! |
1762 |
1781 |
|
1782 byteAt:byteIndex put:anInteger |
|
1783 "set the byte at byteIndex as an unsigned 8 bit value in the range 0..255. |
|
1784 The index is a smalltalk index (i.e. 1-based)." |
|
1785 |
|
1786 %{ |
|
1787 if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) { |
|
1788 unsigned char *cp; |
|
1789 INT sz; |
|
1790 INT val = __intVal(anInteger); |
|
1791 |
|
1792 if ( ((unsigned INT)val) <= 0xFF ) { |
|
1793 __fetchBytePointerAndSize__(self, &cp, &sz); |
|
1794 if (cp) { |
|
1795 unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1796 |
|
1797 if (idx < sz) { |
|
1798 cp[idx] = val & 0xFF; |
|
1799 RETURN (anInteger); |
|
1800 } |
|
1801 } |
|
1802 } |
|
1803 } |
|
1804 %}. |
|
1805 |
|
1806 ^ self at:byteIndex put:anInteger |
|
1807 |
|
1808 " |
|
1809 |b| |
|
1810 b := ByteArray new:3. |
|
1811 b byteAt:1 put:16rFF. |
|
1812 b byteAt:2 put:16r7F. |
|
1813 b byteAt:3 put:16r80. |
|
1814 b signedByteAt:1. |
|
1815 b signedByteAt:2. |
|
1816 b signedByteAt:3. |
|
1817 " |
|
1818 ! |
|
1819 |
|
1820 signedByteAt:byteIndex |
|
1821 "return the byte at byteIndex as a signed 8 bit value in the range -128..+127. |
|
1822 The index is a smalltalk index (i.e. 1-based). |
|
1823 This may be worth a primitive." |
|
1824 |
|
1825 %{ |
|
1826 /* |
|
1827 * handle the most common cases fast ... |
|
1828 */ |
|
1829 if (__isSmallInteger(byteIndex)) { |
|
1830 unsigned char *cp; |
|
1831 INT sz; |
|
1832 |
|
1833 __fetchBytePointerAndSize__(self, &cp, &sz); |
|
1834 if (cp) { |
|
1835 unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1; |
|
1836 char ch; |
|
1837 |
|
1838 if (idx < sz) { |
|
1839 cp += idx; |
|
1840 ch = cp[0]; |
|
1841 # ifndef HAS_SIGNED_CHAR |
|
1842 if ( (unsigned int)ch >= 0x80 ) { |
|
1843 ch = ch - 0x100; |
|
1844 } |
|
1845 #endif |
|
1846 RETURN (__mkSmallInteger( ch )); |
|
1847 } |
|
1848 } |
|
1849 } |
|
1850 %}. |
|
1851 |
|
1852 ^ (self byteAt:byteIndex) signExtendedByteValue |
|
1853 |
|
1854 " |
|
1855 |b| |
|
1856 b := ByteArray new:3. |
|
1857 b at:1 put:16rFF. |
|
1858 b at:2 put:16r7F. |
|
1859 b at:3 put:16r80. |
|
1860 b byteAt:1. |
|
1861 b byteAt:2. |
|
1862 b byteAt:3. |
|
1863 " |
|
1864 |
|
1865 "Modified: / 01-07-1996 / 21:13:53 / cg" |
|
1866 "Modified (comment): / 26-09-2011 / 11:57:14 / cg" |
|
1867 ! |
|
1868 |
1763 signedByteAt:index put:aSignedByteValue |
1869 signedByteAt:index put:aSignedByteValue |
1764 "return the byte at index as a signed 8 bit value in the range -128..+127. |
1870 "return the byte at index as a signed 8 bit value in the range -128..+127. |
1765 The index is a smalltalk index (i.e. 1-based). |
1871 The index is a smalltalk index (i.e. 1-based). |
1766 Return the signedByteValue argument. |
1872 Return the signedByteValue argument. |
1767 This may be worth a primitive." |
1873 This may be worth a primitive." |
1768 |
1874 |
1769 |b "{ Class: SmallInteger }"| |
1875 |b "{ Class: SmallInteger }"| |
1770 |
1876 |
1771 aSignedByteValue >= 0 ifTrue:[ |
1877 aSignedByteValue >= 0 ifTrue:[ |
1772 b := aSignedByteValue |
1878 b := aSignedByteValue |
1773 ] ifFalse:[ |
1879 ] ifFalse:[ |
1774 b := 16r100 + aSignedByteValue |
1880 b := 16r100 + aSignedByteValue |
1775 ]. |
1881 ]. |
1776 self at:index put:b. |
1882 self byteAt:index put:b. |
1777 ^ aSignedByteValue |
1883 ^ aSignedByteValue |
1778 |
1884 |
1779 " |
1885 " |
1780 |b| |
1886 |b| |
1781 b := ByteArray new:2. |
1887 b := ByteArray new:2. |
1802 %{ |
1908 %{ |
1803 /* |
1909 /* |
1804 * handle the most common cases fast ... |
1910 * handle the most common cases fast ... |
1805 */ |
1911 */ |
1806 if (__isSmallInteger(index)) { |
1912 if (__isSmallInteger(index)) { |
1807 unsigned char *cp; |
1913 unsigned char *cp; |
1808 INT sz; |
1914 INT sz; |
1809 |
1915 |
1810 __fetchBytePointerAndSize__(self, &cp, &sz); |
1916 __fetchBytePointerAndSize__(self, &cp, &sz); |
1811 if (cp) { |
1917 if (cp) { |
1812 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
1918 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
1813 |
1919 |
1814 if ((idx+(sizeof(double)-1)) < sz) { |
1920 if ((idx+(sizeof(double)-1)) < sz) { |
1815 cp += idx; |
1921 cp += idx; |
1816 /* |
1922 /* |
1817 * aligned |
1923 * aligned |
1818 */ |
1924 */ |
1819 if (((INT)cp & (sizeof(double)-1)) == 0) { |
1925 if (((INT)cp & (sizeof(double)-1)) == 0) { |
1820 double dVal = ((double *)cp)[0]; |
1926 double dVal = ((double *)cp)[0]; |
1821 OBJ f; |
1927 OBJ f; |
1822 |
1928 |
1823 __qMKFLOAT(f, dVal); |
1929 __qMKFLOAT(f, dVal); |
1824 RETURN (f); |
1930 RETURN (f); |
1825 } |
1931 } |
1826 } |
1932 } |
1827 } |
1933 } |
1828 } |
1934 } |
1829 %}. |
1935 %}. |
1830 |
1936 |
1831 newFloat := Float basicNew. |
1937 newFloat := Float basicNew. |
1832 1 to:8 do:[:destIndex| |
1938 1 to:8 do:[:destIndex| |
1833 newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
1939 newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex)) |
1834 ]. |
1940 ]. |
1835 ^ newFloat. |
1941 ^ newFloat. |
1836 |
1942 |
1837 " |
1943 " |
1838 |b| |
1944 |b| |
1853 machine, some conversion is usually needed." |
1959 machine, some conversion is usually needed." |
1854 |
1960 |
1855 |newFloat| |
1961 |newFloat| |
1856 |
1962 |
1857 msb == IsBigEndian ifTrue:[ |
1963 msb == IsBigEndian ifTrue:[ |
1858 ^ self doubleAt:index. |
1964 ^ self doubleAt:index. |
1859 ]. |
1965 ]. |
1860 |
1966 |
1861 newFloat := Float basicNew. |
1967 newFloat := Float basicNew. |
1862 1 to:8 do:[:destIndex| |
1968 1 to:8 do:[:destIndex| |
1863 newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex) |
1969 newFloat basicAt:(9-destIndex) put:(self byteAt:(index - 1 + destIndex)) |
1864 ]. |
1970 ]. |
1865 ^ newFloat. |
1971 ^ newFloat. |
1866 |
1972 |
1867 "Created: / 15.5.1998 / 17:21:45 / cg" |
1973 "Created: / 15.5.1998 / 17:21:45 / cg" |
1868 ! |
1974 ! |
1881 %{ |
1987 %{ |
1882 /* |
1988 /* |
1883 * handle the most common cases fast ... |
1989 * handle the most common cases fast ... |
1884 */ |
1990 */ |
1885 if (__isSmallInteger(index)) { |
1991 if (__isSmallInteger(index)) { |
1886 unsigned char *cp; |
1992 unsigned char *cp; |
1887 INT sz; |
1993 INT sz; |
1888 |
1994 |
1889 __fetchBytePointerAndSize__(self, &cp, &sz); |
1995 __fetchBytePointerAndSize__(self, &cp, &sz); |
1890 if (cp) { |
1996 if (cp) { |
1891 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
1997 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
1892 |
1998 |
1893 if ((idx+(sizeof(double)-1)) < sz) { |
1999 if ((idx+(sizeof(double)-1)) < sz) { |
1894 cp += idx; |
2000 cp += idx; |
1895 /* |
2001 /* |
1896 * aligned |
2002 * aligned |
1897 */ |
2003 */ |
1898 if (((INT)cp & (sizeof(double)-1)) == 0) { |
2004 if (((INT)cp & (sizeof(double)-1)) == 0) { |
1899 if (__isFloat(aFloat)) { |
2005 if (__isFloat(aFloat)) { |
1900 ((double *)cp)[0] = __floatVal(aFloat); |
2006 ((double *)cp)[0] = __floatVal(aFloat); |
1901 RETURN (aFloat); |
2007 RETURN (aFloat); |
1902 } |
2008 } |
1903 if (__isShortFloat(aFloat)) { |
2009 if (__isShortFloat(aFloat)) { |
1904 ((double *)cp)[0] = (double)(__shortFloatVal(aFloat)); |
2010 ((double *)cp)[0] = (double)(__shortFloatVal(aFloat)); |
1905 RETURN (aFloat); |
2011 RETURN (aFloat); |
1906 } |
2012 } |
1907 if (__isSmallInteger(aFloat)) { |
2013 if (__isSmallInteger(aFloat)) { |
1908 ((double *)cp)[0] = (double)(__intVal(aFloat)); |
2014 ((double *)cp)[0] = (double)(__intVal(aFloat)); |
1909 RETURN (aFloat); |
2015 RETURN (aFloat); |
1910 } |
2016 } |
1911 } |
2017 } |
1912 } |
2018 } |
1913 } |
2019 } |
1914 } |
2020 } |
1915 %}. |
2021 %}. |
1916 |
2022 |
1917 flt := aFloat asFloat. |
2023 flt := aFloat asFloat. |
1918 1 to:8 do:[:srcIndex| |
2024 1 to:8 do:[:srcIndex| |
1919 self at:index - 1 + srcIndex put:(flt basicAt:srcIndex) |
2025 self byteAt:(index - 1 + srcIndex) put:(flt basicAt:srcIndex) |
1920 ]. |
2026 ]. |
1921 ^ aFloat |
2027 ^ aFloat |
1922 ! |
2028 ! |
1923 |
2029 |
1924 doubleAt:index put:aFloat MSB:msb |
2030 doubleAt:index put:aFloat MSB:msb |
1931 machine, some conversion is usually needed." |
2037 machine, some conversion is usually needed." |
1932 |
2038 |
1933 |flt| |
2039 |flt| |
1934 |
2040 |
1935 msb == IsBigEndian ifTrue:[ |
2041 msb == IsBigEndian ifTrue:[ |
1936 ^ self doubleAt:index put:aFloat. |
2042 ^ self doubleAt:index put:aFloat. |
1937 ]. |
2043 ]. |
1938 |
2044 |
1939 flt := aFloat asFloat. |
2045 flt := aFloat asFloat. |
1940 1 to:8 do:[:srcIndex| |
2046 1 to:8 do:[:srcIndex| |
1941 self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex)) |
2047 self byteAt:(index - 1 + srcIndex) put:(flt basicAt:(9-srcIndex)) |
1942 ]. |
2048 ]. |
1943 ^ aFloat |
2049 ^ aFloat |
1944 |
2050 |
1945 "Created: / 15.5.1998 / 17:22:27 / cg" |
2051 "Created: / 15.5.1998 / 17:22:27 / cg" |
1946 "Modified: / 15.5.1998 / 17:26:29 / cg" |
2052 "Modified: / 15.5.1998 / 17:26:29 / cg" |
1961 %{ |
2067 %{ |
1962 /* |
2068 /* |
1963 * handle the most common cases fast ... |
2069 * handle the most common cases fast ... |
1964 */ |
2070 */ |
1965 if (__isSmallInteger(index)) { |
2071 if (__isSmallInteger(index)) { |
1966 unsigned char *cp; |
2072 unsigned char *cp; |
1967 INT sz; |
2073 INT sz; |
1968 |
2074 |
1969 __fetchBytePointerAndSize__(self, &cp, &sz); |
2075 __fetchBytePointerAndSize__(self, &cp, &sz); |
1970 if (cp) { |
2076 if (cp) { |
1971 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
2077 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
1972 |
2078 |
1973 if ((idx+(sizeof(float)-1)) < sz) { |
2079 if ((idx+(sizeof(float)-1)) < sz) { |
1974 cp += idx; |
2080 cp += idx; |
1975 /* |
2081 /* |
1976 * aligned |
2082 * aligned |
1977 */ |
2083 */ |
1978 if (((INT)cp & (sizeof(float)-1)) == 0) { |
2084 if (((INT)cp & (sizeof(float)-1)) == 0) { |
1979 float fVal = ((float *)cp)[0]; |
2085 float fVal = ((float *)cp)[0]; |
1980 OBJ f; |
2086 OBJ f; |
1981 |
2087 |
1982 __qMKSFLOAT(f, fVal); |
2088 __qMKSFLOAT(f, fVal); |
1983 RETURN (f); |
2089 RETURN (f); |
1984 } |
2090 } |
1985 } |
2091 } |
1986 } |
2092 } |
1987 } |
2093 } |
1988 %}. |
2094 %}. |
1989 |
2095 |
1990 newFloat := ShortFloat basicNew. |
2096 newFloat := ShortFloat basicNew. |
1991 1 to:4 do:[:destIndex| |
2097 1 to:4 do:[:destIndex| |
1992 newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
2098 newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex)) |
1993 ]. |
2099 ]. |
1994 ^ newFloat. |
2100 ^ newFloat. |
1995 ! |
2101 ! |
1996 |
2102 |
1997 floatAt:index MSB:msb |
2103 floatAt:index MSB:msb |
2005 machine, some conversion is usually needed." |
2111 machine, some conversion is usually needed." |
2006 |
2112 |
2007 |newFloat| |
2113 |newFloat| |
2008 |
2114 |
2009 msb == IsBigEndian ifTrue:[ |
2115 msb == IsBigEndian ifTrue:[ |
2010 ^ self floatAt:index |
2116 ^ self floatAt:index |
2011 ]. |
2117 ]. |
2012 |
2118 |
2013 newFloat := ShortFloat basicNew. |
2119 newFloat := ShortFloat basicNew. |
2014 1 to:4 do:[:destIndex| |
2120 1 to:4 do:[:destIndex| |
2015 newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex) |
2121 newFloat basicAt:(5-destIndex) put:(self byteAt:(index - 1 + destIndex)) |
2016 ]. |
2122 ]. |
2017 ^ newFloat. |
2123 ^ newFloat. |
2018 |
2124 |
2019 "Modified: / 15.5.1998 / 17:20:19 / cg" |
2125 "Modified: / 15.5.1998 / 17:20:19 / cg" |
2020 "Created: / 15.5.1998 / 17:20:35 / cg" |
2126 "Created: / 15.5.1998 / 17:20:35 / cg" |
2034 %{ |
2140 %{ |
2035 /* |
2141 /* |
2036 * handle the most common cases fast ... |
2142 * handle the most common cases fast ... |
2037 */ |
2143 */ |
2038 if (__isSmallInteger(index)) { |
2144 if (__isSmallInteger(index)) { |
2039 unsigned char *cp; |
2145 unsigned char *cp; |
2040 INT sz; |
2146 INT sz; |
2041 |
2147 |
2042 __fetchBytePointerAndSize__(self, &cp, &sz); |
2148 __fetchBytePointerAndSize__(self, &cp, &sz); |
2043 if (cp) { |
2149 if (cp) { |
2044 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
2150 unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
2045 |
2151 |
2046 if ((idx+(sizeof(float)-1)) < sz) { |
2152 if ((idx+(sizeof(float)-1)) < sz) { |
2047 cp += idx; |
2153 cp += idx; |
2048 /* |
2154 /* |
2049 * aligned |
2155 * aligned |
2050 */ |
2156 */ |
2051 if (((INT)cp & (sizeof(float)-1)) == 0) { |
2157 if (((INT)cp & (sizeof(float)-1)) == 0) { |
2052 if (__isShortFloat(aFloat)) { |
2158 if (__isShortFloat(aFloat)) { |
2053 ((float *)cp)[0] = __shortFloatVal(aFloat); |
2159 ((float *)cp)[0] = __shortFloatVal(aFloat); |
2054 RETURN (self); |
2160 RETURN (self); |
2055 } |
2161 } |
2056 if (__isFloat(aFloat)) { |
2162 if (__isFloat(aFloat)) { |
2057 ((float *)cp)[0] = (float)__floatVal(aFloat); |
2163 ((float *)cp)[0] = (float)__floatVal(aFloat); |
2058 RETURN (self); |
2164 RETURN (self); |
2059 } |
2165 } |
2060 if (__isSmallInteger(aFloat)) { |
2166 if (__isSmallInteger(aFloat)) { |
2061 ((float *)cp)[0] = (float)__intVal(aFloat); |
2167 ((float *)cp)[0] = (float)__intVal(aFloat); |
2062 RETURN (self); |
2168 RETURN (self); |
2063 } |
2169 } |
2064 // bail out to smalltalk code |
2170 // bail out to smalltalk code |
2065 } |
2171 } |
2066 } |
2172 } |
2067 } |
2173 } |
2068 } |
2174 } |
2069 %}. |
2175 %}. |
2070 |
2176 |
2071 sflt := aFloat asShortFloat. |
2177 sflt := aFloat asShortFloat. |
2072 1 to:4 do:[:srcIndex| |
2178 1 to:4 do:[:srcIndex| |
2073 self at:index - 1 + srcIndex put:(sflt basicAt:srcIndex) |
2179 self byteAt:index - 1 + srcIndex put:(sflt basicAt:srcIndex) |
2074 ]. |
2180 ]. |
2075 ! |
2181 ! |
2076 |
2182 |
2077 floatAt:index put:aFloat MSB:msb |
2183 floatAt:index put:aFloat MSB:msb |
2078 "store the 4 bytes of value of the argument, aFloat into the receiver |
2184 "store the 4 bytes of value of the argument, aFloat into the receiver |