10 REM > LCD/lbr
   20 REM Z80 8-bit LCD library
   30 REM
   40 REM
   50 OSBYTE=&FFF4
   60 mcode%=&C000:code%=&C000
   70 FOR P=0 TO 1
   80   P%=mcode%:O%=code%
   90   [OPT P*3+4
  100   .INIT_ALL:  JP Init_all
  110   .PR_STRING: JP Pr_String
  120   .PR_TEXT:   JP Pr_Text
  130   RET:NOP:NOP
  140   RET:NOP:NOP
  150   RET:NOP:NOP
  160   RET:NOP:NOP
  170   RET:NOP:NOP
  180   RET:NOP:NOP
  190   :
  200   :
  210   .Init_all
  220   LD BC,&0100:CALL SendCom
  230   LD BC,&0101:JR SendCom
  240   :
  250   .Get_portNum
  260   \ C=part no (0/1)
  270   SLA C
  280   .Get_port
  290   \ C=Y coord
  300   LD A,C:AND 2:OR &80:XOR 2:LD L,A
  310   RET
  320   \ L=port addr of command reg
  330   :
  340   .SendCom_C:      \ C=Y addr
  350   SRL C
  360   .SendCom:        \ C=port num, B=command
  370   CALL Get_portNum:\ L=port addr
  380   CALL IOwait_busy
  390   INC A
  400   LD H,B:          \ command
  410   CALL OSBYTE:     \ Send command
  420   LD A,B:CP 12:    \ Display off
  430   RET Z
  440   CALL IOwait_busy:\ Wait until not busy
  450   INC A
  460   LD H,13:\ disp on
  470   JP OSBYTE
  480   :
  490   .IOwait_busy
  500   \ L=port number
  510   LD A,146
  520   .IOwait_loop
  530   CALL &FFF4
  540   BIT 7,H
  550   JR NZ,IOwait_loop
  560   RET
  570   \ A=146, L=port, H=corrupt
  580   :
  590   :
  600   .Pr_String
  610   \ HL=string
  620   \ BC=coords
  630   PUSH AF:PUSH BC:PUSH DE
  640   EX DE,HL:     \ DE=string
  650   LD A,C:RRCA:RRCA:RRCA
  660   AND 64:OR B:OR 128:LD B,A
  670   CALL SendCom_C:\ Send comm to set addr of cursor
  680   \ A=147, B=addr, C=Y coord, H=corrupt, L=port
  690   INC L:         \ L= data port
  700   .Pr_Str_lp
  710   LD A,(DE):AND A
  720   JR Z,Pr_Str_End
  730   LD H,A:LD A,147
  740   CALL OSBYTE
  750   INC DE:JR Pr_Str_lp
  760   .Pr_Str_End
  770   EX DE,HL
  780   POP DE:POP BC:POP AF
  790   RET
  800   \ HL=zero byte marker
  810   \ DE, BC, AF=ok
  820   :
  830   .Pr_Text
  840   \ Prints in-line text
  850   EX (SP),HL
  860   CALL Pr_String
  870   EX (SP),HL
  880   RET
  890   \ Regs preserved
  900   ]
  910 NEXT