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