~rabbits/uxn

ref: 806b8c0fa922d394eaea8aa33dc3762da5a8e4f6 uxn/projects/utils/hexdump.tal -rw-r--r-- 1.1 KiB
806b8c0fDevine Lu Linvega (hexdump.tal)Removed trailing short 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
( usage: uxncli hexdump.rom file.bin )

|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2

|0000

	@src $40

|0100 ( -> )

	;on-console .Console/vector DEO2

BRK

@on-console ( -> )

	;src STH2
	( read input )
	.Console/read DEI
	DUP #20 LTH OVR #7f GTH ORA ,&end JCN
	STH2kr ,slen JSR #003f GTH2 ,&end JCN
		STH2kr ,scap JSR STA POP2r BRK
		&end
	POP
	STH2r .File/name DEO2
	#0002 .File/length DEO2
	LIT2r 0000
	&stream
		#0000 ,&buf STR2
		;&buf .File/read DEO2
		.File/success DEI2 #0000 EQU2 ,&eof JCN
		;&buf LDA2 ,print JSR #2018 DEO
		INC2r
		( linebreak )
		STH2kr #0007 AND2 ORA ,&no-lb JCN
			#0a18 DEO &no-lb
		,&stream JMP &eof
	POP2r
	#010f DEO

BRK
	&buf $2

@slen ( str* -- len* )

	DUP2 ,scap JSR SWP2 SUB2

JMP2r

@scap ( str* -- end* )

	LDAk #00 NEQ JMP JMP2r
	&while
		INC2 LDAk ,&while JCN

JMP2r

@print ( short* -- )

	SWP ,&byte JSR
	&byte ( byte -- ) DUP #04 SFT ,&char JSR
	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO

JMP2r