wwarthen / RomWBW

System Software for Z80/Z180/Z280 Computers
GNU Affero General Public License v3.0
339 stars 99 forks source link

Z180 ICR *is* relocated #141

Closed jblang closed 4 years ago

jblang commented 4 years ago

In z180.inc, you have a comment that the Z180 ICR is not relocated. I'm pretty sure this isn't true. I can't find anything in the Z180 docs confirming this, and my own experiments show that it is relocated:

Monitor Ready (H for Help)
>I FF
DF
>I 3F
78
>I 3F
78
>O 3F 0
>
>
>
>I 3F
78
>O FF 0

You can see that at FF, it is returning the expected value, and at 3F it isn't. When I write to 3F, it has no effect, serial is still working. When I write to FF, though, it moves the registers and serial stops working.

This currently has little practical impact since the register is never accessed again in RomWBW after being relocated, but if that changes in the future it would be a problem, and the comment might confuse people.

wwarthen commented 4 years ago

Thanks J.B. That file actually pre-dates the start of RomWBW. I have confirmed your tests and based on my reading of the Z180 User Manual, the ICR register is relocated. I will be checking in a correction for this later today.

jblang commented 4 years ago

By the way, I'm working on some Z180 utility routines to use in my programs, and I have one that will detect a Z180 and then find the ICR location, in case this is useful for you:

z180base:       defb 0

; Detect Z180 and find base address
; sets z180base to found address, or FFh if not found
z180detect:
        ld      hl, 202h                ; load 2 x 2 in hl
        defb    0edh, 06ch              ; mlt hl on Z180, nop on Z80
        ld      a,l
        cp      4                       ; 2 x 2 = 4?
        ld      a, 0ffh
        jp      nz, z180l1              ; no, not a Z180
        ld      bc, 0ffh                ; check for ICR in each of the possible locations
        in      a, (c)
        and     0c0h
        cp      0c0h
        jp      z, z180l1
        ld      bc, 0bfh
        in      a, (c)
        and     0c0h
        cp      80h
        jp      z, z180l1
        ld      bc, 7fh
        in      a, (c)
        and     0c0h
        cp      40h
        jp      z, z180l1
        ld      bc,3fh
        in      a,(c)
        and     0c0h
        jp  z, z180l1
    ld  a, 0ffh         ; couldn't find ICR
z180l1: ld      (z180base), a
        ret

Edit: I should say, just finished writing this and haven't tested it yet...

wwarthen commented 4 years ago

Fixed the include file.

I think the original goal of the include file was to allow referring to the ICR constant to set the I/O address base. All of the other constants assume the I/O base is already set. The ICR register is a catch-22. I think it makes more sense to be consistent with the other constants (as you point out) and use a hard-coded constant to initially set the ICR after boot.

wwarthen commented 4 years ago

Thanks J.B.

RomWBW HBIOS proper does not need to detect the location of the internal registers because it controls them itself. There may be a use for this in some of the supporting applications though. I will take a look.

-Wayne

On Sat, Jun 6, 2020 at 9:33 AM J.B. Langston notifications@github.com wrote:

By the way, I'm working on some Z180 utility routines to use in my programs, and I have one that will detect a Z180 and then find the ICR location, in case this is useful for you:

z180base: defb 0

; Detect Z180 and find base address ; sets z180base to found address, or FFh if not found z180detect: ld hl, 202h ; load 2 x 2 in hl defb 0edh, 06ch ; mlt hl on Z180, nop on Z80 ld a,l cp 4 ; 2 x 2 = 4? ld a, 0ffh jp nz, z180l1 ; no, not a Z180 ld bc, 0ffh ; check for ICR in each of the possible locations in a, (c) and 0c0h cp 0c0h jp z, z180l1 ld bc, 0bfh in a, (c) and 0c0h cp 80h jp z, z180l1 ld bc, 7fh in a, (c) and 0c0h cp 40h jp z, z180l1 ld bc,3fh in a,(c) and 0c0h jp z, z180l1 ld a, 0ffh ; couldn't find ICR z180l1: ld (z180base), a ret

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/wwarthen/RomWBW/issues/141#issuecomment-640086245, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATNT2NLAK5SZ5WWJFXUP43RVJVWPANCNFSM4NWD3VTQ .