Import Amiga applications and desktop tools
This commit is contained in:
commit
1c144c9a3c
347 files changed
+423483
No files matched your search
@@ -0,0 +1,9 @@
|
||||
* text=auto eol=lf
|
||||
*.bin binary
|
||||
*.info binary
|
||||
*.ttf binary
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.raw binary
|
||||
*.exe binary
|
||||
**/dist/* binary
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
**/build/
|
||||
**/__pycache__/
|
||||
*.pyc
|
||||
*.o
|
||||
*.log
|
||||
*.prefs
|
||||
.vs/
|
||||
.DS_Store
|
||||
|
||||
# Local history, copy metadata and machine backups
|
||||
**/versions/
|
||||
*.before*
|
||||
COPY-MANIFEST.json
|
||||
VALIDATION.md
|
||||
@@ -0,0 +1,3 @@
|
||||
build/
|
||||
*.o
|
||||
*.asm
|
||||
@@ -0,0 +1,11 @@
|
||||
# Rendering optimization (2026-11-06)
|
||||
|
||||
Preserves the existing palette, dimensions, animation rates and visual design.
|
||||
|
||||
- Boing/Matrix: fuse resized pixel sampling and RGB15 conversion into one pass; duplicate scanlines with memcpy.
|
||||
- Boing: ellipse shadow spans replace repeated per-pixel multiplications with identical coverage.
|
||||
- Boing 3D: cache horizontal sphere sampling coordinates per apparent size.
|
||||
- Matrix: cache sparse glyph pixels, preserving glow and core drawing order.
|
||||
- Chrono: cache horizontal sampling coordinates and date conversion; omit invisible analog/digital calculations.
|
||||
|
||||
Original source and executable retained in versions/before-optimization/. Build with build.ps1. No frame-rate reduction.
|
||||
@@ -0,0 +1,3 @@
|
||||
# Amber Chrono
|
||||
|
||||
Native AmigaOS 3.1 analog/digital clock. Independent source project. Build with ./build.ps1 -Toolchain <VBCC toolchain directory>. Output in build/. Copy executable and assets together. Double-click switches display modes; keys 1/2/3 select analog/digital/both; Esc closes.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
param([string]$Toolchain = $env:AMIGA_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/Chrono chrono.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
Copy-Item -LiteralPath assets/face.bin,assets/font.bin,assets/Chrono.info -Destination $buildPath -Force
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1,94 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <dos/datetime.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "colors.h"
|
||||
#include "trig.h"
|
||||
#define W 320
|
||||
#define H 430
|
||||
struct IntuitionBase *IntuitionBase;
|
||||
struct GfxBase *GfxBase;
|
||||
static UBYTE *face,*frame,*out,*font;
|
||||
static LONG pen[64];
|
||||
static UWORD *xmap;
|
||||
static int mapWidth;
|
||||
static LONG lastDate=-1;
|
||||
static int mode=2,borderless=0,px=976,py=28,pw=280,ph=394;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void dot(int x,int y,int r,int c){int a,b;for(b=-r;b<=r;b++)for(a=-r;a<=r;a++)if(a*a+b*b<=r*r)pixel(x+a,y+b,c);}
|
||||
static void line(int x0,int y0,int x1,int y1,int r,int c){int dx=abs(x1-x0),sx=x0<x1?1:-1,dy=-abs(y1-y0),sy=y0<y1?1:-1,e=dx+dy,e2;for(;;){dot(x0,y0,r,c);if(x0==x1&&y0==y1)break;e2=2*e;if(e2>=dy){e+=dy;x0+=sx;}if(e2<=dx){e+=dx;y0+=sy;}}}
|
||||
static void hand(int angle,int length,int tail,int radius,int color){int a=(angle%3600)*2;line(160-trig[a]*tail/10000,158-trig[a+1]*tail/10000,160+trig[a]*length/10000,158+trig[a+1]*length/10000,radius,color);}
|
||||
static void label(int x,int y,char *s,int color){int i,j,k;for(k=0;s[k];k++){i=(unsigned char)s[k]-32;if(i<0||i>=96)continue;for(j=0;j<12;j++){int z;for(z=0;z<8;z++)if(font[j*768+i*8+z])pixel(x+k*8+z,y+j,color);}}}
|
||||
static void digit(int x,int y,int n){static int bits[]={63,6,91,79,102,109,125,7,127,111};int b=bits[n],i;static int seg[7][4]={{5,0,24,0},{28,4,28,19},{28,25,28,40},{5,44,24,44},{1,25,1,40},{1,4,1,19},{5,22,24,22}};for(i=0;i<7;i++)line(x+seg[i][0],y+seg[i][1],x+seg[i][2],y+seg[i][3],2,(b&(1<<i))?2:4);}
|
||||
static int load(char *name,UBYTE *buf,long size){FILE*f=fopen(name,"rb");int ok;if(!f)return 0;ok=fread(buf,1,size,f)==size;fclose(f);return ok;}
|
||||
static void save(struct Window*w){FILE*f;px=w->LeftEdge;py=w->TopEdge;pw=w->Width;ph=w->Height;f=fopen("PROGDIR:Chrono.prefs","w");if(f){fprintf(f,"%d %d %d %d %d %d\n",px,py,pw,ph,mode,borderless);fclose(f);}}
|
||||
static void fitmode(struct Window*w,struct Screen*s){int h=(w->Width-w->BorderLeft-w->BorderRight)*(mode==0?320:mode==1?110:430)/320+w->BorderTop+w->BorderBottom;int top=w->TopEdge;if(h<100)h=100;if(top+h>s->Height)top=s->Height-h;ChangeWindowBox(w,w->LeftEdge,top,w->Width,h);}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct DateTime dt;struct DateStamp ds;char date[64],time[32];FILE*f;int got=0,i,x,y,done=0,reopen=0,iw,ih,rw,rh,ox,oy,srcH,srcOff,sec,min,hour;ULONG cls,ts=0,tm=0,ms,mm;UWORD code;int ticks;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);if(!IntuitionBase||!GfxBase)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;
|
||||
face=malloc(W*H);frame=malloc(W*H);font=malloc(768*12);out=malloc((ULONG)sc->Width*sc->Height);xmap=malloc((ULONG)sc->Width*sizeof(UWORD));if(!face||!frame||!font||!out||!xmap)goto end;
|
||||
if(!load("PROGDIR:face.bin",face,W*H)||!load("PROGDIR:font.bin",font,768*12))goto end;
|
||||
for(i=0;i<64;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}
|
||||
for(i=0;i<W*H;i++)face[i]=(UBYTE)pen[face[i]];
|
||||
f=fopen("PROGDIR:Chrono.prefs","r");if(f){fscanf(f,"%d %d %d %d %d %d",&px,&py,&pw,&ph,&mode,&borderless);fclose(f);}
|
||||
if(mode<0||mode>2)mode=2;if(pw<180||pw>sc->Width)pw=280;if(ph<100||ph>sc->Height)ph=394;
|
||||
if(px<0)px=0;if(py<12)py=12;if(px+pw>sc->Width)px=sc->Width-pw;if(py+ph>sc->Height)py=sc->Height-ph;
|
||||
open:
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,px,WA_Top,py,WA_Width,pw,WA_Height,ph,
|
||||
WA_Title,(ULONG)"Amber Chrono",WA_CloseGadget,!borderless,WA_DragBar,!borderless,WA_DepthGadget,!borderless,WA_SizeGadget,!borderless,WA_SizeBBottom,TRUE,WA_Borderless,borderless,
|
||||
WA_MinWidth,180,WA_MinHeight,100,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,
|
||||
WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE|IDCMP_CHANGEWINDOW,TAG_DONE);
|
||||
if(!w)goto end;
|
||||
while(!done&&!reopen){
|
||||
while((m=(struct IntuiMessage*)GetMsg(w->UserPort))!=0){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;ReplyMsg((struct Message*)m);
|
||||
if(cls==IDCMP_CLOSEWINDOW||(cls==IDCMP_RAWKEY&&code==0x45))done=1;
|
||||
if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){if(DoubleClick(ts,tm,ms,mm)){mode=(mode+1)%3;ts=tm=0;fitmode(w,sc);}else{ts=ms;tm=mm;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code>=1&&code<=3){mode=code-1;fitmode(w,sc);}if(code==0x35){save(w);borderless=!borderless;reopen=1;}}
|
||||
if(cls==IDCMP_NEWSIZE||cls==IDCMP_CHANGEWINDOW)save(w);
|
||||
}
|
||||
DateStamp(&ds);ticks=ds.ds_Tick;sec=ticks/50;min=ds.ds_Minute%60;hour=ds.ds_Minute/60;
|
||||
memcpy(frame,face,W*H);
|
||||
if(mode!=1){
|
||||
hand((hour%12)*300+min*5+ticks/600,63,7,3,1);
|
||||
hand(min*60+ticks/50,91,10,2,5);
|
||||
/* Keep a solid three-pixel stroke so downscaling cannot drop the hand. */
|
||||
hand(ticks*6/5,111,23,1,2);dot(160,158,6,3);dot(160,158,3,2);
|
||||
}
|
||||
if(mode!=0){
|
||||
digit(34,351,hour/10);digit(70,351,hour%10);digit(132,351,min/10);digit(168,351,min%10);digit(230,351,sec/10);digit(266,351,sec%10);
|
||||
dot(116,365,2,2);dot(116,383,2,2);dot(214,365,2,2);dot(214,383,2,2);
|
||||
if(ds.ds_Days!=lastDate){lastDate=ds.ds_Days;
|
||||
memset(&dt,0,sizeof(dt));dt.dat_Stamp=ds;dt.dat_Format=FORMAT_DOS;dt.dat_StrDate=date;dt.dat_StrTime=time;DateToStr(&dt);}
|
||||
label(116,403,date,5);
|
||||
/* A tiny pendulum swings below the seconds display. */
|
||||
x=160+trig[(ticks%100)*72]*11/10000;line(160,398,x,401,0,3);dot(x,401,1,2);
|
||||
}
|
||||
iw=w->Width-w->BorderLeft-w->BorderRight;ih=w->Height-w->BorderTop-w->BorderBottom;
|
||||
srcH=mode==0?320:mode==1?110:430;srcOff=mode==1?320:0;
|
||||
if(iw>0&&ih>0&&iw<=sc->Width&&ih<=sc->Height){rw=iw;rh=iw*srcH/W;if(rh>ih){rh=ih;rw=ih*W/srcH;}ox=(iw-rw)/2;oy=(ih-rh)/2;memset(out,(UBYTE)pen[0],(ULONG)iw*ih);
|
||||
if(mapWidth!=rw){for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;mapWidth=rw;}
|
||||
{int previous=-1;
|
||||
for(y=0;y<rh;y++){
|
||||
int sy=srcOff+(ULONG)y*srcH/rh;UBYTE *dst=out+(ULONG)(oy+y)*iw+ox;
|
||||
if(sy==previous)memcpy(dst,dst-iw,rw);
|
||||
else{UBYTE *src=frame+sy*W;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}
|
||||
previous=sy;
|
||||
}
|
||||
}
|
||||
WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,out,iw);
|
||||
}
|
||||
Delay(2);
|
||||
}
|
||||
save(w);CloseWindow(w);w=0;if(reopen){reopen=0;goto open;}
|
||||
end:
|
||||
if(w)CloseWindow(w);if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}free(face);free(frame);free(font);free(out);free(xmap);
|
||||
if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
static UBYTE colors[][3]={{20,19,16},{236,220,189},{255,183,66},{100,72,34},{48,35,18},{197,145,66},{219,193,148},{179,143,87},{126,102,66},{100,79,47},{87,67,39},{78,58,31},{72,56,34},{70,53,30},{70,52,27},{67,49,26},{65,47,25},{64,46,24},{62,48,27},{62,45,23},{56,47,30},{60,44,23},{57,42,22},{55,40,21},{53,38,20},{49,40,26},{49,37,21},{49,36,18},{41,35,26},{46,34,18},{45,33,17},{39,33,23},{40,30,17},{31,28,22},{29,27,21},{30,26,19},{28,26,21},{27,26,21},{28,25,20},{27,25,20},{27,25,19},{26,25,20},{27,24,18},{24,23,19},{24,22,18},{22,21,17},{21,20,16},{20,20,17},{20,19,17},{20,19,16},{20,19,15},{19,19,16},{19,18,15},{18,18,15},{17,17,14},{15,15,14},{13,14,13},{14,13,10},{12,13,14},{12,13,11},{12,13,10},{11,13,13},{10,12,10},{4,7,8}};
|
||||
@@ -0,0 +1,38 @@
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
from pathlib import Path
|
||||
import math,struct
|
||||
p=Path(__file__).parent
|
||||
S=3
|
||||
im=Image.new('RGB',(320*S,430*S),'#141310');d=ImageDraw.Draw(im)
|
||||
def ellipse(box,fill=None,outline=None,width=1):d.ellipse(tuple(int(v*S) for v in box),fill,outline,width*S)
|
||||
def line(points,fill,width=1):d.line([(int(x*S),int(y*S)) for x,y in points],fill,width*S)
|
||||
fontpath='C:/Windows/Fonts/consola.ttf'
|
||||
def text(x,y,t,size,color):
|
||||
f=ImageFont.truetype(fontpath,size*S); d.text((x*S,y*S),t,font=f,fill=color,anchor='mm')
|
||||
for r in range(148,134,-1):
|
||||
c=int(42+(148-r)*3);ellipse((160-r,158-r,160+r,158+r),(c,int(c*.74),int(c*.39)))
|
||||
ellipse((25,23,295,293),'#1b1914','#dfad61',1)
|
||||
ellipse((29,27,291,289),None,'#413723',1)
|
||||
for i in range(60):
|
||||
a=i*math.pi/30; r=123; ri=111 if i%5==0 else 118
|
||||
line([(160+math.sin(a)*ri,158-math.cos(a)*ri),(160+math.sin(a)*r,158-math.cos(a)*r)],'#e3c693' if i%5==0 else '#726147',2 if i%5==0 else 1)
|
||||
for n in (12,1,2,3,4,5,6,7,8,9,10,11):
|
||||
a=n*math.pi/6;text(160+math.sin(a)*96,158-math.cos(a)*96,str(n),16,'#ecdcbd')
|
||||
text(160,308,'PRECISION / LOCAL TIME',8,'#b59561')
|
||||
d.rounded_rectangle((12*S,326*S,308*S,417*S),radius=8*S,fill='#0c0d0b',outline='#73542b',width=S)
|
||||
text(160,338,'D I G I T A L / 2 4 H',8,'#a78a56')
|
||||
im=im.resize((320,430),Image.Resampling.LANCZOS)
|
||||
# Fixed palette shared by the face, hands, digits and glow levels.
|
||||
base=[(20,19,16),(236,220,189),(255,183,66),(100,72,34),(48,35,18),(197,145,66)]
|
||||
pal=im.quantize(colors=58).getpalette()[:58*3]
|
||||
colors=base+[tuple(pal[i:i+3]) for i in range(0,len(pal),3)]
|
||||
pi=Image.new('P',(1,1));pi.putpalette(sum(map(list,colors),[])+[0]*(768-len(colors)*3))
|
||||
indexed=im.quantize(palette=pi,dither=Image.Dither.NONE)
|
||||
(p/'face.bin').write_bytes(indexed.tobytes());im.save(p/'preview.png')
|
||||
(p/'colors.h').write_text('static UBYTE colors[][3]={'+','.join('{%d,%d,%d}'%c for c in colors)+'};\n')
|
||||
lut=[]
|
||||
for i in range(3600):lut.extend((round(math.sin(i*math.pi/1800)*10000),round(-math.cos(i*math.pi/1800)*10000)))
|
||||
(p/'trig.h').write_text('static short trig[7200]={'+','.join(map(str,lut))+'};\n')
|
||||
atlas=Image.new('1',(96*8,12));a=ImageDraw.Draw(atlas);f=ImageFont.truetype(fontpath,11)
|
||||
for i in range(96):a.text((i*8,0),chr(i+32),font=f,fill=1)
|
||||
(p/'font.bin').write_bytes(bytes(atlas.getpixel((x,y)) for y in range(12) for x in range(768)))
|
||||
@@ -0,0 +1 @@
|
||||
static short trig[7200]={0,-10000,17,-10000,35,-10000,52,-10000,70,-10000,87,-10000,105,-9999,122,-9999,140,-9999,157,-9999,175,-9998,192,-9998,209,-9998,227,-9997,244,-9997,262,-9997,279,-9996,297,-9996,314,-9995,332,-9995,349,-9994,366,-9993,384,-9993,401,-9992,419,-9991,436,-9990,454,-9990,471,-9989,488,-9988,506,-9987,523,-9986,541,-9985,558,-9984,576,-9983,593,-9982,610,-9981,628,-9980,645,-9979,663,-9978,680,-9977,698,-9976,715,-9974,732,-9973,750,-9972,767,-9971,785,-9969,802,-9968,819,-9966,837,-9965,854,-9963,872,-9962,889,-9960,906,-9959,924,-9957,941,-9956,958,-9954,976,-9952,993,-9951,1011,-9949,1028,-9947,1045,-9945,1063,-9943,1080,-9942,1097,-9940,1115,-9938,1132,-9936,1149,-9934,1167,-9932,1184,-9930,1201,-9928,1219,-9925,1236,-9923,1253,-9921,1271,-9919,1288,-9917,1305,-9914,1323,-9912,1340,-9910,1357,-9907,1374,-9905,1392,-9903,1409,-9900,1426,-9898,1444,-9895,1461,-9893,1478,-9890,1495,-9888,1513,-9885,1530,-9882,1547,-9880,1564,-9877,1582,-9874,1599,-9871,1616,-9869,1633,-9866,1650,-9863,1668,-9860,1685,-9857,1702,-9854,1719,-9851,1736,-9848,1754,-9845,1771,-9842,1788,-9839,1805,-9836,1822,-9833,1840,-9829,1857,-9826,1874,-9823,1891,-9820,1908,-9816,1925,-9813,1942,-9810,1959,-9806,1977,-9803,1994,-9799,2011,-9796,2028,-9792,2045,-9789,2062,-9785,2079,-9781,2096,-9778,2113,-9774,2130,-9770,2147,-9767,2164,-9763,2181,-9759,2198,-9755,2215,-9751,2233,-9748,2250,-9744,2267,-9740,2284,-9736,2300,-9732,2317,-9728,2334,-9724,2351,-9720,2368,-9715,2385,-9711,2402,-9707,2419,-9703,2436,-9699,2453,-9694,2470,-9690,2487,-9686,2504,-9681,2521,-9677,2538,-9673,2554,-9668,2571,-9664,2588,-9659,2605,-9655,2622,-9650,2639,-9646,2656,-9641,2672,-9636,2689,-9632,2706,-9627,2723,-9622,2740,-9617,2756,-9613,2773,-9608,2790,-9603,2807,-9598,2823,-9593,2840,-9588,2857,-9583,2874,-9578,2890,-9573,2907,-9568,2924,-9563,2940,-9558,2957,-9553,2974,-9548,2990,-9542,3007,-9537,3024,-9532,3040,-9527,3057,-9521,3074,-9516,3090,-9511,3107,-9505,3123,-9500,3140,-9494,3156,-9489,3173,-9483,3190,-9478,3206,-9472,3223,-9466,3239,-9461,3256,-9455,3272,-9449,3289,-9444,3305,-9438,3322,-9432,3338,-9426,3355,-9421,3371,-9415,3387,-9409,3404,-9403,3420,-9397,3437,-9391,3453,-9385,3469,-9379,3486,-9373,3502,-9367,3518,-9361,3535,-9354,3551,-9348,3567,-9342,3584,-9336,3600,-9330,3616,-9323,3633,-9317,3649,-9311,3665,-9304,3681,-9298,3697,-9291,3714,-9285,3730,-9278,3746,-9272,3762,-9265,3778,-9259,3795,-9252,3811,-9245,3827,-9239,3843,-9232,3859,-9225,3875,-9219,3891,-9212,3907,-9205,3923,-9198,3939,-9191,3955,-9184,3971,-9178,3987,-9171,4003,-9164,4019,-9157,4035,-9150,4051,-9143,4067,-9135,4083,-9128,4099,-9121,4115,-9114,4131,-9107,4147,-9100,4163,-9092,4179,-9085,4195,-9078,4210,-9070,4226,-9063,4242,-9056,4258,-9048,4274,-9041,4289,-9033,4305,-9026,4321,-9018,4337,-9011,4352,-9003,4368,-8996,4384,-8988,4399,-8980,4415,-8973,4431,-8965,4446,-8957,4462,-8949,4478,-8942,4493,-8934,4509,-8926,4524,-8918,4540,-8910,4555,-8902,4571,-8894,4586,-8886,4602,-8878,4617,-8870,4633,-8862,4648,-8854,4664,-8846,4679,-8838,4695,-8829,4710,-8821,4726,-8813,4741,-8805,4756,-8796,4772,-8788,4787,-8780,4802,-8771,4818,-8763,4833,-8755,4848,-8746,4863,-8738,4879,-8729,4894,-8721,4909,-8712,4924,-8704,4939,-8695,4955,-8686,4970,-8678,4985,-8669,5000,-8660,5015,-8652,5030,-8643,5045,-8634,5060,-8625,5075,-8616,5090,-8607,5105,-8599,5120,-8590,5135,-8581,5150,-8572,5165,-8563,5180,-8554,5195,-8545,5210,-8536,5225,-8526,5240,-8517,5255,-8508,5270,-8499,5284,-8490,5299,-8480,5314,-8471,5329,-8462,5344,-8453,5358,-8443,5373,-8434,5388,-8425,5402,-8415,5417,-8406,5432,-8396,5446,-8387,5461,-8377,5476,-8368,5490,-8358,5505,-8348,5519,-8339,5534,-8329,5548,-8320,5563,-8310,5577,-8300,5592,-8290,5606,-8281,5621,-8271,5635,-8261,5650,-8251,5664,-8241,5678,-8231,5693,-8221,5707,-8211,5721,-8202,5736,-8192,5750,-8181,5764,-8171,5779,-8161,5793,-8151,5807,-8141,5821,-8131,5835,-8121,5850,-8111,5864,-8100,5878,-8090,5892,-8080,5906,-8070,5920,-8059,5934,-8049,5948,-8039,5962,-8028,5976,-8018,5990,-8007,6004,-7997,6018,-7986,6032,-7976,6046,-7965,6060,-7955,6074,-7944,6088,-7934,6101,-7923,6115,-7912,6129,-7902,6143,-7891,6157,-7880,6170,-7869,6184,-7859,6198,-7848,6211,-7837,6225,-7826,6239,-7815,6252,-7804,6266,-7793,6280,-7782,6293,-7771,6307,-7760,6320,-7749,6334,-7738,6347,-7727,6361,-7716,6374,-7705,6388,-7694,6401,-7683,6414,-7672,6428,-7660,6441,-7649,6455,-7638,6468,-7627,6481,-7615,6494,-7604,6508,-7593,6521,-7581,6534,-7570,6547,-7559,6561,-7547,6574,-7536,6587,-7524,6600,-7513,6613,-7501,6626,-7490,6639,-7478,6652,-7466,6665,-7455,6678,-7443,6691,-7431,6704,-7420,6717,-7408,6730,-7396,6743,-7385,6756,-7373,6769,-7361,6782,-7349,6794,-7337,6807,-7325,6820,-7314,6833,-7302,6845,-7290,6858,-7278,6871,-7266,6884,-7254,6896,-7242,6909,-7230,6921,-7218,6934,-7206,6947,-7193,6959,-7181,6972,-7169,6984,-7157,6997,-7145,7009,-7133,7022,-7120,7034,-7108,7046,-7096,7059,-7083,7071,-7071,7083,-7059,7096,-7046,7108,-7034,7120,-7022,7133,-7009,7145,-6997,7157,-Line truncated
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,7 @@
|
||||
# AmberMod
|
||||
|
||||
Sorgenti raccolti da work/modplayer. Binario installato conservato in dist/ModPlayer; risorse in assets.
|
||||
|
||||
Build: ./build.ps1 -Toolchain <VBCC/VASM/VLINK + NDK m68k-amigaos>.
|
||||
|
||||
Gli script originali sono conservati senza modificarne i percorsi: alcuni generatori leggono C:/Amiga o font Windows. Il binario presente in dist e quello effettivamente installato; il sorgente raccolto e la versione locale piu recente.
|
||||
@@ -0,0 +1,4 @@
|
||||
Stack 131072
|
||||
Run >NIL: SYS:Utilities/HippoPlayer/HiP HIDE
|
||||
Wait 1 SECS
|
||||
Run >NIL: SYS:Utilities/AmberMod/ModPlayer
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
import math,unicodedata
|
||||
p=Path(__file__).parent;dest=Path('C:/Amiga/HD0/Utilities/AmberMod')
|
||||
root=Path('C:/Amiga/WHDLoad/MODS')
|
||||
def display(s):return ''.join(c for c in unicodedata.normalize('NFKD',s) if ord(c)<128 and ord(c)>=32).strip()
|
||||
rows=[]
|
||||
for f in sorted(root.rglob('*'),key=lambda f:str(f).lower()):
|
||||
if not f.is_file() or f.suffix.lower()!='.mod':continue
|
||||
try:
|
||||
with f.open('rb') as h: title=h.read(20).split(b'\0')[0].decode('latin1')
|
||||
title=display(title)
|
||||
filename=display(f.stem)
|
||||
shown=filename if not title or title.lower() in filename.lower() else filename+' / '+title
|
||||
path='WHDLoad:MODS/'+f.relative_to(root).as_posix()
|
||||
rows.append(shown[:94]+'\t'+path)
|
||||
except OSError:pass
|
||||
rows.sort(key=lambda row:row.split('\t',1)[0].casefold())
|
||||
(dest/'catalog.txt').write_bytes(('\n'.join(rows)+'\n').encode('latin1',errors='replace'))
|
||||
def arr(name,values):return 'static short '+name+'[]={'+','.join(map(str,values))+'};\n'
|
||||
(p/'fft.h').write_text(arr('hann',[round((.5-.5*math.cos(2*math.pi*i/255))*16384) for i in range(256)])+arr('twcos',[round(math.cos(-2*math.pi*i/256)*16384) for i in range(128)])+arr('twsin',[round(math.sin(-2*math.pi*i/256)*16384) for i in range(128)])+arr('bandedge',[round(1*(127**(i/24))) for i in range(25)])+arr('logheight',[round(144*math.log1p(i)/math.log(129)) for i in range(256)]))
|
||||
print(len(rows),'MOD indicizzati')
|
||||
@@ -0,0 +1,26 @@
|
||||
param([string]$Toolchain = $env:AMIGA_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/ModPlayer player.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
Copy-Item -LiteralPath assets/font.bin,assets/ModPlayer.info,assets/MOD,assets/MOD.info -Destination $buildPath -Force
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <exec/types.h>
|
||||
#include <proto/exec.h>
|
||||
#include <stdio.h>
|
||||
int main(void){UBYTE*p=(UBYTE*)FindPort("HiP-Port");FILE*f=fopen("SYS:ModPlayerStop.log","w");if(f){fprintf(f,"playing=%d\n",p?p[sizeof(struct MsgPort)+13]:0);fclose(f);}return 0;}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <exec/types.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <stdio.h>
|
||||
int main(void){FILE*f=fopen("SYS:ModPlayerDiag.txt","w");UBYTE*p,*ch,*s;int i,c;Forbid();p=(UBYTE*)FindPort("HiP-Port");Permit();fprintf(f,"MsgPort size %d port %lx rexx %lx\n",sizeof(struct MsgPort),p,FindPort("HIPPOPLAYER"));if(p){for(i=0;i<110;i++)fprintf(f,"%02x%s",p[i],i%16==15?"\n":" ");for(c=0;c<4;c++){ch=*(UBYTE**)(p+50+c*4);fprintf(f,"\nCH%d ",c);if(ch){for(i=0;i<16;i++)fprintf(f,"%02x ",ch[i]);s=*(UBYTE**)ch;if(s){fprintf(f,"\nsample ");for(i=0;i<32;i++)fprintf(f,"%02x ",s[i]);}}}}fclose(f);return 0;}
|
||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
static short hann[]={0,2,10,22,40,62,89,122,159,201,247,299,355,417,483,553,628,708,793,881,975,1072,1174,1281,1391,1506,1624,1747,1874,2004,2138,2276,2417,2562,2710,2862,3017,3175,3336,3500,3667,3837,4009,4184,4361,4541,4722,4906,5092,5280,5469,5661,5853,6047,6243,6439,6637,6836,7035,7235,7436,7637,7839,8041,8242,8444,8646,8847,9048,9249,9449,9648,9846,10043,10239,10434,10627,10819,11010,11198,11385,11570,11753,11934,12112,12288,12462,12633,12801,12966,13129,13288,13445,13598,13748,13895,14038,14178,14313,14446,14574,14699,14819,14936,15049,15157,15261,15361,15456,15548,15634,15716,15794,15867,15935,15999,16057,16111,16161,16205,16245,16279,16309,16334,16354,16368,16378,16383,16383,16378,16368,16354,16334,16309,16279,16245,16205,16161,16111,16057,15999,15935,15867,15794,15716,15634,15548,15456,15361,15261,15157,15049,14936,14819,14699,14574,14446,14313,14178,14038,13895,13748,13598,13445,13288,13129,12966,12801,12633,12462,12288,12112,11934,11753,11570,11385,11198,11010,10819,10627,10434,10239,10043,9846,9648,9449,9249,9048,8847,8646,8444,8242,8041,7839,7637,7436,7235,7035,6836,6637,6439,6243,6047,5853,5661,5469,5280,5092,4906,4722,4541,4361,4184,4009,3837,3667,3500,3336,3175,3017,2862,2710,2562,2417,2276,2138,2004,1874,1747,1624,1506,1391,1281,1174,1072,975,881,793,708,628,553,483,417,355,299,247,201,159,122,89,62,40,22,10,2,0};
|
||||
static short twcos[]={16384,16379,16364,16340,16305,16261,16207,16143,16069,15986,15893,15791,15679,15557,15426,15286,15137,14978,14811,14635,14449,14256,14053,13842,13623,13395,13160,12916,12665,12406,12140,11866,11585,11297,11003,10702,10394,10080,9760,9434,9102,8765,8423,8076,7723,7366,7005,6639,6270,5897,5520,5139,4756,4370,3981,3590,3196,2801,2404,2006,1606,1205,804,402,0,-402,-804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379};
|
||||
static short twsin[]={0,-402,-804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379,-16384,-16379,-16364,-16340,-16305,-16261,-16207,-16143,-16069,-15986,-15893,-15791,-15679,-15557,-15426,-15286,-15137,-14978,-14811,-14635,-14449,-14256,-14053,-13842,-13623,-13395,-13160,-12916,-12665,-12406,-12140,-11866,-11585,-11297,-11003,-10702,-10394,-10080,-9760,-9434,-9102,-8765,-8423,-8076,-7723,-7366,-7005,-6639,-6270,-5897,-5520,-5139,-4756,-4370,-3981,-3590,-3196,-2801,-2404,-2006,-1606,-1205,-804,-402};
|
||||
static short bandedge[]={1,1,1,2,2,3,3,4,5,6,8,9,11,14,17,21,25,31,38,46,57,69,85,104,127};
|
||||
static short logheight[]={0,21,33,41,48,53,58,62,65,68,71,74,76,78,80,82,84,86,87,89,90,92,93,94,95,97,98,99,100,101,102,103,104,104,105,106,107,108,109,109,110,111,111,112,113,113,114,115,115,116,117,117,118,118,119,119,120,120,121,121,122,122,123,123,124,124,125,125,125,126,126,127,127,128,128,128,129,129,129,130,130,131,131,131,132,132,132,133,133,133,134,134,134,135,135,135,136,136,136,136,137,137,137,138,138,138,138,139,139,139,140,140,140,140,141,141,141,141,142,142,142,142,143,143,143,143,144,144,144,144,144,145,145,145,145,146,146,146,146,146,147,147,147,147,147,148,148,148,148,148,149,149,149,149,149,150,150,150,150,150,151,151,151,151,151,151,152,152,152,152,152,153,153,153,153,153,153,154,154,154,154,154,154,155,155,155,155,155,155,155,156,156,156,156,156,156,157,157,157,157,157,157,157,158,158,158,158,158,158,158,159,159,159,159,159,159,159,160,160,160,160,160,160,160,160,161,161,161,161,161,161,161,162,162,162,162,162,162,162,162,163,163,163,163,163,163,163,163,163,164,164,164,164,164,164,164};
|
||||
@@ -0,0 +1,9 @@
|
||||
from pathlib import Path
|
||||
p=Path(__file__).parent/'player.c';s=p.read_text()
|
||||
s=s.replace('lastState=-1,full=1,lastw=0','lastState=-1,full=1,hud=0,repaint=0,lastw=0')
|
||||
s=s.replace('full=dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState;','hud=seconds!=lastSecond||(hip?hip->play:0)!=lastState;repaint=dirty;full=dirty||hud;')
|
||||
s=s.replace('memcpy(frame,panel,W*H);drawAudio();','full=repaint;memcpy(frame,panel,W*H);drawAudio();')
|
||||
s=s.replace('frame+504*W+382,W);}','frame+504*W+382,W);if(hud)WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+354,w->BorderLeft+741,w->BorderTop+409,frame+354*W+382,W);}')
|
||||
s=s.replace('}else if(full){scaledRegion(w,iw,rw,rh,ox,oy,0,0,W,H);}','}else if(full){for(y=0;y<rh;y++){UBYTE*src=frame+ymap[y]*W;UBYTE*dst=scaled+(ULONG)(oy+y)*iw+ox;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}')
|
||||
s=s.replace('scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);}','scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);if(hud)scaledRegion(w,iw,rw,rh,ox,oy,382,354,742,410);}')
|
||||
p.write_text(s)
|
||||
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
import struct
|
||||
p=Path('C:/Amiga/HD0/Utilities/AmberMod')
|
||||
h=bytearray(Path('C:/Amiga/HD0/System/Shell.info').read_bytes()[:78])
|
||||
def u16(n):return struct.pack('>H',n)
|
||||
def u32(n):return struct.pack('>I',n&0xffffffff)
|
||||
h[12:16]=u16(48)+u16(40);h[16:18]=u16(6);h[48]=3
|
||||
for off in (22,26):h[off:off+4]=u32(1)
|
||||
for off in (44,50,54,66,70):h[off:off+4]=u32(0)
|
||||
h[58:66]=u32(-1)+u32(-1);h[74:78]=u32(131072)
|
||||
data=bytearray(h)
|
||||
for selected in (False,True):
|
||||
im=Image.new('P',(48,40),0);d=ImageDraw.Draw(im)
|
||||
d.rounded_rectangle((2,1,45,35),radius=3,fill=2,outline=1 if selected else 3,width=2)
|
||||
d.ellipse((8,6,35,32),fill=3,outline=1);d.ellipse((16,14,27,25),fill=2,outline=1);d.polygon(((21,17),(21,23),(26,20)),fill=1);d.rectangle((36,9,39,30),fill=1)
|
||||
d.line((6,32,41,32),fill=1);d.rectangle((18,36,30,38),fill=3)
|
||||
data+=u16(0)+u16(0)+u16(48)+u16(40)+u16(2)+u32(1)+bytes([3,0])+u32(0)
|
||||
for plane in range(2):
|
||||
for y in range(40):
|
||||
for x in range(0,48,8):data.append(sum((128>>i) if im.getpixel((x+i,y))&(1<<plane) else 0 for i in range(8)))
|
||||
(p/'ModPlayer.info').write_bytes(data)
|
||||
@@ -0,0 +1,10 @@
|
||||
from pathlib import Path
|
||||
import struct
|
||||
p=Path('C:/Amiga/HD0/Utilities/AmberMod')
|
||||
b=bytearray((p/'ModPlayer.info').read_bytes())
|
||||
b[48]=4;b[50:54]=struct.pack('>I',1);b[54:58]=struct.pack('>I',1)
|
||||
def s(t):
|
||||
z=t.encode('ascii')+b'\0';return struct.pack('>I',len(z))+z
|
||||
b+=s('SYS:C/IconX')+struct.pack('>I',8)+s('WINDOW=CON:0/0/640/80/MOD Player/AUTO/CLOSE')
|
||||
(p/'MOD.info').write_bytes(b)
|
||||
(p/'MOD').write_bytes(b'Stack 131072\nRun >NIL: SYS:Utilities/HippoPlayer/HiP HIDE\nWait 1 SECS\nRun >NIL: SYS:Utilities/AmberMod/ModPlayer\n')
|
||||
@@ -0,0 +1,40 @@
|
||||
from pathlib import Path
|
||||
p=Path(__file__).parent/'player.c'
|
||||
s=p.read_text()
|
||||
s=s.replace('static UBYTE *frame,*scaled,*font;','static UBYTE *frame,*scaled,*font,*panel;')
|
||||
s=s.replace('static int bars[24],peak[24],vu[4]','static int bars[24],peak[24],target[24],vu[4]')
|
||||
old='if(t>bars[i])bars[i]=(bars[i]+t*4)/5;else{bars[i]=(bars[i]*2+t)/3;if(bars[i]>t)bars[i]--;}if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>2)peak[i]-=3;else peak[i]=0;'
|
||||
assert old in s
|
||||
s=s.replace(old,'target[i]=t;')
|
||||
helper='''
|
||||
static void drawAudio(void){int i,h,b;for(i=0;i<24;i++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
'''
|
||||
s=s.replace('int main(void)',helper+'\nint main(void)')
|
||||
s=s.replace('frames=0,active=0,dragging=0','frames=0,active=0,dragging=0,dirty=1,lastState=-1')
|
||||
s=s.replace('ULONG cls,lasts=0','ULONG lastSecond=0xffffffff,cls,lasts=0')
|
||||
s=s.replace('frame=malloc(W*H);font=','frame=malloc(W*H);panel=malloc(W*H);font=')
|
||||
s=s.replace('if(!frame||!font||!scaled)','if(!frame||!panel||!font||!scaled)')
|
||||
s=s.replace('ReplyMsg((struct Message*)m);if(cls==IDCMP_CLOSEWINDOW)','ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)')
|
||||
s=s.replace('frames++;spectrum();','frames++;if(frames%2==0)spectrum();\n if(dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState){')
|
||||
bar=' for(i=0;i<24;i++){int h=bars[i],px=398+i*13;for(y=0;y<h;y+=3)rect(px,302-y,9,2,y>112?8:y>70?2:6);if(peak[i])rect(px,302-peak[i],9,1,9);}'
|
||||
assert bar in s
|
||||
s=s.replace(bar,'')
|
||||
vu=' for(i=0;i<4;i++){int vv=vu[i]*70/64;rect(382+i*90,504,80,5,4);rect(382+i*90,504,vv,5,5);}'
|
||||
assert vu in s
|
||||
s=s.replace(vu,'')
|
||||
mark=' iw=w->Width-w->BorderLeft-w->BorderRight;'
|
||||
assert mark in s
|
||||
s=s.replace(mark,' memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}\n memcpy(frame,panel,W*H);drawAudio();\n'+mark)
|
||||
s=s.replace(' Delay(2);',' Delay(1);')
|
||||
s=s.replace('free(frame);free(font);','free(frame);free(panel);free(font);')
|
||||
p.write_text(s)
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <rexx/storage.h>
|
||||
#include <dos/dostags.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/rexxsyslib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fft.h"
|
||||
#define W 760
|
||||
#define H 560
|
||||
#define MAXSONGS 6000
|
||||
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct RxsLib*RexxSysBase;
|
||||
struct PTChannel{BYTE*start;UWORD length;BYTE*loop;UWORD replen,volume,period,priv;};
|
||||
struct HipPort{struct MsgPort port;ULONG priv1;APTR kpl;UWORD reserved;UBYTE quit,opens,volume,play,type,res2;struct PTChannel*ch[4];BYTE*left,*right;ULONG offs,maxoffs;UBYTE trigger[4];APTR priv2;ULONG seconds,colordiv;UWORD rate;};
|
||||
struct Song{char*title,*path,*key;};static struct Song songs[MAXSONGS];static int matches[MAXSONGS],total=0,found=0,selected=0,top=0;
|
||||
static UBYTE *frame,*scaled,*font,*panel;static LONG pen[12];static UBYTE colors[][3]={{17,18,15},{238,222,190},{255,180,62},{93,71,37},{33,32,24},{185,147,82},{116,211,138},{37,75,49},{236,105,56},{255,220,142},{53,43,27},{12,14,12}};
|
||||
static struct HipPort*hip=0;static struct MsgPort*reply=0;static int pending=0,playing=0,volume=48,editing=1,rows=17;static char query[64]="",now[96]="Scegli un brano dalla libreria",currentPath[320]="";
|
||||
static short pcm[256],re[256],im[256];static int bars[24],peak[24],target[24],vu[4],available=0;static ULONG seconds=0;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void rect(int x,int y,int w,int h,int c){int j;for(j=0;j<h;j++)if(y+j>=0&&y+j<H){int l=x<0?0:x,r=x+w>W?W:x+w;if(r>l)memset(frame+(y+j)*W+l,(UBYTE)pen[c],r-l);}}
|
||||
static void box(int x,int y,int w,int h,int c){rect(x,y,w,h,3);rect(x+1,y+1,w-2,h-2,c);}
|
||||
static void text(int x,int y,char*s,int c,int scale,int max){int a,b,k,ch;for(k=0;s[k]&&k<max;k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)ch='?'-32;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a])rect(x+(k*8+a)*scale,y+b*scale,scale,scale,c);}}
|
||||
static void center(int x,int y,int w,char*s,int c){text(x+(w-strlen(s)*8)/2,y,s,c,1,99);}
|
||||
static void button(int x,int y,int w,char*s,int active){box(x,y,w,28,active?10:4);center(x,y+7,w,s,active?2:1);}
|
||||
static char*dup(char*s){char*p=malloc(strlen(s)+1);if(p)strcpy(p,s);return p;}
|
||||
static void lower(char*s){for(;*s;s++)*s=tolower((unsigned char)*s);}
|
||||
static void filter(void){int i;char q[64];strcpy(q,query);lower(q);found=0;for(i=0;i<total;i++)if(!q[0]||strstr(songs[i].key,q))matches[found++]=i;selected=top=0;}
|
||||
static void catalog(void){FILE*f=fopen("SYS:Utilities/AmberMod/catalog.txt","r");char line[700],key[700],*p,*e;if(!f)return;while(total<MAXSONGS&&fgets(line,sizeof(line),f)){p=strchr(line,'\t');if(!p)continue;*p++=0;e=strpbrk(p,"\r\n");if(e)*e=0;songs[total].title=dup(line);songs[total].path=dup(p);snprintf(key,sizeof(key),"%s %s",line,p);lower(key);songs[total].key=dup(key);if(!songs[total].title||!songs[total].path||!songs[total].key)break;total++;}fclose(f);filter();}
|
||||
static void replies(void){struct RexxMsg*m;while((m=(struct RexxMsg*)GetMsg(reply))){if(m->rm_Args[0])DeleteArgstring(m->rm_Args[0]);if(m->rm_Result1==0&&m->rm_Result2)DeleteArgstring((UBYTE*)m->rm_Result2);DeleteRexxMsg(m);pending--;}}
|
||||
static int sendcommand(char*s){struct RexxMsg*m;struct MsgPort*dest;m=CreateRexxMsg(reply,0,"HIPPOPLAYER");if(!m)return 0;m->rm_Action=RXCOMM;m->rm_Args[0]=CreateArgstring(s,strlen(s));if(!m->rm_Args[0]){DeleteRexxMsg(m);return 0;}Forbid();dest=FindPort("HIPPOPLAYER");if(dest){PutMsg(dest,(struct Message*)m);pending++;}Permit();if(!dest){DeleteArgstring(m->rm_Args[0]);DeleteRexxMsg(m);return 0;}return 1;}
|
||||
static char commands[16][450];static int qhead=0,qtail=0,qcount=0;
|
||||
static int command(char*s){if(qcount>=16)return 0;strncpy(commands[qtail],s,449);commands[qtail][449]=0;qtail=(qtail+1)%16;qcount++;return 1;}
|
||||
static void dispatch(void){if(!pending&&qcount){sendcommand(commands[qhead]);qhead=(qhead+1)%16;qcount--;}}
|
||||
static void attach(void){if(hip&&hip->quit){Forbid();hip->opens--;hip=0;Permit();}if(!hip){Forbid();hip=(struct HipPort*)FindPort("HiP-Port");if(hip&&!hip->quit)hip->opens++;else hip=0;Permit();}}
|
||||
static void play(void){char cmd[450];int n;if(!found)return;n=matches[selected];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;}}
|
||||
static void move(int delta,int start){if(!found)return;selected=(selected+delta+found)%found;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;if(start)play();}
|
||||
static void scrollto(int y){int max=found-rows;if(max<0)max=0;top=(y-140)*max/340;if(top<0)top=0;if(top>max)top=max;selected=top;}
|
||||
static void audio(void){int i,c;memset(pcm,0,sizeof(pcm));memset(vu,0,sizeof(vu));available=0;seconds=0;attach();if(!hip)return;
|
||||
Forbid();if(!hip->quit){seconds=hip->seconds;if(hip->play&&hip->type!=49){for(c=0;c<4;c++){struct PTChannel*p=hip->ch[c];BYTE*s,*loop;ULONG len,looplen,step,off;int vol,period;if(!p)continue;s=p->start;loop=p->loop;len=(ULONG)p->length*2;looplen=(ULONG)p->replen*2;vol=p->volume;period=p->period;if(!s||len<2||period<40||period>4000||vol>64)continue;available=1;step=(3546895UL*256)/(period*11025UL);vu[c]=vol;for(i=0;i<256;i++){off=(i*step)>>8;if(off<len)pcm[i]+=s[off]*vol/256;else if(loop&&looplen>2)pcm[i]+=loop[(off-len)%looplen]*vol/256;}}}
|
||||
else if(hip->play&&hip->type==49&&hip->left&&hip->right&&hip->maxoffs<1048576&&hip->maxoffs>255){available=1;for(i=0;i<256;i++){ULONG off=(hip->offs+(ULONG)i*(hip->rate?hip->rate:22050)/11025)&hip->maxoffs;pcm[i]=(hip->left[off]+hip->right[off])/2;}vu[0]=vu[1]=hip->volume;}}
|
||||
Permit();
|
||||
}
|
||||
static void spectrum(void){int i,j,k,len,half,step,idx,a,b,tr,ti,ur,ui,mag,t;audio();for(i=0;i<256;i++){re[i]=pcm[i]*hann[i]/256;im[i]=0;}j=0;for(i=1;i<256;i++){k=128;while(j&k){j^=k;k>>=1;}j^=k;if(i<j){t=re[i];re[i]=re[j];re[j]=t;}}
|
||||
for(len=2;len<=256;len*=2){half=len/2;step=256/len;for(i=0;i<256;i+=len)for(j=0;j<half;j++){idx=j*step;a=i+j;b=a+half;tr=(twcos[idx]*re[b]-twsin[idx]*im[b])/16384;ti=(twcos[idx]*im[b]+twsin[idx]*re[b])/16384;ur=re[a];ui=im[a];re[a]=(ur+tr)/2;im[a]=(ui+ti)/2;re[b]=(ur-tr)/2;im[b]=(ui-ti)/2;}}
|
||||
for(i=0;i<24;i++){mag=0;for(j=bandedge[i];j<=bandedge[i+1]&&j<128;j++){t=abs(re[j])+abs(im[j]);if(t>mag)mag=t;}mag/=5;if(mag>255)mag=255;t=available?logheight[mag]:0;if(t>144)t=144;target[i]=t;}
|
||||
}
|
||||
|
||||
static void drawAudio(void){int i,h,b;for(i=0;i<24;i++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*single=0;int got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,frames=0,active=0,dragging=0,dirty=1,lastState=-1;ULONG lastSecond=0xffffffff,cls,lasts=0,lastm=0,ms,mm;UWORD code;char buf[160],cmd[40];FILE*f;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);RexxSysBase=(struct RxsLib*)OpenLibrary("rexxsyslib.library",0);if(!IntuitionBase||!GfxBase||!RexxSysBase)goto end;
|
||||
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMBER.MOD.PLAYER";Forbid();if(FindPort("AMBER.MOD.PLAYER")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();reply=CreateMsgPort();if(!reply)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);panel=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);if(!frame||!panel||!font||!scaled)goto end;f=fopen("SYS:Utilities/AmberMod/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<12;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}catalog();
|
||||
command("HIDE 0");snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,230,WA_Top,150,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"MOD Player",WA_Activate,TRUE,WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,650,WA_MinHeight,495,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,WA_ReportMouse,TRUE,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
||||
while(!done){replies();dispatch();while((m=(struct IntuiMessage*)GetMsg(w->UserPort))){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;x=(m->MouseX-w->BorderLeft)*W/(w->Width-w->BorderLeft-w->BorderRight);y=(m->MouseY-w->BorderTop)*H/(w->Height-w->BorderTop-w->BorderBottom);ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)done=1;if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTUP)dragging=0;if(cls==IDCMP_MOUSEMOVE&&dragging)scrollto(y);if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN&&x>=348&&x<366&&y>=138&&y<=480){dragging=1;scrollto(y);}if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){editing=y>=48&&y<=84;if(y>=140&&y<480&&x>=18&&x<348){i=(y-140)/20+top;if(i<found){selected=i;if(DoubleClick(lasts,lastm,ms,mm))play();lasts=ms;lastm=mm;}}
|
||||
if(y>=422&&y<450){if(x>=382&&x<442)move(-1,1);if(x>=450&&x<520)play();if(x>=528&&x<608){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}if(x>=616&&x<690){command("STOP");playing=0;}}
|
||||
if(y>=462&&y<490){if(x>=382&&x<442)move(1,1);if(x>=450&&x<548&&found){selected=rand()%found;top=selected>rows?selected-rows/2:0;play();}if(x>=558&&x<596&&volume>=4)volume-=4;if(x>=650&&x<690&&volume<=60)volume+=4;snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);}}
|
||||
if(cls==IDCMP_VANILLAKEY){if(code==27){if(editing){editing=0;query[0]=0;filter();}else done=1;}else if(code==13)play();else if(editing){i=strlen(query);if(code==8&&i){query[i-1]=0;filter();}else if(code>=32&&code<127&&i<62){query[i]=code;query[i+1]=0;filter();}}else if(code==' '){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}else if(code=='/'){editing=1;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code==0x4c)move(-1,0);if(code==0x4d)move(1,0);if(code==0x7a)move(-3,0);if(code==0x7b)move(3,0);}}
|
||||
frames++;if(frames%2==0)spectrum();
|
||||
if(dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState){
|
||||
memset(frame,(UBYTE)pen[0],W*H);text(20,12,"MOD / PLAYER",1,2,30);text(470,21,"AMIGA MODULE LIBRARY",5,1,30);
|
||||
box(18,48,724,36,editing?10:4);text(30,60,"CERCA >",5,1,10);text(106,60,query,1,1,64);if(editing&&frames%20<12)rect(106+strlen(query)*8,60,6,12,2);if(!query[0]&&!editing)text(106,60,"Titolo, nome file o cartella...",3,1,64);
|
||||
box(18,104,350,408,11);sprintf(buf,"LIBRERIA %d / %d",found,total);text(30,116,buf,5,1,40);
|
||||
for(i=0;i<rows;i++){int n=i+top;if(n>=found)break;if(n==selected)rect(24,138+i*20,338,19,10);text(30,141+i*20,songs[matches[n]].title,n==selected?2:1,1,38);}
|
||||
rect(350,138,11,340,4);{int size=found>rows?rows*340/found:340;int pos;if(size<22)size=22;pos=found>rows?top*(340-size)/(found-rows):0;rect(351,138+pos,9,size,5);rect(354,143+pos,3,size>10?size-10:1,2);}
|
||||
box(382,104,360,238,11);text(396,116,"SPECTRUM / FFT",5,1,35);
|
||||
for(y=151;y<=302;y+=30)rect(396,y,330,1,4);
|
||||
|
||||
text(398,317,"44Hz 1kHz 5.5kHz",3,1,40);if(hip&&hip->play&&!available)center(396,220,330,"ANALISI NON DISPONIBILE",5);
|
||||
box(382,354,360,56,4);text(394,362,now,1,1,42);if(strlen(now)>42)text(394,376,now+42,1,1,42);sprintf(buf,"%s %02lu:%02lu %s",hip&&hip->play?"PLAY":playing==2?"PAUSE":"STOP",seconds/60,seconds%60,hip&&hip->type==33?"4CH / PAULA":"HIPPO ENGINE");text(394,393,buf,5,1,42);
|
||||
button(382,422,60,"|<",0);button(450,422,70,"PLAY",playing==1);button(528,422,80,"PAUSA",playing==2);button(616,422,74,"STOP",playing==0);
|
||||
button(382,462,60,">|",0);button(450,462,98,"RANDOM",0);button(558,462,38,"-",0);sprintf(buf,"%02d",volume*100/64);center(598,470,50,buf,2);button(650,462,40,"+",0);
|
||||
|
||||
text(20,532,"DOPPIO CLIC / INVIO: PLAY /: CERCA SPAZIO: PAUSA",5,1,80);
|
||||
memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}
|
||||
memcpy(frame,panel,W*H);drawAudio();
|
||||
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)pen[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(1);
|
||||
}
|
||||
end:
|
||||
if(hip){Forbid();hip->opens--;hip=0;Permit();}if(reply&&RexxSysBase){command("STOP");while(pending||qcount){dispatch();if(pending)WaitPort(reply);replies();}}if(w)CloseWindow(w);if(reply)DeleteMsgPort(reply);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}for(i=0;i<total;i++){free(songs[i].title);free(songs[i].path);free(songs[i].key);}free(frame);free(panel);free(font);free(scaled);if(RexxSysBase)CloseLibrary((struct Library*)RexxSysBase);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <rexx/storage.h>
|
||||
#include <dos/dostags.h>
|
||||
#include <dos/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/rexxsyslib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fft.h"
|
||||
#define W 760
|
||||
#define H 560
|
||||
#define MAXSONGS 6000
|
||||
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct RxsLib*RexxSysBase;
|
||||
struct PTChannel{BYTE*start;UWORD length;BYTE*loop;UWORD replen,volume,period,priv;};
|
||||
struct HipPort{struct MsgPort port;ULONG priv1;APTR kpl;UWORD reserved;UBYTE quit,opens,volume,play,type,res2;struct PTChannel*ch[4];BYTE*left,*right;ULONG offs,maxoffs;UBYTE trigger[4];APTR priv2;ULONG seconds,colordiv;UWORD rate;};
|
||||
struct Song{char*title,*path,*key;};static struct Song songs[MAXSONGS];static int matches[MAXSONGS],total=0,found=0,selected=0,top=0;
|
||||
static UBYTE *frame,*scaled,*font,*panel;static UWORD *xmap,*ymap;static LONG pen[12];static UBYTE colors[][3]={{17,18,15},{238,222,190},{255,180,62},{93,71,37},{33,32,24},{185,147,82},{116,211,138},{37,75,49},{236,105,56},{255,220,142},{53,43,27},{12,14,12}};
|
||||
static int playlist[MAXSONGS],plistCount=0,plistPos=0,currentSong=-1;static ULONG clockTicks=0,playTick=0,previousSeconds=0,trackDuration=0;static int seenPlaying=0,animTicks=1,durationQueries=0;static ULONG lastDurationQuery=0;
|
||||
static struct HipPort*hip=0;static struct MsgPort*reply=0;static int pending=0,playing=0,volume=48,editing=1,rows=17;static char query[64]="",now[96]="Scegli un brano dalla libreria",currentPath[320]="";
|
||||
static short pcm[256],re[256],im[256];static int bars[24],peak[24],target[24],vu[4],available=0;static ULONG seconds=0;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void rect(int x,int y,int w,int h,int c){int j;for(j=0;j<h;j++)if(y+j>=0&&y+j<H){int l=x<0?0:x,r=x+w>W?W:x+w;if(r>l)memset(frame+(y+j)*W+l,(UBYTE)pen[c],r-l);}}
|
||||
static void box(int x,int y,int w,int h,int c){rect(x,y,w,h,3);rect(x+1,y+1,w-2,h-2,c);}
|
||||
static void text(int x,int y,char*s,int c,int scale,int max){int a,b,k,ch;for(k=0;s[k]&&k<max;k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)ch='?'-32;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a])rect(x+(k*8+a)*scale,y+b*scale,scale,scale,c);}}
|
||||
static void center(int x,int y,int w,char*s,int c){text(x+(w-strlen(s)*8)/2,y,s,c,1,99);}
|
||||
static void button(int x,int y,int w,char*s,int active){box(x,y,w,28,active?10:4);center(x,y+7,w,s,active?2:1);}
|
||||
static char*dup(char*s){char*p=malloc(strlen(s)+1);if(p)strcpy(p,s);return p;}
|
||||
static void lower(char*s){for(;*s;s++)*s=tolower((unsigned char)*s);}
|
||||
static void filter(void){int i;char q[64];strcpy(q,query);lower(q);found=0;for(i=0;i<total;i++)if(!q[0]||strstr(songs[i].key,q))matches[found++]=i;selected=top=0;}
|
||||
static void catalog(void){FILE*f=fopen("SYS:Utilities/AmberMod/catalog.txt","r");char line[700],key[700],*p,*e;if(!f)return;while(total<MAXSONGS&&fgets(line,sizeof(line),f)){p=strchr(line,'\t');if(!p)continue;*p++=0;e=strpbrk(p,"\r\n");if(e)*e=0;songs[total].title=dup(line);songs[total].path=dup(p);snprintf(key,sizeof(key),"%s %s",line,p);lower(key);songs[total].key=dup(key);if(!songs[total].title||!songs[total].path||!songs[total].key)break;total++;}fclose(f);filter();}
|
||||
static void replies(void){struct RexxMsg*m;while((m=(struct RexxMsg*)GetMsg(reply))){if(m->rm_Result1==0&&m->rm_Result2&&m->rm_Args[0]&&!strcmp(m->rm_Args[0],"GET DURA"))trackDuration=atol((char*)m->rm_Result2);if(m->rm_Args[0])DeleteArgstring(m->rm_Args[0]);if(m->rm_Result1==0&&m->rm_Result2)DeleteArgstring((UBYTE*)m->rm_Result2);DeleteRexxMsg(m);pending--;}}
|
||||
static int sendcommand(char*s){struct RexxMsg*m;struct MsgPort*dest;m=CreateRexxMsg(reply,0,"HIPPOPLAYER");if(!m)return 0;m->rm_Action=RXCOMM;if(!strncmp(s,"GET ",4))m->rm_Action|=RXFF_RESULT;m->rm_Args[0]=CreateArgstring(s,strlen(s));if(!m->rm_Args[0]){DeleteRexxMsg(m);return 0;}Forbid();dest=FindPort("HIPPOPLAYER");if(dest){PutMsg(dest,(struct Message*)m);pending++;}Permit();if(!dest){DeleteArgstring(m->rm_Args[0]);DeleteRexxMsg(m);return 0;}return 1;}
|
||||
static char commands[16][450];static int qhead=0,qtail=0,qcount=0;
|
||||
static int command(char*s){if(qcount>=16)return 0;strncpy(commands[qtail],s,449);commands[qtail][449]=0;qtail=(qtail+1)%16;qcount++;return 1;}
|
||||
static void dispatch(void){if(!pending&&qcount){sendcommand(commands[qhead]);qhead=(qhead+1)%16;qcount--;}}
|
||||
static void attach(void){if(hip&&hip->quit){Forbid();hip->opens--;hip=0;Permit();}if(!hip){Forbid();hip=(struct HipPort*)FindPort("HiP-Port");if(hip&&!hip->quit)hip->opens++;else hip=0;Permit();}}
|
||||
static void loadsong(int n){char cmd[450];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;currentSong=n;playTick=clockTicks;previousSeconds=0;trackDuration=0;seenPlaying=0;durationQueries=1;lastDurationQuery=clockTicks;command("GET DURA");}}
|
||||
static void play(void){int i;if(!found)return;if(found==1){plistCount=total;for(i=0;i<total;i++)playlist[i]=i;plistPos=matches[selected];}else{plistCount=found;for(i=0;i<found;i++)playlist[i]=matches[i];plistPos=selected;}loadsong(matches[selected]);}
|
||||
static void nextsong(void){int i;if(!plistCount)return;plistPos=(plistPos+1)%plistCount;loadsong(playlist[plistPos]);for(i=0;i<found;i++)if(matches[i]==currentSong){selected=i;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;break;}}
|
||||
static void move(int delta,int start){if(!found)return;selected=(selected+delta+found)%found;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;if(start)play();}
|
||||
static void scrollto(int y){int max=found-rows;if(max<0)max=0;top=(y-140)*max/340;if(top<0)top=0;if(top>max)top=max;selected=top;}
|
||||
static void audio(void){int i,c;memset(pcm,0,sizeof(pcm));memset(vu,0,sizeof(vu));available=0;seconds=0;attach();if(!hip)return;
|
||||
Forbid();if(!hip->quit){seconds=hip->seconds;if(hip->play&&hip->type!=49){for(c=0;c<4;c++){struct PTChannel*p=hip->ch[c];BYTE*s,*loop;ULONG len,looplen,step,off;int vol,period;if(!p)continue;s=p->start;loop=p->loop;len=(ULONG)p->length*2;looplen=(ULONG)p->replen*2;vol=p->volume;period=p->period;if(!s||len<2||period<40||period>4000||vol>64)continue;available=1;step=(3546895UL*256)/(period*11025UL);vu[c]=vol;for(i=0;i<256;i++){off=(i*step)>>8;if(off<len)pcm[i]+=s[off]*vol/256;else if(loop&&looplen>2)pcm[i]+=loop[(off-len)%looplen]*vol/256;}}}
|
||||
else if(hip->play&&hip->type==49&&hip->left&&hip->right&&hip->maxoffs<1048576&&hip->maxoffs>255){available=1;for(i=0;i<256;i++){ULONG off=(hip->offs+(ULONG)i*(hip->rate?hip->rate:22050)/11025)&hip->maxoffs;pcm[i]=(hip->left[off]+hip->right[off])/2;}vu[0]=vu[1]=hip->volume;}}
|
||||
Permit();
|
||||
}
|
||||
static void spectrum(void){int i,j,k,len,half,step,idx,a,b,tr,ti,ur,ui,mag,t;audio();for(i=0;i<256;i++){re[i]=pcm[i]*hann[i]/256;im[i]=0;}j=0;for(i=1;i<256;i++){k=128;while(j&k){j^=k;k>>=1;}j^=k;if(i<j){t=re[i];re[i]=re[j];re[j]=t;}}
|
||||
for(len=2;len<=256;len*=2){half=len/2;step=256/len;for(i=0;i<256;i+=len)for(j=0;j<half;j++){idx=j*step;a=i+j;b=a+half;tr=(twcos[idx]*re[b]-twsin[idx]*im[b])/16384;ti=(twcos[idx]*im[b]+twsin[idx]*re[b])/16384;ur=re[a];ui=im[a];re[a]=(ur+tr)/2;im[a]=(ui+ti)/2;re[b]=(ur-tr)/2;im[b]=(ui-ti)/2;}}
|
||||
for(i=0;i<24;i++){mag=0;for(j=bandedge[i];j<=bandedge[i+1]&&j<128;j++){t=abs(re[j])+abs(im[j]);if(t>mag)mag=t;}mag/=5;if(mag>255)mag=255;t=available?logheight[mag]:0;if(t>144)t=144;target[i]=t;}
|
||||
}
|
||||
|
||||
static void drawAudio(void){int i,h,b,n;for(i=0;i<24;i++){for(n=0;n<animTicks;n++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;}
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
|
||||
static void scaledRegion(struct Window*w,int iw,int rw,int rh,int ox,int oy,int x0,int y0,int x1,int y1){int x,y,dx0=ox+x0*rw/W,dx1=ox+(x1*rw+W-1)/W,dy0=oy+y0*rh/H,dy1=oy+(y1*rh+H-1)/H;for(y=dy0;y<dy1;y++){UBYTE*src=frame+ymap[y-oy]*W;UBYTE*dst=scaled+(ULONG)y*iw;for(x=dx0;x<dx1;x++)dst[x]=src[xmap[x-ox]];}WriteChunkyPixels(w->RPort,w->BorderLeft+dx0,w->BorderTop+dy0,w->BorderLeft+dx1-1,w->BorderTop+dy1-1,scaled+(ULONG)dy0*iw+dx0,iw);}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*single=0;int got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,frames=0,active=0,dragging=0,dirty=1,lastState=-1,full=1,hud=0,repaint=0,lastw=0,lasth=0;struct DateStamp stamp;ULONG lastTick=0,lastAnalysis=0,lastSecond=0xffffffff,cls,lasts=0,lastm=0,ms,mm;UWORD code;char buf[160],cmd[40];FILE*f;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);RexxSysBase=(struct RxsLib*)OpenLibrary("rexxsyslib.library",0);if(!IntuitionBase||!GfxBase||!RexxSysBase)goto end;
|
||||
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMBER.MOD.PLAYER";Forbid();if(FindPort("AMBER.MOD.PLAYER")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();reply=CreateMsgPort();if(!reply)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);panel=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);xmap=malloc(sc->Width*sizeof(UWORD));ymap=malloc(sc->Height*sizeof(UWORD));if(!xmap||!ymap||!frame||!panel||!font||!scaled)goto end;f=fopen("SYS:Utilities/AmberMod/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<12;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}catalog();
|
||||
command("HIDE 0");snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,230,WA_Top,150,WA_InnerWidth,950,WA_InnerHeight,700,WA_Title,(ULONG)"MOD Player",WA_Activate,TRUE,WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,650,WA_MinHeight,495,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,WA_ReportMouse,TRUE,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
||||
while(!done){DateStamp(&stamp);clockTicks=(ULONG)stamp.ds_Minute*3000+stamp.ds_Tick;animTicks=lastTick?clockTicks-lastTick:1;if(animTicks<0||animTicks>10)animTicks=1;lastTick=clockTicks;replies();dispatch();while((m=(struct IntuiMessage*)GetMsg(w->UserPort))){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;x=(m->MouseX-w->BorderLeft)*W/(w->Width-w->BorderLeft-w->BorderRight);y=(m->MouseY-w->BorderTop)*H/(w->Height-w->BorderTop-w->BorderBottom);ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)done=1;if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTUP)dragging=0;if(cls==IDCMP_MOUSEMOVE&&dragging)scrollto(y);if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN&&x>=348&&x<366&&y>=138&&y<=480){dragging=1;scrollto(y);}if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){editing=y>=48&&y<=84;if(y>=140&&y<480&&x>=18&&x<348){i=(y-140)/20+top;if(i<found){selected=i;if(DoubleClick(lasts,lastm,ms,mm))play();lasts=ms;lastm=mm;}}
|
||||
if(y>=422&&y<450){if(x>=382&&x<442)move(-1,1);if(x>=450&&x<520)play();if(x>=528&&x<608){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}if(x>=616&&x<690){command("STOP");playing=0;}}
|
||||
if(y>=462&&y<490){if(x>=382&&x<442)move(1,1);if(x>=450&&x<548&&found){selected=rand()%found;top=selected>rows?selected-rows/2:0;play();}if(x>=558&&x<596&&volume>=4)volume-=4;if(x>=650&&x<690&&volume<=60)volume+=4;snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);}}
|
||||
if(cls==IDCMP_VANILLAKEY){if(code==27){if(editing){editing=0;query[0]=0;filter();}else done=1;}else if(code==13)play();else if(editing){i=strlen(query);if(code==8&&i){query[i-1]=0;filter();}else if(code>=32&&code<127&&i<62){query[i]=code;query[i+1]=0;filter();}}else if(code==' '){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}else if(code=='/'){editing=1;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code==0x4c)move(-1,0);if(code==0x4d)move(1,0);if(code==0x7a)move(-3,0);if(code==0x7b)move(3,0);}}
|
||||
frames++;if(playing==1&&!trackDuration&&durationQueries<3&&clockTicks-lastDurationQuery>=250&&!pending&&!qcount){command("GET DURA");durationQueries++;lastDurationQuery=clockTicks;}if(clockTicks-lastAnalysis>=2){spectrum();lastAnalysis=clockTicks;}
|
||||
if(playing==1&&clockTicks-playTick>=150){if(trackDuration&&seconds>=trackDuration){nextsong();dirty=1;}else if(hip&&hip->play){if(seenPlaying&&seconds+2<previousSeconds){nextsong();dirty=1;}else seenPlaying=1;}else if(seenPlaying){nextsong();dirty=1;}}
|
||||
previousSeconds=seconds;
|
||||
hud=seconds!=lastSecond||(hip?hip->play:0)!=lastState;repaint=dirty;full=dirty||hud;
|
||||
if(full){
|
||||
memset(frame,(UBYTE)pen[0],W*H);text(20,12,"MOD / PLAYER",1,2,30);text(470,21,"AMIGA MODULE LIBRARY",5,1,30);
|
||||
box(18,48,724,36,editing?10:4);text(30,60,"CERCA >",5,1,10);text(106,60,query,1,1,64);if(editing&&frames%20<12)rect(106+strlen(query)*8,60,6,12,2);if(!query[0]&&!editing)text(106,60,"Titolo, nome file o cartella...",3,1,64);
|
||||
box(18,104,350,408,11);sprintf(buf,"LIBRERIA %d / %d",found,total);text(30,116,buf,5,1,40);
|
||||
for(i=0;i<rows;i++){int n=i+top;if(n>=found)break;if(n==selected)rect(24,138+i*20,338,19,10);text(30,141+i*20,songs[matches[n]].title,n==selected?2:1,1,38);}
|
||||
rect(350,138,11,340,4);{int size=found>rows?rows*340/found:340;int pos;if(size<22)size=22;pos=found>rows?top*(340-size)/(found-rows):0;rect(351,138+pos,9,size,5);rect(354,143+pos,3,size>10?size-10:1,2);}
|
||||
box(382,104,360,238,11);text(396,116,"SPECTRUM / FFT",5,1,35);
|
||||
for(y=151;y<=302;y+=30)rect(396,y,330,1,4);
|
||||
|
||||
text(398,317,"44Hz 1kHz 5.5kHz",3,1,40);if(hip&&hip->play&&!available)center(396,220,330,"ANALISI NON DISPONIBILE",5);
|
||||
box(382,354,360,56,4);text(394,362,now,1,1,42);if(strlen(now)>42)text(394,376,now+42,1,1,42);sprintf(buf,"%s %02lu:%02lu %s",hip&&hip->play?"PLAY":playing==2?"PAUSE":"STOP",seconds/60,seconds%60,hip&&hip->type==33?"4CH / PAULA":"HIPPO ENGINE");text(394,393,buf,5,1,42);
|
||||
button(382,422,60,"|<",0);button(450,422,70,"PLAY",playing==1);button(528,422,80,"PAUSA",playing==2);button(616,422,74,"STOP",playing==0);
|
||||
button(382,462,60,">|",0);button(450,462,98,"RANDOM",0);button(558,462,38,"-",0);sprintf(buf,"%02d",volume*100/64);center(598,470,50,buf,2);button(650,462,40,"+",0);
|
||||
|
||||
text(20,532,"DOPPIO CLIC / INVIO: PLAY /: CERCA SPAZIO: PAUSA",5,1,80);
|
||||
memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}
|
||||
full=repaint;memcpy(frame,panel,W*H);drawAudio();
|
||||
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!=lastw||ih!=lasth){full=1;lastw=iw;lasth=ih;rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;for(y=0;y<rh;y++)ymap[y]=(ULONG)y*H/rh;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);}
|
||||
if(iw==W&&ih==H){
|
||||
if(full)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);
|
||||
else{WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+104,w->BorderLeft+741,w->BorderTop+341,frame+104*W+382,W);WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+504,w->BorderLeft+741,w->BorderTop+509,frame+504*W+382,W);if(hud)WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+354,w->BorderLeft+741,w->BorderTop+409,frame+354*W+382,W);}
|
||||
}else if(full){for(y=0;y<rh;y++){UBYTE*src=frame+ymap[y]*W;UBYTE*dst=scaled+(ULONG)(oy+y)*iw+ox;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}
|
||||
else{scaledRegion(w,iw,rw,rh,ox,oy,382,104,742,342);scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);if(hud)scaledRegion(w,iw,rw,rh,ox,oy,382,354,742,410);}
|
||||
}
|
||||
WaitTOF();
|
||||
}
|
||||
end:
|
||||
if(hip){Forbid();hip->opens--;hip=0;Permit();}if(reply&&RexxSysBase){command("STOP");while(pending||qcount){dispatch();if(pending)WaitPort(reply);replies();}}if(w)CloseWindow(w);if(reply)DeleteMsgPort(reply);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}for(i=0;i<total;i++){free(songs[i].title);free(songs[i].path);free(songs[i].key);}free(xmap);free(ymap);free(frame);free(panel);free(font);free(scaled);if(RexxSysBase)CloseLibrary((struct Library*)RexxSysBase);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <rexx/storage.h>
|
||||
#include <dos/dostags.h>
|
||||
#include <dos/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/rexxsyslib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fft.h"
|
||||
#define W 760
|
||||
#define H 560
|
||||
#define MAXSONGS 6000
|
||||
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct RxsLib*RexxSysBase;
|
||||
struct PTChannel{BYTE*start;UWORD length;BYTE*loop;UWORD replen,volume,period,priv;};
|
||||
struct HipPort{struct MsgPort port;ULONG priv1;APTR kpl;UWORD reserved;UBYTE quit,opens,volume,play,type,res2;struct PTChannel*ch[4];BYTE*left,*right;ULONG offs,maxoffs;UBYTE trigger[4];APTR priv2;ULONG seconds,colordiv;UWORD rate;};
|
||||
struct Song{char*title,*path,*key;};static struct Song songs[MAXSONGS];static int matches[MAXSONGS],total=0,found=0,selected=0,top=0;
|
||||
static UBYTE *frame,*scaled,*font,*panel;static UWORD *xmap,*ymap;static LONG pen[12];static UBYTE colors[][3]={{17,18,15},{238,222,190},{255,180,62},{93,71,37},{33,32,24},{185,147,82},{116,211,138},{37,75,49},{236,105,56},{255,220,142},{53,43,27},{12,14,12}};
|
||||
static int playlist[MAXSONGS],plistCount=0,plistPos=0,currentSong=-1;static ULONG clockTicks=0,playTick=0,previousSeconds=0,trackDuration=0;static int seenPlaying=0,animTicks=1,durationQueries=0;static ULONG lastDurationQuery=0;
|
||||
static struct HipPort*hip=0;static struct MsgPort*reply=0;static int pending=0,playing=0,volume=48,editing=1,rows=17;static char query[64]="",now[96]="Scegli un brano dalla libreria",currentPath[320]="";
|
||||
static short pcm[256],re[256],im[256];static int bars[24],peak[24],target[24],vu[4],available=0;static ULONG seconds=0;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void rect(int x,int y,int w,int h,int c){int j;for(j=0;j<h;j++)if(y+j>=0&&y+j<H){int l=x<0?0:x,r=x+w>W?W:x+w;if(r>l)memset(frame+(y+j)*W+l,(UBYTE)pen[c],r-l);}}
|
||||
static void box(int x,int y,int w,int h,int c){rect(x,y,w,h,3);rect(x+1,y+1,w-2,h-2,c);}
|
||||
static void text(int x,int y,char*s,int c,int scale,int max){int a,b,k,ch;for(k=0;s[k]&&k<max;k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)ch='?'-32;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a])rect(x+(k*8+a)*scale,y+b*scale,scale,scale,c);}}
|
||||
static void center(int x,int y,int w,char*s,int c){text(x+(w-strlen(s)*8)/2,y,s,c,1,99);}
|
||||
static void button(int x,int y,int w,char*s,int active){box(x,y,w,28,active?10:4);center(x,y+7,w,s,active?2:1);}
|
||||
static char*dup(char*s){char*p=malloc(strlen(s)+1);if(p)strcpy(p,s);return p;}
|
||||
static void lower(char*s){for(;*s;s++)*s=tolower((unsigned char)*s);}
|
||||
static void filter(void){int i;char q[64];strcpy(q,query);lower(q);found=0;for(i=0;i<total;i++)if(!q[0]||strstr(songs[i].key,q))matches[found++]=i;selected=top=0;}
|
||||
static void catalog(void){FILE*f=fopen("SYS:Utilities/AmberMod/catalog.txt","r");char line[700],key[700],*p,*e;if(!f)return;while(total<MAXSONGS&&fgets(line,sizeof(line),f)){p=strchr(line,'\t');if(!p)continue;*p++=0;e=strpbrk(p,"\r\n");if(e)*e=0;songs[total].title=dup(line);songs[total].path=dup(p);snprintf(key,sizeof(key),"%s %s",line,p);lower(key);songs[total].key=dup(key);if(!songs[total].title||!songs[total].path||!songs[total].key)break;total++;}fclose(f);filter();}
|
||||
static void replies(void){struct RexxMsg*m;while((m=(struct RexxMsg*)GetMsg(reply))){if(m->rm_Result1==0&&m->rm_Result2&&m->rm_Args[0]&&!strcmp(m->rm_Args[0],"GET DURA"))trackDuration=atol((char*)m->rm_Result2);if(m->rm_Args[0])DeleteArgstring(m->rm_Args[0]);if(m->rm_Result1==0&&m->rm_Result2)DeleteArgstring((UBYTE*)m->rm_Result2);DeleteRexxMsg(m);pending--;}}
|
||||
static int sendcommand(char*s){struct RexxMsg*m;struct MsgPort*dest;m=CreateRexxMsg(reply,0,"HIPPOPLAYER");if(!m)return 0;m->rm_Action=RXCOMM;if(!strncmp(s,"GET ",4))m->rm_Action|=RXFF_RESULT;m->rm_Args[0]=CreateArgstring(s,strlen(s));if(!m->rm_Args[0]){DeleteRexxMsg(m);return 0;}Forbid();dest=FindPort("HIPPOPLAYER");if(dest){PutMsg(dest,(struct Message*)m);pending++;}Permit();if(!dest){DeleteArgstring(m->rm_Args[0]);DeleteRexxMsg(m);return 0;}return 1;}
|
||||
static char commands[16][450];static int qhead=0,qtail=0,qcount=0;
|
||||
static int command(char*s){if(qcount>=16)return 0;strncpy(commands[qtail],s,449);commands[qtail][449]=0;qtail=(qtail+1)%16;qcount++;return 1;}
|
||||
static void dispatch(void){if(!pending&&qcount){sendcommand(commands[qhead]);qhead=(qhead+1)%16;qcount--;}}
|
||||
static void attach(void){if(hip&&hip->quit){Forbid();hip->opens--;hip=0;Permit();}if(!hip){Forbid();hip=(struct HipPort*)FindPort("HiP-Port");if(hip&&!hip->quit)hip->opens++;else hip=0;Permit();}}
|
||||
static void loadsong(int n){char cmd[450];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;currentSong=n;playTick=clockTicks;previousSeconds=0;trackDuration=0;seenPlaying=0;durationQueries=1;lastDurationQuery=clockTicks;command("GET DURA");}}
|
||||
static void play(void){int i;if(!found)return;if(found==1){plistCount=total;for(i=0;i<total;i++)playlist[i]=i;plistPos=matches[selected];}else{plistCount=found;for(i=0;i<found;i++)playlist[i]=matches[i];plistPos=selected;}loadsong(matches[selected]);}
|
||||
static void nextsong(void){int i;if(!plistCount)return;plistPos=(plistPos+1)%plistCount;loadsong(playlist[plistPos]);for(i=0;i<found;i++)if(matches[i]==currentSong){selected=i;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;break;}}
|
||||
static void move(int delta,int start){if(!found)return;selected=(selected+delta+found)%found;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;if(start)play();}
|
||||
static void scrollto(int y){int max=found-rows;if(max<0)max=0;top=(y-140)*max/340;if(top<0)top=0;if(top>max)top=max;selected=top;}
|
||||
static void audio(void){int i,c;memset(pcm,0,sizeof(pcm));memset(vu,0,sizeof(vu));available=0;seconds=0;attach();if(!hip)return;
|
||||
Forbid();if(!hip->quit){seconds=hip->seconds;if(hip->play&&hip->type!=49){for(c=0;c<4;c++){struct PTChannel*p=hip->ch[c];BYTE*s,*loop;ULONG len,looplen,step,off;int vol,period;if(!p)continue;s=p->start;loop=p->loop;len=(ULONG)p->length*2;looplen=(ULONG)p->replen*2;vol=p->volume;period=p->period;if(!s||len<2||period<40||period>4000||vol>64)continue;available=1;step=(3546895UL*256)/(period*11025UL);vu[c]=vol;for(i=0;i<256;i++){off=(i*step)>>8;if(off<len)pcm[i]+=s[off]*vol/256;else if(loop&&looplen>2)pcm[i]+=loop[(off-len)%looplen]*vol/256;}}}
|
||||
else if(hip->play&&hip->type==49&&hip->left&&hip->right&&hip->maxoffs<1048576&&hip->maxoffs>255){available=1;for(i=0;i<256;i++){ULONG off=(hip->offs+(ULONG)i*(hip->rate?hip->rate:22050)/11025)&hip->maxoffs;pcm[i]=(hip->left[off]+hip->right[off])/2;}vu[0]=vu[1]=hip->volume;}}
|
||||
Permit();
|
||||
}
|
||||
static void spectrum(void){int i,j,k,len,half,step,idx,a,b,tr,ti,ur,ui,mag,t;audio();for(i=0;i<256;i++){re[i]=pcm[i]*hann[i]/256;im[i]=0;}j=0;for(i=1;i<256;i++){k=128;while(j&k){j^=k;k>>=1;}j^=k;if(i<j){t=re[i];re[i]=re[j];re[j]=t;}}
|
||||
for(len=2;len<=256;len*=2){half=len/2;step=256/len;for(i=0;i<256;i+=len)for(j=0;j<half;j++){idx=j*step;a=i+j;b=a+half;tr=(twcos[idx]*re[b]-twsin[idx]*im[b])/16384;ti=(twcos[idx]*im[b]+twsin[idx]*re[b])/16384;ur=re[a];ui=im[a];re[a]=(ur+tr)/2;im[a]=(ui+ti)/2;re[b]=(ur-tr)/2;im[b]=(ui-ti)/2;}}
|
||||
for(i=0;i<24;i++){mag=0;for(j=bandedge[i];j<=bandedge[i+1]&&j<128;j++){t=abs(re[j])+abs(im[j]);if(t>mag)mag=t;}mag/=5;if(mag>255)mag=255;t=available?logheight[mag]:0;if(t>144)t=144;target[i]=t;}
|
||||
}
|
||||
|
||||
static void drawAudio(void){int i,h,b,n;for(i=0;i<24;i++){for(n=0;n<animTicks;n++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;}
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
|
||||
static void scaledRegion(struct Window*w,int iw,int rw,int rh,int ox,int oy,int x0,int y0,int x1,int y1){int x,y,dx0=ox+x0*rw/W,dx1=ox+(x1*rw+W-1)/W,dy0=oy+y0*rh/H,dy1=oy+(y1*rh+H-1)/H;for(y=dy0;y<dy1;y++){UBYTE*src=frame+ymap[y-oy]*W;UBYTE*dst=scaled+(ULONG)y*iw;for(x=dx0;x<dx1;x++)dst[x]=src[xmap[x-ox]];}WriteChunkyPixels(w->RPort,w->BorderLeft+dx0,w->BorderTop+dy0,w->BorderLeft+dx1-1,w->BorderTop+dy1-1,scaled+(ULONG)dy0*iw+dx0,iw);}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*single=0;int got=0,done=0,i,x,y,iw,ih,rw=W,rh=H,ox=0,oy=0,frames=0,active=0,dragging=0,dirty=1,lastState=-1,full=1,hud=0,repaint=0,lastw=0,lasth=0;struct DateStamp stamp;ULONG lastTick=0,lastAnalysis=0,lastSecond=0xffffffff,cls,lasts=0,lastm=0,ms,mm;UWORD code;char buf[160],cmd[40];FILE*f;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);RexxSysBase=(struct RxsLib*)OpenLibrary("rexxsyslib.library",0);if(!IntuitionBase||!GfxBase||!RexxSysBase)goto end;
|
||||
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMBER.MOD.PLAYER";Forbid();if(FindPort("AMBER.MOD.PLAYER")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();reply=CreateMsgPort();if(!reply)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);panel=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);xmap=malloc(sc->Width*sizeof(UWORD));ymap=malloc(sc->Height*sizeof(UWORD));if(!xmap||!ymap||!frame||!panel||!font||!scaled)goto end;f=fopen("SYS:Utilities/AmberMod/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<12;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}catalog();
|
||||
command("HIDE 0");snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,230,WA_Top,150,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"MOD Player",WA_Activate,TRUE,WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,650,WA_MinHeight,495,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,WA_ReportMouse,TRUE,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
||||
while(!done){DateStamp(&stamp);clockTicks=(ULONG)stamp.ds_Minute*3000+stamp.ds_Tick;animTicks=lastTick?clockTicks-lastTick:1;if(animTicks<0||animTicks>10)animTicks=1;lastTick=clockTicks;replies();dispatch();while((m=(struct IntuiMessage*)GetMsg(w->UserPort))){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;x=(m->MouseX-w->BorderLeft-ox)*W/rw;y=(m->MouseY-w->BorderTop-oy)*H/rh;ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)done=1;if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTUP)dragging=0;if(cls==IDCMP_MOUSEMOVE&&dragging)scrollto(y);if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN&&x>=348&&x<366&&y>=138&&y<=480){dragging=1;scrollto(y);}if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){editing=y>=48&&y<=84;if(y>=140&&y<480&&x>=18&&x<348){i=(y-140)/20+top;if(i<found){selected=i;if(DoubleClick(lasts,lastm,ms,mm))play();lasts=ms;lastm=mm;}}
|
||||
if(y>=422&&y<450){if(x>=382&&x<442)move(-1,1);if(x>=450&&x<520)play();if(x>=528&&x<608){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}if(x>=616&&x<690){command("STOP");playing=0;}}
|
||||
if(y>=462&&y<490){if(x>=382&&x<442)move(1,1);if(x>=450&&x<548&&found){selected=rand()%found;top=selected>rows?selected-rows/2:0;play();}if(x>=558&&x<596&&volume>=4)volume-=4;if(x>=650&&x<690&&volume<=60)volume+=4;snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);}}
|
||||
if(cls==IDCMP_VANILLAKEY){if(code==27){if(editing){editing=0;query[0]=0;filter();}else done=1;}else if(code==13)play();else if(editing){i=strlen(query);if(code==8&&i){query[i-1]=0;filter();}else if(code>=32&&code<127&&i<62){query[i]=code;query[i+1]=0;filter();}}else if(code==' '){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}else if(code=='/'){editing=1;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code==0x4c)move(-1,0);if(code==0x4d)move(1,0);if(code==0x7a)move(-3,0);if(code==0x7b)move(3,0);}}
|
||||
frames++;if(playing==1&&!trackDuration&&durationQueries<3&&clockTicks-lastDurationQuery>=250&&!pending&&!qcount){command("GET DURA");durationQueries++;lastDurationQuery=clockTicks;}if(clockTicks-lastAnalysis>=2){spectrum();lastAnalysis=clockTicks;}
|
||||
if(playing==1&&clockTicks-playTick>=150){if(trackDuration&&seconds>=trackDuration){nextsong();dirty=1;}else if(hip&&hip->play){if(seenPlaying&&seconds+2<previousSeconds){nextsong();dirty=1;}else seenPlaying=1;}else if(seenPlaying){nextsong();dirty=1;}}
|
||||
previousSeconds=seconds;
|
||||
hud=seconds!=lastSecond||(hip?hip->play:0)!=lastState;repaint=dirty;full=dirty||hud;
|
||||
if(full){
|
||||
memset(frame,(UBYTE)pen[0],W*H);text(20,12,"MOD / PLAYER",1,2,30);text(470,21,"AMIGA MODULE LIBRARY",5,1,30);
|
||||
box(18,48,724,36,editing?10:4);text(30,60,"CERCA >",5,1,10);text(106,60,query,1,1,64);if(editing&&frames%20<12)rect(106+strlen(query)*8,60,6,12,2);if(!query[0]&&!editing)text(106,60,"Titolo, nome file o cartella...",3,1,64);
|
||||
box(18,104,350,408,11);sprintf(buf,"LIBRERIA %d / %d",found,total);text(30,116,buf,5,1,40);
|
||||
for(i=0;i<rows;i++){int n=i+top;if(n>=found)break;if(n==selected)rect(24,138+i*20,338,19,10);text(30,141+i*20,songs[matches[n]].title,n==selected?2:1,1,38);}
|
||||
rect(350,138,11,340,4);{int size=found>rows?rows*340/found:340;int pos;if(size<22)size=22;pos=found>rows?top*(340-size)/(found-rows):0;rect(351,138+pos,9,size,5);rect(354,143+pos,3,size>10?size-10:1,2);}
|
||||
box(382,104,360,238,11);text(396,116,"SPECTRUM / FFT",5,1,35);
|
||||
for(y=151;y<=302;y+=30)rect(396,y,330,1,4);
|
||||
|
||||
text(398,317,"44Hz 1kHz 5.5kHz",3,1,40);if(hip&&hip->play&&!available)center(396,220,330,"ANALISI NON DISPONIBILE",5);
|
||||
box(382,354,360,56,4);text(394,362,now,1,1,42);if(strlen(now)>42)text(394,376,now+42,1,1,42);sprintf(buf,"%s %02lu:%02lu %s",hip&&hip->play?"PLAY":playing==2?"PAUSE":"STOP",seconds/60,seconds%60,hip&&hip->type==33?"4CH / PAULA":"HIPPO ENGINE");text(394,393,buf,5,1,42);
|
||||
button(382,422,60,"|<",0);button(450,422,70,"PLAY",playing==1);button(528,422,80,"PAUSA",playing==2);button(616,422,74,"STOP",playing==0);
|
||||
button(382,462,60,">|",0);button(450,462,98,"RANDOM",0);button(558,462,38,"-",0);sprintf(buf,"%02d",volume*100/64);center(598,470,50,buf,2);button(650,462,40,"+",0);
|
||||
|
||||
text(20,532,"DOPPIO CLIC / INVIO: PLAY /: CERCA SPAZIO: PAUSA",5,1,80);
|
||||
memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}
|
||||
full=repaint;memcpy(frame,panel,W*H);drawAudio();
|
||||
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!=lastw||ih!=lasth){full=1;lastw=iw;lasth=ih;rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;for(y=0;y<rh;y++)ymap[y]=(ULONG)y*H/rh;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);}
|
||||
if(iw==W&&ih==H){
|
||||
if(full)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);
|
||||
else{WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+104,w->BorderLeft+741,w->BorderTop+341,frame+104*W+382,W);WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+504,w->BorderLeft+741,w->BorderTop+509,frame+504*W+382,W);if(hud)WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+354,w->BorderLeft+741,w->BorderTop+409,frame+354*W+382,W);}
|
||||
}else if(full){for(y=0;y<rh;y++){UBYTE*src=frame+ymap[y]*W;UBYTE*dst=scaled+(ULONG)(oy+y)*iw+ox;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}
|
||||
else{scaledRegion(w,iw,rw,rh,ox,oy,382,104,742,342);scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);if(hud)scaledRegion(w,iw,rw,rh,ox,oy,382,354,742,410);}
|
||||
}
|
||||
WaitTOF();
|
||||
}
|
||||
end:
|
||||
if(hip){Forbid();hip->opens--;hip=0;Permit();}if(reply&&RexxSysBase){command("STOP");while(pending||qcount){dispatch();if(pending)WaitPort(reply);replies();}}if(w)CloseWindow(w);if(reply)DeleteMsgPort(reply);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}for(i=0;i<total;i++){free(songs[i].title);free(songs[i].path);free(songs[i].key);}free(xmap);free(ymap);free(frame);free(panel);free(font);free(scaled);if(RexxSysBase)CloseLibrary((struct Library*)RexxSysBase);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
from pathlib import Path
|
||||
p=Path(__file__).parent/'player.c';s=p.read_text()
|
||||
s=s.replace('#include <dos/dostags.h>','#include <dos/dostags.h>\n#include <dos/dos.h>')
|
||||
s=s.replace('static UBYTE *frame,*scaled,*font,*panel;','static UBYTE *frame,*scaled,*font,*panel;static UWORD *xmap,*ymap;')
|
||||
mark='static struct HipPort*hip=0;'
|
||||
s=s.replace(mark,'static int playlist[MAXSONGS],plistCount=0,plistPos=0,currentSong=-1;static ULONG clockTicks=0,playTick=0,previousSeconds=0;static int seenPlaying=0,animTicks=1;\n'+mark)
|
||||
start=s.index('static void play(void)');end=s.index('static void move(',start)
|
||||
s=s[:start]+'''static void loadsong(int n){char cmd[450];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;currentSong=n;playTick=clockTicks;previousSeconds=0;seenPlaying=0;}}
|
||||
static void play(void){int i;if(!found)return;if(found==1){plistCount=total;for(i=0;i<total;i++)playlist[i]=i;plistPos=matches[selected];}else{plistCount=found;for(i=0;i<found;i++)playlist[i]=matches[i];plistPos=selected;}loadsong(matches[selected]);}
|
||||
static void nextsong(void){int i;if(!plistCount)return;plistPos=(plistPos+1)%plistCount;loadsong(playlist[plistPos]);for(i=0;i<found;i++)if(matches[i]==currentSong){selected=i;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;break;}}
|
||||
''' +s[end:]
|
||||
# Animate in clock ticks, independent of render duration.
|
||||
s=s.replace('static void drawAudio(void){int i,h,b;for(i=0;i<24;i++){','static void drawAudio(void){int i,h,b,n;for(i=0;i<24;i++){for(n=0;n<animTicks;n++){')
|
||||
s=s.replace('else peak[i]=0;\n h=bars[i];','else peak[i]=0;}\n h=bars[i];')
|
||||
# Scale only the requested dirty region, with lookup tables instead of division per pixel.
|
||||
at=s.index('int main(void)')
|
||||
helper='''static void scaledRegion(struct Window*w,int iw,int rw,int rh,int ox,int oy,int x0,int y0,int x1,int y1){int x,y,dx0=ox+x0*rw/W,dx1=ox+(x1*rw+W-1)/W,dy0=oy+y0*rh/H,dy1=oy+(y1*rh+H-1)/H;for(y=dy0;y<dy1;y++){UBYTE*src=frame+ymap[y-oy]*W;UBYTE*dst=scaled+(ULONG)y*iw;for(x=dx0;x<dx1;x++)dst[x]=src[xmap[x-ox]];}WriteChunkyPixels(w->RPort,w->BorderLeft+dx0,w->BorderTop+dy0,w->BorderLeft+dx1-1,w->BorderTop+dy1-1,scaled+(ULONG)dy0*iw+dx0,iw);}
|
||||
'''
|
||||
s=s[:at]+helper+s[at:]
|
||||
s=s.replace('dirty=1,lastState=-1;ULONG lastSecond','dirty=1,lastState=-1,full=1,lastw=0,lasth=0;struct DateStamp stamp;ULONG lastTick=0,lastAnalysis=0,lastSecond')
|
||||
s=s.replace('scaled=malloc((ULONG)sc->Width*sc->Height);if(!frame','scaled=malloc((ULONG)sc->Width*sc->Height);xmap=malloc(sc->Width*sizeof(UWORD));ymap=malloc(sc->Height*sizeof(UWORD));if(!xmap||!ymap||!frame')
|
||||
s=s.replace('while(!done){replies();dispatch();','while(!done){DateStamp(&stamp);clockTicks=(ULONG)stamp.ds_Minute*3000+stamp.ds_Tick;animTicks=lastTick?clockTicks-lastTick:1;if(animTicks<0||animTicks>10)animTicks=1;lastTick=clockTicks;replies();dispatch();')
|
||||
s=s.replace('frames++;if(frames%2==0)spectrum();\n if(dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState){','''frames++;if(clockTicks-lastAnalysis>=2){spectrum();lastAnalysis=clockTicks;}
|
||||
if(playing==1&&clockTicks-playTick>=150){if(hip&&hip->play){if(seenPlaying&&seconds+2<previousSeconds){nextsong();dirty=1;}else seenPlaying=1;}else if(seenPlaying){nextsong();dirty=1;}}
|
||||
previousSeconds=seconds;
|
||||
full=dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState;
|
||||
if(full){''')
|
||||
start=s.index(' iw=w->Width-w->BorderLeft-w->BorderRight;');end=s.index(' Delay(1);',start)
|
||||
s=s[:start]+''' 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!=lastw||ih!=lasth){full=1;lastw=iw;lasth=ih;rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;for(y=0;y<rh;y++)ymap[y]=(ULONG)y*H/rh;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);}
|
||||
if(iw==W&&ih==H){
|
||||
if(full)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);
|
||||
else{WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+104,w->BorderLeft+741,w->BorderTop+341,frame+104*W+382,W);WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+504,w->BorderLeft+741,w->BorderTop+509,frame+504*W+382,W);}
|
||||
}else if(full){scaledRegion(w,iw,rw,rh,ox,oy,0,0,W,H);}
|
||||
else{scaledRegion(w,iw,rw,rh,ox,oy,382,104,742,342);scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);}
|
||||
}
|
||||
''' +s[end:]
|
||||
s=s.replace(' Delay(1);',' WaitTOF();')
|
||||
s=s.replace('free(frame);free(panel);','free(xmap);free(ymap);free(frame);free(panel);')
|
||||
p.write_text(s)
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <exec/types.h>
|
||||
#include <exec/tasks.h>
|
||||
#include <proto/exec.h>
|
||||
#include <stdio.h>
|
||||
int main(void){FILE*f=fopen("SYS:PlayerTask.log","w");struct MsgPort*p=FindPort("AMBER.MOD.PLAYER");struct Task*t;if(p){t=p->mp_SigTask;fprintf(f,"state %d wait %08lx recv %08lx stack %lx\n",t->tc_State,t->tc_SigWait,t->tc_SigRecvd,t->tc_SPReg);}else fprintf(f,"no player\n");fclose(f);return 0;}
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <exec/types.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
int main(void){struct MsgPort*p;int i;for(i=0;i<20;i++){Forbid();p=FindPort("HIPPOPLAYER");if(p)Signal(p->mp_SigTask,1UL<<p->mp_SigBit);Permit();Delay(3);}return 0;}
|
||||
@@ -0,0 +1,7 @@
|
||||
# AmberMonitor
|
||||
|
||||
Sorgenti raccolti da work/sysmon. Binario installato conservato in dist/Monitor; risorse in assets.
|
||||
|
||||
Build: ./build.ps1 -Toolchain <VBCC/VASM/VLINK + NDK m68k-amigaos>.
|
||||
|
||||
Gli script originali sono conservati senza modificarne i percorsi: alcuni generatori leggono C:/Amiga o font Windows. Il binario presente in dist e quello effettivamente installato; il sorgente raccolto e la versione locale piu recente.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
param([string]$Toolchain = $env:AMIGA_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/Monitor monitor.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
Copy-Item -LiteralPath assets/face.bin,assets/font.bin,assets/Monitor.info -Destination $buildPath -Force
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1 @@
|
||||
static UBYTE colors[][3]={{20,19,16},{236,220,189},{255,183,66},{100,72,34},{48,35,18},{197,145,66},{113,212,135},{41,77,48},{235,102,57},{165,139,95},{94,75,45},{76,64,44},{71,57,35},{67,59,43},{69,53,31},{67,54,33},{67,51,30},{63,51,32},{53,47,32},{35,46,36},{35,45,35},{34,44,34},{44,37,25},{32,29,22},{30,27,21},{28,26,20},{26,27,21},{28,25,20},{27,25,21},{27,25,20},{27,25,19},{26,25,20},{27,24,19},{26,24,19},{26,23,18},{24,23,18},{23,22,18},{22,20,17},{21,20,17},{21,19,16},{20,19,17},{20,19,16},{20,19,15},{18,20,17},{19,19,17},{19,18,15},{18,18,15},{17,17,14},{15,18,16},{15,18,15},{15,17,16},{14,17,15},{13,17,14},{13,16,15},{13,16,14},{12,16,14},{15,15,13},{13,15,14},{13,15,13},{12,15,13},{14,14,13},{12,13,13},{10,13,12},{6,9,10}};
|
||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
from pathlib import Path
|
||||
import math
|
||||
p=Path(__file__).parent;S=2
|
||||
im=Image.new('RGB',(520*S,470*S),'#141310');d=ImageDraw.Draw(im)
|
||||
def box(b,fill,outline=None):d.rounded_rectangle(tuple(int(v*S) for v in b),radius=7*S,fill=fill,outline=outline,width=S)
|
||||
def txt(x,y,t,size,c):d.text((x*S,y*S),t,font=ImageFont.truetype('C:/Windows/Fonts/consola.ttf',size*S),fill=c)
|
||||
txt(22,12,'AMBER / SYSTEM MONITOR',18,'#edc37d');txt(23,36,'VIRTUAL MACHINE TELEMETRY',8,'#907751')
|
||||
box((14,60,204,225),'#1b1914','#66502e');box((216,60,506,225),'#0d100e','#51452d')
|
||||
txt(32,72,'PROCESSOR LOAD',10,'#bda579');txt(230,72,'CPU HISTORY / 60 s',10,'#bda579')
|
||||
for x in range(232,491,26):d.line((x*S,99*S,x*S,202*S),fill='#263126',width=S)
|
||||
for y in range(100,203,25):d.line((232*S,y*S,492*S,y*S),fill='#263126',width=S)
|
||||
for i in range(41):
|
||||
a=math.radians(225+i*270/40)
|
||||
x=109+math.sin(a)*70;y=153-math.cos(a)*70
|
||||
xx=109+math.sin(a)*79;yy=153-math.cos(a)*79
|
||||
d.line((int(x*S),int(y*S),int(xx*S),int(yy*S)),fill='#524024',width=3*S)
|
||||
txt(40,204,'0',8,'#9c8258');txt(160,204,'100',8,'#9c8258')
|
||||
box((14,237,506,325),'#1b1914','#66502e');txt(26,245,'CHIP RAM',10,'#bda579');txt(270,245,'FAST RAM',10,'#bda579')
|
||||
box((14,337,506,456),'#10120f','#51452d');txt(26,345,'EXEC TASKS',10,'#bda579')
|
||||
im=im.resize((520,470),Image.Resampling.LANCZOS)
|
||||
base=[(20,19,16),(236,220,189),(255,183,66),(100,72,34),(48,35,18),(197,145,66),(113,212,135),(41,77,48),(235,102,57)]
|
||||
pal=im.quantize(colors=55).getpalette()[:55*3];colors=base+[tuple(pal[i:i+3]) for i in range(0,len(pal),3)]
|
||||
pi=Image.new('P',(1,1));pi.putpalette(sum(map(list,colors),[])+[0]*(768-len(colors)*3))
|
||||
(p/'face.bin').write_bytes(im.quantize(palette=pi,dither=Image.Dither.NONE).tobytes())
|
||||
(p/'colors.h').write_text('static UBYTE colors[][3]={'+','.join('{%d,%d,%d}'%c for c in colors)+'};\n')
|
||||
im.save(p/'preview.png')
|
||||
@@ -0,0 +1,26 @@
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
from pathlib import Path
|
||||
import math
|
||||
p=Path(__file__).parent;S=2
|
||||
im=Image.new('RGB',(520*S,336*S),'#141310');d=ImageDraw.Draw(im)
|
||||
def box(b,fill,outline=None):d.rounded_rectangle(tuple(int(v*S) for v in b),radius=7*S,fill=fill,outline=outline,width=S)
|
||||
def txt(x,y,t,size,c):d.text((x*S,y*S),t,font=ImageFont.truetype('C:/Windows/Fonts/consola.ttf',size*S),fill=c)
|
||||
txt(22,12,'SYSTEM MONITOR',18,'#edc37d');txt(23,36,'VIRTUAL MACHINE TELEMETRY',8,'#907751')
|
||||
box((14,60,204,225),'#1b1914','#66502e');box((216,60,506,225),'#0d100e','#51452d')
|
||||
txt(230,72,'CPU HISTORY / 60 s',10,'#bda579')
|
||||
for x in range(232,491,26):d.line((x*S,99*S,x*S,202*S),fill='#263126',width=S)
|
||||
for y in range(100,203,25):d.line((232*S,y*S,492*S,y*S),fill='#263126',width=S)
|
||||
points=[]
|
||||
for i in range(271):
|
||||
a=math.radians(225+i)
|
||||
points.append((int((109+math.sin(a)*70)*S),int((148-math.cos(a)*70)*S)))
|
||||
d.line(points,fill='#43331e',width=9*S)
|
||||
txt(40,204,'0',8,'#9c8258');txt(160,204,'100',8,'#9c8258')
|
||||
box((14,237,506,325),'#1b1914','#66502e');txt(26,245,'CHIP RAM',10,'#bda579');txt(270,245,'FAST RAM',10,'#bda579')
|
||||
im=im.resize((520,336),Image.Resampling.LANCZOS)
|
||||
base=[(20,19,16),(236,220,189),(255,183,66),(100,72,34),(48,35,18),(197,145,66),(113,212,135),(41,77,48),(235,102,57)]
|
||||
pal=im.quantize(colors=55).getpalette()[:55*3];colors=base+[tuple(pal[i:i+3]) for i in range(0,len(pal),3)]
|
||||
pi=Image.new('P',(1,1));pi.putpalette(sum(map(list,colors),[])+[0]*(768-len(colors)*3))
|
||||
(p/'face.bin').write_bytes(im.quantize(palette=pi,dither=Image.Dither.NONE).tobytes())
|
||||
(p/'colors.h').write_text('static UBYTE colors[][3]={'+','.join('{%d,%d,%d}'%c for c in colors)+'};\n')
|
||||
im.save(p/'preview.png')
|
||||
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
import struct
|
||||
p=Path('C:/Amiga/HD0/Utilities/AmberMonitor')
|
||||
h=bytearray(Path('C:/Amiga/HD0/System/Shell.info').read_bytes()[:78])
|
||||
def u16(n):return struct.pack('>H',n)
|
||||
def u32(n):return struct.pack('>I',n&0xffffffff)
|
||||
h[12:16]=u16(48)+u16(40);h[16:18]=u16(6);h[48]=3
|
||||
for off in (22,26):h[off:off+4]=u32(1)
|
||||
for off in (44,50,54,66,70):h[off:off+4]=u32(0)
|
||||
h[58:66]=u32(-1)+u32(-1);h[74:78]=u32(65536)
|
||||
data=bytearray(h)
|
||||
for selected in (False,True):
|
||||
im=Image.new('P',(48,40),0);d=ImageDraw.Draw(im)
|
||||
d.rounded_rectangle((2,1,45,35),radius=3,fill=2,outline=1 if selected else 3,width=2)
|
||||
for x,height in [(8,6),(14,12),(20,9),(26,19),(32,14),(38,23)]:d.rectangle((x,30-height,x+3,30),fill=3 if height<20 else 1)
|
||||
d.line((6,32,41,32),fill=1);d.rectangle((18,36,30,38),fill=3)
|
||||
data+=u16(0)+u16(0)+u16(48)+u16(40)+u16(2)+u32(1)+bytes([3,0])+u32(0)
|
||||
for plane in range(2):
|
||||
for y in range(40):
|
||||
for x in range(0,48,8):data.append(sum((128>>i) if im.getpixel((x+i,y))&(1<<plane) else 0 for i in range(8)))
|
||||
(p/'Monitor.info').write_bytes(data)
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <exec/types.h>
|
||||
#include <dos/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
int main(void){struct DateStamp a,b;long start,now;SetTaskPri(FindTask(0),-5);DateStamp(&a);start=a.ds_Minute*3000+a.ds_Tick;do{DateStamp(&b);now=b.ds_Minute*3000+b.ds_Tick;}while(now-start<350);return 0;}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include <exec/types.h>
|
||||
#include <exec/execbase.h>
|
||||
#include <exec/memory.h>
|
||||
#include <exec/interrupts.h>
|
||||
#include <hardware/intbits.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "colors.h"
|
||||
#include "trig.h"
|
||||
#define W 520
|
||||
#define H 470
|
||||
struct IntuitionBase *IntuitionBase;struct GfxBase *GfxBase;
|
||||
extern struct ExecBase *SysBase;
|
||||
static UBYTE *face,*frame,*out,*font;static LONG pens[64];
|
||||
static volatile ULONG spin;
|
||||
static int offset=0;
|
||||
struct Sampling {struct ExecBase *base;struct Task *probe;volatile ULONG total,idle;};
|
||||
static struct Sampling sample;
|
||||
static void idleprobe(void){for(;;)spin++;}
|
||||
static ULONG __saveds sampler(__reg("a1") struct Sampling *s){s->total++;if(s->base->ThisTask==s->probe)s->idle++;return 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 line(int x0,int y0,int x1,int y1,int c){int dx=abs(x1-x0),sx=x0<x1?1:-1,dy=-abs(y1-y0),sy=y0<y1?1:-1,e=dx+dy,e2;for(;;){pixel(x0,y0,c);if(x0==x1&&y0==y1)break;e2=e*2;if(e2>=dy){e+=dy;x0+=sx;}if(e2<=dx){e+=dx;y0+=sy;}}}
|
||||
static void text(int x,int y,char*s,int c,int scale){int a,b,k,z,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])for(z=0;z<scale;z++)rect(x+(k*8+a)*scale,y+b*scale+z,scale,1,c);}}
|
||||
static int load(char*name,UBYTE*p,long n){FILE*f=fopen(name,"rb");int ok;if(!f)return 0;ok=fread(p,1,n,f)==n;fclose(f);return ok;}
|
||||
struct Row {char name[37];int state,pri;};static struct Row rows[6];
|
||||
static int tasks(struct Task*probe){struct Node*n;int count=0,r=0,k;struct Task*t;Forbid();
|
||||
for(k=0;k<3;k++){
|
||||
if(k==0)n=(struct Node*)SysBase->ThisTask;else n=(k==1?SysBase->TaskReady:SysBase->TaskWait).lh_Head;
|
||||
while(n&&(k==0||n->ln_Succ)){
|
||||
t=(struct Task*)n;if(t!=probe){count++;if(count>offset&&r<6){strncpy(rows[r].name,n->ln_Name?n->ln_Name:"(unnamed)",36);rows[r].name[36]=0;rows[r].state=t->tc_State;rows[r].pri=n->ln_Pri;r++;}}
|
||||
if(k==0)break;n=n->ln_Succ;
|
||||
}
|
||||
}Permit();for(;r<6;r++)rows[r].name[0]=0;if(offset>=count)offset=0;return count;}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct Task*probe=0;UBYTE*stack=0;struct Interrupt irq;int irqon=0,taskon=0,got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,loadpct=0,history[60],histn=0,nt=0,step=0;ULONG total,idle,cf,ct,ff,ft;char buf[100],cpu[24];int angle,a,xx,yy;ULONG cls;UWORD code;FILE*f;
|
||||
SysBase=*(struct ExecBase**)4;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);if(!IntuitionBase||!GfxBase)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;face=malloc(W*H);frame=malloc(W*H);font=malloc(768*12);out=malloc((ULONG)sc->Width*sc->Height);if(!face||!frame||!font||!out)goto end;
|
||||
if(!load("PROGDIR:face.bin",face,W*H)||!load("PROGDIR:font.bin",font,768*12))goto end;
|
||||
for(i=0;i<64;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++;}for(i=0;i<W*H;i++)face[i]=(UBYTE)pens[face[i]];
|
||||
strcpy(cpu,(SysBase->AttnFlags&AFF_68060)?"MOTOROLA 68060":(SysBase->AttnFlags&AFF_68040)?"MOTOROLA 68040":(SysBase->AttnFlags&AFF_68030)?"MOTOROLA 68030":(SysBase->AttnFlags&AFF_68020)?"MOTOROLA 68020":"MOTOROLA 68000");
|
||||
probe=AllocMem(sizeof(struct Task),MEMF_PUBLIC|MEMF_CLEAR);stack=AllocMem(8192,MEMF_PUBLIC|MEMF_CLEAR);if(!probe||!stack)goto end;
|
||||
probe->tc_Node.ln_Type=NT_TASK;probe->tc_Node.ln_Pri=-127;probe->tc_Node.ln_Name="AmberMonitor.idle";
|
||||
probe->tc_SPLower=stack;probe->tc_SPUpper=stack+8192;probe->tc_SPReg=stack+8192;
|
||||
probe->tc_MemEntry.lh_Head=(struct Node*)&probe->tc_MemEntry.lh_Tail;probe->tc_MemEntry.lh_TailPred=(struct Node*)&probe->tc_MemEntry.lh_Head;
|
||||
sample.base=SysBase;sample.probe=probe;
|
||||
memset(&irq,0,sizeof(irq));irq.is_Node.ln_Type=NT_INTERRUPT;irq.is_Node.ln_Name="AmberMonitor.sample";irq.is_Node.ln_Pri=0;irq.is_Data=&sample;irq.is_Code=(VOID(*)())sampler;
|
||||
AddIntServer(INTB_VERTB,&irq);irqon=1;AddTask(probe,(APTR)idleprobe,0);taskon=1;
|
||||
memset(history,0,sizeof(history));
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,352,WA_Top,180,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"Amber Monitor | CPU virtuale",WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,360,WA_MinHeight,330,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,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==0x4d)offset+=6;if(cls==IDCMP_RAWKEY&&code==0x4c){offset-=6;if(offset<0)offset=0;}if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}}
|
||||
Disable();total=sample.total;idle=sample.idle;if(total>=50){sample.total=sample.idle=0;}Enable();
|
||||
if(total>=50){loadpct=(int)((total-idle)*100/total);if(loadpct>100)loadpct=100;memmove(history,history+1,59*sizeof(int));history[59]=loadpct;if(histn<60)histn++;}
|
||||
cf=AvailMem(MEMF_CHIP);ct=AvailMem(MEMF_CHIP|MEMF_TOTAL);ff=AvailMem(MEMF_FAST);ft=AvailMem(MEMF_FAST|MEMF_TOTAL);nt=tasks(probe);
|
||||
memcpy(frame,face,W*H);text(26,51,cpu,1,1);text(272,51,"CLOCK: DINAMICO / MAX + JIT",5,1);
|
||||
for(i=0;i<40;i++)if(i*100/40<loadpct){angle=2250+i*2700/40;a=(angle%3600)*2;xx=109+trig[a]*70/10000;yy=153+trig[a+1]*70/10000;for(x=-1;x<=1;x++)line(xx+x,yy,109+trig[a]*79/10000+x,153+trig[a+1]*79/10000,loadpct>85?8:2);}
|
||||
sprintf(buf,"%3d%%",loadpct);text(76,141,buf,2,2);text(54,181,"CPU / STIMA",5,1);
|
||||
for(i=1;i<60;i++)if(i>=60-histn){int x0=232+(i-1)*260/59,x1=232+i*260/59;line(x0,201-history[i-1],x1,201-history[i],6);line(x0,202-history[i-1],x1,202-history[i],6);}
|
||||
text(232,209,"CAMPIONAMENTO EXEC / 50 Hz",5,1);
|
||||
rect(26,268,218,10,4);rect(270,268,218,10,7);if(ct)rect(26,268,(ct-cf)/(ct/218+1),10,2);if(ft)rect(270,268,(ft-ff)/(ft/218+1),10,6);
|
||||
sprintf(buf,"%lu / %lu KB",(ct-cf)/1024,ct/1024);text(26,284,buf,1,1);sprintf(buf,"%lu / %lu KB",(ft-ff)/1024,ft/1024);text(270,284,buf,1,1);
|
||||
sprintf(buf,"LIBERA %lu KB",cf/1024);text(26,302,buf,5,1);sprintf(buf,"LIBERA %lu KB",ff/1024);text(270,302,buf,5,1);
|
||||
sprintf(buf,"%d TASK %d-%d [UP/DN]",nt,offset+1,offset+6<nt?offset+6:nt);text(176,345,buf,5,1);
|
||||
for(i=0;i<6;i++)if(rows[i].name[0]){text(26,363+i*14,rows[i].name,1,1);sprintf(buf,"%s %4d",rows[i].state==TS_RUN?"RUN ":rows[i].state==TS_READY?"READY":"WAIT ",rows[i].pri);text(382,363+i*14,buf,5,1);}
|
||||
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){rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;memset(out,(UBYTE)pens[0],(ULONG)iw*ih);for(y=0;y<rh;y++){int sy=(ULONG)y*H/rh;for(x=0;x<rw;x++)out[(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,out,iw);}
|
||||
Delay(11+(step++%3));
|
||||
}
|
||||
end:
|
||||
if(irqon)RemIntServer(INTB_VERTB,&irq);if(taskon)RemTask(probe);if(stack)FreeMem(stack,8192);if(probe)FreeMem(probe,sizeof(struct Task));
|
||||
if(w)CloseWindow(w);if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pens[i]);UnlockPubScreen(0,sc);}free(face);free(frame);free(font);free(out);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#include <exec/types.h>
|
||||
#include <exec/execbase.h>
|
||||
#include <exec/memory.h>
|
||||
#include <exec/interrupts.h>
|
||||
#include <hardware/intbits.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "colors.h"
|
||||
#include "trig.h"
|
||||
#define W 520
|
||||
#define H 336
|
||||
struct IntuitionBase *IntuitionBase;struct GfxBase *GfxBase;
|
||||
extern struct ExecBase *SysBase;
|
||||
static UBYTE *face,*frame,*out,*font;static LONG pens[64];
|
||||
static volatile ULONG spin;
|
||||
static int offset=0;
|
||||
struct Sampling {struct ExecBase *base;struct Task *probe;volatile ULONG total,idle;};
|
||||
static struct Sampling sample;
|
||||
static void idleprobe(void){for(;;)spin++;}
|
||||
static ULONG __saveds sampler(__reg("a1") struct Sampling *s){struct Task*t=s->base->ThisTask;s->total++;if(!t||t->tc_State!=TS_RUN)s->idle++;return 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 line(int x0,int y0,int x1,int y1,int c){int dx=abs(x1-x0),sx=x0<x1?1:-1,dy=-abs(y1-y0),sy=y0<y1?1:-1,e=dx+dy,e2;for(;;){pixel(x0,y0,c);if(x0==x1&&y0==y1)break;e2=e*2;if(e2>=dy){e+=dy;x0+=sx;}if(e2<=dx){e+=dx;y0+=sy;}}}
|
||||
static void text(int x,int y,char*s,int c,int scale){int a,b,k,z,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])for(z=0;z<scale;z++)rect(x+(k*8+a)*scale,y+b*scale+z,scale,1,c);}}
|
||||
static int load(char*name,UBYTE*p,long n){FILE*f=fopen(name,"rb");int ok;if(!f)return 0;ok=fread(p,1,n,f)==n;fclose(f);return ok;}
|
||||
struct Row {char name[37];int state,pri;};static struct Row rows[6];
|
||||
static int tasks(struct Task*probe){struct Node*n;int count=0,r=0,k;struct Task*t;Forbid();
|
||||
for(k=0;k<3;k++){
|
||||
if(k==0)n=(struct Node*)SysBase->ThisTask;else n=(k==1?SysBase->TaskReady:SysBase->TaskWait).lh_Head;
|
||||
while(n&&(k==0||n->ln_Succ)){
|
||||
t=(struct Task*)n;if(t!=probe){count++;if(count>offset&&r<6){strncpy(rows[r].name,n->ln_Name?n->ln_Name:"(unnamed)",36);rows[r].name[36]=0;rows[r].state=t->tc_State;rows[r].pri=n->ln_Pri;r++;}}
|
||||
if(k==0)break;n=n->ln_Succ;
|
||||
}
|
||||
}Permit();for(;r<6;r++)rows[r].name[0]=0;if(offset>=count)offset=0;return count;}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct Task*probe=0;UBYTE*stack=0;struct Interrupt irq;int irqon=0,taskon=0,got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,loadpct=0,history[60],histn=0,nt=0,step=0,display=0,diff=0;ULONG total,idle,cf,ct,ff,ft;char buf[100],cpu[24];int angle,a,xx,yy;ULONG cls;UWORD code;FILE*f;
|
||||
SysBase=*(struct ExecBase**)4;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);if(!IntuitionBase||!GfxBase)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;face=malloc(W*H);frame=malloc(W*H);font=malloc(768*12);out=malloc((ULONG)sc->Width*sc->Height);if(!face||!frame||!font||!out)goto end;
|
||||
if(!load("PROGDIR:face.bin",face,W*H)||!load("PROGDIR:font.bin",font,768*12))goto end;
|
||||
for(i=0;i<64;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++;}for(i=0;i<W*H;i++)face[i]=(UBYTE)pens[face[i]];
|
||||
strcpy(cpu,(SysBase->AttnFlags&AFF_68060)?"MOTOROLA 68060":(SysBase->AttnFlags&AFF_68040)?"MOTOROLA 68040":(SysBase->AttnFlags&AFF_68030)?"MOTOROLA 68030":(SysBase->AttnFlags&AFF_68020)?"MOTOROLA 68020":"MOTOROLA 68000");
|
||||
sample.base=SysBase;sample.probe=probe;
|
||||
memset(&irq,0,sizeof(irq));irq.is_Node.ln_Type=NT_INTERRUPT;irq.is_Node.ln_Name="AmberMonitor.sample";irq.is_Node.ln_Pri=0;irq.is_Data=&sample;irq.is_Code=(VOID(*)())sampler;
|
||||
AddIntServer(INTB_VERTB,&irq);irqon=1;
|
||||
memset(history,0,sizeof(history));
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,352,WA_Top,180,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"System Monitor",WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,360,WA_MinHeight,240,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,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==0x4d)offset+=6;if(cls==IDCMP_RAWKEY&&code==0x4c){offset-=6;if(offset<0)offset=0;}if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}}
|
||||
Disable();total=sample.total;idle=sample.idle;if(total>=50){sample.total=sample.idle=0;}Enable();
|
||||
if(total>=50){loadpct=(int)((total-idle)*100/total);if(loadpct>100)loadpct=100;memmove(history,history+1,59*sizeof(int));history[59]=loadpct;if(histn<60)histn++;}
|
||||
cf=AvailMem(MEMF_CHIP);ct=AvailMem(MEMF_CHIP|MEMF_TOTAL);ff=AvailMem(MEMF_FAST);ft=AvailMem(MEMF_FAST|MEMF_TOTAL);
|
||||
memcpy(frame,face,W*H);text(26,47,cpu,1,1);text(272,47,"CLOCK: DINAMICO / MAX + JIT",5,1);
|
||||
diff=loadpct*16-display;if(diff){int delta=diff/8;if(!delta)delta=diff>0?1:-1;display+=delta;}
|
||||
for(angle=2250;angle<=2250+(LONG)display*2700/1600;angle+=3){a=(angle%3600)*2;for(i=66;i<=74;i++){xx=109+trig[a]*i/10000;yy=148+trig[a+1]*i/10000;pixel(xx,yy,display>1360?8:2);}}
|
||||
sprintf(buf,"%d%%",(display+8)/16);text(109-strlen(buf)*8,132,buf,2,2);text(97,166,"CPU",1,1);
|
||||
for(i=1;i<60;i++)if(i>=60-histn){int x0=232+(i-1)*260/59,x1=232+i*260/59;line(x0,201-history[i-1],x1,201-history[i],6);line(x0,202-history[i-1],x1,202-history[i],6);}
|
||||
|
||||
rect(26,268,218,10,4);rect(270,268,218,10,7);if(ct)rect(26,268,(ct-cf)/(ct/218+1),10,2);if(ft)rect(270,268,(ft-ff)/(ft/218+1),10,6);
|
||||
sprintf(buf,"%lu / %lu KB",(ct-cf)/1024,ct/1024);text(26,284,buf,1,1);sprintf(buf,"%lu / %lu KB",(ft-ff)/1024,ft/1024);text(270,284,buf,1,1);
|
||||
sprintf(buf,"LIBERA %lu KB",cf/1024);text(26,302,buf,5,1);sprintf(buf,"LIBERA %lu KB",ff/1024);text(270,302,buf,5,1);
|
||||
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){rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;memset(out,(UBYTE)pens[0],(ULONG)iw*ih);for(y=0;y<rh;y++){int sy=(ULONG)y*H/rh;for(x=0;x<rw;x++)out[(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,out,iw);}
|
||||
Delay(2+(step++%2));
|
||||
}
|
||||
end:
|
||||
if(irqon)RemIntServer(INTB_VERTB,&irq);if(taskon)RemTask(probe);if(stack)FreeMem(stack,8192);if(probe)FreeMem(probe,sizeof(struct Task));
|
||||
if(w)CloseWindow(w);if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pens[i]);UnlockPubScreen(0,sc);}free(face);free(frame);free(font);free(out);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
static short trig[7200]={0,-10000,17,-10000,35,-10000,52,-10000,70,-10000,87,-10000,105,-9999,122,-9999,140,-9999,157,-9999,175,-9998,192,-9998,209,-9998,227,-9997,244,-9997,262,-9997,279,-9996,297,-9996,314,-9995,332,-9995,349,-9994,366,-9993,384,-9993,401,-9992,419,-9991,436,-9990,454,-9990,471,-9989,488,-9988,506,-9987,523,-9986,541,-9985,558,-9984,576,-9983,593,-9982,610,-9981,628,-9980,645,-9979,663,-9978,680,-9977,698,-9976,715,-9974,732,-9973,750,-9972,767,-9971,785,-9969,802,-9968,819,-9966,837,-9965,854,-9963,872,-9962,889,-9960,906,-9959,924,-9957,941,-9956,958,-9954,976,-9952,993,-9951,1011,-9949,1028,-9947,1045,-9945,1063,-9943,1080,-9942,1097,-9940,1115,-9938,1132,-9936,1149,-9934,1167,-9932,1184,-9930,1201,-9928,1219,-9925,1236,-9923,1253,-9921,1271,-9919,1288,-9917,1305,-9914,1323,-9912,1340,-9910,1357,-9907,1374,-9905,1392,-9903,1409,-9900,1426,-9898,1444,-9895,1461,-9893,1478,-9890,1495,-9888,1513,-9885,1530,-9882,1547,-9880,1564,-9877,1582,-9874,1599,-9871,1616,-9869,1633,-9866,1650,-9863,1668,-9860,1685,-9857,1702,-9854,1719,-9851,1736,-9848,1754,-9845,1771,-9842,1788,-9839,1805,-9836,1822,-9833,1840,-9829,1857,-9826,1874,-9823,1891,-9820,1908,-9816,1925,-9813,1942,-9810,1959,-9806,1977,-9803,1994,-9799,2011,-9796,2028,-9792,2045,-9789,2062,-9785,2079,-9781,2096,-9778,2113,-9774,2130,-9770,2147,-9767,2164,-9763,2181,-9759,2198,-9755,2215,-9751,2233,-9748,2250,-9744,2267,-9740,2284,-9736,2300,-9732,2317,-9728,2334,-9724,2351,-9720,2368,-9715,2385,-9711,2402,-9707,2419,-9703,2436,-9699,2453,-9694,2470,-9690,2487,-9686,2504,-9681,2521,-9677,2538,-9673,2554,-9668,2571,-9664,2588,-9659,2605,-9655,2622,-9650,2639,-9646,2656,-9641,2672,-9636,2689,-9632,2706,-9627,2723,-9622,2740,-9617,2756,-9613,2773,-9608,2790,-9603,2807,-9598,2823,-9593,2840,-9588,2857,-9583,2874,-9578,2890,-9573,2907,-9568,2924,-9563,2940,-9558,2957,-9553,2974,-9548,2990,-9542,3007,-9537,3024,-9532,3040,-9527,3057,-9521,3074,-9516,3090,-9511,3107,-9505,3123,-9500,3140,-9494,3156,-9489,3173,-9483,3190,-9478,3206,-9472,3223,-9466,3239,-9461,3256,-9455,3272,-9449,3289,-9444,3305,-9438,3322,-9432,3338,-9426,3355,-9421,3371,-9415,3387,-9409,3404,-9403,3420,-9397,3437,-9391,3453,-9385,3469,-9379,3486,-9373,3502,-9367,3518,-9361,3535,-9354,3551,-9348,3567,-9342,3584,-9336,3600,-9330,3616,-9323,3633,-9317,3649,-9311,3665,-9304,3681,-9298,3697,-9291,3714,-9285,3730,-9278,3746,-9272,3762,-9265,3778,-9259,3795,-9252,3811,-9245,3827,-9239,3843,-9232,3859,-9225,3875,-9219,3891,-9212,3907,-9205,3923,-9198,3939,-9191,3955,-9184,3971,-9178,3987,-9171,4003,-9164,4019,-9157,4035,-9150,4051,-9143,4067,-9135,4083,-9128,4099,-9121,4115,-9114,4131,-9107,4147,-9100,4163,-9092,4179,-9085,4195,-9078,4210,-9070,4226,-9063,4242,-9056,4258,-9048,4274,-9041,4289,-9033,4305,-9026,4321,-9018,4337,-9011,4352,-9003,4368,-8996,4384,-8988,4399,-8980,4415,-8973,4431,-8965,4446,-8957,4462,-8949,4478,-8942,4493,-8934,4509,-8926,4524,-8918,4540,-8910,4555,-8902,4571,-8894,4586,-8886,4602,-8878,4617,-8870,4633,-8862,4648,-8854,4664,-8846,4679,-8838,4695,-8829,4710,-8821,4726,-8813,4741,-8805,4756,-8796,4772,-8788,4787,-8780,4802,-8771,4818,-8763,4833,-8755,4848,-8746,4863,-8738,4879,-8729,4894,-8721,4909,-8712,4924,-8704,4939,-8695,4955,-8686,4970,-8678,4985,-8669,5000,-8660,5015,-8652,5030,-8643,5045,-8634,5060,-8625,5075,-8616,5090,-8607,5105,-8599,5120,-8590,5135,-8581,5150,-8572,5165,-8563,5180,-8554,5195,-8545,5210,-8536,5225,-8526,5240,-8517,5255,-8508,5270,-8499,5284,-8490,5299,-8480,5314,-8471,5329,-8462,5344,-8453,5358,-8443,5373,-8434,5388,-8425,5402,-8415,5417,-8406,5432,-8396,5446,-8387,5461,-8377,5476,-8368,5490,-8358,5505,-8348,5519,-8339,5534,-8329,5548,-8320,5563,-8310,5577,-8300,5592,-8290,5606,-8281,5621,-8271,5635,-8261,5650,-8251,5664,-8241,5678,-8231,5693,-8221,5707,-8211,5721,-8202,5736,-8192,5750,-8181,5764,-8171,5779,-8161,5793,-8151,5807,-8141,5821,-8131,5835,-8121,5850,-8111,5864,-8100,5878,-8090,5892,-8080,5906,-8070,5920,-8059,5934,-8049,5948,-8039,5962,-8028,5976,-8018,5990,-8007,6004,-7997,6018,-7986,6032,-7976,6046,-7965,6060,-7955,6074,-7944,6088,-7934,6101,-7923,6115,-7912,6129,-7902,6143,-7891,6157,-7880,6170,-7869,6184,-7859,6198,-7848,6211,-7837,6225,-7826,6239,-7815,6252,-7804,6266,-7793,6280,-7782,6293,-7771,6307,-7760,6320,-7749,6334,-7738,6347,-7727,6361,-7716,6374,-7705,6388,-7694,6401,-7683,6414,-7672,6428,-7660,6441,-7649,6455,-7638,6468,-7627,6481,-7615,6494,-7604,6508,-7593,6521,-7581,6534,-7570,6547,-7559,6561,-7547,6574,-7536,6587,-7524,6600,-7513,6613,-7501,6626,-7490,6639,-7478,6652,-7466,6665,-7455,6678,-7443,6691,-7431,6704,-7420,6717,-7408,6730,-7396,6743,-7385,6756,-7373,6769,-7361,6782,-7349,6794,-7337,6807,-7325,6820,-7314,6833,-7302,6845,-7290,6858,-7278,6871,-7266,6884,-7254,6896,-7242,6909,-7230,6921,-7218,6934,-7206,6947,-7193,6959,-7181,6972,-7169,6984,-7157,6997,-7145,7009,-7133,7022,-7120,7034,-7108,7046,-7096,7059,-7083,7071,-7071,7083,-7059,7096,-7046,7108,-7034,7120,-7022,7133,-7009,7145,-6997,7157,-Line truncated
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,7 @@
|
||||
/build/
|
||||
/toolchain/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.o
|
||||
*.asm
|
||||
/assets/preview.png
|
||||
@@ -0,0 +1,11 @@
|
||||
# Rendering optimization (2026-11-06)
|
||||
|
||||
Preserves the existing palette, dimensions, animation rates and visual design.
|
||||
|
||||
- Boing/Matrix: fuse resized pixel sampling and RGB15 conversion into one pass; duplicate scanlines with memcpy.
|
||||
- Boing: ellipse shadow spans replace repeated per-pixel multiplications with identical coverage.
|
||||
- Boing 3D: cache horizontal sphere sampling coordinates per apparent size.
|
||||
- Matrix: cache sparse glyph pixels, preserving glow and core drawing order.
|
||||
- Chrono: cache horizontal sampling coordinates and date conversion; omit invisible analog/digital calculations.
|
||||
|
||||
Original source and executable retained in versions/before-optimization/. Build with build.ps1. No frame-rate reduction.
|
||||
@@ -0,0 +1,60 @@
|
||||
# Boing Ball per Amiga
|
||||
|
||||
Animazione nativa in finestra, ridimensionabile, con palla a scacchi e ombra.
|
||||
Il movimento usa timer.device; la rotazione usa 64 sprite prerenderizzati.
|
||||
|
||||
## File
|
||||
|
||||
- `boing.c`: programma C, movimento, input, ridimensionamento e disegno.
|
||||
- `generate.py`: genera griglia, 64 sprite e palette. Richiede Python e Pillow.
|
||||
- `palette.h`: palette generata.
|
||||
- `assets/background.bin`, `assets/sprites.bin`: asset pronti per l'esecuzione.
|
||||
- `assets/Boing.info`: icona Workbench.
|
||||
- `vbcc-config.in`, `build.ps1`: configurazione e compilazione Windows.
|
||||
|
||||
## Compilazione
|
||||
|
||||
Toolchain VBCC per Windows con VASM, VLINK, target m68k-amigaos e NDK.
|
||||
La toolchain usata e' disponibile da https://github.com/kusma/amiga-dev
|
||||
La toolchain resta esterna al repository. Non servono Python/Pillow se si
|
||||
usano gli asset gia' inclusi.
|
||||
|
||||
```powershell
|
||||
.\build.ps1 -Toolchain "C:\percorso\amiga-dev"
|
||||
```
|
||||
|
||||
Oppure impostare `BOING_TOOLCHAIN` e avviare `build.ps1`.
|
||||
Per rigenerare gli asset: `python generate.py` (dipendenza: Pillow).
|
||||
La cartella `build` contiene Boing, Boing.info, background.bin e sprites.bin.
|
||||
Copiarli insieme sull'Amiga, per esempio in `SYS:Utilities/Boing`.
|
||||
|
||||
## Requisiti e comandi
|
||||
|
||||
AmigaOS 3.x: intuition.library v39, graphics.library v40, layers.library v39.
|
||||
Schermo pubblico a palette oppure RTG; per RTG oltre 8 bit serve
|
||||
Picasso96API.library v2. Compilato per 68000; testato sull'emulatore 68040 RTG.
|
||||
Spazio: pausa/riprendi. Esc o gadget chiusura: esci.
|
||||
Al rilascio del gadget di ridimensionamento la finestra si aggancia al rapporto
|
||||
4:3 originale (area interna, esclusi i bordi), senza margini laterali.
|
||||
Il limite minimo e i bordi dello schermo vengono rispettati scalando i due assi insieme.
|
||||
|
||||
## Correzione del 6 novembre 2026
|
||||
|
||||
Il fotogramma viene composto in RAM e convertito in un bitmap fuori schermo.
|
||||
Su Picasso96 i colori vengono convertiti esplicitamente in RGB 15 bit:
|
||||
la conversione di indici su un RastPort fuori schermo non usa necessariamente
|
||||
la palette della finestra. Dopo WaitBlit/WaitTOF il bitmap completo viene
|
||||
copiato nella finestra con un solo BltBitMapRastPort. Il layer resta bloccato
|
||||
per la presentazione e un fotogramma con dimensioni superate viene saltato.
|
||||
Questo riduce l'esposizione di righe parziali, senza promettere di eliminare
|
||||
il tearing eventualmente introdotto dal compositor o dal display Windows.
|
||||
|
||||
Riferimento ABI Picasso96: https://github.com/tonioni/WinUAE/blob/master/include/picasso96.h
|
||||
Formati RGB: https://github.com/tonioni/WinUAE/blob/master/include/rtgmodes.h
|
||||
|
||||
## Git
|
||||
|
||||
Questa cartella contiene solo il progetto: nessuna ROM, disco di sistema,
|
||||
credenziale o toolchain. `.gitignore` esclude build e file intermedi.
|
||||
Non e' stato inizializzato un repository ne' aggiunta una licenza:
|
||||
puoi scegliere repository, licenza e primo commit.
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,224 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <graphics/view.h>
|
||||
#include <devices/timer.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/layers.h>
|
||||
#include <proto/timer.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "palette.h"
|
||||
#define W 400
|
||||
#define H 300
|
||||
#define D 114
|
||||
#define N 64
|
||||
struct IntuitionBase *IntuitionBase;
|
||||
struct GfxBase *GfxBase;
|
||||
struct Library *TimerBase;
|
||||
struct Library *LayersBase;
|
||||
static struct Library *P96Base;
|
||||
/* Picasso96 public ABI: RenderInfo is 12 bytes; RGBFB_R5G5B5 = 11.
|
||||
Only this function is needed, so no complete P96 SDK is required. */
|
||||
struct BoingRenderInfo {APTR Memory;WORD BytesPerRow,pad;ULONG RGBFormat;};
|
||||
void __boingP96Write(__reg("a6") void *,__reg("a0") struct BoingRenderInfo *,
|
||||
__reg("d0") UWORD,__reg("d1") UWORD,__reg("a1") struct RastPort *,
|
||||
__reg("d2") UWORD,__reg("d3") UWORD,__reg("d4") UWORD,__reg("d5") UWORD)="\tjsr\t-102(a6)";
|
||||
static UWORD *rgbFrame,rgbPens[256];
|
||||
static void uploadRGB(struct RastPort *rp,int width,int height){
|
||||
struct BoingRenderInfo ri;
|
||||
ri.Memory=rgbFrame;ri.BytesPerRow=width*2;ri.pad=0;ri.RGBFormat=11;
|
||||
__boingP96Write(P96Base,&ri,0,0,rp,0,0,width,height);
|
||||
}
|
||||
static void writeBack(struct RastPort *rp,UBYTE *pixels,int width,int height){
|
||||
if(rgbFrame){
|
||||
ULONG n=(ULONG)width*height,k;struct BoingRenderInfo ri;
|
||||
for(k=0;k<n;k++)rgbFrame[k]=rgbPens[pixels[k]];
|
||||
uploadRGB(rp,width,height);
|
||||
}else WriteChunkyPixels(rp,0,0,width-1,height-1,pixels,width);
|
||||
}
|
||||
static UBYTE *background,*sprites,*frame,*scaled;
|
||||
static UWORD *xmap;
|
||||
static LONG pens[21];
|
||||
static int load(char *path,UBYTE *p,long size) {
|
||||
FILE *f=fopen(path,"rb"); int ok; if(!f)return 0;
|
||||
ok=fread(p,1,size,f)==size; fclose(f);return ok;
|
||||
}
|
||||
/* Intuition completes the native resize first; snap its inner area to 4:3.
|
||||
Use the axis moved most, then clamp both axes together in 4x3 pixel steps. */
|
||||
static void keepAspect(struct Window *w,struct Screen *sc,int *oldw,int *oldh){
|
||||
int bw=w->BorderLeft+w->BorderRight,bh=w->BorderTop+w->BorderBottom;
|
||||
int iw=w->Width-bw,ih=w->Height-bh,k,kmin,kmax,t;
|
||||
if(iw*3==ih*4){*oldw=iw;*oldh=ih;return;}
|
||||
if(abs(iw-*oldw)*3>=abs(ih-*oldh)*4)k=(iw+2)/4;
|
||||
else k=(ih+1)/3;
|
||||
kmin=(w->MinWidth-bw+3)/4;
|
||||
t=(w->MinHeight-bh+2)/3;if(t>kmin)kmin=t;
|
||||
if(kmin<1)kmin=1;
|
||||
kmax=(sc->Width-w->LeftEdge-bw)/4;
|
||||
t=(sc->Height-w->TopEdge-bh)/3;if(t<kmax)kmax=t;
|
||||
if(kmax<kmin)kmax=kmin;
|
||||
if(k<kmin)k=kmin;if(k>kmax)k=kmax;
|
||||
*oldw=k*4;*oldh=k*3;
|
||||
ChangeWindowBox(w,w->LeftEdge,w->TopEdge,*oldw+bw,*oldh+bh);
|
||||
}
|
||||
int main(void) {
|
||||
struct BitMap *backBitmap=0;struct RastPort backRPort;
|
||||
int backw=0,backh=0,aspectw=W,aspecth=H;
|
||||
struct Screen *screen=0; struct Window *win=0; struct IntuiMessage *msg;
|
||||
int i,j,x,y,bx=45,by=20,vx=3,vy=0,phase=0,done=0,paused=0,got=0;
|
||||
ULONG cls; UWORD code; UBYTE *sp; int sx,sy,dx,dy;
|
||||
int iw,ih,rw,rh,ox,oy,lastw=0,lasth=0,srcy,prevy;
|
||||
UBYTE *row;
|
||||
struct MsgPort *timerport=0;
|
||||
struct timerequest *timerio=0;
|
||||
struct EClockVal clock;
|
||||
ULONG frequency=0,last=0,delta,dt,rotation=0;
|
||||
LONG xpos=45*1024,ypos=20*1024,xspeed=75,yspeed=0;
|
||||
int timeropen=0;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);
|
||||
GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);
|
||||
LayersBase=OpenLibrary("layers.library",39);
|
||||
if(!IntuitionBase||!GfxBase||!LayersBase)goto end;
|
||||
timerport=CreateMsgPort();if(!timerport)goto end;
|
||||
timerio=(struct timerequest*)CreateIORequest(timerport,sizeof(struct timerequest));if(!timerio)goto end;
|
||||
if(OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest*)timerio,0))goto end;
|
||||
timeropen=1;TimerBase=(struct Library*)timerio->tr_node.io_Device;
|
||||
frequency=ReadEClock(&clock);last=clock.ev_lo;
|
||||
screen=LockPubScreen(0); if(!screen)goto end;
|
||||
if(GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH)>8){
|
||||
P96Base=OpenLibrary("Picasso96API.library",2);
|
||||
if(!P96Base)goto end;
|
||||
rgbFrame=malloc((ULONG)screen->Width*screen->Height*sizeof(UWORD));
|
||||
if(!rgbFrame)goto end;
|
||||
}
|
||||
scaled=malloc((ULONG)screen->Width*screen->Height);
|
||||
xmap=malloc((ULONG)screen->Width*sizeof(UWORD));
|
||||
background=malloc(W*H); frame=malloc(W*H); sprites=malloc(N*D*D);
|
||||
if(!background||!frame||!sprites||!scaled||!xmap)goto end;
|
||||
if(!load("PROGDIR:background.bin",background,W*H)||!load("PROGDIR:sprites.bin",sprites,N*D*D))goto end;
|
||||
for(i=0;i<21;i++) {
|
||||
pens[i]=ObtainBestPen(screen->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);
|
||||
if(pens[i]<0||pens[i]>255)goto end; got++;
|
||||
rgbPens[pens[i]]=(colors[i][0]>>3)<<10|(colors[i][1]>>3)<<5|(colors[i][2]>>3);
|
||||
}
|
||||
for(i=0;i<W*H;i++)background[i]=(UBYTE)pens[background[i]];
|
||||
for(i=0;i<N*D*D;i++)if(sprites[i]!=255)sprites[i]=(UBYTE)pens[sprites[i]];
|
||||
win=OpenWindowTags(0,WA_PubScreen,(ULONG)screen,WA_Left,420,WA_Top,160,
|
||||
WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"Boing! | Space: pausa Esc: esci",
|
||||
WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_Activate,TRUE,
|
||||
WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,
|
||||
WA_MinWidth,240,WA_MinHeight,195,WA_MaxWidth,screen->Width,WA_MaxHeight,screen->Height,
|
||||
WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE,TAG_DONE);
|
||||
if(!win)goto end;
|
||||
while(!done) {
|
||||
while((msg=(struct IntuiMessage*)GetMsg(win->UserPort))!=0) {
|
||||
cls=msg->Class;code=msg->Code;ReplyMsg((struct Message*)msg);
|
||||
if(cls==IDCMP_CLOSEWINDOW||(cls==IDCMP_RAWKEY&&code==0x45))done=1;
|
||||
if(cls==IDCMP_RAWKEY&&code==0x40)paused=!paused;
|
||||
if(cls==IDCMP_NEWSIZE)keepAspect(win,screen,&aspectw,&aspecth);
|
||||
if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(win);EndRefresh(win,TRUE);}
|
||||
}
|
||||
ReadEClock(&clock);delta=clock.ev_lo-last;last=clock.ev_lo;
|
||||
if(delta>frequency/20)delta=frequency/20;
|
||||
dt=delta*1024/frequency;
|
||||
if(!paused){
|
||||
xpos+=xspeed*(LONG)dt;
|
||||
if(xpos<24*1024){xpos=24*1024;xspeed=75;}
|
||||
if(xpos>(W-D-24)*1024){xpos=(W-D-24)*1024;xspeed=-75;}
|
||||
ypos+=yspeed*(LONG)dt/1024+625*(LONG)dt*(LONG)dt/2048;
|
||||
yspeed+=625*(LONG)dt;
|
||||
if(ypos>(H-D-37)*1024){ypos=(H-D-37)*1024;yspeed=-400*1024;}
|
||||
rotation=(rotation+dt*50)%(N*1024);
|
||||
}
|
||||
bx=(xpos+512)/1024;by=(ypos+512)/1024;phase=rotation/1024;
|
||||
memcpy(frame,background,W*H);
|
||||
/* Shadow follows the sphere on the grid and contracts with height. */
|
||||
sx=bx+D/2+23;sy=H-39;dx=34+by/10;dy=6+by/28;
|
||||
for(y=-dy;y<=dy;y++){
|
||||
int span=dx,left,right,yy=sy+y;
|
||||
LONG limit=(LONG)dx*dx*((LONG)dy*dy-(LONG)y*y);
|
||||
if(yy<0||yy>=H)continue;
|
||||
while(span>0&&(LONG)span*span*dy*dy>limit)span--;
|
||||
left=sx-span;right=sx+span;if(left<0)left=0;if(right>=W)right=W-1;
|
||||
if(left<=right)memset(frame+yy*W+left,(UBYTE)pens[2],right-left+1);
|
||||
}
|
||||
sp=sprites+phase*D*D;
|
||||
for(j=0;j<D;j++)for(i=0;i<D;i++)if(sp[j*D+i]!=255 && by+j>=0&&by+j<H)
|
||||
frame[(by+j)*W+bx+i]=sp[j*D+i];
|
||||
iw=win->Width-win->BorderLeft-win->BorderRight;
|
||||
ih=win->Height-win->BorderTop-win->BorderBottom;
|
||||
if(done)break;
|
||||
if(iw<=0||ih<=0||iw>screen->Width||ih>screen->Height){WaitTOF();continue;}
|
||||
/* Build a complete frame off screen. Never expose the scanline conversion. */
|
||||
if(iw!=backw||ih!=backh){
|
||||
struct BitMap *replacement=AllocBitMap(iw,ih,
|
||||
GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH),BMF_CLEAR,
|
||||
screen->RastPort.BitMap);
|
||||
if(!replacement)break;
|
||||
WaitBlit();if(backBitmap)FreeBitMap(backBitmap);
|
||||
backBitmap=replacement;backw=iw;backh=ih;
|
||||
InitRastPort(&backRPort);backRPort.BitMap=backBitmap;
|
||||
}
|
||||
WaitBlit();
|
||||
if(iw==W&&ih==H){
|
||||
writeBack(&backRPort,frame,W,H);
|
||||
}else
|
||||
if(iw>0&&ih>0&&iw<=screen->Width&&ih<=screen->Height) {
|
||||
/* Fit a 4:3 scene inside any window shape; keep the sphere round. */
|
||||
rw=iw;rh=iw*H/W;
|
||||
if(rh>ih){rh=ih;rw=ih*W/H;}
|
||||
ox=(iw-rw)/2;oy=(ih-rh)/2;
|
||||
if(iw!=lastw||ih!=lasth){
|
||||
for(i=0;i<rw;i++)xmap[i]=(ULONG)i*W/rw;
|
||||
lastw=iw;lasth=ih;
|
||||
}
|
||||
if(rgbFrame){ULONG k,n=(ULONG)iw*ih;UWORD bg=rgbPens[pens[0]];for(k=0;k<n;k++)rgbFrame[k]=bg;}
|
||||
else memset(scaled,(UBYTE)pens[0],(ULONG)iw*ih);
|
||||
prevy=-1;
|
||||
for(y=0;y<rh;y++){
|
||||
srcy=(ULONG)y*H/rh;row=scaled+(ULONG)(oy+y)*iw+ox;
|
||||
if(rgbFrame){
|
||||
UWORD *dst=rgbFrame+(ULONG)(oy+y)*iw+ox;
|
||||
if(srcy==prevy)memcpy(dst,dst-iw,rw*2);
|
||||
else for(x=0;x<rw;x++)dst[x]=rgbPens[frame[srcy*W+xmap[x]]];
|
||||
}else{
|
||||
if(srcy==prevy)memcpy(row,row-iw,rw);
|
||||
else for(x=0;x<rw;x++)row[x]=frame[srcy*W+xmap[x]];
|
||||
}
|
||||
prevy=srcy;
|
||||
}
|
||||
if(rgbFrame)uploadRGB(&backRPort,iw,ih);
|
||||
else writeBack(&backRPort,scaled,iw,ih);
|
||||
}
|
||||
/* Finish conversion, then present once per refresh. A resize between
|
||||
rendering and presentation invalidates the old geometry: skip that frame. */
|
||||
WaitBlit();WaitTOF();
|
||||
LockLayer(0,win->WLayer);
|
||||
if(iw==win->Width-win->BorderLeft-win->BorderRight&&
|
||||
ih==win->Height-win->BorderTop-win->BorderBottom){
|
||||
BltBitMapRastPort(backBitmap,0,0,win->RPort,
|
||||
win->BorderLeft,win->BorderTop,iw,ih,0xc0);
|
||||
WaitBlit();
|
||||
}
|
||||
UnlockLayer(win->WLayer);
|
||||
}
|
||||
end:
|
||||
if(GfxBase){WaitBlit();if(backBitmap)FreeBitMap(backBitmap);}
|
||||
if(win)CloseWindow(win);
|
||||
if(screen){for(i=0;i<got;i++)ReleasePen(screen->ViewPort.ColorMap,pens[i]);UnlockPubScreen(0,screen);}
|
||||
free(background);free(frame);free(sprites);
|
||||
free(scaled);free(xmap);free(rgbFrame);
|
||||
if(P96Base)CloseLibrary(P96Base);
|
||||
if(timeropen)CloseDevice((struct IORequest*)timerio);
|
||||
if(timerio)DeleteIORequest((struct IORequest*)timerio);
|
||||
if(timerport)DeleteMsgPort(timerport);
|
||||
if(LayersBase)CloseLibrary(LayersBase);
|
||||
if(GfxBase)CloseLibrary((struct Library*)GfxBase);
|
||||
if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
param([string]$Toolchain = $env:BOING_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/Boing boing.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
Copy-Item -LiteralPath assets/background.bin,assets/sprites.bin,assets/Boing.info -Destination $buildPath -Force
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1,44 @@
|
||||
from pathlib import Path
|
||||
import math
|
||||
from PIL import Image, ImageDraw
|
||||
root=Path(__file__).parent
|
||||
out=root/'assets'
|
||||
out.mkdir(exist_ok=True)
|
||||
W,H,R,N=400,300,57,64
|
||||
palette=[(170,170,170),(145,0,145),(75,75,75),(110,110,110),(215,215,215)]
|
||||
palette += [(int(160+i*95/7),int(8+i*12/7),int(8+i*12/7)) for i in range(8)]
|
||||
palette += [(int(160+i*95/7),)*3 for i in range(8)]
|
||||
bg=Image.new('P',(W,H),0)
|
||||
bg.putpalette(sum((list(c) for c in palette),[])+[0]*(768-len(palette)*3))
|
||||
d=ImageDraw.Draw(bg)
|
||||
# Orthogonal grid and receding floor, echoing the 1984 demonstration.
|
||||
for x in range(20,381,24): d.line((x,12,x,239),fill=1)
|
||||
for y in range(12,240,24): d.line((20,y,380,y),fill=1)
|
||||
d.line((20,239,380,239),fill=1)
|
||||
for x in range(20,381,24): d.line((x,239,200+(x-200)*1.6,299),fill=1)
|
||||
for y in [249,264,285]: d.line((0,y,399,y),fill=1)
|
||||
(out/'background.bin').write_bytes(bg.tobytes())
|
||||
sprites=bytearray()
|
||||
for phase in range(N):
|
||||
im=Image.new('P',(R*2,R*2),255); im.putpalette(bg.getpalette())
|
||||
for y in range(R*2):
|
||||
for x in range(R*2):
|
||||
nx=(x+.5-R)/R; ny=(y+.5-R)/R; rr=nx*nx+ny*ny
|
||||
if rr>=1: continue
|
||||
nz=math.sqrt(1-rr)
|
||||
# Tilt the rotation axis, as in the original red/white ball.
|
||||
a=.24; xx=nx*math.cos(a)-ny*math.sin(a); yy=nx*math.sin(a)+ny*math.cos(a)
|
||||
# The checker pattern repeats after two columns (45 degrees).
|
||||
# Sample that period densely instead of aliasing a full turn.
|
||||
lon=math.atan2(xx,nz)+phase*(math.pi/4)/N
|
||||
lat=math.acos(max(-1,min(1,yy)))
|
||||
red=(math.floor((lon+math.pi)*8/math.pi)+math.floor(lat*8/math.pi))%2
|
||||
light=max(0,min(1,.45+.55*(nz*.8-nx*.35-ny*.35)))
|
||||
shade=min(7,int(light*7))
|
||||
im.putpixel((x,y),(5 if red else 13)+shade)
|
||||
sprites.extend(im.tobytes())
|
||||
if phase==3:
|
||||
preview=bg.copy(); preview.paste(im,(120,65),im.point(lambda p:0 if p==255 else 255).convert('1'))
|
||||
preview.convert('RGB').save(out/'preview.png')
|
||||
(out/'sprites.bin').write_bytes(sprites)
|
||||
(root/'palette.h').write_text('static unsigned char colors[][3] = {'+','.join('{%d,%d,%d}'%c for c in palette)+'};\n')
|
||||
@@ -0,0 +1 @@
|
||||
static unsigned char colors[][3] = {{170,170,170},{145,0,145},{75,75,75},{110,110,110},{215,215,215},{160,8,8},{173,9,9},{187,11,11},{200,13,13},{214,14,14},{227,16,16},{241,18,18},{255,20,20},{160,160,160},{173,173,173},{187,187,187},{200,200,200},{214,214,214},{227,227,227},{241,241,241},{255,255,255}};
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,7 @@
|
||||
/build/
|
||||
/toolchain/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.o
|
||||
*.asm
|
||||
/assets/preview.png
|
||||
@@ -0,0 +1 @@
|
||||
PASS: 476 comparisons of partial vs full redraw at 4 sizes; no missing changed pixels. Mean updated area in synthetic motion: 13.3%.
|
||||
@@ -0,0 +1,27 @@
|
||||
# Rendering optimization (2026-11-06)
|
||||
|
||||
Preserves the existing palette, dimensions, animation rates and visual design.
|
||||
|
||||
- Boing/Matrix: fuse resized pixel sampling and RGB15 conversion into one pass; duplicate scanlines with memcpy.
|
||||
- Boing: ellipse shadow spans replace repeated per-pixel multiplications with identical coverage.
|
||||
- Boing 3D: cache horizontal sphere sampling coordinates per apparent size.
|
||||
- Matrix: cache sparse glyph pixels, preserving glow and core drawing order.
|
||||
- Chrono: cache horizontal sampling coordinates and date conversion; omit invisible analog/digital calculations.
|
||||
|
||||
Original source and executable retained in versions/before-optimization/. Build with build.ps1. No frame-rate reduction.
|
||||
|
||||
## Multitasking update (2026-11-10)
|
||||
|
||||
- Convert, upload and present only the union of the old/new sphere and shadow bounds. Full redraw on resize/refresh.
|
||||
- Animation task priority -1: normal desktop applications take precedence.
|
||||
- Event-aware timer pacing: up to 30 fps active / 15 fps inactive; paused windows wait for input.
|
||||
- Position and rotation use elapsed time; scene, palette, projection and sprites retained.
|
||||
- Removed the unconditional WaitTOF, keeping the layer locked only during partial presentation.
|
||||
- 476 synthetic comparisons at 240x180, 400x300, 800x600 and 1280x960 passed against full redraw. Synthetic mean damage area 13.3%; this is not a measured CPU percentage.
|
||||
- Emulator smoke check: animation, resize and unsent RetroIRC typing with the demo running. Perceived latency still needs the user's judgement.
|
||||
|
||||
Previous source and installed executable: versions/before-damage-rendering/.
|
||||
|
||||
|
||||
### Fluidity correction
|
||||
The user found 30/15 fps pacing visibly less fluid. Pacing is now 50 fps in both foreground and background; damage rendering, priority -1 and event-aware waits remain. This supersedes the initial 30/15 fps cap.
|
||||
@@ -0,0 +1,27 @@
|
||||
# Boing Ball 3D - variante separata
|
||||
|
||||
Progetto indipendente da BoingBall, che resta invariato.
|
||||
Rimbalzi fisici lungo X, altezza Y e profondita Z dentro una stanza.
|
||||
Proiezione prospettica della posizione, del diametro e dell'ombra al suolo.
|
||||
La sfera conserva i 64 sprite di rotazione precalcolati: non e' una mesh 3D.
|
||||
Il moto, la profondita e la prospettiva sono calcolati in tempo reale in C.
|
||||
Buffer fuori schermo e ridimensionamento dell'area interna sempre 4:3.
|
||||
|
||||
## Compilazione
|
||||
|
||||
```powershell
|
||||
.\build.ps1 -Toolchain "C:\percorso\amiga-dev"
|
||||
```
|
||||
|
||||
Il risultato e' in `build/Boing3D` con i due file .bin e l'icona.
|
||||
Copiare insieme in `SYS:Utilities/Boing3D`.
|
||||
Per rigenerare gli asset: `python generate.py` (Python + Pillow).
|
||||
Toolchain esterna: VBCC, VASM, VLINK, target m68k-amigaos e NDK,
|
||||
come https://github.com/kusma/amiga-dev.
|
||||
AmigaOS 3.x, graphics.library v40; per RTG >8 bit Picasso96API.library v2.
|
||||
|
||||
Spazio: pausa/riprendi. Esc: esci. Mouse: sposta o ridimensiona la finestra.
|
||||
I limiti del mondo e la camera si trovano nel ciclo principale di `boing.c`
|
||||
e nella funzione `project` di `generate.py`; devono rimanere coerenti.
|
||||
|
||||
Latest version uses damage-based partial rendering, low task priority and 50 fps pacing to protect Workbench responsiveness. See OPTIMIZATION.md. The executable was built from this C:/git project and installed under SYS:Utilities/Boing3D/.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,273 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <graphics/view.h>
|
||||
#include <devices/timer.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/layers.h>
|
||||
#include <proto/timer.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "palette.h"
|
||||
#define W 400
|
||||
#define H 300
|
||||
#define D 114
|
||||
#define N 64
|
||||
struct IntuitionBase *IntuitionBase;
|
||||
struct GfxBase *GfxBase;
|
||||
struct Library *TimerBase;
|
||||
struct Library *LayersBase;
|
||||
static struct Library *P96Base;
|
||||
/* Picasso96 public ABI: RenderInfo is 12 bytes; RGBFB_R5G5B5 = 11.
|
||||
Only this function is needed, so no complete P96 SDK is required. */
|
||||
struct BoingRenderInfo {APTR Memory;WORD BytesPerRow,pad;ULONG RGBFormat;};
|
||||
void __boingP96Write(__reg("a6") void *,__reg("a0") struct BoingRenderInfo *,
|
||||
__reg("d0") UWORD,__reg("d1") UWORD,__reg("a1") struct RastPort *,
|
||||
__reg("d2") UWORD,__reg("d3") UWORD,__reg("d4") UWORD,__reg("d5") UWORD)="\tjsr\t-102(a6)";
|
||||
static UWORD *rgbFrame,rgbPens[256];
|
||||
static int damageX,damageY,damageW,damageH;
|
||||
static void uploadRGB(struct RastPort *rp,int width,int height){
|
||||
struct BoingRenderInfo ri;
|
||||
ri.Memory=rgbFrame;ri.BytesPerRow=width*2;ri.pad=0;ri.RGBFormat=11;
|
||||
__boingP96Write(P96Base,&ri,damageX,damageY,rp,damageX,damageY,damageW,damageH);
|
||||
}
|
||||
static void writeBack(struct RastPort *rp,UBYTE *pixels,int width,int height){
|
||||
if(rgbFrame){
|
||||
int x,y;for(y=damageY;y<damageY+damageH;y++)for(x=damageX;x<damageX+damageW;x++)rgbFrame[(ULONG)y*width+x]=rgbPens[pixels[(ULONG)y*width+x]];
|
||||
uploadRGB(rp,width,height);
|
||||
}else WriteChunkyPixels(rp,0,0,width-1,height-1,pixels,width);
|
||||
}
|
||||
static UBYTE *background,*sprites,*frame,*scaled;
|
||||
static UWORD *xmap;
|
||||
static UBYTE sphereX[D*2];
|
||||
static int lastSphereSize;
|
||||
static LONG pens[21];
|
||||
static int load(char *path,UBYTE *p,long size) {
|
||||
FILE *f=fopen(path,"rb"); int ok; if(!f)return 0;
|
||||
ok=fread(p,1,size,f)==size; fclose(f);return ok;
|
||||
}
|
||||
/* Intuition completes the native resize first; snap its inner area to 4:3.
|
||||
Use the axis moved most, then clamp both axes together in 4x3 pixel steps. */
|
||||
static void keepAspect(struct Window *w,struct Screen *sc,int *oldw,int *oldh){
|
||||
int bw=w->BorderLeft+w->BorderRight,bh=w->BorderTop+w->BorderBottom;
|
||||
int iw=w->Width-bw,ih=w->Height-bh,k,kmin,kmax,t;
|
||||
if(iw*3==ih*4){*oldw=iw;*oldh=ih;return;}
|
||||
if(abs(iw-*oldw)*3>=abs(ih-*oldh)*4)k=(iw+2)/4;
|
||||
else k=(ih+1)/3;
|
||||
kmin=(w->MinWidth-bw+3)/4;
|
||||
t=(w->MinHeight-bh+2)/3;if(t>kmin)kmin=t;
|
||||
if(kmin<1)kmin=1;
|
||||
kmax=(sc->Width-w->LeftEdge-bw)/4;
|
||||
t=(sc->Height-w->TopEdge-bh)/3;if(t<kmax)kmax=t;
|
||||
if(kmax<kmin)kmax=kmin;
|
||||
if(k<kmin)k=kmin;if(k>kmax)k=kmax;
|
||||
*oldw=k*4;*oldh=k*3;
|
||||
ChangeWindowBox(w,w->LeftEdge,w->TopEdge,*oldw+bw,*oldh+bh);
|
||||
}
|
||||
int main(void) {
|
||||
struct BitMap *backBitmap=0;struct RastPort backRPort;
|
||||
int backw=0,backh=0,aspectw=W,aspecth=H;
|
||||
struct Screen *screen=0; struct Window *win=0; struct IntuiMessage *msg;
|
||||
int i,j,x,y,bx,by,size,den,wx,wy,wz,phase=0,done=0,paused=0,got=0;
|
||||
ULONG cls; UWORD code; UBYTE *sp; int sx,sy,dx,dy;
|
||||
int iw,ih,rw,rh,ox,oy,lastw=0,lasth=0,srcy,prevy;
|
||||
UBYTE *row;
|
||||
struct MsgPort *timerport=0;
|
||||
struct timerequest *timerio=0;
|
||||
struct EClockVal clock;
|
||||
ULONG frequency=0,last=0,delta,dt,rotation=0;
|
||||
LONG xpos=-95*1024,ypos=150*1024,zpos=180*1024;
|
||||
LONG xspeed=95,yspeed=0,zspeed=110;
|
||||
int timeropen=0,force=1,oldL=0,oldT=0,oldR=W-1,oldB=H-1;
|
||||
int dl,dr,dtp,db,nl,nr,nt,nb,renderX,renderY,renderR,renderB;
|
||||
ULONG frameStart=0,interval,elapsed,signals;LONG oldPriority=0;int prioritySet=0;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);
|
||||
GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);
|
||||
LayersBase=OpenLibrary("layers.library",39);
|
||||
if(!IntuitionBase||!GfxBase||!LayersBase)goto end;
|
||||
timerport=CreateMsgPort();if(!timerport)goto end;
|
||||
timerio=(struct timerequest*)CreateIORequest(timerport,sizeof(struct timerequest));if(!timerio)goto end;
|
||||
if(OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest*)timerio,0))goto end;
|
||||
timeropen=1;TimerBase=(struct Library*)timerio->tr_node.io_Device;
|
||||
frequency=ReadEClock(&clock);last=clock.ev_lo;
|
||||
screen=LockPubScreen(0); if(!screen)goto end;
|
||||
if(GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH)>8){
|
||||
P96Base=OpenLibrary("Picasso96API.library",2);
|
||||
if(!P96Base)goto end;
|
||||
rgbFrame=malloc((ULONG)screen->Width*screen->Height*sizeof(UWORD));
|
||||
if(!rgbFrame)goto end;
|
||||
}
|
||||
scaled=malloc((ULONG)screen->Width*screen->Height);
|
||||
xmap=malloc((ULONG)screen->Width*sizeof(UWORD));
|
||||
background=malloc(W*H); frame=malloc(W*H); sprites=malloc(N*D*D);
|
||||
if(!background||!frame||!sprites||!scaled||!xmap)goto end;
|
||||
if(!load("PROGDIR:background.bin",background,W*H)||!load("PROGDIR:sprites.bin",sprites,N*D*D))goto end;
|
||||
for(i=0;i<21;i++) {
|
||||
pens[i]=ObtainBestPen(screen->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);
|
||||
if(pens[i]<0||pens[i]>255)goto end; got++;
|
||||
rgbPens[pens[i]]=(colors[i][0]>>3)<<10|(colors[i][1]>>3)<<5|(colors[i][2]>>3);
|
||||
}
|
||||
for(i=0;i<W*H;i++)background[i]=(UBYTE)pens[background[i]];
|
||||
for(i=0;i<N*D*D;i++)if(sprites[i]!=255)sprites[i]=(UBYTE)pens[sprites[i]];
|
||||
win=OpenWindowTags(0,WA_PubScreen,(ULONG)screen,WA_Left,740,WA_Top,400,
|
||||
WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"Boing 3D | Space: pausa Esc: esci",
|
||||
WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_Activate,TRUE,
|
||||
WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,
|
||||
WA_MinWidth,240,WA_MinHeight,195,WA_MaxWidth,screen->Width,WA_MaxHeight,screen->Height,
|
||||
WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE,TAG_DONE);
|
||||
if(!win)goto end;
|
||||
oldPriority=SetTaskPri(FindTask(0),-1);prioritySet=1;
|
||||
while(!done) {
|
||||
while((msg=(struct IntuiMessage*)GetMsg(win->UserPort))!=0) {
|
||||
cls=msg->Class;code=msg->Code;ReplyMsg((struct Message*)msg);
|
||||
if(cls==IDCMP_CLOSEWINDOW||(cls==IDCMP_RAWKEY&&code==0x45))done=1;
|
||||
if(cls==IDCMP_RAWKEY&&code==0x40){paused=!paused;force=1;}
|
||||
if(cls==IDCMP_NEWSIZE)force=1;
|
||||
if(cls==IDCMP_NEWSIZE)keepAspect(win,screen,&aspectw,&aspecth);
|
||||
if(cls==IDCMP_REFRESHWINDOW){force=1;BeginRefresh(win);EndRefresh(win,TRUE);}
|
||||
}
|
||||
if(done)break;
|
||||
/* Sleep on timer OR window input; never busy-wait or delay keyboard events. */
|
||||
ReadEClock(&clock);interval=frequency/50;elapsed=clock.ev_lo-frameStart;
|
||||
if(frameStart&&elapsed<interval){timerio->tr_node.io_Command=TR_ADDREQUEST;timerio->tr_time.tv_secs=0;timerio->tr_time.tv_micro=(interval-elapsed)*1000UL/(frequency/1000);
|
||||
SendIO((struct IORequest*)timerio);signals=Wait((1UL<<timerport->mp_SigBit)|(1UL<<win->UserPort->mp_SigBit));if(!CheckIO((struct IORequest*)timerio))AbortIO((struct IORequest*)timerio);WaitIO((struct IORequest*)timerio);continue;
|
||||
}
|
||||
frameStart=clock.ev_lo;
|
||||
if(paused&&!force){Wait(1UL<<win->UserPort->mp_SigBit);continue;}
|
||||
ReadEClock(&clock);delta=clock.ev_lo-last;last=clock.ev_lo;
|
||||
if(delta>frequency/10)delta=frequency/10;
|
||||
dt=delta*1024/frequency;
|
||||
if(!paused){
|
||||
/* World space in fixed point. Sphere radius 50; room 380x250x400. */
|
||||
xpos+=xspeed*(LONG)dt;
|
||||
if(xpos<-140*1024){xpos=-140*1024;xspeed=95;}
|
||||
if(xpos>140*1024){xpos=140*1024;xspeed=-95;}
|
||||
zpos+=zspeed*(LONG)dt;
|
||||
if(zpos<50*1024){zpos=50*1024;zspeed=110;}
|
||||
if(zpos>350*1024){zpos=350*1024;zspeed=-110;}
|
||||
ypos+=yspeed*(LONG)dt/1024-625*(LONG)dt*(LONG)dt/2048;
|
||||
yspeed-=625*(LONG)dt;
|
||||
if(ypos<50*1024){ypos=50*1024;yspeed=400*1024;}
|
||||
if(ypos>200*1024){ypos=200*1024;yspeed=-abs(yspeed);}
|
||||
rotation=(rotation+dt*50)%(N*1024);
|
||||
}
|
||||
wx=xpos/1024;wy=ypos/1024;wz=zpos/1024;
|
||||
den=260+wz;
|
||||
size=100*340/den;
|
||||
bx=200+wx*340/den-size/2;
|
||||
by=100+(150-wy)*340/den-size/2;
|
||||
phase=rotation/1024;
|
||||
memcpy(frame,background,W*H);
|
||||
/* Project the shadow separately on the floor at the sphere's world depth. */
|
||||
{int shadowz=wz+(wy-50)/7,shadowden=260+shadowz;
|
||||
sx=200+(wx+(wy-50)/6)*340/shadowden;
|
||||
sy=100+150*340/shadowden;
|
||||
dx=(40+(wy-50)/10)*340/shadowden;
|
||||
dy=(11+(wy-50)/30)*340/shadowden;
|
||||
if(dy<2)dy=2;
|
||||
}
|
||||
nl=bx<sx-dx?bx:sx-dx;nr=bx+size>sx+dx?bx+size:sx+dx;
|
||||
nt=by<sy-dy?by:sy-dy;nb=by+size>sy+dy?by+size:sy+dy;
|
||||
dl=nl<oldL?nl:oldL;dr=nr>oldR?nr:oldR;dtp=nt<oldT?nt:oldT;db=nb>oldB?nb:oldB;
|
||||
oldL=nl;oldR=nr;oldT=nt;oldB=nb;
|
||||
if(dl<0)dl=0;if(dtp<0)dtp=0;if(dr>=W)dr=W-1;if(db>=H)db=H-1;
|
||||
for(y=-dy;y<=dy;y++){
|
||||
int span=dx,left,right,yy=sy+y;
|
||||
LONG limit=(LONG)dx*dx*((LONG)dy*dy-(LONG)y*y);
|
||||
if(yy<0||yy>=H)continue;
|
||||
while(span>0&&(LONG)span*span*dy*dy>limit)span--;
|
||||
left=sx-span;right=sx+span;if(left<0)left=0;if(right>=W)right=W-1;
|
||||
if(left<=right)memset(frame+yy*W+left,(UBYTE)pens[2],right-left+1);
|
||||
}
|
||||
sp=sprites+phase*D*D;
|
||||
/* The checker sphere uses the original prerendered rotation frames;
|
||||
position and apparent diameter come from a real perspective projection. */
|
||||
if(size!=lastSphereSize){for(i=0;i<size;i++)sphereX[i]=i*D/size;lastSphereSize=size;}
|
||||
for(j=0;j<size;j++){
|
||||
int yy=by+j,srcrow=j*D/size*D;
|
||||
if(yy<0||yy>=H)continue;
|
||||
for(i=0;i<size;i++){
|
||||
UBYTE c=sp[srcrow+sphereX[i]];int xx=bx+i;
|
||||
if(c!=255&&xx>=0&&xx<W)frame[yy*W+xx]=c;
|
||||
}
|
||||
}
|
||||
iw=win->Width-win->BorderLeft-win->BorderRight;
|
||||
ih=win->Height-win->BorderTop-win->BorderBottom;
|
||||
if(done)break;
|
||||
if(iw<=0||ih<=0||iw>screen->Width||ih>screen->Height){WaitTOF();continue;}
|
||||
/* Build a complete frame off screen. Never expose the scanline conversion. */
|
||||
if(iw!=backw||ih!=backh){
|
||||
force=1;
|
||||
struct BitMap *replacement=AllocBitMap(iw,ih,
|
||||
GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH),BMF_CLEAR,
|
||||
screen->RastPort.BitMap);
|
||||
if(!replacement)break;
|
||||
WaitBlit();if(backBitmap)FreeBitMap(backBitmap);
|
||||
backBitmap=replacement;backw=iw;backh=ih;
|
||||
InitRastPort(&backRPort);backRPort.BitMap=backBitmap;
|
||||
}
|
||||
if(force){damageX=damageY=0;damageW=iw;damageH=ih;}
|
||||
else{damageX=dl*iw/W;damageY=dtp*ih/H;damageW=(dr+1)*iw/W+2-damageX;damageH=(db+1)*ih/H+2-damageY;if(damageX+damageW>iw)damageW=iw-damageX;if(damageY+damageH>ih)damageH=ih-damageY;}
|
||||
WaitBlit();
|
||||
if(iw==W&&ih==H){
|
||||
writeBack(&backRPort,frame,W,H);
|
||||
}else
|
||||
if(iw>0&&ih>0&&iw<=screen->Width&&ih<=screen->Height) {
|
||||
/* Fit a 4:3 scene inside any window shape; keep the sphere round. */
|
||||
rw=iw;rh=iw*H/W;
|
||||
if(rh>ih){rh=ih;rw=ih*W/H;}
|
||||
ox=(iw-rw)/2;oy=(ih-rh)/2;
|
||||
if(iw!=lastw||ih!=lasth){
|
||||
for(i=0;i<rw;i++)xmap[i]=(ULONG)i*W/rw;
|
||||
lastw=iw;lasth=ih;
|
||||
}
|
||||
if(rgbFrame&&force){ULONG k,n=(ULONG)iw*ih;UWORD bg=rgbPens[pens[0]];for(k=0;k<n;k++)rgbFrame[k]=bg;}
|
||||
else if(!rgbFrame)memset(scaled,(UBYTE)pens[0],(ULONG)iw*ih);
|
||||
prevy=-1;
|
||||
for(y=damageY>oy?damageY-oy:0;y<rh&&y+oy<damageY+damageH;y++){
|
||||
srcy=(ULONG)y*H/rh;row=scaled+(ULONG)(oy+y)*iw+ox;
|
||||
if(rgbFrame){
|
||||
UWORD *dst=rgbFrame+(ULONG)(oy+y)*iw+ox;
|
||||
for(x=damageX>ox?damageX-ox:0;x<rw&&x+ox<damageX+damageW;x++)dst[x]=rgbPens[frame[srcy*W+xmap[x]]];
|
||||
}else{
|
||||
if(srcy==prevy)memcpy(row,row-iw,rw);
|
||||
else for(x=0;x<rw;x++)row[x]=frame[srcy*W+xmap[x]];
|
||||
}
|
||||
prevy=srcy;
|
||||
}
|
||||
if(rgbFrame)uploadRGB(&backRPort,iw,ih);
|
||||
else writeBack(&backRPort,scaled,iw,ih);
|
||||
}
|
||||
/* Finish conversion, then present once per refresh. A resize between
|
||||
rendering and presentation invalidates the old geometry: skip that frame. */
|
||||
WaitBlit();
|
||||
LockLayer(0,win->WLayer);
|
||||
if(iw==win->Width-win->BorderLeft-win->BorderRight&&
|
||||
ih==win->Height-win->BorderTop-win->BorderBottom){
|
||||
BltBitMapRastPort(backBitmap,damageX,damageY,win->RPort,
|
||||
win->BorderLeft+damageX,win->BorderTop+damageY,damageW,damageH,0xc0);
|
||||
force=0;
|
||||
WaitBlit();
|
||||
}
|
||||
UnlockLayer(win->WLayer);
|
||||
}
|
||||
end:
|
||||
if(prioritySet)SetTaskPri(FindTask(0),oldPriority);
|
||||
if(GfxBase){WaitBlit();if(backBitmap)FreeBitMap(backBitmap);}
|
||||
if(win)CloseWindow(win);
|
||||
if(screen){for(i=0;i<got;i++)ReleasePen(screen->ViewPort.ColorMap,pens[i]);UnlockPubScreen(0,screen);}
|
||||
free(background);free(frame);free(sprites);
|
||||
free(scaled);free(xmap);free(rgbFrame);
|
||||
if(P96Base)CloseLibrary(P96Base);
|
||||
if(timeropen)CloseDevice((struct IORequest*)timerio);
|
||||
if(timerio)DeleteIORequest((struct IORequest*)timerio);
|
||||
if(timerport)DeleteMsgPort(timerport);
|
||||
if(LayersBase)CloseLibrary(LayersBase);
|
||||
if(GfxBase)CloseLibrary((struct Library*)GfxBase);
|
||||
if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
param([string]$Toolchain = $env:BOING_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/Boing3D boing.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
Copy-Item -LiteralPath assets/background.bin,assets/sprites.bin,assets/Boing3D.info -Destination $buildPath -Force
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1,57 @@
|
||||
from pathlib import Path
|
||||
import math
|
||||
from PIL import Image, ImageDraw
|
||||
root=Path(__file__).parent
|
||||
out=root/'assets'
|
||||
out.mkdir(exist_ok=True)
|
||||
W,H,R,N=400,300,57,64
|
||||
palette=[(170,170,170),(145,0,145),(75,75,75),(110,110,110),(215,215,215)]
|
||||
palette += [(int(160+i*95/7),int(8+i*12/7),int(8+i*12/7)) for i in range(8)]
|
||||
palette += [(int(160+i*95/7),)*3 for i in range(8)]
|
||||
bg=Image.new('P',(W,H),0)
|
||||
bg.putpalette(sum((list(c) for c in palette),[])+[0]*(768-len(palette)*3))
|
||||
d=ImageDraw.Draw(bg)
|
||||
# Perspective room: same camera and dimensions used by the C animation.
|
||||
def project(x,y,z):
|
||||
return (200+x*340/(260+z),100+(150-y)*340/(260+z))
|
||||
def line(a,b): d.line((project(*a),project(*b)),fill=1)
|
||||
def plane(points,color):d.polygon([project(*v) for v in points],fill=color)
|
||||
plane([(-190,0,400),(190,0,400),(190,250,400),(-190,250,400)],4)
|
||||
plane([(-190,0,0),(-190,0,400),(-190,250,400),(-190,250,0)],3)
|
||||
plane([(190,0,0),(190,0,400),(190,250,400),(190,250,0)],3)
|
||||
for x in range(-190,191,38):
|
||||
line((x,0,0),(x,0,400))
|
||||
line((x,0,400),(x,250,400))
|
||||
for z in range(0,401,40):
|
||||
line((-190,0,z),(190,0,z))
|
||||
line((-190,0,z),(-190,250,z))
|
||||
line((190,0,z),(190,250,z))
|
||||
for y in range(0,251,50):
|
||||
line((-190,y,400),(190,y,400))
|
||||
line((-190,y,0),(-190,y,400))
|
||||
line((190,y,0),(190,y,400))
|
||||
(out/'background.bin').write_bytes(bg.tobytes())
|
||||
sprites=bytearray()
|
||||
for phase in range(N):
|
||||
im=Image.new('P',(R*2,R*2),255); im.putpalette(bg.getpalette())
|
||||
for y in range(R*2):
|
||||
for x in range(R*2):
|
||||
nx=(x+.5-R)/R; ny=(y+.5-R)/R; rr=nx*nx+ny*ny
|
||||
if rr>=1: continue
|
||||
nz=math.sqrt(1-rr)
|
||||
# Tilt the rotation axis, as in the original red/white ball.
|
||||
a=.24; xx=nx*math.cos(a)-ny*math.sin(a); yy=nx*math.sin(a)+ny*math.cos(a)
|
||||
# The checker pattern repeats after two columns (45 degrees).
|
||||
# Sample that period densely instead of aliasing a full turn.
|
||||
lon=math.atan2(xx,nz)+phase*(math.pi/4)/N
|
||||
lat=math.acos(max(-1,min(1,yy)))
|
||||
red=(math.floor((lon+math.pi)*8/math.pi)+math.floor(lat*8/math.pi))%2
|
||||
light=max(0,min(1,.45+.55*(nz*.8-nx*.35-ny*.35)))
|
||||
shade=min(7,int(light*7))
|
||||
im.putpixel((x,y),(5 if red else 13)+shade)
|
||||
sprites.extend(im.tobytes())
|
||||
if phase==3:
|
||||
preview=bg.copy(); preview.paste(im,(120,65),im.point(lambda p:0 if p==255 else 255).convert('1'))
|
||||
preview.convert('RGB').save(out/'preview.png')
|
||||
(out/'sprites.bin').write_bytes(sprites)
|
||||
(root/'palette.h').write_text('static unsigned char colors[][3] = {'+','.join('{%d,%d,%d}'%c for c in palette)+'};\n')
|
||||
@@ -0,0 +1 @@
|
||||
static unsigned char colors[][3] = {{170,170,170},{145,0,145},{75,75,75},{110,110,110},{215,215,215},{160,8,8},{173,9,9},{187,11,11},{200,13,13},{214,14,14},{227,16,16},{241,18,18},{255,20,20},{160,160,160},{173,173,173},{187,187,187},{200,200,200},{214,214,214},{227,227,227},{241,241,241},{255,255,255}};
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,3 @@
|
||||
# DCTelnet theme
|
||||
|
||||
Script locale per applicare il tema ambra a una installazione DCTelnet. Il programma e i sorgenti upstream non sono inclusi. Lo script originale usa percorsi C:/Amiga.
|
||||
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
import struct,shutil
|
||||
app=Path('C:/Amiga/HD0/Utilities/DCTelnet')
|
||||
shutil.copy2(app/'DCTelnet.Prefs','work/telnet-theme/DCTelnet.Prefs.before')
|
||||
p=app/'DCTelnet.Prefs'
|
||||
b=bytearray(p.read_bytes())
|
||||
assert len(b)==376
|
||||
# Native m68k PrefsStruct: 16 RGB4 colors at 200, then flags and window geometry.
|
||||
colors=[0x321,0xedb,0xa73,0xdb7,0x865,0xc95,0xdb9,0xa62,
|
||||
0x653,0xffe,0xc94,0xfd8,0xba8,0xeb7,0xfec,0xe93]
|
||||
for i,c in enumerate(colors):struct.pack_into('>H',b,200+2*i,c)
|
||||
flags=struct.unpack_from('>I',b,232)[0]
|
||||
# Workbench window and monochrome terminal text use the desktop's own pens.
|
||||
struct.pack_into('>I',b,232,flags|8|64)
|
||||
struct.pack_into('>4H',b,236,240,240,680,480)
|
||||
p.write_bytes(b)
|
||||
dock=Path('C:/Amiga/HD0/Utilities/WBDock2/Amber.config')
|
||||
shutil.copy2(dock,'work/telnet-theme/Amber.config.before')
|
||||
s=dock.read_text()
|
||||
entry='SYS:Utilities/DCTelnet/DCTelnet'
|
||||
if entry not in s:s=s.replace('HD0:WookieChat_OS3','HD0:WookieChat_OS3\n'+entry)
|
||||
dock.write_bytes(s.encode('ascii'))
|
||||
@@ -0,0 +1,2 @@
|
||||
build/
|
||||
*.o
|
||||
@@ -0,0 +1,7 @@
|
||||
Wait 6 SECS
|
||||
C:RestoreMouse >NIL:
|
||||
C:SetClock LOAD
|
||||
Stack 65536
|
||||
Execute S:Session-Apps
|
||||
Stack 65536
|
||||
Run >NIL: SYS:Utilities/WBDock2/WBDock CONFIG=SYS:Utilities/WBDock2/Amber.config POS=BL STYLE=T FONT=topaz/8 DISTANCE=20 NODRAGBAR STICKY ICONDIST=12 PATTERN=#24211B QUIET
|
||||
@@ -0,0 +1,11 @@
|
||||
# Desktop Session
|
||||
|
||||
Helper AmigaOS 3 per salvare e ripristinare le finestre delle app native realizzate in questa raccolta.
|
||||
|
||||
C:AmigaSession SAVE salva geometria e ordine e genera S:Session-Apps con le app attualmente aperte. C:AmigaSession RESTORE attende fino a 30 secondi le finestre e ne ripristina posizione, dimensioni e ordine. Non lancia duplicati: il lancio viene eseguito solo dallo script di avvio. S:Amber-Desktop esegue Session-Apps al posto del precedente avvio singolo di Chrono; il dock conserva il suo avvio esistente.
|
||||
|
||||
Snapshot iniziale: RetroIRC 28,397 920x477; Matrix 30,36 488x341; Boing3D 523,36 436x342; Chrono digitale 961,36 296x120.
|
||||
|
||||
Per aggiornare in futuro la disposizione salvata: Workbench Execute -> execute savesession. Non e un salvataggio continuo: registra la disposizione al momento del comando. Le conversazioni e le connessioni IRC non vengono salvate/ripristinate da questo helper.
|
||||
|
||||
Build: ./build.ps1 -Toolchain <VBCC/VASM/VLINK + NDK>. Copiare build/AmigaSession in SYS:C/. Backup dell'avvio precedente: Amber-Desktop.before. Le copie degli script e Saved.layout documentano la configurazione iniziale, specifica di questo desktop 1280x1024.
|
||||
@@ -0,0 +1,2 @@
|
||||
Stack 65536
|
||||
C:AmigaSession SAVE
|
||||
@@ -0,0 +1,4 @@
|
||||
3 28 397 920 477
|
||||
2 30 36 488 341
|
||||
1 523 36 436 342
|
||||
0 961 36 296 120
|
||||
@@ -0,0 +1,7 @@
|
||||
; Generated by AmigaSession SAVE. Restore the captured applications.
|
||||
Stack 262144
|
||||
Run >NIL: SYS:Utilities/AmberChrono/Chrono
|
||||
Run >NIL: SYS:Utilities/Boing3D/Boing3D
|
||||
Run >NIL: SYS:Utilities/Matrix/Matrix
|
||||
Run >NIL: SYS:Utilities/RetroIRC/RetroIRC
|
||||
Run >NIL: C:AmigaSession RESTORE
|
||||
@@ -0,0 +1,25 @@
|
||||
param([string]$Toolchain = $env:AMIGA_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/AmigaSession session.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
struct IntuitionBase*IntuitionBase;
|
||||
struct App {char*title,*path;};
|
||||
static struct App apps[]={
|
||||
{"Amber Chrono","SYS:Utilities/AmberChrono/Chrono"},{"Boing 3D","SYS:Utilities/Boing3D/Boing3D"},{"Matrix |","SYS:Utilities/Matrix/Matrix"},{"RetroIRC","SYS:Utilities/RetroIRC/RetroIRC"},{"RetroTerm","SYS:Utilities/RetroTerm/RetroTerm"},{"Boing!","SYS:Utilities/Boing/Boing"},{"System Monitor","SYS:Utilities/AmberMonitor/Monitor"},{"Tech News","SYS:Utilities/NewsTicker/News"},{"MOD Player","SYS:Utilities/AmberMod/ModPlayer"}};
|
||||
#define APPS (sizeof(apps)/sizeof(apps[0]))
|
||||
struct Entry {int app,x,y,w,h;};static struct Entry entries[APPS];static struct Window*found[APPS];
|
||||
static int identify(struct Window*w){int i;if(!w->Title)return -1;for(i=0;i<APPS;i++)if(!strncmp((char*)w->Title,apps[i].title,strlen(apps[i].title)))return i;return -1;}
|
||||
int main(int argc,char**argv){struct Screen*sc;struct Window*w;ULONG lock;FILE*f;int n=0,i,j,id,pass,restoring=argc>1&&!strcmp(argv[1],"RESTORE");IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);if(!IntuitionBase)return 20;sc=LockPubScreen(0);if(!sc){CloseLibrary((struct Library*)IntuitionBase);return 20;}
|
||||
if(!restoring){lock=LockIBase(0);for(w=sc->FirstWindow;w&&n<APPS;w=w->NextWindow){id=identify(w);if(id<0)continue;for(i=0;i<n;i++)if(entries[i].app==id)break;if(i<n)continue;entries[n].app=id;entries[n].x=w->LeftEdge;entries[n].y=w->TopEdge;entries[n].w=w->Width;entries[n++].h=w->Height;}UnlockIBase(lock);
|
||||
if(!n)goto end;f=fopen("SYS:Prefs/AmigaSession.layout","w");if(!f)goto end;for(i=0;i<n;i++)fprintf(f,"%d %d %d %d %d\n",entries[i].app,entries[i].x,entries[i].y,entries[i].w,entries[i].h);fclose(f);
|
||||
f=fopen("S:Session-Apps","w");if(f){fprintf(f,"; Generated by AmigaSession SAVE. Restore the captured applications.\nStack 262144\n");for(i=n-1;i>=0;i--)fprintf(f,"Run >NIL: %s\n",apps[entries[i].app].path);fprintf(f,"Run >NIL: C:AmigaSession RESTORE\n");fclose(f);}
|
||||
}else{f=fopen("SYS:Prefs/AmigaSession.layout","r");if(!f)goto end;while(n<APPS&&fscanf(f,"%d %d %d %d %d",&entries[n].app,&entries[n].x,&entries[n].y,&entries[n].w,&entries[n].h)==5){if(entries[n].app>=0&&entries[n].app<APPS)n++;}fclose(f);
|
||||
for(pass=0;pass<300;pass++){for(i=0;i<n;i++){if(found[i])continue;lock=LockIBase(0);for(w=sc->FirstWindow;w;w=w->NextWindow)if(identify(w)==entries[i].app)break;UnlockIBase(lock);if(!w)continue;ChangeWindowBox(w,entries[i].x,entries[i].y,entries[i].w,entries[i].h);found[i]=w;}for(i=0;i<n;i++)if(!found[i])break;if(i==n)break;Delay(5);}
|
||||
/* Re-find each window before the final pass: apps can reopen while starting. */
|
||||
Delay(25);for(i=n-1;i>=0;i--){lock=LockIBase(0);for(w=sc->FirstWindow;w;w=w->NextWindow)if(identify(w)==entries[i].app)break;UnlockIBase(lock);if(w){ChangeWindowBox(w,entries[i].x,entries[i].y,entries[i].w,entries[i].h);WindowToFront(w);}}
|
||||
}
|
||||
end:UnlockPubScreen(0,sc);CloseLibrary((struct Library*)IntuitionBase);return 0;}
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,3 @@
|
||||
# Desktop toolkit
|
||||
|
||||
Script originali per icone, ordinamento drawer, tema desktop, dock, anteprime e configurazione di avvio. Conservano i percorsi della macchina originale: leggere lo script prima di riutilizzarlo. Nessuna immagine disco o configurazione personale inclusa.
|
||||
@@ -0,0 +1,9 @@
|
||||
from pathlib import Path
|
||||
base=Path('C:/Amiga/HD0/S')
|
||||
s=Path('work/boot040/Startup-Sequence.before').read_text()
|
||||
checks=['C:SetPatch QUIET','C:CPU CHECKINSTALL','C:Mount >NIL: DEVS:DOSDrivers/~(#?.info)','C:IPrefs',' Execute S:User-Startup','C:Mount DEVS:DOSDrivers/VNC >NIL:','C:LoadWB']
|
||||
for n,line in enumerate(checks):
|
||||
s=s.replace(line,line+'\nEcho "Check '+str(n)+': $RC" >>HD0:Boot-Audit.log')
|
||||
s=s.replace('C:LoadWB\n','C:CPU >HD0:CPU040.log\nC:Version 68040.library FULL >>HD0:CPU040.log\nC:LoadWB\n')
|
||||
s='Echo "Boot audit" >HD0:Boot-Audit.log\n'+s
|
||||
(base/'Startup-Sequence').write_bytes(s.encode('ascii'))
|
||||
@@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
base=Path('C:/Amiga/HD0/S')
|
||||
s=Path('work/boot040/User-Startup.before').read_text()
|
||||
lines=s.splitlines()
|
||||
out=['Echo "User startup audit" >HD0:User-Audit.log']
|
||||
for n,line in enumerate(lines):
|
||||
out.append(line)
|
||||
if line.strip().lower().startswith(('assign ','path ','amitcp:bin/umask','version ')):
|
||||
out.append('Echo "Line '+str(n+1)+': $RC" >>HD0:User-Audit.log')
|
||||
(base/'User-Startup').write_bytes(('\n'.join(out)+'\n').encode('ascii'))
|
||||
s=(base/'Startup-Sequence').read_text()
|
||||
s=s.replace('C:Mount >NIL: DEVS:DOSDrivers/~(#?.info)','C:Mount DEVS:DOSDrivers/~(#?.info) >HD0:Mount-error.log')
|
||||
(base/'Startup-Sequence').write_bytes(s.encode('ascii'))
|
||||
@@ -0,0 +1,14 @@
|
||||
from pathlib import Path
|
||||
base=Path('C:/Amiga/HD0/S')
|
||||
s=Path('work/boot040/Startup-Sequence.before').read_text()
|
||||
s=s.replace('DEVS:DOSDrivers/~(#?.info)','DEVS:DOSDrivers/~(#?.info|#?.uaem)')
|
||||
s=s.replace('DEVS:Monitors/~(#?.info|VGAOnly)','DEVS:Monitors/~(#?.info|#?.uaem|VGAOnly)')
|
||||
s=s.replace('C:Mount DEVS:DOSDrivers/VNC >NIL:\n','')
|
||||
Path('work/boot040/Startup-Sequence.fixed').write_bytes(s.encode('ascii'))
|
||||
for n,line in enumerate(['C:SetPatch QUIET','C:CPU CHECKINSTALL','C:Mount >NIL: DEVS:DOSDrivers/~(#?.info|#?.uaem)',' Execute S:User-Startup','C:LoadWB']):
|
||||
s=s.replace(line,line+'\nEcho "Check '+str(n)+': $RC" >>HD0:Boot-Fixed.log')
|
||||
s=s.replace(' Execute S:User-Startup',' Echo "Monitors-result: $RC" >>HD0:Boot-Fixed.log\n Execute S:User-Startup')
|
||||
s=s.replace('C:LoadWB\n','C:CPU >HD0:CPU040.log\nC:Version 68040.library FULL >>HD0:CPU040.log\nC:LoadWB\n')
|
||||
s='Echo "Fixed boot audit" >HD0:Boot-Fixed.log\n'+s
|
||||
(base/'Startup-Sequence').write_bytes(s.encode('ascii'))
|
||||
(base/'User-Startup').write_bytes(Path('work/boot040/User-Startup.before').read_text().encode('ascii'))
|
||||
@@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
import zipfile,io
|
||||
p=Path('C:/Users/Public/Documents/Amiga Files/Titles/Systems/Alberto2 (Commodore-Amiga, 1992, Amiga).rp9')
|
||||
z=zipfile.ZipFile(io.BytesIO(p.read_bytes()))
|
||||
out=io.BytesIO()
|
||||
with zipfile.ZipFile(out,'w') as w:
|
||||
for i in z.infolist():
|
||||
data=z.read(i.filename)
|
||||
if i.filename=='rp9-manifest.xml':
|
||||
assert b'type="68030"' in data
|
||||
data=data.replace(b'type="68030"',b'type="68040"')
|
||||
w.writestr(i,data)
|
||||
p.write_bytes(out.getvalue())
|
||||
@@ -0,0 +1,16 @@
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @'
|
||||
using System;using System.IO;
|
||||
public class CliIcon {
|
||||
const int W=64,H=40;
|
||||
static void R(byte[,]p,int x,int y,int w,int h,byte c){for(int j=y;j<y+h;j++)for(int i=x;i<x+w;i++)p[j,i]=c;}
|
||||
static byte[,] P(bool sel){var p=new byte[H,W];R(p,3,3,59,35,2);R(p,1,1,60,35,3);R(p,2,2,58,33,0);R(p,3,3,56,6,3);R(p,4,10,54,23,2);R(p,5,4,2,2,2);R(p,8,4,2,2,2);R(p,11,4,2,2,2);R(p,7,14,2,2,1);R(p,9,16,2,2,1);R(p,7,18,2,2,1);R(p,13,19,7,1,3);R(p,7,24,27,1,3);R(p,7,27,18,1,3);R(p,38,24,12,1,0);R(p,38,27,8,1,0);if(sel){R(p,1,1,60,1,1);R(p,1,1,1,35,1);}return p;}
|
||||
static void U16(BinaryWriter w,int n){w.Write((byte)(n>>8));w.Write((byte)n);}static void U32(BinaryWriter w,int n){w.Write((byte)(n>>24));w.Write((byte)(n>>16));w.Write((byte)(n>>8));w.Write((byte)n);}static void S(BinaryWriter w,string s){var b=System.Text.Encoding.ASCII.GetBytes(s+"\0");U32(w,b.Length);w.Write(b);}
|
||||
static void Img(BinaryWriter w,byte[,]p){U16(w,0);U16(w,0);U16(w,W);U16(w,H);U16(w,2);w.Write(new byte[]{0,0,0,1,3,0,0,0,0,0});for(int q=0;q<2;q++)for(int y=0;y<H;y++)for(int x=0;x<W;x+=8){byte b=0;for(int i=0;i<8;i++)if((p[y,x+i]&(1<<q))!=0)b|=(byte)(128>>i);w.Write(b);}}
|
||||
public static void Make(string template,string output){var h=new byte[78];Array.Copy(File.ReadAllBytes(template),h,78);h[12]=0;h[13]=W;h[14]=0;h[15]=H;h[16]=0;h[17]=6;h[48]=4;foreach(int p in new[]{22,26,50,54}){for(int k=0;k<4;k++)h[p+k]=0;h[p+3]=1;}foreach(int p in new[]{44,66,70})for(int k=0;k<4;k++)h[p+k]=0;using(var f=File.Create(output))using(var w=new BinaryWriter(f)){w.Write(h);Img(w,P(false));Img(w,P(true));S(w,"SYS:System/CLI");U32(w,16);S(w,"WINDOW=VNC:80/90/900/580/Amber CLI/SHELL/CLOSE");S(w,"STACK=16384");S(w,"FROM=S:Shell-Startup");}}}
|
||||
'@
|
||||
[CliIcon]::Make('C:\Amiga\HD0\System\Shell.info','C:\Amiga\HD0\Utilities\WBDock2\CLI.info')
|
||||
[IO.File]::WriteAllText('C:\Amiga\HD0\Utilities\WBDock2\CLI','',[Text.Encoding]::ASCII)
|
||||
$p='C:\Amiga\HD0\Utilities\WBDock2\Amber.config'
|
||||
$s=[IO.File]::ReadAllText($p).Replace('SYS:System/Shell','SYS:Utilities/WBDock2/CLI')
|
||||
[IO.File]::WriteAllText($p,$s,[Text.Encoding]::ASCII)
|
||||
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
import struct
|
||||
|
||||
def chunk(tag,data):
|
||||
return tag+struct.pack('>I',len(data))+data+(b'\0' if len(data)%2 else b'')
|
||||
|
||||
def preview(src,dest):
|
||||
im=Image.open(src).convert('RGB').resize((320,256),Image.Resampling.LANCZOS).quantize(colors=64)
|
||||
w,h=im.size
|
||||
pixels=im.load()
|
||||
body=bytearray()
|
||||
for y in range(h):
|
||||
for plane in range(6):
|
||||
for x in range(0,w,8):
|
||||
body.append(sum(((pixels[x+i,y]>>plane)&1)<<(7-i) for i in range(8)))
|
||||
bmhd=struct.pack('>HHhhBBBBHBBhh',w,h,0,0,6,0,0,0,0,1,1,w,h)
|
||||
payload=b'ILBM'+chunk(b'BMHD',bmhd)+chunk(b'CMAP',bytes(im.getpalette()[:192]))+chunk(b'BODY',body)
|
||||
Path(dest).write_bytes(chunk(b'FORM',payload))
|
||||
|
||||
preview('work/igame/cannon-shot.png','C:/Amiga/WHDLoad/CannonFodderITA/igame.iff')
|
||||
preview('work/igame/pinball-shot.png','C:/Amiga/WHDLoad/PinballFantasies_v2.7_0025/PinballFntsies/igame.iff')
|
||||
@@ -0,0 +1,35 @@
|
||||
$ErrorActionPreference='Stop'
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @'
|
||||
using System;using System.IO;using System.Drawing;
|
||||
public class AmberClockIcon {
|
||||
const int W=48,H=48;
|
||||
static void Dot(byte[,]p,int x,int y,byte c){if(x>=0&&x<W&&y>=0&&y<H)p[y,x]=c;}
|
||||
static void Line(byte[,]p,int x0,int y0,int x1,int y1,byte c){int dx=Math.Abs(x1-x0),sx=x0<x1?1:-1,dy=-Math.Abs(y1-y0),sy=y0<y1?1:-1,e=dx+dy;while(true){Dot(p,x0,y0,c);if(x0==x1&&y0==y1)break;int e2=2*e;if(e2>=dy){e+=dy;x0+=sx;}if(e2<=dx){e+=dx;y0+=sy;}}}
|
||||
static byte[,] Pixels(bool selected){var p=new byte[H,W];
|
||||
for(int y=4;y<46;y++)for(int x=5;x<46;x++)if((x-25)*(x-25)+(y-25)*(y-25)<=400)Dot(p,x,y,2);
|
||||
for(int y=1;y<=43;y++)for(int x=2;x<=44;x++){double d=Math.Sqrt((x-23)*(x-23)+(y-22)*(y-22));if(d<=21){byte c=2;if(d>19)c=(byte)((x+y<45||selected)?1:2);else if(d>16)c=3;Dot(p,x,y,c);}}
|
||||
for(int t=0;t<12;t++){double a=t*Math.PI/6;int r0=t%3==0?12:14;Line(p,23+(int)Math.Round(Math.Sin(a)*r0),22-(int)Math.Round(Math.Cos(a)*r0),23+(int)Math.Round(Math.Sin(a)*15),22-(int)Math.Round(Math.Cos(a)*15),(byte)(t%3==0?1:3));}
|
||||
Line(p,23,22,15,15,1);Line(p,23,23,15,16,1);
|
||||
Line(p,23,22,34,13,1);Line(p,24,22,35,13,1);
|
||||
Line(p,23,22,26,35,3);Line(p,23,22,22,18,3);
|
||||
Dot(p,23,22,1);Dot(p,24,22,1);Dot(p,23,23,1);
|
||||
for(int y=43;y<=45;y++)for(int x=15;x<=31;x++)Dot(p,x,y,(byte)(y==43?3:2));
|
||||
Line(p,12,46,34,46,3);Line(p,14,45,32,45,1);
|
||||
return p;}
|
||||
static int Word(byte[]b,int o){return b[o]*256+b[o+1];}
|
||||
static uint Long(byte[]b,int o){return ((uint)b[o]<<24)|((uint)b[o+1]<<16)|((uint)b[o+2]<<8)|b[o+3];}
|
||||
static void U16(BinaryWriter w,int v){w.Write((byte)(v>>8));w.Write((byte)v);}
|
||||
static void Image(BinaryWriter w,byte[,]p){U16(w,0);U16(w,0);U16(w,W);U16(w,H);U16(w,2);w.Write(new byte[]{0,0,0,1,3,0,0,0,0,0});for(int plane=0;plane<2;plane++)for(int y=0;y<H;y++)for(int b=0;b<6;b++){byte v=0;for(int bit=0;bit<8;bit++)if((p[y,b*8+bit]&(1<<plane))!=0)v|=(byte)(128>>bit);w.Write(v);}}
|
||||
public static void Make(string source,string output,string preview){var old=File.ReadAllBytes(source);int end=78;if(Long(old,66)!=0)throw new Exception("Clock icon unexpectedly has drawer data");foreach(int ptr in new[]{22,26})if(Long(old,ptr)!=0){bool next;do{int width=Word(old,end+4),height=Word(old,end+6),depth=Word(old,end+8);next=Long(old,end+16)!=0;end+=20+((width+15)/16)*2*height*depth;}while(next);}
|
||||
var header=new byte[78];Array.Copy(old,header,78);header[12]=0;header[13]=W;header[14]=0;header[15]=H;header[16]=0;header[17]=6;foreach(int ptr in new[]{22,26}){for(int k=0;k<4;k++)header[ptr+k]=0;header[ptr+3]=1;}for(int k=0;k<4;k++)header[44+k]=0;
|
||||
using(var f=File.Create(output))using(var w=new BinaryWriter(f)){w.Write(header);Image(w,Pixels(false));Image(w,Pixels(true));w.Write(old,end,old.Length-end);}
|
||||
Color[]colors={Color.FromArgb(53,50,44),Color.FromArgb(228,213,181),Color.FromArgb(25,23,19),Color.FromArgb(169,111,39)};
|
||||
var pix=Pixels(false);using(var im=new Bitmap(W*6,H*6)){using(var g=Graphics.FromImage(im)){for(int y=0;y<H;y++)for(int x=0;x<W;x++)using(var br=new SolidBrush(colors[pix[y,x]]))g.FillRectangle(br,x*6,y*6,6,6);}im.Save(preview);}
|
||||
}}
|
||||
'@
|
||||
$path='C:\Amiga\HD0\Utilities\Clock.info'
|
||||
Copy-Item $path 'C:\Amiga\backup-riparazione-20261030\Clock-prima-icona-ambra.info'
|
||||
[AmberClockIcon]::Make($path,'C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\Clock-Amber.info','C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\Clock-Amber-preview.png')
|
||||
Copy-Item 'C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\Clock-Amber.info' $path
|
||||
Copy-Item $path 'C:\Amiga\Snapshots\Alberto2-Amber\HD0\Utilities\Clock.info'
|
||||
@@ -0,0 +1,40 @@
|
||||
$ErrorActionPreference='Stop'
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @'
|
||||
using System;using System.IO;using System.Drawing;
|
||||
public class RamIcon {
|
||||
const int W=64,H=32;
|
||||
static void Rect(byte[,] p,int x,int y,int w,int h,byte c){for(int yy=y;yy<y+h;yy++)for(int xx=x;xx<x+w;xx++)p[yy,xx]=c;}
|
||||
static byte[,] Pixels(bool selected){var p=new byte[H,W];
|
||||
// A compact vintage SIMM: stepped PCB silhouette, four ICs, gold contacts.
|
||||
Rect(p,3,6,58,20,2);Rect(p,5,4,54,24,2);
|
||||
Rect(p,5,5,54,1,1);Rect(p,4,7,1,16,1);
|
||||
Rect(p,6,7,52,16,0);Rect(p,6,22,52,2,3);
|
||||
Rect(p,58,7,2,17,3);
|
||||
for(int chip=0;chip<4;chip++){int x=9+chip*12;
|
||||
Rect(p,x,9,10,11,2);Rect(p,x+1,9,8,1,(byte)(selected?3:1));
|
||||
Rect(p,x+1,10,8,8,2);Rect(p,x+2,12,4,1,0);
|
||||
for(int pin=0;pin<3;pin++){Rect(p,x-1,11+pin*3,1,1,3);Rect(p,x+10,11+pin*3,1,1,3);}
|
||||
}
|
||||
for(int x=9;x<=54;x+=4){if(x>=29&&x<=33)continue;Rect(p,x,25,2,5,3);Rect(p,x,25,1,4,(byte)(selected?1:3));}
|
||||
Rect(p,29,24,5,6,2);Rect(p,30,25,3,5,0);
|
||||
Rect(p,6,25,2,2,1);Rect(p,56,25,2,2,1);
|
||||
return p;}
|
||||
static void U16(BinaryWriter w,int v){w.Write((byte)(v>>8));w.Write((byte)v);}
|
||||
static void Image(BinaryWriter w,byte[,] p){U16(w,0);U16(w,0);U16(w,W);U16(w,H);U16(w,2);w.Write(new byte[]{0,0,0,1});w.Write((byte)3);w.Write((byte)0);w.Write(new byte[4]);for(int plane=0;plane<2;plane++)for(int y=0;y<H;y++)for(int b=0;b<8;b++){byte v=0;for(int bit=0;bit<8;bit++)if((p[y,b*8+bit]&(1<<plane))!=0)v|=(byte)(128>>bit);w.Write(v);}}
|
||||
public static void Make(string original,string output,string preview){var old=File.ReadAllBytes(original);var header=new byte[134];Array.Copy(old,header,134);
|
||||
header[12]=0;header[13]=W;header[14]=0;header[15]=H;header[16]=0;header[17]=6;
|
||||
for(int o=22;o<=26;o+=4){for(int k=0;k<4;k++)header[o+k]=0;header[o+3]=1;}
|
||||
foreach(int o in new[]{44,50,54,70})for(int k=0;k<4;k++)header[o+k]=0;
|
||||
header[58]=0;header[59]=0;header[60]=0;header[61]=29;
|
||||
header[62]=0;header[63]=0;header[64]=0;header[65]=18;
|
||||
var normal=Pixels(false);using(var f=File.Create(output))using(var w=new BinaryWriter(f)){w.Write(header);Image(w,normal);Image(w,Pixels(true));}
|
||||
Color[] colors={Color.FromArgb(53,50,44),Color.FromArgb(228,213,181),Color.FromArgb(25,23,19),Color.FromArgb(169,111,39)};
|
||||
using(var im=new Bitmap(W*6,H*6)){using(var g=Graphics.FromImage(im)){for(int y=0;y<H;y++)for(int x=0;x<W;x++)using(var brush=new SolidBrush(colors[normal[y,x]]))g.FillRectangle(brush,x*6,y*6,6,6);}im.Save(preview);}
|
||||
}}
|
||||
'@
|
||||
$old='C:\Amiga\HD0\Prefs\Env-Archive\Sys\def_RAM.info'
|
||||
Copy-Item $old 'C:\Amiga\backup-riparazione-20261030\RAM-prima-modulo-ambra.info'
|
||||
[RamIcon]::Make($old,'C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\RamDisk-Amber.info','C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\RamDisk-Amber-preview.png')
|
||||
Copy-Item 'C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\RamDisk-Amber.info' $old
|
||||
Copy-Item $old 'C:\Amiga\Snapshots\Alberto2-Amber\HD0\Prefs\Env-Archive\Sys\def_RAM.info'
|
||||
@@ -0,0 +1,48 @@
|
||||
$ErrorActionPreference='Stop'
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$root='C:\Amiga'
|
||||
$backup='C:\Amiga\backup-riparazione-20261030\drawer-prima-riordino.zip'
|
||||
if(Test-Path -LiteralPath $backup){throw 'Backup già presente: non sovrascrivo'}
|
||||
$files=@(foreach($volume in @('HD0','Share','WHDLoad')){Get-ChildItem -LiteralPath (Join-Path $root $volume) -Recurse -File -Filter '*.info'})
|
||||
$zip=[IO.Compression.ZipFile]::Open($backup,'Create')
|
||||
try{foreach($f in $files){[IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip,$f.FullName,$f.FullName.Substring($root.Length+1).Replace('\','/'))|Out-Null}}finally{$zip.Dispose()}
|
||||
function Put16($b,$o,$v){$b[$o]=[byte](($v -shr 8)-band 255);$b[$o+1]=[byte]($v-band 255)}
|
||||
function Put32($b,$o,$v){$b[$o]=[byte](($v-shr 24)-band 255);$b[$o+1]=[byte](($v-shr 16)-band 255);$b[$o+2]=[byte](($v-shr 8)-band 255);$b[$o+3]=[byte]($v-band 255)}
|
||||
$records=@(foreach($f in $files){
|
||||
$b=[IO.File]::ReadAllBytes($f.FullName)
|
||||
if($b.Length-lt 78 -or $b[0]-ne 227 -or $b[1]-ne 16){continue}
|
||||
$object=$f.FullName.Substring(0,$f.FullName.Length-5)
|
||||
$isDisk=$f.Name-ieq 'Disk.info'
|
||||
if(-not $isDisk -and -not(Test-Path -LiteralPath $object)){continue}
|
||||
$drawerPointer=($b[66]-bor $b[67]-bor $b[68]-bor $b[69])-ne 0
|
||||
[pscustomobject]@{Path=$f.FullName;Name=[IO.Path]::GetFileName($object);Parent=$f.DirectoryName;IsDisk=$isDisk;IsDirectory=(Test-Path -LiteralPath $object -PathType Container);Bytes=$b;Original=$b.Clone();Drawer=($drawerPointer -and $b.Length-ge 134 -and $b[48]-in @(1,2));W=($b[12]*256+$b[13]);H=($b[14]*256+$b[15]);Changed=$false}
|
||||
})
|
||||
$leftOut=@{}
|
||||
foreach($v in @('HD0','Share','WHDLoad')){
|
||||
$bp=Join-Path $root "$v\.backdrop"
|
||||
if(Test-Path -LiteralPath $bp){foreach($line in [IO.File]::ReadAllLines($bp)){if($line.StartsWith(':')){$leftOut[(Join-Path $root ($v+'\'+$line.Substring(1).Replace('/','\')+'.info'))]=$true}}}
|
||||
}
|
||||
$groups=0
|
||||
foreach($group in ($records|Where-Object {-not $_.IsDisk -and -not $leftOut.ContainsKey($_.Path)}|Group-Object Parent)){
|
||||
$ordered=@($group.Group|Sort-Object @{Expression={-not $_.IsDirectory}},Name)
|
||||
$cellW=150;$cellH=88
|
||||
foreach($r in $ordered){$cellW=[Math]::Max($cellW,[Math]::Max($r.Name.Length*8+24,$r.W+24));$cellH=[Math]::Max($cellH,$r.H+30)}
|
||||
$columns=[Math]::Max(1,[Math]::Floor(940/$cellW));$i=0
|
||||
foreach($r in $ordered){Put32 $r.Bytes 58 (20+($i%$columns)*$cellW);Put32 $r.Bytes 62 (14+[Math]::Floor($i/$columns)*$cellH);$r.Changed=$true;$i++}
|
||||
$groups++
|
||||
}
|
||||
$windows=0
|
||||
foreach($r in $records){if($r.Drawer){
|
||||
Put16 $r.Bytes 78 80;Put16 $r.Bytes 80 55;Put16 $r.Bytes 82 1000;Put16 $r.Bytes 84 720
|
||||
Put32 $r.Bytes 126 0;Put32 $r.Bytes 130 0
|
||||
$r.Changed=$true;$windows++
|
||||
}}
|
||||
$allowed=@(58..65)+@(78..85)+@(126..133)
|
||||
$changed=0
|
||||
foreach($r in $records|Where-Object Changed){
|
||||
for($i=0;$i-lt $r.Bytes.Length;$i++){if($r.Bytes[$i]-ne $r.Original[$i] -and $i-notin $allowed){throw "Modifica fuori dai campi posizione: $($r.Path), $i"}}
|
||||
[IO.File]::WriteAllBytes($r.Path,$r.Bytes)
|
||||
if(-not [Linq.Enumerable]::SequenceEqual([byte[]][IO.File]::ReadAllBytes($r.Path),[byte[]]$r.Bytes)){throw "Verifica scrittura fallita: $($r.Path)"}
|
||||
$changed++
|
||||
}
|
||||
[pscustomobject]@{Backup=$backup;BackupIcons=$files.Count;OrderedDirectories=$groups;SavedWindows=$windows;UpdatedIcons=$changed}|ConvertTo-Json
|
||||
@@ -0,0 +1,62 @@
|
||||
$ErrorActionPreference='Stop'
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
$src=[Drawing.Image]::FromFile('C:\Users\tilar\.codex\generated_images\01a18c54-cbcf-72e0-985c-3c5d721eb505\exec-8c844b57-8586-4f14-9cd4-3035f1ad4f34.png')
|
||||
$dst=[Drawing.Bitmap]::new(1280,1024)
|
||||
$g=[Drawing.Graphics]::FromImage($dst)
|
||||
$g.InterpolationMode=[Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||
$g.DrawImage($src,0,0,1280,1024)
|
||||
$png='C:\Amiga\HD0\Prefs\Presets\Amiga-Amber-1280x1024.png'
|
||||
$dst.Save($png,[Drawing.Imaging.ImageFormat]::Png)
|
||||
$g.Dispose();$dst.Dispose();$src.Dispose()
|
||||
Copy-Item $png 'C:\Users\tilar\Documents\Codex\2026-10-30\c\outputs\Amiga-Amber-1280x1024.png'
|
||||
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @'
|
||||
using System;using System.IO;using System.Drawing;
|
||||
public class ThemeIFF{
|
||||
static void U16(BinaryWriter w,int x){w.Write((byte)(x>>8));w.Write((byte)x);}
|
||||
static void U32(BinaryWriter w,int x){w.Write((byte)(x>>24));w.Write((byte)(x>>16));w.Write((byte)(x>>8));w.Write((byte)x);}
|
||||
static void Tag(BinaryWriter w,string s){w.Write(System.Text.Encoding.ASCII.GetBytes(s));}
|
||||
public static void Save(string input,string output){using(var b=new Bitmap(input))using(var f=File.Create(output))using(var w=new BinaryWriter(f)){int row=((b.Width+15)/16)*2,size=row*b.Height*24;Tag(w,"FORM");U32(w,4+28+8+size);Tag(w,"ILBM");Tag(w,"BMHD");U32(w,20);U16(w,b.Width);U16(w,b.Height);U16(w,0);U16(w,0);w.Write(new byte[]{24,0,0,0});U16(w,0);w.Write(new byte[]{1,1});U16(w,b.Width);U16(w,b.Height);Tag(w,"BODY");U32(w,size);for(int y=0;y<b.Height;y++){var colors=new Color[b.Width];for(int x=0;x<b.Width;x++)colors[x]=b.GetPixel(x,y);for(int p=0;p<24;p++){var data=new byte[row];for(int x=0;x<b.Width;x++){int v=p<8?colors[x].R:p<16?colors[x].G:colors[x].B;if((v&(1<<(p%8)))!=0)data[x/8]|=(byte)(128>>(x%8));}w.Write(data);}}}}
|
||||
}
|
||||
'@
|
||||
[ThemeIFF]::Save($png,'C:\Amiga\HD0\Prefs\Presets\Amiga-Amber-1280x1024.iff')
|
||||
function Put16($b,$o,$v){$b[$o]=[byte](($v-shr 8)-band 255);$b[$o+1]=[byte]($v-band 255)}
|
||||
function Put32($b,$o,$v){$b[$o]=[byte](($v-shr 24)-band 255);$b[$o+1]=[byte](($v-shr 16)-band 255);$b[$o+2]=[byte](($v-shr 8)-band 255);$b[$o+3]=[byte]($v-band 255)}
|
||||
function U32($b,$o){return [long]$b[$o]*16777216+[long]$b[$o+1]*65536+[long]$b[$o+2]*256+$b[$o+3]}
|
||||
# Keep the existing pattern behavior, replace only the pathname and chunk lengths.
|
||||
$p='C:\Amiga\HD0\Prefs\Env-Archive\Sys\WBPattern.prefs';$old=[IO.File]::ReadAllBytes($p)
|
||||
$name=[Text.Encoding]::ASCII.GetBytes('HD0:Prefs/Presets/Amiga-Amber-1280x1024.iff'+[char]0)
|
||||
$len=58+$name.Length;$b=[byte[]]::new($len+($len%2));[Array]::Copy($old,$b,58);[Array]::Copy($name,0,$b,58,$name.Length)
|
||||
Put32 $b 4 ($b.Length-8);Put32 $b 30 ($len-34);Put16 $b 56 $name.Length
|
||||
[IO.File]::WriteAllBytes($p,$b)
|
||||
# PalettePrefs PALT: 16 reserved bytes, 32 four-color pens, 32 eight-color pens, ColorSpec table.
|
||||
$b=[IO.File]::ReadAllBytes('C:\Users\Public\Documents\Amiga Files\Shared\dir\System\Prefs\Env-Archive\Sys\palette.prefs')
|
||||
$colors=@('34322C','E4D5B5','8B8170','68431C','151410','FFBC55','B88A49','C0B29A')
|
||||
for($i=0;$i-lt 8;$i++){for($c=0;$c-lt 3;$c++){$v=[Convert]::ToInt32($colors[$i].Substring($c*2,2),16)*257;Put16 $b (178+$i*8+2+$c*2) $v}}
|
||||
$pens=@(4,1,1,2,4,3,1,0,5,1,0,4)
|
||||
for($i=0;$i-lt $pens.Count;$i++){Put16 $b (114+$i*2) $pens[$i]}
|
||||
[IO.File]::WriteAllBytes('C:\Amiga\HD0\Prefs\Env-Archive\Sys\Palette.prefs',$b)
|
||||
function Position($path,$x,$y){$b=[IO.File]::ReadAllBytes($path);Put32 $b 58 $x;Put32 $b 62 $y;[IO.File]::WriteAllBytes($path,$b)}
|
||||
Position 'C:\Amiga\HD0\Disk.info' 20 24
|
||||
Position 'C:\Amiga\Share\Disk.info' 20 132
|
||||
Position 'C:\Amiga\WHDLoad\Disk.info' 20 240
|
||||
Position 'C:\Amiga\HD0\WookieChat_OS3.info' 150 24
|
||||
Position 'C:\Amiga\HD0\Utilities\Clock.info' 150 132
|
||||
Position 'C:\Amiga\HD0\Utilities\HippoPlayer\HiP.info' 150 240
|
||||
# Update Clock's native tooltypes while retaining its icon graphics and extended data.
|
||||
$p='C:\Amiga\HD0\Utilities\Clock.info';$b=[IO.File]::ReadAllBytes($p);$o=78
|
||||
if((U32 $b 66)-ne 0){$o+=56}
|
||||
foreach($ptr in @(22,26)){if((U32 $b $ptr)-ne 0){do{$w=$b[$o+4]*256+$b[$o+5];$h=$b[$o+6]*256+$b[$o+7];$d=$b[$o+8]*256+$b[$o+9];$next=(U32 $b ($o+16))-ne 0;$o+=20+([int][Math]::Ceiling($w/16))*2*$h*$d}while($next)}}
|
||||
if((U32 $b 50)-ne 0){$o+=4+(U32 $b $o)}
|
||||
$start=$o;$types=@()
|
||||
if((U32 $b 54)-ne 0){$count=(U32 $b $o)/4-1;$o+=4;for($i=0;$i-lt $count;$i++){$l=U32 $b $o;$o+=4;$types+=[Text.Encoding]::GetEncoding(28591).GetString($b,$o,$l).TrimEnd([char]0);$o+=$l}}
|
||||
$types=@($types|Where-Object {$_ -notmatch '^\(?(DIGITAL|ANALOG|24HOUR|SECONDS|DATE|LEFT|TOP|WIDTH|HEIGHT)(=|\)|$)'})+@('DIGITAL','24HOUR','SECONDS','LEFT=1040','TOP=28','WIDTH=220','HEIGHT=56')
|
||||
$ms=[IO.MemoryStream]::new();$ms.Write($b,0,$start)
|
||||
$tmp=[byte[]]::new(4);Put32 $tmp 0 (($types.Count+1)*4);$ms.Write($tmp,0,4)
|
||||
foreach($type in $types){$s=[Text.Encoding]::GetEncoding(28591).GetBytes($type+[char]0);Put32 $tmp 0 $s.Length;$ms.Write($tmp,0,4);$ms.Write($s,0,$s.Length)}
|
||||
$ms.Write($b,$o,$b.Length-$o);$out=$ms.ToArray();$ms.Dispose();Put32 $out 54 1;[IO.File]::WriteAllBytes($p,$out)
|
||||
# A single desktop widget, delayed until IPrefs has completed the screen setup.
|
||||
[IO.File]::WriteAllText('C:\Amiga\HD0\S\Amber-Desktop',"Wait 6 SECS`nRun >NIL: SYS:Utilities/Clock DIGITAL 24HOUR SECONDS LEFT=1040 TOP=28 WIDTH=220 HEIGHT=56`n",[Text.Encoding]::ASCII)
|
||||
$p='C:\Amiga\HD0\S\Startup-Sequence';$s=[IO.File]::ReadAllText($p)
|
||||
if($s-notmatch 'Execute S:Amber-Desktop'){$s=$s.Replace('C:LoadWB',"C:LoadWB`nRun >NIL: Execute S:Amber-Desktop")}
|
||||
[IO.File]::WriteAllText($p,$s,[Text.Encoding]::ASCII)
|
||||
Write-Output 'Wallpaper IFF/PNG, palette, desktop positions and digital clock configured.'
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal static class IrcTlsBridge
|
||||
{
|
||||
const int LocalPort = 16697;
|
||||
const string RemoteHost = "irc.tilaro.net";
|
||||
const int RemotePort = 6697;
|
||||
static readonly object LogLock = new object();
|
||||
static readonly string LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bridge.log");
|
||||
static readonly SemaphoreSlim Slots = new SemaphoreSlim(4);
|
||||
static int ConnectionId;
|
||||
|
||||
static void Log(string message)
|
||||
{
|
||||
lock (LogLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(LogPath) && new FileInfo(LogPath).Length > 262144)
|
||||
File.Move(LogPath, LogPath + "." + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + ".old");
|
||||
File.AppendAllText(LogPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz") + " " + message + Environment.NewLine);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
bool created;
|
||||
using (var mutex = new Mutex(true, "Local\\TilaroIrcTlsBridge16697", out created))
|
||||
{
|
||||
if (!created) return;
|
||||
try { Run().GetAwaiter().GetResult(); }
|
||||
catch (Exception ex) { Log("STOP " + ex.Message); }
|
||||
}
|
||||
}
|
||||
|
||||
static async Task Run()
|
||||
{
|
||||
var listener = new TcpListener(IPAddress.Loopback, LocalPort);
|
||||
listener.Start(8);
|
||||
Log("START 127.0.0.1:" + LocalPort + " -> " + RemoteHost + ":" + RemotePort + " TLS; certificate validation enabled");
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var client = await listener.AcceptTcpClientAsync();
|
||||
if (!Slots.Wait(0)) { client.Close(); continue; }
|
||||
Handle(client);
|
||||
}
|
||||
}
|
||||
finally { listener.Stop(); }
|
||||
}
|
||||
|
||||
static async void Handle(TcpClient client)
|
||||
{
|
||||
int id = Interlocked.Increment(ref ConnectionId);
|
||||
try
|
||||
{
|
||||
using (client)
|
||||
using (var remote = new TcpClient())
|
||||
{
|
||||
client.NoDelay = true;
|
||||
remote.NoDelay = true;
|
||||
var connect = remote.ConnectAsync(RemoteHost, RemotePort);
|
||||
if (await Task.WhenAny(connect, Task.Delay(15000)) != connect)
|
||||
throw new TimeoutException("Remote TCP connection timed out");
|
||||
await connect;
|
||||
using (var tls = new SslStream(remote.GetStream(), false))
|
||||
{
|
||||
// The default validation checks both trust and the target hostname.
|
||||
var authenticate = tls.AuthenticateAsClientAsync(RemoteHost, null, SslProtocols.Tls12, true);
|
||||
if (await Task.WhenAny(authenticate, Task.Delay(20000)) != authenticate)
|
||||
throw new TimeoutException("TLS handshake timed out");
|
||||
await authenticate;
|
||||
Log("CONNECTED #" + id + " TLS=" + tls.SslProtocol + " certificate=" + tls.RemoteCertificate.Subject);
|
||||
var local = client.GetStream();
|
||||
var upstream = local.CopyToAsync(tls);
|
||||
var downstream = tls.CopyToAsync(local);
|
||||
var finished = await Task.WhenAny(upstream, downstream);
|
||||
client.Close();
|
||||
remote.Close();
|
||||
try { await finished; } catch (IOException) { }
|
||||
try { await upstream; } catch { }
|
||||
try { await downstream; } catch { }
|
||||
}
|
||||
}
|
||||
Log("CLOSED #" + id);
|
||||
}
|
||||
catch (Exception ex) { Log("ERROR #" + id + " " + ex.GetBaseException().Message); }
|
||||
finally { client.Dispose(); Slots.Release(); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
Ponte IRC per WookieChat
|
||||
WookieChat: server 127.0.0.1, porta 16697, nel gruppo Alberto.
|
||||
Destinazione: irc.tilaro.net:6697, TLS 1.2 con verifica del certificato e del nome.
|
||||
Accetta connessioni solo dal PC locale. Nessuna porta LAN viene aperta.
|
||||
Avvio automatico: registro utente HKCU\Software\Microsoft\Windows\CurrentVersion\Run, valore TilaroIrcTlsBridge.
|
||||
Log tecnico: bridge.log, senza contenuti delle chat o password.
|
||||
Per disattivarlo: rimuovere il valore di avvio automatico e terminare IrcTlsBridge.exe.
|
||||
|
||||
Aggiornamento 2026-11-01: avvio tramite attivita pianificata 'Amiga IRC TLS Bridge', al login dell'utente RADIO\tilar con ritardo di 10 secondi. Nessun limite di durata. Riavvio su errore (3 tentativi). Il precedente valore Run resta come avvio di riserva; il mutex impedisce istanze duplicate.
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal static class MailTlsBridge
|
||||
{
|
||||
const int LocalPort = 1465;
|
||||
const string RemoteHost = "smtp.gmail.com";
|
||||
const int RemotePort = 465;
|
||||
static readonly object LogLock = new object();
|
||||
static readonly string LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bridge.log");
|
||||
static readonly SemaphoreSlim Slots = new SemaphoreSlim(4);
|
||||
static int ConnectionId;
|
||||
|
||||
static void Log(string message)
|
||||
{
|
||||
lock (LogLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(LogPath) && new FileInfo(LogPath).Length > 262144)
|
||||
File.Move(LogPath, LogPath + "." + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + ".old");
|
||||
File.AppendAllText(LogPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz") + " " + message + Environment.NewLine);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
bool created;
|
||||
using (var mutex = new Mutex(true, "Local\\TilaroMailTlsBridge1465", out created))
|
||||
{
|
||||
if (!created) return;
|
||||
try { Run().GetAwaiter().GetResult(); }
|
||||
catch (Exception ex) { Log("STOP " + ex.Message); }
|
||||
}
|
||||
}
|
||||
|
||||
static async Task Run()
|
||||
{
|
||||
var listener = new TcpListener(IPAddress.Loopback, LocalPort);
|
||||
listener.Start(8);
|
||||
Log("START 127.0.0.1:" + LocalPort + " -> " + RemoteHost + ":" + RemotePort + " TLS; certificate validation enabled");
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var client = await listener.AcceptTcpClientAsync();
|
||||
if (!Slots.Wait(0)) { client.Close(); continue; }
|
||||
Handle(client);
|
||||
}
|
||||
}
|
||||
finally { listener.Stop(); }
|
||||
}
|
||||
|
||||
static async void Handle(TcpClient client)
|
||||
{
|
||||
int id = Interlocked.Increment(ref ConnectionId);
|
||||
try
|
||||
{
|
||||
using (client)
|
||||
using (var remote = new TcpClient())
|
||||
{
|
||||
client.NoDelay = true;
|
||||
remote.NoDelay = true;
|
||||
var connect = remote.ConnectAsync(RemoteHost, RemotePort);
|
||||
if (await Task.WhenAny(connect, Task.Delay(15000)) != connect)
|
||||
throw new TimeoutException("Remote TCP connection timed out");
|
||||
await connect;
|
||||
using (var tls = new SslStream(remote.GetStream(), false))
|
||||
{
|
||||
// The default validation checks both trust and the target hostname.
|
||||
var authenticate = tls.AuthenticateAsClientAsync(RemoteHost, null, SslProtocols.Tls12, true);
|
||||
if (await Task.WhenAny(authenticate, Task.Delay(20000)) != authenticate)
|
||||
throw new TimeoutException("TLS handshake timed out");
|
||||
await authenticate;
|
||||
Log("CONNECTED #" + id + " TLS=" + tls.SslProtocol + " certificate=" + tls.RemoteCertificate.Subject);
|
||||
var local = client.GetStream();
|
||||
var upstream = local.CopyToAsync(tls);
|
||||
var downstream = tls.CopyToAsync(local);
|
||||
var finished = await Task.WhenAny(upstream, downstream);
|
||||
client.Close();
|
||||
remote.Close();
|
||||
try { await finished; } catch (IOException) { }
|
||||
try { await upstream; } catch { }
|
||||
try { await downstream; } catch { }
|
||||
}
|
||||
}
|
||||
Log("CLOSED #" + id);
|
||||
}
|
||||
catch (Exception ex) { Log("ERROR #" + id + " " + ex.GetBaseException().Message); }
|
||||
finally { client.Dispose(); Slots.Release(); }
|
||||
}
|
||||
}
|
||||
Loaded 100 of 347 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user