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 / CPM / TURBODSG / RS.MAC < prev    next >
Text File  |  2000-06-30  |  8KB  |  454 lines

  1. ; RS version 1.40 (c) 1986 ESKAY Software Service
  2. ;
  3. ; N O T E
  4. ;
  5. ; RS is a variant of RELED with a certain specific purpose.
  6. ; ESKAY Software Service does not support or encourage
  7. ; copyright infringements and RS should only be used
  8. ; in cases of extreme emergency, or after clearing its use
  9. ; with the copyright holder!!!!!
  10. ;
  11. .z80
  12. ;
  13. cr    equ    0dh
  14. lf    equ    0ah
  15. dfcb    equ    5ch
  16. dbuf    equ    80h
  17. ;
  18. ; syslib externals
  19. ;
  20. .request syslib
  21.     extrn    print,phl4hc,phlfdc,pfn2,crlf,pstr
  22.     extrn    bbline,condin,cout,eval10,compb
  23.     extrn    f$open,f$read,f$write,f$close,initfcb
  24.     extrn    codend
  25. ;
  26. ; other externals
  27. ;
  28.     extrn    getbit        ;get one bit from bit field
  29.     extrn    putbit        ;put one bit into bit field
  30.     extrn    wildex
  31. ;
  32.     cseg
  33. ;
  34. begin:    ld    sp,stack
  35.     call    print
  36.     db    cr,lf,lf
  37.     db    9,9,' ----------------------------------------',cr,lf
  38.     db    9,9,'|              RS version 1.4            |',cr,lf
  39.     db    9,9,'|               RESERIALIZER             |',cr,lf
  40.     db    9,9,'|       USE THIS PROGRAM RESPONSIBLY     |',cr,lf
  41.     db    9,9,'| (c) infrigement is YOUR responsibility |',cr,lf
  42.     db    9,9,' ----------------------------------------',cr,lf,lf,0
  43.     ld    a,(dfcb+1)
  44.     cp    ' '
  45.     jp    z,nofile
  46.     ld    hl,dfcb+9
  47.     ld    (hl),'R'
  48.     inc    hl
  49.     ld    (hl),'E'
  50.     inc    hl
  51.     ld    (hl),'L'
  52. getor:    call    print
  53.     db    cr,lf
  54.     db    'Enter new value for ?ORIG? in DECIMAL : ',0
  55.     call    bbline
  56.     or    a
  57.     jr    z,getor
  58.     call    eval10
  59.     ld    (newo),de
  60. getun:    call    print
  61.     db    cr,lf
  62.     db    'Enter new value for ?UNIT? in DECIMAL : ',0
  63.     call    bbline
  64.     or    a
  65.     jr    z,getun
  66.     call    eval10
  67.     ld    (newu),de
  68.     call    codend        ;get buffer addr
  69.     ld    (fnbuf),hl
  70.     ld    de,1000h    ;handle up to 256 files
  71.     add    hl,de
  72.     ld    (buffer),hl
  73.     push    hl
  74.     pop    ix        ;ix is buffer ptr
  75.     ld    de,dfcb
  76.     ld    hl,(fnbuf)
  77.     call    wildex
  78.     jp    z,nofile
  79.     call    print
  80.     db    cr,lf
  81.     db    'Matching files: ',0
  82.     call    phlfdc
  83.     inc    hl
  84.     ld    (files),hl
  85.     call    print
  86.     db    cr,lf,lf,0
  87. nextf:    ld    hl,(files)
  88.     dec    hl
  89.     ld    (files),hl
  90.     ld    a,h
  91.     or    l
  92.     jp    z,finish
  93.     xor    a
  94.     ld    (chgd),a
  95.     ld    (bithi),a
  96.     ld    h,a
  97.     ld    l,a
  98.     ld    (bitml),hl
  99.     ld    de,dfcb
  100.     ld    hl,(fnbuf)
  101.     ld    bc,16
  102.     ldir
  103.     ld    (fnbuf),hl
  104.     ld    de,dfcb        ;point to file name
  105.     call    initfcb
  106.     push    de
  107.     inc    de
  108.     call    print
  109.     db    cr,lf
  110.     db    'Now processing ',0
  111.     call    pfn2
  112.     pop    de
  113.     call    f$open        ;open it
  114.     jp    nz,notfnd    ;not there!
  115.     ld    hl,(buffer)    ;hl=buffer start
  116. lodlp:    call    f$read        ;read a sector
  117.     jr    nz,allrd    ;done?
  118.     ld    bc,dbuf        ;bc=buffer ptr
  119. movlp:    ld    a,(bc)
  120.     ld    (hl),a
  121.     inc    hl
  122.     inc    c
  123.     jr    nz,movlp
  124.     jr    lodlp
  125. ;
  126. allrd:    call    f$close
  127.     call    print
  128.     db    ', size ',0
  129.     ld    (eofptr),hl
  130.     push    hl
  131.     ld    hl,(buffer)
  132.     ex    de,hl
  133.     pop    hl
  134.     or    a
  135.     sbc    hl,de
  136.     call    phl4hc
  137.     call    print
  138.     db    'H bytes.',cr,lf,lf,0
  139. ;
  140. ; this is the main evaluation loop
  141. ; come here for every new item
  142. ;
  143. eval:    ld    e,0
  144.     call    get1        ;get 1 bit
  145.     or    a
  146.     jr    nz,not8
  147.     call    get8        ;get next 8 bits (and swallow them)
  148.     jr    eval
  149. ;
  150. ; get next 2 bits and interpret
  151. ;
  152. not8:    call    get2
  153.     or    a        ;see if special item
  154.     jr    z,spec
  155.     call    get8        ;swallow 16 bits
  156.     call    get8
  157.     jr    eval
  158. ;
  159. ; evaluate special item
  160. ;
  161. spec:    call    get4        ;get 4-bit field
  162. ;
  163. ; following items followed by name field
  164. ;
  165.     or    a        ;entry symbol
  166.     jp    z,skipn        ;skip name
  167.     cp    1        ;select common
  168.     jp    z,skipn        ;skip name
  169.     cp    2
  170.     jp    z,name        ;display module name
  171.     cp    3        ;request item
  172.     jp    z,skipn
  173. ;
  174. ; following items followed by value and name field
  175. ;
  176.     cp    5        ;common size
  177.     jp    z,skpvn        ;skip val/name
  178.     cp    6        ;chain external
  179.     jp    z,skpvn        ;skip it
  180.     cp    7        ;define entry point
  181.     jp    z,ckntry    ;check if we want something
  182. ;
  183.     cp    15        ;end of file?
  184.     jp    z,eof
  185.     cp    14        ;end module
  186.     jp    z,endm
  187. ;
  188. ; all others followed by value field
  189. ; let's swallow it
  190. ;
  191.     call    skpval
  192.     jr    eval
  193. ;
  194. ; end of module - skip to next byte boundary
  195. ;
  196. endm:    ld    a,9        ; a tab
  197.     call    cout
  198.     ld    a,(rsmod)
  199.     or    a        ; rsed this?
  200.     ld    hl,rsedy
  201.     jr    nz,.em..
  202.     ld    hl,rsedn
  203. .em..:    call    pstr
  204.     call    crlf
  205.     call    skpval
  206.     ld    hl,(bitml)
  207.     ld    de,7
  208.     add    hl,de
  209.     jr    nc,..em
  210.     ld    a,(bithi)
  211.     inc    a
  212.     ld    (bithi),a
  213. ..em:    ld    a,l
  214.     and    0f8h
  215.     ld    l,a
  216.     ld    (bitml),hl
  217.     jp    eval
  218. ;
  219. eof:    call    print
  220.     db    cr,lf
  221.     db    'end of file',cr,lf,0
  222.     ld    a,(chgd)
  223.     or    a
  224.     jr    nz,wrback
  225.     call    print
  226.     db    'Unchanged - not saved',cr,lf,0
  227.     jp    nextf
  228. ;
  229. wrback:    ld    de,dfcb
  230.     call    initfcb
  231.     call    f$open
  232.     jr    z,opnok
  233.     call    print
  234.     db    cr,lf
  235.     db    '*** cannot open file ***',cr,lf,0
  236.     jp    nextf
  237. ;
  238. opnok:    ld    hl,(buffer)    ;get start of buffer
  239. svlp:    ld    bc,dbuf
  240. ..sav:    ld    a,(hl)
  241.     ld    (bc),a
  242.     inc    hl
  243.     inc    c
  244.     jr    nz,..sav
  245.     ld    de,dfcb
  246.     call    f$write
  247.     jr    nz,wrerr
  248.     ld    de,(eofptr)
  249.     push    hl
  250.     sbc    hl,de
  251.     pop    hl
  252.     jr    nz,svlp
  253.     ld    de,dfcb
  254.     call    f$close
  255.     inc    de
  256.     call    pfn2
  257.     call    print
  258.     db    ' written back, all modules serialized ',0
  259.     ld    hl,(newo)
  260.     call    phlfdc
  261.     ld    a,'/'
  262.     call    cout
  263.     ld    hl,(newu)
  264.     call    phlfdc
  265.     call    crlf
  266.     jp    nextf
  267. ;
  268. wrerr:    call    print
  269.     db    cr,lf
  270.     db    '*** write error - aborted ***',cr,lf,0
  271.     jp    nextf
  272. ;
  273. ckntry:    call    get2        ;get type
  274.     or    a        ;absolute?
  275.     jr    z,abs
  276.     call    get8
  277.     call    get8
  278.     jp    skipn
  279. ;
  280. abs:    ld    hl,(bitml)
  281.     ld    (savml),hl
  282.     ld    a,(bithi)
  283.     ld    (savhi),a
  284.     call    get8        ;get first half
  285.     call    get8        ;get second half
  286.     call    dspnam
  287.     ld    hl,nme
  288.     ld    de,orig
  289.     ld    b,7
  290.     call    compb
  291.     ld    de,(newo)
  292.     jr    z,chg
  293.     ld    de,unit
  294.     call    compb
  295.     jp    nz,eval
  296.     ld    de,(newu)
  297. chg:    ld    a,e        ;get low byte
  298.     call    put8b        ;stash 8 bits into REL file
  299.     ld    a,d        ;get high byte
  300.     call    put8b
  301.     ld    a,1
  302.     ld    (chgd),a
  303.     jp    eval
  304. ;
  305. put8b:    push    de        ;save word
  306.     ld    e,a        ;save byte
  307.     ld    a,(savhi)
  308.     ld    d,a
  309.     ld    hl,(savml)
  310.     ld    b,8        ;8 bits to process
  311. ..put:    rlc    e        ;put bit in position
  312.     ld    a,e        ;get byte
  313.     and    1        ;isolate bit
  314.     ld    c,a
  315.     call    putbit
  316.     call    incbit        ;point to next bit in file
  317.     djnz    ..put        ;do it 8 times
  318.     ld    a,1
  319.     ld    (rsmod),a    ; set "module reserialized" flag
  320.     ld    (savml),hl
  321.     ld    a,d
  322.     ld    (savhi),a
  323.     pop    de
  324.     ret
  325. ;
  326. name:    xor    a
  327.     ld    (rsmod),a    ; reset flag
  328.     call    dspnam1
  329.     jp    eval
  330. ;
  331. dspnam1:exx
  332.     ld    l,0
  333.     jr    .dsp..
  334. ;
  335. dspnam:    exx
  336.     ld    l,1
  337. .dsp..:    exx
  338.     ld    e,0
  339.     call    get3        ;get name length
  340.     ld    iy,nme
  341.     ld    b,a        ;length into b
  342. namelp:    push    bc
  343.     call    get8        ;get a byte
  344.     exx
  345.     bit    0,l
  346.     exx
  347.     call    z,cout
  348.     ld    (iy+0),a
  349.     inc    iy
  350.     pop    bc
  351.     djnz    namelp
  352.     ld    (iy+0),0
  353.     ret
  354. ;
  355. skpvn:    call    skpval
  356. ;
  357. ; skip a name
  358. ;
  359. skipn:    ld    e,0
  360.     call    get3        ;get name field length
  361.     ld    b,a        ;length into b
  362. skipnl:    push    bc
  363.     call    get8        ;swallow 8 bits
  364.     pop    bc
  365.     djnz    skipnl
  366.     jp    eval
  367. ;
  368. skpval:    ld    e,0
  369.     call    get2
  370.     call    get8
  371. ;
  372. ; the following routines return 1,2,3,4, or 8 bits in A.
  373. ; when calling, E must be zero!
  374. ;
  375. get8:    call    get4
  376.     ld    e,a
  377. get4:    call    get3
  378.     ld    e,a
  379.     jr    get1
  380. ;
  381. ; get next 3 bits into A
  382. ;
  383. get3:    call    get2        ;get 2 bits
  384.     ld    e,a
  385.     jr    get1
  386. ;
  387. ; get next 2 bits into A
  388. ;
  389. get2:    call    get1
  390.     ld    e,a
  391. get1:    ld    a,(bithi)
  392.     ld    d,a
  393.     ld    hl,(bitml)
  394.     call    getbit
  395.     rlc    e
  396.     or    e
  397.     push    af
  398.     call    incbit
  399.     ld    (bitml),hl
  400.     ld    a,d
  401.     ld    (bithi),a
  402.     pop    af
  403.     ld    e,0        ;make this re-entrant
  404.     ret
  405. ;
  406. incbit:    inc    hl
  407.     ld    a,h
  408.     or    l
  409.     ret    nz
  410.     inc    d
  411.     ret
  412. ;
  413. notfnd:    call    print
  414.     db    'File not found',cr,lf,0
  415.     jp    nextf
  416. ;
  417. finish:    call    print
  418.     db    cr,lf,lf
  419.     db    '*** all done ***',cr,lf,0
  420.     rst    0
  421. ;
  422. nofile:    call    print
  423.     db    'No file specified',cr,lf,lf
  424.     db    'Usage:',cr,lf
  425.     db    '0A}RS FILENAME[.REL]',cr,lf
  426.     db    'program prompts for input',cr,lf
  427.     db    'NOTE: the author cannot assume any liability',cr,lf
  428.     db    'for copyright violation by the user!',cr,lf,lf,0
  429.     rst    0
  430. ;
  431.     dseg
  432. ;
  433. nme:    ds    10
  434. orig:    db    '?ORIG?',0
  435. unit:    db    '?UNIT?',0
  436. rsmod:    db    0
  437. rsedy:    db    ' reserialized.',0
  438. rsedn:    db    ' unserialized.',0
  439. chgd:    db    0
  440. newo:    dw    1111h
  441. newu:    dw    2222h
  442. fnbuf:    dw    0
  443. files:    dw    0
  444. buffer:    dw    0
  445. eofptr:    dw    0
  446. bitml:    dw    0        ;bit address medium+low
  447. bithi:    db    0        ;bit address high
  448. savml:    dw    0
  449. savhi:    db    0
  450.     ds    80
  451. stack    equ    $
  452.     end
  453. d    e,a
  454.