54 lines
6.1 KiB
C
54 lines
6.1 KiB
C
#include <exec/types.h>
|
|
#include <intuition/intuition.h>
|
|
#include <graphics/gfxbase.h>
|
|
#include <devices/timer.h>
|
|
#include <proto/exec.h>
|
|
#include <proto/dos.h>
|
|
#include <proto/intuition.h>
|
|
#include <proto/graphics.h>
|
|
#include <proto/timer.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#define W 1000
|
|
#define H 142
|
|
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct Library*TimerBase;
|
|
static UBYTE *frame,*scaled,*font;static LONG pens[8];
|
|
static UBYTE colors[8][3]={{17,18,14},{242,222,184},{255,177,54},{97,71,33},{35,32,23},{151,114,54},{116,211,138},{255,218,137}};
|
|
static char titles[24][256],metadata[96];static int count=0;
|
|
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pens[c];}
|
|
static void rect(int x,int y,int w,int h,int c){int a,b;for(b=0;b<h;b++)for(a=0;a<w;a++)pixel(x+a,y+b,c);}
|
|
static void text(int x,int y,char*s,int color,int scale,int lo,int hi){int a,b,k,ch;for(k=0;s[k];k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)continue;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a]){int xx=x+(k*8+a)*scale;if(xx>=lo&&xx+scale<=hi)rect(xx,y+b*scale,scale,scale,color);}}}
|
|
static void trim(char*s){int n=strlen(s);while(n&&(s[n-1]=='\n'||s[n-1]=='\r'))s[--n]=0;}
|
|
static int reload(void){FILE*f=fopen("PROGDIR:news.txt","r");int n=0;if(!f)return 0;if(!fgets(metadata,sizeof(metadata),f)){fclose(f);return 0;}trim(metadata);while(n<24&&fgets(titles[n],256,f)){trim(titles[n]);if(titles[n][0])n++;}fclose(f);count=n;return n>0;}
|
|
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*tp=0,*single=0;struct timerequest*tr=0;struct EClockVal ec;ULONG freq=0,last=0,delta,cls;UWORD code;int timeron=0,got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,index=0,paused=0,speed=72,frames=0;LONG pos=(W-32)*16;char current[256],buf[96];FILE*f;
|
|
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);if(!IntuitionBase||!GfxBase)goto end;
|
|
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMIGA.NEWSWIRE";Forbid();if(FindPort("AMIGA.NEWSWIRE")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();
|
|
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);if(!frame||!font||!scaled)goto end;
|
|
f=fopen("PROGDIR:font.bin","rb");if(!f)goto end;i=fread(font,1,768*12,f);fclose(f);if(i!=768*12)goto end;
|
|
for(i=0;i<8;i++){pens[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pens[i]<0)goto end;got++;}
|
|
tp=CreateMsgPort();if(!tp)goto end;tr=(struct timerequest*)CreateIORequest(tp,sizeof(struct timerequest));if(!tr)goto end;if(OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest*)tr,0))goto end;timeron=1;TimerBase=(struct Library*)tr->tr_node.io_Device;freq=ReadEClock(&ec);last=ec.ev_lo;
|
|
if(!reload()){strcpy(titles[0],"In attesa delle notizie... controlla la connessione internet del PC.");count=1;strcpy(metadata,"HARDWARE UPGRADE | CACHE NON DISPONIBILE");}strcpy(current,titles[0]);
|
|
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,100,WA_Top,790,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"Tech News | Hardware Upgrade",WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,500,WA_MinHeight,110,WA_MaxWidth,sc->Width,WA_MaxHeight,300,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
|
while(!done){while((m=(struct IntuiMessage*)GetMsg(w->UserPort))!=0){cls=m->Class;code=m->Code;ReplyMsg((struct Message*)m);if(cls==IDCMP_CLOSEWINDOW||(cls==IDCMP_RAWKEY&&code==0x45))done=1;if(cls==IDCMP_RAWKEY&&code==0x40)paused=!paused;if(cls==IDCMP_RAWKEY&&code==0x36){index=(index+1)%count;strcpy(current,titles[index]);pos=(W-32)*16;}if(cls==IDCMP_RAWKEY&&code==0x4e&&speed<150)speed+=12;if(cls==IDCMP_RAWKEY&&code==0x4f&&speed>24)speed-=12;if(cls==IDCMP_RAWKEY&&code==0x13){reload();if(index>=count)index=0;}if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}}
|
|
ReadEClock(&ec);delta=ec.ev_lo-last;last=ec.ev_lo;if(delta>freq/4)delta=freq/4;
|
|
if(!paused)pos-=(delta*speed*16)/freq;
|
|
if(pos/16+(LONG)strlen(current)*16<120){index=(index+1)%count;strcpy(current,titles[index]);pos=(W-32)*16;}
|
|
if(++frames%600==0){reload();if(index>=count)index=0;}
|
|
memset(frame,(UBYTE)pens[0],W*H);
|
|
rect(10,5,W-20,1,3);rect(10,32,W-20,1,3);rect(10,105,W-20,1,3);
|
|
text(20,10,"TECH / NEWSWIRE",1,1,0,W);text(240,10,metadata,5,1,0,W);rect(928,12,5,5,paused?3:6);text(940,8,paused?"HOLD":"LIVE",paused?5:6,1,0,W);
|
|
for(y=43;y<97;y+=3)rect(16,y,W-32,1,4);
|
|
sprintf(buf,"%02d/%02d",index+1,count);text(22,59,buf,5,1,0,W);
|
|
/* Headline enters from the right, one illuminated character at a time. */
|
|
text(pos/16+1,58,current,3,2,120,W-20);text(pos/16,57,current,2,2,120,W-20);
|
|
x=pos/16+strlen(current)*16;if(x>=120&&x<W-26&&frames%24<17)rect(x,59,10,19,7);
|
|
rect(118,43,1,52,3);
|
|
text(20,119,"SPAZIO PAUSA N SUCCESSIVA R RICARICA",5,1,0,W);sprintf(buf,"%d PX/S | RSS / 5 MIN",speed);text(744,119,buf,5,1,0,W);
|
|
iw=w->Width-w->BorderLeft-w->BorderRight;ih=w->Height-w->BorderTop-w->BorderBottom;if(iw>0&&ih>0&&iw<=sc->Width&&ih<=sc->Height){if(iw==W&&ih==H)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);else{rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;memset(scaled,(UBYTE)pens[0],(ULONG)iw*ih);for(y=0;y<rh;y++){int sy=(ULONG)y*H/rh;for(x=0;x<rw;x++)scaled[(ULONG)(oy+y)*iw+ox+x]=frame[sy*W+(ULONG)x*W/rw];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}}
|
|
Delay(2);
|
|
}
|
|
end:
|
|
if(w)CloseWindow(w);if(timeron)CloseDevice((struct IORequest*)tr);if(tr)DeleteIORequest((struct IORequest*)tr);if(tp)DeleteMsgPort(tp);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pens[i]);UnlockPubScreen(0,sc);}free(frame);free(font);free(scaled);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
|
}
|