Following the Compute books instructions I redid the routine that sets up PM. Still not getting valid results, but I think its closer.
The players are cleared after the graphics are setup which is done in another routine.
I am a bit defeated at this point and going to step away and come back with a fresh perspective at some point in time, unless I get some new understanding of where I'm failing. At this point I think its something CC65 is doing with the memory segments -or- the display list is getting knocked out. One thing the book says is to give a graphics 0 command after setup so the OS will move the display and display list below the new RAMTOP. I cant figure out how to do that in CC65.
I dont have a screen shot, essentially it gets through this procedure, then starts clearing the players. Once it hits the 2nd pleyer, the screen goes into graphics 13 and you can see some text flash in and out of the first line.
void PMGraphics(byte bN)
{
// Address Masks, and Mem Sizes for each mode
unsigned int aAM[4] = { 0, 0xF800, 0xFC00 },
aMS[4] = { 0, 0x800, 0x400 };
// Default # pages to reserve for gr0 display
byte bR = 4;
// RAMTOP worker
byte bT = 0;
// Move all players and missiles off screen
memset((byte *) &(HPOSP0), 0, 8); // word
// Ensure tracking coords are all 0
memset(aPMH, 0, 8);
memset(aPMV, 0, 8);
// Set sizes to 0 and clear shapes of all 5 players
memset((byte *) &(SIZEP0), 0, 10); // word
// If current PM mode is not 0, default everything
// as we restart
if (bPMM != 0) {
SDMCTL = 34; // Default
GRACTL = 0;
}
// If requested mode is 1 (single line)
if (bN == 1) {
// Add 8 pages for single line res
bR += 8;
} else {
// Add 4 pages for double line res
bR += 4;
}
// If requested mode is 0, turn off PMG
if (bN == 0) {
SDMCTL = 34;
GRACTL = 0;
// Reset RAMTOP ? ****************************************************
// Save mode
bPMM = bN;
} else {
// Get current RAMTOP
bT = RAMTOP;
// Lower RAMTOP by # reserve pages
RAMTOP = RAMTOP - bR;
gotoxy(0,16);
printf("Old RAMTOP=%u (%u), R=%d\n", bT, bT * 256, bR); // 40960 (160)
printf("New RAMTOP=%u (%u)\n", RAMTOP, RAMTOP * 256);
printf(" APPMHI=%u\n", APPMHI); // 23583
// Set PMBASE to new RAMTOP
PMBASE = RAMTOP * 256;
wPMB = RAMTOP * 256;
printf("wPMB=%u (%u)\n", wPMB >> 8, wPMB); // 37888
printf(" PMBASE=%u\n", PEEK(54279U)); // 148 (* 256 = 37888)
// If requested mode is 1 (single line)
if (bN == 1) {
SDMCTL = 62;
} else {
// Else double line
SDMCTL = 46;
}
// Set player priority
GPRIOR = (GPRIOR & 0xC0) | 1;
printf(" GPRIOR=%d\n", GPRIOR);
// Turn on PMG
GRACTL = 3;
// Save mode
bPMM = bN;
}
}