//waveデータをサウンドバッファにコピー bool CSound::WriteDataToBuffer(IDirectSoundBuffer** buffer, void* data, DWORD dwOffset, DWORD dwWriteSize) { //EnterCriticalSection(&m_csWriteBuffer); void* pmem[2]; DWORD alloc_size[2]; if(NULL == data || m_pSecondaryBuffer == NULL) return false; if(DSERR_BUFFERLOST == (*buffer)->Lock(dwOffset, dwWriteSize, &pmem[0], &alloc_size[0], &pmem[1], &alloc_size[1], 0)){//サウンドバッファをロック (*buffer)->Restore(); if(DS_OK != (*buffer)->Lock(dwOffset, dwWriteSize, &pmem[0], &alloc_size[0], &pmem[1], &alloc_size[1], 0)) return false; } //読み込んだサイズ分コピー if(pmem[0]){ CORE_ASSERT(dwWriteSize==alloc_size[0], ""); copyMem(pmem[0], data, alloc_size[0]); }else if(pmem[1]){ CORE_ASSERT(dwWriteSize==alloc_size[1], ""); copyMem(pmem[1], data, alloc_size[1]); }else{ CORE_ASSERT(0, "sound memory allocation error"); } (*buffer)->Unlock(pmem[0], alloc_size[0], pmem[1], alloc_size[1]); //バッファをアンロック //LeaveCriticalSection(&m_csWriteBuffer); return true; }
//================================================ // Read noBytes into buffer from the file fHandle //================================================ long ReadFromFile(struct FCB *fHandle, char *buffer, long noBytes) { long retval = 0; long bytesRead = 0; char done = 0; char *buff; struct Message *FSMsg; if (noBytes == 0) return 0; buff = AllocKMem(PageSize); FSMsg = ALLOCMSG; while (noBytes > PageSize) { FSMsg->nextMessage = 0; FSMsg->byte = READFILE; FSMsg->quad1 = (long) fHandle; FSMsg->quad2 = (long) buff; FSMsg->quad3 = PageSize; SendReceiveMessage(FSPort, FSMsg); copyMem(buff, buffer + bytesRead, (size_t) (FSMsg->quad1)); bytesRead += FSMsg->quad1; noBytes -= PageSize; if (FSMsg->quad1 < PageSize) done = 1; } if (!done) { FSMsg->nextMessage = 0; FSMsg->byte = READFILE; FSMsg->quad1 = (long) fHandle; FSMsg->quad2 = (long) buff; FSMsg->quad3 = noBytes; SendReceiveMessage(FSPort, FSMsg); copyMem(buff, buffer + bytesRead, (size_t) (FSMsg->quad1)); bytesRead += FSMsg->quad1; } retval = bytesRead; DeallocMem(buff); DeallocMem(FSMsg); return (retval); }
static UNUSED bool copyMMap(int in_fd, int out_fd) { off_t in_len = lseek(in_fd, 0, SEEK_END); void const * volatile in_buf = 0; void * volatile out_buf = 0; loff_t volatile buf_size = 0; bool volatile res = false; if (in_len==-1) return false; if (in_len>0 && ftruncate(out_fd, in_len)==-1) // create sparse file return false; bus_error = 0; if (sigsetjmp(bus_error_restore, 1)==0) { off_t offset = 0; while (offset < in_len) { buf_size = in_len - offset; if (buf_size > MMAP_BLOCKSIZE) buf_size = MMAP_BLOCKSIZE; if ((in_buf = mmap(0, buf_size, PROT_READ, MAP_SHARED, in_fd, offset))==MAP_FAILED || (out_buf = mmap(0, buf_size, PROT_WRITE, MAP_SHARED, out_fd, offset))==MAP_FAILED) { perror("mmap()"); goto out; } offset += buf_size; madvise(const_cast(void *)(in_buf), buf_size, MADV_SEQUENTIAL); madvise(out_buf, buf_size, MADV_SEQUENTIAL); TESTSUITE_COPY_CODE; copyMem(out_buf, in_buf, buf_size); munmap(out_buf, buf_size); out_buf = 0; munmap(const_cast(void *)(in_buf), buf_size); in_buf = 0; } res = true; }
//control passed here from bootTestCrt.S after creating stack int boot(){ uint32 *STORE1 = (uint32 *)0x4090002c; //Use RTC alarms as uint32 *STORE2 = (uint32 *)0x40900030; // storage for debugging int i,j; *STORE1 = 0x98765; setupLEDs(); setLEDs(GREEN); uint32 *kernel = (uint32 *)(RAM_START + KERNEL_OFFSET); uint32 *tags = (uint32 *)(RAM_START + TAGS_OFFSET); uint32 cs; setLEDs(GREEN); //now we need to copy the kernel code to where it likes to be cs = copyMem((uint32*)kernel_start,kernel, (kernel_end - kernel_start)); if(cs != KERN_CHECKSUM) error(5,0); setup_tags(tags); setLEDs(BLUE); uint32 mtype = MACH_TYPE_HPIPAQ214; void (*theKernel)(uint32 zero, uint32 mtype, uint32 *tags); theKernel = (void (*)(uint32, uint32, uint32 *))kernel; /* set the kernel address */ theKernel(0, mtype, tags); /* jump to kernel with register set */ death: __asm("nop"); goto death; }