Previous | Contents | Next

LENSLIST2

NEW ROM

In chapter 16 there's a program which I've called LENSLIST. I really liked this program since I've been used to the single byte list in HEXLD3, but it has some shortcomings and so I've decided to implement a more robust version. I am proudly going to state that this is my first ZX81 machine code program which I've achieved by reading this book, so thanks Toni Baker :)

Program Organisation
This should be written with HEXLD3D (chapter11-hexld3d.p)
which has its machine code located between 4A82 and 4B77
(RAMTOP should be set to 4A00).

Program Listing
Don't be put off by this table; it's only 256 bytes
but I've shown the individual bits to track errors.
You only need type-in the hex bytes down the left.

;                   After -- DD ED FD
4B78: 40    LENS     DEFB 01-00-00-00        00
      C0             DEFB 11-00-00-00        01
      40             DEFB 01-00-00-00        02
      40             DEFB 01-00-00-00        03
      40             DEFB 01-00-00-00        04
      40             DEFB 01-00-00-00        05
      80             DEFB 10-00-00-00        06
      40             DEFB 01-00-00-00        07
      40             DEFB 01-00-00-00        08
      51             DEFB 01-01-00-01        09
      40             DEFB 01-00-00-00        0A
      40             DEFB 01-00-00-00        0B
      40             DEFB 01-00-00-00        0C
      40             DEFB 01-00-00-00        0D
      80             DEFB 10-00-00-00        0E
      40             DEFB 01-00-00-00        0F

4B88: 80             DEFB 10-00-00-00        10
      C0             DEFB 11-00-00-00        11
      40             DEFB 01-00-00-00        12
      40             DEFB 01-00-00-00        13
      40             DEFB 01-00-00-00        14
      40             DEFB 01-00-00-00        15
      80             DEFB 10-00-00-00        16
      40             DEFB 01-00-00-00        17
      80             DEFB 10-00-00-00        18
      51             DEFB 01-01-00-01        19
      40             DEFB 01-00-00-00        1A
      40             DEFB 01-00-00-00        1B
      40             DEFB 01-00-00-00        1C
      40             DEFB 01-00-00-00        1D
      80             DEFB 10-00-00-00        1E
      40             DEFB 01-00-00-00        1F

4B98: 80             DEFB 10-00-00-00        20
      F3             DEFB 11-11-00-11        21
      F3             DEFB 11-11-00-11        22
      51             DEFB 01-01-00-01        23
      40             DEFB 01-00-00-00        24
      40             DEFB 01-00-00-00        25
      80             DEFB 10-00-00-00        26
      40             DEFB 01-00-00-00        27
      80             DEFB 10-00-00-00        28
      51             DEFB 01-01-00-01        29
      F3             DEFB 11-11-00-11        2A
      51             DEFB 01-01-00-01        2B
      40             DEFB 01-00-00-00        2C
      40             DEFB 01-00-00-00        2D
      80             DEFB 10-00-00-00        2E
      40             DEFB 01-00-00-00        2F

4BA8: 80             DEFB 10-00-00-00        30
      C0             DEFB 11-00-00-00        31
      C0             DEFB 11-00-00-00        32
      40             DEFB 01-00-00-00        33
      62             DEFB 01-10-00-10        34
      62             DEFB 01-10-00-10        35
      B3             DEFB 10-11-00-11        36
      40             DEFB 01-00-00-00        37
      80             DEFB 10-00-00-00        38
      51             DEFB 01-01-00-01        39
      C0             DEFB 11-00-00-00        3A
      40             DEFB 01-00-00-00        3B
      40             DEFB 01-00-00-00        3C
      40             DEFB 01-00-00-00        3D
      80             DEFB 10-00-00-00        3E
      40             DEFB 01-00-00-00        3F

4BB8: 44             DEFB 01-00-01-00        40
      44             DEFB 01-00-01-00        41
      44             DEFB 01-00-01-00        42
      4C             DEFB 01-00-11-00        43
      44             DEFB 01-00-01-00        44
      44             DEFB 01-00-01-00        45
      66             DEFB 01-10-01-10        46
      44             DEFB 01-00-01-00        47
      44             DEFB 01-00-01-00        48
      44             DEFB 01-00-01-00        49
      44             DEFB 01-00-01-00        4A
      4C             DEFB 01-00-11-00        4B
      40             DEFB 01-00-00-00        4C
      44             DEFB 01-00-01-00        4D
      62             DEFB 01-10-00-10        4E
      44             DEFB 01-00-01-00        4F

4BC8: 44             DEFB 01-00-01-00        50
      44             DEFB 01-00-01-00        51
      44             DEFB 01-00-01-00        52
      4C             DEFB 01-00-11-00        53
      40             DEFB 01-00-00-00        54
      40             DEFB 01-00-00-00        55
      66             DEFB 01-10-01-10        56
      44             DEFB 01-00-01-00        57
      44             DEFB 01-00-01-00        58
      44             DEFB 01-00-01-00        59
      44             DEFB 01-00-01-00        5A
      4C             DEFB 01-00-11-00        5B
      40             DEFB 01-00-00-00        5C
      40             DEFB 01-00-00-00        5D
      66             DEFB 01-10-01-10        5E
      44             DEFB 01-00-01-00        5F

4BD8: 44             DEFB 01-00-01-00        60
      44             DEFB 01-00-01-00        61
      44             DEFB 01-00-01-00        62
      40             DEFB 01-00-00-00        63
      40             DEFB 01-00-00-00        64
      40             DEFB 01-00-00-00        65
      62             DEFB 01-10-00-10        66
      44             DEFB 01-00-01-00        67
      44             DEFB 01-00-01-00        68
      44             DEFB 01-00-01-00        69
      44             DEFB 01-00-01-00        6A
      40             DEFB 01-00-00-00        6B
      40             DEFB 01-00-00-00        6C
      40             DEFB 01-00-00-00        6D
      62             DEFB 01-10-00-10        6E
      44             DEFB 01-00-01-00        6F

4BE8: 62             DEFB 01-10-00-10        70
      62             DEFB 01-10-00-10        71
      66             DEFB 01-10-01-10        72
      6E             DEFB 01-10-11-10        73
      62             DEFB 01-10-00-10        74
      62             DEFB 01-10-00-10        75
      40             DEFB 01-00-00-00        76
      62             DEFB 01-10-00-10        77
      44             DEFB 01-00-01-00        78
      44             DEFB 01-00-01-00        79
      44             DEFB 01-00-01-00        7A
      4C             DEFB 01-00-11-00        7B
      40             DEFB 01-00-00-00        7C
      40             DEFB 01-00-00-00        7D
      62             DEFB 01-10-00-10        7E
      40             DEFB 01-00-00-00        7F

4BF8: 40             DEFB 01-00-00-00        80
      40             DEFB 01-00-00-00        81
      40             DEFB 01-00-00-00        82
      40             DEFB 01-00-00-00        83
      40             DEFB 01-00-00-00        84
      40             DEFB 01-00-00-00        85
      62             DEFB 01-10-00-10        86
      40             DEFB 01-00-00-00        87
      40             DEFB 01-00-00-00        88
      40             DEFB 01-00-00-00        89
      40             DEFB 01-00-00-00        8A
      40             DEFB 01-00-00-00        8B
      40             DEFB 01-00-00-00        8C
      40             DEFB 01-00-00-00        8D
      62             DEFB 01-10-00-10        8E
      40             DEFB 01-00-00-00        8F

4C08: 40             DEFB 01-00-00-00        90
      40             DEFB 01-00-00-00        91
      40             DEFB 01-00-00-00        92
      40             DEFB 01-00-00-00        93
      40             DEFB 01-00-00-00        94
      40             DEFB 01-00-00-00        95
      62             DEFB 01-10-00-10        96
      40             DEFB 01-00-00-00        97
      40             DEFB 01-00-00-00        98
      40             DEFB 01-00-00-00        99
      40             DEFB 01-00-00-00        9A
      40             DEFB 01-00-00-00        9B
      40             DEFB 01-00-00-00        9C
      40             DEFB 01-00-00-00        9D
      62             DEFB 01-10-00-10        9E
      40             DEFB 01-00-00-00        9F

4C18: 44             DEFB 01-00-01-00        A0
      44             DEFB 01-00-01-00        A1
      44             DEFB 01-00-01-00        A2
      44             DEFB 01-00-01-00        A3
      40             DEFB 01-00-00-00        A4
      40             DEFB 01-00-00-00        A5
      62             DEFB 01-10-00-10        A6
      40             DEFB 01-00-00-00        A7
      44             DEFB 01-00-01-00        A8
      44             DEFB 01-00-01-00        A9
      44             DEFB 01-00-01-00        AA
      44             DEFB 01-00-01-00        AB
      40             DEFB 01-00-00-00        AC
      40             DEFB 01-00-00-00        AD
      62             DEFB 01-10-00-10        AE
      40             DEFB 01-00-00-00        AF

4C28: 44             DEFB 01-00-01-00        B0
      44             DEFB 01-00-01-00        B1
      44             DEFB 01-00-01-00        B2
      44             DEFB 01-00-01-00        B3
      40             DEFB 01-00-00-00        B4
      40             DEFB 01-00-00-00        B5
      62             DEFB 01-10-00-10        B6
      40             DEFB 01-00-00-00        B7
      44             DEFB 01-00-01-00        B8
      44             DEFB 01-00-01-00        B9
      44             DEFB 01-00-01-00        BA
      44             DEFB 01-00-01-00        BB
      40             DEFB 01-00-00-00        BC
      40             DEFB 01-00-00-00        BD
      62             DEFB 01-10-00-10        BE
      40             DEFB 01-00-00-00        BF

4C38: 40             DEFB 01-00-00-00        C0
      40             DEFB 01-00-00-00        C1
      C0             DEFB 11-00-00-00        C2
      C0             DEFB 11-00-00-00        C3
      C0             DEFB 11-00-00-00        C4
      40             DEFB 01-00-00-00        C5
      80             DEFB 10-00-00-00        C6
      40             DEFB 01-00-00-00        C7
      40             DEFB 01-00-00-00        C8
      40             DEFB 01-00-00-00        C9
      C0             DEFB 11-00-00-00        CA
      00             DEFB 00-00-00-00        CB
      C0             DEFB 11-00-00-00        CC
      C0             DEFB 11-00-00-00        CD
      80             DEFB 10-00-00-00        CE
      40             DEFB 01-00-00-00        CF

4C48: 40             DEFB 01-00-00-00        D0
      40             DEFB 01-00-00-00        D1
      C0             DEFB 11-00-00-00        D2
      80             DEFB 10-00-00-00        D3
      C0             DEFB 11-00-00-00        D4
      40             DEFB 01-00-00-00        D5
      80             DEFB 10-00-00-00        D6
      40             DEFB 01-00-00-00        D7
      40             DEFB 01-00-00-00        D8
      40             DEFB 01-00-00-00        D9
      C0             DEFB 11-00-00-00        DA
      80             DEFB 10-00-00-00        DB
      C0             DEFB 11-00-00-00        DC
      00             DEFB 00-00-00-00        DD
      80             DEFB 10-00-00-00        DE
      40             DEFB 01-00-00-00        DF

4C58: 40             DEFB 01-00-00-00        E0
      51             DEFB 01-01-00-01        E1
      C0             DEFB 11-00-00-00        E2
      51             DEFB 01-01-00-01        E3
      C0             DEFB 11-00-00-00        E4
      51             DEFB 01-01-00-01        E5
      80             DEFB 10-00-00-00        E6
      40             DEFB 01-00-00-00        E7
      40             DEFB 01-00-00-00        E8
      51             DEFB 01-01-00-01        E9
      C0             DEFB 11-00-00-00        EA
      51             DEFB 01-01-00-01        EB
      C0             DEFB 11-00-00-00        EC
      00             DEFB 00-00-00-00        ED
      80             DEFB 10-00-00-00        EE
      40             DEFB 01-00-00-00        EF

4C68: 40             DEFB 01-00-00-00        F0
      40             DEFB 01-00-00-00        F1
      C0             DEFB 11-00-00-00        F2
      40             DEFB 01-00-00-00        F3
      C0             DEFB 11-00-00-00        F4
      40             DEFB 01-00-00-00        F5
      80             DEFB 10-00-00-00        F6
      40             DEFB 01-00-00-00        F7
      40             DEFB 01-00-00-00        F8
      51             DEFB 01-01-00-01        F9
      C0             DEFB 11-00-00-00        FA
      40             DEFB 01-00-00-00        FB
      C0             DEFB 11-00-00-00        FC
      00             DEFB 00-00-00-00        FD
      80             DEFB 10-00-00-00        FE
      40             DEFB 01-00-00-00        FF
256 bytes.

4C78: 2A994A    LLIST2    LD HL,(LIMIT)       Entry point (call this).
      22974A              LD (ADD2),HL
      54                  LD D,H
      5D                  LD E,L
      2A954A              LD HL,(ADDRESS)
4C83: A7        NXTAD     AND A               Clear carry flag.
      ED52                SBC HL,DE
      19                  ADD HL,DE
      3802                JR C,PRINTAD
      CF                  RST 08              Exit with error code
      00                  DEFB 00             of 0 + 1.
19 bytes.

4C8B: 7C        PRINTAD   LD A,H              Print address.
      CD824A              CALL HPRINT
      7D                  LD A,L
      CD824A              CALL HPRINT
      AF                  XOR A               Print space.
      D7                  RST 10
      7E                  LD A,(HL)           Get byte to disassemble.
11 bytes.

4C96: FECB      ISITCB    CP CB               Is it CB*?
      2015                JR NZ,ISITDDFDCB
      23                  INC HL
      7E                  LD A,(HL)           Validate next byte.
      E6F0                AND F0
      FE30                CP 30               Filter out 30 to 37 as they
      2009                JR NZ,CBVALID       are the only invalid
      7E                  LD A,(HL)           instructions after CB.
      E608                AND 08
      FE08                CP 08
      2802                JR Z,CBVALID
      1829                JR DATA
4CAB: 0602      CBVALID   LD B,02             All instructions after CB
      1827                JR DUMP             are 1 byte.
25 bytes.

4CAF: FEDD     ISITDDFDCB CP DD               Is it DDCB* or FDCB*?
      2804                JR Z,DDFDCBCONT
      FEFD                CP FD
      2031                JR NZ,USELENS
4CB7: 23       DDFDCBCONT INC HL
      7E                  LD A,(HL)           Validate next byte.
      FECB                CP CB
      202B                JR NZ,USELENS
      23                  INC HL              Point past displacement.
      23                  INC HL
      7E                  LD A,(HL)           Validate next byte.
      FE36                CP 36               Valid instructions are *6
      2810                JR Z,DATA           and *E except 36 only.
      E60F                AND 0F
      FE06                CP 06
      2806                JR Z,DDFDCBVALID
      FE0E                CP 0E
      2802                JR Z,DDFDCBVALID
      1804                JR DATA
4CD0: 0604    DDFDCBVALID LD B,04             All instructions after DDCB
      1802                JR DUMP             are 2 bytes.
37 bytes.

4CD4: 0601      DATA      LD B,01             Default byte dump count.
4CD6: 2A954A    DUMP      LD HL,(ADDRESS)     Dump B bytes to screen.
4CD9: 7E        NXBYT     LD A,(HL)
      CD824A              CALL HPRINT
      23                  INC HL
      10F9                DJNZ NXBYT
      3E76                LD A,76             Print newline.
      D7                  RST 10
      22954A              LD (ADDRESS),HL
      189B                JR NXTAD
20 bytes.

4CE8: 0601      USELENS   LD B,01             One byte for the DD, ED or
      2A954A              LD HL,(ADDRESS)     FD prefix.
      7E                  LD A,(HL)
4CEE: FEDD     ISITLENSDD CP DD               Is it DD*?
      2004                JR NZ,ISITLENSED
      0E04                LD C,04             Shift right count.
      180E                JR POINTOVR
4CF6: FEED     ISITLENSED CP ED               Is it ED*?
      2004                JR NZ,ISITLENSFD
      0E02                LD C,02             Shift right count.
      1806                JR POINTOVR
4CFE: FEFD     ISITLENSFD CP FD               Is it FD*?
      2006                JR NZ,ORDINARY
      0E00                LD C,00             Shift right count.
4D04: 23        POINTOVR  INC HL              Point over prefix to the
      7E                  LD A,(HL)           following byte.
      1804                JR GETLENSBYTE
4D08: 0600      ORDINARY  LD B,00             No prefix byte.
      0E06                LD C,06             Shift right count.
36 bytes.
      
4D0C: 264B    GETLENSBYTE LD H,LENS-high      Now we need to lookup the
      C678                ADD A,LENS-low      byte in the LENS table.
      6F                  LD L,A              Adding LENS-low may have
      3001                JR NC,AISOK         overflowed.
      24                  INC H               If so increment H.
4D14: 7E        AISOK     LD A,(HL)
      0C                  INC C               Add 1 as we test first.
4D16: 0D        SHIFTR    DEC C
      2804                JR Z,SHIFTOK
      CB2F                SRA A               Shift A right by C bits.
      18F9                JR SHIFTR
4D1D: E603      SHIFTOK   AND 03              Isolate bits 0 and 1.
      80                  ADD A,B
      47                  LD B,A
      18B3                JR DUMP
23 bytes.

Total 427 bytes.

The BASIC Part
2 PRINT "LENSLIST2"
3 GOSUB 600
4 RAND USR 19576

The above lines are in addition to the BASIC lines of
HEXLD3D which you still need to restore the machine
code to its correct destination.

Operating Instructions
Type RUN to use LENSLIST2.

HEXLD3D's original LIST can now be executed by RUN 10.

Download available for 16K ZX81 -> sif-lenslist2.p

Previous | Contents | Next