here you go:
This routine isnt mine so dont give me credit ! It was written by Dwedit over at the Maxcoderz forums
Code: ;Fastcopy + Horizontal + Vertical Scrolling Tilemap by Dwedit
;
;Input:
; de = plotsscreen
; (MapBase) = word,Base address of map
; (cameray) = word,vertical location of camera
; (camerax) = word,horizontal location of camera
; (tilesbase) = word,pointer to tileset
; tilesbuf = label,destructable tileset buffer equal in size to the tileset
; tilesbuf2 = label,another destructable tileset buffer, also equal in size to the tileset
; NUM_TILES = byte constant,number of tiles in the tileset (size of tileset/8)
; (mapwidth) = word,width of tilemap
;Output:
; screen copied from buffer to screen
; tilemap drawn on buffer, with origin (camerax,cameray)
;
;Needs modification, change where it multiplies hl by map width (currently fixed at 12)
FastCopyTilemap:
di
ld a,$80
out ($10),a;set row 0
push de
;Get new mapbase and x-tile scroll from camerax
ld hl,(camerax)
call DivBy8Common
ld bc,(MapBase)
add hl,bc
push hl
call MessUpTiles
;Now get yscroll and adjust basemap for cameray
ld hl,(cameray)
call DivBy8Common
ld (TM_ModYpos+1),a
;Multiply HL by map width here (needs modify)
add hl,hl
add hl,hl
ld b,h
ld c,l
add hl,hl
add hl,bc
pop bc
add hl,bc
push hl
;RenderTileModder:
add a,a
add a,a
ld c,a
add a,a
add a,c
ld b,0
ld c,a
ld hl,RenderTile
push hl
add hl,bc
ld (TM_Mod1+1),hl
pop hl
ld a,c
cpl
add a,97
ld c,a
add hl,bc
ld (TM_Mod2+1),hl
pop hl
pop de
xor a
TileMapLoop1:
push af
push hl \ push de;save base coordinates
add a,$20 ;$20 + C = set column
out ($10),a;set column
;Draw top tile (clipped)
push hl
ld bc,TilesBuf2
ld a,(hl)
inc hl
ld l,(hl)
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,bc
push hl
pop ix
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld bc,TilesBuf
add hl,bc
TM_ModYpos:
ld bc,0000
add hl,bc
add ix,bc
ex de,hl
ld bc,12
TM_Mod1:
call 0
pop hl
ld bc,(mapwidth)
add hl,bc;advance tile pointer by map's width
;Draw next 7 tiles
ld b,7 ;8 tiles per column
TileMapLoop2:
push bc
push hl ;save position on map
ld bc,tilesBuf2
ld a,(hl)
inc hl
ld l,(hl)
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,bc
push hl
pop ix
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld bc,tilesBuf
add hl,bc
ex de,hl
ld bc,12
call RenderTile
pop hl
ld bc,(mapwidth)
add hl,bc;advance tile pointer by map's width
pop bc
djnz TileMapLoop2
;Draw bottom tile (clipped)
ld bc,tilesBuf2
ld a,(hl)
inc hl
ld l,(hl)
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,bc
push hl
pop ix
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld bc,tilesBuf
add hl,bc
ex de,hl
ld bc,12
TM_Mod2:
call 0
DontRenderLastTile:
pop de \ pop hl;back to the top
inc hl \ inc de;next column for map and screen
pop af
inc a;next column
; ld a,c
cp 12;stop after 12 columns (maybe replace this if you need a smaller map)
jp c,TileMapLoop1
ret;Done
RenderTile:
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ld a,(hl) ;Write old byte to LCD
out ($11),a
ld a,(de) ;read graphics data
or (ix+0)
ld (hl),a
inc de
inc ix
add hl,bc
ex de,hl
ret
DivBy8Common:
ld a,l
sra h
rra
sra h
rra
sra h
rra
ld c,l
ld l,a
ld a,c
and 7
ret
MessUpTiles:;input: a=x pixel position
cpl
add a,8
MessUpTiles2:
ld (MessUpTilesModify+1),a
ld hl,InvertedMaskTable
ld b,0
ld c,a
add hl,bc
ld a,(hl)
ld (MessUpTilesMask1+1),a
cpl
ld (MessUpTilesMask2+1),a
ld hl,(Tilesbase)
ld de,TilesBuf
ld ix,TilesBuf2
ld bc,8*NUM_TILES
MessUpTilesLoop:
ld a,(hl)
MessUpTilesModify:
jr $+2
rlca
rlca
rlca
rlca
rlca
rlca
rlca
ld (de),a
MessUpTilesMask2:
and 0
ld (ix+0),a
ld a,(de)
MessUpTilesMask1:
and 0
ld (de),a
inc de
inc ix
cpi
jp pe,MessUpTilesLoop
ret
InvertedMaskTable:;stick this wherever you like
.db %10000000
.db %11000000
.db %11100000
.db %11110000
.db %11111000
.db %11111100
.db %11111110
.db %11111111
|