home *** CD-ROM | disk | FTP | other *** search
-
- ;*****************************
- ;* Space Invaders demo V1.0 *
- ;*****************************
- ; by Jeff Frohwein
-
- ; First edit 24-Oct-97
- ; Last edit 26-Oct-97
-
- ; All include files not distributed with this file
- ; may be found on the Code Libraries web page.
- ; http://hiwaay.net/~jfrohwei/gameboy/
-
- INCLUDE "hardware.inc"
-
- ;Version 1.5 or later of 'hardware.inc' is required.
- rev_Check_hardware_inc 1.5
-
- ;lorambase = $c000
- ;hirambase = $80
-
- ;Low RAM Assignments
-
- SECTION "Low Ram",BSS
-
- XOffsetTable DS 144
- SpriteTable DS 160
- XOffset DB
- VBlankDone DB
-
- ;High RAM Assignments
-
- SPR_DMA equ $ff80
-
- SECTION "Org $00",HOME
- ret
-
- SECTION "Org $40",HOME[$40] ; Vertical Blank Interrupt
- jp VBlankIntr
-
- SECTION "Org $48",HOME[$48] ; LCDC Interrupt
- jp LCDIntr
-
- SECTION "Org $50",HOME[$50] ; Timer Overflow Interrupt
- reti
-
- DB "Date 971026"
-
- SECTION "Org $100",HOME[$100]
-
- ;*** Beginning of rom execution point ***
-
- nop
- jp begin
-
- NINTENDO_LOGO
-
- ;Rom Header Info
- ; 1234567890123456
- db "SPACE INV DEMO",0,0 ; Cart name 16bytes
- db 0,0,0 ; Not used
- db 3 ; Cart type ROM+MBC1+RAM+Battery
- db 0 ; ROM Size 32k
- db 0 ; RAM Size 8k
- db 1,1 ; Maker ID
- db 0 ; Version =0
- db $24 ; Complement check (important)
- dw $0 ; Checksum (not important on real GB)
-
- INCLUDE "memory1.asm"
- INCLUDE "export.asm"
-
- begin:
- di
- ; The stack initializes to $FFFE
-
- xor a ;a = 0
- ldh [rIF],a ;clear pending interrupts
- ldh [rIE],a ;disable interrupts
-
- ; Must be in VBL before turning the screen off.
- WaitVBL:
- ldh a,[rLY] ; $ff44=LCDC Y-Pos
- cp $90 ; $90 and bigger = in VBL
- jr c,WaitVBL ; Loop until it is $90 or >
-
- ld a,%00010101 ; LCD Controller = Off [No picture on screen]
- ; WindowBank = $9800 [Not used]
- ; Window = OFF
- ; BG Chr = $8000
- ; BG Bank= $9800
- ; OBJ = 8x16
- ; OBJ = Off
- ; BG = On
- ldh [rLCDC],a
-
- ld hl,TileData+1
- ld de,$8000
- ld bc,$1000
- call mem_Copy ; Copy tile set to memory
-
- ld hl,MapData+4
- ld de,$9800
- ld bc,$0400
- call mem_Copy ; Copy tile map to memory
-
- ld a,$c0
- ldh [rBGP],a ; Set BG default colors
-
- xor a ;Initialize interupt vars
- ld [VBlankDone],a
- ld [XOffset],a
-
- ld a,$40 ; Set LCDC Intr to LYC
- ldh [rSTAT],a
-
- ld a,3
- ldh [rIE],a ;enable LCD interrupt
-
- ld a,%10010101 ; LCD Controller = On
- ldh [rLCDC],a
-
- ei
-
- ; Clear whole X offset table to 00
- ld hl,XOffsetTable
- ld b,144
- clroff1:
- xor a
- ld [hl+],a
- dec b
- jr nz,clroff1
-
- ; Position "invaders" to the right side of screen
-
- ld hl,XOffsetTable + 8
- ld b,80
- clroff2:
- ld a,$ec
- ld [hl+],a
- dec b
- jr nz,clroff2
-
- ;* Main Loop - scroll Invaders 32 pixels to the left *
- ;* then 32 pixels to the right & start over. *
-
- ld d,1
- loop1:
- ld c,32
- loop2:
- ld a,d
- ld [XOffset],a
-
- call VBlankWait
-
- xor a
- ld [XOffset],a
-
- ld b,5
- loop3:
- call VBlankWait
- dec b
- jr nz,loop3
-
- dec c
- jr nz,loop2
-
- ; d = -d
-
- ld a,d
- cpl
- inc a
- ld d,a
-
- jr loop1
-
- ; Wait for VBlank Interrupt to occur
-
- VBlankWait:
- xor a
- ld [VBlankDone],a
- lpp1: ld a,[VBlankDone]
- or a
- jr z,lpp1
- ret
-
- ; LCD Interrupt Routine
-
- LCDIntr:
- push af
- push hl
-
- ldh a,[rLYC]
- ld l,a
- inc a
- cp 144
- jr nz,l2947
- ld a,1
- l2947: ldh [rLYC],a
-
- ; Set scroll X register
- ld h,XOffsetTable / 256
- ld a,[hl]
- ldh [rSCX],a ; ScrollX = [$c000 + [$45]]
-
- pop hl
- pop af
- reti
-
- ; VBlank Interrupt Routine
-
- VBlankIntr:
- push af
- push bc
- push hl
-
- ld hl,XOffsetTable + $17
- ld b,60
- ld a,[XOffset]
- ld c,a
- Vloop:
- ld a,[hl]
- add a,c
- ld [hl+],a
- dec b
- jr nz,Vloop
-
- ld a,1
- ld [VBlankDone],a
- pop hl
- pop bc
- pop af
- reti
-
-