toying with banks
Blitz3D Forums/Blitz3D Programming/toying with banks
| ||
For my current project, I needed to create functions that permit shuffling values from/to a buffer that is consisted of a bank and some pointers. Here is one of the functions. It is meant to take an INT value and add that into a bank buffer as ascii values. It is a working function. Any improvements would be greatly appreciated: Function term_insert_INT_into_request(num_in%) Local num_send_subsequent% = False num_out% = Floor (num_in * 0.000001) Mod 10 : If num_out > 0 Then term_insert_into_answerback_buffer(num_out + 48) : num_send_subsequent% = True num_out% = Floor (num_in * 0.00001 ) Mod 10 : If num_out > 0 Or num_send_subsequent = True Then term_insert_into_request_buffer(num_out + 48) : num_send_subsequent% = True num_out% = Floor (num_in * 0.0001 ) Mod 10 : If num_out > 0 Or num_send_subsequent = True Then term_insert_into_request_buffer(num_out + 48) : num_send_subsequent% = True num_out% = Floor (num_in * 0.001 ) Mod 10 : If num_out > 0 Or num_send_subsequent = True Then term_insert_into_request_buffer(num_out + 48) : num_send_subsequent% = True num_out% = Floor (num_in * 0.01 ) Mod 10 : If num_out > 0 Or num_send_subsequent = True Then term_insert_into_request_buffer(num_out + 48) : num_send_subsequent% = True num_out% = Floor (num_in * 0.1 ) Mod 10 : If num_out > 0 Or num_send_subsequent = True Then term_insert_into_request_buffer(num_out + 48) : num_send_subsequent% = True num_out% = Floor (num_in ) Mod 10 : term_insert_into_request_buffer(num_out + 48) End Function Function term_insert_into_request_buffer(char%) term\request_buffer_write_marker = term\request_buffer_write_marker + 1 PokeByte (term\request_buffer, term\request_buffer_write_marker, char) End Function What is missing as it stands, is a way to theck if the buffer is full, and return -1 error code if so. I'm also looking at a way of removing the Floor command. Also, values > 9999999 won't be rendered properly into the buffer. Finally, the INT values are all to be positive, and that is part of the specs of the buffer. Here is how I initialize the buffer: term\request_buffer_write_marker = 0 term\request_buffer_max = 4096 term\request_buffer = CreateBank(term\request_buffer_max + 2) PokeByte (term\request_buffer, term\request_buffer_max, 48) ; end request_buffer with a useful 0 ascii value PokeByte (term\request_buffer, term\request_buffer_max + 1, 0) ; end request_buffer with a useful null value The buffer is part of a type, as such: Type my_buffer Field request_buffer% Field request_buffer_write_marker% Field request_buffer_instring_marker% Field request_buffer_max% Field request_buffer_tokencount% End Type |