]> git.sur5r.net Git - cc65/blob - libsrc/geos-cbm/disk/dio_stc.s
Normalized coding style.
[cc65] / libsrc / geos-cbm / 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
18             .include "dio.inc"
19             .include "geossym.inc"
20             .include "const.inc"
21
22 _dio_log_to_phys:
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         lda #DEV_NOT_FOUND      ; unknown device
70         ldx #0
71         beq _ret
72
73 dio_stcend:
74         ldy #diopp_track
75         lda tmp1
76         sta (ptr1),y
77         ldy #diopp_sector
78         lda tmp2
79         sta (ptr1),y
80             
81         ldx #0
82         txa 
83 _ret:       
84         sta __oserror
85         rts                     ; return success
86
87 ; errors
88 _inv_data:
89         lda #INV_TRACK
90         .byte $2c
91 _inv_hand:
92         lda #INCOMPATIBLE
93         ldx #0
94         beq _ret
95
96 dio_stc1541:
97 ; if 1541:
98 ; - compare with table to find track
99 ; - subtract and find sector
100
101         ldx #0                  ; index=(track-1)
102 _loop41:
103         lda tmp2
104         cmp sectab_1541_h+1,x
105         bne _nxt
106         lda tmp1
107         cmp sectab_1541_l+1,x
108         bcc _found
109 _nxt:   inx 
110         cpx #35
111         bne _loop41
112         beq _inv_data
113             
114 _found:     
115         lda tmp1
116         sec 
117         sbc sectab_1541_l,x
118         sta tmp2
119 _fndend:    
120         inx 
121         stx tmp1
122         jmp dio_stcend
123
124 dio_stc1571:
125 ; if 1571:
126 ; - check size, if too big - subtract and add 35 to track
127 ; - fall down to 1541
128         lda tmp2
129         cmp #>683
130         bne _cnt71
131         lda tmp1
132         cmp #<683
133         bcc dio_stc1541
134             
135 _cnt71:     
136         lda tmp1
137         sec 
138         sbc #<683
139         sta tmp1
140         lda tmp2
141         sbc #>683
142         sta tmp2
143         jsr dio_stc1541         ; will fall through here
144             
145         ldy #diopp_track
146         lda (ptr1),y
147         clc 
148         adc #35
149         sta (ptr1),y
150         lda #0
151         beq _ret
152
153 ; if 1581:
154 ; - subtract 40 in loop (at most 80 times) to find track
155 ; - the remainder is sector
156 dio_stc1581:
157         ldx #0                  ; index=(track-1)
158 _loop81:    
159         lda tmp2
160         bne _sub81
161         lda tmp1
162         cmp #40
163         bcc _got81
164 _sub81: lda tmp1
165         sec 
166         sbc #40
167         sta tmp1
168         lda tmp2
169         sbc #0
170         sta tmp2
171         inx 
172         cpx #81
173         bne _loop81
174         beq _inv_data
175             
176 _got81: lda tmp1
177         sta tmp2
178         inx 
179         stx tmp1
180         jmp dio_stcend