Skip to content

Commit

Permalink
polish balance and messaging at beginning and end (#3)
Browse files Browse the repository at this point in the history
* bootloader println

* Some keyboard interactivity

* 2 newlines

* player is smiley and game is winnable

* more balance and exit message
  • Loading branch information
metavee authored Aug 6, 2024
1 parent 549226f commit a686e59
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ build-bootloader: build-stage2
file_size=$(wc -c < "{{stage2_out}}")
num_sectors=$(( (file_size + SECTOR_SIZE - 1) / SECTOR_SIZE ))

nasm -f bin -DNUM_SECTORS=$num_sectors -o {{bootloader_out}} {{bootloader_in}}
nasm -f bin -DNUM_SECTORS=$num_sectors -DNUM_SECTORS_STR="\"$num_sectors\"" -o {{bootloader_out}} {{bootloader_in}}

build-stage2:
nasm -f bin -D BOOT -o {{stage2_out}} {{infile}} -l {{listing_out}}
Expand Down
35 changes: 30 additions & 5 deletions bootloader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ start:
mov [boot_drive], dl

; Display a message to indicate bootloader is running
mov si, msg
call print_string
mov si, init_msg
call println

mov si, loading_msg
call println

; Load the second sector from the disk
; Use the drive number in 'boot_drive'
Expand All @@ -25,16 +27,20 @@ start:
; Check for errors
jc disk_error ; If carry flag is set, there was an error

mov si, ready_msg
call println
call read_keyboard

; Jump to loaded code
jmp 0x0000:0x0600 ; Segment:Offset where the second sector is loaded

disk_error:
; Display error message and halt
mov si, err_msg
call print_string
call println
jmp $

print_string:
println:
push ax
push si
mov ah, 0x0E ; BIOS teletype function
Expand All @@ -46,13 +52,32 @@ print_char:
inc si
jmp print_char
print_done:
; 2 newlines
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10

pop si
pop ax
ret

; read keylevel input into AL; trash AH
read_keyboard:
mov ah,0x00 ; set AH for keylevel read
int 0x16 ; call interrupt to read keylevel

ret ; returns to caller

boot_drive db 0 ; Storage for boot drive number

msg db 'Bootloader running...', 0
init_msg db 'Bootloader running...', 0
ready_msg db 'Loaded program into memory. Press any key to boot.', 0
loading_msg db 'Loading ', NUM_SECTORS_STR, ' sectors from disk...', 0
err_msg db 'Disk load error', 0

times 510-($-$$) db 0 ; Fill the rest of the 512 bytes with zeros
Expand Down
19 changes: 16 additions & 3 deletions puzdug.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ player_addr: equ entity_arr
player_health_str_addr: equ (hp_str + 4)
enemy_str_addr: equ (enemy_str + 5)

player_start_hp: equ 125
player_start_hp: equ 150
player_atk: equ 20
enemy_start_hp: equ 100
enemy_atk: equ 15
Expand All @@ -47,7 +47,7 @@ screen_height: equ 25
wall_char: equ 0x04b2 ; black bg, red fg, heavy texture ▓
empty_char: equ 0x072e ; black bg, grey fg, .
fog_char: equ 0x07f7 ; black bg, grey fg, almost equal ≈
player_char: equ 0x0f40 ; black bg, white fg, @
player_char: equ 0x0f01 ; black bg, white fg, smiley
house_char: equ 0x0d7f ; black bg, pink fg, house symbol
tree_char: equ 0x0206 ; black bg, green fg, spade symbol

Expand Down Expand Up @@ -428,8 +428,14 @@ do_lose_wait:
call waiter
loop do_lose_wait
do_exit:
call scroll_cursor
mov bx,exit_str
mov dl,2
mov dh,20
mov ah, 0x0f ; white text black bg
call draw_text
%ifdef DOS
call read_keyboard
call scroll_cursor
int 0x20
%else
jmp $ ; infinite loop
Expand Down Expand Up @@ -724,6 +730,13 @@ game_over_str:
victory_str:
db "VICTORY ATTAINED", 0

exit_str:
%ifdef DOS
db "The game has ended. Press any key to exit", 0
%else
db "The game has ended. You may now power off your computer", 0
%endif

scroll_cursor:
; scroll the screen by typing one page full of newlines in teletype
mov cx, screen_height
Expand Down

0 comments on commit a686e59

Please sign in to comment.