-
Notifications
You must be signed in to change notification settings - Fork 0
/
newimage.asm
218 lines (209 loc) · 2.9 KB
/
newimage.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
BITS 16
ORG 0x100
_start:
clc
mov di, zeroes
mov cx, 16128
xor ax, ax
rep stosw
mov si, 0x81
.loop1 lodsb
cmp al, ' '
je .loop1
cmp al, 0x0D
je .usage
mov dx, si
dec dx
mov [_start], dx
.loop2 lodsb
cmp al, 0x0D
je .usage
cmp al, ' '
jne .loop2
mov [si - 1], byte 0
mov cx, 10
.loop3 lodsb
cmp al, ' '
je .loop3
.loop4 cmp al, '0'
jb .usage
cmp al, '9'
ja .usage
mov ah, 0
sub al, '0'
mov bx, ax
call .mx2b
lodsb
cmp al, ' '
je .usage
cmp al, 0x0D
je main
cmp al, 'K'
je .k
cmp al, 'k'
je .k
cmp al, 'M'
je .m
cmp al, 'm'
je .m
cmp al, 'G'
je .g
cmp al, 'g'
je .g
jmp .loop4
.overflow:
mov dx, overflow
jmp .ue
.usage:
mov dx, usage
.ue mov ah, 9
int 0x21
mov ax, 0x4C03
int 0x21
.k mov cx, 2
jmp .mx
.m mov cx, 2048
jmp .mx
.g mov cx, 2048
call .mx2
mov cx, 1024
jmp .mx
.mx2 xor bx, bx
.mx2b mov ax, [space]
mul cx
add ax, bx
adc dx, 0
mov bx, dx
mov [space], ax
mov ax, [space + 2]
mul cx
add ax, bx
adc dx, 0
mov [space + 2], ax
or dx, dx
jnz .overflow
ret
.mx call .mx2
main: ;space = the size of the image in 512 byte sectors; I need to divide by 1008 for cylinders
mov cx, 1008
mov dx, [space + 2]
cmp dx, cx
jae _start.overflow
mov ax, [space]
div cx
or dx, dx
jz .noinc
inc ax
jz _start.overflow
.noinc mov bp, ax ; BP = number of cylinders in image
mov di, number + 5
mov cx, 10
.itoa xor dx, dx
div cx
add dl, '0'
dec di
mov [di], dl
or ax, ax
jnz .itoa
mainloop:
mov dx, [_start]
mov cx, 0
mov ah, 0x3C
int 0x21
jc .doserror
or bp, bp
jz .nodata
mov dx, zeroes
mov bx, ax
mov cx, 32256
.loop1 mov si, 16
.loop2 mov ah, 0x40
int 0x21
jc .cdoserror
dec si
jnz .loop2
push bx
push cx
push dx
mov dx, dot
mov cx, 1
mov bx, 2
mov ah, 0x40
int 0x21
pop dx
pop cx
pop bx
dec bp
jnz .loop1
mov ah, 0x3E
int 0x21
jc .doserror ; Our most graciuos host has different rules
mov dx, eol
mov cx, 2
mov bx, 2
mov ah, 0x40
int 0x21
.nodata:
mov ah, 0x9
mov dx, newimg1
int 0x21
call outname
mov ah, 0x9
mov dx, newimg2
int 0x21
mov ah, 0x9
mov dx, di
int 0x21
mov ah, 0x9
mov dx, newimg3
int 0x21
call outname
mov ah, 0x9
mov dx, newimg4
int 0x21
mov ax, 0x4C00
int 0x21
.cdoserror:
push ax
mov ah, 0x3E
int 0x21
pop ax
.doserror:
mov bx, ax
shl bx, 1
mov dx, [bx + errorcodes]
mov ah, 0x9
int 0x21
mov ax, 0x4C01
int 0x21
outname:
mov dx, [_start]
mov si, dx
xor cx, cx
.loop inc cx
lodsb
or al, al
jnz .loop
dec cx
mov bx, cx
mov si, dx
mov [bx + si], byte '$'
mov ah, 0x9
int 0x21
ret
align 2, db 0xCC
%include 'errormsg.asm'
align 2, db 0
space dd 0
overflow db 'Arithmatic overflow computing image geometry, 13, 10, $'
usage db 'Usage: dosbox NEWIMAGE'
dot db '.'
db 'COM C.IMG size[K/M/G]'
eol db 13, 10, '$'
newimg1 db 'imgmount 2 $'
newimg2 db ' -t hdd -size 512,63,16,$'
newimg3 db ' -fs none', 13, 10, 'boot $'
newimg4 db ' -l C', 13, 10, '$'
number db ' $'
align 4, db 0
zeroes: