cc65 : graphic with the vic20

You need an actual VIC.

Moderator: Moderators

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

cc65 : graphic with the vic20

Post by funkheld »

Hi good afternoon.

have now programmed the vic20 with the cc65.
the help here from the forum was helpful with the cfg.

start of the prg: sys 8717
see vic20-32k.cfg

have the memory beginning at 8717byte because the
graphics start at 4352byte.

draw with the "w / s / a / d /" keys.
use the "r" key to clear the screen to redraw
with the key "t" back to vic20

maybe you can expand that with "LINE" and "DRAW"?
Who can help.

vic20-32k.cfg

Code: Select all

# sys 8717
SYMBOLS {
    __LOADADDR__:  type = import;
    __EXEHDR__:    type = import;
    __STACKSIZE__: type = weak, value = $0800; # 2k stack
}
MEMORY {
    ZP:       file = "", define = yes, start = $0002, size = $001A;
    LOADADDR: file = %O,               start = $21FF, size = $0002;
    HEADER:   file = %O,               start = $2201, size = $000C;
    MAIN:     file = %O, define = yes, start = $220D, size = $5DF3 - __STACKSIZE__;
}
SEGMENTS {
    ZEROPAGE: load = ZP,       type = zp;
    LOADADDR: load = LOADADDR, type = ro;
    EXEHDR:   load = HEADER,   type = ro;
    STARTUP:  load = MAIN,     type = ro;
    LOWCODE:  load = MAIN,     type = ro,  optional = yes;
    ONCE:     load = MAIN,     type = ro,  optional = yes;
    CODE:     load = MAIN,     type = ro;
    RODATA:   load = MAIN,     type = ro;
    DATA:     load = MAIN,     type = rw;
    INIT:     load = MAIN,     type = bss;
    BSS:      load = MAIN,     type = bss, define   = yes;
}
FEATURES {
    CONDES: type    = constructor,
            label   = __CONSTRUCTOR_TABLE__,
            count   = __CONSTRUCTOR_COUNT__,
            segment = ONCE;
    CONDES: type    = destructor,
            label   = __DESTRUCTOR_TABLE__,
            count   = __DESTRUCTOR_COUNT__,
            segment = RODATA;
    CONDES: type    = interruptor,
            label   = __INTERRUPTOR_TABLE__,
            count   = __INTERRUPTOR_COUNT__,
            segment = RODATA,
            import  = __CALLIRQ__;
}
grafplot.c

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <modload.h>
#include <peekpoke.h>
#include <string.h>

char a,x,y,ma;
int scradr;
int ad,ay,i;

void text() {
POKE(36864,12);
POKE(36866,22);
POKE(36867,174);
POKE(36869,192);
}

void grafcls() {
for(i= 4352; i <= 8047; i += 1)
{
POKE(i,0);
}  
}

void  scrgraf() {	
for(i= 4352; i <= 8047; i += 1)
{
POKE(i,0);
}  

POKE(36867,151);
POKE(36866,21);
POKE(36869,204);
POKE(36864,14);

for(i= 16; i <= 255; i += 1)
{
POKE(4096+i-16,i);
POKE(37888+i-16,6);
} 
}	 

void plot() {
ad=4352;
ay=(y/16)*336+(y & 15);
ad=ad+16*(x/8)+ay;
ma= 1 << ((7-x) & 7);
POKE(ad,PEEK(ad) | ma);
}	

void main(void)
{
scradr=4352;

scrgraf();

x=80;
y=95;
plot();

while (1)
{
a=PEEK(197);

if (a==17)
{	
x=x-1;
if (x==255)
{	
x=x+1;
}	
plot();
}

if (a==18)
{	
x=x+1;
if (x>=168)
{	
x=x-1;
}	
plot();
}

if (a==9)
{	
y=y-1;
if (y==255)
{	
y=y+1;
}	
plot();
}

if (a==41)
{	
y=y+1;
if (y>=176)
{	
y=y-1;
}	
plot();
}

if (a==10)
{	
grafcls();
x=80;
y=95;
plot();
}

if (a==42)
{	
text();
break;
}
}
}
Thank you
greeting
Attachments
cc65-bild.jpg
Last edited by funkheld on Thu Jan 16, 2020 12:13 pm, edited 2 times in total.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: cc65 : graphic with the vic20

Post by Mike »

11 MB as attachment just to download a full copy of cc65 and your program as payload? :roll:

Other forums are much less generous for the allowed size of attachments!

Please shrink the attachment and include only the compiled program, its source and the makefile.

Then, provide a link where you downloaded that version of cc65 and we're fine.

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

I have a while loop here in cc65. the run goes too fast.

Post by funkheld »

Hi good afternoon.

I have a while loop here in cc65.
the run goes too fast.
what kind of timer can I put in there with that
it doesn't go that fast.

Thank you.
greeting

Code: Select all

while (1)
{
a=PEEK(197);

if (a==17)
{	
	x=x-1;
	if (x==255)
	{	
			x=x+1;
	}	
	p=y*22+x+scradr;
	POKE(p,0);
}

if (a==18)
{	
	x=x+1;
	if (x>=22)
	{	
			x=x-1;
	}	
	p=y*22+x+scradr;
	POKE(p,0);			
}

if (a==41)
{	
	y=y+1;
	if (y>=23)
	{	
			y=y-1;
	}	
	p=y*22+x+scradr;
	POKE(p,0);						
}
	
if (a==9)
{	
	y=y-1;
	if (y==255)
	{	
			y=y+1;
	}	
	p=y*22+x+scradr;
	POKE(p,0);		 			
}
}
(mod: thread merged as it's related to "cc65 : graphic with the vic20")
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: I have a while loop here in cc65. the run goes too fast.

Post by Mike »

funkheld wrote:what kind of timer can I put in there with that[?]
You can use the function clock() defined in <time.h> for this.

clock() determines the processor time used since startup (of the computer or of the program, that's implementation defined), in CLOCKS_PER_SECOND. How many clocks/second are there again is implementation defined, but that constant also is defined in <time.h>.

Then you'd proceed as follows:

Code: Select all

#include <time.h>

[...]

void my_delay(unsigned long dt)
{
  clock_t t0=clock();

  while(clock()-t0 < dt)
  {
  }
}

[... somewhere in your program ...]

my_delay(CLOCKS_PER_SECOND/10);  /* wait 1/10 second, as example */
This takes the timestamp t0 at function invocation, and then loops until the (continuously updated) time difference t-t0 exceeds the parameter dt.

The argument of the example call makes the delay roughly 1/10 second, which should be appropriate for your needs.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: cc65 : graphic with the vic20

Post by funkheld »

hello, thanks for the help.
is wonderfull.

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

I can't make it in the while 1 second to stop.

Post by funkheld »

Hi good afternoon.
I can't make it in the while 1 second to stop.

how does that work please

Thank you.
greeting

Code: Select all

unsigned long clocks_per_second;

void my_delay(unsigned long dt)
{
  clock_t t0=clock();

  while(clock()-t0 < dt)
  {
  }
}

void main(void)
{	
while (1)
{	
clocks_per_second=75000; 

a=PEEK(197);
	
if (a==17)
 {		      
  zahl=zahl >> 1 ;
  itoa(zahl,strwert,2); 
  printf(strwert);
  printf("\n");
 }
}		
}
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: cc65 : graphic with the vic20

Post by Mike »

Please stop asking questions that show an obvious misunderstanding how to use other people's code.

I gave you a working example for the use of the function my_delay() in my posting above.

Your preceding post does not call my_delay() at any point in the main program, for whatever reason you write to an extern variable 'clocks_per_second' that is never used otherwise. How could you expect the program to do whatever you wanted?
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: cc65 : graphic with the vic20

Post by funkheld »

ahhhh thank you ....
I did not think of that.

with fats 71 years you slowly get stupid in the head.

Thank you.
greeting
Post Reply