LISTING 1 - Assembly Portion of Matrix.library 1 ; 2 ; MatrixLib.a - shared library assembly header 3 ; 4 ; Contains the Resident and Library structures, jump vector table, 5 ; user data, and function stub routines 6 ; 7 ; This code is FREELY DISTRIBUTABLE but NOT PUBLIC DOMAIN 8 ; (Written by Randy Finch) 9 ; 10 11 VERSION equ 1 12 REVISION equ 0 13 14 CSECT text 15 16 XDEF _LibName,_LibID,_SysBase,_MathIeeeDoubBasBase 17 18 ; Library C functions to be accessed from assembly 19 20 XREF _CInit 21 XREF _LibOpen 22 XREF _LibClose 23 XREF _LibExpunge 24 25 ; User C functions to be accessed from assembly 26 27 XREF _AllocLVector 28 XREF _AllocLMatrix 29 XREF _FreeLVector 30 XREF _FreeLMatrix 31 XREF _AddLVectors 32 XREF _SubLVectors 33 XREF _AddLMatrices 34 XREF _SubLMatrices 35 XREF _MultLMatrices 36 XREF _MultLVectorMatrix 37 XREF _MultLMatrixVector 38 XREF _TransposeLMatrix 39 40 XREF _AllocDVector 41 XREF _AllocDMatrix 42 XREF _FreeDVector 43 XREF _FreeDMatrix 44 XREF _AddDVectors 45 XREF _SubDVectors 46 XREF _AddDMatrices 47 XREF _SubDMatrices 48 XREF _MultDMatrices 49 XREF _MultDVectorMatrix 50 XREF _MultDMatrixVector 51 XREF _TransposeDMatrix 52 53 XREF _InvertDMatrix ;no equivalent for LONG 54 ;for obvious reasons 55 56 57 ; In case we are executed as a program 58 59 Start: clr.l D0 60 rts 61 62 ; romtag (or Resident) structure - 63 ; Exec looks for $4AFC followed by a pointer to it near the 64 ; beginning of load point. 65 ; Lets Exec know how to set up library. 66 67 InitDesc: dc.w $4AFC ;RTC_MATCHWORD 68 dc.l InitDesc ;Pointer to beginning 69 dc.l EndCode ;Not sure it matters 70 dc.b 0 ;flags (NO RTF_AUTOINIT) 71 dc.b VERSION ;version 72 dc.b 9 ;NT_LIBRARY 73 dc.b 0 ;priority (doesn't matter) 74 dc.l _LibName ;Name of library (given below) 75 dc.l _LibID ;ID string (note CR-LF at end below) 76 dc.l Init ;Pointer to init routine 77 78 _LibName: dc.b "Matrix.library",0 79 _LibID: dc.b "Matrix.library 1.00 (21 Jan 1990)",13,10,0 80 81 ; Force word alignment 82 83 ds.w 0 84 85 ; Here is the function list or jump vectors. 86 ; If you use MakeLibrary() this is not needed, but a table of vectors 87 ; must be passed to MakeLibrary() which allocates space for the jump 88 ; vectors. 89 90 Funcs: 91 92 ; First the user functions - reverse order from .fd file 93 94 jmp AInvertDMatrix ;no equivalent for LONG 95 96 jmp ATransposeDMatrix 97 jmp AMultDMatrixVector 98 jmp AMultDVectorMatrix 99 jmp AMultDMatrices 100 jmp ASubDMatrices 101 jmp AAddDMatrices 102 jmp ASubDVectors 103 jmp AAddDVectors 104 jmp AFreeDMatrix 105 jmp AFreeDVector 106 jmp AAllocDMatrix 107 jmp AAllocDVector 108 109 jmp ATransposeLMatrix 110 jmp AMultLMatrixVector 111 jmp AMultLVectorMatrix 112 jmp AMultLMatrices 113 jmp ASubLMatrices 114 jmp AAddLMatrices 115 jmp ASubLVectors 116 jmp AAddLVectors 117 jmp AFreeLMatrix 118 jmp AFreeLVector 119 jmp AAllocLMatrix 120 jmp AAllocLVector 121 122 ; System functions are always here in this order 123 124 jmp ALibReserved ;Not used at this time 125 jmp ALibExpunge ;For removing library 126 jmp ALibClose ;Guess what? Close the library 127 jmp ALibOpen ;Right again! Open the library 128 129 ; Here is the Library structure. Must be at this location, just 130 ; after the jump vectors. This must be initialized if not using 131 ; MakeLibrary(). 132 133 Lib: 134 135 ; First five items make up the Node structure which is the first 136 ; data item in the Library structure. 137 138 dc.l 0 ;ln_Succ (next node) 139 dc.l 0 ;ln_Pred (previous node) 140 dc.b 9 ;ln_Type (NT_LIBRARY) 141 dc.b 0 ;ln_Pri (priority) 142 dc.l _LibName ;ln_Name (Library name) 143 144 ; The next nine items make up the remainder of the Library structure 145 146 dc.b 6 ;lib_Flags (LIBF_CHANGED | LIBF_SUMUSED) 147 dc.b 0 ;lib_pad 148 149 ; The next value will change when the number of user functions change. 150 151 dc.w Lib-Funcs ;lib_NegSize (size of jump vectors) 152 ; (6 bytes per vector) 153 154 ; The next value will change when the number of user data items change. 155 ; The value is (Library structure size)+(User data size) = 34+User. 156 157 dc.w EndData-Lib ;lib_PosSize (size of data) 158 159 dc.w VERSION ;lib_Version 160 dc.w REVISION ;lib_Revision 161 dc.l _LibID ;lib_IdString 162 dc.l 0 ;lib_Sum (the checksum) 163 dc.w 0 ;lib_OpenCnt (number of opens on lib) 164 165 ; User data can be placed here. If you are using C, only the data needed 166 ; in assembly code needed here. Make sure all user data appears before 167 ; the EndData label so lib_PosSize will be correct. 168 169 _seglist: dc.l 0 170 _SysBase: dc.l 0 171 _MathIeeeDoubBasBase: dc.l 0 172 173 ; EndData label only used for data size in lib_PosSize above 174 175 EndData: 176 177 ; Initialization routine - 178 ; This is only called once - when the library is first loaded. 179 ; Exec passes the load point or seglist of the library in A0. 180 ; Since we are not auto init, the Library structure pointer, Lib, must 181 ; be passed to the C routine so AddLibrary() can be called. 182 183 Init: move.l A6,_SysBase ;Save A6 (SysBase) 184 move.l A0,_seglist ;Save segment list 185 lea Lib,A1 ;Bring in Library base 186 move.l A1,-(sp) ;Put Library base on stack 187 jsr _CInit ;Call our C init routine 188 addq.l #4,sp ;Reset the stack pointer 189 rts 190 191 ; Open routine - 192 ; This is called each time an application opens the library. 193 ; Just set up stack here and call the C routine. 194 195 ALibOpen: move.l D0,-(sp) ;Put version number on the stack 196 move.l A6,-(sp) ;Put Library base on stack 197 jsr _LibOpen ;Call our C routine 198 addq.l #8,sp ;Adjust the stack 199 rts 200 201 ; Close routine - 202 ; This is called each time an application closes the library. 203 ; Again, just set up stack and call the C routine. 204 205 ALibClose: move.l A6,-(sp) ;Put Library base on stack 206 jsr _LibClose ;Call our C routine 207 addq.l #4,sp ;Adjust the stack 208 rts 209 210 ; Expunge routine - 211 ; When all applications that opened the library have also closed the 212 ; library, this routine is called to clean up and unload the library. 213 ; Again, set up stack and call the C routine. 214 215 ALibExpunge: 216 move.l A6,-(sp) ;Put Library base on stack 217 jsr _LibExpunge ;Call our C routine 218 addq.l #4,sp ;Adjust the stack 219 rts 220 221 ; This is a reserved routine and not used at this time. 222 223 ALibReserved: 224 clr.l 0 225 rts 226 227 ; User routines - 228 ; Again these are used to set up the stack to call our C functions. 229 ; When the routines are called, the arguments will be in registers. 230 ; These arguments must be put on the stack before executing the C function. 231 ; The stack will be adjusted by 4 for each argument after returning from 232 ; the C function. 233 ; Arguments are placed on the stack from right to left. 234 235 ; Here are the setup routines for the LONG functions 236 237 AAllocLVector: 238 move.l D0,-(sp) 239 jsr _AllocLVector 240 addq.l #4,sp 241 rts 242 243 AAllocLMatrix: 244 movem.l D0-D1,-(sp) 245 jsr _AllocLMatrix 246 addq.l #8,sp 247 rts 248 249 AFreeLVector: 250 move.l D0,-(sp) 251 move.l A0,-(sp) 252 jsr _FreeLVector 253 addq.l #8,sp 254 rts 255 256 AFreeLMatrix: 257 movem.l D0-D1,-(sp) 258 move.l A0,-(sp) 259 jsr _FreeLMatrix 260 add.l #12,sp 261 rts 262 263 AAddLVectors: 264 move.l D0,-(sp) 265 movem.l A0-A2,-(sp) 266 jsr _AddLVectors 267 add.l #16,sp 268 rts 269 270 ASubLVectors: 271 move.l D0,-(sp) 272 movem.l A0-A2,-(sp) 273 jsr _SubLVectors 274 add.l #16,sp 275 rts 276 277 AAddLMatrices: 278 movem.l D0-D1,-(sp) 279 movem.l A0-A2,-(sp) 280 jsr _AddLMatrices 281 add.l #20,sp 282 rts 283 284 ASubLMatrices: 285 movem.l D0-D1,-(sp) 286 movem.l A0-A2,-(sp) 287 jsr _SubLMatrices 288 add.l #20,sp 289 rts 290 291 AMultLMatrices: 292 movem.l D0-D2,-(sp) 293 movem.l A0-A2,-(sp) 294 jsr _MultLMatrices 295 add.l #24,sp 296 rts 297 298 AMultLVectorMatrix: 299 movem.l D0-D1,-(sp) 300 movem.l A0-A2,-(sp) 301 jsr _MultLVectorMatrix 302 add.l #20,sp 303 rts 304 305 AMultLMatrixVector: 306 movem.l D0-D1,-(sp) 307 movem.l A0-A2,-(sp) 308 jsr _MultLMatrixVector 309 add.l #20,sp 310 rts 311 312 ATransposeLMatrix: 313 movem.l D0-D1,-(sp) 314 movem.l A0-A1,-(sp) 315 jsr _TransposeLMatrix 316 add.l #16,sp 317 rts 318 319 ; Here are the setup routines for the DOUBLE functions 320 321 AAllocDVector: 322 movem.l D0,-(sp) 323 jsr _AllocDVector 324 addq.l #4,sp 325 rts 326 327 AAllocDMatrix: 328 movem.l D0-D1,-(sp) 329 jsr _AllocDMatrix 330 addq.l #8,sp 331 rts 332 333 AFreeDVector: 334 move.l D0,-(sp) 335 move.l A0,-(sp) 336 jsr _FreeDVector 337 addq.l #8,sp 338 rts 339 340 AFreeDMatrix: 341 movem.l D0-D1,-(sp) 342 move.l A0,-(sp) 343 jsr _FreeDMatrix 344 add.l #12,sp 345 rts 346 347 AAddDVectors: 348 move.l D0,-(sp) 349 movem.l A0-A2,-(sp) 350 jsr _AddDVectors 351 add.l #16,sp 352 rts 353 354 ASubDVectors: 355 move.l D0,-(sp) 356 movem.l A0-A2,-(sp) 357 jsr _SubDVectors 358 add.l #16,sp 359 rts 360 361 AAddDMatrices: 362 movem.l D0-D1,-(sp) 363 movem.l A0-A2,-(sp) 364 jsr _AddDMatrices 365 add.l #20,sp 366 rts 367 368 ASubDMatrices: 369 movem.l D0-D1,-(sp) 370 movem.l A0-A2,-(sp) 371 jsr _SubDMatrices 372 add.l #20,sp 373 rts 374 375 AMultDMatrices: 376 movem.l D0-D2,-(sp) 377 movem.l A0-A2,-(sp) 378 jsr _MultDMatrices 379 add.l #24,sp 380 rts 381 382 AMultDVectorMatrix: 383 movem.l D0-D1,-(sp) 384 movem.l A0-A2,-(sp) 385 jsr _MultDVectorMatrix 386 add.l #20,sp 387 rts 388 389 AMultDMatrixVector: 390 movem.l D0-D1,-(sp) 391 movem.l A0-A2,-(sp) 392 jsr _MultDMatrixVector 393 add.l #20,sp 394 rts 395 396 ATransposeDMatrix: 397 movem.l D0-D1,-(sp) 398 movem.l A0-A1,-(sp) 399 jsr _TransposeDMatrix 400 add.l #16,sp 401 rts 402 403 AInvertDMatrix: 404 move.l D0,-(sp) 405 movem.l A0-A2,-(sp) 406 jsr _InvertDMatrix 407 add.l #16,sp 408 rts 409 410 EndCode: 411 END