seti $printhelp = $printhelp
if $printhelp = 1
  exit 0
endif

include good_subroutines

# enable vendor specific commands
buffersize 0
setreadpio
ata28cmd 0x45 0x0b 0x00 0x44 0x57 0xa0 0x80
# check if command failed
gosub status_check

# vsc to prepare for rom read
buffersize 0x200
clearbuffer
setbuffer 0
  24 00 01 00 00 00 00 00 00 00 03 00 00 00 00 00
endbuffer
setwritepio
ata28cmd 0xd6 0x01 0xbe 0x4f 0xc2 0xa0 0xb0
# check if command failed
gosub status_check

# vsc to get a section of the rom
# the buffer size is based on the second byte of the command
# 0x80 sectors * 0x200 bytes per sector = 0x10000
buffersize 0x10000
clearbuffer
setreadpio
ata28cmd 0xd5 0x80 0xbf 0x4f 0xc2 0xa0 0xb0
# check if command failed
gosub status_check

# write the buffer to file
writebuffer 3rom0.bin 0 0 0x10000

# vsc to get another section of the rom
clearbuffer
ata28cmd 0xd5 0x80 0xbf 0x4f 0xc2 0xa0 0xb0
# check if command failed
gosub status_check

# write the buffer to file
writebuffer 3rom1.bin 0 0 0x10000

# vsc to get another section of the rom
clearbuffer
ata28cmd 0xd5 0x80 0xbf 0x4f 0xc2 0xa0 0xb0
# check if command failed
gosub status_check

# write the buffer to file
writebuffer 3rom2.bin 0 0 0x10000



previousscript
end



subroutine status_check
  seti $command_failed = 0
  gosub check_command_status
  if $command_failed = 1
    echo "Command failed!"
    gosub show_sense_data
    gosub show_ata_return_status
    previousscript
  endif
endsubroutine