Finish and Fix FAT Driver
This commit is contained in:
parent
473dac80f2
commit
ebaffb85ad
5
Makefile
5
Makefile
@ -18,11 +18,12 @@ floppy_image: $(BUILD_DIR)/main_floppy.img
|
||||
|
||||
$(BUILD_DIR)/main_floppy.img: bootloader kernel
|
||||
dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880
|
||||
mkfs.fat -F 12 -n "Nanite" $(BUILD_DIR)/main_floppy.img
|
||||
mkfs.fat -F 12 -n "NANITE" $(BUILD_DIR)/main_floppy.img
|
||||
dd if=$(BUILD_DIR)/stage1.bin of=$(BUILD_DIR)/main_floppy.img conv=notrunc
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/stage2.bin "::stage2.bin"
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin"
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img test.txt "::test.txt"
|
||||
mmd -i $(BUILD_DIR)/main_floppy.img "::misc"
|
||||
mcopy -i $(BUILD_DIR)/main_floppy.img test.txt "::misc/test.txt"
|
||||
|
||||
#
|
||||
# Bootloader
|
||||
|
||||
@ -19,8 +19,8 @@ isLittleEndian = TRUE
|
||||
DefaultAsmLines = 512
|
||||
DumpWSIndex = 0
|
||||
DockOrder = 0x123
|
||||
ListWidthPix[0] = 179
|
||||
ListWidthPix[1] = 248
|
||||
ListWidthPix[2] = 283
|
||||
MainWindow = 0, 0, 714, 500
|
||||
ListWidthPix[0] = 486
|
||||
ListWidthPix[1] = 667
|
||||
ListWidthPix[2] = 763
|
||||
MainWindow = 0, 0, 1280, 500
|
||||
FontName = Normal
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
BUILD_DIR?=build/
|
||||
ASM?=nasm
|
||||
ASMFLAGS?=-f obj
|
||||
CC16?=/opt/watcom/binl/wcc
|
||||
CC16?=/usr/bin/watcom/binl/wcc
|
||||
CFLAGS16?=-4 -d3 -s -wx -ms -zl -zq -za99 # -oneatxzh
|
||||
LD16?=/opt/watcom/binl/wlink
|
||||
LD16?=/usr/bin/watcom/binl/wlink
|
||||
|
||||
SOURCES_C=$(wildcard *.c)
|
||||
SOURCES_ASM=$(wildcard *.asm)
|
||||
@ -30,4 +30,4 @@ always:
|
||||
mkdir -p $(BUILD_DIR)/stage2/asm
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/stage2.bin
|
||||
rm -f $(BUILD_DIR)/stage2.bin
|
||||
@ -15,8 +15,8 @@ bool DISK_Initialize(DISK* disk, uint8_t driveNumber) {
|
||||
return false;
|
||||
|
||||
disk->id = driveNumber;
|
||||
disk->cylinders = cylinders;
|
||||
disk->heads = heads;
|
||||
disk->cylinders = cylinders + 1;
|
||||
disk->heads = heads + 1;
|
||||
disk->sectors = sectors;
|
||||
|
||||
return true;
|
||||
|
||||
@ -112,7 +112,7 @@ bool FAT_Initialize(DISK* disk) {
|
||||
g_Data->RootDirectory.Public.Position = 0;
|
||||
g_Data->RootDirectory.Public.Size = sizeof(FAT_DirectoryEntry) * g_Data->BS.BootSector.DirEntryCount;
|
||||
g_Data->RootDirectory.Opened = true;
|
||||
g_Data->RootDirectory.FirstCluster = 0;
|
||||
g_Data->RootDirectory.FirstCluster = rootDirLba;
|
||||
g_Data->RootDirectory.CurrentCluster = 0;
|
||||
g_Data->RootDirectory.CurrentSectorInCluster = 0;
|
||||
|
||||
@ -149,14 +149,14 @@ FAT_File far* FAT_OpenEntry(DISK* disk, FAT_DirectoryEntry* entry) {
|
||||
}
|
||||
|
||||
// setup vars
|
||||
FAT_FileData far* fd = &g_Data->OpenedFiles[handle];
|
||||
fd->Public.Handle = handle;
|
||||
fd->Public.IsDirectory = (entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) != 0;\
|
||||
fd->Public.Position = 0;
|
||||
fd->Public.Size = 0;
|
||||
fd->FirstCluster = entry->FirstClusterLow + ((uint32_t)entry->FirstClusterHigh << 16);
|
||||
fd->CurrentCluster = fd->FirstCluster;
|
||||
fd->CurrentSectorInCluster = 0;
|
||||
FAT_FileData far* fd = &g_Data->OpenedFiles[handle];
|
||||
fd->Public.Handle = handle;
|
||||
fd->Public.IsDirectory = (entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) != 0;
|
||||
fd->Public.Position = 0;
|
||||
fd->Public.Size = entry->Size;
|
||||
fd->FirstCluster = entry->FirstClusterLow + ((uint32_t)entry->FirstClusterHigh << 16);
|
||||
fd->CurrentCluster = fd->FirstCluster;
|
||||
fd->CurrentSectorInCluster = 0;
|
||||
|
||||
if (!DISK_ReadSectors(disk, FAT_ClusterToLba(fd->CurrentCluster), 1, fd->Buffer)) {
|
||||
printf("FAT: Read Error!\r\n");
|
||||
@ -170,9 +170,9 @@ FAT_File far* FAT_OpenEntry(DISK* disk, FAT_DirectoryEntry* entry) {
|
||||
uint32_t FAT_NextCluster(uint32_t currentCluster) {
|
||||
uint32_t fatIndex = currentCluster * 3 / 2;
|
||||
if (currentCluster % 2 == 0)
|
||||
return (*(uint16_t*)(g_Fat + fatIndex)) & 0x0FFF;
|
||||
return (*(uint16_t far*)(g_Fat + fatIndex)) & 0x0FFF;
|
||||
else
|
||||
return (*(uint16_t*)(g_Fat + fatIndex)) >> 4;
|
||||
return (*(uint16_t far*)(g_Fat + fatIndex)) >> 4;
|
||||
|
||||
}
|
||||
|
||||
@ -183,21 +183,21 @@ uint32_t FAT_Read(DISK* disk, FAT_File far* file, uint32_t byteCount, void* data
|
||||
: &g_Data->OpenedFiles[file->Handle];
|
||||
|
||||
uint8_t* u8DataOut = (uint8_t*)dataOut;
|
||||
|
||||
|
||||
// don't read past EOF
|
||||
byteCount = min(byteCount, fd->Public.Size - fd->Public.Position);
|
||||
|
||||
if (!fd->Public.IsDirectory)
|
||||
byteCount = min(byteCount, fd->Public.Size - fd->Public.Position);
|
||||
|
||||
while (byteCount > 0) {
|
||||
uint32_t leftInBuffer = SECTOR_SIZE - (fd->Public.Position % SECTOR_SIZE);
|
||||
uint32_t take = min(byteCount, leftInBuffer);
|
||||
|
||||
memcpy(u8DataOut, fd->Buffer + fd->Public.Position % SECTOR_SIZE, take);
|
||||
u8DataOut += take;
|
||||
fd->Public.Position += take;
|
||||
byteCount -= take;
|
||||
|
||||
// see if we need to read more data
|
||||
if (byteCount > 0) {
|
||||
if (leftInBuffer == take) {
|
||||
// root dir handler
|
||||
if (fd->Public.Handle == ROOT_DIRECTORY_HANDLE) {
|
||||
++fd->CurrentCluster;
|
||||
@ -215,7 +215,8 @@ uint32_t FAT_Read(DISK* disk, FAT_File far* file, uint32_t byteCount, void* data
|
||||
fd->CurrentCluster = FAT_NextCluster;
|
||||
}
|
||||
if (fd->CurrentCluster >= 0x0FF8) {
|
||||
printf("FAT: Read Error, Invalid Next Cluster!\r\n");
|
||||
// mark EOF
|
||||
fd->Public.Size = fd.Public.Position;
|
||||
break;
|
||||
|
||||
}
|
||||
@ -254,7 +255,7 @@ bool FAT_FindFile(DISK* disk, FAT_File far* file, const char* name, FAT_Director
|
||||
const char* ext = strchr(name, '.');
|
||||
if (ext == NULL)
|
||||
ext = name + 11;
|
||||
for (int i = 0; i < 8 && name + i < ext; i++)
|
||||
for (int i = 0; i < 8 && name[i] && name + i < ext; i++)
|
||||
fatName[i] = toupper(name[i]);
|
||||
if (ext != NULL) {
|
||||
for (int i = 0; i < 3 && ext[i + 1]; i++)
|
||||
|
||||
@ -48,4 +48,4 @@ bool FAT_Initialize(DISK* disk);
|
||||
FAT_File far* FAT_Open(DISK* disk, const char* path);
|
||||
uint32_t FAT_Read(DISK* disk, FAT_File far* file, uint32_t byteCount, void* dataOut);
|
||||
bool FAT_ReadEntry(DISK* disk, FAT_File far* file, FAT_DirectoryEntry* dirEntry);
|
||||
void FAT_Close(FAT_File far* file);
|
||||
void FAT_Close(FAT_File far* file);
|
||||
@ -8,35 +8,56 @@
|
||||
#include "disk.h"
|
||||
#include "fat.h"
|
||||
|
||||
void far* g_data = (void far*)0x00500200;
|
||||
#define LOGO " _ _____ _ __________________\r\n / | / / | / | / / _/_ __/ ____/\r\n / |/ / /| | / |/ // / / / / __/ \r\n / /| / ___ |/ /| // / / / / /___ \r\n\\/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \r\n"
|
||||
#define VERSION "v0.0.1"
|
||||
|
||||
void _cdecl cstart_(uint16_t bootDrive) {
|
||||
|
||||
printf("Loading NANITE %s\r\n\r\n", VERSION);
|
||||
|
||||
printf("%s", LOGO);
|
||||
printf(" %s\r\n--------------------------------------\r\n", VERSION);
|
||||
|
||||
printf("Initializing FAT Driver...");
|
||||
DISK disk;
|
||||
if (!DISK_Initialize(&disk, bootDrive)) {
|
||||
printf("Failed!\r\nDisk Init Error!");
|
||||
printf("Failed!\r\nDisk Initialization Error\r\n");
|
||||
goto end;
|
||||
}
|
||||
else {
|
||||
printf("Done!\r\n");
|
||||
}
|
||||
|
||||
// list files in root DIR
|
||||
printf("Listing Files in Root Directory...");
|
||||
DISK_ReadSectors(&disk, 19, 1, g_data);
|
||||
|
||||
if (!FAT_Initialize(&disk)) {
|
||||
printf("Failed!\r\nDisk Initialization Error\r\n");
|
||||
goto end;
|
||||
}
|
||||
printf("Done!\r\n");
|
||||
// printf("Listing Root DIR...\r\n");
|
||||
// // browse files in root
|
||||
FAT_File far* fd = FAT_Open(&disk, "/");
|
||||
FAT_DirectoryEntry entry;
|
||||
while (FAT_ReadEntry(&disk, fd, &entry)) {
|
||||
printf(" ");
|
||||
for (int i = 0; i < 11; i++)
|
||||
putc(entry.Name[i]);
|
||||
printf("\r\n");
|
||||
int i = 0;
|
||||
// while (FAT_ReadEntry(&disk, fd, &entry) && i++ < 5) {
|
||||
// printf(" ");
|
||||
// for (int i = 0; i < 11; i++)
|
||||
// putc(entry.Name[i]);
|
||||
// printf("\r\n");
|
||||
// }
|
||||
// FAT_Close(fd);
|
||||
|
||||
printf("Testing FAT Driver...");
|
||||
// read test.txt
|
||||
char buffer[100];
|
||||
uint32_t read;
|
||||
fd = FAT_Open(&disk, "misc/test.txt");
|
||||
while ((read = FAT_Read(&disk, fd, sizeof(buffer), buffer)))
|
||||
{
|
||||
for (uint32_t i = 0; i < read; i++)
|
||||
{
|
||||
if (buffer[i] == '\n')
|
||||
putc('\r');
|
||||
putc(buffer[i]);
|
||||
}
|
||||
}
|
||||
FAT_Close(fd);
|
||||
printf("Done!\r\n");
|
||||
|
||||
|
||||
end:
|
||||
for (;;);
|
||||
|
||||
@ -5,15 +5,15 @@
|
||||
\*----------------*/
|
||||
#pragma once
|
||||
|
||||
// 0x00000000 - 0x000003FF - int vector table
|
||||
// 0x00000400 - 0x000004FF - Bios Data
|
||||
// 0x00000000 - 0x000003FF - interrupt vector table
|
||||
// 0x00000400 - 0x000004FF - BIOS data area
|
||||
|
||||
#define MEMORY_MIN 0x00000500
|
||||
#define MEMORY_MAX 0x00080000
|
||||
|
||||
// 0x00000500 - 0x00010500 - FAT Driver
|
||||
#define MEMORY_FAT_ADDR ((void far*)0x00500000) // segment:offset SSSS:OOOO
|
||||
#define MEMORY_FAT_SIZE 0x00010500
|
||||
// 0x00000500 - 0x00010500 - FAT driver
|
||||
#define MEMORY_FAT_ADDR ((void far*)0x00500000) // segment:offset (SSSSOOOO)
|
||||
#define MEMORY_FAT_SIZE 0x00010000
|
||||
|
||||
// 0x00020000 - 0x00030000 - stage2
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\*----------------*/
|
||||
#include "memory.h"
|
||||
|
||||
int memcpy(void far* dst, const void far* src, uint16_t num) {
|
||||
void far* memcpy(void far* dst, const void far* src, uint16_t num) {
|
||||
uint8_t far* u8Dst = (uint8_t far *)dst;
|
||||
const uint8_t far* u8Src = (const uint8_t far *)src;
|
||||
|
||||
|
||||
@ -6,6 +6,6 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
int memcpy(void far* dst, const void far* src, uint16_t num);
|
||||
void far* memcpy(void far* dst, const void far* src, uint16_t num);
|
||||
void far* memset(void far* ptr, int value, uint16_t num);
|
||||
int memcmp(const void far* ptr1, const void far * ptr2, uint16_t num);
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed long int int32_t;
|
||||
typedef unsigned long int uint32_t;
|
||||
@ -16,8 +16,8 @@ typedef unsigned long long int uint64_t;
|
||||
|
||||
typedef uint8_t bool;
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
#define NULL ((void*)0)
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
@ -7,6 +7,7 @@ bits 16
|
||||
|
||||
section _TEXT class=CODE
|
||||
|
||||
|
||||
;
|
||||
; U4D
|
||||
;
|
||||
@ -36,93 +37,102 @@ __U4D:
|
||||
shr edx, 16
|
||||
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
; U4M
|
||||
;
|
||||
; Operation: Interger 4 Byte Multiplication
|
||||
; Inputs: DX;AX INT M1
|
||||
; CX;BX INT M2
|
||||
; Outputs: DX;AX Product
|
||||
; Volatile: CX;BX Destroyed
|
||||
; Operation: integer four byte multiply
|
||||
; Inputs: DX;AX integer M1
|
||||
; CX;BX integer M2
|
||||
; Outputs: DX;AX product
|
||||
; Volatile: CX, BX destroyed
|
||||
;
|
||||
global __U4M
|
||||
__U4M:
|
||||
shl edx, 16 ;DX to upper 1/2 of EDX
|
||||
mov dx, ax
|
||||
mov eax, edx
|
||||
shl edx, 16 ; dx to upper half of edx
|
||||
mov dx, ax ; m1 in edx
|
||||
mov eax, edx ; m1 in eax
|
||||
|
||||
shl ecx, 16
|
||||
mov cx, bx
|
||||
|
||||
mul ecx
|
||||
mov edx, eax
|
||||
shr edx, 16
|
||||
|
||||
ret
|
||||
shl ecx, 16 ; cx to upper half of ecx
|
||||
mov cx, bx ; m2 in ecx
|
||||
|
||||
mul ecx ; result in edx:eax (we only need eax)
|
||||
mov edx, eax ; move upper half to dx
|
||||
shr edx, 16
|
||||
|
||||
ret
|
||||
|
||||
;
|
||||
;void _cdecl x86_div64_32(uint64_t dividend, uint32_t divisor, uint64_t* quotentOut, uint32_t* remainderOut);
|
||||
; void _cdecl x86_div64_32(uint64_t dividend, uint32_t divisor, uint64_t* quotientOut, uint32_t* remainderOut);
|
||||
;
|
||||
|
||||
global _x86_div64_32
|
||||
_x86_div64_32:
|
||||
;make new call frame
|
||||
push bp ;save old call frame
|
||||
mov bp, sp ;init new call frame
|
||||
|
||||
push bx
|
||||
; make new call frame
|
||||
push bp ; save old call frame
|
||||
mov bp, sp ; initialize new call frame
|
||||
|
||||
;divide upper 32 bits
|
||||
mov eax, [bp + 4] ;eax is upper 32 bits of divedend
|
||||
mov ecx, [bp + 12] ;ecx is the divisor
|
||||
xor edx, edx
|
||||
div ecx ;eax - quot, edx - remainder
|
||||
push bx
|
||||
|
||||
;store upper 32 bits
|
||||
mov ebx, [bp + 16]
|
||||
mov [bx + 4], eax
|
||||
; divide upper 32 bits
|
||||
mov eax, [bp + 8] ; eax <- upper 32 bits of dividend
|
||||
mov ecx, [bp + 12] ; ecx <- divisor
|
||||
xor edx, edx
|
||||
div ecx ; eax - quot, edx - remainder
|
||||
|
||||
;divide lower 32 bits
|
||||
mov eax, [bp + 4] ;eax is the lower 32 bits of the dividend
|
||||
;edx is old remainder
|
||||
div ecx
|
||||
; store upper 32 bits of quotient
|
||||
mov bx, [bp + 16]
|
||||
mov [bx + 4], eax
|
||||
|
||||
;store results
|
||||
mov [bx], eax
|
||||
mov bx, [bp + 18]
|
||||
mov [bx], edx
|
||||
|
||||
pop bx
|
||||
|
||||
;restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
; divide lower 32 bits
|
||||
mov eax, [bp + 4] ; eax <- lower 32 bits of dividend
|
||||
; edx <- old remainder
|
||||
div ecx
|
||||
|
||||
; store results
|
||||
mov [bx], eax
|
||||
mov bx, [bp + 18]
|
||||
mov [bx], edx
|
||||
|
||||
pop bx
|
||||
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
|
||||
;
|
||||
; int 10h ah=0Eh
|
||||
; args: character, page
|
||||
;
|
||||
global _x86_Video_WriteCharTeletype
|
||||
_x86_Video_WriteCharTeletype:
|
||||
|
||||
; make new call frame
|
||||
push bp ; save old call frame
|
||||
mov bp, sp ; initialize new call frame
|
||||
|
||||
push bp
|
||||
mov bp,sp
|
||||
; save bx
|
||||
push bx
|
||||
|
||||
push bx
|
||||
; [bp + 0] - old call frame
|
||||
; [bp + 2] - return address (small memory model => 2 bytes)
|
||||
; [bp + 4] - first argument (character)
|
||||
; [bp + 6] - second argument (page)
|
||||
; note: bytes are converted to words (you can't push a single byte on the stack)
|
||||
mov ah, 0Eh
|
||||
mov al, [bp + 4]
|
||||
mov bh, [bp + 6]
|
||||
|
||||
mov ah, 0Eh
|
||||
mov al, [bp + 4]
|
||||
mov bh, [bp + 6]
|
||||
int 10h
|
||||
|
||||
int 10h
|
||||
; restore bx
|
||||
pop bx
|
||||
|
||||
pop bx
|
||||
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
@ -130,127 +140,140 @@ _x86_Video_WriteCharTeletype:
|
||||
;
|
||||
global _x86_Disk_Reset
|
||||
_x86_Disk_Reset:
|
||||
;make new call frame
|
||||
push bp ;save old call frame
|
||||
mov bp, sp ;init new call frame
|
||||
|
||||
mov ah, 0
|
||||
mov dl, [bp + 4]; dl - drive
|
||||
std
|
||||
int 13h
|
||||
; make new call frame
|
||||
push bp ; save old call frame
|
||||
mov bp, sp ; initialize new call frame
|
||||
|
||||
mov ax, 1
|
||||
sbb ax, 0 ; 1 is true 0 is false
|
||||
mov ah, 0
|
||||
mov dl, [bp + 4] ; dl - drive
|
||||
stc
|
||||
int 13h
|
||||
|
||||
;restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
mov ax, 1
|
||||
sbb ax, 0 ; 1 on success, 0 on fail
|
||||
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
|
||||
|
||||
;
|
||||
; bool _cdecl x86_Disk_Read(uint8_t drive,
|
||||
; uint16_t cylinder,
|
||||
; uint16_t head,
|
||||
; uint16_t sector,
|
||||
; uint8_t count,
|
||||
; uint8_t far * dataout);
|
||||
; uint16_t cylinder,
|
||||
; uint16_t sector,
|
||||
; uint16_t head,
|
||||
; uint8_t count,
|
||||
; void far * dataOut);
|
||||
;
|
||||
global _x86_Disk_Read
|
||||
_x86_Disk_Read:
|
||||
;make new call frame
|
||||
push bp ;save old call frame
|
||||
mov bp, sp ;init new call frame
|
||||
|
||||
;setup args
|
||||
mov dl, [bp + 4]; dl - drive
|
||||
; make new call frame
|
||||
push bp ; save old call frame
|
||||
mov bp, sp ; initialize new call frame
|
||||
|
||||
mov ch, [bp + 6]; ch - cylinder (lower 8 bits)
|
||||
mov cl, [bp + 7]; cl - cylinder to to bits 6-7
|
||||
shl cl, 6
|
||||
; save modified regs
|
||||
push bx
|
||||
push es
|
||||
|
||||
mov dh, [bp + 10]; dh - head
|
||||
; setup args
|
||||
mov dl, [bp + 4] ; dl - drive
|
||||
|
||||
mov al, [bp + 8]; cl - sectory to bits 0-5
|
||||
and al, 3Fh
|
||||
or cl, al
|
||||
mov ch, [bp + 6] ; ch - cylinder (lower 8 bits)
|
||||
mov cl, [bp + 7] ; cl - cylinder to bits 6-7
|
||||
shl cl, 6
|
||||
|
||||
mov al, [bp + 8] ; cl - sector to bits 0-5
|
||||
and al, 3Fh
|
||||
or cl, al
|
||||
|
||||
mov al, [bp + 12]; count
|
||||
mov dh, [bp + 10] ; dh - head
|
||||
|
||||
mov bx, [bp + 16]; es:bx - far pointer to data out
|
||||
mov es, bx
|
||||
mov bx, [bp + 14]
|
||||
mov al, [bp + 12] ; al - count
|
||||
|
||||
; call
|
||||
mov al, 02h
|
||||
std
|
||||
int 13h
|
||||
mov bx, [bp + 16] ; es:bx - far pointer to data out
|
||||
mov es, bx
|
||||
mov bx, [bp + 14]
|
||||
|
||||
mov ax, 1
|
||||
sbb ax, 0 ; 1 is true 0 is false
|
||||
; call int13h
|
||||
mov ah, 02h
|
||||
stc
|
||||
int 13h
|
||||
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
; set return value
|
||||
mov ax, 1
|
||||
sbb ax, 0 ; 1 on success, 0 on fail
|
||||
|
||||
; restore regs
|
||||
pop es
|
||||
pop bx
|
||||
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; bool _cdelc x86_Disk_GetDriveParams(uint8_t drive,
|
||||
; uint8_t* driveTypeOut,
|
||||
; uint16_t* cylindersOut,
|
||||
; uint16_t* sectorsOut,
|
||||
; uint16_t* headsOut);
|
||||
;
|
||||
; bool _cdecl x86_Disk_GetDriveParams(uint8_t drive,
|
||||
; uint8_t* driveTypeOut,
|
||||
; uint16_t* cylindersOut,
|
||||
; uint16_t* sectorsOut,
|
||||
; uint16_t* headsOut);
|
||||
;
|
||||
global _x86_Disk_GetDriveParams
|
||||
_x86_Disk_GetDriveParams:
|
||||
; make new call frame
|
||||
push bp ; save old frame
|
||||
mov bp, sp ; init new frame
|
||||
|
||||
; save regs
|
||||
push es
|
||||
push bx
|
||||
push si
|
||||
push di
|
||||
; make new call frame
|
||||
push bp ; save old call frame
|
||||
mov bp, sp ; initialize new call frame
|
||||
|
||||
; call int13h
|
||||
mov dl, [bp + 4] ;dl - drive
|
||||
mov ah, 08h
|
||||
mov di, 0 ;es:di - 0000:0000
|
||||
mov es, di
|
||||
stc
|
||||
int 13h
|
||||
; save regs
|
||||
push es
|
||||
push bx
|
||||
push si
|
||||
push di
|
||||
|
||||
; return
|
||||
mov ax, 1
|
||||
sbb ax, 0
|
||||
; call int13h
|
||||
mov dl, [bp + 4] ; dl - disk drive
|
||||
mov ah, 08h
|
||||
mov di, 0 ; es:di - 0000:0000
|
||||
mov es, di
|
||||
stc
|
||||
int 13h
|
||||
|
||||
; out params
|
||||
mov si, [bp + 6] ; drive type
|
||||
mov [si], bl
|
||||
; return
|
||||
mov ax, 1
|
||||
sbb ax, 0
|
||||
|
||||
mov bl, ch ; cyl - lower bits in ch
|
||||
mov bh, cl ; cyl - upper bits in ch (6-7)
|
||||
shr bh, 6
|
||||
mov si, [bp + 8]
|
||||
mov [si], bx
|
||||
; out params
|
||||
mov si, [bp + 6] ; drive type from bl
|
||||
mov [si], bl
|
||||
|
||||
xor ch, ch ; sectors - lower 5 bits of cl
|
||||
and cl, 3Fh
|
||||
mov si, [bp + 10]
|
||||
mov [si], cx
|
||||
mov bl, ch ; cylinders - lower bits in ch
|
||||
mov bh, cl ; cylinders - upper bits in cl (6-7)
|
||||
shr bh, 6
|
||||
mov si, [bp + 8]
|
||||
mov [si], bx
|
||||
|
||||
mov cl, dh
|
||||
mov si, [bp + 12]
|
||||
mov [si], cx
|
||||
xor ch, ch ; sectors - lower 5 bits in cl
|
||||
and cl, 3Fh
|
||||
mov si, [bp + 10]
|
||||
mov [si], cx
|
||||
|
||||
; restore regs
|
||||
pop di
|
||||
pop si
|
||||
pop bx
|
||||
pop es
|
||||
mov cl, dh ; heads - dh
|
||||
mov si, [bp + 12]
|
||||
mov [si], cx
|
||||
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
; restore regs
|
||||
pop di
|
||||
pop si
|
||||
pop bx
|
||||
pop es
|
||||
|
||||
; restore old call frame
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
void _cdecl x86_div64_32(uint64_t dividend, uint32_t divisor, uint64_t* quotentOut, uint32_t* remainderOut);
|
||||
void _cdecl x86_div64_32(uint64_t dividend, uint32_t divisor, uint64_t* quotientOut, uint32_t* remainderOut);
|
||||
|
||||
void _cdecl x86_Video_WriteCharTeletype(char c, uint8_t page);
|
||||
|
||||
@ -17,7 +17,7 @@ bool _cdecl x86_Disk_Read(uint8_t drive,
|
||||
uint16_t sector,
|
||||
uint16_t head,
|
||||
uint8_t count,
|
||||
void far * dataout);
|
||||
void far * dataOut);
|
||||
|
||||
bool _cdecl x86_Disk_GetDriveParams(uint8_t drive,
|
||||
uint8_t* driveTypeOut,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user