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


; params: %1 source card deck to assemble with soap
;         %2 start address to run program (If empty, program not run)
;         %3 input card deck (if empty, do not attach input card)
;         %4 input card deck wiring (if empty, uses 8WORD)
;         %5 output card deck wiring (if empty, uses 8WORD)

set cpu 4k
set cpu soapmne

; if TAP pseudo-op is to be used in SOAP source program, this section must be uncommented
; start of TAP pseudocode enable section

set cpu CntrlUnit
set cpu StorageUnit

at mt2 soaplib.tap

; end of TAP pseudocode enable section

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

set cdr1 wiring=8word
att cdr1 -q -l soap/soap4.dck

echo *** 
echo *** Load SOAP4 deck into drum
echo *** 

d csw 7019519999
d ar 8000
go

; Now put source cards in reader and start soap assembler

att cdr1 -q %1
set cdr1 wiring=soapa

att cdp1 -n -q deck_out.dck
set cdp1 echo, print, wiring=soapa
att cdp0 -n -q print.txt

echo *** 
echo *** Assemble source deck
echo *** 

; uncomment this debug to get trace of how source deck is assembled
; set debug -n debug.txt

d ar 1000
go

; separate 5 words per card deck if any generated
carddeck -q split 5cd cdp1 deck_out.dck deck_out_5cd.dck

; discard availability card generated if any
carddeck -q split pat deck_out.dck deck_out.dck nul


if "%2" == "" goto end

; 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_out.dck

att cdp1 -n -q deck_out_run.dck
set cdp1 echo, print, wiring=8WORD


echo *** 
echo *** Read assembled program deck
echo *** 

d csw 7019519999
d ar 8000
go

; attach input deck
if "%3" == "" goto run1

if "%4" == "" goto run2
set cdr1 wiring=%4
:run2

if "%5" == "" goto run3
set cdp1 wiring=%5
:run3

att cdr1 -q %3

; Now execute the loaded deck
:run1

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

; uncomment this debug to get trace of how assembled source deck is executed
; set debug -n debug.txt

d ar %2
go

det all

:end

