home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnusmalltalk / wordmemory.st < prev    next >
Text File  |  1992-02-15  |  3KB  |  94 lines

  1. "======================================================================
  2. |
  3. |   Word oriented memory definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbb         16 Mar 91      Class creation now separate statement.
  34. |
  35. | sbyrne     29 May 89      created.
  36. |
  37. "
  38.  
  39. Memory variableWordSubclass: #WordMemory
  40.        instanceVariableNames: ''
  41.        classVariableNames: ''
  42.        poolDictionaries: ''
  43.        category: nil
  44. !
  45.  
  46. WordMemory comment: 
  47. 'I have no instances.  I provide messages to my class that access real memory 
  48. as 32-bit words (well, really 31 bit integers).  An alternative implementation 
  49. would be to have a single instance of word memory that represented all memory, 
  50. and at: and at:put: accessor methods, but since you''d typically refer to that
  51. instance via a global variable, and since the global variable would probably be
  52. named WordMemory, the actual method invocations are exactly the same in 
  53. either case.' !
  54.  
  55.  
  56. !WordMemory class methodsFor: 'accessing'!
  57.  
  58. at: address
  59.     | value |
  60.     "### This is dependent on big-endian byte ordering..."
  61.     Bigendian 
  62.     ifTrue:
  63.         [ value _ ByteMemory at: address.
  64.           value >= 64 
  65.           ifTrue: [ ^self error: 'Word at ' , 
  66.                 address radix: 8 ,
  67.                 ' is not representable yet' ].
  68.           address + 1 to: address + 3 do:
  69.           [ :addr | value _ value * 256 + (ByteMemory at: addr) ].
  70.           ^value ]
  71.     ifFalse:
  72.         [ ^self error:
  73.           'I''m not preprared to handle little endian just yet' ].
  74. !
  75.  
  76. at: address put: value
  77.     Bigendian
  78.     ifTrue:
  79.         [ address + 3 to: address + 1 by: -1 do:
  80.           [ :addr | ByteMemory at: addr
  81.                 put: ( value \\ 256).
  82.                 value _ value // 256 ].
  83.           value < 0
  84.           ifTrue: [ value _ value negated.
  85.                 value _ value + 64.
  86.                 ByteMemory at: address put: value ]
  87.           ifFalse: [ ByteMemory at: address put: value ] ]
  88.     ifFalse:
  89.         [ ^self error:
  90.           'I''m not preprared to handle little endian just yet' ].
  91. !!
  92.