Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main:
- nop
- di ;disable interrupts
- ld sp, $dfff
- call wait_vblank
- xor a
- ld [rLCDC], a
- ; Set palettes and clear the scroll
- ld a, %01101100
- ldh [rBGP], a
- ld a, %00011100
- ldh [rOBP0], a
- ld a, %01101100
- ldh [rOBP1], a
- xor a
- ldh [rSCX], a
- ldh [rSCY], a
- ; Clear RAM
- ld hl, WRAM_START
- ld bc, 4096
- call memclear
- ; Copy in DMA routine
- ld hl, oam_dma_routine
- ld de, $ff80
- ld bc, oam_dma_routine_end - oam_dma_routine
- call memcpy
- ; Upload graphics
- ld hl, graphics
- ld de, VRAM_LOW
- ld bc, 8192
- call memcpy
- ; Initialize nametable
- ld hl, SCREEN1
- ld bc, 1024
- ld e, " "
- call memset
- ; Upload graphics
- ld hl, RobotnikText
- ld de, SCREEN1+32*2+3
- ld bc, 14
- call memcpy
- ld hl, LandText
- ld de, SCREEN1+32*3+8
- ld bc, 4
- call memcpy
- ld a, LCDCF_ON|LCDCF_OBJ8|LCDCF_OBJON|LCDCF_BGON
- ldh [rLCDC],a
- ; Initialize variables
- ld a, 30
- ld [PlayerPX], a
- ld [PlayerPYL], a
- ld [PlayerPYH], a
- forever:
- call wait_vblank
- ld a, $c0
- call $ff80
- call readkeys
- ; Clear OAM
- ld hl, WRAM_START
- ld bc, $a0
- call memclear
- xor a
- ld [PlayerOnGround], a
- ; Add velocity
- lda h, [PlayerPYH]
- lda l, [PlayerPYL]
- lda d, [PlayerVYH]
- lda e, [PlayerVYL]
- add hl, de
- lda [PlayerPYH], h
- lda [PlayerPYL], l
- ; Add gravity
- ld h, d
- ld l, e
- ld de, 16
- add hl, de
- lda [PlayerVYH], h
- lda [PlayerVYL], l
- ld a, [PlayerPYH]
- cp 144-16
- jr c, .NoGround
- xor a
- ld [PlayerPYL], a
- ld [PlayerVYH], a
- ld [PlayerVYL], a
- ld a, 144-16
- ld [PlayerPYH], a
- .NoGround:
- ld a, [PlayerPYH]
- cp 144-16
- jr nz, .NoGround2
- ld a, 1
- ld [PlayerOnGround], a
- .NoGround2:
- ld hl, PlayerPX
- ld a, [KeyDown]
- and KEY_RIGHT
- jr z, .noright
- inc [hl]
- xor a
- ld [PlayerDir], a
- .noright:
- ld a, [KeyDown]
- and KEY_LEFT
- jr z, .noleft
- dec [hl]
- ld a, 1
- ld [PlayerDir], a
- .noleft:
- ld a, [KeyNew]
- and KEY_B
- jr z, .nopingas
- ld a, [PingasTimer]
- or a
- jr nz, .nopingas
- ld a, 15
- ld [PingasTimer], a
- .nopingas:
- ld a, [PlayerOnGround]
- or a
- jr z, .nojump
- ld a, [KeyNew]
- and KEY_A
- jr z, .nojump
- ld a, (-$200)&$ff
- ld [PlayerVYL], a
- ld a, ((-$200)>>8)&$ff
- ld [PlayerVYH], a
- .nojump:
- ; Draw the player
- xor a
- ld [oam_ptr], a
- lda b, [PlayerPX]
- lda c, [PlayerPYH]
- ld hl, StandingFrame
- ld a, [KeyDown]
- and KEY_LEFT+KEY_RIGHT
- jr z, .notmoving
- ld a, [retraces]
- and %100
- jr z, .notmoving
- ld hl, WalkingFrame
- .notmoving:
- ld a, [PlayerOnGround]
- or a
- jr nz, .onground
- ld hl, JumpingFrame
- .onground:
- ld a, [PingasTimer]
- or a
- jr z, .nopingas2
- dec a
- ld [PingasTimer],a
- ld hl, PingasFrame1
- cp 8
- jr nc, .nopingas2
- ld hl, PingasFrame2
- .nopingas2:
- ld a, [PlayerDir]
- or a
- jr nz, .facingleft
- call DrawMetasprite
- jr .facingright
- .facingleft:
- call DrawMetaspriteFlipped
- .facingright
- jp forever
- DrawMetasprite:
- ld d, $c0
- lda e, [oam_ptr]
- .loop:
- push bc
- ldi a, [hl]
- cp 255
- jr z, .done
- add a, c
- ld c, a
- ld [de], a
- inc de
- ldi a, [hl]
- add a, b
- ld b, a
- ld [de], a
- inc de
- ldi a, [hl]
- ld [de], a
- inc de
- xor a
- ld [de], a
- inc de
- pop bc
- jp .loop
- .done:
- pop bc
- ret
- DrawMetaspriteFlipped:
- ld d, $c0
- lda e, [oam_ptr]
- .loop:
- push bc
- ldi a, [hl]
- cp 255
- jr z, .done
- add a, c
- ld c, a
- ld [de], a
- inc de
- ldi a, [hl]
- cpl
- inc a
- add a, b
- ld b, a
- ld [de], a
- inc de
- ldi a, [hl]
- ld [de], a
- inc de
- ld a, OAM_XFLIP
- ld [de], a
- inc de
- pop bc
- jp .loop
- .done:
- pop bc
- ret
- vblank:
- push hl
- ld hl, retraces
- inc [hl]
- pop hl
- reti
- wait_vblank:
- ld a, %00001
- ld [$FFFF],a ; enable vblank interrupt
- ei
- ld hl, retraces
- ld a, [hl]
- .loop:
- halt
- cp a, [hl]
- jr z, .loop
- ret
- stat:
- timer:
- serial:
- joypad:
- reti
- memclear:
- xor a
- ldi [hl], a
- dec bc
- ld a,b
- or c
- jr nz, memclear
- ret
- memset:
- ld [hl], e
- inc hl
- dec bc
- ld a,b
- or c
- jr nz, memset
- ret
- memcpy:
- ldi a, [hl]
- ld [de], a
- inc de
- dec bc
- ld a,b
- or c
- jr nz, memcpy
- ret
- oam_dma_routine:
- ldh [rDMA],a
- ld a,$28
- .wait:
- dec a
- jr nz,.wait
- ret
- oam_dma_routine_end:
- readkeys:
- ld a, [KeyDown]
- ld [KeyLast], a
- ld a, KEY_BUTTONS
- ldh [rKEYS], a
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- and $f
- ld b, a
- ld a, KEY_DIRECTION
- ldh [rKEYS], a
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- ldh a, [rKEYS]
- and $f
- swap a
- or b
- cpl
- ld [KeyDown], a
- ld a, [KeyLast]
- cpl
- ld b, a
- ld a, [KeyDown]
- and b
- ld [KeyNew], a
- ret
- StandingFrame:
- db 0, -4, $00, 0, 4, $01
- db 8, -4, $10, 8, 4, $11
- db 16, -4, $20, 16, 4, $21
- db 24, -4, $30, 24, 4, $31
- db 255
- WalkingFrame:
- db 0, -4, $00, 0, 4, $01
- db 8, -4, $02, 8, 4, $11
- db 16, -4, $12, 16, 4, $21
- db 24, -4, $22, 24, 4, $23
- db 255
- JumpingFrame:
- db 0,-4, $00, 0, 4, $01
- db 8,-4, $02, 8, 4, $11
- db 16,-8, $03, 16, 0, $04
- db 24,-8, $13, 24, 0, $14
- db 16, 8, $05, 24, 8, $15
- db 255
- PingasFrame1:
- db 0, -4, $00, 0, 4, $01
- db 8, -4, $10, 8, 4, $11
- db 16, -4, $20, 16, 4, $24
- db 24, -4, $30, 24, 4, $34
- db 16, 12, $25, 24,12, $35
- db 255
- PingasFrame2:
- db 0, -4, $00, 0, 4, $01
- db 8, -4, $10, 8, 4, $11
- db 16, -4, $20, 16, 4, $32
- db 24, -4, $30, 24, 4, $33
- db 255
- RobotnikText:
- db "Super Robotnik"
- LandText:
- db "Land"
- graphics:
- INCBIN "graphics.chr"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement