	.ORIG x3000
	
;;; MAIN
;;; Register Input
;;;   None
;;; Register Output
;;;   None

MAIN

	;; 
	;; put your code here!!!
	;; 

GAME_OVER
	HALT

; Data Section for MAIN (local variables and shape and color definitions)

; You may want to add some variables here

; Shapes and Colors
SHAPES          .FILL xCC00
                .FILL xCC00
                .FILL xCC00
                .FILL xCC00

                .FILL xF000
                .FILL x4444
                .FILL xF000
                .FILL x4444

                .FILL x8E00
                .FILL x6440
                .FILL x0E20
                .FILL x44C0

                .FILL x2E00
                .FILL x4460
                .FILL x0E80
                .FILL xC440

                .FILL xC600
                .FILL x4C80
                .FILL xC600
                .FILL x4C80

                .FILL x6C00
                .FILL x8C40
                .FILL x6C00
                .FILL x8C40

                .FILL x4E00
                .FILL x4640
                .FILL xE400
                .FILL x4C40

TETRIS_COLORS   .FILL xFFFF     ; White
                .FILL x43FF     ; Light Cyan
                .FILL x7E1F     ; Light Magenta
                .FILL x7FF0     ; Light Yellow
                .FILL x421F     ; Light Blue
                .FILL x43F0     ; Light Green
                .FILL x7E10     ; Light Red

;;; DRAW_SHAPE
;;; Register Input
;;;   r0:	 "row" - row in game field
;;;   r1:	 "col" - column in game field
;;;   r2:	 "shape" - 16-bit encoding of the piece
;;;   r3:	 "color" - color to be drawn
;;; Register Output
;;;   None

DRAW_SHAPE

        ; Register Saving
	ST R0, DSR0
	ST R1, DSR1
	ST R2, DSR2
	ST R3, DSR3
	ST R4, DSR4
	ST R5, DSR5
	ST R6, DSR6
	ST R7, DSR7

	;; 
	;; put your code here!!!
	;; 

        ; Register Restoring
	LD R0, DSR0
	LD R1, DSR1
	LD R2, DSR2
	LD R3, DSR3
	LD R4, DSR4
	LD R5, DSR5
	LD R6, DSR6
	LD R7, DSR7

        RET

; DRAW_SHAPE local variables

; You may want to add some variables here
	
DSR0	.BLKW #1
DSR1	.BLKW #1
DSR2	.BLKW #1
DSR3	.BLKW #1
DSR4	.BLKW #1
DSR5	.BLKW #1
DSR6	.BLKW #1
DSR7	.BLKW #1



;;; DETECT_COLLISION
;;; Register Input
;;;   r0:	 "row" - row in game field
;;;   r1:	 "col" - column in game field
;;;   r2:	 "shape" - 16-bit encoding of the piece
;;; Register Output
;;;   r5:	 1 if a collision would occur, otherwise return 0

DETECT_COLLISION

        ; Register Saving
	ST R0, DCR0
	ST R1, DCR1
	ST R2, DCR2
	ST R3, DCR3
	ST R4, DCR4
	ST R6, DCR6
	ST R7, DCR7

	;; 
	;; put your code here!!!
	;; 

        ; Register Restoring
	LD R0, DCR0
	LD R1, DCR1
	LD R2, DCR2
	LD R3, DCR3
	LD R4, DCR4
	;; don't restore R5, b/c it's the return value
	LD R6, DCR6
	LD R7, DCR7

	RET

; DETECT_COLLISION local variables
	
; You may want to add some variables here

DCR0	.BLKW #1
DCR1	.BLKW #1
DCR2	.BLKW #1
DCR3	.BLKW #1
DCR4	.BLKW #1
DCR6	.BLKW #1
DCR7	.BLKW #1

	
;;; REMOVE_FILLED_ROWS
;;; Register Input
;;;   None
;;; Register Output
;;;   None


REMOVE_FILLED_ROWS

        ; Register Saving
	ST R0, RFRR0
	ST R1, RFRR1
	ST R2, RFRR2
	ST R3, RFRR3
	ST R4, RFRR4
	ST R5, RFRR5
	ST R6, RFRR6
	ST R7, RFRR7

	;; 
	;; put your code here!!!
	;; 

        ; Register Restoring
	LD R0, RFRR0
	LD R1, RFRR1
	LD R2, RFRR2
	LD R3, RFRR3
	LD R4, RFRR4
	LD R5, RFRR5
	LD R6, RFRR6
	LD R7, RFRR7

	RET

; REMOVE_FILLED_ROWS local variables

; You may want to add some variables here

RFRR0	.BLKW #1
RFRR1	.BLKW #1
RFRR2	.BLKW #1
RFRR3	.BLKW #1
RFRR4	.BLKW #1
RFRR5	.BLKW #1
RFRR6	.BLKW #1
RFRR7	.BLKW #1




	.END
