;  **************************
; * orion-128.2 "STARS" 256B *
; *        VERSION 2         *
; *    BY RIDDLE (C) 2016    *
;  **************************
ORG 0
START:
MVI A,6
STA 0F800H ; 16-COLOR MODE
JMP CLS
SETCLR:    ; RST 1 -> HL - ADDRESS, C - COLOR
MVI A,1
JMP 0F839H
RAND:
DW 0F900H
NOP
RND:       ; RST 2
PUSH H
LHLD RAND
MOV A,L
INR L
ADD M
SHLD RAND
POP H
RET
CLS:
MVI C,1FH
CALL 0F809H
LOGO:
LXI H,0C0CH
CALL 0F83CH
LXI H,INTRO
CALL 0F818H
MVI L,CCLOGO
MVI D,0E0H
CALL LGOCPY
INR D
CALL LGOCPY
LXI B,300FH
LXI H,200H ; STARS
MVI D,0C0H
GSTARS:
RST 2
JM GS1
SUI 11
GS1:
MOV M,A
INR L
RST 2
ANI 1FH
MOV E,A
RST 2
ANA C
ADD D
ADD E
MOV M,A
INR L
JNZ GSTARS
MOV E,L  ; HL - STARS, DE - SCREEN
LOOP:
PUSH H
CALL CLR ; Z=1 - COLOR INITIALIZED, CAN USE DE & C
POP H
CZ SINTRO
STARS: 
PUSH D
MOV E,M
INX H
MOV D,M
JNZ ST0  ; COLOR IS NOT INITIALIZED YET
MVI C,3
RST 2
XCHG
CNC SETCLR
XCHG
ST0:
RST 2
RST 2
LDAX D
XRI 8
STAX D
INR L
POP D
JMP LOOP
CLR: ; DE - SCREEN, B - COLUMN, C - COLOR
MOV A,B
ORA A
RZ
PUSH D
POP H
RST 1
INR L
RST 1
INR D
DCR B
RNZ
MVI D,0C0H
MVI B,30H
MOV E,L
INR E
RNZ
MOV B,E
RET
LGOCPY:
MVI E,118
MVI C,11
SPRCPY:
LDAX D
ORA M
STAX D
INX H
INX D
DCR C
JNZ SPRCPY
SI0:
XRA A
RET
SINTRO:
INR E
MOV A,E
ANI 3FH
JNZ SI0
PUSH D
PUSH H
LXI D,0C976H
LXI B,1E0BH
SCROLL: ; DE - X,Y; BC - W,H
MOV A,D
ADD B
DCR A
MOV H,A
MOV L,E
LDAX D
RAL
PUSH B
SC1:
MOV A,M
RAL
MOV M,A
DCR H
DCR B
JNZ SC1
POP B
INR E
DCR C
JNZ SCROLL
MOV B,C
POP H
POP D
RET
CCLOGO:
DB 7,0FH,0,3CH,7EH,0E0H,0CFH,0C7H,0E0H,07EH,3CH
DB 80H,0C0H,0E0H,60H,60H,0E0H,0C0H,080H,0,0,0
INTRO:
DB 'WELCOME TO CHAOS CONSTRUCTIONS   2016'
DB 0
END
