* * HW5 * * Purpose: Given the mid-point and one corner of a rectangle * find the other three corners * * Author: Heather D. Pfeiffer * RAM equ $0010 EEPROM equ $f800 CONSTS equ $f900 RESET equ $fffe * Save space in RAM for three new corner points org RAM Xcrn2 rmb 1 Ycrn2 rmb 1 Xcrn3 rmb 1 Ycrn3 rmb 1 Xcrn4 rmb 1 Ycrn4 rmb 1 * The algorithm for the mid-point is: mid-point = (X1 + X2)/2 * the X2 point will be on the opposite side of the rectangle. * * Could look like: X4,Y4 X3,Y3 * * ------------------------------ * * | | * | | * | XC,YC | * | | * | | * * ------------------------------ * * X1,Y1 X2,Y2 * * Note: X1, Y1 can be in any corner; rectangle just rotates. * org EEPROM start * First set X4 and Y2 from known values ldaa Xcrn1 staa Xcrn4 ldaa Ycrn1 staa Ycrn2 * Now find X2 given the re-evaluation of above equation: * X2 = 2*XC - X1 ldaa Xctr tab aba ldab Xcrn1 sba staa Xcrn2 * Store X3 now that it is known staa Xcrn3 * Now find Y4 given the re-evaluation of above equation: * Y4 = 2*YC - Y1 ldaa Yctr tab aba ldab Ycrn1 sba staa Ycrn4 * Store Y3 now that it is known staa Ycrn3 endloop bra endloop * dead loop * Set the beginning constants for the program org CONSTS Xcrn1 fcb 2 Ycrn1 fcb 6 Xctr fcb 7 Yctr fcb 13 * Setup reset vector org RESET fdb start