Implement READFILE function (#1759)

This commit is contained in:
Rangi
2025-07-18 18:27:52 -04:00
committed by GitHub
parent 4a2f9fc744
commit 53c39d01d4
12 changed files with 102 additions and 9 deletions

View File

@@ -0,0 +1,24 @@
section "tilemap", rom0
/*
input:
$20
$01 $03 $05 $07 $09
$02 $04 $06 $08 $10
$00 $de $01 $df $80
5
*/
def tilemap equs readfile("readfile-binary.inc.bin")
def area = bytelen(#tilemap) - 2
def offset = strbyte(#tilemap, 0)
def width = strbyte(#tilemap, area + 1)
db width, area / width
for idx, area
db strbyte(#tilemap, idx + 1) + offset
endr
/*
output:
5, 3
$21 $23 $25 $27 $29
$22 $24 $26 $28 $30
$20 $fe $21 $ff $a0
*/

Binary file not shown.

View File

@@ -0,0 +1 @@
!#%')"$&(0 <20>!<21><>

View File

@@ -0,0 +1,2 @@
def s equs readfile("readfile-nonexist.inc")
assert strlen(#s) == 0

View File

@@ -0,0 +1,3 @@
error: readfile-nonexist.asm(1):
Error opening READFILE file 'readfile-nonexist.inc': No such file or directory
Assembly aborted with 1 error!

5
test/asm/readfile.asm Normal file
View File

@@ -0,0 +1,5 @@
def s equs readfile("readfile.inc")
println strupr(#s) ++ "!"
redef s equs readfile("readfile.inc", 5)
println strrpl(#s, "l", "w") ++ "?"

1
test/asm/readfile.inc Normal file
View File

@@ -0,0 +1 @@
hello world

2
test/asm/readfile.out Normal file
View File

@@ -0,0 +1,2 @@
HELLO WORLD!
hewwo?