*/05MAY12:00 --CAMASM--
ORG $8000
OBJ $8000
KEYCLR EQU $C010
KEYHIT EQU $C000
BEEP EQU $C030
GMODE EQU $C050
TMODE EQU $C051
MIXED EQU $C053
PAGE1 EQU $C054
PAGE2 EQU $C055
HGR EQU $C057
STATUS EQU $C08E
DATA EQU $C08F
WAIT EQU $FCA8
COMMAND EQU $300
SOAKTIME EQU $301
SLOTADR EQU $303
KEYEXIT EQU $304
KEY EQU $305
WHITECT EQU $306
COLBYTES EQU $308
ROWCT EQU $309
EXITEOF EQU $30B
BYTSUSED EQU $30C
RADR EQU $06
MAP EQU $08
MAPADR EQU $6000
CTR EQU $19
YREG EQU $1B
TMPCMD EQU $1C
TMP EQU $1E
*
GETARRAY JMP INIT ;ROUTINE TO GET IMAGES FROM THE MICRONEYE
P2XFER JMP PAG2XFER ;ROUTINE TO MOVE BOTTOM OF TEXTPAGE1 TO PAGE2
SAVESCR JMP SCR2MAP ;ROUTINE TO COMPRESS IMAGE FOR DISK STORAGE
LOADSCR JMP MAP2SCR ;ROUTINE TO DECOMPRESS DISK IMAGE
ONERRFIX JMP FIXUP ;ROUTINE TO MAKE APPLESOFT 'ONERR' WORK PROPERLY
*
ALARMF DFB 0
LOALARM DA 0
HIALARM DA $FFFF
*
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
JSR ACIACLR ;FLUSH THE INPUT BUFFER
START LDA COMMAND ;IF THE SOAK BIT IS SET WE JUST SOAK AND SEND
AND #2 ; THE COMMAND AS IS
BNE B0
LDA PREVCMD ;IF THIS COMMAND REFRESHES BUT THE LAST COMMAND
AND #2 ; SOAKED WE NEED TO RECHARGE THE ARRAY TO 5V
BEQ B00 ; BY TELLING THE CAMERA TO SEND A FRAME WITH
JSR TOSSCAN ; THE REFRESH BIT SET
B00 LDA COMMAND ;WHEN USING REFRESH/PROCESSING BETWEEN SCANS
ORA #$13 ; 1) COMMAND CAMERA TO GO INTO SOAK MODE
STA TMPCMD ; WITHOUT SENDING AN IMAGE
JSR SENDCMD
JSR SOAK ; 2) SOAK FOR THE SPECIFIED PERIOD OF TIME
LDA COMMAND ; 3) CHANGE COMMAND SO THAT IT WILL NOT SOAK
AND #$FC ; WHILE SENDING
STA TMPCMD
JMP B2
B0 LDA KEY ;WE WERE SOAKING BUT HAD TO EXIT TO PROCESS A
BEQ B1 ; KEY. THEREFORE WE NEED TO TOSS THIS FIRST
JSR TOSSCAN ; FRAME BECAUSE ITS OVEREXPOSED
B1 JSR SOAK ;ELSE JUST SOAK FOR THE SPECIFIED PERIOD OF TIME
LDA COMMAND
STA TMPCMD
B2 JSR SENDCMD ;TELL MICRONEYE TO SEND IMAGE AS SPECIFIED
LDX #0 ;INITIALIZE THE ROW INDEX AND WHITECT
STX WHITECT ;WHITECT IS A SAMPLING OF THE NUMBER OF WHITE
STX WHITECT+1 ; BITS IN THE IMAGE (1 BIT/BYTE SAMPLED)
STX ROWPGS ;ROWPGS IS INCREMENTED WHEN X REG EXCEEDS 255
STX KEY
NEWROW LDY #0 ;START NEXT ROW AND INIT COLUMN INDEX (Y)
LDA ROWPTR,X ;BUILD BASE ROW ADRESS FOR CURRENT ROW
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
BPL STARTJ ; IF KEY HIT THEN RETURN TO APPLESOFT
JMP DONE
STARTJ 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
LSR ;SAMPLE LOW BIT OF BYTE
BCC C2
INC WHITECT ;IF WHITE THEN INCREMENT WHITECT
BNE C2
INC WHITECT+1
C2 ROL ;RESTORE BYTE FROM CAMERA TO ORIGINAL FORM
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 COLBYTES ;HAVE WE REACHED THE END OF THE COLUMN?
BNE GET ; IF NOT JUST GO GET THE NEXT BYTE
CPX ROWCT ; OTHERWISE
BNE NEWROW ; IF NOT DONE WITH IMAGE GO TO NEXTROW
CPX #0 ; IF BOTH X AND LSB OF ROWCT = 0 THEN
BNE REFCK
INC ROWPGS ; INCREMENT ROWPGS
LDA ROWPGS ; IF ROWPGS <> MSB OF ROWCT THEN
CMP ROWCT+1
BNE NEWROW ; JUST GO ON TO NEXT ROW
REFCK LDA COMMAND
AND #2
BNE ALARMCK
LDA COMMAND
AND #$FC
ORA #$11
STA TMPCMD
JSR SENDCMD
ALARMCK LDA ALARMF ;CHECK TO SEE IF IN ALARM MODE
BEQ NOALARM ;IF NOT, SKIP OVER TEST
LDA LOALARM+1
CMP WHITECT+1
BEQ EQ1
BCS SOUNDIT
BCC HICHK
EQ1 LDA LOALARM
CMP WHITECT
BCS SOUNDIT
HICHK LDA HIALARM+1
CMP WHITECT+1
BEQ EQ2
BCC SOUNDIT
BCS NOALARM
EQ2 LDA HIALARM
CMP WHITECT
BCS NOALARM
SOUNDIT LDX #$80
BL1 LDA #$18
JSR WAIT
LDA BEEP
DEX
BNE BL1
LDA #$60
JSR WAIT
LDA KEYHIT
BPL SOUNDIT
JMP DONE
NOALARM LDA EXITEOF ; OTHERWISE
BNE DONE ; WE RETURN TO APPLESOFT IF EXIT FLAG SET
LDA KEYHIT ; ALSO RETURN TO APPLESOFT IF KEY WAS HIT
BMI DONE
JMP START ; JUST START OVER AGAIN IF NOT EXITING
DONE LDA #0
STA KEYEXIT
STA KEY
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 ; PUT APPLE INTO TEXTMODE
LDA PAGE1
D1 LDA COMMAND
STA PREVCMD
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 #$40
STA RADR+1
TXA
E2 STA (RADR),Y
INY
BNE E2
INC RADR+1
INX
CPX #$20
BNE E2
RTS
*
SETGR LDA MIXED ;SELECT MIXED GRAPHICS AND TEXT MODE
LDA HGR ;USE HIRES GRAPHICS
LDA PAGE2 ;USE PAGE2 OF HIRES
LDA GMODE ;SWITCH FROM TEXT TO GRAPHICS MODE
RTS
*
SENDCMD STY YREG ;SEND THEBYTE IN TMPCMD TO THE MICRONEYE
LDY SLOTADR
F1 LDA STATUS,Y
AND #2
BEQ F1
LDA TMPCMD
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
*
TOSSCAN LDA COMMAND
STA TMPCMD
JSR SENDCMD
LDY SLOTADR
W0 LDX #$10
W1 LDA STATUS,Y
DEX
BEQ W3
LSR
BCC W1
LDA DATA,Y
JMP W0
W3 RTS
*
MSEC STY YREG ;1 MILLISECOND LOOP
LDY #$A7
H1 DEY
BNE H1
LDY YREG
RTS
********************
SCR2MAP LDX #<MAPADR
STX MAP
LDA #>MAPADR
STA MAP+1
N0 LDY #39
LDA ROWPTR,X
STA RADR
INX
LDA ROWPTR,X
STA RADR+1
INX
N1 LDA (RADR),Y
STA (MAP),Y
DEY
BPL N1
CLC
LDA MAP
ADC #40
BCC N2
INC MAP+1
N2 STA MAP
CPX ROWCT
BNE N0
RTS
*
MAP2SCR LDX ROWCT
LDA #<MAPADR
STA MAP
LDA #>MAPADR
STA MAP+1
P0 LDY #39
LDA ROWPTR,X
STA RADR
INX
LDA ROWPTR,X
STA RADR+1
INX
P1 LDA (MAP),Y
STA (RADR),Y
DEY
BPL P1
CLC
LDA MAP
ADC #40
BCC P2
INC MAP+1
P2 STA MAP
CPX #0
BNE P0
RTS
*
* SEE APPLESOFT MANUAL PG 82
FIXUP PLA
TAY
PLA
LDX $DF
TXS
PHA
TYA
PHA
RTS
*
PAG2XFER STX TMP
LDX #$27
PX LDA $650,X
STA $A50,X
LDA $6D0,X
STA $AD0,X
LDA $750,X
STA $B50,X
LDA $7D0,X
STA $BD0,X
DEX
BPL PX
LDX TMP
RTS
********************
STRING EQU *
GRSETUP DFB $1B,$41,$7,$1B,$4F,$1B,$3D,$0D,$FF
GRPRINT DFB 09,$1B,$4B,0,0,$FF
TEXTSET DFB $1B,$32,$0D,$1B,$4E,$06,$0D,$0C,$FF
TABSET DFB $1B,$44,$13,0,$0D,$FF
*
ROWPGS DS 1
PREVCMD DS $FF
FIRST DFB 1
ROWPTR DA $4000,$4400,$4800,$4C00,$5000,$5400,$5800,$5C00
DA $4080,$4480,$4880,$4C80,$5080,$5480,$5880,$5C80
DA $4100,$4500,$4900,$4D00,$5100,$5500,$5900,$5D00
DA $4180,$4580,$4980,$4D80,$5180,$5580,$5980,$5D80
DA $4200,$4600,$4A00,$4E00,$5200,$5600,$5A00,$5E00
DA $4280,$4680,$4A80,$4E80,$5280,$5680,$5A80,$5E80
DA $4300,$4700,$4B00,$4F00,$5300,$5700,$5B00,$5F00
DA $4380,$4780,$4B80,$4F80,$5380,$5780,$5B80,$5F80
DA $4028,$4428,$4828,$4C28,$5028,$5428,$5828,$5C28
DA $40A8,$44A8,$48A8,$4CA8,$50A8,$54A8,$58A8,$5CA8
DA $4128,$4528,$4928,$4D28,$5128,$5528,$5928,$5D28
DA $41A8,$45A8,$49A8,$4DA8,$51A8,$55A8,$59A8,$5DA8
DA $4228,$4628,$4A28,$4E28,$5228,$5628,$5A28,$5E28
DA $42A8,$46A8,$4AA8,$4EA8,$52A8,$56A8,$5AA8,$5EA8
DA $4328,$4728,$4B28,$4F28,$5328,$5728,$5B28,$5F28
DA $43A8,$47A8,$4BA8,$4FA8,$53A8,$57A8,$5BA8,$5FA8
END