P720 CEEFAX 720 Wed 27 Jan 21:00/23 |B2201209 SBITS M An Exploration of the BBC Micro at Machine Level BP  .......................................N ............ PIN s I oration of the BBC MI over two areas. Thfy are convfrting ASC II numbfrs into numbers in memory (input ), and vice versa  hmetical processes of multiplication  divisionN Since inputting and multipli cation are  r. II have used OSRDCH to  ingle byteN In module 6 we printed out thd value of that byte in three formats, decimal, NB e were expecting a single O SRDCH was being used that was all we got . T esigned to accept large NY n dffine just how large yourself, bu|c
P720 CEEFAX 720 Wed 27 Jan 21:01/04 |B2202209|a17T/OSB11|i14TEXT|m336D|s÷n1÷ et for  umbfrs that can be hfld in  I the real world there are always users wh ose m—in aim in  ograms, and quite right tooN You  o try to anticipate everything a malicio us user (or a  even if it seems totally NN where is this a grfater problem than wit h  F what our input routine is going to doN This is known as its Functional Spfcific ation, and even if  g the way it helps enormously to knos  at you are trying to achieve. In its br iefest form then  this module is as follows: P typfd in by the user into a defined are a of  at do not form numbers  user to delete the last character he inp ut. T
P720 CEEFAX 720 Wed 27 Jan 21:00/11 |B2203209 esuch a way as to be easily  in an ASCII to binary conversion routin e in the  TOS utine for input NI is OSWORD a piece of memory to  ing input, the input buffer, and we can also set an spper and lower limit to the characters accepted  hf stringN On exit from the routine we can find out thf length of the string en tered and we can ESCAPE pressed. HOSWORD advantagesN ghen you define  he characters entered the routine behave s a NI cters are still printed  d attempts to delete characters will hav e  cters are presentN I  e an interesting exercise to write a  ilar routine myself which would not |c
P720 CEEFAX 720 Wed 27 Jan 21:07/02 |B2204209 eexhibit such strange  h would allow clearer defining of  ter limits. S next module to using this routine  asis for inputting numbers and convfrthn g them to  t this module, B/osb11. T program goes like this: I aracter ssing OSRDCH I s occurred then exit) C rriage return which terlhnates inp3t  (If a CR then exit) C ete I aracter) C against valid list O character to screen and add to string  in memory WY ter to keep track of the position of  last character in the buffer. T section of the code lies between lines 210 and 390N H ed ssing OSRDCH and it is checsed 
P720 CEEFAX 720 Wed 27 Jan 21:01/30 |B2205209 e sfe if it is a carriagd return (13) or a delete (127),  al treatment. Thf number of  in the buffer is checked agahnst the buf fer NI en the character is  ine at 'check#character' which we will ome onto in a momentN If the accumulato r contains a null  outine then the character was not N Otherwise the character, which has now passed all  reen and added to the string in  t 'input#buffergN The Y registdr, which is counting  is increasdd. It will always  umber of characters in the input buffer L ter a carriage rfturnN T the input and we store a CR at the end o f  n a piece of memory 
P720 CEEFAX 720 Wed 27 Jan 21:11/42 |B2206209|a17T/OSB11|i14TEXT|m41119|s÷n1 ÷e#lengthgN This latter is to allow us to use BASIC s working correctly after  led the programN We exit having cleared the C ndicate a valid result. L re we go on detecting an error, usually ESCAPE, during inputN Note that part of the string may be  e Carry flag will be sftN Again we can ssf this to indicate an invalid rfsult. A e buffer was already  racter was keyed inN The lhcro bfeps (b y VDUNOSRCH accumulator) to warn N The character just entered is discarded and the next character is awaited by ret urnhng to the start T he only ways out of this situation would ESCAPECR g thf last character. L
P720 CEEFAX 720 Wed 27 Jan 21:00/12 |B2207209|a17T?OSB11|i14TEXT|m41483|s÷n1 ÷ehe start of the delete routineN As lo ng as Y  ddlete the characterN If  ng past the start without trapping this error  thd previous line We  lete if thfre is something to delete (wh ich  y by calling OSgRCH with  mulatorN The Y rdgHster must be rdduced by  ter in the buffer and we  tart of the loop. N e casfs the Y registdr will only be  eased by one if there is a valid charact er going into  T# op' subroutine is at line 870N ge enter this  tor and we will use the X H index along a string which contains all the  T t 'valid#listgN So, 
P720 CEEFAX 720 Wed 27 Jan 21:10/10 |B2208209|a17T/OSB11417ED|s÷n1 ÷e as a temporary store for A while we c heck  the list, (where there   ook along thf list, a character at a tim e,  CMPN ghen we reach a  list that matches the one in A then the zero flag is set and we can branch on :f ro (BEP) to the NI reach a zero in the list first this  s the character is not valid and we bran ch to 'invalidg. N id' we have to rdbalance the stack  a PLA becausf we didn't rfach the one at line 920N Z or and the subroutine returnsN F lid character the subroutine returns imm ediately. T at line 1070, is terlhnated by  yte. In this example it contains all th e characters  thmetic but you could include a 
P720 CEEFAX 720 Wed 27 Jan 21:10/12 |B2209209|a17T/OSB11|i14TEXT|m41B57|s÷n1 ÷emal point for example, or &ABCDEF for hexadecimal  T ctually one larger than the buffer size is  the final carriage T is is the first time wegve used thf FNEQ UM function to set asidf some memoryN I 've put &FF7255  ith but it could contain anything  lly. ABASIC which rfpeatedly calls the  rints out the contfnts of the buffer, so you  is put into the buffer. I ule we will use this routine as the basi s of ASCII will introduce a use of  cation; and in the module after that I w ill  ation routine. 