Prev: 44203 Up: Map Next: 44464
44290: 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 23) 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 71 (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 44290 PUSH HL Stash the start of the first line on the stack.
44291 PUSH DE Stash the end of the first line on the stack.
44292 EXX Switch to the shadow registers.
44293 CALL Set_Up_Line Set up the second line.
44296 LD (43681),A Store the low byte of the slope as the fraction of the second line.
44299 LD C,L Copy the x position of the start to C.
44300 CALL ScreenAddress Get the display file address of the start.
44303 EXX Switch to the main registers.
44304 POP DE Restore the end of the first line from the stack.
44305 POP HL Restore the start of the first line from the stack.
44306 EXX Switch to the shadow registers.
44307 PUSH HL Stash the display file address of the second line on the stack.
44308 PUSH DE Stash the slope of the second line on the stack.
44309 PUSH BC Stash the steps of the second line on the stack.
44310 EXX Switch to the main registers.
44311 CALL Set_Up_Line Set up the first line.
44314 LD (43680),A Store the low byte of the slope as the fraction of the first line.
44317 LD C,L Copy the x position of the start to C.
44318 CALL ScreenAddress Get the display file address of the start.
44321 EXX Switch to the shadow registers.
44322 POP BC Restore the steps of the second line from the stack.
44323 POP DE Restore the slope of the second line from the stack.
44324 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.
44325 LD A,(IX+0) Fetch the sprite id.
44328 CP 23 Jump to Draw_Line_Step_Loop if the object is not the rope.
44330 JR NZ,Draw_Line_Step_Loop
44332 BIT 0,(IX+15) Jump to Draw_Line_Reset_Redraw_Flag if bit 0 of the redraw flags is set.
44336 JR NZ,Draw_Line_Reset_Redraw_Flag
44338 LD B,1 Limit the second line to one step.
44340 EXX Switch to the main registers.
44341 LD B,1 Limit the first line to one step.
44343 EXX Switch to the shadow registers.
Draw_Line_Reset_Redraw_Flag 44344 RES 0,(IX+15) 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 44348 CALL Draw_Line_Step Draw a step of the second line.
44351 EXX Switch to the main registers.
44352 PUSH BC Stash the steps and the direction of the first line on the stack.
44353 CALL Plot_Pixel Plot a pixel of the first line.
44356 LD A,H Stash the high byte of the display file address in AF'.
44357 EX AF,AF'
44358 LD A,(43680) Fetch the fraction of the first line.
44361 LD H,C Copy the x position to H.
44362 LD B,L Stash the low byte of the display file address in B.
44363 LD L,A Copy the fraction to L.
44364 ADD HL,DE Add the slope to the x position and the fraction.
44365 LD A,L Copy the new fraction to A.
44366 LD (43680),A Store it as the fraction of the first line.
44369 LD C,H Copy the new x position to C.
44370 LD A,B Restore the low byte of the display file address.
44371 AND %11100000 Keep only the row bits of the low byte.
44373 LD B,A Store them in B.
44374 LD A,C Copy the new x position to A.
44375 RRA Divide the x position by 8.
44376 RRA
44377 RRA
44378 AND %00011111 Keep only five bits to make the column.
44380 OR B Combine the row bits with the column.
44381 LD L,A Store the new low byte of the display file address in L.
44382 LD A,C Copy the new x position to A.
44383 POP BC Restore the steps and the direction of the first line from the stack.
44384 LD C,A Store the new x position in C.
44385 EX AF,AF' Restore the high byte of the display file address and store it in H.
44386 LD H,A
44387 CALL ScreenPosition1PixelAbove Move up a pixel line.
44390 DEC B Jump to Draw_Line_First_Line_Ended if the first line has ended.
44391 JR Z,Draw_Line_First_Line_Ended
44393 EXX Switch to the shadow registers.
44394 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.
44396 LD A,(43680) Fetch the fraction of the first line.
44399 LD (43681),A Store it as the fraction used by Draw_Line_Step.
44402 EXX Switch to the main registers.
44403 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 44405 EXX Switch to the shadow registers.
44406 DEC B Jump to Draw_Line_Set_Attributes if the second line has ended as well.
44407 JR Z,Draw_Line_Set_Attributes
Draw_Line_Finish_Line_Loop 44409 CALL Draw_Line_Step Draw a step of the line.
44412 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 44414 EX DE,HL Move the slope to HL.
44415 LD DE,8192 DE=8192 (one row of attribute cells, in the high byte).
44418 AND A Subtract 8192 from the slope.
44419 SBC HL,DE
44421 EX DE,HL Store the result in DE.
44422 LD HL,(43669) Fetch the position of the end of the rope.
44425 INC L Move the x position on by four pixels.
44426 INC L
44427 INC L
44428 INC L
44429 CALL AttributeAddress Get the attribute address of the position.
44432 XOR A Clear the fraction in AF'.
44433 EX AF,AF'
44434 LD A,(43667) Fetch the number of steps.
44437 RRA Divide the number of steps by eight.
44438 RRA
44439 RRA
44440 AND %00011111 Keep only five bits to make the number of cells.
44442 RET Z Return if there are no cells.
44443 LD B,A Copy the number of cells to B.
Draw_Line_Attribute_Loop 44444 LD (HL),71 Set the attribute to 71 (white ink on black paper).
44446 LD C,H Stash the high byte of the attribute address in C.
44447 LD H,L Copy the low byte to H.
44448 EX AF,AF' Restore the fraction from AF'.
44449 LD L,A Copy it to L.
44450 ADD HL,DE Move the position by the slope and up by one row of cells.
44451 LD A,L Copy the new fraction to A.
44452 PUSH AF Stash it, with the carry flag, on the stack.
44453 EX AF,AF' Keep the new fraction in AF'.
44454 POP AF Restore the carry flag from the stack.
44455 LD L,H Copy the new low byte of the attribute address to L.
44456 LD A,C Fetch the stashed high byte of the attribute address.
44457 CCF Invert the carry flag.
44458 SBC A,0 Subtract the carry from the high byte, in case the address has crossed into another third of the screen.
44460 LD H,A Store it as the high byte of the attribute address.
44461 DJNZ Draw_Line_Attribute_Loop Decrease the cell counter and loop back until all of the cells have been done.
44463 RET Return.
Prev: 44203 Up: Map Next: 44464