Skip to content

Commit

Permalink
Mitigated odd bug not allowing linkage of data labels, updated credit
Browse files Browse the repository at this point in the history
  • Loading branch information
jesings committed Apr 9, 2021
1 parent 752d282 commit 902512d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
33 changes: 15 additions & 18 deletions bootsweeper.S
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
.code16
#60 free bytes to play with
.global _start
#16x16 board, each tile is a single bit, mine or not
.data
x: .short 0
y: .byte 0
#The first byte here is technically part of y, but I use it here to simplify memory access
minecolors: .byte 0, 0x79, 0x72, 0x74, 0x71, 0x76, 0x73, 0x78
.text
.code16
.macro getrand #Credit goes to https://b2d-f9r.blogspot.com/2010/08/16-bit-xorshift-rng-now-with-more.html for the xorshift algorithm
#static uint16_t x=1,y=1;
#uint16_t t=(x^(x<<5));
movw x, %cx
movw (0x7df3), %cx
shlw $5, %cx
xorw x, %cx
xorw (0x7df3), %cx
#x=y;
movw y, %ax
movw %ax, x
movw (0x7df5), %ax
movw %ax, (0x7df3)
#return y=(y^(y>>1))^(t^(t>>3));
shrw %ax
xorw y, %ax
xorw (0x7df5), %ax
movw %cx, %bx
shrw $3, %bx
xorw %bx, %cx
xorw %ax, %cx
movw %cx, y
movw %cx, (0x7df5)
#Random number is now in %cx
.endm
#16x16 board, each tile is a single bit, mine or not
.text

_start:
xorw %ax, %ax
Expand All @@ -37,8 +32,8 @@ _start:
movw %ax, %ds
movb $0x02, %ah
int $0x1A #Read RTC value
movw %cx, x #Seed RNG
movw %dx, y #Seed RNG
movw %cx, (0x7df3) #Seed RNG
movw %dx, (0x7df5) #Seed RNG
newgame:
#initialize screen
xorw %ax, %ax
Expand All @@ -53,7 +48,9 @@ newgame:
movw $0xAB1, %ax
int $0x10 #print out 16 dummy characters for each row
getrand
andw x, %cx #And 2 random-ish numbers, making it so that on average 25% of tiles will be mines
mov %cx, %si
getrand
andw %si, %cx #And 2 random-ish numbers, making it so that on average 25% of tiles will be mines
movzxb %dh, %di
subw $0x5, %di#di is used for index in 16 bit
shlw %di
Expand Down Expand Up @@ -207,7 +204,7 @@ uncover3: #Print correct character for tile at cursor, if it is 0 call the flood
int $0x10
ret
nonzero:
leaw minecolors, %bx
leaw (0x7df6), %bx
movzx %al, %di
movb (%bx, %di), %bl
xorb %bh, %bh
Expand Down
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dosboxmine: mine
dosbox
mine:
as bootsweeper.S -o mine.o
ld -o mine.bin --oformat binary -e _start mine.o -T miner.ld
strip --remove-section=.note.gnu.property mine.o
ld -o mine.bin --oformat binary mine.o -T miner.ld
15 changes: 14 additions & 1 deletion miner.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ SECTIONS
. = 0x7c00;
.text :
{
mine.o (.*)
mine.o (.text)
. = 0x1FE - 0xb;
SHORT(0x0)
. = 0x1FE - 0x9;
BYTE(0x0)
. = 0x1FE - 0x8;
BYTE(0x0)
BYTE(0x79)
BYTE(0x72)
BYTE(0x74)
BYTE(0x71)
BYTE(0x76)
BYTE(0x73)
BYTE(0x78)
. = 0x1FE;
SHORT(0xAA55)
}
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The game features stunning 16 color text mode graphics, colored numbers, cursor

## How do I play?

In order to run the program, you must have the qemu, bochs, or DOSBox emulator installed (if you want to use a different emulator, feel free to configure that on your own). To run with qemu, simply use `make` and the program will compile and run! To run with bochs, use `make bochsmine` and then type `c` into the bottom input on the debug window. For DOSBox, run `dosboxmine` and then in the DOSBox command prompt type `boot mine.bin`.
In order to run the program, you must have the qemu, bochs, or DOSBox emulator installed (if you want to use a different emulator, feel free to configure that on your own). To run with qemu, simply use `make` and the program will compile and run! To run with bochs, use `make bochsmine` and then type `c` into the bottom input on the debug window. For DOSBox, run `dosboxmine` and then in the DOSBox command prompt, mount your host system directory as the C drive, go to the C drive, and `boot mine.bin`.

NOTE: In order to get arrow keys support on DOSBox (on my linux system), I needed to change usescancodes to false in ~/.dosbox/dosbox-0.74-3.conf (replace 0.74-3 with your version number).

Expand All @@ -26,9 +26,9 @@ NOTE: In order to get arrow keys support on DOSBox (on my linux system), I neede

## Also check out

https://gitlab.com/blevy/boot-sector-minesweeper
https://github.com/io12/bootmine

This is another minesweeper clone in the bootsector, it's got some interesting differences to this version, please check it out!
This is another minesweeper clone in the bootsector, it's got some interesting differences to this version (being 40x25, a slightly easier difficulty, it makes use of rdtsc), please check it out!

https://github.com/nanochess/bootOS

Expand Down

0 comments on commit 902512d

Please sign in to comment.