⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sector.asm

📁 功能强大的磁盘维护工具
💻 ASM
📖 第 1 页 / 共 3 页
字号:
extern HighLight:far,GetKey:far,HideCursor:far,ShowCursor:far,GetCursor:far		;From Common
extern _CurDisk:byte,_MaxCylin:word,_MaxHead:word,_SectPerTrack:word,DiskBuffer:byte	;From Main
extern Dap:byte,DapOffset:word,DapSegment:word,DapBlockNumLL:word,DapBlockNumLH:word	;From Main
extern MenuBar:byte,State_Red:byte,State_Black:byte	;From Main
extern _HeadLineCode:byte,_DriveSign:byte,_TempDwordH:word,_TempDwordL:word	;From Main
extern CHSBuffer:byte,_TempCylin:word,_TempHead:word,_TempSector:word,DiskSize:byte		;From Info
extern State_ROnly:far		;From Info
public WarningTitle,ConOKSel,OffsetBuffer1,HexBuffer1,ErrorTitle
public SinSector,MulSector,CMOS

include	MACRO.ASM

.model small
.stack
.data
	OffsetBuffer1 byte 16 dup(30h,00h,00h,30h,3ah)
	OffsetBuffer2 byte 16 dup(30h,00h,00h,30h,3ah)
	TempBuffer1 byte 256 dup(0)
	TempBuffer2 byte 256 dup(0)
	HexBuffer1 byte 16 dup(23 dup(0),2dh,24 dup(0))
	HexBuffer2 byte 16 dup(23 dup(0),2dh,24 dup(0))
	AsciiBuffer1 byte 256 dup(0)
	AsciiBuffer2 byte 256 dup(0)
	EnterBuffer byte 27 dup(0),0
	TempCHSBuffer byte 6 dup(0)

	HeadLineMBR byte 0b3h," Master Boot Record ",0b3h,"$"
	HeadLineDBR byte 0b3h," DOS Boot Record ",0b3h,"$"
	HeadLineDPT byte 0b3h," Drive Partition Table Of ",00h,": ",0b3h,"$"
	HeadLineBoot byte 0b3h," Boot Record Of ",00h,": ",0b3h,"$"
	HeadLineRandom byte 0b3h," Random Physical Sector ",0b3h,"$"
	HeadLineCMOS byte 0b3h," CMOS Data ",0b3h,"$"
	WarningTitle byte "Warning","$"
	WarningModifyMsg byte "Data Have Been Changed! Save?","$"
	WarningOverWriteMsg byte "File Exists, Overwrite?","$"
	ConYes byte "  Yes  ","$"
	ConYesSel byte 10h," Yes ",11h,"$"
	ConNo byte "  No  ","$"
	ConNoSel byte	10h," No ",11h,"$"
	SaveTitle byte "Save To File","$"
	LoadTitle byte "Load From File","$"
	FileName byte "File Name:","$"
	DefaultNameMBR byte "MBR.dat","$"
	DefaultNameDBR byte "DBR.dat","$"
	DefaultNameDPT byte "DPT_",00,".dat","$"
	DefaultNameBoot byte "Boot_",00,".dat","$"
	DefaultNameRandom byte "Sector.dat","$"
	DefaultCMOS byte "CMOS.dat","$"
	BcdChs byte " Cylin: 00000  Head: 000  Sector: 00 ","$"
        BcdLbaSect byte " LBASector: 000000000 ","$"
	ChangeTitle byte " Change Parameters ","$"
	ChangeCylin byte " Cylinder: ","$"
	ChangeHead byte " Head: ","$"
	ChangeSector byte " Sector: ","$"
	ErrorTitle byte "Error","$"
	ErrorReadMsg byte "Reading Sector Error !","$"
	ErrorWriteMsg byte "Writing Sector Error !","$"
	ErrorCreatFileMsg byte "Invalid File Name !","$"
	ErrorWriteFileMsg byte "Writing File Error !","$"
	ErrorOpenFileMsg byte "File Not Found !","$"
	ErrorReadFileMsg byte "Reading File Error !","$"
	ConOKSel byte 10h," OK ",11h,"$"
	TextYes byte "Yes","$"
	TextNo byte "No","$"
	TextFAT16 byte "FAT16","$"
	TextFAT32 byte "FAT32","$"
	TextFAT16E byte "FAT16-Ext","$"
	TextFAT32E byte "FAT32-Ext","$"
	TextUnused byte "Unused","$"
	TextUnknown byte "Unknown","$"
	TextPartHeader byte "Part-1     Part-2     Part-3     Part-4","$"
	TextPartBootState byte "Boot State","$"
	TextPartType byte "Partition Type","$"
	TextPartBCylin byte "Beginning Cylin","$"
	TextPartBHead byte "Beginning Head","$"
	TextPartBSector byte "Beginning Sector","$"
	TextPartECylin byte "Ending Cylin","$"
	TextPartEHead byte "Ending Head","$"
	TextPartESector byte "Ending Sector","$"
	TextPartBootSector byte "Boot Sector","$"
	TextPartTSectors byte "Total Sectors","$"
	TextBootUnused byte "(Unused)","$"
	TextBootOEMID byte "OEM ID :","$"
	TextBootSectSize byte "Sector Size :","$"
	TextBootSPCluster byte "Sectors per Cluster :","$"
	TextBootResSectors byte "Reserved Sectors :","$"
	TextBootFATCopies byte "FAT Copies :","$"
	TextBootRoot byte "Root Directory FDB :","$"
	TextBootTSectors byte "Total Sectors :","$"
	TextBootMedia byte "Media Descriptor :","$"
	TextBootSPFAT byte "Sectors per FAT :","$"
	TextBootSPTrack byte "Sectors per Track :","$"
	TextBootHeads byte "Heads :","$"
	TextBootHSectors byte "Hidden Sectors :","$"
	TextBootBTSectors byte "Big Total Sectors :","$"
	TextBootDiskNum byte "Disk Number :","$"
	TextBootEBRS byte "Extend Boot Record :","$"
	TextBootVSNum byte "Volume ID Number :","$"
	TextBootVLabel byte "Volume Label :","$"
	TextBootFSType byte "File System Type :","$"
	TextBootBSPFAT byte "Big Sectors per FAT :","$"
	TextBootESign byte "Extend Sign :","$"
	TextBootFSVer byte "File System Version :","$"
	TextBootCORoot byte "Clusters of Root :","$"
	TextBootFSSect byte "File System Sector :","$"
	TextBootBSect byte "Boot Sectors :","$"

	_OffsetBuffer word 0
	_HexBuffer word 0
	_AsciiBuffer word 0
	_CurCylin word 0
	_CurHead word 0
	_CurSector word 0
	_CurX byte 0
	_CurY byte 0
	_TempWord word 0
	_TempByte equ byte ptr _TempWord
	_FuncSign byte 0
	_FileHandle word 0
	_DialogSign byte 0
	b_Single byte TRUE
	b_2ndPage byte FALSE
	b_Modify byte FALSE
	b_SelectFalse byte FALSE
	b_SaveFile byte FALSE

.code
.startup

SinSector proc far
	mov ax,@data
	mov es,ax

	mov _FuncSign,00h
	Call IntialSect
	Call State_Sin

;===[ 窗口名字 ]
	.if _HeadLineCode==00h
	ShowString_DOS HeadLineMBR,29,3	
	.elseif _HeadLineCode==10h
	ShowString_DOS HeadLineDBR,30,3
	.elseif _HeadLineCode==01h
	mov di,offset HeadLineDPT
	mov si,offset DefaultNameDPT
	mov al,_DriveSign
	mov [di+27],al
	mov [si+4],al
	ShowString_DOS HeadLineDPT,24,3
	.else
	mov di,offset HeadLineBoot
	mov si,offset DefaultNameBoot
	mov al,_DriveSign
	mov [di+17],al
	mov [si+5],al
	ShowString_DOS HeadLineBoot,30,3
	.endif

	Call ReadSector
	Call ConvertBuffer
	Call DisplayBuffer
	Call DisplayPara

;---[ 按键检测 ]
SectKeyCheck:
        Call GetKey
	.if al==1bh
        jmp Exit
        .elseif al==0
                Call GetKey
                .if al==49h		;PageUp
                Call PgUp_Sin
                .elseif al==51h		;PageDown
                Call PgDn_Sin
		.elseif al==3bh && _HeadLineCode<10h		;F1
		Call TextPart
		.elseif al==3bh && _HeadLineCode>=10h
		Call TextBoot
                .elseif al==3dh		;F3
                Call Edit
		.elseif al==42h		;F8
		mov b_SaveFile,TRUE
		Call S_LFile
		.elseif al==43h		;F9
		mov b_SaveFile,FALSE
		Call S_LFile
                .endif
        .endif
        jmp SectKeyCheck

Exit:	
	ret
SinSector endp


MulSector proc far
	mov ax,@data
	mov es,ax

	mov _FuncSign,01h
	Call IntialSect
	Call State_Mul
	ShowString_DOS HeadLineRandom,27,3

	mov _CurCylin,0
	mov _CurHead,1
	mov _CurSector,1
	Call ReadSector
	Call ConvertBuffer
	Call DisplayBuffer
	Call DisplayPara

SectKeyCheck:
        Call GetKey
	.if al==1bh
        jmp Exit
        .elseif al==0
                Call GetKey
                .if al==49h		;PageUp
                Call PgUp_Mul
                .elseif al==51h		;PageDown
                Call PgDn_Mul
                .elseif al==3dh		;F3
                Call Edit
		.elseif al==3eh		;F4
		Call ChangeCHS
		.elseif al==42h		;F8
		mov b_SaveFile,TRUE
		Call S_LFile
		.elseif al==43h		;F9
		mov b_SaveFile,FALSE
		Call S_LFile
                .endif
        .endif
        jmp SectKeyCheck

Exit:	
	ret
MulSector endp


CMOS proc far
	mov ax,@data
	mov es,ax

	mov _FuncSign,10h
	Call IntialSect
	Call State_CMOS
	ShowString_DOS HeadLineCMOS,33,3

	Call ReadCMOS
	Call ConvertBuffer
	Call DisplayBuffer

CMOSKeyCheck:
        Call GetKey
	.if al==1bh
        jmp Exit
        .elseif al==0
                Call GetKey
                .if al==3dh		;F3
                Call Edit
		.elseif al==42h		;F8
		mov b_SaveFile,TRUE
		Call S_LFile
		.elseif al==43h		;F9
		mov b_SaveFile,FALSE
		Call S_LFile
                .endif
        .endif
        jmp CMOSKeyCheck
	

Exit:	
	ret
CMOS endp


IntialSect proc near	;===[ 初始化 ]
;---[ 生成偏移序列 ]---
	xor bx,bx
	mov di,offset OffsetBuffer1
	inc di
	mov cx,20h

MakeOffsetList:
	push cx
	HexByte2Ascii bl,[di],[di+1]
	pop cx
	inc bx
	add di,5
	loop MakeOffsetList

;---[ 初始化变量 ]---
	mov _OffsetBuffer,offset OffsetBuffer1
	mov _HexBuffer,offset HexBuffer1
	mov _AsciiBuffer,offset AsciiBuffer1
	mov b_2ndPage,FALSE

;---[ 初始化界面 ]---
	Call HideCursor
	OpenWin 0,1,79,1,70h		;菜单条
	ShowString_DOS MenuBar,3,1
	GotoXY 0,2			;背景
	MulShowCharA 0b1h,9fh,1760
	OpenWin 3,4,78,21,00h		;窗口阴影
	OpenWin 2,3,77,20,9eh		;显示窗口
	DRectangle 2,3,77,20
	ret
IntialSect endp


ReadSector proc near
Read:

	.if _FuncSign==00h
	ClearArr DapBlockNumLL,4
	EMov DapBlockNumLH,DapBlockNumLL,_TempDwordH,_TempDwordL
	.else
	ClearArr DapBlockNumLL,4
	EMul 0,_CurCylin,_MaxHead,DapBlockNumLH,DapBlockNumLL
	ClearArr _TempDwordL,2
	mov ax,_CurHead
	mov _TempDwordL,ax
	EAdd DapBlockNumLH,DapBlockNumLL,_TempDwordH,_TempDwordL
	EMul DapBlockNumLH,DapBlockNumLL,_SectPerTrack,DapBlockNumLH,DapBlockNumLL
	ClearArr _TempDwordL,2
	mov ax,_CurSector
	dec ax
	mov _TempDwordL,ax
	EAdd DapBlockNumLH,DapBlockNumLL,_TempDwordH,_TempDwordL
	.endif

	EInt13 42h,DiskBuffer
	.if Carry?
	mov _DialogSign,22h
	mov b_SelectFalse,FALSE
	Call Dialog
	ret
	.endif

	mov di,offset TempBuffer1
	mov si,offset DiskBuffer
	mov cx,512
	cld
	rep movsb
	ret
ReadSector endp


WriteSector proc near
Write:
	EInt13 43h,TempBuffer1
	.if Carry?
	mov _DialogSign,23h
	mov b_SelectFalse,FALSE
	Call Dialog
	.endif
	ret
WriteSector endp


ReadCMOS proc near
	ClearArr DiskBuffer,128
	xor bx,bx
	mov di,offset DiskBuffer
	mov cx,128

LpRead:
	mov al,bl
	out 70h,al
	in al,71h
	mov [di],al
	inc bx
	inc di
	loop LpRead

	mov di,offset TempBuffer1
	mov si,offset DiskBuffer
	mov cx,128
	cld
	rep movsb

	ret
ReadCMOS endp


WriteCMOS proc near
	xor bx,bx
	mov di,offset TempBuffer1
	mov cx,128

LpWrite:
	mov al,bl
	out 70h,al
	mov al,[di]
	out 71h,al
	inc bx
	inc di
	loop LpWrite
	ret
WriteCMOS endp


State proc near
	.if _FuncSign==00h
	Call State_Sin
	.elseif _FuncSign==01h
	Call State_Mul
	.else
	Call State_CMOS
	.endif
	ret
State endp


State_Sin proc near	;===[ Single状态栏 ]
        OpenWin 0,24,79,24,0f0h
        mov bp,offset State_Red
        ShowString_BIOS 3,2,24,0fch	;ESC
        add bp,14
        ShowString_BIOS 2,12,24,0fch    ;F1
        add bp,2
        ShowString_BIOS 2,21,24,0fch    ;F3
	add bp,6
        ShowString_BIOS 2,30,24,0fch    ;F8
	MulShowCharA "/",0f0h,1		;/
	add bp,2
        ShowString_BIOS 2,33,24,0fch    ;F9
        .if b_2ndPage
        add bp,2
        ShowString_BIOS 4,52,24,0fch    ;PgUp
        .else
	add bp,6
        ShowString_BIOS 4,52,24,0fch    ;PgDn
        .endif
        mov bp,offset State_Black
        add bp,5
        ShowString_BIOS 5,5,24,0f0h	;=Exit
        add bp,74
        ShowString_BIOS 5,14,24,0f0h    ;=Text
        sub bp,55
        ShowString_BIOS 5,23,24,0f0h    ;=Edit
	add bp,15
        ShowString_BIOS 15,35,24,0f0h   ;=Save/Load File
        .if b_2ndPage
        add bp,15
        ShowString_BIOS 5,56,24,0f0h    ;=Back
	add bp,9
        ShowString_BIOS 4,61,24,0f0h    ;+ward
        .else
        GotoXY 56,24
	MulShowCharA "=",0f0h,1		;=
        add bp,21
        ShowString_BIOS 7,57,24,0f0h    ;+Forward
        .endif
	ret
State_Sin endp


State_Mul proc near	;===[ Multi状态栏 ]
        OpenWin 0,24,79,24,0f0h
        mov bp,offset State_Red
        ShowString_BIOS 3,2,24,0fch	;ESC
        add bp,16
        ShowString_BIOS 2,12,24,0fch	;F3
	add bp,2
	ShowString_BIOS 2,21,24,0fch	;F4
	add bp,4
	ShowString_BIOS 2,35,24,0fch	;F8
	MulShowCharA "/",0f0h,1		;/
	add bp,2
	ShowString_BIOS 2,38,24,0fch	;F9
	add bp,2
        ShowString_BIOS 4,57,24,0fch	;PgUp
	MulShowCharA "/",0f0h,1		;/
	add bp,4
	ShowString_BIOS 4,62,24,0fch	;PgDn
        mov bp,offset State_Black
        add bp,5
        ShowString_BIOS 5,5,24,0f0h	;=Exit
        add bp,19
        ShowString_BIOS 5,14,24,0f0h	;=Edit
	add bp,5
	ShowString_BIOS 10,23,24,0f0h	;=ChangeCHS
	add bp,10
	ShowString_BIOS 15,40,24,0f0h	;=Save/Load File
	add bp,15
        ShowString_BIOS 13,66,24,0f0h	;=Back/Forward
	ret
State_Mul endp


State_CMOS proc near
        OpenWin 0,24,79,24,0f0h
        mov bp,offset State_Red
        ShowString_BIOS 3,2,24,0fch	;ESC
        add bp,16
        ShowString_BIOS 2,12,24,0fch	;F3
	add bp,6
	ShowString_BIOS 2,21,24,0fch	;F8
	MulShowCharA "/",0f0h,1		;/
	add bp,2
	ShowString_BIOS 2,24,24,0fch	;F9
        mov bp,offset State_Black
        add bp,5
        ShowString_BIOS 5,5,24,0f0h	;=Exit
        add bp,19
        ShowString_BIOS 5,14,24,0f0h	;=Edit
	add bp,15
	ShowString_BIOS 15,26,24,0f0h	;=Save/Load File
	ret
State_CMOS endp


State_Edit proc near	;===[ 编辑状态栏 ]
        OpenWin 0,24,79,24,0f0h
        mov bp,offset State_Red
        ShowString_BIOS 3,2,24,0fch	;ESC
        add bp,8
        ShowString_BIOS 4,12,24,0fch	;↑↓←→
        add bp,12
        ShowString_BIOS 2,23,24,0fch	;F5
        mov bp,offset State_Black
        add bp,5
        ShowString_BIOS 5,5,24,0f0h	;=Exit
        add bp,62
        ShowString_BIOS 5,16,24,0f0h	;=Move
	sub bp,28
	ShowString_BIOS 5,25,24,0f0h	;=Save
	ret
State_Edit endp


ConvertBuffer proc near		;===[ 对DiskBuffer的内容进行处理 ]
;---[ 把ASCII码序列转为十六进制数序列 ]===
        mov bx,offset DiskBuffer
        mov bp,offset HexBuffer1
        xor di,di
        xor si,si
        mov cx,200h

ConvertHex:
        push cx
        HexByte2Ascii [bx+di],[bp+si],[bp+si+1]
        pop cx
        inc di
        add si,3
        loop ConvertHex

;---[ 过滤ASCII码 ]---
        mov bx,offset DiskBuffer
        mov bp,offset AsciiBuffer1
	xor di,di
        mov cx,200h

FilterAscii:
        mov al,[bx+di]
        .if al==07h || al==08h || al==0ah || al==0bh || al==0dh
        mov al,2eh
        .endif
        mov [bp+di],al
        inc di
        loop FilterAscii

	ret
ConvertBuffer endp


ChangeCHS proc near
	OpenWin 26,8,55,16,00h
	OpenWin 25,7,54,15,0b0h	
	DRectangle 25,7,54,15
	OpenWin 25,7,54,7,0f4h
	OpenWin 42,9,46,9,0fh
	OpenWin 42,11,46,11,0fh
	OpenWin 42,13,46,13,0fh
	ShowString_DOS ChangeTitle,31,7
	ShowString_DOS ChangeCylin,30,9
	ShowString_DOS ChangeHead,34,11
	ShowString_DOS ChangeSector,32,13
	Call ShowCursor
	mov _CurX,42
	mov _CurY,9
	mov si,offset TempCHSBuffer

InputStart:	
	GotoXY _CurX,_CurY
	xor cx,cx
	mov di,offset EnterBuffer

InputKeyCheck:
	Call GetKey
	.if al==1bh
	jmp ExitChange
	.elseif al==0dh && cl!=0
	jmp SaveInput
	.elseif al>=30h && al<=39h && cl!=5
	mov [di],al
	inc di
	ShowChar_DOS al
	inc cx
	.elseif al==08h && cl!=0
	ShowChar_DOS al
	push cx
	MulShowChar 0,1
	pop cx
	dec di
	dec cx
	.endif
	jmp InputKeyCheck

SaveInput:
	xor ax,ax
	mov bx,10
	mov di,offset Enterbuffer
ProMul:	
	push cx
	mul bx
	xor dx,dx
	mov dl,[di]
	sub dl,30h
	add ax,dx
	inc di
	pop cx
	loop ProMul

	.if (_CurY==9 && ax>_MaxCylin) || (_CurY==11 && ax>_MaxHead) || (_CurY==13 && (ax>_SectPerTrack || ax==0))
	GotoXY _CurX,_CurY
	MulShowChar 0,5
	jmp InputStart
	.endif

	mov word ptr [si],ax
	add si,2
	.if _CurY!=13
	add _CurY,2
	jmp InputStart
	.endif

	mov si,offset TempCHSBuffer
	mov ax,word ptr [si]
	mov _CurCylin,ax
	mov ax,word ptr [si+2]
	mov _CurHead,ax
	mov ax,word ptr [si+4]
	mov _CurSector,ax
	Call HideCursor
	Call ReadSector
	Call ConvertBuffer
	Call DisplayPara

ExitChange:
	Call DisplayBuffer
	Call HideCursor
	ret
ChangeCHS endp


DisplayBuffer proc near		;===[ 对DiskBuffer的内容进行显示 ]
;---[ 显示偏移序列 ]---
        mov bp,_OffsetBuffer
        mov cx,10h
        mov dh,4

DisplayOffsetList:
        push cx
        ShowString_BIOS 5,4,dh,9fh
        pop cx
        inc dh
        add bp,5
        loop DisplayOffsetList

;---[ 显示十六进制数序列 ]---
        mov bp,_HexBuffer
        mov cx,10h
        mov dh,4

DisplayHexCodes:
        push cx
        ShowString_BIOS 48,0bh,dh,9fh
        pop cx
        inc dh
        add bp,48
        loop DisplayHexCodes

;---[ 显示ASCII码序列 ]---
        mov bp,_AsciiBuffer
        mov cx,10h
        mov dh,4

DisplayAsciiCodes:
        push cx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -