- Timestamp:
- 07/01/2017 02:34:46 PM (7 years ago)
- Branches:
- master
- Children:
- 08e1da1
- Parents:
- f40a309
- Location:
- lib700
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
lib700/aldiv.s
rf40a309 r4f508e6 1 * 2 *aldiv.s -- indirect long divide3 *Version 1 -- 1989-01-24 -- D.N. Lynx Crowe4 * 1 2 | aldiv.s -- indirect long divide 3 | Version 1 -- 1989-01-24 -- D.N. Lynx Crowe 4 5 5 .text 6 * 6 7 7 .xdef aldiv 8 8 .xdef _aldiv 9 * 9 10 10 .xref _ldiv 11 * 11 12 12 aldiv: 13 13 _aldiv: 14 * 14 15 15 link a6,#-2 16 16 move.l 12(a6),-(a7) … … 23 23 unlk a6 24 24 rts 25 * 25 26 26 .end -
lib700/almul.s
rf40a309 r4f508e6 1 * 2 *almul.s -- indirect long multiply3 *Version 1 -- 1989-01-24 -- D.N. Lynx Crowe4 * 1 2 | almul.s -- indirect long multiply 3 | Version 1 -- 1989-01-24 -- D.N. Lynx Crowe 4 5 5 .text 6 * 6 7 7 .xdef almul 8 * 8 9 9 .xref lmul 10 * 10 11 11 almul: move.l a5,-(a7) 12 12 movea.l 8(a7),a5 … … 18 18 movea.l (a7)+,a5 19 19 rts 20 * 20 21 21 .end -
lib700/alrem.s
rf40a309 r4f508e6 1 * 2 *alrem.s -- indirect long modulus3 *Version 1 -- 1989-01-24 -- D.N. Lynx Crowe4 * 1 2 | alrem.s -- indirect long modulus 3 | Version 1 -- 1989-01-24 -- D.N. Lynx Crowe 4 5 5 .text 6 * 6 7 7 .xdef alrem 8 8 .xdef _alrem 9 * 9 10 10 .xref _ldiv 11 11 .xref _ldivr 12 * 12 13 13 alrem: 14 14 _alrem: 15 * 15 16 16 link a6,#-2 17 17 move.l 12(a6),-(a7) … … 25 25 unlk a6 26 26 rts 27 * 27 28 28 .end -
lib700/blkfill.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *blkfill.s -- block fill function3 *Version 1 -- 1987-08-28 -- D.N. Lynx Crowe4 * 5 *void6 *blkfill(where, what, count)7 * char *where;8 *char what;9 *short count;10 * 11 *Fills 'count' bytes at 'where' with 'what'.12 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | blkfill.s -- block fill function 3 | Version 1 -- 1987-08-28 -- D.N. Lynx Crowe 4 5 | void 6 | blkfill(where, what, count) 7 | char |where; 8 | char what; 9 | short count; 10 11 | Fills 'count' bytes at 'where' with 'what'. 12 | ------------------------------------------------------------------------------ 13 13 .text 14 * 14 15 15 .xdef _blkfill 16 * 16 17 17 _blkfill: link a6,#0 18 18 movem.l d5-d7/a5-a5,-(a7) … … 21 21 move.w 14(a6),d6 22 22 bra blkf2 23 * 23 24 24 blkf1: move.b d7,(a5)+ 25 * 25 26 26 blkf2: move.w d6,d0 27 27 subq.w #1,d6 28 28 tst.w d0 29 29 bgt blkf1 30 * 30 31 31 tst (a7)+ 32 32 movem.l (a7)+,d6-d7/a5-a5 33 33 unlk a6 34 34 rts 35 * 35 36 36 .end -
lib700/blkmove.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *blkmove.s -- block move function3 *Version 1 -- 1987-08-28 -- D.N. Lynx Crowe4 * 5 *void6 *blkmove(to, from, n)7 * char *to, *from;8 *short n;9 * 10 *Copies 'n' bytes from address 'from' to address 'to'.11 *Treats overlaps of from and to areas intelligently.12 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | blkmove.s -- block move function 3 | Version 1 -- 1987-08-28 -- D.N. Lynx Crowe 4 5 | void 6 | blkmove(to, from, n) 7 | char |to, |from; 8 | short n; 9 10 | Copies 'n' bytes from address 'from' to address 'to'. 11 | Treats overlaps of from and to areas intelligently. 12 | ------------------------------------------------------------------------------ 13 13 .text 14 * 14 15 15 .xdef _blkmove 16 * 17 _blkmove: link a6,# $FFFC16 17 _blkmove: link a6,#-4 18 18 move.l 8(a6),d0 19 19 cmp.l 12(a6),d0 20 20 bcc blkm3 21 * 21 22 22 bra blkm2 23 * 23 24 24 blkm1: movea.l 8(a6),a0 25 25 movea.l 12(a6),a1 … … 27 27 addq.l #1,8(a6) 28 28 addq.l #1,12(a6) 29 * 29 30 30 blkm2: move.w 16(a6),d0 31 31 subq.w #1,16(a6) 32 32 tst.w d0 33 33 bne blkm1 34 * 34 35 35 bra blkm6 36 * 36 37 37 blkm3: move.w 16(a6),d0 38 38 ext.l d0 … … 40 40 add.l d0,12(a6) 41 41 bra blkm5 42 * 42 43 43 blkm4: subq.l #1,8(a6) 44 44 subq.l #1,12(a6) … … 46 46 movea.l 12(a6),a1 47 47 move.b (a1),(a0) 48 * 48 49 49 blkm5: move.w 16(a6),d0 50 50 subq.w #1,16(a6) 51 51 tst.w d0 52 52 bne blkm4 53 * 53 54 54 blkm6: unlk a6 55 55 rts 56 * 56 57 57 .end -
lib700/finalone.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *finalone.s -- the last stuff to get loaded3 *Version 4 -- 1987-06-30 -- D.N. Lynx Crowe4 * 5 *This is so we can figure out where things got loaded.6 *------------------------------------------------------------------------------7 * 1 | ------------------------------------------------------------------------------ 2 | finalone.s -- the last stuff to get loaded 3 | Version 4 -- 1987-06-30 -- D.N. Lynx Crowe 4 5 | This is so we can figure out where things got loaded. 6 | ------------------------------------------------------------------------------ 7 8 8 .text 9 * 9 10 10 .xdef FinalOne 11 11 .xdef The_Fini 12 12 .xdef Text_End 13 * 14 * 15 *This is the last piece of code in the 'text' segment.16 * 17 FinalOne: rts *we just need the address here18 * 19 Text_End: rts *we just need the address here20 * 21 *------------------------------------------------------------------------------22 * 13 14 15 | This is the last piece of code in the 'text' segment. 16 17 FinalOne: rts | we just need the address here 18 19 Text_End: rts | we just need the address here 20 21 | ------------------------------------------------------------------------------ 22 23 23 .data 24 24 .even 25 * 26 The_Fini: dc.w $FFFF *last thing in the 'data' segment27 * 28 *------------------------------------------------------------------------------29 * 25 26 The_Fini: dc.w 0xFFFF | last thing in the 'data' segment 27 28 | ------------------------------------------------------------------------------ 29 30 30 .end -
lib700/jumpto.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *jumpto.s -- miscellaneous ROMP support functions3 *Version 4 -- 1987-10-14 -- D.N. Lynx Crowe4 * 5 *WARNING:6 *--------7 *These functions, in general, assume supervisor mode and8 *'sane' arguments, so no error checking is done.9 * 10 *halt()11 * 12 *Brings the processor to a grinding halt. Requires external13 *reset to restart things. Use only for catastrophic hard halts.14 * 15 *jumpto(addr)16 *long addr;17 * 18 *Jumps to 'addr'. No error check is done on 'addr'.19 * 20 *rjumpto(addr)21 *long addr;22 * 23 *Performs the 68000 'RESET' command, then jumps to 'addr'.24 *No error check is made on 'addr'.25 * 26 *sjumpto(addr, stack)27 *long addr, stack;28 * 29 *Sets a7 to 'stack', then jumps to 'addr'.30 *No error check is done on 'addr'.31 * 32 *xreset()33 * 34 *Performs the 68000 'RESET' command. This is very dangerous,35 *and should be used with extreme care regarding such36 *things as interrupts, device initialization, vectors,37 *and sundry other reset-related things.38 * 39 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | jumpto.s -- miscellaneous ROMP support functions 3 | Version 4 -- 1987-10-14 -- D.N. Lynx Crowe 4 5 | WARNING: 6 | -------- 7 | These functions, in general, assume supervisor mode and 8 | 'sane' arguments, so no error checking is done. 9 10 | halt() 11 12 | Brings the processor to a grinding halt. Requires external 13 | reset to restart things. Use only for catastrophic hard halts. 14 15 | jumpto(addr) 16 | long addr; 17 18 | Jumps to 'addr'. No error check is done on 'addr'. 19 20 | rjumpto(addr) 21 | long addr; 22 23 | Performs the 68000 'RESET' command, then jumps to 'addr'. 24 | No error check is made on 'addr'. 25 26 | sjumpto(addr, stack) 27 | long addr, stack; 28 29 | Sets a7 to 'stack', then jumps to 'addr'. 30 | No error check is done on 'addr'. 31 32 | xreset() 33 34 | Performs the 68000 'RESET' command. This is very dangerous, 35 | and should be used with extreme care regarding such 36 | things as interrupts, device initialization, vectors, 37 | and sundry other reset-related things. 38 39 | ------------------------------------------------------------------------------ 40 40 .text 41 * 41 42 42 .xdef _halt,_jumpto,_rjumpto,_sjumpto,_xreset 43 * 43 44 44 .page 45 * 46 _halt: stop # $2700 *stop dead, interrupts disabled47 jmp _halt *stay stopped if stepped thru48 * 49 _jumpto: movea.l 4(a7),a0 *get jump address50 jmp (a0) *go to the jump address51 * 52 _rjumpto: reset *reset external devices53 movea.l 4(a7),a0 *get jump address54 jmp (a0) *go to the jump address55 * 56 _sjumpto: movea.l 4(a7),a0 *get jump address57 movea.l 8(a7),a7 *set stack pointer58 jmp (a0) *go to the jump address59 * 60 _xreset: reset *reset external devices61 rts *return to caller62 * 45 46 _halt: stop #0x2700 | stop dead, interrupts disabled 47 jmp _halt | stay stopped if stepped thru 48 49 _jumpto: movea.l 4(a7),a0 | get jump address 50 jmp (a0) | go to the jump address 51 52 _rjumpto: reset | reset external devices 53 movea.l 4(a7),a0 | get jump address 54 jmp (a0) | go to the jump address 55 56 _sjumpto: movea.l 4(a7),a0 | get jump address 57 movea.l 8(a7),a7 | set stack pointer 58 jmp (a0) | go to the jump address 59 60 _xreset: reset | reset external devices 61 rts | return to caller 62 63 63 .end -
lib700/ldiv.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *ldiv.s -- long division3 *Version 1 -- 1988-01-224 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | ldiv.s -- long division 3 | Version 1 -- 1988-01-22 4 | ------------------------------------------------------------------------------ 5 5 .text 6 * 6 7 7 .xdef _ldiv 8 8 .xdef ldiv 9 * 9 10 10 .xdef _ldivr 11 * 12 ARG1 .equ813 ARG2 .equ1214 * 11 12 ARG1 = 8 13 ARG2 = 12 14 15 15 _ldiv: 16 16 ldiv: link a6,#-2 … … 21 21 move.l ARG2(a6),d6 22 22 bne ldiv1 23 * 24 move.l # $80000000,_ldivr25 move.l # $80000000,d023 24 move.l #0x80000000,_ldivr 25 move.l #0x80000000,d0 26 26 divs #0,d0 27 27 bra ldiv11 28 * 28 29 29 ldiv1: bge ldiv2 30 * 30 31 31 neg.l d6 32 32 addq.w #1,d3 33 * 33 34 34 ldiv2: tst.l d7 35 35 bge ldiv3 36 * 36 37 37 neg.l d7 38 38 addq.w #1,d3 39 * 39 40 40 ldiv3: cmp.l d7,d6 41 41 bgt ldiv9 42 * 42 43 43 bne ldiv4 44 * 44 45 45 moveq.l #1,d5 46 46 clr.l d7 47 47 bra ldiv9 48 * 49 ldiv4: cmp.l # $10000,d748 49 ldiv4: cmp.l #0x10000,d7 50 50 bge ldiv5 51 * 51 52 52 divu d6,d7 53 53 move.w d7,d5 … … 55 55 ext.l d7 56 56 bra ldiv9 57 * 57 58 58 ldiv5: moveq.l #1,d4 59 * 59 60 60 ldiv6: cmp.l d6,d7 61 61 bcs ldiv7 62 * 62 63 63 asl.l #1,d6 64 64 asl.l #1,d7 65 65 bra ldiv6 66 * 66 67 67 ldiv7: tst.l d4 68 68 beq ldiv9 69 * 69 70 70 cmp.l d6,d7 71 71 bcs ldiv8 72 * 72 73 73 or.l d4,d5 74 74 sub.l d6,d7 75 * 75 76 76 ldiv8: lsr.l #1,d4 77 77 lsr.l #1,d6 78 78 bra ldiv7 79 * 79 80 80 ldiv9: cmp.w #1,d3 81 81 bne ldiv10 82 * 82 83 83 neg.l d7 84 84 move.l d7,_ldivr … … 86 86 neg.l d0 87 87 bra ldiv11 88 * 88 89 89 ldiv10: move.l d7,_ldivr 90 90 move.l d5,d0 91 * 91 92 92 ldiv11: tst.l (a7)+ 93 93 movem.l (a7)+,d3-d7 94 94 unlk a6 95 95 rts 96 * 96 97 97 .bss 98 * 98 99 99 _ldivr: .ds.l 1 100 * 100 101 101 .end -
lib700/lmul.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *lmul.s -- long multiply3 *Version 2 -- 1989-07-184 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | lmul.s -- long multiply 3 | Version 2 -- 1989-07-18 4 | ------------------------------------------------------------------------------ 5 5 .text 6 * 6 7 7 .xdef lmul 8 * 9 ARG1 .equ810 ARG2 .equ1211 * 12 TEMP .equ-413 * 8 9 ARG1 = 8 10 ARG2 = 12 11 12 TEMP = -4 13 14 14 lmul: link a6,#-4 15 15 clr.w d2 16 16 tst.l ARG1(a6) 17 17 bge lmul1 18 * 18 19 19 neg.l ARG1(a6) 20 20 addq.w #1,d2 21 * 21 22 22 lmul1: tst.l ARG2(a6) 23 23 bge lmul2 24 * 24 25 25 neg.l ARG2(a6) 26 26 addq.w #1,d2 27 * 27 28 28 lmul2: move.w ARG1+2(a6),d0 29 29 mulu ARG2+2(a6),d0 … … 39 39 btst #0,d2 40 40 beq lmul3 41 * 41 42 42 neg.l d0 43 * 43 44 44 lmul3: unlk a6 45 45 rts 46 * 46 47 47 .end -
lib700/lrem.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *lrem.s -- long modulo3 *Version 1 -- 1988-01-224 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | lrem.s -- long modulo 3 | Version 1 -- 1988-01-22 4 | ------------------------------------------------------------------------------ 5 5 .text 6 * 6 7 7 .xdef _lrem 8 8 .xdef lrem 9 * 9 10 10 .xref ldiv 11 11 .xref _ldivr 12 * 13 ARG1 .equ814 ARG2 .equ1215 * 12 13 ARG1 = 8 14 ARG2 = 12 15 16 16 _lrem: 17 17 lrem: link a6,#-2 … … 23 23 unlk a6 24 24 rts 25 * 25 26 26 .end -
lib700/rand24.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *rand24.s -- generate a 24 bit random number3 *Version 3 -- 1988-04-29 -- D.N. Lynx Crowe4 *------------------------------------------------------------------------------5 *Synopsis:6 *long7 *rand24()8 * 9 *Based on:10 *Knuth, Donald E.11 *The Art of Computer Programming,12 *Volume 2: Semi-Numerical Algorithms13 * 14 *Computes:15 * S = [S *C] + K16 * 17 *Where:18 *K = 119 *C = 314159262120 *S = the seed (if zero, it gets set from the 200 Hz clock)21 * 22 *Returns:23 *S >> 8 (a 24 bit pseudo-random number)24 * 25 *Note: this function has an LSB with an exactly 50% distribution, so using26 *individual bits is probably not a good idea. Using more bits makes things27 *appear more random.28 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | rand24.s -- generate a 24 bit random number 3 | Version 3 -- 1988-04-29 -- D.N. Lynx Crowe 4 | ------------------------------------------------------------------------------ 5 | Synopsis: 6 | long 7 | rand24() 8 9 | Based on: 10 | Knuth, Donald E. 11 | The Art of Computer Programming, 12 | Volume 2: Semi-Numerical Algorithms 13 14 | Computes: 15 | S = [S | C] + K 16 17 | Where: 18 | K = 1 19 | C = 3141592621 20 | S = the seed (if zero, it gets set from the 200 Hz clock) 21 22 | Returns: 23 | S >> 8 (a 24 bit pseudo-random number) 24 25 | Note: this function has an LSB with an exactly 50% distribution, so using 26 | individual bits is probably not a good idea. Using more bits makes things 27 | appear more random. 28 | ------------------------------------------------------------------------------ 29 29 .text 30 * 30 31 31 .xdef _rand24 32 * 32 33 33 .xdef _rseed 34 * 35 *equates for things in the BIOS36 * 37 RCLOCK .equ $49E *LONG - 200 Hz clock38 * 39 *equates for stack offsets40 * 41 ARG1 .equ 8 *LONG / WORD - arg1 / MS bits42 ARG1L .equ 10 *WORD - arg1 LS bits43 ARG2 .equ 12 *LONG / WORD - arg2 / MS bits44 ARG2L .equ 14 *WORD - arg2 LS bits45 * 46 PART .equ -4 *LONG - partial product47 * 48 PI .equ $BB40E62D *LONG - PI as a hex value49 * 34 35 | equates for things in the BIOS 36 37 RCLOCK = 0x49E | LONG - 200 Hz clock 38 39 | equates for stack offsets 40 41 ARG1 = 8 | LONG / WORD - arg1 / MS bits 42 ARG1L = 10 | WORD - arg1 LS bits 43 ARG2 = 12 | LONG / WORD - arg2 / MS bits 44 ARG2L = 14 | WORD - arg2 LS bits 45 46 PART = -4 | LONG - partial product 47 48 PI = 0xBB40E62D | LONG - PI as a hex value 49 50 50 .page 51 * 52 *mult32 -- 32 bit signed multiply53 *------ ----------------------54 mult32: link a6,#-4 *link stack frames55 clr.w d2 *clear sign flags56 tst.l ARG1(a6) *check sign of 1st argument57 bge mult32a *...58 * 59 neg.l ARG1(a6) *make 1st argument positive60 addq.w #1,d2 *log its sign as negative61 * 62 mult32a: tst.l ARG2(a6) *check sign of 2nd argument63 bge mult32b *...64 * 65 neg.l ARG2(a6) *make 2nd argument positive66 addq.w #1,d2 *log its sign as negative67 * 68 mult32b: move.w ARG1L(a6),d0 *generate 1st partial product69 mulu ARG2L(a6),d0 *...70 move.l d0,PART(a6) *...71 move.w ARG1(a6),d0 *generate 2nd partial product72 mulu ARG2L(a6),d0 *...73 move.w ARG2(a6),d1 *generate 3rd partial product74 mulu ARG1L(a6),d1 *...75 add.w d1,d0 *add partial products76 add.w PART(a6),d0 *...77 move.w d0,PART(a6) *...78 move.l PART(a6),d0 *...79 btst #0,d2 *adjust sign of result80 beq mult32c *...81 * 82 neg.l d0 *...83 * 84 mult32c: unlk a6 *unlink stack frames85 rts *return86 * 51 52 | mult32 -- 32 bit signed multiply 53 | ------ ---------------------- 54 mult32: link a6,#-4 | link stack frames 55 clr.w d2 | clear sign flags 56 tst.l ARG1(a6) | check sign of 1st argument 57 bge mult32a | ... 58 59 neg.l ARG1(a6) | make 1st argument positive 60 addq.w #1,d2 | log its sign as negative 61 62 mult32a: tst.l ARG2(a6) | check sign of 2nd argument 63 bge mult32b | ... 64 65 neg.l ARG2(a6) | make 2nd argument positive 66 addq.w #1,d2 | log its sign as negative 67 68 mult32b: move.w ARG1L(a6),d0 | generate 1st partial product 69 mulu ARG2L(a6),d0 | ... 70 move.l d0,PART(a6) | ... 71 move.w ARG1(a6),d0 | generate 2nd partial product 72 mulu ARG2L(a6),d0 | ... 73 move.w ARG2(a6),d1 | generate 3rd partial product 74 mulu ARG1L(a6),d1 | ... 75 add.w d1,d0 | add partial products 76 add.w PART(a6),d0 | ... 77 move.w d0,PART(a6) | ... 78 move.l PART(a6),d0 | ... 79 btst #0,d2 | adjust sign of result 80 beq mult32c | ... 81 82 neg.l d0 | ... 83 84 mult32c: unlk a6 | unlink stack frames 85 rts | return 86 87 87 .page 88 * 89 *_rand24 -- Generate a random number90 *------- ------------------------91 _rand24: link a6,#0 *Link stack frames92 tst.l _rseed *See if the seed is zero93 bne rand01 *Jump if not94 * 95 move.l RCLOCK,d0 *Pick up the 200 Hz clock96 moveq.l #16,d1 *Shift it left97 asl.l d1,d0 *...98 or.l RCLOCK,d0 *OR in current 200 Hz clock99 move.l d0,_rseed *Use that as the seed100 * 101 rand01: move.l #PI,-(a7) *Put PI on the stack102 move.l _rseed,-(a7) *... and _rseed, too103 bsr mult32 *Multiply them104 addq.l #8,a7 *Cleanup stack105 addq.l #1,d0 *Add 1 to the result106 move.l d0,_rseed *Save as new seed107 asr.l #8,d0 *Make it a 24 bit number108 and.l # $00FFFFFF,d0 *...109 unlk a6 *Unlink stack frames110 rts *Return to caller111 * 112 *------------------------------------------------------------------------------88 89 | _rand24 -- Generate a random number 90 | ------- ------------------------ 91 _rand24: link a6,#0 | Link stack frames 92 tst.l _rseed | See if the seed is zero 93 bne rand01 | Jump if not 94 95 move.l RCLOCK,d0 | Pick up the 200 Hz clock 96 moveq.l #16,d1 | Shift it left 97 asl.l d1,d0 | ... 98 or.l RCLOCK,d0 | OR in current 200 Hz clock 99 move.l d0,_rseed | Use that as the seed 100 101 rand01: move.l #PI,-(a7) | Put PI on the stack 102 move.l _rseed,-(a7) | ... and _rseed, too 103 bsr mult32 | Multiply them 104 addq.l #8,a7 | Cleanup stack 105 addq.l #1,d0 | Add 1 to the result 106 move.l d0,_rseed | Save as new seed 107 asr.l #8,d0 | Make it a 24 bit number 108 and.l #0x00FFFFFF,d0 | ... 109 unlk a6 | Unlink stack frames 110 rts | Return to caller 111 112 | ------------------------------------------------------------------------------ 113 113 .bss 114 *------------------------------------------------------------------------------115 * 116 _rseed: .ds.l 1 *random number seed117 * 114 | ------------------------------------------------------------------------------ 115 116 _rseed: .ds.l 1 | random number seed 117 118 118 .end -
lib700/setjmp.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *setjmp.s -- Unix(tm) compatible setjmp(env) and longjmp(env,ret)3 *Version 3 -- 1987-06-16 -- D.N. Lynx Crowe4 *------------------------------------------------------------------------------5 * 1 | ------------------------------------------------------------------------------ 2 | setjmp.s -- Unix(tm) compatible setjmp(env) and longjmp(env,ret) 3 | Version 3 -- 1987-06-16 -- D.N. Lynx Crowe 4 | ------------------------------------------------------------------------------ 5 6 6 .text 7 * 7 8 8 .xdef _setjmp,_longjmp 9 * 10 _setjmp: movea.l 4(a7),a0 *Get env pointer11 move.l (a7),(a0) *Put return address in env12 movem.l d1-d7/a1-a7,4(a0) *Save registers in env13 moveq.l #0,d0 *Set return value to 014 rts *Return to caller15 * 16 _longjmp: move.w 8(a7),d0 *Get ret value17 bne lj1 *Jump if non-zero18 * 19 moveq.l #1,d0 *Force return value to 120 * 21 lj1: movea.l 4(a7),a0 *Get env pointer22 movem.l 4(a0),d1-d7/a1-a7 *Restore registers from env23 move.l (a0),(a7) *Get return address from env24 rts *Return to caller25 * 9 10 _setjmp: movea.l 4(a7),a0 | Get env pointer 11 move.l (a7),(a0) | Put return address in env 12 movem.l d1-d7/a1-a7,4(a0) | Save registers in env 13 moveq.l #0,d0 | Set return value to 0 14 rts | Return to caller 15 16 _longjmp: move.w 8(a7),d0 | Get ret value 17 bne lj1 | Jump if non-zero 18 19 moveq.l #1,d0 | Force return value to 1 20 21 lj1: movea.l 4(a7),a0 | Get env pointer 22 movem.l 4(a0),d1-d7/a1-a7 | Restore registers from env 23 move.l (a0),(a7) | Get return address from env 24 rts | Return to caller 25 26 26 .end -
lib700/uldiv.s
rf40a309 r4f508e6 1 *------------------------------------------------------------------------------2 *uldiv.s -- unsigned long division, with remainder3 *Version 2 -- 1987-06-08 -- D.N. Lynx Crowe4 *Lifted from the Alcyon C library by disassembly so I could fix a bug -5 *_uldivr must be in the bss segment so the code will work in PROM.6 * 7 *long8 *uldiv(dividnd, divisor)9 *long dividnd, divisor;10 * 11 *extern long uldivr;12 * 13 *Divides 'dividnd' by 'divisor', treating both as unsigned14 *long integers. Returns the quotient and leaves the15 *remainder in 'uldivr'. Produces a divide check on division16 * by zero, with $80000000 returned for both quotient and17 *remainder.18 *------------------------------------------------------------------------------1 | ------------------------------------------------------------------------------ 2 | uldiv.s -- unsigned long division, with remainder 3 | Version 2 -- 1987-06-08 -- D.N. Lynx Crowe 4 | Lifted from the Alcyon C library by disassembly so I could fix a bug - 5 | _uldivr must be in the bss segment so the code will work in PROM. 6 7 | long 8 | uldiv(dividnd, divisor) 9 | long dividnd, divisor; 10 11 | extern long uldivr; 12 13 | Divides 'dividnd' by 'divisor', treating both as unsigned 14 | long integers. Returns the quotient and leaves the 15 | remainder in 'uldivr'. Produces a divide check on division 16 | by zero, with 0x80000000 returned for both quotient and 17 | remainder. 18 | ------------------------------------------------------------------------------ 19 19 .text 20 * 20 21 21 .xdef _uldiv,_uldivr 22 * 23 DIVIDEND .equ824 DIVISOR .equ1225 * 26 _uldiv: link a6,#0 *Link stack frames27 movem.l d3-d7,-(a7) *Save registers28 move.l DIVIDEND(a6),d7 *d7 = DIVIDEND29 move.l DIVISOR(a6),d6 *d6 = DIVISOR30 tst.l d6 *Divide by zero ?31 bne notdzero *Jump if not32 * 33 move.l # $80000000,_uldivr *Force error result34 move.l # $80000000,d0 *... by dividing35 divu #0,d0 *... by zero36 bra ulexit *... then exit37 * 38 notdzero: cmp.l d7,d6 *Divide underflow ?39 bls notunflo *Jump if not40 * 41 move.l d7,_uldivr *Remainder = dividend42 clr.l d0 *Quotient = 043 bra ulexit *Exit44 * 45 notunflo: cmp.l d6,d7 *Is dividend = divisor ?46 bne startdiv *Go start dividing if not47 * 48 moveq.l #1,d5 *Quotient = 149 clr.l d7 *Remainder = 050 bra setreslt *Go set result51 * 22 23 DIVIDEND = 8 24 DIVISOR = 12 25 26 _uldiv: link a6,#0 | Link stack frames 27 movem.l d3-d7,-(a7) | Save registers 28 move.l DIVIDEND(a6),d7 | d7 = DIVIDEND 29 move.l DIVISOR(a6),d6 | d6 = DIVISOR 30 tst.l d6 | Divide by zero ? 31 bne notdzero | Jump if not 32 33 move.l #0x80000000,_uldivr | Force error result 34 move.l #0x80000000,d0 | ... by dividing 35 divu #0,d0 | ... by zero 36 bra ulexit | ... then exit 37 38 notdzero: cmp.l d7,d6 | Divide underflow ? 39 bls notunflo | Jump if not 40 41 move.l d7,_uldivr | Remainder = dividend 42 clr.l d0 | Quotient = 0 43 bra ulexit | Exit 44 45 notunflo: cmp.l d6,d7 | Is dividend = divisor ? 46 bne startdiv | Go start dividing if not 47 48 moveq.l #1,d5 | Quotient = 1 49 clr.l d7 | Remainder = 0 50 bra setreslt | Go set result 51 52 52 .page 53 * 54 startdiv: moveq.l #1,d4 *Set result bit in d455 * 56 divloop1: cmp.l d6,d7 *Divisor aligned OK ?57 bcs divloop2 *Jump if so58 * 59 move.l d6,d0 *Can we align things better ?60 asl.l #1,d0 *...61 cmp.l d0,d6 *...62 bhi divloop2 *Jump if not63 * 64 asl.l #1,d6 *Shift the divisor65 asl.l #1,d4 *Shift the result bit66 bra divloop1 *Loop for next bit67 * 68 divloop2: clr.l d5 *Clear quotient69 * 70 divloop3: tst.l d4 *More bits to do ?71 beq setreslt *Go set result if not72 * 73 cmp.l d6,d7 *Can we subtract ?74 bcs divloop4 *Jump if not75 * 76 or.l d4,d5 *Set a bit in the quotient77 sub.l d6,d7 *Subtract divisor from dividend78 * 79 divloop4: lsr.l #1,d4 *Shift the result bit80 lsr.l #1,d6 *Shift the divisor81 bra divloop3 *Loop for next bit82 * 83 setreslt: move.l d7,_uldivr *Store remainder84 move.l d5,d0 *Put quotient in d085 * 86 ulexit: tst.l (a7)+ *Discard top of stack87 movem.l (a7)+,d4-d7 *Restore registers88 unlk a6 *Unlink stack frames89 rts *Return to caller90 * 53 54 startdiv: moveq.l #1,d4 | Set result bit in d4 55 56 divloop1: cmp.l d6,d7 | Divisor aligned OK ? 57 bcs divloop2 | Jump if so 58 59 move.l d6,d0 | Can we align things better ? 60 asl.l #1,d0 | ... 61 cmp.l d0,d6 | ... 62 bhi divloop2 | Jump if not 63 64 asl.l #1,d6 | Shift the divisor 65 asl.l #1,d4 | Shift the result bit 66 bra divloop1 | Loop for next bit 67 68 divloop2: clr.l d5 | Clear quotient 69 70 divloop3: tst.l d4 | More bits to do ? 71 beq setreslt | Go set result if not 72 73 cmp.l d6,d7 | Can we subtract ? 74 bcs divloop4 | Jump if not 75 76 or.l d4,d5 | Set a bit in the quotient 77 sub.l d6,d7 | Subtract divisor from dividend 78 79 divloop4: lsr.l #1,d4 | Shift the result bit 80 lsr.l #1,d6 | Shift the divisor 81 bra divloop3 | Loop for next bit 82 83 setreslt: move.l d7,_uldivr | Store remainder 84 move.l d5,d0 | Put quotient in d0 85 86 ulexit: tst.l (a7)+ | Discard top of stack 87 movem.l (a7)+,d4-d7 | Restore registers 88 unlk a6 | Unlink stack frames 89 rts | Return to caller 90 91 91 .bss 92 92 .even 93 * 93 94 94 _uldivr: ds.l 1 95 * 95 96 96 .end
Note:
See TracChangeset
for help on using the changeset viewer.