pure pascal *** routines for peek poke byte word long***

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2476
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

pure pascal *** routines for peek poke byte word long***

Postby charles » Thu Feb 02, 2012 2:56 am

i'll post my code here later , but have a topic which needs some explaining ..

i have used asm to write external functions that do a peek , dpeek and a lpeek ,
in asm and linked them to my pascal program .

the peek works ,
and the dpeek works ,

but lastily the lpeek , does not.

read on....

so when i first began i thought
move.l(a0),do
would move a long value into d0 the first 4 bytes on the stack?returning from a linked code
it didn't
so i had to use the algo which move 4 bytes ,shl #8 --> form the long integer,in d0,
addtionily still won't return as a 4 byte value ,,
from #255,#255,#255,#255
returns -1 ?????

peek returns #255
dpeek returns #65535


so anybody ever experienced such instance?
how is it handeled to return properly..

charles
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2476
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: pure pascal *** routines for peek poke byte word long**

Postby charles » Thu Feb 02, 2012 3:39 am

the code:

Code: Select all


program peek_poke;

uses tos,dos,crt,gem,system;
{$X+}

function  peek(addr: longint): byte;  external;
function  dpeek(addr: longint): word;  external;
function  lpeek(addr: longint): longint;  external;

{$L PEEKS.O}

(* ****************************************** *)
const
bytes=100;

var
ab:packed array[0..bytes]of byte;
a:pointer;
aa:byte;

begin

a:=malloc(bytes);

(* *** with malloc mem ************* attempt 1 ************)
fillchar(a^,bytes,255);
write(peek(longint(a)),' ');
write(dpeek(longint(a)),' ');
write(lpeek(longint(a)),' ');
writeln('');
write(peek(longint(a)),' ');
write(peek(longint(a)+1),' ');
write(peek(longint(a)+2),' ');
write(peek(longint(a)+3),' ');
writeln('');
mfree(a);

(* *** with array mem ************** more attempts *********)
fillchar(ab[0],bytes,255);
a:=@ab[0];
write(peek(longint(a)),' ');
write(dpeek(longint(a)),' ');
write(lpeek(longint(a)),' ');
writeln('');
write(ab[0],' ');
write(ab[1],' ');
write(ab[2],' ');
write(ab[3],' ');
writeln('');




end.


{ ****** the asm assemble to dri with devpac ******

        OPT DRI
         
        XDEF PEEK,DPEEK,LPEEK

PEEK:   move.l d0,a0
        move.b (a0),d0           
        rts

DPEEK:    move.l  d0,a0
       move.b  (a0)+,d0
       lsl.w   #8,d0
       move.b  (a0)+,d0
        rts

LPEEK:    move.l  d0,a0
       move.b  (a0)+,d0
       lsl.w   #8,d0
       move.b  (a0)+,d0
       lsl.l   #8,d0
       move.b  (a0)+,d0
       lsl.l   #8,d0
       move.b  (a0)+,d0
       rts
}




The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

!cube
Atari maniac
Atari maniac
Posts: 80
Joined: Thu Jun 14, 2007 6:37 am
Location: Vantaa, Finland
Contact:

Re: pure pascal *** routines for peek poke byte word long**

Postby !cube » Thu Feb 02, 2012 9:55 am

Is there a particular reason why you read the data byte-by-byte? Are you expecting to load long words from unaligned memory addresses? If not, read the data in their correct size with move.w and move.l instead of juggling the bytes around with shifts.

You do realize that the four bytes #255, #255, #255, #255, interpreted as a long word, is -1 in decimal?
Kludge power since 1976.

joska
Hardware Guru
Hardware Guru
Posts: 4377
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: pure pascal *** routines for peek poke byte word long**

Postby joska » Thu Feb 02, 2012 12:00 pm

charles wrote:from #255,#255,#255,#255
returns -1 ?????


http://en.wikipedia.org/wiki/Two's_complement
Jo Even

VanillaMiNT - Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: pure pascal *** routines for peek poke byte word long**

Postby Nyh » Thu Feb 02, 2012 2:39 pm

joska wrote:
charles wrote:from #255,#255,#255,#255
returns -1 ?????


http://en.wikipedia.org/wiki/Two's_complement

Don't bother. He was told to read this 4 years ago.

Hans Wessels
Last edited by Nyh on Fri Feb 03, 2012 9:11 am, edited 1 time in total.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2476
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: pure pascal *** routines for peek poke byte word long**

Postby charles » Fri Feb 03, 2012 12:13 am

wow..? really? 255 255 255 255 is -1 ?
i knew it .

sorry , then my long peek routine might just work properly...been busy spent maybe an hour or two here and there throwing it together.

cub!: yes i will be using uneven address to retrieve word/longs from and its not memory allocated at run time its kind of "dynamic" allocated under certain condition using malloc,

so there are some tell tale signs i am programing again.

thanks everybody.. any use streamlining . and optimizing these codes?
even writing a super state peek dpeek lpeek?

thanks again thisw is very reassuring my skills are up but knowledge is down

charles
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2476
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: pure pascal *** routines for peek poke byte word long**

Postby charles » Fri Feb 03, 2012 11:43 pm

so , here is where i ask for some assistance , ..

what about the poke dpoke and lpoke ,

something is not taking , , i have been away from programming for a half year ,,and the instructions
for pure pascal are in complete german...

boils down to , link own routine for poke dpoke and lpoke

i'll post more code in abreif spell , be back later

charles
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest