int CpsPalInit() { int nLen = 0; nLen = 0x1000 * sizeof(short); CpsPalSrc = (unsigned char*)malloc(nLen); if (CpsPalSrc == NULL) { return 1; } memset(CpsPalSrc, 0, nLen); // The star layer palettes are at the end of the normal palette, so double the size nLen = 0x1000 * sizeof(int); CpsPal = (unsigned int*)malloc(nLen); if (CpsPal == NULL) { return 1; } // Set CpsPal to initial values CalcAll(); if (CpsStar) { CalcAllStar(0); CalcAllStar(1); } if (nLagObjectPalettes) { CpsObjPal = CpsPal + 0x0C00; } else { CpsObjPal = CpsPal; } return 0; }
void call_debugger(int where) { if (where == D_INT) { /* printf("Interrupt!\n"); */ return; } if (running) return; if (breakpoint) { if (&c_cs[ip] != bpoint) return; } in_debug = TRUE; running = breakpoint = FALSE; CalcAll(); process_input(); in_debug = FALSE; }
// Update CpsPal with the new palette at pNewPal (length 0x1000 bytes) int CpsPalUpdate(unsigned char* pNewPal, int bRecalcAll) { int i; unsigned short *ps, *pn; // If we are recalculating the whole palette, just copy to CpsPalSrc // and recalculate it all if (bRecalcAll) { ps = (unsigned short*)CpsPalSrc; pn = (unsigned short*)pNewPal; if (nLagObjectPalettes) { int nBuffer = 0x0C00 + ((GetCurrentFrame() & 1) << 9); memcpy(ps + 0x0200, pn + 0x0200, 0x0600 << 1); memcpy(ps + nBuffer, pn, 0x0200 << 1); memcpy(ps + 0x0E00, pn, 0x0200 << 1); CpsObjPal = CpsPal + nBuffer; } else { memcpy(ps, pn, 0x0800 << 1); } CalcAll(); return 0; } if (Cps == 2) { if (nLagObjectPalettes) { int nBuffer = 0x0C00 + ((GetCurrentFrame() & 1) << 9); ps = (unsigned short*)CpsPalSrc + (nBuffer ^ 0x0200); pn = (unsigned short*)pNewPal; CpsObjPal = CpsPal + (nBuffer ^ 0x0200); for (i = 0; i < 0x0200; i++, ps++, pn++) { unsigned short n; n = *pn; if (*ps == n) { continue; // Colour hasn't changed - great! } *ps = n; // Update our copy of the palette CpsObjPal[i ^ 15] = CalcColCPS2(n); } ps = (unsigned short*)CpsPalSrc + 0x0200; pn = (unsigned short*)pNewPal + 0x0200; for (i = 0x0200; i < 0x0800; i++, ps++, pn++) { unsigned short n; n = *pn; if (*ps == n) { continue; // Colour hasn't changed - great! } *ps = n; // Update our copy of the palette CpsPal[i ^ 15] = CalcColCPS2(n); } CpsObjPal = CpsPal + nBuffer; } else { ps = (unsigned short*)CpsPalSrc; pn = (unsigned short*)pNewPal; for (i = 0x0000; i < 0x0800; i++, ps++, pn++) { unsigned short n = *pn; if (*ps == n) { continue; // Colour hasn't changed - great! } *ps = n; // Update our copy of the palette CpsPal[i ^ 15] = CalcColCPS2(n); } } } else { ps = (unsigned short*)CpsPalSrc; pn = (unsigned short*)pNewPal; for (i = 0x0000; i < 0x0800; i++, ps++, pn++) { unsigned short n = *pn; if (*ps == n) { continue; // Colour hasn't changed - great! } *ps = n; // Update our copy of the palette CpsPal[i ^ 15] = CalcColCPS1(n); } } return 0; }