Skip to navigation

Lander on the Acorn Archimedes

Drawing triangles: DrawTriangle (Part 6 of 11)

Name: DrawTriangle (Part 6 of 11) [Show more] Type: Subroutine Category: Drawing triangles Summary: Draw a clipped triangle that's partly off-screen Deep dive: Drawing triangles
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.trin23 CMP R1, #239 \ If all of the y-coordinates are off-screen CMPHS R3, #239 \ then return from the subroutine CMPHS R5, #239 MOVHS PC, R14 CMP R0, #320 \ If all of the x-coordinates are off-screen CMPHS R2, #320 \ then return from the subroutine CMPHS R4, #320 MOVHS PC, R14 STMFD R13!, {R14} \ Store the return address on the stack LDR R12, screenAddr \ Set R12 to the address of the screen bank \ we are drawing in, pointing just below \ the two lines of text at the top of the \ screen \ We start by ordering the triangle corners \ by y-coordinate, so (x1, y1) is the \ furthest down the screen with the highest \ y-coordinate, followed by (x2, y2) then \ (x3, y3), at the same or higher level, and \ in that order CMP R1, R3 \ If R1 > R3, jump to trin24 to skip the BGT trin24 \ following, as y1 > y2 already MOV R6, R0 \ Swap (x1, y1) and (x2, y2), so we now have MOV R0, R2 \ y1 >= y2 MOV R2, R6 MOV R6, R1 MOV R1, R3 MOV R3, R6 .trin24 CMP R1, R5 \ If R1 > R5, jump to trin25 to skip the BGT trin25 \ following, as y1 > y3 already MOV R6, R0 \ Swap (x1, y1) and (x3, y3), so we now have MOV R0, R4 \ y1 >= y3 MOV R4, R6 MOV R6, R1 MOV R1, R5 MOV R5, R6 .trin25 CMP R3, R5 \ If R3 > R5, jump to trin26 to skip the BGT trin26 \ following, as y2 > y3 already MOV R6, R2 \ Swap (x2, y2) and (x3, y3), so we now have MOV R2, R4 \ y2 >= y3 MOV R4, R6 MOV R6, R3 MOV R3, R5 MOV R5, R6 \ So the triangle coordinates are ordered \ like this on-screen: \ \ (x3, y3) \ (x2, y2) \ (x1, y1) .trin26 MOV R11, R1 \ Set R11 = R1 \ = y1 \ \ We use the value of R11 in part 11, when \ drawing the clipped triangle