I fixed this up to work with version .21. There were a few errors since the variable declaration format has changed since .15.
ttdblitzvib1.bi
'-------------------------------------------------------------------
' The Tin Dragons
' TinyPTC Based Lib to emulate a blitz2d like enviroment
'
' by Joncom2000
' Coded May 2006
'
'-------------------------------------------------------------------
'-------------------------------------------------------------------
' Includes
'-------------------------------------------------------------------
#Include Once "tinyptc.bi"
'-------------------------------------------------------------------
' Setup Constants
'-------------------------------------------------------------------
'-------------------------------------------------------------------
' Declare Globals
'-------------------------------------------------------------------
dim shared as integer ptr Backbuffer
dim shared as integer XRES, YRES
'-------------------------------------------------------------------
' Pre Declare Subroutines
'-------------------------------------------------------------------
declare sub TTDGraphics(ByVal x as integer, ByVal y as integer, Byval title as string)
declare sub TTDEndGraphics()
declare sub TTDFlip()
declare sub TTDCls(ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
declare sub TTDFastCls(ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
declare sub TTDPlot(ByVal x as integer, ByVal y as integer,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
declare sub TTDLine(ByVal x1 as double, ByVal y1 as double,ByVal x2 as double, ByVal y2 as double,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer,ByVal Alpha as single)
declare sub TTDOval(ByVal xCenter as integer,ByVal yCenter as integer,ByVal Rx as integer,ByVal Ry as integer,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
'-------------------------------------------------------------------
' Actual Subroutines Follow
'-------------------------------------------------------------------
'-------------------------------------------------------------------
' NAME : TTDGraphics()
' PURPOSE : This function opens a screen display
' INPUTS : x=width, y=height, title=app title.
' RETURNS : nothing.
'-------------------------------------------------------------------
Sub TTDGraphics(ByVal x as integer, ByVal y as integer, ByVal title as string)
if ptc_open(title, x, y) = 0 then
print "Cannot open compatible graphics display :"+str(x)+", "+str(y)
sleep
end -1
endif
Backbuffer = callocate(x*y, Len(integer))
XRES=x
YRES=y
End Sub
'-------------------------------------------------------------------
' NAME : TTDFlip()
' PURPOSE : This function Flips the backbuffer into view
' INPUTS : None.
' RETURNS : nothing.
'-------------------------------------------------------------------
Sub TTDFlip()
ptc_update(Backbuffer)
End Sub
'-------------------------------------------------------------------
' NAME : TTDEndGraphics()
' PURPOSE : This function closes ptc window
' INPUTS : None.
' RETURNS : nothing.
'-------------------------------------------------------------------
Sub TTDEndGraphics()
ptc_close
End Sub
'-------------------------------------------------------------------
' NAME : TTDCls()
' PURPOSE : This function clears the buffer to RGB passed
' INPUTS : Red, Green,Blue values range 0-255.
' RETURNS : nothing.
'-------------------------------------------------------------------
Sub TTDCls(ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
Dim ClsColor as integer
ClsColor= ( Red shl 16 ) + ( Green shl 8 ) + Blue
For y As Integer=0 to YRES-1
For x As Integer=0 to XRES-1
Backbuffer[(y*XRES+x)] = ClsColor
next
next
End Sub
'-------------------------------------------------------------------
' NAME : TTDFastCls()
' PURPOSE : This function clears the buffer to RGB passed
' INPUTS : Red, Green,Blue values range 0-255.
' RETURNS : nothing.
'-------------------------------------------------------------------
Sub TTDFastCls(ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
Dim ClsColor as integer
Dim num_ints as integer 'Size of buffer were clearing
ClsColor= ( Red shl 16 ) + ( Green shl 8 ) + Blue
num_ints=XRES*YRES
asm
mov eax, [ClsColor]
mov ecx, [num_ints]
mov edi, [BackBuffer]
cld
rep stosd
end asm
End Sub
'-------------------------------------------------------------------
' NAME : TTDPlot()
' PURPOSE : This function plots a pixel in RGB color
' INPUTS : x,y position and Red, Green,Blue values range 0-255.
' RETURNS : nothing.
'-------------------------------------------------------------------
Sub TTDPlot(ByVal x as integer, ByVal y as integer,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
Dim PlotColor as integer
PlotColor = ( Red shl 16 ) + ( Green shl 8 ) + Blue
if (x>-1) AND (x<XRES) AND (y>-1) AND (y<YRES) THEN
Backbuffer[(y*XRES+x)] = PlotColor
end if
End Sub
'-------------------------------------------------------------------
' NAME : TTDLine()
' PURPOSE : This function draw a line of RGB and Has Alpha option
' INPUTS : x1,y1,x2,y2,r,g,b
' RETURNS : Nothing.
'-------------------------------------------------------------------
Sub TTDLine(ByVal x1 as double, ByVal y1 as double,ByVal x2 as double, ByVal y2 as double,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer,ByVal Alpha as single)
Dim As Integer PlotColor,OldColor,TempColor, steps
Dim As Integer r2,g2,b2, dy, dx
Dim As Double xI,Alpha2
PlotColor = ( Red shl 16 ) + ( Green shl 8 ) + Blue
xI=0
x2 = x2-x1
y2 = y2-y1
If Abs(x2)>Abs(y2) THEN
steps = Abs(x2)
Else
steps = Abs(y2)
Endif
xI = x2 / steps
y2 = Y2 / steps
if Alpha>=1.0 then
For x2 = 1 To steps
dy=Int(y1)
dx=Int(x1)
If dy>-1 And dy<YRES then
If dx>-1 And dx<XRES then
Backbuffer[(dy*XRES+dx)] = PlotColor
EndIf
EndIf
x1=x1+xI:y1=y1+y2
Next
else
Alpha2=1.0 - Alpha
For x2 = 1 To steps
dy=Int(y1)
dx=Int(x1)
If dy>-1 And dy<YRES then
If dx>-1 And dx<XRES then
OldColor=Backbuffer[(dy*XRES+dx)]
'do alphablend
r2 = ( ( OldColor Shr 16 ) And 255 ) * Alpha + ( ( PlotColor Shr 16 ) And 255 ) * Alpha2
g2 = ( ( OldColor Shr 8 ) And 255 ) * Alpha + ( ( PlotColor Shr 8 ) And 255 ) * Alpha2
b2 = ( OldColor And 255 ) * Alpha + ( PlotColor And 255 ) * Alpha2
If r2 > 255 Then r2 = 255
If g2 > 255 Then g2 = 255
If b2 > 255 Then b2 = 255
TempColor = ( r2 shl 16 ) + ( g2 shl 8 ) + b2
Backbuffer[(dy*XRES+dx)] = TempColor
EndIf
EndIf
x1=x1+xI:y1=y1+y2
Next
endif
end Sub
'-------------------------------------------------------------------
' NAME : TTDFastLine()
' PURPOSE : This function draw a line of RGB
' INPUTS : stx,sty,enx,endy,r,g,b
' RETURNS : Nothing.
'-------------------------------------------------------------------
Sub TTDFastLine(Byval stx as integer,Byval sty as integer,Byval enx as integer,Byval eny as integer,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
Dim As Double stpx,stpy
dim As Integer mvx,mvy,mv
Dim PlotColor as integer
PlotColor = ( Red shl 16 ) + ( Green shl 8 ) + Blue
mvx=Stx-enx
mvy=sty-eny
If mvx<0 then
mvx=-mvx
endif
If mvy<0 then
mvy=-mvy
endif
If mvy>mvx then
mv=mvy
Else
mv=mvx
endif
stpx=(mvx/mv)
If Stx>enx then
stpx=-stpx
endif
stpy=(mvy/mv)
If Sty>eny then
stpy=-stpy
endif
For nc As Integer =0 To mv
If sty>-1 And sty<YRES then
If stx>-1 And stx<XRES then
Backbuffer[(sty*XRES+stx)] = PlotColor
EndIf
EndIf
stx=stx+stpx
sty=sty+stpy
Next
End Sub
'-------------------------------------------------------------------
' NAME : TTDOval()
' PURPOSE : This function draw a Oval of RGB
' INPUTS : xcentre,ycentre=centre of oval Rx,Ry=size of oval r,g,b=color
' RETURNS : Nothing.
'-------------------------------------------------------------------
Sub TTDOval(ByVal xCenter as integer,ByVal yCenter as integer,ByVal Rx as integer,ByVal Ry as integer,ByVal Red as integer,ByVal Green as integer,ByVal Blue as integer)
Dim As Integer p,px,py,x,y
Dim As Integer Rx2,Ry2,twoRx2,twoRy2
Dim pFloat as single
' The complex code I converted from a bmax example
Rx2=Rx*Rx
Ry2=Ry*Ry
twoRx2=Rx2 Shl 1
twoRy2=Ry2 Shl 1
'Region 1
x=0
y=Ry
TTDPlot(xCenter+x,yCenter+y,Red,Green,Blue)
TTDPlot(xCenter-x,yCenter+y,Red,Green,Blue)
TTDPlot(xCenter+x,yCenter-y,Red,Green,Blue)
TTDPlot(xCenter-x,yCenter-y,Red,Green,Blue)
pFloat=(Ry2-(Rx2*Ry))+(0.25*Rx2)
p=Int(pFloat)
If pFloat Mod 1.0>=0.5 Then
p=p+1
endif
px=0
py=twoRx2*y
While px<py
x=x+1
px=px+twoRy2
If p>=0 then
y=y-1
py=py-twoRx2
EndIf
If p<0 Then
p=p+Ry2+px
Else
p=p+Ry2+px-py
endif
TTDPlot(xCenter+x,yCenter+y,Red,Green,Blue)
TTDPlot(xCenter-x,yCenter+y,Red,Green,Blue)
TTDPlot(xCenter+x,yCenter-y,Red,Green,Blue)
TTDPlot(xCenter-x,yCenter-y,Red,Green,Blue)
Wend
'Region 2
pFloat=(Ry2*(x+0.5)*(x+0.5))+(Rx2*(y-1.0)*(y-1.0))-(Rx2*(CSNG(Ry2)))
p=Int(pFloat)
If pFloat Mod 1.0>=0.5 Then
p=p+1
endif
While y>0
y=y-1
py=py-twoRx2
If p<=0 then
x=x+1
px=px+twoRy2
EndIf
If p>0 Then
p=p+Rx2-py
Else
p=p+Rx2-py+px
endif
TTDPlot(xCenter+x,yCenter+y,Red,Green,Blue)
TTDPlot(xCenter-x,yCenter+y,Red,Green,Blue)
TTDPlot(xCenter+x,yCenter-y,Red,Green,Blue)
TTDPlot(xCenter-x,yCenter-y,Red,Green,Blue)
Wend
End Sub
test.bas:
#define PTC_WIN
#include "ttdblitzlib1.bi"
'-------------------------------------------------------------------
' Test of Lib
'-------------------------------------------------------------------
TTDGraphics(640,480,"TTD Test App")
Dim count as integer
do
TTDFastCls(0,0,0)
for i As Integer=0 to 255
TTDLine(0,10,500,10+i,0,i,0,0.5)
TTDLine(0,YRES,500,YRES-i,0,0,i,0.5)
next
TTDFlip()
loop until inkey$<>""
TTDEndGraphics()
end
'-------------------------------------------------------------------
' End Test of Lib
'-------------------------------------------------------------------