WDC C Compiler for 65816 in action [PART II]
Hey all…
I managed to do a real quick update today. I’m back with both pad reading and background scrolling as promised. Scrolling was all easy to implement. Pad reading function was more difficult to get working. It’s mainly due to a bug or a bad usage from myself when linking. It don’t like return the padStatus struct. So i needed to modify my function to make it return a word and then cast. Here is code in details :
typedef struct padStatus{ byte right:1; byte left:1; byte down:1; byte up:1; byte start:1; // Enter byte select:1; // Space byte Y:1; // X byte B:1; // C //-------------------------------- byte Dummy:4; byte R:1; // Z byte L:1; // A byte X:1; // S byte A:1; // D } padStatus;word readPad(byte padNumber) { word test; // Enable pad reading *(byte*)0x4200 = 0x01; padNumber = padNumber << 1; test = (word) *(byte*)0x4218+padNumber << 8; test |= (word) *(byte*)0x4219+padNumber; return test; }
This allow to easily read the pad and then doing stuff like : if(pad1->left) … wich is quite nice.
I have contact WDC about the bug and i will keep you updated.
For you information here is the scrool code :
word padValue1; padStatus *pad1; byte HScroll = 0;// Pointer hacker for typecasting padStatus pad1 = (padStatus *) &padValue1;...// Loop forever while(1) { waitForVBlank(); // Read pad1 value padValue1 = readPad((byte) 0); if(pad1->left) { HScroll++; } else if(pad1->right) { HScroll--; } // Plane 0 scroll register *(byte*) 0x210d = HScroll; }
Full archive is available here as usual.
For any question, problem getting the code to compile, … please don’t hesitate to post a comment. I will then be glad to answer you.
So whats next ? What about a two simple effects and debug function to print text on screen ? Sounds nice …
++ Lint