//******************************************************************* // IRISモニタプログラム サブルーチン //******************************************************************* #include "IrisMon.h" //--------------------- グローバル 変数 ------------------------------- //---------------------------------------------------------------------- // レジスタ初期化 //---------------------------------------------------------------------- void InitReg(void) { *(vu32 *)REG_IME = 0; // IME クリア *(vu32 *)REG_IE = 0; // IE クリア *(vu32 *)REG_IF = -1; // IF クリア *(vu8 *)REG_WRAMCNT = WRAM_SUBP_ALL; // 共有内部ワークRAM割り当て #ifdef TS_MON *(vu16 *)REG_POWCNT = 0; // LCD OFF #else *(vu16 *)REG_POWCNT = POW_LCDC_ON; // LCD ON(TEGボードにてサウンド出力を有効にするため) #endif #ifdef TEST_ENABLE_JTAG *(u8 *)REG_PAUSE = 3; // JTAGイネーブル & チェックフラグ セット #endif // TEST_ENABLE_JTAG } //---------------------------------------------------------------------- // メモリ初期化 //---------------------------------------------------------------------- void InitRam(void) { #ifdef TEG_MON CpuClearFast32(0xffffffff, 0x01000000, 0xf000); // リストRAM クリア #endif CpuClearFast32(0, MON_DTCM, DTCM_SIZE - 512); // DTCM クリア CpuClearFast32(0, MAIN_MEM_EX_END - 0x8000, 0x8000); // メインメモリ・システム32KB領域 クリア } //---------------------------------------------------------------------- // CRC16bit 算出 //---------------------------------------------------------------------- const u16 crc16_table[16] = { 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 }; u16 GetCRC16(u32 start, u16 *datap, u32 size) { u16 *dataEndp = datap + size/2; u16 data16; u32 shift = 0; u16 r1, total = start; while(datap < dataEndp) { if (!shift) data16 = *datap; // 4bit単位 r1 = crc16_table[total & 0xf]; total = (total >>4); total = total ^ r1 ^ crc16_table[(data16 >>shift) & 0xf]; shift += 4; if (shift >= 0x10) { shift = 0; datap++; } } return total; } //---------------------------------------------------------------------- // メインメモリ 拡張チェック //---------------------------------------------------------------------- const u16 mmemSizeCheckTable[] = {0x56a9, 0x695a, 0xa695, 0x96a5}; s32 IsMmem8MB(void) { u32 mmemExFlag = 0; int i; for (i=0; i<4; i++) { *(vu16 *)MMEM_CHK_SIZE_WRITE_BUF = mmemSizeCheckTable[i]; if (*(vu16 *)MMEM_CHK_SIZE_READ_BUF != mmemSizeCheckTable[i]) mmemExFlag++; } *(vu16 *)MMEM_CHK_SIZE_WRITE_BUF = 0; return (mmemExFlag >= 3); } //---------------------------------------------------------------------- // ハフマンデータ展開(32Bit→32Bit) //---------------------------------------------------------------------- #define TREE_END 0x80 s32 UnCompHuffman32(const u8 *srcp, u32 *destp, u8 *tableBufp, const UC_InternalFuncp *ifp) { u8 *treep;// = (u8 *)srcp + 4; s32 treeSize;// = (*treep + 1) * 2; u32 treeCheck; u32 treeShift; u32 srcTmp; u32 destTmp = 0; u32 destTmpCount = 0; s32 srcCount; s32 error; int i; s32 header = ifp->InitFuncp(srcp, destp, tableBufp); // 初期化(アドレス送信) s32 size = header >>8; s32 destCount = size; s32 dataBit = header & 0x0f; u32 destTmpDataNum = 4 + (dataBit & 0x7); u32 destTopShift = 32 - dataBit; if (header < 0) { size = header; goto terminate; } srcp += 3; tableBufp[0] = ifp->ByteStreamFuncp(++srcp); treeSize = (tableBufp[0] + 1) * 2; for (i=1; iByteStreamFuncp(++srcp); srcp++; treep = tableBufp + 1; while (destCount > 0) { srcCount = 32; srcTmp = ifp->WordStreamFuncp(srcp); srcp += 4; while (--srcCount >= 0) { treeShift = (srcTmp >> 31) & 0x1; treeCheck = *treep; treeCheck <<= treeShift; treep = (u8 *)((((u32 )treep>>1) <<1) + (((*treep & 0x3f)+1) <<1) + treeShift); if (treeCheck & TREE_END) { destTmp >>= dataBit; destTmp |= *treep << destTopShift; treep = tableBufp + 1; if (++destTmpCount == destTmpDataNum) { *destp++ = destTmp; destCount -= 4; destTmpCount = 0; } } if (destCount <= 0) break; srcTmp <<= 1; } } terminate: if (ifp->TerminateFuncp) { // 終了ダミー読み込み if ((error = ifp->TerminateFuncp(srcp)) < 0) return error; } return size; } //---------------------------------------------------------------------- // LZバイトデータ展開(8Bit→16Bit) //---------------------------------------------------------------------- s32 UnCompLZ77Short(const u8 *srcp, u16 *destp, const void *paramp, const UC_InternalFuncp *ifp) { u32 destTmp = 0; u32 flags; s32 offset; s32 offset0_8; s32 length; u32 shift = 0; u8 src; s32 error; int i; s32 header = ifp->InitFuncp(srcp, destp, paramp); // 初期化(アドレス送信) s32 size = header >>8; s32 destCount = size; if (header < 0) { size = header; goto terminate; } srcp += 3; while (destCount > 0) { flags = ifp->ByteStreamFuncp(++srcp); for (i=8; --i>=0; ) { if (!(flags & 0x80)){ destTmp |= ifp->ByteStreamFuncp(++srcp) <ByteStreamFuncp(++srcp)) >>4) + 3; offset = ( src & 0x0f) << 8; offset = (offset | ifp->ByteStreamFuncp(++srcp)) + 1; offset0_8 = (8 - shift) ^ ((offset & 1) <<3); destCount -= length; while (--length >= 0) { offset0_8 ^= 8; destTmp |= (destp[-((offset + ((8 - shift) >>3)) >>1)] & (0xff <>offset0_8 <TerminateFuncp) { // 終了ダミー読み込み if ((error = ifp->TerminateFuncp(++srcp)) < 0) return error; } return size; } //---------------------------------------------------------------------- // ランレングスデータ展開(8Bit→16Bit) //---------------------------------------------------------------------- s32 UnCompRLShort(const u8 *srcp, u16 *destp, const void *paramp, const UC_InternalFuncp *ifp) { s32 srcTmp; s32 destTmp = 0; u32 flags; s32 offset; s32 length; u32 shift = 0; s32 error; s32 header = ifp->InitFuncp(srcp, destp, paramp); // 初期化(アドレス送信) s32 size = header >>8; s32 destCount = size; if (header < 0) { size = header; goto terminate; } srcp += 3; while (destCount > 0) { flags = ifp->ByteStreamFuncp(++srcp); length = flags & 0x7f; if (!(flags & 0x80)) { length++; destCount -= length; while (--length >= 0){ destTmp |= ifp->ByteStreamFuncp(++srcp) << shift; if (!(shift ^= 8)){ *destp++ = destTmp; destTmp = 0; } } } else { length += 3; destCount -= length; srcTmp = ifp->ByteStreamFuncp(++srcp); while (--length >= 0){ destTmp |= srcTmp << shift; if (!(shift ^= 8)){ *destp++ = destTmp; destTmp = 0; } } } } terminate: if (ifp->TerminateFuncp) { // 終了ダミー読み込み if ((error = ifp->TerminateFuncp(++srcp)) < 0) return error; } return size; }