*/31JAN18:00 --GREYASM--
ORG $8000
OBJ $8000
KEYCLR EQU $C010
KEYHIT EQU $C000
BEEP EQU $C030
GMODE EQU $C050
TMODE EQU $C051
MIXED EQU $C053
NOMIX EQU $C052
PAGE1 EQU $C054
HGR EQU $C057
STATUS EQU $C08E
DATA EQU $C08F
PRTOUT EQU $C090
PRTRDY EQU $C1C1
SOAKTIME EQU $301
SLOTADR EQU $303
KEYEXIT EQU $304
KEY EQU $305
ROWSTART EQU $309
RADR EQU $06
DEST EQU $08
DEST2 EQU $1C
CTR EQU $19
YREG EQU $1B
TMP EQU $1E
*
GETARRAY JMP INIT ;ROUTINE TO GET IMAGES FROM THE MICRONEYE
JMP ROLLUP ;ROLLUP SCREEN IMAGE 1/3 OF THE WAY
JMP BITMAP ;8BIT VERSION OF GETARRAY STORED IN $4000-$43FF)
JMP CLRGREY ;CLEARS GREY CTR ARRAY
JMP ADDGREY ;BUILDS GREY SCALE TABLE OF IMAGE
JMP HGRPRINT ;PRINTS PICTURE IN 10 SHADES OF GREY
JMP HGINIT ;SETS UP EPSON FOR HIRES PRINTING
JMP HGDONE ;RESETS EPSON FOR NORMAL OPERATION
JMP EIGHT27
*
INIT LDA FIRST ;IF NOT FIRST TIME THRU ROUTINE THEN SKIP
BEQ A1 ; INITIALIZATION
DEC FIRST ;CLEAR 'FIRST TIME' FLAG TO FALSE
JSR GRCLR ;CLEAR HIRES SCREEN
A1 JSR SETGR ;SET UP APPLE FOR HIRES PAGE2 USAGE
START JSR ACIACLR ;FLUSH THE INPUT BUFFER
LDA #$D3
JSR SENDCMD
JSR SOAK
LDA #$C0
JSR SENDCMD ;TELL MICRONEYE TO SEND IMAGE AS SPECIFIED
LDX #0 ;INITIALIZE THE ROW INDEX
NEWROW LDY #0 ;START NEXT ROW AND INIT COLUMN INDEX (Y)
LDA ROWPTR,X ;BUILD BASE ROW ADRESS FOR CURRENT ROW
CLC
ADC ROWSTART
STA RADR ; FROM THE TABLE OF ADRESSES IN ROWPTR
INX
LDA ROWPTR,X
STA RADR+1
INX ;POINT X-REG TO NEXT ADDRESS IN ROWPTR
GET STY YREG ;GET NEXT BYTE FROM MICRONEYE
LDY SLOTADR ; LOAD OFFSET TO MICRONEYE SLOT
LDA STATUS,Y ; CHECK TO SEE IF NEXT BYTE HAS ARRIVED
LSR
BCS C15 ; IF BYTE AVAILABLE BRANCH
LDA #0 ; IF BYTE NOT YET AVAILABLE
STA CTR ; SET UP TIMEOUT COUNTER
LDA #$15
STA CTR+1
C0 DEC CTR ; CHECK FOR BYTE UNTIL TIMED OUT
BNE C1
DEC CTR+1
BNE C1
LDA BEEP ; IF TIMED OUT CLICK APPLE SPEAKER
LDA KEYHIT ; CHECK FOR KEYPRESS AFTER TIMING OUT
BMI DONE ; IF KEY HIT THEN RETURN TO APPLESOFT
JMP START ; OTHERWISE TRY REISSUING COMMAND SEQUENCE
C1 LDA STATUS,Y
LSR
BCC C0
C15 LDA DATA,Y ;WHEN BYTE AVAILABLE GET IT
LDY YREG ;RESTORE COLUMN POINTER TO Y-REG
CPY #40 ;IF PAST THE 40TH BYTE IN CURRENT ROW THEN
BGE C3 ; DONT PUT ONTO HIRES SCREEN
STA (RADR),Y
C3 INY ;INCREMENT COLUMN POINTER
CPY #37 ;HAVE WE REACHED THE END OF THE COLUMN?
BNE GET ; IF NOT JUST GO GET THE NEXT BYTE
CPX #$80 ; OTHERWISE
BNE NEWROW ; IF NOT DONE WITH IMAGE GO TO NEXTROW
DONE LDA #$D1
JSR SENDCMD
LDA #$20 ; BY DEFAULT CLEAR THE 'EXIT CAUSED BY KEY' FLAG
STA KEY ; AND BLANK THE KEY VALUE FOR SAFEKEEPING
LDA #0
STA KEYEXIT
LDA KEYHIT ; IF A KEY WAS HIT, THOUGH, WE NEED TO
BPL D1
BIT KEYCLR ; CLEAR THE KEYBOARD STROBE
INC KEYEXIT ; SET THE 'EXIT CAUSED BY KEY' FLAG
STA KEY
CMP #"Q" ; IF THE KEY WAS A 'Q'
BNE D1
JSR GRCLR ; CLEAR THE GRAPHICS SCREEN
LDA TMODE
D1 JSR MSEC
JSR MSEC
RTS
*
ROLLUP LDX #0
RU0 LDA ROWPTR,X
STA RADR
CLC
ADC #$28
STA DEST
ADC #$28
STA DEST2
INX
LDA ROWPTR,X
STA RADR+1
STA DEST+1
STA DEST2+1
INX
LDY #39
RU1 LDA (DEST),Y
STA (RADR),Y
LDA (DEST2),Y
STA (DEST),Y
LDA #0
STA (DEST2),Y
DEY
BPL RU1
CPX #$80
BNE RU0
RTS
*
BITMAP JSR ACIACLR
LDA #$DB
JSR SENDCMD
JSR SOAK
LDA #$D8
JSR SENDCMD
LDA #0
STA RADR
LDA #$40
STA RADR+1
LDY #0
LDX SLOTADR
GSTAT LDA STATUS,X
LSR
BCC GSTAT
LDA DATA,X
STA (RADR),Y
INY
BNE GSTAT
INC RADR+1
LDA RADR+1
CMP #$44
BNE GSTAT
LDA #$D9
JSR SENDCMD
JSR MSEC
JSR MSEC ;BUILD IN SOME WAIT
RTS
*
ACIACLR LDA #3 ;MASTER RESET ACIA
STY YREG
LDY SLOTADR
STA STATUS,Y
LDA #$14 ;1 START BIT, 8 DATA, 1 STOP BIT WITH EXT CLOCK
STA STATUS,Y
LDY YREG
RTS
*
GRCLR LDX #0 ;CLEAR PAGE2 OF HIRES
LDY #0
STY RADR
LDA #$20
STA RADR+1
TXA
E2 STA (RADR),Y
INY
BNE E2
INC RADR+1
INX
CPX #$20
BNE E2
RTS
*
SETGR LDA NOMIX ;SELECT MIXED GRAPHICS AND TEXT MODE
LDA HGR ;USE HIRES GRAPHICS
LDA PAGE1 ;USE PAGE1 OF HIRES
LDA GMODE ;SWITCH FROM TEXT TO GRAPHICS MODE
RTS
*
SENDCMD STY YREG ;SEND THEBYTE IN ACC TO THE MICRONEYE
LDY SLOTADR
PHA
F1 LDA STATUS,Y
AND #2
BEQ F1
PLA
STA DATA,Y
LDY YREG
RTS
*
SOAK LDA SOAKTIME+1 ;SOAK FOR THE NUMBER OF MILLISECONDS SPECIFIED
STA CTR+1 ; BY SOAKTIME
INC CTR+1
LDA SOAKTIME
STA CTR
INC CTR
LDA SOAKTIME
BNE G1
LDA SOAKTIME+1
BEQ G3
G1 JSR MSEC
DEC CTR
BNE G1
DEC CTR+1
BNE G1
G3 RTS
*
MSEC STY YREG ;1 MILLISECOND LOOP
LDY #197
H1 DEY
BNE H1
LDY YREG
RTS
*
EIGHT27 LDX #0
STX RADR
LDA #$40
STA RADR+1
NXTROW LDA ROWPTR,X
STA DEST
INX
LDA ROWPTR,X
STA DEST+1
INX
LDY #$0F
MOV LDA (RADR),Y
STA (DEST),Y
DEY
BPL MOV
LDY #0
RESHFT PHP
STY TMP
SHFT LDA (DEST),Y
PLP
ROL
STA (DEST),Y
PHP
INY
CPY #$13
BNE SHFT
PLP
LDY TMP
LDA (DEST),Y
LSR
STA (DEST),Y
INY
CPY #$13
BNE RESHFT
DEY
LDA #3
AND (DEST),Y
STA (DEST),Y
CLC
LDA RADR
ADC #$10
STA RADR
BCC NOCF
INC RADR+1
NOCF CPX #$80
BNE NXTROW
RTS
********************
PUTSTR STY TMP
TAY
BIT KEYCLR
M0 LDA STRING,Y
BMI M1
JSR PUTBYTE
INY
JMP M0
M1 LDY TMP
RTS
*
PUTBYTE STA PRTOUT
RDYWAIT LDA PRTRDY
BMI RDYWAIT
RTS
*
* SEE APPLESOFT MANUAL PG 82
FIXUP PLA
TAY
PLA
LDX $DF
TXS
PHA
TYA
PHA
RTS
*
CLRGREY LDX #0
LDY #0
STY RADR
LDA #$60
STA RADR+1
TXA
JMP E2 ;IN GRCLR ROUTINE
*
ADDGREY LDA #0
STA DEST
STA RADR
LDA #$60
STA DEST+1
LDA #$40
STA RADR+1
LDY #0
NBYTE LDA (RADR),Y
EOR #$FF
STA TMP
LDY #7
NBIT ASL TMP
LDA #0
ADC (DEST),Y
STA (DEST),Y
DEY
BPL NBIT
LDY #0
INC RADR
BNE Q0
INC RADR+1
Q0 CLC
LDA #8
ADC DEST
STA DEST
BCC Q1
INC DEST+1
LDA DEST+1
CMP #$80
BNE Q1
RTS
Q1 JMP NBYTE
*
HGRPRINT LDA #0
STA RADR
LDA #$60
STA RADR+1
BIT BEEP
BIT KEYCLR
LDY #0
HGROW LDA #HGRLINE-STRING
JSR PUTSTR
HG0 LDA (RADR),Y
CMP #9
BLT HGOK
LDA #8
HGOK ASL
ASL
ASL
CLC
ADC #P0-STRING
JSR PUTSTR
INY
BEQ HG1
CPY #$80
BEQ HG2
BNE HG0
HG1 INC RADR+1
LDA #CRLF-STRING
JSR PUTSTR
JMP HGROW
HG2 LDA #CRLF-STRING
JSR PUTSTR
LDA RADR+1
CMP #$7F
BEQ HGOUT
BIT KEYHIT
BPL HGROW
BIT KEYCLR
HGOUT RTS
*
HGINIT LDA #HGRSET-STRING
JSR PUTSTR
RTS
*
HGDONE LDA #HGREND-STRING
JSR PUTSTR
RTS
*
********************
STRING EQU *
HGRLINE DFB $1B,$4C,$00,$03,$FF
CRLF DFB $0D,$0A,$FF
HGRSET DFB $1B,$4F,$0D,$1B,$33,4,$0D,$FF
HGREND DFB $1B,$32,$0D,$0A,$1B,$4E,6,$0A,$FF
P0 DFB 00,00,00,00,00,00,$FF,$FF
DFB 00,00,00,01,00,04,$FF,$FF
DFB 08,02,00,00,04,01,$FF,$FF
DFB 10,00,01,04,10,00,$FF,$FF
DFB 10,00,05,00,10,05,$FF,$FF
DFB 03,04,10,05,10,04,$FF,$FF
DFB 10,05,10,05,10,05,$FF,$FF
DFB 15,13,11,06,13,11,$FF,$FF
DFB 15,15,15,15,15,15,$FF,$FF
*
FIRST DFB 1
ROWPTR DA $2000,$2400,$2800,$2C00,$3000,$3400,$3800,$3C00
DA $2080,$2480,$2880,$2C80,$3080,$3480,$3880,$3C80
DA $2100,$2500,$2900,$2D00,$3100,$3500,$3900,$3D00
DA $2180,$2580,$2980,$2D80,$3180,$3580,$3980,$3D80
DA $2200,$2600,$2A00,$2E00,$3200,$3600,$3A00,$3E00
DA $2280,$2680,$2A80,$2E80,$3280,$3680,$3A80,$3E80
DA $2300,$2700,$2B00,$2F00,$3300,$3700,$3B00,$3F00
DA $2380,$2780,$2B80,$2F80,$3380,$3780,$3B80,$3F80
END
4