Release 0.9.1-3 with RetroBrowser, PPC audio, XP diagnostics and LP64 repair
This commit is contained in:
17
clients/retro-browser/common/rbp.c
Normal file
17
clients/retro-browser/common/rbp.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#include "rbp.h"
|
||||
#include <string.h>
|
||||
rb_u16 rb_get16(const rb_u8 *p){return (rb_u16)(((rb_u16)p[0]<<8)|p[1]);}
|
||||
rb_u32 rb_get32(const rb_u8 *p){return ((rb_u32)p[0]<<24)|((rb_u32)p[1]<<16)|((rb_u32)p[2]<<8)|p[3];}
|
||||
void rb_put16(rb_u8 *p,rb_u16 n){p[0]=(rb_u8)(n>>8);p[1]=(rb_u8)n;}
|
||||
void rb_put32(rb_u8 *p,rb_u32 n){p[0]=(rb_u8)(n>>24);p[1]=(rb_u8)(n>>16);p[2]=(rb_u8)(n>>8);p[3]=(rb_u8)n;}
|
||||
int rb_read(rb_io *io,void *p,rb_u32 n){rb_u8 *b=(rb_u8*)p;while(n){unsigned int ask=n>16384?16384:(unsigned int)n;int k=io->read(io->ctx,b,ask);if(k<=0||(unsigned int)k>ask)return -1;b+=k;n-=k;}return 0;}
|
||||
static int write_all(rb_io *io,const void *p,rb_u32 n){const rb_u8 *b=(const rb_u8*)p;while(n){unsigned int ask=n>16384?16384:(unsigned int)n;int k=io->write(io->ctx,b,ask);if(k<=0||(unsigned int)k>ask)return -1;b+=k;n-=k;}return 0;}
|
||||
int rb_send(rb_io *io,rb_u16 type,const void *p,rb_u32 n){rb_u8 h[16];memcpy(h,"RBP1",4);rb_put16(h+4,1);rb_put16(h+6,type);rb_put32(h+8,n);rb_put32(h+12,0);return write_all(io,h,16)||write_all(io,p,n)?-1:0;}
|
||||
int rb_header_read(rb_io *io,rb_header *h){rb_u8 b[16];if(rb_read(io,b,16)||memcmp(b,"RBP1",4)||rb_get16(b+4)!=1)return -1;h->type=rb_get16(b+6);h->length=rb_get32(b+8);h->timestamp=rb_get32(b+12);return h->length> 9UL*1024*1024?-1:0;}
|
||||
int rb_hello(rb_io *io,rb_u16 w,rb_u16 h,rb_u8 codecs,rb_u8 audio){rb_u8 b[6];rb_put16(b,w);rb_put16(b+2,h);b[4]=codecs;b[5]=audio;return rb_send(io,RB_HELLO,b,6);}
|
||||
int rb_rgb565(const rb_u8 *p,rb_u32 n,rb_u16 *dst,rb_u32 pixels,int rle){rb_u32 j=0,i=0;if(!rle){if(n!=pixels*2)return -1;while(j<pixels){dst[j++]=rb_get16(p+i);i+=2;}return 0;}while(i<n){rb_u16 count,v;if(n-i<4)return -1;count=rb_get16(p+i);v=rb_get16(p+i+2);i+=4;if(!count||count>pixels-j)return -1;while(count--)dst[j++]=v;}return j==pixels?0:-1;}
|
||||
static const long steps[89]={7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767};
|
||||
static const int adj[8]={-1,-1,-1,-1,2,4,6,8};
|
||||
static long signed16(rb_u16 x){return x>=32768U?(long)x-65536L:x;}
|
||||
int rb_audio(const rb_u8 *p,rb_u32 n,short *dst,rb_u32 capacity){rb_u32 frames,total,i,k;int ch,c,idx[2],code;long pred[2],s,v;if(n<8)return -1;ch=p[4];frames=rb_get16(p+6);if(ch<1||ch>2||!frames)return -1;total=frames*ch;if(total>capacity)return -1;if(p[5]==1){if(n!=8+total*2)return -1;for(i=0;i<total;i++)dst[i]=(short)signed16(rb_get16(p+8+i*2));return (int)total;}if(p[5]!=2||n!=8+(rb_u32)ch*4+(total-ch+1)/2)return -1;p+=8;for(c=0;c<ch;c++){pred[c]=signed16(rb_get16(p+c*4));idx[c]=p[c*4+2];if(idx[c]>88)return -1;dst[c]=(short)pred[c];}p+=ch*4;k=0;for(i=ch;i<total;i++){c=(int)(i%ch);code=(p[k/2]>>((k%2)*4))&15;k++;s=steps[idx[c]];v=(s>>3)+((code&4)?s:0)+((code&2)?s>>1:0)+((code&1)?s>>2:0);pred[c]+=(code&8)?-v:v;if(pred[c]>32767)pred[c]=32767;if(pred[c]<-32768)pred[c]=-32768;idx[c]+=adj[code&7];if(idx[c]<0)idx[c]=0;if(idx[c]>88)idx[c]=88;dst[i]=(short)pred[c];}return (int)total;}
|
||||
Reference in New Issue
Block a user