Author Topic: copying to second sector  (Read 11040 times)

Zulfi Khan

  • Guest
copying to second sector
« on: July 06, 2009, 10:18:32 AM »
Hi,
Can somebody plz help me with copying this code to sector2 of my floppy. I am using partcopy but its not working.
;--- test kernel.bin---

;    push cs
;    push cs
;    pop ds
;    pop es

mov si, msg

mov ah, 0Eh
    mov bx, 7
top:
    lodsb
    cmp al, 0
    jz blackhole
    int 10h
    jmp short top

blackhole:
    hlt
    jmp blackhole

msg db 'Welcome to the Kernel!', 0


        D:\NASMPR~1>partcopy test.bin 0 200 -f0 200
Failed to read source at offset 2C
D:\NASMPR~1>

Zulfi.

nobody

  • Guest
Re: copying to second sector
« Reply #1 on: July 06, 2009, 12:41:56 PM »
Zulfi, stop spamming the nasm-devel list with repeats of questions here.

Continue to do so, and you will find that more people will ignore you than help you.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: copying to second sector
« Reply #2 on: July 06, 2009, 01:30:07 PM »
Yeah! (statistically, more people are ignoring him than helping him now! :)

I think the only problem with "partcopy" is that you're asking it to read more than you've got in the file. Cut it down to:

partcopy test.bin 0 2C -f0 200

May work... An alternative... You've got the lame little program "writeit.asm":

; Your boot sector:  DOS FILE: WRITEIT.ASM
; nasm -f bin -o writeit.com writeit.asm

[BITS 16]
[ORG 0x100]
  mov  ax,3D00h
  mov  dx,filename
  int  21h
  ; check for errors here!

jc exit
  mov  bx,ax
  mov  ah,3Fh
  mov  dx,buffer
  mov  cx,512
  int  21h
  ; check for errors here!
jc exit
; at an equivalent point, "partcopy" apparently checks the
; number of bytes actually read (in ax). We could do the same.
; ... but we won't :)

mov  ah,3Eh ; close input file...
  int  21h

push ds ; don't think we need this...
  pop  es  ; won't hurt.

mov bx, buffer
 mov dl, 00h
 mov dh, 0
 mov cl, 1 ; change this to 2 for sector 2
 mov ch, 0
 mov ah, 03h
 mov al, 1
  int  13h
exit:
 mov ax, 4C00h
 int 21h

filename  db 'BOOT.BIN',0 ; change to "test.bin" or whatever

;buffer    times 512 db 0   ; is this correct nasm syntax?
; yeah, the syntax is fine, but why clutter up our executable
; with zeros?
section .bss
 buffer resb 512
;-----------------------

Copy "writeit.asm" to "writek.asm" or something, make those couple changes, and it might work for you. But it's strictly a "one trick pony" - will only write a single sector, etc. We could make it a lot more powerful... prompt for the filename, show the length read and how many sectors it will take up, ask which sector to start writing it at, display results, prompt for another filename... until done. Might make an interesting "project" - sector to CHS arithmetic is a PITA... (example in Deb Wiles' "bootsect.bin", which you've got). But it's "been done".

You could also copy multiple .bin files to a single "image.bin" and write it to floppy with "rawwrite" or such:

copy /b boot.bin+map.bin+root.bin+kernel.bin+shell.bin image.bin
rawwrite image.bin

There's more than one way to skin a cat (but it makes a really small fur coat :)

Best,
Frank

nobody

  • Guest
Re: copying to second sector
« Reply #3 on: July 06, 2009, 01:56:34 PM »
Sorry I am not much  familiar with these forums. That's why I put my questions on SourceForge as well as on nabble. But this time i wrongly put it on the deve forum and i would take care of it next time.
I am still working on the solutions.

Zulfi.