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
19 .importzp ptr2, tmp1, sp
26 .res NUMDRVS * sst_size
33 cmp #NUMDRVS ; valid drive id?
36 asl a ; make index from drive id
39 lda #128 ; preset sectsize, will be overridden by query_sectorsize
40 sta sectsizetab+sst_sectsize,x
41 sta sectsizetab+sst_flag,x ; set flag that drive is "open"
43 sta sectsizetab+sst_sectsize+1,x
44 sta __oserror ; success
46 sta sectsizetab+sst_driveno,x
56 jmp query_sectorsize ; query drive for current sector size
60 lda #NONDEV ; non-existent device
75 sta __oserror ; success
81 ; query drive for current sector size
83 ; - read sector #4 (SIO command $54) to update drive status
84 ; read length is 128 bytes, buffer is below the stack pointer,
85 ; sector data is ignored
86 ; command status is ignored, we will get an error with a DD disk
87 ; anyway (read size 128 vs. sector size 256)
88 ; - issue SIO command $53 (get status) to retrieve the sector size
89 ; if the command returns with an error, we set sector size to 128
94 .proc query_sectorsize
97 stx ptr2+1 ; remember pointer to sectsizetab entry
99 ; jsr pushax ; handle for subsequent __sio_call
102 jsr subysp ; use buffer on the stack
115 jsr pushax ; sect_num
118 ; jsr subysp ; use buffer on the stack
124 ; jsr pushax ; buffer address (not pushed, _dio_read is __fastcall__)
126 jsr _dio_read ; read sector to update status
129 jsr addysp ; discard stack buffer
134 jsr pushax ; handle for subsequent __sio_call
139 jsr pushax ; dummy sector #
143 jsr pushax ; buffer address
147 sta (ptr2),y ; 4 bytes transfer
149 ldx #%01000000 ; direction value
150 lda #SIO_STAT ; get status
168 finish: sta (ptr2),y ; set default sector size
173 error: ldy #sst_sectsize