Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:50 05 Mar 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 : Open SCR file (ZX Spectrum standard screen)

Author Message
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 11:32am 25 Jan 2023
Copy link to clipboard 
Print this post

What is scr file?
The scr file extension is used for ZX Spectrum standard screen.
The scr files are memory dumps of the first 6912 bytes of the Spectrum memory.
32*192 Bytes Pixel Data + 32*24 Bytes Color Data

I've made a little Tool to show ZX Spectrum Screen$ files on the Pico
Missing: Flash Attribut and Brightness for white.


'ZX Spectrum Screen Loader for PicoMite
' by Martin Herhaus 2023
'input =File in .SCR Format
Dim col%(15) : '8 Colors in 2 BrightLevels
For f%=0 To 15:Read col%(f%):Next
MODE 1: Input "Filename :";SC$
CLS col%(7)
'
Open sc$ For Input As #1
ty%=0
'read screen data
py%=0:ty%=0
For f%=0 To 2
py%=f%*64
For y%=0 To 7
For l%=0 To 7
Lne%=py%+l%*8+y%
For x%=0 To 31
spx%=64+(16*x%)
byte$=Input$(1,1)
plot spx%,lne%+24,Asc(byte$)
Next x%
Next l%
Next y%
Next f%
'read Attributes
For y%=0 To 23
For x%=0 To 31
ink%=0:Paper%=0
byte$=Input$(1,1)
If Asc(byte$) And 64 Then cl%=8 Else cl%=0
Paper%=Asc(byte$) And 7
Ink%=(Asc(byte$) And 56)>>3
TILE x%+4,y%+3,col%(ink%+cl%),col%(paper%+cl%)
Next
Next
Close #1

Sub plot px%,py%,pval%
s%=128
For n%=0 To 7
If pval% And s% Then Box px%+n%*2,py%*2,2,2,,0,0
s%=s%/2
Next
End Sub

'--Spectrum Colors (-----
Data 0,255,16711680,16711935,32768,33023,16744448,16777215
Data 0,16639,16728064,16728319,65280,65535,16776960,16777215

to keep things easier, I used Mode 1 and the Tile Command for the Colors.
The disadvantage of this is that you cannot save the image with Colors as a BMP File.


here the Sample Picture

clive.zip

Cheers
Mart!n
Edited 2023-01-25 21:55 by Martin H.
'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3340
Posted: 12:47pm 25 Jan 2023
Copy link to clipboard 
Print this post

Smart thinking, using mode 1 and tiles. That is basiclly what the spectrum also did (and many other until the moment there was sufficient cheap memory for full RGB per pixel).
The only one that is different was Teletext. They has a color attribute per character, sacrificing one character preceeding.
Edited 2023-01-25 22:48 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 01:06pm 25 Jan 2023
Copy link to clipboard 
Print this post

  Volhout said  Smart thinking, using mode 1 and tiles. That is basiclly what the spectrum also did (and many other until the moment there was sufficient cheap memory for full RGB per pixel).
The only one that is different was Teletext. They has a color attribute per character, sacrificing one character preceeding.

it was also the logical way, because at the time when the point is set there is no information about what color it will get.
I found a WebPage as Source of hunderts of Spectrum Screens.
ZX ART
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 02:21pm 25 Jan 2023
Copy link to clipboard 
Print this post

ok, I also managed it for Mode 2

'ZX Spectrum Screen Loader mode 2 for PicoMite
'by Martin Herhaus 2023
'input =File in .SCR Format
Dim col%(15) '8 Colors in 2 Bightnesses
Restore Scolors:For f%=0 To 15:Read col%(f%):Next
MODE 2: Input "Filename :";SC$
CLS col%(7)
Open sc$ For Input As #1
ty%=0
'read screen data
py%=0:ty%=0
For f%=0 To 2
†py%=f%*64
†For y%=0 To 7
† †For l%=0 To 7
† † †Lne%=py%+l%*8+y%
† † † †For x%=0 To 31
† † † † †spx%=32+(8*x%)
† † † † †byte$=Input$(1,1)
† † † † †plot spx%,lne%+24,Asc(byte$)
† † † †Next x%
† † †Next l%
† †Next y%
†Next f%
'read Attributes
For y%=0 To 23
†For x%=0 To 31
† †ink%=0:Paper%=0
† †byte$=Input$(1,1)
† †If Asc(byte$) And 64 Then cl%=8 Else cl%=0
† †Paper%=Asc(byte$) And 7
† †Ink%=(Asc(byte$) And 56)>>3
† †recol x%+4,y%+3,col%(ink%+cl%),col%(paper%+cl%)
†Next
Next

Close #1

Scolors:
Data 0,255,16711680,16711935,32768,33023,16744448,16777215
Data 0,16639,16728064,16728319,65280,65535,16776960,16777215

Sub plot px%,py%,pval%
s%=128
For n%=0 To 7
If pval% And s% Then Pixel px%+n%,py%,0
'If pval% And s% Then Box px%+n%*2,py%*2,2,2,,0,0
s%=s%/2
Next
End Sub

Sub recol cx%,cy%,bg%,fg%
†xx%=8*cx%:yy%=8*cy%
†For i1x%=0 To 7:For i1y%=0 To 7
† †If Pixel(xx%+i1x%,yy%+i1y%) Then pcl%=bg% Else pcl%=fg%
† †Pixel xx%+i1x%,yy%+i1y%,pcl%
†Next :Next
End Sub † † † † † † † † † † † † † † † † † † † † † † † † † †




but.. wec.scr † †6912 Bytes
† † †WEC.bmp †230454 Bytes
so the bmp file is 33.3 times as large as the source
Cheers
Mart!n
Edited 2023-01-26 00:39 by Martin H.
'no comment
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5571
Posted: 04:21pm 25 Jan 2023
Copy link to clipboard 
Print this post

This is excellent work! The beauty of it is that it can be used for PicoMite specific screens too. The scr format is fine for a lot of uses. Converting from bmp to scr is probably more important than going the other way. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 497
Posted: 05:12pm 25 Jan 2023
Copy link to clipboard 
Print this post

Maybe peter can implement the load Data / save Data from cmm2 to the pico?.
Plasma
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 05:42pm 25 Jan 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  This is excellent work! The beauty of it is that it can be used for PicoMite specific screens too. The scr format is fine for a lot of uses. Converting from bmp to scr is probably more important than going the other way. :)

The nested loops are only necessary because of the somewhat strange structure of the Spectrum on the screen memory.
Storing a 320x240 Picture from the Pico would take 40x240=9600 Bytes for Monochrome Screen and 40*30=1200 Bytes for the Color Information, so a Full screen takes 10800Bytes.
BUT ... you stuck with the 8x8 Pixel Bicolor Problem. You have to pay attention to this when creating the pictures. With 3600 more Bytes, one can use a 4x4 Pixel Color Structur. to be more flexible.
Edited 2023-01-26 03:43 by Martin H.
'no comment
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 10:12am 26 Jan 2023
Copy link to clipboard 
Print this post

Maybe you can reuse sub for save BMP from GRF.INC:
GRF.INC on GitHub

I did it also because of size...
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 10:54am 26 Jan 2023
Copy link to clipboard 
Print this post

  jirsoft said  Maybe you can reuse sub for save BMP from GRF.INC:
GRF.INC on GitHub

I did it also because of size...

NICE  
as I see, you use also many nested Loops in the GRF.loadZX FUNCTION †

The Pico can allready Save BMP with the Save Image Command, but it uses 24Bit BMP, thats why every Pixel needs 3Bytes. As alternative we can also Load JPG Files.
The Pico is not able to write JPG because of the high computational effort that would be required for compression.
But you can convert the BMP to JPG on the PC and then send it back to the Pico.
Edited 2023-01-26 20:58 by Martin H.
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 11:53am 26 Jan 2023
Copy link to clipboard 
Print this post

with a little tweak now also for MMB4W

'ZX Spectrum Screen Loader mode 2/7 for PicoMite & MMB4W
'by Martin Herhaus 2023
'input =File in .SCR Format

Dim col%(15) '8 Colors in 2 Bightnesses
Restore PScolors:
if mm.device$="PicoMiteVGA" then
MODE 2
else
Mode 7
Restore WSColors
endif
For f%=0 To 15:Read col%(f%):Next
Input "Filename :";SC$
CLS col%(7):t%=Timer
Open sc$ For Input As #1
'
'read screen data
For f%=24 To 152 Step 64
†For y%=0 To 7
† †For l%=0 To 56 Step 8
† † † †For x%=32 To 280 Step 8
† † † † †byte%=Asc(Input$(1,1))
† † † † †plot x%,f%+l%+y%,byte%
† † † †Next x%
† † †Next l%
† †Next y%
Next f%
'read Attributes
For y%=3 To 26
†For x%=4 To 35
† †byte%=Asc(Input$(1,1))
† †If byte% And 64 Then cl%=8 Else cl%=0
† †Paper%=(byte% And 7)
† †Ink%=(byte% And 56)>>3
† †recol x%,y%,col%(ink%+cl%),col%(paper%+cl%)
†Next
Next
Close #1

PScolors:
Data 0,255,16711680,16711935,32768,33023,16744448,16777215
Data 0,16639,16728064,16728319,65280,65535,16776960,16777215
'
WSColors:
data 0,&HD70000,&HD7,&HD700D7,&H00D700,&HD70800,&H00D7D7,&HD7D7D7
data 0,&HFF0000,&HFF,&HFF00FF,&H00ff00,&HFFff00,&H00ffFF,&HFFFFFF
Sub plot px%,py%,pval%
s%=128
For n%=0 To 7
If pval% And s% Then Pixel px%+n%,py%,0
s%=s%>>1
Next
End Sub

Sub recol cx%,cy%,bg%,fg%
†xx%=8*cx%
†For i1x%=xx% To xx%+7
† †yy%=8*cy%:
† †For i1y%=yy% To yy%+7
† † †PC%=Pixel(i1x%,i1y%) AND &HFFFFFF
† † †If †PC% Then
† † † †Pixel i1x%,i1y%,bg%
† † †Else
† † † †Pixel i1x%,i1y%,fg%
† † †EndIf
† †Next
†Next
End Sub

maybe someone with Color Maximite can test it there

Cheers
†Mart!n
Edited 2023-01-26 22:59 by Martin H.
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 09:06am 12 Feb 2023
Copy link to clipboard 
Print this post

To use this as a slideshow it would be nice to read the Filenames from the Program.
with files "*.scr" I get a list of all scr files, but is there a way in MM Basic to automatic transfer Filenames (redirect Console Output) into a text file?
Like, in DOS:

DIR *.SCR >Files.txt /b

Cheers
Mart!n
'no comment
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5841
Posted: 11:08am 12 Feb 2023
Copy link to clipboard 
Print this post

look up
DIR$( [fspec [, type ]] )

Jim
VK7JH
MMedit   MMBasic Help
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 11:43am 12 Feb 2023
Copy link to clipboard 
Print this post

  TassyJim said  look up
DIR$( [fspec [, type ]] )

Jim

Thank you Jim,    that does the Job

for the Test I used to list all "*.scr" files before the Input

fl$=dir$("*.scr",FILE)
do while fl$<>""
print fl$
fl$=dir$()
loop
Input "Filename :";SC$


Thank you
Cheers
  Mart!n
'no comment
 
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 56
Posted: 10:14am 12 May 2023
Copy link to clipboard 
Print this post

Hi Martin,

i updated my PicoMite VGA to V5.07.07 and the SCR viewer doesn¬īt work anymore.
Do you have a newer code which works with V5.07.07?
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 01:33pm 12 May 2023
Copy link to clipboard 
Print this post

  PilotPirx said  Hi Martin,

i updated my PicoMite VGA to V5.07.07 and the SCR viewer doesn¬īt work anymore.
Do you have a newer code which works with V5.07.07?


I think this is due to the changed tile structure for mode 1 in V5.05.07
But the Mode2 Version does its job as usual:

'ZX Spectrum Screen Loadermode 2 for PicoMite
'by Martin Herhaus 2023
'input =File in .SCR Format

Dim col%(15) '8 Colors in 2 Bightnesses
Restore Scolors:For f%=0 To 15:Read col%(f%):Next
MODE 2: Input "Filename :";SC$
CLS col%(7):t%=Timer
Open sc$ For Input As #1
ty%=0
'read screen data
'py%=0:ty%=0

For f%=24 To 152 Step 64
 For y%=0 To 7
   For l%=0 To 56 Step 8
       For x%=32 To 280 Step 8
         byte%=Asc(Input$(1,1))
         plot x%,f%+l%+y%,byte%
       Next x%
     Next l%
   Next y%
Next f%
'read Attributes
For y%=3 To 26
 For x%=4 To 35
   byte%=Asc(Input$(1,1))
   If byte% And 64 Then cl%=8 Else cl%=0
   Paper%=(byte% And 7)
   Ink%=(byte% And 56)>>3
   recol x%,y%,col%(ink%+cl%),col%(paper%+cl%)
 Next
Next

Close #1
'Print Timer-t%;
Scolors:
Data 0,255,16711680,16711935,32768,33023,16744448,16777215
Data 0,16639,16728064,16728319,65280,65535,16776960,16777215

Sub plot px%,py%,pval%
s%=128
For n%=0 To 7
If pval% And s% Then Pixel px%+n%,py%,0
s%=s%>>1
Next
End Sub

Sub recol cx%,cy%,bg%,fg%
 xx%=8*cx%
 For i1x%=xx% To xx%+7:yy%=8*cy%:For i1y%=yy% To yy%+7
   If Pixel(i1x%,i1y%) Then
     Pixel i1x%,i1y%,bg%
   Else
     Pixel i1x%,i1y%,fg%
   EndIf
 Next :Next
End Sub


I will fix the Mode 1 Version soon
Edit:
  Quote  Sets the colour for one or more tiles on the screen.
When in monochrome mode by default the VGA screen is split up into
80x40 tiles each 8x12 pixels. This matches font 1 and allows full colour
coding in the editor in monochrome mode


this will not give a useful result, since the tiles are no longer square.
but we can stay with mode 2  
cheers
 Mart!n
Edited 2023-05-12 23:52 by Martin H.
'no comment
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8412
Posted: 02:49pm 12 May 2023
Copy link to clipboard 
Print this post

You can set the tile height using TILE HEIGHT. Set it to 16 and then two tiles wide is 16x16 like before
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 854
Posted: 03:57pm 12 May 2023
Copy link to clipboard 
Print this post

  matherp said  You can set the tile height using TILE HEIGHT. Set it to 16 and then two tiles wide is 16x16 like before

thank you          
that works  
'ZX Spectrum Screen Loader for PicoMite
'input =File in .SCR Format
Dim col%(15) '8 Colors in 2 Bightnesses
Restore Scolors:For f%=0 To 15:Read col%(f%):Next
TILE HEIGHT 16
MODE 1: Input "Filename :";SC$
CLS
Open sc$ For Input As #1
ty%=0
'read screen data
py%=0:ty%=0
For f%=0 To 2
py%=f%*64
For y%=0 To 7
For l%=0 To 7
Lne%=py%+l%*8+y%
For x%=0 To 31
 spx%=64+(16*x%)
 byte$=Input$(1,1)
 plot spx%,lne%+24,Asc(byte$)
Next x%
 Next l%
Next y%

Next f%
'read Attributes
For y%=0 To 23
For x%=0 To 31
ink%=0:Paper%=0
byte$=Input$(1,1)
If Asc(byte$) And 64 Then cl%=8 Else cl%=0
Paper%=Asc(byte$) And 7
Ink%=(Asc(byte$) And 56)>>3
TILE (2*x%)+8 ,y%+3,col%(ink%+cl%),col%(paper%+cl%)
TILE (2*x%)+9,y%+3,col%(ink%+cl%),col%(paper%+cl%)
Next
Next
Close #1

Scolors:
Data 0,255,16711680,16711935,32768,33023,16744448,16777215
Data 0,16639,16728064,16728319,65280,65535,16776960,16777215
Sub plot px%,py%,pval%
s%=128
For n%=0 To 7
If pval% And s% Then
 Box px%+n%*2,py%*2,2,2,,0,0
 Else
 Box px%+n%*2,py%*2,2,2,,col%(7),Col%(7)
 EndIf
s%=s%/2
Next
End Sub



Edited 2023-05-13 02:10 by Martin H.
'no comment
 
Print this page


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

© JAQ Software 2024