C - Assembly

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
Post Reply
vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

C - Assembly

Post by vrozos » Sun Oct 28, 2012 8:29 pm

I am planning to do something in C for Oric and I need
the Basic's functions PLOT and SCRN.

In the OSDK the hello_world_advanced is included
in the C samples. In this project there is a function
written in assembly which is called AdvancedPrint and is
equivalent to PLOT (I think so).

Is the Basic's SCRN already implemented somehow in C?
If not, then I would prefer to prepare something in assembly.

The AdvancedPrint demonstrates how to read arguments
passed from a call from C (use of sp variable). Can anyone
please tell me how can I return a value (say a char) from
assembly to C?

Thanks

V.

User avatar
Dbug
Site Admin
Posts: 2299
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: C - Assembly

Post by Dbug » Sun Oct 28, 2012 10:49 pm

Depends of the performance you are looking for, but the PLOT and SCRN functions can be implemented like that in C:

Code: Select all

void PLOT(unsigned char x,unsigned char y,unsigned char car)
{
   unsigned char* screen=(unsigned char*)0xBB80;
   screen[x+(int)y*40]=car;
}

unsigned char SCRN(unsigned char x,unsigned char y)
{
   unsigned char* screen=(unsigned char*)0xBB80;
   return screen[x+(int)y*40];
}
Disclaimer: Just typed on the message, not tested :)

vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Re: C - Assembly

Post by vrozos » Mon Oct 29, 2012 7:05 am

Thanks Dbug. I will use this for the moment, see how things go
and decide if I need something funkier.

V.

vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Re: C - Assembly

Post by vrozos » Sun Nov 04, 2012 9:46 pm

Dbug wrote:Depends of the performance you are looking for, but the PLOT and SCRN functions can be implemented like that in C:

Code: Select all

void PLOT(unsigned char x,unsigned char y,unsigned char car)
{
   unsigned char* screen=(unsigned char*)0xBB80;
   screen[x+(int)y*40]=car;
}

unsigned char SCRN(unsigned char x,unsigned char y)
{
   unsigned char* screen=(unsigned char*)0xBB80;
   return screen[x+(int)y*40];
}
Disclaimer: Just typed on the message, not tested :)

void PLOT(int x,int y, char car)
{
screen[x+(y+1)*40]=car;
}

unsigned char SCRN(int x,int y)
{
return screen[x+(y+1)*40];
}

The first line is not accessible by Basic's PLOT so you need to increase y by 1.

V.

vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Re: C - Assembly

Post by vrozos » Wed Nov 21, 2012 8:41 am

vrozos wrote: Can anyone
please tell me how can I return a value (say a char) from
assembly to C?

V.
Please correct me if I am wrong. The register A contains the high
and the register X the low value of the address where function
result is stored.

V.

User avatar
Chema
Game master
Posts: 1918
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: C - Assembly

Post by Chema » Wed Nov 21, 2012 9:46 am

vrozos wrote:
vrozos wrote: Can anyone
please tell me how can I return a value (say a char) from
assembly to C?

V.
Please correct me if I am wrong. The register A contains the high
and the register X the low value of the address where function
result is stored.

V.
Not sure if I that is correct. In fact the returned value, I think, is always a 16-bit number stored in A and X (can't remember which one holds the high byte and which the low byte), not the address of the value.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest