Sound working at very low cpu frequencies

This commit is contained in:
Daniele Verducci su MatissePenguin 2020-12-05 12:45:18 +01:00
parent 7c6300af8a
commit 3d4d5360c1
4 changed files with 106 additions and 32 deletions

View File

@ -16,7 +16,7 @@ void setup() {
pinMode(WE, OUTPUT);
digitalWrite(WE, HIGH);
/* Init device (silence all channels)
/* Init device (silence all channels)
* Bits meaning:
* 1 R0 R1 R2 A0 A1 A2 A3
* Bit0 is 1
@ -32,7 +32,7 @@ void setup() {
// Channel 1 to max volume
SendByte(B10010000);
/* Play note on channel 1
* Requires sending 2 bytes.
* Bits meaning:
@ -50,7 +50,7 @@ void setup() {
SendByte(B10000000); SendByte(B00001000);
delay(500);
SendByte(B10011111); // Sil ch 1
SendByte(B10011111); // Sil ch 1
delay(1000);
@ -65,7 +65,7 @@ void setup() {
SendByte(B11000000); SendByte(B00001000); // Note on ch3
delay(500);
SendByte(B10011111); // Sil ch 1
SendByte(B10011111); // Sil ch 1
SendByte(B10111111); // Sil ch 2
SendByte(B11011111); // Sil ch 3
@ -73,13 +73,10 @@ void setup() {
/*
* Play noise on channel 4
*/
}
void loop() {
}
void loop() {}
void SendByte(byte b) {
digitalWrite(DATA_BUS[0], (b&1)?HIGH:LOW);

View File

@ -0,0 +1,50 @@
; TI SN76489 sound chip display driver
; @author Daniele Verducci
;
; USAGE:
; call Snd_init <-- inits sound (and silences default tone)
; call Snd_beep <-- system beep
; Sound card is on port 0
SND_DATA_REG: EQU IO_0
; Init device (silence all channels)
; Bits meaning:
; 1 R0 R1 R2 A0 A1 A2 A3
; Bit0 is 1
; Bit1,2,3 select the channel: 001, 011, 101, 111(noise)
; Bit4,5,6,7 selecy the attenuation (0000=full volume, 1111=silent)
Snd_init:
; silence ch1
ld a,%11111001
;ld a,%10011111
out (SND_DATA_REG),a
; silence ch2
ld a,%11111101
;ld a,%10111111
out (SND_DATA_REG),a
; silence ch3
ld a,%11111011
;ld a,%11011111
out (SND_DATA_REG),a
; silence noise ch
ld a,%11111111
out (SND_DATA_REG),a
ret
Snd_beep:
; ch1 max volume
ld a,%10010000
out (SND_DATA_REG),a
; play beep freq
ld a,%10000000
out (SND_DATA_REG),a
ld a,%00001000
out (SND_DATA_REG),a
; wait 1 sec
ld bc, 10
call Time_delay55
; silence ch1
ld a,%10011111
out (SND_DATA_REG),a
ret

View File

@ -0,0 +1,19 @@
; Time library
; @author Daniele Verducci
; Duration (change these values based on CPU frequency)
TIME_DUR_SECOND: EQU 255
; Wait bc * 55 states
; Use 1 iteration as delay between I/O bus writes
; @param bc The number of iterations. Each iteration is 55 states long.
Time_delay55:
bit 0,a ; 8
bit 0,a ; 8
bit 0,a ; 8
and a,255 ; 7
dec bc ; 6
ld a,c ; 4
or a,b ; 4
jp nz,Time_delay55 ; 10, total = 55 states/iteration
ret

View File

@ -42,38 +42,46 @@ IO_7: EQU 0xE0
;include 'drivers/hd44780.asm'
;include 'drivers/keyboard.asm'
include 'drivers/arduino_terminal.asm'
include 'monitor.asm'
;include 'drivers/arduino_terminal.asm'
include 'drivers/sn76489.asm'
;include 'monitor.asm'
include 'libs/time.asm'
; SYSTEM CALLS
; User I/O
; Prints string
; @param BC Pointer to a null-terminated string first character
Print:
call Term_print
ret
; ; Prints string
; ; @param BC Pointer to a null-terminated string first character
; Print:
; call Term_print
; ret
; Writes a single character
; @param A Value of character to print
Printc:
call Term_printc
ret
; ; Writes a single character
; ; @param A Value of character to print
; Printc:
; call Term_printc
; ret
; Reads a single character
; @return A The read character
Readc:
call Term_readc
ret
; ; Reads a single character
; ; @return A The read character
; Readc:
; call Term_readc
; ret
; Reads a line
; @return BC The pointer to a null-terminated read string
Readline:
call Term_readline
ret
; ; Reads a line
; ; @return BC The pointer to a null-terminated read string
; Readline:
; call Term_readline
; ret
; System initialization
Sysinit:
; Start Monitor
call Monitor_main
;call Monitor_main
call Snd_init
ld bc, 10
call Time_delay55
call Snd_beep
halt