Instructor Notes
February 27, 2008
Quote
"The prospect of charging money for software was a crime against humanity." (Richard M. Stallman, 1979)
Assignment Reminder
- Hello Sprite: due March 2 midnight
Hello GameBoy and Hello Sprite projects
- also show hello-sprite-white
Review
Sprites
- questions?
Window
- overview: gbspec 640 - 668
- not scrollable, but you can position it with WNDPOSX-7, WNDPOSY
- not transparent. Always on top of background
gbspec lines 1778 - 1788:
Lets say WY = 70 and WX = 87. The window would be positioned as so: 0 80 159 ______________________________________ 0 | | | | | | | | Background Display | | Here | | | | | 70 | - +------------------| | | 80,70 | | | | | | Window Display | | | Here | | | | | | | 143 |___________________|__________________|
- specify Window Data Table with register LCDC (gbspec lines 1525 - 1565)
- turn window off and on using STAT register (gbspec lines 1566 - 1625)
- use LCDC status interrupt with coincidence flag to get HBLANK interrupts
Assembler commands
- help: asm.htm
- MACRO: asm/macro.htm
- SET, PRINT, RSSET, HOME, BSS, .labels (see line 101 in hello-world.asm for example)
- _RS counter
- walkthrough of hello-sprite.inc:
LoByteVar sort of like declaring variables in c
- declaration of a structure
- show docs for rgbds
Hello Sprite Good Timer
- questions?
- how would you time multiple things?
Interrupts
- define Interrupt
Z80 Interrupt vector not on the GameBoy but there is an IF flag (gbspec line 921 to 964)
- interrupt addresses: gbspec.txt lines 156-180
- vblank
- timer (rTMA, rTAC (gbspec lines 1137 - 1155)
serial transfer (for connecting multiple GameBoys, for example)
new material
Sprites
- sprite bug (gbspec.txt lines 770-790)
- use incdecss.inc and the inc/dev macros to prevent this
No$GMB emulator
- breakpoint
- animate, trace
Z80 wrapup-part I
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
below is incomplete notes
- instruction types
- 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
- addressing modes (page 44 of Z80 user's manual)
- Immediate: opcode and 1 byte
- Immediate extended: opcode and 2 byte data
- Modified Page 0 Addressing: (b5 b4 b3 0 0 0)
- Relative Addressing
- Extended Addressing: and 2 byte address
Indexed Addressing: not used on GameBoy. on Z80 offers displacement to IX or IY
- Register Addressing:
- Implied Addressing: register is implied
- Register Indirect Addressing: pointer to location in memory
- Bit Addressing
- 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
differences between Z80 and GameBoy
gbspec lines 60-90:
The following are added instructions: ADD SP,nn ;nn = signed byte LD (HLI),A ;Write A to (HL) and increment HL LD (HLD),A ;Write A to (HL) and decrement HL LD A,(HLI) ;Write (HL) to A and increment HL LD A,(HLD) ;Write (HL) to A and decrement HL LD A,($FF00+nn) LD A,($FF00+C) LD ($FF00+nn),A LD ($FF00+C),A LD (nnnn),SP LD HL,SP+nn ;nn = signed byte STOP ;Stop processor & screen until button press SWAP r ;Swap high & low nibbles of r The following instructions have been removed: Any command that uses the IX or IY registers. All IN/OUT instructions. All exchange instructions. All commands prefixed by ED (except remapped RETI). All conditional jumps/calls/rets on parity/overflow and sign flag. The following instructions have different opcodes: LD A,[nnnn] LD [nnnn],A RETI