* EXTENDED MODE TEST
*
* START ADDRESS: (OCTAL) 1000
*
* DATE: JAN-15-2010
*
* AUTHOR : THEO ENGEL
* CONTACT: INFO@THEOENGEL.NL
*
\LOAD
\ORG\'100
* IN THIS PROGRAM USE IS MADE OF THE FOLLOWING CODE
* TO CHECK WHETHER THE CPU IS IN NORMAL MODE OR IN
* EXTEND MODE:
* -TEST FOR EXTENDED MODE, WHEN X=1, BY DOING: 
* LDA* A,1
* THE RESULT OF THIS LOAD SHOULD BE:
* -NORMAL MODE:   A=-1 (CONTENT OF C)
* -EXTENDED MODE: A=0  (CONTENT OF D) 
*
* A SWITCH FROM NORMAL TO EXTENDED MODE IS OBTAINED BY:
* -EXECUTING THE EXA INSTRUCTION, OR
* -AFTER AN INTERRUPT, OR
* -EXECUTING AN OTK INSTRUCTION WITH A3=1
*
* A SWITCH FROM EXTENDED TO NORMAL MODE IS OBTAINED BY:
* -EXECUTING THE DXA INSTRUCTION, OR
* -EXECUTING AN OTK INSTRUCTION WITH A3=0
* IN BOTH CASES, THE NORMAL MODE IS ACTIVATED AFTER
* THE EXECTION OF 1ST JMP AFTER EITHER THE DXA OR OTK.
*
* WITH AN INTERRUPT, THE CURRENT MODE (EITHER NORMAL,
* OR EXTENDED) IS STORED IN PMI. THE VALUE OF PMI CAN
* BE OBTAINED IN A3 BY MEANS OF A INK INSTRUCTION.
*
A\DAC*\E
B\DAC\C
E\DAC\C
C\OCT\177777
D\OCT\0
*
* CLOCK 1 INTERRUPT DATA 
* (ENTERS INTERRUPT WITH NORMAL MODE)
M50\DEC\-50\50 TICK PER SECOND
MASK\DEC\1\RTC MASK BIT
INT1\DAC\ID1\TO BE LOADED IN '63
* CLOCK 2 INTERRUPT DATA 
* (ENTERS INTERRUPT WITH EXTENDED MODE)
INT2\DAC\ID2\TO BE LOADED IN '63
PME\OCT\020000\PME BIT
* CLOCK 3 INTERRUPT DATA 
* (ENTERS INTERRUPT WITH NORMAL MODE)
INT3\DAC\ID3\TO BE LOADED IN '63
*
MSB\OCT\100000
MO1\OCT\120000\OTK:SET C AND EXTEND
ONL\OCT\'106612\NLCR
AST\BCI\1, *
MSTR\OCT\30000
MEND\OCT\47757
ONE\OCT\1
FFFF\OCT\177777
*
* POINTER TO EXTENDED MEMORY CODE
MUP\EAC\ECD
BACK\DAC\STR
*
* PRINT ASCII
ASRO\DAC\**
\SKS\'104
\JMP\*-1
\OCP\'104
\OTA\4
\JMP\*-1
\JMP*\ASRO
*
* PRINT 2 ASCII'S
PRIN\DAC\**
\ICA
\JST\ASRO
\ICA
\JST\ASRO
\JMP*\PRIN
*
* PRINT NLCR
NLCR\DAC\**
\LDA\ONL
\JST\PRIN
\JMP*\NLCR
*
\BCI\15,X16 EXTENDED MODE TEST PROGRAM
M1\EQU\*
ML\DEC\-15
*
\ORG\'1000\
STRT\CRA\\START ADDRESS
\LDX\ML
\LDA\M1,1
\JST\PRIN
\IRS\0
\JMP\*-3
\JST\NLCR
STR\CRA
* BASIC EXA AND DXA TESTING
\AOA
\STA\0\X=1
\LDA*\A,1\NORMAL MODE?
\CMA
\SZE
\HLT\\NO=>ERROR
\AOA\\A#0
\EXA\\SET EXT MODE
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
\DXA
\AOA\\A#0
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
\JMP\*+1
* AFTER THIS JMP WE MUST HAVE NORMAL MODE
\LDA*\A,1\NORMAL MODE?
\CMA
\SZE
\HLT\\NO=>ERROR
*
* BASIC INK AND OTK TESTING
\SCB\\C=1
\INK
\ERA\MSB\A1 MUST BE 1
\SZE
\HLT
\RCB\\C=0
\INK\\A MUST BE 0
\SZE
\HLT
\AOA
\LGL\15\A1=1
\OTK\\C=1?
\SSC
\HLT
\CRA
\OTK\\C=0?
\SRC
\HLT
* WE MUST BE IN NORMAL MODE
\LDA*\A,1\NORMAL MODE?
\CMA
\SZE
\HLT\\NO=>ERROR
* SET C AND EXTEND
\LDA\MO1\'120000
\OTK
\SSC
\HLT
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
* RESET C AND SET NORMAL
\OTK\\C=0?
\SRC
\HLT
\AOA\\BUT STILL IN EXTEND
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
\JMP\*+1
* NOW WE MUST NORMAL MODE
\LDA*\A,1\NORMAL MODE?
\CMA
\SZE
\HLT\\NO=>ERROR
*
* ENTER IN NORMAL MODE AND TEST WHETHER IN 
* EXTENDED MODE AFTER INTERRUPT
\LDA\INT1\INTERRUPT SETUP
\STA\'63
\LDA\M50
\STA\'61\INIT RTC TO INTERRUPT (1 SEC)
\LDA\IA
\STA\ID1
\OCP\'20\START RTC
*
* INIT THE INTERRUPT PROCESSING
\LDA\MASK\ENABLE RTC INTERRUPT
\SMK\'20
\CRA
\ENB
CD\JMP\*\AND WAIT FOR AN INTERRUPT
\NOP
IA\DAC*\**,1
*
*
* INTERRUPT ROUTINE, ENTERS HERE *
* CHECK WHETHER THE JST* '63 KEEPS THE FLAG IN ID1
* AND DESTROYS ITS TAG BIT
ID1\DAC*\**,1
* CHECK FOR A CLOCK INTERRUPT
\SKS\'20
\JMP\CLCK
* NO RTC INTERRUPT, SO ERROR
\HLT
\JMP\*-1
*
* RTC INTERRUPT
ACD\DAC\CD
CLCK\AOA\\A#0
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
* PME AND C MUST BE 0
\AOA
\INK
\SZE
\HLT
\LDA\ID1\
\SMI\\FLAG OK?
\HLT\\NO=>ERROR
\CSA
\SUB\ACD\ADDRESS OK?
\SZE
\HLT\\NO=>ERROR
\LDA\AST
\JST\PRIN\PRINT *
*
* ENTER IN EXTENDED MODE AND TEST WHETHER IN 
* EXTENDED MODE AFTER INTERRUPT
\LDA\INT2\INTERRUPT SETUP
\STA\'63
\LDA\M50
\STA\'61\INIT RTC TO INTERRUPT (1 SEC)
\LDA\IA
\STA\ID2
\OCP\'20\START RTC
*
* INIT THE INTERRUPT PROCESSING
\LDA\MASK\ENABLE RTC INTERRUPT
\SMK\'20
\CRA
\ENB
CD1\JMP\*\AND WAIT FOR AN INTERRUPT
\NOP
*
*
* INTERRUPT ROUTINE, ENTERS HERE *
* CHECK WHETHER THE JST* '63 KEEPS THE FLAG IN ID2
* AND DESTROYS ITS TAG BIT
ID2\DAC*\**,1
* CHECK FOR A CLOCK INTERRUPT
\SKS\'20
\JMP\CLK1
* NO RTC INTERRUPT, SO ERROR
\HLT
\JMP\*-1
*
* RTC INTERRUPT
ACD1\DAC\CD1
CLK1\AOA\\A#0
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
* PME MUST BE 1 AND C MUST BE 0
\AOA
\INK
\ERA\PME\A3=1?
\SZE
\HLT
\LDA\ID2\
\SMI\\FLAG OK?
\HLT\\NO=>ERROR
\CSA
\SUB\ACD1\ADDRESS OK?
\SZE
\HLT\\NO=>ERROR
\DXA
\LDA\AST
\JST\PRIN\PRINT *
*
* ENTER IN NORMAL MODE AND TEST WHETHER IN 
* EXTENDED MODE AFTER INTERRUPT
\LDA\INT3\INTERRUPT SETUP
\STA\'63
\LDA\M50
\STA\'61\INIT RTC TO INTERRUPT (1 SEC)
\LDA\IA
\STA\ID3
\OCP\'20\START RTC
*
* INIT THE INTERRUPT PROCESSING
\LDA\MASK\ENABLE RTC INTERRUPT
\SMK\'20
\CRA
\ENB
CD2\JMP\*\AND WAIT FOR AN INTERRUPT
\NOP
*
*
* INTERRUPT ROUTINE, ENTERS HERE *
* CHECK WHETHER THE JST* '63 KEEPS THE FLAG IN ID3
* AND DESTROYS ITS TAG BIT
ID3\DAC*\**,1
* CHECK FOR A CLOCK INTERRUPT
\SKS\'20
\JMP\CLK2
* NO RTC INTERRUPT, SO ERROR
\HLT
\JMP\*-1
*
* RTC INTERRUPT
ACD2\DAC\CD2
CLK2\AOA\\A#0
\LDA*\A,1\EXT MODE?
\SZE
\HLT\\NO=>ERROR
* PME MUST BE 0 AND C MUST BE 0
\AOA
\INK
\SZE
\HLT
\LDA\ID3\
\SMI\\FLAG OK?
\HLT\\NO=>ERROR
\CSA
\SUB\ACD2\ADDRESS OK?
\SZE
\HLT\\NO=>ERROR
\DXA
\LDA\AST
\JST\PRIN\PRINT *
\JST\NLCR
* NORMAL MODE AND PME==0
*
* TEST JST IN NORMAL MODE
\LDA*\A,1\NORMAL MODE?
\CMA
\SZE
\HLT\\NO=>ERROR
\LDA\IA
\STA\ID4
\JST\ID4
ACD3\DAC\*
ID4\DAC\**
* FLAG AND TAG OK?
\LDA\ID4
\ANA\IA
\ERA\IA
\SZE
\HLT\\NO=>ERROR
\LDA\ID4\ADDRESS
\ERA\IA
\SUB\ACD3
\SZE
\HLT\\NO=>ERROR
*
\EXA
* TEST JST IN EXTENDED MODE
\AOA
\LDA*\A,1\EXTENDED MODE?
\SZE
\HLT\\NO=>ERROR
\LDA\IA
\STA\ID5
\JST\ID5
ACD4\DAC\*
ID5\DAC\**
* FLAG AND TAG OK?
\LDA\ID5
\ANA\MSB
\ERA\MSB
\SZE
\HLT\\NO=>ERROR
\LDA\ID5\ADDRESS
\ERA\MSB
\SUB\ACD4
\SZE
\HLT\\NO=>ERROR
*
* MEMORY STORE AND LOAD IN EXTENDED MODE
\CRA
\STA\0\X=0
ML1\CRA
\AOA
\STA*\MSTR,1\POSTINDEXING
\IRS\0
\LDA\0
\CAS\MEND
\JMP\*+3
\JMP\ML1
\JMP\ML1
* CHECK
\CRA
\STA\0\X=0
ML11\LDA*\MSTR,1\POSTINDEXING
\CAS\ONE
\HLT\\NE 1 =>ERROR
\SKP
\HLT\\NE 1 =>ERROR
\IRS\0
\LDA\0
\CAS\MEND
\JMP\*+3
\JMP\ML11
\JMP\ML11
* OK, NEXT TEST
\CRA
\STA\0\X=0
ML2\LDA\FFFF
\STA*\MSTR,1\POSTINDEXING
\IRS\0
\LDA\0
\CAS\MEND
\JMP\*+3
\JMP\ML2
\JMP\ML2
* CHECK
\CRA
\STA\0\X=0
ML21\LDA*\MSTR,1\POSTINDEXING
\CMA
\SZE
\HLT\\NE FFFF => ERROR
\IRS\0
\LDA\0
\CAS\MEND
\JMP\*+3
\JMP\ML21
\JMP\ML21
* OK, NEXT TEST
\CRA
\STA\0\X=0
ML3\CRA
\STA*\MSTR,1\POSTINDEXING
\IRS\0
\LDA\0
\CAS\MEND
\JMP\*+3
\JMP\ML3
\JMP\ML3
* CHECK
\CRA
\STA\0\X=0
ML31\LDA*\MSTR,1\POSTINDEXING
\SZE
\HLT\\NE 0 => ERROR
\IRS\0
\LDA\0
\CAS\MEND
\JMP\*+3
\JMP\ML31
\JMP\ML31
*
* EXE SOME CODE IN EXTENDED MEMORY 
\JMP*\MUP
*
\ORG\'77760
ECD\EQU\*
\NOP
\NOP
\NOP
\NOP
\NOP
\LDA\MSB
\ERA\MSB
\SZE
\HLT
\LDA*\IIA
\ERA*\IIA
\SZE
\HLT
\DXA
\JMP*\BACK
IIA\DAC\IA
\END
