Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .nolist
- #include "ti83plus.inc"
- #define gbuf plotsscreen
- #define fallingBlocks AppBackUpScreen
- #define setBlocks AppBackUpScreen+8
- .list
- ; coords go x, y, x, y in fallingBlocks
- ; h = y coordinate, l = x coordinate
- ; coords go (0, 0), (1, 0), ..., (9, 0), (0, 1), (1, 1), ...,
- ; (9, 1), (0, 2), (1, 2), ... in setBlocks
- .org $9D93
- .db $BB, $6D
- programStart:
- ld hl, $FC0B
- ld (fallingBlocks), hl
- ld hl, $FF0B
- ld (fallingBlocks+2), hl
- ld hl, $FF0E
- ld (fallingBlocks+4), hl
- ld hl, $FF11
- ld (fallingBlocks+6), hl
- ld a, (fallTime)
- ld (fallTimer), a
- ld a, (lockTime)
- ld (lockTimer), a
- gameLoop:
- ld a, 0
- ld (isBlocked), a
- ld a, (fallTimer)
- dec a
- jp nz, writeFallTimer
- call dropFallingBlocks
- ld a, (fallTime)
- writeFallTimer:
- ld (fallTimer), a
- keyInput:
- bcall(_GetCSC)
- cp skleft
- jp z, keyLeft
- cp skright
- jp z,keyRight
- softDrop:
- cp skdown
- jp z, keyDown
- rotation:
- ; cp skup
- ; jp z, keyUp
- locking:
- ld a, (isBlocked)
- cp 0 ; z flag is only set after cp 0
- jp z, notBlocked
- ld a, (lockTimer)
- dec a
- ld (lockTimer), a
- jp z, drawBlocks
- ret
- ; ld b, 4 ; the block has been fully locked
- ; ld hl, fallingBlocks + 7
- ;settingBlocks:
- ; ld a, (hl)
- ; call divideBy3
- ; sla a ; multiplying by 10
- ; ld c, a
- ; sla a
- ; sla a
- ; add a, c
- ; ld c, a
- ; dec hl
- ; ld a, (hl)
- ; call divideBy3
- ; add a, c
- ; push hl
- ; ld hl, setBlocks
- ; add a, l ; this will not overflow
- ; ld l, a
- ; ld (hl), 1
- ; pop hl
- ; dec hl
- ; djnz settingBlocks
- ; call drawBlocks
- ; call fastCopy
- ; jp programStart
- notBlocked:
- ld a, (lockTime)
- ld (lockTimer), a
- drawBlocks:
- call drawFallingBlocks
- call fastCopy
- call drawFallingBlocks ; erase the blocks through XOR
- jp gameLoop
- ret
- keyDown:
- ld a, 1
- ld (fallTimer), a
- jp rotation
- keyLeft:
- ld b, 4
- ld hl, fallingBlocks + 6
- leftWallCheckLoop:
- ld a, (hl)
- cp 2
- jp nz, leftNotBlocked
- jp softdrop
- leftNotBlocked:
- dec l
- dec l
- djnz leftWallCheckLoop
- ld b, 4
- ld hl, fallingBlocks + 6
- keyLeftLoop:
- ld a, (hl)
- sub 3
- ld (hl), a
- dec l
- dec l
- djnz keyLeftLoop
- jp softDrop
- keyRight:
- ld b, 4
- ld hl, fallingBlocks + 6
- rightWallCheckLoop:
- ld a, (hl)
- cp 29
- jp nz, rightNotBlocked
- jp softdrop
- rightNotBlocked:
- dec l
- dec l
- djnz rightWallCheckLoop
- ld b, 4
- ld hl, fallingBlocks + 6
- keyRightLoop:
- ld a, (hl)
- add a, 3
- ld (hl), a
- dec l
- dec l
- djnz keyRightLoop
- jp softDrop
- ; drops all 4 falling blocks by one block height
- ; input: none
- ; output:
- ; drops each falling block by one block height
- ; destroys: a b hl
- dropFallingBlocks:
- ld b, 4
- ld hl, fallingBlocks + 7
- fallingBlocksFloorCheckLoop:
- ld a, (hl)
- cp 59
- jp nz, fallNotBlocked
- ld a, 1 ; at least one block is obstructed
- ld (isBlocked), a
- ret
- fallNotBlocked:
- dec l
- dec l
- djnz fallingBlocksFloorCheckLoop
- ld b, 4
- ld hl, fallingBlocks + 7
- dropFallingBlocksLoop:
- ld a, (hl)
- add a, 3
- ld (hl), a
- dec l
- dec l
- djnz dropFallingBlocksLoop
- ret
- ; draws the 4 falling blocks
- ; input: none
- ; output: draws the 4 blocks to the screen
- ; destroys: af bc de hl ix
- drawFallingBlocks:
- ld b, 4
- ld de, fallingBlocks
- ld a, e
- add a, b
- add a, b
- ld e, a
- drawFallingBlocksLoop:
- dec e
- ld a, (de)
- ld l, a
- dec e
- ld a, (de)
- push bc
- push de
- ld ix, block
- ld b, 3
- call putSprite
- pop de
- pop bc
- djnz drawFallingBlocksLoop
- ret
- ; copies sprite to gbuf
- ; destroys: af bc de hl ix
- putSprite:
- ld e,l
- ld h,$00
- ld d,h
- add hl,de
- add hl,de
- add hl,hl
- add hl,hl ;Find the Y displacement offset
- ld e,a
- and $07 ;Find the bit number
- ld c,a
- srl e
- srl e
- srl e
- add hl,de ;Find the X displacement offset
- ld de,gbuf
- add hl,de
- putSpriteLoop1:
- sl1: ld d,(ix) ;loads image byte into D
- ld e,$00
- ld a,c
- or a
- jr z,putSpriteSkip1
- putSpriteLoop2:
- srl d ;rotation to give out smooth moving
- rr e
- dec a
- jr nz,putSpriteLoop2
- putSpriteSkip1:
- ld a,(hl)
- xor d
- ld (hl),a
- inc hl
- ld a,(hl)
- xor e
- ld (hl),a ;copy to buffer using XOR logic
- ld de,$0B
- add hl,de
- inc ix ;Set for next byte of image
- djnz putSpriteLoop1
- ret
- ; copies gbuf to the LCD
- ; Input: nothing
- ; Output: graph buffer is copied to the screen and subsequently cleared
- ; destroys: af bc de hl
- fastCopy:
- di
- ld a,$80
- out ($10),a
- ld hl,gbuf-12-(-(12*64)+1)
- ld a,$20
- ld c,a
- inc hl ;filler
- dec hl ;filler
- fastCopyAgain:
- ld b,64
- inc c
- ld de,-(12*64)+1
- out ($10),a
- add hl,de
- ld de,10
- fastCopyLoop:
- add hl,de
- inc hl ;filler
- inc hl ;filler
- inc de ;filler
- ld a,(hl)
- out ($11),a
- dec de ;filler
- djnz fastCopyLoop
- ld a,c
- cp $2B+1
- jr nz,fastCopyAgain
- ret
- ; sutracts 2 from the a register, divides by 3,
- ; and puts the result back into a
- ; only works if 0 < a < 62 and if (a - 2) | 3
- ; destroys: de
- divideBy3:
- cp 20
- jp nc, greaterThan20
- ld de, divisionBy3LookUpTable - 2
- jp division
- greaterThan20:
- cp 41
- jp nc, greaterThan41
- ld de, divisionBy3LookUpTable - 22
- jp division
- greaterThan41:
- ld de, divisionBy3LookUpTable - 42
- division:
- add a, e
- ld e, a
- ld a, (de)
- ret
- divisionBy3LookUpTable:
- .db 0
- .db 7
- .db 14
- .db 1
- .db 8
- .db 15
- .db 2
- .db 9
- .db 16
- .db 3
- .db 10
- .db 17
- .db 4
- .db 11
- .db 18
- .db 5
- .db 12
- .db 19
- .db 6
- .db 13
- .db 20
- ; variables
- fallTimer:
- .db %00000000
- fallTime:
- .db %01111111
- lockTimer:
- .db %00000000
- lockTime:
- .db %00111111
- isBlocked:
- .db %00000000
- ; sprites
- block:
- .db %11000000
- .db %11000000
- .db %00000000
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement