*********************
*ASSEMBLER CODE FOR ALP FOR CENTRAL DATA COMPUTER
*THIS LSITING IS TO BE IDENTICAL TO THE PRINTED LISTING IN ALP.PDF
*THIS LISTING IS VERIFIED AS TO BE:
*ALL LABELS HAVE IDENTICAL LINENUMBERS AND HEX ADRESSES, ONCE
*THIS COMMENT BLOCK HAS BEEN REMOVED. FOR THIS REASON MANY EMPTY LINES ARE PRESENT.
*THIS LISTING HAS BEEN CREATED BY GERT GREMMEN (G.GREMMEN@CETEST.NL)
*AND HAS NOT BEEN TESTED YET ON NOV-22.
*FOR TESTING AS A CENTRAL DATA 2650 COMPUTER IS NEEDED, WHIH I DO NOT HAVE.
*THE IDEA IS TO HAVE IT RUN ON PIP4K, A UPDATED MONITOR VERSION 
*(BUT ESSENTIALLY IDENTICAL IN OPERATION AS PIPBUG) 
*THAT I WROTE FOR ARTEMIS, A SMALL 2650 BOARD THAT I DESIGNED AND OF WHICH
*YOU CAN GET SOFTWARE AND DESIGN FILES FOR FREE.
*MESSAGE ME IF YOU WANT TO USE THIS FILE. AN UPDATED OR CORRECTED VERSION MAY BE AVAIABLE
*ERRORS WILL BE PRESENT.... THOUGH MORE THAN 99.5% IS EXPECTED TO BE CORRECT.
*THIS SOFTWARE RUNS IN 2 FIXED 2650-PAGES 2000-3FFF AND 4000 UP. (SEARCH ORG $4000)
*I HAVE NOT SEEN OBJECTIONS TO USE OTHER PAGES, BUT BEWARE.
*THIS SOFTWARE EXPECTS A PARALLEL KEYBOARD TE BE READ WITH REDD COMMAND.
*MODS TO THIS CONCEPT SEEM NOT TOO DIFFICULT.
*IT CONTAINS 3 PROGRAMS, A TEXT EDITOR, AN FULL 2-PASS ASSEMBLER AND A DEBUGGER.
*THE CODE IN THIS FILE IS ASSEMBLYCODE MODIFIED FOR THE ASM32.EXE ASSEMBLER (ASK MY COPY)
*WHICH IS SLIGHTLY DIFFERENT FROM THE ORIGINAL, WHICH ASSEMBLIES ON ITSELF. (ESP INDEXING)
*SOME LABELS HAVE BEEN MODIFIED DUE SYNTAX RESTRICTION OF THIS ASSEMBLER.
*OPCODES AND ASSEMBLER DIRECIVES ARE NOT ACCEPTED AS LABEL, ADDED x y z CHAR.
*I/O AS LABEL HAS BEEN REPLACED BY INOUT
*ANY QUESTIONS ?  MAIL ME.
***********************
* alp.ASM ORIGINAL VERSION 0.1
******************************************************************	
	ORG	$2000
;R0	EQU	$0	;
;R1	EQU	$1	;
;R2	EQU	$2	;
;R3	EQU	$3	;



EQ	EQU	$0	;
GT	EQU	$1	;
LT	EQU	$2	;
UN	EQU	$3	;
NE	EQU	$80	;
LE	EQU	$81	;
GE	EQU	$82	;
Z	EQU	$0	;




CRY	EQU	$1	;PSL
CCM	EQU	$2	;
OVF	EQU	$4	;
WC	EQU	$8	;
RS	EQU	$10	;
IDC	EQU	$20	;
COND	EQU	$C0	;
SP	EQU	$7	;PSU
II	EQU	$20	;
FLAG	EQU	$40	;
SENSE	EQU	$80	;



ESC	EQU	$1B	;
BS	EQU	$8	;
CR	EQU	$D	;
CRCD	EQU	$D	;
CCOPY	EQU	$10	;
CTRLX	EQU	$18	;
ETX	EQU	$3	;
CTRLO	EQU	$F	;
CTRLP	EQU	$10	;
CTRLN	EQU	$E	;
CTRLY	EQU	$15	
BLKSP	EQU	$53	;
DISPP	EQU	$55

HT	EQU	$9	;



LF	EQU	$A	;
FORMF	EQU	$C	;

SERO	EQU	$24F	;
SERI	EQU	$2E9	;
DELAY	EQU	$278	;

	BCTA,UN	EDITOR	;
BSTART	DB	$4A	;
IBST	DB	$50	;
OBST	DB	$5C	;
ENDRAM	DB	$60	;
TABSS	DB	$7	;
CHGA	DB	$12	;
	DB	$1B	;

DPRINT	BCTA,UN	*6046	;PRINTER	DRIVER

MBUF	DS	$10	;



CCMS	DS	$1	;
NAMEX	DS	$10	;



TMPS	DS	$1	;
TEMP	DS	$1	;

EBC	EQU	$83	;



EDITOR	LODI,R0	$2	;
	LPSL		;
	PPSU	$40	;
	EORZ	R0
	STRA,R0	OBPTR+1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ADL	BSTA,UN	AOK	;2E0A
	BSTA,UN	LOADA	;2D9F
	BCTA,EQ	SCERR	;RELATIVE
	BCTA,UN	FBDN	;2048
		;
SCERR	LODI,R3	$10	;
	BCTA,UN	ERROR	;
		;
TAPEO	BSTA,UN	AOK	;2E0A
	LODA,R0	BSTART	;2003
	STRA,R0	DUMA	;
TAPEOT	EORZ	R0
	STRR,R0	*SUMK	;
	STRA,R0	DUMA	;2A03
	LODI,R3	';'	;
	BSTA,UN	SERO	;
	LODI,R1	$FF	;
NAM0	LODA,R0	NAMEX,R1,+	;
	STRZ	R3	;
	BSTA,UN	SERO	;
	COMI,R0	$7	;
	BCFR,EQ	NAM0	;
	LODR,R3	*SUMK	;
	BSTA,UN	SERO	;
	LODI,R1	$0	;
	STRR,R1	*SUMK	;
BYTE0	LODA,R0	*DUMA,R1	;
	STRZ	R3	;
	BCTR,LT	ENDO	;
	BSTA,UN	SERO	;
	BIRR,R1	BYTE0	;
	LODR,R3	*SUMK	;
	BSTA,UN	SERO	;
	BSTA,UN	A1DA	;
	BCFA,LT	FBDN	;2048	4048
	BCFA,LT	FBDN	;
		;
SUMK	DW	$17F9	;(37F9)
		;
ENDO	BSTA,UN	SERO	;
ENDT	LODR,R3	*SUMK	;
	BSTA,UN	SERO	;
	BCTA,UN	FBDN	;

OPCD1	DB	'LLLLSSSAAAASSSSDAAAAIIIIEEEECCCCRRBBBBBBBBBBZ'
	DB	'BBBBBBBZBRRWRWRWRHNTLLSSCCPPTTOEDAREAPBBDT'





















OPCD2	DB	'OOOOTTTDDDDUUUUANNNNCOOOOOOOOOOORRCCCCRRIIDDF'
	DB	'ISSSSSSBSEERERERFAOMPPPPPPPPPPROACENLRLUIA'





















OPCD3	DB	'DDDDRRRDDDDBBBBRDDDDRRRRRRRRMMMMRLTTFFNNERRRR'
	DB	'ATTFFNNSXTTTDTDTDLPISSSSSSSSSSGUTOSDINKMSP'




















OPCD4	DB	'ZIRAZRAZIRAZIRA ZIRAZIRAZIRAZIRA  RARARARARAR'
	DB 	' RARARARACEDDCCEET  ULULULULUL  AN  TTSPPE'
	





















OPCD5	DB	$00,$04,$08,$0C,$C0,$C8,$CC,$80,$84,$88,$8C,$A0,$A4,$A8,$AC
	DB	$94,$40,$44,$48,$4C,$60,$64,$68,$6C,$20,$24,$28,$2C,$E0,$E4
	DB	$E8,$EC,$50,$D0,$18,$1C,$98,$9C,$58,$5C,$D8,$DC,$F8,$FC,$9B
	DB 	$9F,$38,$3C,$B8,$BC,$78,$7C,$BB,$BF,$14,$34,$F0,$70,$B0,$30
	DB	$D4,$54,$40,$C0,$F4,$92,$93,$12,$12,$74,$75,$76,$77,$B4,$B5

	



	





	





PASS	DS	1	
LTBL	DS	2
OUTOFF	DS	1
DISPON	DS	1
BPPC	DS	1
COMAST	DS	1
BPTR	DS	1
SPTR	DS	1
CURA	DS	2
DUMA	DS	1
DUM2	DS	1
TMPA	DS	1
TEMP2	DS	1
BSA1	DS	2
CBGA	DS 	2
CHGST	DS	2
PAGEN	DS	2
BUMPON	DS	1
DISPLN	DS	1
BLKSON	DS	1
TAPEON	DS	1
SECB	DS	2
OBPTR	DS	2
LINE	DS	2
TXTBUF	DS	$51

BYTSTG	DS	$100
ORGP	EQU	$4B
EQUP	EQU	$4C
DATAP	EQU	$4D
ACONP	EQU	$4E
RESP	EQU	$4F
ENDP	EQU	$50
ALITP	EQU	$51
PRNTP	EQU	$52
BUMPP	EQU	$54
TAPEP	EQU	$56
TCPCOM	EQU	$55	;EXCHGE MET TAPEP?























ASM	BSTA,UN	ERASE
PASS1	EORZ	R0
	STRA,R0	PASS
	STRA,R0	BLKSIN
	STRA,R0	PC
	STRA,R0	PC+1
	STRA,R0 	LTBL+1
	STRA,R0	TXTBUF+$50
	STRA,R0	ERRS
	BSTA,UN	BEGIN
	LODA,R0	IBST
	STRA,R0	LTBL
	LODI,R0	$FF
	STRA,R0	BUMPON
	STRA,R0	SPTR
	STRA,R0	BPTR
	STRA,R0	ERRPTR
	STRA,R0	*LTBL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INE
	ADDI,R0	1
	STRA,R0	PLINE
	COMI,R0	$36
	BSTA,GT	HEADIN
	BCTA,UN	ERRP
	
	
CHKPR	LODA,R0	OUTOFF
	RETC,EQ
	LODA,R0	DISPON
	RETC,UN
	
	
EMSG2	DB	'OPCODE',$FF


	DB	'LABEL USED TWICE',$FF


	DB	'OPERAND',$FF


	DB	'REGISTER FIELD',$FF


	DB	'DISPLACEMENT',$FF


	DB	'PAGING',$FF
	







ERRS	DS	1

GETADD	LODI,R1	$11
GETAD2	STRA,R1	TMPS2
	EORZ	R0	; 0 OF 2
	STRA,R0	OPSTG
	STRA,R0	OPER2
	STRA,R0	OPER3
ADL2A	BSTA,UN	EVAL
	LODA,R0	OPSTG
	BCTA,EQ	ADDADD
	COMI,R0	$2B
	BCTR,EQ	ADDADD
	COMI,R0	$2D
	BCFR,EQ	SUBADD
	LODA,R0	OPER3
	SUBA,R0	OPER1
	STRA,R0	OPER3
	LODA,R0	OPER2
	PPSL	WC
	SUBA,R0	OPER0
	STRA,R0	OPER2
	CPSL	WC
	BCTR,UN	SUBADD
ADDADD	LODA,R0	OPER3
	ADDA,R0	OPER1
	STRA,R0	OPER3
	PPSL	WC
	LODA,R0	OPER2
	ADDA,R0	OPER0
	STRA,R0	OPER2
	CPSL	WC
SUBADD	LODA,R1	R2POS
	STRA,R1	TMPS2
	LODA,R0	TXTBUF,R1
	BCTR,EQ	CKHIG
	COMI,R0	','
	BCTR,EQ	CKHIG
	COMI,R0	' '
	BCTR,EQ	CKHIG
	STRR,R0	OPSTG
	BCTA,UN	ADL2A
CKHIG	LODI,R1	$11
	LODA,R0	TXTBUF,R1
	COMI,R0	'^'
	RETC,GT
	RETC,LT
	LODA,R0	OPER2
	STRA,R0	OPER3
	RETC,UN
	
OPSTG	DS	1

EVAL	LODA,R1	TMPS2
LU	LODA,R0	TXTBUF,R1,+
	BCTR,EQ	STRR2
	COMI,R0	' '
	BCTR,EQ	STRR2
	COMI,R0	$2D	; minus -
	BCTR,EQ	STR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1
	PPSL	WC
	LODA,R0	PAGEN
	ADDI,R0	$66
	DAR,R0
	STRA,R0	PAGEN
	CPSL	WC
	BSTA,UN	PRINT
	LODA,R2	PAGEN+1
	BSTA,UN	PRINT
	LODI,R0	LF
	BSTA,UN	PRNT
	LODI,R0	CR
	BSTA,UN	PRNT
	RETC,UN


PRTBUF	DB	FORMF,LF,LF,LF,CR

	DB	'LINE  ADDR B1 B2 B3 B4  LABEL  OPCODE    OPERAND'











	DB	'  COMMENTS        PAGE  ',$FF






PMSG4	db	'*** ',$FF

PMSG5	db	' ERROR ***',LF,CR,$FF




BLKPRT	LODA,R0	PRTBUF,R1   ;
	RETC,LT
	BSTA,UN	PRNT
	BIRR,R1	BLKPRT
	RETC,UN
	
BUG	BSTA,UN	ERASE
	BCTA,UN	DCOMD
DEBUG	BSTA,UN	ERASE
	BSTA,UN	AR




TAB1	DB	INZERO-JADD1
	DB	INIM-JADD1
	DB	INREL-JADD1
	DB	INABS-JADD1
TAB2	DB	CTZERO-JADD2
	DB	OUTIM-JADD2
	DB	OUTREL-JADD2
	DB	OUTABS-JADD2
TAB3	DB	EX1-JADD3
	DB	EX0-JADD3
	DB	GREL-JADD3
	DB	GABS-JADD3
	
TABEX0	DB	RETCX-JEX0
	DB	RETEX-JEX0
	DB	REDEY-JEX0
	DB	CPS-JEX0
	DB	DARX-JEX0
	DB	TBS-JEX0
	DB	WRTZ-JEX0
	DB	TMIX-JEX0
	
TABEX1	DB	SPS-JEX1
	DB	REDCX-JEX1
	DB	RRRX-JEX1
	DB	REDDX-JEX1
	DB	LPS-JEX1
	DB	WRTCX-JEX1
	DB	RRLX-JEX1
	DB	WRTDX-JEX1
	
REDETB	DB	REDEI-REDEI
	DB	REDE1-REDEI
	DB	REDE1-REDEI
	DB	REDB-REDEI
	
REDTAB	DB	RED0-RED0
	DB	RED1-RED0
	DB	RED1-RED0
	DB	RED2-RED0
	
WRTETB	DB	WRTEX-WRTEX
	DB	WRTE1-WRTEX
	DB	WRTE5-WRTEX
	DB	WRTE5-WRTEX
	
WRTTB	DB	WRT1-WRT1
	DB	WRT5-WRT1
	DB	WRT4-WRT1
	DB	WRT4-WRT1
	
MODTAB	DB	DCOMD-OUT
	DB	SI-OUT
	DB	ST-OUT
	DB	TR-OUT
	DB	SS-OUT
	
INVAL	DB	$10,$11,$90,$91,$B6,$B7,$C4,$C5,$C6,$C7











KEYTAB	DB	'JLUIOM,.'

KEY0	DB	$FF,$01,$EF,$F0,$F1,$0F,$10,$11








HXTBL	DB	'0123456789ABCDEF'




ADRTAB	DB	$00,$01,$01,$02





comtb2	DB	'CH'
	DW	CH
	DB	'CO'
	DW	CO
	DB	'DI'
	DW	DDIS
	DB	'DS'
	DW	DSBUG
	DB	'IN'
	DW	IN
	DB	'PA'
	DW	DPAGE
	DB	'PC'
	DW	PCIT
	DB	'RE'
	DW	RE
	DB	'AA'
	DW	AA
	DB	'AP'
	DW	AP
	DB	'AR'
	DW	AR
	DB	'AS'
	DW	AS
	DB	'IP'
	DW	IP
	DB	'IR'
	DW	IRIT
	DB	'IS'
	DW	IS
	DB	'OA'
	DW	OA
	DB	'OS'
	DW	OS
	DB	'OR'
	DW	OR
	DB	'SI'
	DW	CSI
	DB	'ST'
	DW	CST
	DB	'TR'
	DW	CTR
	DB	'BR'
	DW	BR
	DB	'CL'
	DW	CLIT
	DB	'EX'
	DW	EX
	DB	'RU'
	DW	PASS1
	DB	'ED'
	DW	EDITOR
	DB	$FF
	



MSG0	DB	'INPUT PORT ',$FF
MSG1	DB	'OUTPUT PORT ',$Ff
MSG2	DB	'BREAK POINT ',$FF
MSG3	DB	' CLEARED',$FF
MSG4	DB	'STACK= ',$FF
MSG5	DB	' INVALID COMMAND',$FF
MSG6	DB	'DEBUG> ',$FF
MSG7	DB	'PROGRAM HALTED',$FF
MSG8	DB	' REACHED AT ',$FF
MSG9	DB	'INVALID OPCODE',$FF
MSGA	DB	' CC=',$FF
MSGB	DB	'  INVALID HEX VALUE',$FF
MSGC	DB	'BLOCKS  LEFT:  ',$FF
MSGD	DB	'TOO MUCH',$FF
MSGE	DB	'NOT FOUND',$FF
MSGF	DB	'MODIFY STRING ',$FF
MNAME	DS	$10
MSG102	DB	'  TO  ',$FF   ;CHECK THIS
MSG10	DB	'CHECKSUM ERROR',$FF
MSG11	DB	'PASS 1',$FF
MSG12	DB	'PASS 2',$FF
MSG13	DB	'SYMBOL OVERFLOW',$FF
MSG14	DB	' ERRORS',$FF
MSG15	DB	'DUPLICATE LABLE: ',$FF
MSG16	DB	'OPCODE',$FF
MSG17	DB	'LABLE USED TWICE',$FF
MSG18	DB	'OPERAND',$FF
MSG19	DB	'REGISTER FIELD',$FF
MSG1A	DB	'DISPLACEMENT',$FF
MSG1B	DB	'PAGEING',$FF
MSG1C	DB	'BINARY  OUTPUT',$FF
MSG1D	DB	'COMMAND:  ',$FF
MSG1E	DB	'DATA INPUT',$FF
MSG1F	DB	' OK',$FF



































































































***** SIMULATOR ************


INER	LODI,R1	9
	BSTA,UN	PSTRNG
	BCTA,UN	COMD
	
	IR	DS	1
	
GETOP	LODA,R0	*PC
	BSTA,UN	PCINC
	STRR,R0	IR
	LODI,R3	$0A
VALID	COMA,R0	INVAL,R3,-
	BCTR,EQ	INER
	BRNR,R3	VALID
	STRZ	R1
	STRZ	R2
	ANDI,R0	3
	STRA,R0	REGIND ;STORE REGISTER BITS
	RRR,R1
	RRR,R1
	LODZ	R1
	ANDI,R0	3
	STRZ	R3
	STRA,R0	ADRMD  ; ADRESSMODE BITS
	RRR,R1
	RRR,R1
	LODZ	R1
	ANDI,R1	$0E
	ANDI,R0	1
	BCFA,EQ	BRANCH ; PROCESS BRANCH
NONB	COMI,R2	$C0	;TEST ON NOP
	BCTA,EQ	NOPX
	COMI,R2	$40	;TEST ON HALT INSTR
	BCTA,EQ	HALTX
	LODA,R0	TAB1,R3	;SET UP REGISTERS
	STRZ	R3
	BSXA	JADD1
	LODA,R3	IR	;SETUP OPCODE
	ANDI,R3	$E0
	IORI,R3	01
NON0	ST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