Guest User

Untitled

a guest
Jan 20th, 2026
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. gfx_ScaledSprite_NoClip_Fast:
  2. ; Draws a 160x120 sprite scaled 2x to 320x240 at (0,0)
  3. ; Optimized for speed.
  4.     push ix                 ; Preserve IX
  5.     ld   iy, 0
  6.     add  iy, sp
  7.    
  8.     ; --- Setup Source and Destination ---
  9.     ld   hl, (iy + 6)       ; Get sprite pointer (Arg0)
  10.     inc  hl                 ; Skip width byte
  11.     inc  hl                 ; Skip height byte
  12.    
  13.     ld   de, (CurrentBuffer) ; DE = Top-left of screen (X=0, Y=0)
  14.    
  15.     ; We use IXL as our row counter (120 rows)
  16.     ld   a, 120
  17.     ld   ixl, a
  18.  
  19. NcSprRowLoop:
  20.     ; --- Horizontal Scale (160 -> 320 pixels) ---
  21.     ; We process 160 pixels. Unrolled 4x to reduce branch overhead.
  22.     ld   b, 40              ; 40 * 4 = 160 pixels
  23. NcSprPixelLoop:
  24.     repeat 4
  25.         ld   a, (hl)        ; Load 1 pixel
  26.         inc  hl             ; Next source pixel
  27.         ld   (de), a        ; Write pixel once
  28.         inc  de
  29.         ld   (de), a        ; Write pixel twice
  30.         inc  de
  31.     end repeat
  32.     djnz NcSprPixelLoop
  33.  
  34.     ; --- Vertical Scale (Line Copy) ---
  35.     ; At this point, HL is at the start of the NEXT sprite row.
  36.     ; DE is at the start of the NEXT screen row.
  37.     ; We need to copy the 320 bytes we just wrote to the current screen row.
  38.    
  39.     push hl                 ; Save sprite pointer
  40.    
  41.     ; Source for copy = Current DE - 320 bytes
  42.     push de
  43.     pop  hl                
  44.     ld   bc, 320
  45.     or   a
  46.     sbc  hl, bc             ; HL = Start of the line we just finished
  47.    
  48.     ; Destination = DE (Start of the next line)
  49.     ; Count = 320
  50.     ld   bc, 320
  51.     ldir                    ; High-speed copy of the entire line
  52.    
  53.     ; After LDIR, DE is now at the start of the 3rd row (ready for next loop)
  54.     pop  hl                 ; Restore sprite pointer
  55.    
  56.     dec  ixl
  57.     jr   nz, NcSprRowLoop
  58.  
  59.     pop  ix                 ; Restore IX
  60.     ret
Advertisement
Add Comment
Please, Sign In to add comment