]> git.sur5r.net Git - cc65/blob - libsrc/atari/siocall.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / atari / siocall.s
1 ;
2 ; Christian Groessler, October 2000
3 ;
4 ; This file provides the __sio_call function
5 ; The function does a SIO call, it's not completely
6 ; generic (e.g. transfer size is fixed), it's used
7 ; to save space with _dio_read and _dio_write functions.
8 ;
9 ; unsigned char __fastcall__ _sio_call(dhandle_t handle,
10 ;                                      unsigned sect_num,
11 ;                                      void *buffer,
12 ;                                      unsigned sio_val);
13 ; dhandle_t - 16bit (ptr)
14 ; sio_val is (sio_command | sio_direction << 8)
15 ;
16
17         .export         __sio_call
18         .include        "atari.inc"
19         .import         popa,popax
20         .import         sectsizetab,__oserror
21         .importzp       ptr1
22
23 .proc   __sio_call
24
25         sta     DCOMND          ; set command into DCB
26         stx     DSTATS          ; set data flow directon
27         jsr     popax           ; get buffer address
28         sta     DBUFLO          ; set buffer address into DCB
29         stx     DBUFHI
30         jsr     popax
31         sta     DAUX1           ; set sector #
32         stx     DAUX2
33
34         jsr     popax
35         sta     ptr1
36         stx     ptr1+1
37
38         ldy     #sst_flag
39         lda     (ptr1),y
40         and     #128
41         beq     _inv_hand       ; handle not open or invalid
42
43         ldy     #sst_driveno
44         lda     (ptr1),y
45
46         clc
47         adc     #1
48         sta     DUNIT           ; unit number (d1,d2,d3,...)
49
50         lda     DAUX2           ; high byte sector #
51         bne     _realsz
52         lda     DAUX1
53         cmp     #4              ; sectors 1 to 3 are special (always 128 bytes)
54         bcs     _realsz
55
56         lda     #$80
57         sta     DBYTLO
58         asl     a
59         sta     DBYTHI
60         beq     _cont
61
62 _realsz:ldy     #sst_sectsize
63         lda     (ptr1),y
64         sta     DBYTLO
65         iny
66         lda     (ptr1),y
67         sta     DBYTHI
68
69 _cont:  lda     #DISKID         ; SIO bus ID of diskette drive
70         sta     DDEVIC
71         lda     #15
72         sta     DTIMLO          ; value got from DOS source
73
74         jsr     SIOV            ; execute
75
76         ldx     #0
77         lda     DSTATS
78         bmi     _req_err        ; error occurred
79         txa                     ; no error occurred
80 _req_err:
81         sta     __oserror
82         rts
83
84 _inv_hand:
85         ldx     #0
86         lda     #BADIOC
87         bne     _req_err
88
89 .endproc