~rabbits/gyo

6669509e4fa838be624bb638570401807016e88f — neauoire a month ago e394fd5
Revert "Revert "Revert "Revert "Load program from file""""

This reverts commit e394fd558d818198ecc80e3f838a218fd8e3ba5e.
3 files changed, 40 insertions(+), 36 deletions(-)

M build.sh
M src/gyo.tal
A src/program.gyo
M build.sh => build.sh +1 -0
@@ 3,5 3,6 @@
rm -rf bin
mkdir -p bin

uxnasm src/program.gyo bin/program.rom 
uxnasm src/gyo.tal bin/gyo.rom 
uxncli bin/gyo.rom

M src/gyo.tal => src/gyo.tal +33 -36
@@ 1,14 1,18 @@
( uxnasm src/gyo.tal bin/gyo.rom && uxncli bin/gyo.rom )
( GYO! )

|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2

|0000

	@status 
		&pc $2
	@stack
		&ptr $1
		&dat
	@status &pc $2
	@stack &ptr $1 &dat

|0100

	( load )
	;program-txt .File/name DEO2
	#8000 .File/length DEO2
	;program .File/read DEO2
	
	( start )
	#1000


@@ 21,6 25,13 @@
	
BRK

@program-txt "bin/program.rom $1

@acc
	.stack/dat .stack/ptr LDZ #02 SUB ADD JMP2r
	&set ( acc* -- ) ,acc JSR STZ2 JMP2r
	&get ( -- acc* ) ,acc JSR LDZ2 JMP2r

@step ( -- )

	;print-state JSR2


@@ 32,46 43,44 @@ BRK
		DUP2 EQU ,&jump JCN
	( mul )
	STH2
	( if cannot multiply ) 
	;get-acc JSR2 #00 STHkr ( mod2 ) DIV2k MUL2 SUB2 ORA ,&fail JCN
	( if cannot multiply )
	;acc/get JSR2 #00 STHkr ( mod2 ) DIV2k MUL2 SUB2 ORA ,&fail JCN
	( else )
	;get-acc JSR2 #00 STHr DIV2 #00 STHr MUL2
	.stack/dat .stack/ptr LDZ #02 SUB ADD STZ2
	;acc/get JSR2 #00 STHr DIV2 #00 STHr MUL2 ;acc/set JSR2
	,&move JMP

JMP2r
	&drop POP2 JMP2r
	&load
		SWP ;program ADD2 LDA2
		.stack/dat .stack/ptr LDZ ADD STZ2
		.stack/ptr LDZ INC INC .stack/ptr STZ
		SWP ;program ADD2 LDA2 ;acc/set JSR2
		,&move JMP
	&save 
	&save
		;program ADD2 STH2
		.stack/dat .stack/ptr LDZ #02 SUB ADD LDZ2 STH2r STA2
		;acc/get JSR2 STH2r STA2
		.stack/ptr LDZ #02 SUB .stack/ptr STZ
		,&move JMP
	&jump 
		POP #00 SWP .status/pc STZ2 
	&jump
		POP #00 SWP .status/pc STZ2
		JMP2r
	&fail 
		POPr #00 STHr .status/pc LDZ2 ADD2 #0002 ADD2 .status/pc STZ2 
	&fail
		POPr #00 STHr .status/pc LDZ2 ADD2 #0002 ADD2 .status/pc STZ2
		JMP2r
	&move 
		.status/pc LDZ2 INC2 INC2 .status/pc STZ2 
	&move
		.status/pc LDZ2 INC2 INC2 .status/pc STZ2
		JMP2r

( debugger )

@print-state ( -- )

	;acc-txt ;print-str JSR2 #2018 DEO ;get-acc JSR2 ,print JSR #2018 DEO
	;acc-txt ;print-str JSR2 #2018 DEO ;acc/get JSR2 ,print JSR #2018 DEO
	;ptr-txt ;print-str JSR2 #2018 DEO .status/pc LDZ2 ,print JSR #2018 DEO
	.status/pc LDZ2 ;program ADD2 LDA2 
	.status/pc LDZ2 ;program ADD2 LDA2
	DUP2
		SWP ;print/byte JSR2
		LIT '/ #18 DEO
		;print/byte JSR2 
		;print/byte JSR2
	#2018 DEO
	( print opcode )
	;get-opcode JSR2 #05 MUL #00 SWP ;opcodes ADD2 ;print-str JSR2


@@ 96,12 105,6 @@ JMP2r

JMP2r

@get-acc ( -- acc* )

	.stack/dat .stack/ptr LDZ #02 SUB ADD LDZ2

JMP2r

@get-opcode ( num den -- type )

	DUP2 #0000 EQU2 ,&drop JCN


@@ 125,10 128,4 @@ JMP2r
@acc-txt "ACC $1
@ptr-txt "PTR $1

|8000

@program 

0400 0606 0012 ( load 0012 in acc, jump to 0006 )
0203 0302 ( swp registers )
0205 1234 6001 ( if not divisible by 5, jump by 2 )
|8000 @program

A src/program.gyo => src/program.gyo +6 -0
@@ 0,0 1,6 @@

|0100 @program 

0400 0606 0012 ( load 0012 in acc, jump to 0006 )
0203 0302 ( swp registers )
0205 1234 6001 ( if not divisible by 5, jump by 2 )