Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __addsi3:
- ; *hl = *bc + *de
- push hl
- ld h, d
- ld l, e
- pop de
- ld a, [bc]
- add [hl]
- ld [de], a
- inc bc
- inc de
- inc hl
- ld a, [bc]
- adc [hl]
- ld [de], a
- inc bc
- inc de
- inc hl
- ld a, [bc]
- adc [hl]
- ld [de], a
- inc bc
- inc de
- inc hl
- ld a, [bc]
- adc [hl]
- ld [de], a
- ret
- __shlsi3:
- ; *hl = *de << b
- ld a, b
- and a
- jr z, .sh0
- cp 32
- jr c, .proceed
- xor a
- ld [hli], a
- ld [hli], a
- ld [hli], a
- ld [hl], a
- scf
- ret
- .sh0:
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hl], a
- and a
- ret
- .proceed:
- xor a ; reset carry
- push af
- add sp, -4
- push hl
- ld hl, sp + 2
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hl], a
- .loop:
- ld hl, sp + 2
- sla [hl]
- inc hl
- rla [hl]
- inc hl
- rla [hl]
- inc hl
- rla [hl]
- push af
- ld hl, sp + 1
- ld a, [hl]
- and $10
- ld hl, sp + 9
- or [hl]
- ld [hl], a
- pop af
- dec b
- jr nz, .loop
- ld hl, sp + 2
- pop de
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hl]
- ld [de], a
- add sp, 4
- pop af
- ret
- __mulsi3:
- ; *hl = *bc * *de
- xor a
- push af
- add sp, -8
- push hl
- ld hl, sp + 2
- xor a
- ld [hli], a
- ld [hli], a
- ld [hli], a
- ld [hli], a
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hli], a
- inc de
- ld a, [de]
- ld [hl], a
- ld d, 4
- .loop:
- ld a, [bc]
- ld e, 8
- .loop2:
- push bc
- push de
- rrca
- jr nc, .skip
- ld hl, sp + 10
- ld b, h
- ld c, l
- ld hl, sp + 6
- ld d, h
- ld e, l
- call __addsi3
- push af
- ld hl, sp + 1
- ld a, [hl]
- and $10
- ld hl, sp + 17
- or [hl]
- ld [hl], a
- pop af
- .skip:
- ld hl, sp + 10
- ld d, h
- ld e, l
- ld b, 1
- call __shlsi3
- pop de
- pop bc
- dec e
- jr nz, .loop2
- inc bc
- dec b
- jr nz, .loop
- pop de
- ld hl, sp + 0
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hl]
- ld [de], a
- add sp, 8
- pop af
- ret
- Random:
- ld hl, wRngValue
- ld d, h
- ld e, l
- ld bc, .multiplicand
- call __mulsi3
- ld hl, wRngValue
- ld d, h
- ld e, l
- ld bc, .addend
- call __addsi3
- ld hl, wRngValue + 2
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ret
- .multiplicand: dl 1103515245
- .addend: dl 24691
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement