2 ; Ullrich von Bassewitz, 20.09.1998
4 ; CC65 runtime: right shift support for longs
8 .export tosasreax, tosshreax
10 .importzp sp, sreg, ptr1, ptr2
12 ; --------------------------------------------------------------------
17 jsr getlhs ; Get the lhs from the stack
19 jsr checkovf ; Check for overflow
20 bcs L6 ; Jump if shift count too large
22 cpy #0 ; Shift count zero?
25 ; We must shift. Shift by multiples of eight if possible
43 ; Shift count is now less than eight. Do a real shift.
45 L3: tay ; Shift count to Y
46 lda ptr2+1 ; Get one byte into A for speed
48 beq L4a ; Jump if done
49 L4: cmp #$80 ; Get sign bit into C
57 ; Put the result in place
66 ; Jump here if shift count overflow
69 lda ptr2+1 ; Check sign
79 ; --------------------------------------------------------------------
84 jsr getlhs ; Get the lhs from the stack
86 jsr checkovf ; Check for overflow
87 bcs L6 ; Jump if shift count too large
89 cpy #0 ; Shift count zero?
92 ; We must shift. Shift by multiples of eight if possible
108 ; Shift count is now less than eight. Do a real shift.
110 L3: tay ; Shift count to Y
111 lda ptr2+1 ; Get one byte into A for speed
113 beq L4a ; Jump if done
121 ; Put the result in place
130 ; Jump here if shift count overflow
140 ; --------------------------------------------------------------------
143 .proc getlhs ; Get the lhs from stack into ptr1/ptr2
164 .proc checkovf ; Check for shift overflow
166 tay ; Low byte of shift count into y
169 ora sreg+1 ; Check high 24 bit
170 bne TooLarge ; Shift count too large