Option explicit
Option default none

If Instr(MM.DEVICE$,"HDMI")<1 Then Print "only for HDMI-devices": End

Dim fl$,fpa$ 'filenames: bmp and palette
Dim integer DimPal(15,4)
Dim integer d
MODE 3

'show all bmp-files with a pal-file(same title) in current dir
Do
  fl$ = Dir$("*.bmp",FILE)
  Do While fl$<>""
    fpa$=Mid$(fl$,1,Len(fl$)-3)+"pal"
    If MM.Info(EXISTS FILE fpa$) Then
      For d = 3 To 0 Step -1'fade out
       SetPal(d)
       Pause 50
      Next d
      LoadMap(fpa$)
      Load image fl$
      For d = 1 To 4'fade in
        SetPal(d)
        Pause 40
      Next d
    Else
      Map reset
      Load image fl$
    End If
    Pause 2000
    fl$=Dir$()
  Loop
Loop 'end main loop

'- subs ----------------------------
Sub LoadMap(fn As string)
'load a pal-file exported by IrfanView: Image/Palette/Export Palette
' and set the Pico-MAP with this values
  Local integer i,s1,s2,r,g,b
  Local string tStr

  Open fn For input As #1      'open for reading
   Seek #1,1                   'goto first char
   For i=0 To 2: Line Input #1,tStr: Next 'step over first 3 lines
   For i=0 To 15'
    Line Input #1,tStr         'read line by line
    s1= Instr(   1,tStr," ")   'first space position
    If s1>0 Then
      s2= Instr(s1+1,tStr," ") 'second space position
      r = Val(Mid$(tStr,1,s1-1))
      g = Val(Mid$(tStr,s1+1,s2-s1))
      b = Val(Mid$(tStr,s2+1))
      DimPal(i,4)=RGB(r,g,b)   'save new color
    End If
   Next
  Close #1

  For i = 3 To 0 Step-1        'calc colors for dimming
    For b = 0 To 15
      DimPal(b,i)=(DimPal(b,i+1) And &hFEFEFE)>>1'mask lsb then mov right(/2)
    Next b
  Next i
End Sub 'LoadMap

Sub SetPal(idx As integer)
'idx: 0-4
Local integer i
  For i = 0 To 15
    Map(i)=DimPal(i,idx)
  Next i
  Map set
End Sub
