home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1995-02-19 | 6.0 KB | 197 lines |
- This application is FreeWare. (c) 1995 Dick Alstein
- $;" at line ";
- loadprologue
- codesize%=&2000
- armcode% codesize%
- leafname$="bas2app"
- 2help$="Syntax: "+leafname$+" infile [outfile]"
- -fname$="<MakeApp2$Dir>.CLIapp."+leafname$
- assemble
- "OS_File",10,fname$,&FF8,,code_start,code_end
- loadprologue
- fn$,f%
- !fn$="<MakeApp2$Dir>.Prologue"
- "OS_File",17,fn$
- ,,,,prologuesize%
- prologue% prologuesize%
- "OS_GBPB",4,f%,prologue%,prologuesize%
- set all line nunmbers in prologue to 0
- prologue%?i%<>&FF
- 3 prologue%?i%=0 :
- set line nunber to 0
- prologue%?(i%+1)=0
- 2 i%+=prologue%?(i%+2) :
- on to the next line
- 9prologuesize%=i%-1 :
- omit the terminating &0D + &FF
- assemble
- ! LR=14
- " PC=15
- dblquote$=
- argbuffersize%=512
- pass%=8
- P%=armcode%
- L%=armcode%+codesize%
- [ OPT pass%
- .code_start
- B conversion_start
- .argbuffer
- dim(argbuffersize%)
- .inputtype
- EQUD &FFB
- .outputtype
- EQUD &FF8
- .commandsyntax
- 3- EQUS "Program,Help/S,Infile,Outfile"
- EQUS
- ALIGN
- .helpstring
- EQUS help$
- EQUS
- ALIGN
- .err_wrongtype
- EQUD 0
- </ EQUS "Input file must be a Basic file"
- EQUS
- ALIGN
- .conversion_start
- A5 ; --- This is the part that does the conversion
- C. ; 1. read the name of infile and outfile
- SWI "OS_GetEnv"
- F@ MOV R1,R0 ; pointer to command line in R1
- ADR R0,commandsyntax
- ADR R2,argbuffer
- I MOV R3,#argbuffersize%
- SWI "OS_ReadArgs"
- K; LDR R0,[R2,#4] ; check for "-Help" switch
- TEQ R0,#0
- BNE printhelp
- ND LDR R6,[R2,#8] ; keep pointer to infile name in R6
- TEQ R6,#0
- BEQ printhelp
- QE LDR R7,[R2,#12] ; keep pointer to outfile name in R7
- TEQ R7,#0
- Q R7,R6 ; if no outfile name given then same as infile
- UB ; 2. check filetype of infile and calculate size of outfile
- MOV R0,#17
- MOV R1,R6
- Y! SWI "OS_File"
- MOV R2,R2,LSL #12
- LDR R1,inputtype
- CMP R1,R2,LSR #20
- ADR R0,err_wrongtype
- ^ SWINE "OS_GenerateError"
- _L ADD R8,R4,#prologuesize% ; outputsize = infilesize + prologuesize
- a% ; 3. fill in 'blanks' of prefix
- STR R8,program_size
- LDR R3,program_end
- ADD R3,R3,R8
- STR R3,program_end
- LDR R3,program_dest
- ADD R3,R3,R8
- STR R3,program_dest
- ADD R0,R8,#&9000
- k ADR R1,cmdline_endaddr
- MOV R2,#9
- SWI "OS_ConvertHex8"
- o' ; 4. load input file after prefix
- MOV R0,#16
- MOV R1,R6
- ADR R2,prologue_end
- MOV R3,#0
- SWI "OS_File"
- w& ; 5. write result to output file
- MOV R0,#10
- MOV R1,R7
- LDR R2,outputtype
- |! ADR R4,outputcode_start
- }6 ADD R5,R4,#(prologue_start-outputcode_start)
- ADD R5,R5,R8
- SWI "OS_File"
- ; 6. ready
- SWI "OS_Exit"
- .printhelp
- ADR R0,helpstring
- SWI "OS_Write0"
- SWI "OS_NewLine"
- SWI "OS_Exit"
- .outputcode_start
- K ; --- This is the prefix that is prepended to the given Basic program
- & ; 1. copy Basic program to &9000
- LDR R1,program_size
- LDR R2,program_end
- LDR R3,program_dest
- .copyabyte
- LDRB R0,[R2],#-1
- STRB R0,[R3],#-1
- SUBS R1,R1,#1
- BNE copyabyte
- & ; 2a. construct new command line
- G SWI "OS_GetEnv" ; get pointer to original command line
- ADR R2,newcmdline_rest
- O.copyachar ; copy first part (=name of the Absolute file)
- LDRB R1,[R0],#1
- 3 TEQ R1,#0 ; stop if at zero
- 1 TEQNE R1,#
- (" ") ; or if at a space
- STRNEB R1,[R2],#1
- BNE copyachar
- D MOV R3,#
- (dblquote$) ; file name goes between doublequotes
- STRB R3,[R2],#1
- B MOV R3,#
- (" ") ; and is always followed by a space
- STRB R3,[R2],#1
- M TEQ R1,#0 ; if at zero then skip back to read it again
- ! SUBEQ R0,R0,#1
- Q.copytailchar ; copy rest of command line (=arguments, if any)
- LDRB R1,[R0],#1
- STRB R1,[R2],#1
- TEQ R1,#0
- BNE copytailchar
- / ; 2b. create environment variable from it
- ADR R0,varname
- ADR R1,newcmdline
- O SUB R2,R2,R1 ; length of string, including terminating zero
- MOV R3,#0
- A MOV R4,#4 ; variable type = literal string
- SWI "OS_SetVarVal"
- ; 3. enter Basic
- ADR R0,cmdline
- SWI "OS_CLI"
- I ; --- The following 4 data fields are filled in when bas2app is run
- .program_size
- F EQUD 0 ; set to (outputsize)
- .program_end
- J EQUD &8000+(prologue_start-outputcode_start)-1 ; add (outputsize)
- .program_dest
- C EQUD &9000-1 ; add (outputsize)
- .cmdline
- & EQUS "Basic -quit @00009000,"
- .cmdline_endaddr
- L EQUS "00000000" ; insert (&9000+outputsize)
- EQUS
- .varname
- EQUS "MakeApp2$CLI"
- EQUS
- .newcmdline
- & EQUS "Basic -quit "+dblquote$
- I ; the rest is filled in after(!!) the Basic program has been moved,
- , ; otherwise it overwrites the prologue
- .newcmdline_rest
- .prologue_start
- dim(prologuesize%) ; prologue contents to be filled in after assembling
- .prologue_end
- 0 ; --- The original Basic program goes here
- .code_end
- pass%
- put the prologue contents into place
- i%=0
- prologuesize%-1
- # prologue_start?i%=prologue%?i%
- dim(size%)
- i%=1
- size%
- [ OPT pass%
- EQUB 0
-