diff --git a/src/burn/drv/pgm/pgm_crypt.cpp b/src/burn/drv/pgm/pgm_crypt.cpp index 88ca37584..910458f74 100644 --- a/src/burn/drv/pgm/pgm_crypt.cpp +++ b/src/burn/drv/pgm/pgm_crypt.cpp @@ -8,14 +8,14 @@ void pgm_decrypt_dw2() UINT16 *src = (UINT16 *)PGM68KROM; for (INT32 i = 0; i> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -546,7 +546,7 @@ void pgm_decrypt_ddp2() UINT16 *src = (UINT16 *)PGMUSER0; for (INT32 i = 0; i < nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x0480) != 0x0080) x ^= 0x0001; if ((i & 0x0042) != 0x0042) x ^= 0x0008; @@ -557,7 +557,7 @@ void pgm_decrypt_ddp2() x ^= ddp2_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -585,7 +585,7 @@ void pgm_decrypt_martmast() // and dw2001 UINT16 *src = (UINT16 *)PGMUSER0; for (INT32 i = 0; i < nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x040480) != 0x000080) x ^= 0x0001; if ((i & 0x004008) == 0x004008) x ^= 0x0002; @@ -598,7 +598,7 @@ void pgm_decrypt_martmast() // and dw2001 x ^= mm_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -626,7 +626,7 @@ void pgm_decrypt_kov2() UINT16 *src = (UINT16 *)PGMUSER0; for (INT32 i = 0; i < nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x40080) != 0x00080) x ^= 0x0001; if ((i & 0x80030) == 0x80010) x ^= 0x0004; @@ -638,7 +638,7 @@ void pgm_decrypt_kov2() x ^= kov2_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -666,7 +666,7 @@ void pgm_decrypt_kov2p() UINT16 *src = (UINT16*)PGMUSER0; for (INT32 i = 0; i < nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x040080) != 0x000080) x ^= 0x0001; if ((i & 0x004008) == 0x004008) x ^= 0x0002; @@ -679,7 +679,7 @@ void pgm_decrypt_kov2p() x ^= kov2p_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -707,7 +707,7 @@ void pgm_decrypt_theglad() UINT16 *src = (UINT16*)PGMUSER0; for (INT32 i = 0; i < nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x040080) != 0x000080) x ^= 0x0001; if ((i & 0x104008) == 0x104008) x ^= 0x0002; @@ -720,7 +720,7 @@ void pgm_decrypt_theglad() x ^= theglad_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -748,7 +748,7 @@ void pgm_decrypt_killbldp() UINT16 *src = (UINT16*)PGMUSER0; for (INT32 i = 0; i< nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x040480) != 0x000080) x ^= 0x0001; if ((i & 0x104008) == 0x104008) x ^= 0x0002; @@ -761,7 +761,7 @@ void pgm_decrypt_killbldp() x ^= killbldp_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -789,7 +789,7 @@ void pgm_decrypt_happy6in1() UINT16 *src = (UINT16*)PGMUSER0; for (INT32 i = 0; i < nPGMExternalARMLen/2; i++) { - UINT16 x = src[i]; + UINT16 x = BURN_ENDIAN_SWAP_INT16(src[i]); if ((i & 0x040480) != 0x000080) x ^= 0x0001; if ((i & 0x104008) == 0x104008) x ^= 0x0002; @@ -802,7 +802,7 @@ void pgm_decrypt_happy6in1() x ^= happy6in1_tab[(i >> 1) & 0xff] << 8; - src[i] = x; + src[i] = BURN_ENDIAN_SWAP_INT16(x); } } @@ -836,7 +836,7 @@ void pgm_decode_kovqhsgs_tile_data(UINT8 *source) { j = BITSWAP24(i, 23, 22, 9, 8, 21, 18, 0, 1, 2, 3, 16, 15, 14, 13, 12, 11, 10, 19, 20, 17, 7, 6, 5, 4); - dst[j] = BITSWAP16(src[i], 1, 14, 8, 7, 0, 15, 6, 9, 13, 2, 5, 10, 12, 3, 4, 11); + dst[j] = BURN_ENDIAN_SWAP_INT16(BITSWAP16(BURN_ENDIAN_SWAP_INT16(src[i]), 1, 14, 8, 7, 0, 15, 6, 9, 13, 2, 5, 10, 12, 3, 4, 11)); } memcpy (src, dst, 0x800000); @@ -862,7 +862,7 @@ static void pgm_decode_kovqhsgs_program() { j = BITSWAP24(i, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 6, 7, 5, 4, 3, 2, 1, 0); - dst[j] = BITSWAP16(src[i], 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0); + dst[j] = BURN_ENDIAN_SWAP_INT16(BITSWAP16(BURN_ENDIAN_SWAP_INT16(src[i]), 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0)); } memcpy (src, dst, 0x400000); @@ -892,7 +892,7 @@ static void pgm_decode_kovlsqh2_program() { j = BITSWAP24(i, 23, 22, 21, 20, 19, 16, 15, 14, 13, 12, 11, 10, 9, 8, 0, 1, 2, 3, 4, 5, 6, 18, 17, 7); - dst[j] = src[i]; + dst[j] = BURN_ENDIAN_SWAP_INT16(src[i]); } memcpy (src, dst, 0x400000); diff --git a/src/burn/drv/pgm/pgm_draw.cpp b/src/burn/drv/pgm/pgm_draw.cpp index 0a0155785..c029986ae 100644 --- a/src/burn/drv/pgm/pgm_draw.cpp +++ b/src/burn/drv/pgm/pgm_draw.cpp @@ -321,18 +321,18 @@ static void pgm_drawsprites() { if (source[4] == 0) break; // right? - INT32 xpos = source[0] & 0x07ff; - INT32 ypos = source[1] & 0x03ff; - INT32 xzom = (source[0] & 0x7800) >> 11; - INT32 xgrow= (source[0] & 0x8000) >> 15; - INT32 yzom = (source[1] & 0x7800) >> 11; - INT32 ygrow= (source[1] & 0x8000) >> 15; - INT32 palt = (source[2] & 0x1f00) >> 8; - INT32 flip = (source[2] & 0x6000) >> 13; - INT32 boff =((source[2] & 0x007f) << 16) | (source[3] & 0xffff); - INT32 wide = (source[4] & 0x7e00) >> 9; - INT32 prio = (source[2] & 0x0080) >> 7; - INT32 high = source[4] & 0x01ff; + INT32 xpos = BURN_ENDIAN_SWAP_INT16(source[0]) & 0x07ff; + INT32 ypos = BURN_ENDIAN_SWAP_INT16(source[1]) & 0x03ff; + INT32 xzom = (BURN_ENDIAN_SWAP_INT16(source[0]) & 0x7800) >> 11; + INT32 xgrow= (BURN_ENDIAN_SWAP_INT16(source[0]) & 0x8000) >> 15; + INT32 yzom = (BURN_ENDIAN_SWAP_INT16(source[1]) & 0x7800) >> 11; + INT32 ygrow= (BURN_ENDIAN_SWAP_INT16(source[1]) & 0x8000) >> 15; + INT32 palt = (BURN_ENDIAN_SWAP_INT16(source[2]) & 0x1f00) >> 8; + INT32 flip = (BURN_ENDIAN_SWAP_INT16(source[2]) & 0x6000) >> 13; + INT32 boff =((BURN_ENDIAN_SWAP_INT16(source[2]) & 0x007f) << 16) | (BURN_ENDIAN_SWAP_INT16(source[3]) & 0xffff); + INT32 wide = (BURN_ENDIAN_SWAP_INT16(source[4]) & 0x7e00) >> 9; + INT32 prio = (BURN_ENDIAN_SWAP_INT16(source[2]) & 0x0080) >> 7; + INT32 high = BURN_ENDIAN_SWAP_INT16(source[4]) & 0x01ff; if (xgrow) xzom = 0x10-xzom; if (ygrow) yzom = 0x10-yzom; @@ -366,12 +366,12 @@ static void draw_text() { UINT16 *vram = (UINT16*)PGMTxtRAM; - INT32 scrollx = ((INT16)PGMVidReg[0x6000 / 2]) & 0x1ff; - INT32 scrolly = ((INT16)PGMVidReg[0x5000 / 2]) & 0x0ff; + INT32 scrollx = ((INT16)BURN_ENDIAN_SWAP_INT16(PGMVidReg[0x6000 / 2])) & 0x1ff; + INT32 scrolly = ((INT16)BURN_ENDIAN_SWAP_INT16(PGMVidReg[0x5000 / 2])) & 0x0ff; for (INT32 offs = 0; offs < 64 * 32; offs++) { - INT32 code = vram[offs * 2]; + INT32 code = BURN_ENDIAN_SWAP_INT16(vram[offs * 2]); if (texttrans[code] == 0) continue; // transparent INT32 sx = (offs & 0x3f) << 3; @@ -384,7 +384,7 @@ static void draw_text() if (sx >= nScreenWidth || sy >= nScreenHeight) continue; - INT32 attr = vram[offs * 2 + 1]; + INT32 attr = BURN_ENDIAN_SWAP_INT16(vram[offs * 2 + 1]); INT32 color = ((attr & 0x3e) >> 1) | 0x80; INT32 flipx = (attr & 0x40); INT32 flipy = (attr & 0x80); @@ -462,15 +462,15 @@ static void draw_background() UINT16 *dst = pTransDraw; UINT16 *rowscroll = PGMRowRAM; - INT32 yscroll = (INT16)PGMVidReg[0x2000 / 2]; - INT32 xscroll = (INT16)PGMVidReg[0x3000 / 2]; + INT32 yscroll = (INT16)BURN_ENDIAN_SWAP_INT16(PGMVidReg[0x2000 / 2]); + INT32 xscroll = (INT16)BURN_ENDIAN_SWAP_INT16(PGMVidReg[0x3000 / 2]); // check to see if we need to do line scroll INT32 t = 0; { UINT16 *rs = rowscroll; for (INT32 i = 0; i < 224; i++) { - if (rs[0] != rs[i]) { + if (BURN_ENDIAN_SWAP_INT16(rs[0]) != BURN_ENDIAN_SWAP_INT16(rs[i])) { t = 1; break; } @@ -495,12 +495,12 @@ static void draw_background() if (sx >= nScreenWidth || sy >= nScreenHeight) continue; - INT32 code = vram[offs * 2]; + INT32 code = BURN_ENDIAN_SWAP_INT16(vram[offs * 2]); if (code >= nTileMask) continue; if (tiletrans[code] == 0) continue; // transparent - INT32 color = ((vram[offs*2+1] & 0x3e) >> 1) | 0x20; - INT32 flipy = vram[offs*2+1] & 0x80; - INT32 flipx = vram[offs*2+1] & 0x40; + INT32 color = ((BURN_ENDIAN_SWAP_INT16(vram[offs*2+1]) & 0x3e) >> 1) | 0x20; + INT32 flipy = BURN_ENDIAN_SWAP_INT16(vram[offs*2+1]) & 0x80; + INT32 flipx = BURN_ENDIAN_SWAP_INT16(vram[offs*2+1]) & 0x40; if (sx < 0 || sy < 0 || sx >= nScreenWidth - 32 || sy >= nScreenHeight - 32) { @@ -584,11 +584,11 @@ static void draw_background() INT32 offs = ((scrolly & 0x1e0) << 2) | (((scrollx + x) & 0x7e0) >> 4); - INT32 code = vram[offs]; + INT32 code = BURN_ENDIAN_SWAP_INT16(vram[offs]); if (code >= nTileMask) continue; if (tiletrans[code] == 0) continue; - INT32 attr = vram[offs + 1]; + INT32 attr = BURN_ENDIAN_SWAP_INT16(vram[offs + 1]); INT32 color = ((attr & 0x3e) << 4) | 0x400; INT32 flipx = ((attr & 0x40) >> 6) * 0x1f; INT32 flipy = ((attr & 0x80) >> 7) * 0x1f; diff --git a/src/burn/drv/pgm/pgm_prot.cpp b/src/burn/drv/pgm/pgm_prot.cpp index 4e5d15a3d..2c5312431 100644 --- a/src/burn/drv/pgm/pgm_prot.cpp +++ b/src/burn/drv/pgm/pgm_prot.cpp @@ -560,7 +560,7 @@ static void IGS022_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT16 mode) { for (INT32 x = 0; x < size; x++) { - UINT16 dat2 = PROTROM[src + x]; + UINT16 dat2 = BURN_ENDIAN_SWAP_INT16(PROTROM[src + x]); UINT8 extraoffset = param & 0xfe; UINT8* dectable = (UINT8 *)PROTROM; @@ -573,10 +573,18 @@ static void IGS022_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT16 mode) if (mode==2) dat2 += extraxor; if (mode==1) dat2 -= extraxor; - sharedprotram[dst + x] = dat2; + sharedprotram[dst + x] = BURN_ENDIAN_SWAP_INT16(dat2); } - if ((mode==3) && (param==0x54) && (src*2==0x2120) && (dst*2==0x2600)) sharedprotram[0x2600 / 2] = 0x4e75; // hack + if ((mode==3) && (param==0x54) && (src*2==0x2120) && (dst*2==0x2600)) + { + #ifdef LSB_FIRST + sharedprotram[0x2600 / 2] = 0x4e75; // hack + #else + sharedprotram[0x2600 / 2] = 0x754e; + #endif + } + } break; @@ -610,12 +618,12 @@ static void IGS022_do_dma(UINT16 src, UINT16 dst, UINT16 size, UINT16 mode) static void IGS022_handle_command() { - UINT16 cmd = sharedprotram[0x200/2]; + UINT16 cmd = BURN_ENDIAN_SWAP_INT16(sharedprotram[0x200/2]); if (cmd == 0x6d) // Store values to asic ram { - UINT32 p1 = (sharedprotram[0x298/2] << 16) | sharedprotram[0x29a/2]; - UINT32 p2 = (sharedprotram[0x29c/2] << 16) | sharedprotram[0x29e/2]; + UINT32 p1 = BURN_ENDIAN_SWAP_INT16((sharedprotram[0x298/2] << 16)) | BURN_ENDIAN_SWAP_INT16(sharedprotram[0x29a/2]); + UINT32 p2 = BURN_ENDIAN_SWAP_INT16((sharedprotram[0x29c/2] << 16)) | BURN_ENDIAN_SWAP_INT16(sharedprotram[0x29e/2]); if ((p2 & 0xffff) == 0x9) // Set value { @@ -638,17 +646,17 @@ static void IGS022_handle_command() if ((p2 & 0xffff) == 0xa) // Get value { INT32 reg = (p1 >> 16) & 0x00ff; - sharedprotram[0x29c/2] = (kb_regs[reg] >> 16) & 0xffff; - sharedprotram[0x29e/2] = (kb_regs[reg] >> 0) & 0xffff; + sharedprotram[0x29c/2] = BURN_ENDIAN_SWAP_INT16((kb_regs[reg] >> 16) & 0xffff); + sharedprotram[0x29e/2] = BURN_ENDIAN_SWAP_INT16((kb_regs[reg] >> 0) & 0xffff); } } if (cmd == 0x4f) // memcpy with encryption / scrambling { - UINT16 src = sharedprotram[0x290 / 2] >> 1; // ? - UINT16 dst = sharedprotram[0x292 / 2]; - UINT16 size = sharedprotram[0x294 / 2]; - UINT16 mode = sharedprotram[0x296 / 2]; + UINT16 src = BURN_ENDIAN_SWAP_INT16(sharedprotram[0x290 / 2]) >> 1; // ? + UINT16 dst = BURN_ENDIAN_SWAP_INT16(sharedprotram[0x292 / 2]); + UINT16 size = BURN_ENDIAN_SWAP_INT16(sharedprotram[0x294 / 2]); + UINT16 mode = BURN_ENDIAN_SWAP_INT16(sharedprotram[0x296 / 2]); IGS022_do_dma(src, dst, size, mode); } @@ -1177,7 +1185,7 @@ static UINT16 __fastcall asic27a_read_word(UINT32 address) { if ((address & 0xff0000) == 0xd00000) { pgm_cpu_sync(); - return *((UINT16*)(PGMARMShareRAM + (address & 0xfffe))); + return BURN_ENDIAN_SWAP_INT16(*((UINT16*)(PGMARMShareRAM + (address & 0xfffe)))); } if ((address & 0xfffffc) == 0xd10000) { @@ -1269,7 +1277,7 @@ static void __fastcall kovsh_asic27a_write_word(UINT32 address, UINT16 data) static UINT16 __fastcall kovsh_asic27a_read_word(UINT32 address) { if ((address & 0xffffc0) == 0x4f0000) { - return *((UINT16*)(PGMARMShareRAM + (address & 0x3e))); + return BURN_ENDIAN_SWAP_INT16(*((UINT16*)(PGMARMShareRAM + (address & 0x3e)))); } switch (address) @@ -1292,7 +1300,7 @@ static void kovsh_asic27a_arm7_write_word(UINT32 address, UINT16 data) { // written... but never read? if ((address & 0xffffff80) == 0x50800000) { - *((UINT16*)(PGMARMShareRAM + ((address>>1) & 0x3e))) = data; + *((UINT16*)(PGMARMShareRAM + ((address>>1) & 0x3e))) = BURN_ENDIAN_SWAP_INT16(data); return; } } @@ -1495,7 +1503,7 @@ static UINT16 __fastcall olds_mainram_read_word(UINT32 address) { if (SekGetPC(-1) >= 0x100000 && address != 0x8178d8) SekWriteWord(0x8178f4, SekReadWord(0x8178D8)); - return *((UINT16*)(PGM68KRAM + (address & 0x1fffe))); + return BURN_ENDIAN_SWAP_INT16(*((UINT16*)(PGM68KRAM + (address & 0x1fffe)))); } static UINT8 __fastcall olds_mainram_read_byte(UINT32 address) @@ -1532,7 +1540,15 @@ void install_protection_asic25_asic28_olds() UINT16 *gptr = (UINT16*)(PGMUSER0 + 0x10000); for(INT32 i = 0; i < 0x4000 / 2; i++) { - if (gptr[i] == (0xffff - i)) gptr[i] = 0x4e75; + if (gptr[i] == (0xffff - i)) + { +#ifdef LSB_FIRST + gptr[i] = 0x4e75; +#else + gptr[i] = 0x754e; +#endif + } + } }