Removed the endx and y local vars from the filled rect function

Added checks for the filled rect function
Added comments for the filled rect function
This commit is contained in:
iDunnoDev
2022-11-16 00:43:03 +00:00
committed by iDunnoDev
parent c3113bc245
commit d679b2b6bf
6 changed files with 83 additions and 22 deletions

View File

@ -8,6 +8,12 @@
"type": "shell",
"command": "make qemu",
"problemMatcher": []
},
{
"label": "Build and QEMU (debug)",
"type": "shell",
"command": "make qemu-gdb",
"problemMatcher": []
}
]
}

View File

@ -257,13 +257,10 @@ cons_plot_pixel_end:
#define recty 6
#define rectx 4
#define rectendx -2
#define rectendy -4
cons_draw_filled_rect:
pushw %bp
movw %sp, %bp
subw $4, %sp # Make room for our local variables in the stack
#subw $4, %sp # Make room for our local variables in the stack
# Store existing register values to the stack so we can restore later
pushw %ax
@ -273,15 +270,73 @@ cons_draw_filled_rect:
pushw %si
pushw %di
cons_filled_rect_setup:
movw rectwidth(%bp), %ax
add rectx(%bp), %ax
movw %ax, rectendx(%bp)
movw rectheight(%bp), %bx
add recty(%bp), %bx
movw %bx, rectendy(%bp)
cons_filled_rect_check_x_dir:
movw rectwidth(%bp), %ax # Check if the user has entered a negative width value and swap the direction to a positive
cmpw $0, %ax
jge cons_filled_rect_check_y_dir
add %ax, rectx(%bp)
neg rectwidth(%bp)
cons_filled_rect_check_y_dir:
movw rectheight(%bp), %ax # Check if the user has entered a negative height value and swap the direction to a pos
cmpw $0, %ax
jge cons_filled_rect_check_x_zero
add %ax, recty(%bp)
neg rectheight(%bp)
cons_filled_rect_check_x_zero:
movw rectx(%bp), %ax # Check if the x value is a negative value, set it to 0 and figure out the offset so we
movw $0, %bx # dont write to unwanted memory locations
cmpw %bx, %ax
jge cons_filled_rect_check_x_screenwidth
movw %bx, rectx(%bp) # Set to x 0
sub %ax, %bx # get the distance from 0 to x
sub %bx, rectwidth(%bp) # take this away from the width
jmp cons_filled_rect_check_width_screenwidth
cons_filled_rect_check_x_screenwidth:
movw (screen_width), %bx # Check if the x is outside of the view port, if so just end the call
cmpw %bx, %ax # since it will never draw anything
jg cons_filled_rect_loop_end
cons_filled_rect_check_width_screenwidth:
add rectwidth(%bp), %ax
movw (screen_width), %bx # Check if the width ends up outside of the view port
cmpw %bx, %ax
jle cons_filled_rect_check_y_zero
sub %bx, %ax
sub %ax, rectwidth(%bp) # Remove the excess from the width value so we dont overflow memory
cons_filled_rect_check_y_zero:
movw recty(%bp), %ax # Check if the y value is a negative value, set it to 0 and figure out the offset so we
movw $0, %bx # dont write to unwanted memory locations
cmpw %bx, %ax
jge cons_filled_rect_check_y_screenheight
movw %bx, recty(%bp) # Set to y 0
sub %ax, %bx # get the distance from 0 to y
sub %bx, rectheight(%bp) # take this away from the height
jmp cons_filled_rect_check_height_screenheight
cons_filled_rect_check_y_screenheight:
movw (screen_height), %bx # Check if the y is outside of the view port, if so just end the call
cmpw %bx, %ax # since it will never draw anything
jg cons_filled_rect_loop_end
cons_filled_rect_check_height_screenheight:
add rectheight(%bp), %ax
movw (screen_height), %bx # Check if the width ends up outside of the view port
cmpw %bx, %ax
jle cons_filled_rect_setup
sub %bx, %ax
sub %ax, rectheight(%bp) # Remove the excess from the width value so we dont overflow memory
cons_filled_rect_check_empty:
cmpw $0, rectwidth(%bp) # Check if the width or height is now zero, end the function if so
jle cons_filled_rect_loop_end
cmpw $0, rectheight(%bp)
jle cons_filled_rect_loop_end
cons_filled_rect_setup:
movw $0xA000, %bx # Set the start of the video memory location
movw %bx, %es # Move that address into the "extra segment" es register
@ -290,21 +345,21 @@ cons_filled_rect_setup:
mul %dx # does the (y * 320) part of our math
add rectx(%bp), %ax # Add the value of x to register ax
movw %ax, %si
lea %es:(%si), %bx # Move the value of ax into the si counter
lea %es:(%si), %bx # Load the memory address into the bx register
movw rectheight(%bp), %si
movw rectheight(%bp), %si # Set the counter to our height which should be the number of lines to draw to
cons_filled_rect_loop_start:
movw rectcolor(%bp), %ax
movw %bx, %di
movw rectwidth(%bp), %cx
cld
rep stosb
movw rectcolor(%bp), %ax # Set the color byte for our rep
movw %bx, %di # move the memory location to the di counter
movw rectwidth(%bp), %cx # Set cx to our width so the rep knows when to end
cld # Clear the direction flag so our rep counter inc's
rep stosb # Run the stosb to copy bytes into the data segment til cx is 0
movw (screen_width), %cx
add %cx, %bx
add %cx, %bx # Add 320 to our current y value for the next line
dec %si
dec %si # Dex the height counter til we hit 0
jnz cons_filled_rect_loop_start

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
stage4/xv6.img (Stored with Git LFS)

Binary file not shown.