2 ; Christian Groessler, February 2005
4 ; This file provides the _dio_open and _dio_close functions
5 ; Since on the Atari no real open and close is necessary, they
6 ; do not open or close something. The _dio_open sets the sector
7 ; size of the drive which is later used by the _dio_read and
8 ; _dio_write functions. To query the sector size, the _dio_open
9 ; accesses the disk drive.
11 ; dhandle_t __fastcall__ dio_open (driveid_t drive_id);
12 ; unsigned char __fastcall__ dio_close (dhandle_t handle);
15 .export _dio_open, _dio_close
17 .import __oserror, __sio_call, _dio_read
18 .import pushax, addysp, subysp
26 .res NUMDRVS * sst_size
33 lda #NONDEV ; non-existent device
41 cmp #NUMDRVS ; valid drive id?
44 asl a ; make index from drive id
47 lda #128 ; preset sectsize
48 sta sectsizetab+sst_sectsize,x
49 sta sectsizetab+sst_flag,x ; set flag that drive is "open"
51 sta sectsizetab+sst_sectsize+1,x
52 sta __oserror ; success
54 sta sectsizetab+sst_driveno,x
63 stx ptr2+1 ; ptr2: pointer to sectsizetab entry
65 ; query drive for current sector size
67 ; - read sector #4 (SIO command $54) to update drive status;
68 ; read length is 128 bytes, buffer is allocated on the stack,
69 ; sector data is ignored;
70 ; returned command status is ignored, we will get an error with
71 ; a DD disk anyway (read size 128 vs. sector size 256);
72 ; - issue SIO command $53 (get status) to retrieve the sector size;
73 ; use the DVSTAT system area as return buffer;
74 ; if the command returns with an error, set sector size to 128
79 jsr subysp ; allocate buffer on the stack
84 pha ; save sp (buffer address) on processor stack
96 pla ; AX - buffer address
98 ; sst_sectsize currently 128
99 jsr _dio_read ; read sector to update status
102 jsr addysp ; discard stack buffer
110 jsr pushax ; dummy sector #, ignored by this SIO command,
111 ; but set to circumvent the special 1-3 sector
112 ; handling in __sio_call
116 jsr pushax ; buffer address
120 sta (ptr2),y ; 4 bytes transfer
122 ldx #%01000000 ; direction value
123 lda #SIO_STAT ; get status
140 finish: sta (ptr2),y ; set default sector size
145 error: ldy #sst_sectsize
159 sta __oserror ; success
161 rts ; return no error