llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler
https://www.llvm-mos.org
Other
266 stars 53 forks source link

Add additional VRAM buffer operations #208

Closed cogwheel closed 11 months ago

cogwheel commented 11 months ago

This restructures the multivram* headers to use a byte for the opcode rather than overloading with the upper byte of the VRAM address. This makes it possible to add many more types of operations to the VRAM buffer.

This involved some high level restructuring of the APIs:

The range of operations now supported by the vram buffer include:

Each of these has helpers for the different directions and also some low level versions to aid composability. For example:

mysterymath commented 11 months ago

Looking broadly at this, I don't think it's a good idea to do any major surgery to nesdoug. These are dougeff's example libraries, ported to llvm-mos for the purpose of allowing the nesdoug tutorial series (in its entirety) to function on llvm-mos with a minimum of alterations. If we want to build out a really solid standard library for NES development on llvm-mos, that's cool, but it should probably be broken out separately as a new NES stdlib, rather than backwards incompatibly changing these pseudo-historical ones, particularly if they bear someone's name.

cogwheel commented 11 months ago

FWIW, the only potentially breaking change here is that multi_vram_buffer takes an extra byte of storage. But in my experience, if you have enough operations to risk filling the buffer, then the NMI routine would take longer than VBLANK anyway. Also, in the original CC65 version, the VRAM_BUF shares space with the software stack. So as long as you're following CC65 "best practices" of using ZP globals for arguments/returns, the total VRAM buffer capacity is nearly a page, compared to the half-page in llvm-mos.

So I'm wondering how you'd feel about a change similar to the first commit on this branch, but without all the noise about supporting more operations. It would just be a straight performance improvement.

mysterymath commented 11 months ago

Performance work like that seems fine; I've already had to do a fair bit a lot of internal rearranging to make it work with llvm-mos's assembler.