Author Topic: TinyPTC Framework Example.  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
TinyPTC Framework Example.
« on: January 22, 2007 »
Here's an example Framework of how to create and run programs using the TinyPTC library.
Although I've based this around Rbraz's TinyPtc with mmx update, this code will also work just as well with the original Freebasic TinyPTC version.
 
Code: [Select]
'
' RBRAZ - TinyPtc Framework Example
' By Clyde Radcliffe
' In January 2007
'

Option Explicit
Option Static

#Include Once "TinyPTC.bi"
#Include Once "Windows.bi"
#Include Once "crt.bi"

Const XRES=640
Const YRES=480
Const ARES=XRES*YRES

Dim Shared ScreenBuffer( ARES )

'
' Subs And Function Initialization.
'
Declare Sub CloseProgram     ( )
Declare Sub FeedPixels       ( Byval x As Integer, Byval y As Integer, Byval col As Integer )
Declare Sub InitializeProgram( ByVal ProgramTitle As String="FB Program using TinyPTC" )
Declare Sub RunProgram       ( )

Declare Function KeyDown( ByVal KeyChar As Integer ) As Integer
Declare Function KeyHit ( ByVal KeyChar As Integer ) As Integer


'
' Running Order.
'
InitializeProgram()
RunProgram()
CloseProgram()
End


Sub CloseProgram()
   
    '
    ' Place to put shutdown instructions
    ' for gfx, music, etc.
    '
   
    '
    ' Close down TinyPtc.
    '
    PTC_Close()
   
End Sub


Sub FeedPixels( Byval x As Integer, Byval y As Integer, Byval col As Integer )
       
    If X>0 and X<XRES-1 and Y>0 and Y<YRES-1 Then
        ScreenBuffer(y*XRES+x) = Col
    End If

End Sub


Sub InitializeProgram( ByVal ProgramTitle As String="FB Program using TinyPTC" )
   
    '
    ' Program name and Screen set up.
    '
    If( Ptc_Open( ProgramTitle, XRES, YRES ) = 0 ) Then
End -1                                   
    End If
   
    '
    ' Load GFX, Perform calculations and setup lookup tables etc.
    '
   
End Sub


Sub RunProgram()
   
    '
    ' Proceed if Escape Key hasn't been pressed.
    '
    While KeyHit(27)<>TRUE
       
        '
        ' Update Program Routines.
        '
       
        '
        ' Update Screen With Colour info stored in ScreenBuffer
        ' Starting at location 0.
        '
        PTC_Update @ScreenBuffer(0)
        Erase ScreenBuffer
       
    Wend
   
End Sub


Function KeyDown( ByVal KeyChar As Integer ) As Integer

    If GetAsyncKeyState(KeyChar) Then
        Return TRUE
    Else
        Return FALSE
    End if

End Function


Function KeyHit( ByVal KeyChar As Integer ) As Integer

    If (GetAsyncKeyState(KeyChar) AND 32768) Then
        Return TRUE
    Else
        Return FALSE
    End if

End Function
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: TinyPTC Framework Example.
« Reply #1 on: January 22, 2007 »
That's useful :) Should help some peeps get started mate! + Karma.
Shockwave ^ Codigos
Challenge Trophies Won: