home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / dev / basic / makeapp.spk / !MakeApp2 / CLIapp / b2a0_src (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1995-03-21  |  4KB  |  136 lines

  1.  This application is FreeWare. (c) 1995 Dick Alstein
  2. $;" at line ";
  3. codesize%=&2000
  4.  armcode% codesize%
  5. leafname$="bas2app0"
  6. 2help$="Syntax: "+leafname$+" infile [outfile]"
  7. -fname$="<MakeApp2$Dir>.CLIapp."+leafname$
  8. assemble
  9.  "OS_File",10,fname$,&FF8,,code_start,code_end
  10. assemble
  11.     LR=14
  12.     PC=15
  13. dblquote$=
  14. argbuffersize%=512
  15.  pass%=8 
  16.   P%=armcode%
  17.   L%=armcode%+codesize%
  18.   [ OPT pass%
  19. .code_start
  20.   B       conversion_start
  21. .argbuffer
  22. dim(argbuffersize%)
  23. .inputtype
  24.   EQUD    &FFB
  25. .outputtype
  26.   EQUD    &FF8  
  27. .commandsyntax
  28.  -  EQUS    "Program,Help/S,Infile,Outfile"
  29.   EQUS    
  30.   ALIGN
  31. .helpstring
  32.   EQUS    help$
  33.   EQUS    
  34.   ALIGN
  35. .err_wrongtype
  36.   EQUD    0
  37. )/  EQUS    "Input file must be a Basic file"
  38.   EQUS    
  39.   ALIGN
  40. .conversion_start
  41. .5  ; --- This is the part that does the conversion
  42. 0.  ; 1. read the name of infile and outfile
  43.   SWI     "OS_GetEnv"
  44. 3@  MOV     R1,R0              ; pointer to command line in R1
  45.   ADR     R0,commandsyntax
  46.   ADR     R2,argbuffer
  47. 6   MOV     R3,#argbuffersize%
  48.   SWI     "OS_ReadArgs"
  49. 8;  LDR     R0,[R2,#4]         ; check for "-Help" switch
  50.   TEQ     R0,#0
  51.   BNE     printhelp
  52. ;D  LDR     R6,[R2,#8]         ; keep pointer to infile name in R6
  53.   TEQ     R6,#0
  54.   BEQ     printhelp
  55. >E  LDR     R7,[R2,#12]        ; keep pointer to outfile name in R7
  56.   TEQ     R7,#0
  57. Q   R7,R6              ; if no outfile name given then same as infile
  58. BB  ; 2. check filetype of infile and calculate size of outfile 
  59.   MOV     R0,#17
  60.   MOV     R1,R6
  61. F!  SWI     "OS_File"          
  62.   MOV     R2,R2,LSL #12
  63.   LDR     R1,inputtype
  64.   CMP     R1,R2,LSR #20
  65.   ADR     R0,err_wrongtype
  66. K   SWINE   "OS_GenerateError"
  67. L:  MOV     R8,R4              ; outputsize = infilesize
  68. N%  ; 3. fill in 'blanks' of prefix
  69.   STR     R8,program_size
  70.   LDR     R3,program_end
  71.   ADD     R3,R3,R8
  72.   STR     R3,program_end
  73.   LDR     R3,program_dest
  74.   ADD     R3,R3,R8
  75.   STR     R3,program_dest
  76.   ADD     R0,R8,#&9000
  77. X   ADR     R1,cmdline_endaddr
  78.   MOV     R2,#9
  79.   SWI     "OS_ConvertHex8"
  80. \'  ; 4. load input file after prefix
  81.   MOV     R0,#16
  82.   MOV     R1,R6
  83.   ADR     R2,program_start
  84.   MOV     R3,#0
  85.   SWI     "OS_File"
  86. d&  ; 5. write result to output file
  87.   MOV     R0,#10
  88.   MOV     R1,R7
  89.   LDR     R2,outputtype
  90. i!  ADR     R4,outputcode_start
  91. j5  ADD     R5,R4,#(program_start-outputcode_start)
  92.   ADD     R5,R5,R8
  93.   SWI     "OS_File"
  94.   ; 6. ready
  95.   SWI     "OS_Exit"
  96. .printhelp
  97.   ADR     R0,helpstring
  98.   SWI     "OS_Write0"
  99.   SWI     "OS_NewLine"
  100.   SWI     "OS_Exit"
  101. .outputcode_start
  102. zK  ; --- This is the prefix that is prepended to the given Basic program
  103. |&  ; 1. copy Basic program to &9000
  104.   LDR     R1,program_size
  105.   LDR     R2,program_end
  106.   LDR     R3,program_dest
  107. .copyabyte
  108.   LDRB    R0,[R2],#-1
  109.   STRB    R0,[R3],#-1
  110.   SUBS    R1,R1,#1
  111.   BNE     copyabyte
  112.   ; 2. enter Basic
  113.   ADR     R0,cmdline
  114.   SWI     "OS_CLI"
  115. J  ; --- The following 4 data fields are filled in when bas2app0 is run
  116. .program_size
  117. F  EQUD    0                                  ; set to (outputsize)
  118. .program_end
  119. I  EQUD    &8000+(program_start-outputcode_start)-1 ; add (outputsize)
  120. .program_dest
  121. C  EQUD    &9000-1                            ; add (outputsize)
  122. .cmdline
  123. &  EQUS    "Basic -quit @00009000,"
  124. .cmdline_endaddr
  125. L  EQUS    "00000000"                         ; insert (&9000+outputsize)
  126.   EQUS    
  127. .program_start
  128. 0  ; --- The original Basic program goes here
  129. .code_end
  130.  pass%
  131. dim(size%)
  132.  i%=1 
  133.  size%
  134.   [ OPT pass%
  135.   EQUB    0
  136.