]> git.sur5r.net Git - cc65/blob - libsrc/geos/disk/dio_stc.s
Added new mouse functions
[cc65] / libsrc / geos / disk / dio_stc.s
1 ;
2 ; Maciej 'YTM/Elysium' Witkowiak
3 ; 2.7.2001
4 ;
5 ; unsigned char __fastcall__ dio_log_to_phys(dhandle_t handle,
6 ;                                            sectnum_t *sectnum,        /* input */
7 ;                                            dio_phys_pos *physpos);    /* output */
8 ;
9 ; dhandle_t - 16bit (ptr)
10 ; sectnum_t - 16bit
11 ;
12
13         .export         _dio_log_to_phys
14         .importzp       ptr1,ptr2,ptr3,tmp1,tmp2
15         .import         popax,__oserror
16         .import         sectab_1541_l, sectab_1541_h
17         .include "../inc/dio.inc"
18         .include "../inc/geossym.inc"
19         .include "../inc/const.inc"
20
21 .proc   _dio_log_to_phys
22
23 ; check device type
24         sta     ptr1
25         stx     ptr1+1          ; pointer to result (struct dio_phys_pos)
26
27         jsr     popax
28         sta     ptr2
29         stx     ptr2+1          ; pointer to input structure (pointer to int)
30
31         jsr     popax
32         sta     ptr3
33         stx     ptr3+1          ; pointer to handle
34
35         ldy     #sst_flag
36         lda     (ptr3),y
37         and     #128
38         beq     _inv_hand       ; handle not open or invalid
39
40 ; fill in all we have
41         ldy     #diopp_head
42         lda     #0              ; head 0
43         sta     (ptr1),y
44         ldy     #diopp_track+1
45         sta     (ptr1),y        ; track <256
46         ldy     #diopp_sector+1
47         sta     (ptr1),y        ; sector <256
48
49         ldy     #0
50         lda     (ptr2),y
51         sta     tmp1
52         iny
53         lda     (ptr2),y
54         sta     tmp2
55
56 ; get drive info
57         ldy     #sst_driveno
58         lda     (ptr3),y
59         tay
60         lda     driveType,y
61         and     #%00000011      ; this is for RamDrive compatibility
62         cmp     #DRV_1541
63         beq     dio_stc1541
64         cmp     #DRV_1571
65         beq     dio_stc1571
66         cmp     #DRV_1581
67         beq     dio_stc1581
68
69 ;       ...
70
71 dio_stcend:
72         ldy     #diopp_track
73         lda     tmp1
74         sta     (ptr1),y
75         ldy     #diopp_sector
76         lda     tmp2
77         sta     (ptr1),y
78
79         ldx     #0
80         txa
81 _ret:
82         sta     __oserror
83         rts                     ; return success
84
85 ; errors
86 _inv_data:
87         lda     #INV_TRACK
88         .byte $2c
89 _inv_hand:
90         lda     #INCOMPATIBLE
91         ldx     #0
92         beq     _ret
93
94 dio_stc1541:
95 ; if 1541:
96 ; - compare with table to find track
97 ; - subtract and find sector
98
99         ldx     #0              ; index=(track-1)
100 _loop41:
101         lda     tmp2
102         cmp     sectab_1541_h+1,x
103         bne     _nxt
104         lda     tmp1
105         cmp     sectab_1541_l+1,x
106         bcc     _found
107 _nxt:   inx
108         cpx     #35
109         bne     _loop41
110         beq     _inv_data
111
112 _found:
113         lda     tmp1
114         sec
115         sbc     sectab_1541_l,x
116         sta     tmp2
117 _fndend:
118         inx
119         stx     tmp1
120         jmp     dio_stcend
121
122 dio_stc1571:
123 ; if 1571:
124 ; - check size, if too big - subtract and add 35 to track
125 ; - fall down to 1541
126         lda     tmp2
127         cmp     #>683
128         bne     _cnt71
129         lda     tmp1
130         cmp     #<683
131         bcc     dio_stc1541
132
133 _cnt71:
134         lda     tmp1
135         sec
136         sbc     #<683
137         sta     tmp1
138         lda     tmp2
139         sbc     #>683
140         sta     tmp2
141         jsr     dio_stc1541     ; will fall through here
142
143         ldy     #diopp_track
144         lda     (ptr1),y
145         clc
146         adc     #35
147         sta     (ptr1),y
148         lda     #0
149         beq     _ret
150
151 ; if 1581:
152 ; - subtract 40 in loop (at most 80 times) to find track
153 ; - the remainder is sector
154 dio_stc1581:
155         ldx     #0              ; index=(track-1)
156 _loop81:
157         lda     tmp2
158         bne     _sub81
159         lda     tmp1
160         cmp     #40
161         bcc     _got81
162 _sub81: lda     tmp1
163         sec
164         sbc     #40
165         sta     tmp1
166         lda     tmp2
167         sbc     #0
168         sta     tmp2
169         inx
170         cpx     #81
171         bne     _loop81
172         beq     _inv_data
173
174 _got81: lda     tmp1
175         sta     tmp2
176         inx
177         stx     tmp1
178         jmp     dio_stcend
179
180 .endproc