Added comments to the source code for stage 1

Changed the parameters for the function to load into registers
Changed all the data types to words instead of int in case ints are not allowed
This commit is contained in:
iDunnoDev
2022-11-05 11:21:06 +00:00
committed by iDunnoDev
parent 9efe950b7b
commit d7f3c20324
5 changed files with 112 additions and 75 deletions

View File

@ -38,6 +38,8 @@ cons_writeline:
call cons_write_crlf call cons_write_crlf
ret ret
# Added Write Hex and Int functions to help with debugging
HexChars: .ascii "0123456789ABCDEF" HexChars: .ascii "0123456789ABCDEF"
cons_write_hex: cons_write_hex:
@ -84,72 +86,78 @@ getdigit:
IntBuffer: .string " " IntBuffer: .string " "
cons_draw_line: cons_draw_line:
movw $0, err movw $0, err # Make sure that err starts at 0
movw x1, %cx movw %ax, (x0) # Move the initial vars from the registers to static memory
movw y1, %dx movb %cl, (y0)
sub x0, %cx movw %bx, (x1)
movb %ch, (y1)
movb %dl, (color)
movw x1, %cx # Load x1 and y1 into the registers
movw y1, %dx
sub x0, %cx # Remove x/y0 from x/y1 to get the delta values
sub y0, %dx sub y0, %dx
movw %cx, (deltax) movw %cx, (deltax) # Store the delta values
movw %dx, (deltay) movw %dx, (deltay)
cons_line_check_x: cons_line_check_x:
movw x0, %cx movw x0, %cx # Load x0 into register cx so we can manipulate this value to plot each pixel
movw $1, (sx) movw $1, (sx) # Preload x slope with 1
cmp x1, %cx cmp x1, %cx # Check if x1 is less than x0 and we can move to y
jl cons_line_check_y jl cons_line_check_y
negw sx negw sx # if x1 is greater than we need to flip the slope and the x delta values
negw deltax negw deltax
cons_line_check_y: cons_line_check_y:
movw y0, %dx movw y0, %dx # Load y0 into register dx so we can manipulate this value to plot each pixel
movw $1, (sy) movw $1, (sy) # Preload y slope with 1
cmpw y1, %dx cmpw y1, %dx # Check if y1 is less than y0 and we can start our plotting
jl cons_line_prep_loop jl cons_line_prep_loop
negw sy negw sy # if y1 is greater than we need to flip the slope y and delta y values
negw deltay negw deltay
cons_line_prep_loop: cons_line_prep_loop:
movw deltax, %ax movw deltax, %ax # Calculate the err variable by subtracting delta y from delta x
sub deltay, %ax sub deltay, %ax
movw %ax, (err) movw %ax, (err)
cons_line_loop_start: cons_line_loop_start:
xor %ax, %ax xor %ax, %ax # Clear ax and bx for use with the draw function
xor %bx, %bx xor %bx, %bx
movb $0x0c, %ah movb $0x0c, %ah # Set the function byte to plot the pixel
movb $0, %bh movb $0, %bh # Set the video page number
movb (color), %al movb (color), %al # Set the color of the pixel
int $0x10 int $0x10 # Call the int
cmpw x1, %cx cmpw x1, %cx # Check if x0 and x1 are equal, if not then we are still plotting
jne cons_line_loop_next_point jne cons_line_loop_next_point
cmpw y1, %dx cmpw y1, %dx # Check if y0 and y1 are equal, if not then we are still plotting
jne cons_line_loop_next_point jne cons_line_loop_next_point
jmp cons_line_loop_end jmp cons_line_loop_end # if both x's and y's are equal then we can end the function
cons_line_loop_next_point: cons_line_loop_next_point:
movw err, %ax movw err, %ax # Load err into ax so that we can multiply it
add %ax, %ax add %ax, %ax # e2 is 2 * err, so we can just add err to itself
cons_line_loop_move_y_point: cons_line_loop_move_y_point:
movw deltay, %bx movw deltay, %bx
negw %bx negw %bx # We need negative deltay to compare
cmpw %bx, %ax cmpw %bx, %ax # Check if we need to apply the slope value to y
jle cons_line_loop_move_x_point jle cons_line_loop_move_x_point
negw %bx negw %bx # Change deltay back to normal
subw %bx, err subw %bx, err # Remove the deltay from the err check
addw sx, %cx addw sx, %cx # Add the slope value to the current y value
cons_line_loop_move_x_point: cons_line_loop_move_x_point:
movw deltax, %bx movw deltax, %bx
cmpw %bx, %ax cmpw %bx, %ax # Check if we need to apply the x slope value
jge cons_line_loop_start jge cons_line_loop_start
addw %bx, err addw %bx, err # Add the deltax to the err value
addw sy, %dx addw sy, %dx # Add the slope value to the current x value
jmp cons_line_loop_start jmp cons_line_loop_start # Go back to the start of the loop
cons_line_loop_end: cons_line_loop_end:
ret ret # Finish the loop and return to the call address
real_start: real_start:
movw $boot_message, %si # Display our boot message movw $boot_message, %si # Display our boot message
@ -162,46 +170,75 @@ draw_start:
int $0x10 int $0x10
xor %ax, %ax xor %ax, %ax
movw $50, x0 movw $50, %ax # Plot a line, ax = x0, bx = x1, cl = y0, ch = y1, dl = color
movw $50, y0 movb $50, %cl # the X values require a full register but the y's only require a byte since the max value is 200
movw $160, x1 movw $160, %bx
movw $55, y1 movb $55, %ch
movb $12, color movb $12, %dl # The Color also only requires a byte
call cons_draw_line call cons_draw_line
movw $150, x0 # Draw the rest of the lines
movw $150, y0 movw $160, %ax
movw $50, x1 movb $55, %cl
movw $50, y1 movw $90, %bx
movb $10, color movb $150, %ch
movb $11, %dl
call cons_draw_line call cons_draw_line
movw $150, x0 movw $90, %ax
movw $150, y0 movb $150, %cl
movw $160, x1 movw $50, %bx
movw $55, y1 movb $50, %ch
movb $11, color movb $14, %dl
call cons_draw_line call cons_draw_line
movw $10, x0 movw $10, %ax
movw $10, y0 movb $10, %cl
movw $310, x1 movw $310, %bx
movw $190, y1 movb $10, %ch
movb $9, color movb $9, %dl
call cons_draw_line call cons_draw_line
movw $310, x0 movw $310, %ax
movw $190, y0 movb $10, %cl
movw $10, x1 movw $310, %bx
movw $95, y1 movb $190, %ch
movb $8, color movb $10, %dl
call cons_draw_line call cons_draw_line
movw $10, x0 movw $310, %ax
movw $95, y0 movb $190, %cl
movw $10, x1 movw $10, %bx
movw $10, y1 movb $190, %ch
movb $7, color movb $13, %dl
call cons_draw_line
movw $10, %ax
movb $190, %cl
movw $10, %bx
movb $10, %ch
movb $15, %dl
call cons_draw_line
movw $75, %ax
movb $150, %cl
movw $250, %bx
movb $110, %ch
movb $1, %dl
call cons_draw_line
movw $210, %ax
movb $30, %cl
movw $300, %bx
movb $150, %ch
movb $6, %dl
call cons_draw_line
movw $180, %ax
movb $180, %cl
movw $170, %bx
movb $20, %ch
movb $3, %dl
call cons_draw_line call cons_draw_line
endless_loop: # Loop forever more endless_loop: # Loop forever more
@ -211,14 +248,14 @@ endless_loop: # Loop forever more
boot_message: boot_message:
.string "Boot Loader Stage 2 loaded" .string "Boot Loader Stage 2 loaded"
x0: .int 0 x0: .word 0
y0: .int 0 y0: .word 0
x1: .int 0 x1: .word 0
y1: .int 0 y1: .word 0
deltax: .int 0 deltax: .word 0
deltay: .int 0 deltay: .word 0
sx: .int 0 sx: .word 0
sy: .int 0 sy: .word 0
err: .int 0 err: .word 0
e2: .int 0 e2: .word 0
color: .byte 0 color: .byte 0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.