Author Topic: TI82 sound [UPDATE: TI 1-bit Pack released]  (Read 13550 times)

0 Members and 1 Guest are viewing this topic.

Offline utz

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 161
  • Rating: +28/-0
    • View Profile
    • official hp - music, demos, and more
TI82 sound [UPDATE: TI 1-bit Pack released]
« on: October 07, 2012, 07:26:23 pm »
Update: Successfully ported some ZX Spectrum Sound routines to TI82, they can be downloaded here.
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

« Last Edit: November 02, 2012, 09:05:50 am by utz »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI82 sound
« Reply #1 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/
« Last Edit: October 07, 2012, 07:37:45 pm by DJ_O »

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI82 sound
« Reply #2 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.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: TI82 sound
« Reply #3 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 ;)

Offline utz

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 161
  • Rating: +28/-0
    • View Profile
    • official hp - music, demos, and more
Re: TI82 sound
« Reply #4 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?!?
« Last Edit: October 08, 2012, 08:21:03 am by utz »

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: TI82 sound
« Reply #5 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. But he hasn't been around for a while. thepenguin77 also made a sound program which, unlike RealPlayer, includes the source. And if i'm not mistaken, Ben Ryves (over at maxcoderz.org), was working on his "QuadPlayer" 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 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/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

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI82 sound
« Reply #6 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
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline utz

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 161
  • Rating: +28/-0
    • View Profile
    • official hp - music, demos, and more
Re: TI82 sound
« Reply #7 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.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: TI82 sound
« Reply #8 on: October 09, 2012, 06:08:21 pm »
I never knew there was a sound program with TI-82 O.O
Sig wipe!

Offline utz

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 161
  • Rating: +28/-0
    • View Profile
    • official hp - music, demos, and more
Re: TI82 sound [UPDATE: TI 1-bit Pack released]
« Reply #9 on: October 26, 2012, 11:50:21 am »
So, I've finally managed to get things going.

TI82 1-Bit Pack 0.1 - This package includes sources for 5 different 1bit sound routines from ZX Spectrum, with precompiled examples.
Texas Beeper Massacre - A short music demo collection, in 82p format. Requires CrASH.
warpzone - A 4 channel 1bit track playing on TI82 (Soundcloud)

Enjoy, and post your bug reports/suggestions here.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: TI82 sound [UPDATE: TI 1-bit Pack released]
« Reply #10 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. :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI82 sound [UPDATE: TI 1-bit Pack released]
« Reply #11 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)
« Last Edit: October 27, 2012, 02:09:18 pm by DJ_O »

Offline utz

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 161
  • Rating: +28/-0
    • View Profile
    • official hp - music, demos, and more
Re: TI82 sound [UPDATE: TI 1-bit Pack released]
« Reply #12 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.

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: TI82 sound [UPDATE: TI 1-bit Pack released]
« Reply #13 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.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: TI82 sound [UPDATE: TI 1-bit Pack released]
« Reply #14 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).
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman