[img] Joining ROM images together
MDFS::Info.Comp.BBC.SROMs.JoinROM/htm Search

Many ROMs programs do not use the full 8K or 16K of the ROM, and have spare space in them. You can use this spare space to add extra ROM code. This is fairly easy to do as long as no more than one component of a multi-code ROM claims memory or provides a language. The simplest method is to add purely service code to an existing ROM.

To do this, you need the image of the ROM you are adding to, and the source code (or a method of relocating the image) for the ROM code you want to add. This is done by changing the destination of the service call entry at &8003 to the start of the spare space at the end of the ROM. At the start of this spare space, the new code firstly calls the old service handler, and then continues with the new code's service handler:

8003   JMP SERV              -> 8003   JMP MYCODE
...
SERV   \ Service handler
...
                                MYCODE JSR SERV
                                ...    \ My service handler
The additional code can even be a relocated ROM image with the language entry point in the first three bytes changed to the JSR SERV instruction. The following instruction will then be the relocated jump to the additional service handler.

Any number of ROM code fragments can be joined together like this. However, as each fragment is independent of each other, only one can claim workspace and use the workspace byte at &DF0+rom, and only one can be a language and be entered at &8000. To be entered as a language, the entry at &8000 should be changed to jump to the ROM code fragment's entry point:

8000   BRK:BRK:BRK           -> 8000   JMP MYLANG
8003   JMP SERV              -> 8003   JMP MYCODE
...
SERV   \ Service handler     -> SERV
...
                                MYCODE JSR SERV
                                ...    \ My service handler
                                MYLANG \ My language startup
ROMMouse shows how to add extra ROM code by adding a mouse driver to a ROM image.
Best viewed with Any Browser Valid HTML 4.0!