From 411b0fda72c30e024bfdd17b7ce0afc7b799ada3 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Sat, 9 Feb 2019 13:11:12 -0800 Subject: [PATCH] factor out mul/div routines --- desktop/desktop_lc.s | 50 ++++++++++++++++++++++++++++++++++++++++++ desktop/desktop_main.s | 13 +++++------ desktop/ovl2.s | 36 ++++++++++++------------------ 3 files changed, 70 insertions(+), 29 deletions(-) diff --git a/desktop/desktop_lc.s b/desktop/desktop_lc.s index 10624f2..8273c44 100644 --- a/desktop/desktop_lc.s +++ b/desktop/desktop_lc.s @@ -253,6 +253,56 @@ op: lda dummy1234 rts .endproc +;;; ============================================================ +;;; Input: numbers in A,X, Y +;;; Output: number in A,X + +.proc Multiply_16_8_16 + stax num16 + sty num8 + copy16 #0, accum + ldx num8 + beq done + +loop: add16 num16, accum, accum + dex + bne loop + +done: ldax accum + rts + +num16: .word 0 +num8: .byte 0 +accum: .word 0 + +.endproc + +;;; ============================================================ +;;; Input: numerator in A,X, divisor in Y +;;; Output: result in A,X + +.proc Divide_16_8_16 + stax numerator + sty divisor + copy16 #0, result + +loop: sub16_8 numerator, divisor, numerator + bmi done + inc16 result + jmp loop + +done: ldax result + rts + +numerator: + .word 0 +divisor: + .byte 0 + +result: .word 0 + +.endproc + ;;; ============================================================ PAD_TO $D200 diff --git a/desktop/desktop_main.s b/desktop/desktop_main.s index a3f68e2..1b778d9 100644 --- a/desktop/desktop_main.s +++ b/desktop/desktop_main.s @@ -14102,7 +14102,7 @@ done: jmp reset_grafport3a jmp skip ;; Compute text width and center it -: tya +: and #$7F ; strip "center?" flag pha add16 ptr, #1, textptr jsr load_aux_from_ptr @@ -14111,14 +14111,13 @@ done: jmp reset_grafport3a lsr16 result sub16 #200, result, dialog_label_pos pla - and #$7F ; strip "center?" flag - tay ;; y = base + desktop_aux::dialog_label_height * line -skip: copy16 dialog_label_base_pos::ycoord, dialog_label_pos::ycoord -: add16 dialog_label_pos::ycoord, #desktop_aux::dialog_label_height, dialog_label_pos::ycoord - dey - bne :- +skip: ldx #0 + ldy #desktop_aux::dialog_label_height + jsr Multiply_16_8_16 + stax dialog_label_pos::ycoord + add16 dialog_label_pos::ycoord, dialog_label_base_pos::ycoord, dialog_label_pos::ycoord MGTK_RELAY_CALL MGTK::MoveTo, dialog_label_pos addr_call_indirect draw_text1, ptr ldx dialog_label_pos diff --git a/desktop/ovl2.s b/desktop/ovl2.s index 119bfa0..775336d 100644 --- a/desktop/ovl2.s +++ b/desktop/ovl2.s @@ -255,7 +255,7 @@ L0B47: .byte 0 ;;; ============================================================ - labels_voffset = 40 + labels_voffset = 49 L0B48: cmp16 screentowindow_windowx, #40 bpl :+ @@ -265,7 +265,7 @@ L0B48: cmp16 screentowindow_windowx, #40 return #$FF : lda screentowindow_windowy sec - sbc #labels_voffset+desktop_aux::dialog_label_height + sbc #labels_voffset sta screentowindow_windowy lda screentowindow_windowy+1 sbc #0 @@ -274,17 +274,12 @@ L0B48: cmp16 screentowindow_windowx, #40 : sta screentowindow_windowy+1 ;; Divide by desktop_aux::dialog_label_height - ldx #0 - lda screentowindow_windowy -: sec - sbc #desktop_aux::dialog_label_height - bmi :+ - inx - bne :- ; always + ldax screentowindow_windowy + ldy #desktop_aux::dialog_label_height + jsr Divide_16_8_16 + stax screentowindow_windowy -: stx screentowindow_windowy - lda screentowindow_windowy - cmp #$04 + cmp #4 bcc L0B98 return #$FF @@ -359,16 +354,13 @@ L0C20: ldy #39 txa sec sbc L0CA9 ; entry % 4 - tax - lda #0 -: clc - adc #desktop_aux::dialog_label_height - dex - bpl :- - adc #labels_voffset - sta select_volume_rect::y1 - lda #0 - sta select_volume_rect::y1+1 + ldx #0 + + ldy #desktop_aux::dialog_label_height + jsr Multiply_16_8_16 + stax select_volume_rect::y1 + add16_8 select_volume_rect::y1, #labels_voffset, select_volume_rect::y1 + add16 select_volume_rect::x1, #label_width-1, select_volume_rect::x2 add16 select_volume_rect::y1, #desktop_aux::dialog_label_height-1, select_volume_rect::y2 MGTK_RELAY_CALL MGTK::SetPenMode, penXOR