
; set console -n log=log.txt 
; set debug -n debug.txt
; set debug stdout
; set cpu debug=cmd;data;detail


; params: %1 source program card deck to compile with it
;         %2 input program data card deck (if empty, do not attach input card)
;         %3 output program data card deck (if empty, attach deck_out.dck file) 

set cpu 2k
att cdp0 -n -q print.txt

; print IT source program 

echo
carddeck -q print %1

; load IT compiler but do not execute it

echo *** 
echo *** Load IT compiler deck into drum
echo *** 

set cdr1 wiring=8word
att cdr1 -q -l it/it_compiler.dck

d csw 70 1951 3000
d ar 8000
go

echo *** 
echo *** Run IT compiler
echo *** 

; Now put source cards in reader and start compiler

att cdr1 -q %1
set cdr1 wiring=it

att cdp1 -n -q deck_out.dck
set cdp1 echo, print, wiring=it

d csw 70 1999 3000
d ar 8000
go

; check if compilation ok 

if accup==0 goto compile_ok

echo 
echo *** (compilation error code in Upper ACC)
echo

ex accup
goto end

:compile_ok

; Prepare PIT deck (as compiled IT program)
; separate last 10 cards from compilation output deck (called reservation cards)

carddeck -q split -10 cdp1 deck_soap.dck deck_res.dck
det cdr1

; create the pit program deck with
; 1) reservation cards from compilation step
; 2) package used reservation deck
; 3) rest of compilation output

carddeck -q join deck_res.dck it/it_reservation_p1.dck deck_soap.dck as deck_pit.dck 

; Load soap deck into drum (1 word per card format), but does not execute it


echo *** 
echo *** Load SOAP deck into drum
echo *** 

att cdr1 -q -l it/soapII.dck

d csw 7019519999
d ar 8000
go

echo *** 
echo *** Apply IT modifications to SOAP deck
echo *** 

att cdr1 -q -l it/soapII_patch.dck

d csw 7019519999
d ar 8000
go


; Now put source cards in reader and start soap assembler

echo *** 
echo *** Assemble PIT deck
echo *** 

att cdr1 -q deck_pit.dck
set cdr1 wiring=soap

att cdp1 -n -q deck_out.dck
set cdp1 echo, print, wiring=soap

d ar 1000
go

; Prepare SPIT deck (as assembled PIT program)

; create the spit program deck with
; 1) package cards 
; 2) assembly output

det cdr1
det cdp1

carddeck -q join it/it_package_p1.dck deck_out.dck as deck_spit.dck

; Load deck into drum (1 word per card format), but does not execute it

echo *** 
echo *** Read SPIT deck to run into drum
echo *** 

; Load assembled deck into drum
; -l switch allows to load the symbolic info so debug cmd info will show 
; soap source code read from card.

set cdr1 wiring=8WORD
att cdr1 -q -l deck_spit.dck


d csw 7019519999
d ar 8000
go

; attach input and output data deck

det cdr1

if "%2" == "" goto run1
att cdr1 -q %2
set cdr1 wiring=it
:run1

if "%3" != "" att cdp1 -n -q %3
if "%3" == "" att cdp1 -n -q deck_out.dck
set cdp1 echo, print, wiring=it

; Now execute the loaded deck

echo *** 
echo *** Run program
echo *** 

; set csw to -1 to activate conditional type statement
d csw 0
d ar 1999
go

; clean up

del deck_pit.dck
del deck_spit.dck
del deck_soap.dck
del deck_res.dck


:end
