Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!bellcore!wind!sdh From: sdh@wind.bellcore.com (Stephen D Hawley) Newsgroups: comp.sys.mac.programmer Subject: Re: Can anyone anser these Questions? Message-ID: <17456@bellcore.bellcore.com> Date: 23 Aug 89 15:43:16 GMT References: <864@eutrc3.urc.tue.nl> Sender: news@bellcore.bellcore.com Reply-To: sdh@wind.UUCP (Stephen D Hawley) Organization: Bellcore, Morristown, NJ Lines: 51 In article <864@eutrc3.urc.tue.nl> rcbaem@eutrc3.uucp writes: > A := Ptr(LongInt(memStart) + P)^; > > PROBLEM!! Assume P has the (integer) value -1. (=$FFFF) and say > memStart = 0; (LongInt(memStart) + P) then gives -1 instead of $FFFF.. > Whatever typecasting I tried, I end up with $FFFF beging extended > to the LongInt $FFFFFFFF... I finally found a solution as follows: Your problem is that things are being sign extended, and you don't want them to be. I forget the exact Pascal standard [sic], but I believe you can declare variables to be unsigned. I think you might also want to try the following as well: const MEMSIZE = 65535; type memtype = array[0..MEMSIZE] of char; var mem: Ptr; Procedure InitMem; { allocate memory } begin mem := NewPtr(MEMSIZE); end; Function ReadMem(MAR:integer): char; { If Pascal has an unsigned integer, use that instead of a plain old integer. It will run faster. Also, mym memory is rusty as to the way that Pascal does type casting, but basically, I'm trying to treat the Pointer as an array address and address the bytes appropriately. The longint cast will sign extend, and the MOD should strip the upper word away. } begin ReadMem = memtype(mem)[longint(MAR) MOD MEMSIZE]; end; Procedure WriteMem(MAR: integer; MDR: char); { similar } begin memtype(mem)[longing(MAR) MOD MEMSIZE] := MDR; end; Oh, BTW, MAR and MDR are the memory address register and memory data register. Good luck. Steve Hawley sdh@flash.bellcore.com "Up is where you hang your hat." --Jim Blandy, computer scientist