-
Notifications
You must be signed in to change notification settings - Fork 21
/
bincode.asm
17377 lines (14323 loc) · 264 KB
/
bincode.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
bits 32
extern jpeg_get_size
extern jpeg_decode
global _start
%define debug 1
%include "vocabulary.inc"
%include "modplay_defines.inc"
%include "jpeg.inc"
; some type definitions from mkbootmsg.c
; struct file_header_t
fh_magic_id equ 0
fh_version equ 4
fh_res_1 equ 5
fh_res_2 equ 6
fh_res_3 equ 7
fh_bincode equ 8
fh_bincode_size equ 12
fh_bincode_crc equ 16
fh_dict equ 20
fh_code equ 24
fh_code_size equ 28
sizeof_file_header_t equ 32
; font file header definition
foh.magic equ 0
foh.entries equ 4
foh.height equ 8
foh.baseline equ 9
foh.line_height equ 10
foh.size equ 11
; char bitmap definitions
; must match values in mkblfont.c
cbm_gray_bits equ 4
cbm_gray_bit_count equ 3
cbm_max_gray equ (1 << cbm_gray_bits) - 3
cbm_rep_black equ cbm_max_gray + 1
cbm_rep_white equ cbm_max_gray + 2
; struct playlist
pl_file equ 0 ; actually file index + 1
pl_loop equ 1
pl_res1 equ 2
pl_res2 equ 3
pl_start equ 4
pl_current equ 8
pl_end equ 12
sizeof_playlist equ 16
playlist_entries equ 4
; struct link
li.label equ 0
li.text equ 4
li.x equ 8
li.row equ 10
li.size equ 12 ; search for 'li.size'!
link_entries equ 64
; sysconfig data (64 bytes [sc.size])
sc.bootloader equ 0
sc.sector_shift equ 1
sc.media_type equ 2
sc.failsafe equ 3
sc.sysconfig_size equ 4
sc.boot_drive equ 5
sc.callback equ 6
sc.bootloader_seg equ 8
sc.serial_port equ 10
sc.user_info_0 equ 12
sc.user_info_1 equ 16
sc.bios_mem_size equ 20
sc.xmem_0 equ 24
sc.xmem_1 equ 26
sc.xmem_2 equ 28
sc.xmem_3 equ 30
sc.file equ 32
sc.archive_start equ 36
sc.archive_end equ 40
sc.mem0_start equ 44
sc.mem0_end equ 48
sc.xmem_start equ 52
sc.xmem_end equ 56
sc.features equ 60
sc.reserved_1 equ 62
sc.cwd equ 64
sc.size equ 68
sc.size_64 equ 64 ; supports xmem_* & feature flags
sc.size_68 equ 68 ; supports cwd
; enum_type_t
t_none equ 0
t_int equ 1
t_unsigned equ 2
t_bool equ 3
t_string equ 4
t_code equ 5
t_ret equ 6
t_prim equ 7
t_sec equ 8
t_dict_idx equ 9
t_array equ 10
t_end equ 11
t_ptr equ 12
t_if equ t_code + 10h
t_loop equ t_code + 20h
t_repeat equ t_code + 30h
t_for equ t_code + 40h
t_forall equ t_code + 50h
t_exit equ t_code + 60h
param_stack_size equ 1000
ret_stack_size equ 1000
; various error codes
pserr_ok equ 0
pserr_nocode equ 1
pserr_invalid_opcode equ 2
pserr_pstack_underflow equ 3
pserr_pstack_overflow equ 4
pserr_rstack_underflow equ 5
pserr_rstack_overflow equ 6
pserr_invalid_dict equ 7
pserr_wrong_arg_types equ 8
pserr_div_by_zero equ 9
pserr_invalid_rstack_entry equ 0ah
pserr_invalid_range equ 0bh
pserr_invalid_exit equ 0ch
pserr_invalid_image_size equ 0dh
pserr_no_memory equ 0eh
pserr_invalid_data equ 0fh
pserr_nop equ 10h
pserr_invalid_function equ 11h
pserr_invalid_dict_entry equ 200h
pserr_invalid_prim equ 201h
keyBS equ 08h
keyLeft equ 4bh ; scan code
keyRight equ 4dh ; scan code
keyHome equ 47h ; scan code
keyEnd equ 4fh ; scan code
keyDel equ 53h ; scan code
max_text_rows equ 128
mhead.memsize equ 0
mhead.ip equ 4
mhead.used equ 8 ; bit 7
mhead.rem equ 8 ; bit 0..6
mhead.size equ 9
section .text
_start:
; jmp table to interface functions
jt_init dw gfx_init
jt_done dw gfx_done
jt_input dw gfx_input
jt_menu_init dw gfx_menu_init
jt_infobox_init dw gfx_infobox_init
jt_infobox_done dw gfx_infobox_done
jt_progress_init dw gfx_progress_init
jt_progress_done dw gfx_progress_done
jt_progress_update dw gfx_progress_update
jt_progress_limit dw gfx_progress_limit
jt_password_init dw gfx_password_init
jt_password_done dw gfx_password_done
align 4, db 0
file.start dd 0 ; the file we are in
archive.start dd 0 ; archive start address (0 -> none)
archive.end dd 0 ; archive end
mem0.start dd 0 ; free low memory area start
mem0.end dd 0 ; dto, end
malloc.areas equ 5
malloc.start dd 0
malloc.end dd 0
; start, end pairs
malloc.area times malloc.areas * 2 dd 0
vbe_buffer dd 0 ; (lin) buffer for vbe calls
vbe_mode_list dd 0 ; (lin) list with (up to 100h) vbe modes
vbe_info_buffer dd 0 ; (lin) buffer for vbe gfx card info
infobox_buffer dd 0 ; (lin) temp buffer for InfoBox messages
local_stack dd 0 ; ofs local stack (8k)
local_stack.ofs equ local_stack
local_stack.seg dw 0 ; dto, seg
old_stack dd 0 ; store old esp value
old_stack.ofs equ old_stack
old_stack.seg dw 0 ; dto, ss
stack.size dd 0 ; in bytes
tmp_stack_val dw 0 ; needed for stack switching
pscode_start dd 0 ; (lin)
pscode_size dd 0
pscode_instr dd 0 ; (lin) current instruction (rel. to pscode_start)
pscode_next_instr dd 0 ; (lin) next instruction
; for debugging only
pscode_next_break dd 0 ; (lin) break at this instruction
pscode_eval dd 0 ; opcode from exec instruction
pscode_error_arg_0 dd 0
pscode_error_arg_1 dd 0
pscode_arg dd 0 ; current arg
pscode_error dw 0 ; error code (if any)
pscode_type db 0 ; current instr type
align 4, db 0
dict dd 0 ; lin
dict.size dd 0 ; dict entries
boot.base dd 0 ; bootloader segment
boot.sysconfig dd 0 ; bootloader parameter block
boot.callback dd 0 ; seg:ofs
pstack dd 0 ; data stack
pstack.size dd 0 ; entries
pstack.ptr dd 0 ; index of current tos
rstack dd 0 ; code stack
rstack.size dd 0 ; entries
rstack.ptr dd 0 ; index of current tos
image dd 0 ; (lin) current image
image_width dw 0
image_height dw 0
image_type db 0 ; 0:no image, 1: pcx, 2:jpeg
pcx_line_starts dd 0 ; (lin) table of line starts
jpg_static_buf dd 0 ; (lin) tmp data for jpeg decoder
screen_width dw 0
screen_height dw 0
screen_vheight dw 0
screen_mem dw 0 ; mem in 64k
screen_line_len dd 0
setpixel dd setpixel_8 ; function that sets one pixel
setpixel_a dd setpixel_a_8 ; function that sets one pixel
setpixel_t dd setpixel_8 ; function that sets one pixel
setpixel_ta dd setpixel_a_8 ; function that sets one pixel
getpixel dd getpixel_8 ; function that gets one pixel
transp dd 0 ; transparency
align 4, db 0
; current font description
font dd 0 ; (lin)
font.entries dd 0 ; chars in font
font.height dw 0
font.baseline dw 0
font.line_height dw 0
font.properties db 0 ; bit 0: pw mode (show '*')
font.res1 db 0 ; alignment
; console font
cfont.lin dd 0 ; console font bitmap
cfont_height dd 0
con_x dw 0 ; cursor pos in pixel
con_y dw 0 ; cursor pos in pixel, *must* follow con_x
; current char description
chr.buf dd 0 ; buffer for antialiased fonts
chr.buf_len dd 0
chr.pixel_buf dd 0
chr.data dd 0 ; encoded char data
chr.bitmap dd 0 ; start of encoded bitmap; bit offset rel to chr.data
chr.bitmap_width dw 0
chr.bitmap_height dw 0
chr.x_ofs dw 0
chr.y_ofs dw 0 ; rel. to baseline
chr.x_advance dw 0
chr.type db 0 ; 0 = bitmap, 1: gray scale
chr.gray_values:
%assign i 0
%rep cbm_max_gray + 1
db (i * 255)/cbm_max_gray
%assign i i + 1
%endrep
utf8_buf times 8 db 0
; pointer to currently active palette (3*100h bytes)
gfx_pal dd 0 ; (lin)
; pointer to tmp area (3*100h bytes)
gfx_pal_tmp dd 0 ; (lin)
; number of fixed pal values
pals dw 0
; the current gfx mode
; note: for vbe modes, bit 14 (framebuffer mode) is always 0
; fb_active is used to indicate whether to use fb drawing functions
gfx_mode dw 3
; != 0 if we're using a vbe mode (hi byte of gfx_mode)
vbe_active equ gfx_mode + 1
pixel_bits db 0 ; pixel size (8, 16, or 32)
color_bits db 0 ; color bits (8, 15, 16, or 24)
pixel_bytes dd 0 ; pixel size in bytes
; framebuffer start
framebuffer dd 0 ; (lin)
; segment address of writeable window
window_seg_w dw 0
; segment address of readable window (= gfx_window_seg_w if 0)
window_seg_r dw 0
; ganularity units per window
window_inc db 0
; currently mapped window
mapped_window db 0
; do we use the framebuffer for drawing?
fb_active db 0
; cursor position
gfx_cur equ $ ; both x & y
gfx_cur_x dw 0
gfx_cur_y dw 0 ; must follow gfx_cur_x
gfx_width dw 0
gfx_height dw 0
line_wrap dd 0
gfx_indent dw 0
; clip region (incl)
clip_l dw 0 ; left, incl
clip_r dw 0 ; right, excl
clip_t dw 0 ; top, incl
clip_b dw 0 ; bottom, excl
line_x0 dd 0
line_y0 dd 0
line_x1 dd 0
line_y1 dd 0
line_tmp dd 0
line_tmp2 dd 0
align 4, db 0
gfx_color dd 0 ; current color
gfx_color0 dd 0 ; color #0 (normal color))
gfx_color1 dd 0 ; color #1 (highlight color)
gfx_color2 dd 0 ; color #2 (link color)
gfx_color3 dd 0 ; color #3 (selected link color)
gfx_color_rgb dd 0 ; current color (rgb)
transparent_color dd -1
char_eot dd 0 ; 'end of text' char
last_label dd 0 ; lin
page_title dd 0 ; lin
max_rows dd 0 ; max. number of text rows
cur_row dd 0 ; current text row (0 based)
cur_row2 dd 0 ; dto, only during formatting
start_row dd 0 ; start row for text output
cur_link dd 0 ; link count
sel_link dd 0 ; selected link
txt_state db 0 ; bit 0: 1 = skip text
; bit 1: 1 = text formatting only
textmode_color db 7 ; fg color for text (debug) output
keep_mode db 0 ; keep video mode in gfx_done
align 4, db 0
idle.draw_buffer dd 0 ; some drawing buffer
idle.data1 dd 0 ; some data
idle.data2 dd 0 ; some more data
idle.run db 0 ; run idle loop
idle.invalid db 0 ; idle loop has been left
align 4, db 0
fname.tmp dd 0 ; tmp buffer for fname processing
fname.abs dd 0 ; tmp buffer for abs fname processing
fname.cwd dd 0 ; current working dir
fname.sys_cwd dd 0 ; real cwd (bootloader's view)
fname.size equ 256 ; buffer size of fname.*
align 4, db 0
row_text times max_text_rows dd 0
ind_text times max_text_rows dw 0
; note: link_list relies on row_start
link_list times li.size * link_entries db 0
; max label size: 32
label_buf times 35 db 0
; buffer for number conversions
; must be large enough for ps_status_info()
num_buf times 23h db 0
num_buf_end db 0
; temp data for printf
tmp_write_data times 10h dd 0
tmp_write_num dd 0
tmp_write_sig db 0
tmp_write_cnt db 0
tmp_write_pad db 0
pf_gfx db 0
pf_gfx_raw_char db 0
pf_gfx_err dw 0
align 4, db 0
pf_gfx_buf dd 0
pf_gfx_max dd 0
pf_gfx_cnt dd 0
input_notimeout db 0
align 4, db 0
input_timeout_start dd 0
input_timeout dd 0
progress_max dd 0
progress_current dd 0
edit_x dw 0
edit_y dw 0
edit_width dw 0
edit_height dw 0
edit_bg dd 0 ; (lin)
edit_buf dd 0 ; (lin)
edit_buf_len dw 0
edit_buf_ptr dw 0
edit_flags dd 0 ; bit 0: cursor visible
; bit 1: complete redraw needed
edit_saved_cursor dd 0 ; (lin)
edit_cursor dw 0 ; cursor pos in pixel
edit_shift dw 0
edit_y_ofs dw 0
edit_length dw 0 ; string length in pixel
kbd_status dw 0
sl.port equ 0
sl.baud equ 2
sl.scancode equ 4
sl.status equ 5 ; bits:
; 0: valid config
; 1: input received
; 2: baud autodetect
sl.recv_mask equ 6 ; for autodetect
sl.recv_cnt equ 7 ; dto.
sl.baud_idx equ 8 ; dto.
sl.size equ 9
; 5 serial lines
serial.lines.max equ 5
serial.lines times serial.lines.max * sl.size db 0
serial.port_noinit dw 0 ; port that was setup by bootloader
serial.key dd 0 ; serial input
; baud divisors
serial.baud_tab db 1, 3, 6, 12, 0
sound_buf_size equ 4*1024
sound_buf_mask equ sound_buf_size - 1
align 4, db 0
sound_unpack_buf dd 0 ; buffer for unpacked sound samples
sound_unpack_buf_size dd 0
cnt0_acc dw 0
cnt0_start_val dw 0
sound_old_int8 dd 0
sound_vol db 0
sound_ok db 0
sound_int_active db 0
sound_playing db 0 ; bits 0-3: mod, 4-7: wav
sound_scale db 0
sound_sample dd 0
sound_buf dd 0 ; (seg:ofs)
sound_buf.lin dd 0 ; buffer for sound player
sound_start dd 0 ; rel. to sound_buf
sound_end dd 0 ; rel. to sound_buf
playlist times playlist_entries * sizeof_playlist db 0
mod_buf dd 0 ; buffer for mod player
int8_count dd 0
wav_current dd 0 ; pointer to currently played way file
wav_end dd 0 ; stop here
wav_next dd 0 ; next sound sample
wav_type db 0
need_sound_update db 0
align 4, db 0
ddc_external dd 0
; temporary vars
tmp_var_0 dd 0
tmp_var_1 dd 0
tmp_var_2 dd 0
tmp_var_3 dd 0
; display size list
display_res.cnt dw 0
display_res times 16 dw 0, 0
display_res_pref dw 0, 0
align 2
pm_idt dw 7ffh ; idt for pm
.base dd 0
rm_idt dw 0ffffh ; idt for real mode
.base dd 0
pm_gdt dw gdt_size-1 ; gdt for pm
.base dd 0
; real mode segment values
rm_seg:
.ss dw 0
.cs dw 0
.ds dw 0
.es dw 0
.fs dw 0
.gs dw 0
align 4
prog.base dd 0 ; our base address
gdt dd 0, 0 ; null descriptor
.4gb_d32 dd 0000ffffh, 00cf9300h ; 4GB segment, data, use32
.4gb_c32 dd 0000ffffh, 00cf9b00h ; 4GB segment, code, use32
; see gdt_init
.prog_c32 dd 00000000h, 00409b00h ; our program as code, use32
.prog_d16 dd 00000000h, 00009300h ; dto, data, use16
.prog_c16 dd 00000000h, 00009b00h ; dto, code, use16
.data_d16 dd 00000000h, 00009300h ; 64k segment, data, use16
.screen_r16 dd 00000000h, 00009300h ; 64k screen, data, use16
.screen_w16 dd 00000000h, 00009300h ; 64k screen, data, use16
.tss dd 00000067h, 00008900h ; 104 byte minimal tss
gdt_size equ $-gdt
; gdt for pm switch
pm_seg.4gb_d32 equ 8 ; covers all 4GB, default ss, es, fs, gs
pm_seg.4gb_c32 equ 10h ; dto, but executable (for e.g., idt)
pm_seg.prog_c32 equ 18h ; default cs, use32
pm_seg.prog_d16 equ 20h ; default ds
pm_seg.prog_c16 equ 28h ; default cs, use16
pm_seg.data_d16 equ 30h ; free to use
pm_seg.screen_r16 equ 38h ; graphics window, for reading
pm_seg.screen_w16 equ 40h ; graphics window, for writing
pm_seg.tss equ 48h ; tss
%if debug
; debug texts
dmsg_01 db 10, 'Press a key to continue...', 0
dmsg_02 db ' mem area %d: 0x%08x - 0x%08x', 10, 0
dmsg_03 db '%4u: addr 0x%08x, size 0x%08x+%u, ip 0x%04x, %s', 10, 0
dmsg_03a db ' ', 10, 0
dmsg_04 db 'oops: block at 0x%08x: size 0x%08x is too small', 10, 0
dmsg_04a db 'oops: 0x%08x > 0x%08x', 10, 0
dmsg_06 db 'addr 0x%08x', 10, 0
dmsg_07 db 'free', 0
dmsg_08 db 'used', 0
dmsg_09 db 'current dictionary', 10, 0
dmsg_10 db ' %2u: type %u, val 0x%x', 10, 0
%endif
single_step db 0
show_debug_info db 0
dtrace_count db 0
fms_cpio_swab db 0
hello db 10, 'Initializing gfx code...', 10
msg_0 db 0
msg_10 db 0b3h, 'ip %4x: %8x.%x ', 0b3h, 10, 0
msg_11 db 0b3h, '%2x: %8x.%2x', 0
msg_12 db 0b3h, ' : ', 0
msg_13 db 0dah, 0c4h, 0c4h, 0c4h, 0c4h, 'data'
times 7 db 0c4h
db 0c2h, 0c4h, 0c4h, 0c4h, 0c4h, 'prog'
times 7 db 0c4h
db 0bfh, 10, 0
msg_14 db 0c3h
times 15 db 0c4h
db 0c1h
times 15 db 0c4h
db 0b4h, 10, 0
msg_15 db 0c0h
times 31 db 0c4h
db 0d9h, 10, 0
msg_16 db 0b3h, 10, 0
msg_17 db 0b3h, 'err %3x ', 0b3h, 10, 0
msg_18 db 0b3h, 'err %3x: %8x ', 0b3h, 10, 0
msg_19 db 0b3h, 'err %3x: %8x %8x ', 0b3h, 10, 0
msg_20 db 0b3h, 'ip %4x: %8x.%x %8x.%x ', 0b3h, 10, 0
msg_21 db 0b3h, '%S', 0b3h, 10, 0
align 2, db 0
; prim_function entries
prim_jump_table
; menu entry descriptor
menu_entries equ 0
menu_default equ 2 ; seg:ofs
menu_ent_list equ 6 ; seg:ofs
menu_ent_size equ 10
menu_arg_list equ 12 ; seg:ofs
menu_arg_size equ 16
sizeof_menu_desc equ 18
; framebuffer mode list
fb_mode equ 0 ; word
fb_width equ 2 ; word
fb_height equ 4 ; word, must follow fb_width
fb_bits equ 6 ; byte
fb_ok equ 7 ; monitor supports it
sizeof_fb_entry equ 8
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
; Some macros.
;
%macro pf_arg_uchar 2
and dword [tmp_write_data + %1 * 4],byte 0
mov [tmp_write_data + %1 * 4],%2
%endmacro
%macro pf_arg_ushort 2
and word [tmp_write_data + %1 * 4 + 2],byte 0
mov [tmp_write_data + %1 * 4],%2
%endmacro
%macro pf_arg_uint 2
mov [tmp_write_data + %1 * 4],%2
%endmacro
%macro pf_arg_char 2
push eax
movsx eax,%2
mov [tmp_write_data + %1 * 4],eax
pop eax
%endmacro
%macro pf_arg_short 2
push eax
movsx eax,%2
mov [tmp_write_data + %1 * 4],eax
pop eax
%endmacro
%macro pf_arg_int 2
mov [tmp_write_data + %1 * 4],%2
%endmacro
%macro pm_enter 0
%%j_pm_1:
call switch_to_pm
%%j_pm_2:
%if %%j_pm_2 - %%j_pm_1 != 3
%error "pm_enter: not in 16 bit mode"
%endif
bits 32
%endmacro
%macro pm_leave 0
%%j_pm_1:
call switch_to_rm
%%j_pm_2:
%if %%j_pm_2 - %%j_pm_1 != 5
%error "pm_leave: not in 32 bit mode"
%endif
bits 16
%endmacro
%macro gfx_enter 0
call _gfx_enter
bits 32
%endmacro
%macro gfx_leave 0
call _gfx_leave
bits 16
%endmacro
%macro rm32_call 1
pm_leave
call %1
pm_enter
%endmacro
%macro pm32_call 1
pm_enter
call %1
pm_leave
%endmacro
%macro wait32 0
pushf
push ecx
push eax
mov ecx,10000000
%%wait32_10:
in al,80h
loop %%wait32_10
pop eax
pop ecx
popf
%endmacro
%macro is_dotdot 1
cmp dword [%1],'/../'
jz %%idd_90
cmp dword [%1],'/..'
%%idd_90:
%endmacro
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
; Interface functions.
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Setup internal data structures.
;
; esi sysconfig data
;
; return:
; CF error
;
bits 16
gfx_init:
; don't change stack layout - see gfx_enter
push fs
push es
push ds
push cs
pop ds
cld
mov [boot.sysconfig],esi
; setup gdt, to get pm-switching going
call gdt_init
; we can run in protected mode but can't handle ints until
; after pm_init
cli
xor ecx,ecx
dec cx
pm_enter
; some via cpus have problems with pm switching (bug #231104), so:
; checking whether pm switch really worked...
inc ecx
jnz gfx_init_10
; ... apparently not; try to get out
cmc
jnc $+2
cmc
jnc $+2
jz $+2
pm_leave
cmc
jnc $+2
cmc
jnc $+2
jz $+2
stc
pop ds
pop es
pop fs
sti
retf
bits 32
gfx_init_10:
mov esi,[boot.sysconfig]
movzx eax,word [es:esi+sc.bootloader_seg]
shl eax,4
mov [boot.base],eax
push dword [es:esi+sc.file]
pop dword [file.start]
push dword [es:esi+sc.archive_start]
pop dword [archive.start]
push dword [es:esi+sc.archive_end]
pop dword [archive.end]
push dword [es:esi+sc.mem0_start]
pop dword [mem0.start]
push dword [es:esi+sc.mem0_end]
pop dword [mem0.end]
mov ax,[es:esi+sc.serial_port]
mov [serial.port_noinit],ax
mov eax,[es:esi+sc.callback]
or ax,ax ; check only offset
jz gfx_init_20
mov [boot.callback],eax
gfx_init_20:
; init malloc memory chain
push dword [mem0.start]
pop dword [malloc.area]
push dword [mem0.end]
pop dword [malloc.area+4]
mov ebx,[boot.sysconfig]
cmp byte [es:ebx+sc.sysconfig_size],sc.size_64
jb gfx_init_28
; pass back feature flags
mov word [es:ebx+sc.features],3
; only one xmem area
mov eax,[es:ebx+sc.xmem_start]
mov edx,[es:ebx+sc.xmem_end]
cmp edx,eax
jbe gfx_init_28
; ok, use only this one
mov [malloc.area+8],eax
mov [malloc.area+8+4],edx
jmp gfx_init_40
gfx_init_28:
; old way to specify extended mem areas
mov esi,malloc.area+8
mov ecx,malloc.areas-1 ; extended mem areas
gfx_init_30:
movzx eax,word [es:ebx+sc.xmem_0] ; extended mem area pointer
or eax,eax
jz gfx_init_40
mov edx,eax
and dl,~0fh
shl edx,16
and eax,0fh
shl eax,20
add eax,edx
mov [esi+4],eax
; magic: if archive was loaded in high memory, exclude it
cmp edx,[archive.start]
jnz gfx_init_35
mov edx,[archive.end]
gfx_init_35:
mov [esi],edx
add esi,8
add ebx,2
dec ecx
jnz gfx_init_30
gfx_init_40:
call malloc_init
; setup full pm interface
; can't do it earlier - we need malloc
call pm_init
; allocate 8k local stack
mov eax,8 << 10
mov [stack.size],eax
add eax,3
call calloc
; dword align
add eax,3
and eax,~3
jnz gfx_init_50
cmp eax,100000h ; must be low memory
jb gfx_init_50
; malloc failed - keep stack
push word [rm_seg.ss]
pop word [local_stack.seg]
mov eax,esp
mov [local_stack.ofs],eax
jmp gfx_init_51
gfx_init_50:
mov edx,eax
and eax,0fh
add eax,[stack.size]
mov [local_stack.ofs],eax
shr edx,4
mov [local_stack.seg],dx
gfx_init_51:
; now we really start...
pm_leave
sti
call use_local_stack
pm_enter
mov esi,hello
call printf
; get initial keyboard state
push word [es:417h]
pop word [kbd_status]
mov eax,[boot.sysconfig]
mov al,[es:eax+sc.failsafe]
test al,1
jz gfx_init_58
xor ebx,ebx
gfx_init_55:
pf_arg_uchar 0,bl
mov eax,[malloc.area+8*ebx]
pf_arg_uint 1,eax
mov eax,[malloc.area+8*ebx+4]
pf_arg_uint 2,eax
or eax,eax
jz gfx_init_57
push ebx
mov esi,dmsg_02
call printf
pop ebx
inc ebx
cmp ebx,malloc.areas
jb gfx_init_55
gfx_init_57:
mov esi,dmsg_01
call printf
call get_key
gfx_init_58:
; alloc memory for palette data
call pal_init
jc gfx_init_90
mov eax,200h
call calloc
cmp eax,1
jc gfx_init_90
mov [vbe_buffer],eax
mov eax,100h
call calloc
cmp eax,1
jc gfx_init_90
mov [vbe_info_buffer],eax
mov eax,sound_buf_size
call calloc
cmp eax,1
jc gfx_init_90
mov [sound_buf.lin],eax
mov edx,eax
and eax,~0fh