Batch, 265 262 242 236236 235 bytes
@echo off
set/pn=
set c=%n%,-1,0
if %n% lss 0 set c=0,1,%n:-=%
for /l %%i in (%c%)do call:l %%i 0
exit/b
:l
set s=_
for /l %%j in (1,1,%n:-=%)do call:m %1 %%j
echo %s%
:m
set t=%s%
if %1 lss %2+%2 set t=%s:_= %
set s=%s%%t%%s%
Edit: Saved 12 1819 bytes thanks to @l4m2. Saved 8 bytes by removing the unnecessary %a%
variable.