home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / EXTRA-ST / CPM-80-E / CPM-0.2 / CPM-0 / cpm-0.2 / z80-sources / mlb / mylib.old < prev    next >
Encoding:
Text File  |  1994-06-06  |  14.6 KB  |  621 lines

  1.         .xlist            ;
  2.  
  3. ;************************************************************************
  4. ;*                                    *
  5. ;*        Z80-Library by Michael Bischoff                *
  6. ;*        Stand: 18.05.1986                    *
  7. ;*                                    *
  8. ;************************************************************************
  9.  
  10. ;************************************************************************
  11. ;*                                    *
  12. ;*        Systemkonstanten                    *
  13. ;*                                    *
  14. ;************************************************************************
  15.  
  16.         .z80            ; Zilog CPU
  17.         if1            ;
  18.           .printx $ MYLIB.MLB 18.05.1986 included $
  19.         endif            ;
  20.  
  21. true        equ 1            ;
  22. false        equ 0            ;
  23.  
  24. reg_b        equ 8            ; define registers
  25. reg_c        equ 8            ;
  26. reg_d        equ 8            ;
  27. reg_e        equ 8            ;
  28. reg_h        equ 8            ;
  29. reg_l        equ 8            ;
  30. reg_a        equ 8            ;
  31. reg_m        equ 8            ; m := (hl) (for 8080 fans)
  32.  
  33.         .8080            ;
  34. dreg_bc        equ lxi b        ; ld bc,...
  35. dreg_de        equ lxi d        ; ld de,...
  36. dreg_hl        equ lxi h        ; ld hl,...
  37.         .z80            ;
  38.  
  39.         ifndef biosio        ;
  40. biosio          equ false        ;
  41.         endif            ;
  42.         ifndef files        ;
  43. files          equ 0            ; no files!
  44.         endif            ;
  45.  
  46. deffcb        equ 005ch        ; Default FCB Adresse
  47. deffcb2        equ 006ch        ; Default FCB Adresse 2
  48. defdma        equ 0080h        ; Default DMA Adresse
  49. ccpsize        equ 806h        ;
  50.  
  51. ctrl_c        equ 'C'-'@'        ; Einige ASCII-Steuerzeichen
  52. bell        equ 'G'-'@'        ;
  53. bs        equ 'H'-'@'        ;
  54. tab        equ 'I'-'@'        ;
  55. lf        equ 'J'-'@'        ;
  56. cr        equ 'M'-'@'        ;
  57. ctrl_z        equ 'Z'-'@'        ;
  58. esc        equ '['-'@'        ;
  59.  
  60. ;************************************************************************
  61. ;*                                    *
  62. ;*        Hilfsmacros                        *
  63. ;*                                    *
  64. ;************************************************************************
  65.  
  66. save        macro            ; rettet Register auf den Stack
  67.           push bc        ;
  68.           push de        ;
  69.           push hl        ;
  70.           push ix        ;
  71.           push iy        ;
  72.         endm            ;
  73.  
  74. restore        macro            ; rettet Register vom Stack
  75.           pop iy        ;
  76.           pop ix        ;
  77.           pop hl        ;
  78.           pop de        ;
  79.           pop bc        ;
  80.         endm            ;
  81.  
  82.  
  83. index        macro table        ; HL:=table + A
  84.           ld hl,table        ;
  85.           call _adda##        ;
  86.         endm            ;
  87.  
  88.  
  89. ld_a        macro dest,val0,val1,val2,val3
  90.           local weiter,lab0,lab1,lab2
  91.  
  92.           or a            ;
  93.           jr z,lab0        ;
  94.           ifnb <val2>        ;
  95.             cp 1        ;
  96.             jr z,lab1        ;
  97.             ifnb <val3>        ;
  98.               cp 2        ;
  99.               jr z,lab2        ;
  100.               ld dest,val3    ;
  101.               jr weiter        ;
  102.             endif        ;
  103. lab2:            ld dest,val2    ;
  104.             jr weiter        ;
  105.           endif            ;
  106. lab1:          ld dest,val1        ;
  107.           jr weiter        ;
  108. lab0:          ld dest,val0        ;
  109. weiter:                    ;
  110.         endm            ;
  111.  
  112.  
  113.  
  114. dlb        macro label        ; "Define Label Byte"
  115. label          equ $-1        ;
  116.         endm            ;
  117.  
  118. dlw        macro label        ; "Define Label Word"
  119. label          equ $-2        ;
  120.         endm            ;
  121.  
  122. ldop        macro reg,instr        ; load register with opcode
  123.           ifdef reg_®    ;
  124.             .8080        ;
  125.             db (mvi reg)    ; ld hl,....
  126.             .z80        ;
  127.           else            ;
  128.             db dreg_®    ;
  129.           endif            ;
  130.           instr            ;
  131.         endm            ;
  132.  
  133. incb        macro address,maxval    ; increment byte
  134.           local weiter        ;
  135.           ifnb <address>    ;
  136.             ld a,address    ;
  137.           endif            ;
  138.           inc a            ;
  139.           ifnb <maxval>        ;
  140.             cp maxval        ;
  141.             jr c,weiter        ;
  142.             xor a        ;
  143. weiter:          endif            ;
  144.           ifnb <address>    ;
  145.             ld address,a    ; then put it there
  146.           endif            ;
  147.         endm            ;
  148.  
  149. incw        macro address,maxval    ; increment word
  150.           local weiter        ;
  151.           ld hl,(address)    ;
  152.           inc hl        ;
  153.           ifnb <maxval>        ; maximum value defined?
  154.             push de        ;
  155.             ld de,maxval    ;
  156.             cmp16        ;
  157.             jr c,weiter        ;
  158.             ld hl,0        ;
  159. weiter:            pop de        ;
  160.           endif            ;
  161.           ld (address),hl    ; if carry is set, we had some overflow
  162.         endm            ;
  163.  
  164. fill        macro length,byte    ; f}llt einen Speicherbereich mit
  165.           rept length        ; konstantem Wert voll
  166.             db byte        ;
  167.           endm            ;
  168.         endm            ;
  169.  
  170. cmp16        macro            ; Vergleich hl-de
  171.           local weiter        ;
  172.           ld a,h        ;
  173.           sub d            ;
  174.           jr nz,weiter        ;
  175.           ld a,l        ;
  176.           sub e            ;
  177. weiter:                    ;
  178.         endm            ;
  179.  
  180. ;************************************************************************
  181. ;*                                    *
  182. ;*        COMPARE length,text1,text2                *
  183. ;*        vergleicht length Bytes                    *
  184. ;*        text1 gegen text2                    *
  185. ;*                                    *
  186. ;************************************************************************
  187.  
  188. compare        macro length,text1,text2;
  189.           ifnb <text2>        ;
  190.             ld hl,text2        ;
  191.           endif            ;
  192.           ifnb <text1>        ;
  193.             ld de,text1        ;
  194.           endif            ;
  195.           ifnb <length>        ;
  196.             ld b,length        ;
  197.           endif            ;
  198.  
  199.           call _cpmem##        ;
  200.         endm            ;
  201.  
  202. ;************************************************************************
  203. ;*                                    *
  204. ;*        MOVE length,text1,text2                    *
  205. ;*        kopiert length Bytes                    *
  206. ;*        ab text1 nach text2                    *
  207. ;*                                    *
  208. ;************************************************************************
  209.  
  210. move        macro length,text1,text2;
  211.           ifnb <text2>        ;
  212.             ld hl,text2        ;
  213.           endif            ;
  214.           ifnb <text1>        ;
  215.             ld de,text1        ;
  216.           endif            ;
  217.           ifnb <length>        ;
  218.             ld bc,length    ;
  219.           endif            ;
  220.           ldir            ;
  221.         endm            ;
  222.  
  223. ;************************************************************************
  224. ;*                                    *
  225. ;*        EXCHANGE length,text1,text2                *
  226. ;*        vertauscht length Bytes                    *
  227. ;*        text1 mit text2                        *
  228. ;*                                    *
  229. ;************************************************************************
  230.  
  231. exchange    macro length,text1,text2;
  232.           ifnb <text2>        ;
  233.             ld hl,text2        ;
  234.           endif            ;
  235.           ifnb <text1>        ;
  236.             ld de,text1        ;
  237.           endif            ;
  238.           ifnb <length>        ;
  239.             ld b,length        ;
  240.           endif            ;
  241.  
  242.           call _exmem##        ;
  243.         endm            ;
  244.  
  245. ld_de_von_hl    macro            ;
  246.           ld e,(hl)        ;
  247.           inc hl        ;
  248.           ld d,(hl)        ;
  249.           inc hl        ;
  250.         endm            ;
  251.  
  252. ld_de_nach_hl    macro            ;
  253.           ld (hl),e        ;
  254.           inc hl        ;
  255.           ld (hl),d        ;
  256.           inc hl        ;
  257.         endm            ;
  258.  
  259. toupper        macro what        ;
  260.           ifnb <what>        ;
  261.             res 5,what        ; lower case => upper case
  262.           else            ;
  263.             res 5,a        ;
  264.           endif            ;
  265.         endm            ;
  266.  
  267. tolower        macro what        ;
  268.           ifnb <what>        ;
  269.             set 5,what        ; lower case => upper case
  270.           else            ;
  271.             set 5,a        ;
  272.           endif            ;
  273.         endm            ;
  274.  
  275. ;************************************************************************
  276. ;*                                    *
  277. ;*        BIOS function,argument                    *
  278. ;*        ruft BIOS-Funktion auf                    *
  279. ;*                                    *
  280. ;************************************************************************
  281.  
  282. bios        macro functn,value    ; bios-call durchfuehren
  283.  
  284. bios_wboot        equ 003h        ;
  285. bios_const        equ 006h        ;
  286. bios_conin        equ 009h        ;
  287. bios_conout        equ 00ch        ;
  288. bios_list        equ 00fh        ;
  289. bios_punch        equ 012h        ;
  290. bios_reader        equ 015h        ;
  291. bios_home        equ 018h        ;
  292. bios_seldsk        equ 01bh        ;
  293. bios_settrk        equ 11eh        ; 16 bit argument!
  294. bios_setsec        equ 121h        ;     "
  295. bios_setdma        equ 124h        ;     "
  296. bios_read        equ 027h        ;
  297. bios_write        equ 02ah        ;
  298. bios_listst        equ 02dh        ;
  299. bios_sectran        equ 130h        ; 16 bit argument!
  300.  
  301.           ifnb <value>        ;
  302.             if bios_&functn gt 0ffh
  303.               ld bc,value    ;
  304.             else        ;
  305.               ld c,value    ;
  306.             endif        ;
  307.           endif            ;
  308.  
  309.           ld l,bios_&functn AND 0ffh
  310.           call _bioscall##    ;
  311.         endm            ;
  312.  
  313. ;************************************************************************
  314. ;*                                    *
  315. ;*        BDOS function,argument                    *
  316. ;*        ruft BDOS-Funktion auf.                    *
  317. ;*        Ist argument nicht angegeben,                *
  318. ;*        wird DE gelassen.                    *
  319. ;*                                    *
  320. ;************************************************************************
  321.  
  322. bdos        macro callnr,arg    ;
  323. system_reset      equ 000h        ;
  324. console_in      equ 001h        ;
  325. console_out      equ 002h        ;
  326. reader_in      equ 003h        ;
  327. punch_out      equ 004h        ;
  328. list_out      equ 005h        ;
  329. direct_conio      equ 006h        ;
  330. get_iobyte      equ 007h        ;
  331. set_iobyte      equ 008h        ;
  332. print_string      equ 109h        ; 2 Byte Argument
  333. inline          equ 10ah        ;    "
  334. get_con_status      equ 00bh        ;
  335. return_version      equ 00ch        ;
  336. disk_reset      equ 00dh        ;
  337. select_disk      equ 00eh        ;
  338. open_file      equ 10fh        ; 2 Byte Argument
  339. close_file      equ 110h        ;
  340. srch_for_first      equ 111h        ;
  341. srch_for_next      equ 012h        ;
  342. delete_file      equ 113h        ;
  343. read_seq      equ 114h        ;
  344. write_seq      equ 115h        ;
  345. make_file      equ 116h        ;
  346. rename_file      equ 117h        ;
  347. get_login_vec      equ 018h        ;
  348. get_cur_disk      equ 019h        ;
  349. set_dma_addr      equ 11ah        ;
  350. get_alloc_addr      equ 01bh        ;
  351. set_ro_disk      equ 01ch        ;
  352. get_ro_vector      equ 01dh        ;
  353. set_file_attr      equ 11eh        ;
  354. get_dpb_addr      equ 01fh        ;
  355. set_get_user      equ 020h        ;
  356. read_random      equ 121h        ;
  357. write_random      equ 122h        ;
  358. comp_file_size      equ 123h        ;
  359. set_rand_rec      equ 124h        ;
  360. reset_drive      equ 125h        ;
  361. wr_rand_with_0      equ 128h        ;
  362.  
  363.           ifnb <arg>        ;
  364.             if callnr gt 0ffh    ; must be defined
  365.               ld de,arg        ; 2 Byte argument
  366.             else        ;
  367.               ld e,arg        ; 1 Byte argument
  368.             endif        ;
  369.           endif            ;
  370.  
  371.           ifnb <callnr>        ;
  372.             ld c,callnr AND 0ffh;
  373.           endif            ;
  374.           call 5        ;
  375.         endm            ;
  376.  
  377. ;************************************************************************
  378. ;*                                    *
  379. ;*        INIT (stacksize)                    *
  380. ;*        pr}ft, ob Cp/M 2.2 Betriebssystem aktiv,        *
  381. ;*        ob Z80-CPU, setzt Stack auf (default: 100 Byte)        *
  382. ;*                                    *
  383. ;************************************************************************
  384.  
  385. init        macro stacksiz        ;
  386.           call _version##    ; richtiges Cp/M release und z80?
  387.  
  388.           dseg            ;
  389.           ifnb <stacksiz>    ;
  390.             ds stacksiz        ;
  391.           else            ;
  392.             ds 100        ;
  393.           endif            ;
  394. ccpstack:      dw 0            ;
  395.           cseg            ;
  396.  
  397.           ld (ccpstack),sp    ; vielleicht braucht er ihn noch?
  398.           ld sp,ccpstack    ;
  399.         endm            ;
  400.  
  401. ;************************************************************************
  402. ;*                                    *
  403. ;*        RETURN (returnvalue)                    *
  404. ;*        verl{~t Programm und kehrt ins CCP zur}ck.        *
  405. ;*                                    *
  406. ;************************************************************************
  407.  
  408. return        macro retval        ;
  409.           if files        ;
  410.             call _clsall##    ;
  411.           endif            ;
  412.           ld sp,(ccpstack)    ;
  413.           ifnb <retval>        ;
  414.             ld a,retval        ;
  415.           endif            ;
  416.           ret            ;
  417.         endm            ;
  418.  
  419. ;************************************************************************
  420. ;*                                    *
  421. ;*        EXIT condition,message                    *
  422. ;*        Wenn condition erf}llt oder blank            *
  423. ;*        wird message ausgedruckt, Dateien            *
  424. ;*        werden geschlossen und Programm    verlassen.        *
  425. ;*                                    *
  426. ;************************************************************************
  427.  
  428. exit        macro condition,text    ;
  429.           local message        ;
  430.  
  431.           dseg            ;
  432.           ifnb <text>        ;
  433. message:        db text,0        ;
  434.           endif            ;
  435.           cseg            ;
  436.  
  437.           ifnb <condition>    ;
  438.             ifnb <text>        ;
  439.               push hl        ;
  440.               ld hl,message    ;
  441.               jp condition,_exit;
  442.               pop hl        ;
  443.             else        ;
  444.               jp condition,_exit0;do not kill $$$.SUB
  445.             endif        ;
  446.           else            ;
  447.             ifnb <text>        ;
  448.               ld hl,message    ;
  449.               jp _exit        ;
  450.             else        ;
  451.               jp _exit0        ;
  452.             endif        ;
  453.           endif            ;
  454.         endm            ;
  455.  
  456. ;************************************************************************
  457. ;*                                    *
  458. ;*        PRINT "message1","message2","message3"            *
  459. ;*        druckt message1,message2,message3            *
  460. ;*        auf stdout aus                        *
  461. ;*        PRINT := use preset HL                    *
  462. ;*                                    *
  463. ;************************************************************************
  464.  
  465. print        macro text        ; druckt Text auf stdout aus
  466.           local weiter,zeile    ;
  467.  
  468.           ifnb <text>        ;
  469.             dseg        ;
  470. zeile:            db text,0        ;
  471.             cseg        ;
  472.             ld hl,zeile        ;
  473.           endif            ;
  474.           call _prmes##        ;
  475.         endm            ;
  476.  
  477. ;************************************************************************
  478. ;*                                    *
  479. ;*        AWAIT char1,char2,char3,char4                *
  480. ;*        wartet, bis eines der angegebenen            *
  481. ;*        Zeichen oder Ctrl-C an der Console            *
  482. ;*        eingegeben wird. Bei Ctrl-C Kaltstart            *
  483. ;*                                    *
  484. ;************************************************************************
  485.  
  486. await        macro c1,c2,c3,c4    ; erwarte eines von maximal
  487.           local weiter,getch,flush; 4 Zeichen von der Console
  488. flush:          call stdsts        ;
  489.           jr z,getch        ;
  490.           call stdin        ;
  491.           jr flush        ;
  492.  
  493. getch:          call stdin        ; Console Input
  494.  
  495.           ifnb <c1>        ;
  496.             cp c1        ; erstes Zeichen?
  497.             jr z,weiter        ;
  498.           endif            ;
  499.           ifnb <c2>        ;
  500.             cp c2        ;
  501.             jr z,weiter        ;
  502.           endif            ;
  503.           ifnb <c3>        ;
  504.             cp c3        ;
  505.             jr z,weiter        ;
  506.           endif            ;
  507.           ifnb <c4>        ;
  508.             cp c4        ;
  509.             jr z,weiter        ;
  510.           endif            ;
  511.  
  512.           cp ctrl_c        ;
  513.           jr nz,getch        ;
  514.           exit ,"^C"        ;
  515. weiter:                    ;
  516.         endm            ;
  517.  
  518. ;************************************************************************
  519. ;*                                    *
  520. ;*        PRINTF [iocvector], string, argumente...        *
  521. ;*        druckt String und Zahlen formatiert aus.        *
  522. ;*        Wenn iovector nicht angegeben wird, entf{llt        *
  523. ;*        Neudefinition des Vektors. Ist iovector = 0, so wird    *
  524. ;*        in Abh{ngigkeit von BIOSIO die Standardausgaberoutine     *
  525. ;*        benutzt, bei anderen Werten iowr_(iovector).        *
  526. ;*        Werden nicht gen}gend Argumente angegeben, so werden    *
  527. ;*        weitere vom Stack geholt (first pushed = last used)    *
  528. ;*                                    *
  529. ;************************************************************************
  530.  
  531. printf        macro iovec,string,arg1,arg2,arg3
  532.           local strptr        ;
  533.           dseg            ;
  534. strptr:          db string,0        ;
  535.           cseg            ;
  536.  
  537.           ifnb <iovec>        ;
  538.             ld iy,iovec        ;
  539.           endif            ;
  540.  
  541.           ifnb <arg1>        ;
  542.             ifnb <arg2>        ;
  543.               ifnb <arg3>    ;
  544.             ld hl,arg3    ; arg3 specified
  545.             push hl        ;
  546.               endif        ;
  547.               ld hl,arg2    ; arg2 specified
  548.               push hl        ;
  549.             endif        ;
  550.             ld hl,arg1        ; arg1 specified
  551.             push hl        ;
  552.           endif            ;
  553.           ld hl,strptr        ;
  554.           call _printf##    ; call output routine
  555.         endm            ;
  556.  
  557. ;************************************************************************
  558. ;*                                    *
  559. ;*        SCANF iovector,string                    *
  560. ;*        pr}ft String und liest Werte ein            *
  561. ;*                                    *
  562. ;************************************************************************
  563.  
  564. scanf        macro iovec,string    ; we return everything in HL
  565.           local strptr        ;
  566.           dseg            ;
  567. strptr:          db string,0        ;
  568.           cseg            ;
  569.  
  570.           ifnb <iovec>        ; special input routine specified?
  571.             ld iy,iovec        ; then use user defined input
  572.           endif            ; else assume user has loaded iy before
  573.  
  574.           ld hl,strptr        ;
  575.           call _scanf##        ;
  576.         endm            ;
  577.  
  578. ;************************************************************************
  579. ;*                                    *
  580. ;*        Standard und Error I/O-Vektoren                *
  581. ;*                                    *
  582. ;************************************************************************
  583.  
  584.         entry _exit, _exit0    ;
  585.         entry stdin, stdout, stdsts
  586.         entry errin, errout, errsts
  587.  
  588. _exit:        ld de,(errout+1)    ; error-vector
  589.         ld (stdout+1),de    ; is stdout
  590.         call _prmes##        ;
  591.         ifndef no_delsub    ;
  592.           bdos delete_file,subfcb
  593.           dseg            ;
  594. subfcb:          db 1,'$$$     SUB'    ; do not continue JOB-Control
  595.           fill 21,0        ;
  596.           cseg            ;
  597.         endif            ;
  598.  
  599. _exit0:        if files        ;
  600.           call _clsal##        ;
  601.         endif            ;
  602.         if biosio        ;
  603.           bios wboot        ;
  604. stdin:          jp _biosin##        ;
  605. stdout:          jp _biosout##        ;
  606. stdsts:          jp _biossts##        ;
  607. errin:          jp _biosin##        ;
  608. errout:          jp _biosout##        ;
  609. errsts:          jp _biossts##        ;
  610.         else            ;
  611.           bdos system_reset    ;
  612. stdin:          jp _bdosin##        ;
  613. stdout:          jp _bdosout##        ;
  614. stdsts:          jp _bdossts##        ;
  615. errin:          jp _bdosin##        ;
  616. errout:          jp _bdosout##        ;
  617. errsts:          jp _bdossts##        ;
  618.         endif            ;
  619.  
  620.         .list            ;
  621.