X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libsrc%2Ftgi%2Ftgi_bar.s;h=476f9d7a4eb4ea5f5e242310f9e8f6ee9659c560;hb=c3922228a989cf93e3b7a2a7c5099d8f0e15ea5c;hp=3f0050f647c42772a15d2518b4f120ecce82b517;hpb=7fc24b058aff3a961c671de44ec7aa2c1ea28d8e;p=cc65 diff --git a/libsrc/tgi/tgi_bar.s b/libsrc/tgi/tgi_bar.s index 3f0050f64..476f9d7a4 100644 --- a/libsrc/tgi/tgi_bar.s +++ b/libsrc/tgi/tgi_bar.s @@ -7,23 +7,127 @@ .include "tgi-kernel.inc" - .import popax .importzp ptr1, ptr2, ptr3, ptr4 - .export _tgi_bar + .import popax + -_tgi_bar: - sta ptr4 ; Get the coordinates +.proc _tgi_bar + + sta ptr4 ; Y2 stx ptr4+1 + jsr popax - sta ptr3 + sta ptr3 ; X2 stx ptr3+1 + jsr popax - sta ptr2 + sta ptr2 ; Y1 stx ptr2+1 + jsr popax - sta ptr1 + sta ptr1 ; X1 stx ptr1+1 - jmp tgi_line ; Call the driver +; Make sure X1 is less than X2. Swap both if not. + + lda ptr3 + cmp ptr1 + lda ptr3+1 + sbc ptr1+1 + bpl @L1 + lda ptr3 + ldy ptr1 + sta ptr1 + sty ptr3 + lda ptr3+1 + ldy ptr1+1 + sta ptr1+1 + sty ptr3+1 + +; Make sure Y1 is less than Y2. Swap both if not. + +@L1: lda ptr4 + cmp ptr2 + lda ptr4+1 + sbc ptr2+1 + bpl @L2 + lda ptr4 + ldy ptr2 + sta ptr2 + sty ptr4 + lda ptr4+1 + ldy ptr2+1 + sta ptr2+1 + sty ptr4+1 + +; Check if X2 or Y2 are negative. If so, the bar is completely out of screen. + +@L2: lda ptr4+1 + ora ptr3+1 + bmi @L9 ; Bail out + +; Check if X1 is negative. If so, clip it to the left border (zero). + + bit ptr1+1 + bpl @L3 + lda #$00 + sta ptr1 + sta ptr1+1 + beq @L4 ; Branch always, skip following test + +; Check if X1 is beyond the right border. If so, the bar is invisible. + +@L3: lda ptr1 + cmp _tgi_xres + lda ptr1+1 + sbc _tgi_xres + bcs @L9 ; Bail out if invisible + +; Check if Y1 is negative. If so, clip it to the top border (zero). + +@L4: bit ptr2+1 + bpl @L5 + lda #$00 + sta ptr2 + sta ptr2+1 + beq @L6 ; Branch always, skip following test + +; Check if Y1 is beyond the bottom border. If so, the bar is invisible. + +@L5: lda ptr2 + cmp _tgi_yres + lda ptr2+1 + sbc _tgi_yres + bcs @L9 ; Bail out if invisible + +; Check if X2 is larger than the maximum x coord. If so, clip it. + +@L6: lda ptr3 + cmp _tgi_xres + lda ptr3+1 + sbc _tgi_xres+1 + bcc @L7 + jsr _tgi_getmaxx + sta ptr3 + stx ptr3+1 + +; Check if Y2 is larger than the maximum y coord. If so, clip it. + +@L7: lda ptr4 + cmp _tgi_yres + lda ptr4+1 + sbc _tgi_yres+1 + bcc @L8 + jsr _tgi_getmaxy + sta ptr4 + stx ptr4+1 + +; The coordinates are now valid. Call the driver. + +@L8: jmp tgi_bar + +; Error exit +@L9: rts +.endproc