Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _lshiftc:
- ; inputs: iy = ptr to src, hl = ptr to dest, a = shift count
- ; ouputs: none
- ; destroys: a, b, c, flags
- ; algorithm:
- ; byte shift: shift by between 1 and 32 (inclusive) bytes by:
- ; shift a to the right 3x (div 8), then and a with 30 to constrain to 30 or less
- ; if a == 0, skip to the bit shift section
- ; set the first a bytes of de to 0
- ; copy 32 - a bytes from hl to de + a
- ; bit shift: shift by between 1 and 7 (inclusive) bits by:
- ; restore original a, then and with 7 to return a value mod 8
- ; return if 0
- ; shift the 32 bytes at hl to the left a times
- push af
- push hl
- push iy
- srl a
- srl a
- srl a
- or a
- jr z, .skip_byte_shift
- ; add a to hl
- ld bc, 0
- ld c, a
- add hl, bc
- ; sub 32 - a
- ld b, a
- ld a, 32 ; set c to 32
- sub a, b
- ld b, a
- .loop_xor_bytes:
- ld a, (iy)
- xor (hl)
- ld (hl), a
- inc iy
- inc hl
- djnz .loop_xor_bytes
- .skip_byte_shift:
- pop iy
- pop hl ; dest into hl now
- pop af ; return original a
- and a, 7 ; and a with 7 to get a % 8
- ret z
- ld b, a
- ld a, 1
- .ishiftc:
- rlca
- djnz .ishiftc
- ld c, a
- ld b, 32
- xor a
- .shift_bits:
- ld e, (iy)
- ld d, c
- mlt de
- add a, e
- xor (hl)
- ld (hl), a
- ld a, d
- inc hl
- djnz .shift_bits
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement