Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Draw a VWF character on the screen.
  2. //
  3. // INPUT    :  A -> Character code
  4. //
  5. // REQUIRES :  P(8A/16XY)
  6. // MODIFIES :  P, A, X, Y
  7. //
  8. renderVwf:
  9.     sta {vwfChar}    // Save the character code.
  10.  
  11.     lda {vwfShift}   // A = Bits already drawn in the tile
  12.     and #$07         // A %= 8
  13.     bne +            // Jump if there is still room in the tile.
  14.  
  15.     jsr nextTile     // Go the next tile in VRAM.
  16.     jsr clearBuffer  // Clear the VWF buffer.
  17.  
  18.     //       vwfShift2 = vwfShift * 2
  19.     // (Required for indexing the jump table)
  20.     +; lda {vwfShift}; asl; sta {vwfShift2}
  21.     lda {vwfChar}  // Reload the char code.
  22.     jsr charIndex  // X = Index of the char in the font
  23.     ldy #$0000     // Y = Index in the VWF buffer
  24.    
  25.     // Draw the character:
  26.     .lsr:
  27.         lda.l font, x      // Load a byte of the char.
  28.         // Shift the pixels to the right:
  29.         phx; ldx {vwfShift2}
  30.         jsr (shiftRight.table, x); plx
  31.         // Draw the result in the tile:
  32.         ora {vwfBuffer}, y
  33.         sta {vwfBuffer}, y
  34.         // Loop until the end of the char:
  35.         inx; iny
  36.         cpy #$0010
  37.         bne .lsr
  38.  
  39.     ldx {vwfChar}             // X = Char code
  40.     lda.l font.widthTable, x  // A = Width of the char
  41.     // Verify if there was overflow:
  42.     clc; adc {vwfShift}
  43.     cmp #$08
  44.     and #$07
  45.     sta {vwfShift}  // Save the new shift value.
  46.     // (A <= 8) --> No overflow, exit:
  47.     bcc .exit; beq .exit
  48.  
  49.     phx; jsr sendVwfBuffer; plx  // Send the tile to VRAM.
  50.     lda.l font.widthTable, x     // A = Width of the char
  51.     // Calculate the number of left shifts to draw overflow:
  52.     sec; sbc {vwfShift}; asl
  53.     sta {vwfShift2}
  54.     txa; jsr charIndex  // X = Index of the char in the font
  55.     ldy #$0000
  56.     // Draw the second part of the character:
  57.     .asl:
  58.         lda.l font, x  // Load a byte of the char.
  59.         // Shift the pixels to the left:
  60.         phx; ldx {vwfShift2}
  61.         jsr (shiftLeft.table, x); plx
  62.         sta {vwfBuffer}, y  // Write the result to the buffer.
  63.         // Loop until the end of the char:
  64.         inx; iny
  65.         cpy #$0010
  66.         bne .asl
  67.     // Select the next tile in VRAM:
  68.     jsr nextTile
  69.  
  70.     .exit:
  71.         jsr sendVwfBuffer  // Write the tile in VRAM.
  72.         // Write the tile in the tilemap:
  73.         stz $2115  
  74.         ldx {tileMapPtr}
  75.         stx $2116
  76.         lda {vramPtr}
  77.         lsr; lsr; lsr
  78.         // Wait for VBlank before writing in VRAM:
  79.         pha
  80.         .waitVBlank:
  81.             lda $4212
  82.             bpl .waitVBlank
  83.         pla
  84.         sta $2118  // Do the write.
  85.  
  86.         rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement