2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-07-05 22:24:06 +00:00
|
|
|
; Ullrich von Bassewitz, 1998-08-05, 2004-06-25
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-07-05 22:24:06 +00:00
|
|
|
; CC65 runtime: left shift support for ints and unsigneds
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2004-07-05 22:24:06 +00:00
|
|
|
; Note: The standard declares a shift count that is negative or >= the
|
|
|
|
; bitcount of the shifted type for undefined behaviour.
|
|
|
|
;
|
|
|
|
; Note^2: The compiler knowns about the register/zero page usage of this
|
|
|
|
; function, so you need to change the compiler source if you change it!
|
|
|
|
;
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
.export tosaslax, tosshlax
|
|
|
|
.import popax
|
|
|
|
.importzp tmp1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
tosshlax:
|
|
|
|
tosaslax:
|
2004-07-05 22:24:06 +00:00
|
|
|
and #$0F ; Bring the shift count into a valid range
|
|
|
|
sta tmp1 ; Save it
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
jsr popax ; Get the left hand operand
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
ldy tmp1 ; Get shift count
|
|
|
|
beq L9 ; Bail out if shift count zero
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
cpy #8 ; Shift count 8 or greater?
|
|
|
|
bcc L3 ; Jump if not
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
; Shift count is greater 7. The carry is set when we enter here.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
tax
|
|
|
|
tya
|
|
|
|
sbc #8
|
|
|
|
tay
|
|
|
|
txa
|
|
|
|
jmp L2
|
|
|
|
L1: asl a
|
|
|
|
L2: dey
|
|
|
|
bpl L1
|
|
|
|
tax
|
|
|
|
lda #$00
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
; Shift count is less than 8.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
L3: stx tmp1 ; Save high byte of lhs
|
|
|
|
L4: asl a
|
|
|
|
rol tmp1
|
|
|
|
dey
|
|
|
|
bne L4
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Done with shift
|
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
ldx tmp1
|
|
|
|
L9: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|