ZX Review #5-6
04 ноября 1997

Forum - Studying and debugging @ files using STS 5.1. Features of debugging using a monitor STS. Bugfix STS 5.1.

<b>Forum</b> - Studying and debugging @ files using STS 5.1.  Features of debugging using a monitor STS. Bugfix STS 5.1.
(C) Ivan Roshchin, Moscow, 1997


  Features of debugging

    using a monitor STS


    Surely every programmer in debugging their creations a 
thought: it would be good to any time during the program being 
debugged when you press a certain key combination to go into 
the debugger (eg, to see the values ​​of variables)

and then, as if nothing had happened
return to program execution. In the ZX-REVIEW have been 
articles on this theme (eg, p. 244

for 1991. on page 33 for 1993)..
Here I want to tell you about the application for this purpose, 
the most popular monitor debugger

STS.

    In the debugger, there is
opportunity to put in the program being debugged breakpoint
above which is the output of STS. Consider in detail what 
happens when you set a breakpoint (using key "W"), and leaving 
in STS, when the program being debugged has reached a 
breakpoint. 


  If you set a breakpoint:

1) of the cells and ADR_W ADR_W +1 Be
   address the previous point is taken

   breakpoint.
2) At this address is entered with
   derzhimoe three bytes of memory

   earlier (when installing the previous
   ing breakpoints) to remember
   GOVERNMENTAL in cells ADR_B-ADR_B +2.
3) In cell ADR_W and ADR_W +1 for
   sends the address noted

   cursor.
4) In the cell ADR_B-ADR_B +2 shown
   pertains contents of three bytes

   memory starting address of
   labeled with the cursor.
5) The address marked the course
   rum, recorded a team JP

   ADR_OST.


   When an executable program
reaches a breakpoint:

1) jumps to the address

   ADR_OST, and control variables
   given by the resident of the STS.
2) STS content stores

   all registers, interrupt mode
   vany etc.
3) From cells ADR_W and ADR_W +1 Be
   address breakpoint is taken.
4) At this address is entered with
   derzhimoe three bytes of memory

   earlier (when this

   breakpoints) stored in

   cells ADR_B-ADR_B +2.
5) You can work in STS.


    Given enough information to write
piece of software that, when
Pressing a certain combination
keys (eg, "SS + D" - from
words "Debugger") provides
entrance to the STS with the possibility of
further continuation of work
program being debugged. Need
only know the address ADR_W, ADR_B
and ADR_OST. I note that in different
STS versions of these addresses are different, and address 
ADR_OST depends More on the location of the STS-resident in 
memory. To find ADR_OST, just look what the command STS will 
supply when you press 'W'. To find ADR_B, you can say, write on 
some memory address bytes # AB, # CD, # EF, then put this 
address breakpoint and find the address at

STS which kept these three
bytes. To find ADR_W, to
put in a URL (eg # 8000) breakpoint, and then see where
These two bytes (# 00, # 80) are stored inside the STS.


    Here is the address for the five known versions of my STS 
(provided that the resident is on at # 5B90):



          ADR_W ADR_B ADR_OST

STS 3.2 # DFC3 # DFE4 # 5B98
STS 3.3 # DFC3 # DFE4 # 5B98
STS 4.1 # E064 # E07C # 5B9B
STS 4.3 # E06E # E088 # 5B9B
STS 5.1 # E02E # E038 # 5B9B


    The following piece of you
can insert in the remote
program, for example, after the procedure poll the keyboard or
another frequently used location.
I note that the address of its
location in memory must
be less than # C000, as in this
fragment switch banks
RAM.
140.
ADR_W EQU # E02E; these addresses are given for
ADR_B EQU # E038; STS version 5.1, if the resident
ADR_OST EQU # 5B9B; Available at # 5B90.
BANK_S EQU # 1F; BANK STS
BANK_D EQU # 18; Bank program being debugged


   LD BC, # 7FFE; ADDRESS keyboard port

   IN A, (C); CHECK OR DEPRESSED "SYMB.SHIFT"

   BIT 1, A; IF YES, SET FLAG Z

   JR NZ, NEXT_C; IF not pressed, exiting ...

   LD B, # FD; changes of address PORT

   IN A, (C); similarly verifies

   BIT 2, A; KEY "D".

   JR NZ, NEXT_C; IF not pressed, exiting ...


   LD BC, # 7FFD; determined by the Bank, in

   LD A, BANK_S; WHICH IS STS.


   OUT (C), A
140.
; Emulating for STS breakpoint:


   LD HL, ADR_B; HERE ARE 3 bytes

                      ; Memorized INSTALLATION

                      , Previous Breakpoints.

   LD DE, (ADR_W); ADDRESS WHERE they should be

                      ; PLACE (REQUIRED BELOW # C000)!

   LD BC, 3

   LDIR; RESTORES 3 bytes


   LD HL, NEXT_C; ADDRESS First team

   LD (ADR_W), HL; BE IMPLEMENTED AFTER EXIT

                      ; FROM STS, Writes CELL

                      ; ADR_W .. ADR_W +1 (STS THEY KEEP

                      ; Address to which was installed

                      ; Breakpoints).

   LD DE, ADR_B; IN CELLS ADR_B .. ADR_B +2 STS STORE

   LD BC, 3, 3 bytes, located at

   LDIR; Breakpoints.


   LD A, BANK_D; returned by the bank, who was

   OUT (C), A; before.

   JP ADR_OST; Breakpoints.

NEXT_C ... ; HERE TO BEGIN AFTER THE EXECUTION

                      ; OUT OF STS.
2

    After clicking the "SS + D" and go to the STS all the 
registers take values ​​that were at the time

termination of a program, so that
can continue its execution.

    In the process of debugging can be
put a breakpoint in the program, if only at the time of
The above code
(When removing the old point
Stop and put new) address
old breakpoint was lower than
# C000.

    You can continue with the program being debugged with
the place where it was stopped, for example, in the step
regime ("SS + Z", "SS + X", "SS + T")
or using the window Trace, or
keyboard shortcut "SS + J"
(STS in versions below 4.0, use the "J", setting the address
run whatever is PC,
or use a combination of
"SS + K", but it will remain
Screen STS). If you want to go back to the assembler, BASIC or
TR-DOS, use the key "Q".


    If your program hangs some unknown reason, STS also can 
help you. For this you have to build a fragment similar to that 
described above, to handle the interrupt 2-nd kind. Bring to 
your attention already finished processing procedure

interrupts, which is just as
and described above, verifies the fact
pressing the "SS + D" and enters the STS.
After exiting the STS performance
the program being debugged will be
resume from where it
was interrupted by an interrupt handler procedure. Therefore, 
while in the STS, you can determine which part of the program 
caused the "hang" register content PC.


    Restriction on the address of the procedure in the memory 
is the same as that previously described fragment. 140.

ADR_W EQU # E02E; these addresses are given for
ADR_B EQU # E038; STS version 5.1, if the resident
ADR_OST EQU # 5B9B; Available at # 5B90.
BANK_S EQU # 1F; BANK STS
BANK_D EQU # 18; Bank program being debugged


   EX (SP), HL; return address from interrupt

   LD (M1 +1), HL; Writes CELL M1 +1, and M1 +2

   EX (SP), HL

   PUSH AF; stored in the stack

   PUSH BC; register value

   PUSH DE

   PUSH HL

   PUSH IX

   PUSH IY

   EXX

   EX AF, AF '

   PUSH AF

   PUSH BC

   PUSH DE

   PUSH HL


   CALL USER; HEREIN MAY BE POLL

                   ; KEYPAD, CALL MUSIC

                   , In general, anything you want.


   LD BC, # 7FFE; ADDRESS keyboard port

   IN A, (C); CHECK OR DEPRESSED "SYMB.SHIFT"

   BIT 1, A; IF YES, SET FLAG Z

   JR NZ, NEXT_C; IF not pressed, exiting ...

   LD B, # FD; changes of address PORT

   IN A, (C); similarly verifies

   BIT 2, A; KEY "D".

   JR NZ, NEXT_C; IF not pressed, exiting ...


   LD BC, # 7FFD; determined by the Bank, in

   LD A, BANK_S; WHICH IS STS.

   OUT (C), A

; Emulating for STS breakpoint:


   LD HL, ADR_B; HERE ARE 3 bytes

                      ; Memorized INSTALLATION

                      , Previous Breakpoints.

   LD DE, (ADR_W); address at which they MUST

                      ; PLACE

   LD BC, 3

   LDIR; RESTORES 3 bytes

M1 LD HL, 0; ADDRESS First team

   LD (ADR_W), HL; BE IMPLEMENTED AFTER EXIT

                      ; FROM STS, Writes CELL

                      ; ADR_W .. ADR_W +1 (STS THEY KEEP

                      ; Address to which was installed

                      ; Breakpoints).

   LD DE, ADR_B; IN CELLS ADR_B .. ADR_B +2 STS STORE

   LD BC, 3, 3 bytes, located at

   LDIR; Breakpoints.


   LD BC, # 7FFD

   LD A, BANK_D; returned by the bank, who was

   OUT (C), A; before.


   POP HL; RESTORES

   POP DE; register value

   POP BC

   POP AF

   EXX

   EX AF, AF '

   POP IY

   POP IX

   POP HL

   POP DE

   POP BC

   POP AF

   EX (SP), HL; removes from STACK

   POP HL; return address

   EI

   JP ADR_OST; Breakpoints.

; After exiting the STS program execution
; Continue from where it was interrupted
; Interrupt servicing routines.

NEXT_C; If the call STS will not need:


   POP HL; RESTORES

   POP DE; register value

   POP BC

   POP AF

   EXX

   EX AF, AF '

   POP IY

   POP IX

   POP HL

   POP DE

   POP BC

   POP AF

   EI

   RET; AND EXIT FROM THE INTERRUPTION.
2

    When debugging programs often
used together STS and assembler (TASM, MASM, ZX ASM and
etc.), which is very convenient. If the
your program is built is one of the
the above-described fragments, you
should pay special attention
on how you run a program for execution. If the
STS, everything will be fine anyway. If the program
start of assembly or
BASIC, you may not be able to leave the STS when you
"SS + D", or you will go to the STS, but
not be able to continue the program.



    It is known that stepping processor commands the STS
in three ways:
using shortcuts
"SS + Z", "SS + X" and "SS + T". I'll try
talk about the features of these
ways and that, when better
use each of them:

1) "SS + Z" - is posha
   govoe command execution of
   core processor Z80. No slozhnos
   Tay using "SS + Z"

   should not be, not only

   trace command HALT,

   when the interruption is prohibited -

   otherwise, the computer freezes.

2) "SS + X" - the same as the "SS +

   Z ", but the team will CALL you
   polyene directly without

   trace caused by
   program, which is assumed
   assumed already debugged. The same

   As for the team and RST (incidentally
   TI, in the description of references STS'a
   is only a CALL, but about the RST

   not a word). Executable

   command can also be found in

   RAM and ROM. This is the best free software
   proper to carry out well-functioning

   routines, but it has

   One more feature: as you
   subroutine call is

   of the resident, the stack instead of

   addresses should be carried out

   commands in your program will

   listed address for return

   resident. Almost always, it is not

   is irrelevant, but

   Some routines can

   use the contents of the degree
   ka. For example, when debugging

   their programs, I have often used
   favor of a subroutine that

   when it is called print on

   the screen contents of the registers

   processor at the time of the call.

   To determine the value of PC,

   it examines what address

   was included in the stack when it is you
   call of.

3) "SS + T" - debugger puts

   after the command being executed,

   which can not be in

   ROM breakpoint and triggering
   follows the program being debugged.

   By this point, the WHO
   rotates through a resident in

   STS.


   "SS + T" is convenient to apply for
Trace DJNZ, but to trace routines (CALL, RST)
better this method is not used, since can be a nuisance. This 
is seen in the following example: 140.

# 8000: CALL # 8004
# 8003: RET
# 8004: LD A, 7
# 8006: OUT 254, A
# 8008: RET
2

   This program must set the white color of the border. If
execute it step by step
with "SS + Z", we can see that this is what she does. However, 
if you execute it, pressing the "SS + T", the expected result 
you get. To understand why this occurs, analyze in detail

algorithm of the debugger when
Pressing "SS + T":

   - After the current command (in
case CALL # 8004) is put the breakpoint (the team
JP, occupying 3 bytes). Former
at this place 3 bytes are stored.

  - Control is transferred to the address # 8000;

  - When a breakpoint is going back to the debugger, memorized 
3 bytes restored. 


   All is good, but in this case 3 bytes command
JP superimposed on the address to
which control is transferred to the
command CALL # 8004. As a result, this is really done
The following sequence of commands:
140.
# 8000: CALL # 8004
# 8004: SBC A, E
# 8005: LD E, E
# 8006: OUT (254), A
# 8008: RET
# 8003: JP # 5B9B
2

   Of course, all of the above applies to the command processor 
DJNZ, so that the "SS + T" should be used with caution.

For example, what may be
The situation in the trace DJNZ:
140.
# 8000: LD B, # 00
# 8002: LD A, (# 800A)
# 8005: OUT (# FE), A
# 8007: DJNZ # 8002
# 8009: RET
# 800A: DB 0; BYTES spoil
2



   Now let's talk about step by step
trace (window Trace). In this
window has a parameter Trace Call.
If it is enabled, the debugger will
to go "inside" the procedure for
Each command CALL
or RST (emulates "SS + Z"), and
If turned off - to perform it with
using a direct run from the resident ("SS + X"). I think that 
would be a useful opportunity regardless of the Trace Call 
disable tracing routines whose addresses are outside the 
pre-defined boundaries. These borders must be made in

window Trace. For example, if the lower limit is # 4000 and the 
top # FFFF, the debugger will not be to go "inside" of all 
sub-ROMs. But since this possibility in the STS there remains 
only hope that it will in one of the following versions.




            *

(C) Ivan Roshchin, Moscow, 1997


   Bugfix STS 5.1


   In STS 5.1 there is a debugger
an issue which can not be
normally edit the contents of memory in symbolic form.
Consider this example: Suppose at # 8007 to put the code
symbol "P":


# 8000 00 00 00 00 00 00 00 00
# 8008 00 00 00 00 00 00 00 00

Enter into edit mode and
indicate the symbol "P":


# 8000 00 00 00 00 00 00 00 00 P
# 8008 00 00 00 00 00 00 00 00

But after clicking 'ENTER' expected results have not been ...


# 8000 50 00 00 00 00 00 00 00 P
# 8008 00 00 00 00 00 00 00 00


   To correct this error
make the following changes to the file "sts5.1a":
140.

   - Starting at address # DE1C
enter the command:


       CALL # E681

       NOP

       NOP

       NOP


   - At # E67F place
Bytes # 2E, # 00;

   - Starting at address # E681
enter the command:


       JP Z, # E5BD

       OR C

       JP # E590
2

   In this case, you have to sacrifice a part of a text message
"File exist, overwrite ...", from
which in the end will only
"File exist, over.".


            *







Other articles:

Adventure Project - Design and razrabotaka Adventyurnyh and RPG games.

Adventure Project - Russification adventyur.

TR-DOS for beginners - Continued.

Authoring - Scorpion 2000 (S. Zonov).

Authoring - Trampoline (S. Veremeenko).

Business Card - a new electronic humor magazine "SpectrofUn".

Crossing Dragon - Promotion of the game Finders Keepers.

Crossing Dragon - Promotion of the game Knight Tyme.

Crossing Dragon - Game Promotions Spellbound.

Crossing Dragon - Game Promotions Stormbringer.

Retro - 40 best procedures: Merge images, rotation of the symbol clockwise Inverting character, changing the attribute, fill circuit construction templates (Dzh.Hardman, E. Hyuzon.).

Expert Tips - Total Eclipse 2.

Expert Tips Super League.

Forum Games - Description of the game land of myths.

Forum Games - Passage Renegade.

Forum Games - Subtleties trading game Elite

Forum - Studying and debugging @ files using STS 5.1. Features of debugging using a monitor STS. Bugfix STS 5.1.

Forum - compression programs.

forum - Reduction in the time format. On the recording sectors while formatting. Rebuilding the screen for one interrupt.

Forum - Features assembly ZX ASM 3.0.

Forum - As for the BASIC compiler "Blast".

Forum - With regard to relotsiruemyh programs.

Forum - Program "Flame" and "Dragon."

reader-reader - TR-DOS: how to avoid mistakes?

reader-reader - The effective work with the drive.

ethidium - The calculation of addresses in the file attributes. Program scrolling specified window 1 pixel to the right. Cleanup of the specified window. Procedure display images from the buffer.

Studies - LED channel music processor. The procedure for cleaning the screen. Proposal for standardization.

Studies - A set of eight programs of "extension" screen. Two procedures are manifestations of the screen.

Studies - New themes for development.

Studies - Playback software tool from the editors of digitized music.

Studies - processing program @ BASIC files.

Studies - The procedure for turning the symbol 90 degrees clockwise.

Studies - The procedure for searching text files.

Studies - Screen procedure "UP HL".


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Copyright notice - The paper is distributed under the BUZZ FREEWARE.
Forum - An interview with Nikolay Noskov and Ivan Makarchenko, creators of "PETERS".
Iron - On AY-mouse (FAQ).

В этот день...   30 April