Skip to content

Commit c67edd3

Browse files
committed
Add DOS support
1 parent 0b96025 commit c67edd3

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
bootmine
1+
*.img
2+
*.com
23
bx_enh_dbg.ini
34
lst
45
TAGS

Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
QEMU = qemu-system-i386
44
BOCHS = bochs
55
NASM = nasm
6+
DOSBOX = dosbox
7+
DOSEMU = dosemu
68

7-
.PHONY: all clean qemu bochs
9+
.PHONY: all clean qemu bochs dosbox dosemu
810

9-
all: bootmine
11+
all: bootmine.img bootmine.com
1012

11-
bootmine: mine.asm
13+
bootmine.img: mine.asm
1214
$(NASM) $< -o $@
1315

16+
bootmine.com: mine.asm
17+
$(NASM) -DDOS $< -o $@
18+
1419
clean:
15-
rm -f bootmine
20+
rm -f bootmine.img bootmine.com
1621

17-
qemu: bootmine
22+
qemu: bootmine.img
1823
$(QEMU) $<
1924

20-
bochs: bootmine
25+
bochs: bootmine.img
2126
$(BOCHS) -q -f bochsrc.txt
27+
28+
dosbox: bootmine.com
29+
$(DOSBOX) $<
30+
31+
dosemu: bootmine.com
32+
$(DOSEMU) $<

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ make
2525

2626
## Installing
2727

28-
This 512-byte file `bootmine`, can be written to the first sector of a floppy disk (or USB drive), with a command like `dd if=bootmine of=/dev/sdb`. Keep in mind that this will effectively destroy all data on the drive.
28+
This 512-byte file `bootmine.img`, can be written to the first sector of a floppy disk (or USB drive), with a command like `dd if=bootmine.img of=/dev/sdb`. Keep in mind that this will effectively destroy all data on the drive.
2929

3030
### Emulation
3131

mine.asm

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ cpu 686
1212
;; Words in 16 bit x86 are 2 bytes
1313
%assign WordSize 2
1414

15+
;; Load address of DOS COM executables (relative to the cs segment)
16+
%assign DosComLoadAddress 0x100
17+
1518
;; This is the value to store in segment register to access the VGA text buffer.
1619
;; In 16 bit x86, segmented memory accesses are of the form:
1720
;;
@@ -68,7 +71,13 @@ cpu 686
6871
;; halves the amount of bombs.
6972
%assign BombFreq 0b111
7073

74+
;; BootMine is supported as both a DOS game and a boot sector game :)
75+
;; To build for DOS, run NASM with -DDOS and name the file with a .com extension
76+
%ifdef DOS
77+
org DosComLoadAddress
78+
%else
7179
org BootSector.Begin
80+
%endif
7281

7382
;; Entry point: set up graphics and run game
7483
BootMine:
@@ -167,8 +176,9 @@ PopulateTextBuf:
167176
; Save di since it will be clobbered later
168177
push di
169178
; Load adjacent cell offset from Dirs array into ax. Since the offset register
170-
; is bp, the segment register used is ss, which zero. This makes the memory
171-
; access relative to the start of RAM instead of the start of the text buffer.
179+
; is bp, the segment register used is ss, which is the same as cs. This makes
180+
; the memory access relative to BootMine's code instead of the start of the
181+
; text buffer.
172182
movsx ax, byte [bp + Dirs - 1]
173183
; Set di = pointer to adjacent cell
174184
add di, ax
@@ -527,11 +537,17 @@ GameOver:
527537
;; * bp - pointer to string
528538
;; * bx - color of string
529539
GameEndHelper:
540+
; Reset es segment register so printing the game end message works correctly.
541+
; When running as a boot sector, cs=0, so this will reset es to 0. When
542+
; running as a DOS COM executable, the original value of es will be the same
543+
; as cs. (COM executables set each segment register to the same value)
544+
;
545+
; es = cs
546+
mov di, cs
547+
mov es, di
548+
530549
mov ax, 0x1300
531550
mov dx, ((TextBuf.Height / 2) << 8) | (TextBuf.Width / 2 - GameOverStr.Len / 2)
532-
; es = 0
533-
xor di, di
534-
mov es, di
535551
int 0x10
536552

537553
;; Wait for restart key to be pressed, then restart game
@@ -548,12 +564,12 @@ WaitRestart:
548564
%warning Code is CodeSize bytes
549565

550566
CodeEnd:
567+
%ifndef DOS
551568
; Pad to size of boot sector, minus the size of a word for the boot sector
552569
; magic value. If the code is too big to fit in a boot sector, the `times`
553570
; directive uses a negative value, causing a build error.
554571
times (BootSector.Size - WordSize) - CodeSize db 0
555572

556573
; Boot sector magic
557574
dw 0xaa55
558-
559-
;; Boot sector ends here
575+
%endif

0 commit comments

Comments
 (0)