From 8a0e4bd1d707e554b9c7f7e5eee224adf9752987 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Thu, 19 May 2016 20:40:59 -0400 Subject: [PATCH] Early generation disk copier, currently only deals with the first 64KB --- stage1_disk_copier.s | 105 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 stage1_disk_copier.s diff --git a/stage1_disk_copier.s b/stage1_disk_copier.s new file mode 100644 index 0000000..3625b3d --- /dev/null +++ b/stage1_disk_copier.s @@ -0,0 +1,105 @@ +BITS 16 + ;; Steps for building + ;; nasm -o stage1_disk_copier stage1_disk_copier.s + ;; + ;; Steps for testing + ;; qemu -fda stage0 + ;; manually toggle in program hex + ;; or + ;; qemu -fda stage1_loader -fdb output + ;; then change floppy0 to the compiled version of this file +start: + mov sp, 256 ; Allocate 256B for stack + mov ax, 7e00h ; Which is much more than we need + mov ss, ax ; And stopping before this code + + ;; Prompt user to press any key after loading desire source into A: + mov ax, MSG0 + call print_string + + ;; Wait until the user presses a key + call read_key + + ;; Inform the user that we are starting to read + mov ax, MSG1 + call print_string + + ;; Read A: into memory + call read_floppy + + ;; Inform the user that we completed reading A: and are starting to write B: + mov ax, MSG2 + call print_string + + ;; Start writing memory into B: + call write_floppy2 + + ;; Inform the user that we completed writing to B: + mov ax, MSG3 + call print_string + jmp start + +;; Our glourious strings +MSG0 db 'Load source into A: and hit any key',10,13,0 +MSG1 db 'Starting to read A:',10,13,0 +MSG2 db 'Read Complete, Starting to write B:',10,13,0 +MSG3 db 'Write Complete',10,13, 0 + +;; Deal with the problem of printing the above strings +print_string: + push bx + mov bx, ax +.L0: + mov al, [cs:bx] + cmp al, 0 + je .L99 + call print_char + add bx, 1 + jmp .L0 +.L99: + pop bx + ret + +print_char: + ; Routine: output char in al to screen + mov ah, 0Eh ; int 10h 'print char' function + int 10h ; print it + ret + +read_floppy: + ;; Read bytes from floppy + push 02000h ; Use The read space + pop es ; ES is needed to be set for bios call + mov al, 128 ; Read 2^15 Bytes from diskette + mov ah, 02h ; Read Sectors to Memory + mov ch, 0 ; Cylinder Number + mov cl, 1 ; Starting sector number + mov dh, 0 ; Drive head number + mov dl, 00h ; Drive number [first floppy] + mov bx, 0h ; Starting address + int 13h ; Make the function call + + jc read_floppy + ret + +read_key: + ;; Routine: read a char into al + mov ah, 00h + int 16h + ret + +write_floppy2: + ;; Write bytes onto floppy2 + push 02000h ; Use the read space + pop es ; ES is needed to be set for bios all + mov al, 128 ; Write 2^15 Bytes to diskette + mov ah, 03h ; Write Sectors from Memory + mov ch, 0 ; Cylinder Number + mov cl, 1 ; Starting sector number + mov dh, 0 ; Drive head number + mov dl, 01h ; Drive number [second floppy] + mov bx, 0h ; Starting address + int 13h ; Make the function call + + jc write_floppy2 + ret