Esempio n. 1
0
//读取'_'开始的行,去注释行
static char* read_line(char *p, char *buf)
{
	int i;
	buf[0]=0;
	do{
		i=0;
		while(p[i]!=0x0A && p[i]!=0x0D){
			if(p[i++]==0) {
				if(i<300){
				strcpy(buf,p);
				}
				else{
				mips_memcpy(buf,p,300);
				}
				return 0;
			}
		}
		while(p[i]==0x0A || p[i]==0x0D){
			p[i++]=0;
		}
		
				if(i<300){
				strcpy(buf,p);
				}
				else{
				mips_memcpy(buf,p,300);
				}
		p=(char *)((unsigned int)p+i);
	}while(buf[0]!='_');
	
	if(p[0]!=0) return p;
	else return 0;
}
Esempio n. 2
0
static char* read_name(char *p, char *buf, int len)
{
	int x = 0;
	do{
		if(x>len-2 || p[x]==0) break;
		if(IsHzcode(x, p)) x+=2;
		else x++;
	}while(1);
	mips_memcpy(buf,p,len);
	buf[x]=0;
	return (char*)(p+x);
}
Esempio n. 3
0
err_t tcp_enqueue (
       struct tcp_pcb* pcb, void* arg, u16_t len,
       u8_t          flags, u8_t            copy,
       u8_t*       optdata, u8_t          optlen
      ) {

 struct pbuf*    p;
 struct tcp_seg* seg, *useg, *queue;
 u32_t           left, seqno;
 u16_t           seglen;
 void*           ptr;
 u8_t            queuelen;
 flags_t         lPCBFlags = pcb -> flags;
 int             iSegCNT   = 0;

 left = len;
 ptr  = arg;

 if ( len > pcb -> snd_buf ) return ERR_MEM;

 seqno    = pcb -> snd_lbb;
 queue    = NULL;
 queuelen = pcb -> snd_queuelen;

 if ( queuelen >= TCP_SND_QUEUELEN ) goto memerr;

 seg    = useg = NULL;
 seglen = 0;

 while ( !queue || left > 0 ) {

  if ( lPCBFlags & TF_EVENSEG ) {

   ++iSegCNT;

   seglen = left > pcb -> mss ? pcb -> mss
                              : (((iSegCNT%2) == 1)? ((left + 1) / 2): left);
  } else seglen = left > pcb -> mss ? pcb -> mss : left;

  seg = memp_malloc ( MEMP_TCP_SEG );

  if ( !seg ) goto memerr;

  seg -> next = NULL;
  seg -> p    = NULL;

  if ( !queue )
   useg = queue = seg;
  else {
   useg -> next = seg;
   useg         = seg;
  }  /* end else */

    if (optdata != NULL) {
      if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) {
        goto memerr;
      }
      ++queuelen;
      seg->dataptr = seg->p->payload;
    }
    else if (copy) {
      if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_RAM)) == NULL) {
        LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue : could not allocate memory for pbuf copy size %u\n", seglen));
        goto memerr;
      }
      ++queuelen;
      if (arg != NULL) {
        mips_memcpy(seg->p->payload, ptr, seglen);
      }
      seg->dataptr = seg->p->payload;
    }
    /* do not copy data */
    else {

      /* first, allocate a pbuf for holding the data.
       * since the referenced data is available at least until it is sent out on the
       * link (as it has to be ACKed by the remote party) we can safely use PBUF_ROM
       * instead of PBUF_REF here.
       */
      if ((p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_ROM)) == NULL) {
        LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for zero-copy pbuf\n"));
        goto memerr;
      }
      ++queuelen;
      p->payload = ptr;
      seg->dataptr = ptr;

      /* Second, allocate a pbuf for the headers. */
      if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM)) == NULL) {
        /* If allocation fails, we have to deallocate the data pbuf as
         * well. */
        pbuf_free(p);
        LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for header pbuf\n"));
        goto memerr;
      }
      ++queuelen;

      /* Concatenate the headers and data pbufs together. */
      pbuf_cat(seg->p, p);
      p = NULL;
    }

    /* Now that there are more segments queued, we check again if the
    length of the queue exceeds the configured maximum. */
    if (queuelen > TCP_SND_QUEUELEN) {
      LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: queue too long %u (%u)\n", queuelen, TCP_SND_QUEUELEN));
      goto memerr;
    }

    seg->len = seglen;

    if (pbuf_header(seg->p, TCP_HLEN)) {

      LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: no room for TCP header in pbuf.\n"));

      TCP_STATS_INC(tcp.err);
      goto memerr;
    }
    seg->tcphdr = seg->p->payload;
    seg->tcphdr->src = htons(pcb->local_port);
    seg->tcphdr->dest = htons(pcb->remote_port);
    seg->tcphdr->seqno = htonl(seqno);
    seg->tcphdr->urgp = 0;
    TCPH_FLAGS_SET(seg->tcphdr, flags);
    /* don't fill in tcphdr->ackno and tcphdr->wnd until later */

    /* Copy the options into the header, if they are present. */
    if (optdata == NULL) {
      TCPH_HDRLEN_SET(seg->tcphdr, 5);
    }
    else {
      TCPH_HDRLEN_SET(seg->tcphdr, (5 + optlen / 4));
      /* Copy options into data portion of segment.
       Options can thus only be sent in non data carrying
       segments such as SYN|ACK. */
      mips_memcpy(seg->dataptr, optdata, optlen);
    }

    left -= seglen;
    seqno += seglen;
    ptr = (void *)((char *)ptr + seglen);
  }


  /* Now that the data to be enqueued has been broken up into TCP
  segments in the queue variable, we add them to the end of the
  pcb->unsent queue. */
  if (pcb->unsent == NULL) {
    useg = NULL;
  }
  else {
    for (useg = pcb->unsent; useg->next != NULL; useg = useg->next);
  }

  /* If there is room in the last pbuf on the unsent queue,
  chain the first pbuf on the queue together with that. */
  if (useg != NULL &&
    TCP_TCPLEN(useg) != 0 &&
    !(TCPH_FLAGS(useg->tcphdr) & (TCP_SYN | TCP_FIN)) &&
    !(flags & (TCP_SYN | TCP_FIN)) &&
    useg->len + queue->len <= pcb->mss) {
    /* Remove TCP header from first segment. */
    pbuf_header(queue->p, -TCP_HLEN);
    pbuf_cat(useg->p, queue->p);
    useg->len += queue->len;
    useg->next = queue->next;

    if (seg == queue) seg = NULL;

    memp_free(MEMP_TCP_SEG, queue);
  }
  else {
    if (useg == NULL) {
      pcb->unsent = queue;

    }
    else {
      useg->next = queue;
    }
  }
  if ((flags & TCP_SYN) || (flags & TCP_FIN)) {
    ++len;
  }
  pcb->snd_lbb += len;
  pcb->snd_buf -= len;
  pcb->snd_queuelen = queuelen;
  LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %d (after enqueued)\n", pcb->snd_queuelen));
  if (pcb->snd_queuelen != 0) {
    LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
      pcb->unsent != NULL);

  }

  /* Set the PSH flag in the last segment that we enqueued, but only
  if the segment has data (indicated by seglen > 0). */
  if (seg != NULL && seglen > 0 && seg->tcphdr != NULL) {
    TCPH_SET_FLAG(seg->tcphdr, TCP_PSH);
  }

  return ERR_OK;
  memerr:
  TCP_STATS_INC(tcp.memerr);

  if (queue != NULL) {
    tcp_segs_free(queue);
  }
  if (pcb->snd_queuelen != 0) {
    LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
      pcb->unsent != NULL);

  }
  LWIP_DEBUGF(TCP_QLEN_DEBUG | DBG_STATE, ("tcp_enqueue: %d (with mem err)\n", pcb->snd_queuelen));
  return ERR_MEM;
}
Esempio n. 4
0
int initBG()
{
	t_bgctx *ctx = &bgctx;
	int backup_size,bg_flag,bg_buf_width;
	void (*color2rgb)(u32 color, u8 *r, u8 *g, u8*b);
	u32 (*rgb2color)(u32 r, u32 g, u32 b);
	switch(ctx->pixelformat)
	{
	case PSP_DISPLAY_PIXEL_FORMAT_565:
		color2rgb = color2rgb565;
		rgb2color = rgb2color565;
		bg_flag = 2;
		break;
	case PSP_DISPLAY_PIXEL_FORMAT_5551:
		color2rgb = color2rgb5551;
		rgb2color = rgb2color5551;
		bg_flag = 2;
		break;
	case PSP_DISPLAY_PIXEL_FORMAT_4444:
		color2rgb = color2rgb4444;
		rgb2color = rgb2color4444;
		bg_flag = 2;
		break;
	case PSP_DISPLAY_PIXEL_FORMAT_8888:
		color2rgb = color2rgb8888;
		rgb2color = rgb2color8888;
		bg_flag = 4;
		break;
	}
	
	if(config.blendmore){
		BACKUP_X1=4;
		BACKUP_X2=468;
	}
	else{
		BACKUP_X1=96;
		BACKUP_X2=384;	
	}
	backup_size = (BACKUP_X2-BACKUP_X1)*(BACKUP_Y2-BACKUP_Y1) * bg_flag ;
	bg_buf_width = (BACKUP_X2-BACKUP_X1)*bg_flag;
	
	bg_buf = smalloc(backup_size, 0xF000);
	if(bg_buf==NULL) return 1;
	
	int i;
	for(i=BACKUP_Y1;i<BACKUP_Y2;i++){
		mips_memcpy(bg_buf+(i-BACKUP_Y1)*bg_buf_width,
		(void *)((unsigned int)ctx->vram+(i*ctx->bufferwidth+BACKUP_X1)*bg_flag),
		bg_buf_width);
	}
	
	u8 r, g, b;
	u16 * vram16 = (u16 *)bg_buf;
	u32 * vram32 = (u32 *)bg_buf;
	int x,y;
	for(y=0;y<(BACKUP_Y2-BACKUP_Y1);y++){
		int tmp = y * (BACKUP_X2-BACKUP_X1);
		for(x=tmp;x<tmp + (BACKUP_X2-BACKUP_X1);x++){
			switch (ctx->pixelformat)
			{
				case PSP_DISPLAY_PIXEL_FORMAT_565:
				case PSP_DISPLAY_PIXEL_FORMAT_5551:
				case PSP_DISPLAY_PIXEL_FORMAT_4444:
					color2rgb(vram16[x],&r,&g,&b);
					break;
				case PSP_DISPLAY_PIXEL_FORMAT_8888:		 			
					color2rgb(vram32[x],&r,&g,&b);
					break;
			}
			r = (ctx->bg_a * ctx->bg_r) / 256 + (255-ctx->bg_a) * r / 256;
			g = (ctx->bg_a * ctx->bg_g) / 256 + (255-ctx->bg_a) * g / 256;
			b = (ctx->bg_a * ctx->bg_b) / 256 + (255-ctx->bg_a) * b / 256;
			switch (ctx->pixelformat)
			{
				case PSP_DISPLAY_PIXEL_FORMAT_565:
				case PSP_DISPLAY_PIXEL_FORMAT_5551:
				case PSP_DISPLAY_PIXEL_FORMAT_4444:
					vram16[x] = rgb2color(r,g,b);
					break;
				case PSP_DISPLAY_PIXEL_FORMAT_8888:
					vram32[x] = rgb2color(r,g,b);
					break;
			}
		}
	}
	
	return 0;
}
Esempio n. 5
0
//-------------------------------------------------------------- 
void cdvd_readee(void *buf)
{	// Read Disc datas to EE mem buffer
	u32 nbytes, nsectors, sectors_to_read, size_64b, size_64bb, bytesent, temp;
	int sector_size, flag_64b;
	void *fsvRbuf = (void *)cdvdfsv_buf;
	void *eeaddr_64b, *eeaddr2_64b;
	cdvdfsv_readee_t readee;
	RpcCdvd_t *r = (RpcCdvd_t *)buf;

	if (r->sectors == 0) {
		*(int *)buf = 0;
		return;
	}

	sector_size = 2328;

	if ((r->mode.datapattern & 0xff) != 1) {
		sector_size = 2340;
		if ((r->mode.datapattern & 0xff) != 2)
			sector_size = 2048;
	}

	r->eeaddr1 = (void *)((u32)r->eeaddr1 & 0x1fffffff);
	r->eeaddr2 = (void *)((u32)r->eeaddr2 & 0x1fffffff);
	r->buf = (void *)((u32)r->buf & 0x1fffffff);

	sceCdDiskReady(0);

	sectors_to_read = r->sectors;  
	bytesent = 0;

	if (r->eeaddr2)
		mips_memset((void *)curlsn_buf, 0, 16);

	readee.pdst1 = (void *)r->buf;
	eeaddr_64b = (void *)(((u32)r->buf + 0x3f) & 0xffffffc0); // get the next 64-bytes aligned address

	if ((u32)r->buf & 0x3f)
		readee.b1len = (((u32)r->buf & 0xffffffc0) - (u32)r->buf) + 64; // get how many bytes needed to get a 64 bytes alignment
	else
		readee.b1len = 0;

	nbytes = r->sectors * sector_size;

	temp = (u32)r->buf + nbytes;
	eeaddr2_64b = (void *)(temp & 0xffffffc0);
	temp -= (u32)eeaddr2_64b;
	readee.pdst2 = eeaddr2_64b;  // get the end address on a 64 bytes align 
	readee.b2len = temp; // get bytes remainder at end of 64 bytes align 
	fsvRbuf += temp;

	if (readee.b1len)
		flag_64b = 0; // 64 bytes alignment flag
	else {
		if (temp)
			flag_64b = 0;
		else
			flag_64b = 1;
	}

	while (1) {
		do {
			if ((sectors_to_read == 0) || (sceCdGetError() == CDVD_ERR_ABRT)) {

				if (r->eeaddr1)
					sysmemSendEE((void *)&readee, (void *)r->eeaddr1, sizeof(cdvdfsv_readee_t));

				if (r->eeaddr2) {
					*((u32 *)&curlsn_buf[0]) = nbytes;
					sysmemSendEE((void *)curlsn_buf, (void *)r->eeaddr2, 16);
				}

				*(int *)buf = 1;
				return;
			}

			if (flag_64b == 0) { // not 64 bytes aligned buf
				if (sectors_to_read < CDVDFSV_BUF_SECTORS)
					nsectors = sectors_to_read;
				else
					nsectors = CDVDFSV_BUF_SECTORS-1;
				temp = nsectors + 1;
			}
			else { // 64 bytes aligned buf
				if (sectors_to_read < (CDVDFSV_BUF_SECTORS+1))
					nsectors = sectors_to_read;
				else
					nsectors = CDVDFSV_BUF_SECTORS;
				temp = nsectors;
			}

			sceCdRead0(r->lsn, temp, (void *)fsvRbuf, NULL);

			size_64b = nsectors * sector_size;
			size_64bb = size_64b;

			if (!flag_64b) {
				if (sectors_to_read == r->sectors) // check that was the first read
					mips_memcpy((void *)readee.buf1, (void *)fsvRbuf, readee.b1len);

				if ((!flag_64b) && (sectors_to_read == nsectors) && (readee.b1len))
					size_64bb = size_64b - 64;
			}

			if (size_64bb > 0) {
				sysmemSendEE((void *)(fsvRbuf + readee.b1len), (void *)eeaddr_64b, size_64bb);
				bytesent += size_64bb;
			}

			if (r->eeaddr2) {
				temp = bytesent;
				if (temp < 0)
					temp += 2047;
				temp = temp >> 11;
				*((u32 *)&curlsn_buf[0]) = temp;
				sysmemSendEE((void *)curlsn_buf, (void *)r->eeaddr2, 16);
			}

			sectors_to_read -= nsectors;
			r->lsn += nsectors;
			eeaddr_64b += size_64b;

		} while ((flag_64b) || (sectors_to_read));

		mips_memcpy((void *)readee.buf2, (void *)(fsvRbuf + size_64b - readee.b2len), readee.b2len);
	}
Esempio n. 6
0
static int read_cwdb(char *filename, char *gameid)
{
	int pos=0;
	char *p;
	char cw_buf[300];
	u32 address,val;
	t_mem_table	t;
	PspFile pf;

	if(openfile(filename, &pf)==0) return 1;
	
	if(gameid!=NULL){
		char codename[11];
		mips_memcpy(codename,gameid,10);
		codename[10]=0;
		do{
			pos=read_sect(pos,&pf);
			p=strstr(pf.buf,codename);
			if(p) break;
		}
		while(pos);
	}
	else{
		read_sect(pos,&pf);
		p=pf.buf;
		p=read_line(p,cw_buf);
	}
	
		if(p==0) {
			closefile(&pf);
			return 1;
		}

#ifdef BIG5_ENCODE_TEXT
	t_encodepack pack;
	char *big5buf = malloc(41688);
	if(big5buf==NULL) return 1;
	if(big5_init(big5buf,&pack)==0 && encode_init(&pack)==0)
	{
		charsets_big5_conv(p,&pack);
		encode_free(&pack);
	}
	free(big5buf);
#endif
	
	p=read_line(p,cw_buf);
	mips_memcpy(ui_get_gamename()+12,cw_buf+3,0x40);
	
	int repeat=0;
	int lock =0;
	char namebuf[80];
	char *namep;
	char nullcode=0;
	while(1){
	//金手指码部分	
		p=read_line(p,cw_buf);
		
		if(cw_buf[0]=='_'){
		if(cw_buf[1]=='C'){
			if(nullcode==1) {
			t.addr=0x8800000;
			t.value=0;
			t.type=0;
			t.lock=0;
			if(mem_table_add(&t)<0) goto READOUT;
			}
		repeat=0;
		namep = namebuf;
		mips_memcpy(namebuf,cw_buf+4,70);
		lock = strtoul(cw_buf+2,NULL,16);
		namep = read_name(namep, t.name, 10);
		mips_memcpy(t.name,namebuf,30);
		t.name[30]=0;
		t.name[31]=0;
		nullcode=1;
		}
		else if(cw_buf[1]=='L'){
			nullcode=0;
			if(repeat<5){
				if(repeat==0) {
				}
				else{
					t.name[0] = '+';
					namep = read_name(namep, t.name+1, 9);
				}
				repeat++;
			}
			else{//strcpy(t.name,"+");
				t.name[0]='+';
				t.name[1]=0;
			}
			char *tempptr;
			address=strtoul(cw_buf+2,&tempptr,16)+0x08800000;
			val=strtoul(tempptr,NULL,16);
			t.addr=address;
			t.value=val;
			t.type=0;
			t.lock=lock;
			if(mem_table_add(&t)<0) goto READOUT;
		}
		else if(cw_buf[1]=='S'){
			break;
		}
		}
		if(p==0) break;
		if(p[0]=='_' && p[1]=='S') break;
	}
	
READOUT:
	closefile(&pf);
	return 0;
}