license
 
	
    : BUS_RESET ( --)
		_breg_SS0 C@
		[ _#SS0_enable_rti -1 XOR ]T LITERAL AND
		_breg_SS0 C!	
	;
    
	: BUS_ENABLE ( --)
		_breg_SS0 C@
		_#SS0_enable_rti OR
		_breg_SS0 C!
	;

    ram_create CARDS #slot_num  8 *  ram_allot
    0   DUP CONSTANT    #card_present   2+
    	DUP CONSTANT    #card_code      2+
    	DUP CONSTANT    #card_base      4+
    		CONSTANT    #card_length
   
   
	( fault exception handleing routine ) HEX
    ( used when testing for cards in rack)
    ram_variable _%bus_error
    interrupt: ?cards_exception 
		TRUE _%bus_error !
	;interrupt
   
	0C000 CONSTANT _#id_offset 
	10000 CONSTANT _#card_address_space

	CODE interruptable_W@ ( addr -- value)
		S )+ A0 MOV
		0 # D0 MOV
		\ get all writes out of the way
		NOP
		A0 ) D0 W. MOV
		NOP
		D0 S -) MOV
	NEXT


	: test_cards { }{
		variable _%cards_array
		variable _%card
		}
		CARDS _%cards_array !
		_#RTI1000_bus_base _%card !
		1F @exception
		['] ?cards_exception 1F EXCEPTION
		#slot_num zero DO
			FALSE _%bus_error !
			_%card @ _#id_offset + interruptable_W@
			_%bus_error @ IF
				\ no card in slot
				\ value will still get pushed on stack
				\ It will be rubbish 
				DROP
			ELSE
				TRUE _%cards_array @ #card_present + W!
				_%cards_array @ #card_code + W!
				_%card @ _%cards_array @ #card_base + !
			THEN
			#card_length _%cards_array +!
    		_#card_address_space _%card +!
		LOOP
		1F EXCEPTION
	;

    
    : ?CARDS ( --)
    	?cards_exception 1F EXCEPTION
    	test_cards
    	TRAP02 1F EXCEPTION
    ;