Publication: Sincus News
Pub Details: SINCUS v5 n4 (Volume 5, Issue 4)
Date: May - June 1987
Pages: 7-10
;Jump here to handle the edit line
; Identical to Spectrum at 0D02
083D FE02 CP #02
083F 3880 JR C,L07C1 ;Error if lower screen is too large
0841 FD8631 ADD A,(IY+49) ;DF_SZ
0844 D619 SUB #19
0846 D0 RET NC ;If we don't have to scroll
0847 ED44 NEG ;Number of lines to scroll
0849 C5 PUSH BC
084A 47 LD B,A
084B 2A8F5C LD HL,(ATTR_T)
084E E5 PUSH HL
084F 2A915C LD HL,(P_FLAG)
0852 E5 PUSH HL
0853 CD8808 CALL #0888 ;Use permanent color info
0856 78 LD A,B ;A=the number of lines to scroll
;Scroll the screen A times
0857 F5 L0857 PUSH AF
0858 216B5C LD HL,DF_SZ
085B 46 LD B,(HL)
085C 78 LD A,B
085D 3C INC A
085E 77 LD (HL),A ;We just incremented DF_SZ
085F 21895C LD HL,S_POSN + 1
0862 BE CP (HL)
0863 3803 JR C,L0868 ;If scrolling lower screen
0865 34 INC (HL)
0866 0618 LD B,#18 ;Scroll whole screen
0868 CD3B09 L0868 CALL #093B ;Does the actual scrolling
086B F1 POP AF
086C 3D DEC A
086D 20E8 JR NZ,L0857 ;If we're not done
086F E1 POP HL
0870 FD7557 LD (IY+87),L ;P_FLAG
0873 E1 POP HL
0874 228F5C LD (ATTR_T),HL
0877 ED4B885C LD BC,(S_POSN)
087B FDCB0286 RES 0,(IY+2) ;TV_FLAG
087F CD1409 CALL #0914 ;Move to new print position
0882 FDCB02C6 SET 0,(IY+2) ;TV_FLAG
0886 C1 POP BC
0887 C9 RET
;Copy permanent color info into using temporary variables
; Identical to Spectrum at 0D4D
0888 AF XOR A
0889 2A8D5C LD HL,(ATTR_P)
088C FDCB0246 BIT 0,(IY+2) ;TV_FLAG
0890 2804 JR Z,L0896
0892 67 LD H,A
0893 FD6E0E LD L,(IY+14) ;BORDCR
0896 228F5C L0896 LD (ATTR_T),HL
0899 21915C LD HL,P_FLAG
089C 2002 JR NZ,L08A0
089E 7E LD A,(HL)
089F 0F RRCA
08A0 AE L08A0 XOR (HL)
08A1 E655 AND #55
08A3 AE XOR (HL)
08A4 77 LD (HL),A
08A5 C9 RET
;CLS handler
; Identical to Spectrum at 0D6B
08A6 CDEA08 CALL #08EA ;Actually clears display memory
08A9 213C5C LD HL,TV_FLAG
08AC CBAE RES 5,(HL) ;Don't clear lower screen after keypress
08AE CBC6 SET 0,(HL) ;Output to lower screen
08B0 CD8808 CALL #0888 ;We'll use permanent color info
08B3 FD4631 LD B,(IY+49) ;DF_SZ
08B6 CD7F09 CALL #097F ;Clear the bottom B lines
08B9 21C05A LD HL,#5AC0 ;First attribute byte for lower screen
08BC 3A8D5C LD A,(ATTR_P)
08BF 05 DEC B
08C0 1807 JR L08C9
08C2 0E20 L08C2 LD C,#20 ;Characters per line
08C4 2B L08C4 DEC HL ;Loop to change all attributes in line
08C5 77 LD (HL),A
08C6 0D DEC C
08C7 20FB JR NZ,L08C4
08C9 10F7 L08C9 DJNZ L08C2 ;Loop if more lines
08CB FD363102 LD (IY+49),#02 ;DF_SZ - 2 lines in lower screen
;Fix up lower screen
; Identical to Spectrum at 0D94
08CF 3EFD LD A,#FD ;Channel "K" - internal stream
08D1 CD3012 CALL #1230 ;Make it current channel
08D4 2A515C LD HL,(CURCHL)
08D7 110005 LD DE,#0500 ;Normal output address for screen
08DA A7 AND A
08DB 73 L08DB LD (HL),E
08DC 23 INC HL
08DD 72 LD (HL),D ;Restore output address
08DE 23 INC HL
08DF 110E0C LD DE,#0C0E ;Normal input address
08E2 3F CCF
08E3 38F6 JR C,L08DB ;Now loop back & restore input address
08E5 012117 LD BC,#1721 ;Point to bottom line
08E8 182A JR L0914 ;Move to that position
;This routine does the actual "display clear"
; Identical to Spectrum at 0DAF
08EA 210000 LD HL,#0000
08ED 227D5C LD (COORDS),HL
08F0 FDCB3086 RES 0,(IY+48) ;FLAGS2
08F4 CDCF08 CALL #08CF ;Cleans up the lower screen
08F7 3EFE LD A,#FE ;Channel "S" - internal stream
08F9 CD3012 CALL #1230 ;Make it current channel
08FC CD8808 CALL #0888 ;Use permanent colors
08FF 0618 LD B,#18
0901 CD7F09 CALL #097F ;Clear bottom B lines
0904 2A515C LD HL,(CURCHL)
0907 110005 LD DE,#0500
090A 73 LD (HL),E
090B 23 INC HL
090C 72 LD (HL),D ;Current output is standard screen out
090D FD365201 LD (IY+82),#01 ;SCR_CT - resets scroll count
0911 012118 LD BC,#1821 ;Point to top line
;Find memory address for first byte of a display file character
; Move to this new print position. Enter with BC = row/column
; on display, or C = column in print buffer; FLAGS, bit 1 decides
; Identical to Spectrum at 0DD9
0914 21005B L0914 LD HL,#5B00 ;Print buffer
0917 FDCB014E BIT 1,(IY+1) ;FLAGS
091B 2012 JR NZ,L092F ;If handling printer
091D 78 LD A,B
091E FDCB0246 BIT 0,(IY+2) ;TV_FLAG
0922 2805 JR Z,L0929 ;If handling upper screen
;Must be lower screen
0924 FD8631 ADD A,(IY+49) ;DF_SZ
0927 D618 SUB #18
0929 C5 L0929 PUSH BC
092A 47 LD B,A
092B CDD609 CALL #09D6 ;Compute disp file address of the line
092E C1 POP BC
092F 3E21 L092F LD A,#21
0931 91 SUB C
0932 5F LD E,A
0933 1600 LD D,#00 ;DE=Column number
0935 19 ADD HL,DE ;Display file address of the character
0936 C3F305 JP #05F3 ;Move to this position
;Scroll the display 17 (hex) times
; Identical to Spectrum at 0DFE
0939 0617 LD B,#17
;Scroll the display B times
; Identical to Spectrum at 0E00
093B CDD609 CALL #09D6 ;Get address of line
093E 0E08 LD C,#08 ;8 Lines per character
0940 C5 L0940 PUSH BC
0941 E5 PUSH HL
0942 78 LD A,B
0943 E607 AND #07
0945 78 LD A,B
0946 200C JR NZ,L0954 ;If we're not moving across one of the
; boundaries for "display thirds"
;Here to handle the "thirds"
0948 EB L0948 EX DE,HL
0949 21E0F8 LD HL,#F8E0
094C 19 ADD HL,DE
094D EB EX DE,HL
094E 012000 LD BC,#0020
0951 3D DEC A
0952 EDB0 LDIR
;Do the actual scrolling
0954 EB L0954 EX DE,HL
0955 21E0FF LD HL,#FFE0
0958 19 ADD HL,DE
0959 EB EX DE,HL
095A 47 LD B,A
095B E607 AND #07
095D 0F RRCA
095E 0F RRCA
095F 0F RRCA
0960 4F LD C,A
0961 78 LD A,B
0962 0600 LD B,#00
0964 EDB0 LDIR
0966 0607 LD B,#07
0968 09 ADD HL,BC
0969 E6F8 AND #F8
096B 20DB JR NZ,L0948 ;If there are more "thirds"
096D E1 POP HL
096E 24 INC H
096F C1 POP BC
0970 0D DEC C
0971 20CD JR NZ,L0940 ;If all 8 lines haven't been scrolled
0973 CDC309 CALL #09C3 ;Get the attribute address
0976 21E0FF LD HL,#FFE0
0979 19 ADD HL,DE
097A EB EX DE,HL
097B EDB0 LDIR ;Move the attribute bytes
097D 0601 LD B,#01
;Clear the bottom B lines of the display
; Identical to Spectrum at 0E44
097F C5 PUSH BC
0980 CDD609 CALL #09D6 ;Get address of line
0983 0E08 LD C,#08
0985 C5 L0985 PUSH BC
0986 E5 PUSH HL
0987 78 LD A,B
0988 E607 L0988 AND #07
098A 0F RRCA
098B 0F RRCA
098C 0F RRCA
098D 4F LD C,A
098E 78 LD A,B
098F 0600 LD B,#00
0991 0D DEC C
0992 54 LD D,H
0993 5D LD E,L
0994 3600 LD (HL),#00
0996 13 INC DE
0997 EDB0 LDIR
0999 110107 LD DE,#0701
099C 19 ADD HL,DE
099D 3D DEC A
099E E6F8 AND #F8
09A0 47 LD B,A
09A1 20E5 JR NZ,L0988
09A3 E1 POP HL
09A4 24 INC H
09A5 C1 POP BC
09A6 0D DEC C
09A7 20DC JR NZ,L0985
;Here to do attributes
09A9 CDC309 CALL #09C3 ;Get attribute address
09AC 62 LD H,D
09AD 6B LD L,E
09AE 13 INC DE
09AF 3A8D5C LD A,(ATTR_P)
09B2 FDCB0246 BIT 0,(IY+2) ;TV_FLAG
09B6 2803 JR Z,L09BB
09B8 3A485C LD A,(BORDCR)
09BB 77 L09BB LD (HL),A
09BC 0B DEC BC
09BD EDB0 LDIR
09BF C1 POP BC
09C0 0E21 LD C,#21
09C2 C9 RET
;Converts display file address in HL to attribute address
; Also converts line number in B to display position in BC
; Identical to Spectrum at 0E88
09C3 7C LD A,H
09C4 0F RRCA
09C5 0F RRCA
09C6 0F RRCA
09C7 3D DEC A
09C8 F650 OR #50
09CA 67 LD H,A
09CB EB EX DE,HL
09CC 61 LD H,C
09CD 68 LD L,B
09CE 29 ADD HL,HL
09CF 29 ADD HL,HL
09D0 29 ADD HL,HL
09D1 29 ADD HL,HL
09D2 29 ADD HL,HL
09D3 44 LD B,H
09D4 4D LD C,L
09D5 C9 RET
;Compute display file address of a line. Enter with line n[illegible]
; = B. HL gets the address.
; Identical to Spectrum at 0E9B
09D6 3E18 LD A,#18
09D8 90 SUB B
09D9 57 LD D,A
09DA 0F RRCA
09DB 0F RRCA
09DC 0F RRCA
09DD E6E0 AND #E0
09DF 6F LD L,A
09E0 7A LD A,D
09E1 E618 AND #18
09E3 F640 OR #40
09E5 67 LD H,A
09E6 C9 RET
;################################################################
;Looks like a debug routine that was never taken out. Waits a
; time delay, then waits for a keypress, then clears the lower
; screen.
; Has no Spectrum counterpart
09E7 F5 PUSH AF
09E8 C5 PUSH BC
09E9 D5 PUSH DE
09EA 01409C LD BC,#9C40 ;Time delay
;Wait till timeout
09ED 0B L09ED DEC BC
09EE 79 LD A,C
09EF B0 OR B
09F0 20FB JR NZ,L09ED
;Wait for keypress
09F2 AF L09F2 XOR A
09F3 DBFE IN A,(#FE)
09F5 E61F AND #1F
09F7 FE1F CP #1F
09F9 28F7 JR Z,L09F2
09FB CDA908 CALL #08A9 ;Part of clear screen routine
09FE D1 POP DE
09FF C1 POP BC
0A00 F1 POP AF
0A01 C9 RET
;##################################
;# TS2040 Printer Control Section #
;##################################
;COPY handler
; Identical to Spectrum at 0EAC
0A02 F3 DI
0A03 06B0 LD B,#B0 ;Lines per display
0A05 210040 LD HL,#4000 ;Start of display file
0A08 E5 L0A08 PUSH HL
0A09 C5 PUSH BC
0A0A CD4A0A CALL #0A4A ;Copy 1 line of pixels
0A0D C1 POP BC
0A0E E1 POP HL
0A0F 24 INC H
0A10 7C LD A,H
0A11 E607 AND #07
0A13 200A JR NZ,L0A1F
0A15 7D LD A,L
0A16 C620 ADD A,#20
0A18 6F LD L,A
0A19 3F CCF
0A1A 9F SBC A,A
0A1B E6F8 AND #F8
0A1D 84 ADD A,H
0A1E 67 LD H,A
0A1F 10E7 L0A1F DJNZ L0A08 ;If all 8 lines not yet printed
0A21 180D JR L0A30 ;To kill the motor & clear the buffer
;Copy print buffer to TS2040 printer
; Identical to Spectrum at 0ECD
0A23 F3 DI
0A24 21005B LD HL,#5B00 ;Address of print buffer
0A27 0608 LD B,#08 ;8 Pixel lines
0A29 C5 L0A29 PUSH BC
0A2A CD4A0A CALL #0A4A ;Copy 1 line of pixels
0A2D C1 POP BC
0A2E 10F9 DJNZ L0A29 ;If all 8 lines not printed
0A30 3E04 L0A30 LD A,#04
0A32 D3FB OUT (#FB),A ;Kill printer motor
0A34 FB EI
;Clear printer buffer
; Identical to Spectrum at 0EDF
0A35 21005B LD HL,#5B00 ;Address of buffer
0A38 FD7546 LD (IY+70),L ;PR_CC - reset printer position
0A3B AF XOR A
0A3C 47 LD B,A
0A3D 77 L0A3D LD (HL),A
0A3E 23 INC HL
0A3F 10FC DJNZ L0A3D ;Clear it all
0A41 FDCB308E RES 1,(IY+48) ;FLAGS2 - buffer empty
0A45 0E21 LD C,#21 ;Print position
0A47 C31409 JP #0914 ;Store it
;Copy 1 line of print buffer to TS2040 printer
; Identical to Spectrum at 0EF4
0A4A 78 LD A,B ;Line number
0A4B FE03 CP #03
0A4D 9F SBC A,A ;00, except for line # = 2 or 1
0A4E E602 AND #02
0A50 D3FB OUT (#FB),A ;Slows the motor on the last 2 lines
0A52 57 LD D,A
0A53 CD0920 L0A53 CALL #2009 ;Check the BREAK key
0A56 380A JR C,L0A62 ;If it's not pressed
0A58 3E04 LD A,#04
0A5A D3FB OUT (#FB),A ;Kill the motor
0A5C FB EI
0A5D CD350A CALL #0A35 ;Clear buffer
0A60 CF RST 8
0A61 0C DEFB #0C ;BREAK - CONT repeats
;Here if BREAK was not pressed
0A62 DBFB L0A62 IN A,(#FB)
0A64 87 ADD A,A
0A65 F8 RET M
0A66 30EB JR NC,L0A53
0A68 0E20 LD C,#20
0A6A 5E L0A6A LD E,(HL)
0A6B 23 INC HL
0A6C 0608 LD B,#08
0A6E CB12 L0A6E RL D
0A70 CB13 RL E
0A72 CB1A RR D
0A74 DBFB L0A74 IN A,(#FB)
0A76 1F RRA
0A77 30FB JR NC,L0A74 ;Wait till it's ready for next pixel
0A79 7A LD A,D
0A7A D3FB OUT (#FB),A
0A7C 10F0 DJNZ L0A6E
0A7E 0D DEC C
0A7F 20E9 JR NZ,L0A6A
0A81 C9 RET
;############################
;# The Line Editor Section #
;############################
;Main editor - to input & edit a line
; Similar to Spectrum at 0F2C
0A82 2A3D5C LD HL,(ERR_SP) ;Address of error handler
0A85 E5 PUSH HL ;Make it a return address
0A86 21E50B LD HL,#0BE5 ;Address of edit error handler
0A89 E5 PUSH HL ;Make it a return address
0A8A ED733D5C LD (ERR_SP),SP ;Error handler is now edit error handl[illegible]
;Get each keystroke
; Similar to Spectrum at 0F38
0A8E CDCF11 CALL #11CF ;Wait for a keypress
0A91 F5 PUSH AF ;Save it
0A92 1600 LD D,#00
0A94 FD5EFF LD E,(IY-1) ;PIP - length of key click
0A97 21C800 LD HL,#00C8 ;pitch
0A9A CDF303 CALL #03F3 ;BEEP the keypress
0A9D F1 POP AF ;Get the keypress
0A9E 218E0A LD HL,#0A8E
0AA1 E5 PUSH HL ;A RET will effectively JP #0A8E
;### The following 6 instructions are an addition for DELETE
0AA2 FE0C CP #0C ;DELETE character
0AA4 200C JR NZ,L0AB2 ;If not DELETE
;Here for DELETE
0AA6 FDCB306E BIT 5,(IY+48) ;FLAGS2 - DELETE key repeat
0AAA 2006 JR NZ,L0AB2 ;If not repeat
0AAC FDCB015E BIT 3,(IY+1) ;FLAGS - L mode
0AB0 2835 JR Z,L0AE7 ;If not, add a DELETE character
0AB2 FE18 L0AB2 CP #18
0AB4 3031 JR NC,L0AE7 ;If a printable character, or a token
0AB6 FE07 CP #07
0AB8 382D JR C,L0AE7 ;Accept a PRINT comma
0ABA FE10 CP #10
0ABC 383A JR C,L0AF8 ;Different routine to handle EDIT chars
;Control characters need more than one byte
0ABE 010200 LD BC,#0002
0AC1 57 LD D,A
0AC2 FE16 CP #16 ;OVER control + 1
0AC4 380C JR C,L0AD2 ;If character was from INK to OVER
;Here for AT & TAB
0AC6 03 INC BC
0AC7 FDCB377E BIT 7,(IY+55) ;FLAGX
0ACB CAB40B JP Z,#0BB4 ;If doing INPUT ... LINE ...
0ACE CDCF11 CALL #11CF ;Wait for keypress
0AD1 5F LD E,A ;Save it
;Get extra bytes for control characters
0AD2 CDCF11 L0AD2 CALL #11CF ;Wait for next character
0AD5 D5 PUSH DE ;Save character
0AD6 2A5B5C LD HL,(K_CUR)
0AD9 FDCB0786 RES 0,(IY+7) ;MODE - K mode
0ADD CDB812 CALL #12B8 ;Make spaces
0AE0 C1 POP BC ;Get characters
0AE1 23 INC HL
0AE2 70 LD (HL),B
0AE3 23 INC HL
0AE4 71 LD (HL),C ;Insert these in BC
0AE5 180A JR L0AF1 ;To insert character in A
;Add a character to INPUT or EDIT line
; Identical to Spectrum at 0F81
0AE7 FDCB0786 L0AE7 RES 0,(IY+7) ;MODE - K mode
0AEB 2A5B5C LD HL,(K_CUR) ;Cursor position
0AEE CDB812 CALL #12B8 ;Make 1 space
0AF1 12 L0AF1 LD (DE),A ;Enter character in A into space
0AF2 13 INC DE
0AF3 ED535B5C LD (K_CUR),DE ;Update cursor position
0AF7 C9 RET ;REturn thru #0A8E that was PUSHed
;Jump here from main editor. Handle editing keys
; Identical to Spectrum at 0F92
0AF8 5F L0AF8 LD E,A
0AF9 1600 LD D,#00 ;Put the code in DE
0AFB 21FF0A LD HL,#0AFF ;Base address for EDIT routines
0AFE 19 ADD HL,DE ;Partial address
0AFF 5E LD E,(HL) ;Get the offset
0B00 19 ADD HL,DE ;Address of handling routine
0B01 E5 PUSH HL ;RET will execute it
0B02 2A5B5C LD HL,(K_CUR) ;Cursor position
0B05 C9 RET ;Effective JP to handler routine
;Offset table for editing keys
; Identical to Spectrum at 0FF0
0B06 09 DEFB #09 ;EDIT
0B07 66 DEFB #66 ;cursor left
0B08 6A DEFB #6A ;cursor right
0B09 50 DEFB #50 ;cursor down
0B0A B5 DEFB #B5 ;cursor up
0B0B 70 DEFB #70 ;DELETE
0B0C 7E DEFB #7E ;ENTER
0B0D CF DEFB #CF ;Symbol Shift
0B0E D4 DEFB #D4 ;Graphics
;Handle the edit keys. Either pull down the current BASIC lin[illegible]
; or erase the present INPUT info
; Identical to Spectrum at 0FA9
0B0F 2A495C LD HL,(E_PPC) ;Current line #
0B12 FDCB376E BIT 5,(IY+55) ;FLAGX - INPUT mode
0B16 C2FD0B JP NZ,#0BFD ;If so, clear the edit area
0B19 CDD616 CALL #16D6 ;Get address of current line
0B1C CD2413 CALL #1324 ;Get the line number
0B1F 7A LD A,D
0B20 B3 OR E
0B21 CAFD0B JP Z,#0BFD ;If number is zero, clear edit area
0B24 E5 PUSH HL ;Save line address
0B25 23 INC HL ;Point to length
0B26 4E LD C,(HL)
0B27 23 INC HL
0B28 46 LD B,(HL) ;Get the length
0B29 210A00 LD HL,#000A
0B2C 09 ADD HL,BC ;Make it a little larger
0B2D 44 LD B,H
0B2E 4D LD C,L ;Put it in BC
0B2F CDBB1F CALL #1FBB ;See if there's enough room in memor[illegible]
; return here only if yes
0B32 CDFD0B CALL #0BFD ;Clear edit area
0B35 2A515C LD HL,(CURCHL) ;Current channel address
0B38 E3 EX (SP),HL ;Exchange it on the stack for curren[illegible]
; line address
0B39 E5 PUSH HL ;Then stack that
0B3A 3EFF LD A,#FF ;Channel "R" - internal stream
0B3C CD3012 CALL #1230 ;Make it current channel
0B3F E1 POP HL ;Line address
0B40 2B DEC HL ;One less than that
0B41 FD350F DEC (IY+15) ;E_PPC - prevent print of cursor
0B44 CDAC15 CALL #15AC ;Print the BASIC line
0B47 FD340F INC (IY+15) ;E_PPC - lo byte
0B4A 2A595C LD HL,(E_LINE) ;Address of line in edit area
0B4D 23 INC HL
0B4E 23 INC HL
0B4F 23 INC HL
0B50 23 INC HL ;Point to BASIC part
0B51 225B5C LD (K_CUR),HL
0B54 E1 POP HL ;Original channel address
0B55 CD4812 CALL #1248 ;Set proper channel flags
0B58 C9 RET ;Effective JP to #0A8E
;Handle a "cursor down"
; Identical to Spectrum at 0FF3
0B59 FDCB376E BIT 5,(IY+55) ;FLAG_X
0B5D 2008 JR NZ,L0B67 ;If in INPUT mode
0B5F 21495C LD HL,E_PPC
0B62 CD5B16 CALL #165B ;Get next line number
0B65 186D JR L0BD4 ;Do an automatic listing
0B67 FD360010 L0B67 LD (IY+0),#10 ;ERR_NR - code for STOP in INPUT
0B6B 181D JR L0B8A ;Treat it as an error
;Handle a "cursor left"
; Identical to Spectrum at 1007
0B6D CD970B CALL #0B97 ;Decrement cursor, unless at start
0B70 1805 JR L0B77 ;Redo K_CUR