Skip to content

The mod examples

timofey edited this page Jun 18, 2022 · 5 revisions

load your scripts

TimCPU mod directory has scriptfile.json file, what stores all your scripts

Examples

toggle value

can toggle values using button on inp1

reg1 is toggles between 0 and PISTONUP value

reg2 is toggles between 0 and 1

video usage

CONS PISTONUP 1
JUMP START
MARK TON
COPY 1 REG2
COPY PISTONUP REG1
JUMP WAITIN
MARK TOFF
COPY 0 REG2
COPY 0 REG1
JUMP WAITIN
MARK START
COPY 0 REG1
COPY 0 REG2
MARK WAITIN
SLEP 1
WAIT
TEST REG2 = 0 TON
TEST REG2 = 1 TOFF

snake game


COMM X IS REG1
COMM Y IS REG2
COMM APPLEX IS REG15
COMM APPLEY IS REG16
COMM SNAKEX IS REG17
COMM SNAKEY IS REG18
COMM OTHER IS DISPLAY BITS
COMM REG19 STORES SNEK DIRECTION
COMM REG20 AND REG21 SHOWS LAST ELEMENT IN STACK

CONS SXP 4
CONS SYP 4

BIND X REG1
BIND Y REG2
BIND AX REG15
BIND AY REG16
BIND SX REG17
BIND SY REG18
BIND LX REG20
BIND LY REG21

BIND UP INP3
BIND LEFT INP4
BIND RIGHT INP2
BIND DOWN INP1

BIND DIR REG19
BIND BUFF REG3
BIND AP REG22

BIND D1 REG7
BIND D2 REG8
BIND D3 REG9
BIND D4 REG10
BIND D5 REG11
BIND D6 REG12
BIND D7 REG13
BIND D8 REG14

BIND SCORE REG24

CALL CLRSCREEN
JUMP START

MARK CLRSCREEN
	COPY 0 D1
	COPY 0 D2
	COPY 0 D3
	COPY 0 D4
	COPY 0 D5
	COPY 0 D6
	COPY 0 D7
	COPY 0 D8
	RETI

MARK FILLSCREEN
	COPY 255 D1
	COPY 255 D2
	COPY 255 D3
	COPY 255 D4
	COPY 255 D5
	COPY 255 D6
	COPY 255 D7
	COPY 255 D8
	RETI

MARK APPLEIMG
	CALL CLRSCREEN
	COPY 8 D1
 	COPY 16 D2
 	COPY 108 D3
 	COPY 254 D4
 	COPY 254 D5
 	COPY 254 D6
 	COPY 254 D7
 	COPY 108 D8
 	RETI

MARK GAMEOVER
	CALL CLRSCREEN
	COPY 100 D1
	COPY 132 D2
	COPY 170 D3
	COPY 106 D4
	COPY 96 D5
	COPY 154 D6
	COPY 154 D7
	COPY 100 D8
	WAIT
	RETI

MARK SNEKMENU
	CALL CLRSCREEN
	COPY 210 D1
	COPY 154 D2
	COPY 86 D3
	COPY 210 D4
	COPY 136 D5
	COPY 202 D6
	COPY 140 D7
	COPY 202 D8
	RETI

MARK CLRSTACK
	COMM CLRSTACK USED TO CLEAR STACK
	STLN REG6
	POPI REG6 X
	SUBI REG6 1 REG6
	TEST REG6 > 0 CLRSTACK
	RETI
	
MARK IS1
	COPY BUFF REG7
	RETI
MARK IS2
	COPY BUFF REG8
	RETI
MARK IS3
	COPY BUFF REG9
	RETI
MARK IS4
	COPY BUFF REG10
	RETI
MARK IS5
	COPY BUFF REG11
	RETI
MARK IS6
	COPY BUFF REG12
	RETI
MARK IS7
	COPY BUFF REG13
	RETI
MARK IS8
	COPY BUFF REG14
	RETI

MARK G1
	COPY REG7 BUFF
	RETI
MARK G2
	COPY REG8 BUFF
	RETI
MARK G3
	COPY REG9 BUFF
	RETI
MARK G4
	COPY REG10 BUFF
	RETI
MARK G5
	COPY REG11 BUFF
	RETI
MARK G6
	COPY REG12 BUFF
	RETI
MARK G7
	COPY REG13 BUFF
	RETI
MARK G8
	COPY REG14 BUFF
	RETI

MARK GETY
	TEST Y = 1 G1
	TEST Y = 2 G2
	TEST Y = 3 G3
	TEST Y = 4 G4
	TEST Y = 5 G5
	TEST Y = 6 G6
	TEST Y = 7 G7
	TEST Y = 8 G8
	TEST Y > 8 GAMEOVER
	COPY 0 BUFF
	COMM RETI NOT NEED
	RETI

MARK SETY
	TEST Y = 1 IS1
	TEST Y = 2 IS2
	TEST Y = 3 IS3
	TEST Y = 4 IS4
	TEST Y = 5 IS5
	TEST Y = 6 IS6
	TEST Y = 7 IS7
	TEST Y = 8 IS8
	TEST Y > 8 GAMEOVER
	COMM RETI NOT NEED
	RETI

MARK DRAW
	COMM DRAW TAKE X AND Y
	SUBI X 1 X
	EXPI 2 X REG4
	CALL GETY
	ORII REG4 BUFF BUFF
	CALL SETY
	RETI

MARK CDRAW
	SUBI X 1 X
	COMM CDRAW TAKE X AND Y
	COMM CDRAW CLEAR ONE PIXEL AT SCREEN
	EXPI 2 X REG4
	CALL GETY
	XORI BUFF REG4 BUFF
	CALL SETY
	RETI

MARK APPLERND
	RAND 8 AX
	RAND 8 AY
	COPY 0 REG6
	RETI
MARK APPLEPOS
	CALL APPLERND
MARK APPLE_CYCLE1
	CALL CONT
	ADDI REG6 1 REG6
	TEST REG6 > REG4 APPLE_CYCLE_END
	STLN REG6
	GETI REG6 BUFF
	CALL EXTRACTNUMS
	COMM GET X, Y AND COMPARE IT TO APPLE POS
	TEST X != AX APPLE_CYCLE1
	TEST Y != AY APPLE_CYCLE1
	CALL APPLERND
	STLN REG4
	TEST REG6 <= REG4 APPLE_CYCLE1
MARK APPLE_CYCLE_END
	COPY AX X
	COPY AY Y
	CALL DRAW
	RETI


COMM REG1 WILL BE USED AS X AND REG2 WILL BE USED AS Y
COMM CPU HAS 8 LINES OF DISPLAY WHAT IS 8X8BIT DISPLAY

MARK START
	CALL CLRSTACK
	CALL SNEKMENU
	COMM ASKING FOR PRESSING BUTTON TO PLAY
	WAIT

	COMM SET SNAKE HEAD AND APPLE POSITION
	COPY SXP SX
	COPY SYP SY
	COPY 1 DIR
	COPY 1 SCORE
	CALL DRAWSNEK
	CALL APPLEPOS
	CALL GAMEPLAY
	COPY 1 REG6
MARK GMOV
	CALL GAMEOVER
	SLEP 3
	WAIT
	JUMP START
	COMM GET X AND Y FROM -1 INDEX AT STACK 23 MEANS WHAT X IS 2 AND Y IS 3

MARK DRAWHEAD
	COPY SX X
	COPY SY Y
	CALL DRAW
	RETI
MARK EXTRACTNUMS
	CUTS BUFF 1 Y
	CUTE BUFF 1 X
	RETI
MARK DRAWSNEK
	CALL CLRSCREEN
	CALL DRAWHEAD
	COPY 0 BUFF
	COPY 0 REG6
MARK DRAWSNEK_CYCLE1
	CALL CONT
	COMM BUFF USED FOR NUMBER WHAT WE DRAW
	GETI REG6 BUFF
	CALL EXTRACTNUMS
	CALL DRAW
	ADDI REG6 1 REG6
	STLN REG4
	TEST REG6 <= REG4 DRAWSNEK_CYCLE1
	RETI

COMM ########GAMEPLAY########

MARK COLTEST
	COMM COLTEST IS USED FOR TESTING COLLISION
	COPY 0 REG6
	COPY 0 REG4
MARK COLTEST_CYCLE1
	ADDI REG6 1 REG6
	GETI REG6 BUFF
	CALL EXTRACTNUMS
	TEST SX != X +2
	TEST SY != Y +1
	COPY 1 REG4
	STLN REG5
	TEST REG6 >= REG5 +1
	JUMP COLTEST_CYCLE1
	RETI

MARK CONT
	TEST UP = 0 +1
	COPY 4 DIR
	TEST LEFT = 0 +1
	COPY 1 DIR
	TEST RIGHT = 0 +1
	COPY 3 DIR
	TEST DOWN = 0 +1
	COPY 2 DIR
	RETI
MARK APPLESHOW
	CALL APPLEIMG
	SLEP 2
	CALL DRAWSNEK
	CALL APPLEPOS
	COPY 1 AP
	ADDI SCORE 1 SCORE
	RETI
MARK GAMEPLAY
	CALL CONT
	SLEP 0.5
	CALL CONT
	CALL DRAWSNEK
	CALL COLTEST
	TEST REG4 != 1 +1
	RETI
	CALL APPLE_CYCLE_END
	COPY 0 AP
	TEST SX != AX +2
	TEST SY != AY +1
	CALL APPLESHOW

	COPY SX LX
	COPY SY LY

	TEST DIR != 1 +1
	ADDI SX 1 SX
	TEST DIR != 2 +1
	ADDI SY 1 SY
	TEST DIR != 3 +1
	SUBI SX 1 SX
	TEST DIR != 4 +1
	SUBI SY 1 SY

	ADDS LX LY BUFF
	PUSH 1 BUFF

	CALL CONT
	TEST SX < 10 +1
	RETI
	TEST SX > -1 +1
	RETI
	TEST SY < 10 +1
	RETI
	TEST SY > -1 +1
	RETI

	TEST AP != 0 SKIPM
	STLN REG6
	POPI REG6 BUFF
	CALL CONT
MARK SKIPM
	JUMP GAMEPLAY

Clone this wiki locally