This program displays an image which is then slowly replaced using a cool transition effect. We do this by creating an array of 0-3999, randomising it and then use this random order to replace the screen bytes with the bytes from another image.
You can download the source using the link below, the actual .app is not included as you will need to specify two image files for the program to use (lines 64 and 67). Once this is done, just run or double click on make.bat to create the pictran.app file.
The Cybiko SDK
Two Cybiko .pic files which are 160x100 (4008 bytes each)
Note: Don't type in the line numbers!
Line(s) | |
---|---|
5-6 | The standard Cybiko include and main module required by most Cybiko programs. |
8 | We are going to be using files so we need this system struct to hold the file details. |
10-26 | As we are loading two images later, it is best to put the could into a function we can re-use. If we can open the file, we skip the first 8 bytes and copy the remaining 4000 (which is the actual raw image) to the area of memory pointed to by the 'dest' variable. |
30-34 | Variable we will need. *pic and *dis are pointers to the hidden picture and the actual display. *order points to the list of bytes that get replaced. |
36 | Initialises the main_module struct (I guess). Another 'needed by most Cybiko programs' line. |
38 | Set the display pointer 'dis' to point to the start of the display data. |
40 | Allocated space for our hidden picture. This is pointed to by 'pic'. |
41 | This allocated the 4000 integers we will need. In most 'c' programs for other systems, we would just use a large array (e.g. int order[4000];) but the Cybiko sdk does not like large amounts of memory being allocated like that, so we use malloc or calloc instead. We must remember to free() these when we are done though, this gives the memory back to the system. |
43 | If pic or order equal zero, it means we were not able to allocate the memory needed. If this is the case we give an error message and end. |
47-50 | This fills the order array with the values 0-3999. We will change the order of these values so that when we display the new image, it appears by a random pattern. |
52-60 | This randomises the order array. It picks two values at random and then swaps them. We will read through this array and use the values to determine which bytes to replace |
64-65 | Using our 'loadpic' function, we load the image to the display memory and then show it. Make sure this image file is one that is on your Cybiko's flash memory. |
67 | This loads our other image into the memory block we allocated earlier. This also needs to be an image on your Cybiko's flash. |
69-74 | To show the new image, we read through the order array and use the value to replace the pixel blocks. Each image byte holds the bits for four pixels. We call the show function to update the display after each change. |
83-84 | Before exiting, we free the memory we allocated at the start. Very important and also very easy to forget... |
Updated 20/04/2024