;-----------------------------------------------------------;
;                                                           ;
; Maths Pack                                                ;
; Version 1.0                                               ;
; Vector Magnitude Finder                                   ;
; By James Vernon <james@calc.org>                          ;
;                                                           ;
;-----------------------------------------------------------;

vecMagName:                                     ; Function description
.db     "Vector Magnitude Finder",0

vecMag:                                         ; Start of actual function
        ld      hl,strVecMagI
        call    putsNewLine
        ld      de,vmI
        call    getNumber
        bcall(_newline)
        ld      hl,strVecMagJ
        call    putsNewLine
        ld      de,vmJ
        call    getNumber
        bcall(_newline)
        ld      hl,strVecMagK
        call    putsNewLine
        ld      de,vmK
        call    getNumber

        call    cls
        ld      hl,strVecMagnitude
        call    putsNewLine
        ld      hl,op1
        ld      de,vmI
        call    popOp
        bcall(_fpsquare)
        ld      hl,op1
        ld      de,vmI
        call    pushOp

        ld      hl,op1
        ld      de,vmJ
        call    popOp
        bcall(_fpsquare)
        ld      hl,op1
        ld      de,vmJ
        call    pushOp

        ld      hl,op1
        ld      de,vmK
        call    popOp
        bcall(_fpsquare)

        ld      hl,op2
        ld      de,vmI
        call    popOp
        bcall(_fpadd)
        ld      hl,op2
        ld      de,vmJ
        call    popOp
        bcall(_fpadd)
        bcall(_sqroot)
        bcall(_formreal)
        ld      hl,op3
        bcall(_puts)
        jp      waitKey

vmI             = float1
vmJ             = float2
vmK             = float3

strVecMagI:
.db     "Enter Vector in "
.db     "I, J, K format. "
.db     "I=",0

strVecMagJ:
.db     "J=",0

strVecMagK:
.db     "K=",0

strVecMagnitude:
.db     "Magnitude=",0

.end
