Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gfx_ScaledSprite_NoClip_Fast:
- ; Draws a 160x120 sprite scaled 2x to 320x240 at (0,0)
- ; Optimized for speed.
- push ix ; Preserve IX
- ld iy, 0
- add iy, sp
- ; --- Setup Source and Destination ---
- ld hl, (iy + 6) ; Get sprite pointer (Arg0)
- inc hl ; Skip width byte
- inc hl ; Skip height byte
- ld de, (CurrentBuffer) ; DE = Top-left of screen (X=0, Y=0)
- ; We use IXL as our row counter (120 rows)
- ld a, 120
- ld ixl, a
- NcSprRowLoop:
- ; --- Horizontal Scale (160 -> 320 pixels) ---
- ; We process 160 pixels. Unrolled 4x to reduce branch overhead.
- ld b, 40 ; 40 * 4 = 160 pixels
- NcSprPixelLoop:
- repeat 4
- ld a, (hl) ; Load 1 pixel
- inc hl ; Next source pixel
- ld (de), a ; Write pixel once
- inc de
- ld (de), a ; Write pixel twice
- inc de
- end repeat
- djnz NcSprPixelLoop
- ; --- Vertical Scale (Line Copy) ---
- ; At this point, HL is at the start of the NEXT sprite row.
- ; DE is at the start of the NEXT screen row.
- ; We need to copy the 320 bytes we just wrote to the current screen row.
- push hl ; Save sprite pointer
- ; Source for copy = Current DE - 320 bytes
- push de
- pop hl
- ld bc, 320
- or a
- sbc hl, bc ; HL = Start of the line we just finished
- ; Destination = DE (Start of the next line)
- ; Count = 320
- ld bc, 320
- ldir ; High-speed copy of the entire line
- ; After LDIR, DE is now at the start of the 3rd row (ready for next loop)
- pop hl ; Restore sprite pointer
- dec ixl
- jr nz, NcSprRowLoop
- pop ix ; Restore IX
- ret
Advertisement
Add Comment
Please, Sign In to add comment