*/02MAR11:30 --ENHANCER--
ORG $8100
OBJ $8100
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
*
SOAKTIME EQU $300
ENHANCMD EQU $302
SLOTADR EQU $304
ROWSTART EQU $305
KEY EQU $306
KEYEXIT EQU $307
*
RADR EQU $06
DEST EQU $08
DEST2 EQU $1C
CTR EQU $19
YREG EQU $1B
TMP EQU $1E
*
BD EQU $06
TERMA EQU $07
TERMB EQU $1C
TERMC EQU $1D
TERMD EQU $1B
TERME EQU $1A
*
DO 0
BLOCK MAC ;DEFINES 8 CONTIGUOUS ROWS OF HIRES SCREEN
DA ]1,]1+$400,]1+$800
DA ]1+$0C00,]1+$1000
DA ]1+$1400,]1+$1800
DA ]1+$1C00
<<<
FIN
*
JMP NORMPIC ;MICRONEYE TO HIRES SCREEN ROUTINE
JMP BITMAP ;MICRONEYE TO $4000-$5FFF W/ENHANCEMENTS
*
*
NORMPIC JSR SETGR ;SET UP APPLE FOR HIRES PAGE1 USAGE
NSTART JSR ACIACLR ;FLUSH THE INPUT BUFFER
LDA #$D3 ;SEND COMMAND TO SOAK W/O SEND
JSR SENDCMD
JSR SOAK
LDA #$C0 ;SEND IMAGE W/O SOAK
JSR SENDCMD ; (ALT,WIDEPIX,7BIT--256 X 64 IMAGE)
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 ;0-SELECT UPPER 1/3 OF SCREEN
STA RADR ; $28 THE 2ND 1/3, $50 THE 3RD THIRD
INX ;RADR CONTAINS ADDRESS OF CURRENT ROW
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 NDONE ; IF KEY HIT THEN RETURN TO APPLESOFT
JMP NSTART ; 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
NDONE LDA #$D1
JSR SENDCMD
DOKEY 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 ; RETURN TO TEXT MODE
D1 RTS
*
BITMAP JSR ACIACLR ;THIS ROUTINE RECEIVES 512 X 128
JSR SETGR ; IMAGE FROM CAMERA AND STORES IT
START LDA #$FB ; IN LOCATIONS $4000-$5FFF
JSR SENDCMD ;TELL CAMERA TO SOAK W/O SEND
JSR SOAK
LDA #$E8 ;HAVE CAMERA SEND IMAGE
JSR SENDCMD ; (NOALT,WIDEPIX,8BIT--512 X128)
LDA #0 ;SET UP INDIRECT ADDR FOR INCOMING DATA
STA RADR
LDA #$40
STA RADR+1
LDY #0
LDX SLOTADR ;GET DATA
GSTAT LDA #0
STA CTR ;SETUP COUNTDOWN TIMER FOR TIMEOUT
GS1 LDA STATUS,X ;LOOP UNTIL CHAR AVAIL OR TIMED OUT
LSR
DEC CTR
BNE NOHANG
LDA BEEP ;IF TIMED OUT, BEEP AND RESTART
JMP START
NOHANG BCC GSTAT
LDA DATA,X
STA (RADR),Y ;STORE BYTE IN BITMAP LOCATION
INY
BNE GSTAT
INC RADR+1
LDA RADR+1
CMP #$60 ;IF DONE THEN ENHANCE THE IMAGE
BNE GSTAT
LDA #$F9 ;BUT FIRST SET CAMERA TO REFRESH W/O SEND
JSR SENDCMD
LDA ENHANCMD ;IF ENHANCMD = 0 THEN
BNE ENH ; PERFORM NO ENHANCEMENTS AND
LDA #0
STA PAGEMASK
JSR EIGHT27B ; JUST MOVE IMAGE TO HIRES SCREEN
JMP DOKEY ; CHECK FOR KEYPRESS
ENH JSR ENHANCE ;IF ENHANCMD <> 0 THEN
LDA ENHANCMD ; ENHANCE THE IMAGE
CMP #3 ; IF ENHANCMD = 3 THEN
BNE NORM ; WE'RE BEING ASKED TO MAKE A GREY
LDA #$60 ; TONE IMAGE BY MOVING THIS IMAGE TO
STA PAGEMASK ; PAGE2 OF HIRES AND ALTERNATING
JSR EIGHT27 ; INTERSPERSING BITS OF THE SECOND
JSR GREYXFER ; EXPOSURE INTO THE FIRST EXPOSURE
JMP DOKEY
NORM LDA #0 ;IF NOT MESSING WITH GREY IMAGE THEN
STA PAGEMASK ; JUST TAKE THE ENHANCED IMAGE AND
JSR EIGHT27 TRANSFER BITMAP TO HIRES SCREEN
JMP DOKEY ; AND LASTLY, CHECK FOR KEYPRESS
*
GREYXFER LDX #0 ;THIS ROUTINE INTERLEAVES THE IMAGE IN
LDA #$55 ; PAGE1 HIRES WITH IMAGE IN PAGE2
STA GMASK ; THE ROUTINE ASSUMES THAT THE CALLING
NGROW LDA ROWPTR,X ; PROGRAM HAS TAKEN CARE OF SEEING THAT
STA RADR ; EACH EXPOSURE WAS OF VARIED DURATION
STA DEST
INX ;EVEN ROWS AND ODD ROWS START ON DIFF
LDA ROWPTR,X ; HIRES PAGES TO CREATE A CHECKERED
STA DEST+1 ; EFFECT
EOR #$60 ;RADR CONTAINS THE CURRENT PAGE2 ROW ADR
STA RADR+1 ;DEST CONTAINS THE CURRENT PAGE1 ROW ADR
LDY #39
NGREY LDA (RADR),Y
AND GMASK
STA TMP
LDA GMASK
EOR #$7F
AND (DEST),Y
ORA TMP
STA (DEST),Y
LDA GMASK
EOR #$7F
STA GMASK
DEY
BPL NGREY
LDA GMASK
EOR #$7F
STA GMASK
INX
BNE NGROW
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 PAGE1 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 MIXED ;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 #199
H1 DEY
BNE H1
LDY YREG
RTS
*
EIGHT27B LDX #0 ;TRANSFER BITMAP IMAGE IN $4000-$5FFF
STX RADR ; TO HIRES PAGE1
LDA #$40 ;PROCESS ONLY ENOUGH OF EACH ROW TO
STA RADR+1 ; FILLUP THE HIRES SCREEN
JMP NXTROW
*
EIGHT27 LDX #0 ;TRANSFER BITMAP IMAGE IN $6000-$7FFF
STX RADR ; TO HIRES PAGE1
LDA #$60 ;PROCESS ONLY ENOUGH OF EACH ROW TO
STA RADR+1 ; FILLUP THE HIRES SCREEN
NXTROW LDA ROWPTR,X ;THE PROCESS INVOLVES TAKING EACH BYTE
STA DEST ; IN THE BITMAP AND PUTTING IT IN THE
INX ; PROPER PLACE IN THE HIRES SCREEN
LDA ROWPTR,X ;THE DIFFICULTY COMES IN CONVERTING
EOR PAGEMASK ; FROM EIGHT IMAGE PIXELS PER BYTE
STA DEST+1 ; TO THE HIRES SCREEN'S REQUIRED
INX ; SEVEN IMAGE PIXELS PER BYTE WITH
LDY #40 ; THE HIGH BIT OF EACH BYTE SET TO 0
MOV LDA (RADR),Y
DEY
STA (DEST),Y
CPY #0
BNE MOV
LDY #0
RESHFT PHP
STY TMP
SHFT LDA (DEST),Y
PLP
ROL
STA (DEST),Y
PHP
INY
CPY #40
BNE SHFT
PLP
LDY TMP
LDA (DEST),Y
LSR
STA (DEST),Y
INY
CPY #40
BNE RESHFT
CLC
LDA RADR
ADC #$40
STA RADR
BCC NOCF
INC RADR+1
NOCF CPX #0
BNE NXTROW
RTS
*
***************************
* ENHANCE REARRANGES THE BITMAP IMAGE IN $4000-$5FFF TO A
* BITMAP IMAGE IN $6000-$7FFF THAT CORRESPONDS MORE
* PRECISELY TO THE ACTUAL PLACEMENT OF IMAGE SENSING
* ELEMENTS IN THE OPTICRAM. BECAUSE THE WIDEPIX OPTION
* WAS SELECTED TO SEND THE IMAGE, THE PICTURE IS 512 X 128
* INSTEAD OF 256 X 128. THE 512 X 128 COINCIDES WITH THE
* SPACING OF PIXELS IN THE HORIZONTAL DIRECTION.
* THE ALGORITHM REARRANGES EACH BYTE AS FOLLOWS:
* FOR BYTES IN EVEN ROWS(STARTING WITH ROW 0) --
* BITS 0,3,4,7 ARE 'HOLES'
* BITS 2 AND 6 ARE UNCHANGED
* BIT 5 COMES FROM BIT 2 OF THEBYTE 1 ROW PREVIOUS
* BIT 1 COMES FROM BIT6 OF THE BYTE 1 ROW PREV - 1 BYTE
*
* FOR BYTES IN ODD ROWS --
* BITS 1,2,5,6 ARE 'HOLES'
* BITS 0 AND 4 ARE UNCHANGED
* BITS 3,7 COME FROM BITS 0,4 OF THE BYTE 1 ROW PREV
* BIT 6 -- PLACE IN BIT 1 OF THIS BYTE+1 OF NEXT ROW
*********************************
ENHANCE LDA #$BF
STA RADR
STA DEST
LDA #$3F
STA RADR+1
LDA #$5F
STA DEST+1
NEVEN LDY #1
LDA (RADR),Y
ASL
ASL
ASL
ORA #$DF
STA DEST2
DEY
LDA (RADR),Y
ROL
ROL
ROL
ORA #$FD
STA DEST2+1
LDY #$41
LDA (RADR),Y
ORA #$BB
AND #$FF
AND DEST2
AND DEST2+1
STA (DEST),Y
INC RADR
INC DEST
BNE NODUB
INC RADR+1
INC DEST+1
NODUB LDA DEST
AND #$3F
CMP #$24
BNE NEVEN
CLC
LDA DEST
ADC #$1B
STA DEST
STA RADR
BCC NODD
INC RADR+1
INC DEST+1
NODD LDY #1
LDA (RADR),Y
ASL
ASL
ASL
ORA #$77
STA DEST2
LDY #$41
LDA (RADR),Y
ORA #$EE
AND #$FF
AND DEST2
STA (DEST),Y
INC RADR
INC DEST
BNE NODUB2
INC RADR+1
INC DEST+1
NODUB2 LDA DEST
AND #$3F
CMP #$24
BNE NODD
CLC
LDA DEST
ADC #$1B
STA DEST
STA RADR
BCC NOINC
INC RADR+1
INC DEST+1
NOINC LDA DEST
CMP #$BF
BNE NEVENJ
LDA DEST+1
CMP #$7F
BNE NEVENJ
JMP FILLCK
NEVENJ JMP NEVEN
FILLCK LDA ENHANCMD ;IF ENHANCMD = 1 THEN ENHANCEMENT
AND #3 ; WITHOUT FILLIN IS PERFORMED
CMP #2 ;OTHERWISE
BGE FILLIN ; THE IMAGE 'HOLES' ARE FILLED IN
JMP ND
FILLIN LDA #$C0
STA DEST
LDA #$5F
STA DEST+1
LDX #0
NE LDY #0
LDA (DEST),Y
STA TERMA
LDY #$80
LDA (DEST),Y
STA TERMB
AND TERMA
STA BD
LDY #$40
LDA (DEST),Y
LSR
ORA RMASK,X
ORA BD
STA TERMC
LDA (DEST),Y
ASL
ORA LMASK,X
ORA BD
STA TERMD
LDA TERMA
ORA TERMB
ORA CMASK,X
AND (DEST),Y
AND TERMC
AND TERMD
STA (DEST),Y
FILDON INC DEST
NI LDA DEST
AND #$3F
CMP #$24
BNE NE
LDA DEST
CLC
ADC #$1C
STA DEST
BCC NI2
INC DEST+1
BMI ND
NI2 TXA
EOR #1
TAX
JMP NE
ND LDX #$39
NCLN LDA $6040,X ;CLEAR UP CLUTTER IN FIRST ROW
STA $6000,X
DEX
BPL NCLN
RTS
*
UNITS DFB 0
WAY DFB 0
MASK DFB $99,$66
CMASK DFB $66,$99
RMASK DFB $EE,$BB
LMASK DFB $77,$DD
GMASK DS 1
PAGEMASK DS 1
********************
EXP OFF ;TURN OFF MACRO EXPANSION
ROWPTR >>> BLOCK.$2000
>>> BLOCK.$2080
>>> BLOCK.$2100
>>> BLOCK.$2180
>>> BLOCK.$2200
>>> BLOCK.$2280
>>> BLOCK.$2300
>>> BLOCK.$2380
>>> BLOCK.$2028
>>> BLOCK.$20A8
>>> BLOCK.$2128
>>> BLOCK.$21A8
>>> BLOCK.$2228
>>> BLOCK.$22A8
>>> BLOCK.$2328
>>> BLOCK.$23A8