/[james]/archive/cdicons/CDIcons+
ViewVC logotype

Contents of /archive/cdicons/CDIcons+

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations) (download)
Tue Jan 28 15:14:05 2003 UTC (21 years, 11 months ago) by james
File size: 14916 byte(s)
Initial import.

1 REM > CDIcons+
2 REM © James Bursa, 2000
3
4 ON ERROR ON ERROR OFF: ERROR 0, REPORT$ + "(" + STR$ERL + "/" + STR$ERR + ")"
5
6 CD_EMPTY = 0
7 CD_DATA = 1
8 CD_AUDIO = 2
9 MAX_TRACKS = 40
10
11 PROCcd_init
12 PROCwimp_init
13 PROCcddb_init
14 PROCwimp_update
15 PROCwimp_poll
16
17 END
18
19 REM********************************************************************************
20 REM CD handling
21 REM********************************************************************************
22
23 REM check how many drives are connected and initialise cd data
24
25 DEF PROCcd_init
26 LOCAL drive%, number%
27
28 SYS"CDFS_GetNumberOfDrives" TO cd_drives%
29 IF cd_drives% = 0 THEN ERROR 1, "CDIcons+ cannot detect any CD drives connected to this computer"
30
31 DIM cd_cb% 20, cd_b% 200
32 DIM cd_id%(cd_drives% - 1), cd_status%(cd_drives% - 1), cd_path$(cd_drives% - 1)
33
34 FOR drive% = 0 TO cd_drives% - 1
35 cd_id%(drive%) = -1
36 NEXT
37
38 ENDPROC
39
40 REM********************************************************************************
41
42 REM convert a CDFS drive number to a CDFS control block in cd_cb%
43
44 DEF PROCcd_device(drive%)
45 LOCAL device%
46 SYS"CDFS_ConvertDriveToDevice", drive% TO , device%
47 cd_cb%!00 = device% AND 7
48 cd_cb%!04 = (device% >> 3) AND 3
49 cd_cb%!08 = (device% >> 5) AND 7
50 cd_cb%!12 = (device% >> 8) AND &ff
51 cd_cb%!16 = device% >> 16
52 ENDPROC
53
54 REM********************************************************************************
55
56 REM return a nearly unique number identifying the cd, 0 if none
57
58 DEF FNcd_id(drive%)
59 PROCcd_device(drive%)
60 SYS"XCD_EnquireTrack", 0, cd_b%,,,,,, cd_cb% TO ;f%
61 IF f% AND 1 THEN =0
62 SYS"CD_DiscUsed", 0, cd_b%,,,,,, cd_cb%
63 =cd_b%!00
64
65 REM********************************************************************************
66
67 REM find out the type of cd and get information about it
68
69 DEF PROCcd_update(drive%)
70 LOCAL f%
71
72 CASE cd_status%(drive%) OF
73 WHEN CD_DATA:
74 PROCclosedir(cd_path$(drive%))
75 SYS"OS_CLI", "CDFS:Dismount " + MID$(cd_path$(drive%), 7, LENcd_path$(drive%) - 8)
76
77 WHEN CD_AUDIO:
78 PROCcddb_finished(drive%)
79
80 ENDCASE
81
82 PROCcd_device(drive%)
83 SYS"XCD_EnquireTrack", 1, cd_b%,,,,,, cd_cb% TO ;f%
84
85 CASE TRUE OF
86 WHEN (f% AND 1) = 1:
87 cd_status%(drive%) = CD_EMPTY
88
89 WHEN (cd_b%?04 AND 1) = 1:
90 cd_status%(drive%) = CD_DATA
91 SYS"OS_FSControl", 37, "CDFS::" + STR$drive%, cd_b%, 0, 0, 200 TO ,, cd_path$(drive%)
92 PROCopendir(cd_path$(drive%))
93
94 OTHERWISE:
95 cd_status%(drive%) = CD_AUDIO
96 PROCcddb_query(drive%)
97
98 ENDCASE
99 ENDPROC
100
101 REM********************************************************************************
102
103 REM call a CD_ swi
104
105 DEF PROCcd_swi(drive%, swi%, r0%, r1%)
106 PROCcd_device(drive%)
107 SYS &41240 + swi%, r0%, r1%,,,,,, cd_cb%
108 ENDPROC
109
110 REM********************************************************************************
111
112 REM return a string suitable for displaying under the icon
113
114 DEF FNcd_title(drive%)
115 LOCAL title$
116
117 CASE cd_status%(drive%) OF
118 WHEN CD_EMPTY: =STR$drive%
119 WHEN CD_DATA : =MID$(cd_path$(drive%), 7, LENcd_path$(drive%) - 8)
120 WHEN CD_AUDIO:
121 title$ = FNcddb_title(drive%)
122 IF title$ = "" THEN
123 =STR$drive%
124 ELSE
125 =title$
126 ENDIF
127 ENDCASE
128 =STR$drive%
129
130 REM********************************************************************************
131
132 REM return a string giving a suitable icon name for the drive
133
134 DEF FNcd_icon(drive%)
135 CASE cd_status%(drive%) OF
136 WHEN CD_EMPTY: ="nocddisc"
137 WHEN CD_DATA: ="cddisc"
138 WHEN CD_AUDIO: ="acddisc"
139 ENDCASE
140 ="cddisc"
141
142 REM********************************************************************************
143
144 DEF PROCcd_eject(drive%)
145 PROCcd_swi(drive%, &7, 0, 0)
146 ENDPROC
147
148 REM********************************************************************************
149
150 DEF PROCcd_close(drive%)
151 PROCcd_swi(drive%, &1b, 0, 0)
152 ENDPROC
153
154 REM********************************************************************************
155
156 DEF PROCcd_stop(drive%)
157 PROCcd_swi(drive%, &12, 0, 0)
158 ENDPROC
159
160 REM********************************************************************************
161
162 DEF FNcd_tracks(drive%)
163 PROCcd_device(drive%)
164 SYS"CD_EnquireTrack", 0, cd_b%,,,,,, cd_cb%
165 =cd_b%?1
166
167 REM********************************************************************************
168
169 DEF PROCcd_play(drive%, track%)
170 PROCcd_device(drive%)
171 SYS"CD_PlayTrack", track%, 255,,,,,, cd_cb%
172 ENDPROC
173
174 REM********************************************************************************
175
176 REM return playing track, 0 if not playing
177
178 DEF FNcd_playingtrack(drive%)
179 LOCAL status%, address%, tracks%, last%
180 PROCcd_device(drive%)
181 SYS"CD_AudioStatus",,,,,,,, cd_cb% TO status%
182 IF status% <> 0 THEN =0
183 SYS"CD_EnquireAddress", 0,,,,,,, cd_cb% TO address%
184 SYS"CD_EnquireTrack", 0, cd_b%,,,,,, cd_cb%
185 tracks% = cd_b%?1
186 FOR track% = 1 TO tracks%
187 SYS"CD_EnquireTrack", track%, cd_b%,,,,,, cd_cb%
188 IF cd_b%!0 > address% THEN =track% - 1
189 NEXT
190 =tracks%
191
192 REM********************************************************************************
193 REM Wimp interaction
194 REM********************************************************************************
195
196 REM initialise with the wimp
197
198 DEF PROCwimp_init
199 LOCAL drive%, data%, handle%, track%
200
201 DIM b% 1023, menu% 28 + 24 * 4, tmenu% 28 + 24 * MAX_TRACKS
202
203 b%!00 = &51bc1
204 b%!04 = 0
205 SYS"Wimp_Initialise", 310, &4b534154, "CDIcons+", b% TO , task%
206
207 DIM iconbar_icon%(cd_drives% - 1), iconbar_data%(cd_drives% - 1)
208
209 FOR drive% = 0 TO cd_drives% - 1
210 DIM data% 60
211 iconbar_icon%(drive%) = -1
212 iconbar_data%(drive%) = data%
213 NEXT
214
215 $(menu%) = "CDFS::?"
216 menu%!12 = &00070207
217 menu%!16 = 200
218 menu%!20 = 44
219 menu%!24 = 0
220
221 menu%!(28 + 0 * 24 + 00) = 0
222 menu%!(28 + 0 * 24 + 04) = -1
223 menu%!(28 + 0 * 24 + 08) = &07000011
224 $(menu% + 28 + 0 * 24 + 12) = "Dismount"
225
226 menu%!(28 + 1 * 24 + 00) = 0
227 menu%!(28 + 1 * 24 + 04) = -1
228 menu%!(28 + 1 * 24 + 08) = &07000011
229 $(menu% + 28 + 1 * 24 + 12) = "Eject"
230
231 menu%!(28 + 2 * 24 + 00) = 0
232 menu%!(28 + 2 * 24 + 04) = -1
233 menu%!(28 + 2 * 24 + 08) = &07000011
234 $(menu% + 28 + 2 * 24 + 12) = "Close"
235
236 menu%!(28 + 3 * 24 + 00) = &80
237 menu%!(28 + 3 * 24 + 04) = -1
238 menu%!(28 + 3 * 24 + 08) = &07000011
239 $(menu% + 28 + 3 * 24 + 12) = "Stop"
240
241 tmenu%!12 = &00070008
242 tmenu%!16 = 500
243 tmenu%!20 = 44
244 tmenu%!24 = 0
245
246 FOR track% = 0 TO MAX_TRACKS - 1
247 tmenu%!(28 + track% * 24 + 04) = -1
248 NEXT
249
250 ENDPROC
251
252 REM********************************************************************************
253
254 REM handle wimp events
255
256 DEF PROCwimp_poll
257 LOCAL time%, reason%
258
259 WHILE 1
260 SYS"OS_ReadMonotonicTime" TO time%
261 SYS"Wimp_PollIdle", &3830, b%, time% + 50 TO reason%
262
263 CASE reason% OF
264
265 WHEN 0:
266 PROCwimp_update
267
268 WHEN 6:
269 PROCwimp_click
270
271 WHEN 9:
272 PROCwimp_menu
273
274 WHEN 17, 18:
275 CASE b%!16 OF
276 WHEN 0 : PROCquit
277 WHEN &51bc1: PROCcddb_results
278 ENDCASE
279
280 ENDCASE
281
282 ENDWHILE
283 ENDPROC
284
285 REM********************************************************************************
286
287 REM check for cd changes and update icons
288
289 DEF PROCwimp_update
290 LOCAL drive%, id%
291
292 FOR drive% = 0 TO cd_drives% - 1
293 id% = FNcd_id(drive%)
294 IF id% <> cd_id%(drive%) THEN
295 PROCcd_update(drive%)
296 PROCwimp_updateicon(drive%)
297 cd_id%(drive%) = id%
298 ENDIF
299 NEXT
300 ENDPROC
301
302 REM********************************************************************************
303
304 REM handle mouse clicks
305
306 DEF PROCwimp_click
307 LOCAL drive%, path$
308
309 drive% = FNicon_to_drive(b%!16)
310
311 IF b%!08 = 2 THEN
312
313 menu_drive% = drive%
314 menu_type% = menu%
315 $(menu%) = "CDFS::" + STR$drive%
316 IF cd_status%(drive%) = CD_DATA THEN
317 menu%!(28 + 08) = &07000011
318 ELSE
319 menu%!(28 + 08) = &07400011
320 ENDIF
321 SYS"Wimp_CreateMenu",, menu%, b%!00 - 64, 272
322
323 ELSE
324
325 CASE cd_status%(drive%) OF
326 WHEN CD_EMPTY:
327 IF b%!08 = 4 THEN
328 PROCcd_eject(drive%)
329 ELSE
330 PROCcd_close(drive%)
331 ENDIF
332 WHEN CD_DATA:
333 PROCopendir(cd_path$(drive%))
334 WHEN CD_AUDIO:
335 PROCwimp_trackmenu(drive%)
336
337 ENDCASE
338
339 ENDIF
340
341 ENDPROC
342
343 REM********************************************************************************
344
345 DEF PROCwimp_trackmenu(drive%)
346 LOCAL track%, title%, tracks%, playing%
347
348 menu_drive% = drive%
349 menu_type% = tmenu%
350
351 title% = FNcddb_titleat(drive%)
352 tracks% = FNcd_tracks(drive%)
353 IF tracks% > MAX_TRACKS THEN tracks% = MAX_TRACKS
354
355 IF title% = 0 THEN
356 $(tmenu%) = "CDFS::" + STR$drive%
357 FOR track% = 0 TO tracks% - 1
358 tmenu%!(28 + track% * 24 + 00) = 0
359 tmenu%!(28 + track% * 24 + 08) = &0b000011
360 $(tmenu% + 28 + track% * 24 + 12) = STR$(track% + 1)
361 NEXT
362 tmenu%!(28 + (tracks% - 1) * 24 + 00) = 1<<7
363
364 ELSE
365 tmenu%!00 = title%
366 tmenu%!04 = -1
367 tmenu%!08 = 0
368 FOR track% = 0 TO tracks% - 1
369 tmenu%!(28 + track% * 24 + 00) = 0
370 tmenu%!(28 + track% * 24 + 08) = &0b000111
371 tmenu%!(28 + track% * 24 + 12) = FNcddb_trackat(drive%, track% + 1)
372 tmenu%!(28 + track% * 24 + 16) = -1
373 tmenu%!(28 + track% * 24 + 20) = 0
374 NEXT
375 tmenu%!28 = 1<<8
376 tmenu%!(28 + (tracks% - 1) * 24 + 00) += 1<<7
377
378 ENDIF
379
380 playing% = FNcd_playingtrack(drive%)
381 IF playing% > 0 THEN tmenu%!(28 + (playing% - 1) * 24 + 00) += 1
382
383 SYS"Wimp_CreateMenu",, tmenu%, b%!00 - 80, 96 + 44 * tracks%
384
385 ENDPROC
386
387 REM********************************************************************************
388
389 REM handle menu selections
390
391 DEF PROCwimp_menu
392 SYS"Wimp_GetPointerInfo",, b% + 800
393 IF menu_type% = menu% THEN
394 CASE b%!00 OF
395 WHEN 0:
396 PROCclosedir(cd_path$(menu_drive%))
397 SYS"OS_CLI", "CDFS:Dismount " + MID$(cd_path$(menu_drive%), 7, LENcd_path$(menu_drive%) - 8)
398 WHEN 1: PROCcd_eject(menu_drive%)
399 WHEN 2: PROCcd_close(menu_drive%)
400 WHEN 3: PROCcd_stop(menu_drive%)
401 ENDCASE
402 ELSE
403 PROCcd_play(menu_drive%, b%!00 + 1)
404 ENDIF
405 IF b%!808 = 1 THEN
406 CASE menu_type% OF
407 WHEN menu% : SYS"Wimp_CreateMenu",, menu%
408 WHEN tmenu%: PROCwimp_trackmenu(menu_drive%)
409 ENDCASE
410 ENDIF
411 ENDPROC
412
413 REM********************************************************************************
414
415 DEF PROCwimp_updateicon(drive%)
416 LOCAL icon%
417 icon% = iconbar_icon%(drive%)
418 iconbar_icon%(drive%) = FNwimp_createicon(drive%, FNcd_title(drive%), FNcd_icon(drive%), iconbar_data%(drive%))
419 IF icon% <> -1 THEN
420 PROCwimp_deleteicon(icon%)
421 ENDIF
422 ENDPROC
423
424 REM********************************************************************************
425
426 DEF FNwimp_createicon(number%, text$, sprite$, data%)
427 LOCAL handle%, width%
428 IF LENtext$ > 25 THEN text$ = LEFT$(text$, 24) + "Œ"
429 SYS"Wimp_TextOp", 1, text$, 0 TO width%
430 IF width% < 68 THEN width% = 68
431 $data% = text$
432 $(data% + 40) = "s" + sprite$
433 b%!800 = -5
434 b%!804 = 0
435 b%!808 = -16
436 b%!812 = width%
437 b%!816 = 80
438 b%!820 = &1700310b
439 b%!824 = data%
440 b%!828 = data% + 40
441 b%!832 = 40
442 SYS"Wimp_CreateIcon", &78000000 + number%, b% + 800 TO handle%
443 =handle%
444
445 REM********************************************************************************
446
447 DEF PROCwimp_deleteicon(handle%)
448 b%!800 = -2
449 b%!804 = handle%
450 SYS"Wimp_DeleteIcon",, b% + 800
451 ENDPROC
452
453 REM********************************************************************************
454 REM Reverse lookup functions
455 REM********************************************************************************
456
457 DEF FNicon_to_drive(icon%)
458 LOCAL drive%
459 FOR drive% = 0 TO cd_drives% - 1
460 IF iconbar_icon%(drive%) = icon% THEN =drive%
461 NEXT
462 =0
463
464 REM********************************************************************************
465
466 DEF FNcddb_ref_to_drive(ref%)
467 LOCAL drive%
468 FOR drive% = 0 TO cd_drives% - 1
469 IF cddb_ref%(drive%) = ref% THEN =drive%
470 NEXT
471 =0
472
473 REM********************************************************************************
474 REM Filer messages
475 REM********************************************************************************
476
477 DEF PROCopendir(dir$)
478 PROCfiler(&400, dir$)
479 ENDPROC
480
481 REM********************************************************************************
482
483 DEF PROCclosedir(dir$)
484 PROCfiler(&401, dir$)
485 ENDPROC
486
487 REM********************************************************************************
488
489 DEF PROCfiler(message%, dir$)
490 b%!800 = 28 + ((LENdir$ DIV 4) + 1) * 4
491 b%!812 = 0
492 b%!816 = message%
493 b%!820 = 37
494 b%!824 = 1
495 $(b% + 828) = dir$ + CHR$0
496 SYS"Wimp_SendMessage", 17, b% + 800, 0
497 ENDPROC
498
499 REM********************************************************************************
500 REM AcornCD CDDB server communication
501 REM********************************************************************************
502
503 REM initialise
504
505 DEF PROCcddb_init
506 DIM cddb_b% 40
507 DIM cddb_ref%(cd_drives% - 1), cddb_area%(cd_drives% - 1), cddb_areaid%(cd_drives% - 1)
508 ENDPROC
509
510 REM********************************************************************************
511
512 REM send a query to the server if possible
513
514 DEF PROCcddb_query(drive%)
515 LOCAL call%, found%, acorncd%, exists%
516
517 call% = 0
518 found% = 0
519 WHILE (call% >= 0) AND (found% = 0)
520 SYS"TaskManager_EnumerateTasks", call%, cddb_b%, 16 TO call%
521 IF FNstring(cddb_b%!04) = "AcornCD" THEN
522 found% = 1
523 acorncd% = cddb_b%!00
524 ENDIF
525 ENDWHILE
526
527 IF found% = 0 THEN
528 SYS"XOS_ReadVarVal", "AcornCD$Dir", cddb_b%, -1 TO ,, exists%
529 IF exists% = 0 THEN ENDPROC
530 SYS"Wimp_StartTask", "Run <AcornCD$Dir>.!Run" TO acorncd%
531 ENDIF
532
533 cddb_b%!00 = 28
534 cddb_b%!12 = 0
535 REM CDDB_Query
536 cddb_b%!16 = &51bc0
537 cddb_b%!20 = 1
538 cddb_b%!24 = drive%
539 SYS"Wimp_SendMessage", 17, cddb_b%, acorncd%
540 cddb_ref%(drive%) = cd_b%!08
541 cddb_area%(drive%) = 0
542 cddb_areaid%(drive%) = 0
543 ENDPROC
544
545 REM********************************************************************************
546
547 REM return the title of the cd if available
548
549 DEF FNcddb_title(drive%)
550 IF cddb_area%(drive%) = 0 THEN =""
551 =FNstring(cddb_area%(drive%)!04)
552
553 REM********************************************************************************
554
555 DEF FNcddb_titleat(drive%)
556 IF cddb_area%(drive%) = 0 THEN =0
557 =cddb_area%(drive%)!04
558
559 REM********************************************************************************
560
561 DEF FNcddb_trackat(drive%, track%)
562 =!(cddb_area%(drive%) + 24 + (track% - 1) * 8)
563
564 REM********************************************************************************
565
566 REM handle CDDB_QueryResults
567
568 DEF PROCcddb_results
569 LOCAL drive%, area%
570
571 drive% = FNcddb_ref_to_drive(b%!12)
572 CASE b%!20 OF
573 WHEN 0, 3:
574 cddb_area%(drive%) = b%!24
575 cddb_areaid%(drive%) = b%!28
576 PROCwimp_updateicon(drive%)
577
578 ENDCASE
579
580 ENDPROC
581
582 REM********************************************************************************
583
584 DEF PROCcddb_finished(drive%)
585 IF cddb_areaid%(drive%) = 0 THEN ENDPROC
586 cddb_b%!00 = 28
587 cddb_b%!12 = 0
588 REM CDDB_FreeArea
589 cddb_b%!16 = &51bc2
590 cddb_b%!20 = 0
591 cddb_b%!24 = cddb_areaid%(drive%)
592 SYS"Wimp_SendMessage", 17, cddb_b%, 0
593 cddb_area%(drive%) = 0
594 cddb_areaid%(drive%) = 0
595 ENDPROC
596
597 REM********************************************************************************
598 REM Useful functions
599 REM********************************************************************************
600
601 DEF FNstring(a%)
602 LOCAL s$
603 s$ = ""
604 WHILE ?a% > 31
605 s$ += CHR$?a%
606 a% += 1
607 ENDWHILE
608 =s$
609
610 REM********************************************************************************
611
612 DEF PROCquit
613 FOR drive% = 0 TO cd_drives% - 1
614 PROCcddb_finished(drive%)
615 NEXT
616 SYS"Wimp_CloseDown", task%, &4b534154
617 END
618 ENDPROC
619
620 REM********************************************************************************

  ViewVC Help
Powered by ViewVC 1.1.26