moulinaie Posted August 5, 2012 Share Posted August 5, 2012 (edited) Hi, I've been asked to share the DRAWTO routine in MLC, here it is with enough comments I thinkl. The code is self modified for one line (the one with label "modif"). ; INPUT ; R0 = X2, R2 = Y2 ; R7 = X1, R8 = Y1 ; you just have to provide a ; PLOT routine that plots the pixel ; (X1,Y1) = (R7,R8) ; the PLOT routine can use R0 to R6 mov r11,@DRAWRT ; save return address mov r0,r10 s r7,r10 ; dx=x2-x1 jgt gbd1 neg r10 mov r0,r1 mov r7,r0 mov r1,r7 ; swap x1 and x2 mov r2,r1 mov r8,r2 mov r1,r8 ; swap y1 and y2 gbd1 li r13,1 ; k=1 mov r2,r12 s r8,r12 ; dy=y2-y1 jlt gbd2 c r10,r12 ; *** here if dy>0 jlt gbd3 gbd7 mov r10,r14 ; e=dx *** here dx>=dy mov r10,r9 inc r9 ; R9 = number of loops (x2-x1+1) a r10,r10 ; dx*2 a r12,r12 ; dy*2 plot1 bl @PLOT ; plot x1,y1 inc r7 ; x1+1 s r12,r14 ; e=e-dy jgt gbd4 jeq gbd4 a r13,r8 ; y1=y1+k (+/-1) a r10,r14 ; e=e+dx gbd4 dec r9 jne plot1 gbd9 mov @DRAWRT,r11 b *r11 gbd3 ; *** here dy>dx li r0,>1500 ; JGT mov r12,r9 gbd8 inc r9 ; number of loops (y2-y1+1) movb r0,@modif mov r12,r14 ; e=dy a r10,r10 ; dx*2 a r12,r12 ; dy*2 plot2 bl @PLOT ; plot x1,y1 a r13,r8 ; y1 +/-1 s r10,r14 ; e=e-dx modif jgt gbd5 ; if dy>=0 then JGT (>15xx) else JLT (>11xx) jeq gbd5 inc r7 ; x1+1 a r12,r14 ; e=e+dy gbd5 dec r9 jne plot2 jmp gbd9 gbd2 ; here dy<0 neg r13 ; k=-1 mov r10,r1 a r12,r1 jlt gbd6 neg r12 ; dy = -dy jmp gbd7 gbd6 neg r10 ; dx = -dx mov r12,r9 neg r9 li r0,>1100 ; JLT jmp gbd8 (source: I worked from this article: http://fr.wikipedia.org/wiki/Algorithme_de_trac%C3%A9_de_segment_de_Bresenham) Guillaume. Edited August 5, 2012 by moulinaie 1 Quote Link to comment https://forums.atariage.com/topic/201138-draw-line-routine-in-assembler/ Share on other sites More sharing options...
sometimes99er Posted August 5, 2012 Share Posted August 5, 2012 (edited) I guess it's much the same. I used the following link to draw lines and circles (and with a bit of changes you could get diamonds, squares and squares with rounded corners). http://www.gamedev.n...algorithms-r767 Here's a cart demo from 07.12.2006. About ordinary speed ... Edited August 8, 2012 by sometimes99er 1 Quote Link to comment https://forums.atariage.com/topic/201138-draw-line-routine-in-assembler/#findComment-2572535 Share on other sites More sharing options...
Willsy Posted August 6, 2012 Share Posted August 6, 2012 That's great Guillaume, thanks! I'll save that code! Quote Link to comment https://forums.atariage.com/topic/201138-draw-line-routine-in-assembler/#findComment-2572850 Share on other sites More sharing options...
Willsy Posted August 6, 2012 Share Posted August 6, 2012 I guess it's much the same. I used the following link to draw lines and circles (and with a bit of changes you could get diamonds, squares and squares with rounded corners). http://www.gamedev.n...algorithms-r767 Here's a cart demo from 07.12.2006 Great link. Just reading up on it. It actually makes sense! Quote Link to comment https://forums.atariage.com/topic/201138-draw-line-routine-in-assembler/#findComment-2572852 Share on other sites More sharing options...
moulinaie Posted August 6, 2012 Author Share Posted August 6, 2012 I guess it's much the same. I used the following link to draw lines and circles (and with a bit of changes you could get diamonds, squares and squares with rounded corners). http://www.gamedev.n...algorithms-r767 Here's a cart demo from 07.12.2006 That's very interesting for the circle algorithm. I didn't know it was so simple...! Guillaume. Quote Link to comment https://forums.atariage.com/topic/201138-draw-line-routine-in-assembler/#findComment-2572853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.