diff options
author | Pixel <> | 2001-05-07 00:02:00 +0000 |
---|---|---|
committer | Pixel <> | 2001-05-07 00:02:00 +0000 |
commit | c88b5d9cb360381d2587adc8e9ca2818d2637284 (patch) | |
tree | 09fcf2ea333f378cbd17e8269d0a632b18ac4b66 | |
parent | bcd2ac69fd6e6de7b611f05297c3368ed5b37329 (diff) |
Hop
-rw-r--r-- | samples/drawline.s | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/samples/drawline.s b/samples/drawline.s new file mode 100644 index 0000000..44632ab --- /dev/null +++ b/samples/drawline.s @@ -0,0 +1,299 @@ +.data +ClrScrMsg DS "\e[2J\e[H" +LocateMsg1 DS "\e[" +LocateMsg2 DS ";" +LocateMsg3 DS "H" +PointMsg DS "." + +.text + +;ClrScr: +; Efface l'écran +; + +ClrScr: MOV, [0xffffff04], ClrScrMsg + RET + +;Locate: +; Positionne le curseur a la position (R10, R11), sous la forme (ligne, colonne) +; + +Locate: MOV, [0xffffff04], LocateMsg1 + MOV, [0xffffff06], R10 + MOV, [0xffffff04], LocateMsg2 + MOV, [0xffffff06], R11 + MOV, [0xffffff04], LocateMsg3 + RET + +;DrawLinePrim1: +; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne)) +; + +; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e + +DrawLinePrim1: PUSH R10 + PUSH R11 + PUSH R12 + PUSH R13 + PUSH R14 + SUB R13, R9, R7 + SHL R13, 1 + SUB R12, R8, R6 + SUB R14, R12, R13 + SHL R12, 1 + MOV R10, R6 + MOV R11, R7 +DrawLinePrim1B: JNLE R10, R8, DrawLinePrim1O + CALL Locate + MOV, [0xffffff04], PointMsg + JNL R14, R0, DrawLinePrim1C + ADD R11, 1 + ADD R14, R12 + SUB R14, R13 + JMP DrawLinePrim1L +DrawLinePrim1C: SUB R14, R12 +DrawLinePrim1L: ADD R10, 1 + JMP DrawLinePrim1B +DrawLinePrim1O: POP R14 + POP R13 + POP R12 + POP R11 + POP R10 + RET + +; void DrawXLine_Prim1(int x1, int y1, int x2, int y2, Color_t color) { +; int x, y, ddx, ddy, e, c; +; +; ddy = (y2 - y1) << 1; +; ddx = x2 - x1; +; e = ddx - ddy; +; ddx <<= 1; +; for (x = x1, y = y1; x <= x2; x++) { +; putpixel(x, y, color); +; if (e < 0) { +; y++; +; e += ddx - ddy; +; } else { +; e -= ddy; +; } +; } +;} + +;DrawLinePrim2: +; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne)) +; + +; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e + +DrawLinePrim2: PUSH R10 + PUSH R11 + PUSH R12 + PUSH R13 + PUSH R14 + SUB R12, R8, R6 + SHL R12, 1 + SUB R13, R9, R7 + SUB R14, R13, R12 + SHL R13, 1 + MOV R10, R6 + MOV R11, R7 +DrawLinePrim2B: JNLE R11, R9, DrawLinePrim2O + CALL Locate + MOV, [0xffffff04], PointMsg + JNL R14, R0, DrawLinePrim2C + ADD R10, 1 + ADD R14, R13 + SUB R14, R12 + JMP DrawLinePrim2L +DrawLinePrim2C: SUB R14, R13 +DrawLinePrim2L: ADD R11, 1 + JMP DrawLinePrim2B +DrawLinePrim2O: POP R14 + POP R13 + POP R12 + POP R11 + POP R10 + RET + +;void DrawXLine_Prim2(int x1, int y1, int x2, int y2, Color_t color) { +; int x, y, ddx, ddy, e; +; +; ddx = (x2 - x1) << 1; +; ddy = y2 - y1; +; e = ddy - ddx; +; ddy <<= 1; +; for (y = y1, x = x1; y <= y2; y++) { +; putpixel(x, y, color); +; if (e < 0) { +; x++; +; e += ddy - ddx; +; } else { +; e -= ddx; +; } +; } +;} + +;DrawLinePrim3: +; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne)) +; + +; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e + +DrawLinePrim3: PUSH R10 + PUSH R11 + PUSH R12 + PUSH R13 + PUSH R14 + SUB R12, R6, R8 + SHL R12, 1 + SUB R13, R9, R7 + SUB R14, R13, R12 + SHL R13, 1 + MOV R10, R6 + MOV R11, R7 +DrawLinePrim3B: JNLE R11, R9, DrawLinePrim3O + CALL Locate + MOV, [0xffffff04], PointMsg + JNL R14, R0, DrawLinePrim3C + ADD R10, 1 + ADD R14, R13 + SUB R14, R12 + JMP DrawLinePrim3L +DrawLinePrim3C: SUB R14, R13 +DrawLinePrim3L: ADD R11, 1 + JMP DrawLinePrim3B +DrawLinePrim3O: POP R14 + POP R13 + POP R12 + POP R11 + POP R10 + RET + +;void DrawXLine_Prim3(int x1, int y1, int x2, int y2, Color_t color) { +; int x, y, ddx, ddy, e; +; +; ddx = (x1 - x2) << 1; +; ddy = y2 - y1; +; e = ddy - ddx; +; ddy <<= 1; +; for (y = y1, x = x1; y <= y2; y++) { +; putpixel(x, y, color); +; if (e < 0) { +; x--; +; e += ddy - ddx; +; } else { +; e -= ddx; +; } +; } +;} + +;DrawLinePrim4: +; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne)) +; + +; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e + +DrawLinePrim4: PUSH R10 + PUSH R11 + PUSH R12 + PUSH R13 + PUSH R14 + SUB R13, R9, R7 + SHL R13, 1 + SUB R12, R6, R8 + SUB R14, R12, R13 + SHL R12, 1 + MOV R10, R6 + MOV R11, R7 +DrawLinePrim4B: JNGE R10, R8, DrawLinePrim4O + CALL Locate + MOV, [0xffffff04], PointMsg + JNL R14, R0, DrawLinePrim4C + ADD R11, 1 + ADD R14, R12 + SUB R14, R13 + JMP DrawLinePrim4L +DrawLinePrim4C: SUB R14, R12 +DrawLinePrim4L: ADD R10, 1 + JMP DrawLinePrim4B +DrawLinePrim4O: POP R14 + POP R13 + POP R12 + POP R11 + POP R10 + RET + +;void DrawXLine_Prim4(int x1, int y1, int x2, int y2, Color_t color) { +; int x, y, ddx, ddy, e; +; +; ddy = (y2 - y1) << 1; +; ddx = x1 - x2; +; e = ddx - ddy; +; ddx <<= 1; +; for (x = x1, y = y1; x >= x2; x--) { +; putpixel(x, y, color); +; if (e < 0) { +; y++; +; e += ddx - ddy; +; } else { +; e -= ddy; +; } +; } +;} + +;DrawLine: +; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne)) +; + +DrawLine: PUSH R1 + PUSH R2 + JNL R9, R7, DrawLineC1 + MOV R1, R6 + MOV R6, R8 + MOV R8, R1 + MOV R1, R7 + MOV R7, R9 + MOV R9, R1 +DrawLineC1: JNGE R8, R6, DrawLineC2 + SUB R1, R8, R6 + SUB R2, R9, R7 + JNGE R1, R2, DrawLineC3 + CALL DrawLinePrim1 + JMP DrawLineO +DrawLineC3: CALL DrawLinePrim2 + JMP DrawLineO +DrawLineC2: SUB R1, R6, R8 + SUB R2, R9, R7 + JNGE R1, R2, DrawLineC4 + CALL DrawLinePrim3 + JMP DrawLineO +DrawLineC4: CALL DrawLinePrim4 +DrawLineO: POP R2 + POP R1 + RET + +;void DrawXLine(int x1, int y1, int x2, int y2, Color_t color) { +; if (y2 < y1) { +; SWAP(x1, x2); +; SWAP(y1, y2); +; } +; if (x2 >= x1) { +; if ((x2 - x1) >= (y2 - y1)) DrawXLine_Prim1(x1, y1, x2, y2, color); +; else DrawXLine_Prim2(x1, y1, x2, y2, color); +; } else { +; if ((x1 - x2) >= (y2 - y1)) DrawXLine_Prim4(x1, y1, x2, y2, color); +; else DrawXLine_Prim3(x1, y1, x2, y2, color); +; } +;} + +.start + CALL ClrScr + MOV R6, 10 + MOV R7, 4 + MOV R8, 15 + MOV R9, 20 + CALL DrawLine + MOV R10, 30 + MOV R11, 1 + CALL Locate + HALT |