;=======================================================
; BAGMenu Progress Bar
; Script
;
; Written by BassAceGold
;
;Renders a progress bar on screen
;based on the following arguments.
;
;
;ARGV arguments
; $R0 = screen to render to
; $R1 = x position to draw bar at
; $R2 = y position to draw bar at
; $R3 = width of progress bar
; $R4 = height of progress bar
; $R5 = progress bar outline color
; $R6 = progress bar fill color
; $R7 = current progress
; $R8 = total progress
;
;
;The calculation used for generating a percent is:
; percent = (current progress * 100) / total progress
;
;
;
;=======================================================
;interpreter pragma
[Script]
;misc regs uses
;$R10 = calculated x2 position
;$R11 = calculated y2 position
;$R15 = final percentage filled
;$R16 = progress bar width
;$R17 = check if boarder color is transparent
;$R18 = storage of the transparent color
;program start
_start:
;first, collecting the values passed
;through argv.
;grab the screen number
ATOI $R0,$ARGV0
;x position
ATOI $R1,$ARGV1
;y position
ATOI $R2,$ARGV2
;width
ATOI $R3,$ARGV3
;height
ATOI $R4,$ARGV4
;boarder color
ATOI $R5,$ARGV5
;interior color
ATOI $R6,$ARGV6
;current progress
ATOI $R7,$ARGV7
;total progress
ATOI $R8,$ARGV8
;then some misc calculations that'll help later on
;add width to x position to get x2 position
SET $R10,$R1
ADD $R10,$R3
;add height to y position to get y2 position
SET $R11,$R2
ADD $R11,$R4
;Now to draw progress bar outline
;If the outline color is set to magenta
;we'll consider that as transparent.
;So lets check if the boarder color is transparent
;Color - Magenta should = exactly zero if a match
SET $R17,$R5
SUB $R17,#64543
;if it is transparent (color - magenta == 0), skip boarder drawing
JMPZ no_boarder
;otherwise, continue drawing outline
;top line
;screen, x1, y1, x2, y2, color, size
DRWLINE $R0,$R1,$R2,$R10,$R2,$R5,#1
;bottom line
DRWLINE $R0,$R1,$R11,$R10,$R11,$R5,#1
;left line
;x2 is the same as x1
DRWLINE $R0,$R1,$R2,$R1,$R11,$R5,#1
;right line
;x1 is the same as x2
DRWLINE $R0,$R10,$R2,$R10,$R11,$R5,#1
;no boarder here
;now we calculate how much to draw inside the box
;first we need to do a check to make sure we aren't going
;to divide by 0
;check if the current progress is 0
no_boarder SUB $R7,#0
JMPP not_zero
;if the current progress is 0, set it to 1
SET $R7,#1
;now calculate a percentage
;percent($R15) = (current progress($R7) * 100)/total progress($R8)
not_zero SET $R15,$R7
MUL $R15,#100
DIV $R15,$R8
;now using the percentage, we'll determine how much of the
;progress bar to fill
;(bar width = percentage * bar width) / 100
SET $R16,$R15
MUL $R16,$R3
DIV $R16,#100
;finally we can draw the interior of the progress bar
;we are going to leave a 1 pixel boarder around the interior
;so lets calculate the bar position
;x + 1
ADD $R1,#1
;y + 1
ADD $R2,#1
;y2 - 1
SUB $R11,#1
;x2 = x + width
SET $R10,$R1
ADD $R10,$R16
;then draw the rectangle
;screen, x1, y1, x2, y2, color
DRWRECT $R0,$R1,$R2,$R10,$R11,$R6
;update the screen
FLIP $R0
HALT