ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Discussions about Sinclair ZX80 and ZX81 Hardware
tdg8934
Posts: 304
Joined: Mon Sep 23, 2013 6:10 pm

Re: ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Post by tdg8934 »

Here are the INPUT P files for register 14 port A and register 15 port B:
Attachments
INB15.P
(995 Bytes) Downloaded 128 times
INA14.P
(995 Bytes) Downloaded 123 times
tdg8934
Posts: 304
Joined: Mon Sep 23, 2013 6:10 pm

Re: ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Post by tdg8934 »

Here are the OUTPUT P files for register 14 port A and register 15 port B:
Attachments
OUTB15.P
(1.03 KiB) Downloaded 116 times
OUTA14.P
(1.03 KiB) Downloaded 122 times
User avatar
1024MAK
Posts: 5123
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Post by 1024MAK »

Sounds like you are having fun :-)

Good work :D

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
tdg8934
Posts: 304
Joined: Mon Sep 23, 2013 6:10 pm

Re: ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Post by tdg8934 »

The program that I posted appears to be the start of something. I think my intention was to make one port an input and continuously read its vale and display it on-screen in binary. The other port would continuously count up for investigation using a logic probe, 'scope or analyser. I have to admit that I haven't run it in a long time and it appears to exit immediately after displaying the port state.

It would be a great service to the community if you wouldn't mind matching up what I posted with the data sheet and reporting on your findings - I don't have the spare time to play at the moment. :(

Good luck
C

Sir Morris,

I ran your ASM code but it had a problem with 'countup'. I set it to 0 in the beginning of the program with an EQU statement and at least it compiled.

The input section worked great and read my 8 input dip switch but the output LEDs seemed not to do anything (some were on and some off) 10101100 pattern. What was the intention for 'countup'? Trying to learn Z80 assembly...

Code: Select all

10      REM _asm

DFILE   EQU $400c
IOPORT  EQU $ef
REGSEL  EQU $cf
REGVAL  EQU $0f
countup EQU 0                       'added this line to allow it to compile

//        org     16514

start:
        push    af
        push    hl
        push    bc

        ld      hl,(DFILE)
        inc     hl

        ld      a,7                     ; register 7 - enables
        out     (REGSEL),a              ; set register

        ld      a,%10111111             ; port a is input, b is output, noise is off
        out     (REGVAL),a              ; set value

        ld      a,14                         ; read from reg 14 - i/o port A
        out     (REGSEL),a              ; set register

        in      a,(IOPORT)              ; read the port
        ld      c,a

        ld      b,8

loopin: 
        ld      a,$1c                   ; '0'
        rlc     c
        adc     a,0
        ld      (hl),a
        inc     hl
        djnz    loopin

        ld      a,15                         ; write to reg 15 - i/o port b
        out     (REGSEL),a              ; set register

        ld      a,(countup)
        inc     a
        ld      (countup),a
        out     (REGVAL),a              ; set register

        pop     bc
        pop     hl
        pop     af
        ret

        END _asm   
2013-11-12_07-06-43-PM.jpg
2013-11-12_07-06-43-PM.jpg (22.04 KiB) Viewed 2144 times
2013-11-12_07-09-03-PM.jpg
2013-11-12_07-09-03-PM.jpg (9.38 KiB) Viewed 2144 times
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Post by PokeMon »

countup is just a counter.
You should use a variable for it, not a constant.
This can be compiled but doesn't make sense.

So A register is read from address "0" and incremented and written to address "0".
This is occupied by ROM and doesn't has an effect but in a system with RAM at this address or even EEPROM your program could crash.

This is a definition for an assembly variable:

Code: Select all

countup db 0 // byte
countupw dw 0 // word
You should place the variable definitions in your assembly section, maybe at the end (after ret but before END _asm).

Definitions with EQU are handled as constants.
So check up the differences between constants and variables.

Code: Select all

        ld      a,(countup)
        inc     a
        ld      (countup),a
        out     (REGVAL),a              ; set register
This code will be compiled to:

Code: Select all

        ld      a,(0)
        inc     a
        ld      (0),a
        out     (REGVAL),a              ; set register
So the byte at address 0 is read ($D3), incremented to $D4 and this is written as output (always the same value).
If you use a variable instead, the output will be incremented from 0 to $FF in 256 steps (8 bit).
tdg8934
Posts: 304
Joined: Mon Sep 23, 2013 6:10 pm

Re: ZXpand-AY Sound Module (Two 8 bit I/O ports control)

Post by tdg8934 »

Thanks PokeMon - That fixed it. The LED/resistor outputs are binary counting and the input switches are displaying on the screen. DONE !

Code: Select all

10      REM _asm

DFILE   EQU $400c
IOPORT  EQU $ef
REGSEL  EQU $cf
REGVAL  EQU $0f

//        org     16514

start:
        push    af
        push    hl
        push    bc

        ld      hl,(DFILE)
        inc     hl

        ld      a,7                     ; register 7 - enables
        out     (REGSEL),a              ; set register

        ld      a,%10111111             ; port a is input, b is output, noise is off
        out     (REGVAL),a              ; set value

        ld      a,14                    ; read from reg 14 - i/o port A
        out     (REGSEL),a              ; set register

        in      a,(IOPORT)              ; read the port
        ld      c,a

        ld      b,8

loopin: 
        ld      a,$1c                   ; '0'
        rlc     c
        adc     a,0
        ld      (hl),a
        inc     hl
        djnz    loopin

        ld      a,15                    ; write to reg 15 - i/o port b
        out     (REGSEL),a              ; set register

        ld      a,(countup)
        inc     a
        ld      (countup),a
        out     (REGVAL),a              ; set register

        pop     bc
        pop     hl
        pop     af
        ret

        countup db 0 // byte

        END _asm      
2013-11-12_07-48-47-PM.jpg
2013-11-12_07-48-47-PM.jpg (21.76 KiB) Viewed 2143 times
Post Reply