1 /*********************************************************************************
\r
3 * --------------------------------------------------------------------------------
\r
5 * This file is part of MiMic
\r
6 * Copyright (C)2011 Ryo Iizuka
\r
8 * MiMic is free software: you can redistribute it and/or modify
\r
9 * it under the terms of the GNU Lesser General Public License as published
\r
10 * by the Free Software Foundation, either version 3 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU Lesser General Public License
\r
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
21 * For further information please contact.
\r
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 *********************************************************************************/
\r
26 #include "NyLPC_cPtrStream_protected.h"
\r
29 * ROMをラップするブロッキングストリーム型です。
\r
30 * このクラスは、NyLPC_TcBlockingStreamにキャストすることができます。
\r
32 このクラスは、read onlyです。write動作は永久に失敗します。
\r
33 また、タイムアウト値は意味を持たず、最終データを読みだした後はカウント0でタイムアウトと同じ挙動を示します。
\r
35 typedef struct NyLPC_TcRomPtrStream NyLPC_TcRomPtrStream_t;
\r
37 /**********************************************************************
\r
39 * NyLPC_TcRomBlockingStream class
\r
41 **********************************************************************/
\r
43 struct NyLPC_TcRomPtrStream
\r
45 NyLPC_TcPtrStream_t _super;
\r
46 NyLPC_TChar* _rom; //ROMアドレス
\r
47 NyLPC_TInt32 _rom_size; //ROMサイズ
\r
48 NyLPC_TInt32 _ed; //読出し済みサイズ
\r
49 NyLPC_TInt16 _packet_size; //一度当たりの読出しサイズ制限
\r
52 NyLPC_TBool NyLPC_TcRomPtrStream_initialize(NyLPC_TcRomPtrStream_t* i_inst,void* i_rom_addr,NyLPC_TInt32 i_length,NyLPC_TInt16 i_packetsize);
\r
54 #define NyLPC_TcRomPtrStream_finalize(i_inst)
\r
56 static NyLPC_TInt32 m_pread(NyLPC_TcPtrStream_t* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec);
\r
57 static void m_close(NyLPC_TcPtrStream_t* i_inst);
\r
58 static void m_preadSeek_func(NyLPC_TcPtrStream_t* i_inst,NyLPC_TUInt16 i_seek);
\r
61 static struct NyLPC_TcPtrStream_TInterface NyLPC_TcRomPtrStream_Interface=
\r
64 NyLPC_cPtrStream_write_func,
\r
71 NyLPC_TBool NyLPC_TcRomPtrStream_initialize(NyLPC_TcRomPtrStream_t* i_inst,void* i_rom_addr,NyLPC_TInt32 i_length,NyLPC_TInt16 i_packetsize)
\r
73 NyLPC_ArgAssert(i_inst!=NULL);
\r
74 NyLPC_ArgAssert(i_rom_addr!=NULL);
\r
75 NyLPC_ArgAssert(i_length>0);
\r
76 NyLPC_ArgAssert(i_packetsize>0);
\r
77 i_inst->_super._interface=&NyLPC_TcRomPtrStream_Interface;
\r
78 i_inst->_rom=(NyLPC_TChar*)i_rom_addr;
\r
79 i_inst->_rom_size=i_length;
\r
80 i_inst->_packet_size=i_packetsize;
\r
81 return NyLPC_TBool_TRUE;
\r
84 static void m_preadSeek_func(NyLPC_TcPtrStream_t* i_inst,NyLPC_TUInt16 i_seek)
\r
87 NyLPC_TcRomPtrStream_t* inst=(NyLPC_TcRomPtrStream_t*)i_inst;
\r
93 static NyLPC_TBool m_pread(NyLPC_TcPtrStream_t* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec)
\r
95 NyLPC_TInt32 size,psize;
\r
96 NyLPC_TcRomPtrStream_t* inst=(NyLPC_TcRomPtrStream_t*)i_inst;
\r
98 NyLPC_ArgAssert(i_inst!=NULL);
\r
99 NyLPC_ArgAssert(o_buf_ptr!=NULL);
\r
101 NyLPC_Assert(inst->_rom!=NULL);
\r
103 size=inst->_rom_size-inst->_ed; //残り長さ計算
\r
104 psize=(size>inst->_packet_size)?inst->_packet_size:size; //パケットサイズ計算
\r
105 *o_buf_ptr=(inst->_rom+inst->_ed); //現在位置を返す
\r
106 inst->_ed+=psize;//読出し位置更新
\r
111 static void m_close(NyLPC_TcPtrStream_t* i_inst)
\r
113 NyLPC_TcRomPtrStream_t* inst=(NyLPC_TcRomPtrStream_t*)i_inst;
\r