1k2b - 2 channel beeper routine for unexpanded ZX81

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by siggi »

Works also on my ZX81 laptop (64KB ram, no ZXPAND but MEFISDOS, MMC and USB-stick as mass storage devices).
Connected the input of active speaker boxes to the video-output of my Zeddy (with Andy's ULA2 video output).

Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by Andy Rea »

Version downloaded from the OP, I'm not 100% sure if ZXpand uses the printer buffer of not, SirMorris is the man for that, but i didn't do anything special, just load her up and go. Clearly there is something funny going on here, i have tried with another ZX81 and it just give a blank ( white screen ) very odd.

Andy

EditL having just read Siggi's post i tried it on my 20Mhz zeddy works althought i took the audio from the composite video.
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by Andy Rea »

had a quick look at the code... think i may of spotted the problem the IN and
OUT instructions. especially OUT (#FC),a that tries to turn NMI on and off simultaneously.
PORT $FE (writing to port OUT ($FE),A) turns on the NMI generator, this port is not fully decoded so any

OUT ($xx),A with bit 0 of the port address low, will turn the NMI generator on.



PORT $FD (writing to port OUT ($FD),A) turns off the NMI generator, this port is not fully decoded so any

OUT ($xx),A with bit 1 of the port address low, will turn the NMI generator off.



IF you were to execute the instruction OUT ($FC),A you would effectively be trying to turn the NMI generator on and off at the same time. In this discrete design no attempt has been made to bias the NAND gate RS latch so that one side would always win in this situation, So the result would be unpredictably. (This is not strictly true as usually one gate would be fractionally quicker than the other and thus win, but to get a predictable result each and every time a better circuit could be used instead of the simple 2-gate RS latch)



PORT $FE (reading the port IN A,($FE)) has 2 effects

a) It always reads the keyboard, tape input and uk/us bit

b) If NMI generator is off will.

i) stop the HSYNC generator

ii) Will start a VSYNC PULSE (this is the tape output pulse to.



PORT $xx (writing to any port) will end the VSYNC pulse and restart the HSYNC generator. (Take care not to write to a port with bit 0 low unless you want to restart the NMI generator also
So in MAIN.ASM i would try changing lines
192, 214 to OUT (#ff),a

and lines

52,67,194,221 to IN a,(#fe)


Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by Andy Rea »

oh thought my copy of pasmo was broken until i realised the code has some self modifying parts....

oops

Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by sirmorris »

The printer buffer is used by the ZXpand LOAD patch.
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by Andy Rea »

oops double post

Regards Andy
Last edited by Andy Rea on Sun Mar 15, 2015 10:49 pm, edited 1 time in total.
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by Andy Rea »

Andy Rea wrote:Hi Utz, ok found a solution...

change the switch1 / switch2 routines thus
switch1 equ $ ;output switch ch1

in a,(#fe) ;11 ;in a,(n) = #db xx; out (n),a = #d3 xx -> XOR val is #8
;using #fc because a write to #fe would enable NMI generator
base1 equ $+1
ld hl,0 ;10 ;base counter value ch1
add hl,bc ;11 ;calculate current counter
ld b,h ;4 ;preserve current counter val in bc
ld c,l ;4
jr nc,skip1 ;12/7
ld hl,switch1
ld a,(hl)
xor #8
ld (hl),a
inc hl
ld a,(hl)
xor #01
ld (hl),a
get rid of redundant code to make space
;wait1
;ld a,(ix+0) ;19
; ld a,0 ;7
; jr skip1 ;12

;wait2
; ld a,(ix+0) ;19
; ld a,0 ;7
;jr skip2 ;12

ds 13
so that IN / OUT self modify code also alters port address tottally messes up the timing but you can fix that with the note table i reckon :-)

and in main section when initializing channels
ld a,#d3 ;set both channel outputs to low
ld (switch1),a
ld (switch2),a
ld a,#ff
ld (switch1 + 1),a
ld (switch2 + 1),a


Regards Andy
main.zip
modified asm and P file
(3.08 KiB) Downloaded 129 times

EDIT Rich, tried to attach the ASM file but got a 403 forbidden message, saying PHP command in the file. ok if i zip it thought
what's that Smell.... smells like fresh flux and solder fumes...
utz
Posts: 27
Joined: Fri Jul 15, 2011 11:06 pm

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by utz »

Wow Andy, you're my hero :D I just tried a bunch of stuff (including something similar to your approach), and it wasn't working. So I'll be doing some more testing with this.
I need to put back in the code you marked as redundant among other things, because that's actually required for correct timing ;) Anyway, thanks a ton!

@sirmorris: Intersting, I'm actually loading code into the printer buffer (and so does Andy's version), but strangely that doesn't seem to disturb ZXpand - on the contrary, it makes a non-working routine work. :?: :?: :?:
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by Andy Rea »

No problem.

the print buffer is probably just used as a kind of scratch pad but once the actual transfer from the SD card starts it writes consecutive bytes from $4009 just like a standard load, in order to remain completely compatible with the existing P file format.

SirMorris will correct me if I'm wrong

Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: 1k2b - 2 channel beeper routine for unexpanded ZX81

Post by sirmorris »

Andy's spot on. The PB is used as a scratch area before the load but the P loads normally after that.
Post Reply