]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/siocall.s
Merged pull request #459 from "pmjdebruijn/pragma".
[cc65] / libsrc / atari / siocall.s
index 7737d3c5c34779ba379248e73ca38dad256d0a0f..3db37753f75ce389a17fd9dc7f28d2a928663a00 100644 (file)
@@ -6,73 +6,84 @@
 ; generic (e.g. transfer size is fixed), it's used
 ; to save space with _dio_read and _dio_write functions.
 ;
-; unsigned char __fastcall__ _sio_call(_dhandle_t handle,
-;                                     _sectnum_t sect_num,
-;                                     void *buffer,
-;                                     unsigned int sio_val);
-; _dhandle_t - 16bit (ptr)
-; _sectnum_t - 16bit
+; unsigned char __fastcall__ _sio_call(dhandle_t handle,
+;                                      unsigned sect_num,
+;                                      void *buffer,
+;                                      unsigned sio_val);
+; dhandle_t - 16bit (ptr)
 ; sio_val is (sio_command | sio_direction << 8)
 ;
 
-       .export         __sio_call
-       .include        "atari.inc"
-       .import         popa,popax
-       .import         sectsizetab,__oserror
-       .importzp       ptr1
+        .export         __sio_call
+        .include        "atari.inc"
+        .import         popa,popax
+        .import         sectsizetab,__oserror
+        .importzp       ptr1
 
-.proc  __sio_call
+.proc   __sio_call
 
-       sta     DCOMND          ; set command into DCB
-       stx     DSTATS          ; set data flow directon
-       jsr     popax           ; get buffer address
-       sta     DBUFLO          ; set buffer address into DCB
-       stx     DBUFHI
-       jsr     popax
-       sta     DAUX1           ; set sector #
-       stx     DAUX2
+        sta     DCOMND          ; set command into DCB
+        stx     DSTATS          ; set data flow directon
+        jsr     popax           ; get buffer address
+        sta     DBUFLO          ; set buffer address into DCB
+        stx     DBUFHI
+        jsr     popax
+        sta     DAUX1           ; set sector #
+        stx     DAUX2
 
-       jsr     popax
-       sta     ptr1
-       stx     ptr1+1
+        jsr     popax
+        sta     ptr1
+        stx     ptr1+1
 
-       ldy     #sst_flag
-       lda     (ptr1),y
-       and     #128
-       beq     _inv_hand       ; handle not open or invalid
+        ldy     #sst_flag
+        lda     (ptr1),y
+        and     #128
+        beq     _inv_hand       ; handle not open or invalid
 
-       ldy     #sst_driveno
-       lda     (ptr1),y
+        ldy     #sst_driveno
+        lda     (ptr1),y
 
-       clc
-       adc     #1
-       sta     DUNIT           ; unit number (d1,d2,d3,...)
+        clc
+        adc     #1
+        sta     DUNIT           ; unit number (d1,d2,d3,...)
 
-       ldy     #sst_sectsize
-       lda     (ptr1),y
-       sta     DBYTLO
-       iny
-       lda     (ptr1),y
-       sta     DBYTHI
+        lda     DAUX2           ; high byte sector #
+        bne     _realsz
+        lda     DAUX1
+        cmp     #4              ; sectors 1 to 3 are special (always 128 bytes)
+        bcs     _realsz
 
-       lda     #$31            ; D1 (drive_id == 0) has id $31
-       sta     DDEVIC
-       lda     #15
-       sta     DTIMLO          ; value got from DOS source
+        lda     #$80
+        sta     DBYTLO
+        asl     a
+        sta     DBYTHI
+        beq     _cont
 
-       jsr     SIOV            ; execute
+_realsz:ldy     #sst_sectsize
+        lda     (ptr1),y
+        sta     DBYTLO
+        iny
+        lda     (ptr1),y
+        sta     DBYTHI
 
-       ldx     #0
-       lda     DSTATS
-       bmi     _req_err        ; error occurred
-       txa                     ; no error occurred
+_cont:  lda     #DISKID         ; SIO bus ID of diskette drive
+        sta     DDEVIC
+        lda     #15
+        sta     DTIMLO          ; value got from DOS source
+
+        jsr     SIOV            ; execute
+
+        ldx     #0
+        lda     DSTATS
+        bmi     _req_err        ; error occurred
+        txa                     ; no error occurred
 _req_err:
-       sta     __oserror
-       rts
+        sta     __oserror
+        rts
 
 _inv_hand:
-       ldx     #0
-       lda     #BADIOC
-       bne     _req_err
+        ldx     #0
+        lda     #BADIOC
+        bne     _req_err
 
 .endproc