]> git.sur5r.net Git - cc65/blob - libsrc/cbm/cbm_filetype.s
fixed optimization bug where array index is 16-bit, e.g. arr16[i & 0x7f7f]
[cc65] / libsrc / cbm / cbm_filetype.s
1 ;
2 ; Determine the CBM file type. From cbm_dir.c by Josef Soucek. Moved into an
3 ; assembler function by Ullrich von Bassewitz 2012-06-03
4 ;
5 ; unsigned char __fastcall__ _cbm_filetype (unsigned char c);
6 ;
7
8         .include "cbm_filetype.inc"
9
10         .macpack generic
11
12
13 ; --------------------------------------------------------------------------
14 ; Table with types for a list of start characters
15
16 .rodata
17 .proc   TypeTable
18         .byte   CBM_T_CBM       ; c
19         .byte   CBM_T_DEL       ; d
20         .byte   CBM_T_OTHER     ; e
21         .byte   CBM_T_OTHER     ; f
22         .byte   CBM_T_OTHER     ; g
23         .byte   CBM_T_OTHER     ; h
24         .byte   CBM_T_OTHER     ; i
25         .byte   CBM_T_OTHER     ; j
26         .byte   CBM_T_OTHER     ; k
27         .byte   CBM_T_LNK       ; l
28         .byte   CBM_T_OTHER     ; m
29         .byte   CBM_T_OTHER     ; n
30         .byte   CBM_T_OTHER     ; o
31         .byte   CBM_T_PRG       ; p
32         .byte   CBM_T_OTHER     ; q
33         .byte   CBM_T_REL       ; r
34         .byte   CBM_T_SEQ       ; s
35         .byte   CBM_T_OTHER     ; t
36         .byte   CBM_T_USR       ; u
37         .byte   CBM_T_VRP       ; v
38 .endproc
39
40
41 ; --------------------------------------------------------------------------
42 ; Mapper function
43
44 .code
45 .proc   __cbm_filetype
46
47         ldx     #0              ; Clear high byte
48
49 ; Check that the given char is in table range
50
51         sec
52         sbc     #'c'
53         bcc     L1
54         cmp     #.sizeof (TypeTable)
55         bge     L1
56
57 ; Ok, load the type
58
59         tay
60         lda     TypeTable,y
61         rts
62
63 ; Out of table range, return CBM_T_OTHER
64
65 L1:     lda     #CBM_T_OTHER
66         rts
67
68 .endproc
69
70
71