Jump to content
  • 0

Using both VERA ports together (in C)?


rje
 Share

Question

If I understand the VERA documentation correctly, I could write to VERA two bytes at a time, if I am careful.  Here's how I think I can do it.

But egads, it's so much work, it ain't worth it, is it?

//
// set the initial address for port 0, and set its auto increment to 2.
//
VERA.control = 0;   // select port 0
VERA.address = my_even_vram_address;
VERA.address_hi = 33; // incr = 2 and address = 1.  I think.
//
// set the initial address for port 1, and set its auto increment to 2.
//
VERA.control = 1;  // now select port 1
VERA.address = my_odd_vram_address;
VERA.address_hi = 33; // i.e. same as before, I think.
// 
// now I can set data, two bytes at a time.
//
#define    VERA_BY_2        (*(uint16_t*)0x9f23) 
VERA_BY_2 =  *((uint16_t*) myTwoByteStruct);
VERA_BY_2 =  *((uint16_t*) myNextTwoByteStruct);
VERA_BY_2 = *((uint16_t*) myThirdTwoByteStruct);
	// and so on

 

Edited by rje
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
7 minutes ago, rje said:

If I understand the VERA documentation correctly, I could write to VERA two bytes at a time, if I am careful.  Here's how I think I can do it.

But egads, it's so much work, it ain't worth it, is it?


//
// set the initial address for port 0, and set its auto increment to 2.
//
VERA.control = 0;   // select port 0
VERA.address = my_even_vram_address;
VERA.address_hi = 33; // incr = 2 and address = 1.  I think.
//
// set the initial address for port 1, and set its auto increment to 2.
//
VERA.control = 1;  // now select port 1
VERA.address = my_odd_vram_address;
VERA.address_hi = 33; // i.e. same as before, I think.
// 
// now I can set data, two bytes at a time.
//
#define    VERA_BY_2        (*(uint16_t*)0x9f23) 
VERA_BY_2 =  *((uint16_t*) myTwoByteStruct);
VERA_BY_2 =  *((uint16_t*) myNextTwoByteStruct);
VERA_BY_2 = *((uint16_t*) myThirdTwoByteStruct);
	// and so on

 

It will potentially simplify your code if you don't have to do all the casting. It won't make the code any faster. Tricks like this work on 16 bit and better machines to improve speed because they can do a single assignment of two or more bytes at once. The generated code will still be LDA STA LDA STA (or some equivalent).

BUT! I like the idea of simplification of code. I would make a dedicated two byte struct type that I can use instead of all the casting of pointers, and then I would make sure my structures were actually of that type. For example:

struct struct vera_data_type {
    uint8_t data0;
    uint8_t data1;
} vera_data_type;

#define VERA_DATA (*(vera_data_type*)0x9F23)

vera_data_type myStruct, myNextStruct, myThirdStruct;
vera_data_type* pMyData = &myStruct;

VERA_DATA = myStruct;
VERA_DATA = myNextStruct;
VERA_DATA = myThirdStruct;
VERA_DATA = *pMyData;
// etc

I hope that makes sense. It is a good idea to reduce redundancies and let the compiler do as much of the heavy lifting for you as possible when the abstraction increases code clarity or performance or both. In this case, I don't think it would be any slower, and your code could be simpler depending on what you need to do.

  • Thanks 1
Link to comment
Share on other sites

  • 0
32 minutes ago, ZeroByte said:

Pretty sure this arrangement exists because at the time it was designed, the 65c816 was still being considered.

That is a good point, though the arrangement still is useful even without for copying data from part of VRAM to another. I don't think VERA has an internal copy or fill function like the C=128 VDC, does it?

Using a 65816 would definitely make that more useful, though. Great point!

LDA x ; 5 cycles (assuming 16 bit accumulator / memory mode)
STA y ; 5 cycles

vs

LDA x+0 ; 4 cycles
STA y+0 ; 4 cycles
LDA x+1 ; 4 cycles
STA y+1 ; 4 cycles

So 10 vs 16 cycles or 37.5% faster. Yay!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use