bakervm 0.9.0

A virtual machine for building and running retro games
Documentation
jmp _std_graphics_draw_filled_rect

include! ../math/max
include! ../math/min
include! draw_point

.std.graphics.draw_filled_rect
  push $st, @9
  add $bp, $st

  ; get all arguments
  mov $vi(20), $st  ; p2-y
  mov $vi(21), $st  ; p2-x

  mov $vi(22), $st  ; p1-y
  mov $vi(23), $st  ; p1-x

  mov $vi(24), $st  ; color


  ; normalize p1
  dup $vi(23)   ; x1
  dup $vi(21)   ; x2
  call std.math.min

  mov $vi(25), $st  ; p1n-x

  dup $vi(22)   ; y1
  dup $vi(20)   ; y2
  call std.math.min

  mov $vi(26), $st  ; p1n-y


  ; normalize p2
  dup $vi(23)   ; x1
  dup $vi(21)   ; x2
  call std.math.max

  mov $vi(27), $st  ; p2n-x

  dup $vi(22)   ; y1
  dup $vi(20)   ; y2
  call std.math.max

  mov $vi(28), $st  ; p2n-y

  ; clean up
  push $vi(20), @0
  push $vi(21), @0
  push $vi(22), @0
  push $vi(23), @0

  ; setup start values
  dup $vi(25)
  mov $vi(20), $st  ; p1-x
  dup $vi(26)
  mov $vi(21), $st  ; p1-y

  ; draw the start-point
  dup $vi(24)   ; color
  dup $vi(25)   ; x
  dup $vi(26)   ; y
  call std.graphics.draw_point

  .std.graphics.draw_filled_rect__draw_outer
    dup $vi(24)   ; color
    dup $vi(20)   ; x
    dup $vi(21)   ; y
    call std.graphics.draw_point

    push $st, @1
    add $vi(20), $st

    cmp $vi(20), $vi(27)
    jmpgt std.graphics.draw_filled_rect__draw_inner
    jmp std.graphics.draw_filled_rect__draw_outer
  .std.graphics.draw_filled_rect__draw_inner
    dup $vi(25)
    mov $vi(20), $st

    push $st, @1
    add $vi(21), $st
    cmp $vi(21), $vi(28)
    jmplteq std.graphics.draw_filled_rect__draw_outer

  dup $vi(24)   ; color
  dup $vi(27)   ; x
  dup $vi(28)   ; y
  call std.graphics.draw_point

  push $st, @9
  sub $bp, $st
ret

._std_graphics_draw_filled_rect