There are some times in programming, particularly on the 2600, that you have to expend a lot of effort to achieve relatively little. The last few days working on the PoP kernel have been like this for me. Having now become convinced of the safety and benefits of the undocumented 6502 instructions, I decided to use them to improve the efficiency of my code. In particular, I wasn't happy with the self-modifying code used in the kernel. Although this code was working fine, it was taking 14 cycles per write, and there were 44 of these writes in the kernel, which adds up to a lot of cycles (616)! Also, these write instructions will only work on the Supercharger and this would make the code difficult to port to other cartridge formats. To remove the self-modifying code, it was necessary to use indirect addressing. I had previously tried this and failed, but this was before using undocumented instructions. I figured that the LAX instruction might help things out, since it allows the X register to be loaded in the indirect mode without costing any cycles. To cut a long story short, after several days of effort I was able to make it work. The result is a very convoluted kernel (always the best kind!) which uses indirect addressing and has no spare cycles in the main loop. This kernel will now work on a regular 2600 without Supercharger, and should be easy to port. However, from an external perspective, the kernel just looks exactly the same on the screen! I therefore made a few cosmetic changes, just to convince myself that I had actually achieved something. I have attached the new version (and code) to this entry. The main changes this time are:
- The doors are now drawn using PF graphics (instead of sprites). Although this means that they don't look so good, it will allow multiple doors on the same horizontal line, which I think will be important later. Also, it will simplify the collision detection process.
- The player now walks in front of the pillars. I was initially trying to copy the original, but this doesn't look good on the 2600 as the player was showing through the pillar in places.
- I have added a colour gradient to the platforms.
The cleanup process is not yet complete. I have removed the self-modifying code from the kernel, but have just replaced it with SLEEP instructions for now. I am not entirely sure what to put in place of this code yet, and I don't want to shrink the size of the platforms. I think the next step is to try and reduce the usage of the precious zero page memory in the kernel, but for now I am going to take a break!Chris