]> wirehaze git hosting - lifeboot.git/blob - lifeboot.asm

wirehaze git hosting

60b5ea4e7e1b58115dfccf2d587b7c6079740823
[lifeboot.git] / lifeboot.asm
1 bits 16
2 org 0x7c00
3
4 %define ORG 0x7c00
5 %define VGA 0xb8000
6
7 %define COLS 80
8 %define ROWS 25
9
10 %define GRID ORG + 512
11 %define NEXT_GRID GRID_CUR + COLS * ROWS
12
13 %define DEAD ' '
14 %define ALIVE '#'
15
16 %define PRINT_COLOR 0x07 ; grey on black
17
18 ; entry point -----------------------------------------------------------------
19
20 ; initialize segment registers
21 xor ax, ax
22 mov ds, ax
23 mov es, ax
24 mov ss, ax
25
26 ; set stack pointers
27 mov sp, ORG
28 mov bp, ORG
29
30 ; clear screen ----------------------------------------------------------------
31
32 ; disable cursor
33 mov ch, 0x3f
34 mov ah, 0x01
35 int 0x10
36
37 ; clear video memory
38 mov cx, COLS * ROWS
39 mov ax, VGA >> 4
40 mov es, ax
41 xor di, di
42 mov ax, (PRINT_COLOR << 8) | DEAD
43
44 rep stosw ; fill cx words at es:di with ax
45
46 ; errors ----------------------------------------------------------------------
47
48 hello:
49 mov si, str.hello
50
51 ; print the error message string in si and halt
52 ; note: we assume es = VGA_SEG and ds = 0
53 printerr:
54 xor di, di
55 mov ah, PRINT_COLOR
56
57 ; es:di = video memory
58 ; ds:si = error message
59 ; al = current char
60 ; ah = color attribute
61
62 write_char:
63 lodsb ; al = [ds:si], si += 1
64 or al, al ; on null terminator,
65 jz halt ; halt
66 stosw ; [es:di] = ax, di += 2
67 jmp write_char
68
69 halt:
70 cli ; disable interrupts
71 hlt
72 jmp halt
73
74 ; data ------------------------------------------------------------------------
75
76 str:
77 .hello:
78 db "lifeboot", 0
79
80 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
81 dw 0xaa55 ; mbr magic byte