; copy modified 27.09.99                                        
; Assembled using Comet assembler Ver 1.8                       
; Machine: Simcoupe.  Ok on real Sam as well.                   
                                                                
; Save this file as outsrc                                      
; Once assembled save Object as "wordcd" start 65527,32760      
                                                                
;       * * * * * * * * * * * * * * * * * * * * *               
;       *                                       *               
;       *        SOURCE FILE CALLED OUTSRC      *               
;       *                                       *               
;       *                                       *               
;       *                                       *               
;       *         RJ WILKINSON SEP 1999        *               
;       *                                       *               
;       * * * * * * * * * * * * * * * * * * * * *               
                                                                
;                        IMPORTANT                              
                                                                
; SEE CONTROL1 AND CONTROL2 FOR ENTRY FROM BASIC TO LOAD        
; AND SAVE ROUTINES                                             
                                                                
; Label "the_end" MUST NOT GO ABOVE 16383 or the system         
; variables will be overwriten. Use Comand mode + v the_end     
; to find address of label after assembly.                      
                                                                
; The routines below will have fetched the directory from       
; basic and need to now jump back to the appropriate routine    
; to continue the save load etc                                 
; Erase a file and load a char set both use the load routine    
; Merge uses the load routine. so control number is same.       
                                                                
; A 1 IN CONTROL FLAG  =  JP   DIRECTORY                        
; A 3 IN CONTROL FLAG  =  JP   LOADER. also merge,erase,ld chars
; A 4 IN CONTROL FLAG  =  JP   sv_full                          
; A 5 IN CONTROL FLAG  =  JP   sv_block                         
                                                                
; ANY NUMBER OTHER THAN THESE AND A JUMP TO THE ERROR ROUTINE   
; IS MADE.                                                      
                                                                
; TEXT PAGE 1 IN .................   PAGE 5   98304             
; TEXT PAGE 2 IN .................   PAGE 7   131072            
; TEXT PAGE 3 IN .................   PAGE 25  425984            
; FORMAT AND BLOCK BUFFER IN .....   PAGE 11                    
; INFO 1 IN ......................   PAGE 17  *                 
; INFO 2 IN ......................   PAGE 19  *                 
; INFO 3 IN ......................   PAGE 9   *                 
; INFO 4 IN ......................   PAGE 21  *                 
; DICTIONARY IN ..................   PAGE 23  *                 
; DOS PAGE .......................   PAGE 29 512k.  PAGE 13 256k
; DIR$ POKED INTO NORMAL RAM......   PAGE 1                     
                                                                
; (* SEE BASIC FOR LOAD ADDRESSES FOR THE ABOVE)                
                                                                
; Constants in the program                                      
                                                                
topmem:        EQU  64768 ; Top of available memory             
file_st:       EQU  32768 ; Start of text file                  
file_len:      EQU  32000 ; Length of text file                 
bottom_line:   EQU  56320 ; Bottom line on the screen           
BF_buf_len:    EQU  32000 ; Block and format buffer length      
astack:        EQU  16999 ; Start of the Machine stack          
chars:         EQU  60768 ; Start of the 16 bit character set   
chars2:        EQU  62768 ; Start of menus charset              
eight_bit_1:   EQU  17000 ; Location of the eight bit char set  
eight_bit_2:   EQU  17830 ; Location of menus char set          
charend:       EQU  18590 ; 60 bytes at end of prev char set    
eight_bit_3:   EQU  18660 ; Selected from menu                  
eight_bit_4:   EQU  19430 ; Selected from menu                  
eight_bit_5:   EQU  20200 ;    "      "    "                    
eight_bit_6:   EQU  20970 ;    "      "    "                    
                                                                
; 6 CHARACTER SETS ARE LOADED. EACH IS 768 BYTES LONG           
; EIGHT_BIT_1 IS THE NORMAL TEXT SET.                           
; EIGHT_BIT_2 IS THE MENUS AND DEFAULT SET.                     
; THE OTHER 4 ARE SELECTABLE FROM THE FONTS MENU.               
; DIFFERENT SETS CAN BE LOADED. INFO BELOW.                     
                                                                
; THE ADDRESSES OF EACH ARE AS FOLLOWS. MUST ONLY BE 8 BIT SETS 
                                                                
                                                                
; EIGHT_BIT_1 ................  82536                           
; EIGHT_BIT_2 ................  83366   TOTAL LENGTH OF CHARSET 
; CHAREND ....................  18590                           
; EIGHT_BIT_3 ................  84196   = 4740 BYTES FROM 82536 
; EIGHT_BIT_4 ................  84966                           
; EIGHT_BIT_5 ................  85736                           
; EIGHT_BIT_6 ................  86506                           
                                                                
; CHAREND IS WHERE THE MENU FRAME DATA IS POKED 6 CHARACTERS    
; 6 X 8 = 48 BYTES. POKED FROM THE CODE NOT BASIC.              
; DATA FOR THESE IS IN THE CODE SO CANNOT BE CHANGED FROM BASIC.
                                                                
BF_buffer:     EQU  32768 ; Block and Format buffer.uses page 11
dictionary:    EQU  32768 ; dictionary in page 18 512k machine  
f8:            EQU  200   ; F8 function key code                
f5:            EQU  197   ; F5 function key code                
f0:            EQU  192   ; F0 function key code                
f9:            EQU  201   ; F9 function key code                
                                                                
;            *****************************                      
;            * PAGES USED IN THE PROGRAM *                      
;            *****************************                      
                                                                
; Pages used in the program. FOR A 256k Change DOS_PAGE value   
; or the clock values wont be passed back to basic.             
                                                                
DOS_PAGE:      EQU  29    ; 29 FOR A 512K OR 13 FOR A 256K      
TEXT1:         EQU  5     ; Normal startup text page = 98304    
TEXT2:         EQU  7     ; Next text page           = 131072   
INFO3P:        EQU  9     ; Info 3 page                         
BUFFERP:       EQU  11    ; Block and format buffer             
INFO1P:        EQU  17    ; Info1 page  512k only               
INFO2P:        EQU  19    ; Info2 page  512k only               
INFO4P:        EQU  21    ; Info4 page  512k only               
DICTP:         EQU  23    ; Dictionary  512k only               
TEXT3:         EQU  25    ; Text file 3            = 425984     
                                                                
                                                                
; System variables from 16384. ADD 65536 WHEN POKING FROM BASIC 
                                                                
kbqb:          EQU  16384 ; Keyboard variables                  
kbqp:          EQU  16401                                       
kbuff:         EQU  16403 ; Keyboard buffer                     
SPARE:         EQU  16421 ; spare                               
lasth:         EQU  16422                                       
cur_pos:       EQU  16423 ; 1 for the dir function              
lkpb:          EQU  16424                                       
repct:         EQU  16426 ; Keyboard repeat value               
lastkv:        EQU  16427 ; Last key pressed                    
lastk:         EQU  16429                                       
repdel:        EQU  16430 ; Repeat and delay                    
repper:        EQU  16431 ; Repeat                              
flags:         EQU  16432                                       
flags2:        EQU  16433                                       
pflag:         EQU  16434 ; Printer flag                        
lf4c0:         EQU  16435                                       
lf4c2:         EQU  16437                                       
lf4c4:         EQU  16439                                       
lf4c6:         EQU  16441                                       
lf4c7:         EQU  16442                                       
lf4c8:         EQU  16443                                       
lf4c9:         EQU  16442                                       
lf4ca:         EQU  16443                                       
                                                                
; Main variables and storage locations                          
                                                                
line:          EQU  16444 ; Current line in the screen          
col:           EQU  16445 ; Current col in the screen           
lline:         EQU  16446                                       
pyge:          EQU  16447 ; Used for the page number            
pstart:        EQU  16448 ; Page start counter                  
pgtemp:        EQU  16449 ; Temporary storage for counter       
sposn:         EQU  16450 ; Address of cursor in screen         
sposn2:        EQU  16452 ; For message printing                
sposn3:        EQU  16454 ; Temporary storage for print position
tempstr:       EQU  16456                                       
temp:          EQU  16458                                       
memry:         EQU  16459 ; Adress of hidden crsr in text file  
total:         EQU  16461 ; Total lines used in text file       
memtop:        EQU  16463 ; Top of available memory             
buffer:        EQU  16465 ;                                     
wrap:          EQU  16535 ; Wrap on off storage                 
chr_cnt:       EQU  16536 ; Count the characters for word wrap  
chr_buf:       EQU  16537 ; Store the last key pressed          
chrbuff:       EQU  16538 ; as above : temporary                
spostmp:       EQU  16539 ; Temporary screen position           
text_page:     EQU  16541 ; Current text page in use * * * *    
ed_var:        EQU  16542 ; Used in word wrap routine           
var:           EQU  16543 ;      "             "                
sc_cnt:        EQU  16544                                       
prntr:         EQU  16545                                       
wvar:          EQU  16547                                       
pnm_var:       EQU  16549                                       
just_var:      EQU  16550 ; Justify on off                      
open_flag:     EQU  16551 ;                                     
buff_flag:     EQU  16552 ; 0 = empty 1= paragraph 2 = screen   
mem_temp:      EQU  16554 ; used in margin format routine       
dir_store:     EQU  16556 ; 2 Store dir printing postion        
s_m_var:       EQU  16558 ; Holds L S M B D save/load flag etc  
len_var:       EQU  16559                                       
f_len_var:     EQU  16561                                       
page_temp:     EQU  16563                                       
aaaa:          EQU  16564                                       
t_just_var:    EQU  16565 ; Temp word wrap and justify on off   
t_wrap:        EQU  16566 ; storage:                            
block_var:     EQU  16567                                       
char_1:        EQU  16568 ; Store char under first block marker 
char_2:        EQU  16569 ; Store char under second block marker
block_strt:    EQU  16570 ; Address of start of block           
block_end:     EQU  16572 ; Adress of end of block              
block_len:     EQU  16574 ; Length of marked block              
close_flg:     EQU  16576 ; Used in closing the text            
ins_flg:       EQU  16577 ; Flags if insert is on or off        
tins_flg:      EQU  16578 ; Temp as above                       
dir_page:      EQU  16579 ; 1 hold text page when doing a dir   
cur_pos2:      EQU  16580 ; 1 for DIR left right limit          
p_cont:        EQU  16581 ; Continuous printing flag            
memtemp:       EQU  16583 ; Temp storage for memory location    
emg_ret:       EQU  16585 ; Store sp value on startup           
re_form_temp:  EQU  16587                                       
left_col:      EQU  16589 ; Left col for margins                
right_col:     EQU  16590 ; Right col for margins               
pad_numl:      EQU  16591 ; Spaces to be inserted into file     
pad_numr:      EQU  16592 ; between right and left margin       
line_length:   EQU  16593 ; line length between margins         
t_left_col:    EQU  16594 ; temporary storage for margins       
t_right_col:   EQU  16595 ; when going to the bottom of the file
t_pad_numl:    EQU  16596 ; as above                            
t_pad_numr:    EQU  16597 ; as above                            
t_line_length: EQU  16598 ; as above                            
w_sposn:       EQU  16599 ; Holds sposn and memry when the crsr 
w_memry:       EQU  16601 ; goes past the right margin.         
both_pads:     EQU  16603 ; Store left and right together       
line_len:      EQU  16604 ; Used in the justify routine.        
j_count:       EQU  16605 ; Counter used in justify routine.    
clock_var:     EQU  16606 ; update clock. yes or no             
t_data:        EQU  16607 ; 2 bytes position of tab data        
error_sp:      EQU  16609 ; hold SP for error RET. printer drivr
error_var:     EQU  16611 ; holds error number                  
nlq_addr:      EQU  16612 ; holds address of pr code start      
char_3:        EQU  16614 ; Holds char for move block           
move_var:      EQU  16615 ; Move flag for scroll                
copies:        EQU  16616 ; Amount of copies to print           
num_buf:       EQU  16617 ; 4 bytes for cop_input               
hide_var:      EQU  16621 ; 255 file hidden. 0 file normal      
sbuffer:       EQU  16622 ; 25 bytes buffer for search          
t_pyge:        EQU  16648 ; Temp page . search routine          
t_total:       EQU  16649 ; Temp total. search routine          
t_lline:       EQU  16651 ; Temp line . search routine          
list_var:      EQU  16652 ; address of cursor in list routine   
CONTROL_FLAG:  EQU  16654 ; Send control to various routines    
                          ; when coming back from basic:        
                          ; will be poked by the code on exit.  
                          ; used to tell the code to jump to    
                          ; DIR or Disk Error routines etc.     
                                                                
merge_var:     EQU  16655 ; Start of the line for merge         
memry_var:     EQU  16657 ; Start of line for copy block        
crsr_flag:     EQU  16659 ; 0=print crsr 1 = dont print crsr    
crsr_tog:      EQU  16660 ; 0= on 255 = off                     
op_len_var:    EQU  16661 ; temp for option bar                 
what_menu:     EQU  16662 ; Flag what menu in use               
dict_count:    EQU  16663 ; counts the dict pages               
info_flg:      EQU  16664 ; 1 = info page 2 = dict page         
                                                                
                                                                
; Clock variables                                               
                                                                
                                                                
cstack_var:    EQU  16665 ; 2  Store for stack pointer          
tposn:         EQU  16667 ; 2  print pos for time elapsed       
t_count:       EQU  16669 ; 1  counter for timer 50 per sec     
hours:         EQU  16670 ; 1  counter for hours max 23         
minute:        EQU  16671 ; 1  counter for minutes max 59       
seconds:       EQU  16672 ; 1  counter for seconds max 59       
cstack:        EQU  16720 ; 2  Clocks own stack                 
                                                                
                                                                
; Ant variable holds the speed of the ant                       
                                                                
ant_speed:     EQU  16722 ; 2  Speed variable for ant           
                                                                
; Calendar variables for day month and year                     
; mtab is a table of the length of the months in the year       
; only the second entry will be changed by the code "cvdays"    
; and this will reflect on whether it is a leap year or not.    
                                                                
                                                                
day:           EQU  16724 ; 1  Holds the first day of month     
month:         EQU  16725 ; 1  Holds 1 to 12 for Jan to Dec     
year:          EQU  16726 ; 1  Holds year of the calendar       
mtab:          EQU  16727 ; 12 Holds length of months           
                                                                
; colour variables                                              
                                                                
PAL:           EQU  16740 ; 1  Basic peeks here for palette     
co1:           EQU  16741 ; 1  Colour 1 default                 
co4:           EQU  16742 ; 1  Colour 2 default                 
                                                                
                                                                
name_address:  EQU  16743 ; 2 address of file name L/S routine  
name_buff:     EQU  16745 ; 2 Address of current name buffer    
data_store:    EQU  16747 ; 2 Store data pointer.      VIEW CODE
sc_pos:        EQU  16749 ; 2 Store printing position. VIEW CODE
pass:          EQU  16751 ; 1 passes through cont code VIEW CODE
save_blk_len:  EQU  16752 ; 2 Block length for the block save   
bar_length:    EQU  16754 ; 1 Menus bar length                  
name_end:      EQU  16755 ; 1  NOT USED                         
error_flag:    EQU  16756 ; 1 Main error flag error num in here 
file_type:     EQU  16757 ; 1 File type poked from basic        
MODE:          EQU  16758 ; 1 Routine in use when error called  
l_or_e:        EQU  16759 ; 1 L or E for load or erase          
bar_jump:      EQU  16760 ; 1 Holds the diplacement for op bar  
CHARSET:       EQU  16761 ; 2 Position of the character set     
                          ;   Equivalent to "chars" in SPECTRUM 
spd_var:       EQU  16763 ; 2 Speed Read pause value            
                                                                
                                                                
; Switching code at 65527. puts the following code at zero      
                                                                
               ORG  65527                                       
               DUMP $                                           
                                                                
               DI                                               
               LD   A,163                                       
               OUT  (250),A                                     
               JP   0                                           
                                                                
                                                                
                                                                
               ORG  0                                           
               DUMP 3,0   ; = page 3 address 0 : page 3 = 65536 
                                                                
               DI                                               
               JP   init  ; Jump to initialise routine          
                                                                
; fixed storage locations in ROM. poke from basic if you wish   
; These are default loading settings and are changed from       
; various menus within the program. Will be saved as defaults   
; when you use the save option from "OPTIONS" menu.             
                                                                
car_ret:       DEFB 10    ; address 4 = 65540 car ret default   
page_length:   DEFB 60    ;         5 = 65541 pge len default   
page_start:    DEFB 1     ;         6 = 65542 pge st default    
skip_perf:     DEFB 6     ;         7 = 65543 perf val default  
pr_tab:        DEFB 8     ;         8 = 65544 prntr col setting 
just_def:      DEFB 255   ;         9 = 65545 justify default   
wrap_def:      DEFB 0     ;        10 = 65546 wrap default      
insert_def:    DEFB 0     ;        11 = 65547 insert default    
case_flag:     DEFB 0     ;        12 = 65548 case default      
cur_height:    DEFB 4     ;        13 = 65549 height default    
repper_val:    DEFB 2     ;        14 = 65550 repeat default    
repdel_val:    DEFB 25    ;        15 = 65551 rep/delay default 
               DEFB 0     ;        16 = 65552 NOT USED          
beep_var:      DEFB 0     ;        17 = 65553 keyboard beep     
               DEFB 0     ;        18 = 65554    NOT USED       
d_sp_var:      DEFB 0     ;        19 = 65555 10 = double spce  
p1_start:      DEFB 1     ;        20 = 65556 page 1 start      
p2_start:      DEFB 9     ;        21 = 65557 page 2 start      
p3_start:      DEFB 17    ;        22 = 65558 page 3 start      
dump_len:      DEFB 60    ;        23 = 65559 dump length       
                                                                
                                                                
               ORG  24             ; THIS IS RST 24  #18        
               DUMP 3,24           ; page 3 address 24          
                                                                
carriage_ret:  LD   A,13           ; Send a line feed and or a  
               RST  40             ; carriage return to the     
               LD   A,(car_ret)    ; printer...                 
               OR   A                                           
               JR   Z,d_space                                   
               RST  40                                          
d_space:       LD   A,(d_sp_var)                                
               CP   10                                          
               RET  NZ                                          
RESTRT:        JP   printer_on     ; THIS IS RST 40  #28        
                                                                
                                                                
               ORG  56                                          
               DUMP 3,56           ; page 3 address 56          
                                                                
intrpt:        DI                  ; Main interupt routine      
               PUSH AF             ; AT RST 56  #38             
               PUSH BC                                          
               PUSH DE                                          
               PUSH HL                                          
               CALL sound_off                                   
               CALL ptime          ; print the clock            
               CALL kscan          ; Scan the keyboard          
               POP  HL                                          
               POP  DE                                          
               POP  BC                                          
               POP  AF                                          
               EI                  ; Re_enable interupts        
               RET                 ; and return                 
                                                                
                                                                
                                                                
               ORG  98                                          
               DUMP 3,98           ; page 3 address 98          
                                                                
exit:          LD   A,95           ; Exit back to basic from my 
               OUT  (250),A        ; code.                      
nmicd:         JP   samret         ; Exit if NMI button pressed 
                                                                
                                                                
init:          LD   SP,astack                                   
               LD   A,35           ; Unlock Rom                 
               OUT  (250),A                                     
               EXX                                              
               LD   (hlstr),HL     ; Store SAMS exchange set    
               LD   (bcstr),BC                                  
               LD   (destr),DE                                  
               EXX                                              
               EX   AF,AF'         ; Store SAMS Alternate AF    
               PUSH AF                                          
               POP  HL                                          
               LD   (afstr),HL                                  
               EX   AF,AF'                                      
               IN   A,(252)        ; Store SAMS default screen  
               LD   (screen),A                                  
               LD   A,(cur_height) ; Adjust to default crsr     
               LD   (height+1),A   ; height                     
               LD   B,A                                         
               LD   A,8                                         
               SUB  B                                           
               LD   (remainder+1),A                             
               LD   A,(repdel_val)    ; Get default rep/del val 
               LD   (poke_repdel+1),A ; Put it into code        
               LD   A,(repper_val)    ; Get repeat value        
               LD   (poke_repper+1),A ; Put it into code        
               LD   A,163             ; Write protect the Rom   
               OUT  (250),A                                     
                                                                
; text_page variable initialy set from basic loader routine     
; but the name buffer must be set from here.                    
                                                                
                                                                
               LD   A,(text_page)     ; Page 5 at 32768 for the 
               OUT  (251),A           ; Text or page 7 or pg 25 
               LD   HL,name_buffer1   ; for text file 1         
;              LD   DE,p1_start                                 
               CP   5                                           
               JR   Z,set_buff                                  
;              LD   DE,p2_start                                 
               LD   HL,name_buffer2   ; for text file 2         
               CP   7                                           
               JR   Z,set_buff                                  
               LD   HL,name_buffer3   ; for text file 3         
;              LD   DE,p3_start                                 
set_buff:      LD   (name_buff),HL    ; holds current name bufer
;              EX   DE,HL                                       
;              LD   A,(HL)                                      
;              LD   (page_start),A                              
                                                                
                                                                
;              LD   A,163                                       
;              OUT  (250),A                                     
                                                                
set_int:       LD   A,63              ; Set interupt value      
               LD   I,A                                         
               DEFB 0,0,0,0,0,0                                 
;              LD   SP,astack         ; Set the stack pointer   
               IM   1                 ; Use interupt mode 1     
               EI                     ; Enable interupt         
               CALL poke_chars        ; Put character set       
               CALL colour                                      
               JP   set_vars          ; into screen             
                                                                
                                                                
; convert 8 bit char set into a 16 bit set. The 8 bit set       
; is loaded to 18010. The 16 bit set is put into the default    
; screen and also the buffer page when required to create a     
; screen                                                        
                                                                
                                                                
poke_chars:    DI                                               
               CALL screen_in                                   
               LD   BC,816            ; into the screen         
               LD   HL,eight_bit_1                              
               LD   DE,chars                                    
convert_loop:  LD   A,(HL)                                      
               PUSH HL                                          
               PUSH BC                                          
               LD   C,A                                         
               LD   B,0                                         
               LD   HL,ctable         ; Character conversion    
               ADD  HL,BC             ; table                   
               ADD  HL,BC                                       
               LD   A,(HL)                                      
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               LD   A,(HL)                                      
               LD   (DE),A                                      
               POP  BC                                          
               POP  HL                                          
               INC  HL                                          
               INC  DE                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JP   NZ,convert_loop                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               EI                                               
               CALL poke_chars2                                 
               RET                                              
                                                                
                                                                
; Routine works out the top of the screen using the current     
; cursor position . Then reprints the complete screen minus     
; the logo line. No entry conditions required.                  
                                                                
reprint_screen:LD   HL,34816                                    
               LD   (sposn2),HL                                 
               LD   A,(col)                                     
               LD   HL,(memry)                                  
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   A,(line)                                    
               CP   3                                           
               JP   Z,just_print                                
               DEC  A                                           
               DEC  A                                           
               DEC  A                                           
               LD   B,A                                         
               LD   DE,64                                       
               OR   A                                           
repr_loop:     SBC  HL,DE                                       
               DJNZ repr_loop                                   
just_print:    LD   BC,1408                                     
pr_loop:       LD   A,(HL)                                      
               CP   255                                         
               JP   Z,do_rest                                   
               CALL pchar2                                      
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,pr_loop                                  
               RET                                              
                                                                
do_rest:       LD   A,32                                        
               CALL pchar2                                      
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,do_rest                                  
               RET                                              
                                                                
                                                                
; Initialise the fixed variables into the normal ram vars       
                                                                
                                                                
set_vars:      LD   HL,chars-512                                
               LD   (CHARSET),HL                                
               LD   A,(case_flag)                               
               LD   (flags2),A                                  
               LD   A,(just_def)                                
               LD   (just_var),A                                
               LD   A,(wrap_def)                                
               LD   (wrap),A                                    
               LD   A,(insert_def)                              
               LD   (ins_flg),A                                 
               LD   A,(f_left_col)                              
               LD   (left_col),A                                
               LD   A,(f_right_col)                             
               LD   (right_col),A                               
               LD   A,(f_pad_numl)                              
               LD   (pad_numl),A                                
               LD   A,(f_pad_numr)                              
               LD   (pad_numr),A                                
               LD   A,(f_line_length)                           
               LD   (line_length),A                             
               XOR  A                                           
               LD   (clock_var),A                               
               LD   (crsr_flag),A                               
               LD   (crsr_tog),A                                
               LD   (move_var),A                                
               LD   (p_cont),A                                  
               LD   HL,repct                                    
               LD   (HL),33                                     
               LD   HL,repper                                   
poke_repper:   LD   (HL),4            ; set from init           
               LD   HL,repdel                                   
poke_repdel:   LD   (HL),33           ; set from init           
               LD   HL,init_data                                
               LD   DE,lf4c0                                    
               LD   BC,9                                        
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
                                                                
               LD   HL,lf4c9                                    
               LD   (HL),100                                    
               INC  HL                                          
               LD   (HL),4                                      
               LD   HL,10                                       
               LD   (wvar),HL                                   
start:         CALL initbuf           ; initialise the buffer   
               CALL inverse           ; Get ready for inverse   
               XOR  A                 ; printing                
                                                                
               LD   (hide_var),A                                
               LD   (close_flg),A                               
               LD   (pflag),A                                   
               LD   (block_var),A                               
               LD   (char_1),A                                  
               LD   (char_2),A                                  
               LD   HL,0                                        
               LD   (block_strt),HL                             
               LD   (block_end),HL                              
               LD   (block_len),HL                              
               DEC  A                                           
               LD   (ed_var),A                                  
               LD   (var),A                                     
               LD   HL,nlq_on                                   
               LD   (nlq_addr),HL                               
               CALL entry                                       
                                                                
                                                                
; Come here when returning to sam basic. and store various      
; system conditions before exiting via NMI address              
                                                                
                                                                
samret:        CALL unlock_rom        ; Store wordwrap / justify
               LD   A,(just_var)      ; insert and Caps lock    
               LD   (just_def),A      ; conditions when exiting 
               LD   A,(ins_flg)       ; back to sam basic.      
               LD   (insert_def),A    ; USED as default values  
               LD   A,(wrap)          ; when coming back from   
               LD   (wrap_def),A      ; basic                   
               LD   A,(flags2)                                  
               LD   (case_flag),A                               
               LD   A,(left_col)      ; also store the margin   
               LD   (f_left_col),A    ; settings ready for a    
               LD   A,(right_col)     ; return from basic       
               LD   (f_right_col),A                             
               LD   A,(pad_numl)                                
               LD   (f_pad_numl),A                              
               LD   A,(pad_numr)                                
               LD   (f_pad_numr),A                              
               LD   A,(line_length)                             
               LD   (f_line_length),A                           
               CALL lock_rom          ; Lock the Rom again      
               CALL poke_dos          ; Time into the DOS       
               LD   HL,(hlstr)        ; Restore SAMS alternate  
               LD   DE,(destr)        ; registers before exiting
               LD   BC,(bcstr)                                  
               EXX                                              
               EX   AF,AF'                                      
               LD   HL,(afstr)                                  
               PUSH HL                                          
               POP  AF             ; Restore SAMS alternate AF  
               EX   AF,AF'                                      
               LD   A,1            ; Put original C SLOT back   
               OUT  (251),A        ; to address 32768           
               LD   A,(screen)     ; Restore SAMS original      
               OUT  (252),A        ; screen.                    
               JP   exit           ; And exit via NMI           
                                                                
                                                                
; Storage locations for Sams alternate registers.               
                                                                
                                                                
hlstr:         DEFW 0                                           
destr:         DEFW 0                                           
bcstr:         DEFW 0                                           
afstr:         DEFW 0                                           
spstr:         DEFW 0                                           
screen:        DEFB 0                                           
                                                                
                                                                
; Store the margin values here when exiting to sam basic        
; These will be used as defaults on re-entry.                   
                                                                
                                                                
f_left_col:    DEFB 0                                           
f_right_col:   DEFB 63                                          
f_pad_numl:    DEFB 0                                           
f_pad_numr:    DEFB 1                                           
f_line_length: DEFB 64                                          
                                                                
                                                                
                                                                
; Printer code.......                                           
                                                                
; This is my original printer code..                            
; Send character in the A register to the printer               
                                                                
printer_on:    PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               PUSH AF                                          
               LD   BC,489                                      
sendlp:        LD   A,247                                       
               IN   A,(249)                                     
               AND  32                                          
               JR   Z,esc_presd                                 
               IN   A,(C)                                       
               RRCA                                             
               JR   C,sendlp                                    
               DEC  C                                           
               POP  AF                                          
               OUT  (C),A                                       
               INC  C                                           
               OUT  (C),B                                       
               DEC  B                                           
               OUT  (C),B                                       
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               SCF                                              
               CCF                                              
               RET                                              
                                                                
       ; Esc key pressed so just exit                           
                                                                
esc_presd:     POP  AF                                          
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               SCF                                              
               RET                                              
                                                                
; Key scan routine. called from interupt...                     
; nicked from original Sam.                                     
                                                                
kscan:         LD   HL,flags                                    
               RES  5,(HL)                                      
               LD   HL,0                                        
               LD   (kbqp),HL                                   
                                                                
scan:          CALL kinter                                      
               LD   HL,(kbqp)                                   
               LD   A,H                                         
               CP   L                                           
               RET  Z                                           
               LD   HL,flags                                    
               BIT  5,(HL)                                      
               RET  NZ                                          
               SET  5,(HL)                                      
               LD   L,A                                         
               LD   H,0                                         
               INC  A                                           
               AND  7                                           
               LD   (kbqp+1),A                                  
               LD   DE,kbqb                                     
               ADD  HL,DE                                       
               LD   A,(flags2)                                  
               AND  8                                           
               LD   A,(HL)                                      
               JR   Z,kyrd2                                     
               CP   97                                          
               JR   C,kyrd2                                     
               CP   123                                         
               JR   NC,kyrd2                                    
               AND  223                                         
                                                                
kyrd2:         LD   (lastk),A                                   
               RET                                              
                                                                
kinter:        CALL keyscn                                      
               LD   C,0                                         
               JR   NZ,ldlh                                     
               CALL kyvl                                        
               LD   HL,(lasth-1)                                
               LD   A,H                                         
               CP   C                                           
               JR   Z,kbcr                                      
               LD   A,L                                         
               CP   C                                           
                                                                
kbcr:          LD   HL,repct                                    
               JR   NZ,kbd1                                     
               DEC  (HL)                                        
               RET  NZ                                          
               PUSH HL                                          
               LD   DE,kbuff+8                                  
               LD   HL,(lkpb)                                   
               LD   A,H                                         
               ADD  E                                           
               LD   E,A                                         
               LD   A,(DE)                                      
kbxl:          RLCA                                             
               DEC  L                                           
               JR   NZ,kbxl                                     
               POP  HL                                          
               RET  C                                           
               INC  (HL)                                        
               LD   A,(flags)                                   
               AND  32                                          
               RET  NZ                                          
               LD   A,(repper)                                  
               JR   kbrk                                        
                                                                
kbd1:          LD   A,(repdel)                                  
                                                                
kbrk:          LD   (HL),A                                      
               LD   HL,(kbqp)                                   
               LD   A,L                                         
               INC  A                                           
               AND  7                                           
               CP   H                                           
               RET  Z                                           
               LD   (kbqp),A                                    
               LD   H,0                                         
               LD   DE,kbqb                                     
               ADD  HL,DE                                       
               LD   (HL),C                                      
                                                                
ldlh:          LD   HL,lasth                                    
               LD   A,(HL)                                      
               LD   (HL),C                                      
               DEC  HL                                          
               LD   (HL),A                                      
               RET                                              
                                                                
kyvl:          LD   HL,kbtab                                    
               LD   A,D                                         
               LD   D,0                                         
               ADD  HL,DE                                       
               AND  A                                           
               JR   Z,kint4                                     
               LD   E,70                                        
               ADD  HL,DE                                       
               DEC  A                                           
               JR   Z,kint4                                     
               ADD  HL,DE                                       
               DEC  A                                           
               JR   Z,kint4                                     
               ADD  HL,DE                                       
                                                                
kint4:         LD   C,(HL)                                      
               RET                                              
                                                                
keyscn:        LD   HL,kbuff                                    
               PUSH HL                                          
               LD   BC,65278                                    
               LD   D,224                                       
                                                                
kbsl:          IN   E,(C)                                       
               LD   A,B                                         
               IN   A,(249)                                     
               XOR  E                                           
               AND  D                                           
               XOR  E                                           
               INC  B                                           
               JR   Z,kbel                                      
               LD   (HL),A                                      
               DEC  B                                           
               INC  HL                                          
               RLC  B                                           
               JR   C,kbsl                                      
               LD   B,255                                       
               JR   kbsl                                        
                                                                
kbel:          OR   225                                         
               LD   (HL),A                                      
               POP  HL                                          
               LD   D,H                                         
               LD   E,L                                         
               SET  0,(HL)                                      
               INC  HL                                          
               INC  HL                                          
               INC  HL                                          
               SET  5,(HL)                                      
               INC  HL                                          
               INC  HL                                          
               INC  HL                                          
               INC  HL                                          
               SET  1,(HL)                                      
               INC  HL                                          
               INC  HL                                          
               LD   B,9                                         
                                                                
kbcl:          LD   A,(DE)                                      
               LD   C,(HL)                                      
               LD   (HL),A                                      
               XOR  C                                           
               CPL                                              
               OR   (HL)                                        
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               DJNZ kbcl                                        
                                                                
               LD   B,9                                         
kbdl:          DEC  DE                                          
               LD   A,(DE)                                      
               INC  A                                           
               JR   NZ,kbyk                                     
               DJNZ kbdl                                        
                                                                
               LD   B,9                                         
               LD   DE,(lastkv)                                 
kbakl:         DEC  HL                                          
               LD   A,(HL)                                      
               INC  A                                           
               JR   NZ,kbsh                                     
               DJNZ kbakl                                       
               INC  B                                           
               RET                                              
                                                                
kbyk:          DEC  A                                           
               LD   C,9                                         
                                                                
kbbl:          DEC  C                                           
               RRA                                              
               JR   C,kbbl                                      
               LD   (lkpb),BC                                   
               LD   A,C                                         
               ADD  A                                           
               ADD  A                                           
               ADD  A                                           
               ADD  C                                           
               SUB  B                                           
               LD   E,A                                         
                                                                
kbsh:          LD   BC,65278                                    
               IN   A,(C)                                       
               LD   D,1                                         
               AND  D                                           
               JR   Z,kbld                                      
               INC  B                                           
               IN   A,(C)                                       
               AND  D                                           
               LD   D,3                                         
               JR   Z,kbld                                      
               DEC  D                                           
               LD   B,127                                       
               IN   A,(C)                                       
               AND  D                                           
               JR   Z,kbld                                      
               DEC  D                                           
               DEC  D                                           
                                                                
kbld:          LD   (lastkv),DE                                 
               RET                                              
                                                                
; Key de-bounce routine....                                     
                                                                
rd_key:        EI                                               
               PUSH HL                                          
               PUSH BC                                          
               CALL crsr                                        
               XOR  A                                           
               LD   (lf4c8),A                                   
               LD   A,(lf4c9)                                   
               LD   (lf4ca),A                                   
lf65f:         LD   A,(lf4ca)                                   
               DEC  A                                           
               LD   (lf4ca),A                                   
               JP   NZ,lf67d                                    
               LD   HL,(sposn)                                  
               CALL crsr                                        
               LD   A,(lf4c8)                                   
               XOR  1                                           
               LD   (lf4c8),A                                   
               LD   A,(lf4c9)                                   
               LD   (lf4ca),A                                   
lf67d:         CALL delay                                       
               LD   A,(repct)                                   
               OR   A                                           
               JR   NZ,lf68c                                    
               XOR  A                                           
               LD   (lf4c6),A                                   
               JR   lf6b8                                       
lf68c:         LD   A,(lf4c6)                                   
               LD   B,A                                         
               LD   A,(lastk)                                   
               CP   B                                           
               JR   Z,lf6a1                                     
               LD   (lf4c6),A                                   
               LD   HL,(lf4c2)                                  
               LD   (lf4c0),HL                                  
               JR   lf6b8                                       
lf6a1:         LD   HL,(lf4c0)                                  
               DEC  HL                                          
               LD   (lf4c0),HL                                  
               LD   A,H                                         
               OR   L                                           
               JR   Z,lf6af                                     
               XOR  A                                           
               JR   lf6b8                                       
lf6af:         LD   HL,(lf4c4)                                  
               LD   (lf4c0),HL                                  
               LD   A,(lf4c6)                                   
lf6b8:         OR   A                                           
               JR   Z,lf65f                                     
               PUSH AF                                          
               LD   A,(lf4c8)                                   
               OR   A                                           
               JR   Z,lf6c8                                     
               LD   HL,(sposn)                                  
               CALL crsr                                        
lf6c8:         XOR  A                                           
               LD   (lastk),A                                   
               CALL crsr_chk                                    
               POP  AF                                          
               POP  BC                                          
               POP  HL                                          
               RET                                              
                                                                
delay:         LD   C,11                                        
again:         LD   B,64                                        
delay2:        NOP                                              
               DJNZ delay2                                      
               DEC  C                                           
               JR   NZ,again                                    
               RET                                              
                                                                
; Print the cursor on the screen...                             
                                                                
crsr:          PUSH AF                                          
               LD   A,(crsr_flag)                               
               OR   A                                           
               JP   Z,cursor                                    
               POP  AF                                          
               RET                                              
                                                                
cursor:        PUSH DE                                          
               LD   A,(crsr_tog)                                
               XOR  255                                         
               LD   (crsr_tog),A                                
               LD   B,8                                         
               LD   A,(flags2)                                  
               OR   A                                           
               JP   NZ,crsr2                                    
               LD   HL,(sposn)                                  
remainder:     LD   B,4                                         
               LD   DE,128                                      
cr_lp:         ADD  HL,DE                                       
               DJNZ cr_lp                                       
height:        LD   B,4                                         
               JP   page_scrn                                   
crsr2:         LD   HL,(sposn)                                  
page_scrn:     CALL screen_in                                   
                                                                
crsr_lwr:      LD   DE,128                                      
               PUSH HL                                          
crsr_loop:     PUSH HL                                          
               LD   A,(HL)                                      
cr_poke1:      XOR  255           ; 255 = exactinverse          
               LD   (HL),A                                      
               INC  HL                                          
               LD   A,(HL)                                      
cr_poke2:      XOR  255         ;   255 = exact inverse         
               LD   (HL),A                                      
               POP  HL                                          
               ADD  HL,DE                                       
               DJNZ crsr_loop                                   
               POP  HL                                          
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  DE                                          
               POP  AF                                          
               RET                                              
                                                                
                                                                
exit_margins:  CALL show_margins      ; Print margin positions  
               LD   A,(pad_numl)                                
               LD   B,A                                         
               LD   A,(pad_numr)                                
               ADD  A,B                                         
               LD   (both_pads),A     ; used in the format rtine
               JP   exit_box                                    
                                                                
                                                                
;              set left margin position                         
                                                                
                                                                
s_left:        LD   A,(col)                                     
               CALL set_left                                    
               JP   exit_margins                                
                                                                
set_left:      LD   (left_col),A                                
               LD   (pad_numl),A                                
               JP   set_line_len                                
                                                                
                                                                
;              set right margin position                        
                                                                
                                                                
s_right:       LD   A,(col)                                     
               CALL set_right                                   
               JP   exit_margins                                
                                                                
set_right:     LD   (right_col),A                               
               LD   B,A                                         
               LD   A,64                                        
               SUB  B                                           
               LD   (pad_numr),A                                
               LD   A,(left_col)                                
               LD   B,A                                         
               LD   A,(right_col)                               
               JP   set_line_len                                
                                                                
                                                                
;              set margins back to full screen width            
                                                                
                                                                
full_screen:   CALL f_screen                                    
               JP   exit_margins                                
                                                                
f_screen:      XOR  A                                           
               LD   (left_col),A                                
               LD   A,63                                        
               LD   (right_col),A                               
               INC  A                                           
               LD   (line_length),A                             
               XOR  A                                           
               LD   (pad_numl),A                                
               INC  A                                           
               LD   (pad_numr),A  ; 1 is required for normal    
               RET                ; incrementing of the file    
                                                                
set_line_len:  LD   A,(pad_numl)                                
               LD   B,A                                         
               LD   A,(pad_numr)                                
               ADD  A,B                                         
               LD   B,A                                         
               LD   A,65                                        
               SUB  B                                           
               LD   (line_length),A                             
               RET                                              
                                                                
; Used to temporarily set the margins to normal. For routines   
; that need the margins at full width.                          
                                                                
clear_margins: LD   B,5                                         
               LD   HL,left_col                                 
               LD   DE,t_left_col                               
cm_loop:       LD   A,(HL)                                      
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               DJNZ cm_loop                                     
               JP   f_screen                                    
                                                                
; Reset margins to original values after routines that need     
; full width has terminated.                                    
                                                                
reset_margins: LD   B,5                                         
               LD   HL,t_line_length                            
               LD   DE,line_length                              
rm_loop:       LD   A,(HL)                                      
               LD   (DE),A                                      
               DEC  HL                                          
               DEC  DE                                          
               DJNZ rm_loop                                     
               RET                                              
                                                                
; Set margins to the rightmost and leftmost characters on the   
; screen.  Check for an empty line and resets if one is found.  
                                                                
auto_margin:   LD   A,(col)     ; point memry location to the   
               LD   HL,(memry)  ; beggining of the line         
               LD   E,A         ; DE = col value                
               LD   D,0         ; subtracted from memry = start 
               OR   A           ; of line                       
               SBC  HL,DE                                       
               LD   B,64        ; Check 64 locations            
auto_loop:     LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,set_both ; non space found so set both   
               INC  HL          ; margins.                      
               DJNZ auto_loop                                   
               JP   full_screen ; all spaces so reset to 64 col 
                                                                
set_both:      LD   A,(col)     ; Find end of the line          
               LD   B,A                                         
               LD   A,63                                        
               SUB  B                                           
               LD   HL,(memry)                                  
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   B,63                                        
                                                                
auto_loop2:    LD   A,(HL)      ; now work back to the last char
               CP   32          ; on the line. once found set it
               JP   NZ,auto_right                               
               DEC  HL                                          
               DEC  B                                           
               JR   auto_loop2                                  
                                                                
auto_right:    LD   A,B                                         
               CALL set_right                                   
               LD   A,(col)     ; now find the start of the line
               LD   HL,(memry)                                  
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   B,0                                         
left_loop:     LD   A,(HL)       ; work forward until first char
               CP   32           ; is found on the line         
               JP   NZ,auto_left ; then set it.                 
               INC  B                                           
               INC  HL                                          
               JR   left_loop                                   
                                                                
auto_left:     LD   A,B                                         
               LD   (memry),HL                                  
               CALL set_left                                    
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur           ; set new print position    
               JP   exit_margins    ; and exit                  
                                                                
                                                                
; Transfer the screen of text from the text file into the help  
; screen. can be saved from there as a screen$                  
                                                                
do_screen:     JP   exit_box                                    
                                                                
                                                                
; Main entry point for the program proper...                    
                                                                
                                                                
entry:         LD   (emg_ret),SP                                
               LD   A,(file_st)                                 
               CP   0                                           
               JP   Z,new_file                                  
               CP   255                                         
               JP   Z,new_file                                  
               JP   prtpge                                      
                                                                
init_top:      LD   A,(page_start)                              
               LD   (pyge),A                                    
               LD   A,1                                         
               LD   (lline),A                                   
               LD   HL,1                                        
               LD   (total),HL                                  
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   L,3                                         
               CALL stcur                                       
               LD   HL,file_st                                  
               LD   A,(left_col)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               LD   HL,file_st                                  
               RET                                              
                                                                
                                                                
                                                                
new_file:      XOR  A                                           
               LD   (pnm_var),A                                 
               LD   HL,file_st                                  
               LD   (memtop),HL                                 
               LD   (HL),255                                    
               INC  HL                                          
               LD   DE,file_st+2                                
               LD   BC,file_len+235                             
               LD   (HL),32                                     
               LDIR                                             
               LD   HL,65535                                    
               LD   (HL),255                                    
               CALL init_top                                    
               CALL do_pge_len                                  
               CALL logo                                        
               CALL update                                      
               CALL show_margins                                
               CALL check_ins                                   
               CALL check_wrap                                  
               CALL check_just                                  
               CALL clear_nm_buf ; Clear the file name buffer   
                                                                
; Check to see if weve just been to basic for the DIR or        
; whatever other routines that I might put in.                  
; Control flag must be set from the code before exiting to      
; basic. It will be set to zero from basic when the program     
; first loads.....only when the routine has finished and an     
; exit is made to "key" will the flag be poked back to zero.    
                                                                
CONTROL2:      LD   A,(error_flag)                              
               CP   0                                           
               JP   NZ,Disk_error                               
               LD   A,(CONTROL_FLAG)                            
               CP   3                                           
               JP   Z,LOADER                                    
               CP   4                                           
               JP   Z,sv_full                                   
               CP   1                                           
               JP   Z,DIRECTORY                                 
               CP   5                                           
               JP   Z,sv_block                                  
                                                                
                                                                
                                                                
                                                                
; All routines jumped to from here are to exit back to here     
                                                                
                                                                
                                                                
key:           XOR  A                                           
               LD   (CONTROL_FLAG),A                            
               LD   (crsr_flag),A                               
               CALL rd_key                                      
next:          LD   (chr_buf),A                                 
do_con_code:   CALL editor                                      
               XOR  A                                           
               LD   (close_flg),A                               
               LD   (crsr_flag),A                               
               CALL memchk                                      
               CALL update                                      
                                                                
; Check if symbol key is being held down                        
                                                                
chk_symbol:    LD   A,(lastkv+1)                                
               CP   0                                           
               JR   Z,key          ; was JR Z,key * BUG FIX *   
               CALL rd_key                                      
               CP   190                                         
               JR   NC,key                                      
               LD   A,(chr_buf)                                 
               LD   B,A                                         
               LD   A,(lf4c6)                                   
               CP   B                                           
               JR   Z,ne_xt                                     
               LD   A,(chr_buf)                                 
               SET  5,A                                         
               LD   B,A                                         
               LD   A,(lf4c6)                                   
               CP   B                                           
               JR   NZ,ne_xt                                    
               JR   chk_symbol                                  
                                                                
ne_xt:         RES  7,A                                         
               JP   next                                        
                                                                
; When returning from the RD_KEY routine check to see if the    
; cursor is turned on and if it is then turn it off....         
                                                                
crsr_chk:      LD   A,(crsr_tog)                                
               OR   A                                           
               RET  Z                                           
               JP   crsr                                        
                                                                
editor:        PUSH AF                                          
               LD   A,(beep_var)                                
               OR   A                                           
               CALL Z,sound2                                    
               POP  AF                                          
                                                                
               CP   32                                          
               JP   C,keys                                      
               CP   127                                         
               JP   NC,keys                                     
from_list:     LD   (chr_buf),A                                 
               LD   A,(block_var)                               
               OR   A                                           
               RET  NZ                                          
               LD   A,(chr_buf)                                 
               CALL pchar                                       
               CALL word_wrap                                   
               RET                                              
                                                                
; This routine pokes the default page length into the           
; printing routine for the printer. This is self modifying code 
; Bit naughty EH!                                               
                                                                
do_pge_len:    CALL unlock_rom                                  
               LD   A,(page_length)                             
               LD   (pgelen2+1),A                               
               LD   (doline+1),A                                
               CALL lock_rom                                    
               RET                                              
                                                                
                                                                
beep_tog:      CALL unlock_rom                                  
               LD   A,(beep_var)                                
               XOR  255                                         
               LD   (beep_var),A                                
               CALL lock_rom                                    
               JP   exit_box                                    
                                                                
; Re print the page when coming back from basic                 
                                                                
prtpge:        LD   A,(s_m_var)                                 
               CP   1           ; Save flag                     
               JP   Z,re_entry                                  
               JP   prt_page                                    
                                                                
                                                                
                                                                
                                                                
; Reprint the screen as it was when left to save file.          
; also when merging a file and doing a DIR                      
                                                                
; Check to see if s_m_var has an "S" "D" "M" in it.             
; If so then reprint the page from the exit point.              
; If not then reprint from the top of the file as normal.       
; Merge will reset the margins to 64 col.                       
                                                                
                                                                
re_entry:      CALL clear_c_chars                               
               CALL logo                                        
               CALL update                                      
               CALL check_ins                                   
               CALL check_wrap                                  
               CALL check_just                                  
               CALL show_margins                                
               CALL norm                                        
               LD   A,(col)                                     
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur                                       
               CALL reprint_screen                              
               LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
               CALL inverse                                     
                                                                
                                                                
; Control routine sends us to routine required on return from   
; basic                                                         
                                                                
CONTROL1:      LD   A,(error_flag)                              
               CP   0                                           
               JP   NZ,Disk_error                               
               LD   A,(CONTROL_FLAG)                            
               OR   A                                           
               JP   Z,key                                       
               CP   3                                           
               JP   Z,LOADER                                    
               CP   4                                           
               JP   Z,sv_full                                   
               CP   1                                           
               JP   Z,DIRECTORY     ; goto DIR from basic       
               CP   5                                           
               JP   Z,sv_block                                  
               JP   key                                         
                                                                
                                                                
                                                                
prt_page:      CALL do_pge_len                                  
               CALL clear_c_chars                               
               CALL init_top                                    
               CALL logo                                        
               CALL update                                      
               CALL show_margins                                
               CALL check_ins                                   
               CALL check_wrap                                  
               CALL check_just                                  
               CALL norm                                        
               LD   HL,34816                                    
               LD   (sposn2),HL                                 
               LD   HL,file_st                                  
                                                                
               CALL just_print    ; now reprint the screen      
                                                                
alldun:        CALL inverse                                     
               JP   key                                         
                                                                
; Remove any Tasword control codes from the text file.          
                                                                
                                                                
clear_c_chars: LD   HL,file_st                                  
               LD   BC,file_len                                 
clear_loop:    LD   A,(HL)                                      
               CP   129                                         
               CALL NC,poke_control                             
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,clear_loop                               
                                                                
                                                                
; Find the end of the file and mark it with a 255 also load     
; memtop with the address .                                     
                                                                
find_end:      LD   HL,topmem+1                                 
end_loop:      DEC  HL                                          
               LD   A,(HL)                                      
               CP   32                                          
               JR   Z,end_loop                                  
               INC  HL                                          
               LD   (HL),255                                    
               LD   (memtop),HL                                 
               RET                                              
                                                                
poke_control:  EXX                                              
               LD   HL,poke_con_data                            
               LD   BC,39                                       
               CPIR                                             
               EXX                                              
               RET  Z                                           
               LD   (HL),32                                     
               RET                                              
                                                                
norm:          LD   HL,chars-512                                
               LD   (CHARSET),HL                                
               LD   HL,0                                        
               JP   poke_code                                   
                                                                
; self modifying code. pokes the instruction XOR 255            
; into the code. Norm pokes NOP NOP into the code               
                                                                
inverse:       LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               LD   A,255    ;  (INV)  ; H = 255 L = 238        
               LD   H,A                                         
               LD   L,238                                       
poke_code:     CALL unlock_rom                                  
               LD   (mod),HL                                    
               LD   (mod2),HL                                   
               JP   lock_rom                                    
                                                                
                                                                
                                                                
keys:          LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
kkkk:          LD   A,(lastkv+1)                                
               OR   A                                           
               JP   Z,normal_keys                               
               CP   2                                           
               JP   Z,symbol                                    
               CP   3                                           
               JP   Z,cntrl_key                                 
               CP   1                                           
               RET  NZ                                          
check_shift:   LD   A,(chr_buf)                                 
               CP   207                                         
               JP   Z,nxt_pg_up                                 
               CP   10                                          
               RET  NZ                                          
               LD   A,(line)                                    
               CP   3                                           
               RET  Z                                           
               CALL scroll                                      
               CALL blank                                       
               LD   A,(line)                                    
               DEC  A                                           
               LD   L,A                                         
               LD   A,(col)                                     
               LD   H,A                                         
               CALL stcur                                       
               LD   A,(line)                                    
                                                                
               LD   B,A                                         
               LD   A,24                                        
               SUB  B                                           
               LD   B,A                                         
               LD   DE,64                                       
               LD   HL,(memry)                                  
shift_loop:    ADD  HL,DE                                       
               DJNZ shift_loop                                  
               LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   B,64                                        
               EX   DE,HL                                       
               LD   A,D                                         
               CP   79                                          
               RET  C                                           
               LD   HL,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               RET  C                                           
               LD   HL,bottom_line                              
               CALL prtline                                     
               RET                                              
                                                                
cntrl_key:     LD   A,(block_var)                               
               CP   255                                         
               RET  Z                                           
               LD   A,(lastkv)                                  
               CP   68                                          
               JP   Z,cont_code                                 
               RET                                              
                                                                
                                                                
symbol:        LD   A,(chr_buf)                                 
               CP   9                                           
               JP   Z,down_page                                 
               CP   8                                           
               JP   Z,up_page                                   
               LD   A,(block_var)                               
               CP   255                                         
               RET  Z                                           
               LD   A,(chr_buf)                                 
               CP   10                                          
               JP   Z,open_file                                 
               CP   11                                          
               JP   Z,close_file                                
               RET                                              
                                                                
normal_keys:   LD   A,(chr_buf)                                 
               CP   9                                           
               JP   Z,right                                     
               CP   8                                           
               JP   Z,left                                      
               CP   10                                          
               JP   Z,down1                                     
               CP   11                                          
               JP   Z,up                                        
               CP   198                                         
               JP   Z,wrdend                                    
               CP   196                                         
               JP   Z,wrdstrt                                   
               CP   197                                         
               JP   Z,next_page                                 
               CP   252                                         
               JP   Z,tab                                       
               CP   253                                         
               JP   Z,menu_4                                    
               CP   7                                           
               JP   Z,menu_1                                    
               CP   13                                          
               JP   Z,enter                                     
               LD   A,(block_var)                               
               CP   255                                         
               RET  Z                                           
               LD   A,(chr_buf)                                 
               CP   12                                          
               JP   Z,delete                                    
               CP   6                                           
               JP   Z,caps_tog                                  
               CP   200                                         
               JP   Z,centre                                    
               CP   201                                         
               JP   Z,pshline                                   
               CP   199                                         
               JP   Z,pull_line                                 
               CP   192                                         
               JP   Z,wrd_cnt                                   
               CP   193                                         
               JP   Z,justify_one                               
               CP   195                                         
               JP   Z,justify_para                              
               CP   194                                         
               JP   Z,unjustify                                 
               RET                                              
                                                                
                                                                
just_top:      XOR  A                                           
               LD   (lastkv+1),A                                
               JP   top_fle                                     
                                                                
                                                                
nxt_pg_up:     LD   A,(pyge)                                    
               LD   B,A                                         
               LD   A,(page_start)                              
               CP   B                                           
               JP   Z,just_top                                  
               DEC  B                                           
               CP   B                                           
               JP   Z,just_top                                  
               LD   A,255                                       
               LD   (move_var),A                                
               CALL strtln                                      
                                                                
nxt_up_loop:   PUSH BC                                          
               CALL up                                          
               POP  BC                                          
               LD   A,(pyge)                                    
               CP   B                                           
               JP   NZ,nxt_up_loop                              
line_loop:     CALL up                                          
               LD   A,(lline)                                   
               CP   1                                           
               JR   NZ,line_loop                                
               XOR  A                                           
               LD   (move_var),A                                
               LD   (lastkv+1),A                                
               CALL exit_box                                    
               JP   goto_margin                                 
                                                                
;          jump down to the next page                           
                                                                
next_page:     LD   A,(pyge)                                    
               INC  A                                           
               LD   B,A                                         
                                                                
;          B holds page to find                                 
                                                                
               LD   A,255                                       
               LD   (move_var),A                                
               CALL strtln                                      
nxt_loop:      PUSH BC                                          
               CALL down1                                       
               POP  BC                                          
               LD   A,(pyge)                                    
               CP   B                                           
               JP   Z,got_nxt_pg                                
               JR   nxt_loop                                    
                                                                
got_nxt_pg:    XOR  A                                           
               LD   (move_var),A                                
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   L,3                                         
               CALL stcur                                       
               CALL goto_margin                                 
               JP   exit_box                                    
                                                                
                                                                
; Enter a control code into the file. X from menu 1 or          
; CNTRL and 1                                                   
                                                                
cont_code:     CALL exit_box                                    
               CALL draw_box                                    
               XOR  A             ; Have a flashing cursor while
               LD   (crsr_flag),A ; entering a control code     
               LD   B,1                                         
               CALL prstr                                       
               LD   B,30                                        
               CALL prstr                                       
cont_loop:     CALL rd_key                                      
               CP   13                                          
               JP   Z,exit_box                                  
               LD   HL,cont_data                                
               LD   BC,41                                       
               CPIR                                             
               JP   Z,got_one                                   
               JP   cont_loop                                   
                                                                
got_one:       LD   (chr_buf),A                                 
               CALL exit_box       ; remove box from screen     
               LD   A,255                                       
               LD   (pflag),A                                   
               POP  BC                                          
               LD   A,(chr_buf)                                 
               EI                                               
               JP   do_con_code                                 
                                                                
                                                                
        ; go to the bottom of the file                          
                                                                
bot_fl:        CALL exit_box                                    
               JP   bottom                                      
                                                                
        ; Toggle caps lock on/off                               
                                                                
                                                                
caps_tog:      LD   A,(flags2)                                  
               XOR  8                                           
               LD   (flags2),A                                  
               RET                                              
                                                                
        ; Go down a page full                                   
                                                                
down_page:     CALL line_strt                                   
dwn_page:      LD   HL,703                                      
               LD   DE,(total)                                  
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,re_print                                  
               JP   Z,re_print                                  
               LD   A,(line)                                    
               CP   24                                          
               JP   Z,re_print                                  
               CALL down                                        
               JR   dwn_page                                    
                                                                
re_print:      LD   HL,34816     ; col 1 line 3                 
               LD   (sposn2),HL                                 
               LD   BC,1408                                     
               LD   HL,(memry)                                  
re_pr_loop:    LD   A,(HL)                                      
               CP   255                                         
               JP   Z,exit_down                                 
               CALL pchar2                                      
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JP   Z,exit_dwn                                  
               JR   re_pr_loop                                  
                                                                
exit_down:     LD   A,32                                        
               CALL pchar2                                      
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,exit_down                                
exit_dwn:      LD   A,(left_col)                                
               LD   H,A                                         
               LD   L,3                                         
               CALL stcur                                       
               LD   HL,(memry)                                  
               LD   A,(pad_numl)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               CALL update                                      
               RET                                              
                                                                
; Go up a pagefull                                              
                                                                
up_page:       CALL line_strt                                   
up_lp1:        LD   A,(line)                                    
               CP   3                                           
               JR   Z,up_lp2                                    
               CALL up1                                         
               JR   up_lp1                                      
                                                                
up_lp2:        LD   B,21                                        
up_lp:         LD   HL,(total)                                  
               LD   A,H                                         
               OR   A                                           
               JP   NZ,do_up                                    
               LD   A,L                                         
               CP   1                                           
               JP   Z,re_print                                  
do_up:         PUSH BC                                          
               CALL up1                                         
               POP  BC                                          
               DJNZ up_lp                                       
               JP   re_print                                    
                                                                
line_strt:     LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               CALL norm                                        
               RET                                              
                                                                
pok:           LD   (chr_buf),A                                 
               JP   pok2                                        
                                                                
; Unlock the ROM ready to poke something into it                
                                                                
unlock_rom:    PUSH AF                                          
               LD   A,35                                        
               OUT  (250),A                                     
               POP  AF                                          
               RET                                              
                                                                
; Write protect the ROM  (my ROM. This code)                    
                                                                
lock_rom:      PUSH AF                                          
               LD   A,163                                       
               OUT  (250),A                                     
               POP  AF                                          
               RET                                              
                                                                
                                                                
; Main character printing routine. used by format and normal    
; typing from the keyboard.                                     
                                                                
                                                                
pchar:         LD   (chr_buf),A                                 
               CALL norm                                        
                                                                
               LD   HL,(memry)                                  
               INC  HL                                          
               LD   DE,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               JP   Z,topfile                                   
               JP   NC,topfile                                  
               LD   A,(chr_buf)                                 
               CP   32                                          
               JR   NZ,pchr                                     
               LD   A,(col)                                     
               LD   B,A                                         
               LD   A,(left_col)                                
               CP   B                                           
               JR   NZ,go_on                                    
               LD   HL,(w_memry)                                
               LD   A,(HL)                                      
               CP   32                                          
               JR   Z,go_on                                     
               LD   A,(var)                                     
               CP   255                                         
               JR   Z,go_on                                     
               LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
               RET ;              JP crsr                       
                                                                
poke255:       LD   A,255                                       
               LD   (ed_var),A                                  
               LD   A,0                                         
               LD   (var),A                                     
               JP   back                                        
                                                                
go_on:         LD   A,32                                        
               JP   back                                        
                                                                
pchr:          LD   A,(var)                                     
               CP   255                                         
               JR   Z,poke255                                   
               LD   A,0                                         
               LD   (ed_var),A                                  
                                                                
back:          CALL memchk                                      
pok2:          LD   HL,(memry)                                  
               LD   DE,(memtop)                                 
               OR   A                                           
               SBC  HL,DE                                       
               JR   C,nxt_chk                                   
               LD   HL,(memtop)                                 
               LD   (HL),32                                     
               LD   HL,(memry)                                  
               INC  HL                                          
               LD   (HL),255                                    
               LD   (memtop),HL                                 
               JR   poke                                        
                                                                
nxt_chk:       LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   255                                         
               JR   NZ,poke                                     
               INC  HL                                          
               LD   (HL),255                                    
               LD   (memtop),HL                                 
                                                                
poke:          LD   A,(pflag)                                   
               CP   0                                           
               JP   Z,poke_2                                    
               XOR  A                                           
               LD   (pflag),A                                   
                                                                
; if character is a control character then print it inverted    
                                                                
print_c_char:  LD   A,(chr_buf)                                 
               SET  7,A                                         
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               LD   HL,(memry)                                  
               LD   (HL),A                                      
               RES  7,A                                         
               LD   DE,(CHARSET)   ;   chars-512                
               LD   L,A                                         
               LD   H,0                                         
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,(sposn)                                  
               CALL screen_in                                   
               LD   B,8                                         
c_char_loop:   LD   A,(DE)                                      
               XOR  255                                         
               LD   (HL),A                                      
               INC  DE                                          
               INC  HL                                          
               LD   A,(DE)                                      
               XOR  255                                         
               LD   (HL),A                                      
               INC  DE                                          
               LD   A,127                                       
               ADD  A,L                                         
               LD   L,A                                         
               JR   NC,n_cary                                   
               INC  H                                           
n_cary:        DJNZ c_char_loop                                 
               EX   AF,AF'                                      
               OUT  (251),A                                     
               LD   HL,chars-512                                
               LD   (CHARSET),HL                                
               JP   right_1                                     
                                                                
; not a control code so print normal character                  
                                                                
poke_2:        LD   A,(chr_buf)                                 
               LD   HL,(memry)                                  
               LD   (HL),A                                      
               LD   DE,(CHARSET)   ;chars-512                   
               LD   L,A                                         
               LD   H,0                                         
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,(sposn)                                  
               CALL screen_in                                   
               LD   B,8                                         
ploop:         LD   A,(HL)                                      
               LD   A,(DE)                                      
               LD   (HL),A                                      
               INC  DE                                          
               INC  HL                                          
               LD   A,(DE)                                      
               LD   (HL),A                                      
               INC  DE                                          
               LD   A,127                                       
               ADD  A,L                                         
               LD   L,A                                         
               JR   NC,ncary                                    
               INC  H                                           
ncary:         DJNZ ploop                                       
               EX   AF,AF'                                      
               OUT  (251),A                                     
                                                                
; Every time the cursor reaches the right col/margin then save  
; the print position and the memry position for use from the    
; wordwrap and justify routine. see also JSCROL                 
; The cursor will drop to the next line after this routine so in
; effect the end of the last line has been saved.               
                                                                
                                                                
right_1:       LD   A,(col)                                     
               LD   B,A                                         
               LD   A,(right_col)                               
               CP   B                                           
               JP   NZ,right                                    
               LD   HL,(memry)                                  
               LD   (w_memry),HL                                
               LD   HL,(sposn)                                  
               LD   (w_sposn),HL                                
                                                                
                                                                
right:         CALL memory_chk                                  
               LD   A,(right_col)                               
               LD   B,A                                         
               LD   A,(col)                                     
               CP   B                                           
               JP   NZ,justinc                                  
               LD   A,(line)                                    
check1:        CP   24                                          
               JP   Z,jscrol                                    
               INC  A                                           
               LD   L,A                                         
               LD   A,(left_col)                                
               LD   H,A                                         
               CALL stcur                                       
               CALL incln                                       
               CALL incfle_m                                    
               LD   A,(ins_flg)                                 
               OR   A                                           
               RET  Z                                           
               LD   A,(chr_buf)                                 
               CP   9                                           
               RET  Z                                           
               JP   open_file                                   
                                                                
; increment the memry pointer when going from the rightmost col 
; to the left. if a normal 64 col screen is in use then padnumr 
; will hold a 1 while padnuml will hold 0.                      
                                                                
                                                                
incfle_m:      LD   HL,(memry)                                  
               LD   A,(pad_numl)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   A,(pad_numr)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
                                                                
; as the memry and sposn were saved at the end of the previous  
; line and now the screen is going to scroll, then the print    
; position that was saved has to be decremented by 1024 bytes   
; If not then the wordwrap and justify routines dont reprint    
; from the right place. W_memry is ok only W_sposn needs doing  
                                                                
jscrol:        CALL memchk                                      
               LD   HL,(w_sposn)                                
               LD   DE,1024                                     
               OR   A                                           
               SBC  HL,DE                                       
               LD   (w_sposn),HL                                
                                                                
               CALL scroll                                      
               LD   HL,bottom_line                              
               CALL blk2                                        
               LD   HL,(memry)                                  
               LD   A,(pad_numr)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
                                                                
               CALL incln                                       
               LD   B,64                                        
               LD   HL,bottom_line                              
               LD   DE,(memry)                                  
               CALL prtline_1                                   
               LD   HL,(memry)                                  
               LD   A,(pad_numl)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur                                       
               LD   A,(chr_buf)                                 
               CP   9                                           
               RET  Z                                           
               LD   A,(ins_flg)                                 
               OR   A                                           
               JP   NZ,open_file                                
               RET                                              
                                                                
justinc:       LD   A,(col)                                     
               INC  A                                           
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur                                       
                                                                
incfle:        LD   HL,(memry)                                  
               INC  HL                                          
               LD   (memry),HL                                  
               RET                                              
                                                                
decfle:        LD   HL,(memry)                                  
               DEC  HL                                          
               LD   (memry),HL                                  
               RET                                              
                                                                
down1:         CALL memchk2                                     
               LD   A,(line)                                    
               CP   24                                          
               JP   NZ,down                                     
               CALL scroll                                      
               LD   HL,bottom_line                              
               CALL blk2                                        
               CALL incln                                       
               LD   HL,(memry)                                  
               LD   DE,64                                       
               ADD  HL,DE                                       
               LD   (memry),HL                                  
               LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               LD   B,64                                        
               LD   HL,bottom_line                              
               LD   A,(move_var)                                
               OR   A                                           
               RET  NZ                                          
               CALL prtline                                     
               RET                                              
                                                                
enter:         CALL memchk2                                     
               LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,64                                       
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,(memry)                                  
               ADD  HL,DE                                       
               LD   A,(pad_numl)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               CALL incln                                       
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   A,(line)                                    
               CP   24                                          
               JP   Z,entscr1                                   
               INC  A                                           
               LD   L,A                                         
               CALL stcur                                       
               LD   A,(ins_flg)                                 
               OR   A                                           
               JP   NZ,open_file                                
               RET                                              
                                                                
entscr1:       CALL scroll                                      
               LD   HL,bottom_line                              
               CALL blk2                                        
               LD   B,64                                        
               LD   HL,(memry)                                  
               LD   A,(pad_numl)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,bottom_line                              
               CALL prtline_1                                   
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   L,24                                        
               CALL stcur                                       
               LD   A,(ins_flg)                                 
               OR   A                                           
               JP   NZ,open_file                                
               RET                                              
                                                                
left:          LD   A,(left_col)                                
               LD   B,A                                         
               LD   A,(col)                                     
               CP   B                                           
               JR   NZ,left1                                    
               LD   HL,(total)                                  
               LD   A,H                                         
               OR   A                                           
               JR   NZ,chk3                                     
               LD   A,L                                         
               CP   1                                           
               SCF                                              
               RET  Z                                           
                                                                
chk3:          LD   A,(line)                                    
               CP   3                                           
               JP   Z,dscroll                                   
               CALL decln                                       
               CALL dec_to_left                                 
               LD   A,(right_col)                               
               LD   H,A                                         
               LD   A,(line)                                    
               DEC  A                                           
               LD   L,A                                         
               CALL stcur                                       
               SCF                                              
               CCF                                              
               RET                                              
                                                                
left1:         LD   A,(col)                                     
               DEC  A                                           
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur                                       
               CALL decfle                                      
               SCF                                              
               CCF                                              
               RET                                              
                                                                
dscroll:       CALL dscrol                                      
               CALL blklin                                      
               CALL decln                                       
               CALL dec_to_left                                 
               LD   HL,(memry)                                  
               LD   A,(right_col)                               
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               LD   B,64                                        
               LD   HL,34816                                    
               CALL prtline                                     
               LD   L,3                                         
               LD   A,(right_col)                               
               LD   H,A                                         
               CALL stcur                                       
               SCF                                              
               CCF                                              
               RET                                              
                                                                
down:          CALL incln                                       
               LD   A,(line)                                    
               INC  A                                           
               LD   L,A                                         
               LD   A,(col)                                     
               LD   H,A                                         
               CALL stcur                                       
               LD   HL,(memry)                                  
               LD   DE,64                                       
               ADD  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
dec_to_left:   LD   HL,(memry)                                  
               LD   A,(pad_numl)                                
               LD   B,A                                         
               LD   A,(pad_numr)                                
               ADD  A,B                                         
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
up:            LD   A,(line)                                    
               CP   3                                           
               JR   NZ,up1                                      
               LD   HL,(total)                                  
               LD   A,H                                         
               OR   A                                           
               JR   NZ,upp                                      
               LD   A,L                                         
               CP   1                                           
               RET  Z                                           
                                                                
upp:           CALL dscrol                                      
               CALL blklin                                      
               CALL decln                                       
               LD   HL,(memry)                                  
               LD   DE,64                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               LD   A,(move_var)                                
               OR   A                                           
               RET  NZ                                          
               LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               LD   B,64                                        
               LD   HL,34816                                    
               CALL prtline                                     
               RET                                              
                                                                
up1:           LD   A,(line)                                    
               DEC  A                                           
               LD   L,A                                         
               LD   A,(col)                                     
               LD   H,A                                         
               CALL stcur                                       
               CALL decln                                       
               LD   HL,(memry)                                  
               LD   DE,64                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
delete:        CALL memchk                                      
               CALL left                                        
               RET  C                                           
               LD   HL,(sposn)                                  
               CALL screen_in                                   
               PUSH DE                                          
               LD   DE,127                                      
               LD   B,8                                         
dloop:         LD   (HL),0                                      
               INC  HL                                          
               LD   (HL),0                                      
               ADD  HL,DE                                       
               DJNZ dloop                                       
               POP  DE                                          
               EX   AF,AF'                                      
               OUT  (251),A                                     
               LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   255                                         
               JR   Z,oldend                                    
               INC  HL                                          
               LD   A,(HL)                                      
               CP   255                                         
               JR   Z,newend                                    
               DEC  HL                                          
               LD   (HL),32                                     
               RET                                              
                                                                
newend:        LD   (HL),32                                     
               DEC  HL                                          
               LD   (HL),32                                     
               INC  HL                                          
decagen:       DEC  HL                                          
               LD   A,(HL)                                      
               CP   32                                          
               JR   Z,decagen                                   
               INC  HL                                          
               LD   (HL),255                                    
               LD   (memtop),HL                                 
               RET                                              
                                                                
oldend:        LD   (HL),255                                    
               RET                                              
                                                                
stcur:         LD   (line),HL  ; puts L into line and H into col
               LD   A,L                                         
               LD   HL,31744                                    
               ADD  A                                           
               ADD  A                                           
               ADD  H                                           
               LD   H,A                                         
               LD   A,(col)                                     
               ADD  A                                           
               ADD  L                                           
               LD   L,A                                         
               LD   (sposn),HL                                  
               RET                                              
                                                                
                                                                
; open_file is called from the enter and right routine if insert
; is turned on. it is also called if symbol key and cursor right
; is pressed (to open the file).                                
; open_fl2 is called from the justify routine if the paragraph  
; being justified is about to bump into the next paragraph.     
; This will only happen if the paragraph is being reformated to 
; a narower format than it was at the start.ie 64 down to 32 etc
                                                                
                                                                
open_file:     LD   A,(block_var)                               
               OR   A                                           
               RET  NZ                                          
open_fl2:      LD   HL,(memtop)                                 
               LD   DE,65                                       
               ADD  HL,DE                                       
               LD   DE,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               JP   Z,topfile                                   
               JP   NC,topfile                                  
               LD   HL,(memtop)                                 
               LD   DE,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               RET  C                                           
               RET  Z                                           
                                                                
               CALL open_scroll                                 
               LD   HL,(sposn)                                  
               LD   (sposn2),HL                                 
               CALL norm                                        
               LD   B,64                                        
o_space_loop:  LD   A,32                                        
               CALL pchar2_2                                    
               DJNZ o_space_loop                                
               LD   HL,(memtop)                                 
               LD   DE,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   B,H                                         
               LD   C,L                                         
               INC  BC                                          
               LD   HL,(memtop)                                 
               PUSH HL                                          
               LD   DE,64                                       
               ADD  HL,DE                                       
               LD   (memtop),HL                                 
               EX   DE,HL                                       
               POP  HL                                          
               LDDR                                             
               LD   HL,(memry)                                  
               LD   B,64                                        
poke32:        LD   (HL),32                                     
               INC  HL                                          
               DJNZ poke32                                      
               LD   HL,64                                       
               LD   DE,(memry)                                  
               ADD  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,(sposn)                                  
               LD   BC,1024                                     
               ADD  HL,BC                                       
               LD   B,64                                        
               CALL prtline                                     
               CALL up_date_2                                   
               RET                                              
                                                                
open_scroll:   LD   A,(line)                                    
               CP   23                                          
               RET  NC                                          
               INC  A                                           
               LD   B,A                                         
               LD   A,24                                        
               SUB  B                                           
               LD   B,A                                         
               LD   DE,1024                                     
               LD   HL,0                                        
open_loop:     ADD  HL,DE                                       
               DJNZ open_loop                                   
               ADD  HL,DE                                       
               LD   B,H                                         
               LD   C,L                                         
               LD   HL,56319                                    
               LD   DE,57343                                    
               CALL screen_in                                   
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDDR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
; close_the file. Called from the format routine and also by    
; pressing symbol and left cursor.                              
                                                                
close_file:    LD   A,(block_var)                               
               OR   A                                           
               RET  NZ                                          
               CALL strtln                                      
               CALL chk_line                                    
               LD   HL,(memtop)                                 
               LD   DE,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,exit_close                                
               JP   Z,exit_close                                
               CALL close_scroll                                
               CALL blank                                       
               LD   HL,(memtop)                                 
               LD   DE,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   B,H                                         
               LD   C,L                                         
               INC  BC                                          
               LD   HL,(memry)                                  
               PUSH DE                                          
               LD   DE,64                                       
               ADD  HL,DE                                       
               POP  DE                                          
               LDIR                                             
               LD   HL,(sposn)                                  
               LD   A,(col)                                     
               ADD  A                                           
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               PUSH HL                                          
               LD   HL,(memry)                                  
               LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               POP  HL                                          
               PUSH DE                                          
               LD   B,64                                        
               CALL prtline                                     
               LD   HL,(memtop)                                 
nwtop:         DEC  HL                                          
               LD   A,(HL)                                      
               CP   255                                         
               JR   NZ,nwtop                                    
               LD   (memtop),HL                                 
               LD   A,(temp)                                    
               LD   B,A                                         
               POP  HL                                          
               LD   DE,64                                       
mempntr:       ADD  HL,DE                                       
               DJNZ mempntr                                     
               EX   DE,HL                                       
               LD   B,64                                        
               LD   A,(line)                                    
               CP   24                                          
               JP   Z,close_next                                
               LD   HL,bottom_line                              
               CALL prtline                                     
close_next:    LD   A,(close_flg)                               
               CP   255                                         
               CALL Z,find_end                                  
               CALL up_date_2                                   
exit_close:    CALL goto_margin                                 
               RET                                              
                                                                
close_scroll:  LD   A,(line)                                    
               CP   24                                          
               RET  Z                                           
               LD   A,(line)                                    
               LD   B,A                                         
               LD   A,24                                        
               SUB  B                                           
               LD   (temp),A                                    
               LD   B,A                                         
               LD   HL,0                                        
               LD   DE,1024                                     
close_loop:    ADD  HL,DE                                       
               DJNZ close_loop                                  
               LD   B,H                                         
               LD   C,L                                         
               LD   DE,(sposn)                                  
               LD   HL,1024                                     
               ADD  HL,DE                                       
scroll_scrn:   CALL screen_in                                   
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
                                                                
                                                                
dscrol:        LD   A,(move_var)                                
               OR   A                                           
               RET  NZ                                          
               LD   A,(sc_cnt)                                  
               INC  A                                           
               LD   (sc_cnt),A                                  
               CALL screen_in                                   
               LD   HL,56319                                    
               LD   DE,57343                                    
               LD   BC,21504                                    
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDDR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
blklin:        LD   HL,34816                                    
               CALL blk2                                        
               RET                                              
                                                                
                                                                
scroll:        LD   A,(move_var)                                
               OR   A                                           
               RET  NZ                                          
                                                                
                                                                
               LD   HL,35840                                    
               LD   DE,34816                                    
               LD   BC,21504                                    
               JP   scroll_scrn                                 
                                                                
blank:         LD   HL,56320                                    
blk2:          INC  HL                                          
               PUSH HL                                          
               POP  DE                                          
               DEC  HL                                          
               LD   BC,1023                                     
               CALL screen_in                                   
               LD   (HL),0                                      
               LDIR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
prtline_1:     LD   A,(ins_flg)                                 
               OR   A                                           
               JP   Z,prtline                                   
               LD   A,(chr_buf)                                 
               CP   9                                           
               JP   Z,prtline                                   
               CP   10                                          
               RET  NZ                                          
                                                                
prtline:       LD   (sposn2),HL                                 
               CALL norm                                        
               EX   DE,HL                                       
linlp:         LD   A,(HL)                                      
               CP   255                                         
               CALL Z,notprt                                    
               CP   0                                           
               JR   Z,nomore                                    
               CALL pchar2                                      
               INC  HL                                          
               DJNZ linlp                                       
nomore:        JP   inverse                                     
                                                                
notprt:        LD   A,32                                        
               RET                                              
                                                                
; printing routine to print messages etc onto the top line      
; or the screen. used mostly when reprinting lines at the top   
; or the bottom of the file after scroll has taken place.       
; also used to reprint the screen when required. Does nothing   
; to the text file. just the screen. Entry condition 'A' holds  
; Character to print (sposn2) holds the screen position.        
                                                                
                                                                
pchar2:        BIT  7,A                                         
               JP   Z,pchar2_2                                  
               PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               PUSH AF                                          
               CALL inverse                                     
               POP  AF                                          
               RES  7,A                                         
               CALL pchar2_2                                    
               CALL norm                                        
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               RET                                              
                                                                
                                                                
; this will print the character inverted ie control character.  
                                                                
                                                                
pchar2_2:      EXX                                              
               LD   DE,(CHARSET)  ;   chars-512                 
               LD   L,A                                         
               LD   H,0                                         
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,(sposn2)                                 
               PUSH HL                                          
               CALL screen_in                                   
               LD   B,8                                         
gloop2:        LD   A,(DE)                                      
mod:           XOR  255                                         
               LD   (HL),A                                      
               INC  DE                                          
               INC  HL                                          
               LD   A,(DE)                                      
mod2:          XOR  255                                         
               LD   (HL),A                                      
               INC  DE                                          
               LD   A,127                                       
               ADD  A,L                                         
               LD   L,A                                         
               JR   NC,no_carry                                 
               INC  H                                           
                                                                
no_carry:      DJNZ gloop2                                      
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  HL                                          
               INC  L                                           
               INC  L                                           
               LD   A,L                                         
               CP   128                                         
               JR   NZ,store_spos                               
               LD   L,0                                         
               LD   A,4                                         
               ADD  H                                           
               LD   H,A                                         
store_spos:    LD   (sposn2),HL                                 
               EXX                                              
               RET                                              
                                                                
pnum2:         LD   C,0                                         
               LD   H,0                                         
               LD   L,A                                         
               CP   10                                          
               JR   C,num1                                      
               JR   num2                                        
                                                                
pnum:          LD   C,1                                         
               LD   DE,10000                                    
               CALL mult                                        
               LD   DE,1000                                     
               CALL mult                                        
               LD   DE,100                                      
               CALL mult                                        
num2:          LD   DE,10                                       
               CALL mult                                        
num1:          LD   A,L                                         
               ADD  48                                          
               CALL pchar2_2                                    
               LD   A,32                                        
               CALL pchar2_2                                    
               LD   A,32                                        
               JP   pchar2_2                                    
                                                                
mult:          XOR  A                                           
mult2:         INC  A                                           
               SBC  HL,DE                                       
               JR   NC,mult2                                    
               ADD  HL,DE                                       
               CP   C                                           
               RET  Z                                           
               DEC  C                                           
               ADD  47                                          
               JP   pchar2                                      
                                                                
                                                                
; print the logo at the top of the screen                       
                                                                
logo:          LD   HL,32768                                    
               LD   (sposn2),HL                                 
               LD   HL,log                                      
               CALL prstr_2                                     
               LD   B,"1"                                       
               LD   A,(text_page)                               
               CP   5                                           
               JR   Z,end_log                                   
               LD   B,"2"                                       
               CP   7                                           
               JR   Z,end_log                                   
               LD   B,"3"                                       
end_log:       LD   A,B                                         
               CALL pchar2_2                                    
               LD   HL,log2                                     
               CALL prstr_2                                     
               RET                                              
                                                                
                                                                
                                                                
                                                                
; increment the line number that the cursor is at               
                                                                
incln:         PUSH AF                                          
               LD   A,(lline)                                   
pgelen2:       CP   58                                          
               JR   Z,incpage                                   
               INC  A                                           
               LD   (lline),A                                   
               CALL inctot                                      
               POP  AF                                          
               RET                                              
                                                                
; increment the page number for the status line printing routine
                                                                
                                                                
                                                                
incpage:       LD   A,(pyge)                                    
               INC  A                                           
               LD   (pyge),A                                    
               LD   A,1                                         
               LD   (lline),A                                   
               CALL inctot                                      
               POP  AF                                          
               RET                                              
                                                                
; total lines in the file. used to check for the top or the     
; bottom of the file.                                           
                                                                
inctot:        PUSH HL                                          
               LD   HL,(total)                                  
               INC  HL                                          
               LD   (total),HL                                  
               POP  HL                                          
               RET                                              
                                                                
dectot:        LD   HL,(total)                                  
               DEC  HL                                          
               LD   (total),HL                                  
               RET                                              
                                                                
decln:         PUSH AF                                          
               LD   A,(lline)                                   
               CP   1                                           
               JR   Z,decpage                                   
               DEC  A                                           
               LD   (lline),A                                   
               CALL dectot                                      
               POP  AF                                          
               RET                                              
                                                                
decpage:       LD   A,(pyge)                                    
               CP   1                                           
               JR   Z,doline                                    
               DEC  A                                           
               LD   (pyge),A                                    
doline:        LD   A,58                                        
               LD   (lline),A                                   
               CALL dectot                                      
               POP  AF                                          
               RET                                              
                                                                
; called after every keypress to update the status line         
                                                                
update:        CALL inverse                                     
               LD   HL,32852                                    
               LD   (sposn2),HL                                 
               LD   A,(pyge)                                    
               LD   H,0                                         
               LD   L,A                                         
               CALL pnum                                        
               LD   HL,32872                                    
               LD   (sposn2),HL                                 
               LD   A,(lline)                                   
               CALL pnum2                                       
               LD   HL,32889                                    
               LD   (sposn2),HL                                 
               LD   A,(col)                                     
               INC  A                                           
               CALL pnum2                                       
               LD   HL,33812                                    
               LD   (sposn2),HL                                 
               LD   HL,(memtop)                                 
               LD   DE,file_st                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   (len_var),HL                                
               CALL pnum                                        
               RET                                              
                                                                
; print the margin values on the screen                         
                                                                
show_margins:  CALL inverse                                     
               LD   HL,33898                                    
               LD   (sposn2),HL                                 
               LD   B,37                                        
               CALL prstr                                       
               LD   A,(left_col)                                
               INC  A                                           
               CALL pnum2                                       
               LD   HL,33908                                    
               LD   (sposn2),HL                                 
               LD   B,38                                        
               CALL prstr                                       
               LD   A,(right_col)                               
               INC  A                                           
               CALL pnum2                                       
               RET                                              
                                                                
                                                                
up_date_2:     CALL inverse                                     
               LD   HL,33812                                    
               LD   (sposn2),HL                                 
               LD   HL,(memtop)                                 
               LD   DE,file_st                                  
               OR   A                                           
               SBC  HL,DE                                       
               JP   pnum                                        
                                                                
; place cursor at the left or right margin                      
                                                                
endlne:        LD   A,(col)                                     
               PUSH AF                                          
               LD   A,(line)                                    
               LD   L,A                                         
               LD   H,63                                        
               CALL stcur                                       
               POP  AF                                          
               INC  A                                           
               LD   B,A                                         
               LD   A,64                                        
               SUB  B                                           
               LD   HL,(memry)                                  
               LD   E,A                                         
               LD   D,0                                         
               ADD  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
; Set the cursor to the start of the line                       
                                                                
strtln:        LD   A,(col)                                     
               PUSH AF                                          
               LD   A,(line)                                    
               LD   L,A                                         
               LD   H,0                                         
               CALL stcur                                       
               POP  AF                                          
               INC  A                                           
               LD   HL,(memry)                                  
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               INC  HL                                          
               LD   (memry),HL                                  
               RET                                              
                                                                
                                                                
; must only be called after a routine has used strtln (above)   
; will return the cursor to the left margin.                    
                                                                
                                                                
goto_margin:   LD   A,(left_col)                                
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur                                       
               LD   A,(pad_numl)                                
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,(memry)                                  
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
; jump to the space between the next word on the line           
                                                                
wrdend:        LD   A,(right_col)                               
               LD   C,A                                         
               LD   A,(col)                                     
               CP   C                                           
               JP   Z,enter_1                                   
               LD   B,A                                         
               LD   HL,(memry)                                  
               LD   A,(HL)                                      
wrd_loop:      CP   32                                          
               JP   Z,wrd_next                                  
               BIT  7,A                                         
               JP   NZ,wrd_next                                 
               JP   inc_to_space                                
                                                                
wrd_next:      INC  HL                                          
               INC  B                                           
               LD   A,B                                         
               CP   C                                           
               JP   Z,end_of_line                               
               LD   A,(HL)                                      
               JP   wrd_loop                                    
                                                                
inc_to_space:  INC  HL                                          
               INC  B                                           
               LD   A,B                                         
               CP   C                                           
               JP   Z,end_of_line                               
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,inc_next                                  
               BIT  7,A                                         
               JP   NZ,inc_next                                 
               JP   inc_to_space                                
                                                                
inc_next:      LD   A,B                                         
end_of_line:   LD   (memry),HL                                  
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               JP   stcur                                       
                                                                
; jump to the space between the previous word on the line       
                                                                
wrdstrt:       LD   A,(left_col)                                
               LD   C,A                                         
               LD   A,(col)                                     
               CP   C                                           
               JP   Z,left                                      
               LD   B,A                                         
               LD   HL,(memry)                                  
               LD   A,(HL)                                      
wrd_loop2:     CP   32                                          
               JP   Z,wrd_next2                                 
               BIT  7,A                                         
               JP   NZ,wrd_next2                                
               JP   dec_to_space                                
                                                                
wrd_next2:     DEC  HL                                          
               DEC  B                                           
               LD   A,B                                         
               CP   C                                           
               JP   Z,line_up                                   
               LD   A,(HL)                                      
               JP   wrd_loop2                                   
                                                                
dec_to_space:  DEC  HL                                          
               DEC  B                                           
               LD   A,B                                         
               CP   C                                           
               JP   Z,line_up                                   
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,dec_next                                  
               BIT  7,A                                         
               JP   NZ,dec_next                                 
               JP   dec_to_space                                
                                                                
dec_next:      LD   A,B                                         
                                                                
line_up:       LD   (memry),HL                                  
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               JP   stcur                                       
                                                                
; various routines to check the memory status                   
                                                                
memchk2:       LD   HL,(memry)                                  
               LD   DE,64                                       
               ADD  HL,DE                                       
               EX   DE,HL                                       
               JR   memchka                                     
                                                                
memchk:        LD   A,(BF_buffer)                               
               CP   32                                          
               RET  NZ                                          
memory_chk:    LD   DE,(memry)                                  
memchka:       LD   HL,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               JR   Z,topfile                                   
               JR   C,topfile                                   
               RET                                              
                                                                
; end of the file reached so print the message and exit         
                                                                
topfile:       CALL draw_box                                    
               LD   B,11                                        
               CALL press_ret                                   
               CALL exit_box                                    
               CALL update                                      
               LD   A,(block_var)                               
               OR   A                                           
               JP   Z,emg_rt                                    
               LD   HL,(block_strt)                             
               LD   A,(char_1)                                  
               LD   (HL),A                                      
               LD   HL,(block_end)                              
               LD   A,(char_2)                                  
               LD   (HL),A                                      
               CALL do_vars                                     
emg_rt:        XOR  A                                           
               LD   (block_var),A                               
               LD   (move_var),A                                
               CALL up                                          
               CALL strtln                                      
               CALL goto_margin                                 
               LD   HL,(emg_ret)  ; Throw away all CALL's       
               LD   SP,HL         ; get entry SP                
               JP   key           ; exit to key                 
                                                                
                                                                
; Clear the file out of memory completely                       
                                                                
                                                                
clr_fle:       CALL draw_box                                    
               LD   B,13                                        
               CALL prstr                                       
clr_kee:       CALL rd_key                                      
               RES  5,A                                         
               CP   "Y"                                         
               JR   Z,clearit                                   
               CP   "N"                                         
               JR   NZ,clr_kee                                  
               CALL norm                                        
               JP   reprint_screen                              
                                                                
clearit:       LD   HL,file_st                                  
               LD   (HL),0                                      
               POP  HL                                          
               CALL cls                                         
               CALL setop                                       
               XOR  A                                           
               LD   (crsr_flag),A                               
               JP   start                                       
                                                                
chk_line:      LD   HL,(memry)                                  
               LD   B,64                                        
chk_loop:      LD   A,(HL)                                      
               CP   255                                         
               JP   Z,set_flag                                  
               INC  HL                                          
               DJNZ chk_loop                                    
               RET                                              
                                                                
set_flag:      LD   A,255                                       
               LD   (close_flg),A                               
               RET                                              
                                                                
                                                                
; Centre the text on the line                                   
                                                                
                                                                
centre:        CALL initbuf                                     
               CALL strtln                                      
               CALL goto_margin                                 
               LD   HL,(memry)                                  
               LD   A,(line_length)                             
               LD   B,A                                         
               LD   C,0                                         
cenloop:       LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,gtfrnt                                   
               INC  HL                                          
               INC  C                                           
               LD   A,C                                         
               CP   B                                           
               JR   NZ,cenloop                                  
               JP   enter_1                                     
                                                                
gtfrnt:        LD   HL,(memry)                                  
               LD   E,B                                         
               LD   D,0                                         
               DEC  DE                                          
               ADD  HL,DE                                       
frntlp:        LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,gotsps                                   
               DEC  HL                                          
               INC  C                                           
               JR   frntlp                                      
                                                                
gotsps:        LD   A,C                                         
               OR   A                                           
               JP   Z,enter_1                                   
               CP   2                                           
               JP   C,enter_1                                   
               PUSH BC                                          
               SRA  C                                           
               LD   HL,buffer                                   
               LD   B,C                                         
filbuf:        INC  HL                                          
               DJNZ filbuf                                      
               LD   DE,(memry)                                  
fillp:         LD   A,(DE)                                      
               CP   32                                          
               JR   NZ,filbuf2                                  
               INC  DE                                          
               JR   fillp                                       
                                                                
filbuf2:       POP  BC                                          
               LD   A,(line_length)                             
               SUB  C                                           
               LD   B,A                                         
filbuf3:       LD   A,(DE)                                      
               LD   (HL),A                                      
               INC  DE                                          
               INC  HL                                          
               DJNZ filbuf3                                     
               LD   HL,(memry)                                  
               LD   DE,buffer                                   
               LD   A,(line_length)                             
               LD   B,A                                         
filmem:        LD   A,(DE)                                      
               LD   (HL),A                                      
               CP   255                                         
               JR   NZ,not_end                                  
               LD   (memtop),HL                                 
not_end:       INC  HL                                          
               INC  DE                                          
               DJNZ filmem                                      
               LD   A,(line_length)                             
               LD   B,A                                         
               LD   HL,(sposn)                                  
               LD   DE,(memry)                                  
               CALL prtline                                     
               CALL initbuf                                     
enter_1:       CALL store_insert                                
               CALL enter                                       
               JP   unstr_insert                                
                                                                
initbuf:       LD   B,64                                        
               LD   A,32                                        
               LD   HL,buffer                                   
inbuf:         LD   (HL),A                                      
               INC  HL                                          
               DJNZ inbuf                                       
               RET                                              
                                                                
; Push line away from the cursor                                
                                                                
pshline:       LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   255                                         
               RET  Z                                           
               LD   B,64                                        
pushlp:        LD   A,(HL)                                      
               CP   255                                         
               JR   Z,chk_top                                   
               INC  HL                                          
               DJNZ pushlp                                      
               JR   psline                                      
                                                                
chk_top:       LD   DE,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               JP   Z,topfile                                   
               JP   NC,topfile                                  
psline:        LD   HL,(memry)                                  
               LD   A,(col)                                     
               INC  A                                           
               LD   C,A                                         
               LD   A,(right_col)                               
               INC  A                                           
               CP   C                                           
               RET  Z                                           
               LD   B,A                                         
               SUB  C                                           
               LD   B,A                                         
               LD   HL,(memry)                                  
               LD   E,A                                         
               LD   D,0                                         
               ADD  HL,DE                                       
               LD   A,(HL)                                      
               CP   32                                          
               RET  NZ                                          
               LD   D,H                                         
               LD   E,L                                         
pshloop:       DEC  DE                                          
               LD   A,(DE)                                      
               LD   (HL),A                                      
               CP   255                                         
               JP   NZ,notend2                                  
               LD   (memtop),HL                                 
notend2:       DEC  HL                                          
               DJNZ pshloop                                     
               LD   (HL),32                                     
               LD   A,(col)                                     
               INC  A                                           
               LD   B,A                                         
               LD   A,64                                        
               SUB  B                                           
               INC  A                                           
               LD   B,A                                         
               LD   HL,(sposn)                                  
               LD   DE,(memry)                                  
               JP   prtline                                     
                                                                
; Pull line to the cursor                                       
                                                                
pull_line:     CALL pulline                                     
               RET  Z                                           
               LD   HL,(sposn)                                  
               LD   DE,(memry)                                  
               JP   prtline                                     
                                                                
pulline:       LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   255                                         
               RET  Z                                           
               LD   A,(col)                                     
               INC  A                                           
               LD   C,A                                         
               LD   A,(right_col)                               
               INC  A                                           
               CP   C                                           
               RET  Z                                           
               SUB  C                                           
               LD   B,A                                         
               PUSH AF                                          
               LD   HL,(memry)                                  
               PUSH HL                                          
               POP  DE                                          
pulloop:       INC  HL                                          
               LD   A,(HL)                                      
               LD   (DE),A                                      
               CP   255                                         
               JR   NZ,notend3                                  
               LD   (memtop),DE                                 
               JR   founend                                     
                                                                
notend3:       INC  DE                                          
               DJNZ pulloop                                     
founend:       LD   (HL),32                                     
               POP  AF                                          
               INC  A                                           
               LD   B,A                                         
                                                                
; make sure z flag = 0 so do a CP 200                           
                                                                
               CP   200                                         
               RET                                              
                                                                
word_wrap:     LD   HL,(w_memry)                                
               DEC  HL                                          
               LD   A,(line_length)                             
                                                                
               CP   3        ; if the line is less than 3 or is 
               RET  C        ; only 3 bytes long then return.   
               RET  Z        ; ie dont attempt to word wrap.    
               DEC  A                                           
               DEC  A                                           
               LD   B,A                                         
sp_loop:       LD   A,(HL)                                      
               CP   32                                          
               JP   Z,wrap_ok                                   
               BIT  7,A                                         
               JP   NZ,wrap_ok                                  
               DEC  HL                                          
               DJNZ sp_loop                                     
               RET                                              
                                                                
wrap_ok:       LD   A,(ed_var)                                  
               CP   255                                         
               RET  Z                                           
               LD   A,(var)                                     
               CP   255                                         
               RET  Z                                           
               LD   A,(wrap)                                    
               CP   255                                         
               RET  Z                                           
                                                                
                                                                
               LD   A,(col)                                     
               LD   B,A                                         
               LD   A,(left_col)                                
               INC  A                                           
               CP   B                                           
               RET  NZ                                          
                                                                
                                                                
               LD   HL,(memry)                                  
               DEC  HL                                          
               LD   A,(HL)                                      
               LD   (chrbuff),A                                 
               LD   HL,(w_memry)                                
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,justify                                   
                                                                
               LD   HL,(w_sposn)                                
               LD   DE,(w_memry)                                
               LD   C,1                                         
c_loop:        INC  C                                           
               DEC  L                                           
               DEC  L                                           
               DEC  DE                                          
               LD   A,(DE)                                      
               CP   32                                          
               JP   Z,do_next                                   
               BIT  7,A                                         
               JP   Z,c_loop                                    
do_next:       INC  L                                           
               INC  L                                           
               INC  DE                                          
               LD   (memtemp),DE                                
               LD   (spostmp),HL                                
               LD   A,C                                         
               LD   (chr_cnt),A                                 
               LD   B,A                                         
               DEC  B                                           
               PUSH BC                                          
               LD   A,(left_col)                                
               LD   H,A                                         
               LD   A,(line)                                    
               LD   L,A                                         
               CALL stcur                                       
               POP  BC                                          
               LD   HL,(memtemp)                                
               LD   DE,(memry)                                  
               DEC  DE                                          
               LD   (memry),DE                                  
trs_fer:       LD   A,(HL)                                      
               EXX                                              
               CALL pok                                         
               EXX                                              
               INC  HL                                          
               DJNZ trs_fer                                     
               LD   A,(chrbuff)                                 
               CALL pok                                         
               CALL norm                                        
               LD   A,(chr_cnt)                                 
               SUB  1                                           
               LD   B,A                                         
               LD   HL,(spostmp)                                
               LD   (sposn2),HL                                 
clr_lne:       LD   A,32                                        
               CALL pchar2                                      
               DJNZ clr_lne                                     
               CALL inverse                                     
               LD   HL,(memtemp)                                
               LD   A,(chr_cnt)                                 
               LD   B,A                                         
               DEC  B                                           
clr_mem:       LD   (HL),32                                     
               INC  HL                                          
               DJNZ clr_mem                                     
                                                                
                                                                
; word wrap has been done so now justify the line               
                                                                
                                                                
justify:       LD   A,(just_var)                                
               OR   A                                           
               RET  NZ                                          
                                                                
justify_1:     LD   HL,(w_memry)                                
               LD   A,(HL)                                      
               CP   32                                          
               RET  NZ                                          
                                                                
               XOR  A                                           
               LD   (j_count),A                                 
                                                                
j_get_len:     LD   HL,(w_memry)                                
               LD   A,(line_length)                             
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               INC  HL                                          
j_inc_hl:      LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,j_do_sub                                 
               INC  HL                                          
               JR   j_inc_hl                                    
                                                                
j_do_sub:      LD   DE,(w_memry)                                
               EX   DE,HL                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   A,L                                         
               LD   (line_len),A                                
                                                                
; Check line for all spaces.                                    
                                                                
               LD   HL,(w_memry)                                
               LD   A,(line_len)                                
               LD   B,A                                         
j_spce_loop:   LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,j_do_chk                                 
               DEC  HL                                          
               DJNZ j_spce_loop                                 
                                                                
j_do_chk:      CP   32                                          
               RET  Z                                           
                                                                
; Is the line full of characters apart from the last char       
                                                                
               LD   HL,(w_memry)                                
               LD   A,(line_len)                                
               LD   B,A                                         
j_full_line:   DEC  HL                                          
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,j_ok_just                                 
               DJNZ j_full_line                                 
               RET                                              
                                                                
j_ok_just:     LD   B,0                                         
               LD   A,(line_len)                                
               LD   C,A                                         
               LD   HL,(w_memry)                                
j_dec_loop:    DEC  HL                                          
               INC  B                                           
               LD   A,B                                         
               CP   C                                           
               JP   Z,j_do_again                                
               LD   A,(HL)                                      
               CP   32                                          
               JR   Z,j_dec_loop                                
j_dec_2:       DEC  HL                                          
               INC  B                                           
               LD   A,B                                         
               CP   C                                           
               JP   Z,j_do_again                                
               LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,j_dec_2                                  
               PUSH HL                                          
               PUSH BC                                          
               CALL j_push                                      
               LD   HL,(w_memry)                                
               LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,j_finish                                 
               POP  BC                                          
               POP  HL                                          
               JP   j_dec_loop                                  
                                                                
j_finish:      POP  BC                                          
               POP  HL                                          
               JP   j_print_line                                
                                                                
j_push:        LD   C,B                                         
               LD   B,0                                         
               LD   DE,(w_memry)                                
               PUSH DE                                          
               POP  HL                                          
               DEC  HL                                          
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDDR                                             
               LD   A,(j_count)  ; This increments every time   
               INC  A            ; this routine is called       
               LD   (j_count),A                                 
               RET                                              
                                                                
j_do_again:    LD   HL,(w_memry)                                
               LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,j_print_line                             
               LD   A,(j_count)    ; if we come here and j_count
               OR   A              ; is still zero it means that
               JP   Z,j_print_line ; we have counted all the way
               JP   j_ok_just      ; back down the line. so exit
                                                                
                                                                
j_print_line:  CALL norm                                        
               LD   A,(line_length)                             
               ADD  A,A                                         
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,(w_sposn)                                
               OR   A                                           
               SBC  HL,DE                                       
               INC  HL                                          
               INC  HL                                          
               LD   (sposn2),HL                                 
               LD   HL,(w_memry)                                
               LD   A,(line_length)                             
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               INC  HL                                          
               LD   B,E                                         
j_pr_loop:     LD   A,(HL)                                      
               CALL pchar2                                      
               INC  HL                                          
               DJNZ j_pr_loop                                   
               RET                                              
                                                                
                                                                
margin_form:   LD   A,(left_col)                                
               LD   B,A                                         
               LD   A,(col)                                     
               SUB  B                                           
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   (mem_temp),HL                               
               LD   C,0                                         
               CALL check_line                                  
               LD   A,B                                         
               OR   C                                           
               JP   Z,exit_box                                  
                                                                
               LD   HL,BF_buffer                                
mform_loop:    LD   IX,(mem_temp)                               
               LD   A,(line_length)                             
               LD   B,A                                         
mpoke_loop:    LD   A,(IX+0)                                    
               LD   (IX+0),32                                   
               CALL poke_hl                                     
               INC  IX                                          
               INC  HL                                          
               DJNZ mpoke_loop                                  
               LD   A,32                                        
               CALL poke_hl                                     
               INC  HL                                          
               PUSH HL                                          
               LD   HL,(mem_temp)                               
               LD   DE,64                                       
               OR   A                                           
               ADC  HL,DE                                       
               LD   (mem_temp),HL                               
               CALL check_line                                  
               POP  HL                                          
               LD   C,0                                         
               LD   A,B                                         
               OR   C                                           
               JP   NZ,mform_loop                               
               LD   A,255                                       
               CALL poke_hl                                     
               LD   A,1                                         
               LD   (buff_flag),A                               
               CALL norm                                        
               CALL reprint_screen                              
               CALL reclaim_para                                
               CALL norm                                        
               JP   reprint_screen                              
                                                                
                                                                
                                                                
check_line:    LD   A,(line_length)                             
               LD   B,A                                         
mchk_loop:     LD   A,(HL)                                      
               CP   32                                          
               RET  NZ                                          
               INC  HL                                          
               DJNZ mchk_loop                                   
               RET                                              
                                                                
                                                                
; Main format routine to take a paragraph and expand it or      
; compress it....                                               
                                                                
format_para:   LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   B,64                                        
chk_lp:        LD   A,(HL)                                      
               CP   255                                         
               JP   Z,exit_box                                  
               CP   32                                          
               JP   NZ,next_job                                 
               INC  HL                                          
               DJNZ chk_lp                                      
               CALL exit_box                                    
               JP   enter                                       
                                                                
next_job:      XOR  A                                           
               LD   (open_flag),A                               
               CALL strtln                                      
               CALL back_line                                   
find_64_32s:   LD   HL,(memry)                                  
               LD   DE,64                                       
find_64_loop:  ADD  HL,DE                                       
               LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,find_64_loop                             
               PUSH HL                                          
               POP  IX                                          
               LD   B,63                                        
f_64_loop:     INC  IX                                          
               LD   A,(IX+0)                                    
               CP   32                                          
               JR   NZ,find_64_loop                             
               DJNZ f_64_loop                                   
               INC  IX                                          
               LD   (re_form_temp),IX                           
loop_64:       DEC  HL                                          
               LD   A,(HL)                                      
               CP   32                                          
               JR   Z,loop_64                                   
               LD   DE,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               INC  HL                                          
               LD   (f_len_var),HL                              
               PUSH HL                                          
               POP  BC                                          
               EX   DE,HL                                       
               LD   HL,BF_buf_len                               
               OR   A                                           
               SBC  HL,DE                                       
               JP   Z,exit_box                                  
               JP   C,exit_box                                  
               XOR  A                                           
               DEC  A                                           
               LD   (ed_var),A                                  
               LD   (var),A                                     
               LD   HL,(re_form_temp)                           
               LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,cont_form                                
               LD   (HL),0                                      
cont_form:     LD   HL,BF_buffer                                
               LD   IX,(memry)                                  
               LD   DE,(f_len_var)                              
               LD   B,0                                         
transfer:      LD   A,(IX+0)                                    
               CALL poke_hl                                     
               INC  B                                           
               LD   A,B                                         
               CP   64                                          
               JP   Z,check_2_bytes                             
trans_loop:    DEC  DE                                          
               LD   A,D                                         
               OR   E                                           
               JP   Z,trans_fin                                 
               INC  HL                                          
               INC  IX                                          
               JP   transfer                                    
                                                                
check_2_bytes: LD   B,0                                         
               LD   A,(IX+0)                                    
               CP   32                                          
               JP   Z,trans_loop                                
               LD   A,(IX+1)                                    
               CP   32                                          
               JP   Z,trans_loop                                
               INC  HL                                          
               LD   A,32                                        
               CALL poke_hl                                     
               JP   trans_loop                                  
                                                                
trans_fin:     INC  HL                                          
               LD   A,255                                       
               CALL poke_hl                                     
               LD   HL,(memry)                                  
               LD   BC,(f_len_var)                              
               INC  BC                                          
clear_para:    LD   (HL),32                                     
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,clear_para                               
               CALL store_insert                                
                                                                
                                                                
; reprint the screen.The paragraph has been buffered and removed
; from memory so reprint the screen will print spaces over the  
; top of the paragraph thus clearing it ready for the reformed  
; paragraph to be printed.                                      
                                                                
                                                                
               LD   A,1            ; signal a paragraph is in   
               LD   (buff_flag),A  ; the buffer..               
               CALL exit_box                                    
get_marg:      CALL goto_margin                                 
                                                                
               LD   HL,BF_buffer                                
out_loop:      CALL peek_hl                                     
               CP   255                                         
               JP   Z,done_all                                  
               CP   32                                          
               JP   Z,got_a_space                               
               CALL out_it                                      
               INC  HL                                          
               JP   out_loop                                    
                                                                
                                                                
got_a_space:   CALL out_it                                      
space_loop:    INC  HL                                          
               CALL peek_hl                                     
               CP   255                                         
               JP   Z,done_all                                  
               CP   32                                          
               JR   Z,space_loop                                
               JP   out_loop                                    
                                                                
out_it:        BIT  7,A                                         
               JR   Z,out_it_2                                  
               PUSH AF                                          
               LD   A,255                                       
               LD   (pflag),A                                   
               POP  AF                                          
               RES  7,A                                         
                                                                
out_it_2:      PUSH DE                                          
               PUSH HL                                          
               LD   (chr_buf),A                                 
               CALL pchar           ; print the char on screen  
                                                                
               LD   A,(right_col)                               
               LD   B,A                                         
               LD   A,(col)                                     
               CP   B                                           
               CALL Z,out_ins                                   
               CALL word_wrap       ; word wrap if needed       
               POP  HL                                          
               POP  DE                                          
               RET                                              
                                                                
open_fle2:     CP   0                                           
               RET  Z                                           
               LD   A,1                                         
               LD   (open_flag),A                               
               CALL open_fl2                                    
               RET                                              
                                                                
out_ins:       LD   HL,(memry)                                  
               LD   A,(pad_numr)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               LD   B,64                                        
o_ins_loop:    LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,got_32                                   
               INC  HL                                          
               DJNZ o_ins_loop                                  
               JP   only_zero                                   
                                                                
                                                                
got_32:        LD   A,1                                         
               LD   (open_flag),A                               
               CALL open_fl2                                    
only_zero:     LD   HL,(memry)                                  
               LD   A,(pad_numr)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               RET                                              
                                                                
                                                                
done_all:      LD   HL,(sposn)                                  
               LD   (sposn2),HL                                 
               CALL norm                                        
               LD   HL,(memry)                                  
dun_all:       LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,done_all_3                               
               LD   A,32                                        
               CALL pchar2_2                                    
               PUSH HL                                          
               LD   HL,(sposn2)                                 
               EX   DE,HL                                       
               LD   HL,56449                                    
               OR   A                                           
               SBC  HL,DE                                       
               POP  HL                                          
               JP   Z,done_all_3                                
               JP   C,done_all_3                                
               INC  HL                                          
               JP   dun_all                                     
                                                                
done_all_3:    CALL clear_c_chars                               
                                                                
               CALL enter                                       
               CALL enter                                       
               LD   A,(open_flag)                               
               OR   A                                           
               JP   NZ,end_format                               
               LD   HL,(memry)                                  
               LD   DE,(memtop)                                 
               OR   A                                           
               SBC  HL,DE                                       
               JP   NC,end_format                               
               LD   B,64                                        
               LD   HL,(memry)                                  
upp_lp:        LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,end_format                               
               INC  HL                                          
               DJNZ upp_lp                                      
               CALL close_file                                  
               LD   B,64                                        
               LD   HL,(memry)                                  
               JP   upp_lp                                      
                                                                
end_format:    LD   HL,file_st                                  
               LD   BC,45000                                    
zero_loop:     LD   A,(HL)                                      
               CP   0                                           
               JP   Z,found_zero                                
               CP   255                                         
               JP   Z,no_zero_found                             
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   Z,no_zero_found                             
               JR   zero_loop                                   
found_zero:    LD   (HL),32                                     
no_zero_found: CALL up                                          
               CALL up                                          
               CALL endlne                                      
lef_loop:      LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,end_format2                              
               CALL left                                        
               JR   lef_loop                                    
                                                                
end_format2:   CALL right                                       
               LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
               CALL clear_c_chars                               
               CALL enter                                       
               CALL strtln                                      
               LD   B,64                                        
               LD   HL,(memry)                                  
full_line:     LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,open_f_le                                
               INC  HL                                          
               DJNZ full_line                                   
exit_form:     CALL goto_margin                                 
               CALL unstr_insert                                
                                                                
               CALL exit_box                                    
               RET                                              
                                                                
open_f_le:     CALL open_file                                   
               JP   exit_form                                   
                                                                
                                                                
; print the drop down menu on the screen                        
                                                                
                                                                
print_menu:    PUSH HL                                          
               PUSH BC                                          
               CALL inverse                                     
               POP  BC                                          
               POP  HL                                          
               CALL pr_menu                                     
               JP   norm                                        
                                                                
                                                                
pr_menu:       LD   (sposn2),HL                                 
               LD   (sposn3),HL                                 
menu_loop:     LD   A,(DE)                                      
               CP   255                                         
               RET  Z                                           
               CP   13                                          
               JP   Z,inc_scrn                                  
               CP   "!"                                         
               JP   Z,prnt_x_chars                              
               PUSH DE                                          
               CALL pchar2_2                                    
               POP  DE                                          
               INC  DE                                          
               JR   menu_loop                                   
                                                                
                                                                
prnt_x_chars:  INC  DE                                          
               LD   A,(DE) ; get amount of characters to print  
               LD   B,A    ; into 'B'                           
               INC  DE     ; de points a character to print.    
               PUSH DE     ; save pointer while printing        
               LD   A,(DE) ; get character into 'A' reg         
prnt_char:     PUSH AF                                          
               CALL pchar2_2                                    
               POP  AF                                          
               DJNZ prnt_char                                   
               POP  DE                                          
               INC  DE                                          
               JP   menu_loop                                   
                                                                
inc_scrn:      LD   HL,(sposn3)                                 
               LD   A,4                                         
               ADD  A,H                                         
               LD   H,A                                         
               INC  DE                                          
               JP   pr_menu                                     
                                                                
                                                                
                                                                
; highlight bar control code                                    
                                                                
                                                                
do_op_bar:     CALL screen_in                                   
               PUSH BC                                          
               LD   B,8                                         
long_loop:     LD   A,(bar_length)                              
               LD   C,A                                         
long_loop1:    LD   A,(HL)                                      
               XOR  255                                         
               LD   (HL),A                                      
               INC  HL                                          
               DEC  C                                           
               LD   A,C                                         
               OR   A                                           
               JR   NZ,long_loop1                               
               LD   A,(bar_jump)                                
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               DJNZ long_loop                                   
               POP  BC                                          
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
next_option:   DEC  C                                           
               LD   A,C                                         
               OR   A                                           
               JP   Z,ret_to_men                                
               LD   HL,(sposn2)                                 
               CALL do_op_bar                                   
               LD   HL,(sposn2)                                 
               LD   DE,1024                                     
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sposn2),HL                                 
               CALL do_op_bar                                   
               RET                                              
                                                                
                                                                
ret_to_men:    POP  DE                                          
               LD   A,(what_menu)                               
               CP   1                                           
               JP   Z,menu1                                     
               CP   2                                           
               JP   Z,menu2                                     
               CP   3                                           
               JP   Z,menu3                                     
               CP   4                                           
               JP   Z,menu4                                     
               CP   5                                           
               JP   Z,blocks                                    
               CP   6                                           
               JP   Z,opt_2                                     
               CP   7                                           
               JP   Z,font_menu                                 
               CP   8                                           
               JP   Z,text_map                                  
               JP   menu1                                       
                                                                
                                                                
prev_option:   INC  C                                           
               LD   A,(op_len_var)                              
               INC  A                                           
               CP   C                                           
               JP   Z,ret_to_men                                
               LD   HL,(sposn2)                                 
               CALL do_op_bar                                   
               LD   HL,(sposn2)                                 
               LD   DE,1024                                     
               OR   A                                           
               SBC  HL,DE                                       
               LD   (sposn2),HL                                 
               CALL do_op_bar                                   
               RET                                              
                                                                
                                                                
check_c:       LD   A,C                                         
               DEC  A                                           
               RL   A                                           
               LD   E,A                                         
               LD   D,0                                         
               ADD  HL,DE                                       
               LD   A,(HL)                                      
               LD   E,A                                         
               INC  HL                                          
               LD   A,(HL)                                      
               LD   D,A                                         
               PUSH DE                                          
               RET                                              
                                                                
                                                                
; main menu selected on entry from the editor                   
                                                                
; Check to see if any blocks are set, if so go to the blocks    
; menu and no other.                                            
                                                                
menu_1:        CALL sound2                                      
               LD   A,1                                         
               LD   (crsr_flag),A                               
               LD   A,30                                        
               LD   (bar_length),A                              
               LD   A,98                                        
               LD   (bar_jump),A                                
               LD   A,(block_var)                               
               CP   255                                         
               JP   Z,blocks                                    
               JP   menu1                                       
                                                                
get_op_len:    LD   (op_len_var),A                              
               LD   C,A                                         
               LD   (sposn2),HL                                 
               LD   A,B                                         
               LD   (what_menu),A                               
               JP   do_op_bar                                   
                                                                
                                                                
menu_4:        CALL sound2                                      
               LD   A,1                                         
               LD   (crsr_flag),A                               
               LD   A,30                                        
               LD   (bar_length),A                              
               LD   A,98                                        
               LD   (bar_jump),A                                
               LD   A,(block_var)                               
               CP   255                                         
               JP   Z,blocks                                    
               JP   menu4                                       
                                                                
menu1:         LD   HL,36864+526 ; screen position              
               LD   DE,menu1_dat                                
               CALL print_menu                                  
               LD   A,(m1_len)                                  
               LD   HL,38417                                    
               LD   B,1                                         
               CALL get_op_len                                  
                                                                
men1_loop:     CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,data_m1                                  
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
               CP   32                                          
               JP   Z,set_time                                  
                                                                
               CP   10          ;    cursor down                
               JP   NZ,chec_up                                  
               CALL next_option                                 
               JR   men1_loop                                   
                                                                
                                                                
                                                                
chec_up:       CP   11                                          
               JP   NZ,chec_edit                                
               CALL prev_option                                 
               JR   men1_loop                                   
                                                                
chec_edit:     CP   7             ; edit key                    
               JP   Z,menu2                                     
               CP   8                                           
               JP   Z,large_map                                 
               CP   "1"                                         
               JP   Z,FILE1                                     
               CP   "2"                                         
               JP   Z,FILE2                                     
               CP   "3"                                         
               JP   Z,FILE3                                     
               RES  5,A                                         
               CP   "A"                                         
               JP   Z,auto_margin                               
               CP   "B"                                         
               JP   Z,bot_fl                                    
               CP   "C"                                         
               JP   Z,full_screen                               
               CP   "F"                                         
               JP   Z,format_para                               
               CP   "H"                                         
               JP   Z,hide                                      
               CP   "L"                                         
               JP   Z,s_left                                    
               CP   "M"                                         
               JP   Z,margin_form                               
               CP   "P"                                         
               JP   Z,reclaim_para                              
               CP   "R"                                         
               JP   Z,s_right                                   
               CP   "T"                                         
               JP   Z,top_fle                                   
               CP   "O"                                         
               JP   Z,options                                   
               CP   "G"                                         
               JP   Z,reprint_block                             
               CP   "X"                                         
               JP   Z,cont_code                                 
               CP   199              ; F7                       
               JP   Z,set_strt       ; block start              
               JP   men1_loop                                   
                                                                
                                                                
menu2:         LD   HL,37888+529  ; screen position             
               LD   DE,menu2_data                               
               CALL print_menu                                  
               LD   A,(m2_len)                                  
               LD   HL,39444                                    
               LD   B,2                                         
               CALL get_op_len                                  
                                                                
men2_loop:     CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,data_m2                                  
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
                                                                
               CP   10                                          
               JP   NZ,chec_up2                                 
               CALL next_option                                 
               JR   men2_loop                                   
                                                                
chec_up2:      CP   11                                          
               JP   NZ,chec_inv                                 
               CALL prev_option                                 
               JR   men2_loop                                   
                                                                
chec_inv:      CP   253            ; inv key                    
               JP   Z,menu1                                     
               CP   7              ; edit key                   
               JP   Z,menu3                                     
               RES  5,A            ; make sure upper case check 
               CP   "S"                                         
               JP   Z,save_file                                 
               CP   "P"                                         
               JP   Z,printer                                   
               CP   "D"                                         
               JP   Z,dir                                       
               CP   "H"                                         
               JP   Z,hide                                      
               CP   "L"                                         
               JP   Z,load_file                                 
               CP   "C"                                         
               JP   Z,cleer_file                                
               CP   "M"                                         
               JP   Z,merge                                     
               CP   "F"                                         
               JP   Z,font_menu                                 
               CP   "V"                                         
               JP   Z,get_file_name                             
               CP   "E"                                         
               JP   Z,erase_a_file                              
               CP   "T"                                         
               JP   Z,text_map                                  
               JP   men2_loop                                   
                                                                
; do menu 3                                                     
                                                                
                                                                
menu3:         LD   HL,38912+532  ; screen position             
               LD   DE,menu3_data                               
               CALL print_menu                                  
               LD   A,(m3_len)                                  
               LD   HL,40471                                    
               LD   B,3                                         
               CALL get_op_len                                  
                                                                
men3_loop:     CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,data_m3                                  
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
                                                                
               CP   10                                          
               JP   NZ,chec_up3                                 
               CALL next_option                                 
               JR   men3_loop                                   
                                                                
chec_up3:      CP   11                                          
               JR   NZ,edit_3                                   
               CALL prev_option                                 
               JR   men3_loop                                   
                                                                
edit_3:        CP   7              ; edit key                   
               JP   Z,menu4                                     
               CP   253            ; inv key                    
               JP   Z,menu2                                     
               RES  5,A                                         
               CP   "B"                                         
               JP   Z,tog_clock                                 
               CP   "C"                                         
               JP   Z,chng_colour                               
               CP   "D"                                         
               JP   Z,dump_cd                                   
               CP   "H"                                         
               JP   Z,hide                                      
               CP   "I"                                         
               JP   Z,tog_ins                                   
               CP   "J"                                         
               JP   Z,tog_just                                  
               CP   "S"                                         
               JP   Z,speed_read                                
               CP   "N"                                         
               JP   Z,beep_tog                                  
               CP   "V"                                         
               JP   Z,view_codes                                
               CP   "T"                                         
               JP   Z,set_tabs                                  
               CP   "P"                                         
               JP   Z,d_install                                 
               CP   "W"                                         
               JP   Z,wr_tog                                    
               JP   men3_loop                                   
                                                                
                                                                
menu4:         LD   HL,39936+535  ; screen position             
               LD   DE,menu4_data                               
               CALL print_menu                                  
                                                                
               LD   A,(m4_len)                                  
               LD   HL,41498                                    
               LD   B,4                                         
               CALL get_op_len                                  
                                                                
menu4_loop:    CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,data_m4                                  
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
                                                                
               CP   10                                          
               JR   NZ,chec_up4                                 
               CALL next_option                                 
               JR   menu4_loop                                  
                                                                
chec_up4:      CP   11                                          
               JP   NZ,edit_4                                   
               CALL prev_option                                 
               JR   menu4_loop                                  
                                                                
edit_4:        CP   253                                         
               JP   Z,menu3                                     
               CP   "1"                                         
               JP   Z,info1                                     
               CP   "2"                                         
               JP   Z,info2                                     
               CP   "3"                                         
               JP   Z,info3                                     
               RES  5,A                                         
               CP   "Z"                                         
               JP   Z,ant                                       
               CP   "D"                                         
               JP   Z,date                                      
               CP   "H"                                         
               JP   Z,hide                                      
               CP   "S"                                         
               JP   Z,search_input                              
               CP   "C"                                         
               JP   Z,con_search                                
               CP   "B"                                         
               JP   Z,box_chars                                 
               CP   "V"                                         
               JP   Z,dict                                      
               CP   "N"                                         
               JP   Z,normal_chars                              
               CP   "L"                                         
               JP   Z,spell_chk                                 
               CP   "A"                                         
               JP   Z,address                                   
               JR   menu4_loop                                  
                                                                
; blocks menu                                                   
                                                                
                                                                
blocks:        LD   HL,38400+9     ; 38400+9   print address    
               LD   DE,block_dat                                
               CALL print_menu                                  
                                                                
               LD   A,(m5_len)                                  
               LD   HL,39436                                    
               LD   B,5                                         
               CALL get_op_len                                  
                                                                
block_loop:    CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,data_m5                                  
               LD   B,5                                         
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
                                                                
               CP   10                                          
               JP   NZ,chec_up5                                 
               CALL next_option                                 
               JR   block_loop                                  
                                                                
chec_up5:      CP   11                                          
               JR   NZ,edit_5                                   
               CALL prev_option                                 
               JR   block_loop                                  
                                                                
edit_5:        CP   199                                         
               JP   Z,set_end                                   
                                                                
               RES  5,A                                         
               CP   "S"                                         
               JP   Z,save_block                                
               CP   "P"                                         
               JP   Z,printer                                   
               CP   "D"                                         
               JP   Z,delete_blocks   ; DELETE MARKERS          
               CP   "C"                                         
               JP   Z,copy_block                                
               CP   "B"                                         
               JP   Z,bot_fl                                    
               CP   "T"                                         
               JP   Z,top_fle                                   
               CP   "E"                                         
               JP   Z,erase_block                               
               CP   "G"                                         
               JP   Z,grab_block                                
               CP   "M"                                         
               JP   Z,move_block                                
               JR   block_loop                                  
                                                                
                                                                
                                                                
; this is the error and message box routine                     
                                                                
                                                                
draw_box:      LD   A,1                                         
               LD   (crsr_flag),A                               
               LD   HL,36876+512 ; print address                
               LD   DE,box_data                                 
               CALL print_menu                                  
reprint_mes:   CALL inverse                                     
               LD   HL,37904+512                                
               LD   (sposn2),HL                                 
               RET                                              
                                                                
                                                                
                                                                
; come here when coming back from basic after having input      
; the word to search for. Make sure that all letters in the     
; search buffer are lower case                                  
                                                                
                                                                
search_rtn:    LD   HL,sbuffer                                  
s_rtn_loop:    LD   A,(HL)                                      
               CP   32                                          
               JP   Z,con_search                                
               SET  5,A                                         
               LD   (HL),A                                      
               INC  HL                                          
               JR   s_rtn_loop                                  
                                                                
                                                                
; come here from search_rtn and also from menu 4 to do the      
; search proper.....                                            
                                                                
                                                                
con_search:    CALL exit_box                                    
               CALL clear_margins                               
               CALL strtln                                      
search_2:      LD   A,(pyge)                                    
               LD   (t_pyge),A                                  
               LD   A,(lline)                                   
               LD   (t_lline),A                                 
               LD   HL,(total)                                  
               LD   (t_total),HL                                
               LD   DE,(memry)                                  
               LD   A,(DE)                                      
               CP   255                                         
               JP   Z,not_found                                 
re_init_b:     LD   B,65           ; 64 cols                    
srch_2a:       DEC  B                                           
               LD   A,B                                         
               CP   255                                         
               JP   Z,re_init_b                                 
               OR   A                                           
               JP   NZ,srch_2                                   
               CALL incln                                       
               LD   B,64                                        
                                                                
srch_2:        LD   HL,sbuffer                                  
srch_3:        LD   A,(DE)                                      
                                                                
               SET  5,A                                         
               CP   (HL)                                        
               JP   Z,got_char                                  
               LD   A,(DE)                                      
               CP   255                                         
               JP   Z,not_found                                 
               INC  DE                                          
               DJNZ srch_3                                      
               CALL incln                                       
               LD   B,64                                        
               JP   srch_2                                      
                                                                
got_char:      INC  HL                                          
                                                                
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,got_word                                  
               INC  DE                                          
               LD   A,(DE)                                      
               CP   255                                         
               JP   Z,not_found                                 
                                                                
               SET  5,A                                         
               CP   (HL)                                        
               JP   NZ,srch_2a                                  
               DJNZ got_char                                    
               CALL incln                                       
               LD   B,64                                        
               JP   srch_2                                      
                                                                
                                                                
got_word:      LD   A,64                                        
               SUB  B                                           
               EX   DE,HL                                       
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               LD   L,3                                         
               LD   H,0                                         
               CALL stcur                                       
               CALL exit_box                                    
               CALL update                                      
               CALL draw_box                                    
               LD   B,47                                        
               CALL prstr                                       
srch_key:      CALL rd_key                                      
               CP   13                                          
               JP   Z,exit_search                               
               RES  5,A                                         
               CP   "N"                                         
               JP   NZ,srch_key                                 
               CALL down1                                       
               JP   search_2                                    
                                                                
                                                                
not_found:     CALL draw_box                                    
               LD   B,45                                        
               CALL press_ret                                   
               LD   A,(t_pyge)                                  
               LD   (pyge),A                                    
               LD   A,(t_lline)                                 
               LD   (lline),A                                   
               LD   HL,(t_total)                                
               LD   (total),HL                                  
exit_search:   CALL reset_margins                               
               CALL goto_margin                                 
               JP   exit_box                                    
                                                                
                                                                
; Hide the file from nosey over the shoulder people             
; do it by adding 5 to every character in the file. leave       
; the end marker as 255                                         
                                                                
                                                                
hide:          LD   A,(hide_var)                                
               OR   A                                           
               JP   NZ,unhide_file                              
                                                                
; Clear the screen as a first priority then scramble the file   
                                                                
                                                                
hide_file:     CALL screen_in                                   
               LD   HL,34816                                    
               LD   DE,34817                                    
               LD   BC,22528                                    
               LD   (HL),0                                      
               LDIR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               LD   HL,file_st                                  
hide_loop:     LD   A,(HL)                                      
               CP   255                                         
               JP   Z,hide_fin                                  
               CP   32                                          
               JP   Z,jp_a_space                                
               ADD  A,5                                         
               LD   (HL),A                                      
jp_a_space:    INC  HL                                          
               JR   hide_loop                                   
                                                                
                                                                
unhide_file:   LD   HL,file_st                                  
unhide_loop:   LD   A,(HL)                                      
               CP   255                                         
               JP   Z,unhide_fin                                
               CP   32                                          
               JP   Z,jp_space                                  
               SUB  5                                           
               LD   (HL),A                                      
jp_space:      INC  HL                                          
               JR   unhide_loop                                 
                                                                
unhide_fin:    XOR  A                                           
hide_fin:      LD   (hide_var),A                                
               JP   exit_box                                    
                                                                
                                                                
dump_cd:       CALL strtln                                      
               LD   HL,(memry)                                  
               LD   (merge_var),HL                              
               CALL goto_margin                                 
               LD   A,"P"                                       
               JP   save_merge                                  
                                                                
                                                                
cleer_file:    CALL reprint_screen                              
               JP   clr_fle                                     
                                                                
exit_menu:     CALL reprint_screen                              
               RET                                              
                                                                
                                                                
; take paragraph that is still in the buffer and put it on the  
; screen between the margins if set...                          
                                                                
no_para:       CALL exit_box                                    
               CALL draw_box                                    
               LD   B,25                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
reclaim_para:  CALL strtln                                      
               CALL goto_margin                                 
               CALL exit_box                                    
               LD   A,(buff_flag)                               
               CP   1                                           
               JP   NZ,no_para                                  
               CALL store_insert                                
               LD   HL,BF_buffer                                
claim_loop:    CALL peek_hl                                     
               CP   255                                         
               JP   Z,fini_reclaim                              
               CP   32                                          
               JP   Z,got_spce                                  
               CALL out_buf                                     
               INC  HL                                          
               JP   claim_loop                                  
                                                                
got_spce:      CALL out_buf                                     
g_space_loop:  INC  HL                                          
               CALL peek_hl                                     
               CP   255                                         
               JP   Z,fini_reclaim                              
               CP   32                                          
               JR   Z,g_space_loop                              
               JP   claim_loop                                  
                                                                
out_buf:       BIT  7,A                                         
               JR   Z,out_buf_2                                 
               PUSH AF                                          
               LD   A,255                                       
               LD   (pflag),A                                   
               POP  AF                                          
               RES  7,A                                         
                                                                
out_buf_2:     PUSH DE                                          
               PUSH HL                                          
               CALL pchar                                       
               CALL word_wrap                                   
               POP  HL                                          
               POP  DE                                          
               RET                                              
                                                                
fini_reclaim:  CALL clear_c_chars                               
               LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
               CALL unstr_insert                                
               RET                                              
                                                                
                                                                
poke_hl:       PUSH AF        ; page in the buffer and poke     
               LD   A,BUFFERP ; character in the 'A' register   
               OUT  (251),A   ; into address held in HL         
               POP  AF                                          
               LD   (HL),A    ; Buffer uses page 11             
               LD   A,(text_page) ; Text file is in page 5 or 7 
               OUT  (251),A                                     
               RET                                              
                                                                
peek_hl:       LD   A,BUFFERP  ; page in the buffer and load    
               OUT  (251),A    ; 'A' with the character held    
               LD   A,(HL)     ; in HL                          
               PUSH AF                                          
               LD   A,(text_page)                               
               OUT  (251),A                                     
               POP  AF                                          
               RET                                              
                                                                
                                                                
justify_one:   CALL store_insert                                
               CALL justify_wun                                 
               PUSH AF                                          
               CALL unstr_insert                                
               POP  AF                                          
               RET                                              
                                                                
                                                                
justify_wun:   CALL strtln                                      
               CALL goto_margin                                 
               LD   A,(line_length)                             
               LD   B,A                                         
               LD   HL,(memry)                                  
wun_loop:      LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,chk_over                                 
               INC  HL                                          
               DJNZ wun_loop                                    
               RET                                              
chk_over:      LD   A,(line_length)                             
               LD   B,A                                         
               LD   HL,(memry)                                  
one_just:      LD   A,(HL)                                      
               CP   255                                         
               RET  Z                                           
               PUSH BC                                          
               PUSH HL                                          
               CALL right_1                                     
               POP  HL                                          
               POP  BC                                          
               INC  HL                                          
               DJNZ one_just                                    
               LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
               CALL justify_1                                   
               RET                                              
                                                                
                                                                
; Justify a complete paragraph. Exit if 'A' = 32 or 255         
; 255 = end marker.                                             
                                                                
                                                                
justify_para:  CALL justify_one                                 
               CP   32                                          
               RET  Z                                           
               CP   255                                         
               RET  Z                                           
               JP   justify_para                                
                                                                
                                                                
                                                                
                                                                
; Unjustify the line within the margins only. Just exit if the  
; line is full of spaces or if the end marker is on the line.   
                                                                
                                                                
unjustify:     CALL strtln       ; put cursor on col 0          
               CALL goto_margin  ; move forward to margin if set
                                                                
; is the line full of spaces. if so just exit. else goto        
; next test to check for end marker.                            
                                                                
               LD   HL,(memry)                                  
               LD   A,(line_length)                             
               LD   B,A                                         
un_j_loop:     LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,nx_test                                  
               INC  HL                                          
               DJNZ un_j_loop                                   
               RET                                              
                                                                
; is the end marker on the line. if so just exit                
                                                                
nx_test:       LD   HL,(memry)                                  
               LD   A,(line_length)                             
               INC  A                                           
               LD   B,A                                         
find_255:      LD   A,(HL)                                      
               CP   255         ; end marker                    
               RET  Z                                           
               INC  HL                                          
               DJNZ find_255                                    
               CALL back_line                                   
               CALL initbuf                                     
               LD   C,0                                         
               LD   HL,(memry)                                  
               LD   DE,buffer                                   
unjust_loop:   LD   A,(HL)                                      
               CP   32                                          
               JP   Z,fnd_nxt_char                              
un_loop_2:     LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               INC  C                                           
               LD   A,(line_length)                             
               CP   C                                           
               JP   Z,fin_unjust                                
               JP   unjust_loop                                 
                                                                
fnd_nxt_char:  LD   (DE),A                                      
               INC  DE                                          
find_loop:     INC  HL                                          
               INC  C                                           
               LD   A,(line_length)                             
               CP   C                                           
               JP   Z,fin_unjust                                
               LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,un_loop_2                                
               JP   find_loop                                   
                                                                
fin_unjust:    LD   HL,buffer                                   
               LD   DE,(memry)                                  
               LD   A,(line_length)                             
               LD   C,A                                         
               LD   B,0                                         
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               LD   HL,(sposn)                                  
               LD   DE,(memry)                                  
               LD   A,(line_length)                             
               LD   B,A                                         
               CALL prtline                                     
               CALL store_insert                                
               CALL enter                                       
               JP   unstr_insert                                
                                                                
back_line:     LD   HL,(memry)                                  
               LD   A,(line_length)                             
               LD   B,A                                         
back_loop:     LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,pull                                     
               INC  HL                                          
               DJNZ back_loop                                   
               RET                                              
                                                                
store_insert:  LD   A,(ins_flg)                                 
               LD   (tins_flg),A                                
               XOR  A                                           
               LD   (ins_flg),A                                 
               RET                                              
                                                                
unstr_insert:  LD   A,(tins_flg)                                
               LD   (ins_flg),A                                 
               RET                                              
                                                                
pull:          LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   32                                          
               RET  NZ                                          
               PUSH HL                                          
               CALL pulline                                     
               POP  HL                                          
               JP   pull                                        
                                                                
bottom:        LD   HL,file_st                                  
               LD   A,(HL)                                      
               CP   255                                         
               RET  Z                                           
               CALL cls                                         
               CALL setop                                       
               LD   A,1                                         
               LD   (lline),A                                   
               LD   A,(page_start)                              
               LD   (pyge),A                                    
               LD   HL,1                                        
               LD   (total),HL                                  
               CALL clear_margins                               
               LD   HL,file_st                                  
bloop:         LD   B,64                                        
               PUSH HL                                          
botlop:        LD   A,(HL)                                      
               CP   255                                         
               JR   Z,prtit                                     
               INC  HL                                          
               DJNZ botlop                                      
               CALL incln                                       
               POP  DE                                          
               JR   bloop                                       
                                                                
prtit:         POP  HL                                          
               LD   (memry),HL                                  
ptit:          LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   255                                         
               JR   Z,endit                                     
               LD   (chr_buf),A                                 
               CALL check_bit_7                                 
               JR   ptit                                        
                                                                
endit:         LD   A,0                                         
               LD   (sc_cnt),A                                  
               LD   B,10                                        
goup:          PUSH BC                                          
               CALL up                                          
               POP  BC                                          
               DJNZ goup                                        
               LD   A,(sc_cnt)                                  
               OR   A                                           
               JP   Z,reset_margins                             
               LD   B,A                                         
godown:        PUSH BC                                          
               CALL down                                        
               POP  BC                                          
               DJNZ godown                                      
               CALL reset_margins                               
               JP   enter                                       
                                                                
check_bit_7:   BIT  7,A                                         
               JP   NZ,print_c_char                             
               JP   poke                                        
                                                                
cls:           CALL screen_in                                   
               LD   HL,34816                                    
               LD   DE,34817                                    
               LD   BC,22528                                    
               LD   (HL),0                                      
               LDIR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
setop:         LD   L,3                                         
               LD   H,0                                         
               JP   stcur                                       
                                                                
                                                                
wr_tog:        CALL exit_box                                    
               LD   A,(wrap)                                    
               XOR  255                                         
               LD   (wrap),A                                    
check_wrap:    LD   HL,33853                                    
               LD   (sposn2),HL                                 
               CALL inverse                                     
               LD   A,(wrap)                                    
               LD   B,14                                        
               OR   A                                           
               JP   Z,prstr                                     
               LD   B,15                                        
               JP   prstr                                       
                                                                
tog_ins:       CALL exit_box                                    
               LD   A,(ins_flg)                                 
               XOR  255                                         
               LD   (ins_flg),A                                 
check_ins:     LD   HL,33842                                    
               LD   (sposn2),HL                                 
               CALL inverse                                     
               LD   B,31                                        
               LD   A,(ins_flg)                                 
               OR   A                                           
               JP   Z,prstr                                     
               LD   B,32                                        
               JP   prstr                                       
                                                                
tog_just:      CALL exit_box                                    
               LD   A,(just_var)                                
               XOR  255                                         
               LD   (just_var),A                                
check_just:    LD   HL,33873                                    
               LD   (sposn2),HL                                 
               CALL inverse                                     
               LD   A,(just_var)                                
               LD   B,19                                        
               OR   A                                           
               JP   Z,prstr                                     
               LD   B,20                                        
               JP   prstr                                       
                                                                
                                                                
tog_clock:     CALL exit_box                                    
               LD   A,(clock_var)                               
               XOR  255                                         
               LD   (clock_var),A                               
               RET                                              
                                                                
                                                                
prstr:         DI                                               
               LD   C,0                                         
               LD   HL,string_data                              
str_loop:      LD   A,(HL)                                      
               INC  HL                                          
               CP   255                                         
               JR   NZ,str_loop                                 
               INC  C                                           
               LD   A,B                                         
               CP   C                                           
               JR   NZ,str_loop                                 
                                                                
prstr_2:       LD   A,(HL)                                      
               CP   255                                         
               JP   Z,enable                                    
               CALL pchar2                                      
               INC  HL                                          
               JR   prstr_2                                     
                                                                
enable:        EI                                               
               RET                                              
                                                                
                                                                
; take the line from the text editor and use it for the         
; tab settings. any non space char is a tab position.           
                                                                
set_tabs:      CALL reprint_screen                              
               CALL unlock_rom                                  
               LD   A,(col)                                     
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,(memry)                                  
               OR   A                                           
               SBC  HL,DE                                       
               LD   DE,tab_dat                                  
               LD   BC,63                                       
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               CALL lock_rom                                    
               RET                                              
                                                                
; Jump to the next tab position                                 
                                                                
                                                                
tab:           LD   A,(col)          ; is the cursor at the     
               LD   B,A              ; rightmost col            
               LD   A,(right_col)                               
               CP   B                                           
               RET  Z                ; return if it is          
                                                                
                                                                
; increment in until tab_data = the cursor position             
                                                                
                                                                
               LD   B,0              ; initialise counter       
               LD   DE,tab_dat       ; point to tab data        
tab_loop:      LD   A,(col)          ; are we at the col        
               CP   B                                           
               JP   Z,got_col        ; jump if matched          
               INC  DE               ; increment tab_data       
               INC  B                ; increment counter        
               JR   tab_loop         ; keep looping             
                                                                
                                                                
got_col:       LD   HL,(memry)       ; is the current position  
               LD   A,(DE)           ; a tab position           
               CP   32                                          
               JR   Z,not_tab_pos    ; if not then jump         
               INC  DE               ; else increment all       
               INC  B                ; pointers to next crsr pos
               INC  HL                                          
not_tab_pos:   LD   C,B              ; initialise c to = cursor 
               LD   B,0              ; position                 
got_loop:      LD   A,(right_col)    ; have we got to right yet 
               CP   C                                           
               RET  Z                ; exit if so               
               LD   A,(DE)           ; else check for a non     
               CP   32               ; space character and jump 
               JR   NZ,set_the_pos   ; to set the position when 
               INC  HL               ; found.                   
               INC  DE               ; keep looping till found. 
               INC  B                                           
               INC  C                                           
               JR   got_loop                                    
                                                                
set_the_pos:   LD   (memry),HL       ; re_initialise memory pntr
               LD   A,C              ; c = new cursor position  
               LD   H,A              ; Now set the cursor and   
               LD   A,(line)         ; exit.                    
               LD   L,A                                         
               CALL stcur                                       
               RET                                              
                                                                
                                                                
wrd_cnt:       LD   HL,file_st                                  
               LD   DE,0                                        
wr_lp3:        DEC  HL                                          
               LD   B,0                                         
wr_lp:         INC  HL                                          
               INC  B                                           
               LD   A,B                                         
wod:           CP   65                                          
               JP   Z,wr_lp3                                    
               LD   A,(HL)                                      
               CP   255                                         
               JP   Z,got_cnt                                   
               CP   32                                          
               JP   Z,wr_lp                                     
               BIT  7,A                                         
               JP   NZ,wr_lp                                    
               INC  DE                                          
wr_lp1:        INC  HL                                          
               INC  B                                           
               LD   A,B                                         
               CP   66                                          
               CALL Z,inc_de                                    
               LD   A,(HL)                                      
               CP   255                                         
               JP   Z,got_cnt                                   
               CP   32                                          
               JP   Z,wr_lp                                     
               BIT  7,A                                         
               JP   NZ,wr_lp                                    
               JP   wr_lp1                                      
                                                                
inc_de:        INC  DE                                          
               LD   B,2                                         
               RET                                              
                                                                
got_cnt:       EX   DE,HL                                       
               PUSH HL                                          
               CALL draw_box                                    
               LD   B,21                                        
               CALL prstr                                       
               POP  HL                                          
               CALL pnum                                        
               LD   HL,(sposn2)                                 
               CALL press_ret2                                  
               JP   exit_box                                    
                                                                
                                                                
printer:       CALL exit_box         ; get rid of menu          
               XOR  A                                           
               LD   (p_cont),A                                  
               LD   BC,489           ; is printer on line       
               IN   A,(C)                                       
               RRCA                                             
               JP   NC,printer_1                                
               CALL draw_box                                    
               LD   B,10                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
printer_1:     LD   A,(block_var)   ; check for block marker    
               OR   A                                           
               JP   Z,blk_not_set                               
               LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   HL,(block_end)                              
               LD   DE,(block_strt)                             
               OR   A                                           
               SBC  HL,DE                                       
               CALL C,rev_blocks                                
               LD   HL,(block_strt)                             
               LD   (prntr),HL       ; print block from here    
               LD   A,(char_1)                                  
               LD   (HL),A                                      
               JP   printer_2                                   
                                                                
rev_blocks:    LD   HL,(block_strt)                             
               LD   DE,(block_end)                              
               LD   (block_strt),DE                             
               LD   (block_end),HL                              
               OR   A                                           
               SBC  HL,DE                                       
               LD   A,(char_1)                                  
               EX   AF,AF'                                      
               LD   A,(char_2)                                  
               LD   (char_1),A                                  
               EX   AF,AF'                                      
               LD   (char_2),A                                  
               RET                                              
                                                                
                                                                
                                                                
only_1_blk:    CALL exit_box                                    
               CALL draw_box                                    
               LD   B,6                                         
               CALL press_ret                                   
               CALL exit_box                                    
               RET                                              
                                                                
blk_not_set:   LD   HL,file_st                                  
               LD   (prntr),HL                                  
                                                                
printer_2:     LD   A,(page_start)                              
               LD   (page_temp),A                               
               CALL draw_box                                    
               LD   B,8                                         
               CALL prstr                                       
                                                                
y_n_loop:      CALL rd_key                                      
               RES  5,A                                         
               CP   "N"                                         
               JP   Z,exit_printr                               
               CP   "Y"                                         
               JR   NZ,y_n_loop                                 
                                                                
               CALL draw_box                                    
               LD   B,35                                        
               CALL prstr                                       
                                                                
con_loop:      CALL rd_key                                      
               RES  5,A                                         
               CP   "N"                                         
               JP   Z,send_out                                  
               CP   "Y"                                         
               JR   NZ,con_loop                                 
num_t_big:     CALL cop_input                                   
               LD   A,H                                         
               OR   A                                           
               JR   NZ,num_t_big   ; number to big              
               LD   A,L                                         
               OR   A                                           
               JP   Z,send_complete                             
               LD   (copies),A                                  
               LD   A,255                                       
               LD   (p_cont),A                                  
               LD   A,(copies)                                  
               OR   A                                           
               JR   Z,continuous                                
               DEC  A                                           
               LD   (copies),A                                  
continuous:    LD   A,0                                         
               RST  40                                          
               LD   A,27                                        
               RST  40                                          
               LD   A,"@"                                       
               RST  40                                          
               LD   A,27                                        
               RST  40                                          
               LD   A,67                                        
               RST  40                                          
               LD   A,(skip_perf)                               
               LD   B,A                                         
               LD   A,(page_length)                             
               ADD  B                                           
               RST  40                                          
               LD   A,27                                        
               RST  40                                          
               LD   A,78                                        
               RST  40                                          
               LD   A,(skip_perf)                               
               RST  40                                          
               JP   init_printer                                
                                                                
                                                                
; Printing not required so put marker back into the file        
                                                                
                                                                
exit_printr:   LD   A,(block_var)                               
               OR   A                                           
               JP   Z,exit_box                                  
               LD   A,127                                       
               LD   HL,(block_strt)                             
               LD   (HL),A                                      
               JP   exit_box                                    
                                                                
                                                                
send_out:      LD   A,0                                         
               RST  40                                          
               LD   A,27                                        
               RST  40                                          
               LD   A,"@"                                       
               RST  40                                          
init_printer:  LD   A,27                                        
               RST  40                                          
               LD   A,"l"                                       
               RST  40                                          
               LD   A,(pr_tab)                                  
               RST  40                                          
               CALL cls                                         
               CALL norm                                        
send_char:     LD   HL,(prntr)                                  
send_loop_1:   CALL print_pge_num                               
               LD   A,(page_length)                             
               LD   C,A                                         
send_loop_2:   LD   B,64                                        
send_loop_3:   LD   A,(HL)                                      
               CP   255                                         
               JP   Z,send_fin                                  
               CP   127                                         
               JP   Z,send_finished                             
               CP   96                                          
               JP   Z,find_cont                                 
               CP   "#"                                         
               JP   Z,find_cont                                 
               BIT  7,A                                         
               JP   NZ,find_cont                                
               RST  40           ; was not_cont                 
               JP   C,Esc_pressed                               
                                                                
                                                                
cont_2:        INC  HL                                          
               DJNZ send_loop_3                                 
               RST  24                                          
               DEC  C                                           
               LD   A,C                                         
               OR   A                                           
               JR   NZ,send_loop_2                              
               LD   A,(p_cont)                                  
               OR   A                                           
               JP   NZ,send_loop_1                              
               PUSH HL                                          
               PUSH BC                                          
               LD   HL,43008                                    
               LD   (sposn2),HL                                 
               LD   B,7                                         
               CALL prstr                                       
               POP  BC                                          
               POP  HL                                          
                                                                
send_key:      CALL rd_key                                      
               RES  5,A                                         
               CP   "N"                                         
               JP   Z,send_loop_1                               
               CP   "E"                                         
               JP   Z,send_complete                             
               JR   send_key                                    
                                                                
                                                                
                                                                
send_finished: RST  24                                          
               LD   A,(p_cont)                                  
               CP   255                                         
               JP   Z,con_print                                 
               CALL another_copy                                
               CP   "Y"                                         
               JP   Z,re_init                                   
send_complete: LD   A,(block_var)                               
               OR   A                                           
               JP   Z,top                                       
               LD   A,(char_2)                                  
               LD   HL,(block_end)                              
               LD   (HL),A                                      
               JP   top                                         
                                                                
send_fin:      RST  24                                          
               LD   A,(p_cont)                                  
               CP   255                                         
               JP   Z,con_print                                 
               CALL another_copy                                
               CP   "Y"                                         
               JP   Z,re_init                                   
               JP   top                                         
                                                                
                                                                
con_print:     LD   A,C                                         
               DEC  A                                           
               OR   A                                           
               JP   Z,con2_print                                
                                                                
                                                                
               LD   A,12            ; WAS CON_PRINT             
               RST  40                                          
con2_print:    LD   A,(copies)                                  
               OR   A                                           
               JP   Z,send_complete                             
               DEC  A                                           
               LD   (copies),A                                  
               JP   continuous                                  
                                                                
re_init:       LD   A,27                                        
               RST  40                                          
               LD   A,"@"                                       
               RST  40                                          
               LD   A,(p_cont)                                  
               CP   255                                         
               JP   Z,continuous                                
               JP   init_printer                                
                                                                
                                                                
send_fini:     LD   A,13                                        
               RST  40                                          
               RET                                              
                                                                
top:           XOR  A                                           
               LD   (p_cont),A                                  
               LD   (block_var),A                               
               JP   do_vars                                     
                                                                
another_copy:  CALL send_fini                                   
               LD   A,(page_start)                              
               LD   (page_temp),A                               
               CALL clear_line                                  
               LD   HL,43047                                    
               LD   (sposn2),HL                                 
               LD   B,34                                        
               CALL prstr                                       
an_loop:       CALL rd_key                                      
               RES  5,A                                         
               CP   "Y"                                         
               RET  Z                                           
               CP   "N"                                         
               RET  Z                                           
               JR   an_loop                                     
                                                                
Esc_pressed:   RST  24                                          
               CALL draw_box                                    
               LD   B,9                                         
               CALL press_ret                                   
               JP   send_complete                               
                                                                
print_pge_num: LD   A,(p_cont)                                  
               OR   A                                           
               JP   NZ,cont_print                               
               LD   A,(block_var)                               
               OR   A                                           
               JP   Z,print_pg_nm                               
               PUSH HL                                          
               PUSH BC                                          
               CALL clear_line                                  
               LD   HL,43055                                    
               LD   (sposn2),HL                                 
               LD   B,23                                        
               CALL prstr                                       
               POP  BC                                          
               POP  HL                                          
               RET                                              
                                                                
cont_print:    PUSH HL                                          
               PUSH BC                                          
               CALL clear_line                                  
               LD   HL,43055                                    
               LD   (sposn2),HL                                 
               LD   B,33                                        
               CALL prstr                                       
               POP  BC                                          
               POP  HL                                          
               RET                                              
                                                                
print_pg_nm:   LD   A,(p_cont)                                  
               OR   A                                           
               RET  NZ                                          
               PUSH HL                                          
               PUSH BC                                          
               CALL clear_line                                  
               LD   HL,43008                                    
               LD   (sposn2),HL                                 
               LD   B,4                                         
               CALL prstr                                       
               LD   A,(page_temp)                               
               INC  A                                           
               LD   (page_temp),A                               
               DEC  A                                           
               CALL pnum2                                       
               LD   B,5                                         
               CALL prstr                                       
               POP  BC                                          
               POP  HL                                          
               RET                                              
                                                                
find_cont:     PUSH HL                                          
               PUSH BC                                          
               PUSH DE                                          
               RES  7,A                                         
               CP   "L"                                         
               JR   Z,d_fd_on                                   
               CP   "l"                                         
               JR   Z,d_fd_off                                  
               LD   BC,39                                       
               LD   HL,cont_data                                
               CPIR                                             
               JP   Z,send_cont                                 
exit_d_sp:     LD   A,32                                        
               RST  40                                          
               POP  DE                                          
               POP  BC                                          
               POP  HL                                          
               JP   cont_2                                      
                                                                
                                                                
;            Double line feed on                                
                                                                
                                                                
d_fd_on:       LD   A,10                                        
d_fd:          CALL unlock_rom                                  
               LD   (d_sp_var),A                                
               CALL lock_rom                                    
               JR   exit_d_sp                                   
                                                                
                                                                
;            Double line feed off                               
                                                                
                                                                
d_fd_off:      XOR  A                                           
               JR   d_fd                                        
                                                                
                                                                
send_cont:     LD   A,39                                        
               SUB  C                                           
               LD   B,A                                         
               LD   DE,21                                       
               LD   HL,nlq_on-21                                
index_loop:    ADD  HL,DE                                       
               DJNZ index_loop                                  
               LD   A,(HL)                                      
               INC  HL                                          
               LD   B,A                                         
send_c:        LD   A,(HL)                                      
               RST  40                                          
               INC  HL                                          
               DJNZ send_c                                      
               POP  DE                                          
               POP  BC                                          
               POP  HL                                          
               JP   cont_2                                      
                                                                
                                                                
clear_line:    LD   HL,43008                                    
               LD   (sposn2),HL                                 
               LD   B,12                                        
               CALL prstr                                       
               RET                                              
                                                                
press_ret:     CALL prstr                                       
press_ret2:    LD   B,30                                        
               CALL prstr                                       
ret_loop:      CALL rd_key                                      
               CP   13                                          
               RET  Z                                           
               JR   ret_loop                                    
                                                                
                                                                
; input routine for amount of copies required for printer       
                                                                
cop_input:     CALL draw_box                                    
               LD   B,44                                        
               CALL prstr                                       
               LD   IX,num_buf                                  
               LD   (IX+0),32                                   
               LD   (IX+1),32                                   
               LD   (IX+2),32                                   
               LD   (IX+3),32                                   
               LD   B,3                                         
cop_loop:      PUSH BC                                          
               CALL rd_key                                      
               POP  BC                                          
               CP   13                                          
               JP   Z,get_nm                                    
               CP   12                                          
               JP   Z,cop_input                                 
               CP   48                                          
               JP   C,cop_loop                                  
               CP   58                                          
               JP   NC,cop_loop                                 
               LD   (IX+0),A                                    
               CALL pchar2_2                                    
               DEC  B                                           
               LD   A,B                                         
               CP   0                                           
               JP   Z,ret_key                                   
               INC  IX                                          
               JR   cop_loop                                    
                                                                
ret_key:       PUSH BC                                          
               CALL rd_key                                      
               POP  BC                                          
               CP   13                                          
               JP   Z,get_nm                                    
               CP   12                                          
               JR   NZ,ret_key                                  
               JP   cop_input                                   
                                                                
get_nm:        LD   IX,num_buf                                  
               LD   HL,1                                        
               LD   A,(IX+0)                                    
               CP   32        ; nothing has been input          
               RET  Z         ; so exit with L holding 1        
               LD   H,0                                         
               SUB  48                                          
               LD   L,A                                         
nm_loop:       INC  IX                                          
               LD   A,(IX+0)                                    
               CP   32                                          
               RET  Z                                           
               CCF                                              
               RET  NC                                          
               SUB  48                                          
               LD   B,H                                         
               LD   C,L                                         
               ADD  HL,HL                                       
               RET  C                                           
               ADD  HL,HL                                       
               RET  C                                           
               ADD  HL,BC                                       
               RET  C                                           
               ADD  HL,HL                                       
               RET  C                                           
               ADD  A,L                                         
               LD   L,A                                         
               JR   NC,nm_loop                                  
               INC  H                                           
               JR   nm_loop                                     
                                                                
;        put the start block marker in the file                 
                                                                
set_strt:      NOP   ;        CALL crsr                         
               CALL strtln                                      
               LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   127                                         
               JP   Z,m_set;        JP   Z,markr_set            
               LD   A,(char_1)                                  
               OR   A                                           
               JP   NZ,m_set;        JP   NZ,markr_set          
               LD   A,255                                       
               LD   (block_var),A                               
               LD   HL,(memry)                                  
               LD   (block_strt),HL                             
               LD   A,(HL)                                      
               LD   (char_1),A                                  
               LD   A,127                                       
               CALL pchar                                       
               CALL enter                                       
               CALL exit_box                                    
               JP   clear_c_chars                               
                                                                
m_set:         CALL goto_margin                                 
               JP   markr_set                                   
                                                                
                                                                
;        put the end block marker in the file                   
                                                                
set_end:       CALL strtln                                      
               LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   127                                         
               JP   Z,m_set                                     
               LD   A,(char_2)                                  
               OR   A                                           
               JP   NZ,m_set                                    
               LD   A,255                                       
               LD   (block_var),A                               
               LD   HL,(memry)                                  
               LD   (block_end),HL                              
               LD   A,(HL)                                      
               LD   (char_2),A                                  
               LD   A,127                                       
               CALL pchar                                       
               CALL enter                                       
               CALL exit_box                                    
               JP   clear_c_chars                               
                                                                
;        delete the block markers from the file                 
                                                                
delete_blocks: NOP                                              
del_blocks:    LD   A,(block_var)                               
               OR   A                                           
               JP   Z,exit_box                                  
               XOR  A                                           
               LD   (block_var),A                               
               LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,do_end                                    
               LD   HL,(block_strt)                             
               LD   A,(char_1)                                  
               LD   (HL),A                                      
do_end:        LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,do_vars                                   
               LD   HL,(block_end)                              
               LD   A,(char_2)                                  
               LD   (HL),A                                      
                                                                
do_vars:       LD   HL,0                                        
               LD   (block_strt),HL                             
               LD   (block_end),HL                              
               LD   (block_len),HL                              
               XOR  A                                           
               LD   (char_1),A                                  
               LD   (char_2),A                                  
               LD   (char_3),A                                  
               CALL norm                                        
               JP   exit_box                                    
                                                                
;          error message. Marker already set                    
                                                                
markr_set:     CALL exit_box                                    
               CALL draw_box                                    
               LD   B,26                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
;         copy block from A to B leaving A intact               
                                                                
copy_block:    CALL exit_box                                    
               CALL strtln                                      
               LD   HL,(memry)                                  
               LD   (memry_var),HL                              
               CALL goto_margin                                 
               LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   HL,(block_end)                              
               LD   DE,(block_strt)                             
               OR   A                                           
               SBC  HL,DE                                       
               CALL C,rev_blocks                                
               LD   (block_len),HL                              
               INC  HL                                          
               LD   B,H                                         
               LD   C,L                                         
               LD   HL,(memry_var)                              
chk_block:     LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,next_chk                                 
               DEC  BC                                          
               INC  HL                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,chk_block                                
               JP   just_move                                   
next_chk:      LD   HL,(memry_var)                              
               LD   DE,(block_len)                              
               ADD  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,no_room                                   
               LD   HL,(memtop)                                 
               LD   DE,(memry_var)                              
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,just_move                                 
               LD   DE,(memtop)                                 
               LD   HL,topmem                                   
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,no_room                                   
               JP   Z,no_room                                   
               LD   DE,(block_len)                              
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,no_room                                   
               LD   DE,(block_len)                              
               LD   HL,BF_buf_len                               
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,block_to_big                              
               LD   HL,(block_strt)                             
               LD   DE,(block_end)                              
               LD   A,(char_1)                                  
               LD   (HL),A                                      
               LD   A,(char_2)                                  
               LD   (DE),A                                      
               XOR  A                                           
               LD   (block_var),A                               
                                                                
; transfer block from text file to buffer                       
                                                                
               LD   DE,(block_strt)                             
               LD   BC,(block_len)                              
               LD   HL,BF_buffer                                
blk_loop:      LD   A,(DE)                                      
               CALL poke_hl                                     
               INC  HL                                          
               INC  DE                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,blk_loop                                 
                                                                
; finished the transfer to the buffer                           
                                                                
               LD   A,0                                         
               LD   (buff_flag),A                               
                                                                
now_move:      LD   HL,(memtop)      ; also entry point for the 
               LD   DE,(memry_var)   ; move block option        
               OR   A                                           
               SBC  HL,DE                                       
               LD   B,H                                         
               LD   C,L                                         
               INC  BC                                          
               LD   HL,(memtop)                                 
               LD   DE,(block_len)                              
               ADD  HL,DE                                       
               EX   DE,HL                                       
               LD   HL,(memtop)                                 
               LDDR                                             
                                                                
; transfer the contents of the buffer back to the text file     
                                                                
               LD   HL,BF_buffer                                
               LD   DE,(memry_var)                              
               LD   BC,(block_len)                              
trans_loop2:   CALL peek_hl                                     
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,trans_loop2                              
                                                                
                                                                
; finished transfering block                                    
                                                                
                                                                
               CALL clear_c_chars                               
               CALL do_vars                                     
               JP   exit_box                                    
                                                                
; Just move if the block is going below the bottom of the text  
; file and there is room for it.                                
                                                                
just_move:     LD   HL,topmem                                   
               LD   DE,(memry_var)                              
               OR   A                                           
               SBC  HL,DE                                       
               LD   DE,(block_len)                              
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,no_room                                   
               LD   HL,(block_strt)                             
               LD   DE,(block_end)                              
               LD   BC,(block_len)                              
               LD   A,(char_1)                                  
               LD   (HL),A                                      
               LD   A,(char_2)                                  
               LD   (DE),A                                      
               XOR  A                                           
               LD   (block_var),A                               
               LD   DE,(memry_var)                              
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               CALL clear_c_chars                               
               CALL do_vars                                     
               JP   enter                                       
                                                                
; no room in text file for block copy so give an error message  
                                                                
no_room:       CALL exit_box                                    
               CALL draw_box                                    
               LD   B,28                                        
n_rm:          CALL press_ret                                   
               JP   exit_box                                    
                                                                
; Block is to big ie bigger than the buffer. buffer is 32k      
                                                                
block_to_big:  CALL exit_box                                    
               CALL draw_box                                    
               LD   B,29                                        
               JP   n_rm                                        
                                                                
; goto the top of the file.                                     
                                                                
top_fle:       CALL exit_box                                    
               CALL norm                                        
               LD   HL,34816                                    
               LD   (sposn2),HL                                 
               LD   BC,1408                                     
clr_lp:        LD   A,32                                        
               CALL pchar2                                      
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,clr_lp                                   
               LD   HL,34816                                    
               LD   (sposn2),HL                                 
               CALL init_top                                    
               CALL just_print                                  
               RET                                              
                                                                
; Erase the block from memory. Confirm first with a Y or N      
                                                                
erase_block:   CALL exit_box                                    
               LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
                                                                
               LD   DE,(block_len)                              
               LD   HL,BF_buf_len                               
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,block_to_big                              
                                                                
               CALL draw_box                                    
               LD   B,27                                        
               CALL prstr                                       
clr_yn:        CALL rd_key                                      
               RES  5,A                                         
               CP   "N"                                         
               JP   Z,exit_box                                  
               CP   "Y"                                         
               JR   NZ,clr_yn                                   
                                                                
               LD   HL,(block_end)                              
               LD   DE,(block_strt)                             
               OR   A                                           
               SBC  HL,DE                                       
               CALL C,rev_blocks                                
               DEC  HL                                          
               LD   (block_len),HL                              
               LD   HL,(block_end)                              
               LD   A,(char_2)                                  
               LD   (HL),A                                      
               LD   HL,(block_strt)                             
               LD   D,H                                         
               LD   E,L                                         
               INC  E                                           
               LD   BC,(block_len)                              
               LD   A,32                                        
               LD   (HL),A                                      
               LDIR                                             
               CALL do_vars                                     
               XOR  A                                           
               LD   (block_var),A                               
               RET                                              
                                                                
                                                                
; Move marked block from A to B removing old block at same time 
                                                                
move_block:    LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   HL,(block_end)                              
               LD   DE,(block_strt)                             
               OR   A                                           
               SBC  HL,DE                                       
               CALL C,rev_blocks                                
               LD   (block_len),HL                              
                                                                
               CALL exit_box                                    
               CALL strtln                                      
               LD   HL,(memry)                                  
               LD   (memry_var),HL                              
               CALL goto_margin                                 
               LD   DE,(block_len)                              
               LD   HL,BF_buf_len                               
               OR   A                                           
               SBC  HL,DE                                       
               JP   C,block_to_big                              
                                                                
                                                                
;        put a marker in the file for later                     
                                                                
               LD   HL,(memry_var)                              
               LD   A,(HL)                                      
               LD   (char_3),A                                  
               LD   A,128                                       
               LD   (HL),A                                      
               LD   (move_var),A                                
                                                                
;    make sure an end file marker is after the 128 character    
                                                                
               CALL clear_c_chars                               
                                                                
               LD   DE,64                                       
               LD   HL,(block_strt)                             
               LD   A,(HL)                                      
               CP   128                                         
               JP   Z,error_n_5                                 
               ADD  HL,DE                                       
move_loop:     LD   A,(HL)                                      
               CP   127                                         
               JP   Z,move_ok                                   
               CP   128                                         
               JP   Z,error_n_5                                 
               ADD  HL,DE                                       
               JR   move_loop                                   
                                                                
;        transfer the block to the buffer                       
                                                                
move_ok:       LD   HL,(block_strt)                             
               LD   A,(char_1)                                  
               LD   (HL),A                                      
               LD   DE,(block_strt)                             
               LD   BC,(block_len)                              
               LD   HL,BF_buffer                                
Tr_loop:       LD   A,(DE)                                      
               CALL poke_hl                                     
               INC  HL                                          
               INC  DE                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,Tr_loop                                  
               LD   HL,(block_strt)                             
               LD   A,(HL)                                      
               LD   (char_1),A                                  
               LD   (HL),127                                    
                                                                
;        Flag a block is in the buffer                          
                                                                
               XOR  A                                           
               LD   (buff_flag),A                               
                                                                
                                                                
;        remove the block from the file                         
                                                                
               LD   HL,(memtop)                                 
               LD   DE,(block_end)                              
               OR   A                                           
               SBC  HL,DE                                       
               PUSH HL                                          
               PUSH HL                                          
               POP  BC                                          
               LD   HL,(block_end)                              
               LD   A,(char_2)                                  
               LD   (HL),A                                      
               LD   DE,(block_strt)                             
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               POP  HL                                          
               LD   DE,(block_strt)                             
               ADD  HL,DE                                       
               LD   BC,(block_len)                              
spc_loop:      LD   A,32                                        
               LD   (HL),A                                      
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,spc_loop                                 
                                                                
;      put a new end marker into the file                       
                                                                
               CALL clear_c_chars                               
               LD   A,255                                       
               LD   (block_var),A                               
                                                                
;      file has been closed up so now go to the top of the      
;      file again and search for the 3rd marker and then        
;      put the block back at that point.                        
                                                                
                                                                
               LD   A,(page_start)                              
               LD   (pyge),A                                    
               LD   A,1                                         
               LD   (lline),A                                   
               LD   HL,1                                        
               LD   (total),HL                                  
               LD   HL,file_st                                  
               LD   (memry),HL                                  
               LD   L,3                                         
               LD   H,0                                         
               CALL stcur                                       
                                                                
scnd_loop:     LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   128                                         
               JP   Z,fnd_scnd                                  
               CALL down1                                       
               JR   scnd_loop                                   
                                                                
;      Put block back into file                                 
;      then call exit box                                       
;      This will reprint the screen and exit the routine        
                                                                
                                                                
                                                                
                                                                
fnd_scnd:      LD   A,(char_3)                                  
               LD   (HL),A                                      
               LD   HL,(memry)                                  
               LD   (memry_var),HL                              
               CALL now_move                                    
               XOR  A                                           
               LD   (block_var),A                               
               LD   (move_var),A                                
               CALL exit_box                                    
               LD   B,10                                        
dwn_move:      PUSH BC                                          
               CALL down1                                       
               POP  BC                                          
               DJNZ dwn_move                                    
               LD   B,10                                        
up_move:       PUSH BC                                          
               CALL up                                          
               POP  BC                                          
               DJNZ up_move                                     
               CALL goto_margin                                 
               JP   exit_box      ; was RET                     
                                                                
error_n_5:     LD   A,(char_3)                                  
               LD   (HL),A                                      
               XOR  A                                           
               LD   (move_var),A                                
               CALL draw_box                                    
               LD   B,43                                        
               JP   n_rm                                        
                                                                
                                                                
; Install printer driver text file into codes area              
                                                                
                                                                
d_install:     CALL exit_box    ; clear margins and menu        
               CALL clear_margins ; store margin values         
               LD   (error_sp),SP                               
               CALL strtln                                      
               LD   DE,(memry)                                  
               LD   A,(DE)                                      
               CP   "#"                                         
               JP   Z,loop_inst                                 
               CP   "`"                                         
               JP   Z,loop_inst                                 
               BIT  7,A                                         
               JP   Z,error_1                                   
loop_inst:     CALL find_code                                   
               PUSH HL                                          
               CALL convert_cds                                 
               CALL unlock_rom                                  
               INC  B                                           
               POP  HL                                          
               LD   A,B                                         
               LD   (HL),A                                      
               EX   DE,HL                                       
               INC  DE                                          
               LD   HL,buffer                                   
               LD   BC,20                                       
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               CALL lock_rom                                    
               CALL enter                                       
               LD   DE,(memry)                                  
               LD   A,(DE)                                      
               CP   "#"                                         
               JP   Z,loop_inst                                 
               CP   "`"                                         
               JP   Z,loop_inst                                 
               BIT  7,A                                         
               JP   NZ,loop_inst                                
               CALL reset_margins                               
               CALL goto_margin                                 
               JP   exit_box                                    
                                                                
convert_cds:   LD   HL,buffer                                   
               PUSH HL                                          
               LD   B,21                                        
               XOR  A                                           
i_buf_fil:     LD   (HL),A                                      
               INC  HL                                          
               DJNZ i_buf_fil                                   
               POP  IX                                          
               PUSH BC                                          
               CALL right_1                                     
               POP  BC                                          
ins_loop:      LD   DE,(memry)                                  
               LD   A,(DE)                                      
               CP   48                                          
               JP   C,error_2                                   
               CP   58                                          
               JP   NC,error_2                                  
               PUSH BC                                          
               CALL getnum                                      
               POP  BC                                          
               LD   A,H                                         
               OR   A                                           
               JP   NZ,error_4                                  
               LD   A,L                                         
               LD   (IX+0),A                                    
               INC  IX                                          
               LD   A,(DE)                                      
               CP   32                                          
               RET  Z                                           
               CP   255                                         
               RET  Z                                           
               INC  B                                           
               LD   A,B                                         
               CP   20                                          
               JP   Z,error_3                                   
               PUSH BC                                          
               CALL right_1                                     
               POP  BC                                          
               JP   ins_loop                                    
                                                                
getnum:        LD   H,0                                         
               SUB  48                                          
               LD   L,A                                         
get_loop:      PUSH BC                                          
               PUSH HL                                          
               CALL right_1                                     
               POP  HL                                          
               POP  BC                                          
               LD   DE,(memry)                                  
               LD   A,(DE)                                      
               CP   ","                                         
               RET  Z                                           
               CP   32                                          
               RET  Z                                           
               CCF                                              
               RET  NC                                          
               SUB  48                                          
               CP   10                                          
               JP   NC,error_2                                  
               LD   B,H                                         
               LD   C,L                                         
               ADD  HL,HL                                       
               RET  C                                           
               ADD  HL,HL                                       
               RET  C                                           
               ADD  HL,BC                                       
               RET  C                                           
               ADD  HL,HL                                       
               RET  C                                           
               ADD  A,L                                         
               LD   L,A                                         
               JR   NC,get_loop                                 
               JP   error_4                                     
                                                                
                                                                
find_code:     RES  7,A                                         
               LD   BC,39                                       
               LD   HL,cont_data                                
               CPIR                                             
               JP   NZ,error_2                                  
               LD   A,39                                        
               SUB  C                                           
               LD   B,A                                         
               LD   DE,21                                       
               LD   HL,nlq_on-21                                
fi_loop:       ADD  HL,DE                                       
               DJNZ fi_loop                                     
               RET                                              
                                                                
                                                                
error_1:       LD   A,39                                        
               JP   error                                       
                                                                
error_2:       LD   A,40                                        
               JP   error                                       
                                                                
error_3:       LD   A,41                                        
               JP   error                                       
                                                                
error_4:       LD   A,42                                        
               JP   error                                       
                                                                
                                                                
                                                                
error:         LD   (error_var),A                               
               CALL full_screen                                 
               LD   HL,(error_sp)                               
               LD   SP,HL                                       
               CALL draw_box                                    
               LD   A,(error_var)                               
               LD   B,A                                         
               JP   n_rm                                        
                                                                
                                                                
                                                                
; SPELL CHECKER      Check the word at the cursor position      
;                    using the file in page ......              
                                                                
spell_chk:     CALL initbuf    ; empty the 70 byte buffer       
               LD   HL,(memry)                                  
               LD   A,(HL)                                      
               CP   255                                         
               JP   Z,no_words2                                 
               LD   A,(col)                                     
               CP   63                                          
               JP   Z,exit_box                                  
               LD   B,A                                         
               LD   A,64                                        
               SUB  B                                           
               LD   B,A                                         
               PUSH BC                                          
spl_loop:      LD   A,(HL)                                      
               CP   255                                         
               JP   Z,no_words                                  
               CP   32                                          
               JP   NZ,got_a_ltr                                
               INC  HL                                          
               DJNZ spl_loop                                    
               JP   no_words                                    
                                                                
                                                                
got_a_ltr:     POP  BC                                          
               DEC  B                                           
               LD   HL,(memry)                                  
lt_loop:       LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,got_a_let                                
               INC  HL                                          
               DJNZ lt_loop                                     
                                                                
got_a_let:     LD   DE,buffer                                   
               SET  5,A                                         
               LD   (DE),A                                      
ltr_loop:      INC  HL                                          
               INC  DE                                          
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,find_word                                 
               CP   255                                         
               JP   Z,find_word                                 
               SET  5,A                                         
               LD   (DE),A                                      
               DJNZ ltr_loop                                    
                                                                
                                                                
find_word:     CALL exit_box                                    
               CALL draw_box                                    
               LD   B,48                                        
               CALL prstr                                       
                                                                
               CALL print_buf                                   
                                                                
                                                                
; page in the dictionary in page 18   addresss 311296           
                                                                
                                                                
check_word:    IN   A,(251)                                     
               PUSH AF                                          
               LD   A,DICTP     ; page 23                       
               OUT  (251),A                                     
               LD   HL,32768    ; start of dictionary           
               LD   A,(HL)                                      
               OR   A                                           
               JP   Z,no_dict                                   
               LD   DE,dictionary                               
chk_two:       LD   HL,buffer                                   
chk_dict:      LD   A,(DE)                                      
               OR   A                                           
               JP   Z,nt_in_dict                                
               SET  5,A                                         
               CP   (HL)                                        
               JP   NZ,word_fail                                
               INC  HL                                          
               INC  DE                                          
               LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,chk_dict                                 
               LD   A,(DE)                                      
               CP   32                                          
               JR   Z,word_ok                                   
                                                                
                                                                
word_fail:     INC  DE                                          
               LD   A,(DE)                                      
               OR   A                                           
               JP   Z,nt_in_dict                                
               CP   32                                          
               JR   NZ,word_fail                                
next_let:      INC  DE                                          
               LD   A,(DE)                                      
               CP   32                                          
               JR   Z,next_let                                  
               JP   chk_two                                     
                                                                
print_buf:     LD   HL,buffer                                   
buff_loop:     LD   A,(HL)                                      
               CP   32                                          
               RET  Z                                           
               CALL pchar2                                      
               INC  HL                                          
               JR   buff_loop                                   
                                                                
                                                                
nt_in_dict:    POP  AF         ; GET CURRENT TEXT PAGE          
               OUT  (251),A                                     
               CALL exit_box                                    
               CALL draw_box                                    
               CALL print_buf                                   
               LD   B,51                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
                                                                
no_words:      POP  BC                                          
no_words2:     CALL exit_box                                    
               CALL draw_box                                    
               LD   B,49                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
                                                                
                                                                
no_dict:       POP  AF       ; GET CURRENT TEXT PAGE            
               OUT  (251),A                                     
               CALL exit_box                                    
               CALL draw_box                                    
               LD   B,50                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
                                                                
word_ok:       POP  AF       ; GET CURRENT TEXT PAGE            
               OUT  (251),A                                     
               CALL exit_box                                    
               CALL draw_box                                    
               CALL print_buf                                   
               LD   B,52                                        
               CALL press_ret                                   
               JP   exit_box                                    
                                                                
                                                                
                                                                
                                                                
; get the information file into page 20 and print it to the     
; screen.                                                       
                                                                
                                                                
info1:         NOP                                              
inf1:          LD   A,2            ; 2 = info page in use       
               LD   (info_flg),A                                
               LD   A,INFO1P       ; PAGE 17                    
               JP   info_ent                                    
                                                                
info2:         NOP                                              
inf2:          LD   A,2                                         
               LD   (info_flg),A                                
               LD   A,INFO2P       ; PAGE 19                    
               JP   info_ent                                    
                                                                
info3:         NOP                                              
inf3:          LD   A,2                                         
               LD   (info_flg),A                                
               LD   A,INFO3P       ; PAGE 9  FOR A 256K         
               JP   info_ent                                    
                                                                
                                                                
                                                                
info4:         NOP                                              
inf4:          LD   A,2                                         
               LD   (info_flg),A                                
               LD   A,INFO4P       ; PAGE 21                    
               JP   info_ent                                    
                                                                
                                                                
                                                                
                                                                
; Modify character set for box characters or normal chrs        
; also poke the dump code in normal ram with the data           
; for either a tight dump or a normal dump                      
; a tight dump means that the graphic characters will touch     
; at the tops and bottoms.                                      
                                                                
                                                                
normal_chars:  LD   HL,nbox1                                    
               CALL do_chars                                    
               CALL poke_chars                                  
               JP   norm_dump                                   
                                                                
                                                                
box_chars:     LD   HL,box1                                     
               CALL do_chars                                    
               CALL poke_chars                                  
               JP   box_dump                                    
                                                                
                                                                
box_dump:      LD   HL,bx_dmp_data                              
               JP   do_dump                                     
                                                                
norm_dump:     LD   HL,nrm_dmp_data                             
               JP   do_dump                                     
                                                                
                                                                
do_dump:       IN   A,(251)                                     
               PUSH AF                                          
               LD   A,1                                         
               OUT  (251),A                                     
               LD   DE,65494                                    
               LD   B,6                                         
nrm_loop:      LD   A,(HL)                                      
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               DJNZ nrm_loop                                    
               POP  AF        ; CURRENT TEXT PAGE               
               OUT  (251),A                                     
               JP   exit_box                                    
                                                                
                                                                
do_chars:      LD   DE,eight_bit_1+224                          
               LD   B,8                                         
               CALL main_loop                                   
                                                                
               LD   DE,eight_bit_1+240                          
               LD   B,8                                         
               CALL main_loop                                   
                                                                
               LD   DE,eight_bit_1+472                          
               LD   B,8                                         
               CALL main_loop                                   
                                                                
               LD   DE,eight_bit_1+488                          
               LD   B,8                                         
               CALL main_loop                                   
                                                                
               LD   DE,eight_bit_1+496                          
               LD   B,8                                         
               CALL main_loop                                   
                                                                
               LD   DE,eight_bit_1+504                          
               LD   B,8                                         
main_loop:     LD   A,(HL)                                      
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               DJNZ main_loop                                   
               RET                                              
                                                                
                                                                
                                                                
; this routine will print the dictionary to the screen          
; and allow a word to be selected and entered into the file     
; using the cursors to move around. F8 moves back to the        
; previous page. F5 moves down to the next page and RETURN      
; enters the word into the file or if on a space when           
; RETURN is pressed then an exit back to the file is made       
; the space key will just exit at any time.                     
                                                                
dict:          CALL cls           ; flag that the dictionary    
               LD   A,1           ; is in use                   
               LD   (info_flg),A                                
                                                                
               LD   A,DICTP       ; get page 23 into 32768      
info_ent:      OUT  (251),A                                     
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
                                                                
                                                                
                                                                
                                                                
; find the end marker in the file if there is one. Then poke    
; the end marker with a space and then the rest of the          
; dictionary with spaces.                                       
                                                                
                                                                
dict2:         LD   BC,32760                                    
               LD   HL,dictionary                               
fi_sp_loop:    LD   A,(HL)                                      
               CP   255                                         
               JP   Z,fill_spaces                               
               OR   A                                           
               JP   Z,fill_spaces                               
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,fi_sp_loop                               
               JR   do_dict                                     
                                                                
; 255 found so fill rest of dictionary file with spaces         
                                                                
                                                                
fill_spaces:   LD   (HL),32                                     
               INC  HL                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,fill_spaces                              
                                                                
                                                                
; now prepare to print the first page to the screen             
                                                                
                                                                
do_dict:       LD   DE,dictionary    ; = 32768                  
               XOR  A                                           
               LD   (dict_count),A                              
dict_sel:      LD   (list_var),DE                               
next_dict:     LD   HL,34816                                    
               LD   BC,1408                                     
               LD   (sposn2),HL                                 
dict_loop:     LD   A,(DE)                                      
               CALL pchar2                                      
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JP   Z,next_loop                                 
               INC  DE                                          
               JR   dict_loop                                   
                                                                
next_loop:     LD   B,0                                         
               LD   C,0                                         
               LD   HL,34816                                    
               LD   (sposn2),HL                                 
nxpg2:         CALL list_crsr                                   
                                                                
                                                                
                                                                
list_loop2:    PUSH DE                                          
nxpg:          CALL rd_key                                      
               CP   32                                          
               JP   Z,lv_dict                                   
               CP   197                                         
               JP   Z,next_dpage                                
               CP   200                                         
               JP   Z,prev_page                                 
               CP   13             ; edit_key                   
               JP   Z,insert_word                               
               CP   9                                           
               JP   Z,move_right                                
               CP   8                                           
               JP   Z,move_left                                 
               CP   10                                          
               JP   Z,move_down                                 
               CP   11                                          
               JP   Z,move_up                                   
               CP   7                                           
               JP   Z,select_let                                
               POP  DE                                          
               CP   "1"                                         
               JP   Z,inf1                                      
               CP   "2"                                         
               JP   Z,inf2                                      
               CP   "3"                                         
               JP   Z,inf3                                      
               CP   "4"                                         
               JP   Z,inf4                                      
               RES  5,A                                         
               CP   "D"                                         
               JP   Z,dict                                      
               PUSH DE                                          
               JP   nxpg                                        
                                                                
                                                                
; select a letter of the alphabet to go to                      
                                                                
select_let:    LD   A,(info_flg)                                
               CP   2                                           
               JP   Z,nxpg                                      
                                                                
                                                                
               CALL draw_box                                    
               LD   B,53                                        
               CALL prstr                                       
sel_loop:      CALL rd_key                                      
               RES  5,A                                         
               CP   64                                          
               JR   C,sel_loop                                  
               CP   91                                          
               JR   NC,sel_loop                                 
               POP  DE      ; throw away old dict addrs         
               PUSH AF                                          
               CALL norm                                        
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               CALL cls       ; CALL exit_box                   
               POP  AF                                          
               CP   "X"                                         
               JR   Z,do_w                                      
               CP   "Y"                                         
               JR   Z,do_w                                      
               CP   "Z"                                         
               JR   NZ,sel_cont                                 
do_w:          LD   A,"W"                                       
sel_cont:      LD   C,A                                         
               LD   HL,dictionary                               
               LD   B,255                                       
sel1_loop:     LD   A,(HL)                                      
               CP   "*"                                         
               JR   Z,got_hash                                  
               INC  HL                                          
               JR   sel1_loop                                   
                                                                
                                                                
                                                                
got_hash:      INC  B                                           
               LD   A,B                                         
               CP   24                                          
               JP   Z,dict2                                     
               INC  HL                                          
               LD   A,(HL)                                      
               CP   C                                           
               JR   NZ,sel1_loop                                
               DEC  HL                                          
               EX   DE,HL                                       
               LD   A,B                                         
               LD   (dict_count),A                              
               JP   dict_sel                                    
                                                                
                                                                
                                                                
                                                                
; put the cursor on the screen                                  
                                                                
list_crsr:     PUSH BC                                          
               PUSH DE                                          
               LD   B,8                                         
               CALL screen_in                                   
               LD   HL,(sposn2)                                 
               LD   DE,128                                      
l_crsr_loop:   PUSH HL                                          
               LD   A,(HL)                                      
               XOR  255                                         
               LD   (HL),A                                      
               INC  HL                                          
               LD   A,(HL)                                      
               XOR  255                                         
               LD   (HL),A                                      
               POP  HL                                          
               ADD  HL,DE                                       
               DJNZ l_crsr_loop                                 
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  DE                                          
               POP  BC                                          
               RET                                              
                                                                
move_right:    LD   A,B                                         
               CP   63                                          
               JP   Z,nxpg                                      
               CALL list_crsr                                   
               LD   HL,(sposn2)                                 
               INC  HL                                          
               INC  HL                                          
               LD   (sposn2),HL                                 
               CALL list_crsr                                   
               INC  B                                           
               LD   HL,(list_var)                               
               INC  HL                                          
               LD   (list_var),HL                               
               JP   nxpg                                        
                                                                
move_left:     LD   A,B                                         
               CP   0                                           
               JP   Z,nxpg                                      
               CALL list_crsr                                   
               LD   HL,(sposn2)                                 
               DEC  HL                                          
               DEC  HL                                          
               LD   (sposn2),HL                                 
               CALL list_crsr                                   
               LD   HL,(list_var)                               
               DEC  HL                                          
               LD   (list_var),HL                               
               DEC  B                                           
               JP   nxpg                                        
                                                                
move_down:     LD   A,C                                         
               CP   21                                          
               JP   Z,nxpg                                      
               CALL list_crsr                                   
               LD   DE,1024                                     
               LD   HL,(sposn2)                                 
               ADD  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   DE,64                                       
               LD   HL,(list_var)                               
               ADD  HL,DE                                       
               LD   (list_var),HL                               
               INC  C                                           
               CALL list_crsr                                   
               JP   nxpg                                        
                                                                
move_up:       LD   A,C                                         
               CP   0                                           
               JP   Z,nxpg                                      
               CALL list_crsr                                   
               LD   DE,1024                                     
               LD   HL,(sposn2)                                 
               OR   A                                           
               SBC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   DE,64                                       
               LD   HL,(list_var)                               
               OR   A                                           
               SBC  HL,DE                                       
               LD   (list_var),HL                               
               DEC  C                                           
               CALL list_crsr                                   
               JP   nxpg                                        
                                                                
insert_word:   POP  DE                                          
               CALL initbuf                                     
               LD   HL,(list_var)                               
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,lv_dict2                                  
               LD   B,20       ; no more than 20 characters     
               LD   DE,buffer                                   
insrt_loop:    LD   A,(HL)                                      
               CP   32                                          
               JP   Z,put_in_file                               
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               DJNZ insrt_loop                                  
                                                                
put_in_file:   LD   A,(text_page)                               
               OUT  (251),A                                     
               LD   HL,(memry)                                  
               LD   DE,buffer                                   
put_loop:      LD   A,(DE)                                      
               PUSH HL                                          
               PUSH DE                                          
               CALL from_list                                   
               POP  DE                                          
               POP  HL                                          
               INC  HL                                          
               INC  DE                                          
               LD   A,(DE)                                      
               CP   32                                          
               JP   Z,put_in_space                              
               JR   put_loop                                    
                                                                
put_in_space:  CALL right                                       
               JP   exit_box                                    
                                                                
next_dpage:    LD   A,(dict_count)                              
               CP   22                                          
               JP   Z,nxpg                                      
               INC  A                                           
               LD   (dict_count),A                              
               CALL cls                                         
               POP  DE                                          
               INC  DE                                          
               LD   (list_var),DE                               
               JP   next_dict                                   
                                                                
prev_page:     LD   A,(dict_count)                              
               OR   A                                           
               JP   Z,nxpg                                      
               DEC  A                                           
               LD   (dict_count),A                              
               CALL cls                                         
               POP  HL                                          
               LD   DE,2815                                     
               OR   A                                           
               SBC  HL,DE                                       
               EX   DE,HL                                       
               LD   (list_var),DE                               
               JP   next_dict                                   
                                                                
                                                                
                                                                
lv_dict:       POP  DE                                          
lv_dict2:      LD   A,(text_page)                               
               OUT  (251),A                                     
               JP   exit_box                                    
                                                                
                                                                
; put my address into the file at the cursor position           
                                                                
                                                                
address:       CALL exit_box                                    
               LD   HL,(memry)                                  
               LD   DE,addr_data                                
next_addr:     PUSH HL                                          
addr_loop:     LD   A,(DE)                                      
               CP   255                                         
               JP   Z,exit_addr                                 
               CP   0                                           
               JP   Z,next_line                                 
               LD   (HL),A                                      
               INC  HL                                          
               INC  DE                                          
               JR   addr_loop                                   
                                                                
next_line:     POP  HL                                          
               PUSH DE                                          
               LD   DE,64                                       
               OR   A                                           
               ADC  HL,DE                                       
               POP  DE                                          
               INC  DE                                          
               JP   next_addr                                   
                                                                
exit_addr:     POP  HL                                          
               CALL clear_c_chars                               
               JP   exit_box                                    
                                                                
                                                                
                                                                
; All data and print statements in the program are below        
                                                                
                                                                
                                                                
; Data for drop down menus.                                     
; ! flags amount of characters to print then the character.     
; @ flags a call to routine to print "RETURN TO EXIT"           
; 13 flags a carriage return.                                   
; > character increments the position between menus             
; 133 = the across character                                    
; 132 = the down character                                      
; 129 = top left corner                                         
; 128 = top right corner                                        
; 131 = bottom left character                                   
; 130 = bottom right character                                  
                                                                
                                                                
                                                                
; box data : poke the characters for the box data into the      
; character set . or poke the normal data back in.              
                                                                
                                                                
                                                                
                                                                
box1:          DEFB 0,0,63,32,32,39,36,36    ; Symbol shift Q   
box2:          DEFB 0,0,252,4,4,228,36,36    ; Symbol shift W   
box3:          DEFB 36,36,39,32,32,63,0,0    ; Symbol shift R   
box4:          DEFB 36,36,228,4,4,252,0,0    ; Symbol shift T   
box5:          DEFB 36,36,36,36,36,36,36,36  ; Symbol shift H   
box6:          DEFB 0,0,255,0,0,255,0,0      ; Symbol shift =   
                                                                
                                                                
; normal character set data                                     
                                                                
                                                                
                                                                
nbox1:         DEFB 12,24,48,96,48,24,12,0   ; Symbol shift Q   
nbox2:         DEFB 96,48,24,12,24,48,96,0   ; Symbol shift W   
nbox3:         DEFB 60,48,48,48,48,48,60,0   ; Symbol shift R   
nbox4:         DEFB 60,12,12,12,12,12,60,0   ; Symbol shift T   
nbox5:         DEFB 24,60,126,24,24,24,24    ; Symbol shift H   
nbox6:         DEFB 0,0,0,0,0,0,0,255,0,0    ; Symbol shift =   
                                                                
                                                                
; data for the dump routine: bx_dmp_data is the data for a      
; tight dump and nrm_dmp_data is for a normal dump              
; this data controls how far forward the paper feeds on the     
; printer between lines.                                        
                                                                
                                                                
bx_dmp_data:   DEFB 5,27,108,8,27,48                            
                                                                
nrm_dmp_data:  DEFB 3,27,108,8,0,0                              
                                                                
                                                                
                                                                
                                                                
;              Drop down menus  4 in all                        
;              Drop down menu 1 data                            
                                                                
                                                                
menu1_dat:     DEFB 129,"!",16,133,128,13,132                   
               DEFM "      QUIT      "                          
               DEFB 132,13,132                                  
               DEFM " A Auto margins "                          
               DEFB 132,13,132                                  
               DEFM " B Goto  bottom "                          
               DEFB 132,13,132                                  
               DEFM " C Clear margin "                          
               DEFB 132,13,132                                  
               DEFM " F Reform  para "                          
               DEFB 132,13,132                                  
               DEFM " L Left  margin "                          
               DEFB 132,13,132                                  
               DEFM " M Form in mrgn "                          
               DEFB 132,13,132                                  
               DEFM " O Options menu "                          
               DEFB 132,13,132                                  
               DEFM " P Reclaim para "                          
               DEFB 132,13,132                                  
               DEFM " R Right margin "                          
               DEFB 132,13,132                                  
               DEFM " T Goto the top "                          
               DEFB 132,13,132                                  
               DEFM " X Enter prcode "                          
               DEFB 132,13,132                                  
               DEFM " G Reprint block"                          
               DEFB 132,13,132                                  
               DEFM " F7 Start block "                          
               DEFB 132,13,131,"!",16,133,130                   
               DEFB 255                                         
                                                                
                                                                
;              Drop down menu 2 data                            
                                                                
                                                                
menu2_data:    DEFB 129,"!",16,133,128,13,132                   
               DEFM "      QUIT      "                          
               DEFB 132,13,132                                  
               DEFM "  C Clear text  "                          
               DEFB 132,13,132                                  
               DEFM "  D Dir   disk  "                          
               DEFB 132,13,132                                  
               DEFM "  E Erase file  "                          
               DEFB 132,13,132                                  
               DEFM "  F Load  font  "                          
               DEFB 132,13,132                                  
               DEFM "  L Load  text  "                          
               DEFB 132,13,132                                  
               DEFM "  M Merge text  "                          
               DEFB 132,13,132                                  
               DEFM "  P Print text  "                          
               DEFB 132,13,132                                  
               DEFM "  S Save  text  "                          
               DEFB 132,13,132                                  
               DEFM "  V File  name  "                          
               DEFB 132,13,132                                  
               DEFM "  T Text  map   "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132   ; print a blank line 
               DEFM "     FILES      "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132                        
               DEFB "!",16,32,132,13,131   ; blank line         
               DEFB "!",16,133,130,255                          
                                                                
                                                                
;              Drop down menu 3 data                            
                                                                
                                                                
menu3_data:    DEFB 129,"!",16,133,128,13                       
               DEFB 132                                         
               DEFM "      QUIT      "                          
               DEFB 132,13,132                                  
               DEFM " B Toggle Clock "                          
               DEFB 132,13,132                                  
               DEFM " C Set  colour  "                          
               DEFB 132,13,132                                  
               DEFM " D Dump  lines  "                          
               DEFB 132,13,132                                  
               DEFM " I Togl insert  "                          
               DEFB 132,13,132                                  
               DEFM " J Togl justfy  "                          
               DEFB 132,13,132                                  
               DEFM " S Speed read   "                          
               DEFB 132,13,132                                  
               DEFM " N Toggle beep  "                          
               DEFB 132,13,132                                  
               DEFM " P Instal drvr  "                          
               DEFB 132,13,132                                  
               DEFM " T Change tabs  "                          
               DEFB 132,13,132                                  
               DEFM " V View  codes  "                          
               DEFB 132,13,132                                  
               DEFM " W Togl W/wrap  "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32                                   
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,131                        
               DEFB "!",16,133,130,255                          
                                                                
                                                                
;              Drop down menu 4 data                            
                                                                
                                                                
menu4_data:    DEFB 129,"!",16,133,128,13,132                   
               DEFM "      QUIT      "                          
               DEFB 132,13,132                                  
               DEFM " C Cont   srch  "                          
               DEFB 132,13,132                                  
               DEFM " B Box    data  "                          
               DEFB 132,13,132                                  
               DEFM " S Search file  "                          
               DEFB 132,13,132                                  
               DEFM " N Normal data  "                          
               DEFB 132,13,132                                  
               DEFM " V View   dict  "                          
               DEFB 132,13,132                                  
               DEFM " L Spell  check "                          
               DEFB 132,13,132                                  
               DEFM " A Home   addrs "                          
               DEFB 132,13,132                                  
               DEFM " 1 info page 1  "                          
               DEFB 132,13,132                                  
               DEFM " 2 info page 2  "                          
               DEFB 132,13,132                                  
               DEFM " 3 info page 3  "                          
               DEFB 132,13,132                                  
               DEFM " D show date    "                          
               DEFB 132,13,132                                  
               DEFM " Z Ant          "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,131                        
               DEFB "!",16,133,130,255                          
                                                                
                                                                
;              Drop down blocks menu data                       
                                                                
                                                                
block_dat:     DEFB 129,"!",16,133,128,13                       
               DEFB 132                                         
               DEFM "      QUIT      "                          
               DEFB 132,13,132                                  
               DEFM " B Goto bottom  "                          
               DEFB 132,13,132                                  
               DEFM " C Copy   block "                          
               DEFB 132,13,132                                  
               DEFM " D Del  markers "                          
               DEFB 132,13,132                                  
               DEFM " E Erase  block "                          
               DEFB 132,13,132                                  
               DEFM " M Move   block "                          
               DEFB 132,13,132                                  
               DEFM " P Print  block "                          
               DEFB 132,13,132                                  
               DEFM " S Save   block "                          
               DEFB 132,13,132                                  
               DEFM " G Grab   block "                          
               DEFB 132,13,132                                  
               DEFM " T Goto the top "                          
               DEFB 132,13,132                                  
               DEFM " F7 End   block "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132                        
               DEFM "     BLOCKS     "                          
               DEFB 132,13,131                                  
               DEFB "!",16,133,130,255                          
                                                                
                                                                
;              The message box data                             
                                                                
                                                                
box_data:      DEFB 129,"!",50,133,128,13                       
               DEFB 132,"!",50,32,132,13                        
               DEFB 131,"!",50,133,130,255                      
                                                                
                                                                
;              Logo message for the top of the screen           
                                                                
                                                                
log:           DEFM " 00:00:00  File "                          
               DEFB 255                                         
log2:          DEFM "  Outwrite! Ver3.0  Page     Line  "       
               DEFM "    Col      File len  "                   
               DEFM "       Insert                  "           
               DEFM "                      "                    
               DEFB 255                                         
                                                                
                                                                
data_m1:       DEFW set_strt                                    
               DEFW reprint_block                               
               DEFW cont_code                                   
               DEFW top_fle                                     
               DEFW s_right                                     
               DEFW reclaim_para                                
               DEFW options                                     
               DEFW margin_form                                 
               DEFW s_left                                      
               DEFW format_para                                 
               DEFW full_screen                                 
               DEFW bot_fl                                      
               DEFW auto_margin                                 
               DEFW exit_menu                                   
                                                                
                                                                
data_m2:       DEFW text_map                                    
               DEFW get_file_name   ; was   save_screen         
               DEFW save_file                                   
               DEFW printer                                     
               DEFW merge                                       
               DEFW load_file                                   
               DEFW font_menu                                   
               DEFW erase_a_file                                
               DEFW dir                                         
               DEFW cleer_file                                  
               DEFW exit_menu                                   
                                                                
data_m3:       DEFW wr_tog                                      
               DEFW view_codes                                  
               DEFW set_tabs                                    
               DEFW d_install                                   
               DEFW beep_tog      ; Was set beep                
               DEFW speed_read                                  
               DEFW tog_just                                    
               DEFW tog_ins                                     
               DEFW dump_cd                                     
               DEFW chng_colour                                 
               DEFW tog_clock                                   
               DEFW exit_menu                                   
                                                                
data_m4:       DEFW ant                                         
               DEFW date                                        
               DEFW info3                                       
               DEFW info2                                       
               DEFW info1                                       
               DEFW address                                     
               DEFW spell_chk                                   
               DEFW dict                                        
               DEFW normal_chars                                
               DEFW search_input                                
               DEFW box_chars                                   
               DEFW con_search                                  
               DEFW exit_menu                                   
                                                                
                                                                
                                                                
data_m5:       DEFW set_end                                     
               DEFW top_fle                                     
               DEFW grab_block                                  
               DEFW save_block                                  
               DEFW printer                                     
               DEFW move_block                                  
               DEFW erase_block                                 
               DEFW delete_blocks                               
               DEFW copy_block                                  
               DEFW bot_fl                                      
               DEFW exit_menu                                   
                                                                
                                                                
m1_len:        DEFB 14                                          
m2_len:        DEFB 11                                          
m3_len:        DEFB 12                                          
m4_len:        DEFB 13                                          
m5_len:        DEFB 11                                          
                                                                
; Address data 85 bytes allowed .                               
; Enter each line, and terminate with a zero as below.          
; The last byte should be a 255.                                
                                                                
                                                                
addr_data:     DEFM "Your address here "                        
               DEFB 0                          ; End line       
               DEFM "with each line "                           
               DEFB 0                                           
               DEFM "terminated with a 0"                       
               DEFB 0                                           
               DEFM "And the final"                             
               DEFB 0                                           
               DEFM "byte a 255      "                          
               DEFB 255                         ; end marker    
                                                                
; This data must stay in order for it to work properly          
; it is found by the routine doing a CPIR.                      
; Any extra data should be put at the end of the list.          
; The labels m1 m2 etc are just for my own use and are not      
; used by the code.                                             
; All data is ended by a 255                                    
                                                                
                                                                
string_data:   DEFB 255                                         
m1:            DEFM " Enter control code or"                    
               DEFB 255                                         
m2:            DEFM " "                                         
               DEFB 255                                         
                                                                
m3:            DEFM "  Clear the file "                         
               DEFM "and Load a new one Y or N ?"               
               DEFB 255                                         
m4:            DEFM "                    Printing "             
               DEFM "page number "                              
               DEFB 255                                         
m5:            DEFM "                 "                         
               DEFB 255                                         
m6:            DEFM " Only one marker set"                      
               DEFB 255                                         
m7:            DEFM "       "                                   
               DEFM "Press N to print next page or E "          
               DEFM "to Return to text.    "                    
               DEFB 255                                         
m8:            DEFM " Do you want to print the file "           
               DEFM "Yes or No "                                
               DEFB 255                                         
m9:            DEFM "Printing Aborted...."                      
               DEFB 255                                         
m10:           DEFM " Printer not on line."                     
               DEFB 255                                         
m11:           DEFM " End of file."                             
               DEFB 255                                         
m12:           DEFM "                                "          
               DEFM "                                "          
               DEFB 255                                         
m13:           DEFM " Clear the text file Y/N ?"                
               DEFB 255                                         
m14:           DEFM "Wrap on "                                  
               DEFB 255                                         
m15:           DEFM "Wrap off"                                  
               DEFB 255                                         
m16:           DEFM " Caps on "                                 
               DEFB 255                                         
m17:           DEFM " Caps off"                                 
               DEFB 255                                         
m18:           DEFM " "                                         
               DEFB 255                                         
m19:           DEFM "Justify on "                               
               DEFB 255                                         
m20:           DEFM "Justify off"                               
               DEFB 255                                         
m21:           DEFM " Word count = "                            
               DEFB 255                                         
m22:           DEFM " Error..File is hidden "                   
               DEFB 255                                         
m23:           DEFM "  Printing block      "                    
               DEFB 255                                         
m24:           DEFM " No screen data present "                  
               DEFB 255                                         
m25:           DEFM " No block to reclaim "                     
               DEFB 255                                         
m26:           DEFM " Marker is already set."                   
               DEFB 255                                         
m27:           DEFM "   Erase block Y or N "                    
               DEFB 255                                         
m28:           DEFM " Not enough memory."                       
               DEFB 255                                         
m29:           DEFM " Block is to large."                       
               DEFB 255                                         
m30:           DEFM " : Press return to exit.."                 
               DEFB 255                                         
m31:           DEFM "off"                                       
               DEFB 255                                         
m32:           DEFM "on "                                       
               DEFB 255                                         
m33:           DEFM "Continuous printing"                       
               DEFB 255                                         
m34:           DEFM "    Another copy Y or N"                   
               DEFB 255                                         
m35:           DEFM " Continuous printing Y or N  "             
               DEFB 255                                         
m36:           DEFM " Press F0 to exit."                        
               DEFB 255                                         
                                                                
m37:           DEFM "L="                                        
               DEFB 255                                         
m38:           DEFM "R="                                        
               DEFB 255                                         
                                                                
m39:           DEFM "No control code present"                   
               DEFB 255                                         
m40:           DEFM "Invalid ASCII character"                   
               DEFB 255                                         
m41:           DEFM "Only 20 codes alowed"                      
               DEFB 255                                         
m42:           DEFM "Number to big"                             
               DEFB 255                                         
m43:           DEFM " Illegal Move operation "                  
               DEFB 255                                         
                                                                
m44:           DEFM "How many copies : "                        
               DEFB 255                                         
                                                                
m45:           DEFM " Not found "                               
               DEFB 255                                         
                                                                
m46:           DEFM " "                                         
               DEFB 255                                         
                                                                
m47:           DEFM " Press N for next occurence or RETURN"     
               DEFM " for text"                                 
               DEFB 255                                         
                                                                
m48:           DEFM " Checking : "                              
               DEFB 255                                         
                                                                
m49:           DEFM " No words on this line  "                  
               DEFB 255                                         
                                                                
m50:           DEFM " No dictionary present  "                  
               DEFB 255                                         
                                                                
                                                                
m51:           DEFM " not found "                               
               DEFB 255                                         
                                                                
                                                                
m52:           DEFM " is correct "                              
               DEFB 255                                         
                                                                
m53:           DEFM "Select an alphabet character A to Z"       
               DEFB 255                                         
                                                                
                                                                
                                                                
                                                                
                                                                
; These are the control codes accepted by the program           
; These codes must stay in order. The code indexes into         
; these codes and uses the number in BC to index into the main  
; set at nlq_on....                                             
                                                                
cont_data:     DEFM "NBISHUOMnbishuoEeDdCcPpRrWw`#1234567890Ll" 
                                                                
                                                                
; This data is the control codes used in outwrite any other code
; with bit 7 set will be removed.                               
                                                                
poke_con_data: DEFB 207,239,213,245,206,238  ; O o U u N n      
               DEFB 194,226,201,233,211,243  ; B b I i S s      
               DEFB 196,228,210,205,197,229  ; D d R M E e      
               DEFB 200,232,195,227,208,240  ; H h C c P p      
               DEFB 242,177,178,215,247,179  ; r 1 2 W w 3      
               DEFB 180,181,182,183,184,185  ; 4 5 6 7 8 9      
               DEFB 176,204,236              ; 0 L l            
                                                                
; Printer control data must stay in order...                    
                                                                
                                                                
nlq_on:        DEFB 4,32,27,120,49,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0,0                                       
bold_on:       DEFB 5,32,27,69,27,71,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0,0                                       
italics_on:    DEFB 3,32,27,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
subscript_on:  DEFB 4,32,27,83,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0                                         
double_h_on:   DEFB 5,32,27,126,49,49,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0,0                                       
underline_on:  DEFB 4,32,27,45,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0                                         
over_scr_on:   DEFB 4,32,27,95,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0                                         
master_reset:  DEFB 6,32,27,64,27,108,8,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0,0                                       
nlq_off:       DEFB 4,27,120,48,32,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0,0                                       
bold_off:      DEFB 5,27,70,27,72,32,0,0,0,0,0,0,0,0,0,0,0,0,0  
               DEFB 0,0                                         
italics_off:   DEFB 3,27,53,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
subscript_off: DEFB 3,27,84,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
double_h_off:  DEFB 5,27,126,49,48,32,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0,0                                       
underline_off: DEFB 4,27,45,48,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0                                         
overscore_off: DEFB 4,27,95,48,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0                                         
emphasised_on: DEFB 3,32,27,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
emphasised_off:DEFB 3,27,70,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
double_strk_on:DEFB 3,32,27,71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
double_strk_of:DEFB 3,27,72,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
compresed_on:  DEFB 2,32,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0     
               DEFB 0,0                                         
compresed_of:  DEFB 2,18,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0     
               DEFB 0,0                                         
proport_on:    DEFB 4,32,27,112,49,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0,0                                       
proport_of:    DEFB 4,27,112,48,32,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0,0                                       
reverse_on:    DEFB 9,32,27,126,56,49,27,126,50,49,0,0,0,0,0    
               DEFB 0,0,0,0,0,0                                 
reverse_off:   DEFB 4,27,126,50,48,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0,0                                       
d_width_on:    DEFB 5,32,27,126,49,51,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0,0                                       
d_width_of:    DEFB 5,27,126,49,48,32,0,0,0,0,0,0,0,0,0,0,0,0   
               DEFB 0,0,0                                       
pound_char:    DEFB 4,27,82,3,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
hash_char:     DEFB 4,27,82,0,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0    
               DEFB 0,0                                         
user_def_1:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_2:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_3:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_4:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_5:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_6:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_7:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_8:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_9:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
user_def_0:    DEFB 1,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
                                                                
                                                                
                                                                
; Default Tab settings every 5 positions                        
; 64 bytes of data will be poked by the set_tabs routine        
; 2 bytes spare for safety.....                                 
                                                                
                                                                
tab_dat:       DEFM "    1    1    1    1    1    1   "         
               DEFM " 1    1    1    1    1    1      "         
                                                                
;        Keyboard table for the scan routine                    
                                                                
                                                                
kbtab:         DEFB 0,253,7,192,12                              
               DEFB 6,201,198,195                               
               DEFB 88,46,58,34,43                              
               DEFB 252,200,197,194                             
               DEFB 88,44,59,61,45                              
               DEFB 32,199,196,193                              
               DEFB 9,98,104,121,54                             
               DEFB 53,116,103,118                              
               DEFB 8,110,106,117,55                            
               DEFB 52,114,102,99,10                            
               DEFB 109,107,105,56                              
               DEFB 51,101,100,120                              
               DEFB 11,88,108,111,57,50                         
               DEFB 119,115,122,88,32                           
               DEFB 13,112,48,49,113,97                         
               DEFB 92,7,202,14,6,211                           
               DEFB 208,205,88,46,58,127                        
               DEFB 42,252,210,207,204                          
               DEFB 88,44,59,95,47,32                           
               DEFB 209,206,203,9,66,72                         
               DEFB 89,38,37,84,71,86,8                         
               DEFB 78,74,85,39,36,82,70                        
               DEFB 67,10,77,75,73,40,35                        
               DEFB 69,68,88,11,88,76,79                        
               DEFB 41,64,87,83,90,88,32                        
               DEFB 13,80,126,33,81,65                          
               DEFB 254,15,48,14,6,57,54                        
               DEFB 51,88,62,42,207,42                          
               DEFB 252,56,53,50,88,60                          
               DEFB 43,95,47,32,55,52,49                        
               DEFB 9,158,94,157,134,133                        
               DEFB 93,125,151,8,164,45                         
               DEFB 129,135,132,91,123                          
               DEFB 168,10,165,43,165                           
               DEFB 128,131,130,156,63                          
               DEFB 11,88,96,148,124,130                        
               DEFB 62,148,63,88,255,13                         
               DEFB 187,126,129,60,177,0                        
               DEFB 0,0,0,0,0,0,0,0,0                           
                                                                
                                                                
;     Data to convert an 8 bit char set to 16 bit....           
                                                                
                                                                
ctable:        DEFB 0,0,0,3,0,12,0,15,0,48                      
               DEFB 0,51,0,60,0,63,0,192,0,195                  
               DEFB 0,204,0,207,0,240,0,243,0,252               
               DEFB 0,255,3,0,3,3,3,12,3,15                     
               DEFB 3,48,3,51,3,60,3,63,3,192                   
               DEFB 3,195,3,204,3,207,3,240,3,243               
               DEFB 3,252,3,255,12,0,12,3,12,12                 
               DEFB 12,15,12,48,12,51,12,60,12,63               
               DEFB 12,192,12,195,12,204,12,207,12,240          
               DEFB 12,243,12,252,12,255,15,0,15,3              
               DEFB 15,12,15,15,15,48,15,51,15,60               
               DEFB 15,63,15,192,15,195,15,204,15,207           
               DEFB 15,240,15,243,15,252,15,255,48,0            
               DEFB 48,3,48,12,48,15,48,48,48,51                
               DEFB 48,60,48,63,48,192,48,195,48,204            
               DEFB 48,207,48,240,48,243,48,252,48,255          
               DEFB 51,0,51,3,51,12,51,15,51,48                 
               DEFB 51,51,51,60,51,63,51,192,51,195             
               DEFB 51,204,51,207,51,240,51,243,51,252          
               DEFB 51,255,60,0,60,3,60,12,60,15                
               DEFB 60,48,60,51,60,60,60,63,60,192              
               DEFB 60,195,60,204,60,207,60,240,60,243          
               DEFB 60,252,60,255,63,0,63,3,63,12               
               DEFB 63,15,63,48,63,51,63,60,63,63               
               DEFB 63,192,63,195,63,204,63,207,63,240          
               DEFB 63,243,63,252,63,255,192,0,192,3            
               DEFB 192,12,192,15,192,48,192,51,192,60          
               DEFB 192,63,192,192,192,195,192,204,192          
               DEFB 207,192,240,192,243,192,252                 
               DEFB 192,255,195,0                               
               DEFB 195,3,195,12,195,15,195,48,195,51           
               DEFB 195,60,195,63,195,192,195,195,195           
               DEFB 204                                         
               DEFB 195,207,195,240,195,243,195,252             
               DEFB 195,255                                     
               DEFB 204,0,204,3,204,12,204,15,204,48            
               DEFB 204,51,204,60,204,63,204,192,204            
               DEFB 195                                         
               DEFB 204,204,204,207,204,240,204,243,204         
               DEFB 252                                         
               DEFB 204,255,207,0,207,3,207,12,207,15           
               DEFB 207,48,207,51,207,60,207,63,207,192         
               DEFB 207,195,207,204,207,207,207,240             
               DEFB 207,243                                     
               DEFB 207,252,207,255,240,0,240,3,240,12          
               DEFB 240,15,240,48,240,51,240,60,240,63          
               DEFB 240,192,240,195,240,204,240,207             
               DEFB 240,240                                     
               DEFB 240,243,240,252,240,255,243,0,243,3         
               DEFB 243,12,243,15,243,48,243,51,243,60          
               DEFB 243,63,243,192,243,195,243,204,243          
               DEFB 207                                         
               DEFB 243,240,243,243,243,252,243,255             
               DEFB 252,0                                       
               DEFB 252,3,252,12,252,15,252,48,252,51           
               DEFB 252,60,252,63,252,192,252,195               
               DEFB 252,204                                     
               DEFB 252,207,252,240,252,243,252,252             
               DEFB 252,255                                     
               DEFB 255,0,255,3,255,12,255,15,255,48            
               DEFB 255,51,255,60,255,63,255,192,255,195        
               DEFB 255,204,255,207,255,240,255,243,255         
               DEFB 252,255,255                                 
                                                                
                                                                
; This is the menu border data and is poked into ram after      
; the 8 bit set.                                                
                                                                
;              Block marker graphic character 127               
                                                                
bord_data:     DEFB 255,195,195,195,195,195,195,255             
                                                                
                                                                
;              menu frame graphics data                         
;                                             position    char  
                                                                
               DEFB 0,0,252,4,4,228,36,36   ; Top right    128  
               DEFB 0,0,63,32,32,39,36,36   ; Top left     129  
               DEFB 36,36,228,4,4,252,0,0   ; Bottom right 130  
               DEFB 36,36,39,32,32,63,0,0   ; Bottom left  131  
               DEFB 36,36,36,36,36,36,36,36 ; down         132  
               DEFB 0,0,255,0,0,255,0,0     ; across       133  
                                                                
                                                                
init_data:     DEFB 125,0,125,0,24,0,13,0,0                     
                                                                
the_end:       DEFB 0                                           
                                                                
                                                                
; FROM 16384  TO 16762 ARE SYSTEM VARIABLES                     
; FROM 16999  DOWNWARDS IS THE STACK                            
; FROM 17000  TO 20198 ARE 6 CHARACTER SETS                     
                                                                
                                                                
                                                                
               ORG  21740                                       
               DUMP 4,5356                                      
                                                                
                                                                
; ptime called on every interupt of the main processor          
; this will be every 50th of a second.                          
                                                                
                                                                
                                                                
ptime:         LD   (cstack_var),SP ; Store stack pointer       
               LD   SP,cstack       ; LD SP, clocks stack       
               PUSH HL              ; Save all registers        
               PUSH DE                                          
               PUSH BC                                          
               PUSH AF                                          
               LD   A,(t_count)     ; A = t_count               
               INC  A               ; increment by 1            
               LD   (t_count),A     ; store result              
               CP   50              ; is it 50                  
               JR   NZ,print_time   ; no so just print the time 
               LD   A,0             ; yes so reset to zero      
               LD   (t_count),A     ; and store result          
               LD   A,(seconds)     ; now increment seconds but 
               INC  A               ; if seconds = 59 reset to 0
               CP   60              ; and then check the minutes
               JR   Z,reset_sec     ; if seconds not 59 then    
               LD   (seconds),A     ; just print the time       
               JR   print_time                                  
reset_sec:     LD   A,0             ; as above reset seconds    
               LD   (seconds),A                                 
               CALL sound                                       
               LD   A,(minute)      ; seconds were 59 so check  
               INC  A               ; the minutes               
               CP   60              ; if minutes = 59 then check
               JR   NZ,time_ok      ; the hours                 
               LD   A,(hours)       ; if hours reach 24 then    
               INC  A               ; reset to zero else just   
               CP   24              ; print the time.           
               JR   Z,set_hour                                  
               LD   (hours),A       ; Hours not 24 so +1        
               LD   A,0             ; set a for the minute      
               JR   time_ok                                     
                                                                
                                                                
set_hour:      LD   A,0             ; hours were 23 so set to 0 
               LD   (hours),A                                   
time_ok:       LD   (minute),A      ; and the minutes           
print_time:    LD   A,(clock_var)                               
               OR   A                                           
               JP   NZ,exit_clock                               
                                                                
                                                                
                                                                
               LD   HL,32770        ; set the printing position 
               LD   (tposn),HL      ; store in variable tposn   
               LD   A,(hours)       ; Get current hour and print
               CALL tpnum           ; Convert real num to ASCII 
               LD   A,":"           ; print the separator       
               CALL tprint_a        ; Print separator           
                                                                
               LD   A,(minute)      ; print the current minute  
               CALL tpnum           ; Convert to ASCII          
               LD   A,":"           ; separator again           
               CALL tprint_a                                    
               LD   A,(seconds)     ; current seconds           
               CALL tpnum           ; Convert to ASCII          
exit_clock:    NOP                                              
               POP  AF              ; retreive all saved regs   
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               LD   SP,(cstack_var) ; get original stack        
               RET                  ; REt to normal interupt    
                                                                
                                                                
; Main clock printing routine                                   
; tposn will be updated for the next character to be printed.   
                                                                
                                                                
tprint_a:      PUSH HL             ; save HL until exit         
               LD   DE,chars2-512  ; point at character         
               LD   L,A            ; get hl = character         
               LD   H,0                                         
               ADD  HL,HL          ; index into char set        
               ADD  HL,HL          ; = hl+hl                    
               ADD  HL,HL                                       
               ADD  HL,HL                                       
               ADD  HL,DE                                       
               EX   DE,HL          ; get pixel data into DE     
               LD   HL,(tposn)     ; Set printing position      
               PUSH HL             ; Save print position        
               IN   A,(251)        ; page 3 position            
               PUSH AF             ; save for later             
               IN   A,(252)        ; current screen in use      
               AND  31             ; remove unwanted bits       
               OUT  (251),A        ; place in page 3 position   
                                   ; = 32768                    
               LD   B,8            ; 8 bytes to poke to screen  
tc_char_loop:  LD   A,(DE)         ; get a = pixel byte         
               XOR  255            ; normal background colour   
               LD   (HL),A         ; put byte into screen       
               INC  DE             ; inc to next data byte      
               INC  HL             ; inc to next screen position
               LD   A,(DE)         ; put byte into screen       
               XOR  255            ; normal background          
               LD   (HL),A         ; poke byte                  
               INC  DE             ; inc to next position       
               LD   A,127          ; inc to next line for pix   
               ADD  A,L            ; add to L and get into HL   
               LD   L,A            ; JR if HL overflows         
               JR   NC,tn_cary     ; A went past 255 when + to L
               INC  H              ; A overflowed so inc H      
tn_cary:       DJNZ tc_char_loop   ; loop unless B = 0          
               POP  AF             ; switch screen out          
               OUT  (251),A        ; and normal ram in page 3   
               POP  HL             ; original start of char     
               INC  L              ; inc to next char position  
               INC  L              ; 16 pixels so inc twice     
               LD   (tposn),HL     ; store for next char        
               POP  HL             ; HL preserved on input      
               RET                 ; ret to calling routine     
                                                                
                                                                
                                                                
                                                                
; Convert real number into ASCII for the printing routine       
; Digits are entered in HL. in this particular case             
; L = number to convert H = zero                                
                                                                
                                                                
tpnum:         LD   L,A        ; L = A. A = real number         
               LD   H,0        ; H = zero . not printing > 9    
               LD   C,0        ; C = 0 to print leading zeros   
               LD   DE,10      ; DE = base count                
               XOR  A          ; Initialise A to zero           
tmult2:        INC  A          ; Inc A on each pass through loop
               SBC  HL,DE      ; Subtract DE from HL. keep going
               JR   NC,tmult2  ; round loop until HL overflows  
               ADD  HL,DE      ; Add HL to DE to retreive last  
               CP   C          ; calc.  Check against C for zero
               JR   Z,tmult3   ; Only check on first pass       
               DEC  C          ; C must be 255 now              
               ADD  47         ; add 47 to A value. A was inced 
               CALL tprint_a   ; Now print ASCII char from A    
tmult3:        LD   A,L        ; Value of L into A add 48 to it 
               ADD  48         ; and print ASCII char           
               CALL tprint_a                                    
               RET             ; Exit to calling routine        
                                                                
; ............................................................  
                                                                
; Code for the ant routine starts here                          
                                                                
                                                                
                                                                
ant:           PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               PUSH AF                                          
                                                                
                                                                
                                                                
                                                                
               CALL exit_box                                    
do_again:      CALL draw_box                                    
               LD   HL,m54                                      
               CALL prstr_2                                     
               LD   HL,flags                                    
speed_loop:    RES  5,(HL)                                      
               LD   A,(lastk)                                   
               CP   13                                          
               JP   Z,exit_ant                                  
               CP   "s"                                         
               JP   Z,slow_ant                                  
               CP   "m"                                         
               JP   Z,medium_ant                                
               CP   "f"                                         
               JP   Z,fast_ant                                  
               JR   speed_loop                                  
                                                                
slow_ant:      LD   HL,5000                                     
a_speed:       LD   (ant_speed),HL                              
               JP   start_ant                                   
                                                                
medium_ant:    LD   HL,1000                                     
               JR   a_speed                                     
                                                                
fast_ant:      LD   HL,1                                        
               JR   a_speed                                     
                                                                
                                                                
                                                                
                                                                
                                                                
;  .........................................                    
                                                                
start_ant:     CALL clear_screen                                
               CALL screen_in                                   
                                                                
               LD   B,128                                       
               LD   HL,32768+2048                               
               LD   A,15                                        
pokeloop:      LD   (HL),A                                      
               INC  HL                                          
               DJNZ pokeloop                                    
                                                                
                                                                
               LD   B,155                                       
               LD   HL,32768+2048                               
               LD   DE,128                                      
               OR   A                                           
               ADC  HL,DE                                       
poke2lp:       LD   A,16                                        
               LD   (HL),A                                      
               OR   A                                           
               ADC  HL,DE                                       
               DJNZ poke2lp                                     
                                                                
                                                                
               LD   HL,57216                                    
               LD   B,128                                       
               LD   A,20                                        
poke3lp:       LD   (HL),A                                      
               INC  HL                                          
               DJNZ poke3lp                                     
                                                                
                                                                
                                                                
               LD   DE,128                                      
new_ant:       LD   HL,(sposn)                                  
                                                                
                                                                
               JP   aup                                         
aleft:         CALL apoke                                       
               DEC  HL                                          
               LD   A,(HL)                                      
               CP   0                                           
               JP   Z,aup                                       
adown:         CALL apoke                                       
ddd1:          OR   A                                           
               ADC  HL,DE                                       
               LD   A,(HL)                                      
               CP   0                                           
               JP   Z,aleft                                     
dleft:         CALL apoke                                       
ddd2:          INC  HL                                          
               LD   A,(HL)                                      
               CP   0                                           
               JP   Z,adown                                     
aup:           CALL apoke                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   A,(HL)                                      
               CP   0                                           
               JP   Z,dleft                                     
               JP   aleft                                       
                                                                
d1:            POP  BC                                          
               JP   ddd1                                        
d2:            POP  BC                                          
               INC  H                                           
               JP   ddd2                                        
                                                                
                                                                
                                                                
                                                                
apoke:         LD   BC,(ant_speed) ;     from 1 to 65535        
aploop:        DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,aploop                                   
                                                                
                                                                
               LD   A,(HL)                                      
               CP   15                                          
               JP   Z,d1                                        
               CP   16                                          
               JP   Z,d2                                        
               CP   20                                          
               JR   NZ,OK                                       
               RES  6,H                                         
OK:            XOR  254                                         
               LD   (HL),A                                      
                                                                
                                                                
; Wait for a keypress                                           
; RETURN moves the ant to the next step.                        
                                                                
               PUSH HL                                          
               LD   HL,flags                                    
kloop:         RES  5,(HL)                                      
               LD   A,(lastk)                                   
               CP   13                                          
               JP   Z,aexit                                     
               CP   7      ; edit key                           
               JR   Z,dif_ant                                   
               POP  HL                                          
               RET                                              
                                                                
                                                                
dif_ant:       POP  HL                                          
               POP  HL                                          
               EX   AF,AF'                                      
               OUT  (251),A                                     
               JP   do_again                                    
                                                                
               CALL clear_screen                                
aexit:         POP  HL        ;   register pushed               
               POP  HL        ;   return address after call     
                              ;   to apoke                      
               EX   AF,AF'                                      
               OUT  (251),A                                     
exit_ant:      LD   A,0                                         
               LD   (lastk),A                                   
               POP  AF                                          
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               JP   exit_box    ; Return to outwrite            
                                                                
                                                                
                                                                
clear_screen:  CALL screen_in                                   
               LD   HL,34816                                    
               LD   DE,34817                                    
               LD   BC,22528                                    
               LD   A,0                                         
               LD   (HL),A                                      
               LDIR                                             
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
                                                                
                                                                
                                                                
m54:           DEFM " The Ant : Select Speed F.M.S "            
               DEFM "RET to Quit "                              
               DEFB 255                                         
                                                                
; The end of the ant routine                                    
; ...................................................           
                                                                
; ...................................................           
; Start of the calendar routine.                                
; From a given input in day,month and year                      
                                                                
                                                                
date:          PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               PUSH AF                                          
               CALL check_input                                 
                                                                
               CALL exit_box                                    
new_date:      LD   A,0                                         
               LD   (lastk),A                                   
               CALL cvdays    ; Get the first day of the month  
                              ; into the L register             
                              ; using the data input to         
                              ; month and year                  
                                                                
                                                                
               LD   A,L                                         
               LD   (day),A   ; Store first day of the month    
                                                                
                                                                
;  Now print the calendar using the data in day month and year  
;  work out how long the month is and print calendar bottom     
                                                                
                                                                
               CALL draw_cal                                    
                                                                
                                                                
               LD   HL,flags                                    
date_loop:     RES  5,(HL)                                      
               LD   A,(lastk)                                   
               CP   13                                          
               JR   Z,exit_date                                 
               CP   11                                          
               JP   Z,next_year                                 
               CP   10                                          
               JP   Z,last_year                                 
               CP   8                                           
               JP   Z,last_month                                
               CP   9                                           
               JP   Z,next_month                                
               JR   date_loop                                   
                                                                
                                                                
exit_date:     LD   A,0                                         
               LD   (lastk),A                                   
                                                                
               POP  AF                                          
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               JP   exit_box                                    
                                                                
                                                                
                                                                
draw_cal:      LD   A,1                                         
               LD   (crsr_flag),A                               
               LD   HL,36876+512                                
               LD   DE,cal_data                                 
               CALL print_menu                                  
               LD   A,(month)        ; 1 to 12                  
               DEC  A                                           
               LD   E,A              ; DE holds month           
               LD   D,0                                         
               LD   HL,mtab          ; length of each month     
               OR   A                                           
               ADC  HL,DE            ; HL points to len of month
               LD   A,(HL)           ; A holds 28 29 30 or 31   
               CP   28                                          
               JR   Z,cal_1                                     
               CP   29                                          
               JR   Z,cal_2                                     
               CP   30                                          
               JR   Z,cal_3                                     
               JR   cal_4                                       
                                                                
cal_1:         LD   DE,cal_1_data                               
               JR   do_bottom                                   
cal_2:         LD   DE,cal_2_data                               
               JR   do_bottom                                   
cal_3:         LD   DE,cal_3_data                               
               JR   do_bottom                                   
cal_4:         LD   DE,cal_4_data                               
                                                                
do_bottom:     LD   HL,(sposn2)                                 
               CALL print_menu                                  
               CALL inverse                                     
               LD   HL,37904+512                                
               LD   (sposn2),HL                                 
                                                                
; now print the month on the calendar                           
                                                                
               LD   HL,jan                                      
               LD   A,(month)                                   
               CP   1                                           
               JR   Z,print_month                               
               DEC  A                                           
               LD   B,A                                         
index:         INC  HL                                          
               LD   A,(HL)                                      
               CP   255                                         
               JR   NZ,index                                    
               DJNZ index                                       
               INC  HL                                          
                                                                
                                                                
print_month:   CALL prstr_2                                     
               LD   A,(year)                                    
               LD   E,A                                         
               LD   D,0                                         
               LD   HL,1900                                     
               OR   A                                           
               ADC  HL,DE                                       
               CALL pnum                                        
               LD   HL,mtab+1                                   
               LD   A,(HL)                                      
               CP   29                                          
               JR   NZ,do_days                                  
               LD   HL,leap                                     
               CALL prstr_2                                     
                                                                
                                                                
do_days:       LD   HL,40464+1024                               
               LD   (sposn2),HL                                 
               LD   A,(day)                                     
               LD   HL,DAY-1                                    
                                                                
               LD   B,A                                         
               LD   C,0                                         
next_letr:     INC  C                                           
next_letter:   INC  HL                                          
                                                                
               LD   A,(HL)                                      
               CP   32                                          
               JR   NZ,next_letter                              
               LD   A,B                                         
               CP   C                                           
               JR   NZ,next_letr                                
                                                                
print_days:    LD   B,28                                        
               INC  HL                                          
DAY_loop:      LD   A,(HL)                                      
               PUSH HL                                          
               PUSH BC                                          
               CALL pchar2_2                                    
               POP  BC                                          
               POP  HL                                          
               INC  HL                                          
               DJNZ DAY_loop                                    
               RET                                              
                                                                
DAY:           DEFM " MON TUE WED THU FRI SAT SUN"              
               DEFM " MON TUE WED THU FRI SAT SUN "             
                                                                
                                                                
leap:          DEFM "   Leap Year"                              
               DEFB 255                                         
                                                                
jan:           DEFM "JANUARY "                                  
               DEFB 255                                         
               DEFM "FEBRUARY "                                 
               DEFB 255                                         
               DEFM "MARCH "                                    
               DEFB 255                                         
               DEFM "APRIL "                                    
               DEFB 255                                         
               DEFM "MAY "                                      
               DEFB 255                                         
               DEFM "JUNE "                                     
               DEFB 255                                         
               DEFM "JULY "                                     
               DEFB 255                                         
               DEFM "AUGUST "                                   
               DEFB 255                                         
               DEFM "SEPTEMBER "                                
               DEFB 255                                         
               DEFM "OCTOBER "                                  
               DEFB 255                                         
               DEFM "NOVEMBER "                                 
               DEFB 255                                         
               DEFM "DECEMBER "                                 
               DEFB 255                                         
                                                                
cal_data:      DEFB 129,"!",29,133,128,13                       
               DEFB 132,"!",29,32,132,13                        
               DEFB 131,"!",29,133,130,13                       
                                                                
               DEFB 129,"!",29,133,128,13                       
               DEFB 132                                         
               DEFM "                             "             
               DEFB 132,13,132                                  
               DEFM "   1   2   3   4   5   6   7 "             
               DEFB 132,13,132                                  
               DEFM "   8   9  10  11  12  13  14 "             
               DEFB 132,13,132                                  
               DEFM "  15  16  17  18  19  20  21 "             
               DEFB 132,13,132                                  
               DEFM "  22  23  24  25  26  27  28 "             
               DEFB 132,13,255                                  
                                                                
                                                                
cal_1_data:    DEFB 132                                         
               DEFM "                             "             
               DEFB 132,13                                      
               DEFB 131,"!",29,133,130,255                      
                                                                
cal_2_data:    DEFB 132                                         
               DEFM "  29                         "             
               DEFB 132,13                                      
               DEFB 131,"!",29,133,130,255                      
                                                                
cal_3_data:    DEFB 132                                         
               DEFM "  29  30                     "             
               DEFB 132,13                                      
               DEFB 131,"!",29,133,130,255                      
                                                                
                                                                
cal_4_data:    DEFB 132                                         
               DEFM "  29  30  31                 "             
               DEFB 132,13                                      
               DEFB 131,"!",29,133,130,255                      
                                                                
                                                                
mtab_dat:      DEFB 31,28,31,30      ; jan feb mar apr          
               DEFB 31,30,31,31      ; may jun jul aug          
               DEFB 30,31,30,31      ; sep oct nov dec          
                                                                
                                                                
cvdays:        LD   HL,mtab_dat                                 
               LD   DE,mtab                                     
               LD   BC,12                                       
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
                                                                
                                                                
               LD   A,(year)                                    
               LD   C,A                                         
               LD   A,(month)                                   
               LD   B,A                                         
               LD   A,1   ; always 1 for the first of the month 
                                                                
                                                                
               LD   H,0                                         
               LD   L,A                                         
               LD   DE,mtab+1                                   
               LD   A,C                                         
               AND  3                                           
               LD   A,28                                        
               JR   NZ,set_feb                                  
               INC  A                                           
set_feb:       LD   (DE),A                                      
                                                                
               DEC  DE                                          
               DEC  C                                           
                                                                
               LD   A,C                                         
               RRA                                              
               RRA                                              
               AND  63                                          
               ADD  A,L                                         
               LD   L,A                                         
                                                                
               DEC  B                                           
               JR   Z,cyrs                                      
                                                                
dymnth:        LD   A,(DE)                                      
               INC  DE                                          
               ADD  A,L                                         
               LD   L,A                                         
               JR   NC,dymtst                                   
               INC  H                                           
dymtst:        DJNZ dymnth                                      
                                                                
cyrs:          LD   A,C                                         
               LD   DE,365                                      
               AND  A                                           
                                                                
dyyrs:         RRA                                              
               JR   NC,nxtplc                                   
               ADD  HL,DE                                       
                                                                
nxtplc:        EX   DE,HL                                       
               ADD  HL,HL                                       
               EX   DE,HL                                       
               OR   A                                           
               JR   NZ,dyyrs                                    
                                                                
               LD   DE,7                                        
               LD   BC,0                                        
               OR   A                                           
wk_loop:       SBC  HL,DE                                       
               JR   C,add_rem                                   
               INC  BC                                          
               JR   wk_loop                                     
                                                                
add_rem:       ADC  HL,DE                                       
               LD   A,L                                         
               RET                                              
                                                                
;  L holds first day of the month                               
                                                                
                                                                
                                                                
next_year:     LD   A,(year)                                    
               CP   179                                         
               JP   Z,new_date                                  
               INC  A                                           
               LD   (year),A                                    
               JP   new_date                                    
                                                                
last_year:     LD   A,(year)                                    
               CP   1                                           
               JP   Z,new_date                                  
               DEC  A                                           
               LD   (year),A                                    
               JP   new_date                                    
                                                                
last_month:    LD   A,(month)                                   
               CP   1                                           
               JR   NZ,last_m                                   
               LD   A,(year)                                    
               CP   1                                           
               JP   Z,new_date                                  
               DEC  A                                           
               LD   (year),A                                    
               LD   A,12                                        
               JR   last_yr                                     
last_m:        DEC  A                                           
last_yr:       LD   (month),A                                   
               JP   new_date                                    
                                                                
next_month:    LD   A,(month)                                   
               CP   12                                          
               JR   NZ,nxt_mnth                                 
               LD   A,(year)                                    
               CP   179                                         
               JP   Z,new_date                                  
               INC  A                                           
               LD   (year),A                                    
               LD   A,1                                         
               JR   nx_mn                                       
nxt_mnth:      INC  A                                           
nx_mn:         LD   (month),A                                   
               JP   new_date                                    
                                                                
                                                                
; Check that the month is between 1 and 12                      
; also that year is between 1 and 179 = 1901 to 2079            
                                                                
                                                                
                                                                
check_input:   LD   A,(month)                                   
               CP   1                                           
               JR   C,input_error                               
               CP   13                                          
               JR   NC,input_error                              
               LD   A,(year)                                    
               CP   1                                           
               JR   C,input_error                               
               CP   180                                         
               JR   NC,input_error                              
               RET                                              
                                                                
                                                                
input_error:   POP  HL              ; pop return address        
               CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,inp_er                                   
               CALL prstr_2                                     
               LD   HL,flags                                    
               RES  5,(HL)                                      
ex_loop:       BIT  5,(HL)                                      
               JR   Z,ex_loop                                   
               JP   exit_date                                   
                                                                
                                                                
inp_er:        DEFM " Error : Date out of range "               
               DEFM " Press any key"                            
               DEFB 255                                         
                                                                
                                                                
set_time:      DI                                               
               LD   A,0                                         
               LD   (t_count),A                                 
               LD   A,(lline)                                   
               CP   24                                          
               JP   NC,time_error                               
               LD   (hours),A                                   
               LD   A,(col)                                     
               INC  A                                           
               CP   60                                          
               JR   NC,time_error                               
               LD   (minute),A                                  
               LD   A,0                                         
               LD   (seconds),A                                 
               EI                                               
               JP   exit_box                                    
                                                                
                                                                
                                                                
time_error:    CALL exit_box                                    
               CALL draw_box                                    
               EI                                               
               LD   HL,tm_err                                   
               CALL prstr_2                                     
               LD   HL,flags                                    
               RES  5,(HL)                                      
tm_loop:       BIT  5,(HL)                                      
               JR   Z,tm_loop                                   
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
tm_err:        DEFM " Time out of range : Press a key"          
               DEFB 255                                         
                                                                
                                                                
                                                                
; Convert real number into ASCII and poke the DOS with the      
; time                                                          
; Digits are entered in HL. in this particular case             
; L = number to convert H = zero                                
                                                                
poke_dos:      DI                                               
               IN   A,(251)                                     
               PUSH AF                                          
               LD   A,DOS_PAGE   ; Page Dos into page 3 slot    
               OUT  (251),A                                     
               LD   A,(hours)                                   
               LD   DE,33408 ; Dos time var start               
               CALL Dpnum                                       
               LD   A,":"    ; Poke in the separator            
               INC  DE                                          
               LD   (DE),A                                      
               INC  DE                                          
               LD   A,(minute)                                  
               CALL Dpnum                                       
               LD   A,":"    ; Poke in 2nd separator            
               INC  DE                                          
               LD   (DE),A                                      
               INC  DE                                          
               LD   A,(seconds)                                 
               CALL Dpnum                                       
               POP  AF                                          
               OUT  (251),A                                     
               EI                                               
               RET                                              
                                                                
                                                                
Dpnum:         PUSH DE         ; address in dos to poke         
               LD   L,A        ; L = A. A = real number         
               LD   H,0        ; H = zero . not printing > 9    
               LD   C,0        ; C = 0 to print leading zeros   
               LD   DE,10      ; DE = base count                
               XOR  A          ; Initialise A to zero           
Dmult2:        INC  A          ; Inc A on each pass through loop
               SBC  HL,DE      ; Subtract DE from HL. keep going
               JR   NC,Dmult2  ; round loop until HL overflows  
               ADD  HL,DE      ; Add HL to DE to retreive last  
               CP   C          ; calc.  Check against C for zero
               JR   Z,Dmult3   ; Only check on first pass       
               DEC  C          ; C must be 255 now              
               ADD  47         ; add 47 to A value. A was inced 
               POP  DE         ; Retreive Dos Var address       
               LD   (DE),A     ; Poke Dos with ASCII character  
               INC  DE         ; inc to next var                
Dmult3:        LD   A,L        ; Value of L into A add 48 to it 
               ADD  48         ; and poke Dos with ASCII char   
               LD   (DE),A                                      
               RET             ; Exit to calling routine        
                                                                
                                                                
                                                                
; Output the colour information to the 16 ports                 
                                                                
                                                                
colour:        LD   HL,c_table       ; bottom of the table      
               LD   B,16                                        
               LD   C,248                                       
               OTDR                                             
               LD   A,(col_1)                                   
               LD   (PAL),A                                     
               RET                                              
                                                                
                                                                
chng_colour:   CALL exit_box                                    
               LD   HL,36864+526                                
               LD   DE,colour_box                               
               CALL print_menu                                  
                                                                
                                                                
               LD   HL,52238                                    
               LD   DE,cbox_data                                
               CALL print_menu                                  
                                                                
                                                                
               CALL inverse                                     
col_again:     LD   HL,53264                                    
               LD   (sposn2),HL                                 
               LD   HL,col_1_num                                
               CALL prstr_2                                     
               LD   A,(col_1)                                   
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
               LD   HL,53306                                    
               LD   (sposn2),HL                                 
               LD   HL,col_2_num                                
               CALL prstr_2                                     
               LD   A,(col_4)                                   
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
                                                                
co_l_loop:     CALL keypress                                    
               CP   13                                          
               JP   Z,exit_col                                  
               CP   11                                          
               JP   Z,col_1_up                                  
               CP   10                                          
               JP   Z,col_1_down                                
               CP   8                                           
               JP   Z,col_4_down                                
               CP   9                                           
               JP   Z,col_4_up                                  
               CP   "1"                                         
               JR   Z,black_white                               
               CP   "2"                                         
               JR   Z,coloured                                  
               CP   "3"                                         
               JR   Z,flip_colours                              
               JR   co_l_loop                                   
                                                                
black_white:   LD   A,127                                       
               LD   (col_1),A                                   
               LD   A,0                                         
               LD   (col_4),A                                   
               JR   change_col                                  
                                                                
coloured:      LD   A,(co1)                                     
               LD   (col_1),A                                   
               LD   A,(co4)                                     
               LD   (col_4),A                                   
               JR   change_col                                  
                                                                
                                                                
flip_colours:  LD   A,(col_1)                                   
               LD   B,A                                         
               LD   A,(col_4)                                   
               LD   (col_1),A                                   
               LD   A,B                                         
               LD   (col_4),A                                   
               JR   change_col                                  
                                                                
                                                                
                                                                
; col_1 changes the screen colour                               
                                                                
                                                                
col_1_up:      LD   A,(col_1)                                   
               CP   127                                         
               JP   Z,col_again                                 
               INC  A                                           
col1:          LD   (col_1),A                                   
               LD   (co1),A                                     
change_col:    CALL colour                                      
               JP   col_again                                   
                                                                
                                                                
col_1_down:    LD   A,(col_1)                                   
               CP   0                                           
               JP   Z,col_again                                 
               DEC  A                                           
               JR   col1                                        
                                                                
                                                                
; col_4 changes the menu colours                                
                                                                
                                                                
col_4_up:      LD   A,(col_4)                                   
               CP   127                                         
               JP   Z,col_again                                 
               INC  A                                           
col4:          LD   (col_4),A                                   
               LD   (co4),A                                     
               CALL colour                                      
               JP   col_again                                   
                                                                
col_4_down:    LD   A,(col_4)                                   
               CP   0                                           
               JP   Z,col_again                                 
               DEC  A                                           
               JR   col4                                        
                                                                
exit_col:      XOR  A                                           
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
                                                                
; Sound a beep for the clock every minute:                      
                                                                
                                                                
sound_off:     LD   BC,511                                      
               LD   A,28                                        
               OUT  (C),A                                       
               DEC  B                                           
               XOR  A                                           
               OUT  (C),A                                       
               RET                                              
                                                                
                                                                
sound:         LD   HL,sound_data                               
               LD   BC,511                                      
ss_loop:       LD   A,(HL)                                      
               CP   255                                         
               RET  Z                                           
               OUT  (C),A                                       
               INC  HL                                          
               DEC  B                                           
               LD   A,(HL)                                      
               OUT  (C),A                                       
               INC  B                                           
               INC  HL                                          
               JR   ss_loop                                     
                                                                
                                                                
sound2:        DI                                               
               PUSH HL                                          
               PUSH BC                                          
               PUSH DE                                          
               PUSH AF                                          
               LD   HL,sound_data2  ; for the dir menu cursor   
               LD   BC,511                                      
ss2_loop:      LD   A,(HL)                                      
               CP   255                                         
               JR   Z,exit_s2                                   
               OUT  (C),A                                       
               INC  HL                                          
               DEC  B                                           
               LD   A,(HL)                                      
               OUT  (C),A                                       
               INC  B                                           
               INC  HL                                          
               JR   ss2_loop                                    
                                                                
exit_s2:       LD   HL,500                                      
ex2:           DEC  HL                                          
               LD   A,H                                         
               OR   L                                           
               JR   NZ,ex2                                      
               CALL sound_off                                   
               POP  AF                                          
               POP  DE                                          
               POP  BC                                          
               POP  HL                                          
               EI                                               
               RET                                              
                                                                
                                                                
; Put the fonts menu on the screen                              
                                                                
                                                                
font_dat:      DEFW get_font4                                   
               DEFW get_font3                                   
               DEFW get_font2                                   
               DEFW get_font1                                   
               DEFW default_font                                
               DEFW load_chars                                  
               DEFW exit_opt                                    
                                                                
                                                                
f_op_len:      DEFB 7                                           
                                                                
                                                                
font_menu:     LD   HL,37410+384                                
               LD   DE,font_data                                
               CALL print_menu                                  
               LD   A,30                                        
               LD   (bar_length),A                              
               LD   A,98                                        
               LD   (bar_jump),A                                
               LD   A,(f_op_len)                                
font_10:       LD   HL,41509+384                                
               LD   B,7                                         
               CALL get_op_len                                  
                                                                
foop_loop:     CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,font_dat                                 
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
               CP   10                                          
               JP   NZ,chk_11                                   
               CALL next_option                                 
               JR   foop_loop                                   
                                                                
chk_11:        CP   11                                          
               JR   NZ,f_hot_keys                               
               CALL prev_option                                 
               JR   foop_loop                                   
                                                                
                                                                
f_hot_keys:    CP   "1"                                         
               JP   Z,get_font1                                 
               CP   "2"                                         
               JP   Z,get_font2                                 
               CP   "3"                                         
               JP   Z,get_font3                                 
               CP   "4"                                         
               JP   Z,get_font4                                 
               RES  5,A                                         
               CP   "Q"                                         
               JP   Z,exit_opt                                  
               CP   "F"                                         
               JP   Z,load_chars                                
               CP   "D"                                         
               JP   Z,default_font                              
               JR   foop_loop                                   
                                                                
                                                                
                                                                
get_font1:     LD   HL,eight_bit_3                              
do_font:       LD   DE,eight_bit_1                              
               LD   BC,768                                      
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               CALL poke_chars                                  
               JP   exit_box                                    
                                                                
                                                                
get_font2:     LD   HL,eight_bit_4                              
               JR   do_font                                     
                                                                
get_font3:     LD   HL,eight_bit_5                              
               JR   do_font                                     
                                                                
get_font4:     LD   HL,eight_bit_6                              
               JR   do_font                                     
                                                                
default_font:  LD   HL,eight_bit_2                              
               JR   do_font                                     
                                                                
                                                                
                                                                
                                                                
                                                                
; put the options menu on the screen and move a highlight       
; bar through it to select your option                          
                                                                
                                                                
data_opp:      DEFW form_feed                                   
               DEFW skip_perfor                                 
               DEFW curhight                                    
               DEFW p_col_length                                
               DEFW carriage_retur                              
               DEFW dump_length                                 
               DEFW page_leng                                   
               DEFW page_strt                                   
               DEFW to_bas                                      
               DEFW save_code                                   
               DEFW exit_menu                                   
                                                                
                                                                
                                                                
op_len:        DEFB 11                                          
                                                                
                                                                
; Print the options menu on the screen before exiting to basic  
                                                                
                                                                
options:       CALL exit_box                                    
opt_2:         LD   HL,37410                                    
               LD   DE,option_data                              
               CALL print_menu                                  
               LD   A,54                                        
               LD   (bar_length),A  ; length of bar             
               LD   A,74            ; displacement between lines
               LD   (bar_jump),A                                
               LD   A,(op_len)                                  
               LD   HL,41509                                    
               LD   B,6                                         
               CALL get_op_len                                  
                                                                
                                                                
opp_loop:      CALL rd_key     ; change this to presskey        
               CALL sound2                                      
               CP   13                                          
               LD   HL,data_opp                                 
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
               CP   10                                          
               JP   NZ,check_11                                 
               CALL next_option                                 
               JR   opp_loop                                    
                                                                
check_11:      CP   11                                          
               JR   NZ,hot_keys                                 
               CALL prev_option                                 
               JR   opp_loop                                    
                                                                
                                                                
                                                                
hot_keys:      RES  5,A                                         
               CP   "Q"                                         
               JP   Z,exit_menu                                 
               CP   "S"                                         
               JP   Z,save_code    ; Save the main code. wordcd 
               CP   "P"                                         
               JP   Z,page_strt    ; Page number at top of scrn 
               CP   "B"                                         
               JP   Z,to_bas                                    
               CP   "L"                                         
               JP   Z,page_leng    ; page length                
               CP   "C"                                         
               JP   Z,p_col_length ; Printer col start          
               CP   "D"                                         
               JP   Z,dump_length                               
               CP   "F"                                         
               JP   Z,form_feed                                 
               CP   "K"                                         
               JP   Z,skip_perfor                               
               CP   "H"                                         
               JP   Z,curhight                                  
               CP   "R"                                         
               JP   Z,carriage_retur                            
               JR   opp_loop                                    
                                                                
                                                                
                                                                
exit_opt:      XOR  A                                           
               LD   (lastk),A                                   
               CALL exit_box                                    
               JP   key                                         
                                                                
                                                                
                                                                
to_bas:        CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,basic_exit                               
               CALL prstr_2                                     
bas_loop:      CALL keypress                                    
               RES  5,A                                         
               CP   "Y"                                         
               JR   Z,ok_basic                                  
               CP   "N"                                         
               JP   Z,options                                   
               JR   bas_loop                                    
                                                                
ok_basic:      LD   A,0                                         
               LD   (lastk),A                                   
               LD   A,"O"                                       
               JP   save_merge                                  
                                                                
                                                                
                                                                
; Save the changes made to the code eg colour word wrap etc     
                                                                
                                                                
save_code:     CALL exit_box                                    
               LD   HL,37400                                    
               LD   DE,schange_menu                             
               CALL print_menu                                  
sv_key:        CALL keypress                                    
               RES  5,A                                         
               CP   "Y"                                         
               JR   Z,yes_save                                  
               CP   "N"                                         
               JP   Z,options                                   
               JR   sv_key                                      
yes_save:      LD   A,0                                         
               LD   (lastk),A                                   
               LD   A,5                                         
               LD   (MODE),A                                    
               LD   A,"2"                                       
               JP   save_merge                                  
                                                                
                                                                
page_strt:     CALL exit_box                                    
               CALL draw_box                                    
page_again:    LD   HL,page_data                                
               CALL prstr_2                                     
               LD   A,(page_start)                              
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
pgg_loop:      CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page_s                               
               CP   11                                          
               JR   Z,page_inc                                  
               CP   10                                          
               JR   Z,page_dec                                  
               JR   pgg_loop                                    
                                                                
                                                                
                                                                
page_inc:      LD   A,(page_start)                              
               CP   85                                          
               JR   NC,pgg_loop                                 
               INC  A                                           
poke_page:     PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (page_start),A                              
               CALL lock_rom                                    
               CALL reprint_mes                                 
               JP   page_again                                  
                                                                
                                                                
page_dec:      LD   A,(page_start)                              
               CP   2                                           
               JR   C,pgg_loop                                  
               DEC  A                                           
               JR   poke_page                                   
                                                                
; Set the page start variable for the page in use               
                                                                
                                                                
exit_page_s:   LD   A,(text_page)                               
               LD   HL,page_start                               
               LD   DE,p1_start                                 
               CP   5                                           
               JR   Z,set_the_page                              
               LD   DE,p2_start                                 
               CP   7                                           
               JR   Z,set_the_page                              
               LD   DE,p3_start                                 
set_the_page:  CALL unlock_rom                                  
               LD   A,(HL)                                      
               LD   (DE),A                                      
               CALL lock_rom                                    
exit_page:     CALL exit_box                                    
               LD   A,0                                         
               LD   (s_m_var),A                                 
               LD   (lastk),A                                   
               JP   0                                           
                                                                
                                                                
                                                                
; Adjust the page length                                        
                                                                
                                                                
                                                                
page_leng:     CALL exit_box                                    
               CALL draw_box                                    
l_page_again:  LD   HL,page_l_data                              
               CALL prstr_2                                     
               LD   A,(page_length)                             
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
lpgg_loop:     CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page                                 
               CP   11                                          
               JR   Z,lpage_inc                                 
               CP   10                                          
               JR   Z,lpage_dec                                 
               JR   lpgg_loop                                   
                                                                
                                                                
                                                                
lpage_inc:     LD   A,(page_length)                             
               CP   70           ; maximum length 70 lines      
               JR   NC,lpgg_loop                                
               INC  A                                           
lpoke_page:    PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (page_length),A                             
               CALL lock_rom                                    
               CALL reprint_mes                                 
               JP   l_page_again                                
                                                                
                                                                
                                                                
lpage_dec:     LD   A,(page_length)                             
               CP   2                                           
               JR   C,lpgg_loop                                 
               DEC  A                                           
               JR   lpoke_page                                  
                                                                
                                                                
                                                                
; Set the column that the printer will start from               
                                                                
                                                                
p_col_length:  CALL exit_box                                    
               CALL draw_box                                    
p_col_again:   LD   HL,p_col_data                               
               CALL prstr_2                                     
               LD   A,(pr_tab)                                  
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
ppgg_loop:     CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page                                 
               CP   11                                          
               JR   Z,ppage_inc                                 
               CP   10                                          
               JR   Z,ppage_dec                                 
               JR   ppgg_loop                                   
                                                                
                                                                
                                                                
ppage_inc:     LD   A,(pr_tab)                                  
               CP   15                                          
               JR   NC,ppgg_loop                                
               INC  A                                           
ppoke_page:    PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (pr_tab),A                                  
               CALL lock_rom                                    
               CALL reprint_mes                                 
               JP   p_col_again                                 
                                                                
                                                                
                                                                
ppage_dec:     LD   A,(pr_tab)                                  
               CP   1                                           
               JR   C,ppgg_loop                                 
               DEC  A                                           
               JR   ppoke_page                                  
                                                                
                                                                
                                                                
                                                                
; Set the page length for the dump routine                      
                                                                
                                                                
dump_length:   CALL exit_box                                    
               CALL draw_box                                    
d_len_again:   LD   HL,dump_data                                
               CALL prstr_2                                     
               LD   A,(dump_len)                                
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
dpgg_loop:     CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page                                 
               CP   11                                          
               JR   Z,dpage_inc                                 
               CP   10                                          
               JR   Z,dpage_dec                                 
               JR   dpgg_loop                                   
                                                                
                                                                
                                                                
dpage_inc:     LD   A,(dump_len)                                
               CP   255                                         
               JR   NC,dpgg_loop                                
               INC  A                                           
dpoke_page:    PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (dump_len),A                                
               CALL lock_rom                                    
               CALL reprint_mes                                 
               JP   d_len_again                                 
                                                                
                                                                
                                                                
dpage_dec:     LD   A,(dump_len)                                
               CP   2                                           
               JR   C,dpgg_loop                                 
               DEC  A                                           
               JR   dpoke_page                                  
                                                                
                                                                
; Set the skip perforations setting: lines at top and bottom    
; of paper                                                      
                                                                
skip_perfor:   CALL exit_box                                    
               CALL draw_box                                    
skip_again:    LD   HL,skip_data                                
               CALL prstr_2                                     
               LD   A,(skip_perf)                               
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
skgg_loop:     CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page                                 
               CP   11                                          
               JR   Z,skage_inc                                 
               CP   10                                          
               JR   Z,skage_dec                                 
               JR   skgg_loop                                   
                                                                
                                                                
                                                                
skage_inc:     LD   A,(skip_perf)                               
               CP   99                                          
               JR   NC,skgg_loop                                
               INC  A                                           
skoke_page:    PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (skip_perf),A                               
               CALL lock_rom                                    
               CALL reprint_mes                                 
               JP   skip_again                                  
                                                                
                                                                
                                                                
skage_dec:     LD   A,(skip_perf)                               
               CP   1                                           
               JR   C,skgg_loop                                 
               DEC  A                                           
               JR   skoke_page                                  
                                                                
                                                                
                                                                
                                                                
; Set the lower case cursor height between 1 and 8              
                                                                
                                                                
curhight:      CALL exit_box                                    
               CALL draw_box                                    
curs_again:    LD   HL,cursor_data                              
               CALL prstr_2                                     
               LD   A,(cur_height)                              
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
cur_loop:      CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page                                 
               CP   11                                          
               JR   Z,curs_inc                                  
               CP   10                                          
               JR   Z,curs_dec                                  
               JR   cur_loop                                    
                                                                
                                                                
                                                                
curs_inc:      LD   A,(cur_height)                              
               CP   6                                           
               JR   NC,cur_loop                                 
               INC  A                                           
cur_page:      PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (cur_height),A                              
               CALL lock_rom                                    
               CALL reprint_mes                                 
               JP   curs_again                                  
                                                                
                                                                
                                                                
curs_dec:      LD   A,(cur_height)                              
               CP   2                                           
               JR   C,cur_loop                                  
               DEC  A                                           
               JR   cur_page                                    
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
; Do a form feed  . From options menu                           
                                                                
form_feed:     LD   A,0                                         
               RST  40                                          
               LD   A,27                                        
               RST  40                                          
               LD   A,12                                        
               RST  40                                          
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
; Set to 10 for a carriage return after every line or 0         
; for no carriage return after each line                        
                                                                
                                                                
carriage_retur:CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,carriage_data                            
               CALL prstr_2                                     
               LD   HL,(sposn2)                                 
               LD   (sc_pos),HL                                 
re_draw:       LD   A,(car_ret)                                 
               CP   10                                          
               JR   Z,car_on                                    
               LD   HL,c_off                                    
               CALL prstr_2                                     
               JR   car_key                                     
car_on:        LD   HL,c_on                                     
               CALL prstr_2                                     
car_key:       CALL presskey1                                   
               CP   13                                          
               JP   Z,exit_page                                 
               RES  5,A                                         
               CP   "Y"                                         
               JR   Z,turn_on                                   
               CP   "N"                                         
               JR   Z,turn_off                                  
               JR   car_key                                     
                                                                
                                                                
turn_on:       LD   A,10                                        
turn_off2:     PUSH AF                                          
               CALL unlock_rom                                  
               POP  AF                                          
               LD   (car_ret),A                                 
               CALL lock_rom                                    
               LD   HL,(sc_pos)                                 
               LD   (sposn2),HL                                 
               JP   re_draw                                     
                                                                
turn_off:      LD   A,0                                         
               JR   turn_off2                                   
                                                                
                                                                
                                                                
; sound a beep before waiting for a key                         
                                                                
presskey1:     CALL sound2                                      
                                                                
; Come here wait for a keypress and just exit                   
                                                                
                                                                
keypress:      PUSH HL                                          
               LD   HL,flags                                    
               RES  5,(HL)                                      
keyp_loop:     BIT  5,(HL)                                      
               JR   Z,keyp_loop                                 
               LD   A,(lastk)                                   
               POP  HL                                          
               RET                                              
                                                                
                                                                
; Dir to the screen.  First print the border                    
; Clear memory where dir info will go   49152 in page 1         
; on return to basic jump to DIRECTORY                          
                                                                
                                                                
dir:           LD   A,1      ; 1 for directory                  
               LD   (CONTROL_FLAG),A                            
               LD   A,"D"                                       
               LD   (MODE),A                                    
get_dir:       CALL fetch_dir                                   
               JP   save_merge                                  
                                                                
                                                                
DIRECTORY:     CALL dir_to_screen                               
dkp:           CALL keypress                                    
               CALL sound2                                      
               CP   f8                                          
               CALL Z,inp_bar                                   
               LD   HL,49552                                    
               CP   f5                                          
               CALL Z,next_dir                                  
               CP   13                                          
               JR   NZ,dkp                                      
               CALL exit_box                                    
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   key                                         
                                                                
; Erase a file from the disk use the loader routine to select   
; the file to erase.                                            
                                                                
                                                                
erase_a_file:  CALL exit_box                                    
               LD   A,3                ; same routine as load   
               LD   (CONTROL_FLAG),A                            
               LD   A,"E"                                       
               JP   LEM                                         
                                                                
                                                                
; Load a character set. Use the loader routine to select        
; set.                                                          
                                                                
                                                                
load_chars:    CALL exit_box                                    
               LD   A,3                                         
               LD   (CONTROL_FLAG),A                            
               LD   A,"X"                                       
               JP   LEM                                         
                                                                
                                                                
                                                                
; Merge will use the loader routine. The variable l_or_e will   
; flag what message to print from the loader routine            
; merge and erase will use a diferent buffer for the name       
; so that the original name of the file is not lost             
                                                                
                                                                
                                                                
                                                                
                                                                
merge:         CALL strtln                                      
               LD   HL,(memry)                                  
               LD   (merge_var),HL                              
               CALL goto_margin                                 
               LD   A,3              ; same routine as load     
               LD   (CONTROL_FLAG),A                            
               LD   A,"M"                                       
               JP   LEM                                         
                                                                
                                                                
                                                                
loader_rtn:    CALL exit_box                                    
               LD   A,3                                         
               LD   (CONTROL_FLAG),A                            
               LD   A,"L"                                       
LEM:           LD   (MODE),A                                    
               LD   (l_or_e),A                                  
               CALL fetch_dir                                   
               JP   save_merge                                  
                                                                
                                                                
                                                                
; Fill the directory buffer in page 1 (normal ram) with spaces  
; before exiting to Get the directory                           
                                                                
fetch_dir:     IN   A,(251)                                     
               PUSH AF                                          
               LD   A,1                                         
               OUT  (251),A                                     
               LD   HL,49152                                    
               LD   DE,49153                                    
               LD   BC,1000                                     
               LD   A,32     ; fill memory with spaces          
               LD   (HL),A                                      
               LDIR                                             
               POP  AF                                          
               OUT  (251),A                                     
               CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,fetching                                 
               CALL prstr_2                                     
               LD   A,"D"            ; D = fetch directory      
               RET                                              
                                                                
LOADER:        CALL exit_box                                    
               LD   A,(MODE)                                    
               CP   "L"              ; use a different buffer   
               JR   Z,do_dir         ; for merge erase and      
               LD   HL,name_buffer4  ; load chars               
               LD   (name_buff),HL                              
do_dir:        CALL dir_to_screen                               
               LD   HL,49152                                    
               LD   (name_address),HL                           
               CALL input_box                                   
               CALL put_in_window                               
               CALL wait_dir                                    
               CALL exit_box                                    
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   key                                         
                                                                
                                                                
                                                                
wait_dir:      LD   HL,42002                                    
               LD   (sposn2),HL                                 
               LD   A,1                                         
               LD   (cur_pos),A   ; control up down limit       
               LD   (cur_pos2),A  ; control left right limit    
wait_d:        CALL high_bar      ; Highlight bar               
                                                                
kp:            CALL sound2       ; was  wait_dir                
kp1:           CALL keypress                                    
               CP   32                                          
               JP   Z,get_old_buf                               
               CP   13                                          
               JP   Z,transfer_name                             
               CP   10                                          
               JP   Z,curs_down                                 
               CP   11                                          
               JP   Z,curs_up                                   
               CP   8                                           
               JP   Z,curs_left                                 
               CP   9                                           
               JP   Z,curs_right                                
               CP   f8                                          
               JP   Z,inpp_bar                                  
               LD   HL,49552         ; Hl points to DIR page 2  
               CP   f5               ; else steps through memry 
               JP   Z,next_d                                    
               JR   kp1                                         
                                                                
                                                                
; if erase merge or load chars has just been used then          
; swap back to the original name buffer                         
                                                                
                                                                
get_old_buf:   LD   A,(text_page)                               
                                                                
               LD   HL,name_buffer1                             
               CP   5                                           
               JR   Z,got_buf                                   
               LD   HL,name_buffer2                             
               CP   7                                           
               JR   Z,got_buf                                   
                                                                
; not text 1 or 2 so must be text file 3. Just load HL and set  
                                                                
               LD   HL,name_buffer3                             
got_buf:       LD   (name_buff),HL                              
               RET                                              
                                                                
                                                                
                                                                
                                                                
transfer_name: IN   A,(251)                                     
               PUSH AF                                          
               LD   A,1                                         
               OUT  (251),A                                     
               LD   HL,(name_address)                           
               LD   A,(HL)                                      
               CP   48                                          
               JP   C,no_file_here                              
               CP   126                                         
               JP   NC,no_file_here                             
               LD   DE,(name_buff)                              
               LD   BC,10                                       
               LD   A,(HL)                                      
               LD   (DE),A                                      
               LDIR                                             
               POP  AF                                          
               OUT  (251),A                                     
                                                                
               CALL input_box                                   
               CALL inverse                                     
               CALL ld_er  ; is this a load or erase            
               CALL norm                                        
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               LD   A,32                                        
               CALL pchar2_2                                    
               LD   HL,(name_buff)                              
               CALL prstr_2                                     
               LD   A,32                                        
               CALL pchar2_2                                    
               CALL inverse                                     
               LD   HL,load_rest                                
               CALL prstr_2                                     
               CALL norm                                        
               CALL sound2                                      
               CALL sound2                                      
               POP  HL         ;  pop return address off stack  
               LD   A,0                                         
               LD   (CONTROL_FLAG),A                            
               LD   (lastk),A                                   
               LD   A,(l_or_e)  ; load erase or merge           
               CP   "E"                                         
               JR   Z,re_load_cont                              
               JP   save_merge                                  
                                                                
                                                                
re_load_cont:  LD   A,3                                         
               LD   (CONTROL_FLAG),A  ; Ensure erase comes back 
               LD   A,"E"                                       
               JP   save_merge                                  
                                                                
                                                                
                                                                
no_file_here:  POP  AF                                          
               OUT  (251),A                                     
               LD   HL,(sposn2)                                 
               PUSH HL                                          
               LD   HL,53898+1024+4                             
               LD   (sposn2),HL                                 
               CALL inverse                                     
               LD   HL,no_file_mess                             
               CALL prstr_2                                     
               CALL norm                                        
               POP  HL                                          
               LD   (sposn2),HL                                 
               JP   kp                                          
                                                                
                                                                
next_d:        LD   (name_address),HL                           
               CALL put_in_window                               
               CALL next_dir                                    
               JP   wait_dir                                    
                                                                
inpp_bar:      LD   HL,49152                                    
               JR   next_d                                      
                                                                
                                                                
                                                                
curs_down:     LD   A,(cur_pos)                                 
               CP   10                                          
               JP   Z,kp1          ; no beep                    
               INC  A                                           
               LD   (cur_pos),A                                 
               CALL high_bar                                    
               LD   HL,(sposn2)                                 
               LD   DE,1024                                     
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   HL,(name_address)                           
               LD   DE,40                                       
               OR   A                                           
               ADC  HL,DE                                       
               LD   (name_address),HL                           
               CALL put_in_window                               
               JP   wait_d                                      
                                                                
                                                                
                                                                
curs_up:       LD   A,(cur_pos)                                 
               CP   1                                           
               JP   Z,kp1           ; no beep                   
               DEC  A                                           
               LD   (cur_pos),A                                 
               CALL high_bar                                    
               LD   HL,(sposn2)                                 
               LD   DE,1024                                     
               OR   A                                           
               SBC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   HL,(name_address)                           
               LD   DE,40                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (name_address),HL                           
               CALL put_in_window                               
               JP   wait_d                                      
                                                                
                                                                
curs_left:     LD   A,(cur_pos2)                                
               CP   1                                           
               JP   Z,kp1           ; no beep                   
               DEC  A                                           
               LD   (cur_pos2),A                                
               CALL high_bar                                    
               LD   HL,(sposn2)                                 
               LD   DE,24                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   HL,(name_address)                           
               LD   DE,10                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (name_address),HL                           
               CALL put_in_window                               
               JP   wait_d                                      
                                                                
                                                                
                                                                
curs_right:    LD   A,(cur_pos2)                                
               CP   4                                           
               JP   Z,kp1         ; no beep                     
               INC  A                                           
               LD   (cur_pos2),A                                
               CALL high_bar                                    
               LD   HL,(sposn2)                                 
               LD   DE,24                                       
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   HL,(name_address)                           
               LD   DE,10                                       
               OR   A                                           
               ADC  HL,DE                                       
               LD   (name_address),HL                           
               CALL put_in_window                               
               JP   wait_d                                      
                                                                
                                                                
                                                                
put_in_window: PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               PUSH AF                                          
               LD   HL,(sposn2)                                 
               PUSH HL                                          
               LD   HL,53898+1024+4                             
               LD   (sposn2),HL                                 
               CALL inverse                                     
               IN   A,(251)                                     
               PUSH AF                                          
               LD   A,1                                         
               OUT  (251),A                                     
               CALL load_or_erase                               
               CALL norm                                        
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               LD   A,32                                        
               CALL pchar2_2                                    
               LD   HL,(name_address)                           
               LD   B,10                                        
nb_loop:       LD   A,(HL)                                      
               CALL pchar2_2                                    
               INC  HL                                          
               DJNZ nb_loop                                     
               LD   A,32                                        
               CALL pchar2_2                                    
                                                                
               CALL inverse                                     
               LD   HL,the_rest                                 
               CALL prstr_2                                     
               POP  AF                                          
               OUT  (251),A                                     
               CALL norm                                        
               POP  HL                                          
               LD   (sposn2),HL                                 
               POP  AF                                          
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               RET                                              
                                                                
                                                                
dir_to_screen: CALL exit_box                                    
dir_screen2:   CALL draw_box                                    
               IN   A,(251)                                     
               PUSH AF                                          
               LD   A,1                                         
               OUT  (251),A                                     
               LD   DE,50002                                    
               LD   A,(DE)                                      
               LD   L,A                                         
               INC  DE                                          
               LD   A,(DE)                                      
               LD   H,A                                         
               CALL pnum                                        
               LD   HL,dir_mess1                                
               CALL prstr_2                                     
               LD   HL,50004                                    
               LD   A,(HL)                                      
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
               LD   HL,dir_mess2                                
               CALL prstr_2                                     
               LD   HL,50005                                    
               LD   A,(HL)                                      
               LD   L,A                                         
               LD   H,0                                         
               CALL pnum                                        
               LD   HL,dir_mess3                                
               CALL prstr_2                                     
               POP  AF                                          
               OUT  (251),A                                     
                                                                
                                                                
               LD   HL,40976                                    
               LD   DE,top_lin                                  
               CALL print_menu                                  
               LD   B,10                                        
mid_loop:      LD   HL,(sposn2)                                 
               LD   DE,mid_lin                                  
               PUSH BC                                          
               CALL print_menu                                  
               POP  BC                                          
               DJNZ mid_loop                                    
               LD   HL,(sposn2)                                 
               LD   DE,bot_lin                                  
               CALL print_menu                                  
                                                                
                                                                
; Now page normal ram page into 32768 Dir$ was poked into       
; address 49152 from basic. So now print it to the screen       
; A disk can have 80 files on it so handle 40 files at a time   
                                                                
inp_bar:       LD   HL,49152                                    
               LD   (name_address),HL                           
next_dir:      PUSH HL                                          
               LD   HL,42002                                    
               LD   (sposn2),HL                                 
               LD   (dir_store),HL                              
               CALL inverse                                     
               IN   A,(251)                                     
               LD   (dir_page),A                                
               LD   A,1                                         
               OUT  (251),A          ; normal ram page to 32768 
               POP  HL               ; Get start of dir         
               LD   A,10                                        
dir_loop3:     PUSH AF                                          
               LD   C,4                                         
dir_loop1:     LD   B,10                                        
dir_loop2:     LD   A,(HL)                                      
               CP   0                                           
               JP   NZ,next_dir_char                            
               LD   A,32             ; End of dir info so pad   
next_dir_char: CALL pchar2_2         ; out dir with spaces      
               INC  HL                                          
               DJNZ dir_loop2                                   
               PUSH HL                                          
               LD   HL,(sposn2)                                 
               INC  HL                                          
               INC  HL                                          
               INC  HL                                          
               INC  HL                                          
               LD   (sposn2),HL                                 
               POP  HL                                          
               DEC  C                                           
               LD   A,C                                         
               OR   A                                           
               JR   Z,next_dir_line                             
               JR   dir_loop1                                   
                                                                
                                                                
                                                                
                                                                
                                                                
next_dir_line: POP  AF                                          
               DEC  A                                           
               OR   A                                           
               JP   Z,dir_fin                                   
               PUSH AF                                          
               PUSH HL                                          
               LD   DE,1024                                     
               LD   HL,(dir_store)                              
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   (dir_store),HL                              
               POP  HL                                          
               POP  AF                                          
               JP   dir_loop3                                   
                                                                
                                                                
dir_fin:       LD   A,(dir_page)                                
               OUT  (251),A                                     
               LD   A,0                                         
               LD   (lastk),A                                   
               RET                                              
                                                                
                                                                
                                                                
                                                                
; Called from the LOADER routine                                
; put the highlight bar in the directory when loading a file    
                                                                
high_bar:      PUSH BC                                          
               PUSH DE                                          
               LD   B,8                                         
               CALL screen_in                                   
               LD   HL,(sposn2)                                 
               LD   DE,128                                      
h_bar_loop:    PUSH HL                                          
               PUSH BC                                          
               LD   B,20                                        
h1_bar_loop:   LD   A,(HL)                                      
               XOR  255                                         
               LD   (HL),A                                      
               INC  HL                                          
               DJNZ h1_bar_loop                                 
               POP  BC                                          
               POP  HL                                          
               ADD  HL,DE                                       
               DJNZ h_bar_loop                                  
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  DE                                          
               POP  BC                                          
               RET                                              
                                                                
                                                                
                                                                
                                                                
                                                                
; used when loading  saveing or mergeing                        
                                                                
                                                                
input_box:     LD   HL,53898                                    
               LD   DE,inbox_data                               
               CALL print_menu                                  
               LD   HL,53898+1024+4                             
               LD   (sposn2),HL                                 
               RET                                              
                                                                
clear_nm_buf:  LD   HL,(name_buff)                              
               PUSH HL                                          
               POP  DE                                          
               INC  DE                                          
               LD   BC,9                                        
               LD   A,32                                        
               LD   (HL),A                                      
               LDIR                                             
               RET                                              
                                                                
                                                                
                                                                
                                                                
; All disk opperations jump to here prior to doing              
; an exit to basic                                              
                                                                
save_merge:    LD   (s_m_var),A ; the text file at the cursor   
exit_to_bas:   LD   A,(hide_var)                                
               OR   A                                           
               JP   NZ,hide_error                               
               LD   HL,(emg_ret); Stack normal on exit          
               LD   SP,HL                                       
               CALL inverse                                     
               LD   A,0                                         
               LD   (error_flag),A  ; ensure no error ON exit   
               RET                                              
                                                                
; file is scrambled so an exit to basic is not allowed          
; Print an error message on screen                              
                                                                
hide_error:    CALL exit_box                                    
               CALL draw_box                                    
               LD   B,22                                        
               JP   n_rm                                        
                                                                
                                                                
load_file:     CALL reprint_screen                              
               LD   A,(file_st)                                 
               CP   255                                         
               JP   Z,no_file_in                                
               CALL draw_box                                    
               LD   B,3     ; message 3                         
               CALL prstr                                       
load_key:      CALL rd_key                                      
               RES  5,A                                         
               CP   "N"                                         
               JP   Z,exit_box                                  
               CP   "Y"                                         
               JR   NZ,load_key                                 
               LD   HL,file_st                                  
               LD   D,H                                         
               LD   E,L                                         
               INC  E                                           
               LD   BC,45100                                    
               LD   (HL),32                                     
               LDIR                                             
no_file_in:    LD   HL,0                                        
               LD   (len_var),HL                                
               LD   (file_st),HL                                
               XOR  A                                           
               LD   (hide_var),A                                
               JP   loader_rtn                                  
                                                                
                                                                
; Exit the message box and reprint the screen                   
                                                                
                                                                
exit_box:      CALL norm                                        
               JP   reprint_screen                              
                                                                
                                                                
; Save a marked block use buffer 4 so the file name stays intact
                                                                
                                                                
                                                                
save_block:    LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               CALL grab_save                                   
               LD   HL,(block_len)                              
               LD   (save_blk_len),HL                           
               LD   HL,0                                        
               LD   (block_len),HL                              
                                                                
; re_entry point from disk error routine                        
                                                                
block_save:    CALL exit_box                                    
               LD   A,5                                         
               LD   (CONTROL_FLAG),A                            
               LD   A,"B"                                       
               LD   (MODE),A                                    
               CALL fetch_dir                                   
               JP   save_merge                                  
                                                                
; come back here when returning from basic for a block save     
                                                                
sv_block:      LD   A,0                                         
               LD   (CONTROL_FLAG),A                            
               LD   HL,name_buffer4                             
               LD   (name_buff),HL                              
               JP   input_name      ; Saving a block so dont    
                                    ; use current file name     
                                    ; just go get a new name    
                                                                
                                                                
                                                                
                                                                
                                                                
; Save the file check for a file name in the name buffer first  
; as this will indicate that the file was loaded and is still in
; memory. If the file buffer is empty invite user to input a    
; file name, then check to see if this name is in the current   
; directory if it is then query the save Y or N if N then go    
; back to the start of the save rouitine.                       
; For a full file save a "S" must be in "A" before exiting to   
; save_merge . For a Block save a "B" must be in "A"            
                                                                
                                                                
                                                                
save_file:     CALL exit_box                                    
               LD   A,4           ; 4 = saving                  
               LD   (CONTROL_FLAG),A                            
               LD   A,"S"                                       
               LD   (MODE),A                                    
               CALL fetch_dir                                   
               JP   save_merge   ; jump out to basic for DIR    
                                                                
                                                                
; Come back to here when coming back with the directory         
                                                                
sv_full:       LD   A,0                                         
               LD   (CONTROL_FLAG),A                            
               LD   HL,(name_buff)                              
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,input_name    ; Must be a new file        
                                    ; so go get a new name      
                                                                
; Report " Press Return to save ??????? " Edit for a new name   
                                                                
               CALL input_box                                   
               CALL inverse                                     
               LD   HL,save_message                             
               CALL prstr_2                                     
               CALL norm                                        
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               LD   A,32                                        
               CALL pchar2_2                                    
               LD   HL,(name_buff)                              
               CALL prstr_2                                     
               LD   A,32                                        
               CALL pchar2_2                                    
               CALL inverse                                     
               LD   HL,save_mes_2                               
               CALL prstr_2                                     
               CALL norm                                        
                                                                
; wait for a keypress. any thing less than an "A" ignore or     
; greater than a "z" ignore.                                    
                                                                
                                                                
try_again:     CALL keypress                                    
               CP   13                                          
               JP   Z,check_s_name   ; look for name in the dir 
               CP   7                ; Edit key                 
               JP   Z,input_name                                
               JR   try_again                                   
                                                                
                                                                
; interogate directory at 49152 to see if the name in the       
; buffer matches any of the files. If so then print overwrite   
; message Y/N                                                   
                                                                
; First page in the dir page 1                                  
                                                                
                                                                
check_s_name:  IN   A,(251)                                     
               PUSH AF                                          
               LD   A,1                                         
               OUT  (251),A                                     
                                                                
; now search through the DIR info for a match with the name     
; in the buffer                                                 
                                                                
               LD   HL,49152                                    
               LD   A,(50004)        ; X  Files on the disk     
               LD   C,A                                         
sr_loop:       LD   B,10             ; 10 chars to a file name  
               PUSH HL               ; save old search start    
               LD   DE,(name_buff)                              
sr1_loop:      LD   A,(DE)                                      
               CP   (HL)                                        
               JR   NZ,next_f_name                              
               INC  HL                                          
               INC  DE                                          
               DJNZ sr1_loop                                    
                                                                
; djnz fails so a match has been found . Now get original page  
; back. and print Overwrite message.                            
                                                                
               POP  HL         ; old search start               
               POP  AF         ; original page number           
               OUT  (251),A    ; original pg now at 32768       
               CALL input_box                                   
               CALL inverse                                     
               LD   HL,question_save ; "overwrite "             
               CALL prstr_2                                     
               CALL norm                                        
               LD   A,32                                        
               CALL pchar2_2                                    
               LD   HL,(name_buff)   ; "???????????"            
               CALL prstr_2                                     
               LD   A,32                                        
               CALL pchar2_2                                    
               CALL inverse                                     
               LD   HL,quest_save    ; " Y or N"                
               CALL prstr_2                                     
                                                                
quest_again:   CALL keypress                                    
               RES  5,A                                         
               CP   "Y"                                         
               JP   Z,ok_save                                   
               CP   "N"                                         
               JP   Z,input_name                                
               JR   quest_again                                 
                                                                
                                                                
next_f_name:   POP  HL         ; Get old file address           
               LD   DE,10      ; increment to next file         
               OR   A                                           
               ADC  HL,DE                                       
               DEC  C          ; Dec the files counter          
               LD   A,C                                         
               CP   0          ; looked at all files if 0       
               JP   Z,ok_save1                                  
               JP   sr_loop    ; go round for the next file chk 
                                                                
                                                                
                                                                
ok_save1:      POP  AF                                          
               OUT  (251),A                                     
ok_save:       LD   A,0                                         
               LD   (lastk),A                                   
               LD   A,(MODE)                                    
               CP   "B"                                         
               JP   Z,save_merge                                
               LD   A,"S"                                       
               LD   (MODE),A                                    
               JP   save_merge                                  
                                                                
                                                                
                                                                
                                                                
Disk_error:    PUSH AF       ; Save error number                
               XOR  A                                           
               LD   (error_flag),A                              
               CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,ERR                                      
               CALL prstr_3                                     
               POP  AF                                          
               CALL find_error                                  
               CALL input_box                                   
               CALL inverse                                     
               LD   HL,do_something                             
               CALL prstr_3                                     
               CALL norm                                        
               CALL keypress                                    
               CP   32                                          
               JP   Z,leave_error                               
               LD   A,0                                         
               LD   (lastk),A                                   
               LD   A,(MODE)                                    
               CP   "D"                                         
               JP   Z,dir                                       
               CP   "L"                                         
               JP   Z,load_file                                 
               CP   "S"                                         
               JP   Z,save_file                                 
               CP   5                                           
               JP   Z,save_code                                 
               CP   "B"                                         
               JP   Z,block_save                                
               CP   "E"                                         
               JP   Z,erase_a_file                              
               CP   "X"                                         
               JP   Z,load_chars                                
leave_error:   LD   A,0                                         
               LD   (lastk),A                                   
               CALL exit_box                                    
               JP   key                                         
                                                                
                                                                
find_error:    LD   HL,trk_sect  ; Track & sector error         
               CP   85                                          
               JP   Z,prstr_3                                   
               LD   HL,cant_erase                               
               CP   1                                           
               JP   Z,prstr_3                                   
               LD   HL,restricted                               
               CP   2                                           
               JP   Z,prstr_3                                   
                                                                
                                                                
               LD   HL,no_disk   ; No disk in drive 1           
               CP   87                                          
               JP   Z,prstr_3                                   
               LD   HL,invalid   ; Invalid file name            
               CP   89                                          
               JP   Z,prstr_3                                   
               LD   HL,wrong_file  ; Wrong file type            
               CP   94                                          
               JP   Z,prstr_3                                   
               LD   HL,protected     ; Disk write protected     
               CP   104                                         
               JP   Z,prstr_3                                   
               LD   HL,run_out     ; Not enougth space on disk  
               CP   105                                         
               JP   Z,prstr_3                                   
               LD   HL,dir_full      ; Directory full           
               CP   106                                         
               LD   HL,f_not_found     ; File not found         
               CP   107                                         
               JP   Z,prstr_3                                   
               LD   HL,esc_pressed                              
               CP   84                                          
               JP   Z,prstr_3                                   
               LD   HL,not_known     ; Error not listed         
               JP   prstr_3                                     
                                                                
                                                                
; this routine will print an error message with a beep after    
; every character printed.                                      
                                                                
prstr_3:       LD   A,(HL)                                      
               CP   255                                         
               JP   Z,enable                                    
               CALL pchar2                                      
               CALL sound2                                      
               INC  HL                                          
               JR   prstr_3                                     
                                                                
                                                                
; input name of file to save. Check for file on disk            
                                                                
                                                                
                                                                
input_name:    CALL dir_screen2                                 
new_name:      CALL clear_nm_buf                                
               CALL input_box                                   
               CALL inverse                                     
               LD   HL,input_mess                               
               CALL prstr_2                                     
               CALL c_sr                                        
               LD   B,10      ; name length                     
               LD   DE,(name_buff)                              
kpress:        CALL keypress                                    
               CALL sound2                                      
               CP   f5                                          
               JP   Z,nxt_p_dir                                 
               CP   f8                                          
               JP   Z,inp_d_dir                                 
               CP   13                                          
               JP   Z,check_inp  ; check for a valid file name  
               CP   12                                          
               JP   Z,del_ete                                   
               CP   f9                                          
               JP   Z,exit_the_save                             
new_nm:        CP   32                                          
               JR   C,kpress                                    
               CP   122                                         
               JR   NC,kpress                                   
               LD   C,A       ; temp hold char and check B      
               LD   A,B                                         
               CP   0                                           
               JP   Z,kpress                                    
               DEC  B                                           
               LD   A,C                                         
               CP   32                                          
               JR   Z,no_set                                    
               SET  5,A                                         
no_set:        CALL c_sr                                        
               LD   (DE),A                                      
               INC  DE                                          
               CALL pchar2_2                                    
               CALL c_sr                                        
               JP   kpress                                      
                                                                
                                                                
del_ete:       LD   A,B                                         
               CP   10                                          
               JP   Z,kpress                                    
               CALL c_sr                                        
               LD   HL,(sposn2)                                 
               DEC  L                                           
               DEC  L                                           
               LD   (sposn2),HL                                 
               LD   A,32                                        
               PUSH HL                                          
               DEC  DE                                          
               LD   (DE),A                                      
               CALL pchar2_2                                    
               POP  HL                                          
               LD   (sposn2),HL                                 
               INC  B                                           
               CALL c_sr                                        
               JP   kpress                                      
                                                                
                                                                
                                                                
                                                                
                                                                
check_inp:     LD   HL,(name_buff)                              
               LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,check_s_name                             
               CALL input_box                                   
               CALL inverse                                     
               LD   HL,must_have     ; Must have a filename     
               CALL prstr_2                                     
               CALL norm                                        
               CALL keypress                                    
               XOR  A                                           
               LD   (lastk),A                                   
               JP   new_name                                    
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
c_sr:          PUSH HL                                          
               PUSH AF                                          
               CALL list_crsr                                   
               POP  AF                                          
               POP  HL                                          
               RET                                              
                                                                
                                                                
nxt_p_dir:     PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               LD   HL,(sposn2)                                 
               PUSH HL                                          
               LD   HL,49552                                    
               CALL next_dir                                    
               POP  HL                                          
               LD   (sposn2),HL                                 
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               JP   kpress                                      
                                                                
inp_d_dir:     PUSH HL                                          
               PUSH DE                                          
               PUSH BC                                          
               LD   HL,(sposn2)                                 
               PUSH HL                                          
               CALL inp_bar                                     
               POP  HL                                          
               LD   (sposn2),HL                                 
               POP  BC                                          
               POP  DE                                          
               POP  HL                                          
               JP   kpress                                      
                                                                
                                                                
exit_the_save: CALL exit_box                                    
               CALL clear_nm_buf                                
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   key                                         
                                                                
                                                                
; determine what message to print from the load routine         
; It is used for LOAD.  MERGE.  ERASE. and LOAD CHARACTER SET   
                                                                
                                                                
load_or_erase: LD   A,(l_or_e)   ; Flag load or erase           
               LD   HL,to_load_mess                             
               CP   "L"                                         
               JR   Z,le                                        
               CP   "X"                                         
               JR   Z,le                                        
               LD   HL,to_erase_mess                            
               CP   "E"                                         
               JR   Z,le                                        
               LD   HL,to_merge_mess                            
le:            CALL prstr_2                                     
               RET                                              
                                                                
; Once return is pressed a different load merge or erase        
; message needs printing                                        
                                                                
ld_er:         LD   A,(l_or_e)                                  
               LD   HL,load_message                             
               CP   "L"                                         
               JR   Z,le                                        
               CP   "X"                                         
               JR   Z,le                                        
               LD   HL,erase_message                            
               CP   "E"                                         
               JR   Z,le                                        
               LD   HL,merge_message                            
               JR   le                                          
                                                                
                                                                
FILE1:         LD   A,TEXT1                                     
               LD   B,A                                         
               LD   A,(p1_start)                                
change_file:   CALL unlock_rom                                  
               LD   (page_start),A                              
               LD   A,B                                         
               LD   (text_page),A                               
               CALL lock_rom                                    
               LD   A,0                                         
               LD   (s_m_var),A                                 
               CALL cls                                         
               JP   0                                           
                                                                
FILE2:         LD   A,TEXT2                                     
               LD   B,A                                         
               LD   A,(p2_start)                                
               JR   change_file                                 
                                                                
FILE3:         LD   A,TEXT3                                     
               LD   B,A                                         
               LD   A,(p3_start)                                
               JR   change_file                                 
                                                                
                                                                
get_file_name: CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,the_name                                 
               CALL prstr_2                                     
               LD   HL,(name_buff)                              
               LD   B,10                                        
g_name:        LD   A,(HL)                                      
               CALL pchar2_2                                    
               INC  HL                                          
               DJNZ g_name                                      
               LD   HL,dun                                      
               CALL prstr_2                                     
               CALL keypress                                    
               JP   exit_box                                    
                                                                
                                                                
                                                                
;         grab block from text file to buffer                   
                                                                
grab_block:    CALL grb_block                                   
               JP   exit_box                                    
                                                                
                                                                
grb_block:     LD   A,(char_1)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
               LD   A,(char_2)                                  
               OR   A                                           
               JP   Z,only_1_blk                                
grab_save:     LD   HL,(block_end)                              
               LD   DE,(block_strt)                             
               OR   A                                           
               SBC  HL,DE                                       
               CALL C,rev_blocks                                
               LD   (block_len),HL                              
                                                                
               LD   HL,(block_strt)                             
               LD   DE,(block_end)                              
               LD   A,(char_1)                                  
               LD   (HL),A                                      
               LD   A,(char_2)                                  
               LD   (DE),A                                      
               XOR  A                                           
               LD   (block_var),A                               
                                                                
                                                                
; transfer block from text file to buffer                       
                                                                
                                                                
               LD   DE,(block_strt)                             
               LD   BC,(block_len)                              
               LD   HL,BF_buffer                                
grb_loop:      LD   A,(DE)                                      
               CALL poke_hl                                     
               INC  HL                                          
               INC  DE                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JR   NZ,grb_loop                                 
               LD   A,255                                       
               CALL poke_hl                                     
                                                                
; finished the transfer to the buffer                           
                                                                
               LD   A,1        ; 1 indicates data in buffer     
               LD   (buff_flag),A                               
               LD   HL,0                                        
               LD   (block_strt),HL                             
               LD   (block_end),HL                              
               XOR  A                                           
               LD   (char_1),A                                  
               LD   (char_2),A                                  
               LD   (char_3),A                                  
               RET             ; Ret to grab_block              
                                                                
; A block has been put in the buffer. Using "G" from menu 1     
; will reprint the block exactly as it was originaly.           
; It will overwrite anything that is already there so space has 
; to be made for it.                                            
                                                                
                                                                
reprint_block: LD   A,(buff_flag)                               
               CP   1                                           
               JP   NZ,no_para                                  
               LD   HL,BF_buffer                                
               LD   DE,(memry)                                  
rep_loop:      CALL peek_hl                                     
               CP   255                                         
               JP   Z,fini_rep                                  
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               JP   rep_loop                                    
                                                                
                                                                
fini_rep:      CALL clear_c_chars                               
               LD   A,255                                       
               LD   (ed_var),A                                  
               LD   (var),A                                     
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
; View the printer control codes 10 at a time                   
                                                                
                                                                
                                                                
view_codes:    CALL clear_screen                                
               LD   HL,chars2-512                               
               LD   (CHARSET),HL                                
               LD   A,1                                         
               LD   (pass),A        ; if pass = 2 then exit     
               LD   C,20            ; print 20 codes first time 
               LD   HL,32768+2048   ; Top of the screen         
               LD   (sposn2),HL                                 
               LD   (sc_pos),HL     ; store the print position  
               LD   HL,nlq_on       ; start of control data     
               PUSH HL              ; save for later            
               LD   HL,first_code   ; First string to print     
nextcode:      CALL prstr_2                                     
               INC  HL              ; point to next string      
               LD   (data_store),HL ; and store pointer         
               POP  HL              ; points to codes to print  
               CALL print_codes                                 
               DEC  C                                           
               LD   A,C                                         
               CP   0                                           
               JP   Z,next_lot                                  
               PUSH HL              ; Store position of next cd 
               LD   HL,(sc_pos)                                 
               LD   DE,1024                                     
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sposn2),HL                                 
               LD   (sc_pos),HL                                 
               LD   HL,(data_store)                             
               JR   nextcode                                    
                                                                
                                                                
                                                                
next_lot:      PUSH HL                                          
               CALL keypress                                    
               POP  HL                                          
               LD   A,(pass)                                    
               CP   2                                           
               JP   Z,leave_here                                
               PUSH HL                                          
               CALL clear_screen                                
               LD   A,2                                         
               LD   (pass),A                                    
               LD   HL,32768+2048                               
               LD   (sposn2),HL                                 
               LD   (sc_pos),HL                                 
               LD   C,19                                        
               LD   HL,(data_store)                             
               JP   nextcode                                    
                                                                
                                                                
leave_here:    LD   A,0                                         
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
; first byte in the data is how many codes there are            
                                                                
print_codes:   PUSH BC               ; Save main counter        
               LD   A,(HL)                                      
               LD   B,A              ; get count byte in "B"    
               INC  HL               ; first code to print      
nxt_code:      LD   A,(HL)                                      
               PUSH HL                                          
               PUSH BC                                          
               LD   H,0                                         
               LD   L,A                                         
               LD   C,1                                         
               CALL pnumber                                     
               LD   A,32                                        
               CALL pchar2_2                                    
               POP  BC                                          
               POP  HL                                          
               INC  HL                                          
               DEC  B                                           
               LD   A,B                                         
               CP   0                                           
               JR   NZ,nxt_code                                 
                                                                
                                                                
; all printable codes printed. zeros will not be printed        
; now find the start of the next control code before exiting    
                                                                
               POP  BC                                          
cont_start:    LD   A,(HL)                                      
               CP   0                                           
               RET  NZ                                          
               INC  HL                                          
               JR   cont_start                                  
                                                                
                                                                
pnumber:       LD   DE,100                                      
               CALL mult                                        
               LD   DE,10                                       
               CALL mult                                        
               LD   A,L                                         
               ADD  48                                          
               CALL pchar2_2                                    
               RET                                              
                                                                
; poke second character set into the screen                     
; this will be the set that is used by the menus and            
; error messages                                                
                                                                
poke_chars2:   LD   B,56                                        
               LD   HL,charend                                  
               LD   DE,bord_data                                
install2:      LD   A,(DE)                                      
               LD   (HL),A                                      
               INC  HL                                          
               INC  DE                                          
               DJNZ install2                                    
               DI                                               
               CALL screen_in                                   
               LD   BC,816            ; into the screen         
               LD   HL,eight_bit_2                              
               LD   DE,chars2                                   
convert_loop2: LD   A,(HL)                                      
               PUSH HL                                          
               PUSH BC                                          
               LD   C,A                                         
               LD   B,0                                         
               LD   HL,ctable         ; Character conversion    
               ADD  HL,BC             ; table                   
               ADD  HL,BC                                       
               LD   A,(HL)                                      
               LD   (DE),A                                      
               INC  HL                                          
               INC  DE                                          
               LD   A,(HL)                                      
               LD   (DE),A                                      
               POP  BC                                          
               POP  HL                                          
               INC  HL                                          
               INC  DE                                          
               DEC  BC                                          
               LD   A,B                                         
               OR   C                                           
               JP   NZ,convert_loop2                            
               EX   AF,AF'                                      
               OUT  (251),A                                     
               EI                                               
               RET                                              
                                                                
                                                                
                                                                
                                                                
screen_in:     IN   A,(251)        ; Page current screen        
               EX   AF,AF'         ; into address 32768         
               IN   A,(252)        ; SLOT C.                    
               AND  31                                          
               OUT  (251),A                                     
               RET                                              
                                                                
; input a string up to 25 chrs long and search the file         
; from the cursor position.                                     
                                                                
search_input:  CALL exit_box                                    
                                                                
; clear the input buffer before entering a new string           
                                                                
               LD   HL,sbuffer                                  
               LD   DE,sbuffer+1                                
               LD   BC,25                                       
               LD   A,32                                        
               LD   (HL),32                                     
               LDIR                                             
                                                                
                                                                
                                                                
                                                                
               CALL draw_box                                    
               CALL inverse                                     
               LD   HL,search_mess                              
               CALL prstr_2                                     
               CALL c_sr                                        
               LD   B,25      ; name length                     
               LD   DE,sbuffer                                  
spress:        CALL keypress                                    
               CALL sound2                                      
               CP   13                                          
               JP   Z,exit_s_inp ; Exit the search input        
               CP   12                                          
               JP   Z,sdel_ete                                  
               CP   32                                          
               JR   C,spress                                    
               CP   122                                         
               JR   NC,spress                                   
               LD   C,A       ; temp hold char and check B      
               LD   A,B                                         
               CP   0                                           
               JP   Z,spress                                    
               DEC  B                                           
               LD   A,C                                         
               CP   32                                          
               JR   Z,sno_set                                   
               SET  5,A                                         
sno_set:       CALL c_sr                                        
               LD   (DE),A                                      
               INC  DE                                          
               CALL pchar2_2                                    
               CALL c_sr                                        
               JP   spress                                      
                                                                
                                                                
sdel_ete:      LD   A,B                                         
               CP   25                                          
               JP   Z,spress                                    
               CALL c_sr                                        
               LD   HL,(sposn2)                                 
               DEC  L                                           
               DEC  L                                           
               LD   (sposn2),HL                                 
               LD   A,32                                        
               PUSH HL                                          
               DEC  DE                                          
               LD   (DE),A                                      
               CALL pchar2_2                                    
               POP  HL                                          
               LD   (sposn2),HL                                 
               INC  B                                           
               CALL c_sr                                        
               JP   spress                                      
                                                                
exit_s_inp:    LD   HL,sbuffer                                  
               LD   A,(HL)                                      
               CP   32                                          
               JP   Z,exits_inp                                 
               LD   A,0                                         
               LD   (lastk),A                                   
               CALL search_rtn                                  
               LD   A,0                                         
               LD   (lastk),A                                   
               JP   key                                         
                                                                
                                                                
exits_inp:     LD   A,0                                         
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
speed_read:    CALL strtln                                      
               CALL exit_box                                    
               CALL draw_box                                    
               LD   HL,38445                                    
               LD   (sposn2),HL                                 
               LD   HL,(memry)                                  
strt_speed:    LD   B,64                                        
strt_loop:     LD   A,(HL)                                      
               CP   255                                         
               JP   Z,exit_box                                  
               CP   32                                          
               JP   Z,get_nxt_word                              
               CP   "."                                         
               JP   Z,a_full_stop                               
               CALL pchar2_2                                    
               INC  HL                                          
               DJNZ strt_loop                                   
               CALL speed_pause                                 
               PUSH HL                                          
               CALL draw_box                                    
               LD   HL,38445                                    
               LD   (sposn2),HL                                 
               POP  HL                                          
               JP   strt_speed                                  
                                                                
speed_pause:   PUSH HL                                          
speed:         LD   HL,(spd_var)                                
get_nxt_pse:   DEC  HL                                          
               LD   A,H                                         
               OR   L                                           
               JR   NZ,get_nxt_pse                              
               POP  HL                                          
               RET                                              
                                                                
a_full_stop:   CALL pchar2_2                                    
               CALL speed_pause                                 
                                                                
                                                                
get_nxt_word:  CALL speed_pause                                 
               LD   A,(lastk)                                   
               CP   32                                          
               JP   Z,exit_speed                                
               CP   "1"                                         
               JP   Z,sp1                                       
               CP   "2"                                         
               JP   Z,sp2                                       
               CP   "3"                                         
               JP   Z,sp3                                       
               CP   11                                          
               JP   Z,inc_speed                                 
               CP   10                                          
               JP   Z,dec_speed                                 
               CP   13                                          
               CALL Z,keypress                                  
ret_to_here:   LD   A,0                                         
               LD   (lastk),A                                   
               PUSH HL                                          
               PUSH BC                                          
               CALL draw_box                                    
               POP  BC                                          
               LD   HL,38445                                    
               LD   (sposn2),HL                                 
               POP  HL                                          
               INC  HL                                          
               DEC  B                                           
not_space:     LD   A,(HL)                                      
               CP   32                                          
               JP   NZ,strt_loop                                
               CP   255                                         
               JP   Z,exit_box                                  
               INC  HL                                          
               DJNZ not_space                                   
               LD   B,64                                        
               JR   not_space                                   
                                                                
                                                                
exit_speed:    LD   A,0                                         
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
inc_speed:     LD   DE,(spd_var)                                
               INC  D                                           
               LD   (spd_var),DE                                
               JP   ret_to_here                                 
                                                                
dec_speed:     LD   DE,(spd_var)                                
               DEC  D                                           
               LD   (spd_var),DE                                
               JP   ret_to_here                                 
                                                                
                                                                
                                                                
sp1:           LD   DE,1000                                     
spp1:          LD   (spd_var),DE                                
               JP   ret_to_here                                 
                                                                
sp2:           LD   DE,5000                                     
               JR   spp1                                        
                                                                
sp3:           LD   DE,10000                                    
               JR   spp1                                        
                                                                
                                                                
                                                                
; Text bit map called from menu 1                               
; Do eight boxes to represent 8 pages of text                   
                                                                
                                                                
m_buffer:      DEFB 0   ; build up the byte value               
sc_store:      DEFW 0   ; hold hl screen position here          
scc_store:     DEFW 0   ; as above but temp                     
lines:         DEFB 60  ; 60 lines to do                        
tex_len:       DEFW 0   ; Text len held here                    
map_mem:       DEFW 0   ; Hold memry position for next box      
map_pos:       DEFW 0                                           
fifth_box:     DEFW 0   ; work out 5th box start from this var  
map_cur:       DEFW 0   ; Cursor position -                     
what_map:      DEFB 0   ; 0 = use map or 1 = just exit          
map_op_len:    DEFB 4   ; 4 options in the menu                 
                                                                
; ..........................................................    
                                                                
; map menu code                                                 
                                                                
                                                                
                                                                
tx_mapdat:     DEFW just_look                                   
               DEFW large_map                                   
               DEFW use_map                                     
               DEFW exit_opt                                    
                                                                
                                                                
                                                                
text_map:      LD   HL,37410+384                                
               LD   DE,map_data                                 
               CALL print_menu                                  
               LD   A,30                                        
               LD   (bar_length),A                              
               LD   A,98                                        
               LD   (bar_jump),A                                
               LD   A,(map_op_len)                              
                                                                
               LD   HL,41509+384                                
               LD   B,8                                         
               CALL get_op_len                                  
                                                                
                                                                
tx_men_loop:   CALL rd_key                                      
               CALL sound2                                      
               CP   13                                          
               LD   HL,tx_mapdat                                
               JP   Z,check_c                                   
               CP   "."                                         
               JP   Z,check_c                                   
               CP   f0                                          
               JP   Z,check_c                                   
               CP   10                                          
               JP   NZ,chk_elv                                  
               CALL next_option                                 
               JR   tx_men_loop                                 
                                                                
                                                                
                                                                
chk_elv:       CP   11                                          
               JR   NZ,map_hot_keys                             
               CALL prev_option                                 
               JR   tx_men_loop                                 
                                                                
                                                                
map_hot_keys:  RES  5,A                                         
               CP   "L"                                         
               JP   Z,large_map                                 
               CP   "V"                                         
               JP   Z,just_look                                 
               CP   "U"                                         
               JP   Z,use_map                                   
               CP   "Q"                                         
               JP   Z,exit_opt                                  
               JR   tx_men_loop                                 
                                                                
                                                                
; .......................................................       
                                                                
use_map:       LD   A,0                                         
               LD   (what_map),A                                
               CALL top_fle                                     
               JR   text_map1                                   
                                                                
just_look:     LD   A,1                                         
               LD   (what_map),A                                
text_map1:     LD   B,64              ; letters to a line       
               LD   A,(page_length)                             
               LD   E,A                                         
               LD   D,0               ; DE holds page length    
               LD   HL,0              ; HL = 0                  
               OR   A                 ; Clear the carry flag    
txt_m_loop:    ADC  HL,DE             ; loop till djnz fails    
               DJNZ txt_m_loop        ; HL now holds length of  
               LD   (tex_len),HL      ; 1 page of text.         
                                                                
                                                                
; box 1      lhc = Left hand corner                             
                                                                
box_poke:      LD   HL,35335                                    
               LD   (map_pos),HL                                
               CALL first_four                                  
                                                                
; now do bottom four boxes                                      
                                                                
box2_poke:     LD   HL,(fifth_box)                              
               LD   DE,1024                                     
               OR   A                                           
               ADC  HL,DE                                       
               LD   (map_pos),HL                                
               CALL map_box                                     
               LD   DE,(map_mem)                                
               LD   HL,(tex_len)                                
               OR   A                                           
               ADC  HL,DE                                       
               EX   DE,HL                                       
               LD   (map_mem),DE                                
               CALL next_four                                   
                                                                
               LD   A,(what_map)                                
               CP   1                                           
               JP   Z,exit_map                                  
                                                                
               JP   select_page                                 
                                                                
                                                                
                                                                
first_four:    CALL cls                                         
               LD   HL,(map_pos)    ; position of 1st box lhc   
               CALL map_box                                     
               LD   (fifth_box),HL  ; saved from map box call   
               LD   DE,(memry)      ; Cursor position           
               LD   (map_mem),DE                                
next_four:     LD   HL,(map_pos)    ; lhc + 1 char in and 1     
               LD   BC,516                                      
               OR   A                                           
               ADC  HL,BC                                       
               CALL poketext        ; down                      
                                                                
; box 2                                                         
                                                                
               LD   HL,(map_pos)                                
               LD   BC,30                                       
               OR   A                                           
               ADC  HL,BC                                       
               CALL map_box                                     
               LD   DE,(map_mem)                                
               LD   HL,(tex_len)                                
               OR   A                                           
               ADC  HL,DE                                       
               EX   DE,HL           ; memry pos now in de       
               LD   (map_mem),DE                                
               LD   HL,(map_pos)                                
               LD   BC,546                                      
               OR   A                                           
               ADC  HL,BC                                       
               CALL poketext                                    
                                                                
                                                                
; box 3                                                         
                                                                
               LD   HL,(map_pos)                                
               LD   BC,60                                       
               OR   A                                           
               ADC  HL,BC                                       
               CALL map_box                                     
               LD   DE,(map_mem)                                
               LD   HL,(tex_len)                                
               OR   A                                           
               ADC  HL,DE                                       
               EX   DE,HL                                       
               LD   (map_mem),DE                                
               LD   HL,(map_pos)                                
               LD   BC,576                                      
               OR   A                                           
               ADC  HL,BC                                       
               CALL poketext                                    
                                                                
                                                                
; box 4                                                         
                                                                
                                                                
               LD   HL,(map_pos)                                
               LD   BC,90                                       
               OR   A                                           
               ADC  HL,BC                                       
               CALL map_box                                     
               LD   DE,(map_mem)                                
               LD   HL,(tex_len)                                
               OR   A                                           
               ADC  HL,DE                                       
               EX   DE,HL                                       
               LD   (map_mem),DE                                
               LD   HL,(map_pos)                                
               LD   BC,606                                      
               OR   A                                           
               ADC  HL,BC                                       
               CALL poketext                                    
               RET                                              
                                                                
                                                                
                                                                
                                                                
poketext:      LD   (sc_store),HL                               
               LD   (scc_store),HL                              
               LD   A,(page_length)                             
               LD   (lines),A                                   
                                                                
               LD   HL,m_buffer                                 
loop3:         LD   C,16                                        
loop2:         LD   B,4                                         
loop1:         LD   A,(DE)                                      
               CP   32                                          
               JR   Z,blank_bit  ; just move bit left           
               SET  0,(HL)       ; Set bit to a 1               
               SET  1,(HL)                                      
                                                                
blank_bit:     SCF                                              
               CCF                                              
               SLA  (HL)         ; move to next bit             
               SLA  (HL)                                        
                                                                
               INC  DE           ; next letter in text          
               DJNZ loop1                                       
               CALL map_poke                                    
               XOR  A                                           
               LD   (HL),A                                      
               DEC  C                                           
               LD   A,C                                         
               CP   0                                           
               JR   NZ,loop2                                    
               LD   A,(lines)                                   
               DEC  A                                           
               LD   (lines),A                                   
               CP   0                                           
               RET  Z          ; back to call before poketext   
               EXX                                              
               LD   HL,(scc_store)                              
               LD   DE,128   ;      256                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sc_store),HL                               
               LD   (scc_store),HL                              
               EXX                                              
               JP   loop3                                       
                                                                
map_poke:      CALL screen_in                                   
               LD   A,(HL)                                      
               PUSH HL                                          
               LD   HL,(sc_store)                               
               LD   (HL),A                                      
               INC  HL                                          
               LD   (sc_store),HL                               
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  HL                                          
               RET                                              
                                                                
                                                                
exit_map:      CALL keypress                                    
exit_map2:     XOR  A                                           
               LD   (lastk),A                                   
               JP   exit_box                                    
                                                                
                                                                
; Draw an empty box for the text map                            
; entered with HL holding the top left corner of the box        
                                                                
map_box:       CALL screen_in                                   
                                                                
               LD   A,(page_length)                             
               ADD  A,8                                         
               LD   C,A             ; height into C reg         
               LD   A,255           ; char into A reg           
               LD   B,24            ; width into B reg          
               LD   DE,128                                      
               PUSH HL                                          
               PUSH BC                                          
bx_top:        LD   (HL),A          ; draw top line from left   
               INC  HL              ; to right for full         
               DJNZ bx_top          ; width in B, leaving HL    
               DEC  HL              ; pointing to TR corner     
                                                                
bx_right:      LD   (HL),A          ; draw right side from top  
               ADD  HL,DE           ; to bottom for full        
               DEC  C               ; height in C.              
               JR   NZ,bx_right                                 
               POP  BC              ; restore width and height  
               POP  HL              ; counts and TL address.    
                                                                
bx_left:       LD   (HL),A          ; draw left side from top   
               ADD  HL,DE           ; to bottom for full        
               DEC  C               ; height in C.              
               JR   NZ,bx_left                                  
               OR   A               ; clear Cflag and point HL  
               SBC  HL,DE           ; back to BL corner         
               PUSH HL              ; save hl for return        
bx_base:       LD   (HL),A          ; draw base line from left  
               INC  HL              ; to right for full         
               DJNZ bx_base         ; width in B.               
               POP  HL                                          
               EX   AF,AF'                                      
               OUT  (251),A                                     
               RET                                              
                                                                
                                                                
; Select page..... 8 boxes representing the text files are      
; now on the screen. Using left and right cursors, select a page
; of text. press Return to Display text from the top of selected
; page, Or use up down cursors to move through the selected page
; pressing Return will display from cursor position....         
                                                                
                                                                
cur_count:     DEFB 0   ; 1 to 8 for bit maps                   
                                                                
                                                                
select_page:   LD   A,1                                         
               LD   (cur_count),A                               
               LD   HL,35849                                    
               LD   (map_cur),HL                                
               CALL put_cursor                                  
map_key_loop:  CALL update                                      
               CALL sound2                                      
               CALL keypress                                    
               CP   13                                          
               JP   Z,exit_map2                                 
               CP   8                                           
               JP   Z,map_cur_left                              
               CP   9                                           
               JP   Z,map_cur_right                             
               CP   10               ; cursor down              
               JP   Z,map_cur_down                              
               CP   11                                          
               JP   Z,map_cur_up                                
               JR   map_key_loop                                
                                                                
                                                                
                                                                
map_cur_down:  LD   A,(page_length)                             
               LD   B,A                                         
               LD   A,(lline)                                   
               CP   B                                           
               JP   Z,map_key_loop                              
               INC  A                                           
               LD   (lline),A                                   
               CALL put_cursor     ; old cursor off             
               LD   HL,(map_cur)                                
               LD   DE,128                                      
               OR   A                                           
               ADC  HL,DE                                       
               LD   (map_cur),HL   ; new cursor on              
               CALL put_cursor                                  
               LD   HL,(memry)                                  
               LD   DE,64                                       
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               LD   HL,(total)                                  
               INC  HL                                          
               LD   (total),HL                                  
               JP   map_key_loop                                
                                                                
map_cur_up:    LD   A,(lline)                                   
               CP   1                                           
               JP   Z,map_key_loop                              
               DEC  A                                           
               LD   (lline),A                                   
               CALL put_cursor                                  
               LD   HL,(map_cur)                                
               LD   DE,128                                      
               OR   A                                           
               SBC  HL,DE                                       
               LD   (map_cur),HL                                
               CALL put_cursor                                  
               LD   HL,(memry)                                  
               LD   DE,64                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               LD   HL,(total)                                  
               DEC  HL                                          
               LD   (total),HL                                  
               JP   map_key_loop                                
                                                                
                                                                
                                                                
                                                                
map_cur_left:  LD   A,(cur_count)  ; maps 1 to 8                
               CP   1                                           
               JP   Z,map_key_loop                              
               DEC  A                                           
               LD   (cur_count),A                               
               PUSH AF                                          
               CALL put_cursor     ; wipe old cursor out        
               POP  AF                                          
               CP   4                                           
               JR   NZ,get_old_hl                               
                                                                
; cursor has to come from bottom row back to top row            
                                                                
               LD   HL,35811      ;   35849+90                  
               LD   A,(lline)                                   
               LD   B,A                                         
               LD   DE,128                                      
               OR   A                                           
ad_line_loop:  ADC  HL,DE                                       
               DJNZ ad_line_loop                                
               LD   (map_cur),HL                                
               CALL put_cursor                                  
               JR   adjust_vars_l                               
                                                                
get_old_hl:    LD   HL,(map_cur)                                
               LD   DE,30                                       
               OR   A                                           
               SBC  HL,DE                                       
               LD   (map_cur),HL                                
               CALL put_cursor                                  
                                                                
adjust_vars_l: LD   A,(pyge)                                    
               DEC  A                                           
               LD   (pyge),A                                    
               LD   HL,(memry)                                  
               LD   DE,(tex_len)                                
               OR   A                                           
               SBC  HL,DE                                       
               LD   (memry),HL                                  
               LD   HL,(total)                                  
               LD   A,(page_length)                             
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               SBC  HL,DE                                       
               LD   (total),HL                                  
               JP   map_key_loop                                
                                                                
                                                                
map_cur_right: LD   A,(cur_count)                               
               CP   8                                           
               JP   Z,map_key_loop                              
               INC  A                                           
               LD   (cur_count),A                               
               PUSH AF                                          
               CALL put_cursor     ; remove old cursor          
               POP  AF                                          
               CP   5                                           
               JP   Z,do_bot_row                                
               LD   HL,(map_cur)                                
               LD   DE,30                                       
               OR   A                                           
               ADC  HL,DE                                       
               LD   (map_cur),HL                                
               CALL put_cursor                                  
               JP   adjust_vars_r                               
                                                                
do_bot_row:    LD   A,(lline)                                   
               LD   B,A                                         
               LD   HL,0                                        
               LD   DE,128                                      
               OR   A                                           
dobot_loop:    ADC  HL,DE                                       
               DJNZ dobot_loop                                  
               EX   DE,HL            ; de holds result          
               LD   HL,(fifth_box)   ; was   do_bot_row         
               OR   A                                           
               ADC  HL,DE                                       
               LD   DE,1538-128                                 
               OR   A                                           
               ADC  HL,DE                                       
               LD   (map_cur),HL                                
               CALL put_cursor      ; new cursor on screen      
adjust_vars_r: LD   A,(pyge)                                    
               INC  A                                           
               LD   (pyge),A                                    
               LD   HL,(memry)                                  
               LD   DE,(tex_len)                                
               OR   A                                           
               ADC  HL,DE                                       
               LD   (memry),HL                                  
               LD   HL,(total)                                  
               LD   A,(page_length)                             
               LD   E,A                                         
               LD   D,0                                         
               OR   A                                           
               ADC  HL,DE                                       
               LD   (total),HL                                  
               JP   map_key_loop                                
                                                                
                                                                
                                                                
; xor the cursor on and off of the screen                       
                                                                
put_cursor:    PUSH HL                                          
               CALL screen_in                                   
               LD   HL,(map_cur)                                
               LD   A,(HL)                                      
               XOR  255                                         
               LD   (HL),A                                      
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  HL                                          
               RET                                              
                                                                
                                                                
                                                                
; large text map                                                
; 1 byte = 1 letter 1 byte = 1 space....                        
                                                                
large_map:     CALL cls                                         
               LD   HL,35840+30                                 
               LD   (sc_store),HL                               
               LD   (scc_store),HL                              
               LD   A,(page_length)                             
               LD   (lines),A                                   
               LD   DE,(memry)                                  
               LD   HL,m_buffer                                 
lr_loop3:      LD   C,32                                        
lr_loop2:      LD   B,2                                         
               SLA  (HL)                                        
               SLA  (HL)                                        
lr_loop1:      LD   A,(DE)                                      
               CP   32                                          
               JR   Z,lr_blankbit                               
               SET  0,(HL)                                      
               SET  1,(HL)                                      
                                                                
lr_blankbit:   SCF                                              
               CCF                                              
               SLA  (HL)                                        
               SLA  (HL)                                        
               RES  0,(HL)                                      
               RES  1,(HL)                                      
               INC  DE                                          
               DJNZ lr_loop1                                    
                                                                
; poke byte into screen                                         
                                                                
               CALL screen_in                                   
               LD   A,(HL)                                      
               PUSH HL                                          
               LD   HL,(sc_store)                               
               LD   (HL),A                                      
               INC  HL                                          
               LD   (sc_store),HL                               
               EX   AF,AF'                                      
               OUT  (251),A                                     
               POP  HL                                          
                                                                
               DEC  C                                           
               LD   A,C                                         
               CP   0                                           
               JR   NZ,lr_loop2                                 
               LD   A,(lines)                                   
               DEC  A                                           
               LD   (lines),A                                   
               CP   0                                           
               JP   Z,exit_map                                  
               EXX                                              
               LD   HL,(scc_store)                              
               LD   DE,256                                      
               OR   A                                           
               ADC  HL,DE                                       
               LD   (sc_store),HL                               
               LD   (scc_store),HL                              
               EXX                                              
               JP   lr_loop3                                    
                                                                
                                                                
                                                                
                                                                
map_data:      DEFB 129,"!",16,133,128,13,132                   
               DEFB "!",16,32,132,13,132                        
               DEFM " TEXT BIT MAPS  "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132                        
               DEFM " Q Quit menu    "                          
               DEFB 132,13,132                                  
               DEFM " U Use the map  "                          
               DEFB 132,13,132                                  
               DEFM " L Large map    "                          
               DEFB 132,13,132                                  
               DEFM " V View maps    "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132                        
               DEFB "!",16,32,132,13,131,"!",16,133,130,255     
                                                                
                                                                
                                                                
                                                                
first_code:    DEFM "N NLQ        ON   "                        
               DEFB 255                                         
               DEFM "B BOLD       ON   "                        
               DEFB 255                                         
               DEFM "I ITALICS    ON   "                        
               DEFB 255                                         
               DEFM "S SUBSCRIPT  ON   "                        
               DEFB 255                                         
               DEFM "H DOUBLE HT  ON   "                        
               DEFB 255                                         
               DEFM "U UNDERLINE  ON   "                        
               DEFB 255                                         
               DEFM "O OVERSCORE  ON   "                        
               DEFB 255                                         
               DEFM "M MASTER RESET    "                        
               DEFB 255                                         
               DEFM "n NLQ        OFF  "                        
               DEFB 255                                         
               DEFM "b BOLD       OFF  "                        
               DEFB 255                                         
               DEFM "i ITALICS    OFF  "                        
               DEFB 255                                         
               DEFM "s SUBSCRIPT  OFF  "                        
               DEFB 255                                         
               DEFM "h DOUBLE HT  OFF  "                        
               DEFB 255                                         
               DEFM "u UNDERLINE  OFF  "                        
               DEFB 255                                         
               DEFM "o OVERSCORE  OFF  "                        
               DEFB 255                                         
               DEFM "E EMPHASISED ON   "                        
               DEFB 255                                         
               DEFM "e EMPHASISED OFF  "                        
               DEFB 255                                         
               DEFM "D DBL STRIKE ON   "                        
               DEFB 255                                         
               DEFM "d DBL STRIKE OFF  "                        
               DEFB 255                                         
               DEFM "C CONDENSED  ON   "                        
               DEFB 255                                         
               DEFM "c CONDENSED  OFF  "                        
               DEFB 255                                         
               DEFM "P PROPORT    ON   "                        
               DEFB 255                                         
               DEFM "p PROPORT    OFF  "                        
               DEFB 255                                         
               DEFM "R REVERSE    ON   "                        
               DEFB 255                                         
               DEFM "r REVERSE    OFF  "                        
               DEFB 255                                         
               DEFM "W DBL WIDTH  ON   "                        
               DEFB 255                                         
               DEFM "w DBL WIDTH  OFF  "                        
               DEFB 255                                         
               DEFM "` POUND CHAR      "                        
               DEFB 255                                         
               DEFM "# HASH CHAR       "                        
               DEFB 255                                         
               DEFM "1 USER DEFINED 1  "                        
               DEFB 255                                         
               DEFM "2 USER DEFINED 2  "                        
               DEFB 255                                         
               DEFM "3 USER DEFINED 3  "                        
               DEFB 255                                         
               DEFM "4 USER DEFINED 4  "                        
               DEFB 255                                         
               DEFM "5 USER DEFINED 5  "                        
               DEFB 255                                         
               DEFM "6 USER DEFINED 6  "                        
               DEFB 255                                         
               DEFM "7 USER DEFINED 7  "                        
               DEFB 255                                         
               DEFM "8 USER DEFINED 8  "                        
               DEFB 255                                         
               DEFM "9 USER DEFINED 9  "                        
               DEFB 255                                         
               DEFM "0 USER DEFINED 0  "                        
               DEFB 255                                         
                                                                
                                                                
                                                                
search_mess:   DEFM "Enter String: "                            
               DEFB 255                                         
                                                                
                                                                
                                                                
the_name:      DEFM " File name  "                              
               DEFB 255                                         
dun:           DEFM "  Press a key to continue"                 
               DEFB 255                                         
                                                                
                                                                
must_have:     DEFM " Sorry I must have a valid File name"      
               DEFB 255                                         
                                                                
input_mess:    DEFM "Input File name to Save :"                 
               DEFB 255                                         
                                                                
save_message:  DEFM " Return to save "                          
               DEFB 255                                         
save_mes_2:    DEFM " Edit for a New name"                      
               DEFB 255                                         
                                                                
question_save: DEFM " Overwrite  "                              
               DEFB 255                                         
quest_save:    DEFM "  Y or N "                                 
               DEFB 255                                         
                                                                
                                                                
ERR:           DEFM " ERROR...."                                
               DEFB 255                                         
                                                                
trk_sect:      DEFM "Track and Sector error."                   
               DEFB 255                                         
cant_erase:    DEFM "You cannot erase this file."               
               DEFB 255                                         
restricted:    DEFM "Dict and Info are restricted."             
               DEFB 255                                         
                                                                
                                                                
                                                                
                                                                
no_disk:       DEFM "Disk missing from drive 1."                
               DEFB 255                                         
invalid:       DEFM "Invalid file name."                        
               DEFB 255                                         
wrong_file:    DEFM "Wrong file type "                          
               DEFB 255                                         
protected:     DEFM "Disk is write protected."                  
               DEFB 255                                         
run_out:       DEFM "Not enough room on disk."                  
               DEFB 255                                         
dir_full:      DEFM "Directory is full."                        
               DEFB 255                                         
f_not_found:   DEFM "File not found."                           
               DEFB 255                                         
not_known:     DEFM "I dont have a clue."                       
               DEFB 255                                         
esc_pressed:   DEFM "Escape pressed..make up your mind ??"      
               DEFB 255                                         
do_something:  DEFM "     Fix Error and Press a key to try"     
               DEFM " again"                                    
               DEFB 255                                         
                                                                
                                                                
                                                                
save_mess:     DEFM " Saving "                                  
               DEFB 255                                         
                                                                
                                                                
load_message:  DEFM " Loading    "                              
               DEFB 255                                         
                                                                
erase_message: DEFM " Erasing    "                              
               DEFB 255                                         
                                                                
merge_message: DEFM " Mergeing   "                              
               DEFB 255                                         
                                                                
load_rest:     DEFM "   Please Wait... "                        
               DEFB 255                                         
                                                                
to_load_mess:  DEFM "Press Return to load "                     
               DEFB 255                                         
                                                                
                                                                
to_erase_mess: DEFM "Press Return to erase "                    
               DEFB 255                                         
                                                                
to_merge_mess: DEFM "Press Return to merge "                    
               DEFB 255                                         
                                                                
the_rest:      DEFM " Space to Exit"                            
               DEFB 255                                         
                                                                
                                                                
fetching:      DEFM " PLEASE WAIT IM FETCHING THE DIRECTORY "   
               DEFM "FOR YOU"                                   
               DEFB 255                                         
                                                                
no_file_mess:  DEFM "      Sorry there's no file here.      "   
               DEFM "        "                                  
               DEFB 255                                         
                                                                
dir_mess1:     DEFM "Free kilobytes   "                         
               DEFB 255                                         
                                                                
dir_mess2:     DEFM "Files   "                                  
               DEFB 255                                         
                                                                
dir_mess3:     DEFM "Free slots"                                
               DEFB 255                                         
                                                                
                                                                
                                                                
schange_menu:  DEFB 129,"!",37,133,128,13,132                   
               DEFB "!",37,32,132,13,132                        
               DEFM "              IMPORTANT              "     
               DEFB 132,13,132                                  
               DEFB "!",37,32,132,13,132                        
               DEFM " Any changes you have made to the    "     
               DEFB 132,13,132                                  
               DEFM " Program eg colour,word wrap,justify "     
               DEFB 132,13,132                                  
               DEFM " etc, will be made permanent when    "     
               DEFB 132,13,132                                  
               DEFM " you use this save option.           "     
               DEFB 132,13,132,"!",37,32,132,13,132             
               DEFM "         PLEASE BE CAREFUL.          "     
               DEFB 132,13,132,"!",37,32,132,13,132             
               DEFM "            PRESS Y or N             "     
               DEFB 132,13,132,"!",37,32,132,13,131,"!"         
               DEFB 37,133,130,255                              
                                                                
                                                                
                                                                
                                                                
basic_exit:    DEFM " So you want to play about with "          
               DEFM "basic do you Y/N "                         
               DEFB 255                                         
                                                                
                                                                
                                                                
page_l_data:   DEFM "Use cursors to change page length."        
               DEFM " Length = "                                
               DEFB 255                                         
                                                                
                                                                
                                                                
page_data:     DEFM " Use cursors to change page start."        
               DEFM " Start = "                                 
               DEFB 255                                         
                                                                
p_col_data:    DEFM "Use cursors to change printer col."        
               DEFM " Start = "                                 
               DEFB 255                                         
                                                                
dump_data:     DEFM "Use cursors to change dump length."        
               DEFM " Length = "                                
               DEFB 255                                         
                                                                
                                                                
                                                                
skip_data:     DEFM "Use cursors to change skip values."        
               DEFM " Value = "                                 
               DEFB 255                                         
                                                                
                                                                
cursor_data:   DEFM "Use cursors to change cur height. "        
               DEFM " Height = "                                
               DEFB 255                                         
                                                                
                                                                
carriage_data: DEFM "Carriage Return Y or N. Currently "        
               DEFM "turned "                                   
               DEFB 255                                         
                                                                
c_on:          DEFM "On "                                       
               DEFB 255                                         
c_off:         DEFM "Off "                                      
               DEFB 255                                         
                                                                
                                                                
                                                                
                                                                
option_data:   DEFB 129,"!",28,133,128,13,132                   
               DEFB "!",28,32,132,13,132                        
               DEFM "        OPTIONS MENU        "              
               DEFB 132,13,132                                  
               DEFB "!",28,32,132,13,132                        
               DEFM " Q. Quit this menu          "              
               DEFB 132,13,132                                  
               DEFM " S. Save the working copy   "              
               DEFB 132,13,132                                  
               DEFM " B. Exit to basic           "              
               DEFB 132,13,132                                  
               DEFM " P. New page number start   "              
               DEFB 132,13,132                                  
               DEFM " L. New page length         "              
               DEFB 132,13,132                                  
               DEFM " D. Set screen dump length  "              
               DEFB 132,13,132                                  
               DEFM " R. Line feed on/off        "              
               DEFB 132,13,132                                  
               DEFM " C. Set left col on printer "              
               DEFB 132,13,132                                  
               DEFM " H. Set cursor height.      "              
               DEFB 132,13,132                                  
               DEFM " K. Set skip perforations   "              
               DEFB 132,13,132                                  
               DEFM " F. Do a form feed          "              
               DEFB 132,13,132                                  
               DEFB "!",28,32,132,13,132                        
               DEFM "   PRESS RETURN TO SELECT   "              
               DEFB 132,13,132                                  
               DEFB "!",28,32,132,13,131,"!",28,133,130,255     
                                                                
                                                                
                                                                
                                                                
font_data:     DEFB 129,"!",16,133,128,13,132                   
               DEFB "!",16,32,132,13,132                        
               DEFM "      FONTS     "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132                        
               DEFM " Q. Quit Fonts  "                          
               DEFB 132,13,132                                  
               DEFM " F. From disk   "                          
               DEFB 132,13,132                                  
               DEFM " D. Default     "                          
               DEFB 132,13,132                                  
               DEFM " 1. Gothic set  "                          
               DEFB 132,13,132                                  
               DEFM " 2. Oldchr set  "                          
               DEFB 132,13,132                                  
               DEFM " 3. Pretty set  "                          
               DEFB 132,13,132                                  
               DEFM " 4. Thick  set  "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,132                        
               DEFM " Ret to Select  "                          
               DEFB 132,13,132                                  
               DEFB "!",16,32,132,13,131,"!",16,133,130,255     
                                                                
                                                                
                                                                
col_1_num:     DEFM " Screen Colour= "                          
               DEFB 255                                         
col_2_num:     DEFM " Menu Colours = "                          
               DEFB 255                                         
                                                                
colour_box:    DEFB 129,"!",42,133,128,13,132                   
               DEFB "!",42,32,132,13,132                        
               DEFM " Cursor up/down    = Change Screen Colour "
               DEFB 132,13,132                                  
               DEFB "!",42,32,132,13,132                        
               DEFM " Cursor left/right = Change Menu Colour   "
               DEFB 132,13,132                                  
               DEFB "!",42,32,132,13,132                        
               DEFM " Press 1 to Change to Black and White     "
               DEFB 132,13,132                                  
               DEFB "!",42,32,132,13,132                        
               DEFM " Press 2 to change to default colour      "
               DEFB 132,13,132                                  
               DEFB "!",42,32,132,13,132                        
               DEFM "           PRESS RETURN TO EXIT           "
               DEFB 132,13,132                                  
               DEFB "!",42,32,132,13,131,"!",42,133,130,255     
                                                                
; Dir box data                                                  
                                                                
top_lin:       DEFB 129,"!",10,133,128                          
               DEFB 129,"!",10,133,128                          
               DEFB 129,"!",10,133,128                          
               DEFB 129,"!",10,133,128,13,255                   
                                                                
mid_lin:       DEFB 132,"!",10,32,132                           
               DEFB 132,"!",10,32,132                           
               DEFB 132,"!",10,32,132                           
               DEFB 132,"!",10,32,132,13,255                    
                                                                
                                                                
bot_lin:       DEFB 131,"!",10,133,130                          
               DEFB 131,"!",10,133,130                          
               DEFB 131,"!",10,133,130                          
               DEFB 131,"!",10,133,130,255                      
                                                                
                                                                
                                                                
                                                                
inbox_data:    DEFB 129,"!",51,133,128,13                       
               DEFB 132,"!",51,32,132,13                        
               DEFB 131,"!",51,133,130,255                      
                                                                
                                                                
                                                                
cbox_data:     DEFB 129,"!",42,133,128,13                       
               DEFB 132,"!",42,32,132,13                        
               DEFB 131,"!",42,133,130,255                      
                                                                
                                                                
                                                                
name_buffer1:  DEFM "          "   ; file 1 name buffer         
               DEFB 255                                         
name_buffer2:  DEFM "          "   ; file 2 name buffer         
               DEFB 255                                         
name_buffer3:  DEFM "          "   ; file 3 name buffer         
               DEFB 255                                         
name_buffer4:  DEFM "          "   ; merge and erase buffer     
               DEFB 255            ; Block save. load chars     
                                                                
                                                                
                                                                
sound_data:    DEFB 28,1,0,254,8,50,16,7,20,1,255               
sound_data2:   DEFB 28,1,0,254,8,50,16,7,20,1,255               
                                                                
col_1:         DEFB 24                                          
col_2:         DEFB 0                                           
col_3:         DEFB 0                                           
col_4:         DEFB 110                                         
col_5:         DEFB 0                                           
col_6:         DEFB 0                                           
col_7:         DEFB 0                                           
col_8:         DEFB 0                                           
col_9:         DEFB 0                                           
col_10:        DEFB 0                                           
col_11:        DEFB 0                                           
col_12:        DEFB 0                                           
col_13:        DEFB 0                                           
col_14:        DEFB 0                                           
col_15:        DEFB 0                                           
c_table:       DEFB 0                                           
                                                                
