; Made by Alessandro Lo-Presti (Agilo) on Januari 24, 2008. ; Playing around with sprites. .orgfill 0x1460 ; Start of General Purpose RAM. ; Variables could go here. .orgfill 0x2100 ; Start of ROM space. .db "MN" ; ROM ID (do not change or validation will fail). .include "irq.asm" ; Game cart IRQ vectors. ; Pokemon Mini game header. .orgfill 0x219E ; 0x219E - 0x21A3 must be empty. .orgfill 0x21A4 ; Start of "NINTENDO" string. .db "NINTENDO" ; Magic signature checked by the BIOS. .db "SPRT" ; Game code, 4 bytes. .db "Sprite tests" ; Name of ROM, 12 chars max. .orgfill 0x21BC ; Will contain the following string: .db "2P" ; At this time it's unknown what "2P" stands for. .orgfill 0x21D0 ; End of rom header, start of program code. .include "irqhandlers.asm" ; Game cart IRQ routine handlers. ; Code entry point. start: movw sp, 0x2000 ; Set SP to end of general purpose RAM (stack grows down). movw nn, 0x2000 ; NN register points to hardware registers. ; Enable primary interrupts on all keys. movb [nn+0x21], 0x0C ; Enable secondary interrupt for the power button (CPU will jump to 0x215C). movb [nn+0x25], (1<<7) ; Clear all flags. movb flags, 0 ; Enable LCD: 12x16, Global rendering, sprite/BG rendering, Non-inverted. movb [nn+0x80], 0b00001110 ; Set refresh rate (60Hz / 2 = 30Hz). movb [nn+0x81], 0b00001001 ; b = 95 (there are 95 blocks of 8x8 pixels on the screen). movb b, 95 ; Set HL to the end of the Tile Map data. movw HL, 0x1360+95 bglinear: ; Move a tileblock (e.g. 95) to the Tile Map (e.g. 1360+95). ; After that, move the next block (e.g. 94) to the Tile Map (e.g. 1360+94). ; Etc. movb [HL], b ; Keep decrementing. dec HL ; While b is not zero, go to the next block, otherwise end this loop. jdbnz bglinear ; Store the address of the image in the memory address register. movw x1, scrtest ; Write the address to a register of the LCD so the PM knows where to look. movw [0x2082], x1 ; Store the address of the sprite in the memory address register. movw x2, sprtest ; Write the address to a register of the LCD so the PM knows where to look. movw [0x2087], x2 ; Temporarily use N as a pointer to the OAM. movw nn, 0x1300 ; Set up sprite settings: X coordinate. movb [nn+0], 20 ; Set up sprite settings: Y coordinate. movb [nn+1], 20 ; Set up sprite settings: ID. movb [nn+2], 0 ; Set up sprite settings: OAM attributes. movb [nn+3], (1<<3) ; Restore N. movw nn, 0x2000 ; Logics start here. PM_loop: ; Move key status into a. movb a, [nn+0x52] ; Invert sprite on A. movb h, [0x1303] test a, 0x01 jnz _noa orb h, 0x04 ; Set 3rd bit (invert bit). jmp _skip_noa _noa: andb h, 0xFB ; Clear 3rd bit. _skip_noa: movb [0x1303], h ; Invert background on B. test a, 0x02 jnz _restore_screen orb [nn+0x80], 0x01 ; Set the invert bit of the LCD controller. jmp _no_restore_screen _restore_screen: andb [nn+0x80], 0xFE ; Clear the invert bit of the LCD controller. _no_restore_screen: ; Rumble on C. test a, (1<<2) jnz _disable_rumble orb [nn+0x61], 0x10 ; Set 5th bit (rumble bit). jmp _skip_disable_rumble _disable_rumble: andb [nn+0x61], 0xEF ; Clear 5th bit. _skip_disable_rumble: ; Move up. test a, (1<<3) jnz _noup movb l, [0x1301] dec l ; Decrement Y coordinate. mov [0x1301], l _noup: ; Move down. test a, (1<<4) jnz _nodown movb l, [0x1301] inc l ; Increment Y coordinate. movb [0x1301], l _nodown: ; Move left. test a, (1<<5) jnz _noleft movb l, [0x1300] dec l ; Increment X coordinate. movb [0x1300], l _noleft: ; Move right. test a, (1<<6) jnz _noright movb l, [0x1300] inc l ; Decrement X coordinate. movb [0x1300], l _noright: ; Wait for vblank. call vblank jmp PM_loop ; Wait a vblank. vblank: mov [nn+0x27], 0x80 _sloop: test [nn+0x27], 0x80 jz _sloop ret ; Wait three vblanks. wait: call vblank call vblank call vblank ret .align 64 sprtest: .incbin evildude.bin ; Blocks are 8x8 pixels (8 bytes large) .align 8 ; Include the image. scrtest: .incbin logo-agilo-96x64_bw.bin