Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user jmi ! (Registered 2024-09-15) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Drive code: Detect missing disk...
2022-11-01 19:50
Bacchus

Registered: Jan 2002
Posts: 155
Drive code: Detect missing disk...

I have detecting missing *device* covered. This logics work really well:https://codebase64.org/doku.php?id=base:reading_the_error_chann..

Also, checking if a file exists, one would expect that a plain Open would do the job, but you basically need to read the first byte and checking the Status. But then you have established that.

But what is the easiest way to detect if the device contains a disk? Let's say we have established that there is a disk in the drive. I can start reading a file, but then I don't know if the error will tell me if the file or the entire disk is missing.

Should I do a block read, start reading the directory or what is the general suggestion?

/Bacchus
2022-11-01 21:27
Comos

Registered: May 2004
Posts: 73
If you rely on the kernal calls, then using a directory routine and to read a valid byte and check $90 might do the trick.
2022-11-01 23:35
Krill

Registered: Apr 2002
Posts: 2940
When using KERNAL calls only, reading the device's error channel is the only way to reliably tell the kind of error.

This is something else than "drive code", though. :)
2022-11-02 16:53
chatGPZ

Registered: Dec 2001
Posts: 11290
Turn on the motor and wait for a sync (with timeout) - should be easy enough :)
2022-11-02 19:55
Count Zero

Registered: Jan 2003
Posts: 1878
Quote: Turn on the motor and wait for a sync (with timeout) - should be easy enough :)

Zibri approves! *SCNR*
2022-11-02 19:58
Bacchus

Registered: Jan 2002
Posts: 155
Quote: If you rely on the kernal calls, then using a directory routine and to read a valid byte and check $90 might do the trick.

So basically a getbyte from the filename "$", and one could tell already from the first byte if there was a byte or not?

I do know how to drivecode, but I want to select the route of the least resistance here.

/Bacchus
2022-11-02 22:24
Comos

Registered: May 2004
Posts: 73
Quote: So basically a getbyte from the filename "$", and one could tell already from the first byte if there was a byte or not?

I do know how to drivecode, but I want to select the route of the least resistance here.

/Bacchus


Read just one byte and check bit 1 of $90, 1 = Timeout on read, which in simple would mean there is no disk inserted since we are accessing the lower level - the directory.
If you do this check on a file, then you won't be able to determinate, if the file is simply not present or there is no disk inserted,since in both cases you'll get the same bit set.
Ofcourse this method is not perfect for some detailed error handling.
If you would like to go the way to read out the error channel, then you have to do something in advance like running the init "I" command and then read out the error channel.
2022-11-02 23:02
Count Zero

Registered: Jan 2003
Posts: 1878
Quoting Bacchus
So basically a getbyte from the filename "$", and one could tell already from the first byte if there was a byte or not?


A drive such as a SD2IEC could easily fool for an inserted disc in such a case - so it likely depends on the used loader/saver compatibility in the end unless you determine the drivetype as well or stick to plain kernal routines. hm?
2022-11-02 23:54
Krill

Registered: Apr 2002
Posts: 2940
The clean way is still to read the error channel.

Why is this not an option? :)
2022-11-03 09:55
Mason

Registered: Dec 2001
Posts: 461
Sorry for my vague memory, but it's many years ago I did it

I reckon you can load a byte from a file or the directory. If it doesn't work I reckon $90 is set as a status
2022-11-03 13:38
chatGPZ

Registered: Dec 2001
Posts: 11290
Quote:
Why is this not an option?

head bump?
2022-11-03 13:53
Krill

Registered: Apr 2002
Posts: 2940
Quoting Groepaz
Quote:
Why is this not an option?
head bump?
If head bump is to be avoided, actual drive code is required*. =) (And then you'll run into problems on exotic drives.)

* Turn on motor, wait for sync, stop on timeout.
2022-11-03 15:34
Bacchus

Registered: Jan 2002
Posts: 155
Quote: Read just one byte and check bit 1 of $90, 1 = Timeout on read, which in simple would mean there is no disk inserted since we are accessing the lower level - the directory.
If you do this check on a file, then you won't be able to determinate, if the file is simply not present or there is no disk inserted,since in both cases you'll get the same bit set.
Ofcourse this method is not perfect for some detailed error handling.
If you would like to go the way to read out the error channel, then you have to do something in advance like running the init "I" command and then read out the error channel.


This is a Kernal only scenario. Would love to see it work on any drive. Codebase has a routine for device detection that it claim is less portable, which I guess means that it risk not working on alternative Kernals, but I would like to assume it works on exotic drives. ($BA is assumed to be right when calling this)

My conclusion here is basically;

jsr TestDevice // Should detect Device not found
bcc !+
jmp DeviceNotPresent // Device not present

!: jsr TestDisk // Should detect Disk not present
bcc !+
jmp DiskNotPresent // Disk not present

!: jsr TestFiles // Load the filenames - Handle file not found

The routines that are used would be:

TestDevice:
lda #$00
sta $02a1
sta $90 // clear status flags

lda $ba // device number
jsr $ffb1 // call listen
lda #$6f // secondary address 15 (command channel)
jsr $ff93 // call seclsn (second)
jsr $ffae // call unlsn
lda $90 // get status flags
bne NotPresent // device not present
clc
rts

NotPresent: sec
rts


TestDisk: lda #1
ldx #<DirName
ldy #>DirName
jsr setnam

lda #$02
ldx $ba // last used device number
// bne !+
// ldx #$08 // default to device 8
!: ldy #$02 // $01 means: load to address stored in file
jsr setlfs // call SETLFS - OK with no vectors

jsr open

ldx #$02
jmp chkin

jsr chrin // Get a byte
jsr readst
jsr DoClose
bne Error
clc // Directory - first byte - loaded fine
rts

Error: sec // DIrectory - first byte - didn't load properly
rts

DoClose: pha
lda #$02
jsr close
jsr clrchn
pla
rts

.encoding "screencode_mixed"
DirName: .text "$"
.encoding "screencode_mixed"

=> Any errors found in that?

=> Should I call to init the drive at any point? If so, would that be the command "U:", "UJ", "U9" or a "plain" "I"?



/Bacchus
2022-11-03 15:42
Bacchus

Registered: Jan 2002
Posts: 155
@krill Ok, gotch - this is not "drive code" - it's computer code, accessing the drive. I know how to push stuff to the drive end execute it and this is not that.

This is Pure computer, pure kernal and working with data on the drive, ensuring I capture ALL and ANY relevant error scenario, and also make it work across as many drives as possibly.

I know the stuff that you make in relations to drives. This is not making the fastest sport car. This is making the Volvo totally solid. ;-)

/Bacchus
2022-11-03 15:45
Bacchus

Registered: Jan 2002
Posts: 155
Bugger - there was a jmp chkin that should be a jsr. Sorry about that...

/Bacchus
2022-11-03 17:29
Krill

Registered: Apr 2002
Posts: 2940
What do you actually want to achieve?

Why does there need to be a distinction between file not found and no disk inserted?
2022-11-03 18:50
Comos

Registered: May 2004
Posts: 73
@Bacchus,

the test device routine you have is serial dependant, if you want to have it universal, it can be rewritten in kernal aswell.
2022-11-04 09:52
Bacchus

Registered: Jan 2002
Posts: 155
@krill I want to load and save stuff to disk as part of a program, and that program needs to handle the situations where there is a save problem. Formally no need to differentiate between the two cases, but if you select a device you might want to capture that this is a device not available and I am also keen to capture no disk in the drive before I start the actual save.

@cosmos The use case is serial with a drive. No need to generalize it beyond the actual use case.

I did a test program where I implemented the above, but there is still issues when the same code is implemented in the program. :-P

/Bacchus
2022-11-04 11:04
Krill

Registered: Apr 2002
Posts: 2940
Quoting Bacchus
if you select a device you might want to capture that this is a device not available and I am also keen to capture no disk in the drive before I start the actual save.
What would be the difference between erroring out after an init command before saving vs. attempting to save and then erroring out?
2022-11-04 17:57
Bacchus

Registered: Jan 2002
Posts: 155
Gunnar, you come from a different perspective.

You do your thing and put the loader out for others to use. I am retrofitting stuff, meaning I need to wedge in my stuff as smoothly as possible. I might also not control what happens after a certain point unless I open up more patching with potential side effects.

So I prefer to do my stuff and secure things are as good as I can make them, and then I release the thing, not being sure I can regain control if it bugs out at a later stage.

Not sure that argument holds water, but also there is an inner loop loading five different files. Letting them all fail will take a long time. Wedging in stuff there is tricky so I prefer to do it this way this time ...

The things with that piece of code I have done is that it tells "device not present" from "disk not present", and that *looks* nice :-)

/Bacchus
2022-11-04 22:21
Comos

Registered: May 2004
Posts: 73
Quoting Bacchus

I did a test program where I implemented the above, but there is still issues when the same code is implemented in the program. :-P


What kind of a issue?
2022-11-05 12:12
Krill

Registered: Apr 2002
Posts: 2940
Quoting Bacchus
there is an inner loop loading five different files. Letting them all fail will take a long time. Wedging in stuff there is tricky so I prefer to do it this way this time ...
Retrofitting or not, what i was saying is that i see no advantage of checking for disk-not-present prior to saving, as saving itself does that check implicitly, too.
This is also independent from any inner loops handling multiple files.
2022-11-05 15:10
Bacchus

Registered: Jan 2002
Posts: 155
Quote: Quoting Bacchus

I did a test program where I implemented the above, but there is still issues when the same code is implemented in the program. :-P


What kind of a issue?


@Cosmos Can't really describe it perfectly but it feels like the commands aren't concluded properly, and the drive isn't ready to accept new commands. The detect disk command works arbitrarily. Sometimes it does and sometimes not (possibly depending on what happened before). Trying to send an "I" commands after my detection routines, I simply get an error. In VICE I can switch to DEV 8: and do M 0200 to see the status message, and sometimes that is Syntax error. That could sometimes happen if I send commands in the wrong case (common issue I have when messing with drive code).

@Krill I fully sympathize with this point of view and I will onboard it when considering the task ahead. Would be stupid not to :-)

Can be agree that if $98 is $00, then I have closed all files I have opened, right?

/Bacchus
2022-11-05 15:20
Krill

Registered: Apr 2002
Posts: 2940
Quoting Bacchus
Can't really describe it perfectly but it feels like the commands aren't concluded properly, and the drive isn't ready to accept new commands. The detect disk command works arbitrarily. Sometimes it does and sometimes not (possibly depending on what happened before).
I think it's important to error out at the earliest possible chance. So i'd check $90 after every command that might fail, plus OPEN returns an error flag via the C flag. On error, of course, need to properly clean up, too.
2022-11-05 21:24
Comos

Registered: May 2004
Posts: 73
Quoting Krill
I think it's important to error out at the earliest possible chance. So i'd check $90 after every command that might fail, plus OPEN returns an error flag via the C flag. On error, of course, need to properly clean up, too.


Besides $90 it's possible to readout accu for error code aswell in certain calls.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
bugjam
Scooby/G★P/Light
Matt
Courage
Sychamis
E$G/HF ⭐ 7
WVL/Xenon
Da Snake
megasoftargentina
alwyz/udi
tlr
Guests online: 139
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 Wonderland XIV  (9.6)
8 Comaland 100%  (9.6)
9 No Bounds  (9.6)
10 Unboxed  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Onscreen 5k  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Morph  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.2)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.065 sec.