its a side project for creating that zx0 in zx itself. if i want to use DEF FN as a subtitue for an C_file on a command line the coding off the DEF FN has to be copied to the C_file
this is a start:
Code: Select all
; DEF FN small self test
; DEFselftst_030
; pasmo -d --tap --name DEFselftst DEFselftst_030.asm DEFselftst_030.tap DEFselftst_030.symbol
; cat DEFselftst2.tap DEFselftst_030.tap > DEFtest_030.tap
; NO ORG > 100% relocatable IF FINISED and without the 'print'
; 10 DEF FN a(a,b,c,d,e,f,g,h,i,j)= USR selftest
; 20 DEF FN a$(a,b,c,d,e,f,g,h,i,j)=STR$ USR selftest
; 25 REM df needs SOME string instruction on BOTH sides to be accepted by the Basic interpreter
; 30 LET l= FN a(1,2,3,4,5,6,7,8,9,0)
; 40 LET l$= FN a$(1,2,3,4,5,6,7,8,9,0)
; print routine can be removed after prove-of-works
print equ 1
setchan equ 0x1601 ; ROM openchannel routine for #0 and #2
DEF_ADR equ 23563 ; sysvar
here equ 25500
org here
USR di
push bc ; THIS=USR adres to stack
exx
pop bc
push hl
push bc ; THIS=USR adres to stack
jr overdata
amount defb 0
name defb 32,32,13,255 ; name$ 2 bytes, 'a ' or 'a$' + /0
overdata pop de ; USR adres to DE
ld hl,9
add hl,de
ex de,hl ; DE should point to 'name'
ld hl,(DEF_ADR) ; hl = actual RAM location in BASIC listing at position off the DEF FN
ld bc,5
ld a,206 ; = 'DEF FN'
cpdr ; lower until DEF FN found
inc hl ; 1 step for last result
inc hl ; 1 step for chr$
ld a,(hl) ; fetch DEF chr$ as NAME
ld (de),a ; store chr$ in 'name'
IF print
rst 16
ENDIF
inc hl ;
ld a,(hl)
cp '$' ; test for string value
jr nz,count0 ; $+4
inc de ; adres for '$' if found
ld a,(hl)
ld (de),a ; store $ aswell
IF print
rst 16
ENDIF
dec de ; step back to 'name'
inc hl ; step over '$'
count0 dec de ; de= 'amount'
ex de,hl
ld (hl),1
; inc (hl) ; amount+1 > the namestring is 1st variable of argc > arg[0] is filename
ex de,hl
firstbracket: ld a,(hl) ; reload DEF data
IF print
rst 16
ld a,(hl)
ENDIF
cp '('
jr nz,error ; not a correct DEF FN
testend inc hl ; +1
ld a,(hl)
IF print
rst 16
ld a,(hl)
ENDIF
cp ')' ; if 1st value is a CLOSE bracket NO VARIABLES are included !!!
; then DEF FN might have no extra functionality for the USR command
jr z,closed
notyet: cp 123 ; 'z+1'
jr nc,error ; to big
cp 56 ; 'A'
jr c,error ; to small
; fetch variable chr$name here if needed!!
; how? is yr own problem!!
inc hl ; +1
ld a,(hl)
cp 14 ; only THEN its a 1+5 notation value start marker
jr nz,error ; no marker found
; correct internal DEF FN variable found
ld bc,6 ; +6
add hl,bc ; raise 6 bytes to step over value
ld a,(hl)
IF print
rst 16
ld a,(hl)
ENDIF
cp ','
jr nz,error
count1 ex de,hl
inc (hl) ; amount+1 > the namestring is 1st variable of argc > arg[0] is filename
ex de,hl
jr testend
closed inc hl
ld a,(hl)
IF print
rst 16
ld a,(hl)
ENDIF
cp '='
jr z,done
error ld bc,65535 ; make here an error message ??
done: ld (errr),bc
call write
pop hl
exx
ei
ret
write
ld a,(de)
ld l,a
call dec_number
ld a,2
call setchan
ld a,13
rst 16
ld hl,name
call ploop
ld hl,number_str
call ploop
ret
ploop: ld a,(hl)
cp 0xFF
ret z
inc hl
rst 16
jr ploop
;http://zxm.speccy.cz/data/Z80%20Bits.html#5.1
; Input: HL = number to convert, DE = location of ASCII string
;Output: ASCII string at (DE) ,0 fast 99 super long in TSTATE, its a 'rotator'
dec_number ld h,0 ; cut h for 8bit handeling, yet 5 digits in 0's used
ld de,number_str
Num2Dec5 ld bc,-10000
call Num1
Num2Dec4 ld bc,-1000
call Num1
Num2Dec3 ld bc,-100 ;10t
call Num1 ;17+
Num2Dec2 ld bc,-10 ;10t 2 digits only
call Num1 ;17+
ld c,b ; 4t 0xffff = -1 in 2complement
Num1 ld a,"0"-1 ; 7t
Num2 inc a ;/ 4t
add hl,bc ;/ 7t add a negative number, CARRY influenced
jr c,Num2 ;/12t-5 /(x*(4+7+12)-5) 0=((23))-5 ,9=(10*(23))-5
sbc hl,bc ;15t
ld (de),a ; 7t
inc de ; 6t
ret ;10t
number_str defb 32,32,32,32,32,255
errr defw 0
END here