Skip to content

Commit d321102

Browse files
committed
feat(gfx): boot-synthesized dither transition tiles (phase 4)
LoadTiles now synthesizes 8 transition tiles (125-133) at boot: 4x4 Bayer-dither pixel mixes of deep/shallow, shallow/sand, and sand/grass parent pairs at 25/50/75 ratios. DecorateTile maps narrow elevation bands around each terrain threshold to them, so coastlines and biome edges blend instead of stepping at tile granularity. Render-only like the variants; TileAttr becomes a 256-byte ROM0 LUT (the added compares blew the R49 frame budget). Mirror bands updated in test_regress; SGB view allowlist extended.
1 parent 6f3819e commit d321102

5 files changed

Lines changed: 351 additions & 66 deletions

File tree

src/defs.inc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,22 @@ DEF TILE_HARBOR EQU 120
114114
; --- Sea-terrain visual variants (render-only) ---
115115
; Picked by DecorateTile (world.asm) in the staging path; WorldTile still
116116
; returns canonical IDs, so collision/chart/logic never see these.
117-
DEF TILE_SHALLOW2 EQU 121 ; foam-flecked shallow (near-coast band)
117+
DEF TILE_SHALLOW2 EQU 121 ; foam-flecked shallow (sand-approach band)
118118
DEF TILE_SAND2 EQU 122 ; shells-and-pebbles sand
119119
DEF TILE_GRASS2 EQU 123 ; flowered grass
120120
DEF TILE_FOREST2 EQU 124 ; sparse canopy
121-
DEF E_FOAM_MIN EQU 144 ; shallow at/above this elevation gets foam
121+
122+
; --- Synthesized transition tiles (tile mixing, LoadTiles) ---
123+
; 4x4 Bayer-dither blends of parent pairs, built at boot by MixTile.
124+
; 50/50 tiles are shared by both sides of their boundary.
125+
DEF TILE_DEEP_SH25 EQU 125 ; deep 75 / shallow 25 (e 128-129)
126+
DEF TILE_DEEP_SH50 EQU 126 ; deep/shallow 50/50 (e 130-131, 134-135)
127+
DEF TILE_SH_DEEP25 EQU 127 ; shallow 75 / deep 25 (e 132-133)
128+
DEF TILE_SH_SAND50 EQU 129 ; shallow/sand 50/50 (e 146-147, 150-151)
129+
DEF TILE_SAND_SH25 EQU 130 ; sand 75 / shallow 25 (e 148-149)
130+
DEF TILE_SAND_GR25 EQU 131 ; sand 75 / grass 25 (e 154-155)
131+
DEF TILE_SAND_GR50 EQU 132 ; sand/grass 50/50 (e 156-157, 160-161)
132+
DEF TILE_GR_SAND25 EQU 133 ; grass 75 / sand 25 (e 158-159)
122133

123134
; --- Port towns (S4) ---
124135
; In a port district, four buildings spawn at hashed spots: tavern,

src/tiles.asm

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,196 @@ LoadTiles::
5454
ld hl, VariantTiles
5555
ld de, $8000 + 121 * 16
5656
ld bc, 4 * 16
57-
; fall through
57+
call CopyVRAM
58+
; --- synthesize the transition tiles (Bayer-dither mixes) ---
59+
ld hl, TerrainTiles + 16 ; DEEP
60+
ld de, TerrainTiles + 32 ; SHALLOW
61+
ld b, 4
62+
ld a, TILE_DEEP_SH25
63+
call SynthTile
64+
ld hl, TerrainTiles + 16
65+
ld de, TerrainTiles + 32
66+
ld b, 8
67+
ld a, TILE_DEEP_SH50
68+
call SynthTile
69+
ld hl, TerrainTiles + 32 ; SHALLOW
70+
ld de, TerrainTiles + 16 ; DEEP
71+
ld b, 4
72+
ld a, TILE_SH_DEEP25
73+
call SynthTile
74+
ld hl, TerrainTiles + 32 ; SHALLOW
75+
ld de, TerrainTiles + 48 ; SAND
76+
ld b, 8
77+
ld a, TILE_SH_SAND50
78+
call SynthTile
79+
ld hl, TerrainTiles + 48 ; SAND
80+
ld de, TerrainTiles + 32 ; SHALLOW
81+
ld b, 4
82+
ld a, TILE_SAND_SH25
83+
call SynthTile
84+
ld hl, TerrainTiles + 48 ; SAND
85+
ld de, TerrainTiles + 64 ; GRASS
86+
ld b, 4
87+
ld a, TILE_SAND_GR25
88+
call SynthTile
89+
ld hl, TerrainTiles + 48
90+
ld de, TerrainTiles + 64
91+
ld b, 8
92+
ld a, TILE_SAND_GR50
93+
call SynthTile
94+
ld hl, TerrainTiles + 64 ; GRASS
95+
ld de, TerrainTiles + 48 ; SAND
96+
ld b, 4
97+
ld a, TILE_GR_SAND25
98+
call SynthTile
99+
ret
100+
101+
; 4x4 ordered-dither matrix (values 0-15); a pixel takes Q when its entry
102+
; is below the ratio (4 = 25%, 8 = 50%, 12 = 75%).
103+
BAYER4: db 0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5
104+
105+
; in: hl = parent P (16 bytes), de = parent Q (16 bytes), b = Q ratio
106+
; (4/8/12), a = destination tile id. Synthesizes into wMixBuf, then VRAM.
107+
SynthTile:
108+
push af
109+
call MixTile
110+
pop af
111+
ld l, a
112+
ld h, 0
113+
REPT 4
114+
add hl, hl
115+
ENDR ; hl = tile id * 16
116+
ld de, $8000
117+
add hl, de
118+
push hl
119+
pop de
120+
ld hl, wMixBuf
121+
ld bc, 16
122+
jp CopyVRAM
123+
124+
; in: hl = P, de = Q, b = Q ratio. Fills wMixBuf (16 bytes).
125+
MixTile:
126+
xor a
127+
ld [wMixRow], a
128+
.rowLoop
129+
ld a, [hli]
130+
ld [wMixP], a
131+
ld a, [hli]
132+
ld [wMixP+1], a
133+
ld a, [de]
134+
inc de
135+
ld [wMixQ], a
136+
ld a, [de]
137+
inc de
138+
ld [wMixQ+1], a
139+
xor a
140+
ld [wMixI], a
141+
.pxLoop
142+
; selector: BAYER4[(row&3)*4 + (i&3)] < ratio ?
143+
ld a, [wMixRow]
144+
and 3
145+
add a
146+
add a
147+
ld c, a
148+
ld a, [wMixI]
149+
and 3
150+
add c
151+
ld e, a
152+
ld d, 0
153+
push hl
154+
ld hl, BAYER4
155+
add hl, de
156+
ld a, [hl]
157+
pop hl
158+
cp b
159+
jr c, .useQ
160+
; take P's top bits into the output, then shift all four planes
161+
ld a, [wMixO]
162+
add a
163+
ld c, a
164+
ld a, [wMixP]
165+
add a
166+
ld [wMixP], a
167+
jr nc, .pLo
168+
inc c
169+
.pLo
170+
ld a, c
171+
ld [wMixO], a
172+
ld a, [wMixO+1]
173+
add a
174+
ld c, a
175+
ld a, [wMixP+1]
176+
add a
177+
ld [wMixP+1], a
178+
jr nc, .pHi
179+
inc c
180+
.pHi
181+
ld a, c
182+
ld [wMixO+1], a
183+
jr .shiftQ
184+
.useQ
185+
ld a, [wMixO]
186+
add a
187+
ld c, a
188+
ld a, [wMixQ]
189+
add a
190+
ld [wMixQ], a
191+
jr nc, .qLo
192+
inc c
193+
.qLo
194+
ld a, c
195+
ld [wMixO], a
196+
ld a, [wMixO+1]
197+
add a
198+
ld c, a
199+
ld a, [wMixQ+1]
200+
add a
201+
ld [wMixQ+1], a
202+
jr nc, .qHi
203+
inc c
204+
.qHi
205+
ld a, c
206+
ld [wMixO+1], a
207+
ld a, [wMixP]
208+
add a
209+
ld [wMixP], a
210+
ld a, [wMixP+1]
211+
add a
212+
ld [wMixP+1], a
213+
jr .next
214+
.shiftQ
215+
ld a, [wMixQ]
216+
add a
217+
ld [wMixQ], a
218+
ld a, [wMixQ+1]
219+
add a
220+
ld [wMixQ+1], a
221+
.next
222+
ld a, [wMixI]
223+
inc a
224+
ld [wMixI], a
225+
cp 8
226+
jp nz, .pxLoop
227+
; store the row's two bytes
228+
ld a, [wMixRow]
229+
add a
230+
ld e, a
231+
ld d, 0
232+
push hl
233+
ld hl, wMixBuf
234+
add hl, de
235+
ld a, [wMixO]
236+
ld [hli], a
237+
ld a, [wMixO+1]
238+
ld [hl], a
239+
pop hl
240+
ld a, [wMixRow]
241+
inc a
242+
ld [wMixRow], a
243+
cp 8
244+
jp nz, .rowLoop
245+
ret
246+
58247
; in: hl = src, de = dst, bc = count (must be a multiple of 8).
59248
; Unrolled 8x: 3 instructions per byte instead of 7.
60249
CopyVRAM::
@@ -1178,3 +1367,11 @@ SkullTile:
11781367
dw `03333300
11791368
dw `00330300
11801369
dw `00000000
1370+
1371+
SECTION "Mixer scratch", WRAM0
1372+
wMixP: ds 2
1373+
wMixQ: ds 2
1374+
wMixO: ds 2
1375+
wMixRow: db
1376+
wMixI: db
1377+
wMixBuf: ds 16

0 commit comments

Comments
 (0)