disasm_with_labels.asm 188 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332
  1. ; z80dasm 1.1.3
  2. ; command line: z80dasm -l -s rom_strings.sym -g 0x0000 -a metric_cpu-s_mc8_v1.2_2716.bin
  3. ;##############################################################################
  4. ; METRIC 8 COMPUTER SYSTEM
  5. ; MONITOR/DEBUGGER REFERENCE MANUAL
  6. ;##############################################################################
  7. ;
  8. ; SYSTEM OVERVIEW:
  9. ; The Metric 8 is a sophisticated Z80-based computer system (circa 1980) with
  10. ; an advanced monitor/debugger ROM providing comprehensive development tools.
  11. ;
  12. ; HARDWARE SPECIFICATIONS:
  13. ; • CPU: Z80 running at 3.93216MHz (sophisticated timing), crystal at 19.6608MHz
  14. ; • ROM: 2 pcs of 2716 EPROM (2KB) containing monitor/debugger
  15. ; • RAM: 1KB base workspace + 64KB paged external memory
  16. ; • I/O: Z80 DMA controller, NEC µPD765A FDC, sophisticated peripherals
  17. ; • Memory Management: Advanced paging system with 8KB windows
  18. ;
  19. ; MONITOR COMMANDS:
  20. ; The monitor provides a '>' prompt and accepts single-letter commands
  21. ; followed by hexadecimal parameters. All addresses are 4-digit hex.
  22. ;
  23. ; MEMORY EXAMINATION COMMANDS:
  24. ; • M XXXX - Memory examine/modify starting at address XXXX (Entry: 0x04FCh)
  25. ; Shows: ADDR: YY (where YY is current byte value)
  26. ; Enter new hex value or press Enter to skip
  27. ; Press 'Q' to quit back to monitor
  28. ;
  29. ; • D XXXX - Memory dump (hex display) starting at address XXXX (Entry: 0x0358h)
  30. ; Format: XXXX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX *................*
  31. ; Shows 32 bytes total (2 lines of 16 bytes each)
  32. ; Non-printable characters shown as '.' in ASCII area
  33. ;
  34. ; • E XXXX YYYY - Enter/Edit memory data command (Entry: 0x0515h)
  35. ; Direct memory data entry starting at address XXXX
  36. ; Allows rapid entry of hex byte sequences
  37. ; YYYY parameter may specify data length or end address
  38. ; More efficient than M command for bulk data entry
  39. ;
  40. ; • C XXXX YYYY ZZZZ - Memory compare command (Entry: l0323h)
  41. ; Compares memory block [XXXX..YYYY] with block starting at ZZZZ
  42. ; Displays differences in format showing both addresses and values
  43. ; Only shows mismatched bytes, silent if blocks are identical
  44. ;
  45. ; MEMORY MODIFICATION COMMANDS:
  46. ; • F XXXX YYYY ZZ - Memory fill command (Entry: 0x03B7h)
  47. ; Fills memory from XXXX to YYYY with byte value ZZ
  48. ; Uses efficient Z80 LDIR instruction for fast block operations
  49. ;
  50. ; DEBUGGING/BREAKPOINT COMMANDS:
  51. ; • B XXXX - Set breakpoint or execution counter (Entry: 0x0313h)
  52. ; Sets debugging parameters for program execution control
  53. ; Counter stored at memory location 0x011D0
  54. ;
  55. ; • G XXXX - Go/Execute program starting from address XXXX (Entry: 0x044Ah)
  56. ; Transfers control to user program at specified address
  57. ; Restores all CPU registers and begins execution
  58. ; Supports breakpoint detection and interrupt handling
  59. ; Returns to monitor if breakpoint hit or program exits
  60. ;
  61. ; • I XXXX - Configure debug display parameters and modes (Entry: 0x03CFh)
  62. ; Sets debugging display parameters stored at 0x11D6
  63. ; Used for display width, format, or visualization options
  64. ; Special case: "II" jumps to specialized display handler
  65. ;
  66. ; • J XXXX - Jump/Execute program (alternate Go command) (Entry: 0x0441h)
  67. ; Similar functionality to G command - executes program
  68. ; Parses hex address and transfers control to user program
  69. ; Supports same breakpoint and register restoration features
  70. ;
  71. ; • L XXXX - Load Intel HEX records into memory (Entry: 0x089Fh)
  72. ; Advanced Intel HEX format loader for program/data transfer
  73. ; XXXX parameter specifies base load address (optional, defaults to 0x0000)
  74. ; Parses Intel HEX records: ":LLAAAATTDDDDDDCC" format
  75. ; LL=byte count, AAAA=address, TT=record type, DD=data, CC=checksum
  76. ; Validates checksums and loads data to calculated addresses
  77. ; Essential for loading programs from external sources or storage
  78. ; Searches for ':' record start markers and processes complete records
  79. ;
  80. ; SYSTEM DISPLAY COMMANDS:
  81. ; • R - Register display - Show CPU register contents (Entry: 0x09FFh)
  82. ; Displays all Z80 registers and system status
  83. ; Shows AF, BC, DE, HL, IX, IY, SP, PC values
  84. ;
  85. ; SEARCH AND CALCULATION COMMANDS:
  86. ; • S XXXX YYYY - Search for data pattern in memory range (Entry: 0x093Fh)
  87. ; Searches memory from XXXX to YYYY for data pattern
  88. ; Pattern specified in subsequent parameter input
  89. ; Can search for byte values or multi-byte sequences
  90. ;
  91. ; • N XXXX YYYY - Numeric calculator (arithmetic operations) (Entry: 0x049Fh)
  92. ; Performs calculations on hex values XXXX and YYYY
  93. ; Shows results of add, subtract, multiply operations
  94. ; Essential for address calculations and data manipulation
  95. ;
  96. ; • H XXXX YYYY - Hex arithmetic calculator (Entry: 0x0887h)
  97. ; Performs hex addition and subtraction on values XXXX and YYYY
  98. ; Displays both sum (XXXX + YYYY) and difference (XXXX - YYYY)
  99. ; Essential for address calculations and memory arithmetic
  100. ; Shows results in 4-digit hexadecimal format
  101. ;
  102. ; • T - Terminal/System control command (Entry: 0x064Fh)
  103. ; Terminal configuration or system test command
  104. ; May include hardware timing tests or peripheral checks
  105. ; Used for system configuration and validation
  106. ;
  107. ; PORT I/O COMMANDS:
  108. ; • O XXXX YYYY - Output/Port write operation (Entry: 0x09BCh)
  109. ; Writes data YYYY to I/O port XXXX
  110. ; Direct hardware control for peripheral programming
  111. ; Used for device configuration and control operations
  112. ; Essential for configuring SIO, CTC, DMA controllers
  113. ;
  114. ; • P XXXX YYYY - Patch/Program memory command (Entry: 0x086Fh)
  115. ; Advanced memory programming operation from XXXX to YYYY
  116. ; May include special programming modes for EPROM/EEPROM
  117. ; Could support verification and programming cycles
  118. ; Used for in-system programming of memory devices
  119. ;
  120. ; • Q XXXX - Query/Quick memory display command (Entry: 0x0BCh)
  121. ; Quick memory content query and display operation
  122. ; Shows memory content at address XXXX with formatted output
  123. ; May provide abbreviated display format for rapid inspection
  124. ; Alternative to D command for single address queries
  125. ;
  126. ; DATA TRANSFER COMMANDS:
  127. ; • U XXXX YYYY - Upload/Memory checksum utility (Entry: 0x0924h)
  128. ; Computes Intel HEX format checksums for memory range XXXX to YYYY
  129. ; Displays memory content in Intel HEX record format with checksums
  130. ; Essential for creating ROM images and data verification
  131. ; Output format: ":LLAAAATT[DD...]CC" where LL=length, AAAA=address,
  132. ; TT=type, DD=data bytes, CC=checksum. Handled by l0924h routine.
  133. ;
  134. ; • W XXXX YYYY - Write/Memory download command (Entry: 0x09FAh)
  135. ; Downloads memory contents from XXXX to YYYY in formatted output
  136. ; Creates output suitable for transfer to external systems
  137. ; May support various output formats for data export/backup
  138. ; Complementary command to U (upload) for memory management
  139. ;
  140. ; EXTENDED SYSTEM COMMANDS:
  141. ; • X - eXamine/Display all CPU registers (Entry: l040fh)
  142. ; Displays complete Z80 register set in formatted output
  143. ; Shows AF, BC, DE, HL, AF', BC', DE', HL', IX, IY, I, PC, SP
  144. ; Essential for debugging - shows complete CPU state
  145. ; Uses register name table at 0x05EB and console buffer setup
  146. ; Provides comprehensive register dump for program analysis
  147. ;
  148. ; ADDITIONAL COMMANDS:
  149. ; • Debug parameters can be configured via additional commands
  150. ; • Monitor supports commands: B,C,D,E,F,G,H,I,J,L,M,N,O,P,R,S,T,W,X
  151. ; • Use single letters followed by hex parameters as needed
  152. ; Values stored at 0x011D6 for various debugging modes
  153. ;
  154. ; SYSTEM MESSAGES:
  155. ; • "BREAK AT XXXX" - Displayed when execution breaks at address XXXX
  156. ; System returns to monitor prompt after breakpoints
  157. ;
  158. ; TECHNICAL FEATURES:
  159. ; • Sophisticated hex string parser supporting multi-parameter input
  160. ; • Intelligent input processing with space skipping and case conversion
  161. ; • Dual-purpose code/data sections for memory efficiency
  162. ; • Register state preservation and restoration
  163. ; • Interrupt mode 2 support with vector table
  164. ; • Advanced memory paging with 64KB external memory card
  165. ; • Professional error handling with graceful returns to command prompt
  166. ;
  167. ; CONTROL CHARACTERS:
  168. ; The monitor responds to standard terminal control characters for user control:
  169. ;
  170. ; • Ctrl+C (0x03 ETX) - Emergency System Reset/Break
  171. ; Immediately aborts current operation and returns to monitor
  172. ; Resets stack pointer and provides clean restart
  173. ; Similar to "break" functionality in modern terminals
  174. ; Works during any input operation or command execution
  175. ;
  176. ; • Ctrl+S (0x13 XOFF) - Pause/Resume Output Flow Control
  177. ; Temporarily pauses output display (standard XOFF)
  178. ; Press any key to resume output (XON behavior)
  179. ; Useful for stopping scrolling during long displays
  180. ; Standard terminal flow control implementation
  181. ;
  182. ; • Backspace (0x08) - Character Deletion During Input
  183. ; Deletes previous character from input buffer
  184. ; Echoes backspace-space-backspace sequence to terminal
  185. ; Provides visual feedback of character removal
  186. ; Standard line editing functionality
  187. ;
  188. ; • DEL (0x7F) - Alternative Character Deletion
  189. ; Functions identically to Backspace (0x08)
  190. ; Supports both common delete key encodings
  191. ; Maintains compatibility with different terminal types
  192. ;
  193. ; These control characters provide immediate user control over system operation
  194. ; and implement standard terminal behavior expected in professional systems.
  195. ;
  196. ; MEMORY MAP:
  197. ; • 0x0000-0x0FFF: ROM code space (4KB 2716 EPROM)
  198. ; • 0x1000-0x13FF: Base RAM workspace (1KB)
  199. ; • 0x1100: Keypress detection buffer (SIO interrupt stores received characters here)
  200. ; • 0x1101-0x1102: Character timing measurement storage (16-bit, for baud rate detection)
  201. ; • 0x1104: Console input buffer start
  202. ; • 0x1168: Input processing buffer (temporary storage)
  203. ; • 0x1169: Command input buffer (keyboard input processing)
  204. ; • 0x11F2: Console output buffer pointer
  205. ; • 0x11D0: Execution counter/breakpoint parameter
  206. ; • 0x11D6: Debug mode parameter
  207. ; • 0x1300-0x1320: Interrupt vector table (IM2 mode)
  208. ; • 0x1400: Stack pointer start (grows downward)
  209. ; • 0x2000-0x3FFF: Paged RAM window (8KB, bank-switched)
  210. ;
  211. ; SYSTEM CONFIGURATION MEMORY LOCATIONS:
  212. ; Hardware Configuration Block (0x1200-0x1227):
  213. ; • 0x1200: 16-bit DMA/buffer address pointer for disk operations
  214. ; • 0x1202: Current drive number (0-3) for multi-drive operations
  215. ; • 0x1203: Drive status/ready flags (0x01 = drive ready bit set)
  216. ; • 0x1205: 16-bit status counter A (initialized to 0xFFFF = ready state)
  217. ; • 0x1207: 16-bit status counter B (initialized to 0xFFFF = ready state)
  218. ; • 0x1209: Sector size parameter (0x24 = 36 decimal bytes per sector)
  219. ; • 0x120A: I/O port configuration byte (0xF0 = upper nibble port settings)
  220. ; • 0x120B: Drive count/operation mode (0x03 = 3 drives or operational mode 3)
  221. ; • 0x120C: Additional FDC configuration and status data
  222. ;
  223. ; FDC Command Parameter Block (0x1213-0x1215):
  224. ; • 0x1213: NEC µPD765A command byte (0x03 = READ DATA command)
  225. ; • 0x1214: Drive/Head selection and DMA control (combined from 0x120B + 0x120A)
  226. ; • 0x1215: Track/Sector/Size parameters (combined from 0x1209 + 0x1204)
  227. ;
  228. ; FDC Drive Control Block (0x1225-0x1227):
  229. ; • 0x1225: Drive parameter/selector register
  230. ; • 0x1226: Drive control flags and status
  231. ; • 0x1227: Drive enable/operation status (1=enabled, 0=disabled)
  232. ;
  233. ; Buffer Management Block (0x1244-0x1248):
  234. ; • 0x1244: 16-bit buffer pointer (low bank) - cleared to 0x0000 at startup
  235. ; • 0x1246: 16-bit buffer pointer (mid bank) - cleared to 0x0000 at startup
  236. ; • 0x1248: 16-bit buffer pointer (high bank) - cleared to 0x0000 at startup
  237. ;
  238. ; FDC Operation Status Block (0x124A-0x124B):
  239. ; • 0x124A: FDC operation completion status flag (0=pending, non-zero=completed)
  240. ; • 0x124B: Additional FDC status and control parameters
  241. ;
  242. ; Hardware Interface Configuration:
  243. ; • 0x1242: SIO serial port configuration pointer (points to table at 0x0507)
  244. ; • 0x1243: Serial port base address configuration byte (used by I/O routines)
  245. ;
  246. ; Monitor/Debugger Variables:
  247. ; • 0x011CF: Saved byte backup (breakpoint restoration storage)
  248. ; • 0x011D0: Breakpoint/execution counter for debugging
  249. ; • 0x011D1: Active breakpoint memory location (current breakpoint address)
  250. ; • 0x011D3: Original byte backup (saved from breakpoint location for restoration)
  251. ; • 0x011D4: Debug parameters and execution status storage
  252. ; • 0x011D6: Debug display parameters and mode settings
  253. ; • 0x011D7: Interrupt vector high byte for IM2 mode
  254. ; • 0x011D8: Complete register save area (AF,BC,DE,HL,IX,IY,SP) for user program execution
  255. ; • 0x011EA: Program execution start address (G/J commands)
  256. ; • 0x011EC: User stack pointer backup storage
  257. ; • 0x011EE: Saved debug parameters (temporary storage during execution)
  258. ; • 0x011F0: Current breakpoint address
  259. ; • 0x011F2: Console input/output buffer pointer (0x1104 default)
  260. ; • 0x011F4: Input buffer current position pointer
  261. ; • 0x011F6: Current prompt character (0x2A='*', 0x3E='>', 0x20=' ')
  262. ;
  263. ; Memory Paging System Variables:
  264. ; • 0x1326: Breakpoint address backup (for memory paging operations)
  265. ;
  266. ; HARDWARE I/O PORTS:
  267. ; • Port 0xF0: Floppy Disk Controller (FDC) main status register
  268. ; • Port 0xF1: Floppy Disk Controller (FDC) data register
  269. ; • Port 0xF3: Z80 DMA controller command/status register
  270. ; • Port 0xFC: Z80 DMA Controller - Command/Parameter Port
  271. ; Used for programming the Z80 DMA with initialization sequences
  272. ; The hardware config table at 0x0F55 shows 19 bytes (count + 18 data bytes)
  273. ; written to this port to configure DMA operations
  274. ; Values 0x83/0xC3 are DMA command codes for control operations
  275. ;
  276. ; This monitor/debugger represents advanced 1980s software engineering with
  277. ; modular design, efficient algorithms, and professional user interface.
  278. ;
  279. ;##############################################################################
  280. ;Memory architecture:
  281. ;• 0x0000-0x0FFF: ROM code space (4KB 2716 EPROM)
  282. ;• 0x1000-0x13FF: Base RAM workspace (1KB)
  283. ;• 0x1242 SIO port config 0x0507
  284. ;• 0x1300-0x1320: Interrupt vector table (IM2 mode) from 0x024f
  285. ;• 0x1400: Stack pointer start (grows downward toward RAM)
  286. ;• 0x2000-0x3FFF: Paged RAM window (8KB, bank-switched)
  287. ;• Extended RAM: 8x 4164 chips = 8 pages × 8KB = 64KB total
  288. ;• Page switching: Hardware register selects active 8KB bank
  289. ;• Effective memory: 1KB base + 8KB paged window + ROM
  290. ;==============================================================================
  291. ; MEMORY PAGING SYSTEM DOCUMENTATION
  292. ;==============================================================================
  293. ; The Metric 8 system implements a sophisticated memory paging mechanism to
  294. ; access a 64KB external memory card through an 8KB window at 0x2000-0x3FFF.
  295. ;
  296. ; CLEVER PORT SHARING STRATEGY:
  297. ; The system exploits the fact that ROM code only uses CTC Channels 1 and 2,
  298. ; leaving Channels 0 and 3 unused. Memory paging "hijacks" these unused ports
  299. ; without conflicting with essential CTC timing functions.
  300. ;
  301. ; PORT ALLOCATION STRATEGY:
  302. ; • PORT 0x000 (CTC Channel 0): UNUSED by ROM → Available for memory control
  303. ; • PORT 0x001 (CTC Channel 1): Used by ROM for timing functions
  304. ; • PORT 0x002 (CTC Channel 2): Used by ROM for SIO baud rate generation
  305. ; • PORT 0x003 (CTC Channel 3): UNUSED by ROM → Available for page selection
  306. ;
  307. ; MEMORY ARCHITECTURE:
  308. ; • Base System RAM: 1KB at 0x1000-0x13FF (always accessible)
  309. ; • Paged Memory Window: 8KB at 0x2000-0x3FFF (bank-switched via ports 0x000/0x003)
  310. ; • External Memory Card: 64KB organized as 8 pages × 8KB each
  311. ; • Total Addressable Memory: 1KB + 64KB = 65KB (plus ROM)
  312. ;
  313. ; CONTROL PORTS:
  314. ; • PORT 0x000: Memory Management Control Register (hijacks unused CTC Channel 0)
  315. ; - Bit 5 (0x20): Enable paging system
  316. ; - Controls overall memory management subsystem
  317. ;
  318. ; • PORT 0x003: Page Selection Register (hijacks unused CTC Channel 3)
  319. ; - 3-bit page number (0-7) selects which 8KB page appears at 0x2000-0x3FFF
  320. ; - Sequential writes may configure additional memory features
  321. ;
  322. ; COEXISTENCE WITH STANDARD HARDWARE:
  323. ; This design allows memory paging to work with standard SIO/CTC configuration:
  324. ; • SIO: ports 0x04-0x07 (unchanged)
  325. ; • CTC Channels 1&2: ports 0x01-0x02 (unchanged, ROM functions preserved)
  326. ; • Memory Management: ports 0x000 & 0x003 (reuse of unused CTC channels)
  327. ; • Result: 64KB memory card works with standard I/O configuration!
  328. ;
  329. ; OBSERVED PORT OPERATIONS:
  330. ; 1. out (000h),20h ; Enable memory management (bit 5 = paging enable)
  331. ; 2. out (003h),87h ; Select page 7 with setup flags (page + control bits)
  332. ; 3. out (003h),01h ; Select page 1 for actual operation
  333. ; 4. out (003h),03h ; Select page 3 (restore/cleanup page)
  334. ;==============================================================================
  335. I/O subsystem:
  336. • SIO 8440 chip for serial console (Pin 15 TxDA, Pin 17 RxDA) port 05-07
  337. • MC1488/MC1489 RS-232 drivers (require ±12V)
  338. • CTC for baud rate generation and timing port 00-04
  339. • Z80 DMA controller for high-speed floppy transfers - port 0xF3
  340. • FDC NEC µPD765A for 8-inch floppy drives (77 tracks, 26 sectors/track):
  341. - 0xF0: FDC Main Status Register (read)
  342. - 0xF1: FDC Data Register (read/write via register C)
  343. - 0xF4: FDC Data Register (direct access)
  344. - 0xF6: FDC Command/Status Register
  345. - 0xFC: Additional FDC control
  346. • I/O ports accessed via register C
  347. org 00000h
  348. l0000h:
  349. jr l000eh ;0000 ; Boot entry: jump to initialization routine
  350. jp l00fdh ;0002 ; Main system routine (post-init)
  351. jp l0dabh ;0005 ; Error/exception handler or alternate entry
  352. jp l0294h ;0008 ; Memory test or hardware check
  353. jp l0de0h ;000b ; Interrupt/Z80 DMA handler or alternate
  354. l000eh:
  355. ld sp,01400h ;000e ; Set stack pointer to top of 1K SRAM (boot RAM)
  356. ld hl,01000h ;0011 ; HL points to start of SRAM
  357. ld de,01001h ;0014 ; DE points to next byte in SRAM
  358. ld bc,003ffh ;0017 ; BC = 1023 bytes (1K - 1)
  359. ld (hl),000h ;001a ; Zero first byte of SRAM
  360. ldir ;001c ; Zero entire 1K SRAM (boot RAM clear)
  361. ld a,013h ;001e ; Load interrupt vector base (IM2 table address)
  362. l0020h:
  363. ld i,a ;0020 ; Set Z80 interrupt vector register (IM2 base)
  364. im 2 ;0022 ; Set interrupt mode 2 (for SIO, Z80 DMA, FDC)
  365. call hw_init_01ach ;0024 ; Call hardware init (Z80 DMA, SIO, FDC setup)
  366. ld hl,l0507h ;0027 ; HL = pointer to boot string or table
  367. l002ah:
  368. jr nz,l002fh ;002a Fail hw test if it find some form of other thing then sio on port 04 06
  369. l002ch:
  370. ld hl,0c3c1h ;002c This should be an alternate SIO card
  371. l002fh:
  372. ld (01242h),hl ;002f ; Save HL (alternate pointer) at 01242h for later use
  373. ld a,l ;0032 ; Load low byte of HL into A (may be used for error handling)
  374. ld hl,linterruptvector_table ;0033 ; Set HL to interrupt vector table address
  375. jr l003bh ;0036 ; Continue with boot sequence (alternate path)
  376. jp l07bch ;0038 ; Jump to CP/M loader or main OS entry if needed
  377. l003bh:
  378. ld de,01300h ;003b ; DE = destination Interruptvector addres
  379. ld bc,l0020h ;003e ; BC = length to copy (from l0020h)
  380. ldir ;0041 ; Block copy: transfer BC bytes from HL to DE
  381. ld hl,setupsio_table ;0043 ; HL = pointer to primary SIO configuration table
  382. cp 007h ;0046 ; Compare A to 7 (hardware detection/boot status)
  383. jr z,l004dh ;0048 ; If A == 7, use primary SIO card (normal case)
  384. ld hl,00214h ;004a ; If not, use secondary SIO card at high port addresses (0xC0+)
  385. l004dh:
  386. call setup_peripherals_01a1h ;004d ; Initialize peripherals (SIO)
  387. push hl ;0050 ; Save HL (pointer or error address)
  388. ld hl,01100h ;0051 ; HL = system buffer or stack
  389. sub a ;0054 ; Clear A (set to zero)
  390. ld (hl),a ;0055 ; Zero system buffer
  391. ei ;0056 Enable interrupts ; ROM code space
  392. l0057h:
  393. or (hl) ;0057 OR accumulator A with memory contents at address HL ; ROM code space,wait for keypress
  394. jr z,l0057h ;0058 Jump relative if Z to 0x0057 ; ROM code space
  395. di ;005a
  396. call sub_0149h ;005b
  397. ld a,030h ;005e //WR= error reset
  398. out (c),a ;0060
  399. jr l0069h ;0062
  400. rst 38h ;0064
  401. rst 38h ;0065
  402. jp l07b3h ;0066 ; Jump to interrupt/error handler - displays "BREAK AT " message
  403. l0069h:
  404. call sub_015dh ;0069 ; Call automatic baud rate detection and SIO configuration
  405. ld a,(01242h) ;006c
  406. cp 007h ;006f
  407. ld c,002h ;0071 ; Set C to 0x02 (standard CTC port)
  408. jr z,l0077h ;0073
  409. ld c,0c4h ;0075 ; Set C to 0xC4 (alternate CTC port)
  410. l0077h:
  411. ;==============================================================================
  412. ; ADAPTIVE CTC CHANNEL INITIALIZATION (0x0079)
  413. ;==============================================================================
  414. ; Purpose: Configure CTC channel with automatic port selection and dual-phase setup
  415. ; Entry: sub_0079h - Called during hardware initialization sequence
  416. ;
  417. ; Input Registers:
  418. ; - A: 0x47 (CTC control word for initial configuration)
  419. ; - B: 0x02 (time constant value)
  420. ; - C: CTC port address (0x02 for standard, 0xC4 for alternate hardware)
  421. ;
  422. ; CTC Control Word 0x47 Breakdown:
  423. ; - Bit 7: 0 = Interrupt enable
  424. ; - Bit 6: 1 = Counter mode (not timer mode)
  425. ; - Bit 5: 0 = Prescaler ÷16
  426. ; - Bit 4: 0 = Positive edge trigger
  427. ; - Bit 3: 1 = Time constant follows command
  428. ; - Bit 2: 1 = Software reset active
  429. ; - Bits 1-0: 11 = Control word identifier
  430. ;
  431. ; Two-Phase Operation:
  432. ; PHASE 1 (0x0079-0x007D): Send control word and time constant
  433. ; PHASE 2 (0x0087-0x008D): Send final control word (0x47) and divisor (0x02)
  434. ;
  435. ; Port Selection Logic:
  436. ; - Compares value from 0x1242 with 0x07 (SIO Channel B Control port)
  437. ; - If 0x1242 = 0x07: Uses standard mapping, C = 0x02 (CTC Channel 2)
  438. ; - If 0x1242 ≠ 0x07: Uses alternate mapping, C = 0xC4 (alternate CTC port)
  439. ;
  440. ; Hardware Compatibility:
  441. ; - Standard: SIO at 0x04-0x07, CTC at 0x00-0x03, configures CTC Channel 2
  442. ; - Alternate: Different SIO ports, CTC at 0xC0-0xC7, configures alternate CTC
  443. ;
  444. ; Time Constant 0x02:
  445. ; - Divides input clock by 2
  446. ; - Used for SIO clock generation (baud rate timing)
  447. ; - Combined with ÷16 prescaler = total division of 32
  448. ;
  449. ; Integration: Part of larger peripheral initialization sequence
  450. ; Called after SIO detection and before final hardware setup
  451. ;==============================================================================
  452. ld a,047h ;0077
  453. sub_0079h:
  454. out (c),a ;0079 Send CTC control word (0x47) to selected port
  455. out (c),b ;007b Send time constant (0x02) to CTC channel
  456. ld a,c ;007d Copy port address to A for comparison
  457. cp 0xc4 ;007f Compare with 0xC4 (alternate hardware marker)
  458. jr z,0x0085 ;0080 If alternate hardware, jump to port adjustment
  459. dec c ;0082 Standard hardware: decrement to previous channel
  460. jr 0x0087 ;0083 Continue to phase 2 initialization
  461. ; Alternate hardware port adjustment
  462. inc c ;0085 Increment port (0xC4 → 0xC5)
  463. inc c ;0086 Increment port (0xC5 → 0xC6)
  464. ; Phase 2: Final CTC configuration
  465. l0087h:
  466. ld a,047h ;0087 Reload CTC control word
  467. out (c),a ;0089 Send control word to final port
  468. ld a,002h ;008b Load final time constant/divisor
  469. out (c),a ;008d Send final configuration to CTC
  470. ;==============================================================================
  471. ; PHASE 3: COMPLETE HARDWARE INITIALIZATION AND SIO TESTING (0x008F+)
  472. ;==============================================================================
  473. ; After CTC setup, complete remaining peripheral initialization and test SIO
  474. ;==============================================================================
  475. ; Continue table-driven peripheral initialization
  476. pop hl ;008f Restore HL from stack (pointer to init table)
  477. inc hl ;0090 Advance to next table entry
  478. call setup_peripherals_01a1h ;0091 Continue table-driven peripheral setup
  479. ; Load test parameters and call diagnostic routine
  480. ld bc,058c0h ;0094 Load test parameters: B=0x58 (count), C=0xC0 (port/data)
  481. call sub_0f0ah ;0097 Call diagnostic/test routine with parameters
  482. ; SIO port preparation and buffer clearing
  483. call sub_0149h ;009a Get SIO port configuration (loads C with SIO control port)
  484. dec c ;009d Convert to SIO data port (control port - 1)
  485. in a,(c) ;009e Read SIO data port (clear any pending RX data)
  486. in a,(c) ;00a0 Read SIO data port again (ensure buffer clear)
  487. in a,(c) ;00a2 Third read to fully flush RX buffer
  488. ; Test SIO transmission capability
  489. call sub_0121h ;00a4 Send test character via SIO (verify TX works)
  490. ; Second SIO buffer clearing after transmission test
  491. dec c ;00a7 Set C back to SIO data port
  492. in a,(c) ;00a8 Read SIO data port (clear any echo/response data)
  493. in a,(c) ;00aa Read SIO data port again (ensure clean state)
  494. in a,(c) ;00ac Third read to fully flush post-transmission buffer
  495. ; Hardware initialization complete - enable interrupts and continue
  496. ei ;00ae Enable interrupts (hardware now fully operational)
  497. ; Print startup message after successful hardware initialization
  498. ld hl,l00e5h ;00af Load pointer to "Self diagnostics ..." message
  499. call l00fdh ;00b2 Print the startup message via serial port
  500. ; Run comprehensive system diagnostics
  501. call sub_0e89h ;00b5 Execute full system diagnostic suite
  502. ;==============================================================================
  503. ; SYSTEM CONFIGURATION MEMORY INITIALIZATION (0x00B8-0x00DF)
  504. ;==============================================================================
  505. ; Purpose: Initialize critical system configuration variables after diagnostics
  506. ; This section sets up default values for system operation parameters
  507. ;==============================================================================
  508. ld a,001h ;00b8 Load configuration value 0x01
  509. ld (01203h),a ;00ba Store at 0x1203: Drive/status flags (bit 0 = drive ready)
  510. ld a,024h ;00bd Load configuration value 0x24 (36 decimal)
  511. ld (01209h),a ;00bf Store at 0x1209: Sector size parameter (36 bytes/sector?)
  512. ld a,0f0h ;00c2 Load configuration value 0xF0 (240 decimal)
  513. ld (0120ah),a ;00c4 Store at 0x120A: Port/channel configuration byte
  514. ld a,003h ;00c7 Load configuration value 0x03
  515. ld (0120bh),a ;00c9 Store at 0x120B: Drive count or operation mode
  516. ld hl,l0000h ;00cc Load 16-bit value 0x0000
  517. ld (01244h),hl ;00cf Store at 0x1244: Clear 16-bit buffer/pointer (low)
  518. ld (01246h),hl ;00d2 Store at 0x1246: Clear 16-bit buffer/pointer (mid)
  519. ld (01248h),hl ;00d5 Store at 0x1248: Clear 16-bit buffer/pointer (high)
  520. dec hl ;00d8 Decrement HL to 0xFFFF
  521. ld (01205h),hl ;00d9 Store at 0x1205: Initialize 16-bit counter/status (0xFFFF)
  522. ld (01207h),hl ;00dc Store at 0x1207: Initialize 16-bit counter/status (0xFFFF)
  523. call sub_0acbh ;00df Call additional hardware setup routine
  524. jp l0294h ;00e2 Jump to main system initialization
  525. ;==============================================================================
  526. ; STARTUP MESSAGE: "Self diagnostics ..."
  527. ;==============================================================================
  528. ; Displayed after successful hardware initialization to indicate system status
  529. ;==============================================================================
  530. l00e5h:
  531. defb "Self diagnostics ..." ;00e5-00f8 Startup message text
  532. defb 0xda ;00f9 Special character (Ú or box drawing)
  533. defb 0x0d ;00fa Carriage return
  534. defb 0x0a ;00fb Line feed
  535. defb 0x00 ;00fc Null terminator
  536. ;==============================================================================
  537. ; STRING OUTPUT ROUTINES - Console Display Functions
  538. ;==============================================================================
  539. ; Two different string output routines for different output methods
  540. ;==============================================================================
  541. ;==============================================================================
  542. ; PRINT STRING ROUTINE (0x00FD) - Standard Console Output
  543. ;==============================================================================
  544. ; Purpose: Print null-terminated string to console via standard output
  545. ; Input: HL = pointer to null-terminated string
  546. ; Output: String displayed on console via sub_0127h (console output with wait)
  547. ; Operation: Loops through string characters until null terminator found
  548. ; Used by: Main system messages, prompts, and user interface text
  549. ;==============================================================================
  550. l00fdh: ; Standard Print String Routine
  551. ld a,(hl) ;00fd Load character from string
  552. and a ;00fe Test for null terminator (sets Z flag if A=0)
  553. ret z ;00ff Return if end of string reached
  554. ld c,a ;0100 Move character to C register for output
  555. call sub_0127h ;0101 Call console output with wait (transmitter ready check)
  556. inc hl ;0104 Point to next character in string
  557. jr l00fdh ;0105 Loop back for next character
  558. ;==============================================================================
  559. ; ALTERNATE PRINT STRING ROUTINE (0x0107) - Direct Serial Output
  560. ;==============================================================================
  561. ; Purpose: Print null-terminated string via direct serial output method
  562. ; Input: HL = pointer to null-terminated string
  563. ; Output: String sent via sub_0111h (direct serial output)
  564. ; Operation: Similar to standard routine but uses different output method
  565. ; Used by: Low-level system messages or when console output unavailable
  566. ;==============================================================================
  567. l0107h: ; Alternate Print String Routine
  568. ld a,(hl) ;0107 Load character from string
  569. and a ;0108 Test for null terminator (sets Z flag if A=0)
  570. ret z ;0109 Return if end of string reached
  571. ld c,a ;010a Move character to C register for output
  572. call sub_0111h ;010b Call direct serial output routine
  573. inc hl ;010e Point to next character in string
  574. jr l0107h ;010f Loop back for next character
  575. ;==============================================================================
  576. ; DIRECT SERIAL OUTPUT ROUTINE (0x0111)
  577. ;==============================================================================
  578. ; Purpose: Output character directly to serial port without full handshaking
  579. ; Input: C = character to output
  580. ; Operation: Calls sub_0121h then jumps to l012ah for immediate transmission
  581. ;==============================================================================
  582. sub_0111h: ; Direct Serial Output
  583. call sub_0121h ;0111 Set up serial port configuration
  584. jr l012ah ;0114 Jump to immediate output routine
  585. ;==============================================================================
  586. ; SERIAL INPUT WITH WAIT (0x0116)
  587. ;==============================================================================
  588. ; Purpose: Wait for and read character from serial input
  589. ; Output: C = received character
  590. ; Operation: Loops until character available, then returns it
  591. ;==============================================================================
  592. l0116h: ; Serial Input with Wait
  593. call sub_011ch ;0116 Check for input character available
  594. jr z,l0116h ;0119 Loop if no character available (Z flag set)
  595. ret ;011b Return with character in C register
  596. ;==============================================================================
  597. ; CHECK SERIAL INPUT READY (0x011C)
  598. ;==============================================================================
  599. ; Purpose: Check if serial input character is available (non-blocking)
  600. ; Output: Z flag = set if no character, clear if character available
  601. ; C = character (if available)
  602. ; Operation: Tests serial port status and reads character if present
  603. ;==============================================================================
  604. sub_011ch: ; Check Serial Input Ready
  605. call sub_0121h ;011c Set up serial port configuration
  606. jr l013dh ;011f Jump to input status check routine
  607. ;==============================================================================
  608. ; SERIAL PORT SETUP ROUTINE (0x0121)
  609. ;==============================================================================
  610. ; Purpose: Set up serial port configuration for I/O operations
  611. ; Input: C = character to be output (preserved in B register)
  612. ; Output: C = serial port address from configuration byte at 0x1243
  613. ; Operation: Saves character, loads port address, prepares for I/O
  614. ;==============================================================================
  615. sub_0121h: ; Serial Port Setup
  616. ld b,c ;0121 Save character/input parameter in B register
  617. ld a,(01243h) ;0122 Load serial port base address from config byte
  618. l0125h:
  619. ld c,a ;0125 Move port address to C register
  620. ret ;0126 Return with port address in C, character in B
  621. ;ROUTINE: Console Output with Wait (0x0127)
  622. ;--------------------------------------------
  623. ;Purpose: Outputs character and waits for transmitter ready
  624. sub_0127h:
  625. call sub_0149h ;0127 Get serial port base address
  626. l012ah:
  627. in a,(c) ;012a Read status register
  628. bit 2,a ;012c Test transmitter ready bit
  629. jr z,l012ah ;012e Wait if not ready
  630. dec c ;0130 Point to data register
  631. out (c),b ;0131 Output character
  632. ret ;0133 Return to caller
  633. l0134h:
  634. call sub_013ah ;0134 Check for input character available
  635. jr z,l0134h ;0137 Loop if no character available (Z flag set)
  636. ret ;0139 Return with character received
  637. ;==============================================================================
  638. ; CHECK SERIAL INPUT READY (0x013A) - Non-blocking Input Status Check
  639. ;==============================================================================
  640. ; Purpose: Check if serial input character is available without blocking
  641. ; Output: Z flag = set if no character, clear if character available
  642. ; C = character data (if available), A = character (7-bit masked)
  643. ; Operation: Tests serial port RX status bit, reads and processes character
  644. ;==============================================================================
  645. sub_013ah: ; Check Serial Input Ready (Non-blocking)
  646. call sub_0149h ;013a Get serial port base address in C register
  647. l013dh: ; Input status check entry point
  648. in a,(c) ;013d Read status register from serial port
  649. bit 0,a ;013f Test bit 0 (receiver ready/character available)
  650. ret z ;0141 Return with Z flag set if no character available
  651. dec c ;0142 Decrement C to point to data register (status+1=data)
  652. in a,(c) ;0143 Read character from serial port data register
  653. and 07fh ;0145 Mask to 7 bits (remove parity/high bit)
  654. sub_0147h: ; Character processing entry point
  655. ld c,a ;0147 Store character in C register for caller
  656. ret ;0148 Return with character in both A and C registers
  657. ;==============================================================================
  658. ; GET SERIAL PORT BASE ADDRESS (0x0149) - Port Configuration Setup
  659. ;==============================================================================
  660. ; Purpose: Load serial port base address from configuration and set up registers
  661. ; Input: C = current value (preserved in B)
  662. ; Output: C = serial port base address, B = saved previous C value
  663. ; Operation: Loads port address from config pointer at 0x1242
  664. ;==============================================================================
  665. sub_0149h: ; Get Serial Port Base Address
  666. ld b,c ;0149 Save current C register value in B
  667. ld a,(01242h) ;014a Load serial port configuration from memory
  668. ld c,a ;014d Set C to serial port base address
  669. ret ;014e Return with port address in C, old value in B
  670. ;==============================================================================
  671. ; ECHO/BRIDGE MODE (0x014F) - Bidirectional Serial Bridge
  672. ;==============================================================================
  673. ; Purpose: Implement echo or serial bridge functionality between ports
  674. ; Operation: Infinite loop that transfers data bidirectionally
  675. ; Used for: Terminal echo, serial port bridging, or communication testing
  676. ;==============================================================================
  677. l014fh: ; Echo/Bridge Mode Entry Point
  678. call sub_013ah ;014f Check for input character from serial port
  679. call nz,sub_0111h ;0152 If character received, output it (echo/bridge)
  680. call sub_011ch ;0155 Check for input from alternate source
  681. call nz,sub_0127h ;0158 If character received, output via console
  682. jr l014fh ;015b Loop continuously (infinite bridge mode)
  683. ;==============================================================================
  684. ; AUTOMATIC BAUD RATE CALCULATOR AND SIO CONFIGURATOR (0x015D)
  685. ;==============================================================================
  686. ; Purpose: Dynamically calculate and configure SIO baud rate based on timing measurements
  687. ; Entry: sub_015dh - Called after serial character timing measurements
  688. ;
  689. ; Input Values:
  690. ; - 0x1100: 8-bit timing measurement (character bit timing)
  691. ; - 0x1101-0x1102: 16-bit timing measurement (character/timeout count)
  692. ;
  693. ; Algorithm:
  694. ; 1. SCALING PHASE:
  695. ; - Loads 16-bit timing value from 0x1101-0x1102 into HL
  696. ; - Multiplies HL by 8 (three left shifts) to scale timing value
  697. ; - Loads 8-bit measurement from 0x1100 into A
  698. ;
  699. ; 2. MAGNITUDE DETECTION:
  700. ; - Performs arithmetic right shifts on A while incrementing HL
  701. ; - Counts significant bits to determine timing magnitude
  702. ; - Stops when carry flag set (found first '1' bit)
  703. ; - Result: BC = scaled timing value for table lookup
  704. ;
  705. ; 3. TABLE LOOKUP:
  706. ; - Searches baud rate table at l0183h (contains standard timing values)
  707. ; - Each table entry: 16-bit timing threshold + 8-bit SIO divisor value
  708. ; - Finds best matching standard baud rate for measured timing
  709. ; - Uses binary search approach with carry flag comparison
  710. ;
  711. ; 4. SIO CONFIGURATION:
  712. ; - Returns A = 0x44 (SIO WR4 register value: 1 stop bit, 16x clock)
  713. ; - Returns B = clock divisor value from table
  714. ;
  715. ; Table Format (l0183h):
  716. ; Each 3-byte entry: [Low_Threshold] [High_Threshold] [SIO_Divisor]
  717. ; - Thresholds define timing ranges for standard baud rates
  718. ; - SIO_Divisor used in WR4 register for clock generation
  719. ;
  720. ; Auto-Detection Process:
  721. ; - System measures actual bit timing from incoming serial data
  722. ; - This routine converts measurements to appropriate SIO clock settings
  723. ; - Enables automatic baud rate detection without manual configuration
  724. ;
  725. ; Applications:
  726. ; - Auto-configure terminal connections
  727. ; - Adapt to different computer baud rates automatically
  728. ; - Robust serial communication without preset requirements
  729. ;
  730. ; Returns: A = 0x44 (WR4 value), B = clock divisor, timing configured
  731. ; Notes: Sophisticated floating-point-like integer math for 1980s hardware
  732. ;==============================================================================
  733. sub_015dh: ; Automatic Baud Rate Calculator Entry Point
  734. ld hl,(01101h) ;015d Load 16-bit timing measurement from memory
  735. ld a,(01100h) ;0160 Load 8-bit character timing measurement
  736. add hl,hl ;0163 Multiply HL by 8 (scale timing value)
  737. add hl,hl ;0164 Left shift 1: HL = HL * 2
  738. add hl,hl ;0165 Left shift 2: HL = HL * 4, total = original * 8
  739. l0166h: ; Magnitude detection loop
  740. sra a ;0166 Arithmetic right shift A (find first significant bit)
  741. inc hl ;0168 Increment HL counter for each bit shift
  742. jr nc,l0166h ;0169 Continue until carry set (found first '1' bit)
  743. ld c,l ;016b Store low byte of scaled timing in C
  744. ld b,h ;016c Store high byte of scaled timing in B (BC = timing)
  745. ld hl,l0183h ;016d Point to baud rate lookup table start
  746. sub a ;0170 Clear A register (will count table entries)
  747. l0171h: ; Table search loop
  748. inc a ;0171 Increment table entry counter
  749. ld e,(hl) ;0172 Load low byte of timing threshold from table
  750. inc hl ;0173 Move to next byte in table
  751. ld d,(hl) ;0174 Load high byte of timing threshold (DE = threshold)
  752. inc hl ;0175 Move to next table entry
  753. ex de,hl ;0176 Exchange: HL = threshold, DE = table pointer
  754. and a ;0177 Clear carry flag for subtraction
  755. sbc hl,bc ;0178 Compare threshold with measured timing (HL - BC)
  756. ex de,hl ;017a Restore: HL = table pointer, DE = difference
  757. inc hl ;017b Move to divisor byte in current table entry
  758. jr c,l0171h ;017c If threshold < timing, try next table entry
  759. dec hl ;017e Back up to divisor byte of matching entry
  760. ld b,(hl) ;017f Load SIO clock divisor value into B register
  761. ld a,044h ;0180 Load SIO WR4 register value (1 stop bit, 16x clock)
  762. ret ;0182 Return with A = WR4 value, B = clock divisor
  763. ;==============================================================================
  764. ; BAUD RATE DETECTION TABLE (0x0183-0x01A0)
  765. ;==============================================================================
  766. ; Format: Each 3-byte entry contains [Low_Limit] [High_Limit] [SIO_Divisor]
  767. ; Used by automatic baud rate detection routine at sub_015dh
  768. ; Entries ordered from fastest to slowest baud rates for binary search
  769. ;==============================================================================
  770. l0183h:
  771. ; Entry 1: High speed range
  772. defb 0x10, 0x01, 0x2C ;0183-0185 ; Limits: 0x0110-0x012C, Divisor: 0x2C (44)
  773. ; Entry 2:
  774. defb 0x5C, 0x00, 0x04 ;0186-0188 ; Limits: 0x005C-0x0004, Divisor: 0x04 (4)
  775. ; Entry 3:
  776. defb 0xBC, 0x00, 0x08 ;0189-018B ; Limits: 0x00BC-0x0008, Divisor: 0x08 (8)
  777. ; Entry 4:
  778. defb 0x7C, 0x01, 0x10 ;018C-018E ; Limits: 0x017C-0x0110, Divisor: 0x10 (16)
  779. ; Entry 5:
  780. defb 0xFC, 0x02, 0x20 ;018F-0191 ; Limits: 0x02FC-0x0220, Divisor: 0x20 (32)
  781. ; Entry 6:
  782. defb 0x05, 0x40, 0x70 ;0192-0194 ; Limits: 0x4005-0x7040, Divisor: 0x70 (112)
  783. ; Entry 7:
  784. defb 0x09, 0x80, 0x70 ;0195-0197 ; Limits: 0x8009-0x7080, Divisor: 0x70 (112)
  785. ; Entry 8:
  786. defb 0x0C, 0xA0, 0xFF ;0198-019A ; Limits: 0xA00C-0xFFA0, Divisor: 0xFF (255)
  787. ; Entry 9: Low speed range
  788. defb 0xFF, 0xFF, 0x00 ;019B-019D ; Limits: 0xFFFF-0x00FF, Divisor: 0x00 (0)
  789. ; Table terminator
  790. defb 0xFF, 0xFF ;019E-019F ; End marker
  791. defb 0x00 ;01A0 ; Padding/terminator
  792. setup_peripherals_01a1h:
  793. ld a,(hl) ;01a1 ; Load count from table (A = number of bytes to output)
  794. and a ;01a2 ; Test if count is zero
  795. ret z ;01a3 ; If zero, end of table, return
  796. ld b,a ;01a4 ; Set B = count
  797. inc hl ;01a5 ; Move to next table entry
  798. ld c,(hl) ;01a6 ; Load port number from table
  799. inc hl ;01a7 ; Move to data bytes
  800. otir ;01a8 ; Output B bytes from (HL) to port C, increment HL each time
  801. jr setup_peripherals_01a1h ;01aa ; Repeat for next table entry
  802. hw_init_01ach: ;Probably check if there is a perifle that can be read and write to which is not a SIO
  803. ld hl,initsio_l01d9h ;01ac ; HL = pointer to hardware register or test value
  804. call setup_peripherals_01a1h ;01af ; Call additional hardware init routine
  805. ld c,004h ;01b2 ; Set port C = 0x04 (SIO A data port)
  806. ld a,055h ;01b4 ; Load test pattern 0x55
  807. call check_peri_01d2h ;01b6 ; Output 0x55 to port 0x04 (SIO A data port)
  808. ret nz ;01b9 ; If error, return
  809. ld a,0aah ;01ba ; Load test pattern 0xAA
  810. call check_peri_01d2h ;01bc ; Output 0xAA to port 0x04 (SIO A data port)
  811. ret nz ;01bf ; If error, return
  812. ld a,055h ;01c0 ; Load test pattern 0x55
  813. ld c,006h ;01c2 ; Set port C = 0x06 (SIO B data port)
  814. call check_peri_01d2h ;01c4 ; Output 0x55 to port 0x06
  815. and 00fh ;01c7 ; Mask lower nibble (hardware check)
  816. ret nz ;01c9 ; If error, return
  817. ld a,0aah ;01ca ; Load test pattern 0xAA
  818. call check_peri_01d2h ;01cc ; Output 0xAA to port 0x06 (SIO B data port)
  819. and 00fh ;01cf ; Mask lower nibble (hardware check)
  820. ret ;01d1 ; Return (hardware init complete)
  821. check_peri_01d2h:
  822. out (c),a ;01d2 ; Output value in A to port C
  823. ld b,a ;01d4 ; Save value in B
  824. in a,(c) ;01d5 ; Read value back from port C into A
  825. xor b ;01d7 ; Compare read value with what was written
  826. ret ;01d8 ; Return
  827. initsio_l01d9h:
  828. ; PRIMARY SIO CARD initialization table (ports 0x04-0x07)
  829. ; This is the first/preferred SIO card on the bus
  830. defb 0x02 ;01d9 ; Count: 2 bytes to output
  831. defb 0x05 ;01da ; Port: 0x05 (Primary SIO Channel A Control)
  832. defb 0xCF ;01db ; Data byte 1: WR 7, SEND ABORT (SDLC), RESET Tx UNDERRUN/EOM LATCH
  833. defb 0x00 ;01dc ; Data byte 2: SYNC BIT 8-15 = 0
  834. defb 0x02 ;01dd ; Count: 2 bytes to output
  835. defb 0x07 ;01de ; Port: 0x07 (Primary SIO Channel B Control)
  836. defb 0xCF ;01df ; Data byte 1: WR 7, SEND ABORT (SDLC), RESET Tx UNDERRUN/EOM LATCH
  837. defb 0xF0 ;01e0 ; Data byte 2: Reset channel B sync bit 12-15
  838. defb 0x00 ;01e1 ; END marker
  839. setupsio_table:
  840. l01e2h:
  841. ; CTC setup for SIO timing
  842. defb 0x02 ;01e2 ; 2 bytes to output
  843. defb 0x02 ;01e3 ; CTC Channel 2 (provides clock for SIO)
  844. defb 0x47 ;01e4 ; CTC Control: Software reset, Time constant follows, Prescaler=16, Counter mode
  845. defb 0x01 ;01e5 ; Time constant = 1 (fast clock for SIO)
  846. ; PRIMARY SIO CHANNEL B (Console/Terminal) - Complete WR Configuration
  847. defb 0x11 ;01e6 ; 17 bytes to configure Channel B
  848. defb 0x07 ;01e7 ; Port 0x07 (Primary SIO Channel B Control)
  849. ; WR0 Commands and Register Selection
  850. defb 0x58 ;01e8 ; WR0: 01011000b = Channel Reset + Reset Rx CRC Checker
  851. defb 0x02 ;01e9 ; WR0: 00000010b = Select WR2 for next write
  852. defb 0x00 ;01ea ; WR2: Interrupt vector = 0x00 (disable interrupts)
  853. defb 0x04 ;01eb ; WR0: 00000100b = Select WR4 for next write
  854. defb 0x10 ;01ec ; WR4: 00010000b = 16x clock, No parity, 1 stop bit, No sync
  855. defb 0x15 ;01ed ; WR0: 00010101b = Select WR5 + Send Abort (SDLC mode prep)
  856. defb 0x84 ;01ee ; WR5: 10000100b = DTR active, 8 bits/char, Tx disabled initially, No RTS yet
  857. defb 0x03 ;01ef ; WR0: 00000011b = Select WR3 + Reset External Status interrupts
  858. defb 0xd2 ;01f0 ; WR3: 11010010b = Rx 8 bits, Enter Hunt Phase, Sync Char Load Inhibit, Rx disabled initially
  859. defb 0x06 ;01f1 ; WR0: 00000110b = Select WR6 for next write
  860. defb 0xff ;01f2 ; WR6: Sync Character bits 0-7 = 0xFF (sync pattern low byte)
  861. defb 0x07 ;01f3 ; WR0: 00000111b = Select WR7 for next write
  862. defb 0x0f ;01f4 ; WR7: Sync Character bits 8-15 = 0x0F (sync pattern high byte)
  863. defb 0x11 ;01f5 ; WR0: 00010001b = Select WR1 + Reset External Status interrupts
  864. defb 0x0c ;01f6 ; WR1: 00001100b = Status affects vector, Rx INT on first char or special condition
  865. defb 0x23 ;01f7 ; WR0: 00100011b = Select WR3 + Enable INT on next Rx char
  866. defb 0xd3 ;01f8 ; WR3: 11010011b = Rx Enable, 8 bits, Enter Hunt Phase, Sync Char Load Inhibit
  867. defb 0x00 ;01f9 ; END marker
  868. l01fa:
  869. ; PRIMARY SIO CHANNEL B (Console) - Simplified Setup for Normal Operation
  870. defb 0x0c ;01fa ; 12 bytes to configure Channel B for basic async operation
  871. defb 0x07 ;01fb ; Port 0x07 (Primary SIO Channel B Control)
  872. defb 0x18 ;01fc ; WR0: 00011000b = Channel Reset (clear all state)
  873. defb 0x02 ;01fd ; WR0: 00000010b = Select WR2 for next write
  874. defb 0x00 ;01fe ; WR2: Interrupt vector = 0x00 (no interrupts)
  875. defb 0x18 ;01ff ; WR0: 00011000b = Channel Reset (ensure clean state)
  876. defb 0x01 ;0200 ; WR0: 00000001b = Select WR1 for next write
  877. defb 0x04 ;0201 ; WR1: 00000100b = Status affects interrupt vector
  878. defb 0x04 ;0202 ; WR0: 00000100b = Select WR4 for next write
  879. defb 0x44 ;0203 ; WR4: 01000100b = 16x clock, 1 stop bit, No parity, 8 bits
  880. defb 0x03 ;0204 ; WR0: 00000011b = Select WR3 + Reset External Status
  881. defb 0xc1 ;0205 ; WR3: 11000001b = Rx Enable, 8 bits/char, No auto enables
  882. defb 0x05 ;0206 ; WR0: 00000101b = Select WR5
  883. defb 0xea ;0207 ; WR5: 11101010b = RTS, DTR, Tx Enable, 8 bits/char, Break
  884. ; PRIMARY SIO CHANNEL A (Auxiliary/Data) - Basic Setup
  885. defb 0x09 ;0208 ; 9 bytes to configure Channel A
  886. defb 0x05 ;0209 ; Port 0x05 (Primary SIO Channel A Control)
  887. defb 0x18 ;020a ; WR0: 00011000b = Channel Reset
  888. defb 0x01 ;020b ; WR0: 00000001b = Select WR1 for next write
  889. defb 0x00 ;020c ; WR1: 00000000b = No interrupts, no status affects vector
  890. defb 0x04 ;020d ; WR0: 00000100b = Select WR4 for next write
  891. defb 0x44 ;020e ; WR4: 01000100b = 16x clock, 1 stop bit, No parity, 8 bits
  892. defb 0x03 ;020f ; WR0: 00000011b = Select WR3 + Reset External Status
  893. defb 0xc1 ;0210 ; WR3: 11000001b = Rx Enable, 8 bits/char
  894. defb 0x05 ;0211 ; WR0: 00000101b = Select WR5
  895. defb 0xea ;0212 ; WR5: 11101010b = RTS, DTR, Tx Enable, 8 bits/char, Break
  896. defb 0x00 ;0213 ; END marker
  897. l0214h:
  898. ; SECONDARY SIO CARD initialization table (ports 0xC0-0xC4)
  899. ; This is an alternate SIO card on the bus, used if primary SIO fails
  900. defb 0x02 ;0214 ; 2 bytes to output
  901. defb 0x02 ;0215 ; CTC channel (shared timing for secondary SIO)
  902. defb 0x47 ;0216 ; CTC Control: SW reset, Time constant follows, Prescaler=16, Counter mode
  903. defb 0x04 ;0217 ; Time constant = 4 (different timing from primary)
  904. defb 0x02 ;0218 ; 2 bytes to output
  905. defb 0xc4 ;0219 ; Port 0xC4 (Secondary SIO Channel A Control - high address mapping)
  906. defb 0x47 ;021a ; Command: 01000111b = Select WR4 + Software reset + Time constant
  907. defb 0x01 ;021b ; Parameter value
  908. ; SECONDARY SIO CHANNEL B (Console backup) - Initial Setup
  909. defb 0x05 ;021c ; 5 bytes to output
  910. defb 0xc3 ;021d ; Port 0xC3 (Secondary SIO Channel B Control - high address mapping)
  911. defb 0x58 ;021e ; WR0: 01011000b = Channel Reset + Reset Rx CRC Checker
  912. defb 0x02 ;021f ; WR0: 00000010b = Select WR2 for next write
  913. defb 0x10 ;0220 ; WR2: Interrupt vector = 0x10 (different from primary)
  914. defb 0x01 ;0221 ; WR0: 00000001b = Select WR1 for next write
  915. defb 0x04 ;0222 ; WR1: 00000100b = Status affects interrupt vector
  916. ; SECONDARY SIO CHANNEL A (Data backup) - Complete Configuration
  917. defb 0x0f ;0223 ; 15 bytes to output (extensive SIO configuration)
  918. defb 0xc1 ;0224 ; Port 0xC1 (Secondary SIO Channel A Control - high address mapping)
  919. defb 0x58 ;0225 ; WR0: 01011000b = Channel Reset + Reset Rx CRC Checker
  920. defb 0x04 ;0226 ; WR0: 00000100b = Select WR4 for next write
  921. defb 0x10 ;0227 ; WR4: 00010000b = 16x clock, No parity, 1 stop bit
  922. defb 0x15 ;0228 ; WR0: 00010101b = Select WR5 + Send Abort (SDLC prep)
  923. defb 0x84 ;0229 ; WR5: 10000100b = DTR active, 8 bits/char, Tx disabled initially
  924. defb 0x03 ;022a ; WR0: 00000011b = Select WR3 + Reset External Status
  925. defb 0xd2 ;022b ; WR3: 11010010b = Rx 8 bits, Enter Hunt Phase, Sync Char Load Inhibit
  926. defb 0x06 ;022c ; WR0: 00000110b = Select WR6 for next write
  927. defb 0xFF ;022d ; WR6: Sync Character bits 0-7 = 0xFF
  928. defb 0x07 ;022e ; WR0: 00000111b = Select WR7 for next write
  929. defb 0x0f ;022f ; WR7: Sync Character bits 8-15 = 0x0F
  930. defb 0x11 ;0230 ; WR0: 00010001b = Select WR1 + Reset External Status
  931. defb 0x0c ;0231 ; WR1: 00001100b = Status affects vector, Rx INT on first char
  932. defb 0x23 ;0232 ; WR0: 00100011b = Select WR3 + Enable INT on next Rx char
  933. defb 0xd3 ;0233 ; WR3: 11010011b = Rx Enable, 8 bits, Enter Hunt Phase
  934. defb 0x00 ;0234 ; END marker
  935. l0235h:
  936. ; SECONDARY SIO - Final Configuration for Normal Operation
  937. ; Simplified setup for basic async operation on backup SIO card
  938. defb 0x0c ;0235 ; 12 bytes to output
  939. defb 0xc3 ;0236 ; Port 0xC3 (Secondary SIO Channel B Control)
  940. defb 0x18 ;0237 ; WR0: 00011000b = Channel Reset (clear all state)
  941. defb 0x02 ;0238 ; WR0: 00000010b = Select WR2 for next write
  942. defb 0x10 ;0239 ; WR2: Interrupt vector = 0x10 (secondary interrupt vector)
  943. defb 0x18 ;023a ; WR0: 00011000b = Channel Reset (ensure clean state)
  944. defb 0x01 ;023b ; WR0: 00000001b = Select WR1 for next write
  945. defb 0x04 ;023c ; WR1: 00000100b = Status affects interrupt vector
  946. defb 0x04 ;023d ; WR0: 00000100b = Select WR4 for next write
  947. defb 0x44 ;023e ; WR4: 01000100b = 16x clock, 1 stop bit, No parity, 8 bits
  948. defb 0x03 ;023f ; WR0: 00000011b = Select WR3 + Reset External Status
  949. defb 0xc1 ;0240 ; WR3: 11000001b = Rx Enable, 8 bits/char, No auto enables
  950. defb 0x05 ;0241 ; WR0: 00000101b = Select WR5
  951. defb 0xea ;0242 ; WR5: 11101010b = RTS, DTR, Tx Enable, 8 bits/char, Break
  952. ; SECONDARY SIO CHANNEL A - Basic Setup
  953. defb 0x09 ;0243 ; 9 bytes to output
  954. defb 0xc1 ;0244 ; Port 0xC1 (Secondary SIO Channel A Control)
  955. defb 0x18 ;0245 ; WR0: 00011000b = Channel Reset
  956. defb 0x01 ;0246 ; WR0: 00000001b = Select WR1 for next write
  957. defb 0x00 ;0247 ; WR1: 00000000b = No interrupts, no status affects vector
  958. defb 0x04 ;0248 ; WR0: 00000100b = Select WR4 for next write
  959. defb 0x44 ;0249 ; WR4: 01000100b = 16x clock, 1 stop bit, No parity, 8 bits
  960. defb 0x03 ;024a ; WR0: 00000011b = Select WR3 + Reset External Status
  961. defb 0xc1 ;024b ; WR3: 11000001b = Rx Enable, 8 bits/char
  962. defb 0x05 ;024c ; WR0: 00000101b = Select WR5
  963. defb 0xea ;024d ; WR5: 11101010b = RTS, DTR, Tx Enable, 8 bits/char, Break
  964. defb 0x00 ;024e ; END marker
  965. ;==============================================================================
  966. ; INTERRUPT VECTOR TABLE FOR SIO OPERATIONS
  967. ;==============================================================================
  968. ; These vectors are loaded into RAM at 0x1300+ for interrupt mode 2 operation
  969. ; Provides specific handlers for different SIO interrupt conditions
  970. ;==============================================================================
  971. defb 0x91 ;024f ; Interrupt vector base (0x1300)
  972. defb 0x02 ;0250 ; Interrupt linterupt2vector 0x1301
  973. defb 0x92 ;0251 ; Interrupt vector 0x1302
  974. defb 0x02 ;0252 ; Interrupt linterupt2vector 0x1303
  975. defb 0x6f ;0253 ; Interrupt vector 0x1304
  976. defb 0x02 ;0254 ; Interrupt linterupt1vector 0x1305
  977. defb 0x91 ;0255 ; Interrupt vector 0x1306
  978. defb 0x02 ;0256 ; Interrupt linterupt2vector 0x1307
  979. defb 0x91 ;0257 ; Interrupt vector 0x1308
  980. defb 0x02 ;0258 ; Interrupt linterupt2vector 0x1309
  981. defb 0x91 ;0259 ; Interrupt vector 0x130a
  982. defb 0x02 ;025a ; Interrupt linterupt2vector 0x130b
  983. defb 0x91 ;025b ; Interrupt vector 0x130c
  984. defb 0x02 ;025c ; Interrupt linterupt2vector 0x130d
  985. defb 0x91 ;025d ; Interrupt vector 0x130e
  986. defb 0x02 ;025e ; Interrupt linterupt2vector 0x130f
  987. defb 0x91 ;025f ; Interrupt vector 0x1310
  988. defb 0x02 ;0260 ; Interrupt linterupt2vector 0x1311
  989. defb 0x91 ;0261 ; Interrupt vector 0x1312
  990. defb 0x02 ;0262 ; Interrupt linterupt2vector 0x1313
  991. defb 0x91 ;0263 ; Interrupt vector 0x1314
  992. defb 0x02 ;0264 ; Interrupt linterupt2vector 0x1315
  993. defb 0x91 ;0265 ; Interrupt vector 0x1316
  994. defb 0x02 ;0266 ; Interrupt linterupt2vector 0x1317
  995. defb 0x91 ;0267 ; Interrupt vector 0x1318
  996. defb 0x02 ;0268 ; Interrupt linterupt2vector 0x1319
  997. defb 0x91 ;0269 ; Interrupt vector 0x1320
  998. defb 0x02 ;026A ; Interrupt linterupt2vector 0x1321
  999. defb 0x6f ;026B ; Interrupt vector 0x1322
  1000. defb 0x02 ;026C ; Interrupt linterupt1vector 0x1323
  1001. defb 0x91 ;026D ; Interrupt vector 0x1324
  1002. defb 0x02 ;026E ; Interrupt linterupt2vector 0x1325
  1003. linterupt1:
  1004. push af ;026f ; Save accumulator and flags
  1005. push bc ;0270 ; Save BC register pair
  1006. call sub_0149h ;0271 ; Setup: loads serial port address into C (from 0x1242), C=command/status port
  1007. push hl ;0274 ; Save HL register pair
  1008. ld hl,l0000h ;0275 ; HL = 0 (used as a counter for timeout/retries)
  1009. l0278h:
  1010. dec c ;0278 ; C = C - 1 (now C=data port)
  1011. in a,(c) ;0279 ; Read data register from port C
  1012. or a ;027b ; Set flags based on A (is data nonzero?)
  1013. jr nz,l0288h ;027c ; If data != 0, jump to l0288h (data ready)
  1014. inc hl ;027e ; HL = HL + 1 (increment timeout/retry counter)
  1015. inc c ;027f ; C = C + 1 (restore C to command/status port,)
  1016. l0280h:
  1017. in a,(c) ;0280 ; Read command/status register from port C,
  1018. bit 0,a ;0282 ; Test bit 0 (is data available/ready) Rx CHARACTER AVAILABLE
  1019. jr nz,l0278h ;0284 ; If bit 0 set, go back to data port read
  1020. jr l0280h ;0286 ; Otherwise, keep polling command/status port
  1021. l0288h:
  1022. ld (01100h),a ;0288 ; Store received byte in 0x1100
  1023. ld (01101h),hl ;028b ; Store HL (timeout/retry count) in 0x1101/0x1102
  1024. pop hl ;028e ; Restore HL (was used as counter)
  1025. pop bc ;028f ; Restore BC
  1026. pop af ;0290 ; Restore AF
  1027. linterupt2:
  1028. ei ;0291 ; Enable interrupts
  1029. reti ;0292 ; Return from interrupt
  1030. ; --------------------------------------------------
  1031. ; 0x0294: System Initialization Block
  1032. ; - Sets stack pointer to 0x1400
  1033. ; - Loads interrupt vector (A=0x13), sets I register
  1034. ; - Sets interrupt mode 2 and enables interrupts
  1035. ; - Calls sub_0770h to save CPU context and further setup
  1036. ; --------------------------------------------------
  1037. l0294h:
  1038. ld sp,01400h ;0294
  1039. ld a,013h ;0297
  1040. ld i,a ;0299
  1041. im 2 ;029b
  1042. ei ;029d
  1043. call sub_0770h ;029e
  1044. ; --------------------------------------------------
  1045. ; After 0x029e: Continued System/Memory Initialization
  1046. ; - Sets HL to 01100h, stores at 011ech
  1047. ; - Sets HL to l0000h, stores at 011f0h
  1048. ; - Sets HL to l0fech, calls l00fdh (setup/copy routine)
  1049. ; - Sets HL to 01104h, stores at 011f2h
  1050. ; - Loads A with 0x2A, stores at 011f6h
  1051. ; - Calls sub_080dh (setup/test routine)
  1052. ; - Branches: if NZ, jumps to l02c9h; else, jumps to l0fbbh
  1053. ; Purpose: Finalizes pointers, memory, and hardware setup, then tests/branches on result
  1054. ; --------------------------------------------------
  1055. ld hl,01100h ;02a1
  1056. ld (011ech),hl ;02a4
  1057. ld hl,l0000h ;02a7
  1058. ld (011f0h),hl ;02aa
  1059. ld hl,l0fech ;02ad Load HL with address of version string ("Ver 1.2x 8 inch")
  1060. call l00fdh ;02b0 Print version string to console via standard output routine
  1061. ld hl,01104h ;02b3 Set HL to console buffer address (0x1104)
  1062. ld (011f2h),hl ;02b6 Store console buffer pointer at 0x011F2
  1063. ld a,02ah ;02b9
  1064. ld (011f6h),a ;02bb
  1065. call sub_080dh ;02be
  1066. jr nz,l02c9h ;02c1
  1067. jp l0fbbh ;02c3
  1068. l02c6h:
  1069. call sub_080dh ;02c6 Get user input from console
  1070. l02c9h:
  1071. call sub_02e4h ;02c9 Execute parsed command (dual-purpose code)
  1072. ; =============================================================================
  1073. ; MAIN MONITOR COMMAND LOOP - Heart of the Debug System
  1074. ; =============================================================================
  1075. ; Purpose: Main command prompt and processing loop for the monitor/debugger
  1076. ; Operation: Sets up input buffer, displays '>' prompt, processes commands
  1077. ; Flow: All monitor commands (dump, compare, breakpoint, etc.) return here
  1078. ; This is the central control point of the entire monitor system
  1079. ; =============================================================================
  1080. l02cch: ; Main Monitor Command Loop Entry Point
  1081. ld hl,01104h ;02cc Point to console input buffer start
  1082. ld (011f2h),hl ;02cf Store input buffer pointer for system use
  1083. ld a,03eh ;02d2 Load '>' character (0x3E = ASCII prompt)
  1084. ld (011f6h),a ;02d4 Store prompt character for display
  1085. jr l02c6h ;02d7 Jump to input processing (creates command loop)
  1086. l02d9h:
  1087. ld sp,01400h ;02d9
  1088. ld hl,l0323h ;02dc
  1089. call l00fdh ;02df
  1090. jr l02cch ;02e2
  1091. ;==============================================================================
  1092. ; DUAL-PURPOSE CODE/DATA TABLE (0x02E4-0x0322)
  1093. ;==============================================================================
  1094. ; This section serves as BOTH executable code AND data table!
  1095. ;
  1096. ; AS EXECUTABLE CODE (when called from 0x02C9):
  1097. ; - 0x02E4: CD 4C 06 call sub_064ch
  1098. ; - 0x02E7: 13 inc de
  1099. ; - 0x02E8: 42 ld b,d
  1100. ; - 0x02E9: E2 03 43 jp po,4303h
  1101. ; - etc.
  1102. ;
  1103. ; AS DATA TABLE (when accessed as bytes):
  1104. ; Contains ASCII character sequence B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,W,X
  1105. ; This appears to be a character encoding or command lookup table
  1106. ;
  1107. ; This technique was common in 1980s ROMs to save precious memory space
  1108. ; by making code serve dual purposes as both instructions and data
  1109. ;==============================================================================
  1110. sub_02e4h: ; Entry point when called as subroutine
  1111. call sub_064ch ;02e4 CD 4C 06
  1112. inc de ;02e7 13
  1113. ld b,d ;02e8 42 (ASCII 'B')
  1114. jp po,04303h ;02e9 E2 03 43 (0x43 = ASCII 'C')
  1115. inc hl ;02ec 23
  1116. inc bc ;02ed 03
  1117. ld b,h ;02ee 44 (ASCII 'D')
  1118. ld e,b ;02ef 58
  1119. inc bc ;02f0 03
  1120. ld b,l ;02f1 45 (ASCII 'E')
  1121. dec d ;02f2 15
  1122. dec b ;02f3 05
  1123. ld b,(hl) ;02f4 46 (ASCII 'F')
  1124. or a ;02f5 B7
  1125. inc bc ;02f6 03
  1126. ld b,a ;02f7 47 (ASCII 'G')
  1127. ld c,d ;02f8 4A (ASCII 'J')
  1128. inc b ;02f9 04
  1129. ld c,b ;02fa 48 (ASCII 'H')
  1130. add a,a ;02fb 87
  1131. ex af,af' ;02fc 08
  1132. ld c,c ;02fd 49 (ASCII 'I')
  1133. rst 8 ;02fe CF
  1134. inc bc ;02ff 03
  1135. ld c,d ;0300 4A (ASCII 'J')
  1136. ld b,c ;0301 41
  1137. inc b ;0302 04
  1138. ld c,h ;0303 4C (ASCII 'L')
  1139. sbc a,a ;0304 9F
  1140. ex af,af' ;0305 08
  1141. ld c,l ;0306 4D (ASCII 'M')
  1142. call p,04e04h ;0307 FC 04 4E
  1143. sbc a,a ;030a 9F
  1144. inc b ;030b 04
  1145. ld c,a ;030c 4F (ASCII 'O')
  1146. cp h ;030d BC
  1147. add hl,bc ;030e 09
  1148. ld d,b ;030f 50 (ASCII 'P')
  1149. ld l,a ;0310 6F
  1150. ex af,af' ;0311 08
  1151. ld d,d ;0312 52 (ASCII 'R')
  1152. rst 38h ;0313 FF
  1153. add hl,bc ;0314 09
  1154. ld d,e ;0315 53 (ASCII 'S')
  1155. ccf ;0316 3F
  1156. ld b,054h ;0317 06 54 (0x54 = ASCII 'T')
  1157. ld c,a ;0319 4F
  1158. ld bc,0fa57h ;031a 01 57 FA (0x57 = ASCII 'W')
  1159. add hl,bc ;031d 09
  1160. ld e,b ;031e 58 (ASCII 'X')
  1161. rrca ;031f 0F
  1162. inc b ;0320 04
  1163. ccf ;0321 3F (ASCII '?')
  1164. nop ;0322 00 (NULL terminator)
  1165. ; =============================================================================
  1166. ; MEMORY COMPARE COMMAND (C command) - Monitor/Debugger Function
  1167. ; =============================================================================
  1168. ; Purpose: Compare two memory regions and display any differences
  1169. ; Input: User enters hex addresses via console (C start1 end1 start2)
  1170. ; Example: "C 1000 10FF 2000" compares memory 1000-10FF with 2000-20FF
  1171. ; Operation: Compares memory at [start1..end1] with memory starting at start2
  1172. ; Output: Shows mismatched bytes with both addresses and different values
  1173. ; Silent operation if regions are identical (no output = blocks match)
  1174. ; Error handling: Returns to monitor prompt on invalid input or completion
  1175. ; Used by: Monitor command interpreter for memory debugging and verification
  1176. ; =============================================================================
  1177. l0323h: ; Memory Compare Command Entry Point
  1178. call sub_0760h ;0323 Parse 3 hex addresses from user input (start1, end1, start2)
  1179. jp z,l02d9h ;0326 Jump to error handler if hex parsing failed
  1180. ex de,hl ;0329 DE=start1, HL=start2 (swap for comparison loop setup)
  1181. l032ah: ; Main Memory Comparison Loop
  1182. call sub_09a3h ;032a Check for keyboard input (allows user to abort with any key)
  1183. ld a,(de) ;032d Load byte from first memory region (source)
  1184. cp (hl) ;032e Compare with byte from second memory region (destination)
  1185. call nz,sub_0338h ;032f If bytes differ, display the mismatch details
  1186. inc de ;0332 Move to next byte in first region (source++)
  1187. cpi ;0333 CP (HL), INC HL, DEC BC - auto-increment second region
  1188. ret po ;0335 Return when BC=0 (all bytes compared, PO=parity odd/BC=0)
  1189. jr l032ah ;0336 Continue comparison loop until all bytes checked
  1190. ; =============================================================================
  1191. ; MEMORY MISMATCH DISPLAY HANDLER
  1192. ; =============================================================================
  1193. ; Purpose: Display details when memory comparison finds a difference
  1194. ; Input: DE=address in first region, HL=address in second region, A=(DE), (HL) differ
  1195. ; Output: Displays both addresses and their differing byte values
  1196. ; Format: Shows both addresses with their different values for user analysis
  1197. ; Example output might be: "1000: 42 2000: 24" (showing the mismatch)
  1198. ; =============================================================================
  1199. sub_0338h: ; Memory Mismatch Display Handler
  1200. push de ;0338 Save first region address on stack
  1201. call sub_0346h ;0339 Display first address and its byte value (format: "ADDR: XX")
  1202. ex (sp),hl ;033c Swap: HL=first addr (from stack), stack=second addr
  1203. call sub_0346h ;033d Display second address and its byte value (format: "ADDR: YY")
  1204. call sub_072ah ;0340 Output formatting/newline routine (complete the line)
  1205. ex de,hl ;0343 Restore proper register order (DE=first, HL=second)
  1206. pop hl ;0344 Restore second region address from stack
  1207. ret ;0345 Return to comparison loop
  1208. ; =============================================================================
  1209. ; ADDRESS AND BYTE VALUE DISPLAY ROUTINE
  1210. ; =============================================================================
  1211. ; Purpose: Display an address followed by the byte value at that address
  1212. ; Input: HL=memory address to display
  1213. ; Output: Shows "ADDR: XX" format to console
  1214. ; Used by: Memory compare, memory dump, and other debugging commands
  1215. ; =============================================================================
  1216. sub_0346h: ; Display Address and Byte Value
  1217. push hl ;0346 Save address
  1218. ld a,(hl) ;0347 Load byte value from address
  1219. push af ;0348 Save the byte value
  1220. call sub_06b8h ;0349 Display the address (HL) in hex
  1221. ld hl,(011f2h) ;034c Get console output buffer pointer
  1222. dec hl ;034f Back up one position
  1223. ld (hl),03dh ;0350 Insert '=' character (0x3D = ASCII '=')
  1224. pop af ;0352 Restore byte value
  1225. call sub_06c6h ;0353 Display byte value in hex
  1226. pop hl ;0356 Restore address
  1227. ret ;0357 Return
  1228. call sub_0763h ;0358
  1229. jr z,l03a0h ;035b
  1230. exx ;035d
  1231. ; =============================================================================
  1232. ; MEMORY DUMP/HEX DISPLAY COMMAND - 32 Bytes per Screen
  1233. ; =============================================================================
  1234. ; Purpose: Display memory contents in hex dump format (D command)
  1235. ; Input: Starting address in HL' (alternate register set)
  1236. ; Output format: XXXX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX *................*
  1237. ; Where: XXXX = 4-digit hex address, XX = hex bytes, * = ASCII representation
  1238. ; Block size: 16 bytes per line, 2 lines = 32 bytes total per screen
  1239. ; User can press any key to abort display and return to monitor
  1240. ; =============================================================================
  1241. l035eh: ; Memory Dump Command Entry Point
  1242. call sub_09a3h ;035e Check for keyboard input/break (allows user abort)
  1243. ld hl,01104h ;0361 Point to display buffer start (console buffer workspace)
  1244. ld de,01105h ;0364 Point to buffer start + 1 (for block fill operation)
  1245. ld bc,00049h ;0367 Set count = 73 bytes to clear (full display line + margin)
  1246. ld (hl),020h ;036a Put space character (0x20) in first position of buffer
  1247. ldir ;036c Fill entire buffer with spaces (clear display workspace)
  1248. ld b,010h ;036e Set counter for 16 bytes per line (standard hex dump width)
  1249. ld hl,01139h ;0370 Point to ASCII display area in buffer (right side of display)
  1250. ld (hl),02ah ;0373 Put '*' character as left ASCII area separator
  1251. inc hl ;0375 Move to first ASCII character position
  1252. exx ;0376 Switch to alternate register set (HL'=current memory address)
  1253. call sub_06b8h ;0377 Display 4-digit hex address at line start (XXXX format)
  1254. l037ah: ; Main byte display loop (16 bytes per line)
  1255. ld a,(hl) ;037a Load byte from current memory address
  1256. exx ;037b Switch to buffer registers (for ASCII display area)
  1257. ld (hl),a ;037c Store byte in ASCII display area (right side preview)
  1258. cp 020h ;037d Compare with space character (0x20)
  1259. jr c,l0385h ;037f If < 0x20 (control character), replace with dot
  1260. cp 07fh ;0381 Compare with DEL character (0x7F)
  1261. jr c,l0387h ;0383 If < 0x7F (printable ASCII), keep original character
  1262. l0385h:
  1263. ld (hl),02eh ;0385 Replace with '.' for non-printable characters (0x00-0x1F, 0x7F-0xFF)
  1264. l0387h:
  1265. inc hl ;0387 Move to next ASCII display position
  1266. ld (hl),02ah ;0388 Put '*' separator after ASCII character
  1267. exx ;038a Switch back to memory address registers
  1268. call sub_06c6h ;038b Display the hex value of current byte (XX format)
  1269. cpi ;038e Compare and increment HL, decrement BC (built-in loop control)
  1270. exx ;0390 Switch to buffer registers for ASCII area management
  1271. inc hl ;0391 Move buffer pointer to next ASCII position
  1272. jp po,l0727h ;0392 If BC=0 (parity odd=end of block), finish and display line
  1273. djnz l039ch ;0395 Decrement line counter B, if not 0 continue current line
  1274. call l0727h ;0397 Display the completed line (16 bytes hex + ASCII representation)
  1275. jr l035eh ;039a Start next line (display next address block)
  1276. l039ch: ; Continue current line processing
  1277. dec hl ;039c Back up buffer pointer (adjust for proper spacing)
  1278. exx ;039d Switch back to memory address registers
  1279. jr l037ah ;039e Continue byte processing loop for same line
  1280. ; =============================================================================
  1281. ; MEMORY EXAMINE AND MODIFY COMMAND (M command)
  1282. ; =============================================================================
  1283. ; Purpose: Interactive memory editing - display address, show current value,
  1284. ; allow user to enter new value, store it, and continue to next address
  1285. ; Input: HL = starting memory address (parsed from user command like "M 1000")
  1286. ; Operation: Shows "ADDR: XX" format, waits for user input, stores new value
  1287. ; User Interface: Enter new hex value to change, press Enter to skip, 'Q' to quit
  1288. ; Exit: User presses 'Q' to quit and return to monitor prompt
  1289. ; Example: "1000: 42" - shows address 1000 has value 42, user can change it
  1290. ; =============================================================================
  1291. l03a0h: ; Memory Examine/Modify Entry Point
  1292. push hl ;03a0 Save current memory address on stack
  1293. call sub_06b8h ;03a1 Display address in 4-digit hex format (e.g., "1000:")
  1294. ld a,(hl) ;03a4 Load current byte value from memory at address
  1295. call sub_0708h ;03a5 Display current value and get user input (hex parser)
  1296. jr z,l03b0h ;03a8 If no input/Enter pressed, skip to next address
  1297. pop hl ;03aa Restore memory address from stack
  1298. ld (hl),a ;03ab Store new value entered by user into memory
  1299. push hl ;03ac Save address on stack again for next iteration
  1300. call sub_0662h ;03ad Call verification/display routine (confirm change)
  1301. l03b0h: ; Next address processing
  1302. pop hl ;03b0 Restore current address from stack
  1303. cp 051h ;03b1 Compare input with 'Q' (0x51 = ASCII 'Q' for quit)
  1304. ret z ;03b3 Return to monitor prompt if user pressed 'Q'
  1305. inc hl ;03b4 Move to next memory address (auto-increment)
  1306. jr l03a0h ;03b5 Loop back to examine next byte (continue editing)
  1307. ; =============================================================================
  1308. ; MEMORY FILL COMMAND (F command) - Fill Memory Block with Pattern Byte
  1309. ; =============================================================================
  1310. ; Purpose: Fill a memory region with a specified byte value using efficient block copy
  1311. ; Input: User enters "F START END VALUE" - three hex parameters on command line
  1312. ; Operation: Fills memory from START to END (inclusive) with VALUE byte
  1313. ; Example: "F 1000 10FF 42" fills addresses 1000-10FF with 0x42 (256 bytes)
  1314. ; Special case: "FO" prefix jumps to different command handler (File Operations?)
  1315. ; Technique: Uses single byte + LDIR for efficient bulk memory fill
  1316. ; =============================================================================
  1317. l03b7h: ; Memory Fill Command Entry Point
  1318. call sub_065eh ;03b7 Get next command character from input buffer (after 'F')
  1319. cp 04fh ;03ba Compare with 'O' (0x4F = ASCII 'O')
  1320. jp z,l0a74h ;03bc If 'O', jump to File Operations handler (FO command)
  1321. call sub_0760h ;03bf Parse three hex parameters: start addr→DE, end addr→HL, value→A
  1322. and a ;03c2 Clear carry flag for subtraction (prepare SBC calculation)
  1323. ld (de),a ;03c3 Store fill value at start address (seeds the pattern)
  1324. sbc hl,de ;03c4 Calculate length = end address - start address
  1325. ret z ;03c6 Return if length is zero (start=end, only one byte filled)
  1326. ld b,h ;03c7 Move length to BC register pair (16-bit byte count)
  1327. ld c,l ;03c8 BC = number of bytes remaining to fill
  1328. ld h,d ;03c9 HL = start address (source for propagating pattern)
  1329. ld l,e ;03ca Copy DE (start) to HL
  1330. inc de ;03cb DE = start address + 1 (destination for pattern copy)
  1331. ldir ;03cc Fill memory: copy (HL) to (DE), repeat BC times
  1332. ret ;03ce Return to monitor (entire memory region now filled)
  1333. ; =============================================================================
  1334. ; DEBUG/DISPLAY PARAMETER COMMAND (I command) - Configure Display Settings
  1335. ; =============================================================================
  1336. ; Purpose: Configure debugging display parameters, modes, or formatting options
  1337. ; Input: User enters "I XXXX" where XXXX is hex value for display parameter
  1338. ; Storage: Parameter value stored at memory address 0x11D6
  1339. ; Special case: "II" command jumps to specialized display handler at 0x0A86
  1340. ; Use cases: Sets display width, format modes, or debugging visualization options
  1341. ; Examples: "I 10" might set 16-byte display width, "I 01" might enable trace mode
  1342. ; =============================================================================
  1343. l03cfh: ; I Command (Debug/Display Parameter) Entry Point
  1344. call sub_065eh ;03cf Get next command character from input buffer (check for "II")
  1345. cp 044h ;03d2 Compare with 'I' (0x49 = ASCII 'I' for "II" command variant)
  1346. jp z,l0a86h ;03d4 If second 'I', jump to specialized display command handler
  1347. ld a,(011d6h) ;03d7 Load current debug display parameter from memory (0x11D6)
  1348. call sub_0708h ;03da Get hex input from user (new parameter value for I command)
  1349. ret z ;03dd Return if no input provided (display current parameter value)
  1350. ld (011d6h),a ;03de Store new debug display parameter at 0x11D6
  1351. ret ;03e1 Return to monitor (I command parameter updated)
  1352. ; =============================================================================
  1353. ; BREAKPOINT/EXECUTION COUNTER COMMAND - Program Execution Control
  1354. ; =============================================================================
  1355. ; Purpose: Set up execution counter for controlled program stepping/tracing
  1356. ; Input: User enters hex counter value (number of instructions to execute)
  1357. ; Operation: Sets up debugging counter for single-step or limited execution
  1358. ; Use case: "B 100" might execute 256 instructions then break back to monitor
  1359. ; =============================================================================
  1360. l03e2h: ; Breakpoint/Counter Command Entry Point
  1361. call sub_03f7h ;03e2 Call setup/initialization routine (clear counters?)
  1362. call sub_0680h ;03e5 Parse hex input from user (execution count)
  1363. ret z ;03e8 Return if no valid input provided (show current count?)
  1364. call sub_0405h ;03e9 Process the counter value (setup execution limit)
  1365. sub_03ech: ; Counter Processing Subroutine - EXECUTION STEP COUNTER
  1366. call sub_0680h ;03ec Parse hex input from user (step count parameter)
  1367. jr nz,l03f3h ;03ef If valid hex input provided, store it as step count
  1368. ld a,001h ;03f1 Default step count = 1 (single step if no input)
  1369. l03f3h:
  1370. ld (011d0h),a ;03f3 Store step counter at 0x11D0 (execution step limit)
  1371. ret ;03f6 Return to single-step execution controller
  1372. ; =============================================================================
  1373. ; BREAKPOINT RESTORATION ROUTINE
  1374. ; =============================================================================
  1375. ; Purpose: Restore original instruction that was replaced by breakpoint
  1376. ; Operation: Reads saved instruction byte and restores it to memory
  1377. ; Used by: Breakpoint system to clean up after break execution
  1378. ; =============================================================================
  1379. sub_03f7h: ; Breakpoint Restoration
  1380. ld hl,(011f0h) ;03f7 Load breakpoint address from memory
  1381. ld a,(011cfh) ;03fa Load saved original instruction byte
  1382. ld (hl),a ;03fd Restore original instruction at breakpoint
  1383. ld hl,l0000h ;03fe Clear breakpoint address (set to 0000)
  1384. ld (011f0h),hl ;0401 Store cleared address (no active breakpoint)
  1385. l0404h:
  1386. ret ;0404 Return
  1387. ; =============================================================================
  1388. ; BREAKPOINT INSTALLATION ROUTINE
  1389. ; =============================================================================
  1390. ; Purpose: Install breakpoint by replacing instruction with 0xFF
  1391. ; Operation: Saves original instruction and replaces it with break opcode
  1392. ; Input: HL = address where breakpoint should be set
  1393. ; Memory: 011cfh = saved original instruction, 011f0h = breakpoint address
  1394. ; =============================================================================
  1395. sub_0405h: ; Breakpoint Installation
  1396. ld a,(hl) ;0405 Load original instruction from target address
  1397. ld (011cfh),a ;0406 Save original instruction byte
  1398. ld (hl),0ffh ;0409 Replace with breakpoint opcode (0xFF = RST 38H)
  1399. ld (011f0h),hl ;040b Store breakpoint address for later restoration
  1400. ret ;040e Return
  1401. ; =============================================================================
  1402. ; INSTRUCTION ANALYSIS AND BREAKPOINT PLACEMENT
  1403. ; =============================================================================
  1404. ; Purpose: Analyze instruction stream and set appropriate breakpoints
  1405. ; Used by: Single-step debugging and program flow analysis
  1406. ; =============================================================================
  1407. l040fh: ; Instruction Analysis Entry Point
  1408. call sub_03f7h ;040f Restore any existing breakpoint first
  1409. ld hl,(011eah) ;0412 Load current execution address
  1410. call sub_0425h ;0415 Analyze instruction at current address
  1411. jp nc,l049fh ;0418 If NOT special instruction, jump to normal execution path
  1412. ld e,a ;041b Move instruction length to E register
  1413. ld d,000h ;041c Clear D register (DE = instruction length in bytes)
  1414. add hl,de ;041e Calculate next instruction address (current + length)
  1415. call sub_0405h ;041f Set breakpoint at NEXT instruction (step-over mode)
  1416. jp l044ah ;0422 Jump to execution setup and run until breakpoint hit
  1417. ; =============================================================================
  1418. ; Z80 INSTRUCTION DECODER - Analyzes instruction types for debugging
  1419. ; =============================================================================
  1420. ; Purpose: Decode Z80 instructions to determine their type and length
  1421. ; Input: HL points to instruction to analyze
  1422. ; Output: Carry set if special instruction, A = instruction length
  1423. ; Special instructions: CALL, RET, conditional jumps, block operations
  1424. ; =============================================================================
  1425. sub_0425h: ; Z80 Instruction Decoder
  1426. ld a,(hl) ;0425 Load instruction opcode
  1427. cp 0edh ;0426 Check for ED prefix (extended instructions)
  1428. jr z,l0437h ;0428 If ED prefix, handle extended instructions
  1429. cp 0cdh ;042a Check for CALL instruction (0xCD)
  1430. jr z,l0433h ;042c If CALL, return length 3
  1431. and 0c4h ;042e Mask bits to check instruction pattern
  1432. xor 0c4h ;0430 Check for conditional CALL pattern (11xxx100)
  1433. ret nz ;0432 Return if not special instruction (carry clear)
  1434. l0433h: ; CALL instruction handler
  1435. ld a,003h ;0433 CALL instructions are 3 bytes long
  1436. scf ;0435 Set carry flag (special instruction detected)
  1437. ret ;0436 Return with instruction length
  1438. l0437h: ; Extended instruction handler (ED prefix)
  1439. inc hl ;0437 Move to second byte of ED instruction
  1440. ld a,(hl) ;0438 Load second opcode byte
  1441. and 0f0h ;0439 Mask upper nibble
  1442. xor 0b0h ;043b Check for block operation pattern (10110xxx)
  1443. ret nz ;043d Return if not block operation
  1444. inc a ;043e A = 1 (ED block instructions are 2 bytes)
  1445. scf ;043f Set carry flag (special instruction detected)
  1446. ret ;0440 Return with instruction length
  1447. ; =============================================================================
  1448. ; JUMP/EXECUTE COMMAND (J command) - Execute program from specified address
  1449. ; =============================================================================
  1450. ; Purpose: Start program execution from user-specified address (same as G command)
  1451. ; Input: User provides "J XXXX" where XXXX is hex address to execute
  1452. ; Operation: Sets up execution environment and transfers control to user program
  1453. ; Note: J command shares the same implementation as G (Go) command
  1454. ; =============================================================================
  1455. l0441h: ; J Command (Jump/Execute) Entry Point
  1456. call sub_0680h ;0441 Parse hex address from user input (e.g., "J 1000")
  1457. jp z,l02d9h ;0444 Jump to error handler if invalid address entered
  1458. ld (011eah),hl ;0447 Store execution start address in system variable
  1459. ; =============================================================================
  1460. ; PROGRAM EXECUTION CONTROLLER (shared by G and J commands)
  1461. ; =============================================================================
  1462. ; Purpose: Set up CPU state and execute user program with debugging support
  1463. ; Features: Interrupt handling, breakpoint detection, register restoration
  1464. ; Used by: Both G (Go) and J (Jump) commands use this same execution logic
  1465. ; =============================================================================
  1466. l044ah: ; Program Execution Setup
  1467. ld a,(011d7h) ;044a Load interrupt vector high byte from system config
  1468. ld i,a ;044d Set Z80 interrupt vector register (for IM2 mode)
  1469. ld de,(011eah) ;044f Load target execution address from user input (G/J command)
  1470. ld hl,(011f0h) ;0453 Load current breakpoint address from active breakpoint
  1471. and a ;0456 Clear carry flag for 16-bit address comparison
  1472. sbc hl,de ;0457 Compare: is breakpoint already at execution start address?
  1473. jr z,l0472h ;0459 If breakpoint at execution address, handle as special case
  1474. ld hl,(011d6h) ;045b Load debug control parameters (interrupt/trace modes)
  1475. ld a,h ;045e Get high byte of debug params for interrupt vector
  1476. ld i,a ;045f Set interrupt vector register for user program context
  1477. di ;0461 Disable interrupts during critical register setup phase
  1478. bit 0,l ;0462 Check debug control bit 0 (interrupt enable flag for user)
  1479. jr z,l0467h ;0464 If bit 0 clear, keep interrupts disabled during execution
  1480. ei ;0466 Re-enable interrupts if user program expects them enabled
  1481. ;==============================================================================
  1482. ; USER PROGRAM EXECUTION CONTROLLER (0x0467-0x0471)
  1483. ;==============================================================================
  1484. ; Purpose: Execute user program with full debugger support and state management
  1485. ; Entry: l0467h - Called after breakpoint setup or direct execution request
  1486. ; Operation: Restore registers → Execute user code → Handle return → Process results
  1487. ;==============================================================================
  1488. l0467h: ; Execute User Program Entry Point
  1489. call sub_079bh ;0467 CRITICAL: Restore all registers and execute user code
  1490. ld hl,(011eah) ;046a Reload execution address from save area (post-execution)
  1491. push hl ;046d Save execution address on stack for debug analysis
  1492. ld hl,(011d4h) ;046e Load debug parameters/status from execution control
  1493. ret ;0471 Return to calling debugger routine with status
  1494. ;==============================================================================
  1495. ; ERROR HANDLER AND MEMORY RESTORATION (0x0472-0x0478)
  1496. ;==============================================================================
  1497. ; Purpose: Handle execution errors and restore memory state after breakpoints
  1498. ; Used by: Debugger cleanup routines and breakpoint removal system
  1499. ;==============================================================================
  1500. l0472h: ; Error Handler Entry Point
  1501. ld hl,l07efh ;0472 Load address for execution/error handler routine
  1502. l0475h: ; Memory restoration entry point (breakpoint cleanup)
  1503. ld a,(011cfh) ;0475 Load saved byte value from backup storage location
  1504. ld (de),a ;0478 Restore original byte at target address (remove breakpoint)
  1505. ;==============================================================================
  1506. ; BREAKPOINT INSTALLATION WITH MEMORY PAGING (0x0479-0x049D)
  1507. ;==============================================================================
  1508. ; Purpose: Install software breakpoint in paged memory with full state management
  1509. ; Features: Memory paging control, interrupt management, state backup/restoration
  1510. ; Operation: Enables paging → Selects memory page → Plants breakpoint → Saves state
  1511. ;
  1512. ; Memory Paging Sequence:
  1513. ; 1. Disable interrupts for atomic operation
  1514. ; 2. Configure interrupt mode 2 with vector table at 0x1300
  1515. ; 3. Enable 64KB memory card paging system via port 0x000
  1516. ; 4. Select target memory page via dual-write to port 0x003
  1517. ; 5. Install breakpoint instruction and backup original data
  1518. ;
  1519. ; Port Operations:
  1520. ; • PORT 0x000 (0x20): Memory management control - enables bank switching
  1521. ; • PORT 0x003 (0x87, 0x01): Page selection - first 0x87 (page 7 + control), then 0x01 (page 1)
  1522. ;
  1523. ; State Management:
  1524. ; • Backs up original instruction before planting 0xFB (EI) breakpoint
  1525. ; • Stores breakpoint location and original data for safe restoration
  1526. ; • Integrates with debugger's execution control and single-step system
  1527. ;==============================================================================
  1528. l0479h: ; Breakpoint Installation Entry Point
  1529. dec de ;0479 Decrement target address by 1 (align to exact breakpoint location)
  1530. di ;047a Disable interrupts for atomic breakpoint installation
  1531. ld a,013h ;047b Set interrupt vector base 0x13 (points to table at 0x1300)
  1532. ld i,a ;047d Load interrupt vector register (prepare for IM2 mode)
  1533. ld a,020h ;047f Memory control: 0x20 = Enable 64KB paging system
  1534. out (000h),a ;0481 PORT 0x000: Memory management control (activate paging)
  1535. im 2 ;0483 Set interrupt mode 2 (vectored interrupts via table)
  1536. ld a,087h ;0485 Page select: 0x87 = Page 7 + control bits active
  1537. out (003h),a ;0487 PORT 0x003: Page selection register (first selection)
  1538. ld a,001h ;0489 Page select: 0x01 = Select memory page 1 for breakpoint
  1539. out (003h),a ;048b PORT 0x003: Page selection register (second selection)
  1540. ld (01326h),hl ;048d Store HL at 0x1326 (breakpoint address for paging system)
  1541. ex de,hl ;0490 Exchange: HL=decremented target addr, DE=original addr
  1542. ld (011d1h),hl ;0491 Store active breakpoint address at 0x11D1 (current BP)
  1543. ld a,(hl) ;0494 Load original instruction byte from breakpoint location
  1544. ld (011d3h),a ;0495 Store original byte at 0x11D3 (backup for restoration)
  1545. ld (hl),0fbh ;0498 Plant breakpoint: 0xFB = EI instruction (interrupt enable)
  1546. ld (011eah),hl ;049a Store breakpoint address at 0x11EA (execution target)
  1547. jr l0467h ;049d Jump to execution preparation (complete breakpoint cycle)
  1548. ;==============================================================================
  1549. ; NORMAL INSTRUCTION EXECUTION PATH (0x049F) - NON-SPECIAL INSTRUCTIONS
  1550. ;==============================================================================
  1551. ; Purpose: Handle execution of normal instructions (not CALL/RET/conditional jumps)
  1552. ; Entry: Jumped to from 0x0418 when instruction decoder finds standard instruction
  1553. ; Operation: Set up single-step debugging environment for normal instruction execution
  1554. ; Features: Console buffer setup, memory management, step-by-step execution control
  1555. ;==============================================================================
  1556. l049fh: ; Normal Instruction Execution Entry Point
  1557. call sub_05a5h ;049f Initialize console buffer system (prepare for single-step I/O)
  1558. call sub_03ech ;04a2 Process execution counter/step parameters
  1559. l04a5h: ; Single-Step Execution Loop Controller
  1560. ld hl,(011d6h) ;04a5 Load debug control parameters from system settings
  1561. ld (011eeh),hl ;04a8 Save debug parameters for restoration after execution
  1562. ld de,(011eah) ;04ab Load current execution address (where to execute next)
  1563. ld hl,(011f0h) ;04af Load active breakpoint address from system
  1564. and a ;04b2 Clear carry flag for 16-bit address comparison
  1565. sbc hl,de ;04b3 Compare: is execution address same as breakpoint address?
  1566. ld hl,l04bch ;04b5 Load address of breakpoint handler routine
  1567. jr z,l0475h ;04b8 If at breakpoint, jump to memory restoration routine
  1568. jr l0479h ;04ba Otherwise, jump to breakpoint installation routine
  1569. l04bch:
  1570. ld (011d4h),hl ;04bc
  1571. pop hl ;04bf
  1572. ld (011ech),sp ;04c0
  1573. ld sp,01400h ;04c4
  1574. call sub_0770h ;04c7
  1575. call sub_04ebh ;04ca
  1576. ld hl,l04d3h ;04cd
  1577. push hl ;04d0
  1578. reti ;04d1
  1579. l04d3h:
  1580. ld hl,(011eeh) ;04d3
  1581. ld (011d6h),hl ;04d6
  1582. call sub_0582h ;04d9
  1583. ld hl,011d0h ;04dc
  1584. dec (hl) ;04df
  1585. jr nz,l04a5h ;04e0
  1586. inc (hl) ;04e2
  1587. call sub_080dh ;04e3
  1588. jp nz,l02c9h ;04e6
  1589. jr l04a5h ;04e9
  1590. ;==============================================================================
  1591. ; MEMORY PAGING RESTORE ROUTINE (0x04EB)
  1592. ;==============================================================================
  1593. ; Purpose: Restore default memory page and clean up paging state
  1594. ; Called during system shutdown or page switching operations
  1595. ;
  1596. ; Operation:
  1597. ; - Switches back to page 3 (likely default/system page)
  1598. ; - Restores original memory contents from backup
  1599. ; - Cleans up paging state for safe transition
  1600. ;==============================================================================
  1601. sub_04ebh:
  1602. ld a,003h ;04eb ; Load page 3 (default/system page)
  1603. out (003h),a ;04ed ; PORT 0x003: Switch to page 3
  1604. ld hl,(011d1h) ;04ef ; Load backup memory address
  1605. ld a,(011d3h) ;04f2 ; Load original byte value
  1606. ld (hl),a ;04f5 ; Restore original memory contents
  1607. ld hl,(011f0h) ;04f6 ; Load cleanup address
  1608. ld (hl),0ffh ;04f9 ; Mark memory as restored/available
  1609. ret ;04fb ; Return to caller
  1610. call sub_0760h ;04fc
  1611. jp z,l02d9h ;04ff
  1612. push hl ;0502
  1613. and a ;0503
  1614. sbc hl,de ;0504
  1615. pop hl ;0506
  1616. l0507h:
  1617. jr c,l050ch ;0507
  1618. l0509h:
  1619. ldir ;0509
  1620. ret ;050b
  1621. l050ch:
  1622. add hl,bc ;050c
  1623. dec hl ;050d
  1624. ex de,hl ;050e
  1625. add hl,bc ;050f
  1626. dec hl ;0510
  1627. ex de,hl ;0511
  1628. lddr ;0512
  1629. ret ;0514
  1630. call sub_0662h ;0515
  1631. jr z,l057fh ;0518
  1632. ld d,a ;051a
  1633. call sub_065eh ;051b
  1634. jr nz,l0522h ;051e
  1635. ld a,020h ;0520
  1636. l0522h:
  1637. ld e,a ;0522
  1638. call sub_05cch ;0523
  1639. dec hl ;0526
  1640. dec hl ;0527
  1641. jp nz,l02d9h ;0528
  1642. l052bh:
  1643. ld de,01104h ;052b
  1644. ldi ;052e
  1645. ldi ;0530
  1646. push hl ;0532
  1647. ex de,hl ;0533
  1648. ld (hl),020h ;0534
  1649. inc hl ;0536
  1650. ld (011f2h),hl ;0537
  1651. ld hl,l060eh ;053a
  1652. or a ;053d
  1653. ex de,hl ;053e
  1654. sbc hl,de ;053f
  1655. ld e,(ix+000h) ;0541
  1656. ld d,(ix+001h) ;0544
  1657. jr nc,l056ah ;0547
  1658. ld a,(de) ;0549
  1659. push de ;054a
  1660. call sub_0708h ;054b
  1661. pop de ;054e
  1662. jr z,l0555h ;054f
  1663. ld (de),a ;0551
  1664. l0552h:
  1665. call sub_0662h ;0552
  1666. l0555h:
  1667. cp 051h ;0555
  1668. pop hl ;0557
  1669. ret z ;0558
  1670. inc ix ;0559
  1671. inc ix ;055b
  1672. ex de,hl ;055d
  1673. push hl ;055e
  1674. ld hl,l0615h ;055f
  1675. or a ;0562
  1676. sbc hl,de ;0563
  1677. pop hl ;0565
  1678. ex de,hl ;0566
  1679. jr nz,l052bh ;0567
  1680. ret ;0569
  1681. l056ah:
  1682. ld a,(de) ;056a
  1683. ld l,a ;056b
  1684. inc de ;056c
  1685. ld a,(de) ;056d
  1686. ld h,a ;056e
  1687. call sub_06b8h ;056f
  1688. push de ;0572
  1689. call sub_070bh ;0573
  1690. pop de ;0576
  1691. jr z,l0555h ;0577
  1692. ex de,hl ;0579
  1693. ld (hl),d ;057a
  1694. dec hl ;057b
  1695. ld (hl),e ;057c
  1696. jr l0552h ;057d
  1697. l057fh:
  1698. call sub_05a5h ;057f
  1699. sub_0582h:
  1700. ld b,011h ;0582
  1701. ld hl,l0615h ;0584
  1702. l0587h:
  1703. ld e,(hl) ;0587
  1704. inc hl ;0588
  1705. ld d,(hl) ;0589
  1706. inc hl ;058a
  1707. ld a,(de) ;058b
  1708. call sub_06c6h ;058c
  1709. djnz l0587h ;058f
  1710. ld b,004h ;0591
  1711. l0593h:
  1712. ld e,(hl) ;0593
  1713. inc hl ;0594
  1714. ld d,(hl) ;0595
  1715. inc hl ;0596
  1716. ex de,hl ;0597
  1717. ld a,(hl) ;0598
  1718. inc hl ;0599
  1719. ld h,(hl) ;059a
  1720. ld l,a ;059b
  1721. call sub_06b8h ;059c
  1722. ex de,hl ;059f
  1723. djnz l0593h ;05a0
  1724. l05a2h:
  1725. jp sub_072ah ;05a2
  1726. ;==============================================================================
  1727. ; CONSOLE BUFFER INITIALIZATION (sub_05a5h) - REGISTER DISPLAY SETUP
  1728. ;==============================================================================
  1729. ; Purpose: Initialize console buffer system with register name templates
  1730. ; Operation: Copy register name strings from ROM table to RAM buffer area
  1731. ; Used by: Single-step debugging to prepare register display output
  1732. ; Buffer: 0x1104 = console buffer start, filled with register names for display
  1733. ;==============================================================================
  1734. sub_05a5h: ; Console Buffer Initialization Entry Point
  1735. ld de,01104h ;05a5 DE = console buffer start address (0x1104)
  1736. ld hl,l05ebh ;05a8 HL = register name table in ROM (0x05EB - register names)
  1737. ld bc,011ffh ;05ab BC = loop count (B=0x01, C=0xFF - copy parameters)
  1738. ld a,020h ;05ae A = 0x20 (space character for formatting)
  1739. l05b0h: ; Register Name Copy Loop
  1740. ldi ;05b0 Copy first character from register table to buffer
  1741. ldi ;05b2 Copy second character from register table to buffer
  1742. ld (de),a ;05b4 Store space character (0x20) after register name
  1743. inc de ;05b5 Advance buffer pointer past space
  1744. djnz l05b0h ;05b6 Loop until all register names copied (B times)
  1745. ld b,004h ;05b8 Set loop counter for additional buffer setup (4 iterations)
  1746. l05bah: ; Additional Buffer Formatting Loop
  1747. ld (de),a ;05ba Store space character in buffer
  1748. inc de ;05bb Advance buffer pointer
  1749. ldi ;05bc Copy character from register table to buffer
  1750. ldi ;05be Copy second character from register table to buffer
  1751. ld (de),a ;05c0 Store space character after register name
  1752. inc de ;05c1 Advance buffer pointer
  1753. ld (de),a ;05c2 Store another space character (double spacing)
  1754. inc de ;05c3 Advance buffer pointer
  1755. djnz l05bah ;05c4 Loop for remaining register names (4 times)
  1756. ld (011f2h),de ;05c6 Store final buffer pointer at 0x11F2 (buffer end)
  1757. jr l05a2h ;05ca Jump to buffer completion routine
  1758. sub_05cch:
  1759. ld ix,l0615h ;05cc
  1760. ld bc,l002ah ;05d0
  1761. ld hl,l05ebh ;05d3
  1762. l05d6h:
  1763. ld a,d ;05d6
  1764. cpi ;05d7
  1765. jr z,l05e5h ;05d9
  1766. xor a ;05db
  1767. cpi ;05dc
  1768. l05deh:
  1769. ret po ;05de
  1770. inc ix ;05df
  1771. inc ix ;05e1
  1772. jr l05d6h ;05e3
  1773. l05e5h:
  1774. ld a,e ;05e5
  1775. cpi ;05e6
  1776. ret z ;05e8
  1777. jr l05deh ;05e9
  1778. ;==============================================================================
  1779. ; Z80 REGISTER NAME TABLE (0x05EB+)
  1780. ; Purpose: ASCII string table of Z80 register names for display/debugging
  1781. ; Format: Space-separated register names, single quotes for alternate registers
  1782. ; Content: "A B C D E F H L I A'B'C'D'E'F'H'L'IXI..."
  1783. ;==============================================================================
  1784. ;==============================================================================
  1785. ; Z80 REGISTER NAME AND ADDRESS LOOKUP TABLE (0x05EB-0x63D)
  1786. ; Purpose: Complete register name table with corresponding addresses for debugger/monitor
  1787. ; Format: ASCII register names followed by address lookup table
  1788. ;==============================================================================
  1789. register_names_05ebh:
  1790. ; Register name strings (space-separated)
  1791. db "A B C D E F H L I A'B'C'D'E'F'H'L'IXI" ;05eb-060f
  1792. db "YPCSP" ;0610-0614 (IY, PC, SP registers)
  1793. ; Address lookup table (each entry is 0x11 followed by address)
  1794. db 0xD9, 0x11, 0xDB, 0x11, 0xDA, 0x11, 0xDD, 0x11 ;0615-061c
  1795. db 0xDC, 0x11, 0xD8, 0x11, 0xD5, 0x11, 0xD4, 0x11 ;061d-0624
  1796. db 0xD7, 0x11, 0xDF, 0x11, 0xE1, 0x11, 0xE0, 0x11 ;0625-062c
  1797. db 0xE3, 0x11, 0xE2, 0x11, 0xDE, 0x11, 0xE5, 0x11 ;062d-0634
  1798. db 0xE4, 0x11, 0xE6, 0x11, 0xE8, 0x11, 0xEA, 0x11 ;0635-063c
  1799. db 0xEC, 0x11 ;063d-063e
  1800. ;==============================================================================
  1801. ; HEX INPUT SEQUENCE (0x063F)
  1802. ;==============================================================================
  1803. ; Purpose: Parse two hexadecimal values from user input
  1804. ; Typical use: Address and data entry for memory operations
  1805. ; Example: User types "1000 FF" to store 0xFF at address 0x1000
  1806. ;==============================================================================
  1807. sub_063fh:
  1808. call sub_0680h ;063f ; Parse first hex string (e.g., address)
  1809. push hl ;0642 ; Save first parsed value on stack
  1810. call sub_0680h ;0643 ; Parse second hex string (e.g., data)
  1811. pop hl ;0646 ; Restore first value to HL
  1812. ret z ;0647 ; Return if second parse failed
  1813. ld (hl),a ;0648 ; Store second value (data) at first value (address)
  1814. inc hl ;0649 ; Increment to next address
  1815. jr $-8 ;064a ; Loop back to continue operation
  1816. sub_064ch:
  1817. ex (sp),hl ;064c
  1818. ld b,(hl) ;064d
  1819. l064eh:
  1820. inc hl ;064e
  1821. cp (hl) ;064f
  1822. inc hl ;0650
  1823. ld e,(hl) ;0651
  1824. inc hl ;0652
  1825. ld d,(hl) ;0653
  1826. jr nz,l0659h ;0654
  1827. ex de,hl ;0656
  1828. ex (sp),hl ;0657
  1829. ret ;0658
  1830. l0659h:
  1831. djnz l064eh ;0659
  1832. jp l02d9h ;065b
  1833. sub_065eh:
  1834. inc hl ;065e
  1835. ld a,(hl) ;065f
  1836. jr l0677h ;0660
  1837. ; =============================================================================
  1838. ; INPUT BUFFER SCANNER - Skip Spaces and Process Next Character
  1839. ; =============================================================================
  1840. ; Purpose: Scan input buffer, skip spaces, and return next non-space character
  1841. ; Input: (011f4h) points to current position in input buffer
  1842. ; Output: A = next non-space character, HL updated to new position
  1843. ; Used by: Memory modify command to parse user input after displaying value
  1844. ; =============================================================================
  1845. sub_0662h: ; Input Buffer Scanner
  1846. ld hl,(011f4h) ;0662 Load current input buffer pointer
  1847. l0665h: ; Space-skipping loop
  1848. ld a,(hl) ;0665 Load character from buffer
  1849. cp 00dh ;0666 Check for CR (end of line)
  1850. jr z,l0674h ;0668 If CR, finish and update pointer
  1851. cp 020h ;066a Check for space character
  1852. l066ch: ; Continue scanning loop
  1853. inc hl ;066c Move to next character
  1854. jr nz,l0665h ;066d If not space, check if still space at new position
  1855. ld a,(hl) ;066f Load next character
  1856. cp 020h ;0670 Check if it's also a space
  1857. jr z,l066ch ;0672 If space, continue skipping spaces
  1858. l0674h: ; Update buffer pointer and process character
  1859. ld (011f4h),hl ;0674 Store updated buffer pointer
  1860. l0677h: ; Character processing
  1861. bit 6,a ;0677 Check bit 6 (lowercase letter detection)
  1862. jr z,l067dh ;0679 If not set, skip case conversion
  1863. res 5,a ;067b Convert lowercase to uppercase (clear bit 5)
  1864. l067dh: ; Final character check
  1865. cp 00dh ;067d Compare with CR (carriage return)
  1866. ret ;067f Return with flags set
  1867. ;==============================================================================
  1868. ; HEXADECIMAL STRING PARSER (0x0680)
  1869. ;==============================================================================
  1870. ; Purpose: Convert ASCII hexadecimal string to binary value
  1871. ; Input: DE points to ASCII hex string (e.g. "1A2F")
  1872. ; Output: HL contains parsed binary value, A contains last character processed
  1873. ;
  1874. ; Supported formats:
  1875. ; - Digits 0-9 (ASCII 0x30-0x39)
  1876. ; - Letters A-F (ASCII 0x41-0x46, case insensitive)
  1877. ; - Automatically converts lowercase a-f to uppercase A-F
  1878. ;
  1879. ; Error handling: Invalid characters cause jump to error handler at l02d9h
  1880. ;
  1881. ; Algorithm:
  1882. ; 1. Initialize result to 0
  1883. ; 2. For each character: validate, convert, pack into result
  1884. ; 3. Use RLD instruction for efficient 4-bit nibble packing
  1885. ; 4. Continue until non-hex character found
  1886. ;==============================================================================
  1887. sub_0680h:
  1888. ld hl,l0000h ;0680 ; Initialize result to 0
  1889. push hl ;0683 ; Save initial value on stack
  1890. add hl,sp ;0684 ; HL = stack pointer (for result storage)
  1891. ex de,hl ;0685 ; DE = stack pointer, HL = string pointer
  1892. call sub_0662h ;0686 ; Get next character from input
  1893. ex de,hl ;0689 ; Restore: HL = stack pointer, DE = string pointer
  1894. jr nz,l068fh ;068a ; If character available, process it
  1895. l068ch:
  1896. pop hl ;068c ; Restore result from stack
  1897. ld a,l ;068d ; Return low byte in A
  1898. ret ;068e ; Return with parsed value
  1899. l068fh:
  1900. cp 030h ;068f ; Compare with '0' (0x30)
  1901. jp c,l02d9h ;0691 ; If < '0', invalid hex character - error
  1902. l0694h:
  1903. cp 041h ;0694 ; Compare with 'A' (0x41)
  1904. jr c,l069ah ;0696 ; If < 'A', must be digit 0-9, go convert
  1905. res 5,a ;0698 ; Convert lowercase to uppercase (clear bit 5)
  1906. l069ah:
  1907. cp 03ah ;069a ; Compare with ':' (0x3A, one past '9')
  1908. jr c,l06aah ;069c ; If < ':', it's digit 0-9, go pack
  1909. cp 041h ;069e ; Compare with 'A' (0x41)
  1910. jp c,l02d9h ;06a0 ; If between ':' and 'A', invalid - error
  1911. cp 047h ;06a3 ; Compare with 'G' (0x47, one past 'F')
  1912. jp nc,l02d9h ;06a5 ; If >= 'G', invalid hex letter - error
  1913. sub 007h ;06a8 ; Convert A-F to 10-15 (subtract 7)
  1914. l06aah:
  1915. rld ;06aa ; Rotate left digit: pack nibble into (HL)
  1916. inc hl ;06ac ; Point to next byte for multi-byte values
  1917. rld ;06ad ; Pack into high nibble of next byte
  1918. dec hl ;06af ; Return to original position
  1919. inc de ;06b0 ; Point to next character in input string
  1920. ld a,(de) ;06b1 ; Load next character
  1921. cp 030h ;06b2 ; Check if >= '0'
  1922. jr nc,l0694h ;06b4 ; If valid hex character, continue parsing
  1923. jr l068ch ;06b6 ; Otherwise, end parsing and return result
  1924. ;==============================================================================
  1925. ; 16-BIT HEX ADDRESS FORMATTER (0x06B8)
  1926. ;==============================================================================
  1927. ; Purpose: Convert 16-bit value in HL to 4-digit hex string and store in output buffer
  1928. ; Used extensively throughout the monitor for displaying memory addresses,
  1929. ; breakpoint locations, and register values in XXXX format.
  1930. ;
  1931. ; Input: HL = 16-bit value to format (e.g., memory address)
  1932. ; Output: 4-character hex string written to console buffer at (0x011F2)
  1933. ; Followed by a space character for proper formatting
  1934. ; Buffer: Updates 0x011F2 pointer to reflect new buffer position
  1935. ;
  1936. ; Format: Converts 0x1234 → "1234 " (4 hex digits + space)
  1937. ; Usage: Called by memory display, breakpoint display, register dump routines
  1938. ;
  1939. ; Technical Details:
  1940. ; • Processes high byte (H) first, then low byte (L)
  1941. ; • Each byte converted to 2 hex characters using sub_06c6h
  1942. ; • Automatically adds space separator after hex digits
  1943. ; • Updates buffer pointer for subsequent output operations
  1944. ;==============================================================================
  1945. sub_06b8h:
  1946. ld a,h ;06b8 ; Load high byte of 16-bit value
  1947. call sub_06c6h ;06b9 ; Convert high byte to 2 hex characters
  1948. push hl ;06bc ; Save original 16-bit value
  1949. ld hl,(011f2h) ;06bd ; Load current console buffer pointer
  1950. dec hl ;06c0 ; Back up one position (preparation for space)
  1951. ld (011f2h),hl ;06c1 ; Update buffer pointer
  1952. pop hl ;06c4 ; Restore original 16-bit value
  1953. ld a,l ;06c5 ; Load low byte of 16-bit value
  1954. ;==============================================================================
  1955. ; SINGLE BYTE HEX FORMATTER (0x06C6)
  1956. ;==============================================================================
  1957. ; Purpose: Convert single byte to 2-digit hex string and store in output buffer
  1958. ; Input: A = byte value to convert (0x00-0xFF)
  1959. ; Output: 2-character hex string written to buffer, followed by space
  1960. ; Used by: 16-bit formatter above, and other hex display routines
  1961. ;==============================================================================
  1962. sub_06c6h:
  1963. push hl ;06c6 ; Save registers
  1964. ld hl,(011f2h) ;06c7 ; Load current console buffer pointer
  1965. call sub_06d6h ;06ca ; Convert byte to 2 hex characters at buffer
  1966. inc hl ;06cd ; Move past the 2 hex characters
  1967. ld (hl),020h ;06ce ; Store space character (0x20) for separation
  1968. inc hl ;06d0 ; Move past space character
  1969. ld (011f2h),hl ;06d1 ; Update buffer pointer to new position
  1970. pop hl ;06d4 ; Restore registers
  1971. ret ;06d5
  1972. ;==============================================================================
  1973. ; BYTE TO HEX DIGIT CONVERTER (0x06D6)
  1974. ;==============================================================================
  1975. ; Purpose: Convert single byte to 2 ASCII hex characters
  1976. ; Input: A = byte value, HL = buffer location
  1977. ; Output: 2 hex characters stored at HL and HL+1
  1978. ; Method: Splits byte into high/low nibbles, converts each to ASCII hex
  1979. ;==============================================================================
  1980. sub_06d6h:
  1981. push af ;06d6 ; Save original byte value
  1982. rra ;06d7 ; Rotate right 4 times to get high nibble
  1983. rra ;06d8 ; in low 4 bits
  1984. rra ;06d9
  1985. rra ;06da
  1986. call sub_06e0h ;06db ; Convert high nibble to hex character
  1987. inc hl ;06de ; Move to next buffer position
  1988. pop af ;06df ; Restore original byte value
  1989. ;==============================================================================
  1990. ; NIBBLE TO HEX CHARACTER CONVERTER (0x06E0)
  1991. ;==============================================================================
  1992. ; Purpose: Convert single nibble (0-15) to ASCII hex character
  1993. ; Input: A = nibble value (0-15), HL = buffer location
  1994. ; Output: ASCII hex character ('0'-'9', 'A'-'F') stored at (HL)
  1995. ;==============================================================================
  1996. sub_06e0h:
  1997. and 00fh ;06e0 ; Mask to get only low 4 bits (nibble)
  1998. cp 00ah ;06e2 ; Compare with 10
  1999. jr c,l06e8h ;06e4 ; If < 10, convert to '0'-'9'
  2000. add a,007h ;06e6 ; If >= 10, add 7 to convert to 'A'-'F'
  2001. l06e8h:
  2002. add a,030h ;06e8 ; Add ASCII '0' offset to get final character
  2003. ld (hl),a ;06ea ; Store ASCII hex character in buffer
  2004. ret ;06eb ; Return
  2005. ;==============================================================================
  2006. ; CONSOLE OUTPUT FORMATTER & UTILITIES (0x06EC-0x076F)
  2007. ;==============================================================================
  2008. ; Collection of routines for formatting and outputting data to the console
  2009. ; with proper control characters and formatting.
  2010. ;==============================================================================
  2011. ;==============================================================================
  2012. ; STRING DISPLAY WITH CONTROL FORMATTING (0x06EC)
  2013. ;==============================================================================
  2014. ; Purpose: Display string from HL with proper control character formatting
  2015. ; Adds ETX (0x02) prefix and EOT (0x03) suffix around displayed text
  2016. ; Used for formatted console output with control framing
  2017. ;==============================================================================
  2018. l06ech:
  2019. inc hl ;06ec ; Move to start of string data
  2020. ld c,002h ;06ed ; Load ETX control character (Start of Text)
  2021. call sub_0111h ;06ef ; Send ETX to serial port
  2022. l06f2h:
  2023. ld a,(hl) ;06f2 ; Load next character from string
  2024. cp 020h ;06f3 ; Check if space character (end marker)
  2025. jr z,l0702h ;06f5 ; If space, end string output
  2026. cp 00dh ;06f7 ; Check if carriage return (end marker)
  2027. jr z,l0702h ;06f9 ; If CR, end string output
  2028. ld c,a ;06fb ; Load character into C for output
  2029. call sub_0111h ;06fc ; Send character to serial port
  2030. inc hl ;06ff ; Move to next character
  2031. jr l06f2h ;0700 ; Continue until end marker found
  2032. l0702h:
  2033. ld c,003h ;0702 ; Load EOT control character (End of Text)
  2034. call sub_0111h ;0704 ; Send EOT to serial port
  2035. ret ;0707 ; Return
  2036. ;==============================================================================
  2037. ; HEX BYTE DISPLAY WITH INPUT PROMPT (0x0708)
  2038. ;==============================================================================
  2039. ; Purpose: Display byte value and prompt for user input
  2040. ; Used by memory examination commands for interactive editing
  2041. ;==============================================================================
  2042. sub_0708h:
  2043. call sub_06c6h ;0708 ; Format and display byte as 2-digit hex + space
  2044. ;==============================================================================
  2045. ; CONSOLE OUTPUT FLUSH AND INPUT PROMPT (0x070B)
  2046. ;==============================================================================
  2047. ; Purpose: Flush current output buffer and prompt for user input
  2048. ; Sets up interactive prompt with space character and waits for input
  2049. ;==============================================================================
  2050. sub_070bh:
  2051. call sub_0745h ;070b ; Flush output buffer to console
  2052. ld a,020h ;070e ; Load space character
  2053. ld (011f6h),a ;0710 ; Set prompt character to space
  2054. call sub_080dh ;0713 ; Get character from user input
  2055. cp 051h ;0716 ; Check if 'Q' (quit command)
  2056. ret z ;0718 ; Return if user wants to quit
  2057. ld hl,01168h ;0719 ; Load input buffer address
  2058. ld (hl),020h ;071c ; Initialize buffer with space
  2059. ld (011f4h),hl ;071e ; Set input buffer pointer
  2060. push de ;0721 ; Save DE register
  2061. call sub_0680h ;0722 ; Parse hex input from user
  2062. pop de ;0725 ; Restore DE register
  2063. ret ;0726 ; Return
  2064. ;==============================================================================
  2065. ; OUTPUT BUFFER MANAGEMENT ROUTINES (0x0727-0x076F)
  2066. ;==============================================================================
  2067. ; Purpose: Handle console output buffer operations including line formatting,
  2068. ; buffer flushing, and register preservation during I/O operations
  2069. ;==============================================================================
  2070. ;==============================================================================
  2071. ; SET OUTPUT BUFFER POINTER (0x0727)
  2072. ;==============================================================================
  2073. l0727h:
  2074. ld (011f2h),hl ;0727 ; Store HL as new output buffer pointer
  2075. ;==============================================================================
  2076. ; FLUSH OUTPUT WITH NEWLINE (0x072A)
  2077. ;==============================================================================
  2078. ; Purpose: Add CR/LF to output buffer and flush to console
  2079. ; Preserves all registers during output operation
  2080. ;==============================================================================
  2081. sub_072ah:
  2082. push hl ;072a ; Save all registers
  2083. push de ;072b
  2084. push bc ;072c
  2085. ld hl,(011f2h) ;072d ; Load current buffer pointer
  2086. ld (hl),00dh ;0730 ; Add carriage return
  2087. inc hl ;0732 ; Move to next position
  2088. ld (hl),00ah ;0733 ; Add line feed
  2089. inc hl ;0735 ; Move to next position
  2090. l0736h:
  2091. ld (hl),000h ;0736 ; Add null terminator
  2092. ld hl,01104h ;0738 ; Reset buffer pointer to start
  2093. ld (011f2h),hl ;073b ; Update buffer pointer
  2094. call l00fdh ;073e ; Send buffer contents to console
  2095. pop bc ;0741 ; Restore all registers
  2096. pop de ;0742
  2097. pop hl ;0743
  2098. ret ;0744 ; Return
  2099. ;==============================================================================
  2100. ; FLUSH OUTPUT WITHOUT NEWLINE (0x0745)
  2101. ;==============================================================================
  2102. ; Purpose: Flush current output buffer to console without adding newline
  2103. ; Used for partial line output and formatting
  2104. ;==============================================================================
  2105. sub_0745h:
  2106. push hl ;0745 ; Save all registers
  2107. push de ;0746
  2108. push bc ;0747
  2109. ld hl,(011f2h) ;0748 ; Load current buffer pointer
  2110. jr l0736h ;074b ; Jump to common flush routine
  2111. ;==============================================================================
  2112. ; OUTPUT BUFFER WITH CHARACTER INPUT (0x074D)
  2113. ;==============================================================================
  2114. ; Purpose: Flush output buffer and get character input from console
  2115. ; Returns input character while preserving registers
  2116. ;==============================================================================
  2117. sub_074dh:
  2118. push hl ;074d ; Save registers
  2119. push de ;074e
  2120. ld hl,(011f2h) ;074f ; Load current buffer pointer
  2121. ld (hl),000h ;0752 ; Add null terminator
  2122. ld hl,01104h ;0754 ; Reset buffer pointer to start
  2123. ld (011f2h),hl ;0757 ; Update buffer pointer
  2124. call l0107h ;075a ; Output buffer and get input character
  2125. pop de ;075d ; Restore registers
  2126. pop hl ;075e
  2127. ret ;075f ; Return with input character in A
  2128. ;==============================================================================
  2129. ; MULTI-PARAMETER HEX INPUT PARSER (0x0760-0x076F)
  2130. ;==============================================================================
  2131. ; Purpose: Parse multiple hexadecimal parameters from user input
  2132. ; Returns parsed values in HL, DE, and BC registers
  2133. ;==============================================================================
  2134. sub_0760h:
  2135. call sub_0680h ;0760 ; Parse first hex parameter → HL
  2136. ;==============================================================================
  2137. ; TWO-PARAMETER HEX INPUT PARSER (0x0763)
  2138. ;==============================================================================
  2139. sub_0763h:
  2140. push hl ;0763 ; Save first parameter
  2141. call sub_0680h ;0764 ; Parse second hex parameter → HL
  2142. push hl ;0767 ; Save second parameter
  2143. call sub_0680h ;0768 ; Parse third hex parameter → HL
  2144. ld b,h ;076b ; Store third parameter high byte in B
  2145. ld c,l ;076c ; Store third parameter low byte in C
  2146. pop hl ;076d ; Restore second parameter to HL
  2147. pop de ;076e ; Restore first parameter to DE
  2148. ret ;076f ; Return: DE=1st param, HL=2nd param, BC=3rd param
  2149. ;==============================================================================
  2150. ; COMPLETE CPU STATE SAVE ROUTINE (sub_0770h) - CRITICAL SYSTEM COMPONENT
  2151. ;==============================================================================
  2152. ; Purpose: Save ALL Z80 CPU registers and set up interrupt environment
  2153. ; Used by: Interrupt handlers, breakpoint system, system initialization
  2154. ; Operation: Saves complete CPU state to stack area, sets up IM2 interrupts
  2155. ; Stack Layout: Creates complete register save area for later restoration
  2156. ;
  2157. ; REGISTER SAVE ORDER (pushed to stack at 0x011EC):
  2158. ; 1. HL (main register pair)
  2159. ; 2. IY (index register Y)
  2160. ; 3. IX (index register X)
  2161. ; 4. HL' (alternate HL)
  2162. ; 5. DE' (alternate DE)
  2163. ; 6. BC' (alternate BC)
  2164. ; 7. AF' (alternate accumulator/flags)
  2165. ; 8. DE (main register pair)
  2166. ; 9. BC (main register pair)
  2167. ; 10. AF (main accumulator/flags)
  2168. ; 11. I register status (interrupt vector register)
  2169. ;==============================================================================
  2170. sub_0770h: ; Complete CPU State Save Entry Point
  2171. ld sp,011ech ;0770 Set stack pointer to register save area (0x011EC)
  2172. push hl ;0773 Save main HL register pair
  2173. push iy ;0774 Save IY index register (2 bytes)
  2174. push ix ;0776 Save IX index register (2 bytes)
  2175. exx ;0778 Switch to alternate register set
  2176. push hl ;0779 Save alternate HL register pair
  2177. push de ;077a Save alternate DE register pair
  2178. push bc ;077b Save alternate BC register pair
  2179. ex af,af' ;077c Switch to alternate AF register
  2180. push af ;077d Save alternate AF (accumulator/flags)
  2181. exx ;077e Switch back to main register set
  2182. ex af,af' ;077f Switch back to main AF register
  2183. push de ;0780 Save main DE register pair
  2184. push bc ;0781 Save main BC register pair
  2185. push af ;0782 Save main AF (accumulator/flags)
  2186. ld a,i ;0783 Load interrupt vector register into A
  2187. push af ;0785 Save interrupt vector register status
  2188. ld a,(011d6h) ;0786 Load debug control parameters from system config
  2189. rra ;0789 Rotate right bit 0 (extract interrupt enable flag)
  2190. rra ;078a Rotate right bit 1 (extract trace mode flag)
  2191. and 001h ;078b Mask to keep only bit 0 (interrupt enable for user)
  2192. ld (011d6h),a ;078d Store processed debug control back to memory
  2193. ld a,013h ;0790 Load interrupt vector base 0x13 (table at 0x1300)
  2194. ld i,a ;0792 Set interrupt vector register for system operation
  2195. im 2 ;0794 Set interrupt mode 2 (vectored interrupts)
  2196. ei ;0796 Enable interrupts for system operation
  2197. ld sp,013feh ;0797 Set stack pointer to system stack area (near top of RAM)
  2198. ret ;079a Return with complete CPU state saved
  2199. ; =============================================================================
  2200. ; USER PROGRAM EXECUTION ENGINE
  2201. ; =============================================================================
  2202. ; Purpose: Restore all CPU registers and transfer control to user program
  2203. ; Operation: Complete register restoration from saved state, then execute
  2204. ; Input: Stack contains saved register state, execution address in HL
  2205. ;==============================================================================
  2206. ; USER PROGRAM EXECUTION ENGINE (sub_079bh) - CRITICAL SYSTEM COMPONENT
  2207. ;==============================================================================
  2208. ; Purpose: Complete register restoration and user program execution
  2209. ; Entry: Called from 0x0467 after breakpoint installation or direct execution
  2210. ; Operation: Restore ALL CPU state → Execute user program → Handle completion
  2211. ; Exit: User program runs with full CPU state, returns via interrupt/break
  2212. ;
  2213. ; EXECUTION FLOW:
  2214. ; 1. Breakpoint installed at target address (0x0479)
  2215. ; 2. Control transferred to execution controller (0x0467)
  2216. ; 3. Register restoration engine called (sub_079bh)
  2217. ; 4. Complete CPU state restored from memory (0x011D8)
  2218. ; 5. User program executed via jp (hl)
  2219. ; 6. Returns via interrupt handler when breakpoint hit or error occurs
  2220. ;
  2221. ; REGISTER SAVE AREA LAYOUT (0x011D8):
  2222. ; • AF (main accumulator/flags)
  2223. ; • BC (main register pair)
  2224. ; • DE (main register pair)
  2225. ; • AF' (alternate accumulator/flags)
  2226. ; • BC' (alternate register pair)
  2227. ; • DE' (alternate register pair)
  2228. ; • HL' (alternate register pair)
  2229. ; • IX (index register X)
  2230. ; • IY (index register Y)
  2231. ; • SP (user stack pointer at 0x011EC)
  2232. ;==============================================================================
  2233. sub_079bh: ; User Program Execution Engine - Heart of debugger execution
  2234. pop hl ;079b Get return address from stack (user program target address)
  2235. ld sp,011d8h ;079c Point stack pointer to register save area at 0x011D8
  2236. pop af ;079f Restore main AF (accumulator + flags) from save area
  2237. pop bc ;07a0 Restore main BC register pair from save area
  2238. pop de ;07a1 Restore main DE register pair from save area
  2239. ex af,af' ;07a2 Switch to alternate AF register (prepare for alt restore)
  2240. exx ;07a3 Switch to alternate BC,DE,HL registers (prepare for alt restore)
  2241. pop af ;07a4 Restore alternate AF register from save area
  2242. pop bc ;07a5 Restore alternate BC register from save area
  2243. pop de ;07a6 Restore alternate DE register from save area
  2244. pop hl ;07a7 Restore alternate HL register (contains execution target!)
  2245. pop ix ;07a8 Restore IX index register from save area
  2246. pop iy ;07aa Restore IY index register from save area
  2247. exx ;07ac Switch back to main register set (BC,DE,HL)
  2248. ex af,af' ;07ad Switch back to main AF register
  2249. ld sp,(011ech) ;07ae Restore user's original stack pointer from 0x011EC
  2250. jp (hl) ;07b2 EXECUTE USER PROGRAM! Jump to target in HL register
  2251. ;==============================================================================
  2252. ; INTERRUPT/ERROR HANDLER (0x07B3)
  2253. ;==============================================================================
  2254. ; Purpose: Handle interrupts or errors, display "BREAK AT " message
  2255. ; Called from 0x0066 during error conditions or break events
  2256. ; This appears to be a debugging/error reporting mechanism
  2257. ;==============================================================================
  2258. l07b3h:
  2259. ld (011d4h),hl ;07b3 ; Save HL register for later restoration
  2260. ld hl,l07c1h ;07b6 ; Load address of continuation routine
  2261. ex (sp),hl ;07b9 ; Exchange with return address on stack
  2262. retn ;07ba ; Return from interrupt/error
  2263. l07bch:
  2264. ld (011d4h),hl ;07bc ; Save HL register to memory location 011d4h
  2265. pop hl ;07bf ; Restore HL from stack
  2266. dec hl ;07c0 ; Decrement HL (adjust return address or pointer)
  2267. l07c1h:
  2268. ld (011ech),sp ;07c1 ; Save current stack pointer to 011ech
  2269. ld sp,01400h ;07c5 ; Set new stack pointer to 0x1400 (top of RAM)
  2270. call sub_0770h ;07c8 ; Save all CPU registers and setup interrupt mode 2
  2271. ld de,(011eah) ;07cb ; Load DE from memory pointer 011eah
  2272. ld hl,(011f0h) ;07cf ; Load HL from memory pointer 011f0h
  2273. and a ;07d2 ; Clear carry flag for subtraction
  2274. sbc hl,de ;07d3 ; Compare HL and DE (subtract DE from HL)
  2275. jr nz,l07dfh ;07d5 ; If not equal, jump to boot message routine
  2276. ld hl,011d0h ;07d7 ; Point to counter at 011d0h
  2277. dec (hl) ;07da ; Decrement the counter
  2278. jp nz,l0472h ;07db ; If counter not zero, jump to l0472h
  2279. inc (hl) ;07de ; Restore counter (prevent underflow)
  2280. ; =============================================================================
  2281. ; BREAKPOINT/INTERRUPT HANDLER - Display Break Location=
  2282. ; ============================================================================
  2283. ; Purpose: Display "BREAK AT XXXX" message when execution is interrupted
  2284. ; Input: DE contains the address where the break/interrupt occurred
  2285. ; Output: "BREAK AT XXXX" followed by return to monitor prompt
  2286. ; Used by: Breakpoint system, interrupt handlers, debugging features
  2287. ; =============================================================================
  2288. l07dfh: ; Breakpoint Display Handler
  2289. ld hl,l0803h ;07df ; Point to "BREAK AT " message string
  2290. call l00fdh ;07e2 ; Output the "BREAK AT " text to console
  2291. ex de,hl ;07e5 ; DE = address where break occurred
  2292. call sub_06b8h ;07e6 ; Display break address in 4-digit hex (XXXX format)
  2293. call sub_072ah ;07e9 ; Output newline/formatting
  2294. jp l02cch ;07ec ; Return to monitor command prompt
  2295. l07efh:
  2296. push hl ;07ef
  2297. push af ;07f0
  2298. call sub_04ebh ;07f1
  2299. ld hl,(011d6h) ;07f4
  2300. ld a,h ;07f7
  2301. ld i,a ;07f8
  2302. bit 0,l ;07fa
  2303. jr z,l07ffh ;07fc
  2304. ei ;07fe
  2305. l07ffh:
  2306. pop af ;07ff
  2307. pop hl ;0800
  2308. reti ;0801
  2309. l0803h:
  2310. defb 0x42 ;0803 B
  2311. defb 0x52 ;0804 R
  2312. defb 0x45 ;0805 E
  2313. defb 0x41 ;0806 A
  2314. defb 0x4b ;0807 K
  2315. defb 0x20 ;0808
  2316. defb 0x41 ;0809 A
  2317. defb 0x54 ;080a T
  2318. defb 0x20 ;080b
  2319. defb 0x00 ;080c
  2320. sub_080dh:
  2321. ld a,(011f6h) ;080d
  2322. ld c,a ;0810
  2323. call sub_0127h ;0811
  2324. ld hl,01169h ;0814
  2325. ld (011f4h),hl ;0817
  2326. ld b,0ffh ;081a
  2327. l081ch:
  2328. push bc ;081c ; Save character count and buffer position
  2329. call l0134h ;081d ; Get character from input (blocks until available)
  2330. cp 020h ;0820 ; Compare with space character (0x20)
  2331. jr c,l083ch ;0822 ; Jump to special character handler if control character (0x00-0x1F)
  2332. cp 07fh ;0824 ; Compare with DEL character (0x7F)
  2333. jr z,l083ch ;0826 ; Jump to special character handler for DEL (same as backspace)
  2334. ld (hl),a ;0828
  2335. inc hl ;0829
  2336. call sub_0127h ;082a
  2337. pop bc ;082d
  2338. djnz l081ch ;082e
  2339. l0830h:
  2340. ld (hl),00dh ;0830
  2341. call sub_0862h ;0832
  2342. ld hl,01169h ;0835
  2343. ld a,(hl) ;0838
  2344. jp l0677h ;0839
  2345. l083ch:
  2346. pop bc ;083c
  2347. cp 00dh ;083d ; Check for CR (Carriage Return, Enter key)
  2348. jr z,l0830h ;083f ; Jump to end input processing if Enter pressed
  2349. cp 008h ;0841 ; Check for Backspace (0x08) - character deletion
  2350. jr z,l0849h ;0843 ; Jump to backspace handler
  2351. cp 07fh ;0845 ; Check for DEL (0x7F) - alternative character deletion
  2352. jr nz,l081ch ;0847 ; Continue input loop if not a special character
  2353. ;==============================================================================
  2354. ; BACKSPACE/DELETE CHARACTER HANDLER (0x0849)
  2355. ;==============================================================================
  2356. ; Purpose: Handle character deletion during input (Backspace 0x08 or DEL 0x7F)
  2357. ; Implements standard line editing by removing the previous character from both
  2358. ; the input buffer and the terminal display.
  2359. ;
  2360. ; Visual Feedback Sequence:
  2361. ; 1. Send Backspace (0x08) - moves cursor left one position
  2362. ; 2. Send Space (0x20) - overwrites the character with blank
  2363. ; 3. Send Backspace (0x08) - moves cursor back to correct position
  2364. ;
  2365. ; Buffer Management:
  2366. ; - Decrements buffer pointer (HL) to remove character
  2367. ; - Increments remaining character count (B)
  2368. ; - Prevents deletion beyond start of input buffer
  2369. ;
  2370. ; This provides standard terminal line editing behavior expected by users.
  2371. ;==============================================================================
  2372. l0849h:
  2373. ld a,b ;0849 ; Load remaining character count
  2374. inc a ;084a ; Increment to test for buffer underflow
  2375. l084bh:
  2376. jr z,l081ch ;084b ; Jump back to input loop if at buffer start (no chars to delete)
  2377. push bc ;084d ; Save character count and position
  2378. ld c,008h ;084e ; Load Backspace character (0x08)
  2379. call sub_0127h ;0850 ; Send backspace to terminal (move cursor left)
  2380. ld c,020h ;0853 ; Load Space character (0x20)
  2381. call sub_0127h ;0855 ; Send space to terminal (erase character)
  2382. ld c,008h ;0858 ; Load Backspace character (0x08) again
  2383. call sub_0127h ;085a ; Send backspace to terminal (reposition cursor)
  2384. pop bc ;085d ; Restore character count and position
  2385. inc b ;085e ; Increment remaining character count (one less char used)
  2386. dec hl ;085f ; Move buffer pointer back one position
  2387. jr l081ch ;0860 ; Return to main input loop
  2388. ;==============================================================================
  2389. ; NEWLINE OUTPUT ROUTINE (0x0862)
  2390. ;==============================================================================
  2391. ; Purpose: Send carriage return and line feed to console
  2392. ; This routine outputs a proper newline sequence (CR+LF) to move the cursor
  2393. ; to the beginning of the next line on the terminal.
  2394. ;
  2395. ; Input: None
  2396. ; Output: CR (0x0D) followed by LF (0x0A) sent to console
  2397. ; Used by: Console formatting, command completion, line breaks in output
  2398. ;
  2399. ; Technical Details:
  2400. ; • Preserves BC register during operation
  2401. ; • Uses sub_0127h (console output with transmitter ready check)
  2402. ; • Implements standard DOS/Windows-style line ending (CR+LF)
  2403. ; • Essential for proper terminal cursor positioning
  2404. ;==============================================================================
  2405. sub_0862h:
  2406. push bc ;0862 ; Save BC register
  2407. ld c,00dh ;0863 ; Load Carriage Return character (CR, 0x0D)
  2408. call sub_0127h ;0865 ; Send CR to console (move cursor to line start)
  2409. ld c,00ah ;0868 ; Load Line Feed character (LF, 0x0A)
  2410. call sub_0127h ;086a ; Send LF to console (move cursor to next line)
  2411. pop bc ;086d ; Restore BC register
  2412. ret ;086e ; Return
  2413. ;==============================================================================
  2414. ; PORT INPUT/OUTPUT COMMAND (I/O Operations) - (0x086F-0x0886)
  2415. ;==============================================================================
  2416. ; Purpose: Interactive port I/O operations for hardware testing and control
  2417. ; Allows user to read from and write to I/O ports with hex parameters
  2418. ;
  2419. ; Operation:
  2420. ; 1. Check for 'U' modifier (possibly "UP" or "UPDATE" command)
  2421. ; 2. Parse port address from user input
  2422. ; 3. Read current value from port and display it
  2423. ; 4. Prompt user for new value (or 'Q' to quit without change)
  2424. ; 5. If new value provided, write it to the port
  2425. ;
  2426. ; Usage: I PPPP [VV] where PPPP=port address, VV=optional value to write
  2427. ; Interactive: Shows current port value, prompts for new value
  2428. ;==============================================================================
  2429. l086fh: ; Port I/O command entry point
  2430. call sub_065eh ;086f ; Get next character from input buffer
  2431. cp 055h ;0872 ; Check if character is 'U' (0x55)
  2432. jp z,l0924h ;0874 ; If 'U', jump to special U command handler
  2433. call sub_0680h ;0877 ; Parse port address from user input → HL
  2434. ld c,l ;087a ; Load port address low byte into C
  2435. ld b,h ;087b ; Load port address high byte into B
  2436. in a,(c) ;087c ; Read current value from I/O port
  2437. push bc ;087e ; Save port address
  2438. call sub_0708h ;087f ; Display current port value in hex + prompt for input
  2439. pop bc ;0882 ; Restore port address
  2440. ret z ;0883 ; Return if user pressed 'Q' (quit without changes)
  2441. out (c),a ;0884 ; Write new value (from user input) to I/O port
  2442. ret ;0886 ; Return
  2443. ;==============================================================================
  2444. ; ARITHMETIC CALCULATOR COMMAND (+ Addition/Subtraction) - (0x0887-0x089C)
  2445. ;==============================================================================
  2446. ; Purpose: Perform arithmetic operations on two hex values
  2447. ; Calculates both addition (A+B) and subtraction (A-B) results
  2448. ; Displays both results in hex format for comparison
  2449. ;
  2450. ; Operation:
  2451. ; 1. Parse first hex parameter (A)
  2452. ; 2. Parse second hex parameter (B)
  2453. ; 3. Calculate A+B (addition result)
  2454. ; 4. Calculate A-B (subtraction result)
  2455. ; 5. Display both results in hex format
  2456. ;
  2457. ; Usage: + AAAA BBBB (where AAAA and BBBB are hex values)
  2458. ; Output: Shows both sum and difference in hex format
  2459. ;==============================================================================
  2460. l0887h: ; Arithmetic calculator entry point
  2461. call sub_0680h ;0887 ; Parse first hex parameter → HL (value A)
  2462. push hl ;088a ; Save first parameter (A)
  2463. call sub_0680h ;088b ; Parse second hex parameter → HL (value B)
  2464. ex de,hl ;088e ; Move second parameter (B) to DE
  2465. pop hl ;088f ; Restore first parameter (A) to HL
  2466. push hl ;0890 ; Save first parameter again for subtraction
  2467. add hl,de ;0891 ; Calculate A + B (addition)
  2468. call sub_06b8h ;0892 ; Display addition result in hex format
  2469. pop hl ;0895 ; Restore first parameter (A)
  2470. or a ;0896 ; Clear carry flag for subtraction
  2471. sbc hl,de ;0897 ; Calculate A - B (subtraction)
  2472. call sub_06b8h ;0899 ; Display subtraction result in hex format
  2473. jp sub_072ah ;089c ; Add newline and flush output buffer
  2474. ; =============================================================================
  2475. ; LOAD/TRANSFER DATA COMMAND (L command) - Memory/Storage Operations
  2476. ; =============================================================================
  2477. ; Purpose: Load or transfer data between memory locations or external storage
  2478. ; Input: User enters "L" optionally followed by hex parameters
  2479. ; Operation: Performs data loading/transfer operations with address management
  2480. ; Storage: Working address stored at 0x11CD for ongoing operations
  2481. ; Features: Supports data checksums, address calculations, and transfer loops
  2482. ; =============================================================================
  2483. l089fh: ; L Command (Load/Transfer) Entry Point
  2484. call sub_0917h ;089f Initialize/setup routine for load operations
  2485. call sub_0680h ;08a2 Parse optional hex parameter from user input
  2486. jr nz,l08aah ;08a5 If parameter provided, use it as load address
  2487. ld hl,l0000h ;08a7 Default to address 0x0000 if no parameter given
  2488. l08aah: ; Load operation setup
  2489. ld (011cdh),hl ;08aa Store load/transfer address at 0x11CD (working address)
  2490. ld c,011h ;08ad Set up for operations (C=0x11, might be record type/command)
  2491. call sub_099dh ;08af Call data processing routine (load/transfer handler)
  2492. l08b2h: ; Data format parsing loop
  2493. call sub_0997h ;08b2 Get next character from input stream
  2494. cp 03ah ;08b5 Compare with ':' character (0x3A = ASCII colon)
  2495. jr nz,l08b2h ;08b7 Keep searching until ':' found (record start marker)
  2496. call sub_08f8h ;08b9 Parse hex byte (record length/type)
  2497. ld b,a ;08bc Store parsed value in B register (byte count)
  2498. call sub_08efh ;08bd Parse hex address (load destination address)
  2499. or h ;08c0 Check if address is valid (OR with H register)
  2500. or b ;08c1 Check if byte count is valid (OR with B register)
  2501. jr nz,l08cch ;08c2
  2502. call sub_08efh ;08c4
  2503. ld a,013h ;08c7
  2504. jp sub_099dh ;08c9
  2505. l08cch:
  2506. call sub_08f8h ;08cc
  2507. add a,b ;08cf
  2508. add a,l ;08d0
  2509. add a,h ;08d1
  2510. ld c,a ;08d2
  2511. ld de,(011cdh) ;08d3
  2512. add hl,de ;08d7
  2513. l08d8h:
  2514. call sub_08f8h ;08d8
  2515. ld (hl),a ;08db
  2516. inc hl ;08dc
  2517. add a,c ;08dd
  2518. ld c,a ;08de
  2519. djnz l08d8h ;08df
  2520. call sub_08f8h ;08e1
  2521. add a,c ;08e4
  2522. jr z,l08b2h ;08e5
  2523. ld c,013h ;08e7
  2524. call sub_099dh ;08e9
  2525. jp l02d9h ;08ec
  2526. sub_08efh:
  2527. call sub_08f8h ;08ef
  2528. ld h,a ;08f2
  2529. call sub_08f8h ;08f3
  2530. ld l,a ;08f6
  2531. ret ;08f7
  2532. sub_08f8h:
  2533. push bc ;08f8
  2534. call sub_0907h ;08f9
  2535. add a,a ;08fc
  2536. add a,a ;08fd
  2537. add a,a ;08fe
  2538. add a,a ;08ff
  2539. ld b,a ;0900
  2540. call sub_0907h ;0901
  2541. add a,b ;0904
  2542. pop bc ;0905
  2543. ret ;0906
  2544. sub_0907h:
  2545. call sub_0997h ;0907
  2546. cp 030h ;090a
  2547. jr c,sub_0907h ;090c
  2548. cp 03ah ;090e
  2549. jr c,l0914h ;0910
  2550. sub 007h ;0912
  2551. l0914h:
  2552. and 00fh ;0914
  2553. ret ;0916
  2554. sub_0917h:
  2555. call sub_0662h ;0917
  2556. cp 040h ;091a
  2557. jp z,l06ech ;091c
  2558. dec hl ;091f
  2559. ld (011f4h),hl ;0920
  2560. ret ;0923
  2561. l0924h:
  2562. call sub_0917h ;0924
  2563. call sub_0680h ;0927
  2564. push hl ;092a
  2565. call sub_0680h ;092b
  2566. ld c,012h ;092e
  2567. call sub_099dh ;0930
  2568. pop de ;0933
  2569. l0934h:
  2570. push hl ;0934
  2571. ld b,010h ;0935
  2572. and a ;0937
  2573. sbc hl,de ;0938
  2574. jr c,l0970h ;093a
  2575. ld a,h ;093c
  2576. and a ;093d
  2577. jr nz,l0946h ;093e
  2578. ld a,l ;0940
  2579. cp b ;0941
  2580. jr nc,l0946h ;0942
  2581. ld b,a ;0944
  2582. inc b ;0945
  2583. l0946h:
  2584. ex de,hl ;0946
  2585. ld c,03ah ;0947
  2586. call sub_099dh ;0949
  2587. ld a,b ;094c
  2588. call sub_0985h ;094d
  2589. add a,h ;0950
  2590. add a,l ;0951
  2591. ld c,a ;0952
  2592. call sub_098ah ;0953
  2593. sub a ;0956
  2594. call sub_0985h ;0957
  2595. l095ah:
  2596. ld a,(hl) ;095a
  2597. call sub_0985h ;095b
  2598. add a,c ;095e
  2599. ld c,a ;095f
  2600. inc hl ;0960
  2601. djnz l095ah ;0961
  2602. ld a,c ;0963
  2603. neg ;0964
  2604. call sub_0985h ;0966
  2605. pop de ;0969
  2606. ex de,hl ;096a
  2607. call sub_074dh ;096b
  2608. jr l0934h ;096e
  2609. l0970h:
  2610. pop hl ;0970
  2611. ld c,03ah ;0971
  2612. call sub_099dh ;0973
  2613. ld b,00ah ;0976
  2614. ld c,030h ;0978
  2615. l097ah:
  2616. call sub_099dh ;097a
  2617. djnz l097ah ;097d
  2618. ld c,014h ;097f
  2619. call sub_099dh ;0981
  2620. ret ;0984
  2621. sub_0985h:
  2622. call sub_06c6h ;0985
  2623. jr l098dh ;0988
  2624. sub_098ah:
  2625. call sub_06b8h ;098a
  2626. l098dh:
  2627. push hl ;098d
  2628. ld hl,(011f2h) ;098e
  2629. dec hl ;0991
  2630. ld (011f2h),hl ;0992
  2631. pop hl ;0995
  2632. ret ;0996
  2633. sub_0997h:
  2634. push bc ;0997
  2635. call l0116h ;0998
  2636. pop bc ;099b
  2637. ret ;099c
  2638. sub_099dh:
  2639. push bc ;099d
  2640. call sub_0111h ;099e
  2641. pop bc ;09a1 ; Restore BC register
  2642. ret ;09a2 ; Return from routine
  2643. ;==============================================================================
  2644. ; CONTROL CHARACTER HANDLER (0x09A3)
  2645. ;==============================================================================
  2646. ; Purpose: Process special control characters during input operations
  2647. ; This routine intercepts and handles special ASCII control characters that
  2648. ; require immediate system response, providing user control over operations.
  2649. ;
  2650. ; Control Characters Handled:
  2651. ; • 0x03 (ETX, Ctrl+C): Emergency system reset/break
  2652. ; • 0x13 (XOFF, Ctrl+S): Pause/resume output flow control
  2653. ;
  2654. ; Character Processing:
  2655. ; 1. Call input routine (sub_013ah) to get character
  2656. ; 2. Check for zero (no character available)
  2657. ; 3. Compare with control character codes
  2658. ; 4. Take appropriate action or return
  2659. ;
  2660. ; Flow Control Features:
  2661. ; • Preserves BC register across all operations
  2662. ; • Returns immediately if no character or unrecognized character
  2663. ; • Provides clean stack management for nested calls
  2664. ; • Implements standard terminal control behavior
  2665. ;==============================================================================
  2666. sub_09a3h:
  2667. push bc ;09a3 ; Save BC register
  2668. call sub_013ah ;09a4 ; Get character from input (keyboard/serial)
  2669. pop bc ;09a7 ; Restore BC register
  2670. ret z ;09a8 ; Return if no character available (zero flag set)
  2671. cp 003h ;09a9 ; Check for ETX (End of Text, Ctrl+C)
  2672. jr z,l09b6h ;09ab ; Jump to system reset if Ctrl+C pressed
  2673. cp 013h ;09ad ; Check for XOFF (Ctrl+S, pause)
  2674. ret nz ;09af ; Return if not XOFF
  2675. push bc ;09b0 ; Save BC register
  2676. call l0134h ;09b1 ; Handle XOFF (pause/resume) functionality
  2677. pop bc ;09b4 ; Restore BC register
  2678. ret ;09b5 ; Return from XOFF handling
  2679. ;==============================================================================
  2680. ; SYSTEM RESET/RESTART ROUTINE (0x09B6)
  2681. ;==============================================================================
  2682. ; Purpose: Emergency system reset triggered by Ctrl+C (ETX) character
  2683. ; This routine provides a clean way to abort current operations and return
  2684. ; to the monitor command prompt, similar to a "break" or "interrupt" function.
  2685. ;
  2686. ; Trigger Conditions:
  2687. ; • Ctrl+C (0x03 ETX character) received during input processing
  2688. ; • User wants to abort current operation and return to monitor
  2689. ; • Emergency recovery from hung or problematic operations
  2690. ;
  2691. ; Reset Actions:
  2692. ; 1. Reset stack pointer to system default (0x1400)
  2693. ; 2. Jump directly to main monitor command loop
  2694. ; 3. Bypass any pending operations or nested calls
  2695. ;
  2696. ; Technical Details:
  2697. ; • Stack Reset: SP = 0x1400 (top of RAM workspace)
  2698. ; • Direct Jump: Goes to 0x02CC (main monitor loop entry)
  2699. ; • Clean State: Abandons current call stack and variables
  2700. ; • User Interface: Provides immediate return to ">" prompt
  2701. ;
  2702. ; This implements a standard "Ctrl+C break" behavior found in many systems
  2703. ; of this era, allowing users to escape from problematic situations.
  2704. ;==============================================================================
  2705. l09b6h:
  2706. ld sp,01400h ;09b6 ; Reset stack pointer to system default
  2707. jp l02cch ;09b9 ; Jump to main monitor command loop (clean restart)
  2708. ;==============================================================================
  2709. ; FLOPPY DISK CONTROLLER COMMAND HANDLER (0x09BC-0x09F9)
  2710. ;==============================================================================
  2711. ; Purpose: Parse and validate floppy disk control parameters
  2712. ; Input Format: Multiple hex parameters specifying drive, track, sector settings
  2713. ; Parameters:
  2714. ; • Drive Number (0-3): Selects physical floppy drive unit
  2715. ; • Control Flags (0-1): Drive control options and formatting modes
  2716. ; • Track/Cylinder (0-76): Physical track number on disk (max 77 tracks)
  2717. ; • Sector Count (1-26): Number of sectors to process (max 27 sectors)
  2718. ;
  2719. ; Memory Storage Locations:
  2720. ; • 0x1202: Drive number (0-3)
  2721. ; • 0x1226: Drive control flags (0 or 1)
  2722. ; • 0x1225: Track/cylinder number (0-76)
  2723. ; • 0x1227: Sector count (1-26)
  2724. ; • 0x11F7: Operation status flag (set to 0xFF when ready)
  2725. ;
  2726. ; Error Handling: Jumps to l02d9h (error handler) for invalid parameters
  2727. ; Used by: Floppy disk read/write/format operations via NEC µPD765A FDC
  2728. ;==============================================================================
  2729. l09bch: ; Floppy Disk Parameter Parser Entry Point
  2730. call sub_065eh ;09bc Get next character from input buffer
  2731. cp 053h ;09bf Compare with 'S' (0x53 = ASCII 'S' for special command)
  2732. jp z,l0fbbh ;09c1 If 'S', jump to special disk handler
  2733. call sub_0680h ;09c4 Parse hex parameter (drive number)
  2734. cp 004h ;09c7 Check if drive number >= 4 (invalid)
  2735. jp nc,l02d9h ;09c9 Jump to error if invalid drive number
  2736. ld (01202h),a ;09cc Store valid drive number (0-3)
  2737. call sub_0680h ;09cf Get next parameter from input
  2738. cp 002h ;09d2 Check if parameter < 2 (valid range)
  2739. jp nc,l02d9h ;09d4 Jump to error if parameter >= 2
  2740. ld (01226h),a ;09d7 Store drive control flags (0 or 1)
  2741. call sub_0680h ;09da Get next parameter from input
  2742. cp 04dh ;09dd Check if parameter < 77 (0x4D, max tracks)
  2743. jp nc,l02d9h ;09df Jump to error if parameter >= 77
  2744. ld (01225h),a ;09e2 Store drive parameter/selector (track/cylinder)
  2745. call sub_0680h ;09e5 Parse final parameter (sector count)
  2746. or a ;09e8 Check if sector count is zero (invalid)
  2747. jp z,l02d9h ;09e9 Jump to error if zero sectors specified
  2748. cp 01bh ;09ec Check if sector count >= 27 (0x1B, max sectors)
  2749. jp nc,l02d9h ;09ee Jump to error if too many sectors
  2750. ld (01227h),a ;09f1 Store valid sector count (1-26)
  2751. ld a,0ffh ;09f4 Load 0xFF (operation ready flag)
  2752. ld (011f7h),a ;09f6 Set operation status flag (ready for disk operations)
  2753. ret ;09f9 Return to caller with parameters validated and stored
  2754. ld hl,l0db1h ;09fa
  2755. jr l0a0ah ;09fd
  2756. call sub_065eh ;09ff
  2757. cp 04fh ;0a02
  2758. jp z,l089fh ;0a04
  2759. ld hl,l0dabh ;0a07
  2760. l0a0ah:
  2761. ld (011f8h),hl ;0a0a
  2762. ld hl,011f7h ;0a0d
  2763. xor a ;0a10
  2764. cp (hl) ;0a11
  2765. jp z,l02d9h ;0a12
  2766. ld (hl),a ;0a15
  2767. call l0de0h ;0a16
  2768. call sub_0680h ;0a19
  2769. push hl ;0a1c
  2770. call sub_0680h ;0a1d
  2771. pop de ;0a20
  2772. ex de,hl ;0a21
  2773. l0a22h:
  2774. or a ;0a22
  2775. inc hl ;0a23
  2776. sbc hl,de ;0a24
  2777. add hl,de ;0a26
  2778. dec hl ;0a27
  2779. ret nc ;0a28
  2780. ld (01200h),hl ;0a29
  2781. push de ;0a2c
  2782. push hl ;0a2d
  2783. ld hl,(011f8h) ;0a2e
  2784. call sub_0da8h ;0a31
  2785. jr nc,l0a60h ;0a34
  2786. ld hl,01227h ;0a36
  2787. ld a,(hl) ;0a39
  2788. inc a ;0a3a
  2789. ld (hl),a ;0a3b
  2790. cp 01bh ;0a3c
  2791. jr c,l0a51h ;0a3e
  2792. ld (hl),001h ;0a40
  2793. ld a,(01203h) ;0a42
  2794. or a ;0a45
  2795. jr z,l0a4dh ;0a46
  2796. dec hl ;0a48
  2797. ld a,(hl) ;0a49
  2798. xor 001h ;0a4a
  2799. ld (hl),a ;0a4c
  2800. l0a4dh:
  2801. jr nz,l0a51h ;0a4d
  2802. dec hl ;0a4f
  2803. inc (hl) ;0a50
  2804. l0a51h:
  2805. ld a,(01203h) ;0a51
  2806. or a ;0a54
  2807. ld hl,l0080h ;0a55
  2808. jr z,l0a5bh ;0a58
  2809. add hl,hl ;0a5a
  2810. l0a5bh:
  2811. pop de ;0a5b
  2812. add hl,de ;0a5c
  2813. pop de ;0a5d
  2814. jr l0a22h ;0a5e
  2815. l0a60h:
  2816. ld hl,l0a69h ;0a60
  2817. call l00fdh ;0a63
  2818. jp l02d9h ;0a66
  2819. l0a69h:
  2820. defb 0x44 ;0a69 D
  2821. defb 0x49 ;0a6a I
  2822. defb 0x53 ;0a6b S
  2823. defb 0x4b ;0a6c K
  2824. defb 0x20 ;0a6d
  2825. defb 0x45 ;0a6e E
  2826. defb 0x52 ;0a6f R
  2827. defb 0x52 ;0a70 R
  2828. defb 0x0d ;0a71 RETURN
  2829. defb 0x0a ;0a72 RETURN
  2830. defb 0x00 ;0a73
  2831. l0a74h:
  2832. call sub_0680h ;0a74 Get drive number parameter from user input
  2833. cp 004h ;0a77 Check if drive number >= 4 (invalid)
  2834. jp nc,l02d9h ;0a79 Jump to error if invalid drive number
  2835. ld (01202h),a ;0a7c Store current drive number (0-3)
  2836. call sub_0e43h ;0a7f Execute drive operation
  2837. jp nc,l0a60h ;0a82
  2838. ret ;0a85
  2839. l0a86h:
  2840. call sub_0acbh ;0a86
  2841. jp nc,l0a60h ;0a89
  2842. ret ;0a8c
  2843. ;==============================================================================
  2844. ; FLOPPY DISK CONTROLLER INITIALIZATION (0x0A8D)
  2845. ;==============================================================================
  2846. ; Purpose: Initialize NEC µPD765A floppy disk controller and Z80 DMA
  2847. ; Hardware Setup:
  2848. ; - Port 0xF6: FDC command/status register
  2849. ; - Port 0xF3: Z80 DMA control register (standalone Z80 DMA chip)
  2850. ; - Port 0xF0: FDC main status register
  2851. ; - Port 0xF4: FDC data register
  2852. ;
  2853. ; Z80 DMA Operations:
  2854. ; - Value 0x08: Enable Z80 DMA for floppy transfers
  2855. ; - Clear bit 3: Modify DMA transfer mode parameters
  2856. ; - Two-stage DMA setup for optimal transfer configuration
  2857. ;
  2858. ; Operation:
  2859. ; 1. Send "specify" command to FDC (configure timing parameters)
  2860. ; 2. Enable Z80 DMA controller for high-speed transfers
  2861. ; 3. Modify DMA transfer mode settings
  2862. ; 4. Wait for FDC ready status
  2863. ; 5. Configure for read/write operations
  2864. ;
  2865. ; Returns: Carry flag set if successful, clear if failed
  2866. ;==============================================================================
  2867. sub_0a8dh:
  2868. ld a,003h ;0a8d ; Load FDC "specify" command
  2869. out (0f6h),a ;0a8f ; Send command to FDC command register
  2870. ld a,008h ;0a91 ; Load Z80 DMA enable control value
  2871. out (0f3h),a ;0a93 ; Enable Z80 DMA for floppy operations
  2872. res 3,a ;0a95 ; Clear bit 3 (modify DMA transfer mode)
  2873. out (0f3h),a ;0a97 ; Update Z80 DMA control register
  2874. ld bc,sub_011ch ;0a99 ; Load timeout/delay parameters
  2875. call sub_0f0ah ;0a9c ; Call delay/timing routine
  2876. ld bc,l0000h ;0a9f ; Initialize counter for FDC status polling
  2877. ;==============================================================================
  2878. ; FDC STATUS POLLING LOOP (0x0AA2)
  2879. ;==============================================================================
  2880. ; Purpose: Wait for FDC to become ready for command execution
  2881. ; This is a critical timing loop that ensures the NEC µPD765A FDC is ready
  2882. ; to accept commands before proceeding with disk operations.
  2883. ;
  2884. ; Hardware Details:
  2885. ; - Port 0xF0: NEC µPD765A Main Status Register (MSR)
  2886. ; - Bit 7 of MSR: RQM (Request for Master) - indicates FDC ready state
  2887. ; - Timeout: 65536 iterations (BC=0x0000 decrements to 0xFFFF then 0x0000)
  2888. ;
  2889. ; Status Register Interpretation:
  2890. ; - MSR bit 7 = 1: FDC ready to accept commands/data
  2891. ; - MSR bit 7 = 0: FDC busy, continue polling
  2892. ; - Expected final state: MSR = 0x80 (only RQM bit set)
  2893. ;
  2894. ; Returns:
  2895. ; - Zero flag set: Timeout occurred (FDC never became ready)
  2896. ; - Zero flag clear: FDC ready, A contains final status
  2897. ; - A = 0x00: Success (MSR was exactly 0x80)
  2898. ; - A ≠ 0x00: Warning (MSR had unexpected bits set)
  2899. ;==============================================================================
  2900. l0aa2h:
  2901. dec bc ;0aa2 ; Decrement timeout counter
  2902. ld a,b ;0aa3 ; Load high byte of counter
  2903. or c ;0aa4 ; OR with low byte to test for zero
  2904. ret z ;0aa5 ; Return if timeout (BC reached 0x0000)
  2905. in a,(0f0h) ;0aa6 ; Read FDC Main Status Register
  2906. bit 7,a ;0aa8 ; Test RQM bit (Request for Master)
  2907. jr z,l0aa2h ;0aaa ; Loop if FDC not ready (RQM=0)
  2908. xor 080h ;0aac ; XOR with 0x80 to check if only RQM bit set
  2909. ret nz ;0aae ; Return if other status bits are set (error condition)
  2910. ;==============================================================================
  2911. ; FDC COMMAND EXECUTION SETUP (0x0AAF)
  2912. ;==============================================================================
  2913. ; Purpose: Execute FDC commands and wait for completion status
  2914. ; This section handles the command execution phase after the FDC is ready.
  2915. ; It coordinates with the NEC µPD765A to execute disk operations.
  2916. ;
  2917. ; Operation Flow:
  2918. ; 1. Call command execution routine (sub_0ba7h)
  2919. ; 2. Wait for command completion (status 0x80)
  2920. ; 3. Setup interrupt vector for DMA completion
  2921. ; 4. Configure DMA parameters for data transfer
  2922. ;
  2923. ; Hardware Configuration:
  2924. ; - Port 0xF4: FDC data register for parameter passing
  2925. ; - Port 0xF6: FDC command register
  2926. ; - Memory 0x1334: Interrupt vector table pointer
  2927. ; - Address 0x0BB6: DMA completion handler
  2928. ;
  2929. ; Status Codes:
  2930. ; - 0x80: Command execution successful, ready for data transfer
  2931. ; - Other: Command still executing or error condition
  2932. ;==============================================================================
  2933. l0aafh:
  2934. call sub_0ba7h ;0aaf ; Execute FDC command sequence
  2935. ret nc ;0ab2 ; Return if command execution failed
  2936. cp 080h ;0ab3 ; Check if execution status is 0x80 (success)
  2937. jr nz,l0aafh ;0ab5 ; Loop until command completes successfully
  2938. ld hl,l0bb6h ;0ab7 ; Load address of DMA completion handler
  2939. ld (01334h),hl ;0aba ; Store in interrupt vector table
  2940. ld a,030h ;0abd ; Load DMA control parameter
  2941. out (0f4h),a ;0abf ; Send to FDC data register
  2942. ld a,0d7h ;0ac1 ; Load FDC command parameter
  2943. out (0f6h),a ;0ac3 ; Send command to FDC
  2944. ld a,001h ;0ac5 ; Load final parameter
  2945. out (0f6h),a ;0ac7 ; Complete command sequence
  2946. scf ;0ac9 ; Set carry flag (success indicator)
  2947. ret ;0aca ; Return with success status
  2948. ;==============================================================================
  2949. ; FLOPPY DISK CONTROLLER MASTER ROUTINE (0x0ACB)
  2950. ;==============================================================================
  2951. ; Purpose: Main floppy disk operation coordinator
  2952. ; Calls sub-routines to:
  2953. ; 1. Initialize FDC and prepare for disk operations (sub_0a8dh)
  2954. ; 2. Execute disk read/write operations (sub_0ae9h)
  2955. ; 3. Loop through multiple drives/sectors (0x0AD8 loop)
  2956. ;
  2957. ; This appears to be the high-level disk I/O interface that coordinates
  2958. ; multiple disk operations across different drives (up to 4 drives/sectors)
  2959. ;==============================================================================
  2960. sub_0acbh:
  2961. call sub_0a8dh ;0acb ; Initialize FDC hardware and prepare for operation
  2962. ret nc ;0ace ; Return if FDC initialization failed
  2963. call sub_0ae9h ;0acf ; Execute the actual disk operation
  2964. ret nc ;0ad2
  2965. xor a ;0ad3 A = 0 (start with drive 0)
  2966. ld iy,01205h ;0ad4 Point IY to drive status table
  2967. l0ad8h: ; Multi-drive boot loop (tries drives 0,1,2,3)
  2968. push af ;0ad8 Save current drive number
  2969. ld (01202h),a ;0ad9 Set current drive number (0x1202)
  2970. call sub_0b1ch ;0adc Attempt to read boot sector from current drive
  2971. pop af ;0adf Restore drive number
  2972. inc iy ;0ae0 Move to next drive status entry
  2973. inc a ;0ae2 Next drive number (0→1→2→3)
  2974. cp 004h ;0ae3 Check if tried all 4 drives
  2975. jr nz,l0ad8h ;0ae5 Loop until all drives tested
  2976. scf ;0ae7 Set carry flag (success)
  2977. ret ;0ae8 Return from multi-drive scan
  2978. ;==============================================================================
  2979. ; FDC COMMAND PARAMETER SETUP (0x0AE9)
  2980. ;==============================================================================
  2981. ; Purpose: Prepare NEC µPD765A command parameters for disk operations
  2982. ; This routine builds the command parameter block required by the FDC to
  2983. ; execute read/write operations. The parameters are assembled from various
  2984. ; system variables and formatted according to NEC µPD765A specifications.
  2985. ;
  2986. ; Memory Layout - FDC Parameter Block (0x1213-0x1215):
  2987. ; • 0x1213: Command byte (0x03 = READ DATA command)
  2988. ; • 0x1214: Drive/Head selection and DMA control
  2989. ; • 0x1215: Track/Sector/Size parameters
  2990. ;
  2991. ; Parameter Sources:
  2992. ; • 0x120B: Drive geometry configuration (tracks, density)
  2993. ; • 0x120A: Head selection and DMA mode settings
  2994. ; • 0x1209: Sector size and format parameters
  2995. ; • 0x1204: Additional drive control flags
  2996. ;
  2997. ; NEC µPD765A Command Format:
  2998. ; - Bit manipulation ensures proper head selection and DMA modes
  2999. ; - Rotation and masking operations format multi-bit parameters
  3000. ; - Command block follows standard FDC command structure
  3001. ;==============================================================================
  3002. sub_0ae9h:
  3003. ld hl,01213h ;0ae9 ; Point to FDC command parameter block
  3004. push hl ;0aec ; Save base pointer for later use
  3005. ld (hl),003h ;0aed ; Set command byte: 0x03 = READ DATA command
  3006. inc hl ;0aef ; Move to drive/head parameter byte (0x1214)
  3007. ld a,(0120bh) ;0af0 ; Load drive geometry configuration
  3008. and 00fh ;0af3 ; Mask to get lower 4 bits (drive geometry)
  3009. sub 011h ;0af5 ; Subtract 0x11 (adjust for FDC format)
  3010. cpl ;0af7 ; Complement bits (invert for FDC encoding)
  3011. rlca ;0af8 ; Rotate left 4 positions to place in upper nibble
  3012. rlca ;0af9 ; (4 rotations = shift left 4 bits)
  3013. rlca ;0afa
  3014. rlca ;0afb
  3015. ld (hl),a ;0afc ; Store formatted drive parameter
  3016. ld a,(0120ah) ;0afd ; Load head selection and DMA mode
  3017. rrca ;0b00 ; Rotate right 4 positions to get lower nibble
  3018. rrca ;0b01 ; (4 rotations = shift right 4 bits)
  3019. rrca ;0b02
  3020. rrca ;0b03
  3021. and 00fh ;0b04 ; Mask to keep only lower 4 bits
  3022. or (hl) ;0b06 ; Combine with previous drive parameter
  3023. ld (hl),a ;0b07 ; Store combined drive/head parameter
  3024. inc hl ;0b08 ; Move to track/sector parameter byte (0x1215)
  3025. ld a,(01209h) ;0b09 ; Load sector size and format configuration
  3026. res 0,a ;0b0c ; Clear bit 0 (modify sector size encoding)
  3027. ld (hl),a ;0b0e ; Store modified sector parameter
  3028. ld a,(01204h) ;0b0f ; Load additional drive control flags
  3029. and 001h ;0b12 ; Mask to get only bit 0 (specific control flag)
  3030. or (hl) ;0b14 ; Combine with sector parameter
  3031. ld (hl),a ;0b15 ; Store final track/sector/control parameter
  3032. ld b,003h ;0b16 ; Set parameter count: 3 bytes for FDC command
  3033. pop hl ;0b18 ; Restore base pointer to command block
  3034. jp l0b64h ;0b19 ; Jump to FDC command execution routine
  3035. ;==============================================================================
  3036. ; FDC OPERATION WITH PARAMETER MANAGEMENT (0x0B1C)
  3037. ;==============================================================================
  3038. ; Purpose: Execute FDC operations with automatic parameter backup/restore
  3039. ; This routine provides a higher-level interface for disk operations that
  3040. ; temporarily modifies drive parameters and ensures they are properly restored
  3041. ; even if the operation fails.
  3042. ;
  3043. ; Operation Flow:
  3044. ; 1. Prepare FDC for operation (sub_0b33h)
  3045. ; 2. Backup current drive parameter (0x1225)
  3046. ; 3. Set temporary parameter (0x03) for operation
  3047. ; 4. Execute disk operation (sub_0c05h)
  3048. ; 5. Restore original parameter regardless of operation result
  3049. ; 6. Verify FDC is ready for next operation
  3050. ;
  3051. ; Memory Locations:
  3052. ; • 0x1225: Drive parameter/selector register (backed up and restored)
  3053. ; • Value 0x03: Temporary parameter setting for this operation type
  3054. ;
  3055. ; Error Handling:
  3056. ; - Parameters are restored even if disk operation fails
  3057. ; - Final FDC readiness check before returning
  3058. ; - Carry flag indicates overall operation success
  3059. ;==============================================================================
  3060. sub_0b1ch:
  3061. call sub_0b33h ;0b1c ; Prepare FDC for operation
  3062. ld a,(01225h) ;0b1f ; Load current drive parameter
  3063. push af ;0b22 ; Save parameter on stack for restoration
  3064. ld a,003h ;0b23 ; Load temporary parameter value
  3065. ld (01225h),a ;0b25 ; Set temporary drive parameter
  3066. call sub_0c05h ;0b28 ; Execute disk operation
  3067. pop af ;0b2b ; Restore original parameter from stack
  3068. ld (01225h),a ;0b2c ; Write back original drive parameter
  3069. call sub_0b33h ;0b2f ; Verify FDC readiness after operation
  3070. ret c ;0b32 ; Return if FDC is ready (carry set = success)
  3071. ;==============================================================================
  3072. ; FDC RECALIBRATE AND COMMAND SETUP (0x0B33)
  3073. ;==============================================================================
  3074. ; Purpose: Prepare FDC for operation with recalibrate command and status monitoring
  3075. ; This routine initializes the FDC to a known state and sets up a recalibrate
  3076. ; command for reliable disk operations. Used both before and after disk operations
  3077. ; to ensure the drive heads are properly positioned.
  3078. ;
  3079. ; Operation Sequence:
  3080. ; 1. Set drive status to 0xFF (reset/initialize state)
  3081. ; 2. Execute low-level FDC preparation (sub_0d2eh)
  3082. ; 3. Clear status flags and setup command parameters
  3083. ; 4. Configure RECALIBRATE command (0x07) with drive parameters
  3084. ; 5. Wait for command completion with timeout monitoring
  3085. ;
  3086. ; Hardware Details:
  3087. ; • IY register: Points to drive status table (set by caller)
  3088. ; • 0x1226: Drive control flags cleared during operation
  3089. ; • 0x1213: Command byte set to 0x07 (RECALIBRATE command)
  3090. ; • 0x124A: Operation completion status flag
  3091. ;
  3092. ; NEC µPD765A RECALIBRATE Command:
  3093. ; - Moves drive head to track 0 (cylinder 0)
  3094. ; - Establishes known reference position for subsequent seeks
  3095. ; - Required after drive selection or power-on sequences
  3096. ;==============================================================================
  3097. sub_0b33h:
  3098. ld (iy+000h),0ffh ;0b33 ; Set drive status to 0xFF (initialize state)
  3099. call sub_0d2eh ;0b37 ; Execute low-level FDC preparation routine
  3100. ret nc ;0b3a ; Return if FDC preparation failed (carry clear)
  3101. xor a ;0b3b ; Load 0 into accumulator
  3102. ld (01226h),a ;0b3c ; Clear drive control flags
  3103. ld hl,01213h ;0b3f ; Point to FDC command parameter block
  3104. push hl ;0b42 ; Save command block pointer
  3105. ld (hl),007h ;0b43 ; Set command byte: 0x07 = RECALIBRATE command
  3106. inc hl ;0b45 ; Move to next parameter byte
  3107. call sub_0b7bh ;0b46 ; Setup additional command parameters
  3108. xor a ;0b49 ; Load 0 into accumulator
  3109. ld (0124ah),a ;0b4a ; Clear operation completion status flag
  3110. ld b,002h ;0b4d ; Set parameter count: 2 bytes for RECALIBRATE command
  3111. pop hl ;0b4f ; Restore command block pointer
  3112. call l0b64h ;0b50 ; Send command to FDC
  3113. ret nc ;0b53 ; Return if command transmission failed
  3114. ;==============================================================================
  3115. ; RECALIBRATE COMPLETION MONITORING (0x0B54)
  3116. ;==============================================================================
  3117. ; Purpose: Wait for RECALIBRATE command completion with status validation
  3118. ; Monitors the operation completion flag and validates the final status to
  3119. ; ensure the recalibrate operation completed successfully.
  3120. ;
  3121. ; Status Monitoring:
  3122. ; • 0x124A: Operation completion flag (0=pending, non-zero=completed)
  3123. ; • Expected completion status: 0x20 (recalibrate successful)
  3124. ; • Status mask 0xF8: Checks upper 5 bits for error conditions
  3125. ;
  3126. ; Returns:
  3127. ; • Carry set: RECALIBRATE completed successfully, drive ready
  3128. ; • Carry clear: RECALIBRATE failed or timeout occurred
  3129. ;==============================================================================
  3130. l0b54h:
  3131. ld a,(0124ah) ;0b54 ; Read operation completion status
  3132. or a ;0b57 ; Test if operation completed (non-zero)
  3133. jr z,l0b54h ;0b58 ; Loop until completion flag is set
  3134. and 0f8h ;0b5a ; Mask upper 5 bits to check for errors
  3135. xor 020h ;0b5c ; Compare with expected success status (0x20)
  3136. ret nz ;0b5e ; Return with carry clear if not successful
  3137. ld (iy+000h),a ;0b5f ; Store final status (0x00) in drive status
  3138. scf ;0b62 ; Set carry flag (operation successful)
  3139. ret ;0b63 ; Return with success status
  3140. ;==============================================================================
  3141. ; FLOPPY CONTROLLER I/O TRANSMITTER (0x0B64)
  3142. ;==============================================================================
  3143. ; Purpose: Send command bytes to floppy controller via I/O ports
  3144. ; Input: HL = pointer to command buffer, B = byte count, C = 0xF1 (data port)
  3145. ;
  3146. ; Function:
  3147. ; - Waits for floppy controller ready (port 0xF0 status bits 0-4 clear)
  3148. ; - Polls bit 7 of status port 0xF0 for command ready signal
  3149. ; - Checks bit 6 for transfer direction/error condition
  3150. ; - Uses OUTI instruction to send bytes from buffer to port 0xF1
  3151. ; - Continues until all B bytes transmitted
  3152. ;
  3153. ; Ports Used:
  3154. ; - 0xF0: Floppy controller status register
  3155. ; - Bit 7: Command ready flag
  3156. ; - Bit 6: Direction/error flag
  3157. ; - Bits 0-4: Various status conditions
  3158. ; - 0xF1: Floppy controller data register (via register C)
  3159. ;
  3160. ; Returns: Carry set on success, clear on error
  3161. ;==============================================================================
  3162. l0b64h:
  3163. ld c,0f1h ;0b64
  3164. l0b66h:
  3165. in a,(0f0h) ;0b66
  3166. and 01fh ;0b68
  3167. jr nz,l0b66h ;0b6a
  3168. l0b6ch:
  3169. in a,(0f0h) ;0b6c
  3170. bit 7,a ;0b6e
  3171. jr z,l0b6ch ;0b70
  3172. and 040h ;0b72
  3173. ret nz ;0b74
  3174. outi ;0b75
  3175. jr nz,l0b6ch ;0b77
  3176. scf ;0b79
  3177. ret ;0b7a
  3178. ;==============================================================================
  3179. ; FLOPPY COMMAND PARAMETER BUILDER (0x0B7B)
  3180. ;==============================================================================
  3181. ; Purpose: Build drive and head selection parameters for floppy commands
  3182. ; Input: HL = pointer to command buffer (pointing to parameter byte location)
  3183. ;
  3184. ; Function:
  3185. ; - Reads drive selection from 0x1226, rotates left twice (bits 6-7 → bits 0-1)
  3186. ; - Combines with head selection from 0x1202
  3187. ; - Stores combined drive/head parameter in command buffer
  3188. ; - Advances buffer pointer for next parameter
  3189. ;
  3190. ; Parameter Format:
  3191. ; - Bits 0-1: Drive number (from 0x1226 bits 6-7)
  3192. ; - Other bits: Head selection and flags (from 0x1202)
  3193. ;
  3194. ; Memory Locations:
  3195. ; - 0x1226: Drive selection (bits 6-7 used)
  3196. ; - 0x1202: Head selection and other flags
  3197. ;==============================================================================
  3198. sub_0b7bh:
  3199. ld a,(01226h) ;0b7b
  3200. rlca ;0b7e
  3201. rlca ;0b7f
  3202. ld (hl),a ;0b80
  3203. ld a,(01202h) ;0b81
  3204. or (hl) ;0b84
  3205. ld (hl),a ;0b85
  3206. inc hl ;0b86
  3207. ret ;0b87
  3208. ;==============================================================================
  3209. ; FLOPPY CONTROLLER RESPONSE READER (0x0B88)
  3210. ;==============================================================================
  3211. ; Purpose: Read response bytes from floppy controller after command execution
  3212. ;
  3213. ; Function:
  3214. ; - Sets up response buffer at 0x121C
  3215. ; - Uses port 0xF1 for data input (via register C)
  3216. ; - Implements timeout loop (B=0x0A iterations)
  3217. ; - Polls port 0xF0 status register:
  3218. ; - Bit 4: Data ready flag
  3219. ; - Bit 7: Controller ready flag
  3220. ; - Bit 6: Direction/completion flag
  3221. ; - Uses INI instruction to read bytes from port 0xF1 to buffer
  3222. ; - Returns first response byte and sets carry on success
  3223. ;
  3224. ; Timeout Handling:
  3225. ; - 10-iteration outer loop for timeout protection
  3226. ; - Inner delay loop for timing control
  3227. ; - Returns with carry clear on timeout
  3228. ;
  3229. ; Returns: A = first response byte, Carry = success flag
  3230. ;==============================================================================
  3231. l0b88h:
  3232. ld hl,0121ch ;0b88
  3233. ld c,0f1h ;0b8b
  3234. l0b8dh:
  3235. ld b,00ah ;0b8d
  3236. l0b8fh:
  3237. djnz l0b8fh ;0b8f
  3238. l0b91h:
  3239. in a,(0f0h) ;0b91
  3240. bit 4,a ;0b93
  3241. jr z,l0ba2h ;0b95
  3242. bit 7,a ;0b97
  3243. jr z,l0b91h ;0b99
  3244. and 040h ;0b9b
  3245. ret z ;0b9d
  3246. ini ;0b9e
  3247. jr l0b8dh ;0ba0
  3248. l0ba2h:
  3249. ld a,(0121ch) ;0ba2
  3250. scf ;0ba5
  3251. ret ;0ba6
  3252. sub_0ba7h:
  3253. ld hl,01213h ;0ba7
  3254. ld (hl),008h ;0baa
  3255. ld bc,001f1h ;0bac
  3256. call l0b6ch ;0baf
  3257. ret nc ;0bb2
  3258. jp l0b88h ;0bb3
  3259. l0bb6h:
  3260. push af ;0bb6
  3261. push hl ;0bb7
  3262. push bc ;0bb8
  3263. push de ;0bb9
  3264. l0bbah:
  3265. in a,(0f0h) ;0bba ; Read floppy controller main status register
  3266. bit 7,a ;0bbc ; Test READY bit (controller ready)
  3267. jr z,l0bbah ;0bbe ; Wait until controller is ready
  3268. bit 6,a ;0bc0 ; Test DATA_REQUEST bit (controller needs data)
  3269. jr z,l0bd9h ;0bc2 ; If no data request, handle differently
  3270. ld a,083h ;0bc4 ; Load DMA command 0x83
  3271. out (0fch),a ;0bc6 ; Send command to Z80 DMA controller port 0xFC
  3272. ; ; 0x83 = DMA control command for FDC coordination
  3273. ld (0124bh),a ;0bc8
  3274. call l0b88h ;0bcb
  3275. ld hl,0121ch ;0bce
  3276. ld de,0120ch ;0bd1
  3277. ld bc,00007h ;0bd4
  3278. ldir ;0bd7
  3279. l0bd9h:
  3280. call sub_0ba7h ;0bd9
  3281. jr nc,l0bebh ;0bdc
  3282. cp 080h ;0bde
  3283. jr z,l0bebh ;0be0
  3284. bit 5,a ;0be2
  3285. jr z,l0bd9h ;0be4
  3286. ld (0124ah),a ;0be6
  3287. jr l0bd9h ;0be9
  3288. l0bebh:
  3289. pop de ;0beb
  3290. pop bc ;0bec
  3291. pop hl ;0bed
  3292. pop af ;0bee
  3293. ei ;0bef
  3294. reti ;0bf0
  3295. ;==============================================================================
  3296. ; FLOPPY CONTROLLER COMMAND SENDER (0x0BF2)
  3297. ;==============================================================================
  3298. ; Purpose: Send command 0x04 to floppy disk controller and read response
  3299. ;
  3300. ; Function:
  3301. ; - Sets up command buffer at 0x1213 with command 0x04
  3302. ; - Calls sub_0b7bh to add drive/head parameters
  3303. ; - Calls l0b64h to transmit command via ports 0xF0/0xF1
  3304. ; - Returns status in accumulator for caller processing
  3305. ;
  3306. ; Command 0x04: Likely "Read Status" or "Sense Drive Status" command
  3307. ; Buffer: 0x1213 = command, 0x1214+ = parameters
  3308. ; I/O Ports: 0xF0 (status check), 0xF1 (data transfer)
  3309. ;==============================================================================
  3310. sub_0bf2h:
  3311. ld hl,01213h ;0bf2
  3312. push hl ;0bf5
  3313. ld (hl),004h ;0bf6
  3314. inc hl ;0bf8
  3315. call sub_0b7bh ;0bf9
  3316. pop hl ;0bfc
  3317. ld b,002h ;0bfd
  3318. call l0b64h ;0bff
  3319. jp l0b88h ;0c02
  3320. sub_0c05h:
  3321. call sub_0d2eh ;0c05
  3322. ret nc ;0c08
  3323. ld hl,01213h ;0c09
  3324. push hl ;0c0c
  3325. ld (hl),00fh ;0c0d
  3326. inc hl ;0c0f
  3327. call sub_0b7bh ;0c10
  3328. ld a,(01225h) ;0c13
  3329. ld (hl),a ;0c16
  3330. xor a ;0c17
  3331. ld (0124ah),a ;0c18
  3332. pop hl ;0c1b
  3333. ld b,003h ;0c1c
  3334. call l0b64h ;0c1e
  3335. ret nc ;0c21
  3336. l0c22h:
  3337. ld a,(0124ah) ;0c22
  3338. or a ;0c25
  3339. jr z,l0c22h ;0c26
  3340. and 0f8h ;0c28
  3341. xor 020h ;0c2a
  3342. ret nz ;0c2c
  3343. scf ;0c2d
  3344. ret ;0c2e
  3345. l0c2fh:
  3346. ld a,006h ;0c2f
  3347. jr l0c35h ;0c31
  3348. l0c33h:
  3349. ld a,005h ;0c33
  3350. l0c35h:
  3351. ld hl,01223h ;0c35
  3352. ld (hl),a ;0c38
  3353. ld a,(01204h) ;0c39
  3354. or a ;0c3c
  3355. ret nz ;0c3d
  3356. call sub_0c6ah ;0c3e
  3357. call sub_0b7bh ;0c41
  3358. call sub_0c73h ;0c44
  3359. call sub_0d2eh ;0c47
  3360. ret nc ;0c4a
  3361. call sub_0ca0h ;0c4b
  3362. call sub_0cc5h ;0c4e
  3363. xor a ;0c51
  3364. ld (0124bh),a ;0c52
  3365. ld hl,01223h ;0c55
  3366. ld b,009h ;0c58
  3367. call l0b64h ;0c5a
  3368. ret nc ;0c5d
  3369. call sub_0d11h ;0c5e
  3370. ret nc ;0c61
  3371. ld a,(0120ch) ;0c62
  3372. and 0c0h ;0c65
  3373. ret nz ;0c67
  3374. scf ;0c68
  3375. ret ;0c69
  3376. sub_0c6ah:
  3377. ld a,(01203h) ;0c6a
  3378. rrca ;0c6d
  3379. rrca ;0c6e
  3380. or (hl) ;0c6f
  3381. ld (hl),a ;0c70
  3382. inc hl ;0c71
  3383. ret ;0c72
  3384. sub_0c73h:
  3385. ld hl,l0c90h ;0c73
  3386. ld de,01228h ;0c76
  3387. jr l0c81h ;0c79
  3388. sub_0c7bh:
  3389. ld hl,l0c98h ;0c7b
  3390. ld de,01215h ;0c7e
  3391. l0c81h:
  3392. ld a,(01203h) ;0c81
  3393. add a,a ;0c84
  3394. add a,a ;0c85
  3395. ld c,a ;0c86
  3396. ld b,000h ;0c87
  3397. add hl,bc ;0c89
  3398. ld bc,00004h ;0c8a
  3399. ldir ;0c8d
  3400. ret ;0c8f
  3401. l0c90h:
  3402. nop ;0c90
  3403. ld a,(de) ;0c91
  3404. rlca ;0c92
  3405. add a,b ;0c93
  3406. ld bc,l0e1ah ;0c94
  3407. rst 38h ;0c97
  3408. l0c98h:
  3409. nop ;0c98
  3410. ld a,(de) ;0c99
  3411. dec de ;0c9a
  3412. push hl ;0c9b
  3413. ld bc,0361ah ;0c9c
  3414. push hl ;0c9f
  3415. sub_0ca0h:
  3416. ld a,(01203h) ;0ca0
  3417. inc a ;0ca3
  3418. ld d,a ;0ca4
  3419. ld e,080h ;0ca5
  3420. jr l0cadh ;0ca7
  3421. sub_0ca9h:
  3422. ld d,001h ;0ca9
  3423. ld e,068h ;0cab
  3424. l0cadh:
  3425. ld c,0f4h ;0cad
  3426. ld a,047h ;0caf
  3427. out (c),a ;0cb1
  3428. out (c),d ;0cb3
  3429. inc c ;0cb5
  3430. ld a,057h ;0cb6
  3431. out (c),a ;0cb8
  3432. out (c),e ;0cba
  3433. ret ;0cbc
  3434. sub_0cbdh:
  3435. ld hl,00068h ;0cbd
  3436. ld a,(01213h) ;0cc0
  3437. jr l0cd2h ;0cc3
  3438. sub_0cc5h:
  3439. ld hl,l0080h ;0cc5
  3440. ld a,(01203h) ;0cc8
  3441. or a ;0ccb
  3442. jr z,l0ccfh ;0ccc
  3443. add hl,hl ;0cce
  3444. l0ccfh:
  3445. ld a,(01223h) ;0ccf
  3446. l0cd2h:
  3447. dec hl ;0cd2
  3448. push hl ;0cd3
  3449. ld hl,l0cfbh ;0cd4
  3450. ld de,0122ch ;0cd7
  3451. ld bc,00016h ;0cda
  3452. ldir ;0cdd
  3453. pop hl ;0cdf
  3454. ld (01235h),hl ;0ce0
  3455. ld hl,(01200h) ;0ce3
  3456. ld (01233h),hl ;0ce6
  3457. and 001h ;0ce9
  3458. rlca ;0ceb
  3459. rlca ;0cec
  3460. ld hl,0123eh ;0ced
  3461. or (hl) ;0cf0
  3462. ld (hl),a ;0cf1
  3463. ld hl,0122ch ;0cf2
  3464. ld bc,016fch ;0cf5
  3465. otir ;0cf8
  3466. ret ;0cfa
  3467. l0cfbh:
  3468. jp 0c3c3h ;0cfb
  3469. jp 0c3c3h ;0cfe
  3470. ld a,c ;0d01
  3471. nop ;0d02
  3472. nop ;0d03
  3473. nop ;0d04
  3474. nop ;0d05
  3475. inc d ;0d06
  3476. jr z,$-121 ;0d07
  3477. jp p,08382h ;0d09
  3478. rst 8 ;0d0c
  3479. ld bc,0cf83h ;0d0d
  3480. add a,a ;0d10
  3481. sub_0d11h:
  3482. ld bc,l0000h ;0d11
  3483. l0d14h:
  3484. ld a,(0124bh) ;0d14
  3485. or a ;0d17
  3486. scf ;0d18
  3487. ret nz ;0d19
  3488. ld a,(0124bh) ;0d1a
  3489. or a ;0d1d
  3490. scf ;0d1e
  3491. ret nz ;0d1f
  3492. djnz l0d14h ;0d20
  3493. dec c ;0d22
  3494. jr nz,l0d14h ;0d23
  3495. ld a,083h ;0d25 ; Load DMA command 0x83
  3496. out (0fch),a ;0d27 ; Send command to Z80 DMA controller port 0xFC
  3497. ; ; 0x83 = DMA control command for disk operations
  3498. call sub_0a8dh ;0d29
  3499. or a ;0d2c
  3500. ret ;0d2d
  3501. sub_0d2eh:
  3502. call sub_0bf2h ;0d2e
  3503. ret nc ;0d31
  3504. and 020h ;0d32
  3505. ret z ;0d34
  3506. scf ;0d35
  3507. ret ;0d36
  3508. sub_0d37h:
  3509. call sub_0d2eh ;0d37
  3510. ret nc ;0d3a
  3511. ld b,002h ;0d3b
  3512. l0d3dh:
  3513. push bc ;0d3d
  3514. call sub_0c05h ;0d3e
  3515. pop bc ;0d41
  3516. ld a,(01225h) ;0d42
  3517. ld (iy+000h),a ;0d45
  3518. ret c ;0d48
  3519. push bc ;0d49
  3520. call sub_0b1ch ;0d4a
  3521. pop bc ;0d4d
  3522. ret nc ;0d4e
  3523. ld hl,(01244h) ;0d4f
  3524. inc hl ;0d52
  3525. ld (01244h),hl ;0d53
  3526. djnz l0d3dh ;0d56
  3527. or a ;0d58
  3528. ret ;0d59
  3529. l0d5ah:
  3530. call sub_0bf2h ;0d5a
  3531. xor 020h ;0d5d
  3532. and 060h ;0d5f
  3533. ret nz ;0d61
  3534. ld hl,l0c33h ;0d62
  3535. jr l0d6eh ;0d65
  3536. l0d67h:
  3537. call sub_0d2eh ;0d67
  3538. ret nc ;0d6a
  3539. ld hl,l0c2fh ;0d6b
  3540. l0d6eh:
  3541. ld b,005h ;0d6e
  3542. l0d70h:
  3543. push bc ;0d70
  3544. push hl ;0d71
  3545. call sub_0da8h ;0d72
  3546. pop hl ;0d75
  3547. pop bc ;0d76
  3548. ret c ;0d77
  3549. push hl ;0d78
  3550. ld a,(0120dh) ;0d79
  3551. and 085h ;0d7c
  3552. jr z,l0d87h ;0d7e
  3553. ld hl,(01246h) ;0d80
  3554. inc hl ;0d83
  3555. ld (01246h),hl ;0d84
  3556. l0d87h:
  3557. ld a,(0120dh) ;0d87
  3558. and 020h ;0d8a
  3559. jr z,l0d95h ;0d8c
  3560. ld hl,(01248h) ;0d8e
  3561. inc hl ;0d91
  3562. ld (01248h),hl ;0d92
  3563. l0d95h:
  3564. ld a,(0120eh) ;0d95
  3565. and 012h ;0d98
  3566. jr z,l0da3h ;0d9a
  3567. ld hl,(01244h) ;0d9c
  3568. inc hl ;0d9f
  3569. ld (01244h),hl ;0da0
  3570. l0da3h:
  3571. pop hl ;0da3
  3572. djnz l0d70h ;0da4
  3573. or a ;0da6
  3574. ret ;0da7
  3575. sub_0da8h:
  3576. jp (hl) ;0da8
  3577. sub_0da9h:
  3578. jp (ix) ;0da9
  3579. l0dabh:
  3580. ld ix,l0d67h ;0dab
  3581. jr l0db5h ;0daf
  3582. l0db1h:
  3583. ld ix,l0d5ah ;0db1
  3584. l0db5h:
  3585. ld iy,01205h ;0db5
  3586. ld b,002h ;0db9
  3587. ld a,(01202h) ;0dbb
  3588. ld e,a ;0dbe
  3589. ld d,000h ;0dbf
  3590. add iy,de ;0dc1
  3591. ld a,(01225h) ;0dc3
  3592. cp (iy+000h) ;0dc6
  3593. jr z,l0dd1h ;0dc9
  3594. l0dcbh:
  3595. push bc ;0dcb
  3596. call sub_0d37h ;0dcc
  3597. pop bc ;0dcf
  3598. ret nc ;0dd0
  3599. l0dd1h:
  3600. push bc ;0dd1
  3601. call sub_0da9h ;0dd2
  3602. pop bc ;0dd5
  3603. ret c ;0dd6
  3604. push bc ;0dd7
  3605. call sub_0b1ch ;0dd8
  3606. pop bc ;0ddb
  3607. djnz l0dcbh ;0ddc
  3608. or a ;0dde
  3609. ret ;0ddf
  3610. ;==============================================================================
  3611. ; FLOPPY DISK STATUS CHECK ROUTINE (0x0DE0)
  3612. ;==============================================================================
  3613. ; Purpose: Check floppy disk controller status and extract specific status bit
  3614. ; Entry Point: l0de0h - Called from interrupt vector 0x000B and multiple locations
  3615. ;
  3616. ; Function:
  3617. ; - Sends status command (0x04) to floppy controller via ports 0xF0/0xF1
  3618. ; - Reads back status response from floppy controller
  3619. ; - Extracts bit 3 from status (rotated to bit 0)
  3620. ; - Stores extracted bit at memory location 0x1203
  3621. ;
  3622. ; Status bit extracted (original bit 3) likely indicates:
  3623. ; - Drive ready condition, Track 0 detection, Write protect, or Index pulse
  3624. ;
  3625. ; Used as: Interrupt service routine and general floppy status check
  3626. ; Ports: 0xF0 (status), 0xF1 (data), 0xFC (control)
  3627. ;==============================================================================
  3628. l0de0h:
  3629. call sub_0bf2h ;0de0
  3630. rrca ;0de3
  3631. rrca ;0de4
  3632. rrca ;0de5
  3633. and 001h ;0de6
  3634. ld (01203h),a ;0de8
  3635. ret ;0deb
  3636. sub_0dech:
  3637. call sub_0d2eh ;0dec
  3638. ret nc ;0def
  3639. ld hl,01213h ;0df0
  3640. ld (hl),00dh ;0df3
  3641. call sub_0c6ah ;0df5
  3642. call sub_0b7bh ;0df8
  3643. call sub_0e1fh ;0dfb
  3644. call sub_0ca9h ;0dfe
  3645. call sub_0cbdh ;0e01
  3646. xor a ;0e04
  3647. ld (0124bh),a ;0e05
  3648. ld hl,01213h ;0e08
  3649. ld b,006h ;0e0b
  3650. call l0b64h ;0e0d
  3651. ret nc ;0e10
  3652. l0e11h:
  3653. ld a,(0124bh) ;0e11
  3654. or a ;0e14
  3655. jr z,l0e11h ;0e15
  3656. ld a,(0120ch) ;0e17
  3657. l0e1ah:
  3658. and 0c0h ;0e1a
  3659. ret nz ;0e1c
  3660. scf ;0e1d
  3661. ret ;0e1e
  3662. sub_0e1fh:
  3663. call sub_0c7bh ;0e1f
  3664. ld a,(01203h) ;0e22
  3665. ld e,a ;0e25
  3666. ld a,(01226h) ;0e26
  3667. ld c,a ;0e29
  3668. ld a,(01225h) ;0e2a
  3669. ld d,001h ;0e2d
  3670. ld b,01ah ;0e2f
  3671. ld hl,01000h ;0e31
  3672. ld (01200h),hl ;0e34
  3673. l0e37h:
  3674. ld (hl),a ;0e37
  3675. inc hl ;0e38
  3676. ld (hl),c ;0e39
  3677. inc hl ;0e3a
  3678. ld (hl),d ;0e3b
  3679. inc hl ;0e3c
  3680. ld (hl),e ;0e3d
  3681. inc hl ;0e3e
  3682. inc d ;0e3f
  3683. djnz l0e37h ;0e40
  3684. ret ;0e42
  3685. sub_0e43h:
  3686. call sub_0bf2h ;0e43
  3687. xor 020h ;0e46
  3688. and 060h ;0e48
  3689. ret nz ;0e4a
  3690. call l0de0h ;0e4b
  3691. ld iy,01205h ;0e4e
  3692. ld a,(01202h) ;0e52
  3693. ld e,a ;0e55
  3694. ld d,000h ;0e56
  3695. add iy,de ;0e58
  3696. call sub_0b1ch ;0e5a
  3697. ret nc ;0e5d
  3698. xor a ;0e5e
  3699. ld (01225h),a ;0e5f
  3700. l0e62h:
  3701. call sub_0c05h ;0e62
  3702. ret nc ;0e65
  3703. xor a ;0e66
  3704. ld (01226h),a ;0e67
  3705. call sub_0dech ;0e6a
  3706. ret nc ;0e6d
  3707. ld a,(01203h) ;0e6e
  3708. or a ;0e71
  3709. jr z,l0e7bh ;0e72
  3710. ld (01226h),a ;0e74
  3711. call sub_0dech ;0e77
  3712. ret nc ;0e7a
  3713. l0e7bh:
  3714. ld a,(01225h) ;0e7b
  3715. inc a ;0e7e
  3716. ld (01225h),a ;0e7f
  3717. cp 04dh ;0e82
  3718. jr c,l0e62h ;0e84
  3719. jp sub_0b1ch ;0e86
  3720. sub_0e89h:
  3721. call sub_0ea2h ;0e89
  3722. call nz,sub_0f6bh ;0e8c
  3723. call sub_0ecch ;0e8f
  3724. call nz,sub_0f70h ;0e92
  3725. call sub_0a8dh ;0e95
  3726. call nc,sub_0f75h ;0e98
  3727. call sub_0f10h ;0e9b
  3728. call nz,sub_0f7ah ;0e9e
  3729. ret ;0ea1
  3730. ;==============================================================================
  3731. ; RAM MEMORY DIAGNOSTIC TEST (0x0EA2)
  3732. ;==============================================================================
  3733. ; Purpose: Test available RAM and detect memory boundaries
  3734. ; Tests RAM starting from 0x1400 (above 1KB base RAM) to find additional memory
  3735. ;
  3736. ; Memory Layout:
  3737. ; - 0x0000-0x0FFF: EPROM
  3738. ; - 0x1000-0x13FF: Base 1KB RAM (1024 bytes)
  3739. ; - 0x1400+: Extended RAM (if present) or memory-mapped I/O
  3740. ;
  3741. ; Test Method:
  3742. ; - Starts at 0x1400 (beyond base 1KB RAM)
  3743. ; - Tests each location with multiple bit patterns
  3744. ; - Continues until test fails (indicating no more RAM or different hardware)
  3745. ;
  3746. ; Purpose: Detect extended RAM modules or memory-mapped peripherals
  3747. ; Returns: Z flag clear when memory boundary reached, Z set if wraps to 0x0000
  3748. ;==============================================================================
  3749. sub_0ea2h:
  3750. ld de,l0000h ;0ea2 Set DE = 0x0000 (used for wrap-around detection)
  3751. ld hl,01400h ;0ea5 Start at 0x1400 (beyond 1KB base RAM)
  3752. ; Test each memory location above base RAM
  3753. l0ea8h:
  3754. call sub_0eb3h ;0ea8 Test current memory location with bit patterns
  3755. ret nz ;0eab Return when memory test fails (found boundary)
  3756. inc hl ;0eac Move to next higher memory address
  3757. sbc hl,de ;0ead Check if wrapped around to 0x0000
  3758. add hl,de ;0eaf Restore HL value
  3759. jr nz,l0ea8h ;0eb0 Continue until boundary found or wrap-around
  3760. ret ;0eb2 Return if wrapped to 0x0000 (full 64K RAM)
  3761. ;==============================================================================
  3762. ; MEMORY LOCATION TEST WITH MULTIPLE PATTERNS (0x0EB3)
  3763. ;==============================================================================
  3764. ; Purpose: Test single memory location with all bit patterns from test table
  3765. ; Input: HL = memory address to test
  3766. ;
  3767. ; Test Procedure:
  3768. ; 1. Load test pattern count and pattern table pointer
  3769. ; 2. For each pattern: save original data, write pattern, read back, verify
  3770. ; 3. Restore original data, test next pattern
  3771. ; 4. Interrupts disabled during write/read/verify to prevent corruption
  3772. ;
  3773. ; Test Patterns (at l0ec9h):
  3774. ; - 0x02: Tests bit 1 (and others as 0)
  3775. ; - 0x55: Alternating bits pattern (01010101)
  3776. ; - 0xAA: Inverse alternating pattern (10101010)
  3777. ;
  3778. ; Returns: Z flag set if all patterns pass, Z clear if any pattern fails
  3779. ;==============================================================================
  3780. sub_0eb3h:
  3781. ld ix,l0ec9h ;0eb3 Point IX to test pattern table
  3782. ld b,(ix+000h) ;0eb7 Load pattern count (first byte of table)
  3783. ; Test each pattern from the table
  3784. l0ebah:
  3785. inc ix ;0eba Advance to next test pattern
  3786. ld a,(ix+000h) ;0ebc Load test pattern into A
  3787. ld c,(hl) ;0ebf Save original memory contents in C
  3788. di ;0ec0 Disable interrupts (critical memory test section)
  3789. ld (hl),a ;0ec1 Write test pattern to memory
  3790. cp (hl) ;0ec2 Read back and compare with expected pattern
  3791. ld (hl),c ;0ec3 Restore original memory contents
  3792. ei ;0ec4 Re-enable interrupts
  3793. ret nz ;0ec5 Return with error if pattern didn't match
  3794. djnz l0ebah ;0ec6 Test next pattern (decrement B, loop if not zero)
  3795. ret ;0ec8 Return with Z set (all patterns passed)
  3796. ;==============================================================================
  3797. ; MEMORY TEST PATTERN TABLE (0x0EC9)
  3798. ;==============================================================================
  3799. ; Format: [Count] [Pattern1] [Pattern2] [Pattern3]
  3800. ; These patterns test different failure modes:
  3801. ; - 0x02: Tests if bit 1 can be set while others stay clear
  3802. ; - 0x55: Tests alternating bit pattern (detects adjacent bit interference)
  3803. ; - 0xAA: Inverse alternating (detects stuck bits and crosstalk)
  3804. ;==============================================================================
  3805. l0ec9h:
  3806. defb 0x03 ;0ec9 Number of test patterns
  3807. defb 0x55 ;0eca Test pattern 1: 01010101 (alternating bits)
  3808. defb 0xAA ;0ecb Test pattern 2: 10101010 (inverse alternating)
  3809. ;==============================================================================
  3810. ; INTERRUPT VECTOR TABLE INITIALIZATION (0x0ECC)
  3811. ;==============================================================================
  3812. ; Purpose: Set up interrupt vector table and perform peripheral testing
  3813. ; This routine initializes the interrupt mode 2 vector table with error
  3814. ; handlers and tests peripheral chips through port operations.
  3815. ;
  3816. ; Interrupt Vector Setup:
  3817. ; Sets addresses 0x1330, 0x1332, 0x1334, 0x1336 to point to l0f3fh
  3818. ; These are interrupt vector table entries for IM2 mode interrupts
  3819. ;
  3820. ; Peripheral Testing:
  3821. ; Tests ports 0xF4 through 0xF7 with specific control sequences
  3822. ; Uses port commands 0x30 (initialize) and 0x03 (test/verify)
  3823. ; Validates peripheral response through status flag at 0x1103
  3824. ;==============================================================================
  3825. sub_0ecch:
  3826. ld hl,l0f3fh ;0ecc ; Load address of interrupt error handler
  3827. ld (01330h),hl ;0ecf ; Set interrupt vector table entry 0
  3828. ld (01332h),hl ;0ed2 ; Set interrupt vector table entry 1
  3829. ld (01334h),hl ;0ed5 ; Set interrupt vector table entry 2
  3830. ld (01336h),hl ;0ed8 ; Set interrupt vector table entry 3
  3831. ld c,0f4h ;0edb ; Start with port 0xF4 (first peripheral port)
  3832. ld a,030h ;0edd ; Load initialization command (0x30)
  3833. out (c),a ;0edf ; Send initialization command to peripheral
  3834. ;==============================================================================
  3835. ; PERIPHERAL PORT TESTING LOOP (0x0EE1)
  3836. ;==============================================================================
  3837. ; Purpose: Test peripheral chips at ports 0xF4-0xF7 for proper response
  3838. ; Tests each port with initialization and verification commands
  3839. ;==============================================================================
  3840. l0ee1h:
  3841. ld a,0ffh ;0ee1 ; Set error flag (assume failure initially)
  3842. ld (01103h),a ;0ee3 ; Store error flag in status location
  3843. call sub_0f01h ;0ee6 ; Send command sequence to current peripheral
  3844. push bc ;0ee9 ; Save current port number
  3845. ld bc,01900h ;0eea ; Load delay count (6400 cycles for peripheral response)
  3846. call sub_0f0ah ;0eed ; Wait for peripheral to process command
  3847. pop bc ;0ef0 ; Restore current port number
  3848. ld a,003h ;0ef1 ; Load verification command (0x03)
  3849. out (c),a ;0ef3 ; Send verification command to peripheral
  3850. ld a,(01103h) ;0ef5 ; Read status flag after peripheral operation
  3851. or a ;0ef8 ; Test if peripheral responded correctly (0=success)
  3852. ret nz ;0ef9 ; Return if peripheral failed to respond
  3853. inc c ;0efa ; Move to next peripheral port (0xF4→0xF5→0xF6→0xF7)
  3854. ld a,c ;0efb ; Check current port number
  3855. cp 0f8h ;0efc ; Compare with end limit (0xF8 = beyond 0xF7)
  3856. jr nz,l0ee1h ;0efe ; Continue testing if more ports remain
  3857. ret ;0f00 ; Return with success (all peripherals tested)
  3858. ;==============================================================================
  3859. ; PERIPHERAL COMMAND SEQUENCE (0x0F01)
  3860. ;==============================================================================
  3861. ; Purpose: Send specific command sequence to peripheral chip
  3862. ; Sends initialization commands to configure peripheral for testing
  3863. ;==============================================================================
  3864. sub_0f01h:
  3865. ld a,028h ;0f01 ; Load parameter value (0x28 = timing/mode setting)
  3866. ld b,087h ;0f03 ; Load command value (0x87 = control command)
  3867. out (c),b ;0f05 ; Send control command to peripheral
  3868. out (c),a ;0f07 ; Send parameter value to peripheral
  3869. ret ;0f09 ; Return after command sequence complete
  3870. ; --------------------------------------------------
  3871. ; sub_0f0ah: Wait/Delay Loop
  3872. ; Burns CPU cycles by decrementing BC until it reaches zero.
  3873. ; Used for timing delays, hardware settling, or pacing init steps.
  3874. ; Entry: BC = delay value
  3875. ; Exit: BC = 0
  3876. ; No hardware interaction, pure software delay
  3877. ; --------------------------------------------------
  3878. sub_0f0ah:
  3879. dec bc ;0f0a
  3880. ld a,c ;0f0b
  3881. or b ;0f0c
  3882. jr nz,sub_0f0ah ;0f0d
  3883. ret ;0f0f
  3884. ; --------------------------------------------------
  3885. ; sub_0f10h: Hardware Initialization & Memory Test Routine
  3886. ; - Clears accumulator and sets 01204h to 0
  3887. ; - Sets up pointer at 0133ch to l0f48h
  3888. ; - Sets 01103h to 0xFF (error/status flag)
  3889. ; - Calls setup_peripherals_01a1h with l0f55h (hardware setup)
  3890. ; - Waits using delay loop (sub_0f0ah, BC=0x1000)
  3891. ; - If 01103h is nonzero, returns (error)
  3892. ; - If zero, compares 256 bytes at HL and DE (memory test), returns if mismatch
  3893. ; Called at 0e9b as part of system initialization/test sequence
  3894. ; --------------------------------------------------
  3895. ;==============================================================================
  3896. ; MEMORY TEST AND HARDWARE INITIALIZATION (0x0F10)
  3897. ;==============================================================================
  3898. ; Purpose: Comprehensive RAM test comparing ROM shadow with actual RAM
  3899. ; This routine performs a critical memory integrity test by comparing the
  3900. ; first 256 bytes of ROM (0x0000-0x00FF) with corresponding RAM locations
  3901. ; (0x1000-0x10FF) to verify RAM is functioning correctly.
  3902. ;
  3903. ; Test Strategy:
  3904. ; 1. Initialize hardware peripherals and interrupt handlers
  3905. ; 2. Set up error detection mechanisms
  3906. ; 3. Allow hardware to stabilize with timing delay
  3907. ; 4. Perform byte-by-byte comparison between ROM and RAM
  3908. ; 5. Return status indicating memory integrity
  3909. ;
  3910. ; Memory Locations Used:
  3911. ; • 0x1204: Test control flags (0=test mode, 1=normal operation)
  3912. ; • 0x133C: Interrupt vector pointer (set to 0x0F48)
  3913. ; • 0x1103: Error status flag (0xFF=error, 0x00=success)
  3914. ;
  3915. ; Hardware Integration:
  3916. ; • Configures peripheral hardware via setup_peripherals_01a1h
  3917. ; • Sets up interrupt handling for test environment
  3918. ; • Uses timing delays to ensure hardware stability
  3919. ;
  3920. ; Returns:
  3921. ; • Zero flag set: Memory test passed, RAM integrity verified
  3922. ; • Zero flag clear: Memory test failed, RAM fault detected
  3923. ;==============================================================================
  3924. sub_0f10h:
  3925. xor a ;0f10 ; Clear accumulator (A = 0)
  3926. ld (01204h),a ;0f11 ; Set test control flag to 0 (enable test mode)
  3927. ld hl,l0f48h ;0f14 ; Load address of interrupt service routine
  3928. ld (0133ch),hl ;0f17 ; Set interrupt vector pointer for test environment
  3929. dec a ;0f1a ; Set A = 0xFF (error flag value)
  3930. ld (01103h),a ;0f1b ; Initialize error status to 0xFF (assume error initially)
  3931. ld hl,l0f55h ;0f1e ; Load address of hardware configuration data
  3932. call setup_peripherals_01a1h ;0f21 ; Initialize peripheral hardware and interrupts
  3933. ld bc,01000h ;0f24 ; Load delay count (4096 iterations for hardware stabilization)
  3934. call sub_0f0ah ;0f27 ; Execute timing delay loop (allow hardware to settle)
  3935. ld a,(01103h) ;0f2a ; Read error status flag after hardware initialization
  3936. or a ;0f2d ; Test if error flag is non-zero
  3937. ret nz ;0f2e ; Return immediately if hardware initialization failed
  3938. ;==============================================================================
  3939. ; RAM INTEGRITY TEST - ROM vs RAM COMPARISON (0x0F2F)
  3940. ;==============================================================================
  3941. ; Performs byte-by-byte comparison between ROM (0x0000-0x00FF) and
  3942. ; RAM (0x1000-0x10FF) to verify RAM is correctly mirroring ROM data.
  3943. ; This test validates that the memory system is functioning properly.
  3944. ;==============================================================================
  3945. ld hl,01000h ;0f2f ; Point to start of RAM test area (0x1000)
  3946. ld de,l0000h ;0f32 ; Point to start of ROM reference area (0x0000)
  3947. ld b,0ffh ;0f35 ; Set counter for 255 bytes (256 total with DJNZ behavior)
  3948. l0f37h:
  3949. ld a,(de) ;0f37 ; Load byte from ROM (reference data)
  3950. cp (hl) ;0f38 ; Compare with corresponding byte in RAM
  3951. ret nz ;0f39 ; Return immediately if mismatch found (memory fault)
  3952. inc hl ;0f3a ; Move to next RAM address
  3953. inc de ;0f3b ; Move to next ROM address
  3954. djnz l0f37h ;0f3c ; Continue until all 256 bytes tested
  3955. ret ;0f3e ; Return with zero flag set (test passed)
  3956. ;==============================================================================
  3957. ; INTERRUPT SERVICE ROUTINE - ERROR HANDLER (0x0F3F)
  3958. ;==============================================================================
  3959. ; Purpose: Generic interrupt service routine for error handling during hardware tests
  3960. ; This routine is installed in multiple interrupt vector table entries to catch
  3961. ; any unexpected interrupts that occur during hardware initialization and testing.
  3962. ;
  3963. ; Called from: Interrupt vector table entries at 0x1330, 0x1332, 0x1334, 0x1336
  3964. ; Used during: Hardware initialization, FDC operations, and system testing
  3965. ;
  3966. ; Operation:
  3967. ; 1. Save processor state (AF register)
  3968. ; 2. Clear error status flag (mark as successful)
  3969. ; 3. Restore processor state
  3970. ; 4. Return from interrupt with interrupts enabled
  3971. ;
  3972. ; Function: Provides safe interrupt handling during critical hardware operations
  3973. ; This prevents system crashes if unexpected interrupts occur during testing.
  3974. ;==============================================================================
  3975. l0f3fh:
  3976. push af ;0f3f ; Save accumulator and flags on stack
  3977. ;==============================================================================
  3978. ; INTERRUPT COMPLETION HANDLER (0x0F40)
  3979. ;==============================================================================
  3980. ; Purpose: Common completion path for interrupt service routines
  3981. ; Clears error status and returns from interrupt with proper state restoration.
  3982. ;==============================================================================
  3983. l0f40h:
  3984. xor a ;0f40 ; Clear accumulator (A = 0)
  3985. ld (01103h),a ;0f41 ; Clear error status flag (0 = success, no error)
  3986. pop af ;0f44 ; Restore accumulator and flags from stack
  3987. ei ;0f45 ; Enable interrupts (standard RETI behavior)
  3988. reti ;0f46 ; Return from interrupt (pops PC and restores state)
  3989. ;==============================================================================
  3990. ; SPECIALIZED INTERRUPT HANDLER WITH PORT OPERATIONS (0x0F48)
  3991. ;==============================================================================
  3992. ; Purpose: Interrupt service routine that performs port I/O operations
  3993. ; This appears to be a hardware-specific interrupt handler that sends data
  3994. ; to port 0xFC during interrupt processing, possibly for peripheral control.
  3995. ;
  3996. ; Port Operations:
  3997. ; • Sends 0xC3 to port 0xFC six times in sequence
  3998. ; • Port 0xFC likely controls DMA, FDC, or other peripheral hardware
  3999. ; • Multiple writes may be required for hardware sequencing
  4000. ;
  4001. ; Used by: Hardware initialization routine (pointed to by interrupt vector)
  4002. ; Context: Called during peripheral setup and hardware testing phases
  4003. ;==============================================================================
  4004. l0f48h:
  4005. push af ;0f48 ; Save accumulator and flags
  4006. push bc ;0f49 ; Save BC register pair
  4007. ld a,0c3h ;0f4a ; Load control value 0xC3 for port operation
  4008. ld b,006h ;0f4c ; Set counter for 6 iterations
  4009. l0f4eh:
  4010. out (0fch),a ;0f4e ; Send DMA command 0xC3 to Z80 DMA controller
  4011. ; ; 0xC3 = DMA reset/initialization command
  4012. ; ; Repeated 6 times for proper DMA controller reset
  4013. djnz l0f4eh ;0f50 ; Repeat 6 times (decrement B, loop if not zero)
  4014. pop bc ;0f52 ; Restore BC register pair
  4015. jr l0f40h ;0f53 ; Jump to common interrupt completion routine
  4016. ;==============================================================================
  4017. ; HARDWARE CONFIGURATION DATA TABLE (0x0F55)
  4018. ;==============================================================================
  4019. ; Purpose: Configuration data for peripheral hardware initialization
  4020. ; Used by: setup_peripherals_01a1h routine during system initialization
  4021. ; Format: Binary configuration data for DMA setup
  4022. ;
  4023. ; This table contains the initialization parameters and control sequences
  4024. ; required to properly configure the Z80 peripheral hardware during boot.
  4025. ; The data is processed by the hardware setup routine to configure:
  4026. ; • Z80 DMA controller transfer parameters
  4027. ;
  4028. ; TABLE FORMAT: [byte_count] [port_address] [data_bytes...]
  4029. ; • 0x13 (19 decimal) = total byte count for this configuration block
  4030. ; • 0xFC = Z80 DMA controller port address
  4031. ; • Following 19 bytes = DMA initialization sequence written to port 0xFC
  4032. ;==============================================================================
  4033. l0f55h:
  4034. defb 0x13 ;0f55 Byte count: 19 bytes total (1 count + 18 DMA init bytes)
  4035. defb 0xfc ;0f56 Target port: 0xFC (Z80 DMA controller)
  4036. defb 0x79 ;0f57 DMA WR0: Base register, transfer mode (Block transfer, A→B)
  4037. defb 0x00 ;0f58 DMA WR1: Port A starting address LOW byte
  4038. defb 0x00 ;0f59 DMA WR2: Port A starting address HIGH byte
  4039. defb 0xfe ;0f5a DMA WR0: Port A address LOW (0xFE = FDC data port region)
  4040. defb 0x00 ;0f5b DMA WR1: Port A address HIGH byte
  4041. defb 0x10 ;0f5c DMA WR2: Block length LOW byte (16 bytes)
  4042. defb 0x14 ;0f5d DMA WR3: Block length HIGH + control
  4043. defb 0xdb ;0f5e DMA WR4: Port B starting address LOW byte
  4044. defb 0x00 ;0f5f DMA WR5: Port B starting address HIGH byte
  4045. defb 0x10 ;0f60 DMA WR0: Port B address configuration
  4046. defb 0x12 ;0f61 DMA WR1: Port B control (memory increment mode)
  4047. defb 0x3c ;0f62 DMA WR2: Interrupt control and timing
  4048. defb 0x82 ;0f63 DMA WR3: Interrupt vector base
  4049. defb 0xcf ;0f64 DMA WR4: Pulse control (Ready/Wait signal timing)
  4050. defb 0x05 ;0f65 DMA WR5: Command register (Enable DMA, continuous mode)
  4051. defb 0xcf ;0f66 DMA WR6: Additional control flags
  4052. defb 0xb3 ;0f67 DMA command: Load and enable DMA operation
  4053. defb 0xab ;0f68 DMA command: Configure interrupt and ready modes
  4054. defb 0x87 ;0f69 DMA command: Enable DMA transfer operation
  4055. defb 0x00 ;0f6a Configuration terminator: 0x00
  4056. ;==============================================================================
  4057. ; ERROR MESSAGE DISPLAY ROUTINES (0x0F6B-0x0F7F)
  4058. ;==============================================================================
  4059. ; Purpose: Display specific error messages for hardware failures
  4060. ; These routines set HL to point to error message strings and call the
  4061. ; standard print routine at l00fdh to display them to the console.
  4062. ;
  4063. ; Error Messages:
  4064. ; • sub_0f6bh: "MEM ERR" - Memory error detected
  4065. ; • sub_0f70h: "FLOPPY CTC ERR" - Floppy controller CTC timing error
  4066. ; • sub_0f75h: "FLOPPY NEC ERR" - NEC µPD765A FDC hardware error
  4067. ; • sub_0f7ah: "DMA ERR" - Z80 DMA controller error (also sets drive flag)
  4068. ;==============================================================================
  4069. sub_0f6bh:
  4070. ld hl,l0f85h ;0f6b ; Point to "MEM ERR" message
  4071. jr l0f82h ;0f6e ; Jump to common print routine
  4072. sub_0f70h:
  4073. ld hl,l0f8fh ;0f70 ; Point to "FLOPPY CTC ERR" message
  4074. jr l0f82h ;0f73 ; Jump to common print routine
  4075. sub_0f75h:
  4076. ld hl,l0fa0h ;0f75 ; Point to "FLOPPY NEC ERR" message
  4077. jr l0f82h ;0f78 ; Jump to common print routine
  4078. sub_0f7ah:
  4079. ld a,001h ;0f7a ; Set error flag value
  4080. ld (01204h),a ;0f7c ; Store in drive status location (mark DMA error)
  4081. ld hl,l0fb1h ;0f7f ; Point to "DMA ERR" message
  4082. l0f82h:
  4083. jp l00fdh ;0f82 ; Call standard string print routine
  4084. ;==============================================================================
  4085. ; ERROR MESSAGE STRINGS (0x0F85-0x0FBA)
  4086. ;==============================================================================
  4087. ; Null-terminated error message strings displayed by the error routines above.
  4088. ; Each message includes CR/LF for proper console formatting.
  4089. ;
  4090. ; Messages:
  4091. ; • l0f85h: "MEM ERR" - Memory subsystem error
  4092. ; • l0f8fh: "FLOPPY CTC ERR" - CTC timing error for floppy operations
  4093. ; • l0fa0h: "FLOPPY NEC ERR" - NEC µPD765A FDC hardware error
  4094. ; • l0fb1h: "DMA ERR" - Z80 DMA controller error
  4095. ;==============================================================================
  4096. l0f85h: ; "MEM ERR" message
  4097. defb 0x4d ;0f85 'M'
  4098. defb 0x45 ;0f86 'E'
  4099. defb 0x4d ;0f87 'M'
  4100. defb 0x20 ;0f88 ' '
  4101. defb 0x45 ;0f89 'E'
  4102. defb 0x52 ;0f8a 'R'
  4103. defb 0x52 ;0f8b 'R'
  4104. defb 0x0d ;0f8c <CR>
  4105. defb 0x0a ;0f8d <LF>
  4106. defb 0x00 ;0f8e <NUL>
  4107. l0f8fh:
  4108. defb 0x46 ;0f8f 'F'
  4109. defb 0x4c ;0f90 'L'
  4110. defb 0x4f ;0f91 'O'
  4111. defb 0x50 ;0f92 'P'
  4112. defb 0x50 ;0f93 'P'
  4113. defb 0x59 ;0f94 'Y'
  4114. defb 0x20 ;0f95 ' '
  4115. defb 0x43 ;0f96 'C'
  4116. defb 0x54 ;0f97 'T'
  4117. defb 0x43 ;0f98 'C'
  4118. defb 0x20 ;0f99 ' '
  4119. defb 0x45 ;0f9a 'E'
  4120. defb 0x52 ;0f9b 'R'
  4121. defb 0x52 ;0f9c 'R'
  4122. defb 0x0d ;0f9d <CR>
  4123. defb 0x0a ;0f9e <LF>
  4124. defb 0x00 ;0f9f <NUL>
  4125. l0fa0h:
  4126. defb 0x46 ;0fa0 'F'
  4127. defb 0x4c ;0fa1 'L'
  4128. defb 0x4f ;0fa2 'O'
  4129. defb 0x50 ;0fa3 'P'
  4130. defb 0x50 ;0fa4 'P'
  4131. defb 0x59 ;0fa5 'Y'
  4132. defb 0x20 ;0fa6 ' '
  4133. defb 0x4e ;0fa7 'N'
  4134. defb 0x45 ;0fa8 'E'
  4135. defb 0x43 ;0fa9 'C'
  4136. defb 0x20 ;0faa ' '
  4137. defb 0x45 ;0fab 'E'
  4138. defb 0x52 ;0fac 'R'
  4139. defb 0x52 ;0fad 'R'
  4140. defb 0x0d ;0fae <CR>
  4141. defb 0x0a ;0faf <LF>
  4142. defb 0x00 ;0fb0 <NUL>
  4143. l0fb1h:
  4144. defb 0x44 ;0fb1 'D'
  4145. defb 0x4d ;0fb2 'M'
  4146. defb 0x41 ;0fb3 'A'
  4147. defb 0x20 ;0fb4 ' '
  4148. defb 0x45 ;0fb5 'E'
  4149. defb 0x52 ;0fb6 'R'
  4150. defb 0x52 ;0fb7 'R'
  4151. defb 0x0d ;0fb8 <CR>
  4152. defb 0x0a ;0fb9 <LF>
  4153. defb 0x00 ;0fba <NUL>
  4154. l0fbbh:
  4155. xor a ;0fbb Clear A register (A = 0)
  4156. ld (01226h),a ;0fbc Clear drive control flags
  4157. ld (01202h),a ;0fbf Set current drive number to 0 (start with drive A:)
  4158. ld (01225h),a ;0fc2 Clear drive parameter/selector
  4159. inc a ;0fc5 A = 1
  4160. ld (01227h),a ;0fc6 Enable drive operations (1 = enabled)
  4161. call l0de0h ;0fc9 Initialize FDC and check drive status
  4162. ld hl,01000h ;0fcc Set boot load address to 0x1000
  4163. l0fcfh:
  4164. ld (01200h),hl ;0fcf Store DMA/buffer address for disk operations
  4165. call l0dabh ;0fd2 Attempt to read boot sector from current drive
  4166. jp c,01000h ;0fd5
  4167. ld hl,l0fe1h ;0fd8
  4168. call l00fdh ;0fdb
  4169. jp l0294h ;0fde
  4170. l0fe1h:
  4171. defb 0x42 ;0fe1 'B'
  4172. defb 0x4f ;0fe2 'O'
  4173. defb 0x4f ;0fe3 'O'
  4174. defb 0x54 ;0fe4 'T'
  4175. defb 0x20 ;0fe5 ' '
  4176. defb 0x45 ;0fe6 'E'
  4177. defb 0x52 ;0fe7 'R'
  4178. defb 0x52 ;0fe8 'R'
  4179. defb 0x0d ;0fe9 <CR>
  4180. defb 0x0a ;0fea <LF>
  4181. defb 0x00 ;0feb <NUL>
  4182. l0fec: ; VERSION STRING - Displayed during system initialization
  4183. defb 0x56 ;0fec 'V'
  4184. defb 0x65 ;0fed 'e'
  4185. defb 0x72 ;0fee 'r'
  4186. defb 0x20 ;0fef ' '
  4187. defb 0x31 ;0ff0 '1'
  4188. l0ff1h:
  4189. defb 0x2e ;0ff1 '.'
  4190. defb 0x32 ;0ff2 '2'
  4191. defb 0x78 ;0ff3 'x'
  4192. defb 0x20 ;0ff4 ' '
  4193. defb 0x38 ;0ff5 '8'
  4194. l0ff6h:
  4195. defb 0x20 ;0ff6 ' '
  4196. defb 0x69 ;0ff7 'i'
  4197. defb 0x6e ;0ff8 'n'
  4198. defb 0x63 ;0ff9 'c'
  4199. defb 0x68 ;0ffa 'h'
  4200. l0ffbh:
  4201. defb 0x0d ;0ffb <CR>
  4202. defb 0x0a ;0ffc <LF>
  4203. defb 0x0a ;0ffd <LF>
  4204. defb 0x00 ;0ffe <NUL> - String terminator for print routine
  4205. defb 0xff ;0ffe FF