From ee932924a64e7f6d939791a3ac6c413603c8ef19 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 16 Feb 2018 12:14:39 -0800 Subject: [PATCH] main loop --- desktop.inc | 2 +- desktop/desktop.s | 265 +++++++++++++++++++++++++++------------------- mgtk.inc | 1 + 3 files changed, 159 insertions(+), 109 deletions(-) diff --git a/desktop.inc b/desktop.inc index 099de75..6fe7c6b 100644 --- a/desktop.inc +++ b/desktop.inc @@ -10,7 +10,7 @@ DA_MAX_SIZE := $1C00 - DA_LOAD_ADDRESS ;;; * = Used by Desk Accessories -JUMP_TABLE_00 := $4000 ; ??? +JUMP_TABLE_MAIN_LOOP := $4000 ; Enter DeskTop main loop JUMP_TABLE_MGTK_RELAY := $4003 ; MGTK relay call (main>aux) JUMP_TABLE_SIZE_STRING := $4006 ; Compose "nnn Blocks" string into internal buffer JUMP_TABLE_DATE_STRING := $4009 ; Compose date string into internal buffer diff --git a/desktop/desktop.s b/desktop/desktop.s index 6384ea5..68b6d66 100644 --- a/desktop/desktop.s +++ b/desktop/desktop.s @@ -4305,11 +4305,15 @@ notpenBIC: .byte 7 event_params := * event_params_kind := event_params + 0 + ;; if kind is key_down event_params_key := event_params + 1 event_params_modifiers := event_params + 2 + ;; if kind is no_event, button_down/up, drag, or apple_key: event_params_coords := event_params + 1 event_params_xcoord := event_params + 1 event_params_ycoord := event_params + 3 + ;; if kind is update: +event_params_window_id := event_params + 1 activatectl_params := * activatectl_params_which_ctl := activatectl_params @@ -5047,9 +5051,11 @@ LE061: .byte $00 LE062: .res 170, 0 LE10C: .res 138, 0 -LE196: .res 10, 0 ; device table??? +DESKTOP_DEVICELIST: + .res 10, 0 devlst_copy: .res 16, 0 + LE1B0: .res 65, 0 ; path buffer? LE1F1: .res 15, 0 ; length-prefixed string LE200: .word 0 @@ -5797,7 +5803,7 @@ L0D14 := $0D14 ;; Entries marked with * are used by DAs ;; "Exported" by desktop.inc -L4000: jmp L4042 ; entry point +JT_MAIN_LOOP: jmp enter_main_loop JT_MGTK_RELAY: jmp MGTK_RELAY JT_SIZE_STRING: jmp compose_blocks_string JT_DATE_STRING: jmp compose_date_string @@ -5820,20 +5826,21 @@ JT_CUR_POINTER: jmp set_pointer_cursor ; * JT_CUR_WATCH: jmp set_watch_cursor JT_RESTORE_SEF: jmp restore_dynamic_routine - ;; API entry point -L4042: cli + ;; Main Loop +.proc enter_main_loop + cli sta ALTZPON lda LCBANK1 lda LCBANK1 jsr L4530 - ldx #$00 + ldx #0 L4051: cpx cached_window_icon_count beq L4069 txa pha lda cached_window_icon_list,x jsr icon_entry_lookup - ldy #$01 + ldy #1 jsr DESKTOP_RELAY pla tax @@ -5843,50 +5850,61 @@ L4051: cpx cached_window_icon_count L4069: lda #0 sta cached_window_id jsr DESKTOP_COPY_FROM_BUF - lda #$00 + lda #0 sta LD2A9 sta double_click_flag sta L40DF sta $E26F lda L599F - beq L4088 + beq main_loop tay jsr DESKTOP_SHOW_ALERT0 -L4088: jsr reset_grafport3 + + ;; Main loop + +main_loop: + jsr reset_grafport3 inc L40DF inc L40DF lda L40DF cmp machine_type bcc L40A6 - lda #$00 + lda #0 sta L40DF jsr L4563 beq L40A6 jsr L40E0 L40A6: jsr L464E + + ;; Get an event jsr get_event lda event_params_kind + + ;; Is it a button-down event? (including w/ modifiers) cmp #MGTK::event_kind_button_down - beq L40B7 + beq click cmp #MGTK::event_kind_apple_key - bne L40BD -L40B7: jsr handle_click - jmp L4088 + bne :+ +click: jsr handle_click + jmp main_loop -L40BD: cmp #$03 - bne L40C7 - jsr menu_dispatch - jmp L4088 + ;; Is it a key down event? +: cmp #MGTK::event_kind_key_down + bne :+ + jsr handle_keydown + jmp main_loop -L40C7: cmp #$06 - bne L40DC + ;; Is it an update event? +: cmp #MGTK::event_kind_update + bne :+ jsr reset_grafport3 lda active_window_id sta L40F0 lda #$80 sta L40F1 jsr L410D -L40DC: jmp L4088 + +: jmp main_loop L40DF: .byte $00 L40E0: tsx @@ -5907,15 +5925,15 @@ redraw_windows: sta L40F1 L4100: jsr peek_event lda event_params_kind - cmp #$06 ; ??? + cmp #MGTK::event_kind_update bne L412B jsr get_event L410D: jsr L4113 jmp L4100 -L4113: MGTK_RELAY_CALL MGTK::BeginUpdate, event_params+1 - bne L4151 - jsr L4153 +L4113: MGTK_RELAY_CALL MGTK::BeginUpdate, event_params_window_id + bne L4151 ; did not really need updating + jsr update_window MGTK_RELAY_CALL MGTK::EndUpdate rts @@ -5933,9 +5951,18 @@ L4143: bit L40F1 DESKTOP_RELAY_CALL DT_REDRAW_ICONS L4151: rts +.endproc + main_loop := enter_main_loop::main_loop + redraw_windows := enter_main_loop::redraw_windows + +;;; ================================================== + + L4152: .byte 0 -L4153: lda event_params+1 - cmp #$09 + + +update_window: lda event_params_window_id + cmp #9 ; only handle windows 0...8 bcc L415B rts @@ -6079,7 +6106,7 @@ L42C3: .byte $00 ;;; ================================================== ;;; Menu Dispatch -.proc menu_dispatch_impl +.proc handle_keydown_impl ;; jump table for menu item handlers dispatch_table: @@ -6176,7 +6203,7 @@ offset_table: flag: .byte $00 ;; Handle accelerator keys -menu_dispatch: +handle_keydown: lda event_params_modifiers bne :+ ; either OA or CA ? jmp menu_accelerators ; nope @@ -6242,9 +6269,9 @@ L43E0: tsx jmp dummy1234 ; self-modified .endproc - menu_dispatch := menu_dispatch_impl::menu_dispatch - menu_dispatch2 := menu_dispatch_impl::menu_dispatch2 - menu_dispatch_flag := menu_dispatch_impl::flag + handle_keydown := handle_keydown_impl::handle_keydown + menu_dispatch2 := handle_keydown_impl::menu_dispatch2 + menu_dispatch_flag := handle_keydown_impl::flag ;;; ================================================== ;;; Handle click @@ -6534,13 +6561,13 @@ L463A: .byte $01 L463E: .res 16, 0 L464E: lda LD343 - beq L465E + beq :+ bit LD343+1 bmi L4666 jsr enable_selector_menu_items jmp L4666 -L465E: bit LD343+1 +: bit LD343+1 bmi L4666 jsr disable_selector_menu_items L4666: lda is_file_selected @@ -6548,14 +6575,14 @@ L4666: lda is_file_selected lda selected_window_index bne L4691 lda is_file_selected - cmp #$02 + cmp #2 bcs L4697 lda selected_file_index cmp trash_icon_num bne L468B jsr disable_eject_menu_item jsr disable_file_menu_items - lda #$00 + lda #0 sta $E26F rts @@ -6800,9 +6827,9 @@ show_cursor: ;;; ================================================== .proc L48BE - ldx $E196 + ldx DESKTOP_DEVICELIST inx -: lda $E196,x +: lda DESKTOP_DEVICELIST,x sta DEVCNT,x dex bpl :- @@ -6815,7 +6842,7 @@ show_cursor: rts .endproc - copy16 #L4088, L48E4 + copy16 #main_loop, L48E4 L48E4 := *+1 jmp dummy1234 ; self-modified @@ -6928,7 +6955,7 @@ L49A6: lda menu_click_params::item_num sec sbc #$06 sta L49A5 - jsr a_times_4 + jsr a_times_16 clc adc #$1E sta $06 @@ -6962,7 +6989,7 @@ L49ED: lda L49A5 jmp L4A0A L49FA: lda L49A5 - jsr a_times_6 + jsr a_times_64 clc adc #$9E sta $06 @@ -7000,7 +7027,7 @@ L4A2B: iny L4A46: .byte 0 L4A47: pha - jsr a_times_6 + jsr a_times_64 clc adc #$9E sta $06 @@ -7135,7 +7162,7 @@ L4AEA: jsr L4B5F sta L4BB0 addr_call copy_LD3EE_str, path_buffer lda L4BB0 - jsr a_times_6 + jsr a_times_64 clc adc #<$DB9E sta $06 @@ -7197,7 +7224,7 @@ start: jsr reset_grafport3 lda menu_click_params::item_num ; menu item index (1-based) sec sbc #3 ; About and separator before first item - jsr a_times_4 + jsr a_times_16 clc adc #$1402 + adc #>(selector_list_data_buf+2) tax tya rts -L0AA2: jsr desktop_main::a_times_4 +calc_entry_addr: + jsr desktop_main::a_times_16 clc adc #$1582 + adc #>(selector_list_data_buf+2 + $180) tax tya rts +;;; -------------------------------------------------- + .proc open_params param_count: .byte 3 pathname: .addr str_selector_list -io_buffer: .addr $1000 +io_buffer: .addr selector_list_io_buf ref_num: .byte 0 .endproc @@ -20139,8 +20184,8 @@ str_selector_list: .proc read_params param_count: .byte 4 ref_num: .byte 0 -read_buffer: .addr $1400 -request_count: .word $400 +read_buffer: .addr selector_list_data_buf +request_count: .word selector_list_data_len trans_count: .word 0 .endproc @@ -20149,12 +20194,14 @@ param_count: .byte 1 ref_num: .byte 0 .endproc -L0AE7: MLI_RELAY_CALL OPEN, open_params +read_selector_list: + MLI_RELAY_CALL OPEN, open_params lda open_params::ref_num sta read_params::ref_num MLI_RELAY_CALL READ, read_params MLI_RELAY_CALL CLOSE, close_params rts +.endproc ;;; ================================================== @@ -20374,7 +20421,8 @@ L0D09: .byte 0 ;;; ================================================== -L0D0A: ldy #$00 +.proc L0D0A + ldy #$00 sty desktop_main::L599F sty L0E33 L0D12: lda L0E33 @@ -20523,6 +20571,7 @@ L0E2F: jmp L0D12 L0E32: .byte 0 L0E33: .byte 0 L0E34: .byte 0 +.endproc ;;; ================================================== diff --git a/mgtk.inc b/mgtk.inc index 3307c79..81a8bfc 100644 --- a/mgtk.inc +++ b/mgtk.inc @@ -531,6 +531,7 @@ event_kind_button_up := 2 ; Mouse button was released event_kind_key_down := 3 ; Key was pressed event_kind_drag := 4 ; Mouse button still down event_kind_apple_key := 5 ; Mouse button was depressed, modifier key down +event_kind_update := 6 ; Window update needed event_modifier_open_apple := 1 << 0 event_modifier_solid_apple := 1 << 1