Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 201 online users. » 0 Member(s) | 198 Guest(s) Applebot, Bing, Google
|
Latest Threads |
Printing with FZX
Forum: Help & Support
Last Post: boriel
07-17-2025, 09:08 PM
» Replies: 1
» Views: 111
|
Strange Happenings
Forum: Bug Reports
Last Post: boriel
05-23-2025, 09:15 AM
» Replies: 4
» Views: 2,183
|
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 2,390
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 2,019
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 4,754
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 3,298
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 3,105
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 1,708
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 4,217
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 5,070
|
|
|
pathfinding |
Posted by: slenkar - 04-29-2012, 11:10 PM - Forum: How-To & Tutorials
- Replies (2)
|
 |
you can run the code to get a little demo:
Code: const found as ubyte=1
const pathsuccess as ubyte=1
const CantCreatePathError as ubyte=2
Dim path as integer
Dim SquareState(32,24) as UByte
Dim SquareParentX(32,24) as Ubyte
Dim SquareParentY(32,24) as Ubyte
Dim HCost(32,24) as UByte
Dim PathToWalkX(255) as UByte
Dim PathToWalkY(255) as UByte
Dim StepsOnPath as Integer
Dim PathBlockedByPerson as Ubyte
Dim PathBlocker as Integer
Dim numberofopenlistitems as Integer
Dim LowestFCostSquareX as Integer
Dim LowestFCostSquareY as Integer
Function FindPath(startx as Integer,starty as Integer,targetx as Integer,targety as Integer) as Integer
ClearPath()
pathfindmessage("FindPath")
If startx =targetx And starty = targety then
pathfindmessage("target square = start square")
Return 3
End if
HCost(startx,starty)=GetHCost(startx,starty,targetx,targety)
AddToOpenList(startx,starty,startx,starty)
LowestFCostSquareX=startx
LowestFCostSquareY=starty
path=-1
Dim DebugIter as Integer
while path=-1
DebugIter=DebugIter+1
If DebugIter>200 then
pathfindmessage("path too long")
Exit While
End if
If numberofopenlistitems=0 then
pathfindmessage("no more open list items")
Exit While
End if
'pathfindmessage("Lowest f cost square "+STR(LowestFCostSquareX)+" "+STR(LowestFCostSquareY))
Dim lowx as ubyte
lowx=LowestFCostSquareX
Dim lowy as ubyte
lowy=LowestFCostSquareY
CheckSquare(lowx+1,lowy,targetx,targety,lowx,lowy)
CheckSquare(lowx-1,lowy,targetx,targety,lowx,lowy)
CheckSquare(lowx,lowy+1,targetx,targety,lowx,lowy)
CheckSquare(lowx,lowy-1,targetx,targety,lowx,lowy)
if path<>found then
AddToClosedList(lowx,lowy)
end if
end while
If path = found then
'Print "path was found"
If CreatePath(startx , starty , targetx ,targety)<>1 then
Return CantCreatePathError
End if
Return 1
End if
return 0
End Function
Function CheckSquare(squarex as integer,squarey as integer,targetx as integer,targety as integer,originalx as integer,originaly as integer) as UByte
if squarex>-1 then
if squarex<32 then
if squarey>-1 then
if squarey<24 then
'pathfindmessage("Check square:"+STR(squarex)+" "+STR(squarey))
If OnClosedList(squarex,squarey)=0 then
'pathfindmessage("not on closed list")
If OnOpenList(squarex,squarey)=0 then
'pathfindmessage("not on open list")
If squarex=targetx And squarey=targety then
path = found
End if
HCost(squarex,squarey)=GetHCost(squarex,squarey,targetx,targety)
AddToOpenList(squarex,squarey,originalx,originaly)
If path=found then
SquareParentX(squarex,squarey)=originalx
SquareParentY(squarex,squarey)=originaly
'Print "path is found"
AddToClosedList(squarex,squarey)
End if
End if
End if
End if
End if
End if
end if
End Function
Function GetHCost(squarex as integer,squarey as integer,targetx as integer,targety as integer) as integer
Return (Abs(squarex-targetx)+Abs(squarey-targety))
End Function
Function OnOpenList(squarex as Integer, squarey as Integer) as integer
if SquareState(squarex,squarey)=1 then
return 1
end if
return 0
end function
Function OnClosedList(squarex as Integer, squarey as Integer) as integer
if SquareState(squarex,squarey)=2 then
return 1
end if
return 0
end function
Function AddToOpenList(squarex as Integer, squarey as Integer,parx as integer, pary as integer)
SquareParentX(squarex,squarey)=parx
SquareParentY(squarex,squarey)=pary
numberofopenlistitems=numberofopenlistitems+1
If HCost(squarex,squarey)<HCost(LowestFCostSquareX,LowestFCostSquareY) then
LowestFCostSquareX=squarex
LowestFCostSquareY=squarey
End if
SquareState(squarex,squarey)=1
Print at squarey,squarex;"O"
end function
Function AddToClosedList(squarex as Integer, squarey as Integer)
if LowestFCostSquareX=squarex then
if LowestFCostSquareY=squarey then
Dim dist as Integer
dim chosenX as integer
Dim chosenY as integer
chosenX=-1
chosenY=-1
dist=9999
for x=0 to 32
for y=0 to 24
if OnOpenList(x,y) then
If HCost(x,y)<dist then
dist=HCost(x,y)
chosenX=x
chosenY=y
end if
End if
Next
Next
If chosenX>-1 then
LowestFCostSquareX=chosenX
LowestFCostSquareY=chosenY
End if
end if
end if
if SquareState(squarex,squarey)=1 then
numberofopenlistitems=numberofopenlistitems-1
end if
SquareState(squarex,squarey)=2
Print at squarey,squarex;"C"
end function
Function AddToPath(squarex as Integer, squarey as Integer)
Print at squarey,squarex;"P"
end function
Function CreatePath(StartX as integer,StartY as integer,TargetX as integer,TargetY as integer) as integer
PathBlockedByPerson=0
PathBlocker=0
dim PathCreated as Ubyte
dim ParX as Integer
dim ParY as Integer
StepsOnPath=StepsOnPath+1
PathToWalkX(StepsOnPath)=TargetX
PathToWalkY(StepsOnPath)=TargetY
ParX=PathToWalkX(StepsOnPath)
ParY=PathToWalkY(StepsOnPath)
While PathCreated=0
Dim NewParX as integer
Dim NewParY as integer
NewParX=SquareParentX(ParX,ParY)
NewParY=SquareParentY(ParX,ParY)
ParX=NewParX
ParY=NewParY
AddToPath(ParX,ParY)
StepsOnPath=StepsOnPath+1
If StepsOnPath=StepsOnPath>254 then
Return 2
End if
PathToWalkX(StepsOnPath)=ParX
PathToWalkY(StepsOnPath)=ParY
If PathToWalkX(StepsOnPath)=StartX And PathToWalkY(StepsOnPath)=StartY then
exit while
End if
Wend
Return 1
End Function
function ClearPath()
for x=0 to 32
for y=0 to 24
SquareState(x,y)=0
SquareParentX(x,y)=0
SquareParentY(x,y)=0
HCost(x,y)=0
next
next
'for x=0 to 768
'PathToWalkX(x)=0
'PathToWalkY(x)=0
'next
StepsOnPath=0
PathBlockedByPerson=0
PathBlocker=0
numberofopenlistitems=0
End Function
Dim pathfindprint as ubyte
Function pathfindmessage(msg as string)
Print at pathfindprint,0 ; msg
pathfindprint=pathfindprint+1
if pathfindprint>24 then
pathfindprint=0
end if
end function
Border 5
FindPath(0,10,10,0)
FindPath(0,10,31,23)
FindPath(31,23,0,0)
|
|
|
byte loops (*solved*) |
Posted by: britlion - 04-19-2012, 01:50 AM - Forum: Bug Reports
- Replies (15)
|
 |
This seems to not work - skipping the loop. Surely small negative numbers shouldn't be an issue for a byte sized variable?
Code: DIM x as byte
for x=-91 to 91
print x
next x
|
|
|
Double Size Print |
Posted by: britlion - 04-19-2012, 01:19 AM - Forum: Documentation
- Replies (8)
|
 |
You know, I've focused so much on making itty bitty unreadable text, that it was time to make up the balance.
A whole evening poking in assembly, and it's 143 bytes? Heck, I'm slow!
Anyway - Double sized printing. Including UDG.
<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:DoubleSizePrint.bas">http://www.boriel.com/wiki/en/index.php ... ePrint.bas</a><!-- m -->
No colour. That's what windowPaint - <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:WindowPaint">http://www.boriel.com/wiki/en/index.php ... indowPaint</a><!-- m --> - is for!
(Yes, I also added this - though it's solidly based on the paint routine packaged with putChars)
|
|
|
Screen handling |
Posted by: britlion - 04-18-2012, 01:10 AM - Forum: ZX Basic Compiler
- Replies (9)
|
 |
This is interesting. There's quite a lot of overhead in PLOT, I think - this is fairly unoptimized, still - and appears to be a little buggy. It also doesn't use the screen tables lookup yet. But it's late and I need to go to bed 
Code: SUB plotPoint (x as uByte, y as uByte)
ASM
ld d,(IX+5) ;'X
ld e,(IX+7) ;'Y
ld a, 191
sub e
ret c
ld e, a
and a
rra
scf
rra
and a
rra
xor e
and 248
xor e
ld h, a
ld a, d
rlca
rlca
rlca
xor e
and 199
xor e
rlca
rlca
ld l, a
ld a, d
and 7
ld b, a
inc b
ld a, 1
plotPoint_loop:
rrca
djnz plotPoint_loop
;cpl
ld b, a
ld a, (hl)
or b
ld (hl), a
END ASM
END SUB
FUNCTION t() as uLong
asm
DI
LD DE,(23674)
LD D,0
LD HL,(23672)
EI
end asm
end function
dim time0, time1, time2 as long
dim n as uInteger
cls
for n=1 to 150
plotPoint(n,n-1)
plot n,n+3
next n
time0=t()
for n=0 to 50000
plot 50,50
next n
time1=t()
for n=0 to 50000
plotPoint(50,50)
next n
time2=t()
print "ZX Basic 50,000 plot:"
print time1-time0;"frames =";(time1-time0)/cast(float,50);" seconds"
print
print "plotPoint 50,000 times:"
print time2-time1;"frames=";(time2-time1)/cast(float,50);" seconds"
|
|
|
clearbox |
Posted by: britlion - 04-17-2012, 01:30 AM - Forum: Documentation
- Replies (6)
|
 |
I've added a partial clear screen routine (clearBox.bas) to the library. It does what it says - clears a defined rectangle of the screen. Good for clearing out the bits you don't want, such as the game board, but leave the status bit alone.
<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:ClearBox">http://www.boriel.com/wiki/en/index.php ... C:ClearBox</a><!-- m -->
|
|
|
Using screen lookup tables |
Posted by: britlion - 04-13-2012, 11:12 PM - Forum: Wishlist
- Replies (5)
|
 |
It occurs to me that a lot of game programmers would use screen address lookup tables - I've included one in with several library routines at this point.
I think we need to standardize this important library, to be honest.
1> It should be easily includable, and documented on its use. And only let itself be included once! Perhaps setting some parameter, such that the compiler includes it in automatically?
- it must, of course, be aligned. (which is another topic - the align code should be really clever about not wasting bytes, if it can squeeze some other code up in the "missed space"
2> It should be used, if available, by other ZX Basic functions - I'm thinking in particular of plot and draw, which use the ROM routine PIXELADD. Very important this. If we're willing to give up memory for a table, lets have everything use it!
3> It should be user-replaceable, if they follow the structure - so that they can define their own screen buffer, and fast-lookup screen addresses in the buffer, instead.
|
|
|
|