home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / misc / akf52_2 / AKF52 / AKF52_A_s (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1995-11-28  |  19KB  |  427 lines

  1.  >AKF52_A_s
  2. $+" / "+
  3.  *** You can edit these constants if you need to: ***
  4.  But best leave alone if you're unsure!
  5. vsn$="1.10"
  6.  *** Leave these constants alone or it'll all go pear shaped :-)
  7. VFlag%=1<<28
  8.  code% 163840
  9.  p%=4 
  10. P%=0:O%=code%
  11. [OPT p%
  12. .moduleheader
  13. I.startcode       EQUD 0                \ We are a service module only
  14. N.initcode        EQUD initialise       \ claims workspace, maybe loads map
  15. >.finalisecode    EQUD finalise         \ not much actually
  16. B.servicehandler  EQUD service          \ test for mode changes
  17. ,.titleofset      EQUD titlestring      \
  18. ,.helpofset       EQUD helpstring       \
  19. ?.tableofset      EQUD commtable        \ table of *commands
  20. <.swichunk        EQUD 0 \swichunk%        \ my SWI chunk
  21. >.swihandlerofset EQUD 0 \swihandler       \ my SWI handler
  22. B.swidectabofset  EQUD 0 \swidecodetable   \ and decoding table
  23. M.swidecodeofset  EQUD 0 \swidecodecode    \ doesn't (need to) do anything
  24. ..titlestring     EQUS "AKF52":EQUB 0:ALIGN
  25. H.helpstring      EQUS "AKF52":EQUB 9:EQUB 9:EQUS vsn$+" ("+
  26. $,5,11)
  27. 8                 EQUS ") 
  28.  Musus Umbra":EQUB 0:ALIGN
  29. .commtable
  30. "Kequs "mrep":dcb 0:align:equd mrep:equd &20000:equd mrep_is:equd mrep_he
  31. #Kequs "rmap":dcb 0:align:equd rmap:equd &00000:equd rmap_is:equd rmap_he
  32. $Kequs "reps":dcb 0:align:equd reps:equd &00000:equd reps_is:equd reps_he
  33. equd 0   \ terminator
  34. \ .swidecodetable
  35. \ EQUS "AKF52":EQUB 0
  36. \ equs "Status":dcb 0
  37. \ equs "ShowMap":dcb 0
  38. \ equs "ReadMap":dcb 0
  39. \ equs "WriteMap":dcb 0
  40. \ equd 0
  41. \ALIGN
  42. \.swidecodecode
  43. \MOVS     PC,R14
  44. 46\.swihandler    \ code taken straigt from the PRM!
  45. 5/\CMP      R11,#(EndOfJumpTable-JumpTable)/4
  46. \ADDLO    PC,PC,R11,LSL#2
  47. \B        unknownswierror
  48. \.JumpTable
  49. \B status_entry
  50. \b rmap
  51. \b readmap_entry
  52. \b writemap_entry
  53. \.EndOfJumpTable
  54. \.unknownswierror
  55. \ADR      R0,errtoken
  56. \MOV      R1,#0
  57. \MOV      R2,#0
  58. \ADR      R4,titlestring
  59. D)\SWI      "XMessageTrans_ErrorLookup"
  60. RS     PC,R14,#VFlag%
  61. \.errtoken
  62. G(\EQUD &1E6:EQUS "BadSWI":EQUB0:ALIGN
  63. .initialise
  64. STMFD   R13!,{R7-R11,R14}
  65. K2LDR     R2,[R12]           \ get !private word
  66. LBCMP     R2,#0              \ is this a re-init? (after RMTidy)
  67. MCLDMneFD R13!,{R7-R11,R14}  \ if so then we've got nothing to do
  68. N(MOVnes  PC,R14             \ so exit
  69. P=MOV     R0,#6              \ OS_Module6 = Claim workspace
  70. QRMOV     R3,#256            \ We want 256 bytes (1 byte per mode) + scrap space
  71. R0SWI     "XOS_Module"       \ claim workspace
  72. SQbvs     initover           \ if it didn't work then we'd best just die now...
  73. THSTR     R2,[R12]           \ store workspace pointer in private word
  74. UKbl      copydeftab         \ if not a reinit then install default table
  75. VK.initover                  \ initialisation done (either failed or not)
  76. W-LDMfD   R13!,{R7-R11,R14}  \ restore regs
  77. X6mov     pc,r14             \ exit (with any error)
  78. .finalise
  79. [CMOV     PC,R14             \ goodbye cruel module area, shniff.
  80. \P                           \ I know it's unnecesary, but I used to have some
  81. ]J                           \ code here, and might do again, one day...
  82. a,\\ The command help/syntax message text:
  83. cN.mrep_he  equs "The Mrep command allows you to specify whether the AKF52 "
  84. dN          equs "module should replace the default RISC OS modes with its "
  85. eQ          equs "larger ones for a specific mode. Its main use is to disable "
  86. fO          equs "the replacement of a screen mode that a game fails to use "
  87. gK          equs "properly. If no parameters are given then the current "
  88. hL          equs "screen mode and its 'replaced' status is displayed. If "
  89. iS          equs "you specify a mode but omit the On/Off, the 'replaced' status "
  90. jO          equs "of the mode will be displayed. If you use the full syntax "
  91. kO          equs "the mode's 'replaced' status will be changed. Use 'On' to "
  92. lK          equs "mark the mode as replaced and 'Off' to use the normal "
  93. m2          equs "RISC OS mode.":equb 10:equb 13
  94. nB.mrep_is  equs "Syntax: *Mrep [ <mode> [On|Off] ]":dcb 0:align
  95. pS.rmap_he  equs "The Rmap command displays a table showing which RISC OS modes "
  96. qS          equs "are marked to be replaced by the 'enhanced' modes provided by "
  97. r0          equs "the module.":equb 10:equb 13
  98. s..rmap_is  equs "Syntax: *Rmap":dcb 0:align
  99. uP.reps_he  equs "The Reps command lists all the avlaiable replacement modes."
  100.           equb 10:equb 13
  101. w..reps_is  equs "Syntax: *Reps":dcb 0:align
  102. equd 0
  103. {    ALIGN
  104. }B\\ The service handler; just listens for modeextension service
  105. ~C\\ and replaces the RISCOS mode only if the mode table says so.
  106. 4.service                         \ The backbone!
  107. =teq         r1,#&50              \ is it a modeextension?
  108. DmovNE       pc,r14               \ pass call on ASAP (was movne)
  109. 7ldr         r12,[r12]            \ get private word
  110. 1stmfd       r13!,{r0-r2,r14}     \ store regs
  111. (cmp         r2,#0                \ \
  112. Cldmltfd     r13!,{r0-r2,pc}^     \  \  don't attempt lookup for
  113. Acmp         r2,#64               \  /  modes outide our range
  114. (ldmgefd     r13!,{r0-r2,pc}^     \ /
  115. Eldrb        r1,[r12,r2]          \ get byte corresponding to mode
  116. 0cmp         r1,#0                \ if 0 then
  117. Lldmeqfd     r13!,{r0-r2,pc}^     \    pass call on (mode is unreplaced).
  118. /bl          getptrsformode       \ get ptrs
  119. cmp         r1,#&50
  120. Ildmeqfd     r13!,{r0-r2,pc}^     \ pass call on (mode is unreplaced).
  121.  ldmfd       r13!,{r0-r2,r14}
  122. mov         r1,#0
  123. Emov         pc,r14               \ claim call (mode is replaced).
  124. N\\ Display the mode table. The table is formatted to that the mode numbers
  125. G\\ are right aligned in fields 4 chars wide. Also, the width of the
  126. Q\\ screen is examined so that we can make sure that no column splits over two
  127. P\\ lines. Neat kludge- widths greater than 80 are rounded down to 80 so that
  128. 3\\ the output still looks good in a taskwindow.
  129. 0.rmap                        \ SWI & command
  130. 0stmfd     r13!,{r0-r5,r14}   \ preserve regs
  131. 4ldr       r12,[r12]          \ get workspace ptr
  132. Emov       r1,#1              \ text cols Mode Variable = number 1
  133. <sub       r0,r1,#2           \ -1     (ie. current mode)
  134. $swi       "XOS_ReadModeVariable"
  135. =cmp       r2,#79             \ is is >80  (var is cols-1)
  136. Tmovge     r2,#79             \ clamp to 80 col mode (makes taskwindow O/P nicer)
  137. 9mov       r5,r2,lsr#2        \ modes entries per line
  138. ?mov       r0,#32             \ store the padding spaces now
  139. -strb      r0,[r12,#128]      \ dum de dum
  140. 0strb      r0,[r12,#129]      \ doodedumdedah
  141. *strb      r0,[r12,#130]      \ hmmhmmm
  142. 1swi       "XOS_WriteS"       \ display header
  143. Kequs      "The following modes are marked for replacement:":dcb 0:align
  144. "swi       "XOS_NewLine"      \
  145. ;mov       r4,#0              \ start checking at mode 0
  146. 8mov       r3,#0              \ 0th mode on this line
  147. .showloop
  148. 3ldrb      r1,[r12,r4]       \ get flag for mode
  149. .cmp       r1,#0             \ is it clear?
  150. =beq       notshow           \ if so then don't preent eet
  151. 4mov       r0,r4             \ r0=the mode number
  152. 3add       r1,r12,#131       \ address of buffer
  153. Pmov       r2,#100           \ size of buffer (overkill, but hey, who cares?)
  154. @swi       "XOS_ConvertInteger1"  \ Convert LSB of r0 to text
  155. @sub       r2,r1,r0          \ get length of string resulting
  156. Srsb       r2,r2,#4          \ calculate how many spaces are needed to format it
  157. -add       r0,r12,#131       \ ptr->buffer
  158. ;sub       r0,r0,r2          \ ptr->start of padded text
  159. 5swi       "XOS_Write0"      \ display mode number
  160. Qadd       r3,r3,#1          \ increment the 'modes printed this line' counter
  161. Icmp       r3,r5             \ have we hit the edge of the screen yet?
  162. =movgt     r3,#0             \ if so then start a new line
  163. Qswigt     "XOS_NewLine"     \ with the 'modes printed this line' counter at 0
  164. Q.notshow                    \ right, either we've printed the mode, or didn't
  165. Hadd       r4,r4,#1          \ either way, increment the mode counter
  166. Ccmp       r4,#64            \ have we hit the end of the table?
  167. 7blt       showloop          \ if not then loop back
  168. @cmp       r3,#0             \ did we finish on a blank line?
  169. Kswine     "XOS_NewLine"     \ if not then print a newline to compensate
  170. 0swi       "XOS_WriteS"      \ display footer
  171. Gequs      "All other modes use standard RISC OS modes.":dcb 0:align
  172. swi       "XOS_NewLine"
  173. .ldmfd     r13!,{r0-r5,r14}  \ restore regs
  174. &mov       pc,r14            \ exit
  175. L\\  Okay, the *Mrep command (by far and away the most complex bit of the
  176. \\  module)
  177.     .mrep
  178. 3stmfd       r13!,{r1-r4,r14}       \ Store regs
  179. Ncmp         r1,#0                  \ is this an info request? (ie. 0 args)
  180. 8beq         showcurrmode           \ if so handle it
  181. Kcmp         r1,#2                  \ or a *mode <n> on|off  (ie. 1 arg)
  182. Kbeq         configmode             \ if not then handle the full syntax
  183. 9mov         r1,r0                  \ r1->command tail
  184. Pmov         r2,#63                 \ max value we'll accept as the first arg
  185. Bmov         r0,#10                 \ default base of fisrt arg
  186. Lorr         r0,r0,#(1<<29 
  187.  1<<31) \ must be in range 0..r2 & terminated
  188. ?swi         "XOS_ReadUnsigned"    \ convert arg to a number
  189. @ldmvsfd     r13!,{r1-r4,r14}      \ exit with error if V set
  190. @orrvss      pc,r14,#1<<28         \ ------------------------
  191. 'swi         "XOS_WriteS"          \
  192. 'equs        "Mode: ":dcb 0:align  \
  193. :mov         r0,r2                 \ r0=the mode number
  194. mov         r4,r2
  195. 3ldr         r12,[r12]             \ get ->wkspc
  196. 9add         r1,r12,#131           \ address of buffer
  197. Amov         r2,#100               \ size of buffer (overkill)
  198. Aswi         "XOS_ConvertInteger1" \ Convert LSB of r0 to text
  199. .swi         "XOS_Write0"          \ output
  200. 5ldrb        r1,[r12,r4]           \ get mode flag
  201. 8cmp         r1,#0                 \ replaced or not?
  202. 'beq         unreplaced            \
  203. 'swi         "XOS_WriteS"          \
  204. *equs        " marked for replacement."
  205. dcb 0:align
  206. 'swi         "XOS_NewLine"         \
  207. 0ldmfd       r13!,{r1-r4,r14}      \ and exit
  208. 'mov         pc,r14                \
  209. .unreplaced
  210. 'swi         "XOS_WriteS"          \
  211. *equs        " marked as RISC OS mode."
  212. dcb 0:align
  213. 'swi         "XOS_NewLine"         \
  214. 0ldmfd       r13!,{r1-r4,r14}      \ and exit
  215. 'mov         pc,r14                \
  216. <.showcurrmode                     \ display current mode
  217. 3mov         r0,#135               \ OS_Byte 135
  218. >swi         "XOS_Byte"            \ read screen mode in R2
  219. >swi         "XOS_WriteS"          \ display message header
  220. 3equs        "Current screen mode: ":dcb 0:align
  221. 9ldr         r12,[r12]             \ get workspace ptr
  222. Radd         r1,r12,#132           \ r1->buffer (after mode table in workspace)
  223. -mov         r0,r2                 \ mode#
  224. <ldrb        r3,[r12,r2]           \ get flag (for later)
  225. Dmov         r2,#100               \ buffer size (majot overkill)
  226. =swi         "XOS_ConvertInteger1" \ convert mode# to text
  227. 2swi         "XOS_Write0"          \ write text
  228. Qswi         "XOS_NewLine"         \ do you really *need* this line commented?
  229. Hswi         "XOS_WriteS"          \ think of my poor aching fingers!
  230. #equs        "Marked status:   "
  231. dcb 0:align
  232. Hcmp         r3,#0                 \ is the mode marked as 'enhanced'
  233. Eadreq       r0,unrepmess          \ if not, use the 'off' message
  234. Fadrne       r0,repmess            \ otherwise use the 'on' message
  235. 7swi         "XOS_Write0"          \ display message
  236.     Nswi         "XOS_NewLine"         \ and 5...2...4...3...1...Oh No!...-pop-
  237. Ildmfd       r13!,{r1-r4,r14}      \ Damm. Slip, dammit Freudian SLIP.
  238. ,mov         pc,r14                \ exit
  239. 2.unrepmess equs "standard RISC OS mode.":dcb 0
  240. >.repmess   equs "replaced by 'enhanced' mode.":dcb 0:align
  241. !\\ SWI to update the mode map
  242. J.writemap_entry                \ Set flag for 'mode R0' to '(bool) R1'
  243. ldr         r12,[r12]
  244. cmp         r0,#64
  245. bge         badmodee
  246. cmp         r0,#0
  247. blt         badmodee
  248. stmfd       r13!,{r1}
  249. cmp         r1,#0
  250. movne       r1,#255
  251. strb        r1,[r12,r0]
  252. ldmfd       r13!,{r1}
  253. mov         pc,r14
  254. .badmodee
  255. adr         r0,badmodeeblk
  256. orrs        pc,r14,#1<<28
  257. .badmodeeblk
  258.  -equd 0:equs "Bad mode number":dcb 0:align
  259. "G.readmap_entry       \ Return flag for mode R0 in R1 (r0 preserved)
  260. ldr         r12,[r12]
  261. cmp         r0,#64
  262. bge         badmodee
  263. cmp         r0,#0
  264. blt         badmodee
  265. ldrb        r1,[r12,r0]
  266. mov         pc,r14
  267. \\ Return replacement state
  268. .status_entry
  269. ./mov         pc,r14               \ and exit
  270. 0/\\  Aha! at last! The *Mrep <n> On|Off bit!
  271. .configmode
  272. 3M\ at this point, r1-4,r14 are stacked, r0->command tail, r12=private word
  273. 48ldr         r12,[r12]            \ get workspace ptr
  274. 57mov         r1,r0                \ r1->command tail
  275. 60mov         r2,#63               \ max value
  276. 76mov         r0,#10               \ default base 10
  277. 8Eorr         r0,r0,#(1<<31 
  278.  1<<29)        \ space/ctrl terminated
  279. 95swi         "XOS_ReadUnsigned"   \ convert number
  280. :?ldmvsfd     r13!,{r1-r4,r14}     \ exit with error if V set
  281. ;?orrvss      pc,r14,#1<<28        \ ------------------------
  282. <E\ Okay, so now r2 holds the mode number and r1->terminating space
  283. =@.findnextarg                 \ now find the next argument...
  284. >&ldrb    r0,[r1],#1           \ ...
  285. ?Gcmp     r0,#32               \ by skip spaces until next char found
  286. @&beq     findnextarg          \ ...
  287. A+orr     r0,r0,#32            \ Mung Ho!
  288. BQcmp     r0,#
  289. "o"           \ Test for On|off just like in the VME entry above
  290. bne     mbadarg
  291. D/ldrb    r0,[r1],#1           \ get 2nd char
  292. E"cmp     r0,#32               \
  293. ble     mbadarg
  294. orr     r0,r0,#32
  295. H$cmp     r0,#
  296. "n"           \ On?
  297. beq     mteston
  298. J%cmp     r0,#
  299. "f"           \ Off?
  300. beq     mtestoff
  301. .mbadarg
  302. ldmfd   r13!,{r1-r4,r14}
  303. adr     r0,msyntaxmess
  304. O/orrs    pc,r14,#1<<28        \ Return error
  305. .msyntaxmess
  306. Q7dcd 0:equs "Syntax: Mode [<number> [On|Off]]":dcb 0
  307. R    align
  308. .mbadrep
  309. ldmfd   r13!,{r1-r4,r14}
  310. adr     r0,mrepmess
  311. W/orrs    pc,r14,#1<<28        \ Return error
  312. .mrepmess
  313. YCdcd 0:equs "No replacement available for that mode":dcb 0:align
  314. .mteston
  315. \6ldrb    r0,[r1],#1           \ test for terminator
  316. cmp     r0,#32
  317. bgt     mbadarg
  318. _Q\ at this point, we know that 'on' was the argument. the mode number is in r2
  319. `:\ so we can check if we can actally replace that mode.
  320. bl      getptrsformode
  321. cmp     r1,#0
  322. bne     mbadrep
  323. mov     r1,#255
  324. e:.meupscotty                  \ very crap pun coming up
  325. f<strb    r1,[r12,r2]          \ update mode flag in table
  326. gAmov     r3,r2                \ take a copy of the mode number
  327. h/ldmfd   r13!,{r1-r4,r14}     \ restore regs
  328. i+mov     pc,r14               \ and exit
  329. .mtestoff
  330. k0ldrb    r0,[r1],#1           \ get next char
  331. orr     r0,r0,#32
  332. m cmp     r0,#
  333. "f"           \
  334. n"bne     mbadarg              \
  335. o6ldrb    r0,[r1],#1           \ test for terminator
  336. cmp     r0,#32
  337. bgt     mbadarg
  338. mov     r1,#0
  339. sRb       meupscotty           \ certainly sir, will a 2x4 do?  (I did warn you)
  340. u6.prurm equs " (replacement not used).":dcb 0:align
  341. v4.prrm  equs " (replacement in use).":dcb 0:align
  342. x>\\ Copy the default mode table into the current mode table
  343. y8.copydeftab                \ On entry, R2->workspace
  344. zIadr    r3,defaulttable     \ get pointer to default table (hardcoded)
  345. {Gmov    r5,#128             \ maximum number of entries in the table
  346. |Nmov    r6,#0               \ well, um, zero. Also flag for unenhanced mode
  347. .cleartable
  348. ~Kstr    r6,[r2,r5]          \ blank word in table (starts R5 entries in)
  349. 2subs   r5,r5,#4            \ working backwards
  350. Gbge    cleartable          \ until we've run out of table to blank!
  351. Tmov    r5,#255             \ this is the byte we'll write for an 'enhanced' mode
  352. .cdt_loop
  353. 8ldrb   r4,[r3],#1          \ get next mode from list
  354. /cmp    r4,#128             \ is top bit set
  355. ?movge  pc,r14              \ if so then we're done so exit.
  356. Estrb   r5,[r2,r4]          \ otherwise set mode flag in the table
  357. /b      cdt_loop            \ and loop back.
  358.     .reps
  359. #stmfd    r13!,{r0-r2,r5,r6,r14}
  360. adr      r5,modedata
  361. ldr      r12,[r12]
  362. add      r1,r12,#132
  363. swi      "XOS_WriteS"
  364. 0equs     "Replacements available for modes:"
  365. dcb 0:align
  366. swi      "XOS_NewLine"
  367. .prloop
  368. *ldr      r6,[r5],#176      \ writeback
  369. 7cmn      r6,#1             \ -1 terminates the list
  370. #ldmeqfd  r13!,{r0-r2,r5,r6,pc}^
  371. cmp      r6,#63
  372. #ldmgtfd  r13!,{r0-r2,r5,r6,pc}^
  373. 'mov      r0,r6             \ number
  374. %cmp      r0,#10            \ <10?
  375. .swilt    256+32            \ padding space
  376. swi      256+32
  377. swi      256+32
  378. ,mov      r2,#100           \ buffer size
  379. -swi      "XOS_ConvertInteger1" \ LSB only
  380. ,swi      "XOS_Write0"          \ display
  381. -ldrb     r6,[r12,r6]           \ get flag
  382. 0cmp      r6,#0                 \ unreplaced?
  383. swine    256+42
  384. swi      "XOS_NewLine"
  385. b        prloop
  386. D.getptrsformode            \ on entry, r2=mode number to look up
  387. stmfd    r13!,{r3-r6,r14}
  388. adr      r5,modedata
  389. .searchloop
  390. *ldr      r6,[r5],#176      \ writeback
  391. 7cmn      r6,#1             \ -1 terminates the list
  392. /moveq    r1,#&50           \ not found flag
  393. ldmeqfd  r13!,{r3-r6,pc}^
  394. and      r6,r6,#&ff
  395. Dcmp      r6,r2             \ is this the mode we're looking for?
  396. 6bne      searchloop        \ if not then try again
  397. mov      r1,r5
  398. ldmfd    r13!,{r3-r6,r14}
  399. ,sub      r3,r1,#&ac        \ get -> data
  400. ,add      r4,r3,#&40        \ get -> data
  401. 0mov      r1,#0             \ mode found flag
  402. movs     pc,r14
  403. *\\ Start of 
  404.  table flag - DO 
  405.  OVE!
  406. EQUB 255
  407. H.defaulttable              \ list of mode numbers, terminated by 128
  408. equb 0
  409. equb 12
  410. equb 18
  411. equb 19
  412. equb 20
  413. equb 21
  414.  equb 128                   \
  415.     align
  416. .modedata
  417. ("ModeData"):
  418.  A=0 
  419.  0,"Can't find 'ModeData'.":
  420. "OS_File",255,"ModeData",O%,0:O%+=(E+4)
  421. "OS_File",10,"akf52",&FFA,,code%,O%
  422.  0,"Code size = "+
  423. ~(modedata-moduleheader)+" bytes."
  424. H3(A%):=
  425. "000"+
  426. ~A%,3)
  427.