Prism Paint 256 colors palette load

GFA BASIC-related articles in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
mjvans
Atari User
Atari User
Posts: 34
Joined: Thu Dec 31, 2015 2:08 pm
Location: Netherlands
Contact:

Prism Paint 256 colors palette load

Postby mjvans » Sat Jan 30, 2016 6:28 pm

Hi,
I want to load an uncompressed 640x480x256c prismpaint .PNT file on a Falcon030.
I made the PNT loader years ago and for 16 colors it worked ok. And after switching from the desktop to 256 colors I could load a 256color pnt.
Now I learned something new: the program switches video mode to 640x480x256c and at the end goes back to the video mode where it started.
(many thanks to the Simon Sunnyboy listing of simple 256 color demo)
When switching from 16 to 256 colors you cant use setcolor from the VDI because it still thinks we are in 16 colors right?
So we use Xbios 94 or just fill the palette registers at &HFFFF9800 as in this example.
Whatever I try there are some colors not right. Not only in this test picture.
Prism Paint and Imagecopy show the pictures right.
What am I doing wrong?

PNT256F.GFA:

Image

Prism Paint:

Image

Code: Select all

' Prismpaint 256 kleuren 640x480 plaatje laden
'               by mjvans
'        WARNING FALCON only video mode switching!!
' Falcon video info:  STcomputer 5/1993 p84
'
'
'
err!=FALSE
ON ERROR GOSUB error_handler
ON BREAK GOSUB endit
'
RESERVE 50000
FILESELECT "\*.PNT","",filenaam$
IF filenaam$>""
  INLINE palette%,1024
  super%=GEMDOS(32,L:0)                            ! go SUPERVISOR
  resol&=XBIOS(88,W:-1)                            ! save old resolution
  old_phys%=XBIOS(2)                               ! save old screen
  buffer%=MALLOC(308224)                           ! 640x480 + palette 1024
  monitor%=XBIOS(89)                               ! what sort of display?
  image%=buffer%+1024
  IF monitor%=2
    vga!=TRUE
    rgb!=FALSE
    ~XBIOS(5,L:image%,L:image%,W:3,W:&X111011)   ! switch to VGA: 640x480 256c.
    yoffset%=20
  ELSE
    rgb!=TRUE
    vga!=FALSE
    ~XBIOS(5,L:image%,L:image%,W:3,W:&X10010111) ! RGB/TV:  640x400 256c.
    yoffset%=0
  ENDIF
  BMOVE &HFFFF9800,palette%,1024
  OUT 4,18                                       ! wat is dit?
  '
  prismpaint(filenaam$)                          ! laad plaatje
  ~INP(2)
  einde
  '
ELSE
  ' nothing selected program end
ENDIF
' ********************* EINDE **********
'  cant use VDI setcolor after change video mode
PROCEDURE vdi_setcolor(index&,r&,g&,b&)
  CONTRL(0)=14                                   ! PROFIBUCH p225
  CONTRL(1)=FALSE
  CONTRL(3)=4
  CONTRL(6)=V~H
  INTIN(0)=index&
  INTIN(1)=r&
  INTIN(2)=g&
  INTIN(3)=b&
  VDISYS
RETURN
'
'          set_color by Simon Sunnyboy
'          put colors directly in the registers
'
PROCEDURE set_color(tel&,ro&,gr&,bl&)
  LOCAL ro$,gr$,bl$
  ro$=STRING$(2-LEN(HEX$(ro&)),"0")+HEX$(ro&)            ! red
  gr$=STRING$(2-LEN(HEX$(gr&)),"0")+HEX$(gr&)            ! green
  bl$=STRING$(2-LEN(HEX$(bl&)),"0")+HEX$(bl&)            ! blue
  {ADD(&HFFFF9800,MUL(tel&,4))}=VAL("&h"+ro$+gr$+"00"+bl$) ! set the Falcon color reg
RETURN
PROCEDURE einde
  BMOVE palette%,&HFFFF9800,1024
  ~GEMDOS(32,L:super%)                                ! back to USER MODER
  ~XBIOS(5,L:old_phys%,L:old_phys%,3,resol&)          ! restore old screen
  ~MFREE(buffer%)                                     ! free memory
  RESERVE
  OUT 4,8
  IF ERR!=TRUE
    ~FORM_ALERT(1,ERR$(ERR))
  ENDIF
  EDIT
RETURN
PROCEDURE error_handler
  err!=TRUE
  endit
RETURN
PROCEDURE prismpaint(naam$)
  LOCAL r&,g&,b&,k&,t&,beeldblok%
  rez%=MALLOC(128)
  palet%=MALLOC(1536)
  IF LEN(naam$)=0
    END
  ENDIF
  OPEN "R",#n,naam$
  BGET #n,rez%,128             ! header 128 bytes
  k&=DPEEK(rez%+6)             ! AANTAL KLEUREN
  IF k&=16                     !
    r&=96                      ! 16 kleuren 3x16x2 bytes voor palet
    beeldblok%=153600
  ELSE
    k&=256                     ! 256 kleuren
    r&=1536                    ! 3x256x2 bytes palet
    beeldblok%=307200
  ENDIF
  BGET #n,palet%,r&            ! palet in vdi mode waardes 0-1000
  tel%=0
  FOR t&=0 TO (k&-1)
    ' r&=ROUND(DPEEK(palet%+tel%)/1000*15)      ! 16c palet vdi waardes 0 - 1000
    ' g&=ROUND(DPEEK(palet%+tel%+2)/1000*15)    ! converteren naar 0 - 15
    ' b&=ROUND(DPEEK(palet%+tel%+4)/1000*15)    ! ignore this for now this is for 16c
    ' VSETCOLOR t&,256*b&+16*g&+r&                   ! VDI
    r&=ROUND(DPEEK(palet%+tel%)/1000*252)      ! 256c palet vdi waardes 0 - 1000
    g&=ROUND(DPEEK(palet%+tel%+2)/1000*252)    ! converteren naar 0 - 252
    b&=ROUND(DPEEK(palet%+tel%+4)/1000*252)
    set_color(t&,r&,g&,b&)
    tel%=tel%+6
  NEXT t&
  BGET #n,XBIOS(2),beeldblok%
  CLOSE #n
  a%=MFREE(rez%)
  a%=MFREE(palet%)
RETURN
You do not have the required permissions to view the files attached to this post.

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4773
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Prism Paint 256 colors palette load

Postby simonsunnyboy » Sat Jan 30, 2016 7:38 pm

I can only guess that palette setter is not right. Maybe verflow problems between 16 and 32bit. GFABASIC is a bit tricky for those.

The color routine is actually from Cooper IIRC.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2227
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Prism Paint 256 colors palette load

Postby lp » Sat Jan 30, 2016 9:35 pm

The palette information in the prism paint file is stored in VDI order. You must translate it to hardware order. :wink:

User avatar
mjvans
Atari User
Atari User
Posts: 34
Joined: Thu Dec 31, 2015 2:08 pm
Location: Netherlands
Contact:

Re: Prism Paint 256 colors palette load

Postby mjvans » Sat Jan 30, 2016 10:31 pm

I understand the VDI palette format contains a number of 0-1000 and Falcon 256 color 0-252 that is translated like this: r&=ROUND(DPEEK(palet%+tel%)/1000*252)
But different order I dont know of.

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2227
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Prism Paint 256 colors palette load

Postby lp » Sat Jan 30, 2016 11:11 pm

Here is the table from my Prism Paint codec for zView. Sorry, its written in PureC. ;)

Code: Select all

uint8   c256[256]   = {
   0,255,1,2,4,6,3,5,7,8,9,10,12,14,11,13,
   16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
   32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
   48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
   64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
   80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
   96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
   112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
   128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
   144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
   160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
   176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
   192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
   208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
   224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
   240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,15
};

Assuming you load this table into DIM c256&(256):

Code: Select all

set_color(t&,r&,g&,b&) !old line
set_color(c256&(t&),r&,g&,b&) !change it to something like this

User avatar
mjvans
Atari User
Atari User
Posts: 34
Joined: Thu Dec 31, 2015 2:08 pm
Location: Netherlands
Contact:

Re: Prism Paint 256 colors palette load

Postby mjvans » Sun Jan 31, 2016 8:24 am

oh thank you so much. I thought you fooled me with the "hardware order. :wink:" But this should solve it.

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4773
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Prism Paint 256 colors palette load

Postby simonsunnyboy » Sun Jan 31, 2016 9:23 am

Ah, the old "VDI has its own order" crap. My solution in the old day was to make a palette with SETCOLOR, VDI draw all of them and then note the order of the colors on a piece of paper. Later on I had a lookuptable somewhere.

I am surprised that this problem persists in other video modes aswell.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2227
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Prism Paint 256 colors palette load

Postby lp » Sun Jan 31, 2016 1:18 pm

The GFA v3.5 manual touches on this issue at the section on SETCOLOR and provides the tables for st medium and st low. The 256 color table is missing. Now that I think about it, I will add this table to my gfabasic hyp. ;)

User avatar
mjvans
Atari User
Atari User
Posts: 34
Joined: Thu Dec 31, 2015 2:08 pm
Location: Netherlands
Contact:

Re: Prism Paint 256 colors palette load

Postby mjvans » Wed Feb 03, 2016 12:56 pm

Thanks for the input.
This listing works.
Forget the first one it has too many faults.
Thought it would be nice to share because it contains many things interesting for (beginner) Falcon programmers (a rare breed :) ).
Falcon specific video switching and such you don't find in GFA books.
At some point I got it working in the Interpreter but then the compiled prg didn't work. :?
I found out that XBIOS(89) gave wrong code to integer after being compiled so changed that (I use Compiler 3.6TT unpatched)
This programming is a real brain game. All long ago that I coded GFA but its coming back from deep memory banks. :wink:
Small warning again: It is Falcon VGA only.

Code: Select all

' Prismpaint 256c VGA 640x480 picture loading
'               by mjvans
'        WARNING FALCON only video mode switching!!
' Falcon video info:  STcomputer 5/1993 p84
' more info at atari-forum.com
' incomplete source please use no other formats than 640x480x256 uncompressed
' adapt for your own use
'
err!=FALSE
ON ERROR GOSUB error_handler
ON BREAK GOSUB einde
RESERVE 50000
DIM c256&(255)                               ! Palette order array
'
FILESELECT #"256c Prism Paint",CHR$(65+GEMDOS(25))+":"+DIR$(0)+"\*.PNT","",filenaam$
IF NOT EXIST(filenaam$)
  PRINT "No file selected"
  ~INP(2)
  END
ENDIF
oldpalette%=MALLOC(1024)                         ! save old palette colors
super%=GEMDOS(32,L:0)                            ! go SUPERVISOR
resol&=XBIOS(88,W:-1)                            ! save old resolution
old_phys%=XBIOS(2)                               ! save old screen
buffer%=MALLOC(308224)                           ! 640x480 + palette 1024
monitor&=XBIOS(89)                               ! what sort of display?
image%=buffer%+1024                              ! start of screen
RESTORE palette.order
FOR i&=0 TO 255
  READ c256&(i&)                              ! fill array with data
NEXT i&
BMOVE &HFFFF9800,oldpalette%,1024
OUT 4,18                                       ! waarom?
'
prismpaint(filenaam$)                          ! laad plaatje
~INP(2)
einde
'
'            *******************************
'      cant use VDI setcolor after change video mode
'
'      put colors directly in the hardware registers
'
PROCEDURE set_color(tel&,ro&,gr&,bl&)
  LOCAL ro$,gr$,bl$
  ro$=STRING$(2-LEN(HEX$(ro&)),"0")+HEX$(ro&)            ! red
  gr$=STRING$(2-LEN(HEX$(gr&)),"0")+HEX$(gr&)            ! green
  bl$=STRING$(2-LEN(HEX$(bl&)),"0")+HEX$(bl&)            ! blue
  {ADD(&HFFFF9800,MUL(tel&,4))}=VAL("&h"+ro$+gr$+"00"+bl$) ! set the Falcon color reg
RETURN
PROCEDURE 256videomode(monitor&)
  IF monitor&=2
    vga!=TRUE
    rgb!=FALSE
    ~XBIOS(5,L:image%,L:image%,W:3,W:&X111011)   ! switch to VGA: 640x480 256c.
  ELSE
    WRITE "No VGA detected"
    PAUSE 60
    ' rgb is untested by me so better keep it safe and skip these lines
    ' use something like this:
    ' rgb!=TRUE
    ' vga!=FALSE
    ' ~XBIOS(5,L:image%,L:image%,W:3,W:&X10010111) ! RGB/TV:  640x400 256c.
    einde
  ENDIF
RETURN
PROCEDURE einde
  BMOVE oldpalette%,&HFFFF9800,1024
  ~GEMDOS(32,L:super%)                                ! back to USER MODER
  ~XBIOS(5,L:old_phys%,L:old_phys%,3,resol&)          ! restore old screen
  ~MFREE(buffer%)                                     ! free memory
  RESERVE
  OUT 4,8
  IF ERR!=TRUE
    ~FORM_ALERT(1,ERR$(ERR))
  ENDIF
  EDIT
RETURN
PROCEDURE error_handler
  err!=TRUE
  einde
RETURN
PROCEDURE prismpaint(naam$)
  LOCAL r&,g&,b&,k&,t&,beeldblok%
  rez%=MALLOC(128)
  palet%=MALLOC(1536)
  IF LEN(naam$)=0
    END
  ENDIF
  OPEN "R",#n,naam$
  lof%=LOF(#n)                 ! length of file
  BGET #n,rez%,128             ! header 128 bytes
  k&=DPEEK(rez%+6)             ! AANTAL KLEUREN
  IF k&=16                     !
    r&=96                      ! 16 kleuren 3x16x2 bytes voor palet
    beeldblok%=153600
  ELSE
    k&=256                     ! 256 kleuren
    r&=1536                    ! 3x256x2 bytes palet
    beeldblok%=307200
  ENDIF
  BGET #n,palet%,r&            ! palet in vdi mode waardes 0-1000
  tel%=0
  IF k&=256 AND lof%=308864 THEN
    256videomode(monitor&)                                 ! switch to 640x480x256
    FOR t&=0 TO (k&-1)
      r&=ROUND(DPEEK(palet%+tel%)/1000*252)      ! 256c palet vdi waardes 0 - 1000
      g&=ROUND(DPEEK(palet%+tel%+2)/1000*252)    ! converteren naar 0 - 252
      b&=ROUND(DPEEK(palet%+tel%+4)/1000*252)
      set_color(c256&(t&),r&,g&,b&)
      tel%=tel%+6
    NEXT t&
    BGET #n,XBIOS(2),beeldblok%                 ! put picture on screen
  ELSE
    ' 16 colors and other resolutions to be implemented use something like this:
    ' r&=ROUND(DPEEK(palet%+tel%)/1000*15)      ! 16c palet vdi waardes 0 - 1000
    ' g&=ROUND(DPEEK(palet%+tel%+2)/1000*15)    ! converteren naar 0 - 15
    ' b&=ROUND(DPEEK(palet%+tel%+4)/1000*15)
  ENDIF
  CLOSE #n
  a%=MFREE(rez%)
  a%=MFREE(palet%)
RETURN
palette.order:
DATA 0,255,1,2,4,6,3,5,7,8,9,10,12,14,11,13
DATA 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
DATA 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47
DATA 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
DATA 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79
DATA 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95
DATA 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111
DATA 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127
DATA 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143
DATA 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159
DATA 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175
DATA 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191
DATA 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207
DATA 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223
DATA 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239
DATA 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,15,0


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 1 guest