Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; PROJECT : TinySBRunTime
- ; EDITED : 9/5/2016
- ; ---------------------------------------------------------------------
- //NYI not yet implemented
- Psub parse(mystring$)
- endpsub
- psub get_color#(color$)
- endpsub
- //This does a few things, it draws the text page on the screen and the bg layers including ones shown/hidden
- psub frame_render()
- rendertoscreen
- DRAWBGS()
- render_TEXTPAGE()
- endpsub
- //Draw the textpage onto the screen
- psub render_TEXTPAGE()
- drawimage text_page, 0, 0, 1
- endpsub
- //This should be in charge of stepping the program stack foreward
- psub step_()
- inc pc //Increment the program counter
- endpsub
- //Used for utility to resize the stack of the program
- psub resize_stack(value)
- redim program_stack$(value)
- endpsub
- psub resize_labels(value)
- redim labels$(value) //the labels themselves matter
- redim label_pointers(value) //take care of the pointers to these are important
- endpsub
- psub getlabelbyvalue(value)
- endpsub labels$(value)
- psub add_returnstack(pc_pointer)
- //first increase the return stack size by 1
- inc return_stack_size
- //We also have to resize the return stack array now
- resize_Rstack(return_stack_size)
- return_stack(return_stack_size)=pc //the address or line number to return to after the jump
- pc = pc_pointer //the address or line number we are jumping to by directly modifying the pc pointer.
- //the logic is simple instead of parsing where we are if we see return we pop a value off the stack
- //and go back to the last pc address
- endpsub
- //This should literally take care of gosub
- psub gosub_(label_name$)
- index = findlabelbystring(label_name$)
- if index>0
- add_returnstack(index)
- endif
- endpsub
- psub goto_(label_name$)
- index = findlabelbystring(label_name$)
- address = label_pointers(index)
- if index>0
- jump_pc(address) //changed value to address this would have been broken
- endif
- endpsub
- psub remove_returnstack()
- //first decrement the return stack size by 1
- dec return_stack_size
- //we have to also resize it
- resize_Rstack(return_stack_size)
- //next store the pc address from the jump below us
- pc = return_stack(return_stack_size)
- //the logic is simple, we're going back to the last place we had saved (line number)
- //to continue execution.
- //As you'd expect in this way we can have 5 or even 10 different lines to eventually return to
- endpsub
- psub findlabelbystring(str_$)
- for t=0 to getarrayelements( labels$() )
- if str_$ = labels$(t)
- index=t
- exitfor
- endif
- next t
- endpsub index
- psub resize_Rstack(value)
- redim return_stack(value)
- endpsub
- //this takes care of jumping to the line number or index of the program to run
- //Probably used by goto and other commands like it
- psub jump_pc(value)
- pc = value
- endpsub
- //utility for testing
- //puts an item in the program stack,
- //increments stack counter
- psub put(command$)
- program_stack$(program_stack_size) = command$
- inc program_stack_size //increments the program stack size
- resize_stack(program_stack_size)
- endpsub
- Psub find_labels()
- dim label_strings$(1) //it should auto resize
- current_label = 1 //set the temporary current label counter so we actually have a label counter
- //pre parsing labels so we know what their line numbers are
- for t=1 to program_stack_size //Go through the whoollle stack
- entry_string$ = program_stack$(t)
- //Lots of nested ifs here. basically just check the label string
- if left$(entry_string$, 1)="@"
- //Ok we found one, let's see if we can get the full string of the label we need to store it
- Tokens=SplitToArray(entry_string$," ",label_strings$(),1)
- if len(label_strings$(1))>0 and left$(label_strings$(1), 1)="@"
- //Just double check that the @ symbol is there.
- //and this adds the label to our list
- add_label(label_strings$(1), t, current_label)
- inc current_label //don't forget to increment this or we'll over write
- //a previously saved or stored label
- //and now gosub/goto should work if called
- endif
- endif
- next t
- endpsub
- //This function handles dynamically adding new labels to the label list pre-parsing
- //This is never used during runtime and it better not ever be ;)
- psub add_label(label$, pc_index, current_label)
- //A little safety to make sure it doesn't break things and
- //that this array stays within it's indexes
- if current_label > label_list_size
- resize_labels(current_label)
- endif
- //end of safety
- labels$(current_label) = label$ //the actual label's name
- label_pointers(current_label) = pc_index //the pc address it's on
- endpsub
- Psub parse_command(index)
- dim command_strings$(20)
- dim command_strings_$(20)
- Tokens=SplitToArray(program_stack$(index),", ",command_strings$(),1)
- //Parse the color command
- for g=1 to Tokens
- if command_strings$(g) ="COLOR"
- //Tokens=SplitToArray(command_strings$(g+1),",",command_strings_$(),1)
- color_1$ = command_strings$(g+1)
- color_2$ = command_strings$(g+2)
- color_#(color_1$, color_2$)
- exitfor
- endif
- //Kind of parse the print command
- if command_strings$(g) = "Print"
- output_string$ = command_strings$(g+1)
- //locate(10, g)
- print_string(output_string$)
- endif
- if command_strings$(g) = "goto"
- //We'll get the goto label first
- goto_label$ = command_strings$(g+1)
- //Next we're going to see if it has an @
- if left$(goto_label$, 1)="@"
- //we're dealing with a correct label
- goto_(goto_label$) //and this should change the pc address!
- exitfor //now exit the for loop
- endif
- endif
- if command_strings$(g) = "locate"
- //we'll try to get the X and Y out of this
- X$ = command_strings$(g+1)
- Y$ = command_strings$(g+2)
- //if right$(X$, 1)="," then X$=left$(X$, len(X$)-1)
- x = val(X$)
- y = val(Y$)
- //locate(5, 15)
- //print_string(X$)
- //locate(5, 16)
- //print_string(Y$)
- locate(x, y)// actually try to use the command
- //locate(20, 7)
- exitfor
- endif
- next g
- endpsub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement