Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p_HLine:
- .db __HLineEnd-$-1
- ld de,plotSScreen
- x_HLineEntry:
- ;; de=buff, l=x2, (sp)=ret, (sp+2)=x1, (sp+4)=y
- ;; Rearrange stuff
- ld a,l
- pop hl
- pop bc
- ex (sp),hl
- ;; a=x2, c=x1, de=buff, l=y
- ;; Check if x2 is offscreen left; if so, note and fix it
- ld h,0
- ld b,a
- rla
- jr nc,$+3
- ld b,h
- ;; carry=x2 offscreen, b=left-fixed x2, c=x1, de=buff, h=0, l=y
- ;; Check if x1 is offscreen left; if so, abort if x2 was too, then fix it
- bit 7,c
- jr z,$+4
- ret c
- ld c,h
- ;; b=left-fixed x2, c=left-fixed x1, de=buff, h=0, l=y
- ;; Check if x1 is offscreen right; if so, abort if x2 is too, then fix it
- ld a,95
- cp c
- jr nc,$+5
- cp b
- ret c
- ld c,a
- ;; a=95, b=left-fixed x2, c=fixed x1, de=buff, h=0, l=y
- ;; Check if x2 is offscreen right; if so, fix it
- cp b
- jr nc,$+3
- ld b,a
- ;; X Clipping complete; x1 and x2 guaranteed to be onscreen
- ;; a=95, b=x2, c=x1, de=buff, h=0, l=y
- ;; Locate the lesser and greater (will refer to them as x1 and x2) of x1 and x2
- ld a,b
- cp c
- jr c,$+5
- ld c,b
- ld b,a
- ld a,c
- ;; a=x1, b=x1, c=x2, de=buff, h=0, l=y
- ;; Abort if y is offscreen while calculating y*4
- add hl,hl
- add hl,hl
- dec h
- ret m
- inc h
- ;; a=x1, b=x1, c=x2, de=buff, h=0, l=y*4
- ;; Calculate x1/8 and add it and y*12 to the buffer pointer
- ex de,hl
- add hl,de
- rra
- add hl,de
- rra
- add hl,de
- rra
- ld e,a
- add hl,de
- ;; Begin drawing! y no longer needed
- ;; a=x1/8, b=x1, c=x2, d=0, e=x1/8, hl=y*12+(x1/8)+buff
- ;; Calculate the mask for the first byte
- ld e,b
- ld a,b
- and %00000111
- jr z,__HLineLeft8
- ld b,a
- ld a,$01
- __HLineLeftLoop:
- rrca
- djnz __HLineFirstLoop
- __HLineLeft8:
- dec a
- ;; a=first mask, b=0, c=x2, d=0, e=x1, hl=y*12+(x1/8)+buff
- ;; Prepare the first byte and calculate the negative remaining width after the
- ;; first byte; if positive, jump to the masking code for the last byte
- or (hl)
- ld d,a
- ld a,e
- or %00000111
- sub c
- jr nc,__HLineRight
- ;; a=-width remaining, b=0, c=x2, d=byte, e=x1, hl=y*12+(x1/8)+buff
- ;; Draw bytes until there is no width remaining
- __HLineMidLoop:
- ld (hl),d
- inc hl
- ld d,$FF
- add a,8
- jr nc,__HLineMidLoop
- ;; a=width remaining-1%8+1, b=0, c=x2, d=byte, e=x1, hl=y*12+(x2/8)+buff
- ;; Calculate the mask for the last byte
- __HLineRight:
- ld b,a
- inc b
- ld a,$80
- __HLineRightLoop:
- rlca
- djnz __HLineRightLoop
- dec a
- cpl
- ;; a=mask, b=0, c=x2, d=byte, e=x1, hl=y*12+(x2/8)+buff
- ;; Draw the last byte
- and d
- or (hl)
- ld (hl),a
- ret
- __HLineEnd:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement