Add externs to avoid multiple definitions, and then add missing definitions.
[rrq/maintain_lilo.git] / src / dparam.S
1 ;  dparam.S
2 ;
3 ;  Copyright 1992 Werner Almesberger
4 ;  Copyright 2009-2011 Joachim Wiedorn
5 ;  All rights reserved.
6 ;
7 ;  Licensed under the terms contained in the file 'COPYING'
8 ;  in the source directory.
9 ;
10
11         .text
12
13         .globl  _main
14         .org    0x100
15
16 _main:  mov     bl,0x80                 ! NUL-terminate the command line
17         xor     bh,bh
18         mov     0x81(bx),bh
19         mov     bx,#0x81
20 aloop:  mov     al,(bx)                 ! get the next character
21         inc     bx
22         cmp     al,#32                  ! space ?
23         je      aloop                   ! yes -> skip it
24         cmp     al,#48                  ! '0' ?
25         jne     error                   ! no -> invalid
26         cmpb    (bx),#120               ! 'x' ?
27         je      okay                    ! yes -> okay
28         cmpb    (bx),#88                ! 'X' ?
29         jne     error                   ! no -> invalid
30 okay:   cmpb    1(bx),#56               ! '8' ?
31         jne     error                   ! no -> invalid
32         cmpb    3(bx),#0                ! one more digit ?
33         jne     error                   ! no -> invalid
34         mov     dl,2(bx)                ! get the digit
35         sub     dl,#48                  ! convert to a number
36         cmp     dl,#1                   ! valid ?
37         ja      error                   ! no -> error
38         add     dl,#0x80                ! adjust the number
39         mov     ah,#8                   ! get the drive parameters
40         int     0x13
41         or      ah,ah                   ! error ?
42         jnz     derror                  ! yes -> display a message
43         push    cx                      ! save the parameters
44         push    dx
45         mov     al,cl                   ! number of sectors
46         and     al,#0x3f
47         xor     ah,ah
48         call    decout
49         call    space
50         pop     dx                      ! number of heads
51         mov     al,dh
52         inc     al
53         xor     ah,ah
54         call    decout
55         call    space
56         pop     ax                      ! number of cylinders
57         xchg    ah,al
58         mov     cl,#6
59         shr     ah,cl
60         inc     ax
61         call    decout
62         mov     dx,#crlf                ! crlf
63         mov     ah,#9
64         int     0x21
65         ret                             ! done
66
67 error:  mov     dx,#errmsg              ! display the error message
68         jmp     dispit
69
70 derror: mov     dx,#invdrv              ! display the error message
71         jmp     dispit
72
73 space:  mov     dx,#spc                 ! display two blanks
74         jmp     dispit
75
76 decout: mov     bx,#decend              ! set the pointer to the end
77 declp:  xor     dx,dx                   ! divide by 10
78         mov     cx,#10
79         div     cx
80         add     dl,#48                  ! make a digit
81         dec     bx                      ! store digit
82         mov     (bx),dl
83         or      ax,ax                   ! zero ?
84         jnz     declp                   ! no -> go on
85         mov     dx,bx                   ! display the string
86 dispit: mov     ah,#9
87         int     0x21
88         ret                             ! done
89
90 errmsg: .ascii  "usage: dparam 0x80"
91         .byte   13,10
92         .ascii  "   or  dparam 0x81"
93 crlf:   .byte   13,10
94         .ascii  "$"
95
96 invdrv: .ascii  "Invalid drive"
97         .byte   13,10
98         .ascii  "$"
99
100 spc:    .ascii  "  $"
101
102 decbuf: .byte   0,0,0,0,0
103 decend: .ascii  "$"