非専門的シンギュラリティー研究所

無限に動き続けるシステムを表す方法を AI なども使って考えていきます。

アセンブラ(22)

直線を描画する関数をコンパイルした結果の動作を確認できました。

X68000(21) - 非専門的シンギュラリティー研究所」でやったものを書き換えています。

void DirectDrawLine(HDC hdc, int x1, int y1, int x2, int y2, COLORREF color) {
    int w = x2 - x1;
    int h = y2 - y1;
    if (abs(h) < abs(w)) {
        if (x1 > x2) {
            int t = x1; x1 = x2; x2 = t;
            t = y1; y1 = y2; y2 = t;
            w = -w;
            h = -h;
        }
        for (int x = x1; x < x2; x++) {
            int y = y1 + (h * (x - x1)) / w;
            SetPixel(hdc, x, y, color);
        }
    }
    else {
        if(y1 > y2) {
            int t = x1; x1 = x2; x2 = t;
            t = y1; y1 = y2; y2 = t;
            w = -w;
            h = -h;
        }
        for (int y = y1; y < y2; y++) {
            int x = x1 + (w * (y - y1)) / h;
            SetPixel(hdc, x, y, color);
        }
    }
}

コンパイルした結果は以下のようになります。以前のものは「X68000(30) - 非専門的シンギュラリティー研究所」に書いています。

_Z14DirectDrawLinePiiiiim:
	movem.l #7966,-(%sp)
	move.l 44(%sp),%d4
	move.l 48(%sp),%d3
	move.l 52(%sp),%d6
	move.l 56(%sp),%d5
	move.l 60(%sp),%a5
	move.l %d6,%d7
	sub.l %d4,%d7
	move.l %d5,%a6
	sub.l %d3,%a6
	move.l %a6,%d1
	jpl .L142
	neg.l %d1
.L142:
	move.l %d7,%d0
	jpl .L143
	neg.l %d0
.L143:
	cmp.l %d1,%d0
	jle .L141
	cmp.l %d6,%d4
	jle .L144
	move.l %d4,%d7
	sub.l %d6,%d7
	move.l %d3,%a6
	sub.l %d5,%a6
	move.l %d5,%d3
	move.l %d4,%d0
	move.l %d6,%d4
	move.l %d0,%d6
.L144:
	moveq #0,%d5
	lea g_gmemory,%a3
	lea __divsi3,%a4
.L145:
	cmp.l %d6,%d4
	jlt .L146
.L140:
	movem.l (%sp)+,#30968
	rts
.L146:
	move.l %d7,-(%sp)
	move.l %d5,-(%sp)
	jsr (%a4)
	addq.l #8,%sp
	add.l %d3,%d0
	moveq #9,%d1
	lsl.l %d1,%d0
	add.l %d4,%d0
	add.l %d0,%d0
	move.w %a5,(%a3,%d0.l)
	addq.l #1,%d4
	add.l %a6,%d5
	jra .L145
.L141:
	cmp.l %d5,%d3
	jle .L147
	move.l %d4,%d7
	sub.l %d6,%d7
	move.l %d3,%a6
	sub.l %d5,%a6
	move.l %d3,%d0
	move.l %d5,%d3
	move.l %d0,%d5
	move.l %d6,%d4
.L147:
	moveq #0,%d6
	lea g_gmemory,%a3
	lea __divsi3,%a4
.L148:
	cmp.l %d5,%d3
	jge .L140
	move.l %a6,-(%sp)
	move.l %d6,-(%sp)
	jsr (%a4)
	addq.l #8,%sp
	move.l %d3,%d1
	moveq #9,%d2
	lsl.l %d2,%d1
	add.l %d4,%d0
	add.l %d1,%d0
	add.l %d0,%d0
	move.w %a5,(%a3,%d0.l)
	addq.l #1,%d3
	add.l %d7,%d6
	jra .L148
g_gmemory:
	*const 0xc00000
__mulsi3:
	*lmuls
	rts
__divsi3:
	*ldivs
	rts
__adddf3:
	*dadd
	rts
__subdf3:
	*dsub
	rts
__muldf3:
	*dmul
	rts
__divdf3:
	*ddiv
	rts
sin:
	*dsin
	rts
cos:
	*dcos
	rts