In this section I would like to share
communicate with you with one of its developments, its
conventional name - Smart Print. In one
of the projects I needed a very powerful one
procedure for printing text, and soon it will be
was quickly implemented.
I will list the requirements that were set
when creating this printer:
- first of all, text output in a font with
floating character width (each character
has its own width;
- ability to print formatted
text (stretch across width);
- output in an arbitrary screen window as in
scrolling mode and page by page;
- possibility of slow printing (user-
the caller, if desired, can speed up or
pause);
- insertion of text variables.
The last point I would like npokom-
mehtupobatb especially. If there is enough
in the larger text block changes insignificantly
body part, it is better not to reshape
text, but entrust this work to the process itself
fool of the press. Let me explain the principle with an example.
small BASIC program:
10INPUT "Your Name: "; x$
20 INPUT "Your Age: "; y
30 PRINT "Your name is ";x$;
"and you are ";y;" years old!"
So, our procedure works a little -
in another way:
10 INPUT "Your Name: "; x$
20 INPUT "Your Age: "; y
30 LET y$ = STR$ y
40 LET z$ = "Your name is "+х$+
"and you are "+y$+" years old!"
50 PRINT z$
Especially for implementing this scheme in
memory is allocated a buffer for 8 variables,
maximum 32 characters each. Each re-
corresponds to a certain control
code. Having met it in the main line, the system
The theme will output the contents of the variable and pro-
will continue its work.
The output text is typed in alternative
encoding, the entire tabular
tsa from 0 to 255, with certain codes
are used as managers. Font is possible
prepare, for example, in the BGE program. B
the topmost line of each symbol
there is a binary code that determines the real
character width. In the application, in addition tois-
running code in Alasm format, you will find
and a ready-to-use font.
A number of requirements are presented to the text.
First of all, a set of controls is specified
codes Mostly these are ordinary
ASCII characters from those in your text
will not meet. Initially, their
the layout is:
"#" - this code indicates the end of a paragraph.
Since the printing program itself takes
depending on the location of the text within the window, it
need to know where one paragraph ends
and the next one begins. Warning:
the text is processed and printed paragraph by paragraph
valuable, so there are restrictions on the number
characters in the paragraph, but not in the text.
"@" - paragraph indentation, "red line".
In general, a paragraph may not indicate
begin to indent, but if necessary,
change this code immediately after the previous one
th.
"^" - end of text.
13 - instead of Enter codesare printed pro-
white. Codes 10 are generally ignored.
24.. 31 - having encountered such code, the program
will proceed to printing the variable numbered,
respectively, 0..7.
"£" (pound sterling or reverse anoct-
pof) - applies only inside variables -
noah to mark its end.
Now - about how to use the pe-
chat room. All information is provided via
registers as follows:
IX - address of the beginning of the text;
DE - output window coordinates
(D - row 0..23, E - column 0..31);
VS - output window size
(B - height 1..24, C - width 1..32);
A - flags. The values are summed up:
+1 for output with scrolling from below,
otherwise - regular printing page by page.
+2 for printing formatted text,
otherwise - with a torn edge.
+4 for delayed output.
The following are available during the printing process:
control keys:
Caps Shift- pause on/off;
Symb Shift - print acceleration;
Space - prints the next page.
The following is the full text of the procedure with
minimum comments.
;- Entry point 1, default parameters
PWO XOR A
LD D,A
LD E,A
LD B,24
LD С,32
LD A,4
;- Main entry point
PW1 LD (WIN),DE
LD (SIZ), BC
LD (FLG),A
LD (CRD),DE
LD A,С ;calculate the length
ADD A,A ;lines in pixels.
ADD A,A
ADD A,A
DEC ALD (SLN),A
LD A,B ;number of lines
INC A ;for printing
LD (PRIL),A
LD A,(FLG)
AND 1 ;scrolling?
JR Z,BLD ;teletype!
LD HL,SIZ+1
LD A,(WIN+1)
ADD A,(HL)
DEC A
LD(CRD+1),A
BLD LD (PSGS),IX ;beginning of paragraph
LD HL,BUF ; yes, now
LD BC,0 ;we are looking for the end!
XOR A
LD (LASPAS),A
NLT LD A,(IX)
INC IX
CP "#"
JR Z,FINPAS ;found!
SR "^"
JR Z,FINTXT ;end of text
SR "£"
JR Z,ENDV ;end variable.
SR 10
JR Z,NLT;urhop.
SR 13
JR Z,CRREP ; 13 -> 32
SR 24
JR C,NLT2
SR 32
JR C,VRSB ;variables...
NLT2 LD (HL),A ;copying
INC HL ;text to buffer
INC BC ;paragraph
JR NLT
CRREP LD A,32 ;change Enter
JR NLT2 ;to space
VRSB AND 7 ;3 least significant bits
PUSH HL ;code 24..31
LD L,A;дают номер
LD Н,0 ;перем. 0..7
LD DE,(VARS) ;ищем ее по
ADD HL,HL ;номеру!...
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,DE
LD (VADR),IX ;нашли!
PUSH HL
POP IX
POP HL
JR NLT
ENDV LD IX,(VADR) ;возврат в
JR NLT ;основной текст
FINTXT LD A,1
LD (LASPAS),A
LD A,"#"
FINPAS LD (HL),A ;абзац весь.
LD (PSGS),IX ;Печатаем его.
LD HL,BUFLD (LINS),HL
NXL LD A,(PRIL) ;check
DEC A ;filling
LD (PRIL),A ;windows
JR NZ,NXL2
LD A,(SIZ+1)
LD (PRIL),A
CALL PRSPC ;press SPACE
LD A,(FLG) ;if teletype,
AND 1 ;clean the window.
JR NZ,NXL2 ;if scroller,
CALL CLWIN ;do not clean!
LD HL,(WIN)
LD (CRD),HL
NXL2 LD A,(FLG)
AND 1
JR Z,NXLЗ
LD A,8 ;scroll window to
CALL SCRL ;8 px. up
NXLЗ LD HL,(LINS) ;MOSTCREEPY:
DEC HL ;definition
XOR A ;next
LD (WASP),A ;output
LD (LALI),A ;lines
LD B,A
LD C,A
LD IX,SNG-1
CIL INC HL
INC IX
LD A,(HL)
LD(IX),A
CP "#"
JR Z,ENL
PUSH HL
SR #20 ;a lot depends
JR NZ,NOSP ;from that, there is
LD HL,WASP ;is there a space there?
INC (HL)
NOSP LD DE,FONT ;character width
LD L,A ;take from FONTa
LD Н,0
ADDHL,HL
ADD HL,HL
ADD HL,HL
ADD HL,DE
LD (SYM),HL
LD A,(HL)
LD (IX+64),A
POP HL
INC B
ADD A,С
LD С,A
JR С,QUI
LD A,(SLN)
СР С
JR С,QUI
JR CIL
QUI LD A,B
LD (LLE),A
LD A,С
LD (SUM),A
LD A,(WASP) ;нет пробела?
OR A ;будем резать!
JR NZ,WORD
BROKEN DEC B
LD A,B
LD (LLE),A
LD (LINS),HL
JP NF
WORD LD A,С ;пошел процесс
SUB(IX+64) ;
LD С,A
DEC B
LD A,(IX)
СР
JR Z,WEND
DEC IX
DEC HL
JR WORD
ENL LD A,1 ;
LD (LALI),A ;
WEND INC. HL
LD (LINS), HL
LD A,B
LD (LLE),A
LD A,С
LD (SUM),A
LD A,(WASP)
СР
JR Z,NF
LD A,(FLG)
AND 2
JR Z,NF
LD A,(LALI)
OR A
JR NZ,NF
LD A,(SLN)
СР С
JR Z,NF
SHRT LDA,(LLE)
LD B,A
LD Е,A
XOR A
LD D,A
LD IX,SNG
ADD IX,DE
SHRL DEC IX
LD A,32
СР (IX)
JR Z,EXTE
SHR0 DJNZ SHRL
JR SHRT
EXTE INC (IX+64)
INC С
LD A,(SLN)
СР С
JR NZ,SHR0
NF CALL PLINE ;печать строки
LD A,(FLG)
AND 1
JR NZ,SKIP_3
LD HL,CRD+1
INC (HL)
SKIP_3 LD A,(LALI)
OR A
JP Z,NXL
LD IX,(PSGS)
LD A,(LASPAS)
OR A
JP Z,BLDRET
PLINE XOR A ;печатаем
LD (SHF),A ;строчку
LD DE,(CRD)
CALL CALC
LD (POS),HL
LD IX,SNG-1
LD A,(LLE)
INC A
LD (LENN),A
PQ1 LD A,(LENN)
DEC A
LD (LENN),A
RET Z
LD ВС,65278 ;CS, первое
IN A,(С) ;нажатие
AND 1
JR NZ,CONTIN
HALT
EXPLEA LD ВС,65278 ;отпуск. CS
IN A,(С)
AND 1
JR Z,EXPLEA
HALT
EXPPRE LD ВС,65278 ;CS, второе IN A,(С) ;нажатие
AND 1
JR NZ,EXPPRE
HALT
EXPLE2 LD ВС,65278 ;отпуск. CS
IN A,(С)
AND 1
JR Z,EXPLE2
CONTIN LD A,(FLG)
AND 4
JR Z,NODL
LD HL,1200 ;печать с
LD A,(FLG) ;задержкой
AND 1
JR Z,DLY
LD HL,10000
DLY LD ВС,32766 ;Symb Shift
IN A,(С) ;не отменяет
AND 2 ;задержку, a
JR NZ,DYL ;укopaчивaет
SRL Н ;ее в 8 раз
SRL Н
SRL Н
SRL Н
DYL NOP
DEC HL
LD A,Н
OR L
JR NZ,DYL
NODL INC IX
LD A,(IX) ;печатаем
LD DE,FONT ;символ
LD L,A
LD Н,0
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,DE
LD (SYM),HL
LD DE,(POS)
LD B,7
LPP1 INC D
INC HL
LD С,B
LD A,(SHF)
LD B,A
OR A
LD A,(HL)
JR Z,LPPЗ
LPP2 SRL A
DJNZ LPP2LPPЗ LD B,С
LD С,A
LD A,(DE)
OR С
LD (DE),A
LD A,(SHF)
ADD A,(IX+64)
LD (NSF),A
СР 9
JR С,ONLY1
INC Е
LD С,B
LD A,(SHF)
LD B,A
LD A,8
SUB B
LD B,A
OR A
LD A,(HL)
JR Z,LPPS
LPPЧ SLA A
DJNZ LPPЧ
LPPS LD B,С
LD С,A
LD A,(DE)
OR С
LD (DE),A
DEC Е
ONLY1 DJNZ LPP1
LD A,(NSF)
LD B,A
LD HL,(POS)SRL A
SRL A
SRL A
ADD A,L
LD L,A
LD (POS),HL
LD A,B
AND 7
LD (SHF),A
JP PQ1
CLWIN LD HL,WIN ;очистка окна
LD D,(HL)
INC HL
LD Е,(HL)
LD (COORD),DE
LD HL,SIZ
LD D,(HL)
INC HL
LD Е,(HL)
LD (PARAM),DE
LD DE,(COORD)
LD A,Е
СР #17
RET P
LD (COORD),DE
LD A,Е
AND #18
OR #40
LD Н,A
LD A,Е
AND 7OR A
RRA
RRA
RRA
RRA
ADD A,D
LD L,A
LD A,(PARAM)
LD B,A
LOOP_V PUSH ВС
PUSH HL
LD B,8
LOOP_8 PUSH ВС
PUSH HL
LD A,(PARAM+1)
LD B,A
XOR A
LOOP_Н LD (HL),A
INC HL
DJNZ LOOP_Н
POP HL
POP ВС
INC Н
DJNZ LOOP_8
POP HL
POP ВС
LD A,#20
ADD A,L
LD L,A
JR NC,NO_SEG
LD A,8
ADD A,Н
LD Н,A
NO_SEG DJNZ LOOP_V
RET
PRSPC LD ВС,32766 ;нажатие
IN A,(С) ;пробела
AND 1
JR NZ,PRSPC
RET
SCRL LD B,A ;скроллинг
SCRL0 PUSH ВС ;рабочего окна
SCR_UP LD A,(WIN)
LD С,A
LD A,(SIZ+1)
LD B,A
LD A,(WIN+1)
SLA A
SLA A
SLA A
SLA B
SLA B
SLA B
DEC B
SLA С
SLA С
SLA С
PUSHAF
PUSH ВС
CALL 8880
POP ВС
POP AF
SCRUP1 INC A
PUSH AF
PUSH ВС
PUSH HL
CALL 8880
POP DE
PUSH HL
LD A,(SIZ)
LD С,A
LD B,0
LDIR
POP HL
POP ВС
POP AF
DJNZ SCRUP1
LD (HL),0
LD D,Н
LD Е,L
INC DE
LD A,(SIZ)
DEC A
JR Z,SCROV
LD С,A
LD B,0
LDIR
SCROV POP ВС
DJNZ SCRL0
RETCALC LD A,D ;address calculation
AND #18 ;on the screen
ADD A,#40 ;coordinates
LD Н,A
LD A,D
AND 7
RRCA
RRCA
RRCA
ADD A,E
LD L,A
RET
POS DW 0
SHF DB 0
SYM DW 0
NSF DB 0
VARS DW VAR
VADR DW 0
WIN DW 0
SIZ DW 0
ATR DB 0
FLG DB 0
SLN DB 0
SUM DB 0
LLE DB 0
LENN DB 0
LENN DB 0CRD DW 0
PSGS DW 0
LINS DW 0
LALI DB 0
LASPAS DB 0
PRIL DB 0
WASP DB 0
COORD DW 0
PARAM DW 0
BUF DEFS 2048 ;paragraph buffer
SNG DEFS 128 ;line buffer
VAR DEFS 256 ;variable buffer.
FONT INCBIN "font" ;font
That's it! This procedure, in principle,
Overall, there is only one serious drawback:
It didn't turn out to be very fast. But,
taking into account all its bells and whistles, this is not too
com critical. I hope that someone
this creation will come in handy. Good luck!
Share your thoughts about the article