10-26-2023, 07:52 PM
@bplus Try out the upgraded version here and see what you think:
Differences in these routines and what you currently have:
Yours only tracks: Static font&, dest&, source&, row&, col&, autodisplay&, mb&
This tracks:
'General Screen Settings '15
AutoDisplay As Long '1
Blend As Long '2
Dest As Long '4
Source As Long '8
'Font Settings '496
CursorX As Long '16
CursorY As Long '32
Font As Long '64
FgColor As _Unsigned Long '128
BgColor As _Unsigned Long '256
'Image Settings ' 2560
ColorPalette As _MEM '512
Blink As Long '1024
ScreenData As _MEM '2048
End Type
So that's all the screen data (the image itself can be restored), as well as its palette (in case that changes), with _blink, _blend, color, and background color all added to the mix.
Change 2: Yours holds the data in a STATIC variable, which means it has to be restored in the same routine, and the same pass, as the sub/function that uses it.
The new version uses a settings_type variable to track the changes, so it could be used inside a recursive sub/function -- or called in multiple subs/functions -- and unravel back out in the same order to get you back to your original screen in a FILO method.
Change 3: Yours requires you to get and store all the data that it holds, without choice in case you want any of the changes to actually remain.
The new version lets you specify *exactly* what you want to store and restore. (That's where all the nice CONST come in to help make things more intuitive for users.)
Only want to store the General Settings (AutoDisplay, Blend, Dest, Source) then simply call the sub with: GetSettings 0, Saver, General_Settings
Decide that you actually want your sub/function to be able to change the blend setting, but not those other three? GetSettings 0, Saver, General_Settings - AutoDisplay_Setting
Want to store it all? That's All_Settings
Just the image data, color palette, and blink status? That's Image_Settings
Recursive possible. More settings. Optional and customizable settings...
I'd call it a nice upgrade from the old version which you currently have saved and for use.
Code: (Select All)
Const All_Settings~& = -1~&
Const General_Settings~& = 1 Or 2 Or 4 Or 8
Const AutoDisplay_Setting~& = 1
Const Blend_Setting~& = 2
Const Dest_Setting~& = 4
Const Source_Setting~& = 8
Const Font_Settings~& = 16 Or 32 Or 64 Or 128 Or 256
Const CursorX_Setting~& = 16
Const CursorY_Setting~& = 32
Const Font_Setting~& = 64
Const ForegroundColor_Setting~& = 128
Const BackgroundColor_Setting~& = 256
Const Image_Settings~& = 512 Or 1024 Or 2048
Const ColorPalette_Setting~& = 512
Const Blink_Setting~& = 1024
Const ScreenData_Setting~& = 2048
Type Settings_Type
ControlCode As _Unsigned Long
PixelSize As Long
'General Screen Settings '15
AutoDisplay As Long '1
Blend As Long '2
Dest As Long '4
Source As Long '8
'Font Settings '496
CursorX As Long '16
CursorY As Long '32
Font As Long '64
FgColor As _Unsigned Long '128
BgColor As _Unsigned Long '256
'Image Settings ' 2560
ColorPalette As _MEM '512
Blink As Long '1024
ScreenData As _MEM '2048
End Type
Dim Saver As Settings_Type
'Screen _NewImage(640, 480, 32)
'$Color:32
Randomize Timer
_Blink Off
For i = 0 To 15
Color i, 15 - i
Print "Hello World in Color"; i
Next
Sleep 'so we can view the original screen
GetSettings 0, Saver, All_Settings 'We should now be able to screw with all sorts of stuff and then reset the changes after
_Font 17 'double wide font!
For i = 1 To 10
Color 4, 0: Print "BLAH BLAH BLAH! Look at this junk!" 'just crap to print to the screen!
Next
For i = 0 To 15
_PaletteColor i, _RGB32(Rnd * 256, Rnd * 256, Rnd * 256) 'even the palette changes!
Next
Sleep 'so we can view our drastic changes
RestoreSettings Saver, Image 'put everything back to where it was originally
Sleep 'and let's look at it
System 'before we quit
Sub GetSettings (Image As Long, SaveTo As Settings_Type, Control_Code As _Unsigned Long)
Dim m As _MEM: m = _MemImage(0)
If Control_Code = 0 Then Exit Sub
SaveTo.ControlCode = Control_Code
SaveTo.PixelSize = _PixelSize(Image)
If Control_Code And 1 Then SaveTo.AutoDisplay = _AutoDisplay
If Control_Code And 2 Then SaveTo.Blend = _Blend
If Control_Code And 4 Then SaveTo.Dest = _Dest
If Control_Code And 8 Then SaveTo.Source = _Source
If Control_Code And 16 Then SaveTo.CursorX = Pos(0)
If Control_Code And 32 Then SaveTo.CursorY = CsrLin
If Control_Code And 64 Then SaveTo.Font = _Font(Image)
If Control_Code And 128 Then SaveTo.FgColor = _DefaultColor(Image)
If Control_Code And 256 Then SaveTo.BgColor = _BackgroundColor(Image)
If Control_Code And 512 Then
Select Case SaveTo.PixelSize
Case 0, 256 '16 color palette and 256 color palette
If SaveTo.PixelSize = 0 Then '16 colors for text screen
Limit = 15
Else
Limit = 255
End If
Dim Pal(0 To Limit) As _Unsigned Long
For i = 0 To Limit
Pal(i) = _RGBA32(_Red(i, Image), _Green(i, Image), _Blue(i, Image), _Alpha(i, Image))
Next
m = _Mem(Pal())
SaveTo.ColorPalette = _MemNew(m.SIZE)
_MemCopy m, m.OFFSET, m.SIZE To SaveTo.ColorPalette, SaveTo.ColorPalette.OFFSET
_MemFree m
End Select
End If
If Control_Code And 1024 Then SaveTo.Blink = _Blink
If Control_Code And 2048 Then
m = _MemImage(Image)
SaveTo.ScreenData = _MemNew(m.SIZE)
_MemCopy m, m.OFFSET, m.SIZE To SaveTo.ScreenData, SaveTo.ScreenData.OFFSET
_MemFree m
End If
End Sub
Sub RestoreSettings (FromWhat As Settings_Type, Image As Long)
Dim m As _MEM: m = _MemImage(0)
Dim As _Unsigned Long CC, PS 'save me some typing
CC = FromWhat.ControlCode
PS = FromWhat.PixelSize
If CC = 0 Then Exit Sub
If CC And 1 Then If FromWhat.AutoDisplay Then _AutoDisplay Else _Display
If CC And 2 Then If FromWhat.Blend Then _Blend Else _DontBlend
If CC And 4 Then _Dest FromWhat.Dest
If CC And 8 Then _Source FromWhat.Source
If CC And 16 Then Locate , FromWhat.CursorX
If CC And 32 Then Locate FromWhat.CursorY
If CC And 64 Then _Font FromWhat.Font, Image
If CC And 128 Then Color FromWhat.FgColor
If CC And 256 Then Color , FromWhat.BgColor
If CC And 512 Then
Select Case PS
Case 0, 256 '16 color palette and 256 color palette
If PS = 0 Then '16 colors for text screen
Limit = 15
Else
Limit = 255
End If
Dim Pal(0 To Limit) As _Unsigned Long
m = _Mem(Pal())
_MemCopy FromWhat.ColorPalette, FromWhat.ColorPalette.OFFSET, FromWhat.ColorPalette.SIZE To m, m.OFFSET
_MemFree m
For i = 0 To Limit
_PaletteColor i, Pal(i), Image
Next
End Select
End If
If CC And 1024 Then If FromWhat.Blink Then _Blink On Else _Blink Off
If CC And 2048 Then
m = _MemImage(Image)
_MemCopy FromWhat.ScreenData, FromWhat.ScreenData.OFFSET, FromWhat.ScreenData.SIZE To m, m.OFFSET
_MemFree m
End If
End Sub
Differences in these routines and what you currently have:
Yours only tracks: Static font&, dest&, source&, row&, col&, autodisplay&, mb&
This tracks:
'General Screen Settings '15
AutoDisplay As Long '1
Blend As Long '2
Dest As Long '4
Source As Long '8
'Font Settings '496
CursorX As Long '16
CursorY As Long '32
Font As Long '64
FgColor As _Unsigned Long '128
BgColor As _Unsigned Long '256
'Image Settings ' 2560
ColorPalette As _MEM '512
Blink As Long '1024
ScreenData As _MEM '2048
End Type
So that's all the screen data (the image itself can be restored), as well as its palette (in case that changes), with _blink, _blend, color, and background color all added to the mix.
Change 2: Yours holds the data in a STATIC variable, which means it has to be restored in the same routine, and the same pass, as the sub/function that uses it.
The new version uses a settings_type variable to track the changes, so it could be used inside a recursive sub/function -- or called in multiple subs/functions -- and unravel back out in the same order to get you back to your original screen in a FILO method.
Change 3: Yours requires you to get and store all the data that it holds, without choice in case you want any of the changes to actually remain.
The new version lets you specify *exactly* what you want to store and restore. (That's where all the nice CONST come in to help make things more intuitive for users.)
Only want to store the General Settings (AutoDisplay, Blend, Dest, Source) then simply call the sub with: GetSettings 0, Saver, General_Settings
Decide that you actually want your sub/function to be able to change the blend setting, but not those other three? GetSettings 0, Saver, General_Settings - AutoDisplay_Setting
Want to store it all? That's All_Settings
Just the image data, color palette, and blink status? That's Image_Settings
Recursive possible. More settings. Optional and customizable settings...
I'd call it a nice upgrade from the old version which you currently have saved and for use.