A89: disp d0


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

A89: disp d0




anyone see the bug in this routine?  it works fine the first time I
call it, but crashes when I try to run it a second time.  lea
strBuffer(pc),a0 somehow turns into move.w d0,-(a2) / dc.w $ffff
(determined from the debugger).  I really can't figure it out, I'm
pretty sure the routine is doing it to itself since it occurs in
exactly the same way where ever I move it my program.  I commented it
nicely so it shouldn't be that hard to understand.
thanks boys and girls :-)

;display d0 in unsigned decimal (must be 5 digits or less)
;input: d0.l (value to display); d1.l (upper word = x, lower word =
y); d2.w (color)
;destroyed: d0,d1,d2,a0

dispD0:
 move.w d2,-(a7)       ;push color here so d2 can be used for scratch
 lea strBuffer(pc),a0  ;last byte of string buffer (work right to
left)
 clr.b (a0)                     ;zero terminated string will be
displayed
dispD0Loop:
 divu #10,d0               ;get rightmost base 10 digit into remainder
 move.l d0,d2            ;preserve d0 in case more digits
 swap d2                    ;get remainder into d2.w
 add.b #'0',d2            ;make d2 into an ascii char
 move.b d2,-(a0)       ;store it in the string buffer
 ext.l d0                       ;clear upperword of d0 for next divide
 bne dispD0Loop    ;get next digit if more remain
 move.l a0,-(a7)       ;push pointer to string for DrawStr
 move.l d1,-(a7)       ;push x and y coordinates for DrawStr
 rom_call DrawStr   ;display the string
 lea 10(a7),a7        ;restore stack
 rts

 ds.b 6
strBuffer       equ   $-1



Follow-Ups: References: