home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG051.ARK / ALX.S2M < prev    next >
Text File  |  1984-04-29  |  16KB  |  499 lines

  1. ~`~`0 (+-*/)    MACROS FOR 8080 ASSEMBLY LANGUAGE EXTENSION PREPROCESSOR
  2. .HELLO~
  3. -- ALX 2.6a  03/19/81  For CPMUG`F15~
  4. ~ ------------------------------------
  5. .LSKIP `~            ;To increment label counter by P1
  6. `10`F7~
  7. .INCSYM~
  8. `F8~
  9. ~
  10. .INCSYM~
  11. `01`16~
  12. ~ ---------------------------------------
  13.     `~            ;To accept an input line starting with tab
  14. .TRIM `10~            ;    remove leading spaces or tabs
  15. ^IND`76 ^TRIM`86~        ;    indentation an line reference
  16. >>    `71`81~            ;    output to listing channel
  17. .STM `81~            ;    process statement
  18. .DUMP STACK~
  19. ~ ---------------------------------------
  20. >>`| FIN`~
  21. `10|_FIN`20`F14~
  22. ~ ---------------------------------------
  23. >>`| UNTIL`~
  24. `10|_UNTIL`20`F14~
  25. ~ ---------------------------------------
  26. >>`~
  27. `10`F14~
  28. ~ ---------------------------------------
  29.  `~                ;To accept line starting with space
  30.     `10~            ;    change space to tab
  31. ~ ---------------------------------------
  32. BEGIN`~
  33. .HELLO~
  34. BEGIN`10`F14~
  35. ~ ---------------------------------------
  36. `:`~                ;To accept line with label
  37. `10:`F14~            ;    output label to listing channel
  38. `10:`F13~            ;    output label to ASM file
  39. .IF `20= SKIP 1~
  40.     `20~            ;    pass on rest of statement for processing
  41. ~ ---------------------------------------
  42. PROCEDURE `~            ;To recognize PROCEDURE declaration
  43. .IF ^CSP<1 SKIP 4~
  44. ^DBG`86 `81`86 .STO ^DBG=T~
  45. .DUMP STACK~
  46. .STO ^DBG=`80~
  47. .ERR STACK NOT EMPTY -- CHECK CONTROL STRUCTURES~
  48. .LET ^CSP=0~            ;    clear control stack
  49. .LET ^LEV=0~            ;    control structure level
  50. .STO ^IND=~            ;    clear indentation string
  51. ^PROC`86 .PROC `10~
  52.  `F14~
  53.    - - - - - - - - - - - - - - - - - - - - - - - - - - `81`F14~
  54.  `F14~
  55. PROCEDURE `10`F14~        ;    output to listing channel
  56.  `F14~
  57. `81:  ; - - - - - - - - - - - - - - PROCEDURE `10`F13~
  58. ~ ---------------------------------------
  59. .PROC  `~
  60. .PROC `10~
  61. ~ ---------------------------------------
  62. .PROC `~
  63. `10`27 ;    ~        ;    scan with break on " " or ";" or TAB
  64. .STO ^PROC=`20~
  65. ~ ---------------------------------------
  66. ;`~                ;To accept comment line
  67. ;`10`F14~            ;    output to listing channel
  68. ~ ---------------------------------------
  69. `~                ;To accept any other line
  70. .IF `10-= SKIP 1~        ;    if P1 is null
  71.  `16~                ;    P1 = " "
  72. `10`F14~            ;    output to listing channel
  73. `10`F13~            ;    output to ASM file
  74. ~ ---------------------------------------
  75. .STM IF`(`)`~            ;To recognize IF statement
  76. ...IF (`20)`30~            ;    output comment line to ASM file
  77. .CHECK IF~
  78. .PUSH `01~            ;    push label n
  79. .PUSH K~            ;    push code "K" - IF or WHEN ELSE
  80. .JCF `20,`01~            ;    output conditional jump to n
  81. .XSTM `30~            ;    process remainder of line
  82. ~ ---------------------------------------
  83. .STM WHEN`(`)`~            ;To recognize WHEN statement
  84. ...WHEN (`20)`30~        ;    output comment line to ASM file
  85. .CHECK WHEN~
  86. .PUSH `01~            ;    push label n
  87. .PUSH `02~            ;    push label n+1
  88. .PUSH W~            ;    push code "W" - WHEN
  89. .JCF `20,`02~            ;    output conditional jump to n+1
  90. .XSTM `30~            ;    process remainder of line
  91. ~ ---------------------------------------
  92. .STM ELSE`~            ;To recognize ELSE statement
  93. ...ELSE`10~            ;    output comment line to ASM file
  94. .POP~
  95. ^CSI`96 .ELSE `91~        ;    process else or flag error
  96. .XSTM `10~            ;    process remainder of line
  97. ~ ---------------------------------------
  98. .ELSE E~
  99. .POPL~                ;    output label n+1 from stack
  100. .PUSH K~            ;    push code "K" - IF or WHEN ELSE term.
  101. ~ ---------------------------------------
  102. .ELSE `~
  103. .PUSH `10~            ;    restore stack
  104. .SERR ELSE~
  105. ~ ---------------------------------------
  106. .STM BRANCH`~            ;To recognize BRANCH statement
  107. ...BRANCH`10~            ;    output comment line to ASM file
  108. .CHECK BRANCH~
  109. .PUSH B~            ;    push code "B" - BRANCH
  110. .INCLEV~
  111. ~ ---------------------------------------
  112. .STM SELECT`~            ;To recognize SELECT statement
  113. ...SELECT`10~            ;    output comment line to ASM file
  114. .CHECK SELECT~
  115. .PUSH `01~            ;    push label n
  116. .PUSH S~            ;    push code "S" - SELECT
  117. .INCLEV~
  118. ~ ---------------------------------------
  119. .STM EXECUTE`(`)`~        ;To recognize EXECUTE statement
  120. .PUSH `01~            ;    push label n
  121. .PUSH X~            ;    push code "X" - EXECUTE
  122. .INCLEV~
  123. .. LHLD `20~
  124. .. PCHL ~
  125. ~ ---------------------------------------
  126. .STM SETNEXT`(`=`)`~        ;To recognize SETNEXT statement
  127. ^TRIM`86 .TRIM `30~
  128. .. LXI H,`81~
  129. .TRIM `20~
  130. .. SHLD `81~
  131. ~ ---------------------------------------
  132. .STM (`)`~            ;To recognize SELECT or BRANCH ITEM
  133. ...(`10)`20~            ;    output comment line to ASM file
  134. .TOS~
  135. ^CSI`36 .ITEM `31(`10)`20~
  136. ~ ---------------------------------------
  137. .ITEM B(`)`~            ;To recognize simple BRANCH ITEM
  138. .. CPI `10~            ;    output compare instruction
  139. .. JZ `20~            ;    output jump if match instruction
  140. ~ ---------------------------------------
  141. .ITEM B(`|`)`~            ;To recognize BRANCH ITEM with OR
  142. `10|`20`47|~            ;    scan with break on OR symbol
  143. .. CPI `40~            ;    output compare instruction
  144. .. JZ `30~            ;    output jump if match instruction
  145. `F8~                ;    end of loop
  146. ~ ---------------------------------------
  147. .ITEM B(`OTHERWISE`)`~        ;To recognize BRANCH catch all ITEM
  148. .. JMP `30~            ;    output jump instruction
  149. ~ ---------------------------------------
  150. .ITEM S(`)`~            ;To recognize simple SELECT ITEM
  151. .PUSH `01~            ;    push label n+x
  152. .PUSH I~            ;    push code "I" - SELECT ITEM
  153. .. CPI `10~            ;    output compare instruction
  154. .. JNZ LLZ`01~            ;    output JNZ n+x
  155. .XSTM `20~            ;    process remainder of line
  156. ~ ---------------------------------------
  157. .ITEM S(`|`)`~            ;To recognize SELECT ITEM with OR
  158. .PUSH `02~            ;    push label n+x+1
  159. .PUSH I~            ;    push code "I" - SELECT ITEM
  160. `10|`20`47|~            ;    scan with break on OR symbol
  161. .. CPI `40~            ;    output compare instruction
  162. .IF `43-=| SKIP 2~        ;    if break char. is OR
  163. .. JZ LLZ`01~            ;        output jump to match
  164. .SKIP 1~            ;    else end of line
  165. .. JNZ LLZ`02~            ;        output jump to nomatch
  166. `F8~                ;    end of scan loop
  167. ..LLZ`01:  ~            ;    output label n+x: for match
  168. .XSTM `30~            ;    process remainder of line
  169. ~ ---------------------------------------
  170. .ITEM S(`OTHERWISE`)`~        ;To recognize SELECT catch all ITEM
  171. .PUSH O~            ;    push code "O" - OTHERWISE
  172. .XSTM `30~            ;    process remainder of line
  173. ~ ---------------------------------------
  174. .ITEM X(`)`~            ;To recognize EXECUTE item (state)
  175. .PUSH Y~
  176. ^LABEL`86 .LABEL `10~
  177. ..`81:  ~
  178. .XSTM `20~            ;    process remainder of line
  179. ~ ---------------------------------------
  180. .LABEL  `~
  181. .LABEL `10~
  182. ~ ---------------------------------------
  183. .LABEL `~
  184. `10`27 :    ~
  185. .STO ^LABEL=`20~
  186. ~ ---------------------------------------
  187. .ITEM `(`)`~            ;To recognize SELECT ITEM out of place
  188. .SERR SELECT, BRANCH ITEM~
  189. .ITEM S(`20)`30~        ;    process line anyway
  190. ~ ---------------------------------------
  191. .STM WHILE`(`)`~        ;To recognize WHILE statement
  192. ...WHILE (`20)`30~        ;    output comment line to ASM file
  193. .CHECK WHILE~
  194. .LOOP `01,L~            ;    setup loop
  195. .JCF `20,`01~            ;    output conditional jump to n
  196. .XSTM `30~            ;    process remainder of line
  197. ~ ---------------------------------------
  198. .STM LOOP`~            ;To recognize unconditional LOOP statement
  199. ...LOOP`10~            ;    output comment line to ASM file
  200. .CHECK LOOP~
  201. .LOOP `01,L~            ;    setup loop
  202. .XSTM `10~            ;    process remainder of line
  203. ~ ---------------------------------------
  204. .STM REPEAT`~            ;To recognize REPEAT statement
  205. ...REPEAT`10~            ;    output comment line to ASM file
  206. .CHECK REPEAT~
  207. .LOOP `01,R~            ;    setup loop
  208. .INCLEV~
  209. ~ ---------------------------------------
  210. .LOOP `,`~            ;To setup loop for WHILE, REPEAT or LOOP
  211. .PUSH `10~            ;    put exit label on stack
  212. .PUSH `01~            ;    put loop label on stack
  213. .PUSH `20~            ;    put structure code on stack
  214. ..LLZ`01:  ~            ;    output loop label
  215. ~ ---------------------------------------
  216. .STM UNTIL`(`)`~        ;To recognize UNTIL termination of REPEAT
  217. ...UNTIL (`20)`30~        ;    output comment line to ASM file
  218. .POP~
  219. ^CSI`96 .UNTIL `91,`20~        ;    generate conditional jump or flag error
  220. ~ ---------------------------------------
  221. .UNTIL R,`~
  222. .DECLEV~
  223. .POP~
  224. ^CSI`96 .JCF `10,`91~        ;    output conditional jump to n
  225. .POPL~                ;    output label from stack
  226. ~ ---------------------------------------
  227. .UNTIL `,`~
  228. .PUSH `10~            ;    restore stack
  229. .SERR UNTIL~
  230. ~ ---------------------------------------
  231. .STM BREAK`IF`(`)`~        ;To recognize loop BREAKout statement
  232. ...BREAK IF (`30)~        ;    output comment line to ASM file
  233. .CHECK BREAK IF~
  234. .BRK~                ;    search stack for exit label
  235. ^CSI`86 .JCT `30,`81~        ;    GEN conditional branch
  236. ~ ---------------------------------------
  237. .BRK~                ;To search control stack for exit label
  238. .IF ^CSP>0 SKIP 2~        ;    when stack empty
  239. .SERR BREAK~            ;    BREAK out of place
  240. `F9~                ;    else
  241. .LET ^CSB=^CSP+1~        ;    search pointer = stack pointer + 1
  242. ^CSB`96~
  243. ^CSP`F7~            ;    for i = 1 to stack size
  244. .LET ^CSB=^CSB-1~        ;        decrement search pointer
  245. ^CS`91`86 ^BRK`81`86~
  246. .IF `81-= SKIP 3~        ;        if loop code found goto success
  247. `F8~                ;        fin
  248. .SERR BREAK~            ;    BREAK out of place
  249. `F9~                ;    exit
  250. `91-2`96 ^CS`94`86~        ;    success:  point to exit label on stack
  251. .STO ^CSI=`81~            ;    save exit label
  252. ~ ---------------------------------------
  253. .STM FIN`~            ;To recognize FIN terminator
  254. ...FIN`10~            ;    output comment line to ASM file
  255. .DECLEV~
  256. .POP~
  257. ^CSI`96 .FIN `91~        ;    process FIN by code found on stack
  258. ~ ---------------------------------------
  259. .FIN B~                ;To terminate BRANCH
  260. ~ ---------------------------------------
  261. .FIN I~                ;To terminate SELECT ITEM
  262. .POP~
  263. ^CSI`96 `91`96~            ;    pop label n+x
  264. .POP~
  265. ^CSI`86 `81`86~            ;    pop code "S"
  266. .TOSJ~                ;    output jump to label n (stack top)
  267. .PUSH `80~            ;    push code "S" back on stack
  268. ..LLZ`90:  ~            ;    output label n+x:
  269. ~ ---------------------------------------
  270. .FIN K~                ;To terminate IF or WHEN ELSE
  271. .POPL~                ;    output label n: from stack
  272. ~ ---------------------------------------
  273. .FIN L~                ;To terminate WHILE loop
  274. .POPJ~                ;    output jump to n+1: from stack
  275. .POPL~                ;    output label n: from stack
  276. ~ ---------------------------------------
  277. .FIN O~                ;To terminate SELECT OTHERWISE ITEM
  278. ~ ---------------------------------------
  279. .FIN S~                ;To terminate SELECT
  280. .POPL~                ;    output label n: from stack
  281. ~ ---------------------------------------
  282. .FIN W~                ;To terminate WHEN branch
  283. .POP~
  284. ^CSI`96 `91`96~            ;    pop label n+1
  285. .TOSJ~                ;    output jump to label n (stack top)
  286. .PUSH `90~            ;    put label n+1 back on the stack
  287. .PUSH E~            ;    push code "E" - ELSE
  288. ~ ---------------------------------------
  289. .FIN X~                ;To terminate EXECUTE
  290. .POPL~
  291. ~ ---------------------------------------
  292. .FIN Y~                ;To terminate EXECUTE ITEM
  293. .POP~
  294. ^CSI`86 `81`86~            ;    pop code "X"
  295. .TOSJ~                ;    output jump to label n (stack top)
  296. .PUSH `80~            ;    push code "X" back on stack
  297. ~ ---------------------------------------
  298. .FIN `~                ;To recognize a wayward FIN
  299. .INCLEV~
  300. .PUSH `10~            ;    restore stack
  301. .SERR FIN~
  302. ~ ---------------------------------------
  303. END-`~                ;To recognize END-OF-FILE
  304. END-`10`F14~
  305. ^CSP`26 .IF `21<1 SKIP 3~    ;    if stack not empty
  306. .ERR STACK NOT EMPTY -- CHECK CONTROL STRUCTURES~
  307. .STO ^DBG=T~            ;    set debug mode
  308. .DUMP STACK~            ;    send stack contents to LST file
  309. LLZ`01 Next label not used`F15~
  310. `F0~                ;    stop processing
  311. ~ ---------------------------------------
  312. .STM `~                ;To recognize non control statements
  313. .CHECK `10~
  314.     `10`F13~        ;    output to ASM file
  315. ~ ---------------------------------------
  316. .XSTM `~
  317. .INCLEV~
  318. .TRIM `10~            ;    strip leading spaces and tabs
  319. ^TRIM`26 .YSTM `21~
  320. ~ ---------------------------------------
  321. .YSTM ~
  322. ~ ---------------------------------------
  323. .YSTM ;`~
  324. ~ ---------------------------------------
  325. .YSTM `~
  326. .CHECK `10~
  327.     `10`F13~        ;    output to ASM file
  328. .STM FIN~            ;    generate a FIN statement
  329. ~ ---------------------------------------
  330. .TRIM  `~            ;To strip leading space
  331. .TRIM `10~
  332. ~ ---------------------------------------
  333. .TRIM     `~            ;To strip leading tab
  334. .TRIM `10~
  335. ~ ---------------------------------------
  336. .TRIM `~            ;To save line without leading spaces and tabs
  337. .STO ^TRIM=`10~
  338. ~ ---------------------------------------
  339. .INCLEV~
  340. .LET ^LEV=^LEV+1~
  341. .CAT ^IND, | ~            ;    append to indentation string
  342. ~ ---------------------------------------
  343. .DECLEV~            ;To decrement control structure level
  344. ^LEV`16 .IF `11<1 SKIP 2~
  345. .LET ^LEV=^LEV-1~
  346. ^IND`26 .UND `21~        ;    remove " | " from indentation string
  347. ~ ---------------------------------------
  348. .UND ` | ~            ;To remove one level of indentation
  349. .STO ^IND=`10~
  350. ~ ---------------------------------------
  351. .PUSH `~            ;To push something on the stack
  352. .LET ^CSP=^CSP+1~
  353. ^CSP`96 .STO ^CS`91=`10~
  354. ~ ---------------------------------------
  355. .POPL~                ;To output label from stack
  356. .POP~
  357. ^CSI`96 ..LLZ`91:  ~
  358. ~ ---------------------------------------
  359. .POPJ~                ;To output jump to label from stack
  360. .POP~
  361. ^CSI`96 .. JMP LLZ`91~
  362. ~ ---------------------------------------
  363. .TOSJ~                ;To output jump to label on stack top
  364. .TOS~
  365. ^CSI`96 .. JMP LLZ`91~
  366. ~ ---------------------------------------
  367. .POP~
  368. ^CSP`96 .IF `91<1 SKIP 3~
  369. ^CS`91`86 .STO ^CSI=`81~
  370. .LET ^CSP=^CSP-1~
  371. `F9~
  372. .STO ^CSI=*~
  373. `FE~
  374. ~ ---------------------------------------
  375. .TOS~
  376. ^CSP`96 .IF `91<1 SKIP 2~
  377. ^CS`91`86 .STO ^CSI=`81~
  378. `F9~
  379. .STO ^CSI=*~
  380. ~ ---------------------------------------
  381. .JCT `,`~            ;To output jump condition true
  382. .STO ^TMP=~            ;    set string to null
  383. `10`37     ~            ;    scan and break on space or tab
  384. .CAT ^TMP,`30~            ;    save non space or tab characters
  385. `F8~                ;    end of loop
  386. ^TMP`16 `11`16~            ;    retrieve compressed condition string
  387. .. `11 LLZ`20~            ;    get jump inst. from table and output
  388. ~ ---------------------------------------
  389. .JCF `,`~            ;To output jump on condition false
  390. .STO ^TMP=~            ;    set string to null
  391. `10`37     ~            ;    scan and break on space or tab
  392. .CAT ^TMP,`30~            ;    save non space or tab characters
  393. `F8~                ;    end of loop
  394. ^TMP`16 -`11`16~        ;    retrieve compressed condition string
  395. .. `11 LLZ`20~            ;    get jump inst. from table and output
  396. ~ ---------------------------------------
  397. .DUMP STACK~
  398. ^DBG`56 .IF `51=T SKIP 1~
  399. `F9~
  400. .LET ^CNT=^CSP~
  401. ^CSP`16 `11`F7~
  402. ^CNT`26 ^CS`21`36~
  403. ^CS`21    "`31"`F14~
  404. .LET ^CNT=^CNT-1~
  405. `F8~
  406. ^LEV`46~
  407. ^LEV    =`41`F14~
  408. ~ ---------------------------------------
  409. .DEBUG~
  410. .STO ^DBG=T~
  411. ~ ---------------------------------------
  412. .UNBUG~
  413. .STO ^DBG=F~
  414. ~ ---------------------------------------
  415. ...`~                ;To output comment line to ASM file
  416. ;;            `10`F13~
  417. ~ ---------------------------------------
  418. ..` ` `~            ;To output line to ASM file
  419. `10    `20    `30`F13~
  420. ~ ---------------------------------------
  421. .SERR `~
  422. .ERR "`10" NOT ALLOWED HERE~
  423. ~ ---------------------------------------
  424. .ERR `~                ;To output error messages
  425. >>> ERROR <<< `10`26~
  426. `20`F13~            ;    to ASM file
  427. `20`F14~            ;    to listing file
  428. `20`F15~            ;    to console
  429. .LET ^ERR=^ERR+1~
  430. ~ ---------------------------------------
  431. .CHECK `~            ;To check top of stack for stmt allowed
  432. .TOS~
  433. ^CSI`26 ^^`21`26~
  434. .IF `21=SOK SKIP 1~
  435. .SERR `10~
  436. ~ ---------------------------------------
  437. .CAT `,`~
  438. `11`20`26 `F3~
  439. ~
  440. .STO `=`~
  441. `F3~
  442. ~
  443. .LET `=`~
  444. `24`26 `F3~
  445. ~
  446. .SKIP `~
  447. `F4~
  448. ~
  449. .IF `=` SKIP `~
  450. `F50~
  451. ~
  452. .IF `-=` SKIP `~
  453. `F51~
  454. ~
  455. .IF `<` SKIP `~
  456. `F6-~
  457. ~
  458. .IF `==` SKIP `~
  459. `F60~
  460. ~
  461. .IF `<>` SKIP `~
  462. `F61~
  463. ~
  464. .IF `>` SKIP `~
  465. `F6+~
  466. ~~ ------------ END OF MACROS ------------------- END OF MACROS ------------
  467. .LET ^ERR=0~
  468. .LET ^LEV=0~        CONTROL STRUCTURE LEVEL
  469. .STO ^IND=~        EMPTY INDENTATION STRING
  470. .LET ^CSP=0~        EMPTY STACK
  471. .STO ^CS0=*~        EMPTY STACK ENTRY
  472. .STO ^DBG=F~        DEBUG OFF
  473. .STO ^^I=SOK~        STATEMENT OK IF "I" IS ON STACK
  474. .STO ^^K=SOK~
  475. .STO ^^L=SOK~
  476. .STO ^^O=SOK~
  477. .STO ^^R=SOK~
  478. .STO ^^W=SOK~
  479. .STO ^^Y=SOK~
  480. .STO ^^*=SOK~
  481. .STO ^BRKL=LOOP~    BREAK OK FOR LOOP, OR WHILE
  482. .STO ^BRKR=LOOP~    BREAK OK FOR REPEAT
  483. .STO CARRY=JC~
  484. .STO NOCARRY=JNC~
  485. .STO PLUS=JP~
  486. .STO MINUS=JM~
  487. .STO ZERO=JZ~
  488. .STO NOTZERO=JNZ~
  489. .STO EVEN=JPE~
  490. .STO ODD=JPO~
  491. .STO -CARRY=JNC~        CONDITIONAL JUMP LOOK UP TABLE
  492. .STO -NOCARRY=JC~
  493. .STO -PLUS=JM~
  494. .STO -MINUS=JP~
  495. .STO -ZERO=JNZ~
  496. .STO -NOTZERO=JZ~
  497. .STO -EVEN=JPO~
  498. .STO -ODD=JPE~
  499.