Skip to content

Commit 6505a5d

Browse files
committed
Initial commit.
0 parents  commit 6505a5d

File tree

13 files changed

+354
-0
lines changed

13 files changed

+354
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*.img
2+
build/*.iso

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
NASM = nasm
2+
QEMU = qemu-system-i386
3+
QEMU_DRIVE = a
4+
5+
NAME = retrokern
6+
FILENAME = $(NAME).img
7+
8+
IMAGE = build/$(FILENAME)
9+
ISO_IMAGE = build/iso/$(FILENAME)
10+
ISO = build/$(NAME).iso
11+
ISO_DIR = build/iso
12+
13+
BOOT = src/boot.asm
14+
15+
all: $(IMAGE)
16+
17+
$(IMAGE): $(BOOT)
18+
$(NASM) -isrc/ -f bin -o $(IMAGE) $(BOOT)
19+
20+
floppy:
21+
dd bs=512 count=2880 if=/dev/zero of=$(ISO_IMAGE)
22+
dd status=noxfer conv=notrunc if=$(IMAGE) of=$(ISO_IMAGE)
23+
24+
iso:
25+
$(MAKE) floppy
26+
genisoimage -quiet -V 'FLOPPYBIRD' -input-charset iso8859-1 -o $(ISO) -b $(FILENAME) $(ISO_DIR)
27+
28+
clean:
29+
rm -f $(IMAGE)
30+
rm -f $(ISO_IMAGE)
31+
rm -f $(ISO)
32+

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Retrokern
2+
=========
3+
4+
Retrokern is a 16-bit x86 assembly-based "operating system" that aims to accomplish the following goals:
5+
6+
* Provide a teaching platform for x86 assembly
7+
* Provide a simple non-DOS, completely free operating system for retro projects
8+
9+
This system requires absolutely no operating system and will boot (in theory) in any 8086 or later CPU, including modern x86_64 systems.
10+
11+
Copyright
12+
---------
13+
14+
Written by Robert W. Oliver II <[email protected]>
15+
Copyright (C) 2018 Sourcerer, All Rights Reserved.
16+
17+
License
18+
-------
19+
20+
Licensed under the GPLv3.
21+
22+
This program is free software: you can redistribute it and/or modify
23+
it under the terms of the GNU General Public License as published by
24+
the Free Software Foundation, either version 3 of the License, or
25+
(at your option) any later version.
26+
27+
This program is distributed in the hope that it will be useful,
28+
but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
GNU General Public License for more details.
31+
32+
You should have received a copy of the GNU General Public License
33+
along with this program. If not, see <http://www.gnu.org/licenses/>.
34+
35+
Thanks
36+
------
37+
38+
Retrokern was inspired and borrows some code from Mihail Szabolcs's FloppyBird DOS/Assembly game.
39+
https://github.com/icebreaker/floppybird/
40+
41+
The author would like to thank Sourcerer for inspiration, support, and promotion.

build/.gitkeep

Whitespace-only changes.

build/iso/.gitkeep

Whitespace-only changes.

misc/dosbox.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[cpu]
2+
cycles=10000

src/boot.asm

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
%define SECTORS 16
2+
%define IMAGE_SIZE ((SECTORS + 1) * 512) ; SECTORS + 1 (~= 18) * 512 bytes
3+
%define STACK_SIZE 256 ; 4096 bytes in paragraphs
4+
5+
; Declare 16-bit mode
6+
bits 16
7+
; Boot sector entry point
8+
;org 0x7C00
9+
10+
start:
11+
cli ; disable interrupts
12+
13+
;
14+
; Notes:
15+
; 1 paragraph = 16 bytes
16+
; 32 paragraphs = 512 bytes
17+
;
18+
; Skip past our SECTORS
19+
; Skip past our reserved video memory buffer (for double buffering)
20+
; Skip past allocated STACK_SIZE
21+
;
22+
23+
mov ax, (((SECTORS + 1) * 32) + 4000 + STACK_SIZE)
24+
mov ss, ax
25+
mov sp, STACK_SIZE * 16 ; 4096 in bytes
26+
27+
sti ; enable interrupts
28+
29+
mov ax, 07C0h ; point all segments to _start
30+
mov ds, ax
31+
mov es, ax
32+
mov fs, ax
33+
mov gs, ax
34+
35+
; dl contains the drive number
36+
37+
mov ax, 0 ; reset disk function
38+
int 13h ; call BIOS interrupt
39+
jc disk_reset_error
40+
41+
push es ; save es
42+
43+
mov ax, 07E0h ; destination location (address of _start)
44+
mov es, ax ; destination location
45+
mov bx, 0 ; index 0
46+
47+
mov ah, 2 ; read sectors function
48+
mov al, SECTORS ; number of sectors
49+
mov ch, 0 ; cylinder number
50+
mov dh, 0 ; head number
51+
mov cl, 2 ; starting sector number
52+
int 13h ; call BIOS interrupt
53+
54+
jc disk_read_error
55+
56+
pop es ; restore es
57+
58+
mov si, boot_msg ; boot message
59+
call _puts ; print
60+
61+
jmp 07E0h:0000h ; jump to _start (a.k.a stage 2)
62+
63+
disk_reset_error:
64+
mov si, disk_reset_error_msg
65+
jmp fatal
66+
67+
disk_read_error:
68+
mov si, disk_read_error_msg
69+
70+
fatal:
71+
call _puts ; print message in [DS:SI]
72+
73+
mov ax, 0 ; wait for a keypress
74+
int 16h
75+
76+
mov ax, 0 ; reboot
77+
int 19h
78+
79+
; _puts - in-boot-sector put string function
80+
; pointer in SI
81+
_puts:
82+
lodsb ; move byte [DS:SI] into AL
83+
84+
; is this the end of the string?
85+
cmp al, 0
86+
je .end
87+
88+
; display character BIOS call
89+
mov ah, 0x0E
90+
int 0x10
91+
92+
; move to next character
93+
jmp _puts
94+
95+
.end:
96+
ret
97+
98+
disk_reset_error_msg: db 'Disk reset error.',0
99+
disk_read_error_msg: db 'Disk read error.',0
100+
boot_msg: db 'Booting Retrokern... ', 0
101+
102+
; Pad to 510 bytes, then 2 more magic bytes to fill the boot sector
103+
times 510 - ($ - $$) db 0
104+
dw 0xAA55
105+
106+
; entry point
107+
_start:
108+
call main ; call main
109+
jmp $ ; loop forever
110+
111+
%include 'console.asm';
112+
%include 'timer.asm'
113+
%include 'speaker.asm'
114+
%include 'video.asm'
115+
%include 'core.asm'
116+
117+
; main.asm contains the main loop
118+
%include 'main.asm'
119+
120+
; pad to IMAGE_SIZE
121+
times IMAGE_SIZE - ($ - $$) db 0

src/console.asm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; getchar()
2+
; Returns keyboard press in AX
3+
getchar:
4+
pusha
5+
mov ax, 0x0
6+
int 0x16
7+
8+
mov [.chr], ax
9+
popa
10+
mov ax, [.chr]
11+
ret
12+
13+
.chr: dw 0
14+
15+
; kbhit - returns key hit in AX (without wait)
16+
kbhit:
17+
pusha
18+
19+
mov al, 0 ; check for any keys hit
20+
mov ah, 1 ; but do not block (async)
21+
int 16h ; call BIOS interrupt
22+
jz .end ; if no keys hit jump to end
23+
24+
mov ax, 0 ; get key hit function
25+
int 16h ; call BIOS interrupt
26+
27+
mov [.key], ax
28+
29+
popa
30+
31+
mov ax, [.key]
32+
ret
33+
34+
.end:
35+
popa
36+
37+
mov ax, 0 ; set AX to 0 if no keys hit
38+
ret
39+
40+
.key: dw 0
41+

src/core.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Reboot the system
2+
reboot:
3+
mov ax, 0x0
4+
int 0x19
5+
ret
6+
7+

src/main.asm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
main:
2+
call set_text_mode
3+
4+
.start:
5+
6+
7+
.reboot:
8+
call reboot
9+
ret
10+

0 commit comments

Comments
 (0)