Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 18:20 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM-Basic Sprite Editor

     Page 2 of 2    
Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3558
Posted: 02:23pm 12 Jun 2023
Copy link to clipboard 
Print this post

AFAIK there aare no numbers for the color names in the MMBasic rogram, but there are numbers used in the sprite file, to make the format compliant with CMM1.

Regards,

Volhout
PicomiteVGA PETSCII ROBOTS
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3663
Posted: 04:05pm 12 Jun 2023
Copy link to clipboard 
Print this post

  hhtg1968 said  hello. my picomitevga will be ready in a few days. i tried to start your programm on my cmm2. the colours myrtle, cobalt etc. are no keywords for mmbasic on cmm2. where can i get the numbers for the colour names?

For things like RGB(myrtle) I expect you can
PRINT RGB(myrtle)

Bear in mind not all hardware can do all colours.

John
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 904
Posted: 04:54pm 12 Jun 2023
Copy link to clipboard 
Print this post

  hhtg1968 said  hello. my picomitevga will be ready in a few days. i tried to start your programm on my cmm2. the colours myrtle, cobalt etc. are no keywords for mmbasic on cmm2. where can i get the numbers for the colour names?


If the RGB Handling is equal just replace the Data in the Sourcecode:


colors:
'--Colorscheme accordung to matherp
Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED)
Data RGB(MAGENTA),RGB(YELLOW),RGB(WHITE),RGB(MYRTLE)
Data RGB(COBALT) ,RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST)
Data RGB(FUCHSIA),RGB(BROWN),RGB(LILAC)

pict:


with this

colors:
'--Colorscheme accordung to matherp
Data &H0000FF,&H00FF00,&H00FFFF,&HFF0000
Data &HFF00FF,&HFFFF00,&HFFFFFF,&H004000
Data &H0040FF,&H008000,&H0080FF,&HFF4000
Data &HFF40FF,&HFF8000,&HFF80FF

pict:

as you might see,  myrtle, cobalt etc. are those colors with the Green variants 40,80
Edited 2023-06-13 02:58 by Martin H.
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 904
Posted: 05:25pm 12 Jun 2023
Copy link to clipboard 
Print this post

  Volhout said  Hi Martin,

This is a GREAT tool !!! I used it for 1 week now, and really appreciate it. This really works well. The only negative point I found so far is that <ctrl-C> is needed to Quit (I did not find any other way so far).

Is there any documentation on the "compressed format" ?
So I can implement the compressed sprite reader in MMbasic in my program.

Regards,

Volhout


The principle is simple, repeating pixels of the same color are counted.
The color number is increased by 16 followed by the number of repetitions -1 (max 15)

So far you can use a text editor to search and replace repeating parts of the Sprite Data strings with the compressed form.
which is quite laborious.
Example :
find "0000000000000000" replace with "GF"
find "000000000000000"  replace with "GE"
find "00000000000000"   replace with "GD"
...
find "000" replace with "G2"
and that for all 16 colors.
You can do something like this 2-3 times, but it's boring and a real punishment. So I thought, the pico can do that much faster and with less effort so let him do the work.

you can use the compress and Expand Function from the SprEd Source code..



Function expand$(pxl$)
 Local n%,nmb%,tmp$,co$
 n%=1
 Do
  If Asc(Mid$(pxl$,n%,1))< 71 Then
     tmp$=tmp$+Mid$(pxl$,n%,1)
  Else
     ' length encoded - 1st char is pixel colour+71, 2nd is count-1
     co$=Hex$(Asc(Mid$(pxl$,n%,1))-71)
     Inc n%
     nmb%=Val("&H"+Mid$(pxl$,n%,1))
     tmp$=tmp$+String$(nmb%+1,co$)
  EndIf
  Inc n%
 Loop Until n%>Len(pxl$)
 expand$=tmp$
End Function


Function compress$(search$)
Local String from$,zu$
found=0
For f%=0 To 15
  For n%=16 To 3 Step -1
    from$=String$(n%,Hex$(f%,1))
    zu$=Chr$(71+f%)+Chr$(128+Asc(Hex$(n%-1,1)))
   'addition of 128 prevents the results from
    'being incorrectly counted in a further search
    Do
      search$=replace$(from$,zu$,search$)
      If found=0 Then Exit
    Loop
  Next n%
Next f%
compress$=""
For f%=1 To Len(search$)
  n%=Asc(Mid$(search$,f%,1))
  n%=n%-128*(n%>128):'sub the 128 if needed
  compress$=compress$+Chr$(n%)
Next
End Function
'
Function replace$(sr$,repl$,sear$)
Local n%,tmp$
tmp$=" "+sear$+" "
found=Instr(tmp$,sr$)
If found=0 Then replace$=sear$:Exit Function
tmp$=Left$(tmp$,found-1)+repl$+Right$(tmp$,Len(tmp$)-(found+Len(sr$))+1)
replace$=Mid$(tmp$,2,Len(tmp$)-2)
End Function


To see, how I used it, also take a look at the On the Road again Listing :-)

Sub read_Sprites
Local nr%,p%,n%,byt$,m$
'--- Read/Create Sprites
Restore car
  For p%=1 To 31
    Read Byt$:Byt$=expand$(Byt$)
    For n%=1 To Len(Byt$)/2
      m$=Mid$(Byt$,n%,1)
      Pixel n%-1,p%,COL%(Val("&H"+m$))
      Pixel 56-n%,p%,COL%(Val("&H"+m$))
      m$=Mid$(Byt$,Len(Byt$)-(n%-1),1)
      Pixel n%-1,32+p%,COL%(Val("&H"+m$))
      Pixel 56-n%,32+p%,COL%(Val("&H"+m$))
    Next
  Next
Sprite read #1,0,0,56,32:Sprite read #2,0,32,56,32
'  Sprite load "Car3.spr",3
Restore car3
  For p%=0 To 30
    Read Byt$:Byt$=expand$(Byt$)
    For n%=1 To Len(Byt$)
      m$=Mid$(Byt$,n%,1)
      Pixel n%-1,p%,COL%(Val("&H"+m$))
    Next
  Next
Sprite read #3,0,0,56,30
End Sub

Have Fun
Edited 2023-06-13 03:52 by Martin H.
'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3558
Posted: 09:42pm 12 Jun 2023
Copy link to clipboard 
Print this post

Hi Martin,

I saw you paint the pixel data on screen, and then read the sprite from screen.

Why not uncompress the colors in a linear array, and use
SPRITE LOADARRAY n,w,h,array%

Saves a lot of coordinate calculations

Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 904
Posted: 02:51am 13 Jun 2023
Copy link to clipboard 
Print this post

  Volhout said  
SPRITE LOADARRAY n,w,h,array%
Saves a lot of coordinate calculations
Volhout

sounds good. I missed the option so I've never tried it.
How is the memory consumption?
'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3558
Posted: 04:05am 13 Jun 2023
Copy link to clipboard 
Print this post

Probably bad. You need DIM an array for each size sprite. But you need this only during  creation (local).

Volhout
PicomiteVGA PETSCII ROBOTS
 
hhtg1968
Senior Member

Joined: 25/05/2023
Location: Germany
Posts: 114
Posted: 09:01am 13 Jun 2023
Copy link to clipboard 
Print this post

to martin h:

many thanks for the colour numbers...
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 904
Posted: 05:40am 14 Jun 2023
Copy link to clipboard 
Print this post

  hhtg1968 said  to martin h:

many thanks for the colour numbers...

You're welcome

These were the color values that the PicoMiteVGA returned.
Now I have noticed that in the Windows version, the position of red and blue seem to be reversed. Since I don't know how the colors are used on the CMM, here the codes that MMBasic4Windows gave me back.(just to be on the safe side, if the other colors don't fit).

Data &HFFFF0000,&HFF00FF00,&HFFFFFF00,&HFF0000FF
Data &HFFFF00FF,&HFF00FFFF,&HFFFFFFFF,&HFF004000
Data &HFFFF4000,&HFF008000,&HFFFF8000,&HFF0040FF
Data &HFFFF40FF,&HFF0080FF,&HFFFF80FF

Edited 2023-06-14 15:41 by Martin H.
'no comment
 
hhtg1968
Senior Member

Joined: 25/05/2023
Location: Germany
Posts: 114
Posted: 06:17am 14 Jun 2023
Copy link to clipboard 
Print this post

hello. no i have a running picomitevga and can test this program...

1. i only see 8 colours. the row has 16 parts, so i see the same colours twice...

2. is this software free? i would program further for my purpouses, but only if martinH is saying "yes"...
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3663
Posted: 06:59am 14 Jun 2023
Copy link to clipboard 
Print this post

  hhtg1968 said  hello. no i have a running picomitevga and can test this program...

1. i only see 8 colours. the row has 16 parts, so i see the same colours twice...

A hardware problem? A bit shorted / not connected?

Maybe post a small picture showing all the ones you see and someone may say what's wrong.

John
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 327
Posted: 07:08am 14 Jun 2023
Copy link to clipboard 
Print this post

  Martin H. said  To make the work a little easier I wrote a small sprite editor.
Have Fun
Cheers
�Mart!n


Thanks! This is very useful. If I may make a few suggestions:

1. Don't let the program crash if the load filename is non-existent.

2. Allow the user to exit the load and save prompts without entering a filename and without destroying work in progress.

This can be as easy as this:

Case Chr$(145):fname$=Dialog$("Load File, Name?"):if fname$<>"" then fread(fname$)

Case Chr$(146):fname$=Dialog$("Save File, Name?"):if fname$<>"" then fwrite(fname$)


3. Allow mouse presses for the buttons on the right.
Edited 2023-06-14 17:20 by toml_12953
 
hhtg1968
Senior Member

Joined: 25/05/2023
Location: Germany
Posts: 114
Posted: 08:01am 14 Jun 2023
Copy link to clipboard 
Print this post

the problem with the colours is solved... i placed the connection for 1/3 green wrong... at another topic here i got the solution...
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 904
Posted: 09:04am 14 Jun 2023
Copy link to clipboard 
Print this post

  hhtg1968 said  

2. is this software free? i would program further for my purpouses, but only if martinH is saying "yes"...

I say "Yes"  
'no comment
 
hhtg1968
Senior Member

Joined: 25/05/2023
Location: Germany
Posts: 114
Posted: 10:21am 14 Jun 2023
Copy link to clipboard 
Print this post

thanks.
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024