Langue…
19 utilisateurs en ligne: Ahrion, alvinluis, D1STYNCT, Dark Prince, Fausateeeee, Freitasth, George, GrenCarret, InalienableDreamless, isaix, MarsAmpere, ModernKiwi, Nanny_Skeksis, Saela, ShUriK KiD, Soul,  Thomas, Tio Ruffles, VecchiaZim - Invités: 91 - Robots: 183
Utilisateurs: 55 612 (2 437 actifs)
Dernier utilisateur: arsosa

$7F837D - Example how to use in ASM - Layer 3

  1. RAM address $7F837B (the length of the stripe data) should be used as an index of WHERE in $7F837D to avoid overwriting other stripe image data. Because this is a 16-bit indexing, we need the index to be 16-bit. Therefore:
    REP #$30			;>16-bit AXY
    LDA $7F837B ;>Index length of stripe image (to avoid overwriting previously used stripes)
    TAX ;>LDX $XXXXXX does not exist.
  2. Write out the 4-byte header data starting at $7F837D, using the index from step 1. Example:
    ;header data (4 bytes)
    LDA.w #%0000000001010000 ;>EHHHYXyy and yyyxxxxx becomes %yyyxxxxxEHHHYXyy
    STA $7F837D,x ;
    LDA.w #%0000010100000000 ;>DRllllll and LLLLLLLL becomes %LLLLLLLLDRllllll
    STA $7F837D+2,x ;

    ;Do note that when writing in 16-bit mode here, the values are little endian so the byte pairs are swapped.

    ;We are writing "012" tiles at the top-left corner, left-to-right so:
    ;EHHHYXyy and yyyxxxxx: (should be 01010000 00000000)
    ; EHHHYXyy
    ; E = end of data, should be 0
    ; HHH = layer, we need to have it on layer 3, so this must be %101
    ; YXyy = positions, because top-left is (0,0), all bits related to position should be 0.
    ; yyyxxxxx
    ; yyy = positions again, all zeroes
    ; xxxxx = same as above
    ;DRllllll and LLLLLLLL (should be 00000000 00001001)
    ; DRllllll
    ; D = direction, we are doing this horizontally, so 0.
    ; R = RLE. Since the tiles don't repeat, this is 0
    ; llllll = length (bits 8-13), as the number of bytes excluding the header. "012" is 3 tiles, and each tile is 2 bytes, TTTTTTTT and YXPCCCTT, so 3 tiles * 2 bytes per tile = 6, then -1, which is 5.
    ; LLLLLLLL
    ; LLLLLLLL = length (bits 0-7). We need to write 5 here, 5 is %101 in binary, so this entire byte should be %00000101



  3. Now we are dealing with tile data to write. In this example, we are writing "012" (3 tiles) into the stripe
    LDA #$3800			;\The 3 tiles, "012"
    STA $7F837D+4,x ;|3 tiles * 2 bytes per tile = 6 bytes
    LDA #$3801 ;|
    STA $7F837D+6,x ;|
    LDA #$3802 ;|
    STA $7F837D+8,x ;/

  4. Once all the tile data are written, we need to terminate, so write a single byte of $FF afterwards:
    SEP #$20			;>8-bit A
    LDA #$FF ;\Terminating byte (not counted in the length)
    STA $7F837D+10,x ;/

  5. And update the length of the stripe:
    REP #$21			;REP #$21 is 8-bit A with carry cleared
    TXA ;\Update length of stripe (6 bytes of tile data + 4 bytes of header = 10 bytes)
    ADC #$000A ;|
    STA $7F837B ;/
    SEP #$30 ;>8-bit AXY
    RTL ;>End (assuming this subroutine is called using a JSL)