├── LICENSE ├── Makefile ├── MineBios.img ├── README.md ├── photo ├── 1.png ├── 2.png └── 3.png └── src ├── bootloader └── boot.asm └── kernel └── main.asm /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # This code was taken from channel "nanobyte-dev" and modified. 2 | # https://github.com/nanobyte-dev/nanobyte_os/blob/videos/part2/Makefile 3 | # Thanks 4 | 5 | ASM=nasm 6 | 7 | SRC_DIR=src 8 | TOOLS_DIR=tools 9 | BUILD_DIR=build 10 | 11 | .PHONY: all floppy_image kernel bootloader clean always tools_fat 12 | 13 | all: floppy_image tools_fat 14 | 15 | # 16 | # Floppy image 17 | # 18 | floppy_image: $(BUILD_DIR)/main_floppy.img 19 | 20 | $(BUILD_DIR)/main_floppy.img: bootloader kernel 21 | dd if=/dev/zero of=$(BUILD_DIR)/main_floppy.img bs=512 count=2880 22 | mkfs.fat -F 12 -n "MineBios" $(BUILD_DIR)/main_floppy.img 23 | dd if=$(BUILD_DIR)/bootloader.bin of=$(BUILD_DIR)/main_floppy.img conv=notrunc 24 | mcopy -i $(BUILD_DIR)/main_floppy.img $(BUILD_DIR)/kernel.bin "::kernel.bin" 25 | qemu-system-i386 -fda $(BUILD_DIR)/main_floppy.img 26 | 27 | # 28 | # Bootloader 29 | # 30 | bootloader: $(BUILD_DIR)/bootloader.bin 31 | 32 | $(BUILD_DIR)/bootloader.bin: always 33 | rm -rf $(BUILD_DIR)/* 34 | $(ASM) $(SRC_DIR)/bootloader/boot.asm -f bin -o $(BUILD_DIR)/bootloader.bin 35 | 36 | # 37 | # Kernel 38 | # 39 | kernel: $(BUILD_DIR)/kernel.bin 40 | 41 | $(BUILD_DIR)/kernel.bin: always 42 | $(ASM) $(SRC_DIR)/kernel/main.asm -f bin -o $(BUILD_DIR)/kernel.bin 43 | 44 | # 45 | # Always 46 | # 47 | always: 48 | mkdir -p $(BUILD_DIR) 49 | 50 | # 51 | # Clean 52 | # 53 | clean: 54 | rm -rf $(BUILD_DIR)/* 55 | 56 | info: 57 | mdir -i $(BUILD_DIR)/main_floppy.img 58 | 59 | iso: 60 | mkisofs -o MineBios.iso -V MineBios -b main_floppy.img $(BUILD_DIR) 61 | 62 | -------------------------------------------------------------------------------- /MineBios.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppsever/MineBios/ca9831fa763c637e69b85e244dabe545343d84a8/MineBios.img -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MineBios 2 | Download Link (1.89 mb iso): 3 | 4 | [![Download MineBios](https://a.fsdn.com/con/app/sf-download-button)](https://sourceforge.net/projects/minebios/files/latest/download) 5 | 6 | Or Floppy Disk (1.44 mb): 7 | https://github.com/cppsever/MineBios/raw/main/MineBios.img 8 | 9 | ![png](https://github.com/cppsever/MineBios/blob/main/photo/1.png) 10 | ![png](https://github.com/cppsever/MineBios/blob/main/photo/2.png) 11 | 12 | And You can try: 13 | 14 | Virtual-box or Qemu: 15 | 16 | ``` 17 | qemu-system-x86_64 -boot d -cdrom MineBios.iso -m 512 18 | ``` 19 | 20 | ## Features 21 | > ✅ 100% Assembly 22 | > 23 | > ✅ Movement 24 | > 25 | > ✅ Basic physics 26 | > 27 | > ✅ Interaction 28 | > 29 | > ✅ Supported Qemu and Virtual-Box 30 | > 31 | > ✅ VGA renderer 32 | 33 | If you want to boot to your usb, boot the [MineBios.img](https://github.com/cppsever/MineBios/raw/main/MineBios.img) to your usb using [UNetbootin](https://unetbootin.github.io/). (Bios or uefi-csm must be on) 34 | 35 | ## Compiling 36 | 37 | Normal: 38 | 39 | ``` 40 | make 41 | ``` 42 | 43 | Iso compiling: 44 | 45 | ``` 46 | make iso 47 | ``` 48 | 49 | But you need: 50 | 51 | ``` 52 | sudo pacman -S qemu qemu-full cdrtools make nasm 53 | ``` 54 | 55 | ## Editor 56 | 57 | You can modify the game with these editors: 58 | 59 | > Image Editor : (Web site domain expired) 60 | 61 | In this image editor, add the code of your x=40 y=40 work to the bottom line. And adapt it to the function on line 285. 62 | 63 | ``` 64 | db_to_tx_namer: 65 | cmp [di], byte 7 66 | je .water 67 | (...) 68 | .water: 69 | mov si, tx_water 70 | jmp .done 71 | (...) 72 | tx_water: db (...) 73 | ``` 74 | 75 | And try your block with the start of the start_camera function 76 | 77 | ``` 78 | start_camera: 79 | mov [chunk+450*49+448], byte 7 80 | ``` 81 | 82 | 83 | > Map Editor : (Web site domain expired) 84 | 85 | When drawing, make x=450 y=100. Replace the code with `chunk` 86 | 87 | ## BTW 88 | 89 | ```diff 90 | + Actually the game itself (including texture and world) is 0.06 mb, but due to the Fat 12 file system it is at least 1.44 mb 91 | ``` 92 | 93 | ## And... 94 | 95 | ```diff 96 | - This is the first and last version of the project. There will be no further updates. :( 97 | ``` 98 | 99 | ## Thanks For Character Texture 100 | 101 | [SadikKidas](https://github.com/SadikKidas) 102 | 103 | ![png](https://github.com/cppsever/MineBios/blob/main/photo/3.png) 104 | -------------------------------------------------------------------------------- /photo/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppsever/MineBios/ca9831fa763c637e69b85e244dabe545343d84a8/photo/1.png -------------------------------------------------------------------------------- /photo/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppsever/MineBios/ca9831fa763c637e69b85e244dabe545343d84a8/photo/2.png -------------------------------------------------------------------------------- /photo/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cppsever/MineBios/ca9831fa763c637e69b85e244dabe545343d84a8/photo/3.png -------------------------------------------------------------------------------- /src/bootloader/boot.asm: -------------------------------------------------------------------------------- 1 | ; This code was taken from channel "nanobyte-dev" and modified. 2 | ; https://github.com/nanobyte-dev/nanobyte_os/blob/videos/part2/src/bootloader/boot.asm 3 | ; Thanks 4 | org 0x7C00 5 | bits 16 6 | 7 | %define ENDL 0x0D, 0x0A 8 | 9 | ; 10 | ; FAT12 header 11 | ; 12 | jmp short start 13 | nop 14 | 15 | bdb_oem: db 'MSWIN4.1' ; Oem id (sabit) (8 bytes) 16 | bdb_bytes_per_sector: dw 512 ; Sektör başına düşen byte 17 | bdb_sectors_per_cluster: db 1 18 | bdb_reserved_sectors: dw 1 19 | bdb_fat_count: db 2 20 | bdb_dir_entries_count: dw 0E0h 21 | bdb_total_sectors: dw 2880 ; 2880 * 512 = 1.44MB 22 | bdb_media_descriptor_type: db 0F0h ; F0 = 3.5" floppy disk 23 | bdb_sectors_per_fat: dw 9 ; 9 sectors/fat 24 | bdb_sectors_per_track: dw 18 25 | bdb_heads: dw 2 26 | bdb_hidden_sectors: dd 0 27 | bdb_large_sector_count: dd 0 28 | 29 | ; extended boot record 30 | ebr_drive_number: db 0 ; 0x00 floppy, 0x80 hdd, useless 31 | db 0 ; reserved 32 | ebr_signature: db 29h 33 | ebr_volume_id: db 23h, 23h, 23h, 23h ; 23 ? 34 | ebr_volume_label: db 'MineBios ' ; 11 bytes, padded with spaces 35 | ebr_system_id: db 'FAT12 ' ; 8 bytes 36 | 37 | ; 38 | ; Code goes here 39 | ; 40 | 41 | start: 42 | ; setup data segments 43 | mov ax, 0 ; can't set ds/es directly 44 | mov ds, ax 45 | mov es, ax 46 | 47 | ; setup stack 48 | mov ss, ax 49 | mov sp, 0x7C00 ; stack grows downwards from where we are loaded in memory 50 | 51 | ; some BIOSes might start us at 07C0:0000 instead of 0000:7C00, make sure we are in the 52 | ; expected location 53 | push es 54 | push word .after 55 | retf 56 | 57 | .after: 58 | 59 | ; read something from floppy disk 60 | ; BIOS should set DL to drive number 61 | mov [ebr_drive_number], dl 62 | 63 | ; show loading message 64 | mov si, msg_loading 65 | call puts 66 | 67 | ; read drive parameters (sectors per track and head count), 68 | ; instead of relying on data on formatted disk 69 | push es 70 | mov ah, 08h 71 | int 13h 72 | jc floppy_error 73 | pop es 74 | 75 | and cl, 0x3F ; remove top 2 bits 76 | xor ch, ch 77 | mov [bdb_sectors_per_track], cx ; sector count 78 | 79 | inc dh 80 | mov [bdb_heads], dh ; head count 81 | 82 | ; compute LBA of root directory = reserved + fats * sectors_per_fat 83 | ; note: this section can be hardcoded 84 | mov ax, [bdb_sectors_per_fat] 85 | mov bl, [bdb_fat_count] 86 | xor bh, bh 87 | mul bx ; ax = (fats * sectors_per_fat) 88 | add ax, [bdb_reserved_sectors] ; ax = LBA of root directory 89 | push ax 90 | 91 | ; compute size of root directory = (32 * number_of_entries) / bytes_per_sector 92 | mov ax, [bdb_dir_entries_count] 93 | shl ax, 5 ; ax *= 32 94 | xor dx, dx ; dx = 0 95 | div word [bdb_bytes_per_sector] ; number of sectors we need to read 96 | 97 | test dx, dx ; if dx != 0, add 1 98 | jz .root_dir_after 99 | inc ax ; division remainder != 0, add 1 100 | ; this means we have a sector only partially filled with entries 101 | .root_dir_after: 102 | 103 | ; read root directory 104 | mov cl, al ; cl = number of sectors to read = size of root directory 105 | pop ax ; ax = LBA of root directory 106 | mov dl, [ebr_drive_number] ; dl = drive number (we saved it previously) 107 | mov bx, buffer ; es:bx = buffer 108 | call disk_read 109 | 110 | ; search for kernel.bin 111 | xor bx, bx 112 | mov di, buffer 113 | 114 | .search_kernel: 115 | mov si, file_kernel_bin 116 | mov cx, 11 ; compare up to 11 characters 117 | push di 118 | repe cmpsb 119 | pop di 120 | je .found_kernel 121 | 122 | add di, 32 123 | inc bx 124 | cmp bx, [bdb_dir_entries_count] 125 | jl .search_kernel 126 | 127 | ; kernel not found 128 | jmp kernel_not_found_error 129 | 130 | .found_kernel: 131 | 132 | ; di should have the address to the entry 133 | mov ax, [di + 26] ; first logical cluster field (offset 26) 134 | mov [kernel_cluster], ax 135 | 136 | ; load FAT from disk into memory 137 | mov ax, [bdb_reserved_sectors] 138 | mov bx, buffer 139 | mov cl, [bdb_sectors_per_fat] 140 | mov dl, [ebr_drive_number] 141 | call disk_read 142 | 143 | ; read kernel and process FAT chain 144 | mov bx, KERNEL_LOAD_SEGMENT 145 | mov es, bx 146 | mov bx, KERNEL_LOAD_OFFSET 147 | 148 | .load_kernel_loop: 149 | 150 | ; Read next cluster 151 | mov ax, [kernel_cluster] 152 | 153 | ; not nice :( hardcoded value 154 | add ax, 31 ; first cluster = (kernel_cluster - 2) * sectors_per_cluster + start_sector 155 | ; start sector = reserved + fats + root directory size = 1 + 18 + 134 = 33 156 | mov cl, 1 157 | mov dl, [ebr_drive_number] 158 | call disk_read 159 | 160 | add bx, [bdb_bytes_per_sector] 161 | 162 | ; compute location of next cluster 163 | mov ax, [kernel_cluster] 164 | mov cx, 3 165 | mul cx 166 | mov cx, 2 167 | div cx ; ax = index of entry in FAT, dx = cluster mod 2 168 | 169 | mov si, buffer 170 | add si, ax 171 | mov ax, [ds:si] ; read entry from FAT table at index ax 172 | 173 | or dx, dx 174 | jz .even 175 | 176 | .odd: 177 | shr ax, 4 178 | jmp .next_cluster_after 179 | 180 | .even: 181 | and ax, 0x0FFF 182 | 183 | .next_cluster_after: 184 | cmp ax, 0x0FF8 ; end of chain 185 | jae .read_finish 186 | 187 | mov [kernel_cluster], ax 188 | jmp .load_kernel_loop 189 | 190 | .read_finish: 191 | 192 | ; jump to our kernel 193 | mov dl, [ebr_drive_number] ; boot device in dl 194 | 195 | mov ax, KERNEL_LOAD_SEGMENT ; set segment registers 196 | mov ds, ax 197 | mov es, ax 198 | 199 | jmp KERNEL_LOAD_SEGMENT:KERNEL_LOAD_OFFSET 200 | 201 | jmp wait_key_and_reboot ; should never happen 202 | 203 | cli ; disable interrupts, this way CPU can't get out of "halt" state 204 | hlt 205 | 206 | 207 | ; 208 | ; Error handlers 209 | ; 210 | 211 | floppy_error: 212 | mov si, msg_read_failed 213 | call puts 214 | jmp wait_key_and_reboot 215 | 216 | kernel_not_found_error: 217 | mov si, msg_kernel_not_found 218 | call puts 219 | jmp wait_key_and_reboot 220 | 221 | wait_key_and_reboot: 222 | mov ah, 0 223 | int 16h ; wait for keypress 224 | jmp 0FFFFh:0 ; jump to beginning of BIOS, should reboot 225 | 226 | .halt: 227 | cli ; disable interrupts, this way CPU can't get out of "halt" state 228 | hlt 229 | 230 | 231 | ; 232 | ; Prints a string to the screen 233 | ; Params: 234 | ; - ds:si points to string 235 | ; 236 | puts: 237 | ; save registers we will modify 238 | push si 239 | push ax 240 | push bx 241 | 242 | .loop: 243 | lodsb ; loads next character in al 244 | or al, al ; verify if next character is null? 245 | jz .done 246 | 247 | mov ah, 0x0E ; call bios interrupt 248 | mov bh, 0 ; set page number to 0 249 | int 0x10 250 | 251 | jmp .loop 252 | 253 | .done: 254 | pop bx 255 | pop ax 256 | pop si 257 | ret 258 | 259 | ; 260 | ; Disk routines 261 | ; 262 | 263 | ; 264 | ; Converts an LBA address to a CHS address 265 | ; Parameters: 266 | ; - ax: LBA address 267 | ; Returns: 268 | ; - cx [bits 0-5]: sector number 269 | ; - cx [bits 6-15]: cylinder 270 | ; - dh: head 271 | ; 272 | 273 | lba_to_chs: 274 | 275 | push ax 276 | push dx 277 | 278 | xor dx, dx ; dx = 0 279 | div word [bdb_sectors_per_track] ; ax = LBA / SectorsPerTrack 280 | ; dx = LBA % SectorsPerTrack 281 | 282 | inc dx ; dx = (LBA % SectorsPerTrack + 1) = sector 283 | mov cx, dx ; cx = sector 284 | 285 | xor dx, dx ; dx = 0 286 | div word [bdb_heads] ; ax = (LBA / SectorsPerTrack) / Heads = cylinder 287 | ; dx = (LBA / SectorsPerTrack) % Heads = head 288 | mov dh, dl ; dh = head 289 | mov ch, al ; ch = cylinder (lower 8 bits) 290 | shl ah, 6 291 | or cl, ah ; put upper 2 bits of cylinder in CL 292 | 293 | pop ax 294 | mov dl, al ; restore DL 295 | pop ax 296 | ret 297 | 298 | 299 | ; 300 | ; Reads sectors from a disk 301 | ; Parameters: 302 | ; - ax: LBA address 303 | ; - cl: number of sectors to read (up to 128) 304 | ; - dl: drive number 305 | ; - es:bx: memory address where to store read data 306 | ; 307 | disk_read: 308 | 309 | push ax ; save registers we will modify 310 | push bx 311 | push cx 312 | push dx 313 | push di 314 | 315 | push cx ; temporarily save CL (number of sectors to read) 316 | call lba_to_chs ; compute CHS 317 | pop ax ; AL = number of sectors to read 318 | 319 | mov ah, 02h 320 | mov di, 3 ; retry count 321 | 322 | .retry: 323 | pusha ; save all registers, we don't know what bios modifies 324 | stc ; set carry flag, some BIOS'es don't set it 325 | int 13h ; carry flag cleared = success 326 | jnc .done ; jump if carry not set 327 | 328 | ; read failed 329 | popa 330 | call disk_reset 331 | 332 | dec di 333 | test di, di 334 | jnz .retry 335 | 336 | .fail: 337 | ; all attempts are exhausted 338 | jmp floppy_error 339 | 340 | .done: 341 | popa 342 | 343 | pop di 344 | pop dx 345 | pop cx 346 | pop bx 347 | pop ax ; restore registers modified 348 | ret 349 | 350 | 351 | ; 352 | ; Resets disk controller 353 | ; Parameters: 354 | ; dl: drive number 355 | ; 356 | disk_reset: 357 | pusha 358 | mov ah, 0 359 | stc 360 | int 13h 361 | jc floppy_error 362 | popa 363 | ret 364 | 365 | 366 | msg_loading: db 'Loading...', ENDL, 0 367 | msg_read_failed: db 'Read from disk failed!', ENDL, 0 368 | msg_kernel_not_found: db 'KERNEL.BIN file not found!', ENDL, 0 369 | file_kernel_bin: db 'KERNEL BIN' 370 | kernel_cluster: dw 0 371 | 372 | KERNEL_LOAD_SEGMENT equ 0x2000 373 | KERNEL_LOAD_OFFSET equ 0x0 374 | 375 | 376 | times 510-($-$$) db 0 377 | dw 0AA55h 378 | 379 | buffer: 380 | 381 | --------------------------------------------------------------------------------