; ; coords.s ; ; Messing about with lines and boxes ; ; © 1994-1998 Straylight ; ;----- Licensing note ------------------------------------------------------- ; ; This file is part of Straylight's Steel library. ; ; Steel is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2, or (at your option) ; any later version. ; ; Steel is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with Steel. If not, write to the Free Software Foundation, ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;----- Standard stuff ------------------------------------------------------- GET libs:header ;----- Exported routines ---------------------------------------------------- AREA |C$$Code|,CODE,READONLY ; --- coords_x_toscreen --- ; ; On entry: a1 == abscissa to convert ; a2 == pointer to block of window coordinates ; On exit: a1 == a converted abscissa EXPORT coords_x_toscreen coords_x_toscreen LDR a3,[a2,#0] ;Get x0 from coords block LDR a4,[a2,#16] ;Get xsc from coords block SUB a3,a3,a4 ;Get translation offset ADD a1,a1,a3 ;Convert to screen coords MOVS pc,lr ;Return to caller ; --- coords_y_toscreen --- ; ; On entry: a1 == ordinate to convert ; a2 == pointer to block of window coordinates ; On exit: a1 == a converted ordinate EXPORT coords_y_toscreen coords_y_toscreen ADD a2,a2,#12 ;Find y1 LDMIA a2,{a3,a4,ip} ;Get y1 and ysc (a4 not used) SUB a3,a3,ip ;Get translation offset ADD a1,a1,a3 ;Convert to screen coords MOVS pc,lr ;Return to caller ; --- coords_x_toworkarea --- ; ; On entry: a1 == abscissa to convert ; a2 == pointer to block of window coordinates ; On exit: a1 == a converted abscissa EXPORT coords_x_toworkarea coords_x_toworkarea LDR a3,[a2,#0] ;Get x0 from coords block LDR a4,[a2,#16] ;Get xsc from coords block SUB a3,a3,a4 ;Get translation offset SUB a1,a1,a3 ;Convert to window coords MOVS pc,lr ;Return to caller ; --- coords_y_toworkarea --- ; ; On entry: a1 == ordinate to convert ; a2 == pointer to block of window coordinates ; On exit: a1 == a converted ordinate EXPORT coords_y_toworkarea coords_y_toworkarea ADD a2,a2,#12 ;Find y1 LDMIA a2,{a3,a4,ip} ;Get y1 and ysc (a4 not used) SUB a3,a3,ip ;Get translation offset SUB a1,a1,a3 ;Convert to window coords MOVS pc,lr ;Return to caller ; --- coords_box_toscreen --- ; ; On entry: a1 == pointer to box to convert ; a2 == pointer to coordinates block EXPORT coords_box_toscreen coords_box_toscreen STMFD sp!,{v1,lr} LDR a3,[a2,#0] ;Get x0 from coords block ADD a2,a2,#12 ;Point to y1 LDMIA a2,{a2,a4,v1} ;Get y1 and scroll position SUB a3,a3,a4 ;Get the x translation offset SUB a2,a2,v1 ;Get the y translation offset LDMIA a1,{a4,v1,ip,lr} ADD a4,a4,a3 ADD v1,v1,a2 ADD ip,ip,a3 ADD lr,lr,a2 STMIA a1,{a4,v1,ip,lr} LDMFD sp!,{v1,pc}^ ; --- coords_box_toworkarea --- ; ; On entry: a1 == pointer to box to convert ; a2 == pointer to coordinates block EXPORT coords_box_toworkarea coords_box_toworkarea STMFD sp!,{v1,lr} LDR a3,[a2,#0] ;Get x0 from coords block ADD a2,a2,#12 ;Point to y1 LDMIA a2,{a2,a4,v1} ;Get y1 and scroll position SUB a3,a3,a4 ;Get the x translation offset SUB a2,a2,v1 ;Get the y translation offset LDMIA a1,{a4,v1,ip,lr} SUB a4,a4,a3 SUB v1,v1,a2 SUB ip,ip,a3 SUB lr,lr,a2 STMIA a1,{a4,v1,ip,lr} LDMFD sp!,{v1,pc}^ ; --- coords_point_toscreen --- ; ; On entry: a1 == pointer to box to convert ; a2 == pointer to coordinates block EXPORT coords_point_toscreen coords_point_toscreen LDR a3,[a2,#0] ;Get x0 from coords block ADD a2,a2,#12 ;Point to y1 LDMIA a2,{a2,a4,ip} ;Get y1 and scroll position SUB a3,a3,a4 ;Get the x translation offset SUB a2,a2,ip ;Get the y translation offset LDMIA a1,{a4,ip} ADD a4,a4,a3 ADD ip,ip,a2 STMIA a1,{a4,ip} MOVS pc,lr ; --- coords_point_toworkarea --- ; ; On entry: a1 == pointer to box to convert ; a2 == pointer to coordinates block EXPORT coords_point_toworkarea coords_point_toworkarea LDR a3,[a2,#0] ;Get x0 from coords block ADD a2,a2,#12 ;Point to y1 LDMIA a2,{a2,a4,ip} ;Get y1 and scroll position SUB a3,a3,a4 ;Get the x translation offset SUB a2,a2,ip ;Get the y translation offset LDMIA a1,{a4,ip} SUB a4,a4,a3 SUB ip,ip,a2 STMIA a1,{a4,ip} MOVS pc,lr ; --- coords_withinbox --- ; ; On entry: a1 == pointer to a silly point structure ; a2 == pointer to a slightly more sensible box structure ; On exit: a1 == 1 if the point is inside the box EXPORT coords_withinbox coords_withinbox STMFD sp!,{lr} ;Save the link -- we need it LDMIA a1,{a3,a4} ;Get the point coordinates LDMIA a2,{a1,a2,ip,lr} ;Get the box coordinates CMP a1,a3 ;The magic cascaded condition CMPLE a2,a4 CMPLE a3,ip CMPLE a4,lr MOVLE a1,#1 ;If it succeeded, return TRUE MOVGT a1,#0 ;If not return FALSE LDMFD sp!,{pc}^ ; --- coords_offsetbox --- ; ; On entry: a1 == pointer to input box to mangle ; a2 == x offset to mangle by ; a3 == y offset to mangle by ; a4 == where to put the mangled bits EXPORT coords_offsetbox coords_offsetbox STMFD sp!,{v1,lr} ;Save some registers LDMIA a1,{a1,v1,ip,lr} ;Get the box coordinates ADD a1,a1,a2 ADD v1,v1,a3 ADD ip,ip,a2 ADD lr,lr,a3 STMIA a4,{a1,v1,ip,lr} ;Save the adjusted coords LDMFD sp!,{v1,pc}^ ; --- coords_intersects --- ; ; On entry: a1 == pointer to box structure containing the line ; a2 == pointer to box structure containing the rectangle ; a3 == the `width' of the line (ho-hum) ; On exit: a1 == 0 if it didn't, 1 if it did ; ; This implementation is a really yukky hack, and doesn't test whether the ; line intersects at all, but it's good enough for jazz... EXPORT coords_intersects coords_intersects STMFD sp!,{v1,v2,lr} ;Save some registers LDMIA a1,{a4,v1,v2,ip} ;Get the line coordinates ; --- Sort coordinates properly --- CMP a4,v2 ;Sort the x coordinates EORGT a4,a4,v2 EORGT v2,v2,a4 EORGT a4,a4,v2 CMP v1,ip ;Sort the y coordinates EORGT v1,v1,ip EORGT ip,ip,v1 EORGT v1,v1,ip ; --- `Widen' the line --- SUB a4,a4,a3 SUB v1,v1,a3 ADD v2,v2,a3 ADD ip,ip,a3 ; --- Now get the rectangle and compare --- LDMIA a2,{a1-a3,lr} CMP a4,a3 CMPLE v1,lr CMPLE a1,v2 CMPLE a2,ip MOVLE a1,#1 MOVGT a1,#0 LDMFD sp!,{v1,v2,pc}^ ; --- coords_boxesoverlap --- ; ; On entry: a1,a2 == pointers to boxes ; On exit: a1 == 1 if boxes overlap, 0 otherwise EXPORT coords_boxesoverlap coords_boxesoverlap STMFD sp!,{v1,v2,lr} ;Save registers LDMIA a1,{a3,a4,ip,lr} ;Get coordinates of box 1 LDMIA a2,{a1,a2,v1,v2} ;Get coordinates of box 2 CMP a3,v1 ;Shhh.... it's a secret CMPLE a4,v2 CMPLE a1,ip CMPLE a2,lr MOVLE a1,#1 ;If intersection, return TRUE MOVGT a1,#0 ;Otherwise return FALSE LDMFD sp!,{v1,v2,pc}^ ;Return to caller ;----- That's all, folks ---------------------------------------------------- END