Prev: 38193 Up: Map Next: 38484
38326: Stamp Terrain Tile
Write crater tiles into TerrainData_Active under the current actor and redraw them on the screen.
Input
IX Actor slot
StampTerrainTile 38326 CALL ReadTerrainCell Call ReadTerrainCell.
38329 PUSH HL Stash the cell index on the stack.
38330 LD DE,28672 DE=TerrainData_Active.
38333 EX DE,HL Switch the DE and HL registers.
38334 ADD HL,DE Point HL at that terrain cell.
38335 BIT 3,(HL) Jump to StampTerrainTile_WriteFirstCell if bit 3 of the tile is reset.
38337 JR Z,StampTerrainTile_WriteFirstCell
38339 LD (HL),10 Write 10 to the cell. udg63166_67x4
38341 JR StampTerrainTile_Neighbour Jump to StampTerrainTile_Neighbour.
StampTerrainTile_WriteFirstCell 38343 LD (HL),8 Write 8 to the cell. udg63150_67x4
Stamp the neighbouring cell.
StampTerrainTile_Neighbour 38345 INC DE Move onto the next cell.
38346 LD A,D Fetch the high byte.
38347 AND %00000011 Keep only bits 0-1.
38349 LD D,A Write it back to D.
38350 LD HL,28672 HL=TerrainData_Active.
38353 ADD HL,DE Point HL at that terrain cell.
Pick the tile for the neighbouring cell: 10 if bit 3 is set, else 9.
38354 BIT 3,(HL) Jump to StampTerrainTile_WriteSecondCell if bit 3 of the tile is reset.
38356 JR Z,StampTerrainTile_WriteSecondCell
38358 LD (HL),10 Write 10 to the cell. udg63166_67x4
38360 JR StampTerrainTile_Redraw Jump to StampTerrainTile_Redraw.
StampTerrainTile_WriteSecondCell 38362 LD (HL),9 Write 9 to the cell. udg63158_67x4
Redraw the stamped columns onto the play area.
StampTerrainTile_Redraw 38364 CALL ClearTerrainUnderActor Jump to StampTerrainTile_Restore if ClearTerrainUnderActor returns non-zero.
38367 JP NZ,StampTerrainTile_Restore
38370 LD A,H Subtract 8 from the high byte.
38371 SUB 8
38373 LD H,A Write it back to H.
Wrap the cell index and point DE at its terrain cell.
38374 EX (SP),HL Exchange the cell index with the stacked pointer.
38375 LD A,H Fetch the high byte.
38376 AND %00011111 Keep only bits 0-4.
38378 LD H,A Write it back to H.
38379 LD DE,28672 DE=TerrainData_Active.
38382 EX DE,HL Point DE at that terrain cell.
38383 ADD HL,DE
38384 EX DE,HL
38385 EX (SP),HL Exchange the cell index with the stacked pointer.
Move onto the next screen column if the scroll is on a character boundary.
38386 LD A,(24698) Fetch Jetman_Position.
38389 AND %00000111 Keep only bits 0-2.
38391 JR NZ,StampTerrainTile_XORColumn Jump to StampTerrainTile_XORColumn if the scroll is not on a character boundary, else move onto the next screen column.
38393 INC HL
OR the first graphic column onto the screen.
StampTerrainTile_XORColumn 38394 PUSH HL Stash the screen pointer on the stack.
38395 LD A,(DE) Fetch the tile index from *DE into HL.
38396 LD L,A
38397 LD H,0
38399 LD DE,63086 DE=TerrainUDGs.
38402 ADD HL,HL Multiply the tile index by 8 and add the graphic base.
38403 ADD HL,HL
38404 ADD HL,HL
38405 ADD HL,DE
38406 EX DE,HL Point DE at that graphic.
Work out the pixel shift from the scroll position.
38407 EXX Switch to the shadow registers.
38408 LD A,(24698) Fetch Jetman_Position.
38411 NEG Negate the low byte.
38413 AND %00000111 Keep only bits 0-2.
38415 LD C,A Store the pixel shift in C.
38416 EXX Switch back to the main registers.
38417 POP HL Restore the screen pointer from the stack, but stash a copy of it on the stack again.
38418 PUSH HL
38419 LD B,8 Set a pixel row counter in B for 8 loops.
38421 CALL StampTerrainTile_Loop Call StampTerrainTile_Loop.
Fetch the next terrain cell's graphic and draw it in the next screen column.
38424 POP HL Restore the screen pointer from the stack.
38425 EX (SP),HL Exchange it with the stacked cell index.
38426 INC HL Move onto the next cell.
38427 LD A,H Fetch the high byte.
38428 AND %00000011 Keep only bits 0-1.
38430 LD H,A Write it back to H.
Look up the graphic for that cell.
38431 LD DE,28672 DE=TerrainData_Active.
38434 ADD HL,DE Point HL at that terrain cell.
38435 LD L,(HL) Fetch the tile index from *HL into HL.
38436 LD H,0
38438 ADD HL,HL Multiply the tile index by 8.
38439 ADD HL,HL
38440 ADD HL,HL
38441 LD DE,63086 DE=TerrainUDGs.
38444 ADD HL,DE Point DE at that graphic.
38445 EX DE,HL
Aim at the next screen column and reset the row counter.
38446 POP HL Restore the screen pointer from the stack.
38447 INC L Move onto the next screen column.
38448 LD B,8 Set a pixel row counter in B for 8 loops.
Shift a graphic byte by the scroll and OR it onto two neighbouring screen bytes.
StampTerrainTile_Loop 38450 LD A,(DE) Fetch the graphic byte.
38451 EXX Switch to the shadow registers.
38452 LD H,A Store it in H and clear L.
38453 LD L,0
38455 LD B,C B=the pixel shift.
38456 LD A,C Jump to StampTerrainTile_MergeBytes if there is no shift.
38457 AND A
38458 JR Z,StampTerrainTile_MergeBytes
StampTerrainTile_ShiftPixel 38460 SRL H Shift the graphic right by one pixel.
38462 RR L
38464 DJNZ StampTerrainTile_ShiftPixel Decrease the shift counter by one and loop back to StampTerrainTile_ShiftPixel until the shift is done.
OR the shifted graphic onto the two screen bytes.
StampTerrainTile_MergeBytes 38466 LD A,L Stash the low byte and fetch the high byte.
38467 EX AF,AF'
38468 LD A,H
38469 EXX Switch back to the main registers.
38470 OR (HL) Merge the high byte onto the current screen byte.
38471 LD (HL),A
38472 INC L
38473 EX AF,AF' Fetch the stashed low byte.
38474 OR (HL) Merge the low byte onto the next screen byte.
38475 LD (HL),A
38476 INC DE Move onto the next graphic byte.
38477 DEC L Step back and down one pixel row.
38478 INC H
38479 DJNZ StampTerrainTile_Loop Decrease the row counter by one and loop back to StampTerrainTile_Loop until the column is drawn.
38481 RET Return.
StampTerrainTile_Restore 38482 POP HL Restore the cell index from the stack.
38483 RET Return.
Prev: 38193 Up: Map Next: 38484