Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a little tutorial STEP by STEP on scrolling in 2D graphic mode
#18
@SMcNeill
Hey man thanks for remembering us the use of _MEM, the QB64pe pointers.
So, as I got some time to spend into this features I go on with your demo.
It is fantastic! What can I modify to be nearest to _MEM logic?
Yes filling the screen using the same _MEM functions.
And ,TADA, here it is

So thanks, you have brought me to understand (o to remember?)how characters are stored into screen 0 memory.

I hope you like it.

Code: (Select All)

_ControlChr Off
Dim Shared As Long Display, Widescreen
Display = _NewImage(120, 30, 0)
Widescreen = _NewImage(360, 90, 0) '3 times the display size.
Screen Display
_Dest Widescreen

Dim m As _MEM  ' our MEM pointer
m = _MemImage(Widescreen)

'Fill the widescreen with some text

' il colore in memoria e' conservato come ASCII con valore del risultato di questa formula Fg+(Fg*Bg)+Bg
' ogni carattere usa 2 byte il primo e' il carattere il secondo e' il valore per colore primo piano e colore sfondo


For c = 1 To 3
    For d = 1 To 30
        finalLine$ = ""
        base$ = Line120$(d)
        finalLine$ = RawLine120$(base$, ColorText(15 - c, 7 - c)) + RawLine120$(base$, ColorText(15 - (c + 1), 7 - (c + 3))) + RawLine120$(base$, ColorText(15 - (c + 2), 7 - (c + 4)))
        _MemPut m, m.OFFSET + ((d - 1) * 720) + ((c - 1) * 720 * 30), finalLine$
    Next d
Next c
_MemFree m

'---------------> the PRINT method used in the original code<----------------------
''For xframe = 0 To 2
''    For yframe = 0 To 2
''        c = c + 1
''        For y = 1 To 30
''            Color 15 - c, c
''            Locate yframe * 30 + y, xframe * 120 + 1
''            p$ = Str$(y) + ") LINE NUMBER #" + Str$(y) + Space$(120)
''            p$ = Left$(p$, 120)
''            Print p$;
''        Next
''    Next
''Next
'--------------------><---------------------------------------------------------------

xstart = 1: ystart = 1
Do
    While _MouseInput: Wend

    If _MouseX <= 3 Then xstart = xstart - 1
    If _MouseX >= 118 Then xstart = xstart + 1
    If _MouseY <= 3 Then ystart = ystart - 1
    If _MouseY >= 28 Then ystart = ystart + 1
    If xstart < 1 Then xstart = 1
    If ystart < 1 Then ystart = 1
    If xstart > 241 Then xstart = 241
    If ystart > 61 Then ystart = 61

    PutZero xstart, ystart
    _Limit 30
Loop Until _KeyHit
End

Sub PutZero (xstart, ystart)
    Dim As _MEM m(1)
    m(0) = _MemImage(Display)
    m(1) = _MemImage(Widescreen)
    Dim As _Integer64 yOffset, xOffset, y
    yOffset = (ystart - 1) * 720
    xOffset = (xstart - 1) * 2
    Dim temp As String * 240
    For y = 0 To 29
        _MemGet m(1), m(1).OFFSET + yOffset + y * 720 + xOffset, temp
        _MemPut m(0), m(0).OFFSET + y * 240, temp
    Next
    _MemFree m(0)
    _MemFree m(1)
End Sub

' NEWCODE  for filling the video screen memory
Function ColorText (Fg As Integer, Bg As Integer)
    ColorText = Fg + (Fg * Bg) + Bg
End Function

Function Line120$ (a As Integer)
    p$ = Str$(a) + ") LINE NUMBER #" + Str$(a) + Space$(120)
    p$ = Left$(p$, 120)
    Line120$ = p$
End Function

Function RawLine120$ (a As String, b As Integer)
    For c = 1 To Len(a)
        t$ = t$ + Chr$(Asc(a, c)) + Chr$(b)
    Next c
    RawLine120$ = t$
End Function
Reply


Messages In This Thread
RE: a little tutorial STEP by STEP on scrolling in 2D graphic mode - by TempodiBasic - 12-14-2024, 11:28 AM



Users browsing this thread: 1 Guest(s)