@echo off
:DEBUT

if [%2]==[n] goto n64asm
if [%2]==[N] goto n64asm
if [%2]==[p] goto PATCH
if [%2]==[P] goto PATCH

if exist %1.asm goto start
goto end

:start
edit %1.asm
:asm
asmn64 /P %1.asm,%1.bin,%1.sym,%1.lst >%1.ERR
type %1.err
if errorlevel 1 goto erreur 
rem del %1.err
if [%2]==[send] goto HEADER
if [%2]==[SEND] goto HEADER
if [%2]==[v64] goto V64FORMAT
if [%2]==[V64] goto V64FORMAT
if [%2]==[monit] goto n64mon
if [%2]==[MONIT] goto n64mon
if [%2]==[p] goto PATCH2
if [%2]==[P] goto PATCH2
goto end

:PATCH
EDIT %1.asm
asmn64 /P %1.asm,%1.bin,%1.sym,%1.lst >%1.ERR
if errorlevel 1 goto erreur 
:PATCH2
if [%4]==[nopack] goto nopack
ppibm p d %1.bin

:nopack
edit intro_l.src
:LOADER
asmn64 /p intro_l.src,intro_l.bin >intro_l.err
type intro_l.err
if errorlevel 1 goto err_l
del intro_l.ERR
ncrypt2 intro_l.bin intro_l.cry

edit intro_c.src

:CRYPT
asmn64 /p intro_c.src,intro_c.bin,intro_c.sym,intro_c.lst >intro_c.ERR
type INTRO_c.err
if errorlevel 1 goto err_c
del intro_c.err
if [%3]==[run] goto SKIP
swap intro_c.bin intro_c.v64
if [%3]==[test] goto test:
goto end

:SKIP
COPY /b header.400 + intro_c.bin intro_c.raw
swap intro_c.raw intro_c.v64
chksum64 intro_c.v64
echo ready to send to doctor64
pause
talk64 -p2 -l intro_c.v64
goto end

:HEADER
if NOT [%3]==[] goto CUSTOM
ias -a 0x80000400 -h ultra1.bin --crc -f %1.bin
goto NOSTRIP
:CUSTOM
ias -a 0x%3 -h ultra1.bin --crc -f %1.bin
goto NOSTRIP


:V64FORMAT
swap %1.bin %1.v64
if [%3]==[test] goto test
if [%3]==[TEST] goto test
goto end


:NOSTRIP
rem chksum64 %1.v64
if [%3]==[nosend] goto end
if [%3]==[norun] goto end
:RESEND
echo.
echo.
echo ready to send to DOCTOR64
pause
talk64 -p2 -l %1.bin
if errorlevel 1 goto RESEND


goto end

:test
echo patch trainer onto rom
pause

rem place INTRO_c.v64 0 c:\windows\temp\monitor\rom bff000
place INTRO_c.v64 0 c:\windows\temp\monitor\rom 7f0000
rem place INTRO_c.v64 0 c:\windows\temp\monitor\rom bf0000

chksum64 c:\windows\temp\monitor\rom

rem place64 c:\windows\temp\monitor\rom bff000 11000
place64 c:\windows\temp\monitor\rom 7f0000 10000
rem place64 c:\windows\temp\monitor\rom bf0000 10000

rem talk64 -p2 -l c:\windows\temp\monitor\rom
goto end

:err_l
echo there was an error in loader
pause
edit intro_l.src intro_l.err
goto LOADER

:err_c
echo there was an error in crypter
pause
edit intro_c.src intro_c.err
goto CRYPT

:erreur
pause
edit %1.asm %1.err
goto asm

:n64mon

:end
