|
Post by gtoal on Sept 3, 2023 17:30:58 GMT -5
Before I go down a deep rabbit hole, can anyone tell me if this is the right way to test for a lightpen hit in C?
#define VIA_int_flags (*(volatile int *)0xD00D) VIA_int_flags = 0;
// draw an object if ((VIA_int_flags&2) != 0) { // object was picked. }
My reading of the docs and malban's asm example in Vide suggested something like the above to me, but I wouldn't mind a quick sanity check before I start coding. The pen will only be picking things that are drawn, I don't need to locate it in an empty area.
thanks,
G
|
|
|
Post by Peer on Sept 5, 2023 4:33:55 GMT -5
Before I go down a deep rabbit hole, can anyone tell me if this is the right way to test for a lightpen hit in C? #define VIA_int_flags (*(volatile int *)0xD00D) VIA_int_flags = 0;
// draw an object if ((VIA_int_flags&2) != 0) { // object was picked. } My reading of the docs and malban's asm example in Vide suggested something like the above to me, but I wouldn't mind a quick sanity check before I start coding. The pen will only be picking things that are drawn, I don't need to locate it in an empty area. thanks, G Hi Graham,
so far, I have not yet tried anything with the lightpen myself, so I cannot say. I am curious about what you find out. Just a quick remark, which might be helpful, as I guess that any code accessing the lightpen will be performance critical:
If you are using the C setup which Malban and I have created (and which is included in Vide), then there is no need for preprocessor magic defining the VIA ram locations (or any of the other Vectrex BIOS ram locations). Especially the ugly address cast and pointer dereferencing is avoided. In our setup, by simply including "vectrex.h", those locations are defined as regular global variables, e.g.:
extern volatile unsigned int VIA_int_flags __attribute__((section(".dpd0"))); // 0xD00D, VIA interrupt flags register
This not only allows for better type checking, but the linker also automatically maps them to the correct respective memory addresses. And, in addition to that, there are also corresponding global variables defined, which force the compiler to access those locations by direct page addressing:
extern volatile unsigned int dp_VIA_int_flags __attribute__((section(".direct"))); // 0xD00D, VIA interrupt flags register
In other words, the prefix "dp_" ensures direct page access:
// draw an object if ((dp_VIA_int_flags&2) != 0) { // will use direct page addressing // object was picked. }
You still have to ensure that the dp register is set accordingly, prior to execution of those lines, but properly used you can easily get all the performance advantages of direct page mode from C level.
Hope this helps.
Many Cheers, Peer PS: Malban's documentation on this can be found here.
|
|