Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _STD_MATH_ASM
- #define _STD_MATH_ASM
- ;std/math.asm
- #include "pseudoOps.h"
- :math_ptrA: !16 0 ;pointers that hold locations to operands
- :math_ptrB: !16 0 ;^^
- #ifdef MATH_USE_ADD
- /* *ptrA += (signed)A */
- :_add8s_16:
- ldi #,0 ;set index to 0 for low byte
- and #,0xff && bns .sub ;update n flag && branch to .sub if negative
- lda @,L1ARG ;restore original contents of A
- add *,math_ptrA && sta *,math_ptrA ;add A to low byte && store result
- ldi #,1 && lda *,math_ptrA ;set index to 1 for high byte && load high byte
- adc #,0 && sta *,math_ptrA ;if carry set, increment && store result
- jpr ;return from subroutine
- .sub: ;(remember, it's A-memory, not memory-A)
- lda @,L1ARG ;get two's complement of A
- xor #,0xff && add #,1 ;^^(to make sure we're not subtracting
- sta $,_SCRATCH_A ;^^ by a negative number)
- sec ;preemtively set carry flag so borrow isn't factored in
- lda *,math_ptrA ;get low byte of 16-bit number
- sbc @,_SCRATCH_A && sta *,math_ptrA ;subtract low byte by A && store result
- bcs .r ;if no borrow, then skip decrement
- ldi #,1 && lda *,math_ptrA ;set index to 1 for high byte && load high byte
- add #,-1 && sta *,math_ptrA ;decrement high byte && store result
- ;^^'add -1' instead of 'sec && sbc 1' so carry flag is ignored
- .r: jpr ;return from subroutine
- /* *ptrA += *ptrB */
- :_add16_16:
- ldi #,0 && lda *,math_ptrA ;set index to 0 for low byte && load low byte
- add *,math_ptrB && sta *,math_ptrA ;add low bytes && store result
- ldi #,1 && lda *,math_ptrA ;set index to 1 for high byte && load high byte
- adc *,math_ptrB && sta *,math_ptrA ;add high bytes (+carry bit) && store result
- jpr ;return from subroutine
- #endif
- #ifdef MATH_USE_SIN
- !bin "std/sin256_8.bin"
- #endif
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement