home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / trs80model4.zip / m4h192.asm < prev    next >
Assembly Source File  |  1986-10-22  |  21KB  |  913 lines

  1. ;        M4H192/ASM
  2. CLEAR_TO_EOS    EQU    $
  3.         GET_CURSOR        ;Get the cursor position
  4.         CALL    GET_RC_ADDR    ;Get the real address
  5. R077        EQU    $-2
  6.         PUSH    HL        ;Save the start for LDIR
  7.         PUSH    HL        ;Copy it to BC
  8.         POP    BC
  9.         LD    HL,24*80+0F7FFH    ;Get the last place to blank
  10. CLEAR_SPACE    EQU    $
  11.         OR    A        ;Reset the carry
  12.         SBC    HL,BC        ;HL is now length of area
  13.         PUSH    HL        ;Put it into BC and clear stack
  14.         POP    BC
  15.         POP    HL        ;Get the starting address
  16.         JR    Z,NO_CLEAR    ;Jump if no count
  17.         PUSH    HL        ;Copy to DE
  18.         POP    DE
  19.         INC    DE        ;Point DE one ahead
  20.         PUSH    BC        ;Hide the cursor before
  21.         PUSH    DE
  22.         PUSH    HL
  23.         LD    A,15        ;Use *DO for this
  24.         CALL    CHAIN_IN
  25. R190        EQU    $-2
  26.         POP    HL        ;Restore the stack
  27.         POP    DE
  28.         POP    BC
  29.         SWAP_IN            ;Swap screen into RAM
  30.         LD    (HL),' '    ;Store one blank
  31.         SWAP_OUT
  32. CLR_LOOP    LD    A,30        ;One line max
  33.         SWAP_IN            ;Screen in
  34. LINE_LOOP    PUSH    AF        ;Save the max counter
  35.         LD    A,B        ;Check if done with all bytes
  36.         OR    C
  37.         JR    Z,END_CLEAR    ;If done, exit
  38.         POP    AF        ;Get the max count back
  39.         LDI            ;Blank one byte
  40.         DEC    A        ;Decrement the max count
  41.         JR    NZ,LINE_LOOP    ;If not done, do it again
  42.         SWAP_OUT        ;Swap the video out, and enable
  43.         JR    CLR_LOOP    ;interrupts again, and loop.
  44. ;
  45. END_CLEAR    POP    AF        ;Fix the stack
  46.         SWAP_OUT        ;Swap the video back out
  47.         LD    A,14        ;Turn the cursor back on
  48.         JP    CHAIN_IN
  49. R078        EQU    $-2
  50. NO_CLEAR    EQU    $
  51.         JP    RETOUT
  52. R191        EQU    $-2
  53. ;
  54. CLEAR_TO_EOL    EQU    $
  55.         GET_CURSOR        ;Get the cursor ROW/COL
  56.         PUSH    HL        ;Save it
  57.         CALL    GET_RC_ADDR    ;Get the ADDRESS equivilent
  58. R188        EQU    $-2
  59.         EX    (SP),HL        ;Exchange for ROW/COL
  60.         LD    L,79        ;Point to end of this line
  61.         CALL    GET_RC_ADDR    ;Get the RAM address
  62. R189        EQU    $-2
  63.         POP    BC        ;Restore the beginning
  64.         PUSH    BC        ;Save it
  65.         LD    A,C        ;If C = L then at EOL
  66.         CP    L
  67.         JR    Z,NO_CLEAR    ;So skip rest of operations
  68.         JR    CLEAR_SPACE
  69. ;
  70. DEL_CHAR    EQU    $
  71.         LD    DE,SCR_BUFF    ;Get the buffer address
  72. R079        EQU    $-2
  73.         PUSH    DE        ;Save it for the store
  74.         GET_CURSOR        ;Get the row to retrieve
  75.         PUSH    HL        ;Save the column for later store
  76.         GET_LINE        ;Get the line into the buffer
  77.         LD    A,79        ;Maximum characters to move
  78.         SUB    L        ;Subtract the current position
  79.         LD    H,0        ;Set the column to zero
  80.         ADD    HL,DE        ;HL is now the place to start at
  81.         PUSH    HL        ;Get a copy in de
  82.         POP    DE
  83.         OR    A
  84.         JR    Z,NO_D_CHAR
  85.         LD    C,A        ;Get the count in BC as 16 bits
  86.         LD    B,0
  87.         INC    HL        ;Move the source one forward
  88.         LDIR            ;Skoot it all backwards
  89. NO_D_CHAR    EQU    $
  90.         LD    A,' '        ;Get a space character
  91.         LD    (DE),A        ;Blank the last space on the line
  92.         POP    HL        ;Get the row to store at
  93.         POP    DE        ;Get the buffer address back
  94.         PUT_LINE        ;Put the line back on the screen
  95.         JP    RETOUT
  96. R080        EQU    $-2
  97. ;
  98. END_INSERT    EQU    $
  99.         XOR    A
  100.         LD    (INSERT_FLAG),A    ;End insert mode
  101. R081        EQU    $-2
  102.         JP    RETOUT
  103. R082        EQU    $-2
  104. ;
  105. BEGIN_INSERT    LD    A,1
  106.         LD    (INSERT_FLAG),A    ;Begin insert mode
  107. R083        EQU    $-2
  108.         JP    RETOUT
  109. R084        EQU    $-2
  110. ;
  111. STAND_END    EQU    $
  112.         LD    A,17        ;End standout mode
  113.         JP    STORE_CHAIN
  114. R085        EQU    $-2
  115. ;
  116. STAND_OUT    EQU    $
  117.         LD    A,16
  118.         JP    STORE_CHAIN    ;Begin standout mode
  119. R086        EQU    $-2
  120. ;
  121. ;    At this point, there are still more characters to distinguish
  122. ;    between sequences.  So we set the next state to go to
  123. ;
  124. SET_ESC_2    EQU    $
  125.         LD    HL,ESCAPE_2    ;Get address of the next state
  126. R087        EQU    $-2
  127.         LD    (OLDSTATE),HL    ;Save it
  128. R088        EQU    $-2
  129.         LD    A,(NEWCHAR)    ;Get the character sent this time
  130. R089        EQU    $-2
  131.         LD    (CHAR_2),A    ;Save the character
  132. R090        EQU    $-2
  133.         JP    RETOUT        ;Skip the *do device and return
  134. R091        EQU    $-2
  135. ;
  136. ;    Jump table for processing ESC-y-[123456789] and ESC-x-[123456789]
  137. ;    sequences
  138. ;
  139. MODE_TABLE    EQU    $
  140.         DW    ENABLE_25TH
  141. R153        EQU    $-2
  142.         DW    NO_KEY_CLICK
  143. R154        EQU    $-2
  144.         DW    HOLD_SCREEN
  145. R155        EQU    $-2
  146.         DW    BLOCK_CURSOR
  147. R156        EQU    $-2
  148.         DW    CURSOR_OFF
  149. R157        EQU    $-2
  150.         DW    KEYPAD_SHIFTED
  151. R158        EQU    $-2
  152.         DW    ALT_KEY_MODE
  153. R159        EQU    $-2
  154.         DW    AUTO_LF
  155. R160        EQU    $-2
  156.         DW    AUTO_CR
  157. R161        EQU    $-2
  158.         DW    DISABLE_25TH
  159. R162        EQU    $-2
  160.         DW    KEY_CLICK
  161. R163        EQU    $-2
  162.         DW    NO_HOLD_SCREEN
  163. R164        EQU    $-2
  164.         DW    LINE_CURSOR
  165. R165        EQU    $-2
  166.         DW    CURSOR_ON
  167. R166        EQU    $-2
  168.         DW    KEY_UNSHIFT
  169. R167        EQU    $-2
  170.         DW    EXIT_ALT_KEY
  171. R168        EQU    $-2
  172.         DW    NO_AUTO_LF
  173. R169        EQU    $-2
  174.         DW    NO_AUTO_CR
  175. R170        EQU    $-2
  176. ;
  177. ;    Process third character in 3 character or more sequence
  178. ;
  179. ESCAPE_2    EQU    $
  180.         LD    A,(CHAR_2)    ;Get the previous character
  181. R092        EQU    $-2
  182.         CP    'x'        ;Was it options on
  183.         JR    Z,OPTION_X    ;Yep, go do it
  184.         CP    'y'        ;Was it options off?
  185.         JR    NZ,MOVE_CURSOR    ;Jump if not
  186.         LD    C,18        ;Get the offset
  187.         JR    OPTIONS        ;Join other code
  188. OPTION_X    EQU    $
  189.         LD    C,0        ;Get offset at zero
  190. OPTIONS        EQU    $
  191.         LD    A,(NEWCHAR)    ;Get the character
  192. R130        EQU    $-2
  193.         SUB    '1'        ;Zero base it
  194.         CP    9        ;Check for too big
  195.         JP    NC,RETOUT    ;Can't do this one
  196. R187        EQU    $-2
  197.         CP    0
  198.         JP    C,RETOUT
  199. R171        EQU    $-2
  200.         SLA    A        ;Multiply by 2
  201.         ADD    A,C        ;Tack on offset
  202.         LD    C,A        ;Make BC a 16 bit offset
  203.         LD    B,0
  204.         LD    HL,MODE_TABLE    ;Get the table
  205. R172        EQU    $-2
  206.         ADD    HL,BC
  207.         LD    E,(HL)        ;Get the low order byte
  208.         INC    HL        ;Point to MSB
  209.         LD    D,(HL)        ;Get the MSB
  210.         PUSH    DE        ;Put it on the stack
  211.         RET            ;Jump to it
  212. ;
  213. ;    All of the following options are not implemented, so they are
  214. ;    ignored
  215. ;
  216. ENABLE_25TH:
  217. NO_KEY_CLICK:
  218. HOLD_SCREEN:
  219. KEYPAD_SHIFTED:
  220. ALT_KEY_MODE:
  221. DISABLE_25TH:
  222. KEY_CLICK:
  223. NO_HOLD_SCREEN:
  224. EXIT_ALT_KEY:
  225. KEY_UNSHIFT:
  226. GOOUT        EQU    $
  227.         JP    RETOUT
  228. R173        EQU    $-2
  229. ;
  230. AUTO_LF        EQU    $
  231.         LD    A,(FVAL)
  232. R179        EQU    $-2
  233.         OR    1
  234.         LD    (FVAL),A
  235. R180        EQU    $-2
  236.         JR    GOOUT
  237. ;
  238. AUTO_CR        EQU    $
  239.         LD    A,(FVAL)
  240. R181        EQU    $-2
  241.         OR    2
  242.         LD    (FVAL),A
  243. R182        EQU    $-2
  244.         JR    GOOUT
  245. ;
  246. NO_AUTO_LF    EQU    $
  247.         LD    A,(FVAL)
  248. R183        EQU    $-2
  249.         AND    0FEH
  250.         LD    (FVAL),A
  251. R184        EQU    $-2
  252.         JR    GOOUT
  253. ;
  254. NO_AUTO_CR    EQU    $
  255.         LD    A,(FVAL)
  256. R185        EQU    $-2
  257.         AND    0FDH
  258.         LD    (FVAL),A
  259. R186        EQU    $-2
  260.         JR    GOOUT
  261. ;
  262. BLOCK_CURSOR    EQU    $
  263.         LD    HL,(VIDEO_START);Get the call out vector
  264. R093        EQU    $-2
  265. CHECK_JUMP    LD    A,H        ;Check for valid
  266.         OR    L
  267.         JP    Z,RETOUT    ;Jump if no address specified
  268. R094        EQU    $-2
  269.         LD    DE,RETOUT    ;Push the return address
  270. R095        EQU    $-2
  271.         PUSH    DE
  272.         JP    (HL)        ;Call the users routine
  273. CURSOR_ON    EQU    $
  274.         LD    A,15        ;Cursor on to *DO
  275.         JP    STORE_CHAIN
  276. R151        EQU    $-2
  277. ;
  278. LINE_CURSOR    EQU    $
  279.         LD    HL,(VIDEO_END)    ;Get the vector
  280. R096        EQU    $-2
  281.         JR    CHECK_JUMP
  282. ;
  283. CURSOR_OFF    EQU    $
  284.         LD    A,14
  285.         JP    STORE_CHAIN
  286. R152        EQU    $-2
  287. ;
  288. MOVE_CURSOR    EQU    $
  289.         LD    A,(NEWCHAR)
  290. R097        EQU    $-2
  291.         SUB    ' '        ;This should be the row
  292.         JP    C,RETOUT    ;Abort if bad row
  293. R098        EQU    $-2
  294.         CP    24        ;check for too big    
  295.         JP    NC,RETOUT    ;Abort on bad here too
  296. R099        EQU    $-2
  297.         LD    (GOTO_ROW),A    ;Save the row
  298. R100        EQU    $-2
  299. ;
  300. ;    Now we must wait for the column to get here, so set the state,
  301. ;
  302.         LD    HL,ESCAPE_3    ;Set the state for column
  303. R101        EQU    $-2
  304.         LD    (OLDSTATE),HL    ;Store it
  305. R102        EQU    $-2
  306. CONTINUE    EQU    $
  307.         JP    RETOUT        ;Chain into any filters
  308. R103        EQU    $-2
  309. ;
  310. ;    At this point, we are looking for the column of a cursor
  311. ;    motion sequence.  This is the longest sequence
  312. ;
  313. ESCAPE_3    LD    A,(NEWCHAR)    ;Get the character
  314. R104        EQU    $-2
  315.         SUB    ' '        ;Get rid of the bias
  316.         JP    C,RETOUT    ;Abort if bad column
  317. R105        EQU    $-2
  318.         CP    80        ;Check for too high
  319.         JP    NC,RETOUT    ;Exit if over
  320. R106        EQU    $-2
  321.         LD    L,A        ;Get the column in L
  322.         LD    A,(GOTO_ROW)    ;Get the ROW from the save area
  323. R107        EQU    $-2
  324.         LD    H,A        ;Put it in HL for PUT_CURSOR
  325.         PUT_CURSOR        ;Set the new cursor position
  326.         JP    RETOUT        ;Return
  327. R108        EQU    $-2
  328. ;
  329. DEL_LINE    LD    A,1        ;Set the delete line flag
  330.         JR    LINE_OPS
  331. ;
  332. ADD_LINE    XOR    A        ;Clear the flag
  333. ;
  334. ;    The following code is somewhat shared by the INSERT and DELETE
  335. ;    line code.  This code accesses the video memory directly to get
  336. ;    the fastest possible movement.  Interrupts must be off while
  337. ;    the screen is swapped in, so a compromise was made so that the
  338. ;    interrupts were not off for too long.  The movement of the
  339. ;    screen is done one line at a time.  Interrupts are turned back
  340. ;    on in between lines, so that the UART can generate RECEIVED
  341. ;    CHARACTER AVAILABLE interrupts.  I have had reasonable behavior
  342. ;    at 9600 BAUD with this idea...
  343. ;
  344. LINE_OPS    LD    (DEL_FLAG),A    ;Store the flag value
  345. R109        EQU    $-2
  346.         GET_CURSOR        ;Get the current row and column
  347.         LD    A,23        ;Get the maximum possible
  348.         SUB    H        ;Get the difference in rows
  349.         JR    Z,CLEAR_LINE    ;Go clear the line if on the last
  350.         PUSH    IY
  351.         PUSH    HL        ;Save HL from the call to *DO
  352.         PUSH    BC
  353.         PUSH    DE
  354.         PUSH    AF
  355.         LD    A,15        ;Turn the cursor off
  356.         CALL    CHAIN_IN    ;Call *DO to do the work
  357. R129        EQU    $-2
  358.         POP    AF
  359.         POP    DE
  360.         POP    BC
  361.         POP    HL        ;Restore the ROW/COL
  362.         POP    IY
  363.         LD    A,(DEL_FLAG)    ;Get the flag
  364. R110        EQU    $-2
  365.         OR    A
  366.         JR    Z,INS_MODE
  367. ;
  368. ;    Delete the line that the cursor is on
  369. ;
  370.         PUSH    HL        ;Save the row and column
  371.         LD    L,0        ;Go to the first col of the line
  372.         CALL    GET_RC_ADDR    ;Get the effective address in mem
  373. R111        EQU    $-2
  374.         POP    AF        ;Get the row in A, ignoring F
  375.         PUSH    HL        ;Move the address to DE
  376.         POP    DE
  377.         LD    BC,80        ;One row is this many characters
  378.         ADD    HL,BC        ;Add one row to HL for the source
  379. DEL_LOOP    EQU    $
  380.         SWAP_IN            ;Swap the screen into view
  381.         PUSH    BC
  382.         LDIR            ;Move one rows worth
  383.         POP    BC
  384.         SWAP_OUT        ;Swap the screen back out
  385.         INC    A        ;Add one to the row
  386.         CP    23        ;Are we at the end?
  387.         JR    NZ,DEL_LOOP    ;Loop if not
  388.         LD    H,A        ;Load H with the last row
  389.         JR    LINE_OPS_1    ;Join the other code
  390. ;
  391. INS_MODE    EQU    $
  392.         LD    A,23        ;Max lines on a screen
  393.         SUB    H        ;Minus current line = remaining
  394.         LD    HL,23*80+0F7FFH    ;Source address for LDDR
  395.         LD    DE,24*80+0F7FFH    ;Destination address for LDDR
  396.         LD    BC,80        ;Number of bytes to move
  397. INS_LOOP    EQU    $
  398.         SWAP_IN            ;Swap the screen in
  399.         PUSH    BC
  400.         LDDR            ;Move one line
  401.         POP    BC
  402.         SWAP_OUT        ;Swap the screen out
  403.         DEC    A        ;Decrement the line count
  404.         JR    NZ,INS_LOOP    ;Loop until done
  405. CLEAR_LINE    EQU    $
  406.         GET_CURSOR        ;Get the current row
  407. LINE_OPS_1    EQU    $
  408.         PUSH    HL        ;Save the row
  409.         LD    DE,SCR_BUFF    ;Get the buffer address
  410. R112        EQU    $-2
  411.         PUSH    DE        ;Save the buffer address
  412.         PUSH    DE        ;Copy the address into hl
  413.         POP    HL
  414.         INC    DE        ;Plus one for the copy
  415.         LD    BC,79        ;Copy 79 times
  416.         LD    (HL),' '    ;Store one blank
  417.         LDIR            ;Copy in the rest
  418.         POP    DE        ;Restore the buffer address
  419.         POP    HL        ;Restore the row
  420.         PUT_LINE        ;Put the line back
  421.         LD    A,14        ;Turn the cursor back on
  422.         JP    CHAIN_IN
  423. R113        EQU    $-2
  424. ;
  425. ;    Chain into any filters
  426. ;
  427. CHAIN        EQU    $
  428.         LD    A,(NEWCHAR)    ;Get the character sent to us
  429. R114        EQU    $-2
  430. CHAIN_IN    EQU    $
  431.         LD    C,A        ;Move the character to C for @PUT
  432.         LD    B,2        ;Signal @PUT for others in chain
  433.         OR    A        ;Reset the carry
  434.         CP    A        ;Set Z flag
  435. CHAIN_2        EQU    $
  436.         PUSH    IX        ;Save the old DCB address
  437.         LD    IX,(MODDCB)    ;Get the next in chain
  438. R115        EQU    $-2
  439.         LD    A,@CHNIO
  440.         RST    28H
  441.         POP    IX        ;Restore the old
  442. ;
  443. ;    Return without knowldege of the call to *DO
  444. ;
  445. RETOUT        EQU    $
  446.         LD    A,(NEWCHAR)    ;Get the character sent
  447. R125        EQU    $-2
  448.         CP    A        ;Set the Z flag
  449.         RET
  450. ;
  451. ;    Clear the screen
  452. ;
  453. CLEAR_SCREEN    EQU    $
  454.         LD    HL,0        ;Put the cursor at the top
  455.         PUT_CURSOR
  456.         JP    CLEAR_TO_EOS
  457. R126        EQU    $-2
  458. ;
  459. ;    Put the character in A on the screen at the current screen
  460. ;    position.  If insert mode is active, then perform the shift
  461. ;    of the line before chaining to *DO which will do the actual
  462. ;    displaying for us.
  463. ;
  464. INSERT_A    EQU    $
  465.         PUSH    AF        ;Save the character
  466.         GET_CURSOR        ;Get the cursor position
  467.         PUSH    HL        ;Save the cursor position
  468.         LD    A,(INSERT_FLAG)    ;Get the insert mode flag
  469. R116        EQU    $-2
  470.         OR    A        ;Is insert character mode on?
  471.         JR    Z,NO_MOVE    ;Jump if no insert character mode
  472.         LD    DE,SCR_BUFF    ;Get the buffer's address
  473. R117        EQU    $-2
  474.         GET_LINE        ;Get the line from the screen
  475.         LD    A,79        ;Get the maximum to move
  476.         SUB    L        ;Compute the number to move
  477.         LD    C,A        ;Make the byte, 16 bits in BC
  478.         LD    B,0        ;Zero the high byte for 16 bits
  479.         OR    A        ;Check if count is already zero
  480.         JR    Z,NO_MOVE    ;Skip if it is
  481.         LD    L,79        ;Get the end of the buffer
  482.         LD    H,0        ;    by adding 79 to the address
  483.         ADD    HL,DE        ;HL is now the end of the buffer
  484.         PUSH    DE        ;Save the buffer address
  485.         LD    E,L        ;Copy HL to DE
  486.         LD    D,H
  487.         DEC    HL        ;Decrement the source address
  488.         LDDR            ;Skoot the line over
  489.         POP    DE        ;Restore the buffer address
  490.         POP    HL        ;Restore the row to restore
  491.         PUT_LINE        ;Put it on the screen
  492.         PUSH    HL        ;Push something for the POP
  493. NO_MOVE        EQU    $
  494.         POP    HL        ;Restore the current row/col
  495.         POP    AF        ;Restore the character to insert
  496.         JP    CHAIN        ;Use *DO to display it
  497. R118        EQU    $-2
  498. ;
  499. ;        The default visual begin command is to change the cursor
  500. ;        to a block character
  501. ;
  502. VSTART        EQU    $
  503.         LD    B,8        ;Change cursor character
  504.         LD    A,(VSCUR)    ;Get the video start cursor
  505. R119        EQU    $-2
  506.         LD    C,A        ;Special graphics block
  507.         LD    A,@VDCTL
  508.         RST    28H
  509.         RET
  510. ;
  511. ;    This is the default call out for visual end.
  512. ;
  513. VEND        EQU    $
  514.         LD    B,8        ;Set the normal cursor character
  515.         LD    A,(VECUR)    ;Get the video end cursor
  516. R120        EQU    $-2
  517.         LD    C,A
  518.         LD    A,@VDCTL
  519.         RST    28H
  520.         RET            ;Return
  521. ;
  522. ;
  523. ;    Calculate address of Row and Column in HL
  524. ;
  525. GET_RC_ADDR    PUSH    BC
  526.         PUSH    AF
  527.         PUSH    DE
  528.         PUSH    HL        ;Copy the Row and Column to DE
  529.         POP    DE
  530.         LD    HL,0F800H    ;Get the start of the screen
  531.         LD    BC,80        ;One row is this long
  532. ADD_LOOP    DEC    D        ;Decrement the row count
  533.         JP    M,NO_MORE    ;If less than zero, no more rows
  534. R121        EQU    $-2
  535.         ADD    HL,BC        ;Add one more Row's worth
  536.         JR    ADD_LOOP    ;Go to the top of the loop
  537. NO_MORE        LD    D,0        ;Make it a 16 bit value
  538.         ADD    HL,DE        ;Add it into the total
  539.         POP    DE
  540.         POP    AF
  541.         POP    BC
  542.         RET            ;Return to caller
  543. ;
  544. ;    Calculate Row and Column based on address in HL
  545. ;
  546. GET_ADDR_RC    PUSH    BC        ;Save the registers
  547.         PUSH    AF
  548.         PUSH    DE
  549.         LD    BC,0F800H    ;Get the start of the screen
  550.         OR    A        ;Reset the carry flag
  551.         SBC    HL,BC        ;HL now is the offset into screen
  552.         LD    D,0        ;This is the counter
  553.         LD    BC,80        ;Get one rows worth
  554. SUB_LOOP    OR    A        ;Reset the carry
  555.         SBC    HL,BC        ;Subtract one rows worth
  556.         JP    C,NO_MORE_2    ;There are no more so leave
  557. R122        EQU    $-2
  558.         INC    D        ;Add one to the row count
  559.         JR    SUB_LOOP    ;Go to the top of the loop
  560. NO_MORE_2    ADD    HL,BC        ;Correct for the subtract
  561.         LD    H,D        ;Get the row count, L has the
  562.                     ;Column already in it
  563.         POP    DE        ;Restore the registers
  564.         POP    AF
  565.         POP    BC
  566.         RET            ;Return to the caller
  567. ;
  568. ;    Data storage area
  569. ;
  570. LASTPUSH    DW    PUSHAREA    ;Next place to push pos into
  571. R140        EQU    $-2
  572. PUSHAREA    DS    20        ;Storage area
  573. ENDPUSH        EQU    $        ;End of storage
  574. OLDSTATE    DW    0        ;Any preexisting state for
  575.                     ;special character sequences,
  576.                     ;actually, the address of the
  577.                     ;routine to execute the next time
  578.                     ;that a @PUT request is made.
  579. INSERT_FLAG    DB    0        ;Insert character mode flag
  580. DEL_FLAG    DB    0        ;Delete or Insert line direction
  581. CHAR_2        DB    0        ;Second character in a multiple
  582. ;                    ;character sequence.
  583. VIDEO_START    DW    VSTART        ;Call out address for visual begin
  584. R123        EQU    $-2
  585. VIDEO_END    DW    VEND        ;Call out address for visual end
  586. R124        EQU    $-2
  587. FLAG_ADDR    DW    0        ;Address of flags area
  588. GOTO_ROW    DB    0        ;Saved row for cursor motion
  589. SCR_BUFF    DS    81        ;Space for put_line and get_line
  590. NEWCHAR        DB    0        ;Character sent to @PUT request
  591. MODEND        EQU    $        ;End of the routine
  592. FLTR_LEN    EQU    MODEND-FILTER    ;This is the length
  593. INTRO        EQU    $
  594.         DB    'H19 Emulator-filter for TRSDOS 6.2. '
  595.         DB    'Written by:  Gregg Wonderly',29,26
  596.         DB    'Load address: ',3
  597. INTRO2        DB    '         Ending address: ',3
  598. STRING        DS    80
  599. FIRST        DW    0
  600. ;
  601. ;    Entry point of load routine.
  602. ;
  603. LOAD        EQU    $
  604.         LD    (MODDCB),DE    ;Save the DCB address
  605.         LD    A,@FLAGS    ;Get the Flags area address
  606.         RST    28H
  607.         LD    (FLAG_ADDR),IY    ;Save it away
  608.         LD    HL,INTRO    ;Print the intro message
  609.         LD    A,@DSPLY
  610.         RST    28H
  611.         LD    HL,0        ;Get HIGH MEMORY pointer from DOS
  612.         LD    B,0        ;B=0 selects HIGH$
  613.         LD    A,@HIGH$
  614.         RST    28H
  615.         LD    (OLDLOW),HL    ;Save it for later restoral
  616.         LD    (FILTER+2),HL
  617.         PUSH    HL
  618. ;
  619. ;    Since this filter accesses the video directly, we can not reside
  620. ;    up where it does.  Here we determine if there is suffient space
  621. ;    used to put us below the screen, or that we must waist memory,
  622. ;    and relocate to just below 0F400H.
  623. ;
  624.         LD    HL,0F3FEH    ;Get the highest usable address
  625.         POP    BC        ;Get the old HIGH memory
  626.         OR    A        ;Reset the carry bit
  627.         PUSH    HL        ;Save HL
  628.         SBC    HL,BC        ;See if hl is less than bc
  629.         POP    HL        ;Get HL back
  630.         JR    C,USE_HL    ;If C, then use HL's address
  631.         PUSH    BC        ;Move BC into HL
  632.         POP    HL
  633. USE_HL        EQU    $
  634.         INC    HL        ;Must increment for true value
  635.         LD    BC,FLTR_LEN    ;Get the length of the filter
  636.         OR    A        ;Reset the carry
  637.         SBC    HL,BC        ;Compute the new high
  638.         PUSH    HL        ;Save where to load at
  639.         DEC    HL        ;One below that is new high
  640.         LD    (OLDHIGH),HL    ;Save it for restore when removed
  641.         LD    B,0        ;Select HIGH$
  642.         LD    A,@HIGH$
  643.         RST    28H
  644. RELOCATE    EQU    $
  645. ;
  646. ;    THIS ROUTINE WILL MOVE THE FILTER, UP INTO HIGH MEMORY AND
  647. ;    RESET THE POINTER TO HIGH$
  648. ;
  649.         POP    DE        ;Get the load address
  650.         LD    (FIRST),DE    ;Save it for later
  651.         LD    HL,STRING    ;Get the scratch area
  652.         PUSH    HL        ;Save the address for @DSPLY
  653.         LD    A,@HEX16    ;Convert DE to 4 HEX digits (HL)
  654.         RST    28H
  655.         LD    (HL),3        ;Terminate with ETX
  656.         POP    HL        ;Get the start
  657.         LD    A,@DSPLY    ;Display it
  658.         RST    28H
  659.         LD    HL,(FIRST)    ;Get the starting reloc address
  660.         LD    BC,FILTER    ;Calculate offset from source
  661.         OR    A        ;Reset the carry
  662.         PUSH    HL        ;Save it
  663.         SBC    HL,BC        ;Offset now in HL
  664.         LD    (OFFSET),HL    ;Save it for later reference
  665.         POP    HL        ;Get the load address into hl
  666.         LD    BC,FLTR_LEN    ;Calculate the end
  667.         ADD    HL,BC        ;HL now has the ending address
  668.         PUSH    HL        ;Save it for transfer to DE
  669.         LD    HL,INTRO2    ;Get the message string
  670.         LD    A,@DSPLY    ;Display it
  671.         RST    28H
  672.         POP    DE        ;Get the ending address
  673.         LD    HL,STRING    ;Get the string buffer
  674.         PUSH    HL        ;Save the address for later
  675.         LD    A,@HEX16    ;Convert DE to 4 HEX digits (HL)
  676.         RST    28H
  677.         LD    (HL),13        ;Put a carriage return on the end
  678.         POP    HL        ;Get the starting address back
  679.         LD    A,@DSPLY    ;Display the VALUE
  680.         RST    28H
  681.         LD    IX,OFFTBL    ;Get start of offset table
  682. ;
  683. ;    LOOP TO ADD OFFSET TO ALL ADDRESSES NECESSARY
  684. ;
  685. MOVNXT        EQU    $
  686.         LD    BC,(OFFSET)    ;Put the offset into BC
  687.         LD    L,(IX)        ;Get LSB of address to change
  688.         INC    IX        ;POINT TO MSB
  689.         LD    H,(IX)        ;GET IT
  690.         INC    IX        ;POINT TO LSB OF NEXT, OR END
  691.         PUSH    IX        ;Save pointer to table
  692.         PUSH    HL        ;Put the address into IX
  693.         POP    IX
  694.         LD    L,(IX)        ;Get the LSB for relocation
  695.         LD    H,(IX+1)    ;Get the MSB
  696.         ADD    HL,BC        ;Relocate it
  697.         LD    (IX),L        ;Put it back
  698.         LD    (IX+1),H
  699.         POP    BC        ;Get the table address in BC
  700.         PUSH    BC        ;Copy it back into IX
  701.         POP    IX        ;Restore the table address
  702.         LD    HL,OFFEND    ;Get the end of the offset table
  703.         OR    A        ;Reset the carry
  704.         SBC    HL,BC        ;Compute the difference
  705.         JR    NZ,MOVNXT    ;Loop, if not done
  706. ;
  707.         LD    BC,FLTR_LEN    ;MOVE MODULE INTO HIGH MEMORY.
  708.         LD    DE,(FIRST)
  709.         LD    HL,FILTER    ;Get the load address
  710.         LDIR            ;Move it into place
  711.         LD    IX,(MODDCB)    ;Get the dcb address back
  712.         LD    DE,(FIRST)
  713.         LD    (IX),47H    ;Say we are a filter
  714.         LD    (IX+1),E    ;Tell where the filter starts
  715.         LD    (IX+2),D
  716.         LD    HL,0
  717.         CP    A
  718.         RET
  719. ;
  720. OFFTBL        EQU    $
  721.         DW    R001
  722.         DW    R002
  723.         DW    R003
  724.         DW    R004
  725.         DW    R005
  726.         DW    R006
  727.         DW    R007
  728.         DW    R008
  729.         DW    R009
  730.         DW    R010
  731.         DW    R011
  732.         DW    R012
  733.         DW    R013
  734.         DW    R014
  735.         DW    R015
  736.         DW    R016
  737.         DW    R017
  738.         DW    R018
  739.         DW    R019
  740.         DW    R020
  741.         DW    R021
  742.         DW    R022
  743.         DW    R023
  744.         DW    R024
  745.         DW    R025
  746.         DW    R026
  747.         DW    R027
  748.         DW    R028
  749.         DW    R029
  750.         DW    R030
  751.         DW    R031
  752.         DW    R032
  753.         DW    R033
  754.         DW    R034
  755.         DW    R035
  756.         DW    R036
  757.         DW    R037
  758.         DW    R038
  759.         DW    R039
  760.         DW    R040
  761.         DW    R041
  762.         DW    R042
  763.         DW    R043
  764.         DW    R044
  765.         DW    R045
  766.         DW    R046
  767.         DW    R047
  768.         DW    R048
  769.         DW    R049
  770.         DW    R050
  771.         DW    R051
  772.         DW    R052
  773.         DW    R053
  774.         DW    R054
  775.         DW    R055
  776.         DW    R056
  777.         DW    R057
  778.         DW    R058
  779.         DW    R059
  780.         DW    R060
  781.         DW    R061
  782.         DW    R062
  783.         DW    R063
  784.         DW    R064
  785.         DW    R065
  786.         DW    R066
  787.         DW    R067
  788.         DW    R068
  789.         DW    R069
  790.         DW    R070
  791.         DW    R071
  792.         DW    R072
  793.         DW    R073
  794.         DW    R074
  795.         DW    R075
  796.         DW    R076
  797.         DW    R077
  798.         DW    R078
  799.         DW    R079
  800.         DW    R080
  801.         DW    R081
  802.         DW    R082
  803.         DW    R083
  804.         DW    R084
  805.         DW    R085
  806.         DW    R086
  807.         DW    R087
  808.         DW    R088
  809.         DW    R089
  810.         DW    R090
  811.         DW    R091
  812.         DW    R092
  813.         DW    R093
  814.         DW    R094
  815.         DW    R095
  816.         DW    R096
  817.         DW    R097
  818.         DW    R098
  819.         DW    R099
  820.         DW    R100
  821.         DW    R101
  822.         DW    R102
  823.         DW    R103
  824.         DW    R104
  825.         DW    R105
  826.         DW    R106
  827.         DW    R107
  828.         DW    R108
  829.         DW    R109
  830.         DW    R110
  831.         DW    R111
  832.         DW    R112
  833.         DW    R113
  834.         DW    R114
  835.         DW    R115
  836.         DW    R116
  837.         DW    R117
  838.         DW    R118
  839.         DW    R119
  840.         DW    R120
  841.         DW    R121
  842.         DW    R122
  843.         DW    R123
  844.         DW    R124
  845.         DW    R125
  846.         DW    R126
  847.         DW    R127
  848.         DW    R128
  849.         DW    R129
  850.         DW    R130
  851.         DW    R131
  852.         DW    R132
  853.         DW    R133
  854.         DW    R134
  855.         DW    R135
  856.         DW    R136
  857.         DW    R137
  858.         DW    R138
  859.         DW    R139
  860.         DW    R140
  861.         DW    R141
  862.         DW    R142
  863.         DW    R143
  864.         DW    R144
  865.         DW    R145
  866.         DW    R146
  867.         DW    R147
  868.         DW    R148
  869.         DW    R149
  870.         DW    R150
  871.         DW    R151
  872.         DW    R152
  873.         DW    R153
  874.         DW    R154
  875.         DW    R155
  876.         DW    R156
  877.         DW    R157
  878.         DW    R158
  879.         DW    R159
  880.         DW    R160
  881.         DW    R161
  882.         DW    R162
  883.         DW    R163
  884.         DW    R164
  885.         DW    R165
  886.         DW    R166
  887.         DW    R167
  888.         DW    R168
  889.         DW    R169
  890.         DW    R170
  891.         DW    R171
  892.         DW    R172
  893.         DW    R173
  894.         DW    R174
  895.         DW    R175
  896.         DW    R176
  897.         DW    R177
  898.         DW    R178
  899.         DW    R179
  900.         DW    R180
  901.         DW    R181
  902.         DW    R182
  903.         DW    R183
  904.         DW    R184
  905.         DW    R185
  906.         DW    R186
  907.         DW    R187
  908.         DW    R188
  909.         DW    R189
  910.         DW    R190
  911.         DW    R191
  912. OFFEND        EQU    $
  913.