Skip to content

Commit b8ceb6c

Browse files
committed
Upload source
1 parent cd40ffe commit b8ceb6c

5 files changed

Lines changed: 594 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

build.bat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@echo off
2+
@set path=C:\Program Files\NASM;%path%
3+
4+
mkdir bin
5+
6+
@echo on
7+
nasm -f bin -w-other -o bin\main.bin main.nasm
8+
nasm -f bin -o bin\loader.bin loader.nasm
9+
10+
@echo off
11+
echo.
12+
copy /b bin\loader.bin+bin\main.bin bin\out.img

commonSubroutines.nasm

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
; args: al = char, bl = attibute, bh = page, dl = cursor x, dh = cursor y
3+
; invalidates: ah, cx
4+
printChar:
5+
mov cx, 1
6+
mov ah, 2
7+
int 10h
8+
mov ah, 9
9+
int 10h
10+
inc dl
11+
ret
12+
13+
; args: ax = address to string, bl = attibute, bh = page, dl = cursor x, dh = cursor y
14+
; invalidates: ax, cx, si
15+
printString:
16+
mov si, ax
17+
mov cx, 1
18+
.loop:
19+
mov al, [si]
20+
test al, al
21+
jz .end
22+
mov ah, 2
23+
int 10h
24+
mov ah, 9
25+
int 10h
26+
inc dl
27+
inc si
28+
jmp .loop
29+
.end:
30+
ret
31+
32+
; args: al = number to print, bl = attibute, bh = page, dl = cursor x, dh = cursor y
33+
; invalidates: ax, cx
34+
printNumDec:
35+
test al, al
36+
jnz .print_ax
37+
push ax
38+
mov al, '0'
39+
mov ah, 2
40+
int 10h
41+
mov cx, 1
42+
mov ah, 9
43+
int 10h
44+
inc dl
45+
pop ax
46+
ret
47+
48+
.print_ax:
49+
push ax
50+
push cx
51+
mov ah, 0
52+
cmp ax, 0
53+
je .pn_done
54+
mov cl, 10
55+
div cl
56+
call .print_ax
57+
mov al, ah
58+
add al, 30h
59+
mov ah, 2
60+
int 10h
61+
push cx
62+
mov cx, 1
63+
mov ah, 9
64+
int 10h
65+
pop cx
66+
inc dl
67+
.pn_done:
68+
pop cx
69+
pop ax
70+
ret
71+
72+
; args: ax = number to print, bl = attibute, bh = page, dl = cursor x, dh = cursor y
73+
printNumHex:
74+
push cx
75+
push si
76+
mov cx, ax
77+
rol cx, 4
78+
mov si, 3
79+
.loop:
80+
mov ah, 2
81+
int 10h
82+
mov al, cl
83+
and al, 0Fh
84+
cmp al, 10
85+
jns .letter
86+
add al, '0'
87+
jmp .print
88+
.letter:
89+
add al, ('A' - 10)
90+
.print:
91+
mov ah, 9
92+
push cx
93+
mov cx, 1
94+
int 10h
95+
pop cx
96+
rol cx, 4
97+
inc dl
98+
dec si
99+
jns .loop
100+
pop si
101+
pop cx
102+
ret

loader.nasm

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
org 7C00h
2+
bits 16
3+
cpu 386
4+
5+
jmp short Start
6+
7+
db "FlopBird" ; OEM String
8+
dw 0x200 ; bytes per sector
9+
db 1 ; sectors per cluster
10+
dw 1 ; ;of reserved sectors
11+
db 2 ; ;of FAT copies
12+
dw 224 ; size of root directory
13+
dw 2880 ; total # of sectors if over 32 MB
14+
db 0xF0 ; media Descriptor
15+
dw 9 ; size of each FAT
16+
dw 9 ; sectors per track
17+
dw 2 ; number of read-write heads
18+
dd 0 ; number of hidden sectors
19+
dd 0 ; ; sectors for over 32 MB
20+
db 0 ; holds drive that the boot sector came from
21+
db 0 ; reserved, empty
22+
db 0x29 ; extended boot sector signature
23+
db "seri" ; disk serial
24+
db "Floppy Bird" ; volume label
25+
db "FAT16 " ; file system type
26+
27+
%define STACK_BASE_ADDR 1000h
28+
%define PROGRAM_LOAD_ADDR 1000h
29+
%define SEGMENTS_TO_LOAD 4
30+
31+
startMsg db "Starting loader", 0
32+
jumpingToProgramMsg db "Jumping to program..", 0
33+
programLoadFailedMsg db "Program load failed", 0
34+
currentDrive db 0
35+
36+
Start:
37+
jmp 0000:Start2
38+
Start2:
39+
cli
40+
xor ax, ax
41+
mov ss, ax
42+
mov ds, ax
43+
mov es, ax
44+
mov fs, ax
45+
mov gs, ax
46+
sti
47+
cld
48+
mov [currentDrive], dl
49+
mov bp, STACK_BASE_ADDR
50+
mov sp, STACK_BASE_ADDR
51+
52+
mov bh, al ; page 0
53+
mov bl, 0Fh ; color 15 (white)
54+
mov dl, al ; DL - cursor x
55+
mov dh, al ; DH - cursor y
56+
57+
mov ax, startMsg
58+
call printString
59+
60+
push bx
61+
push dx
62+
mov ah, 2
63+
mov al, SEGMENTS_TO_LOAD
64+
xor ch, ch
65+
mov cl, 2
66+
xor dh, dh
67+
mov dl, [currentDrive]
68+
mov bx, PROGRAM_LOAD_ADDR
69+
int 0x13
70+
pop dx
71+
pop bx
72+
jc short LoadFailature
73+
74+
inc dh
75+
xor dl, dl
76+
mov ax, jumpingToProgramMsg
77+
call printString
78+
inc dh
79+
80+
mov dl, [currentDrive]
81+
; dh - cursor y
82+
jmp PROGRAM_LOAD_ADDR
83+
84+
LoadFailature:
85+
inc dh
86+
xor dl, dl
87+
mov ax, programLoadFailedMsg
88+
call printString
89+
90+
IdleLoop:
91+
hlt
92+
jmp IdleLoop
93+
94+
%include "commonSubroutines.nasm"
95+
96+
times 0200h - 2 - ($ - $$) db 0 ; zerofill up to 510 bytes
97+
dw 0AA55h ; Boot Sector signature

0 commit comments

Comments
 (0)