Instructor Notes
March 5, 2008
Assignment Reminders
- Initial Term Project Proposal: due March 9 midnight
- Midterm: March 12
- Hello Noise: March 25th
- focus on sound effects for the games
Alter gbspec.txt?
- Sound register names
Quote
"Engineering problems are under-defined, there are many solutions, good, bad and indifferent. The art is to arrive at a good solution. This is a creative activity, involving imagination, intuition and deliberate choice." -- Ove Arup
Z80 wrapup: Conclusion
how does the assembler assemble? From http://www.nersc.gov/vendor_docs/ibm/asm/assembler_passes.htm
- First Pass
- Checks to see if the instructions are legal in the current assembly mode.
- Allocates space for instructions and storage areas you request.
- Fills in the values of constants, where possible.
- Builds a symbol table, also called a cross-reference table, and makes an entry in this table for every symbol it encounters in the label field of a statement.
- Second Pass
- Examines the operands for symbolic references to storage locations and resolves these symbolic references using information in the symbol table.
- Ensures that no instructions contain an invalid instruction form.
- Translates source statements into machine code and constants, thus filling the allocated space with object code.
- Produces a file containing error messages, if any have occurred.
- First Pass
- timing (T cycles, M cycles) (Z80 manual page 80)
- 1 T cycle is 1/f of clock
- each machines cycle is one of
- 1st is always "fetch" which is 4-6 T cycles long
- subsequent M cycles move data to or from memory
- see page 12 of z80 manual
- instruction types (see Z80 manual page vi)
- 8 bit load group
- 16 bit load group
- exchange, block transfer, and search group
- 8 bit arithmetic group
DAA
- note addressing mode
- general-purpose arithmetic and CPU control
- 16 bit arithmetic group
rotate and shift group
bit set, reset, and test group
- jump group
- call and return group
- input and output group
== GameBoy Audio: General ==
- 4 sound circuits
1 & 2 are PWM, 3 plays wave patterns, and 4 is noise
- 2 sound channels (stereo), called SO1 (left) and SO2 (right)
- There is a line called Vin which can accept input from a microphone. From there you can route it back to either SO1 or SO2
- channels 1,2 and 4 have envelope functions, meaning you can have them automatically get louder or softer over time
- channel 1 has a sweep function, meaning you can get it to sweep up in pitch (chirp) or down automatically
- All channels have a duration parameter, or can be left continuously on
gbhw-snd.inc is an include file to help your code be more self-documenting when coding sound in your apps
hello-noise.asm demonstrates some basic concepts for producing sound on the GameBoy
General I/O Registers
- AUDVOL
- Controls volume of SO1 and SO2 (range 0 through 7, 7 is the loudest)
- Routes Vin to SO1 and/or SO2
- AUDTERM
- select which of the 4 circuits goes to which of the 2 output channels
- AUDENA
- turn all sound on or all sound off
- read only: find out which sound circuits are on
I/O Registers for Circuits 1 and 2
- AUD1LEN, AUD2LEN
- set duty cycle and sound length
- Sound length is 6 bits and = (64-x)*(1/256) seconds
Duty cycle. From gbspec lines 1220-1223:
Wave Duty: 00: 12.5% ( _--------_--------_-------- ) 01: 25% ( __-------__-------__------- ) 10: 50% ( ____-----____-----____----- ) (default) 11: 75% ( ______---______---______--- )
- AUD1ENV, AUD2ENV
- set an envelope to get either louder or softer
- set initial volume of envelope (4 bit)
- set envelope rate (3 bit). One step = x * (1/64) seconds
- AUD1SWEEP
- circuit 1 only
- sweep time (3 bit). Higher is slower
- sweep up or down
- change of frequency per shift: x(t) = x(t-1) +- x(t-1)/(2^n)
- AUD1LOW, AUD2LOW
- lower 8 bits of 11 bit number (x) representing a frequency: freq = 131072/(2048-x) Hz
- AUD1HIGH, AUD2HIGH
- choose if sound is continuous or indeed only the length you specified in AUD1LEN or AUD2LEN
- upper 3 bits of 11 bit number (x) (see AUD1LOW, AUD2LOW)
- trigger sound
Sound Circuit 3
overall
- Plays wave pattern ram at $ff30 to $ff3f
- stores in nibbles, reading high nibble first. 32 nibble memory
- play continuous sounds by continually shutting off circuit and reloading memory
I/O Registers
- AUD3ENA
- turn circuit 3 on or off
- AUD3LEN
- 8 bits to set sound length (256-x)*.5 seconds
- AUD3LEVEL
- bits 5 and 6:
- 00: mute
- 01: full volume
- 02: 1/2 volume
- 03: 1/4 volume
- bits 5 and 6:
- AUD3LOW, AUD3HIGH
- load 11 bit number representing equation for freq
- trigger sound
- choose whether or not continuous
Sound Circuit 4
overall
- uses binary polynomials to generate pseudo-random numbers (CRC check)
- mess with the parameters and get some interesting effects
I/O registers
- AUD4LEN --- just like AUD1LEN and AUD2LEN
- AUD4ENV --- just like AUD1ENV and AUD2ENV
- AUD4POLY: Parameters for the pseudo random number generator
- shift clock frequency (4 bits - )
- selection of polynomial counter step (7 or 15)
- dividing ratio of freqs (3 bits)
- AUD4GO
- set whether or not continuous
- trigger sound