Page 1 of 3

Textmode Emulation on a WindowedScreen

Posted: Sun Sep 02, 2007 2:11 am
by Kaeru Gaman
because of an actual question, I sat down and wrote a complete Textmode emulation using a TileMap concept.

I like to share it here, should be complete and Code-Archive ready...

note that the demo pauses on windowevents like moving the mouse...

Code: Select all

;***************************************
;***
;*** Textmode Emulation Demo
;***
;*** by Kaeru Gaman, 2007-09-02
;***
;*** PB Ver 4.02
;***
;*** Code-Archive ready
;***
;***************************************
EnableExplicit    ; the obligative

;******************************************************************************
;*** Constants
#TxtScrn_ChrWi = 8
#TxtScrn_ChrHi = 16
#TxtScrn_MatWi = 80
#TxtScrn_MatHi = 30
; Screensize is Matrixsize * Charsize, here 640x480
#TxtScrn_ScrWi = #TxtScrn_MatWi * #TxtScrn_ChrWi
#TxtScrn_ScrHi = #TxtScrn_MatHi * #TxtScrn_ChrHi

#TxtScrn_CrsrSpd = 250  ; duration of Cursor-Phase

#PB_Event_TimeOut = 0   ; WaitWindowEvent Timeout

;******************************************************************************
;*** Variables
Define.l CrsrX, CrsrY 
Define.l EvID, EXIT = 0
Define.l GlobalTimer, DemoCommand, DemoMode = 1
Define.l ComX, ComY, ComT
Define.s CommandString, ComS

Global Dim TextScreen.c(#TxtScrn_MatWi-1,#TxtScrn_MatHi-1) 

;******************************************************************************
;*** Inits
If Not InitSprite()
  MessageRequester("Error","No DX")
EndIf

If Not OpenWindow(0,#PB_Ignore,#PB_Ignore,#TxtScrn_ScrWi,#TxtScrn_ScrHi,"Textmode Demo")
  MessageRequester("Error","No Window")
EndIf

If Not OpenWindowedScreen(WindowID(0),0,0,#TxtScrn_ScrWi,#TxtScrn_ScrHi,0,0,0)
  MessageRequester("Error","No Screen")
EndIf


;******************************************************************************
;*** Procedures
;******************************************************************************

;***************************************
;***
;***  Create_Charset()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** For the demo, I create a Charset on-the-fly out of Courier New.
;*** for serious use, you should create a Sprite-Charset manually
;*** sure you can keep this Proc for testing purposes
;***
;***************************************
Procedure Create_Charset()
  ;*** Creating the Charset
  Protected n.l
  LoadFont(0,"Courier New",10)  ; chars are 8x16pix
                                ; change the Font if you change the sizes
  
  For n=32 To 255 ; ASCII-codes 32 - 255 used
    CreateSprite(n,#TxtScrn_ChrWi,#TxtScrn_ChrHi)
    StartDrawing(SpriteOutput(n))
      DrawingFont(FontID(0))
      DrawText(0,0,Chr(n),$00FF00,$000000) ; green on black
    StopDrawing()
  Next
  
  ;*** Creating the Cursor
    CreateSprite(256,#TxtScrn_ChrWi,#TxtScrn_ChrHi)
    StartDrawing(SpriteOutput(256))
      Line(0,#TxtScrn_ChrHi-3,#TxtScrn_ChrWi,0,$00FF00) ; two filled lines
      Line(0,#TxtScrn_ChrHi-2,#TxtScrn_ChrWi,0,$00FF00) ; one line above the last line
    StopDrawing()
EndProcedure

;***************************************
;***
;***  TxtScrn_Clear( [RePos] )
;***
;***************************************
;*** Arguments    : (optional) #False to keep Cursor position
;*** Return Value : None
;***************************************
;***
;*** Textmatrix Function
;*** 
;*** Clears the internal Textmatrix
;***
;***************************************

Procedure TxtScrn_Clear(RePos = 1)
  Shared CrsrX.l, CrsrY.l
  Protected n.l, t.l
  For t=0 To #TxtScrn_MatHi-1
    For n=0 To #TxtScrn_MatWi-1
      TextScreen(n,t) = 32
    Next
  Next
  If RePos
    CrsrX = 0
    CrsrY = 0
  EndIf
EndProcedure

;***************************************
;***
;***  TxtScrn_Display()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** Textmatrix-to-Display Function
;*** 
;*** displays the internal Textmatrix
;*** to the current Output channel
;***
;***************************************
Procedure TxtScrn_Display()
  Protected n.l, t.l
  For t=0 To #TxtScrn_MatHi-1
    For n=0 To #TxtScrn_MatWi-1
      DisplaySprite(TextScreen(n,t),#TxtScrn_ChrWi*n,#TxtScrn_ChrHi*t)
    Next
  Next
EndProcedure

;***************************************
;***
;***  TxtScrn_Scroll()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** Textmatrix Function
;*** 
;*** scrolls the internal Textmatrix one line up.
;***
;***************************************
Procedure TxtScrn_Scroll()   ; scroll the textscreen up
  Protected n.l, t.l
  For t=0 To #TxtScrn_MatHi-2 ; one line less
    For n=0 To #TxtScrn_MatWi-1
      TextScreen(n,t) = TextScreen(n,t+1) ; replace chars by the line below
    Next
  Next
  For n=0 To #TxtScrn_MatWi-1
    TextScreen(n,#TxtScrn_MatHi-1) = 32 ; clear the last line
  Next
EndProcedure

;***************************************
;***
;***  TxtScrn_ShowCursor()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** Textmatrix-to-Display Function
;***
;*** shows the cursor of the internal
;*** Textmatrix on the screen,
;*** blinking in the defined rate.
;***
;***************************************
Procedure TxtScrn_ShowCursor()
  Static CrsrTimer.l
  Static CrsrMode.l
  Shared CrsrX.l, CrsrY.l

  If CrsrTimer = 0  ; first call
    CrsrTimer = ElapsedMilliseconds()
  EndIf

  If ElapsedMilliseconds() > CrsrTimer
    CrsrTimer + #TxtScrn_CrsrSpd
    CrsrMode = 1 - CrsrMode
  EndIf
  If CrsrMode
    DisplaySprite(256, #TxtScrn_ChrWi*CrsrX, #TxtScrn_ChrHi*CrsrY)
  EndIf
EndProcedure

;***************************************
;***
;***  TxtScrn_Locate(X.l, Y.l)
;***
;***************************************
;*** Arguments    : new Cursor Coordinates
;*** Return Value : #False if outside the Matrix
;***************************************
;***
;*** Textmatrix Function
;*** 
;*** moves the cursor of the internal
;*** Textmatrix to the specified position.
;*** if the position is outside the matrix,
;*** the cursor will not move.
;*** this can be used to create floating text,
;*** when a function always does positioning,
;*** like in this demo.
;***
;***************************************
Procedure.l TxtScrn_Locate(X.l, Y.l)
  Shared CrsrX.l, CrsrY.l
  If X >= 0 And X < #TxtScrn_MatWi And  Y >= 0 And Y < #TxtScrn_MatHi
    CrsrX = X
    CrsrY = Y
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

;***************************************
;***
;***  TxtScrn_Print(OutString.s)
;***
;***************************************
;*** Arguments    : String to write
;*** Return Value : #False if the Textmatrix had to be scrolled up
;***************************************
;***
;*** Textmatrix Function
;***
;*** writes the given String into
;*** the internal Textmatrix.
;***
;***************************************
Procedure.l TxtScrn_Print(OutString.s)
  Shared CrsrX.l, CrsrY.l
  Protected OutString_Pos.l = 1, OutString_Char.c, UnScrolled = #True
  Repeat
    OutString_Char = Asc(Mid(OutString, OutString_Pos, 1))
    Select OutString_Char
    ;***************************************
      Case 32 To 255  ; printable char?
        TextScreen(CrsrX, CrsrY) = OutString_Char
        CrsrX +1  ; next row
        If CrsrX > #TxtScrn_MatWi-1   ; right out
          CrsrX = 0   ; reset to leftmost row
          CrsrY +1    ; next line
          If CrsrY > #TxtScrn_MatHi-1   ; bottom out
            CrsrY -1          ; reset to bottom row
            TxtScrn_Scroll()  ; scroll the textscreen
            UnScrolled = #False
          EndIf
        EndIf
    ;***************************************
      Case 10, 13   ; newline
        ; note that both are used as newline,
        ; so a windows-style #CRLF$ will add TWO newlines
        CrsrX = 0   ; reset to leftmost row
        CrsrY +1    ; next line
        If CrsrY > #TxtScrn_MatHi-1   ; bottom out
          CrsrY -1          ; reset to bottom row
          TxtScrn_Scroll()  ; scroll the textscreen
          UnScrolled = #False
        EndIf
    ;***************************************
    ; add more Cases if you want
    ; e.g. BEEP or any ESCAPE-sequence
    EndSelect
    OutString_Pos +1
  Until OutString_Char = #NUL
EndProcedure

;******************************************************************************
;*** last preparations
Create_Charset()
TxtScrn_Clear()
;******************************************************************************
;*** Main Loop start
Repeat
  EvID = WaitWindowEvent(20)  ; FPS ~50

  Select EvID
    Case #PB_Event_TimeOut  ; no Event? ...carry on with the action
    ;***************************************
    ; the following is only for the demo
    ; to show the Procs work as they should
    ;***************************************
    ;*** Demo Action start
      If DemoMode   ; active until end of demo reached
        If GlobalTimer = 0  ; no timer, read next Command

          Read CommandString ; get DemoCommand
          DemoCommand = Asc(Left(CommandString,1))  ; leftmost token is the command

          Select DemoCommand

            Case 'T'  ; Timer Command
              ComT = Val(Mid(CommandString,3,4))  ; 4 letters timevalue
              GlobalTimer = ElapsedMilliseconds() + ComT

            Case 'P'  ; Print Command
              ComX = Val(Mid(CommandString,3,2))  ; 2 letters X-Pos
              ComY = Val(Mid(CommandString,6,2))  ; 2 letters Y-Pos
              ComS = Mid(CommandString,9,Len(CommandString))  ; rest is out$

                TxtScrn_Locate(ComX,ComY)   ; Locate Cursor
                TxtScrn_Print(ComS)         ; write text into array

            Case 'R'  ; Carriage Return Command
              ComS = #CR$
                TxtScrn_Print(ComS)         ; write text into array

            Case 'C'  ; Clear TextScreen Command
              TxtScrn_Clear()

            Case 'X'  ; 'Special' Command
              ComS = "and now" + #LF$
              ComS + "we test" + #CR$
              ComS + "the newline" + #CRLF$
              ComS + "note that #CRLF$ adds two lines..."
                TxtScrn_Print(ComS)         ; write text into array
            
            Case 'E'  ; End Demo Command
              DemoMode = 0

          EndSelect
        ElseIf ElapsedMilliseconds() > GlobalTimer  ; timer reached
          GlobalTimer = 0   ; reset
        EndIf
      EndIf
    ;*** Demo Action end
    ;***************************************
    Case #PB_Event_CloseWindow
      EXIT = 1
  EndSelect

  ;***************************************
  ;*** Screen Action start
  ClearScreen($000000)    ; not really necessary, because we cover the screen with sprites...
    TxtScrn_Display()     ; display the textmatrix array on the screen
    TxtScrn_ShowCursor()  ; show our cursor
  FlipBuffers()
  ;*** Screen Action end
  ;***************************************
  
Until EXIT
;*** Main Loop end
;******************************************************************************
End

;********************************************
; the whole Datasection is only for the Demo
;********************************************
DataSection
  ComTable:
  Data.s "P 13,15,this is a test"
  Data.s "T 1500"
  Data.s "P 17,09,this is another test"
  Data.s "T 1500"
  Data.s "P 00,16,the quick brown fox jumps over the lazy dog"
  Data.s "T 1000"
  Data.s "P 36,07,the quick brown fox jumps over the lazy dog"
  Data.s "T 1000"
  Data.s "P 18,12,the quick brown fox jumps over the lazy dog"
  Data.s "T 1000"
  Data.s "P 58,17,the quick brown fox jumps over the lazy dog"
  Data.s "T 2000"
  Data.s "P 15,10,worx nice... ain't it? ;)"
  Data.s "T 5000"
  Data.s "C"
  Data.s "P 27,13,special test for CR..."
  Data.s "T 2000"
  Data.s "X"
  Data.s "T 5000"
  Data.s "C"
  Data.s "P 23,13,special test for floating text..."
  Data.s "T 2000"
  Data.s "P 10,27,start here ->"
  Data.s "T 1000", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "R"
  Data.s "T 0200", "R"
  Data.s "T 0200", "R"
  Data.s "T 0200", "P -1,-1,mission accomplished."
  Data.s "T 0200", "R"
  Data.s "T 0200", "P -1,-1,click the close-button to end."
  Data.s "T 0200", "R"
  Data.s "T 9999", "P -1,-1,I'm serious, that's all....."

  Data.s "E"
EndDataSection

Posted: Sun Sep 02, 2007 9:15 am
by Kwai chang caine
I have make a code with almost the same effect but very less difficult :oops: , he use the EditorGadget.
But it's the efffect what i search.

The code of Kaeru Gaman is more better, for it, it's exactly what i want exept the windows and the font is not resizing and he can't read directly the character in the windows, an array is necessary.
And this option is very important for me.

Code: Select all

; EGA Emulation by Kwai chang caine
; With Help of Dobro, Srod, Chris, Derek, Kaeru Gaman, Ollivier
; PureBasic v4.10

#WindowsEGA = 1
#EditorMonochrome = 10

Global PositionCurseurY
Global PositionCurseurY

OpenWindow(#WindowsEGA, 0, 0, 520, 350, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
CreateGadgetList(WindowID(#WindowsEGA)) 
EditorGadget(#EditorMonochrome, 5, 5, 310, 140) 
Font = LoadFont(0, "Arial", GadgetHeight(#EditorMonochrome) /35) 
SetGadgetFont(0, Font) 
SetGadgetColor(#EditorMonochrome, #PB_Gadget_BackColor, RGB(0,0,0))
SetGadgetColor(#EditorMonochrome, #PB_Gadget_FrontColor, RGB(0,255,0))

For a = 1 To 24 
 AddGadgetItem(#EditorMonochrome, a, Space(80))
Next

Procedure WriteLineEGA(Col, Lig, Texte.s)
 
 LigneAvant.s = GetGadgetItemText(#EditorMonochrome, Lig - 1) 
 LigneApres.s = Left(LigneAvant, Col - 1) + Texte + Mid(LigneAvant,Col + Len(Texte) - 1, Len(LigneAvant) - Len(Texte) + 1)
 SetGadgetItemText(#EditorMonochrome, Lig - 1, LigneApres)

EndProcedure

Procedure.s ReadLineEGA(Col, Lig, Longueur)

 LigneComplete.s = GetGadgetItemText(#EditorMonochrome, Lig - 1) 
 ProcedureReturn Mid(LigneComplete, Col, Longueur)
 
EndProcedure

WriteLineEGA(10,24,"Hello")
Debug ReadLineEGA(10, 24, 5)
    
Repeat 
 
 Select WaitWindowEvent() 
 
  Case #PB_Event_SizeWindow 
 
   ResizeGadget(#EditorMonochrome, 1, 1, WindowWidth(#WindowsEGA) - 1, WindowHeight(#WindowsEGA) - 1) 
   Font = LoadFont(0, "Arial", GadgetHeight(#EditorMonochrome) / 35) 
   SetGadgetFont(#EditorMonochrome, Font)
       
  Case #PB_Event_CloseWindow 
 
   Break
 
 EndSelect 

ForEver
I keep moving ameliorate this one

Posted: Sun Sep 02, 2007 9:40 am
by Kaeru Gaman
> but very less difficult
in fact, this code is extremely simple.
is just a little too descriptive, and the demo-functions bloat it a bit.
you can throw everything out except the Procedures and the Global Array.

> use the EditorGadget.
wich is not in screenmode.

> exept the windows and the font is not resizing
wich textmode-screens never did.
but you can set the WindowedScreen on AutoStretch, and make the window resizable.
then you can resize the window, the chars will appear in different sizes,
and the textmatrix will alwys hold 80x30, no matter how you squeeze it.

> he can't read directly the character in the windows, an array is necessary.
wich was always so.
when you read chars out of a textscreen, you always read them out of the textmatrix.
in original textmodes, the matrix was in the grafix-card, for emulations you need your own array.
when you use an EditorGadget, the Gadget is your Textmatrix.
never you can read any characters out of a bitmap, or you'll need a neuronal net for letters interpretation.

when you want to drive on a Cart-Track, you'll need a Go-Cart.
no matter wether you build it youself, or you buy one from SEAT,
it's still a Go-Cart... ;)

Posted: Sun Sep 02, 2007 10:03 am
by DoubleDutch
Kwaï chang caïne wrote:The code of Kaeru Gaman is more better, for it, it's exactly what i want exept the windows and the font is not resizing and he can't read directly the character in the windows, an array is necessary.
Take another look at his code, it should be able to do everything you want. It's not difficult to read! :)

You could try my alternative, ConsoleX...

http://www.purebasic.fr/english/viewtop ... 698#208698

You just use console mode as normal, just add an X to the end of console commands.

Posted: Sun Sep 02, 2007 10:07 am
by Kwai chang caine
wich is not in screenmode.
Yes yes , i know that :wink:
I prefer the screen mode but i search all solution for do ALL the thing i want :wink:
Your code is better than mine, and is that i want, but the problem is the array :cry: if an user write a character with the keyboard or another thing.
If i can't read exactly what is write on the screen, it was perhaps possible to forget some character and it's embarassing :cry:
when you want milk, you'll need a cow, a sheep or a goat.
you can't take a fish or a crocodile.
:lol: Excuse me if i'm weighty man, i'm a beginner, in english AND purebasic it's very difficult for me to do understand what i want.
I have no understand the mechanism of screen mode.
Now, it's more good, with you and derek.

An additional function would be super, the possibility of an user to write with a key somme character :wink:

Thank you very much again, a thousand thanks :D

Posted: Sun Sep 02, 2007 10:30 am
by Kaeru Gaman
but the problem is the array if an user write a character with the keyboard or another thing.
If i can't read exactly what is write on the screen, it was perhaps possible to forget some character and it's embarassing
you ALWAYS have an Array where Text is stored.

when you use a TextGadget, there is an internal array that holds the string.
windows fetches it from there, get's the chars' bitmaps from the font,
and draws the pixels on the screen.
when you request the string, you access the array, not the screen.

it's the same for every kind of displaying text.
the text-information is stored somewhere in an array.

there are two layers of handling:
1) the text in/out, communication between your routines and the text-array.
2) the grafix display, some routines reading the Array and displaying the char-bitmaps on the screen.

what you said to be easier is just, that you use the windows-implemented version of Layer2
but no matter if you do so, or if you write your own handling - it is always the same.

if you need keyboard input, take a key, write it into the array at the cursor position and move the cursor.
in fact, my "print" procedure already handles the writing into the array,
you only need to add the keyboard-reading.

you can exactly read what is on the screen, because it's char by char within the array.

and no, it is NOT possible to forget some charakters.
Arrays do never forget anything. programmes do.


I'm sorry when I sound harsh, but it's some kind of annoying.
but this is not your fault, it's a generations problem.
in the early 80ies, the textmode was absolute standard,
because any grafic mode would have been far too slow.
I programmed Game-Maps and Charsets (Fonts) those days,
so that topic is something absolutely natural for me.

Posted: Sun Sep 02, 2007 10:44 am
by Derek
@Kaeru, you shouldn't hard code the width and height of the characters but should get them from the font that is being used otherwise if the user loads in a different size font the characters get clipped.

If you get the size from the font and use a windowedscreen that is autostetched then you don't have to worry about clipping.

Posted: Sun Sep 02, 2007 10:59 am
by Kwai chang caine
@Kaeru Gaman

Thanks for your full explain 8)
You can't believe that, but i have UNDERSTAND :lol: It's a miracle !!!! Alleluia :lol:

Ok, it's good to use an array :D Like window :D
I change my mind thank to you :wink:

I don't know how you return thanks
You are an angel :D

@DoubleDutch

I have download your lib.
She is great 8)
But i dont't understand the "GetVarXcx" and "GetVarXcy" fonctions :shock:
I need a fonction for read character, is it the good fonction for do this ?
If is not, has what this serves ?

Posted: Sun Sep 02, 2007 11:13 am
by Kaeru Gaman
Kwaï chang caïne wrote:Thanks for your full explain 8)
You can't believe that, but i have UNDERSTAND :lol: It's a miracle !!!! Alleluia :lol:
:D I'm glad to hear this.

...I added the requested functionality...

1) Resizable Output
this was just adding a #PB_Window_SizeGadget to the window,and an AutoStretch to the WindowedScreen.

Code: Select all

OpenWindow(0,#PB_Ignore,#PB_Ignore,#TxtScrn_ScrWi,#TxtScrn_ScrHi,"Textmode Demo", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
OpenWindowedScreen(WindowID(0),0,0,#TxtScrn_ScrWi,#TxtScrn_ScrHi,1,0,0)
2) a Read-Function
here we go

Code: Select all

;***************************************
;***
;***  TxtScrn_Read(X.l, Y.l, Lng.l)
;***
;***************************************
;*** Arguments    : Starting Coordinates and length of string to read
;*** Return Value : String read from the Textmatrix
;***************************************
;***
;*** Textmatrix Function
;***
;*** reads a String of the requested length
;*** from the internal Textmatrix.
;***
;***************************************
Procedure.s TxtScrn_Read(X.l, Y.l, Lng.l)
  Protected ReturnString.s, GetString_Char.c
  If X >= 0 And X < #TxtScrn_MatWi And  Y >= 0 And Y < #TxtScrn_MatHi And Lng > 0
    Repeat
      GetString_Char = TextScreen(X, Y)   ; get the char from the matrix
      ReturnString + Chr(GetString_Char)  ; add it to the String
        X +1  ; next row
        If X > #TxtScrn_MatWi-1   ; right out
          X = 0   ; reset to leftmost row
          Y +1    ; next line
          If Y > #TxtScrn_MatHi-1   ; bottom out
            Lng = 0   ; stop reading and leave proc
          EndIf
        EndIf
      Lng -1
    Until Lng = 0
  Else
    ReturnString = Chr(4)   ; Return EOT if trying to read outside the matrix.
  EndIf
  ProcedureReturn ReturnString
EndProcedure
for those who want to copy-paste-test it rightaway, I post the complete code again.
a demonstration of the read-function was added.

Code: Select all

;***************************************
;***
;*** Textmode Emulation Demo
;***
;*** by Kaeru Gaman, 2007-09-02
;***
;*** PB Ver 4.02
;***
;*** Code-Archive ready
;***
;***************************************
EnableExplicit    ; the obligative

;******************************************************************************
;*** Constants
#TxtScrn_ChrWi = 8
#TxtScrn_ChrHi = 16
#TxtScrn_MatWi = 80
#TxtScrn_MatHi = 30
; Screensize is Matrixsize * Charsize, here 640x480
#TxtScrn_ScrWi = #TxtScrn_MatWi * #TxtScrn_ChrWi
#TxtScrn_ScrHi = #TxtScrn_MatHi * #TxtScrn_ChrHi

#TxtScrn_CrsrSpd = 250  ; duration of Cursor-Phase

#PB_Event_TimeOut = 0   ; WaitWindowEvent Timeout

;******************************************************************************
;*** Variables
Define.l CrsrX, CrsrY 
Define.l EvID, EXIT = 0
Define.l GlobalTimer, DemoCommand, DemoMode = 1
Define.l ComX, ComY, ComT, ComL
Define.s CommandString, ComS

Global Dim TextScreen.c(#TxtScrn_MatWi-1,#TxtScrn_MatHi-1) 

;******************************************************************************
;*** Inits
If Not InitSprite()
  MessageRequester("Error","No DX")
EndIf

If Not OpenWindow(0,#PB_Ignore,#PB_Ignore,#TxtScrn_ScrWi,#TxtScrn_ScrHi,"Textmode Demo", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
  MessageRequester("Error","No Window")
EndIf

If Not OpenWindowedScreen(WindowID(0),0,0,#TxtScrn_ScrWi,#TxtScrn_ScrHi,1,0,0)
  MessageRequester("Error","No Screen")
EndIf


;******************************************************************************
;*** Procedures
;******************************************************************************

;***************************************
;***
;***  Create_Charset()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** For the demo, I create a Charset on-the-fly out of Courier New.
;*** for serious use, you should create a Sprite-Charset manually
;*** sure you can keep this Proc for testing purposes
;***
;***************************************
Procedure Create_Charset()
  ;*** Creating the Charset
  Protected n.l
  LoadFont(0,"Courier New",10)  ; chars are 8x16pix
                                ; change the Font if you change the sizes
  
  For n=32 To 255 ; ASCII-codes 32 - 255 used
    CreateSprite(n,#TxtScrn_ChrWi,#TxtScrn_ChrHi)
    StartDrawing(SpriteOutput(n))
      DrawingFont(FontID(0))
      DrawText(0,0,Chr(n),$00FF00,$000000) ; green on black
    StopDrawing()
  Next
  
  ;*** Creating the Cursor
    CreateSprite(256,#TxtScrn_ChrWi,#TxtScrn_ChrHi)
    StartDrawing(SpriteOutput(256))
      Line(0,#TxtScrn_ChrHi-3,#TxtScrn_ChrWi,0,$00FF00) ; two filled lines
      Line(0,#TxtScrn_ChrHi-2,#TxtScrn_ChrWi,0,$00FF00) ; one line above the last line
    StopDrawing()
EndProcedure

;***************************************
;***
;***  TxtScrn_Clear( [RePos] )
;***
;***************************************
;*** Arguments    : (optional) #False to keep Cursor position
;*** Return Value : None
;***************************************
;***
;*** Textmatrix Function
;*** 
;*** Clears the internal Textmatrix
;***
;***************************************

Procedure TxtScrn_Clear(RePos = 1)
  Shared CrsrX.l, CrsrY.l
  Protected n.l, t.l
  For t=0 To #TxtScrn_MatHi-1
    For n=0 To #TxtScrn_MatWi-1
      TextScreen(n,t) = 32
    Next
  Next
  If RePos
    CrsrX = 0
    CrsrY = 0
  EndIf
EndProcedure

;***************************************
;***
;***  TxtScrn_Display()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** Textmatrix-to-Display Function
;*** 
;*** displays the internal Textmatrix
;*** to the current Output channel
;***
;***************************************
Procedure TxtScrn_Display()
  Protected n.l, t.l
  For t=0 To #TxtScrn_MatHi-1
    For n=0 To #TxtScrn_MatWi-1
      DisplaySprite(TextScreen(n,t),#TxtScrn_ChrWi*n,#TxtScrn_ChrHi*t)
    Next
  Next
EndProcedure

;***************************************
;***
;***  TxtScrn_Scroll()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** Textmatrix Function
;*** 
;*** scrolls the internal Textmatrix one line up.
;***
;***************************************
Procedure TxtScrn_Scroll()   ; scroll the textscreen up
  Protected n.l, t.l
  For t=0 To #TxtScrn_MatHi-2 ; one line less
    For n=0 To #TxtScrn_MatWi-1
      TextScreen(n,t) = TextScreen(n,t+1) ; replace chars by the line below
    Next
  Next
  For n=0 To #TxtScrn_MatWi-1
    TextScreen(n,#TxtScrn_MatHi-1) = 32 ; clear the last line
  Next
EndProcedure

;***************************************
;***
;***  TxtScrn_ShowCursor()
;***
;***************************************
;*** Arguments    : None
;*** Return Value : None
;***************************************
;***
;*** Textmatrix-to-Display Function
;***
;*** shows the cursor of the internal
;*** Textmatrix on the screen,
;*** blinking in the defined rate.
;***
;***************************************
Procedure TxtScrn_ShowCursor()
  Static CrsrTimer.l
  Static CrsrMode.l
  Shared CrsrX.l, CrsrY.l

  If CrsrTimer = 0  ; first call
    CrsrTimer = ElapsedMilliseconds()
  EndIf

  If ElapsedMilliseconds() > CrsrTimer
    CrsrTimer + #TxtScrn_CrsrSpd
    CrsrMode = 1 - CrsrMode
  EndIf
  If CrsrMode
    DisplaySprite(256, #TxtScrn_ChrWi*CrsrX, #TxtScrn_ChrHi*CrsrY)
  EndIf
EndProcedure

;***************************************
;***
;***  TxtScrn_Locate(X.l, Y.l)
;***
;***************************************
;*** Arguments    : new Cursor Coordinates
;*** Return Value : #False if outside the Matrix
;***************************************
;***
;*** Textmatrix Function
;*** 
;*** moves the cursor of the internal
;*** Textmatrix to the specified position.
;*** if the position is outside the matrix,
;*** the cursor will not move.
;*** this can be used to create floating text,
;*** when a function always does positioning,
;*** like in this demo.
;***
;***************************************
Procedure.l TxtScrn_Locate(X.l, Y.l)
  Shared CrsrX.l, CrsrY.l
  If X >= 0 And X < #TxtScrn_MatWi And  Y >= 0 And Y < #TxtScrn_MatHi
    CrsrX = X
    CrsrY = Y
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

;***************************************
;***
;***  TxtScrn_Print(OutString.s)
;***
;***************************************
;*** Arguments    : String to write
;*** Return Value : #False if the Textmatrix had to be scrolled up
;***************************************
;***
;*** Textmatrix Function
;***
;*** writes the given String into
;*** the internal Textmatrix.
;***
;***************************************
Procedure.l TxtScrn_Print(OutString.s)
  Shared CrsrX.l, CrsrY.l
  Protected OutString_Pos.l = 1, OutString_Char.c, UnScrolled = #True
  Repeat
    OutString_Char = Asc(Mid(OutString, OutString_Pos, 1))
    Select OutString_Char
    ;***************************************
      Case 32 To 255  ; printable char?
        TextScreen(CrsrX, CrsrY) = OutString_Char
        CrsrX +1  ; next row
        If CrsrX > #TxtScrn_MatWi-1   ; right out
          CrsrX = 0   ; reset to leftmost row
          CrsrY +1    ; next line
          If CrsrY > #TxtScrn_MatHi-1   ; bottom out
            CrsrY -1          ; reset to bottom row
            TxtScrn_Scroll()  ; scroll the textscreen
            UnScrolled = #False
          EndIf
        EndIf
    ;***************************************
      Case 10, 13   ; newline
        ; note that both are used as newline,
        ; so a windows-style #CRLF$ will add TWO newlines
        CrsrX = 0   ; reset to leftmost row
        CrsrY +1    ; next line
        If CrsrY > #TxtScrn_MatHi-1   ; bottom out
          CrsrY -1          ; reset to bottom row
          TxtScrn_Scroll()  ; scroll the textscreen
          UnScrolled = #False
        EndIf
    ;***************************************
    ; add more Cases if you want
    ; e.g. BEEP or any ESCAPE-sequence
    EndSelect
    OutString_Pos +1
  Until OutString_Char = #NUL
EndProcedure

;***************************************
;***
;***  TxtScrn_Read(X.l, Y.l, Lng.l)
;***
;***************************************
;*** Arguments    : Starting Coordinates and length of string to read
;*** Return Value : String read from the Textmatrix
;***************************************
;***
;*** Textmatrix Function
;***
;*** reads a String of the requested length
;*** from the internal Textmatrix.
;***
;***************************************
Procedure.s TxtScrn_Read(X.l, Y.l, Lng.l)
  Protected ReturnString.s, GetString_Char.c
  If X >= 0 And X < #TxtScrn_MatWi And  Y >= 0 And Y < #TxtScrn_MatHi And Lng > 0
    Repeat
      GetString_Char = TextScreen(X, Y)   ; get the char from the matrix
      ReturnString + Chr(GetString_Char)  ; add it to the String
        X +1  ; next row
        If X > #TxtScrn_MatWi-1   ; right out
          X = 0   ; reset to leftmost row
          Y +1    ; next line
          If Y > #TxtScrn_MatHi-1   ; bottom out
            Lng = 0   ; stop reading and leave proc
          EndIf
        EndIf
      Lng -1
    Until Lng = 0
  Else
    ReturnString = Chr(4)   ; Return EOT if trying to read outside the matrix.
  EndIf
  ProcedureReturn ReturnString
EndProcedure

;******************************************************************************
;*** last preparations
Create_Charset()
TxtScrn_Clear()
;******************************************************************************
;*** Main Loop start
Repeat
  EvID = WaitWindowEvent(20)  ; FPS ~50

  Select EvID
    Case #PB_Event_TimeOut  ; no Event? ...carry on with the action
    ;***************************************
    ; the following is only for the demo
    ; to show the Procs work as they should
    ;***************************************
    ;*** Demo Action start
      If DemoMode   ; active until end of demo reached
        If GlobalTimer = 0  ; no timer, read next Command

          Read CommandString ; get DemoCommand
          DemoCommand = Asc(Left(CommandString,1))  ; leftmost token is the command

          Select DemoCommand

            Case 'T'  ; Timer Command
              ComT = Val(Mid(CommandString,3,4))  ; 4 letters timevalue
              GlobalTimer = ElapsedMilliseconds() + ComT

            Case 'P'  ; Print Command
              ComX = Val(Mid(CommandString,3,2))  ; 2 letters X-Pos
              ComY = Val(Mid(CommandString,6,2))  ; 2 letters Y-Pos
              ComS = Mid(CommandString,9,Len(CommandString))  ; rest is out$

                TxtScrn_Locate(ComX,ComY)   ; Locate Cursor
                TxtScrn_Print(ComS)         ; write text into array

            Case 'R'  ; Carriage Return Command
              ComS = #CR$
                TxtScrn_Print(ComS)         ; write text into array

            Case 'C'  ; Clear TextScreen Command
              TxtScrn_Clear()

            Case 'D'  ; Debug Command
              ComX = Val(Mid(CommandString,3,2))  ; 2 letters X-Pos
              ComY = Val(Mid(CommandString,6,2))  ; 2 letters Y-Pos
              ComL = Val(Mid(CommandString,9,2))  ; 2 letters length

              ComS = TxtScrn_Read(ComX, ComY, ComL)
              Debug ComS

            Case 'X'  ; 'Special' Command
              ComS = "and now" + #LF$
              ComS + "we test" + #CR$
              ComS + "the newline" + #CRLF$
              ComS + "note that #CRLF$ adds two lines..."
                TxtScrn_Print(ComS)         ; write text into array
            
            Case 'E'  ; End Demo Command
              DemoMode = 0

          EndSelect
        ElseIf ElapsedMilliseconds() > GlobalTimer  ; timer reached
          GlobalTimer = 0   ; reset
        EndIf
      EndIf
    ;*** Demo Action end
    ;***************************************
    Case #PB_Event_CloseWindow
      EXIT = 1
  EndSelect

  ;***************************************
  ;*** Screen Action start
  ClearScreen($000000)    ; not really necessary, because we cover the screen with sprites...
    TxtScrn_Display()     ; display the textmatrix array on the screen
    TxtScrn_ShowCursor()  ; show our cursor
  FlipBuffers()
  ;*** Screen Action end
  ;***************************************
  
Until EXIT
;*** Main Loop end
;******************************************************************************
End

;********************************************
; the whole Datasection is only for the Demo
;********************************************
DataSection
  ComTable:
  Data.s "P 13,15,this is a test"
  Data.s "T 1500"
  Data.s "P 17,09,this is another test"
  Data.s "T 1500"
  Data.s "P 00,16,the quick brown fox jumps over the lazy dog"
  Data.s "T 1000"
  Data.s "P 36,07,the quick brown fox jumps over the lazy dog"
  Data.s "T 1000"
  Data.s "P 18,12,the quick brown fox jumps over the lazy dog"
  Data.s "T 1000"
  Data.s "P 58,17,the quick brown fox jumps over the lazy dog"
  Data.s "T 2000"
  Data.s "P 15,10,worx nice... ain't it? ;)"
  Data.s "T 5000"
  Data.s "C"
  Data.s "P 27,13,special test for CR..."
  Data.s "T 2000"
  Data.s "X"
  Data.s "T 5000"
  Data.s "C"
  Data.s "P 23,13,special test for floating text..."
  Data.s "T 2000"
  Data.s "P 10,27,start here ->"
  Data.s "T 1000", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "P -1,-1,this "    , "T 0200", "P -1,-1,is "   , "T 0200", "P -1,-1,the "    , "T 0200", "P -1,-1,poem "
  Data.s "T 0200", "P -1,-1,to "      , "T 0200", "P -1,-1,kill " , "T 0200", "P -1,-1,your "   , "T 0200", "P -1,-1,nerves "
  Data.s "T 0200", "P -1,-1,because " , "T 0200", "P -1,-1,it "   , "T 0200", "P -1,-1,never "  , "T 0200", "P -1,-1,ends!   "
  Data.s "T 0200", "R"
  Data.s "T 0200", "R"
  Data.s "T 0200", "R"
  Data.s "T 0200", "P -1,-1,mission accomplished."

  Data.s "T 1500", "P 10,04,and now we test the reading."
  Data.s "D 05,23,17"  

  Data.s "T 1500", "P 10,05,and we overwrite the part we read to see if it worked correctly."
  Data.s "P 05,23,#################"  

  Data.s "E"
EndDataSection

Posted: Sun Sep 02, 2007 11:28 am
by DoubleDutch
But i dont't understand the "GetVarXcx" and "GetVarXcy" fonctions
They are for finding the current cursor x and y.

I'll put in a ConsolePoint([x][,y]) command to get the chr at the point specified soon, just a bit busy at present.

Posted: Sun Sep 02, 2007 11:31 am
by Kwai chang caine
Ok DoubleDutch :wink:

Thanks

Posted: Sun Sep 02, 2007 11:56 am
by Kwai chang caine
@Kaeru Gaman
Then ......i was verry happy :D
I believe that all is in the code.

Perhaps a procedure to change size and colour of the original start font :oops:
And a choice for the form of the cursor "_" or a black square :oops: :oops:
I found the line of he is

Code: Select all

DisplaySprite(157, #TxtScrn_ChrWi*CrsrX, #TxtScrn_ChrHi*CrsrY) 
But i don't know what the value i can write :cry:
With 157 the square is white and i want this of course black :D

And i have a new idée :D
Can you set up the cursor with the mouse :oops:
Or if is not possible, can you return the position of the mouse in the consolescreen when i clik :D

Aaaarrch !!! This beginner, he is never glad :lol:

Posted: Sun Sep 02, 2007 1:10 pm
by Kaeru Gaman
Derek wrote:@Kaeru, you shouldn't hard code the width and height of the characters but should get them from the font that is being used otherwise if the user loads in a different size font the characters get clipped.

If you get the size from the font and use a windowedscreen that is autostetched then you don't have to worry about clipping.
I do not worry about Font sizes.
read the comment, it sais, you'd better use a self-created spritefont.
if a Programmer wants to use another Font, he has to load another one,
take care that it is a fixedwidth one, and change the size of the chars.
surely he also can use different fonts for different outputs.
you can create various arrays and display them to different sprites
to have several textareas of different sizes on one screen.

the size of the screen is determined by the charsize and the matrix size, as you can see.
even with the new resizable output, the basic screensize stays the same.

a User cannot load or chose any Font here.
this is no console, this is no application, this is Game-Coding.
...have you ever seen varable font sizes in Game elements? surely not.

Posted: Sun Sep 02, 2007 1:23 pm
by Kaeru Gaman
Perhaps a procedure to change size and colour of the original start font
as said, the routine for creating the charset out of a font is just "for testing purposes".
you should prefer a self-created spritefont.
but you can chose any font you want...
just look up the size of the chars by putting some into PAINT.
...and always use a fixedwidth font. the textscreen-concept is NOT suitable for proportional fonts.
And a choice for the form of the cursor "_" or a black square
...
With 157 the square is white and i want this of course black
the char for the cursor is Sprite No. 256, and it's created on it's own.
you can give it any look you want.

but a black square on black ground? :?
you have to SEE a cursor to use it, don't you?
Can you set up the cursor with the mouse
Or if is not possible, can you return the position of the mouse in the consolescreen when i clik
sure I could implement mousehandling...
but there should be something left for you to program...

it's easy. since the size of a char is fixed, you can directly calculate
the coordinates on the textmatrix out of the screen- or window-coordinates of the mouse.

Posted: Sun Sep 02, 2007 3:40 pm
by Kwai chang caine
but there should be something left for you to program...
Don't worry, :wink: it's just for know if it possible.
I don't want obligate you to do any code, if you have not the desire to do this.
It's just somes ideas to ameliorate your super code :wink:
You have already made for me a lot. 8)
I do not want to disturb you :oops:

I have again many code to do after this screen.
This screen is the viewer of a big and long code and it's not simple for me :cry:
but a black square on black ground?
you have to SEE a cursor to use it, don't you?
Excuse me, i have made a mistake :oops:
The character that i want is a square green in background black. :wink:
Like the old computer IBM :D

Thanks again for your interest and friendiness 8)