Оберон-клуб «ВЄДАsoft»

Твердыня модульных языков
Текущее время: 18 июн 2025, 22:08

Часовой пояс: UTC + 2 часа




Начать новую тему Ответить на тему  [ Сообщений: 20 ]  На страницу 1, 2  След.
Автор Сообщение
 Заголовок сообщения: lots of code,
СообщениеДобавлено: 17 июн 2013, 19:11 
Не в сети

Сообщения: 104
I tried converting my A* pathfinding routine to oberon but for some reason the amount of code makes it not run

Код: "OBERON"
  1.  
  2. MODULE hi;
  3. IMPORT B := Basic;
  4. CONST
  5. found=1;
  6. pathsuccess=1;
  7. CantCreatePathError=2;
  8. TYPE
  9. string=ARRAY OF CHAR;
  10. VAR
  11. path:INTEGER;
  12. StepsOnPath:INTEGER;
  13. PathBlockedByPerson:SHORTINT;
  14. PathBlocker:INTEGER;
  15. numberofopenlistitems:INTEGER;
  16. LowestFCostSquareX:SHORTINT;
  17. LowestFCostSquareY:SHORTINT;
  18.  
  19. gameboard:ARRAY 32,22 OF SHORTINT;
  20. SquareState:ARRAY 32,22 OF SHORTINT;
  21. SquareParentX:ARRAY 32,22 OF SHORTINT;
  22. SquareParentY:ARRAY 32,22 OF SHORTINT;
  23. HCost:ARRAY 32,22 OF SHORTINT;
  24. PathToWalkX:ARRAY 100 OF SHORTINT;
  25. PathToWalkY:ARRAY 100 OF SHORTINT;
  26.  
  27.  
  28. (*PROCEDURE pathfindmessage(msg:string);
  29. BEGIN
  30. B.PRSTR(msg);
  31. END pathfindmessage;
  32. *)
  33. (*
  34. PROCEDURE ClearPath();
  35. VAR
  36. x,y:SHORTINT;
  37. BEGIN
  38. FOR x:=0 TO 32 DO
  39. FOR y:=0 TO 24 DO
  40. SquareState[x][y]:=0;
  41. SquareParentX[x][y]:=0;
  42. SquareParentY[x][y]:=0;
  43. HCost[x][y]:=0;
  44. END;
  45. END;
  46. (*
  47. 'for x=0 to 768
  48. 'PathToWalkX(x)=0
  49. 'PathToWalkY(x)=0
  50. 'next*)
  51. StepsOnPath:=0;
  52. PathBlockedByPerson:=0;
  53. PathBlocker:=0;
  54. numberofopenlistitems:=0;
  55.  
  56. END ClearPath;
  57. PROCEDURE GetHCost(squarex:SHORTINT;squarey:SHORTINT;targetx:SHORTINT;targety:SHORTINT):SHORTINT;
  58. BEGIN
  59. RETURN (ABS(squarex-targetx)+ABS(squarey-targety));
  60. END GetHCost;
  61.  
  62. PROCEDURE OnOpenList(squarex:INTEGER;squarey:INTEGER):INTEGER;
  63. BEGIN
  64. IF SquareState[squarex][squarey]=1 THEN
  65. RETURN 1;
  66. END;
  67. RETURN 0;
  68. END OnOpenList;
  69.  
  70. PROCEDURE OnClosedList(squarex:INTEGER; squarey:INTEGER):SHORTINT;
  71. BEGIN
  72. IF SquareState[squarex][squarey]=2 THEN
  73. RETURN 1
  74. END;
  75. RETURN 0
  76. END OnClosedList;
  77.  
  78.  
  79. PROCEDURE AddToOpenList(squarex:SHORTINT;squarey:SHORTINT;parx:SHORTINT;pary:SHORTINT);
  80. VAR
  81. x:INTEGER;
  82. y:INTEGER;
  83. BEGIN
  84. SquareParentX[squarex][squarey]:=parx;
  85. SquareParentY[squarex][squarey]:=pary;
  86. numberofopenlistitems:=numberofopenlistitems+1;
  87.  
  88. IF HCost[squarex][squarey]<HCost[LowestFCostSquareX][LowestFCostSquareY] THEN
  89. LowestFCostSquareX:=squarex;
  90. LowestFCostSquareY:=squarey;
  91. END;
  92.  
  93. SquareState[squarex][squarey]:=1;
  94. B.AT(squarey,squarex);
  95. B.PRSTR( "O");
  96. END AddToOpenList;
  97.  
  98. PROCEDURE AddToClosedList(squarex:INTEGER;squarey:INTEGER);
  99. VAR
  100. dist:INTEGER;
  101. chosenX:SHORTINT;
  102. chosenY:SHORTINT;
  103. x:SHORTINT;
  104. y:SHORTINT;
  105. BEGIN
  106. IF LowestFCostSquareX=squarex THEN
  107. IF LowestFCostSquareY=squarey THEN
  108. chosenX:=-1;
  109. chosenY:=-1;
  110.  
  111. dist:=9999;
  112. FOR x:=0 TO 32 DO
  113. FOR y:=0 TO 24 DO
  114. IF OnOpenList(x,y)=1 THEN
  115. IF HCost[x][y]<dist THEN
  116. dist:=HCost[x][y];
  117. chosenX:=x;
  118. chosenY:=y;
  119. END;
  120. END;
  121. END;
  122. END;
  123.  
  124. IF chosenX>-1 THEN
  125. LowestFCostSquareX:=chosenX;
  126. LowestFCostSquareY:=chosenY;
  127. END;
  128.  
  129. END;
  130. END;
  131.  
  132. IF SquareState[squarex][squarey]=1 THEN
  133. numberofopenlistitems:=numberofopenlistitems-1;
  134. END;
  135. SquareState[squarex][squarey]:=2;
  136. B.AT(squarey,squarex);
  137. B.PRSTR( "C");
  138.  
  139. END AddToClosedList;
  140.  
  141. PROCEDURE AddToPath(squarex:INTEGER;squarey:INTEGER);
  142. BEGIN
  143. B.AT(squarey,squarex);
  144. B.PRSTR( "P");
  145. END AddToPath;
  146.  
  147. PROCEDURE CreatePath(StartX:SHORTINT;StartY:SHORTINT;TargetX:SHORTINT;TargetY:SHORTINT) :SHORTINT;
  148. VAR
  149. PathCreated:SHORTINT;
  150. ParX:SHORTINT;
  151. ParY:SHORTINT;
  152. NewParX:SHORTINT;
  153. NewParY:SHORTINT;
  154. BEGIN
  155. PathBlockedByPerson:=0;
  156. PathBlocker:=0;
  157. PathCreated:=0;
  158. StepsOnPath:=StepsOnPath+1;
  159. PathToWalkX[StepsOnPath]:=TargetX;
  160. PathToWalkY[StepsOnPath]:=TargetY;
  161. ParX:=PathToWalkX[StepsOnPath];
  162. ParY:=PathToWalkY[StepsOnPath];
  163. WHILE PathCreated=0 DO
  164. NewParX:=SquareParentX[ParX][ParY];
  165. NewParY:=SquareParentY[ParX][ParY];
  166. ParX:=NewParX;
  167. ParY:=NewParY;
  168. AddToPath(ParX,ParY);
  169. StepsOnPath:=StepsOnPath+1;
  170. IF StepsOnPath>254 THEN
  171. RETURN 2
  172. END;
  173. PathToWalkX[StepsOnPath]:=ParX;
  174. PathToWalkY[StepsOnPath]:=ParY;
  175. IF (PathToWalkX[StepsOnPath]=StartX) & (PathToWalkY[StepsOnPath]=StartY) THEN
  176. PathCreated:=1;
  177. END;
  178.  
  179. END;
  180. RETURN 1;
  181. END CreatePath;
  182.  
  183.  
  184.  
  185.  
  186. PROCEDURE CheckSquare(squarex:SHORTINT;squarey:SHORTINT;targetx:SHORTINT;targety:SHORTINT;originalx:SHORTINT;originaly:SHORTINT);
  187. BEGIN
  188.  
  189. IF squarex>-1 THEN
  190. IF squarex<32 THEN
  191. IF squarey>-1 THEN
  192. IF squarey<24 THEN
  193.  
  194. B.PRSTR("Check square");
  195. (*CHR(squarex+48)+" "+STR(squarey));*)
  196.  
  197. IF OnClosedList(squarex,squarey)=0 THEN
  198. B.PRSTR("not on closed list");
  199. IF OnOpenList(squarex,squarey)=0 THEN
  200. (*pathfindmessage("not on open list");*)
  201.  
  202. IF (squarex=targetx)&(squarey=targety)THEN
  203. path:=found;
  204. END;
  205.  
  206. HCost[squarex][squarey]:=GetHCost(squarex,squarey,targetx,targety);
  207.  
  208. AddToOpenList(squarex,squarey,originalx,originaly);
  209.  
  210. IF path=found THEN
  211. SquareParentX[squarex][squarey]:=originalx;
  212. SquareParentY[squarex][squarey]:=originaly;
  213. (*pathfindmessage("path is found");*)
  214. AddToClosedList(squarex,squarey);
  215. END;
  216.  
  217.  
  218. END;
  219. END;
  220. END;
  221. END;
  222. END;
  223. END;
  224. END CheckSquare;
  225.  
  226. PROCEDURE FindPath(startx:SHORTINT;starty:SHORTINT;targetx:SHORTINT;targety:SHORTINT):SHORTINT;
  227. VAR
  228. DebugIter:INTEGER;
  229. lowx:SHORTINT;
  230. lowy:SHORTINT;
  231.  
  232. BEGIN
  233. ClearPath();
  234. DebugIter:=0;
  235. (*pathfindmessage("FindPath")*)
  236. IF (startx =targetx) & (starty = targety) THEN
  237. (*pathfindmessage("target square = start square")*)
  238. RETURN 3
  239. END;
  240.  
  241. HCost[startx][starty]:=GetHCost(startx,starty,targetx,targety);
  242. AddToOpenList(startx,starty,startx,starty);
  243. LowestFCostSquareX:=startx;
  244. LowestFCostSquareY:=starty;
  245.  
  246. path:=-1;
  247.  
  248. WHILE (path=-1) DO
  249. DebugIter:=DebugIter+1;
  250.  
  251. IF DebugIter>200 THEN
  252. (*pathfindmessage("path too long")*)
  253. path:=-2
  254. END;
  255.  
  256. IF numberofopenlistitems=0 THEN
  257. (*pathfindmessage("no more open list items");*)
  258. path:=-2
  259. END;
  260.  
  261. (*pathfindmessage("Lowest f cost square "+STR(LowestFCostSquareX)+" "+STR(LowestFCostSquareY))*)
  262.  
  263.  
  264. lowx:=LowestFCostSquareX;
  265. lowy:=LowestFCostSquareY;
  266. CheckSquare(lowx+1,lowy,targetx,targety,lowx,lowy);
  267. CheckSquare(lowx-1,lowy,targetx,targety,lowx,lowy);
  268. CheckSquare(lowx,lowy+1,targetx,targety,lowx,lowy);
  269. CheckSquare(lowx,lowy-1,targetx,targety,lowx,lowy);
  270. IF path#found THEN
  271. AddToClosedList(lowx,lowy);
  272. END;
  273.  
  274. END;
  275.  
  276. IF path = found THEN
  277. (*Print "path was found"*)
  278. IF CreatePath(startx , starty , targetx ,targety)#1 THEN
  279. RETURN CantCreatePathError;
  280. END;
  281.  
  282. RETURN 1 ;
  283. END;
  284.  
  285. RETURN 0;
  286. END FindPath;
  287.  
  288.  
  289.  
  290. *)
  291.  
  292. PROCEDURE Main* ;
  293. CONST
  294.  
  295.  
  296. TYPE
  297.  
  298. VAR
  299. result:SHORTINT;
  300. BEGIN B.Init;
  301. B.BORDER(B.Green);
  302. B.PAPER(B.Black);
  303. B.CLS;
  304. B.PRSTR("hello");
  305. (*result:=FindPath(0,10,10,0);*)
  306. (*result:=FindPath(0,10,31,23);*)
  307. (*result:=FindPath(31,23,0,0);*)
  308. B.PAUSE(B.WaitAKey);
  309. B.Quit;
  310.  
  311. END Main;
  312.  
  313. END hi.
  314.  



if you run it it will say "hello"

if you uncomment the functions it will not work

Are the functions pushing the main function to the wrong place?
So randomize USR 26000 doesnt work as the main function is not at 26000 anymore?


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 17 июн 2013, 21:33 
Не в сети

Сообщения: 104
If I put all the pathfinding functions into a different mod file
then compile to path,.rel
then compile to path.lib

it works :D


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 17 июн 2013, 23:22 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Now the first placed procedure of "main" module is started first. It's not very good, and tomorrow I will try to fix this problem by building a new "crt0.rel" file for SDCC, that will jump to C function "main", then we'll need to use special comment (*$MAIN*) to mark main module (in Oberon environment all modules are equivalent, and there isn't a main module).

In Flower.Mod I've solved this problem so:
Код: "OBERON"
  1. (* Place this procedure at begin of "main" module of your project: *)
  2. PROCEDURE ^Main; PROCEDURE EntryPoint; BEGIN Main END EntryPoint;
  3. (* It defines procedure Main. Procedure EntryPoint is started first *)
  4. (* (for example, at 26000) and run procedure "Main". *)
  5.  
  6. ...
  7.  
  8. PROCEDURE Main;
  9. BEGIN
  10. (* Place your startup code here, *)
  11. (* and not in the initialization section of the module "BEGIN ... END Module. *)
  12. END Main;
It's temporary and dirty solution, need to use "crt0.rel"!

How do you find Oberon? Is it useful? :) If you'll write some stuff, don't forget to show us! :D


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 00:09 
Не в сети

Сообщения: 104
it is good,

it took me a while to figure out that ALL C files have to be placed in the Obj/ folder
or I will get linker errors

here is the make file I use
Код: "OBERON"
  1.  
  2. all: $(target).tap
  3.  
  4. $(target).tap: $(target).bin
  5. Bin/bin2tap -b -a 26000 -c 25999 -r 26000 -o $(target).tap $(target).bin
  6. fuse-gtk $(target).tap
  7. $(target).bin: $(target).ihx
  8. Bin/hex2bin $(target).ihx
  9.  
  10. $(target).ihx: Obj/$(target).c path.lib
  11. Bin/sdcc/bin/sdcc -mz80 --code-loc 26000 --opt-code-size --no-std-crt0 Obj/$(target).c -I Lib -I Obj Lib/z80/Basic.lib path.lib
  12.  
  13. path.lib: path.rel
  14. /root/Downloads/sdcc/bin/sdcclib path.lib path.rel
  15.  
  16. path.rel:Obj/path.c
  17. /root/Downloads/sdcc/bin/sdcc -mz80 -c Obj/path.c -I Obj -I Lib
  18.  
  19. Obj/$(target).c:Mod/$(target).mod Mod/path.mod
  20. "/root/ofront/linux2/bin/ofront" Mod/path.mod Mod/$(target).mod -m -l
  21. mv $(target).c Obj/$(target).c
  22. mv path.c Obj/path.c
  23.  
  24. Obj/path.c:Mod/path.mod
  25. "/root/ofront/linux2/bin/ofront" Mod/path.mod -l
  26.  
  27.  


Последний раз редактировалось slenkar 18 июн 2013, 01:24, всего редактировалось 1 раз.

Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 01:22 
Не в сети

Сообщения: 104
here is a little pathfinding demo

W is a wall


Вложения:
hi.tap [2.59 КБ]
Скачиваний: 1184
Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 18:13 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
I was positively impressed by the your little demo. :) Probably is it a part of the future game?

Also I am grateful to you for your interest to Oberon and ZXDev. You have got very good results in short time. And the information, that was posted by you, will be useful for everyone who wants to try using Ofront under Linux.

P.S. I see that hi.tap works in 32x22 resolution. Have you tried to get 32x24 by editing the configuration file "BasicCfg.h"?


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 21:28 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
See the commit that solves the problem with correct entry point of the main module. I have used this simple crt0.s
Код: "ASM"
	.module crt0
.globl _main
jp _main
It increases each program (that compiles with standard /Bin scripts) to 3 bytes (JP _main). Peephole optimizer not able to remove this jump, even it may be removed.

Now we always need to invoke SDCC without option --no-std-crt0 ("ZXDev/Bin/build.bat" is fixed) and use (*$MAIN*) directive to mark the main module (except a case, if a custom building script is used). Yes, for little funny projects with one procedure in main module, I just propose to write own building script with invoking of SDCC with option --no-std-crt0 and without (*$MAIN*)

Aha! Since you use Ofront for Linux, just use option (probably -m as I remember?) to say Ofront, while compiling main module, to generate function "main". You can use the comment (*$MAIN*) too - for compatibility with ZXDev.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 21:58 
Не в сети

Сообщения: 104
ok thanks
pathfinding can be used for many games like rebelstar

Is there a way of converting REAL to INTEGER?

like FLOOR,


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 22:25 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Sure. It's internal Oberon's procedure ENTIER (x: REAL): LONGINT;
To have INTEGER result, just use:
Код: "OBERON"
  1. VAR i: INTEGER; (* {-32678..32767} *)
  2. BEGIN i := SHORT(ENTIER(real));
  3. ...
SDCC supports only one real type (sizeof(float) == sizeof(double)), therefore in ZXDev, too, SIZE(REAL) = SIZE(LONGREAL) = 4 bytes.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: lots of code,
СообщениеДобавлено: 18 июн 2013, 23:38 
Не в сети

Сообщения: 104
I cant seem to get entier to work,
when linking it says '?ASlink-Warning-Undefined Global '_SYSTEM_ENTIER' referenced by module 'line'
in the C source code the function is called SYSTEM_ENTIER without the first underrscore
Am I not including a lib file somewhere?

Is it something to do with XDev?


Вернуться к началу
 Профиль  
Ответить с цитатой  
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 20 ]  На страницу 1, 2  След.

Часовой пояс: UTC + 2 часа


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
Перейти:  
cron
Создано на основе phpBB® Forum Software © phpBB Group
© VEDAsoft Oberon Club