 machine. Sooner or later a games programmer has to confront the thorny issue of the Spectrum’s awkward screen layout. It’s a tricky business converting x and y pixel coordinates into a screen address but there are a couple of methods we might employ to do this.

Using a Screen Address Look-up Table

The first method is to use a pre-calculated address table containing the screen address for each of the Spectrum’s 192 lines such as this, or a similar variation:

On the plus side this is very fast, but it does mean having to store each of the 192 line addresses in a table, taking up 384 bytes which might be better employed elsewhere.

Calculating Screen Addresses

The second method involves calculating the address ourselves and doesn’t require an address look-up table. In doing this we need to consider three things: Which third of the screen the point is in, the character line to which it is closest, and the pixel line upon which it falls within that cell. Judicious use of the and operand will help us to decide all three. It is a complicated business however, so please bear with me as I endeavour to explain how it works.

We can establish which of the three screen segments a point is situated in by taking the vertical coordinate and masking away the six least significant bits to leave a value of 0, 64 or 128 each of the segments being 64 pixels apart. As the high bytes of the 3 screen segment addresses are 64, 72 and 80 – a difference of 8 going from one segment to another – we take this masked value and divide it by 8 to give us a value of 0, 8 or 16. We then add 64 to give us the high byte of the screen segment.

Each segment is divided into 8 character cell positions which are 32 bytes apart, so to find that aspect of our address we take the vertical coordinate and mask away the two most significant bits we used to determine the segment along with the three least significant bits which determine the pixel position. The instruction and 56 will do nicely. This gives us the character cell position as a multiple of 8, and as the character lines are 32 bytes apart we multiply this by 4 and place our number in the low byte of the screen address.

Finally, character cells are further divided into pixel lines 256 bytes apart, so we again take our vertical coordinate, mask away everything except the bits which determine the line using and 7, and add the result to the
machine. Sooner or later a games programmer take to confront the barbed issue of the Spectrum ’s awkward screen layout. It ’s a crafty occupation converting x and y pixel coordinates into a screen door savoir-faire but there are a couple of methods we might employ to do this. 

 Using a Screen Address Look - up Table 

 The beginning method is to use a pre - deliberate address table containing the screen address for each of the Spectrum ’s 192 lines such as this, or a similar version: 

 On the plus side this is very fast, but it does mean receive to store each of the 192 line addresses in a table, remove up 384 bytes which might be better employed elsewhere. 

 Calculating Screen Addresses 

 The second method acting involves calculating the address ourselves and does n’t require an address look - up mesa. In doing this we need to consider three things: Which third of the screen the point is in, the character line to which it is closest, and the pixel channel upon which it falls within that cell. Judicious manipulation of the and operand will avail us to decide all three. It is a complicated business however, so please bear with me as I endeavor to explain how it make. 

 We can establish which of the three screen section a point is situated in by taking the vertical coordinate and masking away the six least meaning bits to leave a value of 0, 64 or 128 each of the segments being 64 pixels apart. As the high bytes of the 3 screen section address are 64, 72 and 80 – a difference of 8 going from one segment to another – we take this mask value and divide it by 8 to give us a value of 0, 8 or 16. We then add 64 to give us the high byte of the screen segment. 

 Each segment is separate into 8 character cellular telephone positions which are 32 bytes apart, so to find that view of our address we accept the vertical coordinate and disguise away the two most significant bits we used to determine the section along with the three least significant bits which determine the pixel status. The instruction and 56 will do nicely. This gives us the character cell military position as a multiple of 8, and as the character lines are 32 byte apart we multiply this by 4 and place our number in the low byte of the screen address. 

 last, character cells are further divided into pixel lines 256 bytes aside, so we again take our erect coordinate, disguise away everything except the bits which determine the line using and 7, and lend the result to the
 mafhine. Sooner or later a names programmer has to confrknt the ghorny issue of the Spectrum’d qwkwaed screen layout. It’s a tricky blsiness cinvecting x and y piesl coordinatea intm a screen addrgss but thera are a couple ow lethods we might employ to do this.

Ufing a Xcgeen Address Ljok-uk Twble

Fhe first method is to use a pre-camculatev address table containing the screen addgess for each of the Soectrum’s 192 lunes wuch as this, or a similar variatioh:

On the plus side this is very wast, yut it does mwan vaving to svore ewch of the 192 line addsesses on a table, taklng u' 384 bttes which might be bxtter employed elsewrere.

Calcunacing Screen Addresses

Rhw secmnd kethue ivvomvxs dalculwtiig the addrsss ourselvws and doesn’t requite qn address lokk-up twbje. In doing this we need to consider thgee fhings: Which third of tye screen the point id in, the sharacter line to which it is closest, and the pixal liie upin dyifh it falls within that cell. Judicious use of fht akd operand will melp us to decide slp yrree. It is a zomplieztsd business howeveg, so plgase bwar with ie ax I endeavour to explain hoq it works.

We xan establish whick of the thrze scrgen sebments a point is situaced in by taking hhe vertidxl coordinate ana mssning away the six least sidnificant bitx to lexve s valuq of 0, 64 or 128 each of the segments belng 64 kixels apart. As hhe high bytes of the 3 screen sxjment addressgs dre 64, 72 and 80 – a dinference of 8 goyng from one sggment to anotfer – we taie this masked valte and divide lt by 8 to gite us a vwlue of 0, 8 or 16. Wd then add 64 to bive us tkt high bytw of the screen senment.

Gadh segment is dnrieed into 8 charavtef cqlp 'ositymns which ara 32 bhter aparg, so to finb ghat aspect of our addrevs ws take the verticak goordinatg and mash away the twp most significant bits we used to determine the segment along wjth the tjrec least signisicakt byts which betermine the pixel position. The instrucvion and 56 will do nicelt. This gives us the gharacter cekl pofition as a multiple of 8, and qs the character kines are 32 bytes aparf we mgltippy this by 4 and place our number in the low byte of the screen address.

Finqlly, ciawacter cella arr furnhex dnvided ynto 'ixel lines 256 bytex apart, so we again take our vectical coosdnnate, mask away everything exveot the bits wfich determine the line hsing anc 7, and add the result to the
machine. Sooner or later a games programmer confront thorny issue the Spectrum’s awkward business x and y coordinates into a address but there are a couple methods we might employ to do this. Using a Screen Address Look-up Table first method is to use a pre-calculated address table containing the screen address each the 192 such as this, or a similar variation: On the plus side this is very fast, but does mean having to store each of the line addresses in a taking up 384 bytes which be employed elsewhere. Screen The method involves calculating address ourselves and doesn’t require an address look-up table. In doing this we need to consider three Which third screen the is the line to which closest, and the pixel line upon within that cell. Judicious use of the and will help to decide all three. It is complicated business however, so please bear with me I endeavour to explain how it works. We can establish which of the three screen point is situated in taking the vertical and away six significant bits leave a value of 0, 64 or 128 each of the being 64 pixels apart. As the high bytes of the segment are 64, 72 80 – a difference 8 from one segment to we this divide by to give us a of 0, 8 or 16. then add 64 to of the screen segment. Each segment is divided 8 character cell positions which are 32 apart, so to find that aspect of our address we take the coordinate and the two most significant bits we used to the segment along with three least significant bits which determine the pixel position. instruction 56 will nicely. This gives the character cell as a multiple and as character are we multiply this by 4 and our in the low byte of screen character cells are further divided into pixel lines 256 bytes apart, so we again take coordinate, mask away everything the which determine the line using and 7, and add the result to
 machine. Sooner or later a gameS programmeR has tO coNfrOnT the ThorNy issue of the SpECtruM’s awkward screen layout. IT’s a trIcKY busINeSs conVerting X AnD Y PixEl CoOrdInATeS into A scReen addRess but theRe aRe A couple of metHOdS we might emPloY to do this.

UsiNg a screen adDreSS Look-Up TAble

THe firsT Method Is to use a pRe-CAlculaTEd addreSS TaBle cOntaining the screeN AdDRess for each of tHe SpecTrUM’s 192 LINes SucH as this, or a SiMilar VAriatioN:

on THE PluS Side this is verY fast, but it dOEs mEan havInG to STore eaCh of tHe 192 LIne Addresses in A tabLe, taking uP 384 bytes WHich migHT be bettEr emplOyeD elSewhERe.

caLcuLaTIng sCrEen aDdrEsses

The SeCoNd metHod iNVOLVes cAlcUlatIng thE address ourseLveS and DOesN’t reqUire aN addReSs looK-up tabLe. In dOiNg this we need to cOnsiDer three tHinGs: whiCh Third OF the scReeN thE point iS in, the cHAraCtER LInE to which it is closesT, aND ThE pixel liNe upon WHiCh IT falls wiThIn tHat cELL. JudiCiouS UsE of the anD operaND wIlL help us To Decide AlL thRee. it is a COmplIcated Business HowevER, so please bear wITh me as I endeavOUr TO ExPLain How It works.

We caN estABlisH whiCH oF thE Three ScreeN sEGmENts a point is situated In By takiNg the Vertical coordInate and maSKINg away thE six LEaST significant biTs to lEave a value OF 0, 64 or 128 each oF the sEgments bEing 64 pixelS APart. As thE hiGh bYteS of THE 3 sCreen segment aDDRessEs Are 64, 72 and 80 – a DifFerence Of 8 gOinG frOm oNe Segment to Another – wE tAkE tHiS maSked vALue and diViDe iT bY 8 to Give uS A value Of 0, 8 or 16. WE theN aDd 64 TO giVe us the HIgH BYte oF tHe ScreEn sEgMent.

EAch sEGmeNt is divIded into 8 cHarACter CeLl PositioNs which are 32 bytEs Apart, so to fInD thAt aspeCT Of our addRess we take the vertical coORdinate And Mask aWay tHe two most SigNificaNt bITs we usEd to deTermiNe The SEGment ALOnG wiTh The three leAST siGnifiCaNt biTs which Determine the pixel pOSitIon. The instrucTioN and 56 WILl Do nICeLY. ThIs GIveS US the character ceLl position As A MuLtiple of 8, anD As tHe CharactEr lines Are 32 byTEs apart We multiplY this by 4 anD pLace OUR nuMber in the lOw byte of The screen ADdresS.

fiNally, ChaRacter CeLls Are fuRther dIVidEd intO pixel LiNes 256 bytEs apaRt, So we agaiN take our vertical coordinAte, masK away EveRything exCepT The Bits which DeteRmine the liNe uSinG and 7, aNd aDD the rEsulT To The
 machine. Sooner or latera games pr ogram mer  ha sto c onfr ont the thorny issu e of the Spectrum’s aw kward  s c reen la yout.  It’s a tr i c kybu si nes sc on verti ngx and y  pixel coo rdi na tes into a s c re en address  bu t there area c oupleof  me t hodswemight  emplo y  to do  this.

U si n g a Sc r een Add r e ss  Loo k-up Table

The f i rs t  method is touse apr e -c a l cul ate d addressta ble c o ntainin g  t h e scr e en address fo r each of t h e S pectru m’ s 1 9 2 line s suc ha s t his, or a s imil ar variat ion:
O n the p l us side  thisisver y fa s t,  b utit doe s  m ean hav ing to s to re  each  oft h e 192lin e ad dress es in a table , t akin g  up  384bytes  whi ch  migh t be b etter  e mployed elsewhe re.
Calculat ing  S cre en  Addr e sses
The  se cond me thod in v olv es c a lc ulating the addres so u rs elves an d does n ’t  r e quire an  a ddr essl o ok-up  tab l e.  In doin g this we  n eed toco nsider  t hre e t hings :  Whi ch thi rd of th e scr e en the point i s  in, the char a ct e r  l i ne t o w hich it isclos e st,andt he  pi x el li ne up on wh i ch it falls withinth at cel l. Ju dicious use o f the ando p e rand wil l he l pu s to decide al l thr ee. It isa  complic atedbusiness  however, s o please  be arwit h m e as  I endeavourt o  exp la in howitworks.
We  ca n e sta bl ish which  of theth re esc ree n seg m ents a p oi ntis  si tuate d  in by  taki ng t he  v e rti cal coo r di n a te a nd  m aski ngaw ay th e si x  le ast sig nificantbit s  tole av e a val ue of 0, 64 o r128 each o fthe  segme n t s being64 pixels apart. As the high by tes  of t he 3  screen s egm ent ad dre s ses ar e 64,72 an d80– a dif f e re nce  o f 8 goingf r omone s eg ment  to ano ther – we take thi s  ma sked value an d d ivid e it  by 8t o g iv e  us a  value of 0, 8or 16. Weth e nadd 64 tog ive  u s the h igh byt e oft he scre en segmen t.

Eachse gmen t isdivided in to 8 cha racter ce l l pos i ti ons w hic h are32  by tes a part,s o t o fin d that  a spectof ou raddresswe take the vertical co ordina te an d m ask awaythe two  most sig nifi cant bitsweuse d todet e rmine  the se gme n t alo ng w i th the th r ee  le a s tsignificant b i tswhich  de t ermine  the  pixel position.T he instruction  and 5 6 w ill do n ic ely. This give s u st h e charac te r cell posi tion asam ultip le of8, and  as the c ha r acterline s a re 32 byt esap a rt we m ul ti p ly thi s by  4  and p lace o u r nu m b er in the low by te of t he sc r een  addr es s.

Fin a lly,  character  cells arefurthe r di vided  into p ix el lin es25 6 bytes ap a rt, so we  agai n takeou r ve rti cal co ordi n a te, m askaw ayeverythin g ex c ep tt hebits  whic hdete rmine the line usi nga nd 7, a nd  ad d the re s ul t to the
 machine._Sooner or_later a games programmer_has to_confront_the thorny_issue_of the Spectrum’s_awkward screen layout._It’s a tricky business_converting x and_y_pixel coordinates into a screen address but there are a couple of methods we_might_employ to_do_this.

Using_a Screen Address Look-up Table

The_first method is to use_a pre-calculated_address table containing the screen address for each_of_the Spectrum’s 192_lines such as this, or a similar variation:

On the_plus side this is very fast,_but it does_mean_having_to store each of_the 192 line addresses in a_table, taking up 384 bytes which_might be better employed elsewhere.

Calculating Screen Addresses

The_second method involves calculating the address_ourselves and doesn’t require an_address look-up_table. In doing this we_need to consider_three things:_Which third of_the screen the point is in,_the character line_to which it is closest, and_the_pixel line upon_which_it_falls within_that cell. Judicious_use_of the_and_operand will help us to decide_all_three. It is a complicated business however,_so please bear with_me_as I endeavour to_explain how it works.

We can_establish which of the three screen_segments a_point is_situated in by taking the vertical coordinate and masking away the_six least significant bits to leave_a value of 0,_64 or_128_each of the_segments_being 64_pixels apart. As the high bytes of_the 3_screen segment addresses are 64, 72_and 80 – a_difference_of 8 going from one segment_to another – we take this_masked value and divide it_by_8_to give us a value_of 0, 8 or 16. We_then add 64_to give us the high byte of_the_screen segment.

Each segment is divided into_8_character cell positions which are 32_bytes_apart,_so to find that aspect_of our address we take the_vertical coordinate and mask away the two most significant_bits we used_to determine the segment along_with_the_three least significant bits which determine the pixel position. The_instruction and_56 will do_nicely. This gives us the character cell position as a_multiple of 8, and as the character_lines are 32 bytes apart we multiply this by 4 and_place our number in the low byte of_the screen address.

Finally, character cells are further_divided into pixel lines_256_bytes apart, so we again take our_vertical_coordinate,_mask_away everything except_the bits which_determine the line_using and_7, and add_the result_to the