Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: utz on October 07, 2012, 07:26:23 pm

Title: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on October 07, 2012, 07:26:23 pm
Update: Successfully ported some ZX Spectrum Sound routines to TI82, they can be downloaded here (http://irrlichtproject.de/downloads/ti1bit-0.2.zip).
Update 2012/11/02: Added TI83 support, and some other stuff. Download from the link above.

Hai guys,

Since this is my first post here, allow me to quickly introduce myself: I'm utz, aka irrlicht project, a musician working mainly with the Sinclair ZX Spectrum and it's beeper.

A while ago I found my old TI82 from school times again. Considering how similar the two platforms are, I thought it might be interesting to port some ZX Spectrum 1-bit sound routines over to the TI. Unfortunately I'm not really a coder. Well, long story short, after quite a bit of fiddeling around I got a simple two-channel routine working on VTI emulator. Sadly, it's not working on real hardware though.

The code below is for TI82/CrASH, obviously, though with some minor modifications it should work equally well (well, not so well, after all) on other Z80-based TIs. Annotations containing a + mark the modifications done by me.

So, I'm hoping there are still some TI82/83 coders lurking on this forum. Any ideas as to why this isn't working on hardware are highly welcome, and I'll reward you with... ermmm... life-long honors and that kinda stuff  ;D


Code: [Select]
.INCLUDE CRASH82.INC
.DB "HUBY 1-BIT TI82 0.5", 0
#define db .byte
#define dw .word

;Huby beeper music engine by Shiru ([email protected]) 04'11
;Two channels of tone, no volume, global speed
;One drum, replaces note on the first channel
;The main feature of this engine is the size, just 100 bytes
;Feel free to do whatever you want with the code, it is PD

ld hl,musicData
ld a,%00010000 ;+ set interrupts to fastest mode
out (4),a
call play

play
ld e,(hl) ;read speed word
inc hl
ld d,(hl)
inc hl
ld (speed),de ;store it
ld e,(hl) ;read patterns offset
inc hl
ld d,(hl) ;it will be always in DE, and HL is order list pointer now

readPos
inc hl
ld a,(hl) ;read first byte of order list
or a
ret z ;if it is zero, it is end of the song
inc hl
push hl ;store order list pointer
push de ;store patterns offset
ld l,(hl) ;read second byte of order list
ld bc,2*256 ;calculate addresses of two patterns
read
ld h,c ;pattern number*8
add hl,hl
add hl,hl
add hl,hl
add hl,de ;add patterns offset
push hl ;store pattern address
ld l,a ;now second address
djnz read
exx
pop hl ;restore pattern addressed in alternative set
pop de

ld b,8 ;play 8 rows
readRow
ld a,(hl) ;read first note
inc hl ;increase first pattern pointer
ex af,af'
ld a,(de) ;read second note
inc de ;increase second pattern pointer
exx
ld h,a
ex af,af'
ld l,a
cp $2c ;if first note is $2c, it is drum sound
jr z,$+3
xor a
ld (slide),a
speed .EQU $+1
ld bc,0
di

soundLoop
xor a ;clear carry and set A to zero
dec e ;counter of first channel
jr nz,l1
ld e,l ;reload if overflow
sub l ;and set carry if note is not zero (mute)
slide .EQU $
nop ;slide for drum
l1
dec d ;counter of second channel
jr nz,l2
ld d,h ;reload if overflow
sub h ;and set carry if note is not zero (mute)
l2
sbc a,a ;if carry, A=255, otherwise A=0
xor %11111100 ;+ $ff -> $c0, $0 -> $fc
and %00111100
add a,12
out (0),a
out (0),a
out (0),a
out (0),a ;+ 4x to compensate higher cpu speed

ld a,%10111111 ;+ new keyhandler
out (1),a
in a,(1) ;read keyboard
cpl
bit 6,a
jr nz,l3 ;if any key is pressed, exit loop

dec bc
ld a,b
or c
jr nz,soundLoop ;113/123t

l3
ld hl,$2758 ;restore alternative HL to default value
exx
ei

jr nz,$+4 ;if any key was pressed, break loop
djnz readRow

pop de
pop hl
jr z,readPos ;if no key was pressed, continue
ld a,%00010110 ;+ set interrupts back to normal
out (4),a
jp EXIT_2_TIOS ;normally ret, use CrASH syscall to return properly instead

musicData
dw $06f3
dw p-8
db $01,$02
db $01,$03
db $04,$05
db $06,$07
db $08,$09
db $0a,$0b
db $0c,$0d
db $0e,$0f
db $01,$02
db $01,$03
db $04,$05
db $06,$07
db $08,$09
db $0a,$0b
db $0c,$0d
db $0e,$0f
db $10,$02
db $11,$03
db $12,$05
db $13,$07
db $14,$09
db $15,$0b
db $16,$0d
db $17,$0f
db $18,$02
db $18,$03
db $19,$05
db $19,$07
db $1a,$09
db $1a,$0b
db $1b,$0d
db $1c,$0f
db $01,$02
db $01,$03
db $04,$05
db $06,$07
db $08,$09
db $0a,$0b
db $0c,$0d
db $0e,$0f
db $1d,$02
db $1d,$03
db $1e,$05
db $1e,$07
db $1f,$09
db $1f,$0b
db $20,$0d
db $21,$0f
db $10,$02
db $11,$03
db $12,$05
db $13,$07
db $14,$09
db $15,$0b
db $16,$0d
db $17,$0f
db $18,$02
db $18,$03
db $19,$05
db $19,$07
db $1a,$09
db $1a,$0b
db $1b,$0d
db $1c,$0f
db $00
p
db $2c,$3c,$b3,$3c,$b3,$3c,$b3,$3c
db $59,$59,$50,$50,$4b,$4b,$4b,$4b
db $4b,$4b,$4b,$4b,$59,$59,$59,$59
db $2c,$38,$b3,$38,$b3,$38,$b3,$38
db $43,$43,$43,$43,$43,$43,$43,$43
db $2c,$38,$b3,$38,$2c,$38,$2c,$38
db $43,$43,$43,$43,$4b,$4b,$50,$50
db $b3,$32,$b3,$32,$2c,$32,$b3,$32
db $4b,$4b,$50,$50,$59,$59,$59,$59
db $2c,$32,$b3,$32,$b3,$32,$b3,$32
db $59,$59,$59,$59,$4b,$4b,$4b,$4b
db $2c,$43,$b3,$43,$b3,$43,$b3,$43
db $50,$50,$50,$50,$50,$50,$50,$50
db $2c,$43,$b3,$43,$2c,$a0,$2c,$86
db $50,$50,$50,$50,$43,$43,$3c,$3c
db $2c,$3c,$e2,$3c,$e2,$3c,$2c,$3c
db $2c,$3c,$e2,$3c,$2c,$3c,$2c,$3c
db $2c,$38,$e2,$38,$e2,$38,$e2,$38
db $e2,$38,$2c,$38,$2c,$38,$e2,$38
db $2c,$32,$e2,$32,$2c,$32,$e2,$32
db $e2,$32,$e2,$32,$2c,$32,$e2,$32
db $2c,$43,$e2,$43,$e2,$43,$e2,$43
db $2c,$43,$2c,$43,$2c,$2c,$2c,$2c
db $f0,$3c,$f0,$3c,$f0,$3c,$f0,$3c
db $f0,$38,$f0,$38,$f0,$38,$f0,$38
db $f0,$32,$f0,$32,$f0,$32,$f0,$32
db $f0,$43,$f0,$43,$f0,$43,$f0,$43
db $f0,$43,$f0,$43,$f0,$a0,$f0,$86
db $78,$3c,$78,$3c,$78,$3c,$78,$3c
db $78,$38,$78,$38,$78,$38,$78,$38
db $78,$32,$78,$32,$78,$32,$78,$32
db $78,$43,$78,$43,$78,$43,$78,$43
db $78,$43,$78,$43,$78,$a0,$78,$86

Title: Re: TI82 sound
Post by: DJ Omnimaga on October 07, 2012, 07:36:56 pm
Heya and nice to see you here. :)

There aren't many 82 sound programs. The only one I knew about was http://www.ticalc.org/archives/files/fileinfo/338/33890.html but I have ROM 16.0 on my calc so I don't know if it runs on it.

I unfortunately do not know Z80 ASM, but could the fact it doesn't work in Virtual TI be due to the ROM differences between the 1993-01 models? Hopefully someone can help out (although most people are 83+/84+ coders).

By the way does your program work on WabbitEmu emulator? http://wabbit.codeplex.com/
Title: Re: TI82 sound
Post by: calc84maniac on October 07, 2012, 07:57:38 pm
I don't know much about the TI-82, but I do see a potential problem. You seem to have interrupts enabled while you have values in shadow registers, which will probably get destroyed by the interrupt handler.
Title: Re: TI82 sound
Post by: chickendude on October 08, 2012, 02:40:30 am
There aren't many 82 sound programs. The only one I knew about was http://www.ticalc.org/archives/files/fileinfo/338/33890.html but I have ROM 16.0 on my calc so I don't know if it runs on it.
I think there are two files for each version (CrASH/ACE), one for pre 19.006 ROMs and one specifically for 19.006 ROMs, if you ever do care to test it ;)
Title: Re: TI82 sound
Post by: utz on October 08, 2012, 07:52:54 am
@DJ_O: Thanks for the welcome ;) Mateo's Beatbox thingy should work with 16.0, but I've never gotten it to work. (I'm using 19.0 on emu and hardware, btw.)Well, maybe I should have a shot at disassembling that one though. One TI82 music prog that does work is HiFiPad - http://www.ticalc.org/archives/files/fileinfo/147/14793.html. Too bad it's not really useful for making actual music, and the code is pretty ugly, too.

Didn't know about WabbitEmu, going to check it out right away.

@calc84maniac: hmm, good point. I've played around a bit with the interrupts, and disabled them during the whole play routine - sadly, still no sound on hardware. Strangely enough, when I enable interrupts during exchanges with the shadow registers (which is definately not recommendable according to all docs), I get much more stable sound on VTI. Gonna look more into that.

ed: tried WabbitEmu, seems it can't run CrASH properly?!?
Title: Re: TI82 sound
Post by: chickendude on October 08, 2012, 12:42:29 pm
Jim e also had a pretty complex sound program, but i can't remember what it was called anymore. Maybe RealSound? Ah, yeah (http://www.ticalc.org/archives/news/articles/13/136/136239.html). But he hasn't been around for a while. thepenguin77 also made a sound program (http://www.ticalc.org/archives/files/fileinfo/433/43319.html) which, unlike RealPlayer, includes the source. And if i'm not mistaken, Ben Ryves (over at maxcoderz.org), was working on his "QuadPlayer (http://www.maxcoderz.org/forum/viewtopic.php?f=3&t=624)" several years back. He's still around and i don't think he'd mind sharing what he knows/remembers. I think the source is online, too, as well as documentation on how he implemented sound. However, those were all for the 83+/84+ (and possibly the 83). For 82 programmers, if i remember correctly Digitan did some work with sound. He was around until recently, at least until UTI went down... There were also some old games (i can't remember, maybe Penguins?) that had sounds when you jumped or did certain things, this was maybe 10 years ago so it's very likely either a) i was playing it on my 82 or b) i was playing it on my 83 but that it was a port from an 82 version. This (http://www.ticalc.org/archives/files/fileinfo/23/2361.html) is for ASH, and includes source. Unfortunately, i don't know anything about how sound works (i guess it's just outputting values to some port, i'm assuming port 0?). Sorry for just tossing around a bunch of random links, but i really don't have much else to offer other than what i remember other people did ;)

Ahh! IceClimb! from dwedit (who also still lurks around various places and would know a lot about the 82 as well, his site (http://www.dwedit.org/)/forum is probably the best way to get in touch with him). From the IceClimb source:
Code: [Select]
;---------= Make a sound =---------
; c=frequency, b=duration
beep:   di
#ifdef TI82 \ ld e,$FC \ #else \ ld e,$D0 \ #endif
beepl1:   ld   a,c
beepl2:   dec   a
   jr   nz,beepl2
   ld   a,e
#ifdef TI82 \ xor %00111100 \ #else \ xor %00000011 \ #endif
   ld   e,a
   out   (0),a
   djnz   beepl1
   ei
   pop hl
   pop de
   pop bc
   ret
Title: Re: TI82 sound
Post by: calc84maniac on October 08, 2012, 01:41:40 pm
Ah, that code shows me the problem clearly. You want to output $FC or $C0 each time, right? Well, in this code:
Code: [Select]
sbc a,a ;if carry, A=255, otherwise A=0
xor %11111100 ;+ $ff -> $c0, $0 -> $fc
and %00111100
add a,12
I believe the add a,12 is the problem. You can fix this by changing it to add a,$c0 or:
Code: [Select]
sbc a,a ;if carry, A=255, otherwise A=0
and %00111100 ;+ $ff -> $c0, $0 -> $fc
xor %11111100
Title: Re: TI82 sound
Post by: utz on October 09, 2012, 08:24:43 am
Oh boy, now that's rather embarassing ;) you're absolutely right, that value should be $c0, not $0c. thanks a ton for debugging my crappy code, calc84maniac! the routine is working on real hw now, just need to fix some minor glitches. I'll post the finished routine here, anybody who is interested can use it for their own purposes, of course.

If things go well, there'll be more routines coming up, with more channels and better sound than this one. I'll keep you guys updated.
Title: Re: TI82 sound
Post by: Yeong on October 09, 2012, 06:08:21 pm
I never knew there was a sound program with TI-82 O.O
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on October 26, 2012, 11:50:21 am
So, I've finally managed to get things going.

TI82 1-Bit Pack 0.1 (http://irrlichtproject.de/downloads/ti1bit-0.1.zip) - This package includes sources for 5 different 1bit sound routines from ZX Spectrum, with precompiled examples.
Texas Beeper Massacre (http://irrlichtproject.de/downloads/texbeep.zip) - A short music demo collection, in 82p format. Requires CrASH.
warpzone (http://soundcloud.com/irrlicht-project/warpzone-ti82-1-bit) - A 4 channel 1bit track playing on TI82 (Soundcloud)

Enjoy, and post your bug reports/suggestions here.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: TIfanx1999 on October 27, 2012, 11:46:16 am
Hey, that's pretty awesome! I'll see if I can give it a listen on my TI-82 when I have some time. :)
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: DJ Omnimaga on October 27, 2012, 02:09:04 pm
That seems very great! Is it compatible with every ROM version including 1993 and 2001 ones? (16.0 and 19.006 respectively)
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on October 27, 2012, 06:52:14 pm
I can only test on ROM 19.0, since I have just one TI. Theoretically, the routines should work with all ROM versions. If you adapt them for Ion, they should also run on TI83. The routines don't make any calls to ROM except one JP EXIT_2_TIOS at the end, which can be safely replaced with a normal ret.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: chickendude on October 27, 2012, 10:44:22 pm
Wow, that sounds really cool. I've never played with sound before but that sounds amazing :D If something like that could fit behind a program that'd be really cool. Is there an emulator that can emulate sound? WabbitEmu? I used to use the old radio trick to listen to sound.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: calc84maniac on October 27, 2012, 10:45:07 pm
Well, actually the I/O output format is a bit different on 83+, but it could still probably be ported by changing those values, too. (On the 83+ family, you would output 3 for both lines low and 0 for both lines high).
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on October 28, 2012, 12:01:29 pm
Wow, that sounds really cool. I've never played with sound before but that sounds amazing :D If something like that could fit behind a program that'd be really cool. Is there an emulator that can emulate sound? WabbitEmu? I used to use the old radio trick to listen to sound.

couldn't get WabbitEmu to work, unfortunately. VirtualTI will emulate the sound with acceptable quality, though.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: DJ Omnimaga on October 28, 2012, 06:31:09 pm
VirtualTI will emulate the sound with acceptable quality, though.

Just make sure to lower your volume as much as possible first, though. For me VTI sound was about 40 times higher than in WabbitEmu D:
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on October 28, 2012, 08:00:28 pm
The signal is really loud on hardware, too. Had to put a dimmer before I could even record the sound.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on November 02, 2012, 09:11:44 am
double post, yay

Update: TI 1-Bit Pack 0.2 released

Changelog:

- Added TI83/Ion support.
- Added Octode engine (1tracker version)
- Removed all ROM calls
- Various code optimizations
- Moved all song data to external music.asm templates

Download (http://irrlichtproject.de/downloads/ti1bit-0.2.zip)

Btw, I don't have any plans to support TI83+ and later models. The routines should run on these models, too, but at the wrong speed. You'll need to make the necessary speed modifications yourself. ;)
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on June 07, 2013, 09:35:32 am
TI 1-Bit Pack 0.3 released

Changelog:
- Added Phaser1 (digi drums only) and Qchan engines
- Size optimizations
- Improved key handling

Download (http://irrlichtproject.de/downloads/ti1bit.zip) (includes examples and manual)

I'll probably add proper 83+/84+ support at some point, now that I know a bit more about this model. Anyway, the 83 version probably works on 83+ and up, though to be on the safe side you should
Code: [Select]
xor a
out (0),a
on returning from the routine.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: TIfanx1999 on June 07, 2013, 09:44:42 am
The 83 version won't work on the 83+/84+ models. The 83+ version will work on the 84+ though.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: utz on June 07, 2013, 10:00:59 am
Well, of course you need to #define TI83P, change the header and use the correct asm83.bat. But the actual code should work out of the box, since it doesn't really matter if you send $d3/$d0 or $03/$00 to the link port.
Title: Re: TI82 sound [UPDATE: TI 1-bit Pack released]
Post by: DJ Omnimaga on June 08, 2013, 12:50:28 am
Do you plan to add TI-84 Plus C (Color) Silver Edition support as well? That calculator has identical hardware except the screen and it could maybe use a few more programs :P