Skip to content

Commit

Permalink
Add MGTK Font file support for Preview.
Browse files Browse the repository at this point in the history
Correct docs for some DeskTop icon APIs, and improve resilience of
some of the APIs to having atypical grafports selected when called.
  • Loading branch information
inexorabletash committed Jul 27, 2019
1 parent 6e96eae commit 157c6a3
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 67 deletions.
16 changes: 7 additions & 9 deletions APIs.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ Removes an icon by number.

Parameters: { byte window_id }

Highlights (selects) all icons in a window.
Highlights (selects) all icons in specified window (0 = desktop).

### `DT_UNHIGHLIGHT_ALL` ($06)
### `DT_REMOVE_ALL` ($06)

Parameters: _N/A_
Parameters: { byte window_id }

Unhighlights (deselects) all icons.
Removes all icons from specified window (0 = desktop).

### `DT_CLOSE_WINDOW` ($07)

Expand Down Expand Up @@ -234,13 +234,11 @@ Parameters: { byte icon, rect bounds }

Tests to see if the given icon (by number) overlaps the passed rect.

### `DT_REDRAW_ICON_IDX` ($0E)

Parameters: { byte icon_index }
### `DT_ERASE_ICON` ($0E)

Redraws the icon at the given index in the icon list. Note that this
is not the same as the icon number.
Parameters: { byte icon }

Erases the specified icon by number. No error checking is done.


<!-- ============================================================ -->
Expand Down
22 changes: 13 additions & 9 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,21 @@ functionality (see below).

### Automatic Preview

Text and Graphics files with the correct file types can be previewed
without leaving DeskTop; select the file icon then select File > Open,
or double-click the file icon. Text files must be type TXT ($04).
Graphics files must be type FOT ($08), or BIN ($06) with an aux type
of $2000 or $4000 and 17 or 33 blocks (hi-res/double hi-res) or $5800
and 3 blocks (Minipix a.k.a. Print Shop).
Text, Graphics and Font files with the correct file types can be
previewed without leaving DeskTop; select the file icon then select
File > Open, or double-click the file icon.

* Text files must be type TXT ($04).
* Graphics files must be type FOT ($08), or BIN ($06) with an aux type
of $2000 or $4000 and 17 or 33 blocks (hi-res/double hi-res) or $5800
and 3 blocks (Minipix a.k.a. Print Shop).
* Font files must be MGTK fonts with type FNT ($07).

To preview files of other types, you can copy the preview handlers
named `SHOW.TEXT.FILE` and `SHOW.IMAGE.FILE` from the `PREVIEW` folder
to the `DESK.ACC` folder, and restart DeskTop. To use them, select the
file, then select the appropriate command from the Apple menu.
named `SHOW.TEXT.FILE`, `SHOW.IMAGE.FILE`, etc. from the `PREVIEW`
folder to the `DESK.ACC` folder, and restart DeskTop. To use them,
select the file, then select the appropriate command from the Apple
menu.

### Notable Fixes

Expand Down
4 changes: 2 additions & 2 deletions desktop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ DT_HIGHLIGHT_ICON = $02 ; { .byte icon }
DT_REDRAW_ICON = $03 ; { .byte icon }
DT_REMOVE_ICON = $04 ; { .byte icon }
DT_HIGHLIGHT_ALL = $05 ; { .byte window_id }
DT_UNHIGHLIGHT_ALL = $06
DT_REMOVE_ALL = $06 ; { .byte window_id }
DT_CLOSE_WINDOW = $07 ; { .byte window_id }
DT_GET_HIGHLIGHTED = $08 ; { .res 20 }
DT_FIND_ICON = $09 ; { .word mousex, .word mousey, .byte result }
Expand All @@ -107,7 +107,7 @@ DT_DRAG_HIGHLIGHTED = $0A ; { .byte param }
DT_UNHIGHLIGHT_ICON = $0B ; { .addr iconentry }
DT_REDRAW_ICONS = $0C ; Repaints desktop icons *
DT_ICON_IN_RECT = $0D ; { .byte icon, rect bounds }
DT_REDRAW_ICON_IDX = $0E ; { .byte icon_index }
DT_ERASE_ICON = $0E ; { .byte icon }

;;; `icon` is the icon number, i.e. first field in icon entry
;;; `icon_index` is the index in the icon table
Expand Down
119 changes: 75 additions & 44 deletions desktop/desktop_aux.s
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ desktop_jump_table:
.addr REDRAW_ICON_IMPL
.addr REMOVE_ICON_IMPL
.addr HIGHLIGHT_ALL_IMPL
.addr UNHIGHLIGHT_ALL_IMPL
.addr REMOVE_ALL_IMPL
.addr CLOSE_WINDOW_IMPL
.addr GET_HIGHLIGHTED_IMPL
.addr FIND_ICON_IMPL
.addr DRAG_HIGHLIGHTED
.addr UNHIGHLIGHT_ICON_IMPL
.addr REDRAW_ICONS_IMPL
.addr ICON_IN_RECT_IMPL
.addr REDRAW_ICON_IDX_IMPL
.addr ERASE_ICON_IMPL

.macro DESKTOP_DIRECT_CALL op, addr, label
jsr DESKTOP_DIRECT
Expand Down Expand Up @@ -521,6 +521,8 @@ sub: ldx num_icons ; ???
;;; ============================================================
;;; HIGHLIGHT_ICON IMPL

;;; param is pointer to icon id

.proc HIGHLIGHT_ICON_IMPL
PARAM_BLOCK params, $06
ptr_icon: .addr 0
Expand All @@ -541,7 +543,7 @@ bail1: return #1 ; Not found

: asl a
tax
copy16 icon_ptrs,x, ptr
copy16 icon_ptrs,x, ptr ; ptr now points at IconEntry
ldy #IconEntry::state
lda (ptr),y
bne :+ ; Already set ??? Routine semantics are incorrect ???
Expand Down Expand Up @@ -582,13 +584,23 @@ L949D: ldx highlight_count
ldx #1 ; new position
jsr change_icon_index

jsr paint_icon_highlighted
;; Redraw
ldy #IconEntry::id
lda (ptr),y ; icon num
sta icon
DESKTOP_DIRECT_CALL DT_REDRAW_ICON, icon
return #0 ; Highlighted

;; DT_REDRAW_ICON params
icon: .byte 0
.endproc

;;; ============================================================
;;; REDRAW_ICON IMPL

;;; * Assumes correct grafport already selected/maprect specified
;;; * Does not erase background

.proc REDRAW_ICON_IMPL
PARAM_BLOCK params, $06
ptr_icon: .addr 0
Expand Down Expand Up @@ -672,7 +684,7 @@ found: asl a

;; Unhighlight
: jsr calc_icon_poly
jsr draw_icon
jsr erase_icon

;; Move it to the end of the icon list
ldy #IconEntry::id
Expand Down Expand Up @@ -723,9 +735,9 @@ done: return #0 ; Unhighlighted
.endproc

;;; ============================================================
;;; REDRAW_ICON_IDX IMPL
;;; ERASE_ICON IMPL

.proc REDRAW_ICON_IDX_IMPL
.proc ERASE_ICON_IMPL
PARAM_BLOCK params, $06
ptr_icon_idx: .addr 0
END_PARAM_BLOCK
Expand All @@ -736,7 +748,7 @@ ptr_icon_idx: .addr 0
asl a
tax
copy16 icon_ptrs,x, ptr
jmp draw_icon
jmp erase_icon
.endproc

;;; ============================================================
Expand Down Expand Up @@ -821,35 +833,47 @@ loop2: lda buffer,x
.endproc

;;; ============================================================
;;; UNHIGHLIGHT_ALL IMPL
;;; REMOVE_ALL IMPL

.proc UNHIGHLIGHT_ALL_IMPL
jmp L9697
;;; param is window id (0 = desktop)

L9695: .byte 0
L9696: .byte 0
.proc REMOVE_ALL_IMPL
jmp start

L9697: lda num_icons
sta L9696
L969D: ldx L9696
PARAM_BLOCK params, $06
ptr_window_id: .addr 0
END_PARAM_BLOCK

icon_ptr := $08

;; DT_REMOVE_ICON params
icon: .byte 0

count: .byte 0

start: lda num_icons
sta count

loop: ldx count
cpx #0
beq L96CF
dec L9696
beq done
dec count
dex
lda icon_table,x
sta L9695
sta icon
asl a
tax
copy16 icon_ptrs,x, $08
copy16 icon_ptrs,x, icon_ptr
ldy #IconEntry::win_type
lda ($08),y
lda (icon_ptr),y
and #icon_entry_winid_mask
ldy #0
cmp ($06),y
bne L969D
DESKTOP_DIRECT_CALL DT_REMOVE_ICON, L9695
jmp L969D
L96CF: return #0
cmp (params::ptr_window_id),y
bne loop
DESKTOP_DIRECT_CALL DT_REMOVE_ICON, icon
jmp loop

done: return #0
.endproc

;;; ============================================================
Expand Down Expand Up @@ -1392,7 +1416,7 @@ L9BF3: dex
tax
copy16 icon_ptrs,x, $06
jsr calc_icon_poly
jsr draw_icon
jsr erase_icon
pla
tax
jmp L9BF3
Expand Down Expand Up @@ -1612,18 +1636,12 @@ L9EB4: asl a
;;; ============================================================
;;; UNHIGHLIGHT_ICON IMPL

;;; param is pointer to icon entry
;;; param is pointer to IconEntry

.proc UNHIGHLIGHT_ICON_IMPL
PARAM_BLOCK params, $06
ptr_iconent: .addr 0
END_PARAM_BLOCK
ptr := $06 ; Overwrites param

jmp start

;; DT_REDRAW_ICON params
icon: .byte 0

start: lda has_highlight
bne :+
Expand All @@ -1642,15 +1660,18 @@ start: lda has_highlight
dec highlight_count
lda highlight_count
bne :+
lda #0
lda #0 ; Clear flag if no more highlighted
sta has_highlight

;; Redraw
: ldy #0
: ldy #IconEntry::id
lda (params::ptr_iconent),y
sta icon
DESKTOP_DIRECT_CALL DT_REDRAW_ICON, icon
return #0

;; DT_REDRAW_ICON params
icon: .byte 0
.endproc

;;; ============================================================
Expand Down Expand Up @@ -1704,7 +1725,9 @@ L9F8F: return #1
.endproc

;;; ============================================================

;;; Paint icon
;;; * Assumes grafport selected and maprect configured
;;; * Does not erase background

icon_flags: ; bit 7 = highlighted, bit 6 = volume icon
.byte 0
Expand Down Expand Up @@ -1808,8 +1831,10 @@ highlighted: copy #$80, icon_flags ; is highlighted

bit icon_flags ; volume icon (on desktop) ?
bvc do_paint ; nope
;; TODO: This depends on a previous proc having adjusted
;; the grafport (for window maprect and window's items/used/free bar)

;; Redraw desktop background
;; Volume (i.e. icon on desktop)
MGTK_CALL MGTK::InitPort, grafport
jsr set_port_for_vol_icon
: jsr calc_window_intersections
Expand Down Expand Up @@ -2055,6 +2080,10 @@ LA2AA: jsr pop_pointers
rts

LA2AE: jsr push_pointers

MGTK_CALL MGTK::InitPort, icon_grafport
MGTK_CALL MGTK::SetPort, icon_grafport

ldx num_icons
dex
LA2B5: bmi LA2AA
Expand Down Expand Up @@ -2221,8 +2250,9 @@ stash: .word 0
.endproc

;;; ============================================================
;;; Erase an icon; redraws overlapping icons as needed

draw_icon:
erase_icon:
MGTK_CALL MGTK::InitPort, icon_grafport
MGTK_CALL MGTK::SetPort, icon_grafport
jmp LA3B9
Expand Down Expand Up @@ -2259,13 +2289,13 @@ window_id: .byte 0
;; File (i.e. icon in window)
copy #$80, LA3B7
MGTK_CALL MGTK::SetPattern, white_pattern
MGTK_CALL MGTK::FrontWindow, frontwindow_params
MGTK_CALL MGTK::FrontWindow, frontwindow_params ; Use window's port
lda frontwindow_params::window_id
sta getwinport_params::window_id
MGTK_CALL MGTK::GetWinPort, getwinport_params
jsr LA4CC
jsr shift_port_down
jsr erase_icon
jsr shift_port_down ; Further offset by window's items/used/free bar
jsr erase_window_icon
jmp LA446

;; Volume (i.e. icon on desktop)
Expand All @@ -2291,7 +2321,7 @@ volume:
;; fall through
.endproc

.proc erase_icon
.proc erase_window_icon
copy16 poly::v0::ycoord, LA3B1
copy16 poly::v6::xcoord, LA3AF
COPY_BLOCK poly::v4, LA3B3
Expand All @@ -2312,6 +2342,7 @@ LA446: jsr push_pointers
bne LA466
bit LA3B7 ; no, almost done
bpl :+
;; TODO: Is this restoration necessary?
MGTK_CALL MGTK::InitPort, icon_grafport
MGTK_CALL MGTK::SetPort, icon_grafport
: jsr pop_pointers
Expand Down Expand Up @@ -2895,7 +2926,7 @@ vert: cmp16 win_t, cr_t
;;; ============================================================

.proc shift_port_down
;; For window's used/free space bar
;; For window's items/used/free space bar
offset = 15

add16 icon_grafport::viewloc::ycoord, #offset, icon_grafport::viewloc::ycoord
Expand Down
Loading

0 comments on commit 157c6a3

Please sign in to comment.