int main(int argc, char ** argv[]) { char * cs3_base; cs3_base = malloc(4096); memopen(); *(cs3_base + 1) = 'A'; pid_t pid; pid_t ppid; pid = fork(); if (pid == 0) { *(cs3_base + 1) = 'B'; } else if (pid > 0) { *(cs3_base + 2) = 'C'; } write(fd, cs3_base, 10); EXIT2: memrelease(); free(cs3_base); return 0; }
int main() { printf("Hello world!\n"); memopen(); close(fd); return 0; }
void SD_Manage(int mode, int slot){ sd_file *handle; char path[1024]; char msg[128]; int offset = 0; int filesize = 0; int len = 0; //sprintf (filepath, "dev%d:\\%s\\%08x.fcs", slot, SAVEDIR, iNESGameCRC32); sprintf (path, "dev%d:\\%08x.fcs", slot, iNESGameCRC32); if (mode == 0) ShowAction ("Saving STATE to SD..."); else ShowAction ("Loading STATE from SD..."); handle = (mode == 0) ? SDCARD_OpenFile (path, "wb") : SDCARD_OpenFile (path, "rb"); if (handle == NULL){ sprintf(msg, "Couldn't open %s", path); WaitPrompt(msg); return; } if (mode == 0){ //Save filesize = GCFCEUSS_Save(); len = SDCARD_WriteFile (handle, statebuffer, filesize); SDCARD_CloseFile (handle); if (len != filesize){ sprintf (msg, "Error writing %s", path); WaitPrompt (msg); return; } sprintf (msg, "Saved %d bytes successfully", filesize); WaitPrompt (msg); } else{ //Load memopen(); while ((len = SDCARD_ReadFile (handle, &statebuffer[offset], 1024)) > 0) offset += len; SDCARD_CloseFile (handle); sprintf (msg, "Loaded %d bytes successfully", offset); WaitPrompt(msg); GCFCEUSS_Load(); return ; } }
/**************************************************************************** * GCFCEUSS_Save * * This is a modified version of FCEUSS_Save * It uses memory for it's I/O and has an added CHNK block. * The file is terminated with CHNK length of 0. ****************************************************************************/ int GCFCEUSS_Save() { int totalsize = 0; static unsigned char header[16] = "FCS\xff"; char chunk[] = "CHKE"; int zero = 0; char Comment[2][100] = { { MENU_CREDITS_TITLE }, { "GAME" } }; memopen(); /*** Reset Memory File ***/ /*** Add version ID ***/ memcpy(&header[8], &mcversion, 4); /*** Do internal Saving ***/ FCEUPPU_SaveState(); FCEUSND_SaveState(); /*** Write Icon ***/ memfwrite(&saveicon, sizeof(saveicon)); totalsize += sizeof(saveicon); /*** And Comments ***/ strncpy (Comment[1],romFilename,31); // we only have 32 chars to work with! memfwrite(&Comment[0], 64); totalsize += 64; /*** Write header ***/ memfwrite(&header, 16); totalsize += 16; totalsize += GCSaveChunk(1, SFCPU); totalsize += GCSaveChunk(2, SFCPUC); totalsize += GCSaveChunk(3, FCEUPPU_STATEINFO); totalsize += GCSaveChunk(4, FCEUCTRL_STATEINFO); totalsize += GCSaveChunk(5, FCEUSND_STATEINFO); totalsize += GCSaveChunk(0x10, SFMDATA); /*** Add terminating CHNK ***/ memfwrite(&chunk,4); memfwrite(&zero,4); totalsize += 8; /*** Update size element ***/ memcpy(&savebuffer[FILESIZEOFFSET], &totalsize, 4); return totalsize; }
/**************************************************************************** * GCFCEUSS_Save * * This is a modified version of FCEUSS_Save * It uses memory for it's I/O and has an added CHNK block. * The file is terminated with CHNK length of 0. ****************************************************************************/ int GCFCEUSS_Save() { int totalsize = 0; static unsigned char header[16] = "FCS\xff"; char chunk[] = "CHKE"; int zero = 0; char Comment[2][32] = { { "FCEU GC Version 1.0.9" }, { "A GAME" } }; memopen(); /*** Reset Memory File ***/ /*** Add version ID ***/ memcpy(&header[8], &mcversion, 4); /*** Do internal Saving ***/ FCEUPPU_SaveState(); FCEUSND_SaveState(); /*** Write Icon ***/ memfwrite(&saveicon, sizeof(saveicon)); totalsize += sizeof(saveicon); /*** And Comments ***/ sprintf(Comment[1], "NES CRC 0x%08x", iNESGameCRC32); memfwrite(&Comment[0], 64); totalsize += 64; /*** Write header ***/ memfwrite(&header, 16); totalsize += 16; totalsize += GCSaveChunk(1, SFCPU); totalsize += GCSaveChunk(2, SFCPUC); totalsize += GCSaveChunk(3, FCEUPPU_STATEINFO); totalsize += GCSaveChunk(4, FCEUCTRL_STATEINFO); totalsize += GCSaveChunk(5, FCEUSND_STATEINFO); totalsize += GCSaveChunk(0x10, SFMDATA); /*** Add terminating CHNK ***/ memfwrite(&chunk,4); memfwrite(&zero,4); totalsize += 8; /*** Update size element ***/ memcpy(&statebuffer[FILESIZEOFFSET], &totalsize, 4); return totalsize; }
HI_S32 vo_video_csc_config(HI_U32 u32LayerId, HI_U32 enCscMatrix, HI_U32 u32Luma, HI_U32 u32Contrast, HI_U32 u32Hue, HI_U32 u32Satuature, HI_U32 u32Gain) { HI_S32 s32Ret; CscCoef_S stCscCoef; HI_U8 *pAddr = NULL; HI_U32 *pRegAddr = NULL; HI_U32 u32CscIdc, u32CscOdc, u32CscP0, u32CscP1, u32CscP2, u32CscP3, u32CscP4; HI_U32 u32DacCtrl0_2; HI_S32 s32Matrix; usage(); if (u32LayerId < 0 || u32LayerId > 3) { printf ("layer err \n"); usage(); return -1; } if (u32Contrast < 0 || u32Contrast > 100) { printf ("u32Contrast err \n"); usage(); return -1; } if (u32Hue < 0 || u32Hue > 100) { printf ("u32Hue err \n"); usage(); return -1; } if (u32Luma < 0 || u32Luma > 100) { printf ("u32Luma err \n"); usage(); return -1; } if (u32Satuature < 0 || u32Satuature > 100) { printf ("u32Satuature err \n"); usage(); return -1; } if (u32Gain < 0x0 || u32Gain > 0x3F) { printf ("u32Gain err \n"); usage(); return -1; } if (enCscMatrix < 0 || enCscMatrix > 2) { printf ("enCscMatrix err \n"); usage(); return -1; } switch(enCscMatrix) { case 0:s32Matrix = HAL_CSC_MODE_RGB_TO_RGB;break; case 1:s32Matrix = HAL_CSC_MODE_BT601_TO_BT709;break; case 2:s32Matrix = HAL_CSC_MODE_BT709_TO_BT601;break; default: return -1; } vou_cal_csc_matrix(u32Luma, u32Contrast, u32Hue, u32Satuature,s32Matrix, &stCscCoef); u32CscIdc = ((get_xdc_buma(stCscCoef.csc_in_dc2) & 0x1ff) | ((get_xdc_buma(stCscCoef.csc_in_dc1) & 0x1ff) << 9) | ((get_xdc_buma(stCscCoef.csc_in_dc0) & 0x1ff) << 18)); u32CscOdc = ((get_xdc_buma(stCscCoef.csc_out_dc2) & 0x1ff) | ((get_xdc_buma(stCscCoef.csc_out_dc1) & 0x1ff) << 9) | ((get_xdc_buma(stCscCoef.csc_out_dc0) & 0x1ff) << 18)); u32CscP0 = ((conver_csc_coef(stCscCoef.csc_coef00) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef01) & 0x1fff) << 16)); u32CscP1 = ((conver_csc_coef(stCscCoef.csc_coef02) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef10) & 0x1fff) << 16)); u32CscP2 = ((conver_csc_coef(stCscCoef.csc_coef11) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef12) & 0x1fff) << 16)); u32CscP3 = ((conver_csc_coef(stCscCoef.csc_coef20) & 0x1fff) | ((conver_csc_coef(stCscCoef.csc_coef21) & 0x1fff) << 16)); u32CscP4 = (conver_csc_coef(stCscCoef.csc_coef22) & 0x1fff); memopen(); pAddr = (HI_U8 *)memmap(VO_BASE_REG, VO_VIDEO_CSC_SIZE); if(NULL == pAddr) { printf("err: memmap failure\n"); return HI_FAILURE; } //printf("sys_map 0x%x\n", pAddr); pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCIDC)); u32CscIdc |= (*pRegAddr & 0x08000000); //csc_en //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscIdc); *pRegAddr = u32CscIdc; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCODC)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscOdc); *pRegAddr = u32CscOdc; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP0)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP0); *pRegAddr = u32CscP0; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP1)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP1); *pRegAddr = u32CscP1; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP2)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP2); *pRegAddr = u32CscP2; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP3)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP3); *pRegAddr = u32CscP3; pRegAddr = (HI_U32 *)(vo_get_layer_addr(u32LayerId, pAddr + VHDCSCP4)); //printf("addr 0x%x, old value 0x%x, new value 0x%x\n", pRegAddr, *pRegAddr, u32VgaCscP4); *pRegAddr = u32CscP4; pRegAddr = (HI_U32 *)(pAddr + (DACCTRL0_2 - VO_BASE_REG)); set_cvbs_gain(u32LayerId, pRegAddr, u32Gain); memunmap(VO_BASE_REG, VO_VIDEO_CSC_SIZE); memclose(); return HI_SUCCESS; }
int biosmptable_detect(void) { mpfps_t mpfps; mpcth_t mpcth; char *entry_type_p; proc_entry_ptr proc; int ncpu, i; if (!memopen()) return -1; /* XXX 0? */ /* locate and validate the mpfps */ mpfps = biosmptable_find_mpfps(); mpcth = NULL; if (mpfps == NULL) { ncpu = 0; } else if (mpfps->config_type != 0) { /* * If thie config_type is nonzero then this is a default configuration * from Chapter 5 in the MP spec. Report 2 cpus and 1 I/O APIC. */ ncpu = 2; } else { ncpu = 0; mpcth = biosmptable_check_mpcth(PTOV(mpfps->pap)); if (mpcth != NULL) { entry_type_p = (char *)(mpcth + 1); for (i = 0; i < mpcth->entry_count; i++) { switch (*entry_type_p) { case 0: entry_type_p += sizeof(struct PROCENTRY); proc = (proc_entry_ptr) entry_type_p; warnx("MPTable: Found CPU APIC ID %d %s", proc->apic_id, proc->cpu_flags & PROCENTRY_FLAG_EN ? "enabled" : "disabled"); if (proc->cpu_flags & PROCENTRY_FLAG_EN) ncpu++; break; case 1: entry_type_p += sizeof(struct BUSENTRY); break; case 2: entry_type_p += sizeof(struct IOAPICENTRY); break; case 3: case 4: entry_type_p += sizeof(struct INTENTRY); break; default: warnx("unknown mptable entry type (%d)", *entry_type_p); goto done; /* XXX error return? */ } } done: ; } } memclose(); if (mpcth != NULL) free(mpcth); if (mpfps != NULL) free(mpfps); return ncpu; }
HI_S32 SAMPLE_MISC_VoDump(VO_DEV VoDev, HI_U32 u32Cnt) { HI_S32 i, s32Ret; VIDEO_FRAME_INFO_S stFrame; //VIDEO_FRAME_INFO_S astFrame[256]; HI_CHAR szYuvName[128]; HI_CHAR szPixFrm[10]; FILE *pfd; printf("\nNOTICE: This tool only can be used for TESTING !!!\n"); printf("usage: ./vo_screen_dump [vodev] [frmcnt]. sample: ./vo_screen_dump 0 1\n\n"); /* Get Frame to make file name*/ s32Ret = HI_MPI_VO_GetScreenFrame(VoDev, &stFrame); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VO(%d)_GetScreenFrame errno %#x\n", VoDev, s32Ret); return -1; } /* make file name */ strcpy(szPixFrm, (PIXEL_FORMAT_YUV_SEMIPLANAR_420 == stFrame.stVFrame.enPixelFormat)?"p420":"p422"); sprintf(szYuvName, "./vo(%d)_%d_%d_%s_%d.yuv",VoDev, stFrame.stVFrame.u32Width, stFrame.stVFrame.u32Height,szPixFrm,u32Cnt); printf("Dump YUV frame of vo(%d) to file: \"%s\"\n",VoDev, szYuvName); HI_MPI_VO_ReleaseScreenFrame(VoDev, &stFrame); /* open file */ pfd = fopen(szYuvName, "wb"); if (NULL == pfd) { return -1; } memopen(); /* get VO frame */ for (i=0; i<u32Cnt; i++) { s32Ret = HI_MPI_VO_GetScreenFrame(VoDev, &stFrame); if (HI_SUCCESS != s32Ret) { printf("get vo(%d) frame err\n", VoDev); printf("only get %d frame\n", i); break; } printf("addr 0x%x\n", stFrame.stVFrame.u32PhyAddr[0]); /* save VO frame to file */ sample_yuv_dump(&stFrame.stVFrame, pfd); /* release frame after using */ s32Ret = HI_MPI_VO_ReleaseScreenFrame(VoDev, &stFrame); if (HI_SUCCESS != s32Ret) { printf("Release vo(%d) frame err\n", VoDev); printf("only get %d frame\n", i); break; } } memclose(); fclose(pfd); return 0; }
void MCManage(int mode, int slot) { char mcFilename[80]; int CardError; card_dir CardDir; card_file CardFile; int SectorSize; int found = 0; int FileSize; int actualSize; int savedBytes=0; char debug[128]; CARDSLOT = slot; /*** Build the file name ***/ sprintf(mcFilename, "FCEU-%08x.fcs", iNESGameCRC32); /*** Mount the Card ***/ CARD_Init("FCEU", "00"); /*** Try for memory card in slot A ***/ CardError = CARD_Mount(CARDSLOT, SysArea, CardRemoved ); if ( CardError >= 0 ) { /*** Get card sector size ***/ CardError = CARD_GetSectorSize(CARDSLOT, &SectorSize); switch ( mode ) { case 0 : { /*** Save Game ***/ /*** Look for this file ***/ CardError = CARD_FindFirst(CARDSLOT, &CardDir, true); found = 0; card_stat CardStatus; while ( CardError != CARD_ERROR_NOFILE ) { CardError = CARD_FindNext(&CardDir); if ( strcmp(CardDir.filename, mcFilename) == 0 ) found = 1; } /*** Determine number of sectors required ***/ savedBytes = actualSize = GCFCEUSS_Save(); sprintf(debug, "Saving in MC ..."); ShowAction(debug); FileSize = ( actualSize / SectorSize ) * SectorSize; if ( actualSize % SectorSize ) FileSize += SectorSize; /*** Now write the file out ***/ if ( !found ) CardError = CARD_Create(CARDSLOT, mcFilename, FileSize, &CardFile); else CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile); CARD_GetStatus( CARDSLOT, CardFile.filenum, &CardStatus); CardStatus.icon_addr = 0; CardStatus.icon_fmt = 2; CardStatus.icon_speed = 1; CardStatus.comment_addr = sizeof(saveicon); CARD_SetStatus( CARDSLOT, CardFile.filenum, &CardStatus); /*** Haha! libogc only write one block at a time! ***/ if ( CardError == 0 ) { int sbo = 0; while ( actualSize > 0 ) { CardError = CARD_Write(&CardFile, &statebuffer[sbo], SectorSize, sbo ); actualSize -= SectorSize; sbo += SectorSize; } CardError = CARD_Close(&CardFile); sprintf(debug, "Saved %d bytes successfully!", savedBytes); WaitPrompt(debug); } else WaitPrompt("Save Failed!"); CARD_Unmount(CARDSLOT); } break; /*** End save ***/ case 1: { /*** Load state ***/ /*** Look for this file ***/ CardError = CARD_FindFirst(CARDSLOT, &CardDir, true); memopen(); /*** Clear the buffer ***/ found = 0; while ( CardError != CARD_ERROR_NOFILE ) { CardError = CARD_FindNext(&CardDir); if ( strcmp(CardDir.filename, mcFilename) == 0 ) found = 1; } if ( found == 0 ) { WaitPrompt("No Save Game Found"); CARD_Unmount(CARDSLOT); return; } /*** Load the file into memory ***/ CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile); CardError = CARD_Read(&CardFile, &statebuffer, SectorSize, 0); /*** Get actual size of the file ***/ memcpy(&actualSize, &statebuffer[FILESIZEOFFSET], 4); savedBytes = actualSize; int sbo = SectorSize; actualSize -= SectorSize; while( actualSize > 0 ) { CARD_Read(&CardFile, &statebuffer[sbo], SectorSize, sbo); actualSize -= SectorSize; sbo += SectorSize; } CARD_Close(&CardFile); /*** Finally, do load ***/ GCFCEUSS_Load(); CARD_Unmount(CARDSLOT); sprintf(debug, "Loaded %d bytes successfully!", savedBytes); WaitPrompt(debug); } break; /*** End load ***/ default: break; } } else { WaitPrompt("Cannot Mount Memory Card!"); } }