Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ConvOP1:
- ;;Output: HL is the 16-bit result.
- ld de,OP1
- ConvFloat:
- ;;Input: DE points to the float.
- ;;Output: HL is the 16-bit result.
- ;;Errors: DataType if the float is negative or complex
- ;; Domain if the integer exceeds 16 bits.
- ;;Timings: Assume no errors were called.
- ;; Input is on:
- ;; (0,1) => 59cc Average=59
- ;; 0 or [1,10) => 120cc or 129cc =124.5
- ;; [10,100) => 176cc or 177cc =176.5
- ;; [100,1000) => 309cc, 310cc, 318cc, or 319cc. =314
- ;; [1000,10000) => 376cc to 378cc =377
- ;; [10000,65536) => 514cc to 516cc, or 523cc to 525cc =519.5
- ;;Average case: 496.577178955078125cc
- ;;vs 959.656982421875cc
- ;;87 bytes
- ld a,(de)
- or a
- jr nz,ErrDataType
- inc de
- ld hl,0
- ld a,(de)
- inc de
- sub 80h
- ret c
- jr z,final
- cp 5
- jp c,enterloop
- ErrDomain:
- ;Throws a domain error.
- bcall(_ErrDomain)
- ErrDataType:
- ;Throws a data type error.
- bcall(_ErrDataType)
- loop:
- ld a,b
- ld b,h
- ld c,l
- add hl,hl
- add hl,bc
- add hl,hl
- add hl,hl
- add hl,hl
- add hl,bc
- add hl,hl
- add hl,hl
- enterloop:
- ld b,a
- ex de,hl
- ld a,(hl) \ and $F0 \ rra \ ld c,a \ rra \ rra \ sub c \ add a,(hl)
- inc hl
- ex de,hl
- add a,l
- ld l,a
- jr nc,$+3
- inc h
- dec b
- ret z
- djnz loop
- ld b,h
- ld c,l
- xor a
- ;check overflow in this mul by 10!
- add hl,hl \ adc a,a
- add hl,hl \ adc a,a
- add hl,bc \ adc a,0
- add hl,hl \ adc a,a
- jr nz,ErrDomain
- final:
- ld a,(de)
- rrca
- rrca
- rrca
- rrca
- and 15
- add a,l
- ld l,a
- ret nc
- inc h
- ret nz
- jr ErrDomain
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement