Skip to content

Commit

Permalink
extract game from bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Bernhardt committed Jan 25, 2017
1 parent 87f50bb commit d6bfa01
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
41 changes: 41 additions & 0 deletions bootloader.asm
@@ -0,0 +1,41 @@
; initialize the environment
mov ax, 0x07c0
mov ds, ax

; the segment of the game
mov ax, 0x07e0

; setup the file-source
mov ch, 0x00 ; cylinder 0
mov cl, 0x02 ; sector 2 (skip first sector, which is the bootloader)
mov dh, 0x00 ; head 0
mov dl, 0x00 ; drive 0 (floppy disk)

; setup the destination
mov es, ax ; segment starts directly after the bootloader (7c00 - 7dff)
mov bx, 0x0000

; copy data into RAM
read:
mov al, 0x02 ; read two sectors
mov ah, 0x02 ; int 13h subfunction 2 -> read sectors (512 bytes) from disk
int 0x13 ; copy sectors to ES:BX
jc read ; carry-flag is set -> there was a read-error, retry

; rebase segments for game execution
mov ax, 0x07e0
mov ds, ax ; data segment
mov es, ax ; additional segments
mov fs, ax
mov gs, ax
mov ss, ax ; stack segment

; reset stack pointer
; mov sp, 0x0000

; enter the game code -> set CS:IP
jmp 0x07e0:0x0000

; spacing and signature
times 510 - ($ - $$) db 0
dw 0xaa55
Binary file added build/bootloader.bin
Binary file not shown.
Binary file added build/image.bin
Binary file not shown.
Binary file added build/space-invaders.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions scripts/create.sh
@@ -0,0 +1,5 @@
nasm bootloader.asm -f bin -o build/bootloader.bin
nasm space-invaders.asm -f bin -o build/space-invaders.bin

dd if=build/bootloader.bin of=build/image.bin bs=512 count=1
dd if=build/space-invaders.bin of=build/image.bin bs=512 count=2 seek=1
1 change: 1 addition & 0 deletions scripts/start.sh
@@ -0,0 +1 @@
qemu-system-x86_64 -fda build/image.bin
14 changes: 4 additions & 10 deletions si.asm → space-invaders.asm
@@ -1,11 +1,7 @@
; initialize the environment
mov ax, 0x07c0
mov ds, ax ; set the DS to the start of the programm
; this has to be indirectly, since all segement-registers can not directly be written to.

; clear the cursor blinking
mov ah, 0x01
mov cx, 0x2000
int 0x10 ; clear the cursor blinking
int 0x10

; calculate game screen position
mov ah, 0x0F
Expand All @@ -18,7 +14,6 @@ mov [displayOffset], ah
; initialize the bullet list by setting the end-pointer to the list-start
mov word [bulletListEnd], bulletListStart


; game logic
gameLoop:
call clearScreen
Expand Down Expand Up @@ -324,6 +319,5 @@ bulletListStart db 0x00


; ################################################
; spacing and signature
times 510 - ($ - $$) db 0
dw 0xaa55
; spacing
times 1014 - ($ - $$) db 0
23 changes: 0 additions & 23 deletions test

This file was deleted.

0 comments on commit d6bfa01

Please sign in to comment.