]> git.sur5r.net Git - cc65/blob - libsrc/atari/siocall.s
Added tosicmp0, a special entry point that clears the X register.
[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 ;                                      sectnum_t sect_num,
11 ;                                      void *buffer,
12 ;                                      unsigned int sio_val);
13 ; dhandle_t - 16bit (ptr)
14 ; sectnum_t - 16bit
15 ; sio_val is (sio_command | sio_direction << 8)
16 ;
17
18         .export         __sio_call
19         .include        "atari.inc"
20         .import         popa,popax
21         .import         sectsizetab,__oserror
22         .importzp       ptr1
23
24 .proc   __sio_call
25
26         sta     DCOMND          ; set command into DCB
27         stx     DSTATS          ; set data flow directon
28         jsr     popax           ; get buffer address
29         sta     DBUFLO          ; set buffer address into DCB
30         stx     DBUFHI
31         jsr     popax
32         sta     DAUX1           ; set sector #
33         stx     DAUX2
34
35         jsr     popax
36         sta     ptr1
37         stx     ptr1+1
38
39         ldy     #sst_flag
40         lda     (ptr1),y
41         and     #128
42         beq     _inv_hand       ; handle not open or invalid
43
44         ldy     #sst_driveno
45         lda     (ptr1),y
46
47         clc
48         adc     #1
49         sta     DUNIT           ; unit number (d1,d2,d3,...)
50
51         lda     DAUX2           ; high byte sector #
52         bne     _realsz
53         lda     DAUX1
54         cmp     #4              ; sectors 1 to 3 are special (always 128 bytes)
55         bcs     _realsz
56
57         lda     #$80
58         sta     DBYTLO
59         asl     a
60         sta     DBYTHI
61         beq     _cont
62
63 _realsz:ldy     #sst_sectsize
64         lda     (ptr1),y
65         sta     DBYTLO
66         iny
67         lda     (ptr1),y
68         sta     DBYTHI
69
70 _cont:  lda     #DISKID         ; SIO bus ID of diskette drive
71         sta     DDEVIC
72         lda     #15
73         sta     DTIMLO          ; value got from DOS source
74
75         jsr     SIOV            ; execute
76
77         ldx     #0
78         lda     DSTATS
79         bmi     _req_err        ; error occurred
80         txa                     ; no error occurred
81 _req_err:
82         sta     __oserror
83         rts
84
85 _inv_hand:
86         ldx     #0
87         lda     #BADIOC
88         bne     _req_err
89
90 .endproc