TRSE : lo-byte and hi-byte to an integer.

You need an actual VIC.

Moderator: Moderators

Post Reply
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

TRSE : lo-byte and hi-byte to an integer.

Post by funkheld »

Hello, hello.
lo-byte and hi-byte to an integer?
how does that go please in trse?

hi = $34 $56 $77 ...
lo = $00 ,$00 , $00 ...

Result should always be:
$3400 $5600 ......

lo-byte is always 00

Thank you.
grudd
User avatar
AndyH
Vic 20 Afficionado
Posts: 364
Joined: Thu Jun 17, 2004 5:51 am
Website: https://www.hewco.uk
Location: UK
Occupation: Developer

Re: TRSE : lo-byte and hi-byte to an integer.

Post by AndyH »

Several ways I guess. Here's one:

Code: Select all

program Vic16k;

@startblock $2000 "code"

var  
	p1 : pointer;
	i1 : integer = 0; 
   
	addrlo : array[] of byte = ($00, $01, $02);
	addrhi : array[] of byte = ($10, $11, $10);

begin

	definescreen();

	// with a pointer
	poke( p1, 0, addrlo[ 0 ]);	
	poke( p1, 1, addrhi[ 0 ]);
	
	p1[0] := 1;
	


	// with an integer
	poke( i1, 0, addrlo[ 0 ]);	
	poke( i1, 1, addrhi[ 0 ]);

	screenmemory := $1002;
	printdecimal(i1, 4);

	loop();

end.
--
AndyH
HEWCO | Vic 20 blog
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: TRSE : lo-byte and hi-byte to an integer.

Post by funkheld »

hello thanks for the help.

greeting.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: TRSE : lo-byte and hi-byte to an integer.

Post by funkheld »

the last two are wrongly calculated by the poke.

greeting


addrlo : array[] of byte = ($00, $01, $02);
addrhi : array[] of byte = ($10, $11, $10);
Attachments
falsch.jpg
User avatar
AndyH
Vic 20 Afficionado
Posts: 364
Joined: Thu Jun 17, 2004 5:51 am
Website: https://www.hewco.uk
Location: UK
Occupation: Developer

Re: TRSE : lo-byte and hi-byte to an integer.

Post by AndyH »

Ah yes, looking at the asm produced there is a bug in there. I was told by the author not to use peek and poke any longer as pointers were a more elegant solution. Here, try this instead:

Code: Select all

	p1 := i1;
	p1[0] := addrlo[ 2 ];
	p1[1] := addrhi[ 2 ];
	
	screenmemory := $1002;
	printdecimal(i1, 4);
--
AndyH
HEWCO | Vic 20 blog
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: TRSE : lo-byte and hi-byte to an integer.

Post by funkheld »

hello thanks. is ok.

greeting
Post Reply