mirror of
https://github.com/irmen/prog8.git
synced 2024-07-27 12:29:24 +00:00
tehtriz joystick input
This commit is contained in:
parent
52ff61470b
commit
f2b03342ac
@ -105,8 +105,8 @@
|
|||||||
|
|
||||||
; ---- CIA 6526 1 & 2 registers ----
|
; ---- CIA 6526 1 & 2 registers ----
|
||||||
|
|
||||||
memory ubyte CIA1PRA = $DC00 ; CIA 1 DRA, keyboard column drive
|
memory ubyte CIA1PRA = $DC00 ; CIA 1 DRA, keyboard column drive (and joystick control port #2)
|
||||||
memory ubyte CIA1PRB = $DC01 ; CIA 1 DRB, keyboard row port
|
memory ubyte CIA1PRB = $DC01 ; CIA 1 DRB, keyboard row port (and joystick control port #1)
|
||||||
memory ubyte CIA1DDRA = $DC02 ; CIA 1 DDRA, keyboard column
|
memory ubyte CIA1DDRA = $DC02 ; CIA 1 DDRA, keyboard column
|
||||||
memory ubyte CIA1DDRB = $DC03 ; CIA 1 DDRB, keyboard row
|
memory ubyte CIA1DDRB = $DC03 ; CIA 1 DDRB, keyboard row
|
||||||
memory ubyte CIA1TAL = $DC04 ; CIA 1 timer A low byte
|
memory ubyte CIA1TAL = $DC04 ; CIA 1 timer A low byte
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
; TehTriz - a Tetris clone.
|
; TehTriz - a Tetris clone.
|
||||||
;
|
;
|
||||||
|
|
||||||
|
; @todo: slow down joystick input
|
||||||
; @todo: holding a block
|
; @todo: holding a block
|
||||||
; @todo: show next 2 blocks instead of just 1
|
; @todo: show next 2 blocks instead of just 1
|
||||||
; @todo: deal with rotation when block is against a wall or another block (wall kicks) (if no rotate in place possible: move 1 left, try rotate, else move 1 right, try rotate, else no rotation possible)
|
; @todo: deal with rotation when block is against a wall or another block (wall kicks) (if no rotate in place possible: move 1 left, try rotate, else move 1 right, try rotate, else no rotation possible)
|
||||||
@ -17,17 +18,26 @@
|
|||||||
const ubyte startXpos = boardOffsetX + 3
|
const ubyte startXpos = boardOffsetX + 3
|
||||||
const ubyte startYpos = boardOffsetY - 2
|
const ubyte startYpos = boardOffsetY - 2
|
||||||
|
|
||||||
ubyte lines = 0
|
ubyte lines
|
||||||
uword score = 0
|
uword score
|
||||||
ubyte xpos = startXpos
|
ubyte xpos
|
||||||
ubyte ypos = startYpos
|
ubyte ypos
|
||||||
ubyte nextBlock = rnd() % 7
|
ubyte nextBlock
|
||||||
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
@(650) = 128 ; set all keys to repeat
|
@(650) = 128 ; set all keys to repeat
|
||||||
|
newGame()
|
||||||
|
drawBoard()
|
||||||
|
gameOver() ; @todo fix game corruption because loop is called multiple times (???)
|
||||||
|
|
||||||
|
newgame:
|
||||||
|
newGame()
|
||||||
drawBoard()
|
drawBoard()
|
||||||
spawnNextBlock()
|
spawnNextBlock()
|
||||||
|
|
||||||
|
ubyte joystick_delay=1
|
||||||
|
|
||||||
waitkey:
|
waitkey:
|
||||||
if c64.TIME_LO==30 {
|
if c64.TIME_LO==30 {
|
||||||
c64.TIME_LO = 0
|
c64.TIME_LO = 0
|
||||||
@ -42,26 +52,24 @@ waitkey:
|
|||||||
; block can't move further down!
|
; block can't move further down!
|
||||||
; check if the game area is full, if not, spawn the next block at the top.
|
; check if the game area is full, if not, spawn the next block at the top.
|
||||||
if blocklogic.isGameOver(xpos, ypos) {
|
if blocklogic.isGameOver(xpos, ypos) {
|
||||||
game_over()
|
gameOver()
|
||||||
|
goto newgame
|
||||||
} else {
|
} else {
|
||||||
spawnNextBlock()
|
spawnNextBlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ubyte key=c64.GETIN() ; @todo: joystick support as well. (doesn't joy1 input characters as well?)
|
ubyte key=c64.GETIN()
|
||||||
if_z goto waitkey
|
ubyte joystick1 = c64.CIA1PRB
|
||||||
|
if key==0 and joystick1==255 goto waitkey
|
||||||
|
|
||||||
if key>='1' and key<='7' {
|
if joystick1!=255 {
|
||||||
; select block type, reset to start pos
|
joystick_delay--
|
||||||
; @todo remove this feature it is for testing purposes only
|
if_nz goto waitkey
|
||||||
xpos = startXpos
|
|
||||||
ypos = startYpos
|
|
||||||
drawBlock(xpos, ypos, 32)
|
|
||||||
blocklogic.newCurrentBlock(key-'1')
|
|
||||||
drawBlock(xpos, ypos, 160)
|
|
||||||
}
|
}
|
||||||
else if key==157 or key==',' {
|
|
||||||
|
if key==157 or key==',' or not (joystick1 & 4) {
|
||||||
; move left
|
; move left
|
||||||
if blocklogic.canMoveLeft(xpos, ypos) {
|
if blocklogic.canMoveLeft(xpos, ypos) {
|
||||||
drawBlock(xpos, ypos, 32)
|
drawBlock(xpos, ypos, 32)
|
||||||
@ -69,7 +77,7 @@ waitkey:
|
|||||||
drawBlock(xpos, ypos, 160)
|
drawBlock(xpos, ypos, 160)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if key==29 or key=='.' {
|
else if key==29 or key=='.' or not (joystick1 & 8) {
|
||||||
; move right
|
; move right
|
||||||
if blocklogic.canMoveRight(xpos, ypos) {
|
if blocklogic.canMoveRight(xpos, ypos) {
|
||||||
drawBlock(xpos, ypos, 32)
|
drawBlock(xpos, ypos, 32)
|
||||||
@ -77,7 +85,7 @@ waitkey:
|
|||||||
drawBlock(xpos, ypos, 160)
|
drawBlock(xpos, ypos, 160)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if key==17 or key=='m' {
|
else if key==17 or key=='m' or not (joystick1 & 2) {
|
||||||
; move down faster
|
; move down faster
|
||||||
if blocklogic.canMoveDown(xpos, ypos) {
|
if blocklogic.canMoveDown(xpos, ypos) {
|
||||||
drawBlock(xpos, ypos, 32)
|
drawBlock(xpos, ypos, 32)
|
||||||
@ -85,13 +93,13 @@ waitkey:
|
|||||||
drawBlock(xpos, ypos, 160)
|
drawBlock(xpos, ypos, 160)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if key==145 or key==' ' {
|
else if key==145 or key==' ' or not (joystick1 & 1) {
|
||||||
; drop down immediately
|
; drop down immediately
|
||||||
drawBlock(xpos, ypos, 32)
|
drawBlock(xpos, ypos, 32)
|
||||||
ypos = boardOffsetY+boardHeight-4 ; @todo determine proper y position
|
ypos = boardOffsetY+boardHeight-4 ; @todo determine proper y position
|
||||||
drawBlock(xpos, ypos, 160)
|
drawBlock(xpos, ypos, 160)
|
||||||
}
|
}
|
||||||
else if key=='z' {
|
else if key=='z' { ; no joystick equivalent (there is only 1 fire button)
|
||||||
; rotate counter clockwise
|
; rotate counter clockwise
|
||||||
if blocklogic.canRotateCCW(xpos, ypos) {
|
if blocklogic.canRotateCCW(xpos, ypos) {
|
||||||
drawBlock(xpos, ypos, 32)
|
drawBlock(xpos, ypos, 32)
|
||||||
@ -99,7 +107,7 @@ waitkey:
|
|||||||
drawBlock(xpos, ypos, 160)
|
drawBlock(xpos, ypos, 160)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if key=='x' {
|
else if key=='x' or not (joystick1 & 16) {
|
||||||
; rotate clockwise
|
; rotate clockwise
|
||||||
if blocklogic.canRotateCW(xpos, ypos) {
|
if blocklogic.canRotateCW(xpos, ypos) {
|
||||||
drawBlock(xpos, ypos, 32)
|
drawBlock(xpos, ypos, 32)
|
||||||
@ -107,6 +115,7 @@ waitkey:
|
|||||||
drawBlock(xpos, ypos, 160)
|
drawBlock(xpos, ypos, 160)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
joystick_delay = 140 ; this more or less slows down the joystick movements to the rate of what key repeats do
|
||||||
|
|
||||||
; @todo check if line(s) are full -> flash/clear line(s) + add score + move rest down
|
; @todo check if line(s) are full -> flash/clear line(s) + add score + move rest down
|
||||||
|
|
||||||
@ -114,7 +123,8 @@ waitkey:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub game_over() {
|
|
||||||
|
sub gameOver() {
|
||||||
c64scr.PLOT(7, 7)
|
c64scr.PLOT(7, 7)
|
||||||
c64.CHROUT('U')
|
c64.CHROUT('U')
|
||||||
c64scr.print("────────────────────────")
|
c64scr.print("────────────────────────")
|
||||||
@ -125,12 +135,32 @@ waitkey:
|
|||||||
c64.CHROUT('J')
|
c64.CHROUT('J')
|
||||||
c64scr.print("────────────────────────")
|
c64scr.print("────────────────────────")
|
||||||
c64.CHROUT('K')
|
c64.CHROUT('K')
|
||||||
while(true) {
|
|
||||||
; endless loop
|
c64scr.PLOT(7, 18)
|
||||||
; @todo restart game on pressing F1/firebutton
|
c64.CHROUT('U')
|
||||||
|
c64scr.print("────────────────────────")
|
||||||
|
c64.CHROUT('I')
|
||||||
|
c64scr.PLOT(7, 19)
|
||||||
|
c64scr.print("│ f1 for new game │")
|
||||||
|
c64scr.PLOT(7, 20)
|
||||||
|
c64.CHROUT('J')
|
||||||
|
c64scr.print("────────────────────────")
|
||||||
|
c64.CHROUT('K')
|
||||||
|
|
||||||
|
while(c64.GETIN()!=133) {
|
||||||
|
; endless loop until user presses F1 to restart the game
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub newGame() {
|
||||||
|
lines = 0
|
||||||
|
score = 0
|
||||||
|
xpos = startXpos
|
||||||
|
ypos = startYpos
|
||||||
|
nextBlock = rnd() % 7
|
||||||
|
c64.CLEARSCR()
|
||||||
|
}
|
||||||
|
|
||||||
sub spawnNextBlock() {
|
sub spawnNextBlock() {
|
||||||
c64.TIME_LO = 0
|
c64.TIME_LO = 0
|
||||||
blocklogic.newCurrentBlock(nextBlock)
|
blocklogic.newCurrentBlock(nextBlock)
|
||||||
@ -155,17 +185,19 @@ waitkey:
|
|||||||
c64scr.PLOT(28,14)
|
c64scr.PLOT(28,14)
|
||||||
c64scr.print("score:")
|
c64scr.print("score:")
|
||||||
c64.COLOR = 12
|
c64.COLOR = 12
|
||||||
c64scr.PLOT(28,19)
|
c64scr.PLOT(28,18)
|
||||||
c64scr.print("controls:")
|
c64scr.print("controls:")
|
||||||
c64.COLOR = 11
|
c64.COLOR = 11
|
||||||
c64scr.PLOT(27,20)
|
c64scr.PLOT(27,19)
|
||||||
c64scr.print("z/x rotate")
|
c64scr.print("z/x rotate")
|
||||||
c64scr.PLOT(27,21)
|
c64scr.PLOT(27,20)
|
||||||
c64scr.print(",/. move")
|
c64scr.print(",/. move")
|
||||||
c64scr.PLOT(27,22)
|
c64scr.PLOT(27,21)
|
||||||
c64scr.print("spc drop")
|
c64scr.print("spc drop")
|
||||||
c64scr.PLOT(27,23)
|
c64scr.PLOT(27,22)
|
||||||
c64scr.print(" m descend")
|
c64scr.print(" m descend")
|
||||||
|
c64scr.PLOT(27,23)
|
||||||
|
c64scr.print("or joystick1")
|
||||||
|
|
||||||
c64scr.setcc(boardOffsetX-1, boardOffsetY-2, 255, 0) ; invisible barrier
|
c64scr.setcc(boardOffsetX-1, boardOffsetY-2, 255, 0) ; invisible barrier
|
||||||
c64scr.setcc(boardOffsetX-1, boardOffsetY-3, 255, 0) ; invisible barrier
|
c64scr.setcc(boardOffsetX-1, boardOffsetY-3, 255, 0) ; invisible barrier
|
||||||
|
@ -5,37 +5,15 @@
|
|||||||
|
|
||||||
; @todo see problem in looplabelproblem.p8
|
; @todo see problem in looplabelproblem.p8
|
||||||
|
|
||||||
|
; @todo when a for loop is executed multiple times, is the loop var correct? (via goto start)
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
uword w = 12345
|
waitjoy:
|
||||||
ubyte flags
|
ubyte key=c64.GETIN()
|
||||||
|
if_z goto waitjoy
|
||||||
|
c64scr.print_ub(key)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
|
goto waitjoy
|
||||||
clear_irqd()
|
|
||||||
c64utils.uword2bcd(w)
|
|
||||||
flags=read_flags()
|
|
||||||
c64scr.print_ubbin(1,flags)
|
|
||||||
c64.CHROUT('\n')
|
|
||||||
|
|
||||||
set_irqd()
|
|
||||||
c64utils.uword2bcd(w)
|
|
||||||
flags=read_flags()
|
|
||||||
c64scr.print_ubbin(1,flags)
|
|
||||||
c64.CHROUT('\n')
|
|
||||||
|
|
||||||
clear_irqd()
|
|
||||||
c64utils.uword2bcd(w)
|
|
||||||
flags=read_flags()
|
|
||||||
c64scr.print_ubbin(1,flags)
|
|
||||||
c64.CHROUT('\n')
|
|
||||||
|
|
||||||
set_irqd()
|
|
||||||
c64utils.uword2bcd(w)
|
|
||||||
flags=read_flags()
|
|
||||||
c64scr.print_ubbin(1,flags)
|
|
||||||
c64.CHROUT('\n')
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user