Browse code

(hexdump.tal) Rewrote

neauoire authored on 15/03/2022 18:42:17
Showing 2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,131 +0,0 @@
1
-( 
2
-	converts a binary file to a series of shorts as strings
3
-	usage: uxncli binstr.rom file.bin )
4
-
5
-%+  { ADD }  %-  { SUB }  %*  { MUL }  %/  { DIV }
6
-%<  { LTH }  %>  { GTH }  %=  { EQU }  %!  { NEQ }
7
-%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
8
-%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
9
-
10
-%HALT   { #010f DEO }
11
-
12
-( devices )
13
-
14
-|10 @Console    &vector $2 &read     $1 &pad    $5 &write  $1 &error  $1
15
-|a0 @File       &vector $2 &success  $2 &stat   $2 &delete $1 &append $1 &name    $2 &length  $2 &read   $2 &write $2
16
-
17
-( variables )
18
-
19
-|0000
20
-
21
-	@length $2
22
-	@src $30
23
-
24
-|0100 ( -> )
25
-
26
-	;on-console .Console/vector DEO2
27
-
28
-BRK
29
-
30
-@on-console ( -> )
31
-
32
-	( starting )
33
-	[ LIT &trap $1 ] ,&started JCN
34
-		;src #0020 ;mclr JSR2
35
-		#01 ,&trap STR
36
-		&started
37
-	( append )
38
-	.Console/read DEI #20 < ,&validate JCN
39
-	;src ;slen JSR2 #0030 == ,&validate JCN
40
-		;src .Console/read DEI ;sput JSR2 BRK
41
-		&validate
42
-	,parse JSR
43
-	#00 ,&trap STR
44
-
45
-BRK
46
-
47
-@parse ( -- )
48
-	
49
-	( load )
50
-	;src .File/name DEO2
51
-	#fff0 ;data -- .File/length DEO2
52
-	;data .File/read DEO2
53
-	( save length )
54
-	.File/success DEI2 .length STZ2
55
-	( export path )
56
-	;tal-ext ;src ;scat JSR2
57
-	( save )
58
-	;src .File/name DEO2
59
-	#0001 .File/length DEO2
60
-	( stream )
61
-	.length LDZ2 ;data ++ ;data
62
-	&loop
63
-		LDAk #04 SFT ,&parse JSR ,&write JSR
64
-		LDAk #0f AND ,&parse JSR ,&write JSR
65
-		( formatting )
66
-		DUP2 ;data --
67
-		DUP2 #000f AND2 #000f !! ,&no-linebreak JCN 
68
-			#0a ,&write JSR ,&end JMP &no-linebreak
69
-		DUP2 #0001 AND2 #0001 !! ,&no-space JCN 
70
-			#20 ,&write JSR &no-space
71
-		&end
72
-		POP2
73
-		INC2 GTH2k ,&loop JCN
74
-	POP2 POP2
75
-	HALT
76
-
77
-JMP2r
78
-	&write ;&b STA ;&b .File/write DEO2 JMP2r
79
-	&parse DUP #09 GTH ,&above JCN #30 + JMP2r &above #57 + JMP2r
80
-	&b $1
81
-
82
-@tal-ext ".tal $1
83
-
84
-@scat ( src* dst* -- )
85
-
86
-	DUP2 ,slen JSR ++ ,scpy JSR
87
-
88
-JMP2r
89
-
90
-@slen ( str* -- len* )
91
-
92
-	DUP2 ,scap JSR SWP2 --
93
-
94
-JMP2r
95
-
96
-@scap ( str* -- end* )
97
-
98
-	LDAk #00 ! JMP JMP2r
99
-	&while 
100
-		INC2 LDAk ,&while JCN
101
-
102
-JMP2r
103
-
104
-@scpy ( src* dst* -- )
105
-	
106
-	STH2
107
-	&while
108
-		LDAk STH2kr STA INC2r
109
-		INC2 LDAk ,&while JCN
110
-	POP2
111
-	#00 STH2r STA
112
-
113
-JMP2r
114
-
115
-@sput ( str* char -- )
116
-
117
-	ROT ROT ,scap JSR STA
118
-
119
-JMP2r
120
-
121
-@mclr ( addr* len* -- )
122
-
123
-	OVR2 ++ SWP2
124
-	&loop
125
-		STH2k #00 STH2r STA
126
-		INC2 GTH2k ,&loop JCN
127
-	POP2 POP2
128
-
129
-JMP2r
130
-
131
-@data
132 0
new file mode 100644
... ...
@@ -0,0 +1,66 @@
1
+( usage: uxncli hexdump.rom file.bin )
2
+
3
+|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
4
+|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
5
+
6
+|0000
7
+
8
+	@src $40
9
+
10
+|0100 ( -> )
11
+
12
+	;on-console .Console/vector DEO2
13
+
14
+BRK
15
+
16
+@on-console ( -> )
17
+
18
+	;src STH2
19
+	( read input )
20
+	.Console/read DEI
21
+	DUP #20 LTH OVR #7f GTH ORA ,&end JCN
22
+	STH2kr ,slen JSR #003f GTH2 ,&end JCN
23
+		STH2kr ,scap JSR STA POP2r BRK
24
+		&end
25
+	POP
26
+	STH2r .File/name DEO2
27
+	#0002 .File/length DEO2
28
+	LIT2r 0000
29
+	&stream
30
+		#0000 ,&buf STR2
31
+		;&buf
32
+			DUP2 .File/read DEO2
33
+			LDA2 ,print JSR #2018 DEO
34
+		INC2r
35
+		( linebreak )
36
+		STH2kr #0007 AND2 ORA ,&no-lb JCN
37
+			#0a18 DEO
38
+			&no-lb
39
+		.File/success DEI2 ORA ,&stream JCN
40
+	POP2r
41
+	#010f DEO
42
+
43
+BRK
44
+	&buf $2
45
+
46
+@slen ( str* -- len* )
47
+
48
+	DUP2 ,scap JSR SWP2 SUB2
49
+
50
+JMP2r
51
+
52
+@scap ( str* -- end* )
53
+
54
+	LDAk #00 NEQ JMP JMP2r
55
+	&while
56
+		INC2 LDAk ,&while JCN
57
+
58
+JMP2r
59
+
60
+@print ( short* -- )
61
+
62
+	&short ( short* -- ) SWP ,&byte JSR
63
+	&byte ( byte -- ) DUP #04 SFT ,&char JSR
64
+	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
65
+
66
+JMP2r