Prev: ACAB Up: Map Next: ADB0
AD02: Draw Line
Used by the routine at Draw_Rope.
Draws two lines at the same time, both going up the screen. The main registers hold the start and the end of the first line, and the shadow registers hold the start and the end of the second line. The rope uses it to erase the old rope and draw the new one in the same pass (see Draw_Rope), as every pixel is plotted with XOR.
Each line is set up with Set_Up_Line. The two lines are drawn together, one step each at a time, until one of them is finished, and then the other is finished on its own. Each step is the plotting of a pixel with Plot_Pixel, a move of the x position by the slope and a move up by one pixel line with ScreenPosition1PixelAbove.
When the object is the rope (type 17) and bit 0 of its redraw flags is clear, the lines are limited to one step each, and the flag is reset.
At the end the attribute of every cell that the line goes through is set to 47 (white ink on black paper), starting at a cell near the end of the rope and moving up by one cell for each eight steps.
Input
HL Start of the first line
DE End of the first line
HL' Start of the second line
DE' End of the second line
IX Object record
Set up the second line (the shadow registers) and then the first line (the main registers). The fractions of the lines are kept in Shadow_Line_Fraction and Main_Line_Fraction.
Draw_Line AD02 PUSH HL Stash the start of the first line on the stack.
AD03 PUSH DE Stash the end of the first line on the stack.
AD04 EXX Switch to the shadow registers.
AD05 CALL Set_Up_Line Set up the second line.
AD08 LD ($AAA1),A Store the low byte of the slope as the fraction of the second line.
AD0B LD C,L Copy the x position of the start to C.
AD0C CALL ScreenAddress Get the display file address of the start.
AD0F EXX Switch to the main registers.
AD10 POP DE Restore the end of the first line from the stack.
AD11 POP HL Restore the start of the first line from the stack.
AD12 EXX Switch to the shadow registers.
AD13 PUSH HL Stash the display file address of the second line on the stack.
AD14 PUSH DE Stash the slope of the second line on the stack.
AD15 PUSH BC Stash the steps of the second line on the stack.
AD16 EXX Switch to the main registers.
AD17 CALL Set_Up_Line Set up the first line.
AD1A LD ($AAA0),A Store the low byte of the slope as the fraction of the first line.
AD1D LD C,L Copy the x position of the start to C.
AD1E CALL ScreenAddress Get the display file address of the start.
AD21 EXX Switch to the shadow registers.
AD22 POP BC Restore the steps of the second line from the stack.
AD23 POP DE Restore the slope of the second line from the stack.
AD24 POP HL Restore the display file address of the second line from the stack.
For the rope, limit both lines to one step unless bit 0 of the redraw flags is set. Then reset that bit.
AD25 LD A,(IX+$00) Fetch the sprite id.
AD28 CP $17 Jump to Draw_Line_Step_Loop if the object is not the rope.
AD2A JR NZ,Draw_Line_Step_Loop
AD2C BIT 0,(IX+$0F) Jump to Draw_Line_Reset_Redraw_Flag if bit 0 of the redraw flags is set.
AD30 JR NZ,Draw_Line_Reset_Redraw_Flag
AD32 LD B,$01 Limit the second line to one step.
AD34 EXX Switch to the main registers.
AD35 LD B,$01 Limit the first line to one step.
AD37 EXX Switch to the shadow registers.
Draw_Line_Reset_Redraw_Flag AD38 RES 0,(IX+$0F) Reset bit 0 of the redraw flags.
Draw a step of each line in turn, until one of the lines has ended.
Draw_Line_Step_Loop AD3C CALL Draw_Line_Step Draw a step of the second line.
AD3F EXX Switch to the main registers.
AD40 PUSH BC Stash the steps and the direction of the first line on the stack.
AD41 CALL Plot_Pixel Plot a pixel of the first line.
AD44 LD A,H Stash the high byte of the display file address in AF'.
AD45 EX AF,AF'
AD46 LD A,($AAA0) Fetch the fraction of the first line.
AD49 LD H,C Copy the x position to H.
AD4A LD B,L Stash the low byte of the display file address in B.
AD4B LD L,A Copy the fraction to L.
AD4C ADD HL,DE Add the slope to the x position and the fraction.
AD4D LD A,L Copy the new fraction to A.
AD4E LD ($AAA0),A Store it as the fraction of the first line.
AD51 LD C,H Copy the new x position to C.
AD52 LD A,B Restore the low byte of the display file address.
AD53 AND %11100000 Keep only the row bits of the low byte.
AD55 LD B,A Store them in B.
AD56 LD A,C Copy the new x position to A.
AD57 RRA Divide the x position by 08.
AD58 RRA
AD59 RRA
AD5A AND %00011111 Keep only five bits to make the column.
AD5C OR B Combine the row bits with the column.
AD5D LD L,A Store the new low byte of the display file address in L.
AD5E LD A,C Copy the new x position to A.
AD5F POP BC Restore the steps and the direction of the first line from the stack.
AD60 LD C,A Store the new x position in C.
AD61 EX AF,AF' Restore the high byte of the display file address and store it in H.
AD62 LD H,A
AD63 CALL ScreenPosition1PixelAbove Move up a pixel line.
AD66 DEC B Jump to Draw_Line_First_Line_Ended if the first line has ended.
AD67 JR Z,Draw_Line_First_Line_Ended
AD69 EXX Switch to the shadow registers.
AD6A DJNZ Draw_Line_Step_Loop Jump to Draw_Line_Step_Loop until the second line has ended.
The second line has ended first, so the remaining steps of the first line are drawn with its fraction in Shadow_Line_Fraction.
AD6C LD A,($AAA0) Fetch the fraction of the first line.
AD6F LD ($AAA1),A Store it as the fraction used by Draw_Line_Step.
AD72 EXX Switch to the main registers.
AD73 JR Draw_Line_Finish_Line_Loop Jump to Draw_Line_Finish_Line_Loop.
The first line has ended first. Draw the remaining steps of the second line.
Draw_Line_First_Line_Ended AD75 EXX Switch to the shadow registers.
AD76 DEC B Jump to Draw_Line_Set_Attributes if the second line has ended as well.
AD77 JR Z,Draw_Line_Set_Attributes
Draw_Line_Finish_Line_Loop AD79 CALL Draw_Line_Step Draw a step of the line.
AD7C DJNZ Draw_Line_Finish_Line_Loop Repeat until the line has ended.
Set the attributes of the cells that the line goes through.
Draw_Line_Set_Attributes AD7E EX DE,HL Move the slope to HL.
AD7F LD DE,$2000 DE=2000 (one row of attribute cells, in the high byte).
AD82 AND A Subtract 2000 from the slope.
AD83 SBC HL,DE
AD85 EX DE,HL Store the result in DE.
AD86 LD HL,($AA95) Fetch the position of the end of the rope.
AD89 INC L Move the x position on by four pixels.
AD8A INC L
AD8B INC L
AD8C INC L
AD8D CALL AttributeAddress Get the attribute address of the position.
AD90 XOR A Clear the fraction in AF'.
AD91 EX AF,AF'
AD92 LD A,($AA93) Fetch the number of steps.
AD95 RRA Divide the number of steps by eight.
AD96 RRA
AD97 RRA
AD98 AND %00011111 Keep only five bits to make the number of cells.
AD9A RET Z Return if there are no cells.
AD9B LD B,A Copy the number of cells to B.
Draw_Line_Attribute_Loop AD9C LD (HL),$47 Set the attribute to 47 (white ink on black paper).
AD9E LD C,H Stash the high byte of the attribute address in C.
AD9F LD H,L Copy the low byte to H.
ADA0 EX AF,AF' Restore the fraction from AF'.
ADA1 LD L,A Copy it to L.
ADA2 ADD HL,DE Move the position by the slope and up by one row of cells.
ADA3 LD A,L Copy the new fraction to A.
ADA4 PUSH AF Stash it, with the carry flag, on the stack.
ADA5 EX AF,AF' Keep the new fraction in AF'.
ADA6 POP AF Restore the carry flag from the stack.
ADA7 LD L,H Copy the new low byte of the attribute address to L.
ADA8 LD A,C Fetch the stashed high byte of the attribute address.
ADA9 CCF Invert the carry flag.
ADAA SBC A,$00 Subtract the carry from the high byte, in case the address has crossed into another third of the screen.
ADAC LD H,A Store it as the high byte of the attribute address.
ADAD DJNZ Draw_Line_Attribute_Loop Decrease the cell counter and loop back until all of the cells have been done.
ADAF RET Return.
Prev: ACAB Up: Map Next: ADB0