Page 1 of 1

C - Assembly

Posted: Sun Oct 28, 2012 8:29 pm
by vrozos
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.

Re: C - Assembly

Posted: Sun Oct 28, 2012 10:49 pm
by Dbug
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 :)

Re: C - Assembly

Posted: Mon Oct 29, 2012 7:05 am
by vrozos
Thanks Dbug. I will use this for the moment, see how things go
and decide if I need something funkier.

V.

Re: C - Assembly

Posted: Sun Nov 04, 2012 9:46 pm
by vrozos
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.

Re: C - Assembly

Posted: Wed Nov 21, 2012 8:41 am
by vrozos
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.

Re: C - Assembly

Posted: Wed Nov 21, 2012 9:46 am
by Chema
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.