2000-10-16 23:24:24 +00:00
|
|
|
;
|
2005-02-19 01:04:41 +00:00
|
|
|
; Christian Groessler, February 2005
|
2000-10-16 23:24:24 +00:00
|
|
|
;
|
2005-02-19 01:04:41 +00:00
|
|
|
; This file provides the _dio_open and _dio_close functions
|
2000-10-16 23:24:24 +00:00
|
|
|
; Since on the Atari no real open and close is necessary, they
|
2005-02-19 01:04:41 +00:00
|
|
|
; do not open or close something. The _dio_open sets the sector
|
|
|
|
; size of the drive which is later used by the _dio_read and
|
|
|
|
; _dio_write functions. To query the sector size, the _dio_open
|
|
|
|
; accesses the disk drive.
|
2000-10-16 23:24:24 +00:00
|
|
|
;
|
2013-05-09 11:56:54 +00:00
|
|
|
; dhandle_t __fastcall__ dio_open (unsigned char device);
|
2000-11-16 21:27:42 +00:00
|
|
|
; unsigned char __fastcall__ dio_close (dhandle_t handle);
|
2000-10-16 23:24:24 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _dio_open, _dio_close
|
|
|
|
.export sectsizetab
|
2022-08-28 19:52:53 +00:00
|
|
|
.import ___oserror, __sio_call, _dio_read
|
2013-05-09 11:56:54 +00:00
|
|
|
.import pushax, addysp, subysp
|
|
|
|
.importzp ptr2, sp
|
|
|
|
.include "atari.inc"
|
2000-10-16 23:24:24 +00:00
|
|
|
|
2000-10-18 23:51:29 +00:00
|
|
|
|
2000-10-16 23:24:24 +00:00
|
|
|
.bss
|
|
|
|
|
|
|
|
sectsizetab:
|
2013-05-09 11:56:54 +00:00
|
|
|
.res NUMDRVS * sst_size
|
2000-10-16 23:24:24 +00:00
|
|
|
|
|
|
|
.code
|
|
|
|
|
2005-02-20 00:39:46 +00:00
|
|
|
; code for _dio_open
|
2000-10-16 23:24:24 +00:00
|
|
|
|
2005-02-20 00:39:46 +00:00
|
|
|
_inv_drive:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #NONDEV ; non-existent device
|
2022-08-28 19:52:53 +00:00
|
|
|
sta ___oserror
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
tax
|
|
|
|
rts ; return NULL
|
2005-02-20 00:39:46 +00:00
|
|
|
|
|
|
|
_dio_open:
|
2000-10-16 23:24:24 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
cmp #NUMDRVS ; valid drive id?
|
|
|
|
bcs _inv_drive
|
|
|
|
tay ; drive #
|
|
|
|
asl a ; make index from drive id
|
|
|
|
asl a
|
|
|
|
tax
|
|
|
|
lda #128 ; preset sectsize
|
|
|
|
sta sectsizetab+sst_sectsize,x
|
|
|
|
sta sectsizetab+sst_flag,x ; set flag that drive is "open"
|
|
|
|
lda #0
|
|
|
|
sta sectsizetab+sst_sectsize+1,x
|
2022-08-28 20:37:33 +00:00
|
|
|
sta ___oserror ; success
|
2013-05-09 11:56:54 +00:00
|
|
|
tya
|
|
|
|
sta sectsizetab+sst_driveno,x
|
|
|
|
stx ptr2
|
|
|
|
lda #<sectsizetab
|
|
|
|
clc
|
|
|
|
adc ptr2
|
|
|
|
sta ptr2
|
|
|
|
lda #>sectsizetab
|
|
|
|
adc #0
|
|
|
|
tax
|
|
|
|
stx ptr2+1 ; ptr2: pointer to sectsizetab entry
|
2000-10-16 23:24:24 +00:00
|
|
|
|
2005-02-19 01:04:41 +00:00
|
|
|
; query drive for current sector size
|
|
|
|
; procedure:
|
2005-02-20 00:39:46 +00:00
|
|
|
; - read sector #4 (SIO command $54) to update drive status;
|
|
|
|
; read length is 128 bytes, buffer is allocated on the stack,
|
2013-05-09 11:56:54 +00:00
|
|
|
; sector data is ignored;
|
2005-02-20 00:39:46 +00:00
|
|
|
; returned command status is ignored, we will get an error with
|
2013-05-09 11:56:54 +00:00
|
|
|
; a DD disk anyway (read size 128 vs. sector size 256);
|
2005-02-20 00:39:46 +00:00
|
|
|
; - issue SIO command $53 (get status) to retrieve the sector size;
|
|
|
|
; use the DVSTAT system area as return buffer;
|
|
|
|
; if the command returns with an error, set sector size to 128
|
2013-05-09 11:56:54 +00:00
|
|
|
; bytes;
|
2005-02-19 01:04:41 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #128
|
|
|
|
jsr subysp ; allocate buffer on the stack
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda sp
|
|
|
|
pha
|
|
|
|
lda sp+1
|
|
|
|
pha ; save sp (buffer address) on processor stack
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr2
|
|
|
|
ldx ptr2+1
|
|
|
|
jsr pushax ; handle
|
2005-02-20 00:39:46 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #0
|
|
|
|
lda #4
|
|
|
|
jsr pushax ; sect_num
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
pla
|
|
|
|
tax
|
|
|
|
pla ; AX - buffer address
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; sst_sectsize currently 128
|
|
|
|
jsr _dio_read ; read sector to update status
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #128
|
|
|
|
jsr addysp ; discard stack buffer
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr2
|
|
|
|
ldx ptr2+1
|
|
|
|
jsr pushax ; handle
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #0
|
|
|
|
lda #4
|
|
|
|
jsr pushax ; dummy sector #, ignored by this SIO command,
|
|
|
|
; but set to circumvent the special 1-3 sector
|
|
|
|
; handling in __sio_call
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>DVSTAT
|
|
|
|
lda #<DVSTAT
|
|
|
|
jsr pushax ; buffer address
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #sst_sectsize
|
|
|
|
lda #4
|
|
|
|
sta (ptr2),y ; 4 bytes transfer
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #%01000000 ; direction value
|
|
|
|
lda #SIO_STAT ; get status
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr __sio_call
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
bmi error
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #sst_sectsize
|
|
|
|
lda DVSTAT
|
|
|
|
and #%100000
|
|
|
|
beq s128
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2005-02-20 00:39:46 +00:00
|
|
|
;s256
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
sta (ptr2),y
|
|
|
|
iny
|
|
|
|
lda #1
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2022-04-17 14:06:22 +00:00
|
|
|
finish: sta (ptr2),y ; set default sector size
|
2013-05-09 11:56:54 +00:00
|
|
|
fini2: lda ptr2
|
|
|
|
ldx ptr2+1
|
|
|
|
rts
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
error: ldy #sst_sectsize
|
|
|
|
s128: lda #128
|
|
|
|
bne finish
|
2005-02-19 01:04:41 +00:00
|
|
|
|
2005-02-20 00:39:46 +00:00
|
|
|
; end of _dio_open
|
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _dio_close
|
2005-02-20 00:39:46 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1
|
|
|
|
lda #0
|
|
|
|
ldy #sst_flag
|
|
|
|
sta (ptr2),y
|
2022-08-28 20:37:33 +00:00
|
|
|
sta ___oserror ; success
|
2013-05-09 11:56:54 +00:00
|
|
|
tax
|
|
|
|
rts ; return no error
|
2005-02-20 00:39:46 +00:00
|
|
|
|
2005-02-19 01:04:41 +00:00
|
|
|
.endproc
|