Functions, debugging the code and the current state of business

Drawing a picture was as simple as placing the picture in the correct folder on the Brick and call the UI_DRAW BMPFILE function. But I’m not sure about the performance so I still wanted to try to open the file and draw the content through one of the other functions.

The file functions seemed to be straight forward enough. There was a FILE OPEN_READ, FILE READ_BYTES and FILE CLOSE. So I loaded the file into memory and tried using one of the other draw functions, but it didn’t work. For some reason nothing was shown on screen and I still don’t know why.

That also made it abundantly clear that I had no way of debugging my app.

Which led me to investigating a way to get information about what was going on in my apps. As a first attempt I figured I could write text to a log file.

I used the file functions to open a file, write data to the file and close it. I tried it on the brick and saw that a file was indeed created. Happiness! I transferred the file from the brick to my computer and opened it and it contained the string I had written to it. “Hello log”

And this was the code to do so:

vmthread MAIN
{
	DATA16 hLogFile
	FILE( OPEN_APPEND, 'log.txt', hLogFile )
	FILE( WRITE_TEXT, hLogFile, '', 'Hello log\n' )
	FILE( CLOSE, hLogFile )
}

I wanted to wrap the logging code in a function so I had to write my very first function in lms code.

Generally functions seems to be quite easy. You define a label and at the top of the function you define in and out parameters. This is where the problems started. I had a system function that accepted a parameter type (DATA8) which was holding a string. So I created a function that would accept a string and simply pass it on to the system function but when I accepted a DATA8 (as IN8) and passed it on to the system function only the first byte in the string was printed to the file.

So the system function accepts a DATA8 but I can see in the native code that it is type casted to a char pointer.

And that pretty much sums up my work so far. This is where I’m at right now. I have found a way to append a string to a file but I need to find a way to abstract it into a function. When I have this function it will be a lot easier for me to debug future code.

Leave a Reply