more floppy issues

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

more floppy issues

Post by Ferrarius »

hello,

I've been trying to get my driver (read-only) for floppies to work. Under bochs it does fine, yet under a real system it doesn't actually load any content (or at least not at the location it's supposed to load to). Are there maybe some assembly programmer's who can spot the mistake?

Code: Select all

FDD:

%define FD.STATUS_A		0x03F0		;read
%define FD.STATUS_B		0x03F1		;read
%define FD.DRIVE_CONTROL	0x03F2		;DOR
%define FD.DRIVE_STATUS	0x03F3			
%define FD.DRIVE_CONTROLLER_STATUS	0x03F4	;read
%define FD.PRECOMP_SELECT	0x03F4		;write
%define FD.FIFO			0x03F5
%define FD.DATARATE_STATUS	0x03F7		;read
%define	FD.DATARATA_CONTROL	0x03F7		;write

%define FLOPPY.SECTOR		0x200


DMA:

.READFLOPPY:
;-------------------------------;
;DMA Initialization.		;
;IN:				;
;  EBX: 24 bits address		;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
mov	al,0x06		;Mask DMA2
out	0x0A,al

mov	al,0xFF		;Reset Master FlipFlop
out	0xD8,al

mov	eax,ebx		;Get Address
out	0x04,al

shr	eax,0x08	;High Byte
out	0x04,al

mov	al,0xFF		;Reset Master FlipFlop
out	0xD8,al

mov	ebx,eax		;save address part

mov	eax,0x3FF	;Count
out	0x05,al

shr	eax,0x08	;count
out	0x05,al

mov	al,0x46		;mode
out	0x0B,al	

mov	eax,ebx		;Retrieve Address Part

shr	eax,0x08	;Page Address
out	0x81,al

mov	al,0x02
out	0x0a,al

ret


.WRITEFLOPPY:
;-------------------------------;
;DMA setup for Floppy Write	;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;

mov	al,0x06		;DMA channel 2 Mask
out	0x0A,al		;Mask the Bastard

mov	al,0x4a		;Single Transfer, From Mem, CH2
out	0x0a,al		;output to port

mov	al,0x02
out	0x0a,al		;unmask the bastard
ret			;return to calling procedure	


;Now here comes the good stuff;


FLOPPY:

;-------------------------------;
;Clears Interrupt Flag in the 	;
; Status Register Once Arrived	;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
.INT:
mov	al,[FINT]
cmp	al,0xFF
jne	.INT
;call	.RECEIVED
;call	.RECEIVED
xor	al,al
mov	[FINT],al
ret

.SNI:
push	ax
push	dx
mov	ax,FD.FIFO
mov	dx,ax
mov	al,0x08
call	.CHREADY
out	dx,al
mov	al,'Z'
call	[0x20028]
call	.RECEIVED
call	.RECEIVED
mov	al,'{'
call	[0x20028]
pop	dx
pop	ax
ret


.SMM:
push	ax
push	dx
mov	ax,FD.FIFO
mov	dx,ax
mov	al,0x08
call	.CHREADY
out	dx,al
mov	al,'Z'
call	[0x20028]
;call	.RECEIVED
;call	.RECEIVED
mov	al,'{'
call	[0x20028]
pop	dx
pop	ax
ret

.GET:
call	.RECEIVED
call	.RECEIVED
ret

.RNS:
mov	al,[FINT]
cmp	al,0xFF
jne	.RNS
ret
.FINISH:
mov	ax,FD.FIFO
mov	dx,ax
mov	al,0x08
call	.CHREADY
out	dx,al
mov	al,'Z'
call	[0x20028]
xor	al,al
mov	[FINT],al
ret

;-------------------------------;
;Checks to see if FIFO can be	;
; Written to.			;
; With Great Thanks to the 	;
; DynatOS Team. Please Read The	;
; License Agreement Within This	;
; File				;
;-------------------------------;
.CHREADY:
push	eax
push	edx
mov	dx,FD.DRIVE_CONTROLLER_STATUS
.CH:
in	al,dx
and	al,0xC0
cmp	al,0x80
jne	.CH

pop	edx
pop	eax
ret


;-------------------------------;
;Takes Information from FIFO	;
; With Great Thanks to the 	;
; DynatOS Team. Please Read The	;
; License Agreement Within This	;
; File				;
;-------------------------------;
.RECEIVED:
push	eax
push	edx
mov	al,'>'
call	[0x20028]
mov	dx,FD.DRIVE_CONTROLLER_STATUS
.RC:
;in	al,dx
;and	al,0xC0
;cmp	al,0xC0
mov	al,0x10
call	[0x20028]
;jne	.RC
mov	dx,FD.FIFO
in	al,dx
call	[0x20028]
mov	al,'?'
call	[0x20028]
mov	al,0
call	[0x20028]
pop	edx
pop	eax
ret

.ON:
;-------------------------------;
;FD Motor Startup. Uses Basic	;
; Timer to wait for startup	;
; times.			;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
push	eax
push	edx
mov	ax,FD.DRIVE_CONTROL	;Ax gets Port Address
mov	dx,ax			;Port Address
mov	al,00011100b
out	dx,al			;Value to be set: 00011100
; - Motor is now spinning up -;
mov	al,'N'
call	[0x20028]
mov	al,0x05
call	.WAIT
pop	edx
pop	eax
ret


.OFF:
;-------------------------------;
;FD Motor Startup. Uses Basic	;
; Timer to wait for startup	;
; times.			;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
push	eax
push	edx
mov	ax,FD.DRIVE_CONTROL	;Ax gets Port Address
mov	dx,ax			;Port Address
mov	al,0x0c
out	dx,al
mov	al,'F'
call	[0x20028]
pop	edx
pop	eax
ret

.RECALIBRATE:
;-------------------------------;
;Recalibrates Disc System	;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
push	eax
push	edx
mov	al,'E'
call	[0x20028]
mov	ax,FD.FIFO	;ax gets port address
mov	dx,ax		;dx gets port address

mov	al,0x07		;command for recalibration of drive
call	.CHREADY
out	dx,al		;sending command.
mov	al,'-'
call	[0x20028]

xor	al,al		;drive zero to be calibrated
out	dx,al

call	.SNI
call	.INT
mov	al,'R'
call	[0x20028]
pop	edx
pop	eax
ret

.SEEK:
;-------------------------------;
;Seeks to cylinder. For v0.03	;
; MIK only assumes first	;
; Cylinder.			;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
push	eax
push	edx
mov	al,']'
call	[0x20028]
mov	ax,FD.FIFO	;ax gets port address
mov	dx,ax		;dx get port address

mov	al,0x0F		;Command for Seek function
call	.CHREADY
out	dx,al		;output to port

mov	al,'['
call	[0x20028]

xor	al,al		;clearing al
out	dx,al		;Drive 0, Head 0

; - Put cylinder assignment here - ;
out	dx,al		;Cylinder Zero

call	.SMM
call	.GET
mov	al,'S'
call	[0x20028]
mov	byte[FINT],0x00

pop	edx
pop	eax
ret



.READ:
;-------------------------------;
;Reads one sector as specified	;
; in CHS of the disk. For v0.03 ;
; only 18 sectors can be sent.	;
; IN:				;
;  bl: Sector Number		;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
push	eax
push	ebx
push	ecx
push	edx
mov	al,'|'
call	[0x20028]

mov	dx,FD.FIFO	;Port Address
call	.CHREADY	;Check if FIFO is ready

mov	al,'9'
call	[0x20028]

mov	al,0x46		;Read Sector Command
out	dx,al

mov	al,0x00		;Disk 0
out	dx,al
out	dx,al		;Cylinder
out	dx,al		;Head

mov	al,0x07		;Sector Number
out	dx,al

mov	al,0x02		;Sector = 512 bytes
out	dx,al		;SectorSize
mov	al,0x07
inc	al
;mov	al,0x12
out	dx,al		;Last Sector Of Track
mov	al,0x1B
out	dx,al		;Gap Length
mov	al,0xFF
call	[0x20028]
out	dx,al		;Obsolete Hardware Requirement

call	.RNS
mov	ecx,0x07
.READFIN:
call	.RECEIVED
loop	.READFIN
CALL	.FINISH
call	.RECEIVED
call	.RECEIVED
mov	al,'M'
call	[0x20028]

pop	edx
pop	ecx
pop	ebx
pop	eax
ret

.WAIT:
;-------------------------------;
;Waits for a specified amount	;
; of time (multiples of ~55mS	;
; IN:				;
;	al: 55*al		;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
call	.WINIT			;Enable Floppytimer
.WAITLOOP:
mov	bl,[FLOPPYTIMER]	;Get value of timer
cmp	al,bl			;Is time past?
jae	.WAITLOOP		;Nope
call	.WSTOP			;Yep
mov	al,'W'
call	[0x20028]
ret

.WINIT:
;-------------------------------;
;Initiates Timer		;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
mov	bl,[TIMERCENTER]	;Current settings of Timers
or	bl,0x01			;Set Floppytimer Bit
mov	[TIMERCENTER],bl	;Enable Timer
ret				

.WSTOP:
;-------------------------------;
;Stops Timer			;
;Hadrianius Ferrarius -- SCSS	;
; Development Project.		;
; SD: UNK - (2008)		;
;-------------------------------;
mov	bl,[TIMERCENTER]	;Current settings of Timers
or	bl,0x01			;Make it one,
xor	bl,0x01			;Clear the bit
mov	[TIMERCENTER],bl	;Stop timer

xor	bl,bl
mov	[FLOPPYTIMER],bl	;Clear Floppytimer
ret

FINT db 0
;---------------------------------------------------------------;
;     1 Copyright (c) 2007 The DynatOS Project.			;
;    2 
;   3 Permission is hereby granted, free of charge, to any person obtaining a copy of
;    4 this software and associated documentation files (the "Software"), to deal in
;    5 the Software without restriction, including without limitation the rights to
;    6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
;    7 the Software, and to permit persons to whom the Software is furnished to do so,
;    8 provided that the above copyright notice and this permission notice is included
;    9 in all copies or substantial portions of the Software.
;   10 
;   11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
;   13 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
;   14 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
;   15 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;   16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;   17 
;   18 The views, opinions and conclusions contained in the software and documentation
;   19 are those of the authors and should not be interpreted as representing official
;   20 policies, either expressed or implied, of The DynatOS Project.
;---------------------------------------------------------------;
Modular Interface Kernel With a lot of bugs ;)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: more floppy issues

Post by Dex »

If it works in boch, but not a real PC it could be a sign of timing as in delay for timings like spin-up, try puting some bigger delays.
If not you could try comparing your floppy driver code to mine, http://dex4u.com/demos/FloppyDriver.zip
Post Reply