Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;get constants
- INCLUDE "constants.asm"
- ; unused vectors
- SECTION "rst 00", ROM0 [$00]
- rst $38
- SECTION "rst 08", ROM0 [$08]
- rst $38
- SECTION "rst 10", ROM0 [$10]
- rst $38
- SECTION "rst 18", ROM0 [$18]
- rst $38
- SECTION "rst 28", ROM0 [$20]
- rst $38
- SECTION "rst 30", ROM0 [$30]
- rst $38
- SECTION "rst 38", ROM0 [$38]
- rst $38
- ; hardware interrupts
- SECTION "vblank", ROM0 [$40]
- jp VBlank
- SECTION "hblank", ROM0 [$48]
- rst $38
- SECTION "timer", ROM0 [$50]
- reti
- SECTION "serial", ROM0 [$58]
- reti
- SECTION "joypad", ROM0 [$60]
- reti
- SECTION "Entry", ROM0 [$100]
- nop ;go through one cpu cycle
- jp Start ;and jump to start
- SECTION "Header", ROM0 [$104]
- ds $150 - $104 ;rgbfix fixes the header for us.
- SECTION "Main", ROM0 [$150]
- Start::
- di
- ; palettes
- ld a, %11100100
- ld [rBGP], a
- ld a, %11010000
- ld [rOBP0], a
- xor a
- ld [rSCX], a ;scrlx
- ld [rSCY], a ;scrly
- ld a, %11000111 ; lcdc status
- ld [rLCDC], a
- ei
- ; set up stack pointer
- ld sp, $dffe
- call WriteDMACodeToHRAM ;dma must be done in HRAM
- ; vblank copy offsets
- lda [H_FIRSTVBLANK], 1
- ;title screen
- ld hl, Title
- ld de, $9000 ;location
- ld bc, $800
- call CopyData
- ld hl, Title+$800
- ld de, $8800 ;location
- ld bc, $100
- call CopyData
- ;tileset
- ld hl, TitleTilemap
- ld de, W_TILEMAP
- ld bc, TitleTilemapEnd-TitleTilemap
- call CopyData
- ld [$ffff], a
- ld a, %00000001
- ld [$ffff], a
- ei
- halt
- xor a
- ld [H_FIRSTVBLANK], a
- call waitForKey ; wait for A or START to be pressed.
- ; Now we will begin the game.
- ; Load up the map and sprites.
- .debugLoop
- jp .debugLoop
- waitForKey::
- .loop
- halt ;save battery life! <3
- ld a, [H_JOYNEW]
- and a, %00001001 ; A or START
- jr z, .loop
- ret
- VBlank::
- di
- push af
- call DMARoutine
- pop af
- ei
- reti
- ; ---------
- ; lcd functions
- ; ---------
- DisableLCD::
- xor a
- ld [$ff0f], a
- ld a, [$ffff]
- ld b, a
- res 0, a
- ld [$ffff], a
- .waitvblank
- ld a, [$ff44]
- cp a, $91
- jr nz, .waitvblank
- ld a, [$ff40]
- and a, $7f
- ld [$ff40], a
- ld a, b
- ld [$ffff], a
- ret
- EnableLCD::
- ld a, [$ff40]
- set 7, a
- ld [$ff40], a
- ret
- ; -------------
- ; memory functions
- ; -------------
- ReadJoypad: ;;;
- ld a, [H_JOY]
- ld [H_JOYOLD], a
- ld a,%00100000 ; select direction keys
- ld c,$00
- ld [rJOYP],a
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- cpl ; complement the result so that a set bit indicates a pressed key
- and a,%00001111
- swap a ; put direction keys in upper nibble
- ld b,a
- ld a,%00010000 ; select button keys
- ld [rJOYP],a
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- ld a,[rJOYP]
- cpl ; complement the result so that a set bit indicates a pressed key
- and a,%00001111
- or b ; put button keys in lower nibble
- ld [$fff8],a ; save joypad state
- ld a,%00110000 ; unselect all keys
- ld [rJOYP],a
- ld a, [H_JOY]
- ld b, a
- ld a, [H_JOYOLD]
- xor $ff
- and b
- ld [H_JOYNEW], a
- ret
- WriteDMACodeToHRAM::
- ld c, $80
- ld b, $a
- ld hl, DMARoutine
- .copyLoop
- ld a, [hli]
- ld [$ff00+c], a
- inc c
- dec b
- jr nz, .copyLoop
- ret
- DMARoutine::
- ld a, W_OAM >> 8
- ld [$ff00+$46], a ; start DMA
- ld a, $28
- .waitLoop
- dec a
- jr nz, .waitLoop
- ret
- CopyData:: ;memcpy routine
- ld a, [hli]
- ld [de], a
- inc de
- dec bc
- ld a, c
- or b
- jr nz, CopyData
- ret
- FillMemory::
- .loop
- ld [hli], a
- dec b
- jr nz, .loop
- ret
- ClearOAM::
- xor a
- ld hl, W_OAM
- ld b, 4*$28
- call FillMemory
- ret
- ;includes
- INCLUDE "title.z80"
- INCLUDE "tileset.z80"
- ;internal RAM
- SECTION "IntRAM",BSS[$C000]
- player_xpos
- ds 1
- player_ypos
- ds 1
- player_tile:
- ds 1
- player_flags:
- ds 1
- SECTION "highRAM",BSS[$C0A0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement