├── mbr ├── bochsrc.bxrc ├── snake ├── snake.gif ├── snake.img ├── snake.ova ├── snake.vdi ├── virutalbox.txt ├── Makefile ├── snake.vmdk ├── mbr.s ├── function.s ├── README.md └── snake.s /mbr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nongiach/snake_boot_sector/HEAD/mbr -------------------------------------------------------------------------------- /bochsrc.bxrc: -------------------------------------------------------------------------------- 1 | boot:a 2 | floppya: 1_44=snake.img, status=inserted 3 | 4 | -------------------------------------------------------------------------------- /snake: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nongiach/snake_boot_sector/HEAD/snake -------------------------------------------------------------------------------- /snake.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nongiach/snake_boot_sector/HEAD/snake.gif -------------------------------------------------------------------------------- /snake.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nongiach/snake_boot_sector/HEAD/snake.img -------------------------------------------------------------------------------- /snake.ova: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nongiach/snake_boot_sector/HEAD/snake.ova -------------------------------------------------------------------------------- /snake.vdi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nongiach/snake_boot_sector/HEAD/snake.vdi -------------------------------------------------------------------------------- /virutalbox.txt: -------------------------------------------------------------------------------- 1 | 1: 2 | sudo losetup /dev/loop0 3 | vboxmanage internalcommands createrawvmdk -filename snake.vmdk -rawdisk /dev/loop0 4 | 5 | 2: 6 | VBoxManage convertfromraw snake.img snake.vdi --format vdi 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SIZE=512 2 | 3 | NAME = snake.img 4 | 5 | all : 6 | nasm mbr.s 7 | nasm snake.s 8 | cat mbr snake /dev/zero | dd of=$(NAME) bs=512 count=2280 9 | 10 | sdb : 11 | sudo dd bs=512 if=$(NAME) of=/dev/sdb 12 | 13 | dis : 14 | ndisasm -b 16 $(NAME) 15 | 16 | fclean clean : 17 | rm -f $(NAME) mbr snake 18 | 19 | re : fclean all 20 | 21 | -------------------------------------------------------------------------------- /snake.vmdk: -------------------------------------------------------------------------------- 1 | # Disk DescriptorFile 2 | version=1 3 | CID=609a7856 4 | parentCID=ffffffff 5 | createType="fullDevice" 6 | 7 | # Extent description 8 | RW 2280 FLAT "/dev/loop0" 0 9 | 10 | # The disk Data Base 11 | #DDB 12 | 13 | ddb.virtualHWVersion = "4" 14 | ddb.adapterType="ide" 15 | ddb.geometry.cylinders="2" 16 | ddb.geometry.heads="16" 17 | ddb.geometry.sectors="63" 18 | ddb.uuid.image="8e31a5d3-928d-460e-abb9-ec34013ee1e4" 19 | ddb.uuid.parent="00000000-0000-0000-0000-000000000000" 20 | ddb.uuid.modification="00000000-0000-0000-0000-000000000000" 21 | ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000" 22 | ddb.geometry.biosCylinders="2" 23 | ddb.geometry.biosHeads="16" 24 | ddb.geometry.biosSectors="63" 25 | -------------------------------------------------------------------------------- /mbr.s: -------------------------------------------------------------------------------- 1 | ; boot loader 2 | %define BASE 0x100 ; 0x0100:0x0 = 0x1000 3 | %define KSIZE 2 ; nbr de secteurs de 512 octets a charger 4 | 5 | [BITS 16] 6 | [ORG 0] 7 | 8 | jmp 07C0h:start 9 | 10 | msg db 'Chargement du snake', 0 11 | bootdrv db 0 12 | 13 | %include "function.s" 14 | 15 | start: 16 | mov ax, cs 17 | mov ds, ax 18 | mov es, ax 19 | 20 | mov ax, 0x8000 21 | mov ss, ax 22 | mov sp, 0xf000 23 | 24 | ; recuperation de l'unite de boot 25 | mov [bootdrv], dl 26 | 27 | mov si, msg 28 | call print 29 | 30 | ; dump le dans la ram 31 | mov ax, 0 32 | mov dl, [bootdrv] 33 | int 13h ; init le disk 34 | 35 | push es 36 | mov ax, BASE 37 | mov es, ax 38 | mov bx, 0 39 | 40 | mov ah, 2 41 | mov al, KSIZE 42 | mov ch, 0 43 | mov cl, 2 44 | mov dh, 0 45 | mov dl, [bootdrv] 46 | int 13h 47 | pop es 48 | 49 | ; saut vers le dump 50 | jmp word BASE:0 51 | 52 | times 510-($-$$) db 0 ; fill the file with 0 53 | dw 0AA55h ; End of the file with AA55 54 | -------------------------------------------------------------------------------- /function.s: -------------------------------------------------------------------------------- 1 | ; function.s 2 | [BITS 16] 3 | 4 | print: 5 | lodsb 6 | 7 | cmp al, 0 8 | je _print 9 | mov bl, 4 10 | call putchar_ 11 | ;call getcurs 12 | ;inc dl 13 | ;call putcurs 14 | jmp print 15 | _print: 16 | ret 17 | 18 | getkey: 19 | mov ax, 0 20 | int 16h 21 | ret 22 | 23 | getkey_: 24 | mov ax, 0 25 | mov ah, 1 26 | int 16h 27 | jz _getkey 28 | call getkey 29 | _getkey: 30 | ret 31 | ; al : ascii ==> ax 32 | 33 | 34 | 35 | putchar: 36 | ; char al, color bl 37 | mov ah, 9 38 | mov bh, 0 39 | mov cx, 1 40 | int 10h 41 | ret 42 | 43 | putchar_: ; mode teletype 44 | ; char al, color bl 45 | mov ah, 0Eh 46 | mov bh, 0 47 | int 10h 48 | ret 49 | 50 | getchar: 51 | mov ah, 8 52 | mov bh, 0 53 | int 10h 54 | ; char al, color bl 55 | 56 | getcurs: 57 | mov ah, 3 58 | mov bh, 0 59 | int 10h 60 | ret 61 | ; x: dl, y: dh 62 | 63 | putcurs: 64 | ; x : dl, y : dh 65 | mov ah, 2 66 | mov bh, 0 67 | int 10h 68 | ret 69 | 70 | ;get_time: 71 | ; mov ah, 0 72 | ; int 1Ah 73 | ; ret 74 | ; ; cx:dx => time 75 | 76 | last dw 3749h 77 | 78 | random: 79 | mov ax, [last] 80 | mov dx, 8405h 81 | mul dx 82 | cmp dx, [last] 83 | jne _random 84 | mov ah, dl 85 | inc ax 86 | _random: 87 | mov [last], ax 88 | ; ax and dx <== rand mov ax, dx 89 | ret 90 | 91 | sleep: 92 | ; time : cx:dx 93 | mov ah, 86h 94 | int 15h 95 | ret 96 | 97 | putnbr: ; nbr = ax 98 | 99 | ; mov bx, 10 100 | ; div bx 101 | ; mov dx, 0 102 | ; push dx 103 | ; cmp bx, 0 104 | ; je put_nbr_ 105 | ; mov ax, bx 106 | ; call putnbr 107 | ;put_nbr_: pop ax 108 | ; add al, '0' 109 | ; call putchar_ 110 | ; ret 111 | 112 | ; int 10h BIP 113 | 114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Snake game on MBR 2 | 3 | Hi folks! Here is one of my one weekend project that I made back in 2013. 4 | 5 | 6 | # What is this ? 7 | 8 | A custom MBR (Master Boot Record) booting a snake game. Once installed on an usb flash drive it will boot instead of your system. 9 | 10 | # ScreenToGif 11 | 12 | ![Alt Text](/snake.gif) 13 | 14 | ## Start from [qemu](https://www.qemu.org/) 15 | 16 | ```sh 17 | $ qemu-system-i386 snake.img 18 | ``` 19 | 20 | ## Start from [Virtualbox](https://www.virtualbox.org/) 21 | 22 | Import snake.ova from virtualbox and start !! 23 | 24 | ## Start on your hardware using an USB key 25 | 26 | ```sh 27 | $ sudo dd bs=512 if=snake.img of=/dev/YOUR_USB_KEY_DEVICE 28 | ``` 29 | 30 | *Replace YOUR_USB_KEY_DEVICE by your usb device (example: sdb or sdc).* Be careful if you choose the wrong device your computer might break. 31 | **WARNING:** This command will cause your USB device to lose any data present on it. 32 | 33 | Booting on this USB device will not harm your computer. 34 | 35 | ## Start from [bochs](http://bochs.sourceforge.net) 36 | 37 | Tested using bochs [BIOS v2.6.2](http://bochs.sourceforge.net/cgi-bin/lxr/source/bios/BIOS-bochs-latest?raw=1&v=2.6.2) and [VGABIOS v2.6.2](http://bochs.sourceforge.net/cgi-bin/lxr/source/bios/VGABIOS-lgpl-latest?raw=1&v=2.6.2). 38 | 39 | ```sh 40 | $ bochs 41 | ``` 42 | 43 | If the bios is not found by bochs, create a dedicated configuration file and include it at runtime with 44 | 45 | ```sh 46 | $ bochs '#include PATH/TO/YOUR/CONFIGURATION/FILE' 47 | ``` 48 | 49 | *Note: when using git bash in windows, the path should be formatted for windows ("c:\PATH\TO\FILE") instead of an unix path ("/c/PATH/TO/FILE")* 50 | 51 | --- 52 | 53 | By [@chaign\_c][] [#HexpressoTeam][hexpresso]. 54 | 55 | 56 | [hexpresso]: https://hexpresso.github.io 57 | [@chaign\_c]: https://twitter.com/chaign_c 58 | -------------------------------------------------------------------------------- /snake.s: -------------------------------------------------------------------------------- 1 | ; kernel.s 2 | [BITS 16] 3 | [ORG 0] 4 | 5 | 6 | mov ax, 0x100 7 | mov ds, ax 8 | mov es, ax 9 | 10 | mov ax, 0x8000 11 | mov ss, ax 12 | mov sp, 0xf000 13 | 14 | jmp start 15 | 16 | msg db '<-----------Snake----------->', 0 17 | msg1 db ' GAME OVER', 0 18 | 19 | dir equ 0 20 | speed equ 0x99FF 21 | 22 | x equ 1 23 | y equ 2 24 | _x equ 3 25 | _y equ 4 26 | 27 | lx equ 5 28 | ly equ 6 29 | 30 | %include "function.s" 31 | 32 | gere_key : 33 | left: cmp ax, 4B00h 34 | jne right 35 | mov byte [dir], 0 36 | jmp _gerekey 37 | right: cmp ax, 4D00h 38 | jne up 39 | mov byte [dir], 1 40 | jmp _gerekey 41 | up: cmp ax, 4800h 42 | jne down 43 | mov byte [dir], 2 44 | jmp _gerekey 45 | down: cmp ax, 5000h 46 | jne n 47 | mov byte [dir], 3 48 | jmp _gerekey 49 | n: cmp ax, 'n' 50 | jne _gerekey 51 | mov si, 0 52 | _gerekey: 53 | ret 54 | 55 | move: ; dir dl, x al, y, bh 56 | m_left: cmp dl, 0 57 | jne m_right 58 | dec al 59 | jmp _move 60 | m_right:cmp dl, 1 61 | jne m_up 62 | inc al 63 | jmp _move 64 | m_up: cmp dl, 2 65 | jne m_down 66 | dec ah 67 | jmp _move 68 | m_down: cmp dl, 3 69 | jne _move 70 | inc ah 71 | jmp _move 72 | _move: 73 | ret 74 | 75 | aff_snake: 76 | mov dl, byte [x] ; aff '0' 77 | mov dh, byte [y] 78 | call putcurs 79 | call getchar 80 | push ax 81 | 82 | mov al, 'O' 83 | mov bl, 1 84 | call putchar 85 | 86 | mov dl, byte [lx] ; aff '#' 87 | mov dh, byte [ly] 88 | call putcurs 89 | mov al, byte [dir] 90 | add al, 23h 91 | mov bl, 1 92 | call putchar 93 | mov al, byte [x] 94 | mov byte [lx], al 95 | mov al, byte [y] 96 | mov byte [ly], al 97 | 98 | pop ax 99 | cmp al, '@' 100 | je add_item 101 | cmp al, ' ' 102 | jne game_over 103 | 104 | 105 | mov dl, byte [_x] ; aff ' ' 106 | mov dh, byte [_y] 107 | call putcurs 108 | 109 | call getchar 110 | mov dl, al 111 | 112 | mov al, ' ' 113 | mov bl, 1 114 | call putchar 115 | 116 | sub dl, 23h 117 | mov al, byte [_x] 118 | mov ah, byte [_y] 119 | call move 120 | mov byte [_x], al 121 | mov byte [_y], ah 122 | 123 | _aff_snake: 124 | ret 125 | 126 | add_item: 127 | mov si, 16 128 | add_item_: 129 | mov dx, [speed] 130 | add dx, 3 131 | mov [speed], dx 132 | call random 133 | mov dh, ah 134 | push dx 135 | call random 136 | pop dx 137 | mov dl, ah 138 | call putcurs 139 | mov al, '@' 140 | mov bl, 0xA 141 | call putchar 142 | cmp si, 0 143 | dec si 144 | jne add_item_ 145 | ret 146 | 147 | start: 148 | mov ax, cs 149 | mov ds, ax 150 | mov es, ax 151 | 152 | ;mov ah, 1 153 | ;mov ch, 1 154 | ;mov cl, 1 sensed disable vursor 155 | ;int 10h 156 | mov dx, 0 157 | init: ; clear screen 158 | call putcurs 159 | mov al, ' ' 160 | mov ah, 9 161 | mov bh, 0 162 | mov cx, 0xFF 163 | int 10h 164 | inc dh 165 | cmp dh, 0xFF 166 | jne init 167 | 168 | 169 | mov dl, 26 170 | mov dh, 2 171 | call putcurs 172 | 173 | ;mov si, msg 174 | ;call print 175 | 176 | mov byte [x], 5 177 | mov byte [y], 5 178 | mov byte [lx], 4 179 | mov byte [ly], 5 180 | mov byte [_x], 4 181 | mov byte [_y], 5 182 | mov byte [dir], 1 183 | call add_item 184 | 185 | boucle: 186 | call aff_snake 187 | call getkey_ 188 | call gere_key 189 | 190 | mov dl, byte [dir] 191 | mov al, byte [x] 192 | mov ah, byte [y] 193 | call move 194 | mov byte [x], al 195 | mov byte [y], ah 196 | 197 | mov cx, 1 198 | mov dx, [speed] 199 | call sleep 200 | mov dl, 3 201 | mov dh, 3 202 | call putcurs 203 | mov ax, [speed] 204 | ; call putnbr 205 | jmp boucle 206 | 207 | game_over: 208 | mov dl, 30 209 | mov dh, 11 210 | call putcurs 211 | mov si, msg1 212 | call print 213 | call getkey 214 | cmp al, ' ' 215 | je start 216 | jmp game_over 217 | 218 | --------------------------------------------------------------------------------