Skip to content

Commit

Permalink
IconTK: Simplify icon clipping logic more. Saves 15 bytes.
Browse files Browse the repository at this point in the history
Same as previous commit, but for the window bounds right edge.

In the preamble to the complicated icon clipping logic, the right
bounds of the overlapping window is decremented by a pixel before
diving in to determine how to adjust the clipping rect. After staring
at the math for a bit, it turns out that it is because of how "greater
than" test is done - the test was implemented as a "greater than or
equals" (c/o BMI, skipping if "less than"). If the test is inverted
then it can properly be a "greater than" (c/o BPL, skipping if
"greater than or equal") and the decrement can be skipped and a copy
further simplified.

Then there's a follow-on adjustment needed as well, similar but
inverted test, and a +2 becomes a +1 which makes more sense. Yay!
  • Loading branch information
inexorabletash committed Oct 1, 2023
1 parent d91d9a3 commit 7de185b
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions toolkits/icontk.s
Original file line number Diff line number Diff line change
Expand Up @@ -2223,9 +2223,6 @@ do_pt: lda pt_num
copy findwindow_params::window_id, getwinframerect_params::window_id
MGTK_CALL MGTK::GetWinFrameRect, getwinframerect_params

;; TODO: Determine why these are necessary:
dec16 win_r

;; ==================================================
;; At this point, win_r/t/l/b are the window edges,
;; cr_r/t/l/b are the rect we know has at least one
Expand All @@ -2252,17 +2249,11 @@ do_pt: lda pt_num

;; Cases 1/2/3 (and continue below)
;; if (cr_r > win_r)
;; . cr_r = win_r + 1
scmp16 cr_r, win_r
bmi case789
;; . cr_r = win_r
scmp16 win_r, cr_r
bpl case789

ldx win_r
ldy win_r + 1
inx
bne :+
iny
: stx cr_r
sty cr_r + 1
copy16 win_r, cr_r
jmp vert

;; Cases 7/8/9 (and done)
Expand Down Expand Up @@ -2306,16 +2297,16 @@ vert: scmp16 cr_t, win_t

;; Case 2
;; if (win_r < stash_r)
;; . cr_l = win_r + 2
;; . vx = win_r + 2
;; . cr_l = win_r + 1
;; . vx = win_r + 1
;; . cr_r = stash_r + 2 (workaround for https://github.com/a2stuff/a2d/issues/153)
case2:
scmp16 win_r, stash_r
bpl :+
scmp16 stash_r, win_r
bmi :+

lda win_r
clc
adc #2
adc #1
sta cr_l
sta vx
lda win_r+1
Expand Down

0 comments on commit 7de185b

Please sign in to comment.