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

; params: %1 control cards for regional program
;         %2 regional assembly source card deck 
;         %3 start address to run program (If empty, program not run)
;         %4 input card deck (if empty, do not attach input card)

set cpu 2k

; prepare input deck 

carddeck -q join regional/load_id_card.dck  regional/ra.dck  %1  regional/ra_starter_card.dck  %2  AS deck_in.dck

; Now put input deck in reader 

att cdr1 -q deck_in.dck
set cdr1 wiring=ra

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

echo *** 
echo *** Regional Assembler source deck
echo *** 

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

d csw 70 1901 0000
d ar 8000
go

; this generates deck_out.dck as program in five-field card format

if "%3" == "" goto end

; Load five-field card deck into drum

carddeck -q join regional/load_id_card.dck  deck_out.dck  AS deck_in.dck

; Now put input deck in reader 

att cdr1 -q deck_in.dck
set cdr1 wiring=ra

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

d csw 70 1901 0000
d ar 8000
go

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

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

att cdr1 -q %4

; Now execute the loaded deck
:run1

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

d ar %3
go

:end

