[A83] Re: The Working Of Floating Point Numbers
[Prev][Next][Index][Thread]
[A83] Re: The Working Of Floating Point Numbers
;I made this to response of Alexander Hansson's request of how to use
floating point numbers
; Say you want a hp-bar in a game like Asghan: SOTP
; When your health is 100% the bar is 52 pixels in lenght
; Say you get hit and you only have 23% health left
; You first need to get 1% of 52
; so 52/100=0.52, so 1% health is 0,52 pixels in lenght
; you need 23% so: 23*0,52=11,96 pixels.
; after that you round it. So it becomes 12 pixels
; You can define how much % health you have left by just storing hl into
(percent+3).
.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
.org 9327h
ld hl,percenthundred ;copy the floating point number 100 to op1
ld de,op1 ;
ld bc,9 ;
ldir ;
call _op1toop2 ;copy the fp-number in op1 to op2
ld hl,maxbar ;copy the floating number 52 to op1(I take
ld de,op1 ;
ld bc,9 ;
ldir ;
call _fpdiv ;op1 / op2
call _op1toop2 ;copy the remainder to op2 (you can't stack with floating
point numbers)
ld hl,percent ;copy the percentage of health you have left
to op1
ld de,op1 ;
ld bc,9 ;
ldir ;
call _fpmult ;do op1*op2
ld d,0 ;round at 0 digits
call _ROUND ;round i1
call _convop1 ;op1->de
ex de,hl ;de->hl
call _disphl ;display HL (so you no have the value in HL, you can do
anything you like, I just display it :))
call _newline ;miscallen1ous
ret
percent:
.db $00,$81,$23,$00,$00,$00,$00,$00,$00 ; 23
maxbar:
.db $00,$81,$52,$00,$00,$00,$00,$00,$00 ; 52
percenthundred :
.db $00,$82,$10,$00,$00,$00,$00,$00,$00 ; 100
.end
END
;Copyright MaxCoderz Inc. This piece of code may be freely distrinuted under
the GNU license. For more information see www.maxcoderz.com.
;---------------------------------------------------------------------
;Maarten Zwartbol - Maxcoderz Soft. - http://www.maxcoderz.com
;---------------------------------------------------------------------
;"If I have seen farther than others, it is because I was standing on the
shoulders of giants." - scientist Sir Isaac Newton, in a letter to his
colleague Robert Hooke, February 1676.
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
Follow-Ups: