home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / c64 / tvbios.asm < prev    next >
Encoding:
Assembly Source File  |  1984-10-03  |  8.5 KB  |  561 lines

  1. ;TVBIOS v1.0--add terminal emulation to C64 CP/M
  2. ;
  3. ;  28 September 1984
  4. ;
  5. ;  Author:  Ross A.Alford
  6. ;           ...{decvax, akgua, ihnp4}!mcnc!ecsvax!alford
  7. ;           Compuserve 75475,1404
  8. ;
  9. ;           Department of Zoology
  10. ;           Duke University
  11. ;           Durham, NC 27706
  12. ;
  13. ;  This program is copyrighted 1984 by
  14. ;  Ross A. Alford.  Permission is
  15. ;  hereby granted for unlimited nonprofit
  16. ;  distribution, provided this notice is
  17. ;  included.  Permission for any
  18. ;  commercial use must be obtained from
  19. ;  the author.
  20. ;
  21. ;  Adds to the C64 BIOS an emulation of
  22. ;  the Televideo 920 terminal (in
  23. ;  40 columns).
  24. ;
  25. ;  Takes up the space reserved for 6502
  26. ;  BIOS functions 7,8, and 9 at Z80
  27. ;  addresses 0fe00h through 0ffffh.
  28. ;
  29. ;  Also adds auto key repeat after
  30. ;  a short delay.
  31. ;
  32. ;  Using the insert and delete line
  33. ;  functions sometimes makes a few
  34. ;  characters turn odd colors after they
  35. ;  move.  This appears to be due to
  36. ;  some sort of a timing problem with
  37. ;  the 2114 used for color RAM, and I
  38. ;  haven't been able to get around it.
  39. ;  I'd like to hear of any solution
  40. ;  anyone comes up with.
  41. ;
  42. ;  This program works with the version
  43. ;  of C64 CP/M that I own.  There may
  44. ;  be other versions in existance.  If
  45. ;  it doesn't work on your system,
  46. ;  look up the BIOS locations in your
  47. ;  manual and see if they match.
  48. ;
  49. ;  I make no warranty of this program's
  50. ;  usefulness, and assume no liability
  51. ;  for any damages it may cause
  52. ;  directly or indirectly.
  53. ;
  54. ;
  55. ;  Supports the following commands:
  56. ;
  57. ;  decimal sequence    function
  58. ;
  59. ;  26            home and clear
  60. ;  27,82        delete line
  61. ;  27,69        insert line
  62. ;  27,84        erase to end of line
  63. ;  27,85        erase to end of screen
  64. ;  27,41        inverse video on
  65. ;  27,40        inverse video off
  66. ;  27,61,row+32,col+32    position cursor
  67. ;                         at row, col
  68. ;
  69. ;
  70. ;define true and false
  71. ;
  72. true    equ    0ffh
  73. false    equ    00h
  74. ;
  75. ;
  76. ;assemble for 44k or 48k?
  77. ;
  78. forty8    equ    true
  79. forty4    equ    false
  80. ;
  81. ;conditional equates
  82. ;
  83.     if    forty8
  84. lastky    equ    0ba63h
  85. j9    equ    0bbd5h
  86. const1    equ    0bbd7h
  87. const2    equ    0bbdch
  88. conout    equ    0bc76h
  89. j20    equ    0bc7ch
  90. cout1    equ    0bc89h
  91. cout5    equ    0bcaah
  92.     endif
  93. ;
  94.     if    forty4
  95. lastky    equ    0aa63h
  96. j9    equ    0abd5h
  97. const1    equ    0abd7h
  98. const2    equ    0abdch
  99. conout    equ    0ac76h
  100. j20    equ    0ac7ch
  101. cout1    equ    0ac89h
  102. cout5    equ    0acaah
  103.     endif
  104. ;
  105. ;global equates
  106. ;
  107. cr    equ    00dh
  108. lf    equ    00ah
  109. offset    equ    0fb00h    
  110. iotype    equ    0fcffh
  111. chrst    equ    0f400h
  112. colst    equ    0c800h
  113. chrend    equ    0f7bfh
  114. colend    equ    0cbbfh
  115. color    equ    0f286h
  116. row6502    equ    0f0d6h
  117. col6502    equ    0f0d3h
  118. bdos    equ    0005h
  119. prtstr    equ    009h
  120. data6502 equ    0f901h
  121. rvs6502    equ    0f0c7h;
  122. jrnz    equ    020h
  123. ;
  124. ;routine that relocates the
  125. ;  tvbios routines into the
  126. ;  extra 512 bytes at 0fe00h
  127. ;  and patches conout in the
  128. ;  bios to jump to tvbios
  129. ;
  130.     org    0100h
  131.     lxi    d,msg1
  132.     mvi    c,prtstr
  133.     call    bdos
  134.     lxi    b,tvbios
  135.     lxi    h,scend-tvbios
  136.     lxi    d,0fe00h
  137.     call    movup
  138.     lxi    b,bpatch
  139.     lxi    d,conout
  140.     lxi    h,0003h
  141.     call    movup
  142.     lxi    b,bpatch2
  143.     lxi    d,j9-1
  144.     lxi    h,0003h
  145.     call    movup
  146.     lxi    b,bpatch3
  147.     lxi    d,cout5
  148.     lxi    h,0003h
  149.     call    movup
  150.     ret
  151. movup:    ldax    b
  152.     stax    d
  153.     inx    b
  154.     inx    d
  155.     dcx    h
  156.     xra    a
  157.     cmp    h
  158.     jnz    movup
  159.     cmp    l
  160.     jnz    movup
  161.     ret
  162. ;
  163. ;
  164. ;jump to tvbios to patch into
  165. ;  bios80 at conout start
  166. ;
  167. ;
  168. bpatch    jmp    0fe00h
  169. ;
  170. ;
  171. ;patch to jump for keyboard
  172. ;  auto repeat.  inserted into
  173. ;  BIOS80 at j9-1, which should
  174. ;  be CMP M
  175. ;
  176. ;
  177. bpatch2: jmp    rptpat+offset
  178. ;
  179. ;
  180. ;jump to routine to check and
  181. ;  correct inverse/normal video
  182. ;  status.   inserted into the
  183. ;  BIOS at location cout5
  184. ;
  185. ;
  186. bpatch3: jmp    invpat+offset
  187. ;
  188. ;
  189. ;startup messages
  190. ;
  191. msg1    db    cr,lf,'TVBIOS v1.0 for C64 CP/M',cr,lf
  192.     db    'Emulates the TVI 920 in 40 columns',cr,lf,cr,lf
  193.     db    'Copyright 1984 by Ross A. Alford',cr,lf
  194.     db    'All commercial rights reserved',cr,lf,cr,lf,'$'
  195. ;
  196. ;
  197. ;main TVBIOS interpreter
  198. ;
  199. ;
  200.     org    0300h
  201. tvbios    lda    flag+offset
  202.     db    0cbh,07fh
  203. ;    bit    7,a
  204.      jnz    esced+offset
  205.     db    0cbh,047h
  206. ;    bit    0,a
  207.     jnz    curdo+offset
  208.     mov    a,c
  209.     cpi    01bh    ;esc?
  210.     jnz    ccz+offset
  211.     mvi    a,true
  212.     sta    flag+offset
  213.     ret
  214. ccz:    cpi    01ah
  215.     jnz    endscop+offset
  216.     mvi    a,0ch
  217.     mov    c,a
  218. endscop: lda    iotype
  219.     ani    010h
  220.     mov    a,c
  221.     jnz    cout5
  222.     jmp    j20+02h
  223. esced:    xra    a
  224.     sta    flag+offset
  225.     mov    a,c
  226.     cpi    052h
  227.     jz    delrow+offset
  228.     cpi    045h
  229.     jz    insrow+offset
  230.     cpi    054h
  231.     jz    clreol+offset
  232.     cpi    055h
  233.     jz    clreos+offset
  234.     cpi    029h
  235.     jz    invon+offset
  236.     cpi    028h
  237.     jz    invoff+offset
  238.     cpi    03dh
  239.     rnz
  240.     mvi    a,01h
  241.     sta    flag+offset
  242.     ret
  243. curdo:    db    0cbh,04fh
  244. ;    bit    1,a
  245.     jnz    curcol+offset
  246.     mov    a,c
  247.     sui    020h
  248.     sta    row+offset
  249.     mvi    a,03h
  250.     sta    flag+offset
  251.     ret
  252. curcol:    xra    a
  253.     sta    flag+offset
  254.     mov    a,c
  255.     sui    020h
  256.     sta    col+offset
  257.     jmp    curpos+offset
  258. ;
  259. ;subroutine insrow: insert a blank
  260. ;  line at the row given by row
  261. ;
  262. insrow: call    stindl+offset
  263.     push    h
  264.     lxi    b,chrend
  265.     lxi     d,chrend+028h
  266.     call    lddr+offset
  267.     pop    h
  268.     lxi    b,colend
  269.     lxi    d,colend+028h
  270.     call    lddr+offset
  271.     mvi    a,028h
  272.     sta    ntoblk+offset
  273. ;
  274. ;subroutine blank: change 'ntoblk'
  275. ;  positions to blank starting at
  276. ;  current chradr, coladr
  277. ;
  278. blank:    mvi    b,020h
  279.     lda    ntoblk+offset
  280.     lhld    chradr+offset
  281. blank1:    mov    m,b
  282.     inx    h
  283.     dcr    a
  284.     ora    a
  285.     jnz    blank1+offset
  286.     mvi    b,0f6h
  287.     lda    ntoblk+offset
  288.     lhld    coladr+offset
  289. blank2:    mov    m,b
  290.     inx    h
  291.     dcr    a
  292.     ora    a
  293.     jnz    blank2+offset
  294.     ret
  295. ;
  296. ;
  297. ;subroutine saverc: moves row
  298. ;  and col numbers from 6502
  299. ;  locs to tvbios locs
  300. ;
  301. ;
  302. saverc:    lda    col6502
  303.     sta    col+offset
  304.     lda    row6502
  305.     sta    row+offset
  306.     ret
  307. ;
  308. ;subroutine calcstnd:  calculate
  309. ;  addresses for start of color
  310. ;  and char memory given a row #
  311. ;  row passed in 'row', addresses
  312. ;  returned in coladr, chradr
  313. ;
  314. calcstnd: lda    row+offset
  315.     ani    07fh
  316.     lxi    h,0000h
  317.     lxi    b,0000h
  318.     ora    a
  319.     jz    caend+offset
  320.     lxi    b,0028h
  321. calclp:    ora    a
  322.     jz    caend+offset
  323.     dad    b
  324.     dcr    a
  325.     jmp    calclp+offset
  326. caend:    push    h
  327.     lxi    b,chrst
  328.     dad    b
  329.     shld    chradr+offset
  330.     pop    h
  331.     lxi    b,colst
  332.     dad    b
  333.     shld    coladr+offset
  334.     ret
  335. ;
  336. ;
  337. ;subroutine lddr: simulate the
  338. ;  lddr instruction, sort of
  339. ;  pass from in bc, to in de,
  340. ;  number in hl
  341. ;  this is used rather than the
  342. ;  real thing because lddr is
  343. ;  apparently too fast for
  344. ;  the color memory
  345. ;
  346. ;
  347. lddr:    ldax    b
  348.     push    h    ;delay
  349.     pop    h    ;delay
  350.     stax    d
  351.     dcx    b
  352.     dcx    d
  353.     dcx    h
  354.     xra    a
  355.     cmp    h
  356. lddr1:    db    jrnz,(lddr-lddr1-2) and 0ffh
  357.     cmp    l
  358. lddr2:    db    jrnz,(lddr-lddr2-2) and 0ffh
  359.     ret
  360. ;
  361. ;subroutine ldir: move byte
  362. ;  pointed to by bc to loc
  363. ;  pointed to by de, inc bc, de
  364. ;  repeat hl times
  365. ;
  366. ldir    ldax    b
  367.     push    h    ;delay
  368.     pop    h    ;delay
  369.     stax    d
  370.     inx    b
  371.     inx    d
  372.     dcx    h
  373.     xra    a
  374.     cmp    h
  375. ldir1:    db    jrnz,(ldir-ldir1-2) and 0ffh
  376.     cmp    l
  377. ldir2:    db    jrnz,(ldir-ldir2-2) and 0ffh
  378.     ret
  379. ;
  380. ;
  381. ;subroutine clreol:clear to end
  382. ;  of current screen line
  383. ;
  384. ;
  385. clreol:    call    saverc+offset
  386. ceol2:    call    calcstnd+offset
  387.     lxi    h,col+offset
  388.     mvi    a,028h
  389.     sub    m
  390.     sta    ntoblk+offset
  391.     mvi    b,0
  392.     lda    col+offset
  393.     mov    c,a
  394.     lhld    chradr+offset
  395.     dad    b
  396.     shld    chradr+offset
  397.     lhld    coladr+offset
  398.     dad    b
  399.     shld    coladr+offset
  400.     call    blank+offset
  401.     ret
  402. ;
  403. ;
  404. ;subroutine clreos:clear from 
  405. ;  cursor to end of page
  406. ;
  407. ;
  408. clreos:    call    clreol+offset
  409.     xra    a
  410.     sta    col+offset
  411. ceop2:    lxi    h,row+offset
  412.     inr    m
  413.     mvi    a,018h
  414.     cmp    m
  415.     jc    ceopnd+offset
  416.     call    ceol2+offset
  417.     jmp    ceop2+offset
  418. ceopnd:    ret
  419. ;
  420. ;
  421. ;subroutine curpos: position
  422. ;  cursor on coords passed in
  423. ;  locations row and col
  424. ;
  425. ;
  426. curpos:    lda    row+offset
  427.     ani    07fh
  428.     cpi    019h
  429.     rnc
  430.     dcr    a
  431.     sta    row6502
  432.     mvi    a,0dh
  433.     call    cout5
  434.     lda    col+offset
  435.     ani    07fh
  436.     cpi    028h
  437.     rnc
  438.     sta    col6502
  439.     ret
  440. ;
  441. ;
  442. ;subroutine invon:start inverse
  443. ;
  444. ;
  445. invon:    mvi    a,01h
  446.     sta    invflg+offset
  447.     ret
  448. ;
  449. ;
  450. ;subroutine invoff: end inverse
  451. ;
  452. ;
  453. invoff:    xra    a
  454.     sta    invflg+offset
  455.     ret
  456. ;
  457. ;subroutine delrow: delete the
  458. ;  row pointed to by row
  459. ;
  460. delrow: call    stindl+offset
  461.     push    h
  462.     push    h
  463.     lxi    h,0028h
  464.     dad    d
  465.     mov    b,h
  466.     mov    c,l
  467.     pop    h
  468.     call    ldir+offset
  469.     lhld    coladr+offset
  470.     mov    d,h
  471.     mov    e,l
  472.     lxi    h,0028h
  473.     dad    d
  474.     mov    b,h
  475.     mov    c,l
  476.     pop    h
  477.     call    ldir+offset
  478. lastrw:    xra    a
  479.     sta    col+offset
  480.     mvi    a,018h
  481.     sta    row+offset
  482.     call    ceol2+offset
  483.     ret
  484. ;
  485. ;subroutine stindl: startup
  486. ;  for insert/delete a row
  487. ;  routines.  exit with chradr
  488. ;  in d,e and chrend-chradr in
  489. ;  hl
  490. ;
  491. stindl:    call    saverc+offset
  492.     ani    07fh
  493.     cpi    018h
  494.     jc    stin2+offset
  495.     pop    h    ;last return address
  496.     jmp    lastrw+offset
  497. stin2:        call    calcstnd+offset
  498.     xra    a
  499.     lhld    chradr+offset
  500.     mov    d,h
  501.     mov    e,l
  502.     lxi    h,chrend
  503.     db    0edh,052h
  504. ;    sbc    hl,de
  505.     inx    h
  506.     ret
  507. ;
  508. ;
  509. ;rptpat routine: a jump to this
  510. ;  is inserted at j9-1 in the
  511. ;  BIOS.   This repeats any
  512. ;  keypress after a delay
  513. ;
  514. ;
  515. rptpat:    mov    b,a
  516.     cpi    040h
  517.     jnz    rpp1+offset
  518.     sta    lastky
  519.     jmp    const1
  520. rpp1:    cmp    m
  521.     jz    rpp2+offset
  522.     mvi    a,080h
  523.     sta    delay+offset
  524.     mov    a,b
  525.     jmp    const2
  526. rpp2:    lxi    h,delay+offset
  527.     dcr    m
  528.     jnz    const1
  529.     mvi    a,018h
  530.     mov    m,a
  531.     mov    a,b
  532.     jmp    const2
  533. ;
  534. ;
  535. ;routine invpat is jumped to 
  536. ;  by the modified BIOS from 
  537. ;  location COUT5.  it fixes
  538. ;  the inverse/normal status,
  539. ;  then continues as normal
  540. ;
  541. ;
  542. invpat: mov    b,a
  543.     lda    invflg+offset
  544.     sta    rvs6502
  545.     mov    a,b
  546.     sta    data6502
  547.     jmp    cout5+3
  548. ;
  549. ;storage locations
  550. ;
  551. row    db    0
  552. col    db    0
  553. chradr    db    0,0
  554. coladr    db    0,0
  555. ntoblk    db    0
  556. flag    db    0
  557. delay    db    080h
  558. invflg    db    0
  559. ;
  560. scend    end
  561.