Jump to content
IGNORED

Compact assembler loop for loading data: is address -1 ok?


lucienEn

Recommended Posts

Hi,

 

I noticed a lot of sample code (including generated code from 2600 builder) ignores the first byte of the data since they use bne to exit the loop. Or instead they wait for 0 in the data block but that's unpredictable length and wastes 1 byte. I found I could just use the start address -1. It works fine so far but any downsides with this below (or use bmi but that's limited to 127 height):

 

    ldx #10
Kernel1_Loop
    sta WSYNC
    sta HMOVE
    lda colubk_data-1, x      ; this will load data in range colubk_data .. colubk_data+9
    sta COLUBK
    dex
    bne Kernel1_Loop

 

Lucien

Edited by lucienEn
Link to comment
Share on other sites

19 hours ago, splendidnut said:

Since this is being used in a display kernel, don't forget to watch out for page-crossing issues (extra cycle penalty throwing off timing).

I wonder how this syntax works looking at 2600 builder:

 

   if >. != >[.+(playfield_lines)]
      align 256
   endif
 

So maybe the '>' looks at the high byte and compares that to high byte of the playfield lines? What is the [.+?...] meaning?

Link to comment
Share on other sites

Here are the meanings behind the symbols:

'>' says look at the high byte

'.' is the current address in the assembly file

'[ ]' work just like parenthesis... they give an alternative due to 6502 assembly typically using ( ) to imply indirect addressing mode when used in an instruction.

'[.+(playfield_lines)]'  is current address '.' + 'playfield_lines' label address or EQU value 

 

I believe I got everything correct, please let me know if I messed up anything.

 

Looking at the example code, it's not entirely clear what playfield_lines refers to.  If I had to take a guess, 'playfield_lines' refers to the number of lines in (size of) the data table that immediately follows the if...endif construct.

 

If that is true:

   - The example code would make sure the table is within a page... and if it crosses a page boundary, it would align it to the next one (force it to start at the beginning of the next one).

   - You would still need to handle the case of -1... easiest thing would be to put a byte of padding right before the data table (after the if..endif construct)

  • Thanks 1
Link to comment
Share on other sites

Thanks! Yes that code comes from the 2600 builder web site. I want to use that construct as well for my auto-code generation.

 

Downside is that it might waste a lot of bytes but I think auto-code could adjust for that and group them better.

Edited by lucienEn
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...