Advertisement
TheFastFish

[PTC] BEFUNGE Source

Jul 30th, 2014
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.18 KB | None | 0 0
  1. ACLS
  2. CLEAR
  3. COLOR 1
  4. PS=5
  5. DIM S(1000)
  6. DIM G$(24,32)
  7. DIM R$(24,33)
  8. DIM B$(36,2)
  9. FOR Y=0 TO 23
  10. FOR X=0 TO 31
  11. G$(Y,X)=" "
  12. BGPUT 1,X,Y,1000,15,0,0
  13. NEXT
  14. NEXT
  15. TX=1
  16. SB=1
  17. FOR I=0 TO 3
  18. BREPEAT I,10,2
  19. NEXT
  20. I=0
  21. RESTORE @LANG
  22. @P
  23. READ S$,R$
  24. IF S$=="" THEN @EDIT
  25. IF S$=="Q" THEN S$=CHR$(34)
  26. B$(I,0)=S$
  27. B$(I,1)=R$
  28. I=I+1
  29. GOTO @P
  30.  
  31. @EDIT
  32. DF=0
  33. CLS
  34. COLOR 1
  35. FOR Y=0 TO 23
  36. FOR X=0 TO 31
  37. LOCATE X,Y
  38. ?G$(Y,X);
  39. NEXT
  40. NEXT
  41. PNLTYPE "KYA"
  42. @EDITL
  43. VSYNC 1
  44. B=BUTTON(1)
  45. BGPUT 1,GX,GY,4,0,0,0
  46. IF B!=0 THEN GOSUB @BCHK
  47. IF KEYBOARD!=0 THEN GOSUB @PUT
  48. GOTO @EDITL
  49.  
  50. @BCHK
  51. IF B AND 1 THEN BGPUT 1,GX,GY,1000,15,0,0:GY=GY-1
  52. IF B AND 2 THEN BGPUT 1,GX,GY,1000,15,0,0:GY=GY+1
  53. IF B AND 4 THEN BGPUT 1,GX,GY,1000,15,0,0:GX=GX-1
  54. IF B AND 8 THEN BGPUT 1,GX,GY,1000,15,0,0:GX=GX+1
  55. IF B AND 1024 THEN @MENU
  56. IF GX<0 THEN GX=0
  57. IF GY<0 THEN GY=0
  58. IF GX>31 THEN GX=31
  59. IF GY>23 THEN GY=23
  60. RETURN
  61.  
  62. @PUT
  63. K$=INKEY$()
  64. IF KEYBOARD==15 THEN GOSUB @ERASE
  65. G$(GY,GX)=K$
  66. LOCATE GX,GY
  67. ?K$;
  68. RETURN
  69.  
  70. @ERASE
  71. G$(GY,GX)=""
  72. LOCATE GX,GY
  73. ?" ";
  74. RETURN
  75. BREPEAT 15,10,1
  76.  
  77. @MENU
  78. COLOR 0
  79. PNLTYPE "OFF"
  80. PNLSTR 0,0,"BEFUNGE FOR PTC - Menu"
  81. PNLSTR 0,1,"А:Run"
  82. PNLSTR 0,2,"Б:Load"
  83. PNLSTR 0,3,"Ф:Save"
  84. PNLSTR 0,4,"Х:New"
  85. PNLSTR 0,5,"н:Debug"
  86. PNLSTR 0,6,"[START]:Close"
  87. @ML
  88. VSYNC 1
  89. B=BUTTON(1)
  90. IF B AND 16 THEN @RUN
  91. IF B AND 32 THEN @LOAD
  92. IF B AND 64 THEN @SAVE
  93. IF B AND 128 THEN @NEW
  94. IF B AND 512 THEN @DEBUG
  95. IF B AND 1024 THEN @EDIT
  96. GOTO @ML
  97.  
  98. @RUN
  99. CLS
  100. RX=0
  101. RY=0
  102. SP=0
  103. EF=0
  104. CX=0
  105. CY=0
  106. IX=0
  107. IY=0
  108. SA=0
  109. SB=1
  110. COLOR 1
  111. FOR I=0 TO 99
  112. S(I)=0
  113. NEXT
  114. BGPUT 1,GX,GY,1000,15,0,0
  115. FOR Y=0 TO 23
  116. FOR X=0 TO 31
  117. R$(Y,X)=G$(Y,X)
  118. LOCATE X,Y
  119. ?R$(Y,X);
  120. NEXT
  121. NEXT
  122. IF DF==1 THEN @SKPR
  123. COLOR 0
  124. PNLSTR 0,0,"Running... Press [START] to stop"
  125. CY=1
  126. @SKPR
  127. IF DF==1 THEN RETURN
  128. @READ
  129. BGPUT 1,RX-(IX+SX),RY-(IY+SY),1000,15,0,0
  130. SX=0
  131. SY=0
  132. C$=R$(RY,RX)
  133. IF SA==0 AND (C$=="" OR C$==" ") THEN @NXT
  134. IF SA==1 AND C$==CHR$(34) THEN GOSUB @QM:GOTO @NXT
  135. IF SA==1 THEN GOSUB @SGPH:GOTO @NXT
  136. FOR A=0 TO 35
  137. IF C$==B$(A,0) THEN GOSUB B$(A,1)
  138. NEXT
  139. @NXT
  140. BGPUT 1,RX,RY,2,0,0,0
  141. VSYNC 9-PS
  142. IF EF==1 THEN @EP
  143. B=BUTTON(0)
  144. IF B AND 1024 THEN GX=RX:GY=RY:GOTO @EDIT
  145. RX=RX+IX+SX
  146. RY=RY+IY+SY
  147. IF RX<0 THEN RX=RX+32
  148. IF RY<0 THEN RY=RY+24
  149. IF RX>31 THEN RX=RX-32
  150. IF RY>23 THEN RY=RY-24
  151. IF DF==1 THEN RETURN
  152. GOTO @READ
  153.  
  154. @DEBUG
  155. DF=1
  156. CX=0
  157. CY=0
  158. GOSUB @RUN
  159. @DBL
  160. GOSUB @READ
  161. COLOR 0
  162. FOR I=0 TO 23
  163. PNLSTR 0,I," "*32
  164. NEXT
  165. FOR I=0 TO 99
  166. PNLSTR CX,CY,STR$(S(I))
  167. CI=LEN(STR$(S(I)))+1
  168. GOSUB @CSR
  169. NEXT
  170. CX=0
  171. CY=0
  172. @DIL
  173. VSYNC 1
  174. B=BUTTON(1)
  175. IF B!=0 THEN GOTO @DBL
  176. GOTO @DIL
  177.  
  178. @P0
  179. IF SP==100 THEN RETURN
  180. S(SP)=0
  181. SP=SP+1
  182. RETURN
  183.  
  184. @P1
  185. IF SP==1000 THEN RETURN
  186. S(SP)=1
  187. SP=SP+1
  188. RETURN
  189.  
  190. @P2
  191. IF SP==1000 THEN RETURN
  192. S(SP)=2
  193. SP=SP+1
  194. RETURN
  195.  
  196. @P3
  197. IF SP==1000 THEN RETURN
  198. S(SP)=3
  199. SP=SP+1
  200. RETURN
  201.  
  202. @P4
  203. IF SP==1000 THEN RETURN
  204. S(SP)=4
  205. SP=SP+1
  206. RETURN
  207.  
  208. @P5
  209. IF SP==1000 THEN RETURN
  210. S(SP)=5
  211. SP=SP+1
  212. RETURN
  213.  
  214. @P6
  215. IF SP==1000 THEN RETURN
  216. S(SP)=6
  217. SP=SP+1
  218. RETURN
  219.  
  220. @P7
  221. IF SP==1000 THEN RETURN
  222. S(SP)=7
  223. SP=SP+1
  224. RETURN
  225.  
  226. @P8
  227. IF SP==1000 THEN RETURN
  228. S(SP)=8
  229. SP=SP+1
  230. RETURN
  231.  
  232. @P9
  233. IF SP==1000 THEN RETURN
  234. S(SP)=9
  235. SP=SP+1
  236. RETURN
  237.  
  238. @MA
  239. IF SP==0 THEN RETURN
  240. SP=SP-1
  241. A1=S(SP)
  242. S(SP)=0
  243. IF SP==0 THEN RETURN
  244. SP=SP-1
  245. A2=S(SP)
  246. S(SP)=A1+A2
  247. SP=SP+1
  248. RETURN
  249.  
  250. @MS
  251. IF SP==0 THEN RETURN
  252. SP=SP-1
  253. S1=S(SP)
  254. S(SP)=0
  255. IF SP==0 THEN RETURN
  256. SP=SP-1
  257. S2=S(SP)
  258. S(SP)=A2-A1
  259. SP=SP+1
  260. RETURN
  261.  
  262. @MM
  263. IF SP==0 THEN RETURN
  264. SP=SP-1
  265. M1=S(SP)
  266. S(SP)=0
  267. IF SP==0 THEN RETURN
  268. SP=SP-1
  269. M2=S(SP)
  270. S(SP)=M1*M2
  271. SP=SP+1
  272. RETURN
  273.  
  274. @MD
  275. IF SP==0 THEN RETURN
  276. SP=SP-1
  277. D1=S(SP)
  278. S(SP)=0
  279. IF SP==0 THEN RETURN
  280. SP=SP-1
  281. D2=S(SP)
  282. S(SP)=FLOOR(D2/D1)
  283. SP=SP+1
  284. RETURN
  285.  
  286. @MR
  287. IF SP==0 THEN RETURN
  288. SP=SP-1
  289. R1=S(SP)
  290. S(SP)=0
  291. IF SP==0 THEN RETURN
  292. SP=SP-1
  293. R2=S(SP)
  294. S(SP)=D2%D1
  295. SP=SP+1
  296. RETURN
  297.  
  298. @LN
  299. IF SP==0 THEN RETURN
  300. SP=SP-1
  301. NV=S(SP)
  302. S(SP)=!NV
  303. SP=SP+1
  304. RETURN
  305.  
  306. @GT
  307. IF SP==0 THEN RETURN
  308. SP=SP-1
  309. G1=S(SP)
  310. S(SP)=0
  311. IF SP==0 THEN RETURN
  312. SP=SP-1
  313. G2=S(SP)
  314. S(SP)=G2>G1
  315. SP=SP+1
  316. RETURN
  317.  
  318. @DR
  319. IX=1
  320. IY=0
  321. RETURN
  322.  
  323. @DL
  324. IX=-1
  325. IY=0
  326. RETURN
  327.  
  328. @DU
  329. IX=0
  330. IY=-1
  331. RETURN
  332.  
  333. @DD
  334. IX=0
  335. IY=1
  336. RETURN
  337.  
  338. @DQ
  339. DV=RND(4)
  340. IF DV==0 THEN IX=1:IY=0
  341. IF DV==1 THEN IX=0:IY=1
  342. IF DV==2 THEN IX=-1:IY=0
  343. IF DV==3 THEN IX=0:IY=-1
  344. RETURN
  345.  
  346. @HI
  347. IF SP==0 THEN RETURN
  348. SP=SP-1
  349. IV=S(SP)
  350. S(SP)=0
  351. IF IV==0 THEN GOSUB @DR ELSE GOSUB @DL
  352. RETURN
  353.  
  354. @VI
  355. IF SP==0 THEN RETURN
  356. SP=SP-1
  357. IV=S(SP)
  358. S(SP)=0
  359. IF IV==0 THEN GOSUB @DD ELSE GOSUB @DU
  360. RETURN
  361.  
  362. @QM
  363. SWAP SA,SB
  364. RETURN
  365.  
  366. @SD
  367. IF SP==0 THEN RETURN
  368. SP=SP-1
  369. DV=S(SP)
  370. SP=SP+1
  371. S(SP)=DV
  372. SP=SP+1
  373. RETURN
  374.  
  375. @SS
  376. IF SP==0 THEN RETURN
  377. SP=SP-1
  378. S1=S(SP)
  379. IF SP==0 THEN RETURN
  380. SP=SP-1
  381. S2=S(SP)
  382. S(SP)=S1
  383. SP=SP+1
  384. S(SP)=S2
  385. SP=SP+1
  386. RETURN
  387.  
  388. @SE
  389. IF SP==0 THEN RETURN
  390. SP=SP-1
  391. S(SP)=0
  392. RETURN
  393.  
  394. @ON
  395. COLOR 0
  396. SP=SP-1
  397. IF DF==1 THEN @SKPN
  398. CI=LEN(STR$(S(SP)))+1
  399. IF CX+(CI-1)>32 THEN CX=0:CY=CY+1
  400. PNLSTR CX,CY,STR$(S(SP))
  401. GOSUB @CSR
  402. @SKPN
  403. S(SP)=0
  404. RETURN
  405.  
  406. @OC
  407. COLOR 0
  408. SP=SP-1
  409. IF S(SP)==13 THEN @CR
  410. IF DF==1 THEN @SKPC
  411. PNLSTR CX,CY,CHR$(S(SP))
  412. CI=1
  413. GOSUB @CSR
  414. @SKPC
  415. S(SP)=0
  416. RETURN
  417.  
  418. @GS
  419. SX=IX
  420. SY=IY
  421. RETURN
  422.  
  423. @GP
  424. IF SP<3 THEN RETURN
  425. COLOR 1
  426. SP=SP-1
  427. PY=S(SP)
  428. S(SP)=0
  429. SP=SP-1
  430. PX=S(SP)
  431. S(SP)=0
  432. SP=SP-1
  433. PV=S(SP)
  434. S(SP)=0
  435. BGPUT 1,PX,PY,5,0,0,0
  436. VSYNC 1
  437. R$(PY,PX)=CHR$(PV)
  438. VSYNC 1
  439. BGPUT 1,PX,PY,1000,15,0,0
  440. LOCATE PX,PY
  441. ?CHR$(PV);
  442. RETURN
  443.  
  444. @GG
  445. IF SP<2 THEN RETURN
  446. SP=SP-1
  447. PY=S(SP)
  448. S(SP)=0
  449. SP=SP-1
  450. PX=S(SP)
  451. BGPUT 1,PX,PY,10,0,0,0
  452. VSYNC 1
  453. S(SP)=ASC(R$(PY,PX))
  454. VSYNC 1
  455. BGPUT 1,PX,PY,1000,15,0,0
  456. SP=SP+1
  457. RETURN
  458.  
  459. @IN
  460. GOSUB @CG
  461. LOCATE 0,0
  462. COLOR 1
  463. ?"Input a number"
  464. INPUT IN
  465. GOSUB @CSR
  466. S(SP)=IN
  467. SP=SP+1
  468. GOSUB @PG
  469. RETURN
  470.  
  471. @IC
  472. GOSUB @CG
  473. LOCATE 0,0
  474. COLOR 1
  475. ?"Input a character"
  476. LINPUT IC$
  477. GOSUB @CSR
  478. S(SP)=ASC(IC$)
  479. SP=SP+1
  480. GOSUB @PG
  481. RETURN
  482.  
  483. @GE
  484. EF=1
  485. RETURN
  486.  
  487. @SGPH
  488. S(SP)=ASC(R$(RY,RX))
  489. SP=SP+1
  490. RETURN
  491.  
  492. @CSR
  493. CX=CX+CI
  494. IF CX>31 THEN CX=0:CY=CY+1
  495. RETURN
  496.  
  497. @CR
  498. CX=0
  499. CY=CY+1
  500. RETURN
  501.  
  502. @CG
  503. PNLTYPE "KYA"
  504. FOR Y=0 TO 23
  505. FOR X=0 TO 31
  506. LOCATE X,Y
  507. ?" ";
  508. NEXT
  509. NEXT
  510. RETURN
  511.  
  512. @PG
  513. FOR Y=0 TO 23
  514. FOR X=0 TO 31
  515. LOCATE X,Y
  516. ?G$(Y,X);
  517. NEXT
  518. NEXT
  519. PNLTYPE "OFF"
  520. RETURN
  521.  
  522. @EP
  523. PNLSTR 0,CY+1,"Done! Press any button..."
  524. @EPL
  525. VSYNC 1
  526. B=BUTTON(1)
  527. IF B==0 THEN GOTO @EPL
  528. BGPUT 1,RX,RY,1000,15,0,0
  529. GOTO @EDIT
  530.  
  531. @LOAD
  532. CLS
  533. COLOR 1
  534. ?"FYPE TILENAME"
  535. LINPUT FN$
  536. LOAD"GRP:"+FN$,FALSE
  537. FOR Y=0 TO 23
  538. FOR X=0 TO 31
  539. G$(Y,X)=CHR$(GSPOIT(X,Y))
  540. NEXT
  541. NEXT
  542. GOTO @EDIT
  543.  
  544. @SAVE
  545. CLS
  546. COLOR 1
  547. ?"FILENAME PLS"
  548. LINPUT FN$
  549. FOR Y=0 TO 23
  550. FOR X=0 TO 31
  551. IF G$(Y,X)=="" THEN G$(Y,X)=" "
  552. GPSET X,Y,ASC(G$(Y,X))
  553. NEXT
  554. NEXT
  555. SAVE"GRP:"+FN$
  556. GOTO @EDIT
  557.  
  558. @NEW
  559. FOR Y=0 TO 23
  560. FOR X=0 TO 31
  561. G$(Y,X)=" "
  562. NEXT
  563. NEXT
  564. GX=0
  565. GY=0
  566. GOTO @EDIT
  567.  
  568. @LANG
  569. DATA "0","@P0"
  570. DATA "1","@P1"
  571. DATA "2","@P2"
  572. DATA "3","@P3"
  573. DATA "4","@P4"
  574. DATA "5","@P5"
  575. DATA "6","@P6"
  576. DATA "7","@P7"
  577. DATA "8","@P8"
  578. DATA "9","@P9"
  579. DATA "+","@MA"
  580. DATA "-","@MS"
  581. DATA "*","@MM"
  582. DATA "/","@MD"
  583. DATA "%","@MR"
  584. DATA "!","@LN"
  585. DATA "`","@GT"
  586. DATA ">","@DR"
  587. DATA "<","@DL"
  588. DATA "^","@DU"
  589. DATA "V","@DD"
  590. DATA "?","@DQ"
  591. DATA "_","@HI"
  592. DATA "|","@VI"
  593. DATA "Q","@QM"
  594. DATA ":","@SD"
  595. DATA "\","@SS"
  596. DATA "$","@SE"
  597. DATA ".","@ON"
  598. DATA ",","@OC"
  599. DATA "#","@GS"
  600. DATA "P","@GP"
  601. DATA "G","@GG"
  602. DATA "&","@IN"
  603. DATA "~","@IC"
  604. DATA "@","@GE"
  605. DATA "",""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement