Repository navigation
Expand file tree
/
Copy pathalert_dialog.s
More file actions
542 lines (456 loc) · 17.5 KB
/
Copy pathalert_dialog.s
File metadata and controls
542 lines (456 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
;;; ============================================================
;;; Alert Dialog Definition
;;;
;;; Call `Alert` with A,X = `AlertParams` struct
;;;
;;; Requires the following proc definitions:
;;; * `Bell`
;;; * `SystemTask`
;;; Requires the following data definitions:
;;; * `alert_grafport`
;;; Requires the following macro definitions:
;;; * `MGTK_CALL`
;;; * `BTK_CALL`
;;; Optionally define:
;;; * `AD_YESNOALL` (if defined, yes/no/all buttons supported)
;;; * `AD_SAVEBG` (if defined, background saved/restored)
;;; * `AD_EJECTABLE` (if defined, polls for certain messages)
;;; If `AD_EJECTABLE`. requires `WaitForDiskOrEsc` and `ejectable_flag`
;;; ============================================================
.proc Alert
jmp start
question_bitmap:
PIXELS "....................................."
PIXELS ".###########........................."
PIXELS ".###########........................."
PIXELS ".###########........................."
PIXELS ".###########.........#########......."
PIXELS ".####..#####......###############...."
PIXELS ".####..#####.....####.........####..."
PIXELS ".####..#####....####...........####.."
PIXELS ".###########....####...#####...####.."
PIXELS ".###########....####...#####...####.."
PIXELS ".###########....############...####.."
PIXELS ".###########....###########...#####.."
PIXELS ".###########....##########...######.."
PIXELS ".###########....#########...#######.."
PIXELS ".###########....########...########.."
PIXELS ".###########....#######...#########.."
PIXELS ".###########....#######...#########.."
PIXELS ".#####..........###################.."
PIXELS ".########.......#######...########..."
PIXELS ".########......########...#######...."
PIXELS ".###........##################......."
PIXELS ".########............................"
PIXELS ".########............................"
PIXELS "....................................."
exclamation_bitmap:
PIXELS "....................................."
PIXELS ".###########........................."
PIXELS ".###########........................."
PIXELS ".###########........................."
PIXELS ".###########.........#########......."
PIXELS ".####..#####......###############...."
PIXELS ".####..#####.....######....#######..."
PIXELS ".####..#####....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....#######....########.."
PIXELS ".###########....###################.."
PIXELS ".#####..........#######....########.."
PIXELS ".########.......#######....#######..."
PIXELS ".########......##################...."
PIXELS ".###........##################......."
PIXELS ".########............................"
PIXELS ".########............................"
PIXELS "....................................."
kAlertMarginX = kModalDialogInsetX
kAlertMarginY = kModalDialogInsetY
kAlertBitmapWidth = 37
kAlertBitmapHeight = 24
.params alert_bitmap_params
DEFINE_POINT viewloc, kAlertRectLeft + kAlertMarginX, kAlertRectTop + kAlertMarginY
mapbits: .addr SELF_MODIFIED
mapwidth: .byte 6
reserved: .byte 0
DEFINE_RECT maprect, 0, 0, kAlertBitmapWidth-1, kAlertBitmapHeight-1
REF_MAPINFO_MEMBERS
.endparams
pencopy: .byte MGTK::pencopy
notpencopy: .byte MGTK::notpencopy
event_params: .tag MGTK::Event
event_kind := event_params + MGTK::Event::kind
event_coords := event_params + MGTK::Event::xcoord
event_key := event_params + MGTK::Event::key
;;; Bounds of the alert "window"
kAlertRectWidth = 420
kAlertRectHeight = 58
kAlertRectLeft = (::kScreenWidth - kAlertRectWidth)/2
kAlertRectTop = (::kScreenHeight - kAlertRectHeight)/2
;;; Window frame is outside the rect proper
kAlertFrameLeft = kAlertRectLeft - 1
kAlertFrameTop = kAlertRectTop - 1
kAlertFrameWidth = kAlertRectWidth + 2
kAlertFrameHeight = kAlertRectHeight + 2
DEFINE_RECT_SZ alert_rect, kAlertFrameLeft, kAlertFrameTop, kAlertFrameWidth, kAlertFrameHeight
;;; Inner frame
pensize_normal: .byte 1, 1
pensize_frame: .byte kBorderDX, kBorderDY
DEFINE_RECT_SZ alert_inner_frame_rect, kAlertRectLeft + kBorderDX, kAlertRectTop + kBorderDY, kAlertRectWidth - kBorderDX*3 + 1, kAlertRectHeight - kBorderDY*3 + 1
;;; --------------------------------------------------
kAlertButtonTop = kAlertRectTop + kAlertRectHeight - kButtonHeight - kModalDialogInsetY + 1
kAlertButtonRight = kAlertRectLeft + (kAlertRectWidth + 1) - kModalDialogInsetX
kAlertButtonLeft = kAlertRectLeft + kModalDialogInsetX
DEFINE_BUTTON ok_button, 0, res_string_button_ok, kGlyphReturn, kAlertButtonRight - kButtonWidth, kAlertButtonTop
DEFINE_BUTTON try_again_button, 0, res_string_button_try_again, res_char_button_try_again_shortcut, kAlertButtonRight - kButtonWidth, kAlertButtonTop
DEFINE_BUTTON cancel_button, 0, res_string_button_cancel, res_string_button_cancel_shortcut, kAlertButtonLeft, kAlertButtonTop
.ifdef AD_YESNOALL
kYNAButtonWidth = 71
DEFINE_BUTTON yes_button, 0, res_string_button_yes, res_char_button_yes_shortcut, kAlertButtonRight - kYNAButtonWidth*3 - kControlMarginX*2, kAlertButtonTop, kYNAButtonWidth
DEFINE_BUTTON no_button, 0, res_string_button_no, res_char_button_no_shortcut, kAlertButtonRight - kYNAButtonWidth*2 - kControlMarginX*1, kAlertButtonTop, kYNAButtonWidth
DEFINE_BUTTON all_button, 0, res_string_button_all, res_char_button_all_shortcut, kAlertButtonRight - kYNAButtonWidth*1 - kControlMarginX*0, kAlertButtonTop, kYNAButtonWidth
.endif ; AD_YESNOALL
kTextLeft = kAlertRectLeft + kAlertMarginX + kAlertBitmapWidth + 15
kTextRight = kAlertRectLeft + kAlertRectWidth - kAlertMarginX
kWrapWidth = kTextRight - kTextLeft
.if kBuildIsRTL
DEFINE_POINT pos_prompt1, kTextRight, kAlertRectTop + kAlertMarginY + kSystemFontHeight*2 + 2
DEFINE_POINT pos_prompt2, kTextRight, kAlertRectTop + kAlertMarginY + kSystemFontHeight*1
pos_prompt := pos_prompt1
.else
DEFINE_POINT pos_prompt1, kTextLeft, kAlertRectTop + kAlertMarginY + kSystemFontHeight*1
DEFINE_POINT pos_prompt2, kTextLeft, kAlertRectTop + kAlertMarginY + kSystemFontHeight*2 + 2
pos_prompt := pos_prompt2
.endif
.params textwidth_params ; Used for spitting/drawing the text.
data: .addr 0
length: .byte 0
width: .word 0
.endparams
len: .byte 0 ; total string length
split_pos: ; last known split position
.byte 0
test_pos:
.byte 0
.params alert_params
text: .addr 0
buttons: .byte 0 ; AlertButtonOptions
options: .byte 0 ; AlertOptions flags
.endparams
ASSERT_EQUALS .sizeof(alert_params), .sizeof(AlertParams)
kShortcutTryAgain = res_char_button_try_again_shortcut
.ifdef AD_YESNOALL
kShortcutYes = res_char_button_yes_shortcut
kShortcutNo = res_char_button_no_shortcut
kShortcutAll = res_char_button_all_shortcut
.endif ; AD_YESNOALL
;; Actual entry point
start:
;; Copy passed params
stax addr
ldx #.sizeof(AlertParams)-1
DO
addr := *+1
lda SELF_MODIFIED,x
sta alert_params,x
WHILE dex : POS
MGTK_CALL MGTK::GetCursorAdr, saved_cursor_addr
MGTK_CALL MGTK::SetCursor, MGTK::SystemCursor::pointer
;; --------------------------------------------------
;; Draw alert
.ifdef AD_SAVEBG
IF bit alert_params::options : VS ; V = use save area
MGTK_CALL MGTK::SaveScreenRect, alert_rect
END_IF
.endif ; AD_SAVEBG
;; Set up GrafPort - all drawing is in screen coordinates
MGTK_CALL MGTK::InitPort, alert_grafport
MGTK_CALL MGTK::SetPort, alert_grafport
MGTK_CALL MGTK::HideCursor
;; --------------------------------------------------
;; Draw alert box and bitmap
MGTK_CALL MGTK::SetPenMode, pencopy
MGTK_CALL MGTK::PaintRect, alert_rect ; alert background
MGTK_CALL MGTK::SetPenMode, notpencopy
MGTK_CALL MGTK::FrameRect, alert_rect ; alert outline
MGTK_CALL MGTK::SetPenSize, pensize_frame
MGTK_CALL MGTK::FrameRect, alert_inner_frame_rect
MGTK_CALL MGTK::SetPenSize, pensize_normal
ldax #exclamation_bitmap
ldy alert_params::buttons
IF NOT_ZERO
ldax #question_bitmap
END_IF
stax alert_bitmap_params::mapbits
MGTK_CALL MGTK::SetPenMode, pencopy
MGTK_CALL MGTK::PaintBits, alert_bitmap_params
;; --------------------------------------------------
;; Draw appropriate buttons
.ifdef AD_EJECTABLE
bit ejectable_flag
bmi done_buttons
.endif
bit alert_params::buttons ; high bit clear = OK only
bpl draw_ok_btn
;; Cancel button
BTK_CALL BTK::Draw, cancel_button
bit alert_params::buttons ; V bit set = Cancel + OK
bvs draw_ok_btn
.ifdef AD_YESNOALL
;; Yes/No/All?
lda alert_params::buttons
and #$0F
IF NOT_ZERO
BTK_CALL BTK::Draw, yes_button
BTK_CALL BTK::Draw, no_button
BTK_CALL BTK::Draw, all_button
jmp done_buttons
END_IF
.endif
;; Try Again button
BTK_CALL BTK::Draw, try_again_button
jmp done_buttons
;; OK button
draw_ok_btn:
BTK_CALL BTK::Draw, ok_button
done_buttons:
;; --------------------------------------------------
;; Prompt string
.scope
;; Measure for splitting
ldxy alert_params::text
inxy
stxy textwidth_params::data
ptr := $06
copy16 alert_params::text, ptr
ldy #0
lda (ptr),y
sta len ; total length
.if kBuildIsRTL
tay
iny
.endif
sty split_pos ; initialize
;; Search for space or end of string
advance:
DO
.if kBuildIsRTL
dey
BREAK_IF Y = #1
.else
iny
BREAK_IF Y = len
.endif
lda (ptr),y
WHILE A <> #' '
;; Does this much fit?
sty test_pos
.if kBuildIsRTL
add16_8 alert_params::text, test_pos, textwidth_params::data
lda len
sec
sbc test_pos
sta textwidth_params::length
.else
sty textwidth_params::length
.endif
MGTK_CALL MGTK::TextWidth, textwidth_params
.if kBuildIsRTL
add16_8 alert_params::text, #1, textwidth_params::data
.endif
IF u16 textwidth_params::width < #kWrapWidth
;; Yes, record possible split position, maybe continue.
ldy test_pos
sty split_pos
.if kBuildIsRTL
cpy #1 ; hit start of string?
.else
cpy len ; hit end of string?
.endif
bne advance ; no, keep looking
;; Whole string fits, just draw it.
copy8 len, textwidth_params::length
MGTK_CALL MGTK::MoveTo, pos_prompt
MGTK_CALL MGTK::DrawTextForward, textwidth_params
beq done ; always
END_IF
;; Split string over two lines.
ldx split_pos
dex ; eliminate the split position itself
stx textwidth_params::length
MGTK_CALL MGTK::MoveTo, pos_prompt1
MGTK_CALL MGTK::DrawTextForward, textwidth_params
add16_8 textwidth_params::data, split_pos
lda len
sec
sbc split_pos
sta textwidth_params::length
MGTK_CALL MGTK::MoveTo, pos_prompt2
MGTK_CALL MGTK::DrawTextForward, textwidth_params
done:
.endscope
MGTK_CALL MGTK::ShowCursor
;; --------------------------------------------------
;; Play bell
IF bit alert_params::options : NS ; N = play sound
jsr Bell
END_IF
;; --------------------------------------------------
;; Event Loop
event_loop:
.ifdef AD_EJECTABLE
IF bit ejectable_flag : NS
jsr WaitForDiskOrEsc
beq finish_ok
jmp finish_cancel
END_IF
.endif ; AD_EJECTABLE
jsr SystemTask
MGTK_CALL MGTK::GetEvent, event_params
lda event_kind
IF A = #MGTK::EventKind::button_down JUMP HandleButtonDown
IF A <> #MGTK::EventKind::key_down GOTO event_loop
;; --------------------------------------------------
;; Key Down
lda event_key
jsr ToUpperCase
bit alert_params::buttons ; high bit clear = OK only
bpl check_only_ok
IF A = #CHAR_ESCAPE
;; Cancel
BTK_CALL BTK::Flash, cancel_button
finish_cancel:
lda #kAlertResultCancel
jmp finish
END_IF
bit alert_params::buttons ; V bit set = Cancel + OK
bvs check_ok
.ifdef AD_YESNOALL
pha
lda alert_params::buttons
and #$0F
IF NOT_ZERO
pla
IF A = #kShortcutNo
BTK_CALL BTK::Flash, no_button
lda #kAlertResultNo
jmp finish
END_IF
IF A = #kShortcutYes
BTK_CALL BTK::Flash, yes_button
lda #kAlertResultYes
jmp finish
END_IF
IF A = #kShortcutAll
BTK_CALL BTK::Flash, all_button
lda #kAlertResultAll
jmp finish
END_IF
bne event_loop ; always
END_IF
pla
.endif ; AD_YESNOALL
IF A = #kShortcutTryAgain
do_try_again:
BTK_CALL BTK::Flash, try_again_button
lda #kAlertResultTryAgain
jmp finish
END_IF
IF A = #CHAR_RETURN GOTO do_try_again ; also allow Return as default
jmp event_loop
check_only_ok:
IF A = #CHAR_ESCAPE GOTO do_ok ; also allow Escape as default
check_ok:
IF A <> #CHAR_RETURN GOTO event_loop
do_ok: BTK_CALL BTK::Flash, ok_button
finish_ok:
lda #kAlertResultOK
jmp finish ; not a fixed value, cannot BNE/BEQ
;; --------------------------------------------------
;; Buttons
HandleButtonDown:
MGTK_CALL MGTK::MoveTo, event_coords
bit alert_params::buttons ; high bit clear = OK only
bpl check_ok_rect
;; Cancel
MGTK_CALL MGTK::InRect, cancel_button+BTK::ButtonRecord::rect
IF NOT_ZERO
BTK_CALL BTK::Track, cancel_button
IF ZC GOTO was_no_button ; N=0/Z=1 if clicked
lda #kAlertResultCancel
ASSERT_NOT_EQUALS ::kAlertResultCancel, 0
bne finish ; always
END_IF
bit alert_params::buttons ; V bit set = Cancel + OK
bvs check_ok_rect
.ifdef AD_YESNOALL
lda alert_params::buttons
and #$0F
IF NOT_ZERO
;; Yes & No & All
MGTK_CALL MGTK::InRect, yes_button+BTK::ButtonRecord::rect
IF NOT_ZERO
BTK_CALL BTK::Track, yes_button
IF ZC GOTO was_no_button ; N=0/Z=1 if clicked
lda #kAlertResultYes
ASSERT_NOT_EQUALS ::kAlertResultYes, 0
bne finish ; always
END_IF
MGTK_CALL MGTK::InRect, no_button+BTK::ButtonRecord::rect
IF NOT_ZERO
BTK_CALL BTK::Track, no_button
IF ZC GOTO was_no_button ; N=0/Z=1 if clicked
lda #kAlertResultNo
ASSERT_NOT_EQUALS ::kAlertResultNo, 0
bne finish ; always
END_IF
MGTK_CALL MGTK::InRect, all_button+BTK::ButtonRecord::rect
beq was_no_button
BTK_CALL BTK::Track, all_button
IF ZC GOTO was_no_button ; N=0/Z=1 if clicked
lda #kAlertResultAll
ASSERT_NOT_EQUALS ::kAlertResultAll, 0
bne finish ; always
END_IF
.endif
;; Try Again
MGTK_CALL MGTK::InRect, try_again_button+BTK::ButtonRecord::rect
beq was_no_button
BTK_CALL BTK::Track, try_again_button
bne was_no_button
lda #kAlertResultTryAgain
ASSERT_EQUALS ::kAlertResultTryAgain, 0
beq finish ; always
;; OK
check_ok_rect:
MGTK_CALL MGTK::InRect, ok_button+BTK::ButtonRecord::rect
beq was_no_button
BTK_CALL BTK::Track, ok_button
bne was_no_button
lda #kAlertResultOK
ASSERT_NOT_EQUALS ::kAlertResultOK, 0
bne finish ; always
was_no_button:
jmp event_loop
;;; ============================================================
finish:
pha
.ifdef AD_SAVEBG
IF bit alert_params::options : VS ; V = use save area
MGTK_CALL MGTK::RestoreScreenRect, alert_rect
END_IF
.else
MGTK_CALL MGTK::SetPenMode, pencopy
MGTK_CALL MGTK::PaintRect, alert_rect
.endif ; AD_SAVEBG
MGTK_CALL MGTK::SetCursor, SELF_MODIFIED, saved_cursor_addr
pla
rts
;;; ============================================================
.include "uppercase.s"
.endproc ; Alert