Re: A86: mult/div and sprites


[Prev][Next][Index][Thread]

Re: A86: mult/div and sprites




At 10:50 PM 2/20/98 -0800, you wrote:
>
>Is there a way to multiply or divide in asm86?
>

Sure you can.  The basic idea is 5*4=5+5+5+5.  The code keeps adding one
number as many times as specified by the other.  Same thing with division,
except subtraction.  However, this division routine does not keep the
remainder.

;***************************************************
;****Division routine, numerator in AC, denominator
;****in DE, answer without remainder in AC.
;***************************************************
div:
	ld      HL, 0
	ld      B, 16
	and     A
DIVLOOP:
	rl      C
	rl      A
	rl      L
	rl      H
	sbc     HL, DE
	jr      nc, DIVNOADD
	add     HL, DE
DIVNOADD:
	ccf
	djnz    DIVLOOP
	rl      C
	rl      A
	ret

;Multiplication Function

; Arguments:
; A = to be multiplied by DE
; DE = to be multiplied by A

; Returns:
; HL = A * DE
mult:
	ld      HL, 0
	ld      B, 7

	srl     A
	jr      nc, SKIP_BIT0
	add     HL, DE
	jr      c, MULT_OVERFLOW
SKIP_BIT0:
NEXT_BIT:
	sla     E
	rl      D
	jr      nc, START_HERE
	cp      0
	jr      nz, MULT_OVERFLOW
START_HERE:
	srl     A
	jr      nc, SKIP_BIT
	add     HL, DE
	jr      c, MULT_OVERFLOW
SKIP_BIT:
	djnz    NEXT_BIT
	ret
MULT_OVERFLOW:
	scf
	ret



>also, can u store sprites in aliases?
>
>(ie:
>	ld hl,dot
>	ld (picture),hl
>
>dot:
>	.db 8,8
>	.db %00000000
>	.db %00011000
>	.db %00111100
>	.db %001...
>(you get the idea)
>
>


It depends on how you're working with the sprite.  If you're expecting it
to be displayed after that code, you're a bit off.  That stores the address
of <dot> in another address <picture>.  I don't know if you're using some
kind of putsprite routine with it.

ATTENTION - I think this list is getting too many unneeded messages.  Try
to cut back, and only reply if necessary.  It helps with the message flood ;)


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Alan Bailey            mailto:bailela@charlie.cns.iit.edu
 IRC:Abalone              Web:http://www.iit.edu/~bailela/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 


Follow-Ups: References: