trse (turbo rascal)und vic20

You need an actual VIC.

Moderator: Moderators

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

trse (turbo rascal)und vic20

Post by funkheld »

he trse (turbo-rascal) is good for me because I just program almost like in basic.
I did not even tackle the high-level commands from the trse.

a simple push program with the keys is 603 bytes in asm-code.
buttons: W / S / A / D for controlling and R / F for changing the color of the charsprite.

start : sys8192

I like to program with trse and VIV20.
you get to know the vic20 correctly with clear commands.

greeting

Code: Select all

program schiebechar;

var
charset : array[16] of byte = ( 24,24,60,126,255,24,36,66,255,129,129,129,129,129,129,255 );

a,b,f,x,y,p : byte;

zpcharz: pointer;
zpscr: pointer;
zpcol: pointer;

procedure  pause();
begin
	for a:=0 to 50 do
	begin 	     
    wait(100);
  end;
end;

begin
  ClearScreen(white, screen_col_loc);
    
  zpcharz:=5120;
  zpscr:=4096;
  
  zpcol:=37888;
  
  poke(^37139,0,0);
  poke(^37154,0,127);
  poke(^36869,0,205);
  poke(^36867,0,151);
  
  zpcharz:=5120;
	for b:=0 to 16 do
	begin
		zpcharz[b]:=charset[b];
	end;

  x:=11;
  y:=5;
  p:=y*22+x;
  f:=5;
  zpscr[p]:=0;
  zpcol[p]:=f;
		 
  while (true) do
	begin
	  waitforraster(0);
	  
    if peek(^197,0)= 18 then 
    begin
      pause();
      x:=x+1;
      if (x>21) then x:=21;
      p:=y*22+x;
      zpscr[p]:=0;
      zpcol[p]:=f;
      zpscr[p-1]:=128;
    end; 
    
    if peek(^197,0)= 17 then 
    begin
      pause();
      x:=x-1;
      if (x=255) then x:=0;
      p:=y*22+x;
      zpscr[p]:=0;
      zpcol[p]:=f;
      zpscr[p+1]:=128;
    end; 
    
   if peek(^197,0)= 41 then 
    begin
      pause();
      y:=y+1;
      if (y>10) then y:=10;
      p:=y*22+x;
      zpscr[p]:=0;
      zpcol[p]:=f;
      zpscr[p-22]:=128;
    end; 
    
   if peek(^197,0)= 9 then 
    begin
      pause();
      y:=y-1;
      if (y=255) then y:=0;
      p:=y*22+x;
      zpscr[p]:=0;
      zpcol[p]:=f;
      zpscr[p+22]:=128;
    end; 
     
    if peek(^197,0)= 10 then 
    begin
      pause();
      f:=f+1;
      if (f>7) then f:=7;
      zpcol[p]:=f;
    end;  
    
    if peek(^197,0)= 42 then 
    begin
      pause();
      f:=f-1;
      if (f=255) then f:=0;
      zpcol[p]:=f;
    end;  
  end; 
end.
Attachments
test.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 (turbo rascal)und vic20

Post by AndyH »

That's excellent :)

There are loads of example source files that come with TRSE and some games (Pumpkid will be included in a future release).

Remember with pointers:

zpscr[ p ]:=0;

This translates to sta (zpscr),y and y is 8-bit so the range will be limited.

You can use MoveTo to calculate a screenmemory (a built in pointer ) address on the fly, or you can use AddressTable commands to create a lookup table of rows for a little extra speed.


The ASM file that TRSE creates can be very useful to see what commands work best for each situation. TRSE tries to do its best to convert a high level language to a lower level and you can learn a lot by examining the ASM - sometimes you will see a simpler way to do it and there are lots of ways to optimise to make the program code even smaller.
--
AndyH
HEWCO | Vic 20 blog
User avatar
vicist
Vic 20 Afficionado
Posts: 352
Joined: Tue Oct 09, 2012 5:26 am
Location: Sheffield, UK

Re: trse (turbo rascal)und vic20

Post by vicist »

All seems to work OK except when I press the 'W' key to go up, the program quits. :(
I've checked through the code and it should work, but it doesn't.
Any ideas?
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 (turbo rascal)und vic20

Post by AndyH »

Ah yes. The Vic memory is a bit complicated.

The above code assumes 8K+ for the screen address used.

The code starts at $1200. The character memory is set to $1400 and this is overwrting the code which hits at that point.

Add this just under the program statement on line 2:
@startblock $2000 "code"

That will move the code to a higher address and it should then work.

There is a bug in TRSE when you tell it to set a different start address (a project setting). It will move the code to where you want but the BASIC stub that automatically runs it is not set up correctly at the moment, so you have do do your own sys call (and add 1 to the address you specify). I've raised the bug on Github so hopefully Nicolaas will get it fixed soon.

I've been using the startblock to put code and data in the right place instead of the project start address and this seems to work well :)


BTW, Ctrl +U will open the memory map which shows the complicated nature of the Vic memory and where your code and data sits within it.

And use AddBreakpoint(); command (on WIndows) to insert a breakpoint in the code, VICE will open up in the monitor when hit and you can trace through what happens - very useful when you get bugs in your program!
--
AndyH
HEWCO | Vic 20 blog
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: trse (turbo rascal)und vic20

Post by funkheld »

it is a mistake in the Trse.

set "target setting to $1fff" (see picture) and start with sys8192

greeting
Attachments
neu$1fff.jpg
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: trse (turbo rascal)und vic20

Post by funkheld »

@startblock $2000 "code" not ok.

greeting
Attachments
gehtnicht.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 (turbo rascal)und vic20

Post by AndyH »

funkheld wrote: Wed Nov 27, 2019 3:16 pm it is a mistake in the Trse.

set "target setting to $1fff" (see picture) and start with sys8192

greeting
Yes. I think so. I used the target setting in my 3K expanded game, but in my 16K game I used @startblock instead.

Oh, you could report it on the issue log - if it is an error I'm sure it can be fixed: https://github.com/leuat/TRSE/issues
--
AndyH
HEWCO | Vic 20 blog
Post Reply