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.
'
' 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