FHANDLE FileOpen( const char *filename, int mode ) { FHANDLE handle; int c; char *ptr; memset( &handle, -1, sizeof(handle) ); if(!filename) return handle; if( (ptr = strchr( filename, ':' )) == NULL ) { #ifdef _DEBUG printf("FileOpen : Invalid Path (ptr = NULL)\n"); #endif return handle; } c = ptr - filename; // file is on cd/dvd if( !strncmp( filename, "cdfs:", c ) ) { CD_Init(); CDVD_FlushCache(); handle.fh = fioOpen( filename, mode ); handle.dt = DT_CD; } else if( !strncmp( filename, "pfs", 3 ) ) { handle.fh = fileXioOpen( filename, mode, 0 ); handle.dt = DT_HDD; } else if( !strncmp( filename, "mc0:", c ) || !strncmp( filename, "mc1:", c ) ) { handle.fh = fioOpen( filename, mode ); handle.dt = DT_MC; } else if( !strncmp( filename, "mass:", c ) ) { handle.fh = fioOpen( filename, mode ); handle.dt = DT_USB; } else if( !strncmp( filename, "host:", c ) ) { handle.fh = fioOpen( filename, mode ); handle.dt = DT_HOST; } else if( !strncmp( filename, "smb:", c ) ) { handle.fh = smbc_open( filename, mode, 0666 ); handle.dt = DT_SMB_SHARE; } return handle; }
int CD_ReadCNF() { int fd,n,m; fd=fioOpen("cdrom0:\\SYSTEM.CNF;1",1); if(fd>=0) { m=fioLseek(fd,0,2); fioLseek(fd,0,0); if(m>=4095) m=4094; fioRead(fd,systemcnf,m); systemcnf[m+1]=0; m=0; while(systemcnf[m]!=0) { if(systemcnf[m]=='B' && systemcnf[m+1]=='O' && systemcnf[m+2]=='O' && systemcnf[m+3]=='T' && systemcnf[m+4]=='2') {m+=5;break;} m++; } while(systemcnf[m]!=0 && systemcnf[m]==32) m++; if(systemcnf[m]!=0 )m++; // salta '=' while(systemcnf[m]!=0 && systemcnf[m]==32) m++; if(systemcnf[m]==0) return 0; for(n=0;n<255;n++) { CD_DIRELF[n]=systemcnf[m]; if(systemcnf[m]==0) break; if(n>2) if(CD_DIRELF[n-1]==';' && CD_DIRELF[n]=='1') {CD_DIRELF[n+1]=0;break;} m++; } CD_DIRELF[255]=0; fioClose(fd); return 1; } return 0; }
/**************************************************************************** * Universal file opening function. Returns the handle to the file. * ****************************************************************************/ int OpenFile(char *filename, int mode, int media) { int fd = 0; switch (media) { case 0: //hdd { fd = fileXioOpen(filename, mode, 0); break; } case 1: //cdfs { CDVD_FlushCache(); fd = fioOpen(filename, mode); break; } case 2: { //fd = fioOpen(filename, mode); fd = fileXioOpen(filename, mode, 0); break; } case 3: { fd = fileXioOpen(filename, mode, 0); break; } case 4: { fd = fioOpen(filename, mode); break; } case 5: { fd = fileXioOpen(filename, mode, 0); break; } } return fd; }
int Sys_FileOpenWrite (char *path) { int f; int i; i = findhandle (); f = fioOpen(path,O_WRONLY | O_CREAT); //FIXME //if(!f) //{ // Sys_Error ("Error opening %s: %s", path,strerror(errno)); //} sys_handles[i] = f; return i; }
/* * Open a TIFF file for read/writing. */ TIFF* TIFFOpen(const char* name, const char* mode) { static const char module[] = "TIFFOpen"; int fd; TIFF* tif; fd = fioOpen(name, O_RDONLY); if (fd < 0) { TIFFError(module, "%s: Cannot open", name); return ((TIFF *)0); } tif = TIFFFdOpen((int)fd, name, mode); if(!tif) fioClose(fd); return tif; }
unsigned short int detect_bios_version(void) { int fd; char romver_buffer[5]; fd=fioOpen("rom0:ROMVER", O_RDONLY); // Read the PS2's BIOS version from rom0:ROMVER. fioRead(fd, romver_buffer, 4); fioClose(fd); // Null terminate the string. romver_buffer[4]='\0'; // Return the PS2's BIOS version. return(strtoul(romver_buffer, NULL, 16)); }
int Sys_FileOpenRead (char *path, int *hndl) { int f; int i; i = findhandle (); f = fioOpen(path,O_RDONLY); if (!f) { *hndl = -1; return -1; } sys_handles[i] = f; *hndl = i; if(filelength(f) < 0) return -1; return filelength(f); }
int PS2KbdInit(void) /* Initialise the keyboard library */ { if (kbd_iop != _iop_reboot_count) { kbd_iop = _iop_reboot_count; kbd_fd = -1; } if(kbd_fd >= 0) /* Already initialised */ { return 2; } kbd_fd = fioOpen(PS2KBD_DEVFILE, O_RDONLY); if(kbd_fd < 0) { return 0; } return 1; }
static void _load_font ( unsigned int anIndex ) { int lFD = fioOpen ( s_pFontNames[ anIndex ], O_RDONLY ); if ( lFD >= 0 ) { long lSize = fioLseek ( lFD, 0, SEEK_END ); if ( lSize > 0 ) { unsigned char* lpBuff = ( unsigned char* )malloc ( lSize ); fioLseek ( lFD, 0, SEEK_SET ); fioRead ( lFD, lpBuff, lSize ); GSFont_Set ( anIndex, lpBuff ); } /* end if */ fioClose ( lFD ); } /* end if */ } /* end LoadFont */
///////////////////////////////////////////////////////////////////// // reboot IOP ///////////////////////////////////////////////////////////////////// void CD_Reset(int mode) { if(mode==1) SifIopReset("rom0:UDNL rom0:EELOADCNF",0); // normal else {fioOpen("cdrom0:\\SYSTEM.CNF;1",1); // hacking in the night... `_Ž. Prepare SifIopReset("rom0:UDNL cdrom0:\\SYSTEM.CNF;1", 0); // three point!! } while (SifIopSync()) ; fioExit(); SifExitIopHeap(); SifLoadFileExit(); SifExitRpc(); SifExitCmd(); EI(); SifInitRpc(0); FlushCache(0); FlushCache(2); }
char *parseSystemCnf() { char *buffer; int fd, fdSize; int i; // Open SYSTEM.CNF on the cdrom, allocate memory for it, terminate the array fd = fioOpen("cdrom0:\\SYSTEM.CNF;1", O_RDONLY); if(fd < 0) return (char *)ERROR_SYSTEMCNF_FILEIO; fdSize = fioLseek(fd, 0, SEEK_END); fioLseek(fd, 0, SEEK_SET); buffer = malloc(fdSize + 1); if(!buffer) return (char *)ERROR_SYSTEMCNF_MEMORY; if(fioRead(fd, buffer, fdSize) != fdSize) return (char *)ERROR_SYSTEMCNF_FILEIO; fioClose(fd); buffer[fdSize] = '\0'; // Find boot file substring buffer = strstr(buffer, "BOOT2"); buffer += 5; while((*buffer == ' ') || (*buffer == '\t')) buffer++; buffer++; // bypass '=' character while((*buffer == ' ') || (*buffer == '\t')) buffer++; i = 0; while((buffer[i] != '\n') && (buffer[i] != '\r')) i++; // Terminate string at end of boot elf filename buffer[i] = '\0'; // Return pointer to boot elf filename string return buffer; }
int main() { int fd, ret; int i; // Initialise SifInitRpc(0); LoadModules(); #ifdef TYPE_MC if(mcInit(MC_TYPE_MC) < 0) { printf("Failed to initialise memcard server!\n"); SleepThread(); } #else if(mcInit(MC_TYPE_XMC) < 0) { printf("Failed to initialise memcard server!\n"); SleepThread(); } #endif printf("\nMemory card library example code - by Sjeep\n\n"); // int mcGetInfo(int port, int slot, int* type, int* free, int* format); // // mcGetInfo retrieves memcard state info, such as the memcard type, free blocks and // the format status. // // mcGetInfo is passed pointers to three variables, which are filled upon completion // of the getinfo rpc command. The mcGetInfo return values are as follows: // // 0 : The same memory card has been connected since the last mcGetInfo call. // -1 : Switched to a formatted memory card. // -2 : Switched to an unformatted memory card. // -10 or less : The memory card could not be detected. // // NOTE: With the MCMAN/MCSERV, *format is always returned as 0 regardless of if // if the memcard is formatted or not. // Since this is the first call, -1 should be returned. mcGetInfo(0, 0, &mc_Type, &mc_Free, &mc_Format); mcSync(0, NULL, &ret); printf("mcGetInfo returned %d\n",ret); printf("Type: %d Free: %d Format: %d\n\n", mc_Type, mc_Free, mc_Format); // Assuming that the same memory card is connected, this should return 0 mcGetInfo(0,0,&mc_Type,&mc_Free,&mc_Format); mcSync(0, NULL, &ret); printf("mcGetInfo returned %d\n",ret); printf("Type: %d Free: %d Format: %d\n\n", mc_Type, mc_Free, mc_Format); // int mcGetDir(int port, int slot, char *name, unsigned mode, int maxent, mcTable* table); // // mcGetDir retrieves the directory structure of a specific path on the memory card. // // The filename is relative to the root of the memory card. Wildcards such as '*' and '?' // may be used. "maxent" is the maximum number of mcTable elements your array specified // by "table" can hold. The mc_getdir return values are as follows: // // 0 or more : The number of file entries that were obtained. // -2 : The memory card is unformatted // -4 : A non-existant path was specified in the "name" parameter // -10 or less : The memory card could not be detected. mcGetDir(0, 0, "/*", 0, ARRAY_ENTRIES - 10, mcDir); mcSync(0, NULL, &ret); printf("mcGetDir returned %d\n\nListing of root directory on memory card:\n\n", ret); for(i=0; i < ret; i++) { if(mcDir[i].attrFile & MC_ATTR_SUBDIR) printf("[DIR] %s\n", mcDir[i].name); else printf("%s - %d bytes\n", mcDir[i].name, mcDir[i].fileSizeByte); } // Check if existing save is present fd = fioOpen("mc0:PS2DEV/icon.sys", O_RDONLY); if(fd <= 0) { printf("\nNo previous save exists, creating...\n"); if((ret = CreateSave()) < 0) { printf("Failed to create save! Errorno: %d\n",ret); SleepThread(); } } else { printf("\nPrevious save exists, listing directory\n\n"); ret = mcGetDir(0, 0, "/PS2DEV/*", 0, ARRAY_ENTRIES, mcDir); printf("mcGetDir returned %d\n\n", ret); for(i=0; i < ret; i++) { if(mcDir[i].attrFile & MC_ATTR_SUBDIR) printf("[DIR] %s\n", mcDir[i].name); else printf("%s - %d bytes\n", mcDir[i].name, mcDir[i].fileSizeByte); } } // Return to the browser, so you can see the PS2Dev icon :) SifExitRpc(); return 0; }
int CreateSave(void) { int mc_fd; int icon_fd,icon_size; char* icon_buffer; mcIcon icon_sys; static iconIVECTOR bgcolor[4] = { { 68, 23, 116, 0 }, // top left { 255, 255, 255, 0 }, // top right { 255, 255, 255, 0 }, // bottom left { 68, 23, 116, 0 }, // bottom right }; static iconFVECTOR lightdir[3] = { { 0.5, 0.5, 0.5, 0.0 }, { 0.0,-0.4,-0.1, 0.0 }, {-0.5,-0.5, 0.5, 0.0 }, }; static iconFVECTOR lightcol[3] = { { 0.3, 0.3, 0.3, 0.00 }, { 0.4, 0.4, 0.4, 0.00 }, { 0.5, 0.5, 0.5, 0.00 }, }; static iconFVECTOR ambient = { 0.50, 0.50, 0.50, 0.00 }; if(fioMkdir("mc0:PS2DEV") < 0) return -1; // Set up icon.sys. This is the file which controls how our memory card save looks // in the PS2 browser screen. It contains info on the bg colour, lighting, save name // and icon filenames. Please note that the save name is sjis encoded. memset(&icon_sys, 0, sizeof(mcIcon)); strcpy(icon_sys.head, "PS2D"); strcpy_sjis((short *)&icon_sys.title, "Memcard Example\nPS2Dev r0x0rs"); icon_sys.nlOffset = 16; icon_sys.trans = 0x60; memcpy(icon_sys.bgCol, bgcolor, sizeof(bgcolor)); memcpy(icon_sys.lightDir, lightdir, sizeof(lightdir)); memcpy(icon_sys.lightCol, lightcol, sizeof(lightcol)); memcpy(icon_sys.lightAmbient, ambient, sizeof(ambient)); strcpy(icon_sys.view, "ps2dev.icn"); // these filenames are relative to the directory strcpy(icon_sys.copy, "ps2dev.icn"); // in which icon.sys resides. strcpy(icon_sys.del, "ps2dev.icn"); // Write icon.sys to the memory card (Note that this filename is fixed) mc_fd = fioOpen("mc0:PS2DEV/icon.sys",O_WRONLY | O_CREAT); if(mc_fd < 0) return -2; fioWrite(mc_fd, &icon_sys, sizeof(icon_sys)); fioClose(mc_fd); printf("icon.sys written sucessfully.\n"); // Write icon file to the memory card. // Note: The icon file was created with my bmp2icon tool, available for download at // http://www.ps2dev.org icon_fd = fioOpen("host:ps2dev.icn",O_RDONLY); if(icon_fd < 0) return -3; icon_size = fioLseek(icon_fd,0,SEEK_END); fioLseek(icon_fd,0,SEEK_SET); icon_buffer = malloc(icon_size); if(icon_buffer == NULL) return -4; if(fioRead(icon_fd, icon_buffer, icon_size) != icon_size) return -5; fioClose(icon_fd); icon_fd = fioOpen("mc0:PS2DEV/ps2dev.icn",O_WRONLY | O_CREAT); if(icon_fd < 0) return -6; fioWrite(icon_fd,icon_buffer,icon_size); fioClose(icon_fd); printf("ps2dev.icn written sucessfully.\n"); return 0; }
int main() { int xpos=20; int ypos=20; int xdir=1; int ydir=1; gsFontTex* fontTex; // Create a gsDriver with default settings // (320x240 32bit, double-buffer, zbuffer allocated, alpha enabled) gsDriver myGsDriver(NTSC); // Change to hi-res so can fit more of our 16x16 font on screen myGsDriver.setDisplayMode(640, 480, NTSC, FIELD, GS_PSMCT32, GS_ENABLE, GS_PSMZ32, 2); gsFont myFont; // Won't bother creating our own gsPipe, since we can use the one created by our gsDriver // gsPipe myGsPipe; // Assign a gsPipe to the font handler myFont.assignPipe(&myGsDriver.drawPipe); // Enable alpha blending myGsDriver.drawPipe.setAlphaEnable(GS_ENABLE); // Open the file int filehandle = fioOpen("host:arial.fnt",O_RDONLY); // Get the size of the file int filesize = fioLseek( filehandle, 0, SEEK_END); // allocate space to load the file into EE mem fontTex = (gsFontTex*)memalign(64,filesize); //seek back to the start of the file fioLseek(filehandle, 0, SEEK_SET); if (fioRead(filehandle,fontTex,filesize) <= 0) { printf("Could not load texfont.fnt\n"); while(1); } fioClose(filehandle); // Upload into the beginning of texture mem (with texture-buffer width set to 256) myFont.uploadFont(fontTex, myGsDriver.getTextureBufferBase(), fontTex->TexWidth, // Use the fontTex width as texbuffer width (can use diff width) 0, 0 ); while (1) { // Clear the screen (with ZBuffer Disabled) myGsDriver.drawPipe.setZTestEnable(GS_DISABLE); myGsDriver.drawPipe.RectFlat(0,0,640,480,0,GS_SET_RGBA(0x00,0x00,0x00,0x80)); myGsDriver.drawPipe.setZTestEnable(GS_ENABLE); // WHY IS THIS FUBAR IF DRAWN OUT OF SEQUENCE ? (Z-Test should make it okay) // Draw a static, solid red rectangle in the background (z=1) myGsDriver.drawPipe.RectFlat( 120, 60, 120+120, 60+80, 1, GS_SET_RGBA(0xFF,0x00,0x00,0x7F)); // Print some text behind the moving transparent rectangle, but in-front of the static solid one myFont.Print(20, 400, 40, 2, GS_SET_RGBA(0xFF,0xFF,0xFF,0x80), GSFONT_ALIGN_LEFT, "This is some left-aligned text on the first line,\n" "and this is some more text.\n" "Don't get too excited, this is just even more text to prove that line-wrap works properly."); myFont.Print(140, 500, 200, 2, GS_SET_RGBA(0x20,0x20,0xFF,0x80), GSFONT_ALIGN_CENTRE, "This is some blue centred text.\n" "You can do some nice \aunderlining\a if you want to!\n" "It's easy, just use \\a to turn it on or off"); myFont.Print(20, 620, 360, 2, GS_SET_RGBA(0xFF,0x20,0x20,0x80), GSFONT_ALIGN_RIGHT, "This is some red right-aligned text.\n" "You can do some nice \bbold\b text too if you want!\n" "Just use \\b to turn bold text on or off"); // Draw a moving, semi-transparent, rectangle (at z=3) myGsDriver.drawPipe.RectFlat( xpos, ypos, xpos+160, ypos+120, 3, GS_SET_RGBA(0x00,0xFF,0x00,0x40)); // Flush the pipe, to draw the prims myGsDriver.drawPipe.Flush(); // Wait for VSync and then swap buffers myGsDriver.WaitForVSync(); myGsDriver.swapBuffers(); // move the green rectangle xpos+=xdir; ypos+=ydir; // change dir if it hits the limits if (xpos>((640-160)-1)) xdir=-1; if (xpos<1) xdir=1; if (ypos>((480-120)-1)) ydir=-1; if (ypos<1) ydir=1; } }
int fontx_load_double_krom(fontx_t *fontx) { fontx_hdr *fontx_header; int size; int fd = 0; // Font characteristics for double-byte font int header_size = 18; int table_num = 51; int table_size = 4; int char_size = 30; int char_num = 3489; fd = fioOpen("rom0:KROM", O_RDONLY); if (fd < 0) { printf("Error opening KROM font.\n"); } size = header_size + table_num*table_size + char_num*char_size; fontx->font = (char*)malloc(size); if (fontx->font == NULL) { printf("Error allocating memory.\n"); fioClose(fd); return -1; } // Clear memory memset(fontx->font,0,size); // Make sure we're at the beginning fioLseek(fd, 0, SEEK_SET); // Read in 95 characters if (fioRead(fd, fontx->font+header_size+table_num*table_size, char_size*char_num) < 0) { printf("Error reading font.\n"); free(fontx->font); fioClose(fd); return -1; } fioClose(fd); fontx_header = (fontx_hdr*)fontx->font; // define the header as double-byte font strncpy(fontx_header->id, "FONTX2", 6); fontx_header->id[6] = '\0'; strncpy(fontx_header->name, "KROM", 8); fontx_header->name[8] = '\0'; fontx_header->width = 16; fontx_header->height = 15; fontx_header->type = DOUBLE_BYTE; fontx_header->table_num = table_num; // Add the SJIS tables to the font memcpy(fontx->font+header_size,sjis_table,table_num*table_size); // Save it as a font //fd=fioOpen("host:KROM_kanji.fnt",O_WRONLY | O_TRUNC | O_CREAT); //fioWrite(fd, fontx->font, size); //fioClose(fd); return 0; }
int RunElf(char *name) { int fd,size,i; u8 *boot_elf = (u8 *) 0;//&_end; elf_header_t *eh = &elfh; elf_pheader_t *eph; char *argv[1]; void *pdata; fd=-1; if(name[0]=='m' && name[1]=='c') // if mc, test mc0 and mc1 { if((fd = fioOpen(name,1)) < 0) { name[2]='1'; } } if(fd < 0) if((fd = fioOpen(name,1)) < 0) { return -1; } size = fioLseek(fd, 0, SEEK_END); if(!size) { fioClose(fd); return -2; } fioLseek(fd, 0, 0); fioRead(fd, eh, sizeof(elf_header_t)); // read the elf header // crazy code for crazy man :P boot_elf=(u8 *)0x1800000-size-256; //if((eh->entry+size)>=boot_elf) boot_elf=(u8 *)eh->entry-size-256; boot_elf=(u8 *) (((unsigned)boot_elf) &0xfffffff0); // read rest file elf fioRead(fd, boot_elf+sizeof(elf_header_t), size-sizeof(elf_header_t)); fioClose(fd); // mrbrown machine gun ;) eph = (elf_pheader_t *)(boot_elf + eh->phoff); // Scan through the ELF's program headers and copy them into RAM, then // zero out any non-loaded regions. for (i = 0; i < eh->phnum; i++) { if (eph[i].type != ELF_PT_LOAD) continue; pdata = (void *)(boot_elf + eph[i].offset); memcpy2((unsigned char *)eph[i].vaddr, (unsigned char *)pdata, (int)eph[i].filesz); if (eph[i].memsz > eph[i].filesz) memset2((unsigned char *)eph[i].vaddr + eph[i].filesz, (unsigned char)0, (int)eph[i].memsz - eph[i].filesz); } // Let's go. argv[0] = name; fioExit(); Reset(); FlushCache(0); FlushCache(2); ExecPS2((void *)eh->entry, 0, 1, argv); return 0; }
int main ( void ) { /* read file (or part of it ) into memory */ PACKET *lPck = malloc(sizeof(PACKET)); QWORD *q; FRAMEBUFFER frame; ZBUFFER z; InitCBParam lInfo; int lFD = fioOpen ( MPEG_BITSTREAM_FILE, O_RDONLY ); long lSize; long lPTS, lCurPTS; frame.width = 640; frame.height = 512; frame.mask = 0; frame.psm = GS_PSM_32; frame.address = graph_vram_allocate(frame.width,frame.height, frame.psm, GRAPH_ALIGN_PAGE); z.enable = 0; z.mask = 0; z.method = 0; z.zsm = 0; z.address = 0; packet_allocate(lPck, 100, 0, 0); if ( lFD < 0 ) { printf ( "test_mpeg: could not open '%s'\n", MPEG_BITSTREAM_FILE ); goto end; } /* end if */ lSize = fioLseek ( lFD, 0, SEEK_END ); fioLseek ( lFD, 0, SEEK_SET ); if ( lSize <= 0 ) { printf ( "test_mpeg: could not obtain file size (%ld)\n", lSize ); goto end; } /* end if */ s_pMPEGData = ( unsigned char* )malloc ( lSize = lSize > MAX_SIZE ? MAX_SIZE : lSize ); if ( !s_pMPEGData ) { printf ( "test_mpeg: could not allocate enough memory (%ld)\n", lSize ); goto end; } /* end if */ if ( fioRead ( lFD, s_pTransferPtr = s_pMPEGData, s_MPEGDataSize = lSize ) != lSize ) { printf ( "test_mpeg: could not read file\n" ); goto end; } /* end if */ fioClose ( lFD ); /* initialize DMAC (I have no idea what this code does as */ /* I'm not quite familiar with ps2sdk) */ dma_channel_initialize ( DMA_CHANNEL_toIPU, NULL, 0 ); dma_channel_initialize ( DMA_CHANNEL_GIF, NULL, 0 ); dma_channel_fast_waits( DMA_CHANNEL_GIF ); /* initialize graphics synthesizer */ graph_initialize(0,640,512,GS_PSM_32,0,0); /* setup texture buffer address just after the framebuffer */ lInfo.m_TexAddr = graph_vram_allocate(0,0,GS_PSM_32,GRAPH_ALIGN_BLOCK); q = lPck->data; q = draw_setup_environment(q,0,&frame,&z); /* clear screen */ q = draw_clear(q,0,0,0,640.0f,512.0f,0,0,0); dma_channel_send_normal(DMA_CHANNEL_GIF, lPck->data, q - lPck->data, 0, 0); /* now it's time to initialize MPEG decoder (though it can be */ /* initialized any time). Just make sure that DMA transfers */ /* to and from IPU (and DRAM -> SPR) are not active, otherwise */ /* unpredicted things will happen. Initialization code is also */ /* allocating some memory using 'memalign' function and no */ /* check is performed whether the allocation was successful or */ /* not, so, before calling this make sure that at least WxHx4x3 */ /* bytes are avaliable for dynamic allocation (possibly using */ /* ps2_sbrk ( 0 ) call) where W and H are picture dimensions in */ /* units of pixels. */ MPEG_Initialize ( SetDMA, NULL, InitCB, &lInfo, &lCurPTS ); /* during decoding scratchpad RAM from address 0x0000 to 0x3C00 */ /* is used by the decoder. */ /* let's go */ while ( 1 ) { /* try decode picture into "lInfo.m_pData" area. It's allowed */ /* to supply different area each time, just make sure that */ /* there're no conflicts with data cache, as decoder doesn't do */ /* anything to synchronize/flush/invalidate data cache. */ /* RGB -> YUV colorspace conversion is pefromed automatically */ /* using interrupt hahdler/semaphore, so, multithreaded */ /* application can benefit from it. Usage of IPU and DMA channels */ /* to/from IPU and DRAM -> SPR is strictly forbidden during */ /* decoding :). */ if ( !MPEG_Picture ( lInfo.m_pData, &lPTS ) ) { /* MPEG_Picture returns nonzero if the picture was successfully */ /* decoded. Zero return means one of the following: */ /* - end of stream was detected (SetDMA function returned zero) */ /* - MPEG sequence end code (0x000001B7) was detected */ /* this test just finishes in both cases */ if ( lInfo.m_pInfo -> m_fEOF ) break; /* ...instead of 'break' we can continue to the next sequence...*/ /* ...but I'm too lazy to handle second call of 'InitCB' :D */ else break; } /* end if */ /* now transfer decoded picture data into texture area of GS RAM */ dma_wait_fast(); dma_channel_send_chain( DMA_CHANNEL_GIF, lInfo.m_XFerPck.data, lInfo.m_XFerPck.qwc, 0, 0); /* wait for vsync 2 times (we have interlaced frame mode) */ graph_wait_vsync (); graph_wait_vsync (); /* no need to wait for DMA transfer completion since vsyncs above */ /* have enough lattency... */ /* ...and finally draw decoded picture... */ dma_channel_send_normal( DMA_CHANNEL_GIF, lInfo.m_DrawPck.data, lInfo.m_DrawPck.qwc, 0, 0); /* ...and go back for the next one */ } /* end while */ /* free memory and other resources */ MPEG_Destroy (); end: printf ( "test_mpeg: test finished\n" ); return SleepThread (), 0; } /* end main */
int main( int argc, char **argv ) { int bError = 0; int bVelocity = 0; int bPosition = 0; uint64_t N1, N2, nSph1, nSph2, nDark1, nDark2, nStar1, nStar2, i; double dTime1, dTime2; uint64_t iOrder1; double r1[3], v1[3]; float fMass1, fSoft1, fPot1, fRho1, u1, fMetals1, fTimer1; uint64_t iOrder2; double r2[3], v2[3]; float fMass2, fSoft2, fPot2, fRho2, u2, fMetals2, fTimer2; double v, vMin, vMax; FIO fioIn1, fioIn2; FIO_SPECIES eSpecies; const char *inName1, *inName2; for (;;) { int c, option_index=0; static struct option long_options[] = { { "position", 0, 0, OPT_POSITION }, { "velocity", 0, 0, OPT_VELOCITY }, { NULL, 0, 0, 0 }, }; c = getopt_long( argc, argv, "vp", long_options, &option_index ); if ( c == -1 ) break; switch (c) { case OPT_POSITION: bPosition = 1; break; case OPT_VELOCITY: bVelocity = 1; break; default: bError = 1; break; } } if ( optind < argc ) { inName1 = argv[optind++]; } else { fprintf(stderr, "Missing input file(s)\n" ); bError = 1; } if ( optind < argc ) inName2 = argv[optind++]; else { fprintf(stderr, "Missing input file\n" ); bError = 1; } if (bPosition && bVelocity) { fprintf(stderr,"Specify --position or --velocity, but not both\n"); bError = 1; } else if ( !bPosition && !bVelocity) bPosition = 1; if ( bError ) { fprintf(stderr, "Usage: %s [-vp] <file1> <file2>\n", argv[0] ); exit(1); } fioIn1 = fioOpen(inName1,0.0,0.0); if (fioIn1==NULL) { perror(inName1); exit(errno); } fioIn2 = fioOpen(inName2,0.0,0.0); if (fioIn2==NULL) { perror(inName2); exit(errno); } N1 = fioGetN(fioIn1,FIO_SPECIES_ALL); nSph1 = fioGetN(fioIn1,FIO_SPECIES_SPH); nDark1 = fioGetN(fioIn1,FIO_SPECIES_DARK); nStar1 = fioGetN(fioIn1,FIO_SPECIES_STAR); if (!fioGetAttr(fioIn1,"dTime",FIO_TYPE_DOUBLE,&dTime1)) dTime1 = 0.0; N2 = fioGetN(fioIn2,FIO_SPECIES_ALL); nSph2 = fioGetN(fioIn2,FIO_SPECIES_SPH); nDark2 = fioGetN(fioIn2,FIO_SPECIES_DARK); nStar2 = fioGetN(fioIn2,FIO_SPECIES_STAR); if (!fioGetAttr(fioIn2,"dTime",FIO_TYPE_DOUBLE,&dTime2)) dTime2 = 0.0; fprintf(stderr,"Comparing: %s N=%lu, nSph=%lu, nDark=%lu, nStar=%lu, dTime=%g\n", inName1, N1, nSph1, nDark1, nStar1, dTime1); fprintf(stderr," with: %s N=%lu, nSph=%lu, nDark=%lu, nStar=%lu, dTime=%g\n", inName2, N2, nSph2, nDark2, nStar2, dTime2); if ( N1!=N2 || nSph1!=nSph2 || nDark1!=nDark2 || nStar1!=nStar2) { fprintf(stderr,"File headers do not match!\n"); exit(1); } printf("%lu\n",N1); vMin = HUGE_VAL; vMax = -HUGE_VAL; for( i=0; i<N1; i++ ) { eSpecies = fioSpecies(fioIn1); switch(eSpecies) { case FIO_SPECIES_SPH: fioReadSph(fioIn1,&iOrder1,r1,v1,&fMass1,&fSoft1,&fPot1,&fRho1,&u1,&fMetals1); fioReadSph(fioIn2,&iOrder2,r2,v2,&fMass2,&fSoft2,&fPot2,&fRho2,&u2,&fMetals2); break; case FIO_SPECIES_DARK: fioReadDark(fioIn1,&iOrder1,r1,v1,&fMass1,&fSoft1,&fPot1); fioReadDark(fioIn2,&iOrder2,r2,v2,&fMass2,&fSoft2,&fPot2); break; case FIO_SPECIES_STAR: fioReadStar(fioIn1,&iOrder1,r1,v1,&fMass1,&fSoft1,&fPot1,&fMetals1,&fTimer1); fioReadStar(fioIn2,&iOrder2,r2,v2,&fMass2,&fSoft2,&fPot2,&fMetals2,&fTimer2); break; default: fprintf(stderr,"Unsupported particle type: %d\n",eSpecies); abort(); } if (bPosition) v = mag(r1,r2,1); else v = mag(v1,v2,0); if (v>vMax) vMax = v; if (v<vMin) vMin = v; printf("%g\n",v); } fprintf(stderr,"Min: %g, Max: %g\n", vMin, vMax); fioClose(fioIn2); fioClose(fioIn1); return 0; }
fioClose ( lFD ); lFD = fioOpen ( s_pSMSIcn, O_WRONLY | O_CREAT ); if ( lFD >= 0 ) { fioWrite ( lFD, g_IconSMS, sizeof ( g_IconSMS ) ); fioClose ( lFD ); } /* end if */ } /* end if */ } else fioClose ( lFD ); lFD = fioOpen ( s_pMC0SMC, O_WRONLY | O_CREAT ); if ( lFD >= 0 ) { if ( fioWrite ( lFD, &g_Config, sizeof ( g_Config ) ) == sizeof ( g_Config ) ) retVal = 1; fioClose ( lFD ); } /* end if */ } /* end if */ } /* end if */ return retVal;
int /* "192.168.0.10 255.255.255.0 192.168.0.1" */ setup_ip (const char *ipconfig_dat_path, char outp [IPCONF_MAX_LEN], size_t *length) { int result = 0; int conf_ok = 0; #if defined (LOAD_SIOMAN_AND_MC) int fd = fioOpen (ipconfig_dat_path, O_RDONLY); if (!(fd < 0)) { /* configuration file found */ char tmp [IPCONF_MAX_LEN]; int len = fioRead (fd, tmp, IPCONF_MAX_LEN - 1); fioClose (fd); if (len > 0) { int data_ok = 1; int i; tmp [len] = '\0'; for (i=0; data_ok && i<len; ++i) if (isdigit (tmp [i]) || tmp [i] == '.') ; else if (isspace (tmp [i])) tmp [i] = '\0'; else data_ok = 0; if (data_ok) { memcpy (outp, tmp, IPCONF_MAX_LEN); conf_ok = 1; *length = len; } else /* bad format */ result = -2; } } else /* not found */ result = -1; #endif /* LOAD_SIOMAN_AND_MC? */ if (!conf_ok) { /* configuration file not found; use hard-coded defaults */ int len, pos = 0; len = strlen (default_ip); memcpy (outp + pos, default_ip, len); pos += len; *(outp + pos++) = '\0'; len = strlen (default_mask); memcpy (outp + pos, default_mask, len); pos += len; *(outp + pos++) = '\0'; len = strlen (default_gateway); memcpy (outp + pos, default_gateway, len); pos += len; *(outp + pos++) = '\0'; *length = pos; } return (result); }
int loadIrxModules(int device, const char *irxPath, IrxReference **modules) { IrxReference *resModules = (IrxReference *)malloc(numIrxFiles * sizeof(IrxReference)); IrxReference *curModule = resModules; for (int i = 0; i < numIrxFiles; i++) { curModule->fileRef = irxFiles + i; if ((device == HOST_DEV) && (irxFiles[i].flags & NOT_HOST)) continue; if ((irxFiles[i].flags & TYPEMASK) == BIOS) { curModule->loc = IRX_FILE; curModule->path = (char *)malloc(32); sprintf(curModule->path, "rom0:%s", irxFiles[i].name); curModule->buffer = NULL; curModule->size = 0; curModule->argSize = 0; curModule->args = NULL; curModule->errorCode = 0; } else { curModule->loc = IRX_BUFFER; curModule->path = (char *)malloc(256); sprintf(curModule->path, "%s%s%s", irxPath, irxFiles[i].name, (device == CD_DEV) ? ";1" : ""); int fd = fioOpen(curModule->path, O_RDONLY); if (fd < 0) { // IRX not found sioprintf("Can't open %s: %d\n", curModule->path, fd); // we keep the error code of the path where we originally expected the file curModule->errorCode = fd; // try cdrom root directory sprintf(curModule->path, "cdrom0:\\%s;1", irxFiles[i].name); fd = fioOpen(curModule->path, O_RDONLY); if (fd < 0) { // still not found, try host: sioprintf("Can't open %s: %d\n", curModule->path, fd); sprintf(curModule->path, "host:%s", irxFiles[i].name); fd = fioOpen(curModule->path, O_RDONLY); if (fd < 0) { // we simply can't find it. sioprintf("Can't open %s: %d\n", curModule->path, fd); // restore the path where we originally expected the file, for error message (later, after boot up) sprintf(curModule->path, "%s%s%s", irxPath, irxFiles[i].name, (device == CD_DEV) ? ";1" : ""); } } } if (fd >= 0) { curModule->size = fioLseek(fd, 0, SEEK_END); fioLseek(fd, 0, SEEK_SET); curModule->buffer = (uint8 *)memalign(64, (curModule->size + 63) & ~63); fioRead(fd, curModule->buffer, curModule->size); curModule->argSize = irxFiles[i].argSize; curModule->args = irxFiles[i].args; curModule->errorCode = 0; fioClose(fd); } else { if (irxFiles[i].flags & DEPENDANCY) { // other modules depend on this one. // kill the modules we already loaded, if they depend on the one that failed. IrxReference *pos = resModules; while (pos < curModule) { if ((pos->fileRef->flags & TYPEMASK) == (irxFiles[i].flags & TYPEMASK)) { free(pos->path); free(pos->buffer); IrxReference *copyPos = pos; while (copyPos < curModule) { copyPos[0] = copyPos[1]; copyPos++; } curModule--; } else pos++; } // and skip any remaining modules that depend on the missing one, too. while ((i < numIrxFiles - 1) && ((irxFiles[i + 1].flags & TYPEMASK) == (curModule->fileRef->flags & TYPEMASK))) i++; // the module that actually failed (curModule) is kept in the array for displaying an error message } curModule->size = 0; curModule->buffer = NULL; curModule->argSize = 0; curModule->args = NULL; } } curModule++; } *modules = resModules; sioprintf("List of %d modules:\n", curModule - resModules); for (int i = 0; i < curModule - resModules; i++) sioprintf("%s\n", resModules[i].path); return curModule - resModules; }
int fontx_load_single_krom(fontx_t *fontx) { fontx_hdr *fontx_header; int header_size = 17; int char_size = 15; int fd = 0; int size; fd = fioOpen("rom0:KROM", O_RDONLY); if (fd < 0) { printf("Error opening KROM font.\n"); return -1; } // header without table pointer + size of a character * 256 characters size = header_size + char_size * 256; fontx->font = (char*)malloc(size); if (fontx->font == NULL) { printf("Error allocating %d bytes of memory.\n", size); fioClose(fd); return -1; } // Clear the memory memset(fontx->font,0,size); // The offset for the ASCII characters fioLseek(fd, 0x198DE, SEEK_SET); // 17 bytes of header and 15 bytes per 33 characters // Read in 95 characters if (fioRead(fd,fontx->font + header_size+char_size*33, char_size*95) < 0) { printf("Error reading rom0:KROM.\n"); free(fontx->font); fioClose(fd); return -1; } fioClose(fd); fontx_header = (fontx_hdr*)fontx->font; // define header as single-byte font strncpy(fontx_header->id, "FONTX2", 6); fontx_header->id[6] = '\0'; strncpy(fontx_header->name, "KROM", 8); fontx_header->name[8] = '\0'; fontx_header->width = 8; fontx_header->height = 15; fontx_header->type = SINGLE_BYTE; // Save it as a font //fd=fioOpen("host:KROM_ascii.fnt",O_WRONLY | O_TRUNC | O_CREAT); //fioWrite(fd, fontx->font, size); //fioClose(fd); return 0; }
int load_rom(char *filename) { unsigned long file_length; int fd,fd_size; int n; int ret = 0; int ok=0; char tmpnom[0x100]; if(check_zip(filename)) { unzFile fd2=unzOpen(filename); if(fd2==NULL)return (1); // Go to first file in archive ret = unzGoToFirstFile(fd2); if(ret != UNZ_OK) { unzClose(fd2); return (1); } // Get information on the file ret = unzGetCurrentFileInfo(fd2, &info, tmpnom, 0x100, NULL, 0, NULL, 0); if(ret != UNZ_OK) { unzClose(fd2); return (1); } //Open the file for reading ret = unzOpenCurrentFile(fd2); if(ret != UNZ_OK) { unzClose(fd2); return (1); } // Allocate file data buffer fd_size = info.uncompressed_size; // Read (decompress) the file // cartridge_rom = (unsigned char *)malloc(fd_size); cartridge_rom = (u8 *)memalign(64, fd_size); ret = unzReadCurrentFile(fd2,/*(char *)*/cartridge_rom, info.uncompressed_size); if(ret != info.uncompressed_size) { //free(buf2); unzCloseCurrentFile(fd2); unzClose(fd2); return (1); } //printf("zip decomp %d \n",(int)info.uncompressed_size); // Close the current file ret = unzCloseCurrentFile(fd2); if(ret != UNZ_OK) { unzClose(fd2); return (1); } // printf("zip close file\n"); // Close the archive ret = unzClose(fd2); if(ret != UNZ_OK) { return (1); } // printf("zip close archive\n"); // Check for 512-byte header // ok=0; // cartridge_rom = (unsigned char *)malloc(fd_size); // for(n = 0; n <fd_size;n++)cartridge_rom[n]=buf[n+ok]; printf("zip header / rom copy %d %d %s \n",fd_size,ok,tmpnom); } else{ fd = fioOpen(filename, O_RDONLY); if(fd <= 0) { // display_error("Error opening file.",0); printf("%s not found.\n",filename); return 0; } file_length = fioLseek(fd,0,SEEK_END); fioLseek(fd,0,SEEK_SET); cartridge_rom = (unsigned char *)malloc(file_length); fioRead(fd, (char *)cartridge_rom, file_length); fioClose(fd); } // traitement du fich rom .... return 0; }
int SMS_SaveConfig ( void ) { int retVal = 0; int lRes; MC_GetInfo ( 0, 0, &lRes, &lRes, &lRes ); MC_Sync ( &lRes ); if ( lRes > -2 ) { SMS_MCTable lDir __attribute__( ( aligned( 64 ) ) ); MC_GetDir ( 0, 0, s_pSMS, 0, 1, &lDir ); MC_Sync ( &lRes ); if ( lRes || !fioMkdir ( s_pMC0SMS ) ) { int lFD = fioOpen ( s_pIcoSys, O_RDONLY ); if ( lFD < 0 ) { static int lBgClr[ 4 ][ 4 ] __attribute__( ( section( ".data" ) ) ) = { { 68, 23, 116, 0 }, { 255, 255, 255, 0 }, { 255, 255, 255, 0 }, { 68, 23, 116, 0 } }; static float lLightDir[ 3 ][ 4 ] __attribute__( ( section( ".data" ) ) ) = { { 0.5F, 0.5F, 0.5F, 0.0F }, { 0.0F, -0.4F, -0.1F, 0.0F }, { -0.5F, -0.5F, 0.5F, 0.0F } }; static float lLightCol[ 3 ][ 4 ] __attribute__( ( section( ".data" ) ) ) = { { 0.3F, 0.3F, 0.3F, 0.0F }, { 0.4F, 0.4F, 0.4F, 0.0F }, { 0.5F, 0.5F, 0.5F, 0.0F } }; static float lAmb[ 4 ] __attribute__( ( section( ".data" ) ) ) = { 0.5F, 0.5F, 0.5F, 0.0F }; SMS_MCIcon lIcon; memset ( &lIcon, 0, sizeof ( SMS_MCIcon ) ); strcpy ( lIcon.m_Header, s_pPS2D ); strcpy_sjis ( ( short* )&lIcon.m_Title, s_pSMS + 1 ); lIcon.m_Offset = 16; lIcon.m_Trans = 0x60; memcpy ( lIcon.m_ClrBg, lBgClr, sizeof ( lBgClr ) ); memcpy ( lIcon.m_LightDir, lLightDir, sizeof ( lLightDir ) ); memcpy ( lIcon.m_LightCol, lLightCol, sizeof ( lLightCol ) ); memcpy ( lIcon.m_LightAmb, lAmb, sizeof ( lAmb ) ); strcpy ( lIcon.m_View, s_pSMSICN ); strcpy ( lIcon.m_Copy, s_pSMSICN ); strcpy ( lIcon.m_Del, s_pSMSICN ); lFD = fioOpen ( s_pIcoSys, O_WRONLY | O_CREAT ); if ( lFD >= 0 ) { fioWrite ( lFD, &lIcon, sizeof ( lIcon ) ); fioClose ( lFD ); lFD = fioOpen ( s_pSMSIcn, O_WRONLY | O_CREAT ); if ( lFD >= 0 ) { fioWrite ( lFD, g_IconSMS, sizeof ( g_IconSMS ) ); fioClose ( lFD ); } /* end if */ } /* end if */ } else fioClose ( lFD );