2024-01-23 Debugging ZIP
Tags: zip, todayilearned, z80
Published: 2024-02-07 03:00:35

The division problem above was caused by an error in TIL; in D/MOD the line
```
mov1:     ld      d,a     ; store divisor
```
Should be
```
mov1:     ld      e,a     ; store divisor
```
This sets up the arguments to $UD/ correctly, resulting in a correct division.

Now ZIP can print numbers:
```
    DP .
```
yields 
```
   FA  OK
```

```
  DP @ .
```
yields
```
   C4F OK
```
Started in on the number interpreter….

Debugging revealed a couple of transcription errors, and a assembly dialect issue:

Where TIL codes “ADC  A”, z80asm needs “ADC   A,A”, otherwise it assembles an “ADC  A,IXL” instruction.


Now zip can
```
   1000 . 
```
yielding
```
   1000 OK
```

ZIP is printing a garbage character at the end of the “.” string. TIL pushes a space character with the high bit set as an end-of-string marker. I suspect that on Loeliger’s system the terminal ignored the high bit and printed an ordinary space. I am adding a bit of code to clear the high bit.


Works:
```
   !    C!    @   C@   
```
```
1 2 + 
0 OK
```
Plus not working.
```
plus:   dw      $+2     
        pop     hl      ; get first word
        pop     de      ; get second word
        add     hl,de   ; add them
        push    hl      ; push sum
        nxt   
```
That sure looks ok

Heh.  I traced “1 2 + .” and it never executed that code.  I made a typo; the “=” keyword has an incorrect entry “+”.

Ok, + works.
```
1 2 + .                3  OK
```
```
2000 @ .              0  OK
1234 2000 ! 2000 @ .                1234  OK
56 2000 C!  2000 @ .                1256  OK
2000 C@ .                            56  OK
2000 @ . 10 2000 +! 2000 @ .           1256 1266  OK
```
+! works
```
DP @ .                            C52  OK
1234 ,  DP @ .                
```
Crash….  comma not working.

Transcription error; forgot the nxt.
```
DP @ .                C54  OK
1234 , DP @ .          C56  OK
C54 @ .               1234  OK
```
comma works
```
2 1 - .              -1  OK
```
That’s wrong…

Typo in -1
```
   db 1, “-1 “
```
should be
```
   db 2,”-1”
```
```
2 1 - .           1  OK
1 2 - .            -1  OK
-1 .  -1  OK
```
minus works
```
1 0= .               0  OK
0 0= .                1  OK
-1 0= .             0  OK
8000 0= .            0  OK
```
0=  works.
```
1 2+ . 3  OK
```
2+ works
```
1 ABS .          1  OK
-1 ABS .         1  OK

0 ASCII .         30  OK
F ASCII .          46  OK

ASPACE .          20  OK

BASE @ . 10  OK

12 C,       crash
```
Forgot nxt
```
DP @ .          C56  OK
DP @ C@ .        2  OK
12 C, C56 C@ .    12  OK
```
C, works
```
1234 2000 !  2000 C0SET 2000 @ .             1200  OK
```
C0SET works

Skipping CA!
```
3 CCONSTANT 3 
`
RESTART
```
Not good.
```
CREATE FOO      
RESTART
```
The problem seems to be in CREATE.

Forgot the trailing semi
```
CREATE FOO  OK
3 CCONSTANT FOO  OK
FOO . 
FOO ?
DP @ .                 C58  OK
3 CCONSTANT FOO               OK
C58 C@ .                      3  OK
C59 C@ .                      46  OK
C5A C@ .                      4F  OK
C5B C@ .                      4F  OK
FOO 
FOO ?
```
It is building the dictionary entry correctly, but not finding it.  Almost certainly a problem in the vocabulary words.
```
CURRENT @ .   A11  OK
```
```
0a11 3c                         inc     a       ; else bump high
```
That’s not right.
```
CURRENT . 0  OK
```
Ahh. Not initialized?

Ahh. SYS needs to be page aligned.
```
CURRENT .           10E  OK
CURRENT @ .         9AF  OK
3 CCONSTANT FOO     OK
FOO .               3  OK
```
Skipping COMPILER, CORE, CONTEXT, CURRENT, DOES>

(Can’t test DOES> without <BUILDS)
```
1 2 DROP .    1  OK
3 DUP . .        3 3  OK
ENTRY .    
ENTRY ?
```
Typo; length byte wrong.
```
ENTRY .      C46  OK
HERE .      C58  OK
LBP .        
LBP ?
```
Length byte wrong
```
LBP .       104  OK
1 2 OVER . . .       1 2 1  OK
```
Skipping R> 
```
1 2 SWAP . .         1 2  OK
```
Skipping VOCABULAARY

That’s all of the defined words.

Added tick; crashes.
```
aspace token dp    OK
context @ @ search     OK
. 0  OK
. 
```
Hangs when the address is printed??

Back jump address in *END
```
' dp .             A9E  OK
```
Committed and pushed.

Added *

But:
```
zip.l.asm:841: error: `,' expected. Remainder of line: _uds	; multiply 16x8 

        call    _isign  ; field input signs
        call    p_uds   ; multiply 16x8
        call    _posign ; Justify result
```
I have no idea what it is complaining about

Huh. no embedded underscores…  Ok when defined, fail when referenced… only when referenced by call; jumping to them is okay.
```
2 2 * . 4  OK
```
Added
```
*+LOOP
*/
*/MOD
*C+LOOP
*CDO
*CLEAVE
*CLOOP
*DO
*LEAVE
*LOOP
```