;export _draw_tile
;export _draw_image
;export _select_image
;export _draw_tile_key
;export _color_key
macro MDrawTile
ld bc,-16384+40
dup 8
ld a,(de) ;#4xxx
ld (hl),a
inc e
set 5,h
ld a,(de) ;#6xxx
ld (hl),a
inc e
set 7,h
res 6,h
ld a,(de) ;#axxx
ld (hl),a
inc e
res 5,h
ld a,(de) ;#8xxx
ld (hl),a
inc e
add hl,bc
edup
org $-2
endm
macro MDrawTileGetAddrs
ld hl,(tileOffset)
add hl,de
ex de,hl
ld h,high scrTable
ld l,b
ld a,c
add a,(hl)
set 5,l
ld h,(hl)
ld l,a
ld a,d
srl a
add a,low GFX_PAGE
;ld bc,MEM_SLOT0
;cpl
;out (c),a
call setpgc000;SETPG32KHIGH
ld a,e
rrca
rrca
rrca
ld e,a
and 31
bit 0,d
jr z,$+4
or #20
or 0xc0
ld d,a
ld a,e
and #e0
ld e,a
endm
macro MCopyTileColumnFromBuf
ld bc,40
dup 8
ld a,(de)
ld (hl),a
inc e
add hl,bc
edup
endm
macro MCopyTileColumnToBuf
ld bc,40
dup 8
ld a,(hl)
ld (de),a
inc e
add hl,bc
edup
endm
;ъюяшЁютрэшх Єрщыр шч Єхэхтюую ¤ъЁрэр т сєЇхЁ ёяЁрщЄют
;d=x,e=y
updateOneTileToBuffer
exa
push de
ld a,d ;яюыєўшЄ№ шч de рфЁхё т ¤ъЁрэх
ld h,high scrTable
ld l,e
add a,(hl)
set 5,l
ld h,(hl)
ld l,a
ld a,e ;sla e
add a,a ;sla e
add a,a
add a,a
ld e,a ;sla e
ld a,d
or 0xc0
ld d,a
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE0
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnToBuf ;ёЄюысхЎ 0
org $-2
ld a,e
sub 7
ld e,a
ld bc,-7*40+16384
add hl,bc
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE1
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnToBuf ;ёЄюысхЎ 1
org $-2
ld a,e
sub 7
ld e,a
ld bc,-(7*40+8192)
add hl,bc
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE2
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnToBuf ;ёЄюысхЎ 2
org $-2
ld a,e
sub 7
ld e,a
ld bc,-7*40+16384
add hl,bc
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE3
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnToBuf ;ёЄюысхЎ 3
org $-2
pop de
exa
ret
;ъюяшЁютрэшх Єрщыр шч сєЇхЁр ёяЁрщЄр эр Єхэхтющ ¤ъЁрэ
;d=x,e=y
updateOneTileFromBuffer
exa
push de
ld a,d ;яюыєўшЄ№ шч de рфЁхё т ¤ъЁрэх
ld h,high scrTable
ld l,e
add a,(hl)
set 5,l
ld h,(hl)
ld l,a
ld a,e ;sla e
add a,a ;sla e
add a,a
add a,a
ld e,a ;sla e
ld a,d
or 0xc0
ld d,a
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE0
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnFromBuf ;ёЄюысхЎ 0
org $-2
ld a,e
sub 7
ld e,a
ld bc,-7*40+16384
add hl,bc
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE1
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnFromBuf ;ёЄюысхЎ 1
org $-2
ld a,e
sub 7
ld e,a
ld bc,-(7*40+8192)
add hl,bc
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE2
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnFromBuf ;ёЄюысхЎ 2
org $-2
ld a,e
sub 7
ld e,a
ld bc,-7*40+16384
add hl,bc
;ld bc,MEM_SLOT0
ld a,SPBUF_PAGE3
;out (c),a
call setpgc000;SETPG32KHIGH
MCopyTileColumnFromBuf ;ёЄюысхЎ 3
org $-2
pop de
exa
ret
updateTilesToBuffer
ld a,(tileUpdate)
or a
ret z
ld hl,tileUpdateMap
ld e,0 ;y
.clearUpdMap0
ld d,0 ;x
.clearUpdMap1
ld a,(hl)
or a
jr nz,.rowChange
ld a,d
add a,8
ld d,a
jp .noRowChange
.rowChange
push hl
dup 8
rra
call c,updateOneTileToBuffer
inc d
edup
pop hl
ld a,d
.noRowChange
inc l
cp 40
jp nz,.clearUpdMap1
inc l
inc l
inc l
inc e
ld a,e
cp 25
jp nz,.clearUpdMap0
ret
updateTilesFromBuffer
ld hl,tileUpdate ;ld a,(tileUpdate)
xor a
cp (hl) ;or a
ret z
;xor a
ld (hl),a ;ld (tileUpdate),a
ld hl,tileUpdateMap
ld e,a;0 ;y
.clearUpdMap0
ld d,0 ;x
.clearUpdMap1
ld a,(hl)
or a
jr nz,.rowChange
ld a,d
add a,8
ld d,a
jp .noRowChange
.rowChange
push hl
dup 8
rra
call c,updateOneTileFromBuffer
inc d
edup
pop hl
ld (hl),0
ld a,d
.noRowChange
inc l
cp 40
jp nz,.clearUpdMap1
inc l
inc l
inc l
inc e
ld a,e
cp 25
jp nz,.clearUpdMap0
ret
;т√сюЁ шчюсЁрцхэш фы юЄЁшёютъш Єрщыют
_select_image
ld h,0
add hl,hl
add hl,hl
ld bc,IMG_LIST
add hl,bc
;ld bc,MEM_SLOT0
ld a,PAL_PAGE
;out (c),a
call setpgc000;SETPG32KHIGH
ld e,(hl) ;tile
inc l
ld d,(hl)
;set 7,d
;set 6,d
ld (tileOffset),de
ld a,CC_PAGE3;0
;out (c),a
call setpgc000;SETPG32KHIGH
ret
;єёЄрэютър Їырур юсэютыхэш Єрщыр
;c=X, b=y, эх ьхэ хЄ bc ш de
setTileUpdateMapF
ld (tileUpdate),a ;A тёхуфр эх 0 эр тїюфх
setTileUpdateMap
ld h,high tileUpdateXTable
ld l,c
ld a,(hl)
set 6,l
exa
ld a,b
add a,a
add a,a
add a,a
add a,(hl)
ld l,a
ld h,high tileUpdateMap
exa
or (hl)
ld (hl),a
ret
;c=X, b=Y, de=tile
;ъююЁфшэрЄ√ т Єрщырї
_draw_tile
;---------------
ld a,(curpg8000) ;ok ;(_memSlot2)
push af
;---------------
ld a,(spritesActive)
or a
call nz,setTileUpdateMapF
MDrawTileGetAddrs
MSetShadowScreen
MDrawTile
MRestoreMemMap012 ;TODO тюёёЄрэртыштрЄ№ ёЄЁрэшЎ√, с√т°шх фю т√чютр
;-----------------
pop af ;ўЄюс√ эх фхырЄ№ ¤Єю
SETPG8000
;ld (_memSlot2),a
;ld bc,MEM_SLOT2
;out (c),a
;-----------------
ret
;єёЄрэютър яЁючЁрўэюую ЎтхЄр фы draw_tile_key
_color_key
ld b,high colorMaskTable
ld a,(bc)
ld (_draw_tile_key.keyAB0),a
ld (_draw_tile_key.keyAB1),a
ld (_draw_tile_key.keyAB2),a
ld (_draw_tile_key.keyAB3),a
set 4,c
ld a,(bc)
ld (_draw_tile_key.keyA0),a
ld (_draw_tile_key.keyA1),a
ld (_draw_tile_key.keyA2),a
ld (_draw_tile_key.keyA3),a
set 5,c
ld a,(bc)
ld (_draw_tile_key.keyB0),a
ld (_draw_tile_key.keyB1),a
ld (_draw_tile_key.keyB2),a
ld (_draw_tile_key.keyB3),a
ret
;юЄЁшёютър Єрщыр ё яЁючЁрўэ√ьш яшъёхы ьш
;c=X, b=Y, de=tile
;ъююЁфшэрЄ√ т Єрщырї
_draw_tile_key
;---------------
ld a,(curpg8000) ;ok ;(_memSlot2)
push af
;---------------
ld a,(spritesActive)
or a
call nz,setTileUpdateMapF
MDrawTileGetAddrs
MSetShadowScreen
ld a,8
.loop
exa
.column0
ld a,(de)
.keyAB0=$+1
cp 0
jr z,.column0done
and %01000111
.keyA0=$+1
cp 0
jr z,.skipA0
ld c,a
ld a,(hl)
and %10111000
or c
ld (hl),a
.skipA0
ld a,(de)
and %10111000
.keyB0=$+1
cp 0
jr z,.column0done
ld c,a
ld a,(hl)
and %01000111
or c
ld (hl),a
.column0done
inc e
set 5,h
.column1
ld a,(de)
.keyAB1=$+1
cp 0
jr z,.column1done
and %01000111
.keyA1=$+1
cp 0
jr z,.skipA1
ld c,a
ld a,(hl)
and %10111000
or c
ld (hl),a
.skipA1
ld a,(de)
and %10111000
.keyB1=$+1
cp 0
jr z,.column1done
ld c,a
ld a,(hl)
and %01000111
or c
ld (hl),a
.column1done
inc e
res 6,h
set 7,h
.column2
ld a,(de)
.keyAB2=$+1
cp 0
jr z,.column2done
and %01000111
.keyA2=$+1
cp 0
jr z,.skipA2
ld c,a
ld a,(hl)
and %10111000
or c
ld (hl),a
.skipA2
ld a,(de)
and %10111000
.keyB2=$+1
cp 0
jr z,.column2done
ld c,a
ld a,(hl)
and %01000111
or c
ld (hl),a
.column2done
inc e
res 5,h
.column3
ld a,(de)
.keyAB3=$+1
cp 0
jr z,.column3done
and %01000111
.keyA3=$+1
cp 0
jr z,.skipA3
ld c,a
ld a,(hl)
and %10111000
or c
ld (hl),a
.skipA3
ld a,(de)
and %10111000
.keyB3=$+1
cp 0
jr z,.column3done
ld c,a
ld a,(hl)
and %01000111
or c
ld (hl),a
.column3done
inc e
ld bc,-16384+40
add hl,bc
exa
dec a
jp nz,.loop
MRestoreMemMap012
;-----------------
pop af
SETPG8000
;ld (_memSlot2),a
;ld bc,MEM_SLOT2
;out (c),a
;-----------------
ret
;юЄЁшёютър шчюсЁрцхэш Ўхышъюь
;¤Єр яЁюЎхфєЁр с√ёЄЁхх, ўхь т√тюф юЄфхы№э√ї Єрщыют
;a=id, c=X, b=Y
;яЁш cy=1:
;d=begx, e=width
_draw_image
ld l,a
ld a,(curpg8000) ;ok ;(_memSlot2)
push af
;-------------------------
push bc
push af
ld h,0
;ld l,a
add hl,hl
add hl,hl
ld bc,IMG_LIST
add hl,bc
;ld bc,MEM_SLOT0
ld a,PAL_PAGE
;out (c),a
call setpgc000;SETPG32KHIGH
pop af
jr nc,_draw_image_noextra
ld c,e ;width
ld a,d ;begx
add a,(hl) ;tileLSB
ld e,a
inc l
adc a,(hl) ;tileHSB
sub e
ld d,a
inc l
ld a,(hl) ;width
inc l
ld b,(hl) ;height
ld l,a
jp _draw_image_noextraq
_draw_image_noextra
ld e,(hl) ;tile
inc l
ld d,(hl)
inc l
ld c,(hl) ;width
inc l
ld b,(hl) ;height
ld l,c
_draw_image_noextraq
ld h,0
ld (.wdt),hl
pop hl
ld a,l
cp 40
jp nc,.done
ld a,h
cp 25
jp nc,.done
ld a,c
add a,l
cp 40
jr c,.noHClip
ld a,40
sub l
ld c,a
.noHClip
ld a,c
or a
jp z,.done
ld a,b
add a,h
cp 25
jr c,.noVClip
ld a,25
sub h
ld b,a
.noVClip
ld a,b
or a
jp z,.done
push bc
call setShadowScreen
pop bc
push bc ;ЁрчьхЁ
push hl ;ъююЁфшэрЄ√
ld a,l
ld l,h
ld h,high scrTable
add a,(hl)
set 5,l
ld h,(hl)
ld l,a
.loopv
push bc
push hl
push de
ld a,c
exa
ld a,d
srl a
add a,low GFX_PAGE
ld (.page),a
;ld bc,MEM_SLOT0
;out (c),a
call setpgc000;SETPG32KHIGH
ld a,e
rrca
rrca
rrca
ld e,a
and 31
bit 0,d
jr z,$+4
or #20
or 0xc0
ld d,a
ld a,e
and #e0
ld e,a
exa
.looph
exa
MDrawTile
inc e
jr nz,.noPageChange
inc d
;bit 6,d
;jr z,.noPageChange
;res 6,d
jr nz,.noPageChange
ld a,d
or 0xc0
ld d,a
.page=$+1
ld a,0
inc a;dec a
;ld bc,MEM_SLOT0
;out (c),a
ld (.page),a
call setpgc000;SETPG32KHIGH
.noPageChange
ld bc,-(16384+7*40-1)
add hl,bc
exa
dec a
jp nz,.looph
pop de
.wdt=$+1
ld hl,0
add hl,de
ex de,hl
pop hl
ld bc,8*40
add hl,bc
pop bc
dec b
jp nz,.loopv
;ld bc,MEM_SLOT1
ld a,CC_PAGE1
;ld (_memSlot1),a
;out (c),a
call setpg4000;SETPG16K
;ld b,high MEM_SLOT2
ld a,CC_PAGE2
;ld (_memSlot2),a
;out (c),a
call setpg8000;SETPG32KLOW
pop bc ;ъююЁфшэрЄ√ эрўрыр шчюсЁрцхэш B=y C=x
pop hl ;ЁрчьхЁ√ т√тюфшьющ ўрёЄш
;хёыш ёяЁрщЄ√ ЁрчЁх°хэ√, яюьхўрхь т√тхфхээ√х Єрщы√ т ърЁЄх шчьхэшт°шїё Єрщыют
ld a,(spritesActive)
or a
jr z,.done
ld (tileUpdate),a
.setUpd1
push bc
push hl
.setUpd2
push hl
call setTileUpdateMap
pop hl
inc c
dec l
jp nz,.setUpd2
pop hl
pop bc
inc b
dec h
jp nz,.setUpd1
.done
;ld bc,MEM_SLOT0
ld a,CC_PAGE3;0
;out (c),a
call setpgc000;SETPG32KHIGH
;----------------
pop af
SETPG8000
;ld (_memSlot2),a
;ld bc,MEM_SLOT2
;out (c),a
;----------------
ret