![]() |
Forum Index : Microcontroller and PC projects : Open SCR file (ZX Spectrum standard screen)
Author | Message | ||||
Martin H.![]() Senior Member ![]() Joined: 04/06/2022 Location: GermanyPosts: 228 |
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: NetherlandsPosts: 2027 |
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 If nothing goes right ... turn left |
||||
Martin H.![]() Senior Member ![]() Joined: 04/06/2022 Location: GermanyPosts: 228 |
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.![]() Senior Member ![]() Joined: 04/06/2022 Location: GermanyPosts: 228 |
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 KingdomPosts: 3327 |
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: GermanyPosts: 338 |
Maybe peter can implement the load Data / save Data from cmm2 to the pico?. Plasma |
||||
Martin H.![]() Senior Member ![]() Joined: 04/06/2022 Location: GermanyPosts: 228 |
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 RepublicPosts: 529 |
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.![]() Senior Member ![]() Joined: 04/06/2022 Location: GermanyPosts: 228 |
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.![]() Senior Member ![]() Joined: 04/06/2022 Location: GermanyPosts: 228 |
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 |
||||
![]() |