Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INCLUDE "hardware.inc"
- SECTION "Header", ROM0[$100]
- jp EntryPoint
- ds $150 - @, 0 ; Make room for the header
- EntryPoint:
- ; Do not turn the LCD off outside of VBlank
- WaitVBlank:
- ld a, [rLY]
- cp 144
- jp c, WaitVBlank
- ; Turn the LCD off
- ld a, 0
- ld [rLCDC], a
- ; Copy the tile data
- ld de, Tiles
- ld hl, $9000
- ld bc, TilesEnd - Tiles
- call Memcopy
- ; Copy the tilemap
- ld de, Tilemap
- ld hl, $9800
- ld bc, TilemapEnd - Tilemap
- call Memcopy
- ; Copy the paddle tile
- ld de, Paddle
- ld hl, $8000
- ld bc, PaddleEnd - Paddle
- call Memcopy
- ld a, 0
- ld b, 160
- ld hl, _OAMRAM
- ClearOam:
- ld [hli], a
- dec b
- jp nz, ClearOam
- ld hl, _OAMRAM
- ld a, 128 + 16
- ld [hli], a
- ld a, 16 + 8
- ld [hli], a
- ld a, 0
- ld [hli], a
- ld [hli], a
- ; Turn the LCD on
- ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON
- ld [rLCDC], a
- ; During the first (blank) frame, initialize display registers
- ld a, %11100100
- ld [rBGP], a
- ld a, %11100100
- ld [rOBP0], a
- ; Initialize global variables
- ld a, 0
- ld [wFrameCounter], a
- ld [wCurKeys], a
- ld [wNewKeys], a
- Main:
- ld a, [rLY]
- cp 144
- jp nc, Main
- WaitVBlank2:
- ld a, [rLY]
- cp 144
- jp c, WaitVBlank2
- ; Check the current keys every frame and move left or right.
- call UpdateKeys
- ; First, check if the left button is pressed.
- CheckLeft:
- ld a, [wCurKeys]
- and a, PADF_LEFT
- jp z, CheckRight
- Left:
- ; Move the paddle one pixel to the left.
- ld a, [_OAMRAM + 1]
- dec a
- ; If we've already hit the edge of the playfield, don't move.
- cp a, 15
- jp z, Main
- ld [_OAMRAM + 1], a
- jp Main
- ; Then check the right button.
- CheckRight:
- ld a, [wCurKeys]
- and a, PADF_RIGHT
- jp z, Main
- Right:
- ; Move the paddle one pixel to the right.
- ld a, [_OAMRAM + 1]
- inc a
- ; If we've already hit the edge of the playfield, don't move.
- cp a, 105
- jp z, Main
- ld [_OAMRAM + 1], a
- jp Main
- UpdateKeys:
- ; Poll half the controller
- ld a, P1F_GET_BTN
- call .onenibble
- ld b, a ; B7-4 = 1; B3-0 = unpressed buttons
- ; Poll the other half
- ld a, P1F_GET_DPAD
- call .onenibble
- swap a ; A3-0 = unpressed directions; A7-4 = 1
- xor a, b ; A = pressed buttons + directions
- ld b, a ; B = pressed buttons + directions
- ; And release the controller
- ld a, P1F_GET_NONE
- ldh [rP1], a
- ; Combine with previous wCurKeys to make wNewKeys
- ld a, [wCurKeys]
- xor a, b ; A = keys that changed state
- and a, b ; A = keys that changed to pressed
- ld [wNewKeys], a
- ld a, b
- ld [wCurKeys], a
- ret
- .onenibble
- ldh [rP1], a ; switch the key matrix
- call .knownret ; burn 10 cycles calling a known ret
- ldh a, [rP1] ; ignore value while waiting for the key matrix to settle
- ldh a, [rP1]
- ldh a, [rP1] ; this read counts
- or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys
- .knownret
- ret
- ; Copy bytes from one area to another.
- ; @param de: Source
- ; @param hl: Destination
- ; @param bc: Length
- Memcopy:
- ld a, [de]
- ld [hli], a
- inc de
- dec bc
- ld a, b
- or a, c
- jp nz, Memcopy
- ret
- Tiles:
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33322222
- dw `33322222
- dw `33322222
- dw `33322211
- dw `33322211
- dw `33333333
- dw `33333333
- dw `33333333
- dw `22222222
- dw `22222222
- dw `22222222
- dw `11111111
- dw `11111111
- dw `33333333
- dw `33333333
- dw `33333333
- dw `22222333
- dw `22222333
- dw `22222333
- dw `11222333
- dw `11222333
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33333333
- dw `33322211
- dw `33322211
- dw `33322211
- dw `33322211
- dw `33322211
- dw `33322211
- dw `33322211
- dw `33322211
- dw `22222222
- dw `20000000
- dw `20111111
- dw `20111111
- dw `20111111
- dw `20111111
- dw `22222222
- dw `33333333
- dw `22222223
- dw `00000023
- dw `11111123
- dw `11111123
- dw `11111123
- dw `11111123
- dw `22222223
- dw `33333333
- dw `11222333
- dw `11222333
- dw `11222333
- dw `11222333
- dw `11222333
- dw `11222333
- dw `11222333
- dw `11222333
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- dw `11001100
- dw `11111111
- dw `11111111
- dw `21212121
- dw `22222222
- dw `22322232
- dw `23232323
- dw `33333333
- ; Paste your logo here:
- dw `33000000
- dw `33000000
- dw `33000000
- dw `33000000
- dw `33111100
- dw `33111100
- dw `33111111
- dw `33111111
- dw `33331111
- dw `00331111
- dw `00331111
- dw `00331111
- dw `00331111
- dw `00331111
- dw `11331111
- dw `11331111
- dw `11333300
- dw `11113300
- dw `11113300
- dw `11113300
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `00003333
- dw `00000033
- dw `00000033
- dw `00000033
- dw `11000033
- dw `11000033
- dw `11111133
- dw `11111133
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11113311
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `33111111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11331111
- dw `11330000
- dw `11330000
- dw `11330000
- dw `33330000
- dw `11113311
- dw `11113311
- dw `00003311
- dw `00003311
- dw `00003311
- dw `00003311
- dw `00003311
- dw `00333311
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11111133
- dw `11113333
- TilesEnd:
- Tilemap:
- db $00, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $02, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $05, $06, $05, $06, $05, $06, $05, $06, $05, $06, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $0A, $0B, $0C, $0D, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $0E, $0F, $10, $11, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $12, $13, $14, $15, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $07, $03, $16, $17, $18, $19, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- db $04, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $09, $07, $03, $03, $03, $03, $03, $03, 0,0,0,0,0,0,0,0,0,0,0,0
- TilemapEnd:
- Paddle:
- dw `13333331
- dw `30000003
- dw `13333331
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- dw `00000000
- PaddleEnd:
- SECTION "Counter", WRAM0
- wFrameCounter: db
- SECTION "Input Variables", WRAM0
- wCurKeys: db
- wNewKeys: db
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement