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
|
|
|
|
2012-07-06 19:56:42 +00:00
|
|
|
.export tosaslax, tosshlax, aslaxy, shlaxy
|
|
|
|
.import popax
|
|
|
|
.importzp tmp1
|
2012-06-24 22:04:00 +00:00
|
|
|
|
|
|
|
.macpack cpu
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
tosshlax:
|
|
|
|
tosaslax:
|
2012-07-06 19:56:42 +00:00
|
|
|
sta tmp1 ; Save shift count
|
2004-07-05 22:24:06 +00:00
|
|
|
jsr popax ; Get the left hand operand
|
|
|
|
ldy tmp1 ; Get shift count
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2012-06-24 22:04:00 +00:00
|
|
|
; Run into shlaxy
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2012-06-24 22:04:00 +00:00
|
|
|
shlaxy:
|
|
|
|
aslaxy:
|
|
|
|
pha
|
2004-07-05 22:24:06 +00:00
|
|
|
tya
|
2012-06-24 22:04:00 +00:00
|
|
|
and #$0F
|
|
|
|
beq L2 ; Nothing to shift
|
|
|
|
sec
|
|
|
|
sbc #8 ; Shift count 8 or greater?
|
|
|
|
beq L3 ; Jump if exactly 8
|
|
|
|
bcc L4 ; Jump if less than 8
|
|
|
|
|
|
|
|
; Shift count is greater than 8.
|
|
|
|
|
|
|
|
tay ; Shift count into Y
|
|
|
|
pla ; Get low byte
|
|
|
|
|
2004-07-05 22:24:06 +00:00
|
|
|
L1: asl a
|
2012-06-24 22:04:00 +00:00
|
|
|
dey
|
|
|
|
bne L1
|
2004-07-05 22:24:06 +00:00
|
|
|
tax
|
2012-06-24 22:04:00 +00:00
|
|
|
tya ; A = 0
|
|
|
|
rts
|
|
|
|
|
|
|
|
; Shift count is zero
|
|
|
|
|
|
|
|
L2: pla
|
|
|
|
rts
|
|
|
|
|
|
|
|
; Shift count is exactly 8
|
|
|
|
|
|
|
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
|
|
|
L3: plx ; Low byte from stack into X
|
|
|
|
rts ; A is already zero
|
|
|
|
.else
|
|
|
|
L3: pla ; Low byte from stack ...
|
|
|
|
tax ; ... into X
|
|
|
|
lda #$00 ; Clear low byte
|
2004-07-05 22:24:06 +00:00
|
|
|
rts
|
2012-06-24 22:04:00 +00:00
|
|
|
.endif
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2012-06-24 22:04:00 +00:00
|
|
|
; Shift count is less than 8
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2012-06-24 22:04:00 +00:00
|
|
|
L4: adc #8 ; Correct counter
|
|
|
|
tay ; Shift count into Y
|
|
|
|
pla ; Restore low byte
|
|
|
|
stx tmp1 ; Save high byte of lhs
|
2012-07-06 19:56:42 +00:00
|
|
|
L5: asl a
|
|
|
|
rol tmp1
|
2004-07-05 22:24:06 +00:00
|
|
|
dey
|
2012-07-06 19:56:42 +00:00
|
|
|
bne L5
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Done with shift
|
|
|
|
|
2012-07-06 19:56:42 +00:00
|
|
|
ldx tmp1
|
2004-07-05 22:24:06 +00:00
|
|
|
L9: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|