C array reference from asm code with XA ?

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
User avatar
goyo
Pilot Officer
Posts: 64
Joined: Sat Jan 12, 2019 10:16 am

C array reference from asm code with XA ?

Post by goyo »

Hi,
Is it possible to use a C array reference from asm code ? (or the opposite) I wrote the following asm code but it doesn't works .

c code

Code: Select all

signed int map_y_index_lookup_table[] = {0,64,128,192,256,320,384,448,512,576,640,704,768,832,896,960,1024,1088};
asm code

Code: Select all

.global _map_y_index_lookup_table ; => 5177:Syntax error 
User avatar
Dbug
Site Admin
Posts: 4701
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: C array reference from asm code with XA ?

Post by Dbug »

The easiest is to do the opposite:

In you assembler code:

Code: Select all

_map_y_index_lookup_table .word 0,64,128,192,256,320,384,448,512,576,640,704,768,832,896,960,1024,1088
In your C code:

Code: Select all

extern int map_y_index_lookup_table[];
The advantage of declaring stuff in the assembler module over C is that:
- You can align data where you want
- You can declare variables in zero page

The only important thing to remember is that in the assembler module the symbols need to start by a _ character so they have global export.
User avatar
goyo
Pilot Officer
Posts: 64
Joined: Sat Jan 12, 2019 10:16 am

Re: C array reference from asm code with XA ?

Post by goyo »

Thank you Dbug ! I ll do like that
User avatar
goyo
Pilot Officer
Posts: 64
Joined: Sat Jan 12, 2019 10:16 am

Re: C array reference from asm code with XA ?

Post by goyo »

so I would like to set an array with negatives values in 8 bits,

what is the technic and the good practice to do this ?

is it possible for the C to read these values ?

Code: Select all

_tile_delta_y_step_lookup_table
.byt -80,-40,0,40,80
in main.c

Code: Select all

extern char tile_delta_y_step_lookup_table[]; 
it said : syntax error (at assembling phase.)
User avatar
Dbug
Site Admin
Posts: 4701
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: C array reference from asm code with XA ?

Post by Dbug »

Yeah that's unfortunately not something supported by XA, I wanted to fix that, never had the time.
I basically had to cheat by adding 255, like .byt 255-80
User avatar
ibisum
Wing Commander
Posts: 1743
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: C array reference from asm code with XA ?

Post by ibisum »

If its constants, and you need certainty, why not hex?

B0,D8,00,28,50
User avatar
Dbug
Site Admin
Posts: 4701
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: C array reference from asm code with XA ?

Post by Dbug »

When working with natural values signed decimal is a good choice, in the same way as binary works nicely for bitmaps, and hexadecimal nice for addresses.
User avatar
goyo
Pilot Officer
Posts: 64
Joined: Sat Jan 12, 2019 10:16 am

Re: C array reference from asm code with XA ?

Post by goyo »

Thank you Dbug , I didn't know two's complement, I'm discovering :)
Post Reply