10 REM > TestARM/src
   20 REM Some convoluted problems
   30 REM SprowCoPro needs CodeStart=&4C,Entry
   40 REM Other ARMs needs CodeStart=branch or offset
   50 REM ARMDev doesn't have OS_Convert*
   60 :
   70 load%=&8000:DIM mcode% &400
   80 PC=15:LINK=14:SP=13
   90 FOR P=0 TO 1:opt%=P*3+4
  100   P%=load%:O%=mcode%
  110   [OPT opt%
  120   \ CODE HEADER
  130   \ -----------
  140   .CODESTART
  150   \ Problem in the very first byte!
  160   \ SprowCoPro needs this to be &4C,EQUW Entry,&xx
  170   \ Most other systems need B Entry or EQUD Entry-Start
  180   \ RISC OS needs this to be B Entry
  190   \ B Entry will work on all systems except SprowCoPro
  200   \
  210   .L0000:B Entry:\EQUD Entry-L0000:\EQUD Entry:\EQUD Entry*256+&4C
  220   .L0004:EQUW &00
  230   .L0006:EQUB &6D
  240   .L0007:EQUB CopyR-L0000
  250   .Title:EQUB &00:EQUS "ARM Test Program"
  260          EQUB &00:EQUS "0.01 (01 Jan 2017)"
  270   .CopyR:EQUB &00:EQUS "(C)J.G.Harston":EQUB 0
  280          EQUD load%
  290          EQUD CodeEnd-L0000
  300          ALIGN
  310   .Entry
  320   STR R0,TempR0:STR R1,TempR1:STR R2,TempR2:STR R13,TempR13
  330   ADR R0,Title+1
  340   SWI "OS_Write0"
  350   SWI "OS_NewLine"
  360   :
  370   SWI "OS_GetEnv"
  380   MOV SP,R1        :\ SP=MEMTOP, before this point we have no stack
  390   STMFD (SP)!,{R0}
  400   :
  410   LDR R0,TempR13:STMFD (SP)!,{R14,R0}
  420   LDR R0,TempR0:LDR R1,TempR1:LDR R2,TempR2
  430   STMFD (SP)!,{R0-R12}
  440   :
  450   MOV R3,#0
  460   .Registers
  470   SWI 256+ASC"R"
  480   ORR R0,R3,#ASC"0"
  490   CMP R3,#10
  500   SUBHS R0,R0,#10
  510   SWIHS 256+ASC"1"
  520   SWI "OS_WriteC"
  530   SWILO 256+ASC" "
  540   SWI 256+ASC"="
  550   SWI 256+ASC"&"
  560   LDMFD (SP)!,{R0}
  570   BL PrAddress
  580   SWI "OS_NewLine"
  590   ADD R3,R3,#1
  600   CMP R3,#15
  610   BLO Registers
  620   :
  630   SWI "OS_WriteS":EQUS "OS_GetEnv:":EQUB 10:EQUB 13:EQUB 0:ALIGN
  640   :
  650   SWI "OS_WriteS":EQUS "MEMBOT=&":EQUB 0:ALIGN
  660   MOV R0,#&83:SWI "OS_Byte"
  670   ORR R0,R1,R2,LSL #8:BL PrAddress
  680   :
  690   SWI "OS_WriteS":EQUS "  MEMTOP=&":EQUB 0:ALIGN
  700   ADD R0,SP,#4:BL PrAddress
  710   :
  720   SWI "OS_WriteS":EQUB 10:EQUB 13:EQUS "CMD=>":EQUB 0:ALIGN
  730   LDMFD (SP)!,{R3} :\ R3=>command line
  740   .CommandLine
  750   LDRB R0,[R3],#1
  760   CMP  R0,#ASC" "
  770   SWIHS "OS_WriteC"
  780   BHS   CommandLine
  790   SWI "OS_WriteS":EQUS "<":EQUB 10:EQUB 13:EQUB 0:ALIGN
  800   :
  810   SWI "OS_Exit"
  820   :
  830   \ Manually print 32-bit word in R0
  840   .PrAddress
  850   MOV R1,R0  :\ R1=number being processed
  860   MOV R2,#8  :\ R2=number of digits
  870   .PrAddressLoop
  880   MOV R0,R1,LSR #28
  890   MOV R1,R1,LSL #4
  900   CMP R0,#10
  910   ADDHS R0,R0,#7
  920   ADD R0,R0,#48
  930   SWI "OS_WriteC"
  940   SUBS R2,R2,#1
  950   BNE PrAddressLoop
  960   MOV PC,R14
  970   :
  980   .Buffer
  990   .TempR0:EQUD 0
 1000   .TempR1:EQUD 0
 1010   .TempR2:EQUD 0
 1020   .TempR13:EQUD 0
 1030   :
 1040   .CodeEnd
 1050 ]NEXT
 1060 PRINT "Saving";
 1070 OSCLI "SAVE TestARM "+STR$~mcode%+" "+STR$~O%+" "+STR$~load%+" "+STR$~load%
 1080 PRINT