-
Notifications
You must be signed in to change notification settings - Fork 1
/
benplay.asm
308 lines (247 loc) · 7.29 KB
/
benplay.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
; ==================================================================
; benOS Bootloader
; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
;
; The official bootloader for benOS and BenchX desktop/laptop products.
; The first bootloader built for a decentralized operating system.
; Many bootloaders were looked at and utilized in the creation of
; benOS's BenchX bootloader.
;
; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
; ==================================================================
; ------------------------------------------------------------------
; benOS Boot Process - Initialize BenPlay
; ------------------------------------------------------------------
%include "benplay.inc"
SECTION .text
USE16
benplay:
; ------------------------------------------------------------------
; benOS Boot Process - Get Video Card
; ------------------------------------------------------------------
.getvidcard:
mov ax, 0x4F00
mov di, BPBECardInfo
int 0x10
cmp ax, 0x4F
je .findbenmode
mov eax, 1
ret
; ------------------------------------------------------------------
; benOS Boot Process - Reset Configuration List
; ------------------------------------------------------------------
.resetlist:
xor cx, cx
mov [.minx], cx
mov [.miny], cx
mov [benconfig.xres], cx
mov [benconfig.yres], cx
; ------------------------------------------------------------------
; benOS Boot Process - Find benOS Modes
; ------------------------------------------------------------------
.findbenmode:
mov si, [BPBECardInfo.videomodeptr]
mov ax, [BPBECardInfo.videomodeptr+2]
mov fs, ax
sub si, 2
; ------------------------------------------------------------------
; benOS Boot Process - Locate benOS Modes
; ------------------------------------------------------------------
.seekbenmodes:
add si, 2
mov cx, [fs:si]
cmp cx, 0xFFFF
jne .getbenmode
cmp word [.bengoodmode], 0
je .resetlist
jmp .findbenmode
; ------------------------------------------------------------------
; benOS Boot Process - Get benOS Modes
; ------------------------------------------------------------------
.getbenmode:
push esi
mov [.benmode], cx
mov ax, 0x4F01
mov di, BPBEModeInfo
int 0x10
pop esi
cmp ax, 0x4F
je .locatedbenmode
mov eax, 1
ret
; ------------------------------------------------------------------
; benOS Boot Process - Located benOS Mode
; ------------------------------------------------------------------
.locatedbenmode:
;check minimum values, really not minimums from an OS perspective but ugly for users
cmp byte [BPBEModeInfo.bitsperpixel], 32
jb .seekbenmodes
; ------------------------------------------------------------------
; benOS Boot Process - Test X Resolution -- Credit: Canonical (MIT)
; ------------------------------------------------------------------
.testx:
mov cx, [BPBEModeInfo.xresolution]
cmp word [benconfig.xres], 0
je .notrequiredx
cmp cx, [benconfig.xres]
je .testy
jmp .seekbenmodes
; ------------------------------------------------------------------
; benOS Boot Process - Test X Resolution Not Required
; ------------------------------------------------------------------
.notrequiredx:
cmp cx, [.minx]
jb .seekbenmodes
; ------------------------------------------------------------------
; benOS Boot Process - benOS Testy Bootloader Video Testing Suite
; ------------------------------------------------------------------
.testy:
mov cx, [BPBEModeInfo.yresolution]
cmp word [benconfig.yres], 0
je .notrequiredy
cmp cx, [benconfig.yres]
jne .seekbenmodes ;as if there weren't enough warnings, USE WITH CAUTION
cmp word [benconfig.xres], 0
jnz .setbenmode
jmp .benboot_test
; ------------------------------------------------------------------------
; benOS Boot Process - benOS Testy Bootloader Video Testing Not Required
; ------------------------------------------------------------------------
.notrequiredy:
cmp cx, [.miny]
jb .seekbenmodes
; ------------------------------------------------------------------
; benOS Boot Process - benOS BenBoot Test w/ BenPlay Mode
; ------------------------------------------------------------------
.benboot_test:
mov al, 13
call print_char
mov cx, [.benmode]
mov [.bengoodmode], cx
push esi
mov cx, [BPBEModeInfo.xresolution]
call print_dec
mov al, 'x'
call print_char
mov cx, [BPBEModeInfo.yresolution]
call print_dec
mov al, '@'
call print_char
xor ch, ch
mov cl, [BPBEModeInfo.bitsperpixel]
call print_dec
mov si, .modeok
call print
xor ax, ax
int 0x16
pop esi
cmp al, 'y'
je .setbenmode
cmp al, 's'
je .savebenmode
jmp .seekbenmodes
; ------------------------------------------------------------------
; benOS Boot Process - benOS Save BenPlay Video Mode
; ------------------------------------------------------------------
.savebenmode:
mov cx, [BPBEModeInfo.xresolution]
mov [config.xres], cx
mov cx, [BPBEModeInfo.yresolution]
mov [config.yres], cx
call save_config
; ------------------------------------------------------------------
; benOS Boot Process - benOS Set BenPlay Video Mode
; ------------------------------------------------------------------
.setbenmode:
mov bx, [.benmode]
cmp bx, 0
je .nobenmode
or bx, 0x4000
mov ax, 0x4F02
int 0x10
; ---------------------------------------------------------------------
; benOS Boot Process - When No benOS BenPlay Mode Is Chosen Or Found
; ---------------------------------------------------------------------
.nobenmode:
cmp ax, 0x4F
je .returnbengood
mov eax, 1
ret
; ---------------------------------------------------------------------
; benOS Boot Process - Return BenGood Mode
; ---------------------------------------------------------------------
.returnbengood:
xor eax, eax
ret
.minx dw 640
.miny dw 480
.modeok db ": Is this OK? (s)ave/(y)es/(n)o ",8,8,8,8,0
.bengoodmode dw 0
.benmode dw 0
; ---------------------------------------------------------------------
; benOS Boot Process - Print Dec
; ---------------------------------------------------------------------
print_dec:
mov si, .number
; ---------------------------------------------------------------------
; benOS Boot Process - Clear Dec
; ---------------------------------------------------------------------
.clear:
mov al, "0"
mov [si], al
inc si
cmp si, .numberend
jb .clear
dec si
call convert_dec
mov si, .number
.lp:
lodsb
cmp si, .numberend
jae .end
cmp al, "0"
jbe .lp
.end:
dec si
call print
ret
.number times 7 db 0
.numberend db 0
convert_dec:
dec si
mov bx, si
.cnvrt:
mov si, bx
sub si, 4
.ten4: inc si
cmp cx, 10000
jb .ten3
sub cx, 10000
inc byte [si]
jmp .cnvrt
.ten3: inc si
cmp cx, 1000
jb .ten2
sub cx, 1000
inc byte [si]
jmp .cnvrt
.ten2: inc si
cmp cx, 100
jb .ten1
sub cx, 100
inc byte [si]
jmp .cnvrt
.ten1: inc si
cmp cx, 10
jb .ten0
sub cx, 10
inc byte [si]
jmp .cnvrt
.ten0: inc si
cmp cx, 1
jb .return
sub cx, 1
inc byte [si]
jmp .cnvrt
.return:
ret