Prev: 57924 Up: Map Next: 58045
57929: Draw Flat Rows
Draws a flat piece of terrain, three bytes wide, going up the screen two pixel rows at a time. The words of the picture are popped from the stack (which DrawTerrain has pointed at the picture) and stored in a zigzag, so that a word is two screen bytes next to each other. The entry point at DrawFlatRows moves one column to the right and carries on at DrawFlatRows_Start. The three JR instructions at DrawFlatRows_Next, DrawFlatRows_PatchSecond and DrawFlatRows_PatchThird have their displacements set by DrawTerrain to choose how much of the three bytes is drawn. When one is changed to 51 or to 238 the row is drawn from DrawFlatRows_NextColumn or DrawFlatRows, and when DrawFlatRows_PatchSecond or DrawFlatRows_PatchThird is changed to 36 or 38 the word is skipped (DrawFlatRows_SkipWord and DrawFlatRows_SkipOne).
Input
A Number of pairs of pixel rows to draw
HL Screen address of the bottom left of the piece
SP Address of the picture
DrawFlatRows 57929 INC L Advance L.
57930 JP DrawFlatRows_Start Jump to DrawFlatRows_Start.
DrawFlatRows_Normal 57933 LD B,A B=A.
57934 LD A,(52809) The segment screen address.
57937 ADD A,3 Add 3 to A.
57939 LD (52809),A Update the segment screen address.
57942 INC L Advance L.
57943 INC L Advance L.
57944 INC L Advance L.
DrawFlatRows_Next 57945 JR DrawFlatRows_Next Skip ahead by the displacement that DrawTerrain sets.
DrawFlatRows_Word1 57947 POP DE Bring DE back off the stack.
57948 LD (HL),E Write E where HL points.
DrawFlatRows_PatchSecond 57949 JR DrawFlatRows_PatchSecond Skip ahead by the displacement that DrawTerrain sets.
DrawFlatRows_Word2 57951 INC L Advance L.
57952 LD (HL),D Write D where HL points.
DrawFlatRows_PatchThird 57953 JR DrawFlatRows_PatchThird Skip ahead by the displacement that DrawTerrain sets.
DrawFlatRows_Word3 57955 INC L Advance L.
57956 POP DE Bring DE back off the stack.
57957 LD (HL),E Write E where HL points.
57958 DEC H Step H back.
57959 LD (HL),D Write D where HL points.
57960 DEC L Step L back.
DrawFlatRows_Word4 57961 POP DE Bring DE back off the stack.
57962 LD (HL),E Write E where HL points.
57963 DEC L Step L back.
DrawFlatRows_Store 57964 LD (HL),D Write D where HL points.
DrawFlatRows_Up 57965 DEC H Step H back.
57966 LD A,H A=H.
57967 INC A Advance A.
57968 AND %00000111 Keep the bits of A that are set in 7.
57970 JR NZ,DrawFlatRows_Loop Jump to DrawFlatRows_Loop if the zero flag is clear.
57972 LD A,L A=L.
57973 SUB 32 Subtract 32 from A.
57975 LD L,A L=A.
57976 JR C,DrawFlatRows_Loop Jump to DrawFlatRows_Loop if the carry flag is set.
57978 LD A,H A=H.
57979 ADD A,8 Add 8 to A.
57981 LD H,A H=A.
DrawFlatRows_Loop 57982 DJNZ DrawFlatRows_Next Decrease B and jump to DrawFlatRows_Next until none remain.
57984 JP FinishStep_Exchange Jump to FinishStep_Exchange.
DrawFlatRows_SkipWord 57987 DEC H Step H back.
57988 POP DE Bring DE back off the stack.
57989 POP DE Bring DE back off the stack.
57990 JP DrawFlatRows_Store Jump to DrawFlatRows_Store.
DrawFlatRows_SkipOne 57993 DEC H Step H back.
57994 POP DE Bring DE back off the stack.
57995 JP DrawFlatRows_Word4 Jump to DrawFlatRows_Word4.
DrawFlatRows_NextColumn 57998 INC A Advance A.
57999 AND %00011111 Keep the bits of A that are set in 31.
58001 JR NZ,DrawFlatRows_Column Jump to DrawFlatRows_Column if the zero flag is clear.
58003 LD A,L A=L.
58004 SUB 32 Subtract 32 from A.
58006 LD (52809),A Update the segment screen address.
DrawFlatRows_Column 58009 LD A,L A=L.
58010 AND %11100000 Keep the bits of A that are set in 224.
58012 INC A Advance A.
58013 LD L,A L=A.
DrawFlatRows_Start 58014 LD A,76 A=76.
58016 LD (57946),A Skip the rest of the flat row.
58019 INC SP Advance SP.
DrawFlatRows_PatchFourth 58020 JR DrawFlatRows_PatchFourth Skip ahead by the displacement that DrawTerrain sets.
DrawFlatRows_Pop 58022 INC SP Advance SP.
58023 POP DE Bring DE back off the stack.
58024 LD (HL),E Write E where HL points.
DrawFlatRows_PatchFifth 58025 JR DrawFlatRows_PatchFifth Skip ahead by the displacement that DrawTerrain sets.
DrawFlatRows_Right 58027 INC L Advance L.
58028 LD (HL),D Write D where HL points.
58029 POP DE Bring DE back off the stack.
58030 DEC H Step H back.
58031 LD (HL),E Write E where HL points.
58032 DEC L Step L back.
58033 LD (HL),D Write D where HL points.
58034 POP DE Bring DE back off the stack.
58035 JP DrawFlatRows_Up Jump to DrawFlatRows_Up.
DrawFlatRows_Left 58038 DEC H Step H back.
58039 LD (HL),D Write D where HL points.
58040 POP DE Bring DE back off the stack.
58041 POP DE Bring DE back off the stack.
58042 JP DrawFlatRows_Up Jump to DrawFlatRows_Up.
Prev: 57924 Up: Map Next: 58045