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 / KAYPRO / TOON12.LBR / TOON12.AQM / TOON12.ASM
Assembly Source File  |  2000-06-30  |  13KB  |  531 lines

  1. ;                   TOON12.ASM
  2. ;A screen dump program: puts a watchdog between
  3. ;the conin jmp and CONIN itself, which simply passes
  4. ;along normal chars, but writes the screen to disk
  5. ;when it detects ^_.  The screen is written by
  6. ;bank-switching to video memory through rdvid,
  7. ;which alters the bank switch bit from the system 
  8. ;port to read bank 1 memory (video memory + prom)
  9. ;directly.  If TOON, the carTOON file for screens,
  10. ;already exists, the new screen is added on the end.
  11. ;
  12. ;In version 1.1, the sub-CCP address in high memory
  13. ;where TOON goes is hard coded, but the BDOS jump
  14. ;is altered by TOON to point to TOON's lowest addr.
  15. ;The TOON watchdog's first location is then a jump
  16. ;to the original entry point in the BDOS. Therefore, 
  17. ;load TOON first, and later programs can adjust
  18. ;their use of the TPA using the altered BDOS addr.
  19. ;
  20. ;Version 1.2 adds the deletion of space chars in
  21. ;the 80th column to clean up display on 80 char
  22. ;screens, and other minor changes.
  23. ;                      v1.2
  24. ;(c)June, 1985
  25. ;Mike Yarus * 2231 16th Street * Boulder, CO 80302
  26. ;
  27. ;TOON.ASM, TOON.COM, and TOON.DOC are released into
  28. ;the public domain, and may be used freely for any
  29. ;non-commercial purpose.  They may not be sold or
  30. ;used to enhance the value of another product 
  31. ;without the permission of the author.
  32. ;
  33. ;
  34. bdos    equ     0005h
  35. wmboot    equ    0000h
  36. cr    equ    0Dh
  37. lf    equ    0Ah
  38. eof    equ    1Ah
  39. ;
  40. ;the following equate is for the conin bios addr
  41. ;and the original bdos jump address
  42. ;
  43.             ;a dummy address (= 0000)
  44. dmmy$ad    equ    wmboot    ;to hold a place for real
  45.             ;address written at run time
  46. ;
  47. ;equates for the move into high memory
  48. ;
  49. offs    equ    280h    ;distance below ccp to load
  50. ccp    equ     0E400h    ;bios-1600h=ccp start, std 64k
  51. newstrt    equ    ccp-offs;new start, offs-et below ccp
  52. ;
  53.     org    0100h
  54. ;
  55. ;get the bdos address and store it at bottom of dump
  56. ;
  57.     lhld    0006h    ;load bdos jmp addr
  58.     shld    bds$trgt+1    ;store at new site
  59.     lxi    h,newstrt    ;get bottom of dump
  60.     shld    0006h    ;redirect bdos jmp to dump
  61. ;
  62. ;get the address of the bios
  63. ;
  64.     lhld    0001h    ;load bios + 3
  65.     dcx h 
  66.     dcx h
  67.     dcx h        ;hl -> bios address
  68.     shld    bios    ;store start of bios jumps
  69. ;
  70. ;find the phrase "Warm Boot"
  71. ;
  72.     lxi    d,0004h    ;offset to warm boot address
  73.     dad    d    ;hl points to warmst addr
  74.     call     getwd    ;warmst routine addr -> hl
  75. ;
  76.     mvi    c,'W'    ;search for 'W'
  77.     call    find0    ;begin at warmbt routine
  78. ;
  79.     lxi    d,newmsg;address in hl from find
  80.     call    fill0    ;overwrite "Warm Boot"
  81. ;
  82. ;redirect the conin jump in the bios
  83. ;
  84.     lhld    bios    ;load addr of bios
  85.     lxi    d,000ah    ;offset to conin addr addr
  86.     dad    d    ;addr of conin routine addr
  87.     shld    cinadd    ;store it, must overwrite
  88.     call    getwd    ;conin address into hl
  89.     shld    conin    ;store address of conin routine
  90. ;
  91.     lhld     cinadd    ;addr of conin addr
  92.     lxi    d,dump    ;addr of dump in de
  93.     call    putwd    ;alter conout addr to dump addr
  94. ;
  95. ;write in the calculated address of the conin routine
  96. ;
  97.     lhld     conin        ;load conin addr
  98.     xchg            ;conin addr-> de
  99.     lxi    h,cin$trgt+1    ;addr for call to conin
  100.     call     putwd        ;write addr in de to hl
  101. ;
  102.     jmp     launch0    ;move the business end under ccp
  103. ;
  104. ;fills memory at h with string stored at d, term by $
  105. ;used to fill open memory at fixed, dedicated location
  106. ;
  107. fill0    mvi    c,'$'
  108.     ldax    d    ;get char into a
  109.     cmp    c    ;is the new char the end char?
  110.     rz        ;if so, have done string
  111.     mov    m,a    ;if not, store next char
  112. ;
  113.     inx    d
  114.     inx    h    ;increment both string counters
  115.     jmp    fill0    
  116. ;
  117. ;find the character in c after the address supplied in h
  118. ;returns the address of the char in h
  119. ;
  120. find0    mov    a,m    ;get char in a
  121.     cmp    c    ;is it the target char?
  122.     rz        ;char found, address in h
  123.     inx    h    ;inc address and
  124.     jmp    find0    ;get the next char
  125. ;
  126. ;get word at addr in hl into hl: orig addr + 1 -> de
  127. ;
  128. getwd    mov    a,m    ;get low order byte
  129.     mov    e,a    ;move to e
  130.     inx    h    ;reset for high order byte
  131.     mov    a,m    ;get it in a
  132.     mov    d,a    ;put high order byte in d
  133.     xchg        ;exchange number and address
  134.     ret
  135. ;
  136. ;put word in de to address in hl
  137. ;
  138. putwd    mov    a,e    ;lsb to a
  139.     mov    m,a    ;lsb to address in hl
  140.     inx    h    ;address for msb
  141.     mov    a,d    ;msb to a
  142.     mov    m,a    ;msb to address
  143.     ret
  144. ;
  145. ;the routine to move the code below it to high memory
  146. ;
  147. launch0    lxi    b,endmv-begin+1    ;bytes to move
  148.     lxi    d,begin    ;start addr for move
  149.     lxi    h,newstrt    ;new start after move
  150. ;
  151. launch    ldax    d    ;get a char from lo mem
  152.     mov    m,a    ;put char in high mem
  153.     inx    d    ;increment lo addr
  154.     inx    h    ;increment hi mem addr
  155.     dcx    b    ;decrement # bytes to move
  156. ;
  157.     mov    a,b    ;test if b&c = 0
  158.     ora    c    ;a&c = 0?
  159.     jnz    launch    ;no, get another byte
  160. ;
  161.     ret        ;done, back to cpm
  162. ;
  163. newmsg    db    'Toon = ^_$'
  164. bios    ds    2    ;addr of bios jump table
  165. cinadd    ds    2    ;addr of conout jmp addr
  166. conin    ds    2    ;addr of the conout routine
  167. ;
  168. ;***************** all below is moved *****************
  169. begin    equ     $
  170. ;
  171. distnce    equ    newstrt-begin    ;hi mem addr - lo mem
  172. ;
  173. ;redirect the bdos jmp to its original address
  174. ;
  175. bds$trgt
  176.     jmp    dmmy$ad        ;bdos addr at run time
  177. ;
  178. ;and now, the dump routine,...
  179. ;
  180. dump    equ    $+distnce    ;<<< entry, high mem
  181. cin$trgt            ;conin address target
  182.     call     dmmy$ad        ;addr put in at run time
  183.     mvi    c,1fh        ;ctrl underline, ^_
  184.     cmp    c        ;compare to char in c
  185.     jz    dmpfl        ;if ^_, go to routine
  186.     ret            ;otherwise just return
  187. ;
  188. ;open a file, put something in it after the end of the
  189. ;last entry, then close it, OK?
  190. ;
  191. ;row and col must be initialized for each screen written
  192. ;
  193. dmpfl    equ    $+distnce
  194.     mvi    a,1
  195.     sta    col    ;col = 1
  196.     sta     row    ;row = 1
  197. ;
  198. ;set up a local stack
  199. ;
  200.     lxi    h,0    ;clear hl
  201.     dad    sp    ;sp -> hl
  202.     shld    cpmstk    ;store original stack pointer
  203.     lxi    sp,locstk    ;new top of stack
  204. ;
  205. ;define new dma
  206. ;
  207.     mvi    c,1ah
  208.     lxi    d,dma    ;use the equate
  209.     call     bdos
  210. ;
  211. ;initialize address for next write to dma
  212. ;
  213.     lxi    h,dma    ;start of dma
  214.     shld    dmaddr    ;start at first addr in dma
  215. ;
  216. ;prepare the filename in the FCB
  217. ;
  218.     lxi    h,fcb+1    ;destination, for fill
  219.     lxi    d,flnm    ;string address, for fill
  220.     call    fill    ;put filename in fcb
  221. ;
  222. ;open or make file, go to end of a previous file 
  223. ;
  224. openf    equ     $+distnce
  225.     mvi    c,0fh    ;open file
  226.     lxi    d,fcb
  227.     call     bdos    ;A = 0,1,2,3, or ffh
  228.     cpi    0ffh
  229.     jnz    empty    ;is a file, test & find end 
  230.  
  231. makef    equ    $+distnce    ;req'd for era'd Toon
  232.     lxi    d,filler    ;string of 0's
  233.     lxi    h,fcb+0Ch     ;put them after fname
  234.     call    fill        ;zero the fcb
  235. ;
  236.     mvi    c,16h    ;make file via bdos
  237.     lxi    d,fcb
  238.     call     bdos
  239.     jmp    scrloop    ;skip search to end of file
  240. ;
  241. ;find end record of file
  242. ;
  243. fend    equ    $+distnce
  244.     mvi    c,14h    ;read sequential
  245.     lxi    d,fcb    
  246.     call     bdos    ;a=0 if read successful
  247.     ori    0
  248.     jz    fend    ;not at end, read again
  249. ;
  250. ;reset the record number, delete the ^Z at eof
  251. ;
  252. deleof    equ    $+distnce
  253.     lda    fcb+20h    ;the current record number
  254.     dcr    a    ;back to last record
  255.     sta    fcb+20h    ;put decremented cr back
  256.     call    rdseq    ;last rec-> dma: advances rec #!
  257.     lda    fcb+20h    ;the current record number
  258.     dcr    a    ;back to last record
  259.     sta    fcb+20h    ;decremented cr, can rewrite
  260. ;
  261. ;find the eof and overwrite it
  262. ;
  263.     mvi    c,1ah    ;eof in c
  264.     lxi    h,dma    ;address for search
  265.     call     find    ;returns addr of char in c in h
  266.     shld    dmaddr    ;store active address in dma
  267.     jmp     scrloop    ;append new text to end of file
  268. ;
  269. ;measure out a screenfull, write byte by byte from video
  270. ;
  271. scrloop    equ    $+distnce
  272. ;
  273.     lda    col    ;get col, set up to read video
  274.     mov    c,a    ;col into c
  275.     mvi    b,0    ;zero out b
  276.     push     b    ;onto stack
  277.     lda    row    ;get row
  278.     mov    c,a    ;row into c
  279.     mvi    b,0    ;zero b
  280.     push     b    ;onto stack
  281.     call    rdvid    ;return onto stack, get char!
  282. ;
  283. ;process the char from video memory, returned in c
  284. ;
  285.     lhld    dmaddr
  286.     call     dmaout    ;char in c, dmaddr in hl
  287.     lda    col    ;get current column
  288.     inr     a    ;increment col, note col -> 81
  289.     sta    col    ;restore col
  290.     mvi    d,81    ;test, last col?
  291.     cmp    d    ;compare to col
  292.     jnz    scrloop    ;if 80th not written, next col
  293. ;
  294.     lda     row    ;row -> a
  295.     mov    d,a    ;row -> d
  296.     lda     col    ;col -> a
  297.     add    d    ;col + row in a
  298.     cpi    105    ;done? col + row = 105
  299.     jz    endf    ;yes, done with screen        
  300. ;
  301.     inr    d    ;no, increment row
  302.     mov    a,d    ;row + 1 -> a
  303.     sta    row    ;restore row
  304.     call     eoln    ;put in crlf
  305.     mvi    a,1
  306.     sta    col    ;col -> 1 for new row
  307.     jmp    scrloop    ;fill next col
  308. ;
  309. ;read the next record
  310. ;
  311. rdseq    equ    $+distnce
  312.     mvi    c,14h    ;read sequential
  313.     lxi    d,fcb
  314.     call     bdos
  315.     ret        ;done, go back
  316. ;
  317. ;write the dma to current record
  318. ;
  319. wrtseq    equ    $+distnce
  320.     mvi    c,15h    ;write sequential
  321.     lxi    d,fcb
  322.     call     bdos
  323.     ret        ;end
  324. ;
  325. ;close file
  326. ;
  327. clsfl    equ     $+distnce
  328.     mvi    c,10h    ;close file
  329.     lxi    d,fcb
  330.     call     bdos
  331.     ret        ;done
  332. ;
  333. ;test to see if ex=rc=0, eg, empty Toon
  334. ;
  335. empty    equ    $+distnce    ;test for empty Toon
  336.                 ;and delete, if so
  337.     lda    fcb+0Fh    ;load the # rec in extent
  338.     mov    b,a    ;curr record to b
  339.     lda    fcb+0Ch    ;locd curr extent to a
  340.     ora    b    ;rec & extent 0?
  341.     jnz    fend    ;not empty, find end
  342. ;
  343. ;erase file
  344. ;
  345. erafl    equ    $+distnce    ;erase empty file
  346.     mvi    c,13h    ;bdos erase file
  347.     lxi    d,fcb
  348.     call     bdos
  349.     jmp     makef    ;now make new file
  350. ;
  351. ;fills memory at h with string stored at d, term by $
  352. ;used to fill open memory at fixed, dedicated location
  353. ;
  354. fill    equ     $+distnce
  355.     mvi    c,'$'
  356.     ldax    d    ;get char into a
  357.     cmp    c    ;is the new char the end char?
  358.     rz        ;if so, have done string
  359.     mov    m,a    ;if not, store next char
  360. ;
  361.     inx    d
  362.     inx    h    ;increment both string counters
  363.     jmp    fill        
  364. ;
  365. ;find the character in c after the address supplied in h
  366. ;returns the address of the char in h
  367. ;
  368. find    equ     $+distnce
  369.     mov    a,m    ;get char in a
  370.     cmp    c    ;is it the target char?
  371.     rz        ;char found, address in h
  372.     inx    h    ;inc address and
  373.     jmp    find    ;get the next char
  374. ;
  375. ;write to dma from c, which has char
  376. ;dmaddr is in hl
  377. ;
  378. dmaout    equ     $+distnce
  379.     call     ckdma    ;decides to write when dma full
  380.     mov    m,c    ;byte -> dma
  381.     call     incr    ;increment dmaddr
  382.     ret        ;done
  383. ;
  384. ;dma full? yes->reset and restart dma
  385. ;gets and returns current char in c, dmaddr in hl
  386. ;
  387. ckdma    equ    $+distnce
  388.     lxi    d,dma+80h    ;get dma end+1
  389.     mov    a,e    ;lsb of dma end in a
  390.     cmp    l    ;at end of dma?
  391.     rnz        ;ret if not done yet
  392. ;
  393.     push     b    ;save char
  394.     call     wrtseq    ;full dma, write it
  395.     pop    b    ;get char back
  396.     lxi    h,dma    ;reset dmaddr
  397.     shld    dmaddr    ;store dmaddr
  398.     ret        ;done
  399. ;
  400. ;increment the address for current write to dma
  401. ;
  402. incr    equ    $+distnce
  403.     lhld    dmaddr    ;load next write addr
  404.     inx    h    ;+ 1
  405.     shld    dmaddr    ;restore incr addr
  406.     ret        ;done
  407. ;
  408. ;writes crlf after every 80 screen chars
  409. ;deletes blank at eoln to make 79 char lines
  410. ;in order to inprove screen appearance
  411. ;
  412. eoln    equ    $+distnce
  413.     lhld    dmaddr    ;get next location
  414.     dcx    h    ;last written char
  415.     mov    a,m    ;get the char
  416.     cpi    20h    ;was it a blank?
  417.     jnz    eoln1    ;no, terminate line
  418.     shld    dmaddr    ;yes, update address
  419.     jmp    eoln2    ;cr & lf
  420. ;
  421. eoln1    equ    $+distnce
  422.     inx    h    ;skip non-blank
  423. eoln2    equ     $+distnce
  424.     mvi    c,cr    
  425.     call     dmaout    ;check address in hl
  426.     mvi    c,lf    
  427.     call     dmaout    ;check address in hl
  428.     ret
  429. ;
  430. ;puts in last section of file, eof,...Note that 
  431. ;in general, would have to worry about hitting 
  432. ;record end during eorec, but a screenful will 
  433. ;usually end within a record
  434. ;
  435. endf    equ    $+distnce
  436.     call    eoln    ;cr & lf
  437.     lxi    d,eorec    ;addr of string for fill
  438.     lhld    dmaddr    ;fill here
  439.     call    fill    ;with some eof's
  440.     call     wrtseq    ;write the last dma
  441.     call     clsfl    ;close file
  442. ;
  443.     lhld     cpmstk    ;replace the orig stack ptr
  444.     sphl        ;hl -> sp
  445.     ret
  446. ;
  447. ;################ MACHINE DEPENDENT #################
  448. ;                 vvvvvvv vvvvvvvvv
  449. ;
  450. ;this routine switches from normal memory (bank 0) to
  451. ;video memory and prom (bank 1).  it reads one char at 
  452. ;the address calculated for the screen col and row
  453. ;supplied on the stack when rdvid is called, then
  454. ;returns that char in register c
  455. ;
  456. ;reset for input from bank 1, video memory and prom
  457. ;
  458. rdvid    equ    $+distnce
  459.     in      1Ch     ;get system byte from the Z80
  460.         ori     80h     ;force msb -> 1 for bank one
  461.         out     1Ch     ;set port
  462. ;
  463. ;stack on entry: rtn addr,row,col
  464. ;
  465.         pop     h       ;get rtn addr
  466.         pop     b       ;row in BC
  467.         pop     d       ;column in DE
  468.     push    h    ;restore rtn addr
  469. ;
  470. ;calculate the address in video mem
  471. ;
  472.         lxi     h,3000h ;set up hl
  473.         mov     a,c     ;move row -> A
  474.         mvi     c,80h   ;BC = 0080, note B=00 assumed
  475. ;
  476. ;multiplication routine to get (row-1)*80h
  477. ;
  478. rowx    equ    $+distnce
  479.     dcr    a    ;row-1
  480.     jz    donex    ;through multiplying ?
  481.     dad    b    ;addr + 80h
  482.     jnz    rowx    ;not yet HL=3000h+(row-1)*80h
  483.             ;uses flag from dcr
  484. ;
  485. donex    equ    $+distnce
  486.     dcx    d    ;col-1
  487.     dad    d    ;addr+(col-1) in HL
  488. ;
  489.     mov    c,m    ;get the byte from memory in c
  490. ;
  491. ;reset for bank 0 memory
  492. ;
  493.         in      1Ch     ;get system byte
  494.         xri     80h     ;msb -> 0, bank zero
  495.         out     1Ch     ;set it
  496. ;
  497.     ret        ;end of rdvid
  498. ;
  499. ;                 ^^^^^^^ ^^^^^^^^^
  500. ;################ MACHINE DEPENDENT ################
  501. ;
  502. flnm    equ    $+distnce
  503.     db    'TOON       $'
  504. eorec    equ    $+distnce
  505.     db    eof,eof,eof,eof,'$'
  506. dmaddr    equ    $+distnce
  507.     ds    2    ;address of next write to dma
  508. row    equ    $+distnce
  509.     ds    1    ;current screen column, 1->80
  510. col    equ    $+distnce
  511.     ds    1    ;current screen row,1->24
  512. filler    equ    $+distnce
  513.     db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  514.     db    0,0,0,0,0,0,'$'
  515.             ;used to reinit fcb 
  516. fcb    equ    $+distnce
  517.     db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 
  518.     db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 
  519.             ;36 bytes init to 0
  520. dma    equ    $+distnce
  521.     ds    128    ;space for sector buffer
  522.     ds    32    ;local stack
  523. locstk    equ    $+distnce-1    ;top of stack
  524. cpmstk    equ    $+distnce
  525.     ds    2    ;cpm's stack pointer on entry
  526. ;
  527. endmv    equ    $
  528. ;local stack
  529. locstk    equ    $+distnce-1    ;top of stack
  530. cpmstk    equ    $+distnce
  531.     ds    2    ;c