Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - utz

Pages: 1 [2]
16
ASM / 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


Pages: 1 [2]