flat assembler
Message board for the users of flat assembler.

Index > DOS > Problem with INT 13h IBM/MS Disk Extensions

Author
Thread Post new topic Reply to topic
tom1000000



Joined: 12 Feb 2012
Posts: 2
tom1000000
Hello

I have built a simple COM file to get the size of a hard disk, using the INT 13h extensions.

It is a bit annoying the WindowsXP Command Line does not support the INT 13h extensions at all (installation check fails). So I have to reboot....

I have tried this on 2 different computers and it didn't work on both.

For some reason.... INT 13h AH=48h always fails!
I always get: Disk size ERROR
I can't get the disk info for some reason?

If someone can work out whats going on, that would be much appreciated.

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; TEST Int13h IBM/MS EXTENSIONS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org 100h 

    mov     ax, cs          ;just making sure....
    mov     ds, ax
    mov     es, ax
    mov     ss, ax
    mov     sp, 0xFFFE
    
    ; Intialize int13-48h buffer to zeros (probably not required)
    mov     di, buffer
    xor     ax, ax
    mov     cx, 42h/2
    cld
    rep stosw
    clc

    ; Installation Check
    mov     ax, 4100h
    mov     bx, 55AAh
    mov     dx, 0080h
    int     13h
    jc      .endInt48h
    cmp     bx, 0AA55h
    jne     .endInt48h

    mov     si, int48extYes
    call    PrintString
    mov     al, cl
    add     al, 48          ;convert to ascii
    mov     ah, 0Eh
    xor     bh, bh
    mov     cx, 1
    int     10h             ;ah=09h prints character with attributes but doesn't move cursor
    mov     si, newLine
    call    PrintString
    
    ; Get hard disk size
    mov     ax, 4800h
    mov     dx, 0080h
    mov     si, buffer
    int     13h
    jc      .errDiskSize      ;error so skip disk size

    mov     si, diskSizeYes
    call    PrintString
    
    ; Convert QWORD into asciiz string
    ; Assumes sector size is a power of 2
    mov     eax, [buffer+10h]
    mov     edx, [buffer+14h]
    mov     cx, [buffer+18h]
    bsf     cx, cx                  ; finding first set bit from right to left
    shld    edx, eax, cl            ; multiply via shift
    shl     eax, cl                 ; edx:eax now has size in bytes of disk
    mov     ecx, 1000000            ; divide byte size by 1,000,000 to get metric size
    idiv    ecx
    xor     edx,edx                 ; edx:eax now has size in metric megabytes
    
    ;Loop to generate string
    ; [di] = destination string, it must consist of 11 space (' ') characters
    ; bx   = string offset
    ; commaPos = keep track of where to insert commas
    ; ecx  = 10 (divisor)
    ; edx:eax = size in megabytes, edx must be less than 10
    mov     di, sizeNbrStr          ; string pointer
    mov     bx, 10                  ; start at right most position
    mov     ecx, 10                 ; divide by 10 to convert to ascii
    
    .startStrLoop:
    cmp     eax, 0
    je      .endStrLoop
    cmp     [commaPos], byte 3
    jb     .getStrChar
    mov     [di+bx], byte ','
    dec     bx
    cmp     bx, 0
    jl      .endStrLoop
    mov     [commaPos], byte 0      ; reset it
    .getStrChar:
    idiv    ecx
    add     dl, 48                  ; remainder in dl, convert to ascii
    mov     [di+bx], dl             ; store in memory
    dec     bx
    cmp     bx, 0
    jl      .endStrLoop
    xor     dl, dl                  ; edx is reset for next idiv
    inc     byte [commaPos]
    jmp .startStrLoop
    .endStrLoop:
    
    ; Print the message
    mov     si, sizeMsg1
    call    PrintString
    mov     si, sizeNbrStr
    call    PrintString
    mov     si, sizeMsg2
    call    PrintString
 
    ; Finish
    jmp     .quit
    
    .endInt48h:

    mov     si, int48extNo
    call    PrintString
    jmp     .quit
    
    .errDiskSize:
    
    mov     si, diskSizeNo
    call    PrintString
    jmp     .quit

    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;exit
    .quit:
    mov ax,4C00h
    int 21h

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; PrintString
;
; Use BIOS routines to print an asciiz string
;
; In:
; - valid stack required
; SI    Address of string
;
; Out:
; - void
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString:

    push ax
    push bx
    push cx
    push dx
    push si

    .startLoop:
    mov al, byte [si]
    cmp al, 0
    je .endLoop
           
    mov ah, 0Eh
    xor bh, bh
    mov cx, 1
    int 10h             ;ah=09h prints character with attributes but doesn't move cursor
     
    mov ah, 03h
    int 10h

    inc si
    jmp .startLoop
   .endLoop:
      
    pop si
    pop dx
    pop cx
    pop bx
    pop ax
    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End PrintString:



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; DATA
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
newLine:        db 0Dh,0Ah,0
int48extYes     db 'Int48h Extensions are installed. API Subset Support Bitmap (CL): ',0
int48extNo      db 'Int48h Extensions NOT supported.',0Dh,0Ah,0
diskSizeYes     db 'Got disk size',0Dh,0Ah,0
diskSizeNo      db 'Disk size ERROR',0Dh,0Ah,0

sizeMsg1:       db 'Disk size: ',0
sizeNbrStr:     db '           ',0
sizeMsg2:       db 'MB',0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0
commaPos:       db 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; UNINITIALIZED DATA
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 16
buffer:         rb 512
    
Post 12 Feb 2012, 01:10
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 713
Location: Adelaide
sinsi
Before calling function 48h set the buffer size e.g. "mov word[buffer],42h"
Post 12 Feb 2012, 01:57
View user's profile Send private message Reply with quote
tom1000000



Joined: 12 Feb 2012
Posts: 2
tom1000000
Thanks Sinsi!

It works now..... damn I wasted over 3 hours trying to figure it out!

I should have read RBIL more carefully....

Thanks again!
Post 12 Feb 2012, 10:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.