stardot / beebasm

A portable 6502 assembler with BBC Micro style syntax
http://www.retrosoftware.co.uk/wiki/index.php/BeebAsm
GNU General Public License v3.0
84 stars 26 forks source link

add jump_table_at_end.6502 #61

Closed JulieMontoya closed 3 years ago

JulieMontoya commented 3 years ago

This adds a code example showing how to use the ALIGN and CLEAR directives to position some code such as a jump table just before a page boundary. The intended use case is a machine code program with several entry points that sits above HIMEM and is called from a BASIC program.

mungre commented 3 years ago

Excellent, it did work. (I'm ctr in the other place.)

The documentation is an added bonus.

One possible improvement: where you wrote "as long as we subtracted the right number of bytes" you could ASSERT this instead. After the ALIGN save the value of P%; after the jump table ASSERT that P% equals the saved value. You already handle allocating too few bytes with the GUARD and this would also handle allocating too many bytes.

Any changes you push to your fork should automatically appear on this pull request.

JulieMontoya commented 3 years ago

On Thu, 29 Jul 2021 at 16:46, mungre @.***> wrote:

Excellent, it did work. (I'm ctr in the other place.)

The documentation is an added bonus.

One possible improvement: where you wrote "as long as we subtracted the right number of bytes" you could ASSERT this instead. After the ALIGN save the value of P%; after the jump table ASSERT that P% equals the saved value. You already handle allocating too few bytes with the GUARD and this would also handle allocating too many bytes.

I've never used ASSERT before, but it looks as though it takes a Boolean value and stops with an error if it is false. So ASSERT ((P% MOD 256) = 0) in BeebAsm would work something like $(($P % 256 == 0)) || (echo "Assertion failed" >&2; exit 1) in Bash, and stop with an error if it fell shy of the page boundary?

I can actually think of a good reason not to, though. Early in the development cycle, it might be worthwhile leaving a bit of slack space for things you know you will have to implement anyway, but you want to get something tested first. Only the sort of person who always used to press STOP on a cassette player when going from PLAY to REWIND, or writes out every line of code on squared paper with a propelling pencil before opening up a text editor, would ever think to put in dummy entries for all of them, in advance; all pointing to the same RTS instruction, until each individual subroutine is written!

Still, I'll test it works as I think, and insert it (or whatever I end up having to change it to, to make it work). It will make the example code more complete, which can only be a good thing; and it's easy enough for anyone to comment out if they do not want it -- or uncomment it again for release.

Any changes you push to your fork should automatically appear on this pull request.

Yeah, I'm beginning to get git now. I'd only ever used GitHub like a kind of glorified PasteBin. I knew it was capable of more; I just didn't properly appreciate how much more. It absolutely fits my existing development mode, with a text editor and terminal; I can edit a file using my favourite editor, and publish it with a simple shell command -- no need to break my flow uploading files via a web app.

Now I'm using github "properly" for AdveBuilder, I plan to put together at least one more mini-game; then I will be able to revamp my BCP repository completely, and even put up nightly builds without breaking my flow to upload files via a web app.

mungre commented 3 years ago

Thank you, I've merged it.