[comp.sys.mac.programmer] Reading Text With Pointers...

n67786@lehtori.tut.fi (Nieminen Tero) (12/30/90)

In article <50164@cornell.UUCP> wayner@kama.cs.cornell.edu (Peter Wayner) writes:

   If I read in a file of text, each character fills a byte. The
   problem is that the 68000 doesn't allow unalligned access, but
   the 68020/30 does. What is the best way to pull of characters
   one by one? 

All of the 68K series cpus let you access byte (character) sized data at
both even and odd addresses. The restriction on 68000 (and hence Mac
programs) affect only word and long word sized data (and the way stack
is filled).

   -Peter
-- 
   Tero Nieminen                    Tampere University of Technology
   n67786@cc.tut.fi                 Tampere, Finland, Europe

wayner@kama.cs.cornell.edu (Peter Wayner) (12/31/90)

If I read in a file of text, each character fills a byte. The
problem is that the 68000 doesn't allow unalligned access, but
the 68020/30 does. What is the best way to pull of characters
one by one? 

Does the routine need to look like:

Globals: lastword:16bits
         lasthigh:boolean
         position:pointer;

function nextchar:char;

begin
if lasthigh then
 begin
   pointer:=pointer+2;
   lastword:=pointer^;
   lasthigh:=false;
   nextchar:=BAND($ff,lastword);
	{Keep the lower eightbits via a bitwise AND.}
 end
else
 begin
   lasthigh:=true;
   nextchar:=BAND($ff,BSR(lastword,8));
     {Keep the top eight bits by first shifting right 8 bits and then anding.}
  end;

end;{nextchar}


Is there a better way to do this?

-Peter
Peter Wayner   Department of Computer Science Cornell Univ. Ithaca, NY 14850
EMail:wayner@cs.cornell.edu    Office: 607-255-9202 or 255-1008
Home: 116 Oak Ave, Ithaca, NY 14850  Phone: 607-277-6678

oster@well.sf.ca.us (David Phillip Oster) (12/31/90)

In article <50164@cornell.UUCP> wayner@kama.cs.cornell.edu (Peter Wayner) writes:
>If I read in a file of text, each character fills a byte. The
>problem is that the 68000 doesn't allow unalligned access, but
>the 68020/30 does. What is the best way to pull of characters
>one by one? 
Pulling the characters one by one is not a problem on the 68000. Byte
access is always legal, alignment doesn't enter into it. The problme comes
when you want to access Integer data that is not aligned on an even boundary.
	Ptr bufferPtr;

	...
	nextChar := bufferPtr^;
	bufferPtr := bufferPtr + 1;
for single char data.

-- 
-- David Phillip Oster - At least the government doesn't make death worse.
-- oster@well.sf.ca.us = {backbone}!well!oster

philip@pescadero.Stanford.EDU (Philip Machanick) (12/31/90)

In article <22358@well.sf.ca.us>, oster@well.sf.ca.us (David Phillip Oster) writes:
|> In article <50164@cornell.UUCP> wayner@kama.cs.cornell.edu (Peter Wayner) writes:
|> >If I read in a file of text, each character fills a byte. The
|> >problem is that the 68000 doesn't allow unalligned access, but
|> >the 68020/30 does. What is the best way to pull of characters
|> >one by one? 
|> Pulling the characters one by one is not a problem on the 68000. Byte
|> access is always legal, alignment doesn't enter into it. The problme comes
|> when you want to access Integer data that is not aligned on an even boundary.
|> 	Ptr bufferPtr;
|> 	...
|> 	nextChar := bufferPtr^;
|> 	bufferPtr := bufferPtr + 1;
|> for single char data.

Simpler still (though you may have to turn off array bound checking):

      bufferPtr : ^packed array [1..whatever] of char;
      {create space for the array and fill it}
      for i:=1 to size of array
         nextchar := bufferPtr^[i];
-- 
Philip Machanick
philip@pescadero.stanford.edu

siegel@endor.uucp (Rich Siegel) (01/01/91)

In article <50164@cornell.UUCP> wayner@kama.cs.cornell.edu (Peter Wayner) writes:
>If I read in a file of text, each character fills a byte. The
>problem is that the 68000 doesn't allow unalligned access, but
>the 68020/30 does. What is the best way to pull of characters
>one by one? 

	The 68000 does allow unaligned access to bytes, but not to words
or longwords. You can pick off characters one at a time with no problem.
(It'll probably be faster to use BlockMove for getting large chunks of 
characters.)

R.



 Rich Siegel	Symantec Languages Group  Internet: siegel@endor.harvard.edu

"...she's dressed in yellow, she says 'Hello, come sit next to me, you
fine fellow..."

kaufman@Neon.Stanford.EDU (Marc T. Kaufman) (01/01/91)

In article <5189@husc6.harvard.edu> siegel@endor.UUCP (Rich Siegel) writes:

>	The 68000 does allow unaligned access to bytes, but not to words
>or longwords.

There is no such thing as an unaligned byte access.  Every byte is at an
address that is 0 modulo (sizeof(byte)).  On the 68000, word and longword
accesses only have to be aligned to word boundaries (i.e. a longword can
have an address that ends ...xxx10) because the bus is only word sized.

Marc Kaufman (kaufman@Neon.stanford.edu)