diff --git a/stage4/.vscode/tasks.json b/stage4/.vscode/tasks.json index 51722d9..c567be5 100644 --- a/stage4/.vscode/tasks.json +++ b/stage4/.vscode/tasks.json @@ -8,6 +8,12 @@ "type": "shell", "command": "make qemu", "problemMatcher": [] + }, + { + "label": "Build and QEMU (debug)", + "type": "shell", + "command": "make qemu-gdb", + "problemMatcher": [] } ] } \ No newline at end of file diff --git a/stage4/bootasm2.S b/stage4/bootasm2.S index 1d187b0..6d15cf7 100644 --- a/stage4/bootasm2.S +++ b/stage4/bootasm2.S @@ -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 diff --git a/stage4/bootasm2.o b/stage4/bootasm2.o index a7f25f3..6c43a64 100644 Binary files a/stage4/bootasm2.o and b/stage4/bootasm2.o differ diff --git a/stage4/bootblock2 b/stage4/bootblock2 index 98b529f..dda25ec 100644 Binary files a/stage4/bootblock2 and b/stage4/bootblock2 differ diff --git a/stage4/bootblock2.o b/stage4/bootblock2.o index 4c928c9..ad38871 100644 Binary files a/stage4/bootblock2.o and b/stage4/bootblock2.o differ diff --git a/stage4/xv6.img b/stage4/xv6.img index 6f9ef93..6ffd19d 100644 --- a/stage4/xv6.img +++ b/stage4/xv6.img @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0e72ff56ad3e3b45619ce85e77f8a521e4ab77e93fc1b0154d51ccc93efc416a +oid sha256:91937ee0ce0a78815628538f19ff3ee6cf003e740e7815fb11539871c39e068e size 5120000