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