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