| |
TWW
Registered: Jul 2009 Posts: 545 |
KERNAL disk formatting
Hiho.
I am trying to format a disk inside my own program by doing this:
FormatDisk:
sei
lda $01
pha
lda #$36
sta $01
lda #$00
sta $d01a
lda #$01
sta $d019
jsr $ff8a // Restore Vectors
lda #$0f
tay
ldx #$08 // DRIVE
jsr $ffba // SETLFS
lda #$14 // Characters
ldx #<FormatName
ldy #>FormatName
jsr $ffbd // SETNAM
jsr $ffc0 // OPEN
lda #$0f
jsr $ffc3 // CLOSE
lda #$01
sta $d019
sta $d01a
pla
sta $01
cli
rts
FormatName:
.text "N:NAME,ID "
Outside this subroutine I am running a Raster compare IRQ and nothing else. The system is booted from a cartridge and not KERNAL. The drive spins up and led goes green but nothing get's written and it times out after a while and led starts flashing indicating error. Drive has a new D64 mounted.
I also tried running IOINIT and RESTOR but made no difference. Am I missing something? |
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
i think there must be a CR ($0d) at the end of the string...
also, kernal routines will CLI, so the IRQ pointers should be valid and the SEI/CLI around this is kindof pointless |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
Maybe this could end up as an addition on codebase once you get it working? :)
https://codebase64.org/doku.php?id=base:dos_examples
Also see:
https://codebase64.org/doku.php?id=base:formatting_disks |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Can we assume that you've tried OPEN 15,8,15,"N:xxxx,yy":CLOSE15 from basic to the same disk and it worked? It seems to me that this behaviour could be most easily explained by an actual drive error. |
| |
TWW
Registered: Jul 2009 Posts: 545 |
@GPZ:
Yes agreed, was only making sure my IRQ wasn't interfering as I am messing with a lot of things.
@ Frantic:
Sure thing :)
//---------------------------------------------------------------------
// Format the disk in Drive 8
FormatDisk:
lda $01
pha
lda #$36
sta $01
lda #$4a
sta $031a
lda #$f3
sta $031b
lda #$91
sta $031c
lda #$f2
sta $031d // Set KERNAL RAM Vectors (Don't use $fd15 as it will mess up your IRQ Vector)
ldx #6
!: lda SetParameters,x
sta $b7,x // Set SETLFS & SETNAM
dex
bpl !-
jsr $ffc0 // OPEN
lda #$0f
jsr $ffc3 // CLOSE
pla
sta $01
rts
SetParameters:
.byte $14 // Length of Filename
.byte $0f // Logical File Number
.byte $6f // Channel
.byte $08 // Device
.word FormatName
FormatName:
.text "N:DISKNAME,ID"
As soon as I can verify it works I can paste it there.
@ TLR:
That was a good idea and now I'm even more confused here. I launch VICE, attach a disk and type in BASIC:
OPEN 15,8,15,"N:DISKNAME,ID":CLOSE 15
Same thing happens as in my program, the head goes to track zero and after some time, times out and led flashing. Now the weird part, I read the directory:
LOAD"$",8
Then I run the OPEN command again and now it works... Must be some bug of sorts... Any ideas (and if someone say download build XZY of VICE I'm going to shoot myself)! |
| |
Moloch
Registered: Jan 2002 Posts: 2928 |
boot VICE
attach d64
open15,8,15,"n0:diskname,jm":close15
disk formats
check directory
worked
WinVICE 2.4.9 rev31598
true drive emulation on |
| |
TWW
Registered: Jul 2009 Posts: 545 |
Thanks for testing Moloch.
I am running VICE 2.4.20 r29835M and TDE on.
I did however test with an Initialize command both in BASIC and inside my code and then it worked fine:
OPEN 15,8,15,"I":CLOSE 15
OPEN 15,8,15,"N:DISKNAME:ID":Close 15 |
| |
soci
Registered: Sep 2003 Posts: 480 |
TWW:
Just out of interest, why do you bother to change the vector table at all?
You could just directly call $f34a and $f291.
There's no "compatibility" either way but at least it's shorter. |
| |
TWW
Registered: Jul 2009 Posts: 545 |
@Soci: Well, to be honest it was to maintain some degree of compatibility as I really don't know enough about it. Say f.ex. if someone has a non-standard drive ROM or fastloader relying on KERNAL calls to function but as I said, don't know enough about it. So that was the only reason really :) |
| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
Sometimes, using my code with an ar cartridge, i solved some problems resetting the drive using first the UJ then the I command.
Seems cart drivecode causes troubles sometimes... |