LZ: debug program


[Prev][Next][Index][Thread]

LZ: debug program



Here is a debugging program that I wrote that displays the values of the
registers a, b, c, d, e, h, and l. Anyone with a little programming
experience could write the same thing, so this is intended for beginners who
want to know why their programs don't work. I know I have found some stupid
mistakes with this program such as forgetting that certain ROM_CALL's
destroy the registers, such as CLEARLCD (BTW, it does NOT set hl to 0:) and
D_HL_DECI (which also messes with the hl register). If anyone wishes to
modify it, feel free to do so short of stealing credit (you may even want to
include "tested by David Kristensen's debugging program" in your
documentation if you use this program). One thing I have no use for yet, but
other people might would be to include a flag register display also. It
wouldn't be too hard, but it would be a little more complex than the rest of
the program.


How to use this:
  I recommend a macro like this at the start of your program:
#DEFINE debug  CALL_(DEBUG)
  You can also add a feature that would exit from the program quickly by
pressing the clear key:
#DEFINE debug  CALL_(DEBUG)  cp $F  ret z
Unfortunately, this feature only works if you are in the main loop of a
program (not in a call subroutine) and if you have not pushed or poped
anything beforehand.
To use this program, simply type in debug on a separate line anywhere in
your program (with the macro included at the top). The calculator will
display the register. Press any key to exit to your program. Note: if you do
not have the second macro above, do not press the clear key as this will
mess up some registers.
Whether you use the macro or not, you must include debug.asm somewhere in
your program. You can just insert #include "debug.asm" anywhere in your
program and then CALL_(DEBUG) to run it. I recommend, however, that you
insert this line at the end of your program, as if you insert it at the
beginning, it will be the first thing to run when you start your program.


Here's an example of how to use this:
#include "ti-85.h"
#DEFINE debug  CALL_(DEBUG)  cp $F  ret z
.org 0
.db "try program", 0
        ROM_CALL(CLEARLCD)
        debug
        ld hl, $0000
        ld de, $FFFF
        debug
        ex hl, de
        debug
        ret
#include "debug.asm"
.End


The program would clear the screen, then show how the registers are affected
by doing this. After pressing a key, you would see that h and l are 0, while
d and e are FF. After pressing another key, h and l would be FF and d and e
would be 0. Pressing the clear key at any time would exit from the program.


Here it is (finally) and have fun!


data    =$8101
DEBUG:        
        push af
        push bc
        push de
        push hl
        push hl
        push de
        push bc
        push af
        ROM_CALL(CLEARLCD)
        ld l, $FF
        ld a, 'a'
        CALL_(PRINT)
        ld a, 'b'
        CALL_(PRINT)
        ld a, 'c'
        CALL_(PRINT)
        ld a, 'd'
        CALL_(PRINT)
        ld a, 'e'
        CALL_(PRINT)
        ld a, 'h'
        CALL_(PRINT)
        ld a, 'l'
        CALL_(PRINT)
        ld l, $FF
        pop af
        CALL_(Print)
        pop bc
        push bc
        ld a, b
        CALL_(Print)
        pop bc
        ld a, c
        CALL_(Print)
        pop de
        push de
        ld a, d
        CALL_(Print)
        pop de
        ld a, e
        CALL_(Print)
        ld b, l
        pop hl
        push hl
        ld l, b
        ld a, h
        CALL_(Print)
        ld b, l
        pop hl
        ld a, l
        ld l, b
        CALL_(Print)
        jr getloop
PRINT:
        ld h, 1
        inc l
        ld (CURSOR_ROW), hl
        ROM_CALL(TX_CHARPUT)
        ret
Print:        
        ld (data), a
        ld h, 3
        inc l
        ld (CURSOR_ROW), hl
        push hl
        ld hl, (data)
        ROM_CALL(D_HL_DECI)
        pop hl
        ret
getloop:
        call GET_KEY
        or a
        jr z, getloop
        pop hl
        pop de
        pop bc
        cp $F
        jr z, nope
        pop af
        jr leave
nope:        
        pop bc
leave:
        ret


David Kristensen at the University of Missouri - Kansas City
dkristensen@cctr.umkc.edu


The Mind conquers All...


Follow-Ups: