]> git.sur5r.net Git - cc65/blob - libsrc/atari/siocall.s
Changed most "backticks" (grave accents) into apostrophes.
[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,popptr1
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     popptr1
35
36         ldy     #sst_flag
37         lda     (ptr1),y
38         and     #128
39         beq     _inv_hand       ; handle not open or invalid
40
41         ldy     #sst_driveno
42         lda     (ptr1),y
43
44         clc
45         adc     #1
46         sta     DUNIT           ; unit number (d1,d2,d3,...)
47
48         lda     DAUX2           ; high byte sector #
49         bne     _realsz
50         lda     DAUX1
51         cmp     #4              ; sectors 1 to 3 are special (always 128 bytes)
52         bcs     _realsz
53
54         lda     #$80
55         sta     DBYTLO
56         asl     a
57         sta     DBYTHI
58         beq     _cont
59
60 _realsz:ldy     #sst_sectsize
61         lda     (ptr1),y
62         sta     DBYTLO
63         iny
64         lda     (ptr1),y
65         sta     DBYTHI
66
67 _cont:  lda     #DISKID         ; SIO bus ID of diskette drive
68         sta     DDEVIC
69         lda     #15
70         sta     DTIMLO          ; value got from DOS source
71
72         jsr     SIOV            ; execute
73
74         ldx     #0
75         lda     DSTATS
76         bmi     _req_err        ; error occurred
77         txa                     ; no error occurred
78 _req_err:
79         sta     __oserror
80         rts
81
82 _inv_hand:
83         ldx     #0
84         lda     #BADIOC
85         bne     _req_err
86
87 .endproc