Subversion Repositories Kolibri OS

Compare Revisions

Problem with comparison.

Regard whitespace Rev HEAD → Rev 1

/trunk/blkdev/cdrom.inc
0,0 → 1,261
sys_cd_audio:
 
cmp word [cdbase],word 0
jnz @f
mov eax,1
ret
@@:
 
; eax=1 cdplay at ebx 0x00FFSSMM
; eax=2 get tracklist size of ecx to [ebx]
; eax=3 stop/pause playing
 
cmp eax,1
jnz nocdp
call sys_cdplay
ret
nocdp:
 
cmp eax,2
jnz nocdtl
mov edi,[0x3010]
add edi,0x10
add ebx,[edi]
call sys_cdtracklist
ret
nocdtl:
 
cmp eax,3
jnz nocdpause
call sys_cdpause
ret
nocdpause:
 
mov eax,0xffffff01
ret
 
 
 
sys_cd_atapi_command:
 
pushad
 
mov dx,word [cdbase]
add dx,6
mov ax,word [cdid]
out dx,al
mov esi,10
call delay_ms
mov dx,word [cdbase]
add dx,7
in al,dx
and al,0x80
cmp al,0
jnz res
jmp cdl6
res:
mov dx,word [cdbase]
add dx,7
mov al,0x8
out dx,al
mov dx,word [cdbase]
add dx,0x206
mov al,0xe
out dx,al
mov esi,1
call delay_ms
mov dx,word [cdbase]
add dx,0x206
mov al,0x8
out dx,al
mov esi,30
call delay_ms
xor cx,cx
cdl5:
inc cx
cmp cx,10
jz cdl6
mov dx,word [cdbase]
add dx,7
in al,dx
and al,0x88
cmp al,0x00
jz cdl5
mov esi,100
call delay_ms
jmp cdl5
cdl6:
mov dx,word [cdbase]
add dx,4
mov al,0
out dx,al
mov dx,word [cdbase]
add dx,5
mov al,0
out dx,al
mov dx,word [cdbase]
add dx,7
mov al,0xec
out dx,al
mov esi,5
call delay_ms
mov dx,word [cdbase]
add dx,1
mov al,0
out dx,al
add dx,1
mov al,0
out dx,al
add dx,1
mov al,0
out dx,al
add dx,1
mov al,0
out dx,al
add dx,1
mov al,128
out dx,al
add dx,2
mov al,0xa0
out dx,al
xor cx,cx
mov dx,word [cdbase]
add dx,7
cdl1:
inc cx
cmp cx,100
jz cdl2
in al,dx
and ax,0x88
cmp al,0x8
jz cdl2
mov esi,2
call delay_ms
jmp cdl1
cdl2:
 
popad
ret
 
 
sys_cdplay:
 
mov ax,5
push ax
push ebx
cdplay:
call sys_cd_atapi_command
cli
mov dx,word [cdbase]
mov ax,0x0047
out dx,ax
mov al,1
mov ah,[esp+0] ; min xx
out dx,ax
mov ax,[esp+1] ; fr sec
out dx,ax
mov ax,256+99
out dx,ax
mov ax,0x0001
out dx,ax
mov ax,0x0000
out dx,ax
mov esi,10
call delay_ms
sti
add dx,7
in al,dx
test al,1
jz cdplayok
mov ax,[esp+4]
dec ax
mov [esp+4],ax
cmp ax,0
jz cdplayfail
jmp cdplay
cdplayfail:
cdplayok:
pop ebx
pop ax
xor eax, eax
ret
 
 
sys_cdtracklist:
 
push ebx
tcdplay:
call sys_cd_atapi_command
mov dx,word [cdbase]
mov ax,0x43+2*256
out dx,ax
mov ax,0x0
out dx,ax
mov ax,0x0
out dx,ax
mov ax,0x0
out dx,ax
mov ax,200
out dx,ax
mov ax,0x0
out dx,ax
in al,dx
mov cx,1000
mov dx,word [cdbase]
add dx,7
cld
cdtrnwewait:
mov esi,10
call delay_ms
in al,dx
and al,128
cmp al,0
jz cdtrl1
loop cdtrnwewait
cdtrl1:
; read the result
mov ecx,[esp+0]
mov dx,word [cdbase]
cdtrread:
add dx,7
in al,dx
and al,8
cmp al,8
jnz cdtrdone
sub dx,7
in ax,dx
mov [ecx],ax
add ecx,2
jmp cdtrread
cdtrdone:
pop ecx
xor eax, eax
ret
 
 
sys_cdpause:
 
call sys_cd_atapi_command
 
mov dx,word [cdbase]
mov ax,0x004B
out dx,ax
mov ax,0
out dx,ax
mov ax,0
out dx,ax
mov ax,0
out dx,ax
mov ax,0
out dx,ax
mov ax,0
out dx,ax
 
mov esi,10
call delay_ms
add dx,7
in al,dx
 
xor eax, eax
ret
 
/trunk/blkdev/fdc.inc
0,0 → 1,369
;### fdc.inc ### Menuetos floppy stuff.
;Version 0.2: Write individual tracks. / Sync ramdisk <-> floppy
;Version 0.1: Write full ramdisk to floppy.
;£loppyright Tolle.
 
;depends on:
;restorefatchain
;memmove
;Int 6 (sys32.inc) should call fdc_irq func.
;The ramdisk should be at 0x100000
 
;Keeping track of the tracks.
iglobal
cylinder db 0
sector db 1
head db 0
 
;Memory and dma variables.
fdcmem dd 0x100000
cpymem dd 0x100000
dmamem dd 0x100000
endg
 
uglobal
dmasize db 0x0
dmamode db 0x0
endg
 
iglobal
;function pointers.
fdc_irq_func dd fdc_null
fdc_pump_func dd fdc_null
endg
 
uglobal
;General stuff
fdc_st0 db 0 ;status register 0 of last resultphase.
fdc_mutex db 0 ;wait in line. (Block calling app)
fdc_callspending db 0 ;mystery sauce
fdc_settings dd 0 ;bitfield.
endg
;Bit 0 enable direct file write [yes/no]
 
fdc_set: ;ebx: fdc_settings bitfield.
mov [fdc_settings],ebx
ret
 
fdc_get: ;returns fdc_settings in ecx
mov ecx, [fdc_settings]
ret
 
fdc_init: ;start with clean tracks.
mov edi,0xD201
mov al,0
mov ecx,160
rep stosb
ret
 
fdc_filesave: ;ebx: cluster to be saved.
pusha ;returns immediately. does not trigger a write.
mov eax,ebx
add eax,31
mov bl,18
div bl
mov ah,0
add eax,0xD201
mov [eax],byte 1 ;This track is now dirty.
popa
ret
 
 
fdc_writeramdisk: ;mark all tracks as dirty.
mov edi,0xD201
mov al,1
mov ecx,160
rep stosb
jmp fdc_commitflush
fdc_commitfile: ;flush dirty tracks to floppy
test [fdc_settings],1 ;...but only if this is really wanted by the user.
je fdc_commitend
fdc_commitflush:
cmp [fdc_callspending],5
je fdc_commitend
inc [fdc_callspending]
cmp [fdc_callspending],1
je fdc_commitonce
fdc_commitend:
ret
 
fdc_commitonce: ;One at a time.
.stall:
cli
cmp [fdc_mutex],0
jne .stallret
mov [fdc_mutex],1
jmp .goahead
.stallret:
sti
jmp .stall
.goahead:
sti
 
fdc_commitramdisk:
 
call restorefatchain
;Move the bootsector to a safe place.
mov eax,0x100000
mov ebx,0xD000
mov ecx,512
call memmove
;Always write the FAT table
mov eax,0xD201
mov [eax],byte 1
inc eax
mov [eax],byte 1
 
mov [dmamode],0x4A ;read from memory to floppy.
mov [dmasize],0x1 ;read 512 bytes sectors.
mov [fdc_irq_func],fdc_commitramdisk1
call fdc_floppy_on ;start floppy A: moter starts interruptflow.
ret
fdc_commitramdisk1:
mov [fdc_irq_func],fdc_recalibrate_result
mov [fdc_pump_func],fdc_commitramdisk2
call fdc_recalibrate ;retract the head to cylinder 0, sector 1
ret
fdc_commitramdisk2:
mov[head],0 ;set variables.
mov[cylinder],0
mov [sector],1
mov[cpymem],0x102400
mov [fdc_pump_func],fdc_fullpump
call fdc_write ;fdc_write will continue interruptflow
ret
 
fdc_fullpump:
add [dmamem],512
add [sector],1
cmp [sector],19
jne .clusterwrite
sub [dmamem],9216
mov eax,[cpymem]
mov ebx,[fdcmem]
mov ecx,9216
call memmove
add [cpymem],9216
cmp [head],0
je .nocylinderchange
add [cylinder],1
.nocylinderchange:
xor [head],1
cmp [cylinder],80
jne .noendofwrite
mov[fdc_irq_func],fdc_complete
call fdc_floppy_off
call fdc_init
jmp .end
.noendofwrite:
mov [sector],1
.clusterwrite:
xor eax,eax
mov al,[cylinder]
shl eax,1
add al,[head]
add eax,0xD201
mov bl,[eax]
cmp bl,1
jne fdc_fullpump
call fdc_write
.end:
ret
 
fdc_write:
call fdc_program_dma
call fdc_seek
ret
 
fdc_seek:
mov al, 0x0f
call fdc_write_reg
mov al,[head]
shl al,2
call fdc_write_reg
mov al,[cylinder]
call fdc_write_reg
mov [fdc_irq_func],fdc_seek_result
ret
 
fdc_seek_result:
call fdc_sensei
cmp al,[cylinder]
je .succes
call fdc_seek
jmp .end
.succes:
call fdc_write_sector
.end:
ret
 
fdc_write_sector:
mov al,0x45 ;write sector command
fdc_commandphase:
call fdc_write_reg
mov al,[head]
shl al,2
call fdc_write_reg
mov al,[cylinder]
call fdc_write_reg
mov al,[head]
call fdc_write_reg
mov al,[sector]
call fdc_write_reg
mov al,2 ;Sector size (2 ~> 512 bytes)
call fdc_write_reg
mov al,18 ;last sector on track.
call fdc_write_reg
mov al,27 ;length of GAP3
call fdc_write_reg
mov al,0xFF ;data length, ignored.
call fdc_write_reg
mov [fdc_irq_func],fdc_resultphase
ret
 
fdc_resultphase:
call fdc_read_reg
mov [fdc_st0],al
mov cx,6
.readresult:
call fdc_read_reg
loop .readresult
and [fdc_st0],11000000b
cmp [fdc_st0],byte 0
jz .succes
call fdc_seek
jmp .end
.succes:
call [fdc_pump_func]
.end:
ret
 
fdc_sensei:
mov al,0x08 ;get interrupt status command
call fdc_write_reg
call fdc_read_reg ;get result in al;
and al,0x80
cmp al,0x80
je fdc_sensei ;retry
call fdc_read_reg
ret
 
fdc_program_dma:
mov al,0
out 0x0c,al ; reset the flip-flop to a known state.
mov al,6 ; mask channel 2 so we can reprogram it.
out 0x0a,al
mov al,[dmamode] ; 0x46 -> Read from floppy - 0x4A Write to floppy
out 0x0b,al
mov al,0
out 0x0c,al ; reset the flip-flop to a known state.
mov eax,[dmamem]
out 0x04,al ; set the channel 2 starting address to 0
shr eax,8
out 0x04,al
shr eax,8
out 0x81,al
mov al,0
out 0x0c, al ; reset flip-flop
mov al, 0xff ;set count (actual size -1)
out 0x5, al
mov al, [dmasize] ;(0x1ff = 511 / 0x23ff =9215)
out 0x5,al
mov al,2
out 0xa,al
ret
 
fdc_recalibrate:
mov al,0x07 ;calibrate command
call fdc_write_reg
mov al,0 ;select drive 0
call fdc_write_reg
ret
 
fdc_recalibrate_result:
mov al,0x08 ;get interrupt status command
call fdc_write_reg ;send it
call fdc_read_reg ;get command in al;
cmp al,0x80
je fdc_recalibrate_result
mov ah,al
call fdc_read_reg
cmp ah,0x70
jne .end
call fdc_recalibrate
jmp .reallyend
.end:
call [fdc_pump_func]
.reallyend:
ret
 
fdc_busy:
.command_check:
mov dx,0x3F4
in al,dx
and al,0x10
cmp al,0x10
je .command_check
ret
 
fdc_read_reg:
status_check:
mov dx,0x3F4
in al,dx
and al,0xc0
cmp al,0xc0
jne status_check
mov dx, 0x3F5
in al, dx
ret
 
fdc_write_reg:
mov bl,al
.command_check:
mov dx,0x3F4
in al,dx
and al,0x80
cmp al,0x80
jne .command_check
mov al,bl
mov dx,0x3F5
out dx,al
ret
 
fdc_floppy_off:
mov al,0xC
mov dx,0x3f2
out dx,al
ret
 
fdc_floppy_on:
mov dx,0x3f2
mov al,0x0
out dx,al
mov al,0x1C
out dx,al
mov eax,50
call delay_hs
ret
 
fdc_complete:
mov eax,0xD000
mov ebx,0x100000
mov ecx,512
call memmove
 
mov [fdc_irq_func],fdc_null
mov [fdc_mutex],0
dec [fdc_callspending]
cmp [fdc_callspending],0
je .realyend
mov [fdc_mutex],1
call fdc_commitramdisk
.realyend:
ret
 
fdc_irq:
call [fdc_irq_func]
fdc_null:
ret
/trunk/blkdev/flp_drv.inc
0,0 → 1,685
;**********************************************************
; ¥¯®á।á⢥­­ ï à ¡®â  á ª®­â஫«¥à®¬ £¨¡ª®£® ¤¨áª 
;**********************************************************
; €¢â®à ¨á室­®£® ⥪áâ  Šã« ª®¢ ‚« ¤¨¬¨à ƒ¥­­ ¤ì¥¢¨ç.
; €¤ ¯â æ¨ï ¨ ¤®à ¡®âª  Mario79
fdd_read_and_write:
pusha
read_sector:
cmp eax,1
jne write_sector
call save_HTS_values
call flp_readsector
call give_back_application_data
jmp fdd_read_end
write_sector:
cmp eax,2
jne fdd_read_end
call save_HTS_values
call take_data_from_application
call flp_writesector
fdd_read_end:
popa
ret
 
save_HTS_values:
mov [FDD_Sector],bl
mov [FDD_Head],bh
shr ebx,16
mov [FDD_Track],bl
mov [FDD_Type],bh
ret
 
give_back_application_data: ; ¯¥à¥á« âì ¯à¨«®¦¥­¨î
mov edi,[3010h]
mov edi,[edi+10h]
add edi,ecx
give_back_application_data_1:
mov esi,0xD000 ;FDD_DataBuffer ;0x40000
xor ecx,ecx
mov cx,128
cld
rep movsd
ret
 
take_data_from_application: ; ¢§ïâì ¨§ ¯à¨«®¦¥­¨ï
mov esi,[3010h]
mov esi,[esi+10h]
add esi,ecx
take_data_from_application_1:
mov edi,0xD000 ;FDD_DataBuffer ;0x40000
xor ecx,ecx
mov cx,128
cld
rep movsd
ret
 
flp_initialization:
; “áâ ­®¢¨âì ­®¢ë© ®¡à ¡®â稪 ¯à¥à뢠­¨ï ƒŒ„
call SetUserInterrupts
; ‚ª«îç¨âì ¬®â®à ¤¨áª®¢®¤ 
call FDDMotorON
; ˆ­¨æ¨ «¨§¨à®¢ âì ¯¥à¥¬¥­­ë¥
; mov [FDD_Track],0
; mov [FDD_Head],0
; mov [FDD_Sector],1
; à®¢¥á⨠४ «¨¡à®¢ªã ¨ ¯®¨áª ­ã«¥¢®© ¤®à®¦ª¨
call RecalibrateFDD
call SeekTrack
ret
 
flp_readsector:
call flp_initialization
; à®ç¨â âì ᥪâ®à
call ReadSectWithRetr
; call ReadSector
; cmp [FDC_Status],0
; jne @@SectorNotFound
mov [fdc_irq_func],fdc_null
; call FDDMotorOFF
ret
 
flp_writesector:
call flp_initialization
; ‡ ¯¨á âì ᥪâ®à
call WriteSectWithRetr
; call WriteSector
; cmp [FDC_Status],0
; jne @@SectorNotFound
mov [fdc_irq_func],fdc_null
; call FDDMotorOFF
ret
 
@@DiskNotFound:
ret
@@SectorNotFound:
ret
 
; Š®¤ë § ¢¥à襭¨ï ®¯¥à æ¨¨ á ª®­â஫«¥à®¬ (FDC_Status)
FDC_Normal equ 0 ;­®à¬ «ì­®¥ § ¢¥à襭¨¥
FDC_TimeOut equ 1 ;®è¨¡ª  â ©¬- ãâ 
FDC_DiskNotFound equ 2 ;¢ ¤¨áª®¢®¤¥ ­¥â ¤¨áª 
FDC_TrackNotFound equ 3 ;¤®à®¦ª  ­¥ ­ ©¤¥­ 
FDC_SectorNotFound equ 4 ;ᥪâ®à ­¥ ­ ©¤¥­
 
; Œ ªá¨¬ «ì­ë¥ §­ ç¥­¨ï ª®®à¤¨­ â ᥪâ®à  (§ ¤ ­­ë¥
; §­ ç¥­¨ï ᮮ⢥âáâ¢ãîâ ¯ à ¬¥âà ¬ áâ ­¤ àâ­®£®
; âà¥å¤î©¬®¢®£® £¨¡ª®£® ¤¨áª  ®¡ê¥¬®¬ 1,44 Œ¡)
MAX_Track equ 79
MAX_Head equ 1
MAX_Sector equ 18
 
; ‘ç¥â稪 ⨪®¢ â ©¬¥à 
TickCounter dd ?
; Š®¤ § ¢¥à襭¨ï ®¯¥à æ¨¨ á ª®­â஫«¥à®¬ ƒŒ„
FDC_Status DB ?
; ”« £ ¯à¥à뢠­¨ï ®â ƒŒ„
FDD_IntFlag DB ?
; Œ®¬¥­â ­ ç «  ¯®á«¥¤­¥© ®¯¥à æ¨¨ á ƒŒ„
FDD_Time DD ?
; ®¬¥à ¤¨áª®¢®¤ 
FDD_Type db 0
; Š®®à¤¨­ âë ᥪâ®à 
FDD_Track DB ?
FDD_Head DB ?
FDD_Sector DB ?
 
; «®ª १ã«ìâ â  ®¯¥à æ¨¨
FDC_ST0 DB ?
FDC_ST1 DB ?
FDC_ST2 DB ?
FDC_C DB ?
FDC_H DB ?
FDC_R DB ?
FDC_N DB ?
; ‘ç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï
ReadRepCounter DB ?
; ‘ç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ४ «¨¡à®¢ª¨
RecalRepCounter DB ?
; Ž¡« áâì ¯ ¬ï⨠¤«ï åà ­¥­¨ï ¯à®ç¨â ­­®£® ᥪâ®à 
;FDD_DataBuffer: times 512 db 0 ;DB 512 DUP (?)
fdd_motor_status db 0
timer_fdd_motor dd 0
 
;*************************************
;* ˆˆ–ˆ€‹ˆ‡€–ˆŸ …†ˆŒ€ „ „‹Ÿ ƒŒ„ *
;*************************************
Init_FDC_DMA:
pushad
mov al,0
out 0x0c,al ; reset the flip-flop to a known state.
mov al,6 ; mask channel 2 so we can reprogram it.
out 0x0a,al
mov al,[dmamode] ; 0x46 -> Read from floppy - 0x4A Write to floppy
out 0x0b,al
mov al,0
out 0x0c,al ; reset the flip-flop to a known state.
mov eax,0xD000
out 0x04,al ; set the channel 2 starting address to 0
shr eax,8
out 0x04,al
shr eax,8
out 0x81,al
mov al,0
out 0x0c, al ; reset flip-flop
mov al, 0xff ;set count (actual size -1)
out 0x5, al
mov al,0x1 ;[dmasize] ;(0x1ff = 511 / 0x23ff =9215)
out 0x5,al
mov al,2
out 0xa,al
popad
ret
 
;***********************************
;* ‡€ˆ‘€’œ €‰’ ‚ Ž’ „€›• FDC *
;*  à ¬¥âàë: *
;* AL - ¢ë¢®¤¨¬ë© ¡ ©â. *
;***********************************
FDCDataOutput:
; pusha
push ax cx dx
mov AH,AL ;§ ¯®¬­¨âì ¡ ©â ¢ AH
; ‘¡à®á¨âì ¯¥à¥¬¥­­ãî á®áâ®ï­¨ï ª®­â஫«¥à 
mov [FDC_Status],FDC_Normal
; à®¢¥à¨âì £®â®¢­®áâì ª®­â஫«¥à  ª ¯à¨¥¬ã ¤ ­­ëå
mov DX,3F4h ;(¯®àâ á®áâ®ï­¨ï FDC)
xor CX,CX ;ãáâ ­®¢¨âì áç¥â稪 â ©¬- ãâ 
@@TestRS:
in AL,DX ;¯à®ç¨â âì ॣ¨áâà RS
and AL,0C0h ;¢ë¤¥«¨âì à §àï¤ë 6 ¨ 7
cmp AL,80h ;¯à®¢¥à¨âì à §àï¤ë 6 ¨ 7
je @@OutByteToFDC
loop @@TestRS
; Žè¨¡ª  â ©¬- ãâ 
mov [FDC_Status],FDC_TimeOut
jmp @@End_5
; ‚뢥á⨠¡ ©â ¢ ¯®àâ ¤ ­­ëå
@@OutByteToFDC:
inc DX
mov AL,AH
out DX,AL
@@End_5:
; popa
pop dx cx ax
ret
 
;******************************************
;* Ž—ˆ’€’œ €‰’ ˆ‡ Ž’€ „€›• FDC *
;* à®æ¥¤ãà  ­¥ ¨¬¥¥â ¢å®¤­ëå ¯ à ¬¥â஢. *
;* ‚ë室­ë¥ ¤ ­­ë¥: *
;* AL - áç¨â ­­ë© ¡ ©â. *
;******************************************
FDCDataInput:
push ECX
push DX
; ‘¡à®á¨âì ¯¥à¥¬¥­­ãî á®áâ®ï­¨ï ª®­â஫«¥à 
mov [FDC_Status],FDC_Normal
; à®¢¥à¨âì £®â®¢­®áâì ª®­â஫«¥à  ª ¯¥à¥¤ ç¥ ¤ ­­ëå
mov DX,3F4h ;(¯®àâ á®áâ®ï­¨ï FDC)
xor CX,CX ;ãáâ ­®¢¨âì áç¥â稪 â ©¬- ãâ 
@@TestRS_1:
in AL,DX ;¯à®ç¨â âì ॣ¨áâà RS
and AL,0C0h ;¢ë¤«¨âì à §àï¤ë 6 ¨ 7
cmp AL,0C0h ;¯à®¢¥à¨âì à §àï¤ë 6 ¨ 7
je @@GetByteFromFDC
loop @@TestRS_1
; Žè¨¡ª  â ©¬- ãâ 
mov [FDC_Status],FDC_TimeOut
jmp @@End_6
; ‚¢¥á⨠¡ ©â ¨§ ¯®àâ  ¤ ­­ëå
@@GetByteFromFDC:
inc DX
in AL,DX
@@End_6: pop DX
pop ECX
ret
 
;*********************************************
;* Ž€Ž’—ˆŠ …›‚€ˆŸ Ž’ ŠŽ’Ž‹‹…€ ƒŒ„ *
;*********************************************
FDCInterrupt:
;  §à¥è¨âì ¯à¥à뢠­¨ï
; sti
; push AX
; “áâ ­®¢¨âì ä« £ ¯à¥à뢠­¨ï
mov [FDD_IntFlag],1
; ®á« âì ª®¬ ­¤ã EOI ª®­â஫«¥àã ¯à¥à뢠­¨©
; mov AL,20h
; out 20h,AL
; pop AX
ret
 
 
;******************************************
;* “‘’€Ž‚ˆ’œ Ž‚›‰ Ž€Ž’—ˆŠ …›‚€ˆ‰ *
;* ƒŒ„ *
;******************************************
SetUserInterrupts:
mov [fdc_irq_func],FDCInterrupt
ret
 
;*******************************************
;* Ž†ˆ„€ˆ… …›‚€ˆŸ Ž’ ŠŽ’Ž‹‹…€ ƒŒ„ *
;*******************************************
WaitFDCInterrupt:
pusha
; ‘¡à®á¨âì ¡ ©â á®áâ®ï­¨ï ®¯¥à æ¨¨
mov [FDC_Status],FDC_Normal
; ‘¡à®á¨âì ä« £ ¯à¥à뢠­¨ï
mov [FDD_IntFlag],0
; Ž¡­ã«¨âì áç¥â稪 ⨪®¢
mov eax,[timer_ticks]
mov [TickCounter],eax
; Ž¦¨¤ âì ãáâ ­®¢ª¨ ä« £  ¯à¥à뢠­¨ï ƒŒ„
@@TestRS_2:
cmp [FDD_IntFlag],0
jnz @@End_7 ;¯à¥à뢠­¨¥ ¯à®¨§®è«®
mov eax,[timer_ticks]
sub eax,[TickCounter]
cmp eax,50 ;25 ;5 ;®¦¨¤ âì 5 ⨪®¢
jb @@TestRS_2
; jl @@TestRS_2
; Žè¨¡ª  â ©¬- ãâ 
mov [FDC_Status],FDC_TimeOut
; mov [flp_status],0
@@End_7: popa
ret
 
;*********************************
;* ‚Š‹ž—ˆ’œ ŒŽ’Ž „ˆ‘ŠŽ‚Ž„€ "A:" *
;*********************************
FDDMotorON:
pusha
; cmp [fdd_motor_status],1
; je fdd_motor_on
mov al,[flp_number]
cmp [fdd_motor_status],al
je fdd_motor_on
; à®¨§¢¥á⨠á¡à®á ª®­â஫«¥à  ƒŒ„
mov DX,3F2h ;¯®àâ ã¯à ¢«¥­¨ï ¤¢¨£ â¥«ï¬¨
mov AL,0
out DX,AL
; ‚ë¡à âì ¨ ¢ª«îç¨âì ¬®â®à ¤¨áª®¢®¤ 
cmp [flp_number],1
jne FDDMotorON_B
; call FDDMotorOFF_B
mov AL,1Ch ; Floppy A
jmp FDDMotorON_1
FDDMotorON_B:
; call FDDMotorOFF_A
mov AL,2Dh ; Floppy B
FDDMotorON_1:
out DX,AL
; Ž¡­ã«¨âì áç¥â稪 ⨪®¢
mov eax,[timer_ticks]
mov [TickCounter],eax
; Ž¦¨¤ âì 0,5 á
@@dT:
mov eax,[timer_ticks]
sub eax,[TickCounter]
cmp eax,50 ;10
jb @@dT
cmp [flp_number],1
jne fdd_motor_on_B
mov [fdd_motor_status],1
jmp fdd_motor_on
fdd_motor_on_B:
mov [fdd_motor_status],2
fdd_motor_on:
call save_timer_fdd_motor
popa
ret
 
;*****************************************
;* ‘Ž•€…ˆ… “Š€‡€’…‹Ÿ ‚…Œ…ˆ *
;*****************************************
save_timer_fdd_motor:
mov eax,[timer_ticks]
mov [timer_fdd_motor],eax
ret
 
;*****************************************
;* Ž‚…Š€ ‡€„…†Šˆ ‚›Š‹ž—…ˆŸ ŒŽ’Ž€ *
;*****************************************
check_fdd_motor_status:
cmp [fdd_motor_status],0
je end_check_fdd_motor_status
mov eax,[timer_ticks]
sub eax,[timer_fdd_motor]
cmp eax,500
jb end_check_fdd_motor_status
call FDDMotorOFF
mov [fdd_motor_status],0
end_check_fdd_motor_status:
ret
 
;**********************************
;* ‚›Š‹ž—ˆ’œ ŒŽ’Ž „ˆ‘ŠŽ‚Ž„€ *
;**********************************
FDDMotorOFF:
push AX
push DX
cmp [flp_number],1
jne FDDMotorOFF_1
call FDDMotorOFF_A
jmp FDDMotorOFF_2
FDDMotorOFF_1:
call FDDMotorOFF_B
FDDMotorOFF_2:
pop DX
pop AX
; á¡à®á ä« £®¢ ª¥è¨à®¢ ­¨ï ¢ á¢ï§¨ á ãáâ à¥¢ ­¨¥¬ ¨­ä®à¬ æ¨¨
mov [root_read],0
mov [flp_fat],0
ret
 
FDDMotorOFF_A:
mov DX,3F2h ;¯®àâ ã¯à ¢«¥­¨ï ¤¢¨£ â¥«ï¬¨
mov AL,0Ch ; Floppy A
out DX,AL
ret
 
FDDMotorOFF_B:
mov DX,3F2h ;¯®àâ ã¯à ¢«¥­¨ï ¤¢¨£ â¥«ï¬¨
mov AL,5h ; Floppy B
out DX,AL
ret
 
;*******************************
;* …Š€‹ˆŽ‚Š€ „ˆ‘ŠŽ‚Ž„€ "A:" *
;*******************************
RecalibrateFDD:
pusha
call save_timer_fdd_motor
; ®¤ âì ª®¬ ­¤ã "¥ª «¨¡à®¢ª "
mov AL,07h
call FDCDataOutput
mov AL,00h
call FDCDataOutput
; Ž¦¨¤ âì § ¢¥à襭¨ï ®¯¥à æ¨¨
call WaitFDCInterrupt
; cmp [FDC_Status],0
; je no_fdc_status_error
; mov [flp_status],0
;no_fdc_status_error:
call save_timer_fdd_motor
popa
ret
 
;*****************************************************
;* Žˆ‘Š „ŽŽ†Šˆ *
;*  à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1). *
;* ¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;*****************************************************
SeekTrack:
pusha
call save_timer_fdd_motor
; ®¤ âì ª®¬ ­¤ã "®¨áª"
mov AL,0Fh
call FDCDataOutput
; ¥à¥¤ âì ¡ ©â ­®¬¥à  £®«®¢ª¨/­ ª®¯¨â¥«ï
mov AL,[FDD_Head]
shl AL,2
call FDCDataOutput
; ¥à¥¤ âì ¡ ©â ­®¬¥à  ¤®à®¦ª¨
mov AL,[FDD_Track]
call FDCDataOutput
; Ž¦¨¤ âì § ¢¥à襭¨ï ®¯¥à æ¨¨
call WaitFDCInterrupt
cmp [FDC_Status],FDC_Normal
jne @@Exit
; ‘®åà ­¨âì १ã«ìâ â ¯®¨áª 
mov AL,08h
call FDCDataOutput
call FDCDataInput
mov [FDC_ST0],AL
call FDCDataInput
mov [FDC_C],AL
; à®¢¥à¨âì १ã«ìâ â ¯®¨áª 
; ®¨áª § ¢¥à襭?
test [FDC_ST0],100000b
je @@Err
; ‡ ¤ ­­ë© â४ ­ ©¤¥­?
mov AL,[FDC_C]
cmp AL,[FDD_Track]
jne @@Err
; ®¬¥à £®«®¢ª¨ ᮢ¯ ¤ ¥â á § ¤ ­­ë¬?
mov AL,[FDC_ST0]
and AL,100b
shr AL,2
cmp AL,[FDD_Head]
jne @@Err
; Ž¯¥à æ¨ï § ¢¥à襭  ãᯥ譮
mov [FDC_Status],FDC_Normal
jmp @@Exit
@@Err: ; ’४ ­¥ ­ ©¤¥­
mov [FDC_Status],FDC_TrackNotFound
; mov [flp_status],0
@@Exit:
call save_timer_fdd_motor
popa
ret
 
;*******************************************************
;* —’…ˆ… ‘…Š’Ž€ „€›• *
;*  à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* ¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* ‚ á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï *
;* ᮤ¥à¦¨¬®¥ ᥪâ®à  ¡ã¤¥â § ­¥á¥­® ¢ FDD_DataBuffer. *
;*******************************************************
ReadSector:
pushad
call save_timer_fdd_motor
; “áâ ­®¢¨âì ᪮à®áâì ¯¥à¥¤ ç¨ 500 Š¡ ©â/á
mov AX,0
mov DX,03F7h
out DX,AL
; ˆ­¨æ¨ «¨§¨à®¢ âì ª ­ « ¯àאַ£® ¤®áâ㯠 ª ¯ ¬ïâ¨
mov [dmamode],0x46
call Init_FDC_DMA
; ®¤ âì ª®¬ ­¤ã "—⥭¨¥ ¤ ­­ëå"
mov AL,0E6h ;ç⥭¨¥ ¢ ¬ã«ìâ¨â४®¢®¬ ०¨¬¥
call FDCDataOutput
mov AL,[FDD_Head]
shl AL,2
call FDCDataOutput
mov AL,[FDD_Track]
call FDCDataOutput
mov AL,[FDD_Head]
call FDCDataOutput
mov AL,[FDD_Sector]
call FDCDataOutput
mov AL,2 ;ª®¤ à §¬¥à  ᥪâ®à  (512 ¡ ©â)
call FDCDataOutput
mov AL,18 ;+1; 3Fh ;ç¨á«® ᥪâ®à®¢ ­  ¤®à®¦ª¥
call FDCDataOutput
mov AL,1Bh ;§­ ç¥­¨¥ GPL
call FDCDataOutput
mov AL,0FFh ;§­ ç¥­¨¥ DTL
call FDCDataOutput
 
; Ž¦¨¤ ¥¬ ¯à¥à뢠­¨¥ ¯® § ¢¥à襭¨¨ ®¯¥à æ¨¨
call WaitFDCInterrupt
cmp [FDC_Status],FDC_Normal
jne @@Exit_1
; ‘ç¨â뢠¥¬ áâ âãá § ¢¥à襭¨ï ®¯¥à æ¨¨
call GetStatusInfo
test [FDC_ST0],11011000b
jnz @@Err_1
mov [FDC_Status],FDC_Normal
jmp @@Exit_1
@@Err_1: mov [FDC_Status],FDC_SectorNotFound
; mov [flp_status],0
@@Exit_1:
call save_timer_fdd_motor
popad
ret
 
;*******************************************************
;* —’…ˆ… ‘…Š’Ž€ (‘ Ž‚’Ž…ˆ…Œ Ž…€–ˆˆ ˆ ‘Ž…) *
;*  à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* ¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* ‚ á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï *
;* ᮤ¥à¦¨¬®¥ ᥪâ®à  ¡ã¤¥â § ­¥á¥­® ¢ FDD_DataBuffer. *
;*******************************************************
ReadSectWithRetr:
pusha
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ४ «¨¡à®¢ª¨
mov [RecalRepCounter],0
@@TryAgain:
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï
mov [ReadRepCounter],0
@@ReadSector_1:
call ReadSector
cmp [FDC_Status],0
je @@Exit_2
cmp [FDC_Status],1
je @@Err_3
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ç⥭¨ï
inc [ReadRepCounter]
cmp [ReadRepCounter],3
jb @@ReadSector_1
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ४ «¨¡à®¢ª¨
call RecalibrateFDD
call SeekTrack
inc [RecalRepCounter]
cmp [RecalRepCounter],3
jb @@TryAgain
; mov [flp_status],0
@@Exit_2:
popa
ret
@@Err_3:
mov [flp_status],0
popa
ret
 
;*******************************************************
;* ‡€ˆ‘œ ‘…Š’Ž€ „€›• *
;*  à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* ¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* ‚ á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ § ¯¨á¨ *
;* ᮤ¥à¦¨¬®¥ FDD_DataBuffer ¡ã¤¥â § ­¥á¥­® ¢ ᥪâ®à. *
;*******************************************************
WriteSector:
pushad
call save_timer_fdd_motor
; “áâ ­®¢¨âì ᪮à®áâì ¯¥à¥¤ ç¨ 500 Š¡ ©â/á
mov AX,0
mov DX,03F7h
out DX,AL
; ˆ­¨æ¨ «¨§¨à®¢ âì ª ­ « ¯àאַ£® ¤®áâ㯠 ª ¯ ¬ïâ¨
mov [dmamode],0x4A
call Init_FDC_DMA
; ®¤ âì ª®¬ ­¤ã "‡ ¯¨áì ¤ ­­ëå"
mov AL,0xC5 ;0x45 ;§ ¯¨áì ¢ ¬ã«ìâ¨â४®¢®¬ ०¨¬¥
call FDCDataOutput
mov AL,[FDD_Head]
shl AL,2
call FDCDataOutput
mov AL,[FDD_Track]
call FDCDataOutput
mov AL,[FDD_Head]
call FDCDataOutput
mov AL,[FDD_Sector]
call FDCDataOutput
mov AL,2 ;ª®¤ à §¬¥à  ᥪâ®à  (512 ¡ ©â)
call FDCDataOutput
mov AL,18; 3Fh ;ç¨á«® ᥪâ®à®¢ ­  ¤®à®¦ª¥
call FDCDataOutput
mov AL,1Bh ;§­ ç¥­¨¥ GPL
call FDCDataOutput
mov AL,0FFh ;§­ ç¥­¨¥ DTL
call FDCDataOutput
 
; Ž¦¨¤ ¥¬ ¯à¥à뢠­¨¥ ¯® § ¢¥à襭¨¨ ®¯¥à æ¨¨
call WaitFDCInterrupt
cmp [FDC_Status],FDC_Normal
jne @@Exit_3
; ‘ç¨â뢠¥¬ áâ âãá § ¢¥à襭¨ï ®¯¥à æ¨¨
call GetStatusInfo
test [FDC_ST0],11000000b ;11011000b
jnz @@Err_2
mov [FDC_Status],FDC_Normal
jmp @@Exit_3
@@Err_2: mov [FDC_Status],FDC_SectorNotFound
@@Exit_3:
call save_timer_fdd_motor
popad
ret
 
;*******************************************************
;* ‡€ˆ‘œ ‘…Š’Ž€ (‘ Ž‚’Ž…ˆ…Œ Ž…€–ˆˆ ˆ ‘Ž…) *
;*  à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* ¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* ‚ á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ § ¯¨á¨ *
;* ᮤ¥à¦¨¬®¥ FDD_DataBuffer ¡ã¤¥â § ­¥á¥­® ¢ ᥪâ®à. *
;*******************************************************
WriteSectWithRetr:
pusha
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ४ «¨¡à®¢ª¨
mov [RecalRepCounter],0
@@TryAgain_1:
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï
mov [ReadRepCounter],0
@@WriteSector_1:
call WriteSector
cmp [FDC_Status],0
je @@Exit_4
cmp [FDC_Status],1
je @@Err_4
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ç⥭¨ï
inc [ReadRepCounter]
cmp [ReadRepCounter],3
jb @@WriteSector_1
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ४ «¨¡à®¢ª¨
call RecalibrateFDD
call SeekTrack
inc [RecalRepCounter]
cmp [RecalRepCounter],3
jb @@TryAgain_1
@@Exit_4:
popa
ret
@@Err_4:
mov [flp_status],0
popa
ret
 
;*********************************************
;* Ž‹“—ˆ’œ ˆ”ŽŒ€–ˆž Ž …‡“‹œ’€’… Ž…€–ˆˆ *
;*********************************************
GetStatusInfo:
push AX
call FDCDataInput
mov [FDC_ST0],AL
call FDCDataInput
mov [FDC_ST1],AL
call FDCDataInput
mov [FDC_ST2],AL
call FDCDataInput
mov [FDC_C],AL
call FDCDataInput
mov [FDC_H],AL
call FDCDataInput
mov [FDC_R],AL
call FDCDataInput
mov [FDC_N],AL
pop AX
ret
 
/trunk/blkdev/rd.inc
0,0 → 1,446
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; RAMDISK functions ;;
;; (C) 2004 Ville Turjanmaa, License: GPL ;;
;; Addings by M.Lisovin ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
ramdisk_free_space:
;---------------------------------------------
;
; returns free space in edi
; rewr.by Mihasik
;---------------------------------------------
 
push eax ebx ecx
 
mov edi,0x280000 ;start of FAT
xor ax,ax ;Free cluster=0x0000 in FAT
xor ebx,ebx ;counter
mov ecx,2847 ;2849 ;2849 clusters
cld
rdfs1:
repne scasw
jnz rdfs2 ;if last cluster not 0
inc ebx
jcxz rdfs2 ;if last cluster=0
jmp rdfs1 ;if not last
rdfs2:
shl ebx,9 ;free clusters*512
mov edi,ebx
pop ecx ebx eax
ret
 
 
expand_filename:
;---------------------------------------------
;
; exapand filename with '.' to 11 character
; eax - pointer to filename
;---------------------------------------------
 
push esi edi ebx
 
mov edi,esp ; check for '.' in the name
add edi,12+8
 
mov esi,eax
 
mov eax,edi
mov [eax+0],dword ' '
mov [eax+4],dword ' '
mov [eax+8],dword ' '
 
flr1:
 
cmp [esi],byte '.'
jne flr2
mov edi,eax
add edi,7
jmp flr3
 
flr2:
 
mov bl,[esi]
mov [edi],bl
 
flr3:
 
inc esi
inc edi
 
mov ebx,eax
add ebx,11
 
cmp edi,ebx
jbe flr1
 
pop ebx edi esi
ret
 
fileread:
;----------------------------------------------------------------
;
; fileread - sys floppy
;
; eax points to filename 11 chars
; ebx first wanted block ; 1+ ; if 0 then set to 1
; ecx number of blocks to read ; 1+ ; if 0 then set to 1
; edx mem location to return data
; esi length of filename 12*X 0=root
;
; ret ebx = size or 0xffffffff file not found
; eax = 0 ok read or other = errormsg
;
;--------------------------------------------------------------
test ebx,ebx ;if ebx=0 - set to 1
jnz frfl5
inc ebx
frfl5:
test ecx,ecx ;if ecx=0 - set to 1
jnz frfl6
inc ecx
frfl6:
test esi,esi ; return ramdisk root
jnz fr_noroot ;if not root
cmp ebx,14 ;14 clusters=root dir
ja oorr
cmp ecx,14
ja oorr
jmp fr_do
oorr:
mov eax,5 ;out of root range (fnf)
xor ebx,ebx
dec ebx ;0xffffffff
ret
 
fr_do: ;reading rootdir
mov edi,edx
dec ebx
push edx
mov edx,ecx
add edx,ebx
cmp edx,14 ;ebx+ecx=14
pushf
jbe fr_do1
sub edx,14
sub ecx,edx
fr_do1:
shl ebx,9
mov esi,0x100000+512*19
add esi,ebx
shl ecx,7
cld
rep movsd
popf
pop edx
; jae fr_do2
xor eax,eax ; ok read
xor ebx,ebx
ret
fr_do2: ;if last cluster
mov eax,6 ;end of file
xor ebx,ebx
ret
 
fr_noroot:
 
sub esp,32
call expand_filename
 
dec ebx
 
push eax
 
push eax ebx ecx edx esi edi
call rd_findfile
je fifound
add esp,32+28 ;if file not found
ret
 
fifound:
 
mov ebx,[edi-11+28] ;file size
mov [esp+20],ebx
mov [esp+24],ebx
add edi,0xf
movzx eax,word [edi]
mov edi,eax ;edi=cluster
 
frnew:
 
add eax,31 ;bootsector+2*fat+filenames
shl eax,9 ;*512
add eax,0x100000 ;image base
mov ebx,[esp+8]
mov ecx,512 ;[esp+4]
 
cmp [esp+16],dword 0 ; wanted cluster ?
jne frfl7
call memmove
add [esp+8],dword 512
dec dword [esp+12] ; last wanted cluster ?
cmp [esp+12],dword 0
je frnoread
jmp frfl8
frfl7:
dec dword [esp+16]
frfl8:
shl edi,1 ;find next cluster from FAT
add edi,0x280000
movzx eax,word [edi]
mov edi,eax
cmp edi,4095 ;eof - cluster
jz frnoread2
 
cmp [esp+24],dword 512 ;eof - size
jb frnoread
sub [esp+24],dword 512
 
jmp frnew
 
frnoread2:
 
cmp [esp+16],dword 0 ; eof without read ?
je frnoread
 
pop edi esi edx ecx
add esp,4
pop ebx ; ebx <- eax : size of file
add esp,36
mov eax,6 ; end of file
ret
 
frnoread:
 
pop edi esi edx ecx
add esp,4
pop ebx ; ebx <- eax : size of file
add esp,36
xor eax,eax ;read ok
ret
 
filedelete:
;--------------------------------------------
;
; filedelete - sys floppy
; in:
; eax - pointer to filename 11 chars
;
; out:
; eax - 0 = successful, 5 = file not found
;
;--------------------------------------------
 
sub esp,32
call expand_filename
 
push eax ebx ecx edx esi edi
call rd_findfile
je fifoundd
pop edi esi edx ecx ebx eax ;file not found
add esp,32
mov eax,5
ret
 
fifoundd:
 
mov [edi-11],byte 0xE5 ;mark filename deleted
add edi,0xf
movzx eax,word [edi]
mov edi,eax ;edi = cluster
 
frnewd:
 
shl edi,1 ;find next cluster from FAT
add edi,0x280000
movzx eax,word [edi]
mov [edi],word 0x0 ;clear fat chain cluster
mov edi,eax
cmp edi,dword 0xff8 ;last cluster ?
jb frnewd
 
pop edi esi edx ecx ebx eax
add esp,32
xor eax,eax ; file found
ret
 
 
filesave:
;----------------------------------------------------------
;
; filesave - sys floppy
;
; eax points to filename 11 chars
;
; eax ; pointer to file name
; ebx ; buffer
; ecx ; count to write in bytes
; edx ; 0 create new , 1 append
;
;-----------------------------------------------------------
 
sub esp,32
call expand_filename
test edx,edx
jnz fsdel
pusha
call filedelete
popa
 
fsdel:
 
call ramdisk_free_space
cmp ecx,edi
jbe rd_do_save
add esp,32
mov eax,8 ;disk full
ret
 
rd_do_save:
 
push eax ebx ecx edx esi edi
 
mov edi,0x100000+512*18+512 ;Point at directory
mov edx,224 +1
; find an empty spot for filename in the root dir
l20ds:
dec edx
test edx,edx
jz frnoreadds
l21ds:
cmp [edi],byte 0xE5
jz fifoundds
cmp [edi],byte 0x0
jz fifoundds
add edi,32 ; Advance to next entry
jmp l20ds
fifoundds:
 
push edi ; move the filename to root dir
mov esi,[esp+4+20]
mov ecx,11
cld
rep movsb
pop edi
mov edx,edi
add edx,11+0xf ; edx <- cluster save position
mov ebx,[esp+12] ; save file size
mov [edi+28],ebx
mov [edi+11],byte 0x20 ; attribute
; Ivan Poddubny 11/12/2003:
call get_date_for_file ; from FAT32.INC
mov [edi+24],ax ; date
call get_time_for_file ; from FAT32.INC
mov [edi+22],ax ; time
; End
mov edi,0x280000 ;pointer to first cluster
mov ecx,2849
cld
frnewds:
xor ax,ax
repne scasw
mov ebx,2848
sub ebx,ecx
mov [edx],bx ; save next cluster pos. to prev cl.
mov edx,edi ; next save pos abs mem add
dec edx
dec edx
call fdc_filesave
pusha ; move save to floppy cluster
add ebx,31
shl ebx,9
add ebx,0x100000
mov eax,[esp+32+16]
mov ecx,512
call memmove
popa
 
mov eax,[esp+12]
cmp eax,512
jb flnsa
sub eax,512
mov [esp+12],eax
mov eax,[esp+16]
add eax,512
mov [esp+16],eax
jmp frnewds
 
flnsa:
dec edi
dec edi
mov [edi],word 4095 ; mark end of file - last cluster
 
frnoreadds:
 
pop edi esi edx ecx ebx eax
add esp,32
 
pusha
cli
call fdc_commitfile
sti
popa
 
xor eax,eax ;ok write
ret
 
rd_findfile:
;by Mihasik
;IN: eax - pointer to filename OUT: filestring+11 in edi or notZero in flags and fnf in eax,ebx
 
mov edi,0x100000+512*18+512 ;Point at directory
cld
rd_newsearch:
mov esi,eax
mov ecx,11
rep cmpsb
je rd_ff
add cl,21
add edi,ecx
cmp edi,0x100000+512*33
jb rd_newsearch
mov eax,5 ;if file not found - eax=5
xor ebx,ebx
dec ebx ;ebx=0xffffffff and zf=0
rd_ff:
ret
 
rd_getfileinfo:
;get date, time, size or attributes of file
;IN: eax - pointer to file, ebx - type of function: 12-get filesize, 13-get fileattr, 14-get filedate
;ecx - filelengh 0=root
;OUT: eax=0 - Ok or 5 - file not found ebx - date/time, size or attributes
test ecx,ecx
jnz no_getfinfo_root
mov eax,5 ;if root - fnf
xor ebx,ebx
dec ebx
ret
no_getfinfo_root: ;if not root
sub esp,32
call expand_filename
call rd_findfile
je fifoundi
add esp,32 ;if file not found
ret
fifoundi:
cmp ebx,13
jne no_rd_attr
movzx ebx,byte [edi] ;get attributes
jmp rd_getfileinfo_end
no_rd_attr:
cmp ebx,14
jne no_rd_date
mov ebx,dword [edi+11] ;get date/time
jmp rd_getfileinfo_end
no_rd_date:
mov ebx,dword [edi+17] ;get size
rd_getfileinfo_end:
xor eax,eax
add esp,32
ret
/trunk/blkdev/rdsave.inc
0,0 → 1,26
cmp eax,6 ; SAVE FLOPPY IMAGE (HD version only)
jnz nosaveimage
cmp ebx,1
jnz img_save_hd_1
mov edx,bootpath ; path = '/KOLIBRI '
jmp img_save_hd_3
img_save_hd_1:
cmp ebx,2
jnz img_save_hd_2
mov edx,bootpath2 ; path = 0 (root dir)
jmp img_save_hd_3
img_save_hd_2:
cmp ebx,3
jnz exit_for_anyone
mov edx,[3010h]
mov edx,[edx+10h]
add edx,ecx
img_save_hd_3:
call restorefatchain ; restore FAT !!!
mov eax,image_save
mov ebx,1440*1024 ; size 1440 Kb
mov ecx,0x100000 ; address of image
call file_write
ret
 
nosaveimage: