Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; PROJECT : TinySBRunTime
- ; EDITED : 9/5/2016
- ; ---------------------------------------------------------------------
- //psub POW(num,power)
- //n=1
- //for i=1 to power
- //n=n*num
- //next i
- //endpsub n
- //This is called after whatever is meant to be parsed is parsed
- //That is to say any math etc will be parsed before print is called not during
- psub print_string(mystring$)
- //parse(mystring$) I will comment this out for now so that print_string can be called directly
- print_S(mystring$) //Ths calls print_S because it actually prints the colors properly
- endpsub
- //This should print the string after parsing
- psub print_S(mystring$)
- rendertoimage text_page//let's just make sure we're rendering to the screen ok?
- //first we have to print the text background color
- templength = len(mystring$)
- //We're going to paint the tiles for the text background first
- for t=0 to templength
- DrawTXTBG(global_textbackground, global_textcursorX+(t/2), global_textcursorY)
- next t
- ink constant_Tcolors(global_textforeground) //Set the ink color to the right value
- curs_x = (global_textcursorX-1)*16
- curs_y = (global_textcursorY-1)*16
- setcursor curs_x, curs_y
- print mystring$ //Finally we print the string setting the color first
- rendertoscreen
- endpsub
- //Color parsing. I'll seperate these and use a seperate function when parsing to figure out which case to use
- //Then pass the correctly formatted data to whichever case matches.
- psub gcolor_rgb(color)
- #print "nothing"
- endpsub
- psub gcolor_#(color$)
- for t=1 to 18
- if color$=constant_colors$(t)
- ink rgb_colors(t)
- exitfor
- endif
- next t
- endpsub
- //this function deals with if both the parameters use #T
- psub color_#(colorTXT$, colorBG$)
- //we'll get both the colors at once , even if they're closer this is a faster search than trying to search twice
- //in the case that one color may be found right away
- //we're only losing 1/2 the processing time with this search than independently searching each one out
- for t=1 to 15
- if colorTXT$ = constant_Tcolors$(t)
- color1= Constant_tcolors(t)
- set_global_textforeground(t) //This is the global text foreground value we're sending this to to the main system
- endif
- if colorBG$ = constant_Tcolors$(t)
- color2= Constant_tcolors(t)
- colorindex=t //added this so that it can be used to quickly get the color tile the rgb value won't be needed
- //Good to have it as a constant anyways for setting text colors
- set_global_textbackground(t) //This is the global color value, we're sending this to the main system
- endif
- next t
- endpsub color1, color2, colorindex
- //this function deals with if just the first parameter is given using #T
- psub color_1#(colorTXT$)
- for t=1 to 15
- if colorTXT$ = constant_Tcolors$(t)
- color1= Constant_tcolors(t)
- set_global_textforeground(t) //this is the global foreground text color. We're sending this to the system!
- endif
- next t
- endpsub color1
- //This function deals with if just the second parameter was given using #T
- psub color_2#(ColorBG$)
- for t=1 to 15
- if ColorBG$ = constant_Tcolors$(t)
- color2 = Constant_tcolors(t)
- colorindex=t
- set_global_textbackground(t) //This is the global background text color. SEND IT TO THE SYSTEM :D
- endif
- next t
- endpsub color2, colorindex
- psub gcolor_hex(color$)
- endpsub
- psub bgscreen(layer, width, height)
- endpsub
- //Case to clear just one BG layer
- psub bgclr(layer)
- select layer
- case 0:
- rendertoimage BGLAYERS(1).BGImage
- case 1:
- rendertoimage BGLAYERS(2).BGImage
- case 2:
- rendertoimage BGLAYERS(3).BGImage
- case 3:
- rendertoimage BGLAYERS(4).BGImage
- default:
- rendertoimage BGLAYERS(1).BGImage
- endselect
- cls
- rendertoscreen
- endpsub
- //Case to clear all BG layers
- psub bgclrall()
- for t=1 to 4
- rendertoimage BGLAYERS(t).BGImage
- cls
- next t
- rendertoscreen
- endpsub
- psub locate(x, y)
- setcursor (x-1)*16, (y-1)*16
- //Since this modifies the text cursor the entire system should know about it
- global_textcursorX=x
- global_textcursorY=y
- endpsub
- psub BGOFS(layer, NewOFFSETX, NewOFFSETY)
- select layer
- case 0:
- BGLAYERS(1).OFFSETX = NewOFFSETX
- BGLAYERS(1).OFFSETY = NewOFFSETY
- case 1:
- BGLAYERS(2).OFFSETX = NewOFFSETX
- BGLAYERS(2).OFFSETY = NewOFFSETY
- case 2:
- BGLAYERS(3).OFFSETX = NewOFFSETX
- BGLAYERS(3).OFFSETY = NewOFFSETY
- case 3:
- BGLAYERS(4).OFFSETX = NewOFFSETX
- BGLAYERS(4).OFFSETY = NewOFFSETY
- default:
- BGLAYERS(1).OFFSETX = NewOFFSETX
- BGLAYERS(1).OFFSETY = NewOFFSETY
- endselect
- endpsub
- psub BGPUT(Layer,X,Y,Screen_data)
- select layer
- case 0:
- rendertoimage BGLAYERS(1).BGImage
- case 1:
- rendertoimage BGLAYERS(2).BGImage
- case 2:
- rendertoimage BGLAYERS(3).BGImage
- case 3:
- rendertoimage BGLAYERS(4).BGImage
- default:
- rendertoimage BGLAYERS(1).BGImage
- endselect
- drawimage tiles(Screen_data), (x-1)*16, (y-1)*16, 1
- rendertoscreen
- endpsub
- psub DRAWBGS()
- for t=1 to 4
- X_OFFS = BGLAYERS(t).OFFSETX
- Y_OFFS = BGLAYERS(t).OFFSETY
- //Get the visible flag of the BG layer
- VISIBLE = BGLAYERS(t).VISIBLE
- //Only draw the bg layer if visible is true
- if VISIBLE=true then Drawimage BGLAYERS(t).BGImage, X_OFFS, Y_OFFS, 1
- next t
- endpsub
- psub BGhide(layer)
- BGLAYERS(layer).Visible = false
- endpsub
- psub Bgshow(layer)
- BGLAYERS(layer).Visible = true
- endpsub
- psub vsync(value)
- sync
- wait value
- endpsub
- psub vsync_novalue()
- sync
- endpsub
- //These functions deal with arrays that are virtualized.
- psub get_index1D(index)
- index1D = index
- endpsub index1D
- psub get_index2D(x, y, X_width)
- index2D = (y*X_width)+x
- endpsub index2D
- psub get_index3D(x, y, z, X_width, Y_depth)
- index3D = (z * X_width * Y_depth) + (y * X_width) + x
- endpsub index3D
- //This resizes an array of string type in 3 dimensions.
- psub resize_array3DSTR(array_index, X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
- dim temparray$(old_X_width, old_Y_depth, old_Z_depth) //we're making a copy
- dim temparray_$(old_x_width, old_Y_depth, old_Z_depth)
- temparray$() = copyarray3DSTR(array_index, temparray_$(), old_X_width, old_Y_depth, old_Z_depth)
- _type = 3 //type 3 is string
- allocate_size3D(X_width, Y_depth, Z_depth, array_index, _type)
- //Next we need to copy the old contents to the new 3D array.
- copyOld3DNew3DSTR(array_index, temparray$(), X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
- //and that should be it
- endpsub
- //This resizes an array of string type in 2 dimensions.
- psub resize_array2DSTR(array_index, X_width, Y_depth, old_X_width, old_Y_depth)
- dim temparray$(old_X_width, old_Y_depth) //we're making a copy
- dim temparray_$(old_x_width, old_Y_depth)
- temparray$() = copyarray2DSTR(array_index, temparray_$(), old_X_width, old_Y_depth)
- _type = 3 //type 3 is string
- allocate_size2D(X_width, Y_depth, array_index, _type)
- //Next we need to copy the old contents to the new 3D array.
- copyOld2DNew2DSTR(array_index, temparray$(), X_width, Y_depth, old_X_width, old_Y_depth)
- //and that should be it
- endpsub
- psub resize_array1DSTR(array_index, new_length)
- STRINGS1D(array_index).total_length = new_length
- endpsub
- //This resizes an array of int type in 3 dimensions.
- psub resize_array3DINT(array_index, X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
- dim temparray(old_X_width, old_Y_depth, old_Z_depth) //we're making a copy
- dim temparray_(old_x_width, old_Y_depth, old_Z_depth)
- temparray() = copyarray3DINT(array_index, temparray_(), old_X_width, old_Y_depth, old_Z_depth)
- //Next the program needs to resize the array properties. I'll use a function for that too. it's easier.
- _type = 1 //type 1 is int
- allocate_size3D(X_width, Y_depth, Z_depth, array_index, _type)
- //Next we need to copy the old contents to the new 3D array.
- copyOld3DNew3DINT(array_index, temparray(), X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
- //and that should be it
- endpsub
- //This resizes an array of int type in 2 dimensions.
- psub resize_array2DINT(array_index, X_width, Y_depth, old_X_width, old_Y_depth)
- dim temparray(old_X_width, old_Y_depth) //we're making a copy
- dim temparray_(old_x_width, old_Y_depth)
- temparray() = copyarray2DINT(array_index, temparray_(), old_X_width, old_Y_depth)
- //Next the program needs to resize the array properties. I'll use a function for that too. it's easier.
- _type = 1 //type 1 is int
- allocate_size2D(X_width, Y_depth, array_index, _type)
- //Next we need to copy the old contents to the new 3D array.
- copyOld2DNew2DINT(array_index, temparray(), X_width, Y_depth, old_X_width, old_Y_depth)
- //and that should be it
- endpsub
- psub resize_array1DINT(array_index, new_length)
- INTS1D(array_index).total_length = new_length
- endpsub
- //The below function requires both arrays have the same X, Y, Z sizing.
- psub copyarray3DSTR(array_index, temparray$(), sizeX, sizeY, sizeZ )
- for x=0 to SizeX
- for y=0 to SizeY
- for z=0 to SizeZ
- sourceindex = get_index3D(x, y, z, SizeX, SizeY)
- temparray$(x, y, z) = Strings3D(array_index).entries$(sourceindex)
- next z
- next y
- next x
- endpsub temparray$()
- //Copy the 2D string array safely to a temp array
- psub copyarray2DSTR(array_index, temparray$(), sizeX, sizeY)
- for x=0 to SizeX
- for y=0 to SizeY
- sourceindex = get_index2D(x, y, SizeX)
- temparray$(x, y) = Strings3D(array_index).entries$(sourceindex)
- next y
- next x
- endpsub temparray$()
- //Copy the 3D int array safely to a temp array
- psub copyarray3DINT(array_index, temparray(), sizeX, sizeY, sizeZ )
- for x=0 to SizeX
- for y=0 to SizeY
- for z=0 to SizeZ
- sourceindex = get_index3D(x, y, z, SizeX, SizeY)
- temparray(x, y, z) = INTS3D(array_index).entries(sourceindex)
- next z
- next y
- next x
- endpsub temparray()
- //Copy the 2D int array safely to a temp array
- psub copyarray2DINT(array_index, temparray(), sizeX, sizeY)
- for x=0 to SizeX
- for y=0 to SizeY
- sourceindex = get_index2D(x, y, SizeX)
- temparray(x, y) = INTS2D(array_index).entries(sourceindex)
- next y
- next x
- endpsub temparray()
- //This doesn't resize an array it only changes the internal size definition
- psub allocate_size3D(X, Y, Z, index, _type)
- select _type
- case 1:
- INTS3D(index).X_width = X
- INTS3D(index).Y_depth = Y
- INTS3D(index).Z_depth = Z
- case 2:
- case 3:
- Strings3D(index).X_width = X
- Strings3D(index).Y_depth = Y
- Strings3D(index).Z_depth = Z
- endselect
- endpsub
- //This doesn't resize an array it only changes the internal size definition
- psub allocate_size2D(X, Y, index, _type)
- select _type
- case 1:
- INTS2D(index).X_width = X
- INTS2D(index).Y_depth = Y
- case 2:
- case 3:
- Strings2D(index).X_width = X
- Strings2D(index).Y_depth = Y
- endselect
- endpsub
- //Function deals with 3D string arrays
- psub copyOld3DNew3DSTR(array_index, temparray$(), X_width, Y_depth, Z_depth, old_X_width, old_Y_depth, old_Z_depth)
- for x=0 to old_X_width
- for y=0 to old_Y_depth
- for z=0 to old_Z_depth
- //Here the indexes will be different for a differently dimensioned 3D String array as a 1D array so we need
- //to do a translation based on the new Width and Height of the array
- Old_Index = get_index3D(x, y, z, old_X_width, old_Y_depth)
- New_Index = get_index3D(x, y, z, X_width, Y_depth)
- //Ok we have our indexes, let's hope this isn't too costly.
- old_string$ = temparray$(x, y, z)
- Strings3D(array_index).entries$(New_Index) = old_string$
- //and that's it, we've copied back the data.
- //This function should be used with CopyArray3DSTR only.
- next z
- next y
- next x
- endpsub
- //Function deals with 2d String arrays
- psub copyOLD2DNew2DSTR(array_index, temparray$(), X_width, Y_depth, old_X_width, old_y_depth)
- for x=0 to old_X_width
- for y=0 to old_y_width
- //Here the indexes will be different for a differently dimensioned 2D String array as a 1D array so we need
- //to do a translation based on the new Width and Height of the array
- Old_Index = get_index2D(x, y, Old_X_width)
- New_Index = get_index2D(x, y, X_width)
- //We have our indexes, coding this i feel craazy
- old_string$ = temparray$(x, y)
- Strings2D(array_index).entries$(New_Index) = old_string$
- //tada done
- //Skip hop and away we go
- next y
- next x
- endpsub
- //Function deals with 3D Integer arrays
- psub CopyOld3DNew3DINT(array_index, temparray(), X_width, Y_depth, Z_depth, old_X_width, old_y_depth, old_z_depth)
- for x=0 to old_X_width
- for y=0 to old_y_depth
- for z=0 to old_z_depth
- //Here the indexes will be different for a differently dimensioned 3d INT array as 1D array so
- //We have to do a translation based on the new Width and Height of the array yep yep
- Old_Index = get_index3D(x, y, z, old_X_width, old_y_depth)
- New_Index = get_index3D(x, y , z, X_width, y_depth)
- //Got indexes? Great! Next we just copy and it doesn't seem costly
- old_value = temparray(x, y, z)
- INTS3D(array_index).entries(New_Index) = old_value
- //and done
- //~Tada 3D array copying and safety.
- next z
- next y
- next x
- endpsub
- //Function deals with 2D Integer arrays
- psub CopyOld2DNew2DINT(array_index, temparray(), X_width, Y_depth, old_X_width, old_y_depth)
- for x=0 to old_X_width
- for y=0 to old_y_depth
- //Here the indexes will be different for a differently dimensioned 3d INT array as 1D array so
- //We have to do a translation based on the new Width and Height of the array yep yep
- Old_Index = get_index2D(x, y, old_X_width)
- New_Index = get_index2D(x, y , X_width)
- //Got indexes? Great! Next we just copy and it doesn't seem costly
- old_value = temparray(x, y)
- INTS2D(array_index).entries(New_Index) = old_value
- //and done
- //~Tada 2D array copying and safety.
- next y
- next x
- endpsub
- psub get3DSTRByname(total_entries, arrayname$)
- for t=1 to total_entries
- if Strings3D(t).internal_name$=arrayname$
- arrayindex=t
- exitfor
- endif
- next t
- endpsub arrayindex
- psub get2DSTRByname(total_entries, arrayname$)
- for t=1 to total_entries
- if Strings2D(t).internal_name$=arrayname$
- arrayindex=t
- exitfor
- endif
- next t
- endpsub arrayindex
- psub get1DSTRByname(total_entries, arrayname$)
- for t=1 to total_entries
- if Strings1D(t).internal_name$=arrayname$
- arrayindex=t
- exitfor
- endif
- next t
- endpsub arrayindex
- psub get3DINTByname(total_entries, arrayname$)
- for t=1 to total_entries
- if INTS3D(t).internal_name$=arrayname$
- arrayindex=t
- exitfor
- endif
- next t
- endpsub arrayindex
- psub get2DINTByname(total_entries, arrayname$)
- for t=1 to total_entries
- if INTS2D(t).internal_name$=arrayname$
- arrayindex=t
- exitfor
- endif
- next t
- endpsub arrayindex
- psub get1DINTByname(total_entries, arrayname$)
- for t=1 to total_entries
- if INTS1D(t).internal_name$=arrayname$
- arrayindex=t
- exitfor
- endif
- next t
- endpsub arrayindex
- psub DrawTXTBG(colorindex, X, Y)
- PosX=(X-1)*16
- PosY=(Y-1)*16
- drawimage TXTBG(colorindex), PosX, PosY, 0
- endpsub
- //This sets the global text background color
- psub set_global_textbackground(value)
- global_textbackground=value
- endpsub
- //This sets the global text foreground color
- psub set_global_textforeground(value)
- global_textforeground=value
- endpsub
- psub cls_()
- rendertoimage text_page
- cls
- rendertoscreen
- endpsub
- psub gcls()
- rendertoimage graphics_page(currentGPAGEDSP)
- cls
- endpsub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement