ZX Club #04
16 сентября 1997 |
|
Soft group - Intercepting System Errors in Basic and TR-DOS when programming in assmblere (procedure).
Programmers who try to write high-quality programs to run on computers compatible with the ZX Spectrum, faced with some problems of methodological and practical plan. One of them, perhaps the most annoying is the fact that when the any read / write drive system TR-DOS can clear the screen and the message that there was a disk error or that the diskette installed security token from the record. After that, she asked whether to try the operation again, interrupt it or ignore it. For the programmer, a problem that appears the need to restore the screen after Treatment for DOS. In addition, the system changes the number of the current flow. In general, a program running in, say, windowed interface should be fully processed his mistakes in this interface. Next I'll show you how to intercept functions described TR-DOS better, in my view method. Unfortunately, in this If you can not select a certain covering all possible situations the algorithm therefore be given a concrete example, taken from the windowing applied programs developed by the author. But first a few words about how the TR-DOS ROM is drawn to the main computer. As you know, shadow ROM system TR-DOS is connected to the place of the main ROM computer when accessing the processor to certain memory addresses to read the operation code. One of these addresses is the address of # 3D13 - the entry point to serve TR-DOS. This connection sets up a special trigger in Beta Disk Interface, and additional ROM is connected to the treatment CPU for the operation code beyond this Rom. Then the trigger is reset. If the TR-DOS why either need to turn to the main memory (for example, to clear the screen, display characters, etc.), then she does this as follows: 1) placed on the stack the return address for the current part or module TR-DOS; 2) placed on the stack address is required routines in the main ROM; 3) to go at 23,746; 4) because it is the address of RAM Shadow ROM is disabled (cleared by hardware trigger); 5) at this location is situated instruction RET, therefore, is taken from the stack address subroutine in the main ROM and it runs; 6) RET instruction at the end of the running subroutine will jump back in the shadow ROM system TR-DOS. The proposed example shows how You can apply to the TR-DOS, so that no allow it to clear the screen and give their Your Message to the bottom window of the screen. Instead of Your Message of TR-DOS is given in the window "Communication systems" used window interface. In the example, there is recourse to undescribed here windowing procedures. Projecting their routine similar purpose, you can insert into place calls to these procedures, their specific calls with similar functions. In this case, call TR-DOS divided into 3 phases: 1) preliminary tasks: setting interceptors; 2) immediately call TR-DOS at # 3D13 (with ability to work interceptors); 3) completing the operation: the removal of interceptors. The program is written in assembler mnemonics HiSoft GEN Assembler Version 4.1. So the first step - installing interceptors. DOSPRE SUB A LD (RSTFLG), A; message still DOS ; Not issued LD HL, $ $ DOSW LD (RSTPTR), HL; pointer in the text, and those windows - to enter characters CALL CLKON; show cursor ; An hourglass - a long opera, tion " CALL IM1; transfer system ; In interrupt mode 1 , Followed by steps to install the ne; rehvatchikov DOSSWP LD HL, DOS_ST; the first area ; Exchange LD DE, 23746, the second region LD BC, 3; the length of the SWAP2 LD A, (DE); exchange content ; Memory areas LDI DEC HL LD (HL), A INC HL JP PE, SWAP2 , So the team RET at ; 23746 replaced on the team JP DOSEMT LD HL, (23633) is a systemic transition; belt CURCHL LD C, (HL) INC HL LD B, (HL); the address formation; botchika display the current channel LD DE, (DOS_CH); in DOS_CH address , Our handler LD (DOS_CH), BC; rearrange them LD (HL), D DEC HL LD (HL), E , So the procedure for deriving the current ; Substituted for a special channel. Set; ka interceptor finished. RET ; Directly call DOS ; After a single run DOSPRE, you can ; Many times to run DOS; nuzh after all, but run DOSEND DOS PUSH AF LD (IY), -1; "no errors" SUB A; initial value, the return code of TR-DOS LD (23823), A LD (23824), A POP AF CALL # 3D13; run TR-DOS LD A, (23823), setting a flag ; CY on return code TR-DOS AND A RET Z; if code = 0, then ; CY = 0 SCF RET ; Area for temporary storage transition team DOS_ST JP DOSEMT ; Temporary storage registers DOS_HL DEFW 0 DOS_BC DEFW 0 ; Address of the procedure output to a pipe DOS_CH DEFW DOSRST ; Interceptor access to the main ROM; And if the module is running, hence, TR-DOS , Calls the subroutine main ROM DOSEMT LD (DOS_HL), HL; maintain registration; algebra LD (DOS_BC), BC POP BC; is the address of the OS; novnom ROM PUSH AF AND A LD HL, # D6B SBC HL, BC; address = # D6B? ; (Sub clearing the screen) JR Z, DOSCLS; if so, run, eat new module cleanup AND A LD HL, # 1601, Address = # 1601? ; (Sub-setting the current flow) SBC HL, BC JR Z, DOSIGN; if so, ignored; fix the call flow does not change ; Called routine is not one of ; Intercepted, so it ipolnyaem POP AF PUSH BC; vozvrashenie address on ; Place LD HL, (DOS_HL); return result; Giustra LD BC, (DOS_BC) RET; execution ordered ; Sub main ROM DOSIGN POP AF RET ; Non-zero value of this flag indicates ; That the message box TR-DOS is already open, then RSTFLG DEFB 0 ; Address space of the next character in the The text box RSTPTR DEFW $ $ DOSW ; Routine cleaning windows, replacing ; Routine cleaning of the screen DOSCLS POP AF; concrete action, not principal conditions LD HL, $ $ DOSW LD DE, $ $ DOSW +1 LD BC, 5 * 1.21 LD (HL), 255 LDIR LD HL, $ $ DOSW LD (RSTPTR), HL LD A, (RSTFLG); if the window is not on, indoor AND A LD A, 28 CALL Z, OPEN; then open it LD A, -1 LD (RSTFLG), A; change the flag JP REDRAW; redraw neighborhood, but ; Subroutine output symbol in the window replacement; sculpt a character output in the region "K" ; Screen DOSRST PUSH BC PUSH DE PUSH HL LD HL, (RSTPTR) LD (HL), A INC HL LD (RSTPTR), HL CALL TEXTON; update the text in the ; Window POP HL POP DE POP BC RET ; Cleanup operations after a series of calls ; DOS DOSEND LD (IY), -1; "no error occurred" CALL IM2; return mode ; Interrupt 2 CALL CLKOFF; remove cursor ; Hourglass CALL DOSSWP; bring back all ; Vector conversion and Indices LD A, (RSTFLG); if the window messages; of TR-DOS revealed AND A CALL NZ, CLOSE; then close it RET Thus, if the TR-DOS wants to during operation to give a message Disk error or Read only, it is the first step attempt to clean the screen. This attempt will be detected DOSEMT and instead of cleaning screen will be executed withdrawal message box TR-DOS and its purification. Further, TR-DOS tries to open a stream associated with the channel "K" for issuing the message. This attempt also will be caught and ignored. After this transition at # 10 system will print a message. It would seem possible at the same subprogram DOSEMT "catch" and this situation and do not capture the output in the current channel. Experiments have shown that it works, but for output numbers TR-DOS uses the procedure OUT_NUM, which accounts in which case also intercept and emulate that awkward and inelegant. It is much easier to intercept the output channel at the level of the leader tape channel, as done in DOSSWP. As a result of TR-DOS message appears in a beautiful multi-color box in the middle of the screen, not the bottom. The user can respond to a request in the same way as always. In addition, the screen is not broken, that very convenient for the programmer. Upon completion of the sequence of calls to TR-DOS window closes (in the procedure DOSEND). Consult the author You may, by writing to: 257010 Ukraine, Cherkassy-10, PO Box 1529 Kuritsyna BA
Other articles:
From the Editor - On the new sections in the newspaper. |
From the Editor - News from Hughes Garrison. |
Soft group - Intercepting System Errors in Basic and TR-DOS when programming in assmblere (procedure). |
Club IM2 - Work with gaps 2-nd kind. (Train from LASER B.) |
Covox - What is the COVOX (scheme). |
Enjoy - Jokes ... |
Similar articles:
В этот день... 23 November