wonderworm (3 levels (lines), greyscale, vertical scrolling)
[wormy.git] / line.asm
diff --git a/line.asm b/line.asm
new file mode 100644 (file)
index 0000000..0c9cbfa
--- /dev/null
+++ b/line.asm
@@ -0,0 +1,95 @@
+Line:
+        push hl
+        push de
+        ld a,d
+        cp h
+        jr c,LineOrdered
+        ex de,hl
+LineOrdered:  
+        ld b,d
+        ld c,e
+        push hl
+        push bc
+        call FindPixel
+        pop bc
+        pop de
+ConnectedLine:
+        push hl
+        ld h,c
+        ld c,a
+        ld a,d
+        sub b
+        ld b,a
+        ld a,e
+        jr nz,LineNotPoint
+        cp h
+        jr nz,LineNotPoint
+        pop hl
+        jr DoneLine
+LineNotPoint:
+        sub h
+        ld de,16
+        jr nc,LinePositiveY
+        neg
+        ld de,-16
+LinePositiveY:  
+        cp b
+        jr nc,SteepLine
+        add a,a
+        ld (Line2sm+1),a
+        ld h,a
+        xor a
+        sub b
+        add a,a
+        ld (Line1sm+1),a
+        ld a,h
+        sub b
+        pop hl
+LineLoopGentle: 
+        push af
+        ld a,(hl)
+        or c
+        ld (hl),a
+        rrc c
+        jr nc,$+3
+        inc hl
+        pop af       
+        jp m,Line2sm
+Line1sm add a,0
+        add hl,de
+Line2sm add a,0
+        djnz LineLoopGentle
+DoneLine:
+        ld a,(hl)
+        or c
+        ld (hl),a
+        pop de
+        pop hl
+        ret
+
+SteepLine:
+        ld h,a
+        neg
+        add a,a
+        ld (Line3sm+1),a
+        ld a,b
+        add a,a
+        ld (Line4sm+1),a
+        sub h
+        ld b,h
+        pop hl
+LineLoopSteep: 
+        push af
+        ld a,(hl)
+        or c
+        ld (hl),a
+        add hl,de
+        pop af
+        jp m,Line4sm
+Line3sm add a,0
+        rrc c
+        jr nc,$+3
+        inc hl
+Line4sm add a,0
+        djnz LineLoopSteep
+        jr DoneLine