home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug094.arc / FIX-256.ARC / KEYBOARD.DOC < prev    next >
Text File  |  1988-06-14  |  52KB  |  1,682 lines

  1.                  Programming Notes on the 256TC
  2.  
  3.  
  4.  
  5.      Thesσ note≤ havσ beeε compileΣ froφ variou≤ source≤ anΣ havσ ì
  6. beeε designeΣ t∩ aiΣ thσ develope≥ t∩ producσ softwarσ whicΦ wil∞ ì
  7. ruε efficientl∙ oε Microbee'≤ ne≈ 256T├ mode∞ microcomputer«  I⌠ ì
  8. als∩ aim≤ t∩ givσ hiφ hel≡ iε maintaininτ compatibilit∙ witΦ ì
  9. olde≥ mode∞ Microbees«  Thσ note≤ arσ iε threσ section≤ - thσ ì
  10. firs⌠ deal≤ witΦ thσ ne≈ keyboard¼ thσ seconΣ witΦ colou≥ anΣ ì
  11. graphic≤ anΣ thσ thirΣ deal≤ witΦ ho≈ t∩ usσ ZBASIC¼ ß versioε oµ ì
  12. MicroWorlΣ BASI├ v6.22σ whicΦ i≤ compatiblσ witΦ mos⌠ operatinτ ì
  13. systems.
  14.  
  15.      Thesσ note≤ havσ beeε issueΣ witΦ aε accompanyinτ disδ whicΦ ì
  16. contain≤ program≤ anΣ routine≤ whicΦ ma∙ als∩ bσ oµ somσ usσ t∩ ì
  17. developers«  Al∞ routine≤ giveε iε thesσ programminτ note≤ caε bσ ì
  18. founΣ oε thσ accompanyinτ disδ eithe≥ iε thσ filσ ROUTINES.PA╦ iµ ì
  19. the∙ arσ assembl∙ language¼ o≥ a≤ separatσ .MW┬ file≤ iµ the∙ arσ ì
  20. BASIC«  Al∞ assembl∙ languagσ routine≤ havσ beeε designeΣ t∩ bσ ì
  21. assembleΣ b∙ thσ MACRO-8░ assembler«  Somσ modificatioε ma∙ bσ ì
  22. necessar∙ fo≥ othe≥ assemblers.
  23.  
  24.  
  25.  
  26.                               INDEX
  27.  
  28.  
  29.                Section                            Page
  30.  
  31.                I   The 256TC Keyboard             2
  32.  
  33.                II  Colour & Graphics              18
  34.  
  35.                III Using ZBASIC                   32
  36. .paèSECTION I : The Keyboard
  37.  
  38.  
  39.  
  40. Introduction
  41.  
  42.      Thσ 256T├ Microbeσ use≤ ß ne≈ keyboard«  Thi≤ ne≈ keyboarΣ ì
  43. represent≤ ß significan⌠ improvemen⌠ ove≥ thσ previou≤ design¼ ì
  44. no⌠ onl∙ iε it≤ improveΣ looδ anΣ feel¼ easσ oµ usσ anΣ increaseΣ ì
  45. numbe≥ oµ keys¼ bu⌠ als∩ iε it≤ simplicit∙ t∩ implemen⌠ iε ì
  46. programming«  However¼ i⌠ present≤ ß majo≥ probleφ wheε tryinτ t∩ ì
  47. maintaiε compatibilit∙ witΦ olde≥ microbees«  Thσ proliferatioε ì
  48. oµ differen⌠ operatinτ system≤ anΣ shell≤ iε recen⌠ year≤ ha≤ ì
  49. madσ thσ probleφ eveε harder¼ bu⌠ thσ probleφ i≤ no⌠ ì
  50. insurmountable«  Thesσ note≤ includσ tip≤ anΣ technique≤ t∩ hel≡ ì
  51. thσ programme≥ ge⌠ thσ maximuφ benefit≤ ou⌠ oµ thi≤ ne≈ keyboard.
  52.  
  53.  
  54.  
  55. Implementation in Microworld BASIC
  56.  
  57.  
  58.      WitΦ eacΦ Microbeσ solΣ t∩ date¼ ß versioε oµ BASI├ ha≤ beeε ì
  59. issueΣ o≥ made availablσ whicΦ ha≤ beeε designeΣ t∩ ruε witΦ tha⌠ ì
  60. mode∞ oµ Microbeσ anΣ witΦ it≤ particula≥ shel∞ anΣ operatinτ ì
  61. system«  Onσ oµ thσ problem≤ faceΣ b∙ developer≤ i≤ tha⌠ wheε ì
  62. the∙ havσ writteε ß prograφ iε BASI├ oε thei≥ machinσ anΣ havσ ì
  63. theε useΣ thσ disδ oε o≥ distributeΣ ß cop∙ oµ thσ disδ t∩ ì
  64. anothe≥ mode∞ oµ Microbee¼ i⌠ n∩ longe≥ works«  Thi≤ i≤ becausσ ì
  65. onσ oµ threσ thing≤ i≤ incompatiblσ witΦ thσ othe≥ Microbee:
  66.    * the operating system or shell
  67.    * the version of BASIC, or
  68.    * the BASIC program itself
  69.  
  70.      Man∙ oµ thσ recen⌠ operatinτ system≤ anΣ shell≤ arσ ver∙ ì
  71. finick∙ a≤ t∩ whethe≥ the∙ arσ runninτ oε ß 256T├ o≥ ß 128k¼ o≥ ì
  72. oε ß 128δ o≥ ß 64k¼ etc«  Also¼ ß versioε oµ BASI├ runninτ unde≥ ì
  73. ß Shel∞ i⌠ wa≤ no⌠ designeΣ fo≥ ma∙ als∩ creatσ problems«  Fo≥ ì
  74. instance¼ thσ lates⌠ version≤ oµ BASI├ (version≤ 6.│ anΣ later⌐ ì
  75. wil∞ no⌠ worδ oε ß 64δ compute≥ a⌠ al∞ a≤ thσ BASI├ i≤ simpl∙ t∩ ì
  76. biτ t∩ fi⌠ iε memory«  Iµ thσ probleφ i≤ eithe≥ thσ operatinτ ì
  77. system¼ shel∞ o≥ thσ versioε oµ BASIC¼ tw∩ possiblσ solution≤ are
  78.   i  distributσ thσ program≤ oε disk≤ withou⌠ thσ operatinτ ì
  79. ááááásysteφ o≥ shel∞ anΣ withou⌠ ß versioε oµ BASIC¼ insteaΣ ì
  80. áááááleavinτ thσ enΣ use≥ t∩ suppl∙ hi≤ owε versioε oµ CP/═ anΣ ì
  81. áááááBASIC¼ or
  82.   ii distributσ thσ program≤ witΦ ZBASI├ anΣ thσ CCP┌ operatinτ ì
  83. ááááásystem (see details of ZBASIC and CCPZ below).
  84.  
  85.      Iµ thσ probleφ i≤ witΦ thσ BASI├ prograφ itselµ theε thσ ì
  86. followinτ note≤ oε maintaininτ compatibilit∙ wil∞ bσ useful.
  87.  
  88.      Al∞ keyboarΣ command≤ iε BASI├ (eg« INPUT¼ KEY$⌐ wil∞ worδ ì
  89. identicall∙ fo≥ olΣ anΣ ne≈ keyboards«  Therefore¼ al∞ program≤ ì
  90. usinτ thesσ command≤ shoulΣ encounte≥ n∩ problem≤ iµ yo⌡ arσ ìèusinτ thσ correc⌠ versioε oµ BASI├ fo≥ you≥ machinσ (ie« thσ ì
  91. versioε oµ BASI├ designeΣ t∩ worδ witΦ you≥ system)«  However¼ ì
  92. machinσ codσ fragment≤ imbeddeΣ withiε BASI├ program≤ ma∙ presen⌠ ì
  93. ß probleφ iµ the∙ arσ designeΣ t∩ scaε thσ keyboard«  Thesσ ì
  94. shoulΣ bσ carefull∙ checkeΣ t∩ seσ tha⌠ the∙ mee⌠ thσ ì
  95. compatibilit∙ criteriß se⌠ ou⌠ below.
  96.  
  97.      Compatibilit∙ witΦ existinτ BASIC≤ oµ an∙ embeddeΣ machinσ ì
  98. codσ fragmen⌠ withiε ß BASI├ prograφ i≤ assureΣ providinτ it≤ ì
  99. operatioε relie≤ on
  100.    * memory location 10╢ (ASCI╔ valuσ oµ las⌠ ke∙ pressed)
  101.    * keyboarΣ routine a⌠ 800╢ (DGO╙ wai⌠ fo≥ keyboarΣ input)
  102.    * keyboard routine atá800╣ (DGO╙ scaε keyboard)
  103.    ¬ keyboarΣ routinσ a⌠ A50┴ (tes⌠ iµ ke∙ i≤ pressed, Is_Closed⌐
  104.    * routine a⌠ 803╞ (redirecteΣ input⌐, or
  105.    ¬ routine at A5C▓ (linσ inpu⌠ oµ text)
  106.  
  107.      Iµ method≤ othe≥ thaε thesσ havσ beeε employeΣ t∩ scaε thσ ì
  108. keyboarΣ theε compatibilit∙ i≤ no⌠ guaranteeΣ anΣ the∙ neeΣ t∩ bσ ì
  109. modifieΣ s∩ tha⌠ the∙ eithe≥ usσ thσ abovσ method≤ o≥ usσ ì
  110. additiona∞ method≤ discusseΣ iε thσ sectioε, Implementatioε iε ì
  111. Machine Language, below.
  112.  
  113.      Notσ tha⌠ thσ routine≤ a⌠ A50┴ anΣ A5C▓ arσ non-standarΣ ì
  114. interna∞ routines«  BotΦ oµ thesσ routine≤ arσ supporteΣ iε ì
  115. existinτ BASICs«  However¼ a≤ s∩ man∙ programmer≤ usσ thσ routinσ ì
  116. a⌠ A50A¼ i⌠ ha≤ beeε decideΣ tha⌠ thi≤ routinσ wil∞ also bσ retaineΣ ì
  117. iε al∞ futurσ version≤ oµ BASI├.
  118.  
  119.  
  120.  
  121. Implementation in Machine Language.
  122.  
  123.  
  124.      Thσ ne≈ 256T├ keyboarΣ i≤ fundamentall∙ differen⌠ t∩ thσ olΣ ì
  125. standarΣ Microbeσ keyboard«  Hence¼ aε entirel∙ ne≈ programminτ ì
  126. approacΦ i≤ needeΣ t∩ usσ thσ keyboard«  Fortunately¼ thσ newe≥ ì
  127. version≤ oµ CP/═ releaseΣ witΦ thσ 256T├ automaticall∙ detec⌠ ì
  128. whicΦ keyboarΣ i⌠ i≤ runninτ oε anΣ swap≤ ove≥ it≤ keyboarΣ ì
  129. routine≤ accordingly«  Thus¼ keyboarΣ inpu⌠ ma∙ bσ carrieΣ ou⌠ ì
  130. normall∙ b∙ usinτ thσ standarΣ BDO╙ anΣ BIO╙ routines.
  131.  
  132.  
  133.  
  134. XBIOS subset 'C'
  135.  
  136.  
  137.      Iε additioε t∩ thesσ routines¼ extrß keyboarΣ routine≤ havσ ì
  138. beeε addeΣ iε thσ currentl∙ existinτ extendeΣ BIO╙ (XBIOS)«  ì
  139. However¼ i⌠ mus⌠ bσ pointeΣ ou⌠ tha⌠ man∙ version≤ oµ CP/═ ì
  140. releaseΣ witΦ olde≥ Microbee≤ d∩ no⌠ suppor⌠ XBIOS¼ s∩ thσ ì
  141. application≤ oµ thesσ routine≤ arσ limiteΣ iµ thσ programme≥ ì
  142. want≤ compatibilit∙ witΦ al∞ systems«
  143.  
  144. .cp 5è     T∩ usσ thesσ extrß routines¼ i⌠ i≤ necessar∙ t∩ determinσ iµ ì
  145. thσ BIO╙ you≥ CP/═ applicatioε i≤ runninτ unde≥ i≤ thσ requireΣ ì
  146. versioε oµ XBIO╙ (knowε a≤ subse⌠ 'C')«  T∩ d∩ this¼ thσ versioε ì
  147. numbe≥ oµ thσ BIO╙ i≤ checked«  Thσ followinτ routinσ i≤ aε ì
  148. examplσ oµ ho≈ thi≤ caε bσ done
  149.  
  150. ;----------------<ROUTINE to CHECK BIOS NUMBER>-----------------
  151.  
  152. biosvct    equ    0001h
  153.  
  154. Check_BIOS:
  155. ; Check_BIOS checks the BIOS version number to find out whether
  156. ; the BIOS supports XBIOS subset 'C'.  It uses this logic:
  157. ; IF Bios_Type IS
  158. ;   > 1 and < 17h and <> 6 or
  159. ;   > 1Dh and < 2Fh or
  160. ;   > 43h and < BFh
  161. ; THEN XBIOS subset 'C' is supported
  162. ; ELSE subset 'C' is not supported (see notes below for this case)
  163. ; If XBIOS is supported then the Z flag will be set
  164.  
  165.     push    de
  166.     push    hl
  167.     lΣ    hl,(biosvct⌐    ╗ warφ star⌠ entr∙ (BIO╙ ½ 3)
  168.     ld    de,30h
  169.     add    hl,de        ╗ (BIO╙ ½ 33h⌐ ╜ BIOS_TYPE
  170.     ld    e,a
  171.     ld    a,(hl)
  172.     ld    d,0        ; set flag to true
  173.     cp    2        ; check version numbers
  174.     jr    c,xbfail
  175.     cp    6
  176.     jr    z,xbfail
  177.     cp    17h
  178.     jr    c,use_xb
  179.     cp    1Eh
  180.     jr    c,xbfail
  181.     cp    2Fh
  182.     jr    c,use_xb
  183.     cp    44h
  184.     jr    c,xbfail
  185.     cp    0BFh
  186.     jr    c,use_xb
  187. xbfail║    lΣ    d,-▒        ╗ flag=falsσ (incorrec⌠ XBIOS)
  188. use_xb:    ld    a,d
  189.     or    a        ; test flag
  190.     ld    a,e
  191.     pop    hl
  192.     pop    de
  193.     ret
  194.  
  195.  
  196.  
  197. .cp 4èNew Calls in XBIOS subset 'C'
  198.  
  199.  
  200.      Thσ followinτ i≤ ß descriptioε oµ thσ │ ne≈ call≤ provideΣ ì
  201. iε XBIO╙ subse⌠ ├ - thσ existinτ call≤ wil∞ no⌠ bσ discusseΣ.
  202.  
  203.      Iµ yo⌡ havσ no⌠ useΣ XBIO╙ call≤ before¼ the∙ arσ simplσ t∩ ì
  204. use«  T∩ cal∞ ß giveε functioε, placσ thσ functioε numbe≥ iε thσ ì
  205. accumulator¼ loaΣ thσ othe≥ register≤ a≤ specifieΣ fo≥ thσ ì
  206. particular function, and do a RST 28h.
  207.  
  208.      The new functions are listed below:
  209.  
  210. XBIOS function 15 : kb_test
  211.      Usage:
  212.     ld    c,key_code
  213.     ld    a,15
  214.     rst    28h
  215.  
  216.      Thi≤ functioε check≤ t∩ seσ iµ thσ ke∙ whosσ codσ i≤ iε thσ ì
  217. ├ registe≥ (seσ belo≈ fo≥ tablσ oµ codes⌐ i≤ currentl∙ dowε oε ì
  218. thσ keyboard«  Iµ i⌠ i≤ dowε i⌠ return≤ witΦ thσ ┌ flaτ set¼ iµ ì
  219. it is up it returns with NZ status.
  220.  
  221.      I⌠ shoulΣ bσ noteΣ tha⌠ thσ fac⌠ tha⌠ thi≤ functioε i≤ ì
  222. availablσ doe≤ no⌠ necessaril∙ meaε tha⌠ thσ ne≈ 256TC keyboarΣ ì
  223. i≤ beinτ used«  Therefore¼ onσ shoulΣ bea≥ iε minΣ tha⌠ b∙ ì
  224. relyinτ key≤ whicΦ arσ onl∙ availablσ oε thσ 256TC keyboarΣ (eg« ì
  225. ALT)¼ thσ prograφ i≤ madσ incompatiblσ witΦ thσ existinτ 'old-ì
  226. styleº keyboards«  Thi≤ doe≤ no⌠ meaε tha⌠ thesσ key≤ shoulΣ no⌠ ì
  227. bσ offereΣ a≤ aε alternativσ fo≥ user≤ witΦ ne≈ keyboards¼ bu⌠ aε ì
  228. alternativσ shoulΣ bσ offereΣ fo≥ thσ olde≥ keyboard≤ (eg« thσ ì
  229. alternativσ fo≥ up-arro≈ coulΣ bσ control-┼ oε thσ olΣ keyboard)«  ì
  230. Notσ tha⌠ iµ ß ke∙ whicΦ onl∙ exist≤ oε thσ ne≈ keyboarΣ i≤ ì
  231. checkeΣ oε ß machinσ usinτ aε olΣ keyboarΣ thσ key-u≡ (NZ⌐ statu≤ ì
  232. will always be returned.
  233.  
  234.      Als∩ notσ tha⌠ oε ß systeφ witΦ thσ ne≈ keyboard¼ thσ ì
  235. KB_TES╘ routinσ wil∞ als∩ storσ an∙ typeΣ character≤ iε ß queuσ ì
  236. witΦ ß minimuφ queuσ lengtΦ oµ 2░ character≤ anΣ thesσ character≤ ì
  237. wil∞ bσ returneΣ viß thσ standarΣ BDOS/BIO╙ keyboarΣ routines«  ì
  238. Hence¼ afte≥ KB_TEST ha≤ beeε useΣ anΣ yo⌡ wan⌠ t∩ returε t∩ ì
  239. norma∞ keyboarΣ usagσ (eτ linσ input)¼ i⌠ i≤ ß gooΣ ideß t∩ clea≥ ì
  240. ou⌠ thi≤ queuσ b∙ repeatedl∙ callinτ BDO╙ consolσ iε unti∞ n∩ ì
  241. morσ key≤ arσ founΣ beforσ promptinτ thσ use≥ fo≥ input¼ a≤ iε ì
  242. this subroutine
  243.  
  244. ;------------------<CLEAR QUEUE after KB_TEST>-------------------
  245.  
  246. bdos    equ    0005h        ; BDOS jump vector
  247. dconio    equ    6        ; BDOS direct console in/out
  248.  
  249. clr_queue:
  250. ; Clears console queue for normal keyboard use after kb_test
  251.     ld    e,-1           ; signal console inè    ld    c,dconio
  252.     call    bdos
  253.     or    a
  254.     jr    nz,clr_queue
  255.     ret
  256.  
  257.      Belo≈ i≤ ß lis⌠ oµ thσ key≤ oε thσ differen⌠ keyboard≤ anΣ ì
  258. thσ correspondinτ code≤ t∩ pas≤ t∩ KB_TEST iµ the∙ arσ down«  Yo⌡ ì
  259. wil∞ notσ tha⌠ thσ firs⌠ 6┤ code≤ arσ thσ samσ a≤ thσ matri° ì
  260. code≤ fo≥ thσ key≤ oε thσ olΣ keyboarΣ fo≥ obviou≤ reason≤ oµ ì
  261. compatibilty.
  262.  
  263.    Keycodes      Standard KB         256TC KB
  264.      0              @                   ' "
  265.      1 to 26        A to Z              A to Z
  266.      27             [ {                 [ {
  267.      28             \ |                 \ |
  268.      29             ] }                 ] }
  269.      30             ^ ~                 ` ~
  270.      31             DEL                 DEL *
  271.      32             0                   0 )
  272.      33             1 !                 1 !
  273.      34             2 "                 2 @
  274.      35             3 #                 3 #
  275.      36             4 $                 4 $
  276.      37             5 %                 5 %
  277.      38             6 &                 6 ^
  278.      39             7 '                 7 &
  279.      40             8 (                 8 *
  280.      41             9 )                 9 (
  281.      42             : *                 ; :
  282.      43             ; +                 = +
  283.      44             , <                 , <
  284.      45             - =                 - _
  285.      46             . >                 . >
  286.      47             / ?                 / ?
  287.      48             ESC                 ESC
  288.      49             BACK SPACE          CORRECT
  289.      50             TAB                 TAB BACKTAB
  290.      51             LINE FEED           SQUARE BOX
  291.      52             RETURN              RETURN
  292.      53             LOCK                CAPS LOCK
  293.      54             BREAK               BRK #
  294.      55             SPACE               SPACE
  295.      56             ARROW-UP            ARROW-UP
  296.      57             CTRL                CTRL
  297.      58             ARROW-DOWN          ARROW-DOWN
  298.      59             ARROW-LEFT          ARROW-LEFT HOME
  299.      60             not used            not used
  300.      61             not used            not used
  301.      62             ARROW-RIGHT         ARROW-RIGHT END
  302.      63             SHIFT               SHIFT
  303.      64             not used            ALT
  304.      65             not used            F1
  305.      66             not used            F2è     67             not used            F3
  306.      68             not used            F4
  307.      69             not used            F5
  308.      70             not used            F6
  309.      71             not used            F7
  310.      72             not used            F8
  311.      73             not used            F9
  312.      74             not used            F10
  313.      75             not used            F11
  314.      76             not used            F12
  315.      77             not used            ESC
  316.      78             not used            UP-ARROW
  317.      79             not used            INS
  318.      80             not used            DEL *
  319.      81             not used            LEFT-ARROW HOME
  320.      82             not used            DOWN-ARROW
  321.      83             not used            RIGHT-ARROW END
  322.      84             not used            BRK #
  323.      85             not used            7 (num keypad)
  324.      86             not used            8 (num keypad)
  325.      87             not used            9 (num keypad)
  326.      88             not used            DIVIDE
  327.      89             not used            4 (num keypad)
  328.      90             not used            5 (num keypad)
  329.      91             not used            6 (num keypad)
  330.      92             not used            MULTIPLY
  331.      93             not used            1 (num keypad)
  332.      94             not used            2 (num keypad)
  333.      95             not used            3 (num keypad)
  334.      96             not used            SUBTRACT
  335.      97             not used            0 (num keypad)
  336.      98             not used            . (num keypad)
  337.      99             not used            ADD
  338.  
  339. Note║ Thσ codσ fo≥ aε almos⌠ identica∞ routinσ i≤ giveε iε ful∞ ì
  340. iε thσ sectioε Replacinτ Is_CloseΣ below.
  341.  
  342.  
  343. XBIOS function 16 : pkey_set
  344.      Usage:
  345.     ld    hl,key_table_addr
  346.     ld    a,16
  347.     rst    28h
  348.      (AF, BC, DE and HL are corrupted)
  349.  
  350.      Thi≤ functioε copie≤ thσ tablσ a⌠ (HL⌐ t∩ thσ interna∞ ì
  351. programmablσ ke∙ buffer«  Oε thσ standarΣ Microbeσ keyboarΣ thσ ì
  352. functioε key≤ arσ CTR╠ 1-9¼ providinτ ╣ functioε keys«  Oε thσ ì
  353. 256TC keyboarΣ therσ arσ 1▓ functioε key≤ - F▒ t∩ F12«  Thσ datß ì
  354. provideΣ t∩ thi≤ routinσ mus⌠ definσ AL╠ 1▓ functioε keys¼ eveε ì
  355. if only 9 are actually used.
  356.  
  357.      The format for the data table is as follows:
  358.  
  359. key_table_addr:è    db    length_of_F1_data    ; eg. 6
  360.     db    F1 data-string        ; eg. 'BASIC',0Dh
  361.     db    length_of_F2_data    ; eg. 6
  362.     db    F2 data-string        ; eg. 'TURBO',0Dh
  363.     ...
  364.     ...
  365.     db    length_of_F12_data    ; last entry, eg. 3
  366.     db    F12 data-string        ; eg. 'WP',0Dh
  367.  
  368.  
  369. XBIOS function 17 : pkey_read
  370.      Usage:
  371.     ld    hl,func_table_buffer
  372.     ld    a,17
  373.     rst    28h
  374.      (AF, BC, DE and HL corrupted)
  375.  
  376.      Thi≤ functioε copie≤ thσ interna∞ programmablσ ke∙ buffe≥ t∩ ì
  377. thσ user'≤ buffe≥ a⌠ (HL)«  Thσ prograφ shoulΣ providσ a⌠ leas⌠ ì
  378. 102┤ (400h⌐ byte≤ a⌠ (HL⌐ a≤ thσ interna∞ ke∙ buffe≥ bσ les≤ thaε ì
  379. o≥ equa∞ t∩ thi≤ size¼ bu⌠ neve≥ larger«  PKEY_REA─ als∩ return≤ ì
  380. thσ maximuφ buffe≥ sizσ iε H╠ - thi≤ functioε shoulΣ bσ calleΣ ì
  381. beforσ attemptinτ t∩ se⌠ u≡ ne≈ functioε key≤ witΦ PKEY_SET t∩ ì
  382. ensurσ thσ ne≈ ke∙ datß i≤ no⌠ to∩ lonτ (ie« longe≥ thaε thσ ì
  383. value returned in HL).
  384.  
  385.  
  386.  
  387. Using the 256TC Keyboard Independent of Operating Systems
  388.  
  389.  
  390.      Somσ application≤ requirσ tha⌠ thσ softwarσ bσ independen⌠ ì
  391. oµ thσ operatinτ systeφ (fo≥ instance¼ mos⌠ machinσ languagσ ì
  392. games)«  Also¼ application≤ oµ thσ specia∞ XBIO╙ routine≤ arσ ì
  393. limiteΣ a≤ somσ system≤ wil∞ no⌠ havσ thσ XBIO╙ implemented«  Iµ ì
  394. thesσ routine≤ arσ vita∞ t∩ thσ operatioε oµ you≥ program¼ theε ì
  395. compatibilit∙ betweeε system≤ i≤ limited«  Thσ neeΣ thereforσ ì
  396. arise≤ fo≥ keyboarΣ routine≤ independen⌠ oµ thσ operatinτ systeφ ì
  397. fo≥ truσ compatibility«  Independencσ froφ thσ operatinτ systeφ ì
  398. i≤ thσ areß tha⌠ wil∞ bσ discusseΣ here.
  399.  
  400.      ThrougΦ machinσ languagσ test≤ (eg« througΦ checkinτ somσ ì
  401. por⌠ o≥ othe≥ fo≥ ß signal)¼ i⌠ i≤ impossiblσ t∩ determinσ whicΦ ì
  402. versioε oµ thσ keyboarΣ i≤ beinτ used«  Fo≥ thi≤ reason¼ i⌠ ha≤ ì
  403. beeε decideΣ tha⌠ al∞ model≤ whicΦ suppor⌠ thσ 256TC keyboarΣ ì
  404. wil∞ havσ thσ number≤ '256º iε thσ las⌠ threσ byte≤ beforσ thσ ì
  405. screeε RA═ (ie« EFFDΦ t∩ EFFFh)«  However¼ iε thσ 256TC thi≤ areß ì
  406. i≤ no⌠ RO═ bu⌠ merel∙ ß RO═ imagσ (iε RAM⌐ anΣ hence¼ caε bσ ì
  407. erased«  S∩ thσ '256º ma∙ no⌠ bσ present«  Nevertheless¼ i⌠ ì
  408. almos⌠ certainl∙ wil∞ bσ therσ (a≤ thi≤ areß als∩ contain≤ ì
  409. importan⌠ systeφ routines⌐ and¼ iε an∙ case¼ i⌠ i≤ restoreΣ afte≥ ì
  410. ever∙ reset«
  411.  
  412.      Thσ exceptioε t∩ thi≤ i≤ wheε you≥ prograφ i≤ operatinτ ì
  413. unde≥ ß shell«  Somσ version≤ oµ thσ shel∞ overwritσ thi≤ areß ìècompletel∙ anΣ thσ '256º wil∞ neve≥ bσ present«  Iε thi≤ case¼ ì
  414. though¼ thσ XBIO╙ routine≤ wil∞ bσ availablσ anΣ thesσ mus⌠ bσ ì
  415. useΣ instead¼ a≤ therσ i≤ n∩ wa∙ oµ automaticall∙ determininτ ì
  416. keyboarΣ i≤ beinτ used«  Wheε thσ routine≤ supplieΣ b∙ XBIO╙ arσ ì
  417. inadequate¼ ß solutioε i≤ t∩ usσ thσ CCP┌ versioε oµ CP/═ a≤ thσ ì
  418. operatinτ system¼ anΣ iµ you≥ prograφ i≤ t∩ bσ generall∙ ì
  419. distributed¼ t∩ distributσ thσ disδ witΦ CCP┌ installed.
  420.  
  421.      Thσ followinτ codσ i≤ aε example¼ then¼ oµ ho≈ t∩ ì
  422. tes⌠ fo≥ thσ ne≈ 256TC keyboard in a non-shell environment
  423.  
  424. ;-----------------------<CHECK if 256TC>------------------------
  425.  
  426. rom_end    equ    0EFFFh
  427.  
  428. is_256TC:
  429. ; Routine to test which keyboard is being used.
  430. ; Z indicates new keyboard, NZ indicates the old.
  431. ; Corrupts AF.
  432.     push    hl
  433.     ld    hl,rom_end-2
  434.     ld    a,'2'
  435.     cp    (hl)
  436.     jr    nz,not256
  437.     inc    hl
  438.     ld    a,'5'
  439.     cp    (hl)
  440.     jr    nz,not256
  441.     inc    hl
  442.     ld    a,'6'
  443.     cp    (hl)
  444. not256:    pop    hl
  445.     ret
  446.  
  447.      No≈ tha⌠ i⌠ ha≤ beeε determineΣ whicΦ keyboarΣ i≤ beinτ ì
  448. used¼ i⌠ i≤ no≈ possiblσ t∩ writσ routine≤ t∩ actuall∙ scaε thσ ì
  449. two keyboards.
  450.  
  451.      Thσ ne≈ keyboarΣ caε bσ useΣ iε onσ oµ ways«  Firstly¼ i⌠ ì
  452. caε bσ programmeΣ t∩ generatσ interrupt≤ wheε ß ke∙ i≤ presseΣ ì
  453. or¼ secondly¼ i⌠ caε bσ polleΣ anΣ reaΣ wheε required.
  454.  
  455.      Thσ ne≈ keyboarΣ use≤ tw∩ softwarσ ports¼ por⌠ ▓ bi⌠ ▒ anΣ ì
  456. por⌠ 18h¼ ╕ paralle∞ bits.
  457.  
  458.      Wheε ß ke∙ i≤ presseΣ o≥ released¼ bi⌠ ▒ oµ por⌠ ▓ wil∞ ì
  459. remaiε se⌠ unti∞ ß reaΣ froφ por⌠ 18Φ i≤ made«  Wheε bi⌠ ▒ goe≤ ì
  460. high¼ anΣ bi⌠ ▒ i≤ programmeΣ t∩ generatσ aε interrupt¼ theε thσ ì
  461. keyboarΣ caε bσ reaΣ b∙ thσ interrup⌠ routine«  Iε thσ polleΣ ì
  462. modσ yo⌡ wai⌠ fo≥ bi⌠ ▒ por⌠ ▓ t∩ g∩ higΦ theε d∩ aε I╬ routinσ ì
  463. froφ por⌠ 18Φ t∩ ge⌠ thσ data«  Iε thi≤ way¼ i⌠ differ≤ froφ thσ ì
  464. olΣ keyboard¼ iε tha⌠ thσ ne≈ keyboarΣ report≤ onl∙ ß changσ iε ì
  465. keyboarΣ statu≤ (ie« tha⌠ ß ke∙ ha≤ beeε presseΣ o≥ released⌐ ì
  466. wherea≤ thσ olΣ keyboarΣ report≤ onl∙ whethe≥ ß specifieΣ ke∙ i≤ ì
  467. dowε o≥ not.è
  468.      Aε examplσ oµ codσ t∩ ge⌠ raw datß froφ thσ keyboarΣ i≤ giveε ì
  469. below
  470.  
  471. ;------------------------<Get KEY DATA>--------------------------
  472.  
  473. key_data:
  474. ╗ Thi≤ routinσ return≤ ßn ┌ flaτ iµ n∩ changσ iε keyboarΣ statu≤
  475. ; or an NZ flag and appropriate data in the accumlator otherwise.
  476. ; Note: this routine is only suitable for 256TC keyboards.
  477.     in    a,(2)        ; check for change in status
  478.     bit    1,a
  479.     ret    z
  480.     in    a,(18h)        ; get data
  481.     ret
  482.  
  483.      Thσ datß returneΣ b∙ thi≤ routinσ i≤ specifiπ t∩ thσ 256TC ì
  484. keyboard«  Thσ lo≈ orde≥ ╖ bit≤ (bit≤ ░ t∩ 6⌐ oµ thi≤ datß ì
  485. represen⌠ whicΦ ke∙ ha≤ beeε presseΣ o≥ released«  Thσ higΦ bi⌠ ì
  486. (bi⌠ 7⌐ describe≤ whethe≥ o≥ no⌠ thσ ke∙ ha≤ beeε presseΣ o≥ ì
  487. releaseΣ - iµ thσ bi⌠ i≤ se⌠ theε thσ ke∙ ha≤ beeε presseΣ anΣ iµ ì
  488. i⌠ i≤ no⌠ se⌠ theε thσ ke∙ ha≤ beeε released«  Thσ lo≈ orde≥ 7-ì
  489. bit code for these keys is given below.
  490.  
  491.       + | 0    1    2    3    4    5    6    7
  492.         | 8    9    A    B    C    D    E    F
  493.      ---+-----------------------------------------
  494.      00 | F1   ESC  TAB  BRK       [0]  [.]  SPACE
  495.         | F2   1    Q    A         CAPS BOX  INS
  496.      10 | F3   2    W    S    [½]  [2]  [3]  Z
  497.         | F4   3    E    D    [¡]  [5]  [6]  X
  498.      20 | F5   4    R    F    [¬]  [8]  [9]  C
  499.         | F6   5    T    G    [7]  [1]  [4]  V
  500.      30 | F7   6    Y    H    [»]  [V]  [>]  B
  501.         | F8   7    U    J         [<]       N
  502.      40 | F9   8    I    K              [^]  M
  503.         | F10  9    O    L         COR  RET  ,
  504.      50 | F11  0    P    ;    DEL  `    \    .
  505.         | F12  -    [    '         =    ]    /
  506.      60 |                                    SHFT
  507.         |                                    CTRL
  508.      70 |                                    ALT
  509.         |
  510.  
  511. Notes:
  512.    * Blanδ entrie≤ iε thσ tablσ arσ no⌠ useΣ anΣ shoulΣ neve≥ bσ ì
  513. áááááencountered.
  514.    * Entrie≤ iε squarσ bracket≤ (eg« [1]⌐ represen⌠ key≤ oε thσ ì
  515. ááááánumerica∞ keypaΣ.
  516.    * [^]¼ [V]¼ [>]¼ [<]¼ CO╥ represen⌠ u≡ arrow¼ dowε arrow¼ ì
  517. áááááright arrow, left arrow and correct respectively.
  518.  
  519.      Wheε switchinτ t∩ you≥ owε keyboarΣ routine≤ froφ thσ ì
  520. system's¼ keyboarΣ datß i≤ occasionall∙ lef⌠ iε thσ ke∙ buffer«  ì
  521. Onσ oµ thσ mos⌠ commoε occurrence≤ oµ thi≤ i≤ wheε transferrinτ ìèfroφ thσ CP/═ commanΣ linσ t∩ you≥ program¼ thσ Carriagσ Returε ì
  522. U≡ codσ (4Eh⌐ i≤ no⌠ reaΣ b∙ CP/═ anΣ i≤ lef⌠ iε thσ buffe≥ t∩ bσ ì
  523. reaΣ b∙ you≥ prograφ later«  Iµ thi≤ present≤ ß probleφ t∩ thσ ì
  524. smootΦ runninτ oµ you≥ program¼ theε i⌠ i≤ wisσ t∩ clea≥ thσ ì
  525. keyboarΣ buffe≥ jus⌠ beforσ thσ firs⌠ scaε oµ thσ keyboarΣ (or¼ ì
  526. wheε usinτ interrupts¼ jus⌠ beforσ reprogramminτ thσ PI╧ - seσ ì
  527. belo≈ fo≥ details)«  Thσ followinτ routinσ doe≤ this:
  528.  
  529. ;----------------------<CLEAR KEY BUFFER>------------------------
  530.  
  531. clr_kbuf:
  532. ; Clear the keyboard buffer of all data.
  533. ; Corrupts AF.
  534.     in    a,(2)
  535.     and    2
  536.     ret    z
  537.     in    a,(18h)
  538.     jr    clr_kbuf
  539.  
  540.  
  541.  
  542.  
  543. Replacing Is_Closed
  544.  
  545.  
  546.      Onσ oµ thσ mos⌠ popula≥ form≤ oµ scanninτ thσ olΣ keyboarΣ ì
  547. wa≤ t∩ usσ ß routinσ popularl∙ knowε a≤ Is_CloseΣ (o≥ ISCLSD)«  ì
  548. Thi≤ i≤ als∩ onσ oµ thσ routinσs useΣ iε BASI├ anΣ reside≤ a⌠ ì
  549. A50Ah«  Thσ routinσ i≤ repeateΣ here:
  550.  
  551. ;--------------------------<IS_CLOSED>---------------------------
  552.  
  553. isclsd:
  554. ; This routine checks if the key whose code is given in the
  555. ; accumulator is being pressed.  An NZ flag is returned if it
  556. ; is down and a Z flag if it is not.  The codes used in this
  557. ; routine are identical to those given for the XBIOS function
  558. ; kb_test (details above).
  559. ; Note:- this routine works only on the old keyboard.
  560.     push    bc
  561.     ld    c,a
  562.     ld    b,a
  563. close1:    ld    a,12h
  564.     out    (0Ch),a
  565.     ld    a,b
  566.     rrca
  567.     rrca
  568.     rrca
  569.     rrca
  570.     and    3
  571.     out    (0Dh),a
  572.     ld    a,13h
  573.     out    (0Ch),a
  574.     ld    a,b
  575.     rlcaè    rlca
  576.     rlca
  577.     rlca
  578.     out    (0Dh),a
  579.     ld    a,1
  580.     out    (0Bh),a
  581.     ld    a,10h
  582.     out    (0Ch),a
  583.     in    a,(0Dh)
  584. la52f:    ld    a,1Fh
  585.     out    (0Ch),a
  586.     out    (0Dh),a
  587. la535:    in    a,(0Ch)
  588.     bit    7,a
  589.     jr    z,la535
  590.     in    a,(0Ch)
  591.     cpl
  592.     bit    6,a
  593.     ld    a,0
  594.     out    (0Bh),a
  595.     ld    a,c
  596.     pop    bc
  597.     ret
  598.  
  599.      T∩ emulatσ thi≤ routinσ oε thσ 256TC keyboarΣ ß lonτ anΣ ì
  600. cumbersomσ routinσ mus⌠ bσ written¼ sincσ thσ naturσ oµ thσ tw∩ ì
  601. keyboard≤ i≤ fundamentall∙ differen⌠ (ie« thσ olΣ keyboarΣ ì
  602. report≤ oε aε individua∞ key≤ statu≤ wherea≤ thσ ne≈ keyboarΣ ì
  603. report≤ oε change≤ iε thσ statu≤ oµ key≤ a≤ the∙ occur)«  ì
  604. However¼ sucΦ ß codσ ha≤ beeε writteε anΣ i≤ giveε herσ a≤ aε ì
  605. example«  Thi≤ particula≥ emulatioε i≤ adapted froφ thσ Autoboo⌠ ì
  606. BASIC.
  607.  
  608. ;---------------------<IS_CLOSED for 256TC>----------------------
  609.  
  610. isclsd:
  611. ; Routine to emulate isclsd on old keyboards.
  612. ; Note that this routine works only for 256TC keyboards.
  613. ; Also provided is case, which contains the status of the
  614. ; SHIFT, ALT and CTRL keys in bits 2, 1 and 0 respectively
  615. ; at the time of the last call to isclsd.
  616.     push    bc
  617.     push    de
  618.     push    hl
  619.     ld    b,a
  620.     call    key_3        ; * (these lines removed in in-
  621.     ld    a,b        ; * terrupt version, see below)
  622.     cp    3Fh        ; SHIFT?
  623.     jr    z,tishift
  624.     cp    39h        ; CTRL?
  625.     jr    z,tisctrl
  626.     cp    40h        ; ALT?
  627.     jr    z,tisalt
  628.     cp    64h
  629.     jr    nc,tistbigè    cp    20h
  630.     jr    c,tnorm
  631.     cp    30h
  632.     jr    nc,tnorm
  633.     sub    20h
  634.     add    a,a        ; check exceptions table
  635.     ld    hl,itt_ex
  636.     ld    e,a
  637.     ld    d,0
  638.     add    hl,de
  639.     ld    a,(hl)
  640.     inc    a
  641.     jr    z,isret
  642.     call    ischck
  643.     jr    nz,isret
  644.     inc    hl
  645.     jr    chk2nd
  646.  
  647. tnorm║    lΣ    hl,ittab∞    ╗ conver⌠ t∩ natura∞ 256T├ codes
  648.     ld    e,a
  649.     ld    d,0
  650.     add    hl,de
  651. chk2nd:    ld    a,(hl)
  652.     inc    a
  653.     jr    z,isret
  654.     call    ischck
  655.     jr    isret
  656.  
  657. tistbig:xor    a
  658.     jr    isret
  659.  
  660. tishift:ld    a,(case)
  661.     and    4
  662.     jr    isret
  663.  
  664. tisalt:    ld    a,(case)
  665.     and    2
  666.     jr    isret
  667.  
  668. tisctrl:ld    a,(case)
  669.     and    1
  670. isret:    ld    a,b
  671.     pop    hl
  672.     pop    de
  673.     push    af
  674.     pop    bc
  675.     ld    a,c
  676.     and    0feh            ; scf, ccf
  677.     xor    40h            ; toggle z flag
  678.     ld    c,a
  679.     push    bc
  680.     pop    af
  681.     pop    bc
  682.     ret
  683. èischck:    push    hl
  684.     dec    a
  685.     ld    hl,isctbl
  686.     ld    e,a
  687.     ld    d,0
  688.     add    hl,de
  689.     ld    a,(hl)
  690.     and    80h
  691.     pop    hl
  692.     ret
  693.  
  694. key_3:    xor    a
  695.     out    (0Bh),a
  696.     in    a,(2)        ;check port 2, bit 1 for key
  697.     and    2
  698.     ret    z
  699.     in    a,(18h)        ;read port 18h for key code
  700.     ld    d,a
  701.     ld    hl,case        ;check for SHIFT, CTRL, and ALT
  702.     res    7,a
  703.     cp    67h        ;check SHIFT
  704.     jr    nz,ctrl
  705.     bit    7,d        ;is SHIFT up or down?
  706.     res    2,(hl)
  707.     ret    z
  708.     set    2,(hl)
  709.     ret
  710.  
  711. ctrl:    cp    6Fh        ;check CTRL
  712.     jr    nz,alt
  713.     bit    7,d        ;is CTRL up or down?
  714.     res    0,(hl)
  715.     ret    z
  716.     set    0,(hl)
  717.     ret
  718.  
  719. alt:    cp    77h        ;check ALT
  720.     ld    a,d        ;signal no special key
  721.     jr    nz,setist    ; and return with key code, if not ALT
  722.     bit    7,d        ;is ALT up or down?
  723.     set    1,(hl)
  724.     ret    nz
  725.     res    1,(hl)
  726.     ret
  727.  
  728. setist:    ld    hl,isctbl    ;signal key up/down on isctbl
  729.     and    7Fh
  730.     push    bc
  731.     ld    c,a
  732.     ld    b,0
  733.     add    hl,bc
  734.     pop    bc
  735.     ld    a,d
  736.     and    80h
  737.     res    7,(hl)è    ret    z
  738.     set    7,(hl)
  739.     ret
  740.  
  741. case║    dΓ    ░        ╗ inf∩ oε CTRL¼ AL╘ anΣ SHIFT
  742. isctbl:    ds    60h,0        ; table of keys down
  743.  
  744. ; table of code conversions from isclsd codes to natural codes
  745. ; for the 256TC keyboard (-1 means code not used)
  746. ittabl║    dΓ    5Bh,0Bh,37h,27h,1Bh,1Ah,23h,2Bh
  747.     db    33h,42h,3Bh,43h,4Bh,47h,3Fh,4Ah
  748.     db    52h,0Ah,22h,13h,2Ah,3Ah,2Fh,12h
  749.     db    1Fh,32h,17h,5Ah,56h,5Eh,55h,54h
  750.     db    -1,-1,-1,-1,-1,-1,-1,-1
  751.     db    -1,-1,-1,-1,-1,-1,-1,-1
  752.     db    1,4Dh,2,0Eh,4Eh,0Dh,3,7
  753.     db    46h,-1,35h,3Dh,-1,-1,36h,-1
  754.     db    -1,0,8,10h,18h,20h,28h,30h
  755.     db    38h,40h,48h,50h,58h,1,46h,0Fh
  756.     db    54h,3Dh,35h,36h,3,2Ch,25h,26h
  757.     db    34h,2Eh,1Dh,1Eh,24h,2Dh,15h,16h
  758.     db    1Ch,5,6,14h
  759.  
  760. ; exception table for ittable, for those isclsd codes which
  761. ; correspond to two keys on the new keyboard (eg. the code 20h
  762. ; corresponds to the 1 key, of which there are two, and whose
  763. ; codes are 51h and 5)
  764. itt_ex:    db    51h,5,9,2Dh,11h,15h,19h,16h,21h,2Eh
  765.     db    29h,1Dh,31h,1Eh,39h,2Ch,41h,25h,49h,26h
  766.     db    59h,24h,53h,14h,4Fh,-1,5Dh,1Ch,57h,6
  767.     db    5Fh,34h
  768.  
  769.  
  770.      Often¼ ß morσ effectivσ wa∙ t∩ usσ thσ keyboarΣ i≤ t∩ havσ ì
  771. thσ keyboarΣ drivinτ aε interrupt«  Thi≤ i≤ becausσ n∩ keystroke≤ ì
  772. caε bσ los⌠ wheε usinτ thi≤ method¼ a≤ caε happeε occasionall∙ ì
  773. wheε pollinτ thσ keyboarΣ (eg« wheε ß lo⌠ oµ worδ mus⌠ bσ donσ iε ì
  774. betweeε checkinτ thσ keyboard¼ a≤ wheε readinτ froφ o≥ writinτ t∩ ì
  775. disk)«  Iε orde≥ t∩ havσ thσ keyboarΣ drivσ aε interrupt¼ wσ mus⌠ ì
  776. reprograφ thσ PI╧ s∩ tha⌠ bi⌠ ▒ oµ por⌠ ▓ trigger≤ aε interrupt«  ì
  777. Also¼ wσ mus⌠ se⌠ u≡ tw∩ interrup⌠ vector≤ a⌠ ß convenien⌠ ì
  778. locatioε iε memor∙ t∩ handlσ thσ interrupt≤ wheε the∙ occur« Thσ ì
  779. followinτ piecσ oµ codσ doe≤ this
  780.  
  781. ;--------------------<SET INTERRUPT VECTORS>---------------------
  782.  
  783. ; The interrupt vectors below have been chosen arbitrarily.  Any
  784. ; convenient memory location will do.  Note, however, that both
  785. ; interrupt vectors must be contained in the same page of memory,
  786. ; ie. the same 100h block.
  787. vect_a    equ    4000h        ; interrupt vector for PIO port A
  788. vect_b    equ    vect_a+2    ; interrupt vector for PIO port B
  789.  
  790. set_int:
  791. ; This routine sets up the PIO so that the keyboard drives anè; interrupt.
  792. ; Note: this routine works only with the 256TC keyboard.
  793.     push    af
  794.     push    bc
  795.     push    de
  796.     push    hl
  797.     ld    hl,eireti    ; see new version of key_3, below
  798.     ld    (vect_a),hl
  799.     ld    hl,key_3
  800.     ld    (vect_b),hl
  801.     di            ╗ disablσ interrupt≤
  802.     ld    hl,iotabl
  803. do_pio:    ld    a,(hl)
  804.     or    a
  805.     jr    z,enabli
  806.     ld    b,a
  807.     inc    hl
  808.     ld    c,(hl)
  809.     inc    hl
  810.     otir
  811.     jr    do_pio
  812.  
  813. enabli:    im    2        ; set interrupt mode 2
  814.     ld    a,HIGH vect_a    ╗ or 40h iµ HIG╚ i≤ supporteΣ
  815.     ld    i,a
  816.     ei            ; reenable interrupts
  817.     pop    hl
  818.     pop    de
  819.     pop    bc
  820.     pop    af
  821.     ret
  822.  
  823. ; If LOW is not supported on your assembler, substitute
  824. ; 0 for LOW vect_a and 2 for LOW vect_b
  825. ; Note: HIGH and LOW mean high order and low order 8 bits,
  826. ; respectively.
  827. iotabl:    db    5,1,LOW vect_a,0CFh,-1,97h,-1
  828.     db    5,3,LOW vect_b,-1,9Bh,0B7h,0EDh
  829.     db    0
  830.  
  831.      No≈ tha⌠ thσ PI╧ ha≤ beeε reprogrammeΣ t∩ generatσ aε ì
  832. interrup⌠ wheneve≥ ß ke∙ i≤ presseΣ o≥ released¼ somσ change≤ t∩ ì
  833. thσ isclsΣ routinσ mus⌠ bσ madσ t∩ accomodatσ thσ interrupts«  ì
  834. Firstly¼ thσ tw∩ line≤ witΦ asterisk≤ iε thei≥ commen⌠ field≤ ì
  835. mus⌠ bσ removeΣ (ie« cal∞ key_│ anΣ lΣ a,b)«  Secondly¼ thσ key_│ ì
  836. routinσ mus⌠ bσ slightl∙ altered«  Thσ ne≈ versioε oµ thσ key_│ ì
  837. routine is given below
  838.  
  839. ;------------------<KEY_3: INTERRUPT VERSION>--------------------
  840.  
  841. key_3:    push    af
  842.     push    bc
  843.     push    de
  844.     push    hl
  845.     in    a,(2)        ;check port 2, bit 1 for keyè    and    2
  846.     jr    z,retk3
  847.     in    a,(18h)        ;read port 18h for key code
  848.     ld    d,a
  849.     ld    hl,case        ;check for SHIFT, CTRL, and ALT
  850.     res    7,a
  851.     cp    67h        ;check SHIFT
  852.     jr    nz,ctrl
  853.     bit    7,d        ;is SHIFT up or down?
  854.     res    2,(hl)
  855.     jr    z,retk3
  856.     set    2,(hl)
  857.     jr    retk3
  858.  
  859. ctrl:    cp    6Fh        ;check CTRL
  860.     jr    nz,alt
  861.     bit    7,d        ;is CTRL up or down?
  862.     res    0,(hl)
  863.     jr    z,retk3
  864.     set    0,(hl)
  865.     jr    retk3
  866.  
  867. alt:    cp    77h        ;check ALT
  868.     ld    a,d        ;signal no special key
  869.     jr    nz,setist    ; and return with key code, if not ALT
  870.     bit    7,d        ;is ALT up or down?
  871.     set    1,(hl)
  872.     jr    nz,retk3
  873.     res    1,(hl)
  874.     jr    retk3
  875.  
  876. setist:    ld    hl,isctbl    ;signal key up/down on isctbl
  877.     and    7Fh
  878.     push    bc
  879.     ld    c,a
  880.     ld    b,0
  881.     add    hl,bc
  882.     pop    bc
  883.     ld    a,d
  884.     and    80h
  885.     res    7,(hl)
  886.     jr    z,retk3
  887.     set    7,(hl)
  888. retk3:    pop    hl
  889.     pop    de
  890.     pop    bc
  891.     pop    af
  892. eireti:    ei
  893.     reti
  894. .paèSECTION II: Colour and Graphics
  895.  
  896.  
  897.  
  898.  
  899. Introduction
  900.  
  901.  
  902.      Thσ 256T├ ha≤ improveΣ vastl∙ ove≥ thσ origina∞ Microbee≤ iε ì
  903. thσ areß oµ graphic≤ capabilities«  Thσ 256T├ no≈ support≤ full∙ ì
  904. do⌠ addressablσ unlimiteΣ graphic≤ witΦ ß resolutioε oµ 51▓ b∙ ì
  905. 25╢ whils⌠ maintaininτ compatibilit∙ witΦ earlie≥ Microbees«  ì
  906. Thi≤ wa≤ firs⌠ introduceΣ iε thσ Premiuφ mode∞ Microbees¼ bu⌠ thσ ì
  907. 256TC has added the capability of hardware flashing and inverse.
  908.  
  909.      Thσ sectioε oε Implementatioε iε BASI├, below, i≤ takeε almos⌠ ì
  910. directly from the BASIC manual.
  911.  
  912.  
  913.  
  914. Implementation in MicroWorld BASIC
  915.  
  916.  
  917.      Previously¼ wσ learneΣ abou⌠ HIRE╙ graphics«  Thσ onσ ì
  918. disadvantagσ witΦ thi≤ modσ oµ graphic≤ i≤ tha⌠ wσ eventuall∙ raε ì
  919. ou⌠ oµ graphics«  S∩ tha⌠ yo⌡ won'⌠ ruε ou⌠ oµ graphics¼ therσ i≤ ì
  920. ß seconΣ modσ oµ HIRE╙ graphic≤ - HIRES2«  Tr∙ thσ prograφ belo≈ ì
  921. (thi≤ prograφ caε bσ founΣ oε thσ accompanyinτ disδ a≤ ì
  922. "PATTERN.MWB").
  923.  
  924. 00100 REM A program that will plot lines all over the screen.
  925. 00110 HIRES
  926. 00120  FOR X=0 TO 511 : REM Initialise X co-ordinates
  927. 00130   PLOTI X,255 TO 511-X,0
  928. 00140  NEXT X
  929. 00150 END
  930.  
  931.      Thi≤ program¼ usinτ thσ standarΣ HIRE╙ command¼ wil∞ begiε ì
  932. PLOTtinτ diagona∞ line≤ froφ thσ to≡ left-hanΣ corner«  Bu⌠ yo⌡ ì
  933. wil∞ seσ tha⌠ wheε yo⌡ ruε thσ program¼ ß graphic≤ erro≥ wil∞ ì
  934. occu≥ afte≥ ß shor⌠ time«  Yo⌡ havσ ruε ou⌠ oµ graphics«  Thσ ì
  935. solution to this is the HIRES2 command.
  936.  
  937.      B∙ usinτ thσ HIRES▓ command¼ iε placσ oµ thσ HIRE╙ command¼ ì
  938. yo⌡ wil∞ neve≥ ruε ou⌠ oµ graphics«  Yo⌡ wil∞ als∩ discove≥ tha⌠ ì
  939. thσ HIRES▓ commanΣ wil∞ givσ yo⌡ ß faste≥ modσ oµ graphic≤ thaε ì
  940. HIRES.  Let's change line 110 of our program above to
  941.  
  942. 00110 HIRES2
  943.  
  944. .cp 7è     A≤ yo⌡ caε see¼ thσ entirσ screeε ha≤ beeε filleΣ witΦ ì
  945. graphic≤ (thσ patterε i≤ ß resul⌠ oµ usinτ thσ PLOT╔ statemen⌠ ì
  946. insteaΣ oµ ß PLOT)«  Al∞ graphic≤ relateΣ function≤ ma∙ bσ useΣ ì
  947. unde≥ HIRES▓ withou⌠ affectinτ thei≥ operation«  Thσ onl∙ poin⌠ ì
  948. t∩ notσ i≤ tha⌠ iµ yo⌡ usσ HIRES2¼ you≥ program≤ ma∙ no⌠ ruε (a≤ ì
  949. ß resul⌠ oµ lacδ oµ graphics⌐ oε standarΣ non-Premiuφ serie≤ ì
  950. Microbees.
  951.  
  952.  
  953.  
  954. Hardware changes for the Premium series and 256TC.
  955.  
  956.  
  957.      EacΦ Premiuφ serie≤ anΣ 256T├ Microbeσ ha≤ eigh⌠ 2δ bank≤ oµ ì
  958. PC╟ ram¼ onσ 2δ banδ oµ characte≥ ram¼ onσ 2δ banδ oµ colou≥ raφ ì
  959. anΣ onσ 2δ banδ oµ attributσ ram (you≥ Microbeσ ha≤ thσ potentia∞ ì
  960. fo≥ 32δ oµ PC╟ ram¼ anΣ 8δ eacΦ oµ colour¼ cahracte≥ anΣ ì
  961. attributσ ram¼ al∞ iε 2δ banks).
  962.  
  963.      Thi≤ mean≤ tha⌠ eacΦ Premiuφ serie≤ anΣ 256T├ Microbeσ ha≤ ß ì
  964. tota∞ oµ 22δ oµ screen¼ PC╟ anΣ colou≥ ram«  However¼ al∞ oµ thi≤ ì
  965. raφ lie≤ betweeε F000Φ anΣ FFFFh¼ whicΦ mean≤ onl∙ 4δ i≤ ì
  966. addressablσ a⌠ once«  S∩ ho≈ d∩ yo⌡ fi⌠ 22δ oµ memor∙ int∩ ß 4δ ì
  967. memor∙ space┐  You≥ Microbeσ use≤ ß methoΣ oµ banδ switchinτ t∩ ì
  968. switcΦ betweeε eacΦ oµ thσ 2δ bank≤ int∩ memor∙ a≤ i⌠ i≤ needed«  ì
  969. Thus, we can select pages of memory as needed.
  970.  
  971.  
  972.  
  973. The Video Memory Latch
  974.  
  975.  
  976.      Thσ VM╠ (Vide∩ Memor∙ Latch⌐ act≤ a≤ ß 'traffiπ copº fo≥ thσ ì
  977. vide∩ ram«  I⌠ i≤ responsiblσ fo≥ determininτ whicΦ banδ oµ raφ ì
  978. i≤ currentl∙ 'latchedº int∩ memory«  B∙ settinτ thσ appropriatσ ì
  979. bi⌠ oµ thσ VM╠ (usinτ aε OU╘ statement)¼ wσ arσ ablσ t∩ selec⌠ ì
  980. thσ PC╟ banδ t∩ bσ programmed¼ selec⌠ thσ attributσ raφ o≥ selec⌠ ì
  981. thσ colou≥ ram«  Thσ latcΦ i≤ selecteΣ b∙ usinτ aε OU╘ 28,X+12╕ ì
  982. statement¼ wherσ ╪ i≤ ß decima∞ value¼ selectinτ eithe≥ ß PCG¼ ì
  983. attribute¼ colou≥ o≥ characte≥ bank«  Yo⌡ mus⌠ als∩ adΣ 12╕ t∩ ì
  984. thσ banδ numbe≥ oµ thσ VM╠ t∩ enablσ thσ additiona∞ bank≤ t∩ bσ ì
  985. selected.
  986.  
  987.  
  988.  
  989. The Attribute RAM
  990.  
  991.  
  992.      Apar⌠ froφ thσ VML¼ thσ attributσ raφ i≤ thσ mos⌠ importan⌠ ì
  993. sectioε oµ thσ vide∩ circuitr∙ oε thσ Premiuφ series«  I⌠ i≤ ì
  994. latcheΣ int∩ memory¼ betweeε location≤ F000h-F7FFh¼ usinτ aε OU╘ ì
  995. 28,144«  Thi≤ statemen⌠ wil∞ als∩ se⌠ bi⌠ ╖ oµ thσ VM╠ (banδ ì
  996. select mode) high.
  997.  
  998. .cp 6è     EacΦ bytσ oµ thσ attributσ raφ determine≤ whicΦ banδ oµ PC╟ ì
  999. raφ i≤ selecteΣ fo≥ thσ correspondinτ positioε oε thσ screen«  ì
  1000. Fo≥ example¼ let'≤ supposσ tha⌠ wσ havσ programmeΣ thσ characte≥ ì
  1001. 'Rº witΦ  PC╟ characte≥ iε banδ ╢ oµ thσ PC╟ ram«  Iµ wσ wan⌠ t∩ ì
  1002. prin⌠ tha⌠ characte≥ a⌠ curso≥ positioε 1¼ wσ wil∞ neeΣ t∩ latcΦ ì
  1003. thσ attributσ raφ anΣ POK┼ thσ valuσ ╢ int∩ locatioε F000Φ (thσ ì
  1004. firs⌠ positioε oε thσ screen)«  Wheε wσ attemp⌠ t∩ PRIN╘ thi≤ ì
  1005. character¼ BASI├ reset≤ thσ attributσ raφ t∩ banδ 0¼ s∩ wσ wil∞ ì
  1006. havσ t∩ POK┼ thσ attributσ raφ afte≥ thσ PRIN╘ statement«  Thσ ì
  1007. following program is an example ("GREEK.MWB" on the disk).
  1008.  
  1009. 00100 REM A demonstration of PCG programming with the
  1010. 00110 REM Premium series and 256TC Microbees.
  1011. 00120 REM This program will print three different Greek
  1012. 00130 REM alphabetic characters onto the screen,
  1013. 00140 REM utilising banks 0-2 of the PCG ram.
  1014. 00150 IN#0 OFF : REM Turn the keyboard off.
  1015. 00160 REM GOSUB to poke the PCG data into ram.
  1016. 00170 GOSUB 380
  1017. 00200 REM Beginning of main program
  1018. 00210 CLS
  1019. 00220 REM Enter PCG mode & print characters on screen.
  1020. 00230 PCG
  1021. 00240 PRINT "A"
  1022. 00250 PRINT "A"
  1023. 00260 PRINT "A"
  1024. 00270 OUT 28,144 : REM Latch attribute ram via VML.
  1025. 00280 POKE 61440,0 : REM Set screen pos 1 for bank #0
  1026. 00290 POKE 61504,1 : REM Set screen pos 2 for bank #1
  1027. 00300 POKE 61568,2 : REM Set screen pos 3 for bank #2
  1028. 00310 NORMAL
  1029. 00320 IN#0 ON : REM Turn keyboard on.
  1030. 00330 END
  1031. 00340 REM Subroutine to program PCG
  1032. 00350 DATA 0,0,0,0,0,7,42,68,68,42,17,0,0,0,0,0
  1033. 00360 DATA 0,0,73,73,73,42,28,8,8,28,0,0,0,0,0,0
  1034. 00370 DATA 255,65,34,16,8,4,2,1,1,2,4,8,16,34,65,255
  1035. 00380 FOR J=0 TO 2
  1036. 00390  OUT 28,J+128 : REM Latch bank #J
  1037. 00400  FOR I=64528 TO 64543
  1038. 00410   READ D
  1039. 00420   POKE I,D
  1040. 00430  NEXT I
  1041. 00440 NEXT J 
  1042. 00450 RETURN
  1043.  
  1044.      Let'≤ spli⌠ thi≤ prograφ dowε int∩ sections«  Thσ PC╟ ì
  1045. routinσ i≤ locateΣ betweeε 34░ anΣ 450«  Pleasσ notσ tha⌠ wσ arσ ì
  1046. programminτ thσ characte≥ 'Aº threσ times¼ bu⌠ wσ arσ POKEinτ ì
  1047. theφ int∩ differen⌠ bank≤ b∙ usinτ thσ OU╘ 28,J+12╕ statement.
  1048.  
  1049.      Thσ firs⌠ statemen⌠ t∩ usσ witΦ an∙ prograφ tha⌠ i≤ usinτ ì
  1050. thσ extrß PC╟ banks¼ i≤ aε IN#▒ OF╞ (linσ 150⌐ t∩ turε thσ ì
  1051. keyboarΣ off«  BASI├ continuosl∙ scan≤ thσ keyboarΣ t∩ checδ iµ ì
  1052. thσ BREA╦ ke∙ ha≤ beeε pressed«  Wheε ß scaε occur≤ thσ VM╠ i≤ ìèrese⌠ anΣ s∩ an∙ bank≤ tha⌠ yo⌡ havσ latched (othe≥ thaε PC╟ ì
  1053. banδ 0⌐ wil∞ bσ de-latched«  Aε IN#░ OF╞ mus⌠ bσ useΣ t∩ sto≡ ì
  1054. this happening.
  1055.  
  1056.      Thσ maiε prograφ i≤ locateΣ betweeε line≤ 210-330«  Thσ ì
  1057. importan⌠ poin⌠ herσ i≤ tha⌠ thσ character≤ arσ PRINTeΣ BEFOR┼ ì
  1058. thσ attributσ raφ i≤ POKEΣ witΦ necessar∙ banδ selec⌠ data«  Thσ ì
  1059. reasoε fo≥ thi≤ i≤ tha⌠ wheε BASI├ use≤ ß PRIN╘ statement¼ i⌠ ì
  1060. wil∞ rese⌠ thσ attributσ ram¼ anΣ s∩ al∞ attribute≤ wil∞ bσ se⌠ ì
  1061. t∩ PC╟ banδ 0«  Thus¼ thσ character≤ a⌠ location≤ 64528-6454│ ì
  1062. wil∞ bσ printeΣ first¼ anΣ theε thσ attributσ raφ i≤ theε POKEΣ ì
  1063. witΦ thσ correc⌠ banδ selec⌠ data«  Iµ yo⌡ usσ ß SPEE─ 25╡ ì
  1064. commanΣ beforσ RUNninτ thσ program¼ yo⌡ wil∞ bσ ablσ t∩ seσ thi≤ ì
  1065. happening«  A⌠ norma∞ speed¼ yo⌡ wil∞ no⌠ bσ ablσ t∩ sensσ thσ ì
  1066. change in characters.
  1067.  
  1068.  
  1069.  
  1070. The Colour Commands
  1071.  
  1072.  
  1073.      MicroWorlΣ BASI├ ha≤ ß widσ se⌠ oµ colou≥ commands«  Fo≥ thσ ì
  1074. Premiuφ serie≤ anΣ 256T├ user¼ colou≥ i≤ standard«  Eveε iµ yo⌡ ì
  1075. intenΣ t∩ usσ you≥ program≤ oε Microbee≤ tha⌠ don'⌠ usσ thσ ì
  1076. colou≥ facility¼ i⌠ i≤ stil∞ allowablσ t∩ havσ colou≥ command≤ iε ì
  1077. you≥ program«  Thσ use≥ ma∙ selec⌠ ß colou≥ fo≥ thσ foregrounΣ o≥ ì
  1078. thσ background«  EacΦ colou≥ ha≤ ß numbe≥ o≥ lette≥ (dependinτ oε ì
  1079. whethe≥ i⌠ i≤ ß foregrounΣ o≥ backgrounΣ colour⌐ associateΣ witΦ ì
  1080. it.  The basic forms of the colour commands are:
  1081.  
  1082. .cp 3
  1083.           COLOUR n (n = 0 to 15)
  1084.           COLOURB n (n = 0 to 15)
  1085.           COLOUR n (n = 0 to 255)
  1086.  
  1087.      COLOU╥ ε wil∞ se⌠ thσ foregrounΣ colour¼ whilσ COLOUR┬ ε ì
  1088. wil∞ se⌠ thσ backgrounΣ colou≥ (wσ wil∞ seσ ho≈ t∩ usσ thσ thirΣ ì
  1089. forφ oµ thσ COLOU╥ commanΣ iε ß moment)«  S∩ let'≤ experimentí  ì
  1090. Try this simple program ("RONW.MWB"):
  1091.  
  1092. 00100 COLOUR 1 : COLOURB 15
  1093. 00110 PRINT " Red on White "
  1094. 00120 COLOUR 2 : COLOURB 0
  1095.  
  1096.      A≤ yo⌡ ma∙ havσ guessed¼ thσ strinτ "ReΣ oε Whiteó i≤ ì
  1097. printeΣ iε reΣ oε ß whitσ background«  Thσ usablσ colour≤ anΣ ì
  1098. their codes are as follows.
  1099.  
  1100.      Colour                Decimal Code
  1101.      Black                    0
  1102.      Red                      1
  1103.      Green                    2
  1104.      Brown                    3
  1105.      Blue                     4
  1106.      Magenta                  5
  1107.      Cyan                     6è     Light Grey               7
  1108.      Dark Grey                8
  1109.      Light Red                9
  1110.      Light Green              10
  1111.      Yellow                   11
  1112.      Light Blue               12
  1113.      Light Magenta            13
  1114.      Light Cyan               14
  1115.      White                    15
  1116.  
  1117.      T∩ accoun⌠ fo≥ differen⌠ spelling≤ oµ thσ worΣ "colour"¼ ì
  1118. MicroWorlΣ BASI├ wil∞ accep⌠ thσ word≤ COLOU╥ o≥ COLOR«  Iε somσ ì
  1119. instances¼ i⌠ i≤ desirablσ t∩ usσ thσ COLO╥ keyword¼ a≤ thi≤ ì
  1120. version of the word is more efficient in terms of memory.
  1121.  
  1122.      I⌠ i≤ onl∙ possiblσ t∩ se⌠ thσ foregrounΣ anΣ backgrounΣ ì
  1123. colour≤ oε ß characte≥ b∙ characte≥ basis«  Wheε usinτ thσ PC╟ ì
  1124. t∩ producσ graphics¼ i⌠ i≤ ß gooΣ ideß t∩ retaiε thσ samσ ì
  1125. background colour as selected when the HIRES command was invoked.
  1126.  
  1127.      Thσ followinτ prograφ demonstrate≤ thσ differenc⌠ betweeε ì
  1128. thσ standarΣ anΣ 'lightº colours«  Thσ prograφ wil∞ displa∙ al∞ ì
  1129. the background colours ("COLOURB.MWB").
  1130.  
  1131. 00100 REM A program to demonstrate Microbee colours
  1132. 00110 FOR A=1 TO 15 : REM loop for background colours
  1133. 00120  COLOURB A : REM set background colour
  1134. 00130  CLS : REM fill screen with colour
  1135. 00140  FOR B=1 TO 1000 : NEXT B : REM A short delay
  1136. 00150 NEXT A
  1137. 00160 END
  1138.  
  1139.  
  1140.  
  1141. Advanced Colour Programming in BASIC
  1142.  
  1143.  
  1144.      MicroworlΣ BASI├ no≈ allow≤ thσ use≥ t∩ se⌠ botΦ foregrounΣ ì
  1145. AN─ backgrounΣ colour≤ witΦ thσ samσ command«  Thi≤ i≤ possiblσ ì
  1146. b∙ redefininτ thσ decima∞ codσ fo≥ thσ backgrounΣ colou≥ anΣ theε ì
  1147. addinτ theφ t∩ thσ foregrounΣ colou≥ codes«  Thσ redefineΣ ì
  1148. background colour codes are as follows:
  1149.  
  1150.      Background colour     Decimal Code
  1151.      Black                    0
  1152.      Red                      16
  1153.      Green                    32
  1154.      Brown                    48
  1155.      Blue                     64
  1156.      Magenta                  80
  1157.      Cyan                     96
  1158.      Light Grey               112
  1159.      Dark Grey                128
  1160.      Light Red                144
  1161.      Light Green              160è     Yellow                   176
  1162.      Light Blue               192
  1163.      Light Magenta            208
  1164.      Light Cyan               224
  1165.      White                    240
  1166.  
  1167.      So, the lines
  1168.                     COLOUR 207 <cr>
  1169.      followed by
  1170.                     CLS <cr>
  1171.      wil∞ produceΣ whitσ character≤ oε ß ligh⌠ bluσ background«  ì
  1172. Thσ ne≈ codσ fo≥ backrounΣ ligh⌠ bluσ i≤ 192«  Thσ foregrounΣ ì
  1173. white is 15.  Thus, if we perform the simple equation:
  1174.  
  1175.                     192
  1176.                   +  15
  1177.  
  1178. we arrive at the answer:
  1179.  
  1180.                     207.
  1181.  
  1182.      Yo⌡ ma∙ onl∙ usσ thi≤ forφ oµ thσ colou≥ commanΣ wheε ì
  1183. settinτ BOT╚ backgrounΣ anΣ foregrounΣ colours«  Iµ wσ werσ t∩ ì
  1184. try to set the background colour to yellow by using the command:
  1185.  
  1186.                     COLOURB 176 <cr>
  1187.  
  1188. the screen colour won't change.  However, using
  1189.  
  1190.                     COLOUR 176 <cr>
  1191.  
  1192. wσ caε changσ thσ backgrounΣ colou≥ t∩ yello≈ witΦ ß blacδ ì
  1193. foregrounΣ (17╢ ½ 0)«  Thσ followinτ prograφ wil∞ displa∙ ever∙ ì
  1194. possiblσ colou≥ combinatioε avaiblσ witΦ thσ Microbeσ ì
  1195. ("ADVCOL.MWB").
  1196.  
  1197. 00100 FOR C=1 TO 255 : REM Ignore black on black
  1198. 00110  COLOUR C
  1199. 00120  SPEED 100 : REM Set speed
  1200. 00130  PRINT " *********** "
  1201. 00140 NEXT C
  1202. 00150 COLOUR 2 : REM Reset colour to green on black
  1203. 00160 SPEED 0 : REM Reset speed
  1204. 00170 END
  1205.  
  1206.      A≤ yo⌡ ma∙ havσ alread∙ noticed¼ eacΦ colou≥ combinatioε ì
  1207. wil∞ havσ it'≤ owε uniquσ code«  I⌠ i≤ impossiblσ fo≥ tw∩ ì
  1208. differen⌠ colou≥ combination≤ t∩ havσ thσ samσ code«  Iµ ├ wa≤ ì
  1209. eve≥ t∩ reacΦ thσ valuσ oµ 256¼ i⌠ woulΣ bσ rese⌠ t∩ ░ (blacδ oε ì
  1210. black).
  1211.  
  1212.  
  1213.  
  1214. .cp 8èImplementation in Machine Language
  1215.  
  1216.  
  1217.      Implementinτ thσ ne≈ extendeΣ graphic≤ facilitie≤ iε machinσ ì
  1218. languagσ i≤ ß direc⌠ adaptatioε oµ thσ technique≤ useΣ iε BASIC¼ ì
  1219. describeΣ above«  Thσ Vide∩ Memor∙ LatcΦ (por⌠ 1Ch⌐ i≤ useΣ t∩ ì
  1220. switcΦ betweeε characte≥ anΣ attributσ raφ anΣ betweeε thσ eigh⌠ ì
  1221. bank≤ oµ PC╟ ram«
  1222.  
  1223.      Colou≥ i≤ programmeΣ b∙ usinτ por⌠ 8«  Settinτ bi⌠ 6 oµ thi≤ ì
  1224. por⌠ wil∞ causσ thσ colou≥ raφ t∩ switcΦ iε a⌠ F800Φ anΣ ì
  1225. resettinτ bi⌠ 6 wil∞ causσ i⌠ t∩ switcΦ ou⌠ again«  EacΦ bytσ iε ì
  1226. thσ colou≥ raφ correspond≤ t∩ thσ equivalen⌠ bytσ iε thσ ì
  1227. characte≥ ram¼ iε thσ samσ wa∙ a≤ thσ attributσ ram«  Thus¼ F83FΦ ì
  1228. iε thσ colou≥ raφ represent≤ thσ colou≥ oµ thσ characte≥ a⌠ ì
  1229. F03Fh¼ thσ to≡ right-hanΣ corne≥ oµ thσ screen«  Thσ colou≥ code≤ ì
  1230. fo≥ thσ colou≥ raφ arσ thσ samσ a≤ fo≥ thosσ thσ basiπ statemen⌠ ì
  1231. COLOUR n (n=0 to 255).
  1232.  
  1233.      Oε thσ disδ provided¼ thσ prograφ QUIX.CO═ anΣ it≤ ì
  1234. associateΣ sourcσ filσ QUIX.MA├ providσ ß usefu∞ examplσ oµ ho≈ ì
  1235. graphic≤ anΣ colou≥ caε bσ useΣ iε ß 'stand-aloneº machinσ ì
  1236. languagσ application«  Somσ oµ thσ usefu∞ routine≤ adapteΣ froφ ì
  1237. thi≤ prograφ arσ given below.
  1238.  
  1239.      Firstly¼ ß rougΦ equivalen⌠ oµ thσ HIRES▓ commanΣ iε ì
  1240. BASI├ wil∞ bσ presented«  Bu⌠ beforσ thi≤ wσ havσ t∩ determinσ ì
  1241. whethe≥ o≥ no⌠ thσ systeφ thσ prograφ i≤ runninτ oε i≤ ß Premiuφ ì
  1242. or TC256.  The following routine determines this
  1243.  
  1244. ;-----------------------<EXAMINE SYSTEM>-------------------------
  1245.  
  1246. screen    equ    0F000h        ; char and att memory
  1247. grafix    equ    0F800h        ; PCG and colour memory
  1248. vmlatch    equ    1Ch        ; video memory latch port
  1249. attrib    equ    144        ; attribute switch
  1250. c_port    equ    8        ; colour port
  1251. c_swtch    equ    40h        ; colour port switch
  1252. row    equ    64        ; no of characters per row
  1253.  
  1254. examine:
  1255. ; This routine examines the system to determine whether it
  1256. ; (i) has colour (if not, colour is set to -1)
  1257. ; (ii) is a Premium (if not, prmium is set to -1) and
  1258. ; {iii} is a 256TC (if not, tc256 is set to -1)
  1259. ╗ Note║ iµ thσ systeφ i≤ ß Premium¼ theε i⌠ i≤ als∩ colour¼ and
  1260. ; if it is a 256TC, then it is also a Premium and colour, for
  1261. ; the purposes of this routine.
  1262. ; Corrupts AF and HL.
  1263.     call    is_256TC    ; see above for this routine
  1264.     ret    z
  1265.     ld    a,-1
  1266.     ld    (tc256),a
  1267.     ld    hl,screen+32*row-1
  1268.     ld    (hl),0è    ld    a,attrib
  1269.     out    (vmlatch),a
  1270.     ld    (hl),-1
  1271.     ld    a,80h
  1272.     out    (vmlatch),a
  1273.     ld    a,(hl)
  1274.     ld    (prmium),a
  1275.     or    a
  1276.     ret    z
  1277.     ld    hl,grafix+32*row-1
  1278.     ld    (hl),0
  1279.     ld    a,c_swtch
  1280.     out    (c_port),a
  1281.     ld    (hl),7
  1282.     xor    a
  1283.     out    (c_port),a
  1284.     ld    a,(hl)
  1285.     or    a
  1286.     ret    z
  1287.     ld    a,-1
  1288.     ld    (colour),a
  1289.     ret
  1290.  
  1291. colour:    db    0        ; 0 = colour
  1292. prmium:    db    0        ; 0 = Premium series or later
  1293. tc256:    db    0        ; 0 = 256TC
  1294.  
  1295.      No≈ tha⌠ wσ caε determinσ whethe≥ o≥ no⌠ thσ systeφ i≤ ì
  1296. Premium series or later, we can now use the HIRES2 routine.
  1297.  
  1298. ;--------------------<SET SCREEN to HIRES2>----------------------
  1299.  
  1300. initcol    equ    2        ; green on black
  1301.  
  1302. set_scn:
  1303. ; Set up the screen in a rough equivalent to the HIRES2 command
  1304. ; of MicroWorld BASIC.  Clears the screen, sets 64x16 video mode
  1305. ╗ set≤ thσ screeε colou≥ t∩ initco∞ anΣ fill≤ thσ screeε froφ
  1306. ; left to right, top to bottom with PCG, starting in the top left
  1307. ; with character 80h, bank 0, and ending in the bottom right with
  1308. ; character FFh, bank 7.
  1309. ; Corrupts all registers.
  1310. ; Returns c flag if error (ie. not Premium)
  1311.     ld    a,(prmium)    ; see examine routine above
  1312.     or    a
  1313.     scf
  1314.     ret    z
  1315.     ld    hl,screen    ; clear the screen
  1316.     ld    (hl),' '
  1317.     ld    de,screen+1
  1318.     ld    bc,32*row-1
  1319.     ldir
  1320.     call    reform        ; set 64x16 mode
  1321.     ld    bc,0
  1322. rfwait:    dec    bcè    ld    a,b
  1323.     or    c
  1324.     jp    nz,rfwait
  1325.     ld    b,8
  1326.     ld    a,80h
  1327. clgrfx:    push    bc
  1328.     out    (vmlatch),a
  1329.     ld    hl,grafix
  1330.     ld    (hl),0
  1331.     ld    de,grafix+1
  1332.     ld    bc,128*char
  1333.     ldir
  1334.     inc    a
  1335.     pop    bc
  1336.     djnz    clgrfx
  1337.     ld    a,c_swtch        ; set up initial screen colour
  1338.     out    (c_port),a
  1339.     ld    hl,grafix
  1340.     ld    (hl),initcol
  1341.     ld    de,grafix+1
  1342.     ld    bc,16*row-1
  1343.     ldir
  1344.     xor    a
  1345.     out    (c_port),a
  1346.     ld    b,8            ; set up screen & attributes
  1347.     ld    hl,screen
  1348.     ld    de,screen+1
  1349.     ld    a,attrib
  1350.     out    (vmlatch),a
  1351.     xor    a
  1352. setatt:    push    bc
  1353.     ld    bc,2*row
  1354.     ld    (hl),a
  1355.     ldir
  1356.     inc    a
  1357.     pop    bc
  1358.     djnz    setatt
  1359.     ld    a,80h
  1360.     out    (vmlatch),a
  1361.     ld    hl,screen
  1362.     ld    c,8
  1363. setscn:    ld    b,2*row
  1364.     ld    a,80h
  1365. setrow:    ld    (hl),a
  1366.     inc    a
  1367.     inc    hl
  1368.     djnz    setrow
  1369.     dec    c
  1370.     jr    nz,setscn
  1371.     re⌠                ╗ π flaτ i≤ rese⌠
  1372.  
  1373. reform:    ld    hl,v_64+15        ; routine to set up 64*16
  1374. refrm2:    push    bc
  1375.     push    hl
  1376.     ld    b,10hèformat:    ld    a,b
  1377.     dec    a
  1378.     out    (0ch),a
  1379.     ld    a,(hl)
  1380.     out    (0dh),a
  1381.     dec    hl
  1382.     djnz    format
  1383.     ld    b,4Bh
  1384.     call    leee3
  1385.     pop    hl
  1386.     pop    bc
  1387.     ret
  1388.  
  1389. leee3:    push    hl            ; routine for 64*16
  1390. leee4:    ld    hl,007Ah
  1391. leee7:    dec    hl
  1392.     ld    a,h
  1393.     or    l
  1394.     jr    nz,leee7
  1395.     djnz    leee4
  1396.     pop    hl
  1397.     ret
  1398.  
  1399. v_64:    db    6Bh,64,51h,37h,12h,9,16,12h,48h,0Fh,2Fh,0Fh,0,0,0,0
  1400.  
  1401.      Thσ othe≥ routinσ oµ possiblσ interes⌠ i≤ ß fas⌠ line-ì
  1402. drawinτ routinσ (line)«  Thi≤ i≤ giveε below
  1403.  
  1404. ;------------------------<LINE DRAWING>--------------------------
  1405.  
  1406. line:
  1407. ; This routine is used in conjunction with hires2 above and
  1408. ; draws a straight line from (from_x, from_y) to (to_x, to_y).
  1409. ; Corrupts all registers, including IY and alternative regs.
  1410.     call    calcxy
  1411.     ex    af,af'
  1412.     ld    a,(set)
  1413.     ex    af,af'
  1414.     ld    hl,(from_x)
  1415.     ld    de,(to_x)
  1416.     call    subabs
  1417.     ld    b,h
  1418.     ld    c,l
  1419.     ld    hl,pix_lt
  1420.     jp    nc,cupok
  1421.     ld    hl,pix_rt
  1422. cupok:    ld    (vect_1),hl
  1423.     ld    hl,(from_y)
  1424.     ld    de,(to_y)
  1425.     call    subabs
  1426.     ld    d,h
  1427.     ld    e,l
  1428.     ld    hl,pix_up
  1429.     jp    nc,crtok
  1430.     ld    hl,pix_dnècrtok:    ld    (vect_2),hl
  1431.     ld    h,b
  1432.     ld    l,c
  1433.     or    a
  1434.     sbc    hl,de
  1435.     jp    nc,swaphd
  1436.     ld    hl,(vect_1)
  1437.     ld    iy,(vect_2)
  1438.     ld    (vect_2),hl
  1439.     ld    (vect_1),iy
  1440.     ld    h,b
  1441.     ld    l,c
  1442.     ex    de,hl
  1443.     ld    b,h
  1444.     ld    c,l
  1445. swaphd:    push    bc
  1446.     push    bc
  1447.     ld    hl,0
  1448.     srl    b
  1449.     rr    c
  1450.     or    a
  1451.     sbc    hl,bc
  1452.     push    hl
  1453.     pop    iy
  1454.     dec    iy
  1455.     pop    bc
  1456.     ld    hl,0
  1457.     or    a
  1458.     sbc    hl,bc
  1459.     ld    b,h
  1460.     ld    c,l
  1461.     pop    hl
  1462.     ld    a,h
  1463.     or    l
  1464.     jr    z,conend
  1465. smline:    exx
  1466.     call    c_plot
  1467. smmove:    call    pix_rt
  1468.     exx
  1469.     add    iy,de
  1470.     jp    nc,endmov
  1471.     add    iy,bc
  1472.     exx
  1473. bgmove:    call    pix_dn
  1474.     exx
  1475. endmov:    dec    hl
  1476.     ld    a,h
  1477.     or    l
  1478.     jp    nz,smline
  1479. conend:    exx
  1480.     call    c_plot
  1481.     exx
  1482.     ret
  1483.  
  1484. vect_1    equ    smmove+1èvect_2    equ    bgmove+1
  1485.  
  1486. calcxy:    exx
  1487.     lΣ    hl,(from_x⌐    ╗ calculatσ initia∞ datß fo≥ linσ
  1488.     ld    a,7
  1489.     and    l
  1490.     ld    b,a
  1491.     ld    a,80h
  1492.     jr    z,noshft
  1493. shftpx:    srl    a
  1494.     djnz    shftpx
  1495. noshft:    ld    c,a
  1496.     ld    a,0F8h
  1497.     and    l
  1498.     ld    l,a
  1499.     add    hl,hl
  1500.     ex    de,hl
  1501.     ld    hl,(from_y)
  1502.     ld    a,15
  1503.     and    l
  1504.     ld    b,a
  1505.     ld    a,0E0h
  1506.     and    l
  1507.     rlca
  1508.     rlca
  1509.     rlca
  1510.     ld    (bank),a
  1511.     or    80h
  1512.     out    (vmlatch),a
  1513.     bit    4,l
  1514.     ld    l,b
  1515.     ld    h,0
  1516.     jr    z,hlfblk
  1517.     ld    h,4
  1518. hlfblk:    add    hl,de
  1519.     ld    de,grafix
  1520.     add    hl,de
  1521.     exx
  1522.     ret
  1523.  
  1524. ╗ Thσ nex⌠ tw∩ routine≤ se⌠ anΣ rese⌠ thσ pixe∞ a⌠ thσ curren⌠
  1525. ; location
  1526.  
  1527. c_plot:    ex    af,af'
  1528.     or    a
  1529.     jp    z,creset
  1530.     ex    af,af'
  1531.     ld    a,c
  1532.     or    (hl)
  1533.     ld    (hl),a
  1534.     ret
  1535.  
  1536. creset:    ex    af,af'
  1537.     ld    a,c
  1538.     or    (hl)è    xor    c
  1539.     ld    (hl),a
  1540.     ret
  1541.  
  1542. ╗ Thσ followinτ routines¼ pix_lt¼ pix_rt¼ pix_up¼ pix_dn¼ movσ
  1543. ╗ thσ curren⌠ pixe∞ locatioε left¼ right¼ u≡ anΣ dowε
  1544. ; respectively
  1545.  
  1546. pix_lt:    sla    c
  1547.     ret    nc
  1548.     ld    c,1
  1549.     ld    de,-char
  1550.     add    hl,de
  1551.     ret
  1552.  
  1553. pix_rt:    srl    c
  1554.     ret    nc
  1555.     ld    c,80h
  1556.     ld    de,char
  1557.     add    hl,de
  1558.     ret
  1559.  
  1560. pix_up:    ld    a,b
  1561.     or    a
  1562.     jr    z,chr_up
  1563.     dec    b
  1564.     dec    hl
  1565.     ret
  1566.  
  1567. chr_up:    ld    de,char-1
  1568.     ld    b,e
  1569.     add    hl,de
  1570.     ld    a,4
  1571.     xor    h
  1572.     ld    h,a
  1573.     bit    2,h
  1574.     ret    z
  1575.     ld    a,(bank)
  1576.     dec    a
  1577.     ld    (bank),a
  1578.     or    80h
  1579.     out    (vmlatch),a
  1580.     ret
  1581.  
  1582. pix_dn:    ld    a,b
  1583.     inc    a
  1584.     cp    char
  1585.     jr    nc,chr_dn
  1586.     ld    b,a
  1587.     inc    hl
  1588.     ret
  1589.  
  1590. chr_dn:    xor    a
  1591.     ld    b,a
  1592.     ld    de,-char+1è    add    hl,de
  1593.     ld    a,4
  1594.     xor    h
  1595.     ld    h,a
  1596.     bit    2,h
  1597.     ret    nz
  1598.     ld    a,(bank)
  1599.     inc    a
  1600.     ld    (bank),a
  1601.     or    80h
  1602.     out    (vmlatch),a
  1603.     ret
  1604.  
  1605. subabs:    ld    a,h        ;perform absolute of hl - de
  1606.     cp    d
  1607.     jp    c,abshls
  1608.     jp    nz,absdes
  1609.     ld    a,l
  1610.     cp    e
  1611.     jp    c,abshls
  1612. absdes:    or    a
  1613.     sbc    hl,de
  1614.     ret
  1615. abshls:    ex    de,hl
  1616.     or    a
  1617.     sbc    hl,de
  1618.     scf
  1619.     ret
  1620.  
  1621. from_x:    dw    0
  1622. from_y:    dw    0
  1623. to_x:    dw    0
  1624. to_y:    dw    0
  1625. bank:    db    0
  1626. set:    db    0
  1627.  
  1628.  
  1629.  
  1630. Hardware Flashing and Inverse
  1631.  
  1632.  
  1633.      Finally¼ ß notσ oε thσ tw∩ ne≈ feature≤ iε thσ 256TC'≤ ì
  1634. graphics, hardware flashing and inverse.
  1635.  
  1636.      ┴ characte≥ oε thσ screeε caε bσ madσ t∩ flasΦ b∙ settinτ ì
  1637. bi⌠ ╖ oµ it≤ correspondinτ bytσ iε thσ attributσ ram«  Similarly¼ ì
  1638. ß characte≥ caε bσ inverteΣ b∙ settinτ bi⌠ ╢ oµ thσ correspondinτ ì
  1639. byte in the attribute ram.
  1640.  
  1641. .cp 8è     Fo≥ aε examplσ oµ thi≤ iε MicroWorlΣ BASIC¼ wσ wil∞ alte≥ ì
  1642. thσ abovσ examplσ prograφ whicΦ deal⌠ witΦ demonstratinτ thσ ì
  1643. attributσ raφ anΣ PC╟ bank≤ ("GREEK.MWB")«  Changσ line≤ 280-30░ ì
  1644. to
  1645.  
  1646. 00280 POKE 61440,64 : REM Set screen pos 1 to bank 0 + inverse
  1647. 00290 POKE 61504,129 : REM Set screen pos 2 to bank 1 + flashing
  1648. 00300 POKE 61568,198 : REM Screen pos 3 to bank 2 + inv + flash
  1649.  
  1650.      Yo⌡ wil∞ noticσ thσ to≡ characte≥ i≤ inverted¼ thσ middlσ ì
  1651. characte≥ flashes¼ anΣ thσ bottoφ characte≥ i≤ inverteΣ anΣ als∩ ì
  1652. flashes.
  1653. .paèSECTION III : Using ZBASIC
  1654.  
  1655.  
  1656.  
  1657.  
  1658.      T∩ bσ founΣ oε thσ accompan∙ disδ i≤ thσ filσ ZBASIC.COM«  ì
  1659. ZBASI├ i≤ ß versioε oµ MicroWorlΣ BASI├ v6.22σ whicΦ wil∞ worδ ì
  1660. unde≥ an∙ operatinτ systeφ o≥ shel∞ anΣ oε an∙ microbee«  I⌠ ì
  1661. automaticall∙ detect≤ whicΦ compute≥ anΣ operatinτ systeφ i⌠ i≤ ì
  1662. runninτ oε anΣ change≤ it≤ routine≤ accordingly«  I⌠ doe≤ thi≤ a⌠ ì
  1663. thσ expensσ oµ threσ standarΣ BASI├ commands║ EDIT¼ G╪ anΣ RENUM«  ì
  1664. Sincσ thesσ command≤ ver∙ rarel∙ appea≥ iε BASI├ programs¼ thi≤ ì
  1665. shoulΣ presen⌠ n∩ problem.
  1666.  
  1667.      ZBASI├ als∩ ha≤ thσ abilit∙ t∩ loaΣ anΣ ruε BASI├ program≤ ì
  1668. froφ thσ CP/═ commanΣ line«  Thi≤ enable≤ thσ programme≥ t∩ usσ ì
  1669. thσ auto-executσ featurσ oµ CP/═ t∩ automaticall∙ loaΣ u≡ thσ ì
  1670. BASI├ prograφ hσ want≤ wheε bootinτ (eg« settinτ thσ auto-executσ ì
  1671. commanΣ usinτ CONFI╟ t∩ ZBASI├ MENU.MW┬ wil∞ loaΣ anΣ ruε thσ ì
  1672. prograφ "MENU.MWBó ever∙ timσ thσ disδ i≤ booted).
  1673.  
  1674.      Als∩ oε thσ disδ i≤ thσ filσ CCPZGEN.COM«  Thi≤ prograφ wil∞ ì
  1675. generatσ aε imagσ oµ thσ CCP┌ versioε oµ CP/═ ont∩ thσ requireΣ ì
  1676. disk¼ iε exactl∙ thσ samσ wa∙ a≤ doe≤ SYSGEN«  Thσ CCP┌ operatinτ ì
  1677. systeφ i≤ ß barσ bone≤ versioε oµ CP/═ (withou⌠ shells¼ etc.⌐ bu⌠ ì
  1678. i⌠ wil∞ worδ oε an∙ existinτ microbee«  Hence¼ iµ yo⌡ wisΦ t∩ ì
  1679. distributσ ß disδ witΦ aε operatinτ systeφ alread∙ installed¼ ì
  1680. theε CCP┌ shoulΣ bσ thσ systeφ used¼ a≤ i⌠ wil∞ alway≤ worδ (thi≤ ì
  1681. i≤ technicall∙ illegal¼ however).
  1682.