Advertisement
Guest User

TinySB FunctionsLayer2

a guest
Sep 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.23 KB | None | 0 0
  1. ; PROJECT : TinySBRunTime
  2. ; EDITED : 9/5/2016
  3. ; ---------------------------------------------------------------------
  4. //psub POW(num,power)
  5. //n=1
  6. //for i=1 to power
  7. //n=n*num
  8. //next i
  9. //endpsub n
  10.  
  11. //This is called after whatever is meant to be parsed is parsed
  12. //That is to say any math etc will be parsed before print is called not during
  13.  
  14. psub print_string(mystring$)
  15. //parse(mystring$) I will comment this out for now so that print_string can be called directly
  16. print_S(mystring$) //Ths calls print_S because it actually prints the colors properly
  17. endpsub
  18.  
  19. //This should print the string after parsing
  20. psub print_S(mystring$)
  21. rendertoimage text_page//let's just make sure we're rendering to the screen ok?
  22. //first we have to print the text background color
  23. templength = len(mystring$)
  24. //We're going to paint the tiles for the text background first
  25. for t=0 to templength
  26. DrawTXTBG(global_textbackground, global_textcursorX+(t/2), global_textcursorY)
  27. next t
  28. ink constant_Tcolors(global_textforeground) //Set the ink color to the right value
  29. curs_x = (global_textcursorX-1)*16
  30. curs_y = (global_textcursorY-1)*16
  31. setcursor curs_x, curs_y
  32. print mystring$ //Finally we print the string setting the color first
  33. rendertoscreen
  34. endpsub
  35.  
  36. //Color parsing. I'll seperate these and use a seperate function when parsing to figure out which case to use
  37. //Then pass the correctly formatted data to whichever case matches.
  38. psub gcolor_rgb(color)
  39. #print "nothing"
  40. endpsub
  41.  
  42. psub gcolor_#(color$)
  43. for t=1 to 18
  44. if color$=constant_colors$(t)
  45. ink rgb_colors(t)
  46. exitfor
  47. endif
  48. next t
  49. endpsub
  50.  
  51. //this function deals with if both the parameters use #T
  52. psub color_#(colorTXT$, colorBG$)
  53. //we'll get both the colors at once , even if they're closer this is a faster search than trying to search twice
  54. //in the case that one color may be found right away
  55. //we're only losing 1/2 the processing time with this search than independently searching each one out
  56. for t=1 to 15
  57. if colorTXT$ = constant_Tcolors$(t)
  58. color1= Constant_tcolors(t)
  59. set_global_textforeground(t) //This is the global text foreground value we're sending this to to the main system
  60. endif
  61.  
  62. if colorBG$ = constant_Tcolors$(t)
  63. color2= Constant_tcolors(t)
  64. colorindex=t //added this so that it can be used to quickly get the color tile the rgb value won't be needed
  65. //Good to have it as a constant anyways for setting text colors
  66. set_global_textbackground(t) //This is the global color value, we're sending this to the main system
  67. endif
  68.  
  69. next t
  70. endpsub color1, color2, colorindex
  71.  
  72. //this function deals with if just the first parameter is given using #T
  73. psub color_1#(colorTXT$)
  74. for t=1 to 15
  75. if colorTXT$ = constant_Tcolors$(t)
  76. color1= Constant_tcolors(t)
  77. set_global_textforeground(t) //this is the global foreground text color. We're sending this to the system!
  78. endif
  79. next t
  80. endpsub color1
  81.  
  82. //This function deals with if just the second parameter was given using #T
  83. psub color_2#(ColorBG$)
  84.  
  85. for t=1 to 15
  86. if ColorBG$ = constant_Tcolors$(t)
  87. color2 = Constant_tcolors(t)
  88. colorindex=t
  89. set_global_textbackground(t) //This is the global background text color. SEND IT TO THE SYSTEM :D
  90. endif
  91. next t
  92. endpsub color2, colorindex
  93.  
  94. psub gcolor_hex(color$)
  95.  
  96. endpsub
  97.  
  98. psub bgscreen(layer, width, height)
  99.  
  100. endpsub
  101.  
  102. //Case to clear just one BG layer
  103. psub bgclr(layer)
  104. select layer
  105. case 0:
  106. rendertoimage BGLAYERS(1).BGImage
  107. case 1:
  108. rendertoimage BGLAYERS(2).BGImage
  109. case 2:
  110. rendertoimage BGLAYERS(3).BGImage
  111. case 3:
  112. rendertoimage BGLAYERS(4).BGImage
  113. default:
  114. rendertoimage BGLAYERS(1).BGImage
  115. endselect
  116. cls
  117. rendertoscreen
  118. endpsub
  119.  
  120. //Case to clear all BG layers
  121. psub bgclrall()
  122. for t=1 to 4
  123. rendertoimage BGLAYERS(t).BGImage
  124. cls
  125. next t
  126.  
  127. rendertoscreen
  128. endpsub
  129.  
  130. psub locate(x, y)
  131. setcursor (x-1)*16, (y-1)*16
  132. //Since this modifies the text cursor the entire system should know about it
  133. global_textcursorX=x
  134. global_textcursorY=y
  135. endpsub
  136.  
  137. psub BGOFS(layer, NewOFFSETX, NewOFFSETY)
  138. select layer
  139. case 0:
  140. BGLAYERS(1).OFFSETX = NewOFFSETX
  141. BGLAYERS(1).OFFSETY = NewOFFSETY
  142. case 1:
  143. BGLAYERS(2).OFFSETX = NewOFFSETX
  144. BGLAYERS(2).OFFSETY = NewOFFSETY
  145. case 2:
  146. BGLAYERS(3).OFFSETX = NewOFFSETX
  147. BGLAYERS(3).OFFSETY = NewOFFSETY
  148. case 3:
  149. BGLAYERS(4).OFFSETX = NewOFFSETX
  150. BGLAYERS(4).OFFSETY = NewOFFSETY
  151. default:
  152. BGLAYERS(1).OFFSETX = NewOFFSETX
  153. BGLAYERS(1).OFFSETY = NewOFFSETY
  154. endselect
  155.  
  156. endpsub
  157.  
  158. psub BGPUT(Layer,X,Y,Screen_data)
  159.  
  160. select layer
  161. case 0:
  162. rendertoimage BGLAYERS(1).BGImage
  163. case 1:
  164. rendertoimage BGLAYERS(2).BGImage
  165. case 2:
  166. rendertoimage BGLAYERS(3).BGImage
  167. case 3:
  168. rendertoimage BGLAYERS(4).BGImage
  169. default:
  170. rendertoimage BGLAYERS(1).BGImage
  171. endselect
  172.  
  173. drawimage tiles(Screen_data), (x-1)*16, (y-1)*16, 1
  174. rendertoscreen
  175. endpsub
  176.  
  177. psub DRAWBGS()
  178.  
  179. for t=1 to 4
  180. X_OFFS = BGLAYERS(t).OFFSETX
  181. Y_OFFS = BGLAYERS(t).OFFSETY
  182. //Get the visible flag of the BG layer
  183. VISIBLE = BGLAYERS(t).VISIBLE
  184. //Only draw the bg layer if visible is true
  185. if VISIBLE=true then Drawimage BGLAYERS(t).BGImage, X_OFFS, Y_OFFS, 1
  186. next t
  187. endpsub
  188.  
  189. psub BGhide(layer)
  190. BGLAYERS(layer).Visible = false
  191. endpsub
  192.  
  193. psub Bgshow(layer)
  194. BGLAYERS(layer).Visible = true
  195. endpsub
  196.  
  197.  
  198. psub vsync(value)
  199. sync
  200. wait value
  201. endpsub
  202.  
  203. psub vsync_novalue()
  204. sync
  205. endpsub
  206.  
  207. //These functions deal with arrays that are virtualized.
  208. psub get_index1D(index)
  209. index1D = index
  210. endpsub index1D
  211.  
  212. psub get_index2D(x, y, X_width)
  213. index2D = (y*X_width)+x
  214. endpsub index2D
  215.  
  216. psub get_index3D(x, y, z, X_width, Y_depth)
  217. index3D = (z * X_width * Y_depth) + (y * X_width) + x
  218. endpsub index3D
  219.  
  220. //This resizes an array of string type in 3 dimensions.
  221. psub resize_array3DSTR(array_index, X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
  222. dim temparray$(old_X_width, old_Y_depth, old_Z_depth) //we're making a copy
  223. dim temparray_$(old_x_width, old_Y_depth, old_Z_depth)
  224. temparray$() = copyarray3DSTR(array_index, temparray_$(), old_X_width, old_Y_depth, old_Z_depth)
  225. _type = 3 //type 3 is string
  226. allocate_size3D(X_width, Y_depth, Z_depth, array_index, _type)
  227. //Next we need to copy the old contents to the new 3D array.
  228. copyOld3DNew3DSTR(array_index, temparray$(), X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
  229. //and that should be it
  230. endpsub
  231.  
  232. //This resizes an array of string type in 2 dimensions.
  233. psub resize_array2DSTR(array_index, X_width, Y_depth, old_X_width, old_Y_depth)
  234. dim temparray$(old_X_width, old_Y_depth) //we're making a copy
  235. dim temparray_$(old_x_width, old_Y_depth)
  236. temparray$() = copyarray2DSTR(array_index, temparray_$(), old_X_width, old_Y_depth)
  237. _type = 3 //type 3 is string
  238. allocate_size2D(X_width, Y_depth, array_index, _type)
  239. //Next we need to copy the old contents to the new 3D array.
  240. copyOld2DNew2DSTR(array_index, temparray$(), X_width, Y_depth, old_X_width, old_Y_depth)
  241. //and that should be it
  242. endpsub
  243.  
  244. psub resize_array1DSTR(array_index, new_length)
  245. STRINGS1D(array_index).total_length = new_length
  246. endpsub
  247.  
  248. //This resizes an array of int type in 3 dimensions.
  249. psub resize_array3DINT(array_index, X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
  250. dim temparray(old_X_width, old_Y_depth, old_Z_depth) //we're making a copy
  251. dim temparray_(old_x_width, old_Y_depth, old_Z_depth)
  252. temparray() = copyarray3DINT(array_index, temparray_(), old_X_width, old_Y_depth, old_Z_depth)
  253. //Next the program needs to resize the array properties. I'll use a function for that too. it's easier.
  254. _type = 1 //type 1 is int
  255. allocate_size3D(X_width, Y_depth, Z_depth, array_index, _type)
  256. //Next we need to copy the old contents to the new 3D array.
  257. copyOld3DNew3DINT(array_index, temparray(), X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
  258. //and that should be it
  259. endpsub
  260.  
  261. //This resizes an array of int type in 2 dimensions.
  262. psub resize_array2DINT(array_index, X_width, Y_depth, old_X_width, old_Y_depth)
  263. dim temparray(old_X_width, old_Y_depth) //we're making a copy
  264. dim temparray_(old_x_width, old_Y_depth)
  265. temparray() = copyarray2DINT(array_index, temparray_(), old_X_width, old_Y_depth)
  266. //Next the program needs to resize the array properties. I'll use a function for that too. it's easier.
  267. _type = 1 //type 1 is int
  268. allocate_size2D(X_width, Y_depth, array_index, _type)
  269. //Next we need to copy the old contents to the new 3D array.
  270. copyOld2DNew2DINT(array_index, temparray(), X_width, Y_depth, old_X_width, old_Y_depth)
  271. //and that should be it
  272. endpsub
  273.  
  274. psub resize_array1DINT(array_index, new_length)
  275. INTS1D(array_index).total_length = new_length
  276. endpsub
  277.  
  278. //The below function requires both arrays have the same X, Y, Z sizing.
  279. psub copyarray3DSTR(array_index, temparray$(), sizeX, sizeY, sizeZ )
  280. for x=0 to SizeX
  281. for y=0 to SizeY
  282. for z=0 to SizeZ
  283. sourceindex = get_index3D(x, y, z, SizeX, SizeY)
  284. temparray$(x, y, z) = Strings3D(array_index).entries$(sourceindex)
  285. next z
  286. next y
  287. next x
  288. endpsub temparray$()
  289.  
  290. //Copy the 2D string array safely to a temp array
  291. psub copyarray2DSTR(array_index, temparray$(), sizeX, sizeY)
  292. for x=0 to SizeX
  293. for y=0 to SizeY
  294. sourceindex = get_index2D(x, y, SizeX)
  295. temparray$(x, y) = Strings3D(array_index).entries$(sourceindex)
  296. next y
  297. next x
  298. endpsub temparray$()
  299.  
  300. //Copy the 3D int array safely to a temp array
  301. psub copyarray3DINT(array_index, temparray(), sizeX, sizeY, sizeZ )
  302. for x=0 to SizeX
  303. for y=0 to SizeY
  304. for z=0 to SizeZ
  305. sourceindex = get_index3D(x, y, z, SizeX, SizeY)
  306. temparray(x, y, z) = INTS3D(array_index).entries(sourceindex)
  307. next z
  308. next y
  309. next x
  310. endpsub temparray()
  311.  
  312. //Copy the 2D int array safely to a temp array
  313. psub copyarray2DINT(array_index, temparray(), sizeX, sizeY)
  314. for x=0 to SizeX
  315. for y=0 to SizeY
  316. sourceindex = get_index2D(x, y, SizeX)
  317. temparray(x, y) = INTS2D(array_index).entries(sourceindex)
  318. next y
  319. next x
  320. endpsub temparray()
  321.  
  322. //This doesn't resize an array it only changes the internal size definition
  323. psub allocate_size3D(X, Y, Z, index, _type)
  324. select _type
  325. case 1:
  326. INTS3D(index).X_width = X
  327. INTS3D(index).Y_depth = Y
  328. INTS3D(index).Z_depth = Z
  329. case 2:
  330. case 3:
  331. Strings3D(index).X_width = X
  332. Strings3D(index).Y_depth = Y
  333. Strings3D(index).Z_depth = Z
  334. endselect
  335.  
  336. endpsub
  337.  
  338. //This doesn't resize an array it only changes the internal size definition
  339. psub allocate_size2D(X, Y, index, _type)
  340. select _type
  341. case 1:
  342. INTS2D(index).X_width = X
  343. INTS2D(index).Y_depth = Y
  344. case 2:
  345. case 3:
  346. Strings2D(index).X_width = X
  347. Strings2D(index).Y_depth = Y
  348. endselect
  349.  
  350. endpsub
  351.  
  352. //Function deals with 3D string arrays
  353. psub copyOld3DNew3DSTR(array_index, temparray$(), X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
  354. for x=0 to old_X_width
  355. for y=0 to old_Y_depth
  356. for z=0 to old_Z_depth
  357. //Here the indexes will be different for a differently dimensioned 3D String array as a 1D array so we need
  358. //to do a translation based on the new Width and Height of the array
  359. Old_Index = get_index3D(x, y, z, old_X_width, old_Y_depth)
  360. New_Index = get_index3D(x, y, z, X_width, Y_depth)
  361.  
  362. //Ok we have our indexes, let's hope this isn't too costly.
  363. old_string$ = temparray$(x, y, z)
  364.  
  365. Strings3D(array_index).entries$(New_Index) = old_string$
  366. //and that's it, we've copied back the data.
  367. //This function should be used with CopyArray3DSTR only.
  368. next z
  369. next y
  370. next x
  371. endpsub
  372.  
  373. //Function deals with 2d String arrays
  374. psub copyOLD2DNew2DSTR(array_index, temparray$(), X_width, Y_depth, old_X_width, old_y_depth)
  375. for x=0 to old_X_width
  376. for y=0 to old_y_width
  377. //Here the indexes will be different for a differently dimensioned 2D String array as a 1D array so we need
  378. //to do a translation based on the new Width and Height of the array
  379. Old_Index = get_index2D(x, y, Old_X_width)
  380. New_Index = get_index2D(x, y, X_width)
  381.  
  382. //We have our indexes, coding this i feel craazy
  383. old_string$ = temparray$(x, y)
  384. Strings2D(array_index).entries$(New_Index) = old_string$
  385. //tada done
  386. //Skip hop and away we go
  387. next y
  388. next x
  389. endpsub
  390.  
  391. //Function deals with 3D Integer arrays
  392. psub CopyOld3DNew3DINT(array_index, temparray(), X_width, Y_depth, Z_depth, old_X_width, old_y_depth, old_z_depth)
  393. for x=0 to old_X_width
  394. for y=0 to old_y_depth
  395. for z=0 to old_z_depth
  396. //Here the indexes will be different for a differently dimensioned 3d INT array as 1D array so
  397. //We have to do a translation based on the new Width and Height of the array yep yep
  398. Old_Index = get_index3D(x, y, z, old_X_width, old_y_depth)
  399. New_Index = get_index3D(x, y , z, X_width, y_depth)
  400.  
  401. //Got indexes? Great! Next we just copy and it doesn't seem costly
  402. old_value = temparray(x, y, z)
  403. INTS3D(array_index).entries(New_Index) = old_value
  404. //and done
  405. //~Tada 3D array copying and safety.
  406. next z
  407. next y
  408. next x
  409. endpsub
  410.  
  411. //Function deals with 2D Integer arrays
  412. psub CopyOld2DNew2DINT(array_index, temparray(), X_width, Y_depth, old_X_width, old_y_depth)
  413. for x=0 to old_X_width
  414. for y=0 to old_y_depth
  415. //Here the indexes will be different for a differently dimensioned 3d INT array as 1D array so
  416. //We have to do a translation based on the new Width and Height of the array yep yep
  417. Old_Index = get_index2D(x, y, old_X_width)
  418. New_Index = get_index2D(x, y , X_width)
  419.  
  420. //Got indexes? Great! Next we just copy and it doesn't seem costly
  421. old_value = temparray(x, y)
  422. INTS2D(array_index).entries(New_Index) = old_value
  423. //and done
  424. //~Tada 2D array copying and safety.
  425. next y
  426. next x
  427. endpsub
  428.  
  429. psub get3DSTRByname(total_entries, arrayname$)
  430. for t=1 to total_entries
  431. if Strings3D(t).internal_name$=arrayname$
  432. arrayindex=t
  433. exitfor
  434. endif
  435. next t
  436.  
  437. endpsub arrayindex
  438.  
  439. psub get2DSTRByname(total_entries, arrayname$)
  440. for t=1 to total_entries
  441. if Strings2D(t).internal_name$=arrayname$
  442. arrayindex=t
  443. exitfor
  444. endif
  445. next t
  446. endpsub arrayindex
  447.  
  448. psub get1DSTRByname(total_entries, arrayname$)
  449. for t=1 to total_entries
  450. if Strings1D(t).internal_name$=arrayname$
  451. arrayindex=t
  452. exitfor
  453. endif
  454. next t
  455. endpsub arrayindex
  456.  
  457. psub get3DINTByname(total_entries, arrayname$)
  458. for t=1 to total_entries
  459. if INTS3D(t).internal_name$=arrayname$
  460. arrayindex=t
  461. exitfor
  462. endif
  463. next t
  464. endpsub arrayindex
  465.  
  466. psub get2DINTByname(total_entries, arrayname$)
  467. for t=1 to total_entries
  468. if INTS2D(t).internal_name$=arrayname$
  469. arrayindex=t
  470. exitfor
  471. endif
  472. next t
  473. endpsub arrayindex
  474.  
  475. psub get1DINTByname(total_entries, arrayname$)
  476. for t=1 to total_entries
  477. if INTS1D(t).internal_name$=arrayname$
  478. arrayindex=t
  479. exitfor
  480. endif
  481. next t
  482. endpsub arrayindex
  483.  
  484. psub DrawTXTBG(colorindex, X, Y)
  485. PosX=(X-1)*16
  486. PosY=(Y-1)*16
  487. drawimage TXTBG(colorindex), PosX, PosY, 0
  488. endpsub
  489.  
  490. //This sets the global text background color
  491. psub set_global_textbackground(value)
  492. global_textbackground=value
  493. endpsub
  494.  
  495. //This sets the global text foreground color
  496. psub set_global_textforeground(value)
  497. global_textforeground=value
  498. endpsub
  499.  
  500.  
  501. psub cls_()
  502. rendertoimage text_page
  503. cls
  504. rendertoscreen
  505. endpsub
  506.  
  507. psub gcls()
  508. rendertoimage graphics_page(currentGPAGEDSP)
  509. cls
  510. endpsub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement