From 902512d8c05a065968581c65a50c22cfc591012a Mon Sep 17 00:00:00 2001 From: jesings <34111484+jesings@users.noreply.github.com> Date: Fri, 9 Apr 2021 12:16:04 -0500 Subject: [PATCH] Mitigated odd bug not allowing linkage of data labels, updated credit --- bootsweeper.S | 33 +++++++++++++++------------------ makefile | 3 ++- miner.ld | 15 ++++++++++++++- readme.md | 6 +++--- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/bootsweeper.S b/bootsweeper.S index c8d678e..d322b84 100644 --- a/bootsweeper.S +++ b/bootsweeper.S @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/makefile b/makefile index ed90f6b..a201c28 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/miner.ld b/miner.ld index 712ee07..e31596a 100644 --- a/miner.ld +++ b/miner.ld @@ -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) } diff --git a/readme.md b/readme.md index bc31600..4f9afa4 100644 --- a/readme.md +++ b/readme.md @@ -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). @@ -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