]> git.sur5r.net Git - cc65/blob - libsrc/geos-cbm/disk/dio_cts.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / geos-cbm / disk / dio_cts.s
1 ;
2 ; Maciej 'YTM/Elysium' Witkowiak
3 ; 2.7.2001
4 ;
5 ;
6 ; unsigned char __fastcall__ dio_phys_to_log (dhandle_t handle,
7 ;                                             dio_phys_pos *physpos,    /* input */
8 ;                                             unsigned *sectnum);       /* output */
9 ;
10
11             .export _dio_phys_to_log
12             .export sectab_1541_l, sectab_1541_h        ; for log_to_phys
13             .import popax,__oserror
14             .importzp ptr1,ptr2,ptr3,tmp1,tmp2,tmp3,tmp4
15
16             .include "dio.inc"
17             .include "geossym.inc"
18             .include "const.inc"
19
20 _dio_phys_to_log:
21         sta ptr1
22         stx ptr1+1              ; pointer to result
23             
24         jsr popax
25         sta ptr2
26         stx ptr2+1              ; pointer to input structure
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             
38         ldy #diopp_head
39         lda (ptr2),y
40         bne _inv_data           ; there is only head 0
41         ldy #diopp_track
42         lda (ptr2),y
43         beq _inv_data           ; there is no track 0
44         sta tmp1
45         iny
46         lda (ptr2),y
47         bne _inv_data           ; there are no more than 256 tracks
48         dec tmp1                ; normalize track to start from 0
49         ldy #diopp_sector
50         lda (ptr2),y
51         sta tmp2
52         iny
53         lda (ptr2),y
54         bne _inv_data           ; there are no more than 256 sectors
55
56 ; tmp1 (int) holds track+sector, translate it using device info
57
58         ldy #sst_driveno
59         lda (ptr3),y
60         tay
61         lda driveType,y
62         and #%00000011          ; this is for RamDrive compatibility
63         cmp #DRV_1541
64         beq dio_cts1541
65         cmp #DRV_1571
66         beq dio_cts1571
67         cmp #DRV_1581
68         beq dio_cts1581
69             
70         lda #DEV_NOT_FOUND      ; unknown device
71         ldx #0
72         beq ret
73
74 dio_ctsend:
75         ldy #1
76         lda tmp2
77         sta (ptr1),y
78         dey
79         lda tmp1
80         sta (ptr1),y
81             
82         ldx #0
83         txa
84 ret:        
85         sta __oserror
86         rts                     ; return success
87
88 ; errors
89
90 _inv_data:
91         lda #INV_TRACK
92         .byte $2c
93 _inv_hand:
94         lda #INCOMPATIBLE
95         ldx #0
96         beq ret
97
98 ; device-depended stuff, tmp1=track-1, tmp2=sector
99
100 dio_cts1541:
101         ldy tmp1
102         cpy #35
103         bcs _inv_data
104         lda sectab_1541_l,y
105         clc
106         adc tmp2
107         sta tmp1
108         lda sectab_1541_h,y
109         adc #0
110         sta tmp2
111         jmp dio_ctsend
112
113 dio_cts1571:
114         lda tmp1
115         cmp #70
116         bcs _inv_data
117         cmp #35                 ; last track of one side
118         bcs _sub35
119         jmp dio_cts1541         ; track <=35 - same as 1541
120
121 _sub35:
122         sec
123         sbc #35
124         sta tmp1
125         jsr dio_cts1541         ; get offset on second side of disk
126         lda tmp1                ; add second side base
127         clc
128         adc #<683
129         sta tmp1
130         lda tmp2
131         adc #>683
132         sta tmp2
133         jmp dio_ctsend
134
135 dio_cts1581:
136 ; 1581 has 80 tracks, 40 sectors each secnum=track*40+sector
137         ldx #0
138         stx tmp3
139         stx tmp4
140         lda tmp1
141         beq _nomult
142         cmp #80
143         bcs _inv_data
144
145 ; mul40 by Christian Groessler
146         sta tmp4
147         asl a
148         rol tmp3
149         asl a
150         rol tmp3                ; val * 4
151         adc tmp4
152         bcc L1
153         inc tmp3                ; val * 5
154 L1:     asl a
155         rol tmp3                ; val * 10
156         asl a
157         rol tmp3
158         asl a
159         rol tmp3                ; val * 40 = AX
160         ldx tmp3
161         sta tmp3
162         stx tmp4
163
164 _nomult:
165         lda tmp2
166         clc
167         adc tmp3
168         sta tmp1
169         lda tmp4
170         adc #0
171         sta tmp2
172         jmp dio_ctsend
173
174 .rodata
175
176 sectab_1541_l:
177         .byte $00, $15, $2a, $3f, $54, $69, $7e, $93
178         .byte $a8, $bd, $d2, $e7, $fc, $11, $26, $3b
179         .byte $50, $65, $78, $8b, $9e, $b1, $c4, $d7
180         .byte $ea, $fc, $0e, $20, $32, $44, $56, $67
181         .byte $78, $89, $9a, $ab
182 sectab_1541_h:
183         .byte $00, $00, $00, $00, $00, $00, $00, $00
184         .byte $00, $00, $00, $00, $00, $01, $01, $01
185         .byte $01, $01, $01, $01, $01, $01, $01, $01
186         .byte $01, $01, $02, $02, $02, $02, $02, $02
187         .byte $02, $02, $02, $02