ORG #8000
;
NBCOLS EQU 80 ; number of columns
NBROWS EQU 50 ; number of rows
NBPATTS EQU 10 ; number of patterns to compare with
;
JP Generate #8000: create a "telestarized" pict.
JP Display #8003: display function
;
Generate OR a
LD hl,ScrFile default screen file ifnone specified
LD b,CellBuf-ScrFile and its default size
JR z,Begin
CP 2
RET nc too much parameters
LD h,(ix+1)
LD l,(ix+0)
PUSH hl
POP ix
LD b,(ix+0) filename size and adress
LD l,(ix+1)
LD h,(ix+2)
Begin PUSH hl
PUSH bc
LD a,2
CALL #bc0e
POP bc
POP hl
LD de,Buffer
CALL #bc77
RET nc
LD hl,#c000
PUSH hl
CALL #bc83
CALL #bc7a
POP hl
LD iy,TStarMat
LD b,NBROWS
LoopY PUSH bc
PUSH hl
LD b,NBCOLS
LoopX LD de,CellBuf
PUSH bc
PUSH hl
LD b,4
StorCell LD a,(hl) ; buffering the 4 bytes of the cell
LD (de),a
XOR %10101010 just to "watch" the process advance
LD (hl),a
INC de
CALL #bc26
DJNZ StorCell
CALL CellCal pattern-matching calculation
POP hl
INC hl next cell (ie next column here)
INC iy
POP bc
DJNZ LoopX till the 80 cells per line are done
POP hl
LD e,4
NextY CALL #bc26
DEC e
JR nz,NextY the new line address is calculated
POP bc
DJNZ LoopY repeat 'til the whole lines are done
RET
;
CellCal XOR a ; no best response for the moment
LD (CellMax),a
LD ix,Pattern0 ix points the first candidate pattern
LD d,a d is the pattern counter
MatchTst XOR a
LD (CellSum),a pattern-matching sum's reset to 0
LD hl,CellBuf
LD a,(ix+0) a is the first pattern-byte
PUSH af hl points the first cell-byte
AND (hl) and this piece of code
LD b,a performs the "(a.b)+!(a+b)" boolean
POP af operation
OR (hl)
CPL
OR b
INC hl
CALL BitCount whose result is sent for analyse
LD a,(ix+1) idem for the 2nd bytes
PUSH af
AND (hl)
LD b,a
POP af
OR (hl)
CPL
OR b
INC hl
CALL BitCount
LD a,(ix+2) and 3rd bytes of pattern and cell
PUSH af
AND (hl)
LD b,a
POP af
OR (hl)
CPL
OR b
INC hl
CALL BitCount
LD a,(ix+3) ... and last bytes as well
PUSH af
AND (hl)
LD b,a
POP af
OR (hl)
CPL
OR b
CALL BitCount
LD hl,CellSum hl points the pattern-matching score
LD a,(CellMax)
CP (hl) if it's a new max response, save it !
JR c,NewMax
JR NextPatt
NewMax LD a,(hl)
LD (CellMax),a
LD (IY+0),d storage in the TELESTARISATION-buffer
NextPatt INC d ; next pattern to be tested
LD a,d
CP NBPATTS is that the last pattern ?
RET z
INC ix
INC ix
INC ix
INC ix ix now points the new pattern basis
JR MatchTst
;
BitCount LD e,8 ; counts set bits
BCLoop SLA a
JR NC,BCNoBit
PUSH hl for each bit set
LD hl,CellSum the response must be incremented
INC (hl)
POP hl
BCNoBit DEC e
JR NZ,BCLoop
RET
;
DispPatt PUSH hl
LD ix,Pattern0
LD de,4
DispP0 OR a ; calculates pattern offset
JR z,DispP2
DispP1 ADD ix,de
DEC a
JR nz,DispP1
DispP2 LD a,(ix+0) ; display the 4 bytes of the pattern
LD (hl),a
CALL #bc26
INC ix
DEC e
JR nz,DispP2
POP hl
RET
;
ScrFile DM telestar.scr
;
CellBuf DS 4
CellSum DB 0
CellMax DB 0
;
Pattern0 DB %11111111
DB %11111111
DB %00000000
DB %00000000
;
Pattern1 DB %00000000
DB %00000000
DB %11111111
DB %11111111
;
Pattern2 DB %11110000
DB %11110000
DB %11110000
DB %11110000
;
Pattern3 DB %00001111
DB %00001111
DB %00001111
DB %00001111
;
Pattern4 DB %11000000
DB %11110000
DB %11111100
DB %11111111
;
Pattern5 DB %11111111
DB %00111111
DB %00001111
DB %00000011
;
Pattern6 DB %11111111
DB %11111100
DB %11110000
DB %11000000
;
Pattern7 DB %00000011
DB %00001111
DB %00111111
DB %11111111
;
Pattern8 DB %11111111
DB %11111111
DB %11111111
DB %11111111
;
Pattern9 DB %00000000
DB %00000000
DB %00000000
DB %00000000
;
Display LD a,2
CALL #bc0e
LD hl,#c000
LD iy,TStarMat
LD b,NBROWS
NextLine PUSH bc
PUSH hl
LD b,NBCOLS
NextCell LD a,(iy+0)
CALL DispPatt
INC hl next cell (ie next column here)
INC iy
DJNZ NextCell till the 80 cells per line are done
POP hl
LD e,4
NextY2 CALL #bc26
DEC e
JR nz,NextY2 the new line address is calculated
POP bc
DJNZ NextLine till the 50 lines are done
RET
;
TStarMat DS NBROWS*NBCOLS ; the "TeleStar"-picture buffer
;
Buffer