Hello everybody, I'm new in cpctelera so please be patient with my questions
I'm pretty sure this will be simple and easy but can't find a way to read a memory location in cpctelera. I want to read the byte in xC000 (for example), which is the syntax to read a memory location inside a c file?
u8 value = <function>(cpct_getScreenPtr (CPCT_VMEM_START, 0, 0));
Also, how can I know the total size of my resulting project? I don't want to exceed 64KB.Is the file size of the .cdt generated a good reference?
Well, technically, your doubt is not about CPCtelera. Your doubt is about C programming language. You may probably want to refresh some C programming concepts not to have problems when dealing with low-level programming such as directly reading and writting memory bytes. In this case, you need to clearly understand pointers and memory access. Otherwise, the technical misconceptions that lay behind this doubt will probably drive you make mistakes that you won't understand and can frustrate you. Solid low-level understanding of pointers is your first weapon against big problems.
@Arnaud has already given you a possible solution. You may do it in many ways. The key is: in C you access memory through pointers. A pointer is a variable that holds a memory address. You use then the indirection operator (Also called dereference or 'Value at address' operator) '*' to get the value that lies at the address pointed by your pointer. So you may do this:
u8 value = *( (u8*)0xC000 );
0xC000 is just a value, and cannot be directly used to access a memory location (we need a pointer). So we cast it to a u8* (pointer to unsigned char, so it points to a byte). The result is a pointer, and so we can use the indirection operator on it '*' to access the contents of the memory it points to. Finally, that value is assigned to the variable 'value'.
@Arnaud did same operation, but divided into several steps.
If you plan to access several memory locations, you may want to use the pointer as if it was an array, using square brackets operator, like in here:
u8* memptr = (u8*)0xC000; // memptr points to 0xC000
u8 v1 = *(memptr + 9); // We get the value at location 0xC009
u8 v2 = memptr[9]; // Same as before, we get value at 0xC009, but using square brackets operator
u8 v3 = memptr[0]; // This gives as value at 0xC000, same as *memptr, same as *(memptr + 0)
As I said, this has nothing to do with CPCtelera. It is standard C and works either on SDCC for Z80, or on GCC/CLang for your PC.
Hop this helps