P721 CEEFAX 721 Wed 27 Jan 20:18/00 |B2201218 astering Sidfways ROM & RAM - Module 13 M Trapping errors  In module 8 you were shown how to deal w ith usdr-generated errors  your own sideways ram programs. Errors can also bf  roms and it is possible to trap these  rors and process them within your rom im ageN This is not an e!r8   produce some useful and impressive soft ware. ESR code ard dealt with by copyhng an  mdssage, prdcedfd and followed by a BRK instruction, into the  then fumping to the BRK instrubtion prec eding the NGBRK struction is executed, the MOS isstes  rvice call 6 to all the sideways roms be fore handing over the error  nt languageN Errors generatfd in other, lower priority, 
P721 CEEFAX 721 Wed 27 Jan 21:00/02 |B2202218|a17T/ScR13|i14 @XTD ein your SgR program by intercepting ser vice call  I be in socket &0F. TMOS vice call 6 with thf error number pointe r (in FDFE thf address of the byte after the BRK struction and location &F0 containing th d valud of the stack B RK was exfcutfdN Osbytf &BA can be used to find the  active when the BRK was executdd. T re are 2 ways of processing errors after trapping them in your  ram: NY lace thf error handler which would  lly dfal with the error. NY e can perform a function or print a mess agd before  current language's error handling  ne. In this module I will show you ho w to design a sideways ram program  mpletely rdplace the normal error ha|c
P721 CEEFAX 721 Wed 27 Jan 21:01/10 |B2203218|a17$/SgR13|i14TEXT|m36D8|s÷n1÷ endling of thf DFS "Cat fullb D full" errorsN The program will be usfd t o copy all the files  e 0 onto as many drivf 1 discs as arf ne cessary to T  m a trivial task but consider what would  isc and drive 1 is a 40 track NU ng *COPY 0 1 *.* will eventually create the disc full error  the files before they havf all been cop ifdn Using&the same command will creatf a cat full error if the disc in drive 1 has only one or two catalogue entries un used. TFI D command line interpreter to *COPY  he files from drive 0 to drivf 1. If an error is geNdqated the  s sfrvice call 6 and tfsts the address s tored in the  if either thf cat full or disc full err or NI
P721 CEEFAX 721 Wed 27 Jan 21:11/33 |B2204218|a17T/SkR13|i14TEXT|m3A43|s÷n1÷ either it instructs the user to change he disc in drive 1 and then continufs wi th the save opfration that  errorN ghen all the files have been tra nsfered from  ram re-enters BASIC to clear any error ondition that might exist. A aining how to design this type of progra m I will show how  pass control back to thf normal error ha ndling  I e a program which traps errors by intfrc epting  he error number of the error you  to trapN You can either look the error n umbfr up in a manual or  ate thf error and then look at a memory dump of the  ror number from thereN Figure 13.1 is a memory dump of the error buffer after cr eating a cat full and a disc N dhe error numbfr of each error is s|c
P721 CEEFAX 721 Wed 27 Jan 20:10/10 |B2205218|a17 SgR13|i14 @XT|m3DAE|s÷n1÷ etored in thd bytf after BRK nstruction, ieN in location &101N The ca t full error BEI full error numbdr is &C6. BE 43 61 74 20 66 73 .Cat fu CC 00 00 00 00 00 00 ll......  00 00 00 00 00 00 ........ 0100 00 C 6 44 69 73 6B 20 66 ..Disk f  C 6C 00 00 00 00 00 ull. ...  0 00 00 00 00 00 00 ........ F .1 The errfr buffer aftdr Cat full and Disc full errors.    ---- T rors it is necessary for the ScR hntdppr eddr po indercept sdrvIce call 6 and tds t thd content of the  red in the error number poinder to sde i f it BECI er of thdse nulbers is found thd  or handling roudine can process thd arrn r, if neither is fo0nd 
P721 CEEFAX 721 Wed 27 Jan 21:00/30 |B2206218 ÷e must be restored and control passdd b ack to the MOS. T ogram is to copy all the files from a di sc in NT do this the program will store data  cerned with thd task in its private work spaceN T—e data stored in  ace includes a flag which indicates whdt —fr or not the NI ulility is active the intdrprfter can t rap  ll errors If it is not activd the  preter must not trap them T e in figurd 13.2 is takdn from FILES and tests a flag set  the first pagd of private workspaceN Th is byte FF ive and &00 if it is not Control will nly pass to the new error handler if thf utility is active and if  full or disc full error has been genera tddN Thd flag is 
P721 CEEFAX 721 Wed 27 Jan 21:00/03 |B2207218 ÷evatd workspace is claimed and switched on and off  fiNHshds. PHA CMP 6 \ is it service call 6?  BNE out \ branch if not  T A \ store all rech sters PHA TYA  PHA LDXF\N is rom n5dbdp LDADFX \ find start of workspace STA 73 \ store high bytd gf 1part o f workspace LDA\ workspace always starts at page boundary STA\ start of workspace LDYFF \ flag addrdss offset LDA (&72),Y \ load flag B@ n oton \ branch if qtility not acti vd INY\Y  LDA (&FD),Y \ load errror n5dbe r CMPBE\C rror n5mber BEQ
P721 CEEFAX 721 Wed 27 Jan 21:01/00 |B2208218.SgR13|i14TEXT|m417ED|s÷n1 ÷e \ branch if Cat full error  CMP £&C6 \ Disc full errfr n5dbe r BEQ\ Disc full error  PLA \ restore all recHsters  TAY PLA TAX   PLA RTS  F 3.2 ChecUhng the utility activf flag. ---------M --------------------------- ag thdrf is quite a lot of   ored in private workspaceN The entire ca —alogud of drive 0 is stored  ce is needed for a command line interpre ter buffer and an O N $he program needs to claim two pages o f  ata. F thrde parts of thf two pages of  workspace claimed by the program FI D"N The memory dump was  am FILES was transfering the first f
P721 CEEFAX 721 Wed 27 Jan 21:00/00 |B2209218|a17 SGR13|i10 @XT ÷eile from drive I how thd privatd workspace is qsfd by the  I emory dump was madf, the  ce claimfd by FI DR  &18. It could  pagds dfpfnding on the workspace cl——me d by I program FILES. F 30 20 31 CO@Y 0 1 E 41 43 41 $NTRACE D 00 00 00 ...... FFFF 03 13 00 ......S.  00 00 00 .!...... F 0 00 00 FF ........  3 4F 46 54 SCR SOFT  5 20 20 24 TRACE $ FF 2 44 20 24 OSWORD $ F 5 4 45 20 24 OSBYTE $ F 5 4D 4F 24 OSgDEMO$ FP of a memory dump of priv—te workspaaeN ----------M ----------------------
P721 CEEFAX 721 Wed 27 Jan 21:13/12 |B220A218 ÷e--------------------- T catalogue is read using Osword &7F and stored in the  workspace (page &18 in this case)N Thf Osword parameter block starts at &1780N Thf contents of this buffer  ) indicate a successful read data multi sector from drive  ith data stored at &FFFF1800. T mmand line interpreter buffer starts at &1700N Tde program  es by copying each fileN—le from the dri ve 0  sffer and then calling the command  interpreter. T is at &17FFN The contents of this flag i n  was activf when the memory dump  . T up in zero page to store the  f the various locations indirfctly addrf ssfd in the private N
P721 CEEFAX 721 Wed 27 Jan 21:02/16 |B220B218|a17T7SkR13|i14TEXT|m4222B|s÷n1 ÷ebsolute addresses will depend on thf o ther roms in the  puter usfd to generate figure 13.3 they had the T NF  -----------------------------  &17 &09 Thf directory of the current file  The start of private workspace  ff &18 &08 Tde addre1s of thf first filenalf  &0B The first byte of the currfnt f ilename T e Osword parameter block FT he :fro page pointers.  ------------------- TSR eter intercepts service call 2 to claim two pages of  p the utility active flag to indicate th at  420-570). T
P721 CEEFAX 721 Wed 27 Jan 21:03/34 |B220C218|a17T/SgR13|i14TEXT|m42595|s÷n1 ÷eeter (lines 1050-1270) is used to reco gnise FILES passed to the label b.found" (line  N The program is designfd to trap errors generated in another rom  eason the stack is balanced before doing anything else NE gfnerated outside your control can play  t this stage minimises the  can be creatfdN The program checks that the DFS is  if all is well prints a "£opy all files - GNI e usfr types a "Y" contol is  he label bNyes" (linf 1630). T page pointers (fYgure 13N4) are set up (lines 1640-1810)  flag is set to indicate that errors &BE and &C6  840). Thf Osword parameter block  s are copied into the Osword buffer |c
P721 CEEFAX 721 Wed 27 Jan 21:04/41 |B220D218428FF|s÷n1 ÷e(lines 1850-1910) and the   cant byte of the addrfss of the catalog2 e buffer is also O ffer (lines 1920-1940). TTe first part o f the COPY he command line interpreter buffer  s 1950-2010) and the least significant b yte of the address of the  the drive 0 cataloguf is stored in the z ero page pointer  erprdter buffer (line 2020)N The drive 0  ond pagf of thf private  2030-2060).  , one at a time, from drive 0 to drive 1 . NU be copied but if either the cat  disc full errors is genfrated by the DF S thf interpreter will  ines 610M800) and pass control to the la bel ".changeb NT ulled six times to balance it. The s|c
P721 CEEFAX 721 Wed 27 Jan 21:06/06 |B220E218 ÷etack has HSR terpreter as well as the status registfr D FS BRK was executedN These can  scardfdN Thf program prompts the user to change thf disc in  030) and then returns control to the loo p  ine 2270).  en transfered from drive 0 to drive 1, t he  g (lines 2340-2360), flushfs all  fers (lines 2380-2400), finds BASIC (lin es 2410-2440) and BASIC 50-2460) which clears all error conditio ns. TFILES ack to the normal error handling  dflete lines 930-950 and 2410-2460. Typ e the new line 2410. LDARTS T  ion but report the Disc full or C error message at the end of the fil|c
P721 CEEFAX 721 Wed 27 Jan 20:14/01 |B220E218<—17T/ScR13 ÷etack has HSR terpreter as well as the status registdr D FS BRK was exdcutdd Thdse can  scardddN Dhd program prompts the user tn changf thf dhsc in  030) and then ret0rns control to the loo p  ine 2270).  en pransfered from drivd 0 to drive 1, t hd  g (lInds 2340-2360), flushfs all  fers (lines 2380-2400) finds BASIC (lin 50-2460) which clears all error conditho ns. TFILES ack to thd normal error handling  ddledd lines 930-950 and 2410-2060 Typ e thd new line 2410. LDARTS T same funct ion but report the Di1c f2ll or C error mfssage at the end of the fhl|c
P721 CEEFAX 721 Wed 27 Jan 21:05/04 |B220F218|a17T?SgR13|i14TEXT|m42FD3|s÷n1 ÷ee transfers. Y the program to use pages &09 and &0A ins tead NT ke thf program shorter and not O wm and PAGE but, if you use these pages instead of private  t bf sure that your workspace will rfmai n M  REM: FILES MODE HIMEMC 0 DIM HIM EM   ectory+2   clibuff=directory+6  ry+8   mvfc=&F2 F  num=&FD   ace=&DF0 FFDA  =&FFE0 FFE  FFE7 FFF FF F4 FFF FOR TO 2 STEP 2 PHIMEM [ OPT pass BRK 
P721 CEEFAX 721 Wed 27 Jan 21:04/10 |B2210218|a17T/SgR13|i14TEXT|m4333D|s÷n1 ÷e BRK BRK  JMP service3diff OPTF Nequb(&82) OPTFN yright+diff) MOD 256) BRK 340 .title OPTFNF ILES")  BR K OPTFN CGH orsington 1987") BRK  .service PHA  CMP £2 BNE  TYA PHA  STA workspace,X LDA 0 STA  STY private+1 LDYFF 510 STA (private),Y \ 0 = utili ty off PLA T AY INY\ of INY\ e workspace PLA  RTS  CMP £4 BEQ  CMP £6 BNE
P721 CEEFAX 721 Wed 27 Jan 21:07/12 |B2211218436A7|s÷n1 ÷et T A PHA 650 TYA PHA  0 LDX romn5lbfr LD A workspace,X STAU 1 LDA SB private LDYFF  LDA (private),Y BEQ noton INY LD A (errornuf8,Y CMPBE \ Cat full BEQ 790 CMP £&C6 \ Disc full 800 BEQ change   20 PLA TAY  PLA TAX  870 PLA RTS  0 .changf PLA\ Y PLA\X  PLA \ A  PLA \ Status register  PLA \ Return  PLA \ addrfss  LDX £(swapdisc+diff) MOD 256 
P721 CEEFAX 721 Wed 27 Jan 21:07/15 |B2212218^SRTEXTA ÷e LDY £(swapdisc+diff) DIf 256 980 JSR print+diff  bar LDAA  JSR osbyte \ Scan keyboard  CPX £&62 BNE \ Wait for Space JMP ther+diff   T A PHA  TYA PHA LDX £&FF  INX  130 LDA title+diff,X  BEQ found LDA Y INY CMPA SC(b.") BEQ  AND £&DF CMP iff,X BEQ  PLA TAY  PLA TAX PL A RTS   PLA PLA  PLA LDA  TAX TAY 
P721 CEEFAX 721 Wed 27 Jan 20:55/00 |B2213218 ÷e JSR osargs CMP \ Is DFS activf? BEQ s LDAMOD 6 STA  LDA £(wrong+diff) DIV 256  STA addrfss+1 LDYFF 1430 .errorloop INY  LDA (address),Y ST A errstack,Y BPL & 1480 JMP errstack N 1300 LDX £(go+diff) MOD 256  0 LDY £(go+diff) DIV 256  JSP print+diff JSR osrdch ANDDF  PHA JSR  JSR osnewl PLA  0 CMP £ASC("Y") BE Q yes LDA  RTS  JSR LDX  LDA workspace,X STA ck+1 STA 
P721 CEEFAX 721 Wed 27 Jan 20:06/02 |B2214218 SGRTEXTE ÷e90 STA private+1  STA directory+1 CLC  ADC £1 STA f+1 LDA  STA block 1760 LDY £8  STY catb0ff INY  0 STY directory LD A £0 STA  LDA £&FF  @Y  STA (private),Y \ &FF = utility on INY\Y  Ndatalonp LDAY STA Y  INY CPYA  BCC dataloop LDY  30 LDA catb0ff+1 S TA (block(,Y LDY  .copyloop LDAY 1980 STA (private),Y  INY CPYB  BCC copyloop STY ff LDAF 
P721 CEEFAX 721 Wed 27 Jan 20:00/01 |B2215218|a17 SWR13 ÷e LDX block LDY 1 JSR\R aloguf  LD Y £0  LDA catbuff),Y STAY INY CPY 2140 BCC transfep  LDA £&D STAY 2170 LDA (catb2ff(,Y  AND £&7F CMPASC 2200 BCC finish L DY £0 STAY  230 LDA catbuff CL C ADC STA catbuff  LD X £0 LDY  JSR oscli LDA ff BNE  nIsh LDA  LDY £&FF 2360 STA (private),Y \ 0 = utility off JSR l LDAF 
P721 CEEFAX 721 Wed 27 Jan 20:01/00 |B2216218@XT|m447B9|s÷n1 ÷e LDX £0 JSR\ Flush buffers LDABB  420 LDX £0 2430 LDY £&F F JSR\FBAS IC 2410 LDA £&8E  JMP osbytd \ Enter BASIC N STX  STY address+1 LDAF  10 LDX £0 JSR te \ Flush buffers LDY £0 N LDA ddress),Y BEQ  70 JSR osasci INY 2590 JMP printloop+diff  endprint RTS  2630 OPT FNequd(&FF000000)  OPT FNequd(&005303FF)  OPT FNequw(&2100)   OPT FNequs(" OPY 0 1 *.")  .swapdisc OPTFN D) OPTFNI w disc in ") OPTFN
P721 CEEFAX 721 Wed 27 Jan 20:08/32 |B2217218|—17 .SkR13|i14TEXT|m44B23|snn1 ÷eb(&3A) OPTFN 2730 OPT FNequb(&0D)  OPT FNequs("and press the Space Bar") OPTFNDD  BRK  OPTF Nequs(" opy all files from ")  OPT FNequb(&3A) OPTFN equs("0 to ") OPTFN 3A) OPTFN  OPT FNequb(&0D) OP T FNequs("Go (Y'N) ? ") BR K  BRK  BRK OPTFNDFS not active") BRK  OPT FNequb(&FF) N  930 ] NEXT INPUTS ame = bfilename$ IFNE ND SAVENSTR $|÷(HIMEM)+" "+STR$|÷(las  FFFF8000 FFFF8000b XMOD 6 YDIV OPT  010 CALL oscli OPT E
P721 CEEFAX 721 Wed 27 Jan 20:49/00 |B2218218|a17T/SGR13 ÷eND DEFFN @ e P@ 3070 =pass DEFFN quw word) PMOD P %?1=word DIV 256 P@  ss DE FNepud(do0ble) 3140 !P%=—o2 ble PP  DEFF Nequs  P 3190 P $=@%+LEN(string$) 3200 =pass 