0 Members and 3 Guests are viewing this topic.
.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 nowreadPos 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 patternsread 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 rowsreadRow 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),aspeed .EQU $+1 ld bc,0 disoundLoop 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 druml1 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/123tl3 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 insteadmusicData 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 $00p 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
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.
;---------= Make a sound =---------; c=frequency, b=durationbeep: di#ifdef TI82 \ ld e,$FC \ #else \ ld e,$D0 \ #endifbeepl1: ld a,cbeepl2: 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
sbc a,a ;if carry, A=255, otherwise A=0 xor %11111100 ;+ $ff -> $c0, $0 -> $fc and %00111100 add a,12
sbc a,a ;if carry, A=255, otherwise A=0 and %00111100 ;+ $ff -> $c0, $0 -> $fc xor %11111100