home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK5 / DOS_42 / SHOWVECT.ZIP / SHOWVECT.ASM next >
Assembly Source File  |  1992-03-20  |  25KB  |  881 lines

  1. ;-----------------------------------------------------------------------;
  2. ; Show-Vectors, Version 1.00, Copyright (c) 1992 SoftCircuits        ;
  3. ; Redistributed by permission.                        ;
  4. ;                                    ;
  5. ; Created by:                                ;
  6. ;                                    ;
  7. ;    SoftCircuits Programming                    ;
  8. ;    P.O. Box 16262                            ;
  9. ;    Irvine, CA 92714                        ;
  10. ;                                    ;
  11. ; Revision History:                            ;
  12. ; 03/06/92    JBW    Original version                ;
  13. ;-----------------------------------------------------------------------;
  14.  
  15. _TEXT    SEGMENT    PUBLIC
  16.     ASSUME    cs:_TEXT,ds:_TEXT,ss:_TEXT
  17.  
  18.     ORG    100h            ;.COM program
  19.  
  20. start:    jmp    main            ;Jump past data
  21.  
  22. copyright    DB    "Show-Vectors, Version 1.00, "
  23.         DB    "Copyright (c) 1992 SoftCircuits",0
  24. header        DB    " Int  Vector Address  Description",0
  25. status        DB    " <",18h,"> <",19h,"> <PgUp> <PgDn> "
  26.         DB    "<Home> <End>    <Esc>=Exit ",0B3h
  27.         DB    " Redistributed by permission",0
  28.  
  29. start_line    DW    00h        ;Int # for first line of display
  30.  
  31. display_rows    DB    25        ;Display variables
  32. display_columns    DB    80
  33. display_address    LABEL    DWORD        ;Display address
  34. display_offset    DW    0000h        ; Offset (logical cursor)
  35. display_segment    DW    0B000h        ; Segment
  36. display_page    DB    00h        ;Current display page
  37. is_color    DB    00h        ;01h if system supports color
  38. snow_check    DB    00h        ;01h if CGA adapter
  39.  
  40. display_color    DB    07h        ;Main information window color
  41. copyright_color    DB    70h        ;Copyright bar color (1st row)
  42. header_color    DB    70h        ;Column headers color (2nd row)
  43. status_color    DB    70h        ;Status color (bottom row)
  44.  
  45. command_table    DW    4800h,OFFSET line_up
  46.         DW    5000h,OFFSET line_down
  47.         DW    4900h,OFFSET page_up
  48.         DW    5100h,OFFSET page_down
  49.         DW    4700h,OFFSET jump_home
  50.         DW    4F00h,OFFSET jump_end
  51.         DW    0000h        ;Indicates end of table
  52.  
  53. MSG_00        DB    "Divide overflow",0
  54. MSG_01        DB    "Single step",0
  55. MSG_02        DB    "Non-maskable interrupt",0
  56. MSG_03        DB    "Breakpoint",0
  57. MSG_04        DB    "Overflow",0
  58. MSG_05        DB    "ROM BIOS print screen",0
  59. MSG_06        DB    "Reserved",0
  60. MSG_08        DB    "IRQ0-System timer",0
  61. MSG_09        DB    "IRQ1-Keyboard",0
  62. MSG_0A        DB    "IRQ2-Reserved",0
  63. MSG_0B        DB    "IRQ3-Reserved",0
  64. MSG_0C        DB    "IRQ4-Reserved",0
  65. MSG_0D        DB    "IRQ5-Reserved",0
  66. MSG_0E        DB    "IRQ6-Floppy disk",0
  67. MSG_0F        DB    "IRQ7-Reserved",0
  68. MSG_10        DB    "ROM BIOS Video services",0
  69. MSG_11        DB    "ROM BIOS Equipment determination",0
  70. MSG_12        DB    "ROM BIOS Memory-size service",0
  71. MSG_13        DB    "ROM BIOS Disk services",0
  72. MSG_14        DB    "ROM BIOS Communication services",0
  73. MSG_15        DB    "ROM BIOS Miscellaneous services",0
  74. MSG_16        DB    "ROM BIOS Keyboard services",0
  75. MSG_17        DB    "ROM BIOS Printer services",0
  76. MSG_18        DB    "ROM BASIC",0
  77. MSG_19        DB    "ROM BIOS Bootstrap",0
  78. MSG_1A        DB    "ROM BIOS Time-of-day service",0
  79. MSG_1B        DB    "ROM BIOS Ctrl-Break handler",0
  80. MSG_1C        DB    "ROM BIOS Timer tick",0
  81. MSG_1D        DB    "ROM BIOS Video parameter table",0
  82. MSG_1E        DB    "ROM BIOS Floppy disk parameters",0
  83. MSG_1F        DB    "ROM BIOS Font (characters 80H-FFH)",0
  84. MSG_20        DB    "MS-DOS Process termination",0
  85. MSG_21        DB    "MS-DOS General services",0
  86. MSG_22        DB    "MS-DOS Terminate address",0
  87. MSG_23        DB    "MS-DOS Ctrl-C handler",0
  88. MSG_24        DB    "MS-DOS Critical error handler",0
  89. MSG_25        DB    "MS-DOS Absolute disk read service",0
  90. MSG_26        DB    "MS-DOS Absolute disk write service",0
  91. MSG_27        DB    "MS-DOS Terminate and stay resident service",0
  92. MSG_28        DB    "MS-DOS Idle interrupt",0
  93. MSG_29        DB    "MS-DOS Reserved",0
  94. MSG_2F        DB    "MS-DOS Multiplex interrupt",0
  95. MSG_33        DB    "Mouse driver",0
  96. MSG_40        DB    "ROM BIOS Floppy-disk driver (if fixed disk"
  97.         DB    " installed)",0
  98. MSG_41        DB    "ROM BIOS Fixed disk parameters",0
  99. MSG_42        DB    "ROM BIOS Default video driver (if EGA installed)",0
  100. MSG_43        DB    "EGA, MCGA, VGA character table",0
  101. MSG_44        DB    "ROM BIOS Font (characters 00H-7FH)",0
  102. MSG_46        DB    "ROM BIOS Fixed disk parameters (drive 1)",0
  103. MSG_4A        DB    "ROM BIOS Alarm handler",0
  104. MSG_60        DB    "User interrupts",0
  105. MSG_67        DB    "Expanded memory driver",0
  106. MSG_70        DB    "IRQ8 CMOS real-time clock",0
  107. MSG_71        DB    "IRQ9-Reserved",0
  108. MSG_72        DB    "IRQ10-Reserved",0
  109. MSG_73        DB    "IRQ11-Reserved",0
  110. MSG_74        DB    "IRQ12-Reserved",0
  111. MSG_75        DB    "IRQ13-Reserved",0
  112. MSG_76        DB    "IRQ14-Reserved",0
  113. MSG_77        DB    "IRQ15-Reserved",0
  114. MSG_80        DB    "Reserved for BASIC",0
  115.  
  116. descript_table    LABEL    WORD
  117.     ;00h-0Fh
  118.     DW    OFFSET MSG_00,OFFSET MSG_01,OFFSET MSG_02,OFFSET MSG_03
  119.     DW    OFFSET MSG_04,OFFSET MSG_05,OFFSET MSG_06,OFFSET MSG_06
  120.     DW    OFFSET MSG_08,OFFSET MSG_09,OFFSET MSG_0A,OFFSET MSG_0B
  121.     DW    OFFSET MSG_0C,OFFSET MSG_0D,OFFSET MSG_0E,OFFSET MSG_0F
  122.     ;10h-1Fh
  123.     DW    OFFSET MSG_10,OFFSET MSG_11,OFFSET MSG_12,OFFSET MSG_13
  124.     DW    OFFSET MSG_14,OFFSET MSG_15,OFFSET MSG_16,OFFSET MSG_17
  125.     DW    OFFSET MSG_18,OFFSET MSG_19,OFFSET MSG_1A,OFFSET MSG_1B
  126.     DW    OFFSET MSG_1C,OFFSET MSG_1D,OFFSET MSG_1E,OFFSET MSG_1F
  127.     ;20h-2Fh
  128.     DW    OFFSET MSG_20,OFFSET MSG_21,OFFSET MSG_22,OFFSET MSG_23
  129.     DW    OFFSET MSG_24,OFFSET MSG_25,OFFSET MSG_26,OFFSET MSG_27
  130.     DW    OFFSET MSG_28,OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29
  131.     DW    OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_2F
  132.     ;30h-3Fh
  133.     DW    OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_33
  134.     DW    OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29
  135.     DW    OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29
  136.     DW    OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29,OFFSET MSG_29
  137.     ;40h-4Fh
  138.     DW    OFFSET MSG_40,OFFSET MSG_41,OFFSET MSG_42,OFFSET MSG_43
  139.     DW    OFFSET MSG_44,OFFSET MSG_06,OFFSET MSG_46,OFFSET MSG_06
  140.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_4A,OFFSET MSG_06
  141.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  142.     ;50h-5Fh
  143.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  144.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  145.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  146.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  147.     ;60h-6Fh
  148.     DW    OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60
  149.     DW    OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_67
  150.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  151.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  152.     ;70-7Fh
  153.     DW    OFFSET MSG_70,OFFSET MSG_71,OFFSET MSG_72,OFFSET MSG_73
  154.     DW    OFFSET MSG_74,OFFSET MSG_75,OFFSET MSG_76,OFFSET MSG_77
  155.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  156.     DW    OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06,OFFSET MSG_06
  157.     ;80h-80h
  158.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  159.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  160.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  161.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  162.     ;90h-9Fh
  163.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  164.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  165.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  166.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  167.     ;A0h-AFh
  168.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  169.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  170.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  171.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  172.     ;B0h-BFh
  173.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  174.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  175.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  176.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  177.     ;C0h-CFh
  178.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  179.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  180.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  181.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  182.     ;D0h-DFh
  183.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  184.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  185.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  186.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  187.     ;E0h-EFh
  188.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  189.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  190.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  191.     DW    OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80,OFFSET MSG_80
  192.     ;F0h-FFh
  193.     DW    OFFSET MSG_80,OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60
  194.     DW    OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60
  195.     DW    OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60
  196.     DW    OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60,OFFSET MSG_60
  197.  
  198. ;-----------------------------------------------------------------------;
  199.  
  200. main:
  201.     call    init_display        ;Initialize display
  202. main_loop:
  203.     call    get_key            ;Read next available keystroke
  204.     cmp    ax,011Bh        ;Was Esc pressed?
  205.     je    end_program        ;Yes, exit
  206.     mov    bx,OFFSET command_table    ;Else use bx to index command table
  207. scan_loop:
  208.     cmp    [bx],ax            ;Does keystroke match this entry?
  209.     je    handle_command        ;Yes, process this command
  210.     add    bx,4            ;Else bump bx to next entry
  211.     cmp    WORD PTR [bx],0000h    ;End of table?
  212.     jne    scan_loop        ;No
  213.     call    beep            ;Else sound error
  214.     jmp    main_loop        ;Get next command
  215. handle_command:
  216.     call    flush_kbd        ;Discard any additional keystrokes
  217.     call    WORD PTR [bx+0002h]    ;Call handler for this command
  218.     jmp    main_loop        ;Go back for next keystroke
  219. end_program:
  220.     mov    bh,07h            ;Restore screen
  221.     call    clear_screen
  222.     sub    dx,dx
  223.     call    set_text_cursor
  224.     mov    ax,4C00h        ;Terminate
  225.     int    21h
  226.  
  227. ;-----------------------------------------------------------------------;
  228. ; Moves the display up 1 line.                        ;
  229. ;-----------------------------------------------------------------------;
  230. line_up        PROC
  231.     push    ax
  232.     push    cx
  233.     push    dx
  234.     cmp    start_line,0        ;Are we already home?
  235.     je    end_line_up        ;Yes, ignore request
  236.     dec    start_line        ;Else move up 1 line
  237.     mov    al,-1            ;Negative scroll
  238.     call    scroll_page
  239.     mov    dh,2            ;Display new line
  240.     mov    cx,start_line
  241.     call    paint_line
  242. end_line_up:
  243.     pop    dx
  244.     pop    cx
  245.     pop    ax
  246.     ret
  247. line_up        ENDP
  248.  
  249. ;-----------------------------------------------------------------------;
  250. ; Moves the display down 1 line.                    ;
  251. ;-----------------------------------------------------------------------;
  252. line_down    PROC
  253.     push    ax
  254.     push    cx
  255.     push    dx
  256.     mov    al,display_rows        ;Calculate maximum start vector
  257.     sub    al,3
  258.     neg    al
  259.     sub    ah,ah
  260.     cmp    start_line,ax        ;Are we already at end?
  261.     je    end_line_down        ;Yes, ignore request
  262.     inc    start_line        ;Else move down 1 line
  263.     mov    al,01h            ;Positive scroll
  264.     call    scroll_page
  265.     mov    dh,display_rows        ;Display new bottom row
  266.     sub    dh,02h
  267.     mov    cx,start_line
  268.     add    cl,dh
  269.     sub    cl,2
  270.     call    paint_line        ;Display new line
  271. end_line_down:
  272.     pop    dx
  273.     pop    cx
  274.     pop    ax
  275.     ret
  276. line_down    ENDP
  277.  
  278. ;-----------------------------------------------------------------------;
  279. ; Moves the display up 1 page.                        ;
  280. ;-----------------------------------------------------------------------;
  281. page_up        PROC
  282.     push    ax
  283.     push    dx
  284.     cmp    start_line,0        ;Are we already home?
  285.     je    end_page_up        ;Yes, ignore request
  286.     mov    dl,display_rows        ;Else move up 1 page
  287.     sub    dl,3
  288.     sub    dh,dh
  289.     sub    start_line,dx
  290.     jnc    show_page_up
  291.     mov    start_line,0
  292. show_page_up:
  293.     call    paint_page        ;Update display
  294. end_page_up:
  295.     pop    dx
  296.     pop    ax
  297.     ret
  298. page_up        ENDP
  299.  
  300. ;-----------------------------------------------------------------------;
  301. ; Moves the display down 1 page.                    ;
  302. ;-----------------------------------------------------------------------;
  303. page_down    PROC
  304.     push    ax
  305.     push    dx
  306.     mov    dl,display_rows        ;Calculate maximum start vector
  307.     sub    dl,3
  308.     sub    dh,dh
  309.     mov    ax,dx
  310.     neg    al
  311.     cmp    start_line,ax        ;Are we already at end?
  312.     je    end_page_down        ;Yes, ignore request
  313.     add    start_line,dx        ;Else move down 1 page
  314.     cmp    start_line,ax
  315.     jna    show_page_down
  316.     mov    start_line,ax
  317. show_page_down:
  318.     call    paint_page        ;Update display
  319. end_page_down:
  320.     pop    dx
  321.     pop    ax
  322.     ret
  323. page_down    ENDP
  324.  
  325. ;-----------------------------------------------------------------------;
  326. ; Moves the display to the first page.                    ;
  327. ;-----------------------------------------------------------------------;
  328. jump_home    PROC
  329.     cmp    start_line,0        ;Are we already home?
  330.     je    end_jump_home        ;Yes, ignore request
  331.     mov    start_line,0        ;Else move home
  332.     call    paint_page        ;Update display
  333. end_jump_home:
  334.     ret
  335. jump_home    ENDP
  336.  
  337. ;-----------------------------------------------------------------------;
  338. ; Moves the display to the last page.                    ;
  339. ;-----------------------------------------------------------------------;
  340. jump_end    PROC
  341.     push    ax
  342.     mov    al,display_rows        ;Calculate maximum start vector
  343.     sub    al,3
  344.     neg    al
  345.     sub    ah,ah
  346.     cmp    start_line,ax        ;Are we already at end?
  347.     je    end_jump_end        ;Yes, ignore request
  348.     mov    start_line,ax        ;Else move to end
  349.     call    paint_page        ;Update display
  350. end_jump_end:
  351.     pop    ax
  352.     ret
  353. jump_end    ENDP
  354.  
  355. ;-----------------------------------------------------------------------;
  356. ; Prints a screen full of information.                    ;
  357. ;-----------------------------------------------------------------------;
  358. paint_page    PROC
  359.     push    cx
  360.     push    dx
  361.     mov    dh,02h            ;Starting row number
  362.     mov    dl,display_rows        ;Ending row number
  363.     dec    dl
  364.     mov    cx,start_line        ;Interrupt for first line
  365. page_loop:
  366.     call    paint_line        ;Display 1 line
  367.     inc    cx            ;Next interrupt vector
  368.     inc    dh            ;Next row
  369.     cmp    dh,dl            ;Screen full?
  370.     jb    page_loop        ;No, do it again
  371.     pop    dx
  372.     pop    cx
  373.     ret
  374. paint_page    ENDP
  375.  
  376. ;-----------------------------------------------------------------------;
  377. ; Paints one line of information to the display.            ;
  378. ;                                    ;
  379. ;    Input:    dh    Screen row.                    ;
  380. ;        cx    Interrupt number.                ;
  381. ;                                    ;
  382. ;-----------------------------------------------------------------------;
  383. paint_line    PROC
  384.     push    ax
  385.     push    bx
  386.     push    dx
  387.     push    si
  388.     mov    bh,display_color    ;Select color attribute
  389.     mov    dl,1            ;Set starting column
  390.     call    set_cursor
  391.     mov    dx,cx            ;Write interrupt number
  392.     call    write_hex
  393.     call    get_cursor        ;Put spaces between int# and vector
  394.     add    dl,4
  395.     call    set_cursor
  396.     call    get_vector        ;Get vector for interrupt in cx
  397.     call    write_hex        ;Write segment in dx
  398.     push    cx            ;Preserve interrupt number
  399.     mov    dl,':'            ;Write ':'
  400.     mov    cx,01h
  401.     call    write_char
  402.     pop    cx
  403.     mov    dx,ax            ;Write offset in ax
  404.     call    write_hex
  405.     call    get_cursor        ;Put spaces between vector and
  406.     add    dx,4            ; description
  407.     call    set_cursor
  408.     mov    si,cx            ;Write description
  409.     shl    si,1
  410.     mov    dx,descript_table[si]
  411.     call    write_string
  412.     call    clear_eol        ;Clear to end of line
  413.     pop    si
  414.     pop    dx
  415.     pop    bx
  416.     pop    ax
  417.     ret
  418. paint_line    ENDP
  419.  
  420. ;-----------------------------------------------------------------------;
  421. ; Returns the interrupt vector address for the given interrupt.        ;
  422. ;                                    ;
  423. ;    Input:    cx    Interrupt number.                ;
  424. ;                                    ;
  425. ;    Output:    dx:ax    Segment:offset of interrupt vector.        ;
  426. ;                                    ;
  427. ;-----------------------------------------------------------------------;
  428. get_vector    PROC
  429.     push    bx
  430.     push    es
  431.     sub    bx,bx            ;Read from 0000:(int x 4)
  432.     mov    es,bx
  433.     mov    bx,cx
  434.     shl    bx,1
  435.     shl    bx,1
  436.     mov    dx,es:[bx+02h]        ;Segment in dx
  437.     mov    ax,es:[bx+00h]        ;Offset in ax
  438.     pop    es
  439.     pop    bx
  440.     ret
  441. get_vector    ENDP
  442.  
  443. ;-----------------------------------------------------------------------;
  444. ; Writes a null-terminated string to the display.            ;
  445. ;                                    ;
  446. ;    Input:    ds:dx    String address.                    ;
  447. ;        bh    Color attribute                    ;
  448. ;                                    ;
  449. ;-----------------------------------------------------------------------;
  450. write_string    PROC
  451.     push    ax
  452.     push    cx
  453.     push    dx
  454.     push    si
  455.     pushf
  456.     cld
  457.     mov    cx,01h            ;Write 1 copy of each character
  458.     mov    si,dx
  459. string_loop:
  460.     lodsb
  461.     or    al,al
  462.     jz    end_write_string
  463.     mov    dl,al
  464.     call    write_char
  465.     jmp    string_loop
  466. end_write_string:
  467.     popf
  468.     pop    si
  469.     pop    dx
  470.     pop    cx
  471.     pop    ax
  472.     ret
  473. write_string    ENDP
  474.  
  475. ;-----------------------------------------------------------------------;
  476. ; Writes a 16-bit value to the screen in hexadecimal format.        ;
  477. ;                                    ;
  478. ;    Input:    dx    16-bit value                    ;
  479. ;        bh    Color attribute.                ;
  480. ;                                    ;
  481. ;-----------------------------------------------------------------------;
  482. write_hex    PROC
  483.     push    cx
  484.     push    dx
  485.     mov    cx,4
  486. hex_loop:
  487.     rol    dx,1            ;Move next digit to low nibble
  488.     rol    dx,1
  489.     rol    dx,1
  490.     rol    dx,1
  491.     call    write_hex_char        ;Write this digit
  492.     loop    hex_loop        ;Repeat for each digit
  493.     pop    dx
  494.     pop    cx
  495.     ret
  496. write_hex    ENDP
  497.  
  498. ;-----------------------------------------------------------------------;
  499. ; Writes a 4-bit number to the screen in hexadecimal format.        ;
  500. ;                                    ;
  501. ;    Input:    dl    Lower nibble contains 4-bit number.        ;
  502. ;        bh    Color attribute.                ;
  503. ;                                    ;
  504. ;-----------------------------------------------------------------------;
  505. write_hex_char    PROC
  506.     push    cx
  507.     push    dx
  508.     and    dl,0Fh            ;Isolate lower nibble
  509.     or    dl,30h            ;Convert to ASCII
  510.     cmp    dl,'9'            ;Will a decimal digit suffice?
  511.     jna    hex_char_ready        ;Yes
  512.     add    dl,07h            ;Else adjust for 'A'-'F'
  513. hex_char_ready:
  514.     mov    cx,01h            ;Write 1 copy of digit
  515.     call    write_char
  516.     pop    dx
  517.     pop    cx
  518.     ret
  519. write_hex_char    ENDP
  520.  
  521. ;-----------------------------------------------------------------------;
  522. ; Writes a single character to the display.                ;
  523. ;                                    ;
  524. ;    Input:    dl    Character to write.                ;
  525. ;        bh    Color attribute.                ;
  526. ;        cx    Number of times to print character.        ;
  527. ;                                    ;
  528. ;-----------------------------------------------------------------------;
  529. write_char    PROC
  530.     push    ax
  531.     push    bx
  532.     push    cx
  533.     push    dx
  534.     push    di
  535.     push    es
  536.     jcxz    end_write_char        ;Don't try to write 0 times
  537.     mov    bl,dl            ;bl = character, bh = color
  538.     les    di,display_address    ;es:di = screen address
  539.     cmp    snow_check,0        ;Are we testing video retrace?
  540.     je    direct_write        ;No, write direct
  541.     mov    dx,03DAh        ;dx = video status port address
  542. snow_write:
  543.     cli                ;Disable interrupts
  544. wait_low:
  545.     in    al,dx            ;Make sure the video controller scan
  546.     shr    al,1            ; status is low
  547.     jc    wait_low
  548. wait_high:
  549.     in    al,dx            ;After port has gone low, it must go
  550.     shr    al,1            ; high before it is safe to write
  551.     jnc    wait_high        ; directly to screen memory
  552.     mov    es:[di],bx        ;Write character/attribute to screen
  553.     sti                ;Enable interrupts
  554.     add    di,02h
  555.     loop    snow_write
  556.     jmp    end_write_char
  557. direct_write:
  558.     mov    ax,bx
  559.     rep    stosw
  560. end_write_char:
  561.     mov    display_offset,di    ;Update display offset
  562.     pop    es
  563.     pop    di
  564.     pop    dx
  565.     pop    cx
  566.     pop    bx
  567.     pop    ax
  568.     ret
  569. write_char    ENDP
  570.  
  571. ;-----------------------------------------------------------------------;
  572. ; Writes spaces from the current cursor location to the end of the line    ;
  573. ; using the current display attribute.                    ;
  574. ;                                    ;
  575. ;    Input:    bh    Color attribute.                ;
  576. ;                                    ;
  577. ;-----------------------------------------------------------------------;
  578. clear_eol    PROC
  579.     push    cx
  580.     push    dx
  581.     mov    cl,display_columns
  582.     call    get_cursor
  583.     sub    cl,dl
  584.     jbe    end_clear_eol        ;Exit if already at end of line
  585.     mov    dl,' '            ;Write spaces
  586.     call    write_char
  587. end_clear_eol:
  588.     pop    dx
  589.     pop    cx
  590.     ret
  591. clear_eol    ENDP
  592.  
  593. ;-----------------------------------------------------------------------;
  594. ; Clears the entire screen.                        ;
  595. ;                                    ;
  596. ;    Input:    bh    Color attribute                    ;
  597. ;                                    ;
  598. ;-----------------------------------------------------------------------;
  599. clear_screen    PROC
  600.     push    ax
  601.     push    cx
  602.     push    dx
  603.     sub    al,al
  604.     mov    ch,00h
  605.     mov    dh,display_rows
  606.     dec    dh
  607.     mov    cl,00h
  608.     mov    dl,display_columns
  609.     dec    dl
  610.     call    scroll
  611.     pop    dx
  612.     pop    cx
  613.     pop    ax
  614.     ret
  615. clear_screen    ENDP
  616.  
  617. ;-----------------------------------------------------------------------;
  618. ; Scrolls the information area of the display. This procedure is used    ;
  619. ; by the scrolling/position routines.                    ;
  620. ;                                    ;
  621. ;    Input:    al    Scroll type (see scroll).            ;
  622. ;                                    ;
  623. ;-----------------------------------------------------------------------;
  624. scroll_page    PROC
  625.     push    bx
  626.     push    cx
  627.     push    dx
  628.     mov    bh,display_color    ;Use information area color
  629.     mov    ch,02h            ;Get information area coordinates
  630.     mov    dh,display_rows
  631.     sub    dh,02h
  632.     mov    cl,00h
  633.     mov    dl,display_columns
  634.     dec    dl
  635.     call    scroll            ;Do scroll
  636.     pop    dx
  637.     pop    cx
  638.     pop    bx
  639.     ret
  640. scroll_page    ENDP
  641.  
  642. ;-----------------------------------------------------------------------;
  643. ; Scrolls or clears an area of the display.                ;
  644. ;                                    ;
  645. ;    Input:    al    Number of lines to scroll. Positive numbers    ;
  646. ;            scroll up, negative numbers scroll down, 0    ;
  647. ;            clears the window.                ;
  648. ;        bh    Color attribute.                ;
  649. ;        ch    Top row.                    ;
  650. ;        dh    Bottom row.                    ;
  651. ;        cl    Left column.                    ;
  652. ;        dl    Right column.                    ;
  653. ;                                    ;
  654. ;-----------------------------------------------------------------------;
  655. scroll        PROC
  656.     push    ax
  657.     push    bx
  658.     push    si
  659.     push    di
  660.     push    bp
  661.     mov    ah,06h
  662.     cmp    al,00h
  663.     jge    scroll_ready
  664.     mov    ah,07h
  665.     neg    al
  666. scroll_ready:
  667.     int    10h            ;Call ROM BIOS
  668.     pop    bp
  669.     pop    di
  670.     pop    si
  671.     pop    bx
  672.     pop    ax
  673.     ret
  674. scroll        ENDP
  675.  
  676. ;-----------------------------------------------------------------------;
  677. ; Sets the logical write position.                    ;
  678. ;                                    ;
  679. ;    Input:    dh    Row coordinate (0-based)            ;
  680. ;        dl    Column coordinate (0-based)            ;
  681. ;                                    ;
  682. ;-----------------------------------------------------------------------;
  683. set_cursor    PROC
  684.     push    ax
  685.     push    dx
  686.     mov    al,dh            ;Multiply row by number of columns
  687.     mul    display_columns
  688.     sub    dh,dh            ;Add column
  689.     add    ax,dx
  690.     shl    ax,1            ;Adjust for attribute bytes
  691.     mov    display_offset,ax    ;Set video offset
  692.     pop    dx
  693.     pop    ax
  694.     ret
  695. set_cursor    ENDP
  696.  
  697. ;-----------------------------------------------------------------------;
  698. ; Returns the logical write position.                    ;
  699. ;                                    ;
  700. ;    Output:    dh    Row coordinate (0-based)            ;
  701. ;        dl    Column coordinate (0-based)            ;
  702. ;                                    ;
  703. ;-----------------------------------------------------------------------;
  704. get_cursor    PROC
  705.     push    ax
  706.     mov    ax,display_offset    ;Load current video offset into ax
  707.     shr    ax,1            ;Calculate column value
  708.     div    display_columns
  709.     mov    dh,al            ;Row
  710.     mov    dl,ah            ;Column
  711.     pop    ax
  712.     ret
  713. get_cursor    ENDP
  714.  
  715. ;-----------------------------------------------------------------------;
  716. ; Initializes the display.                        ;
  717. ;-----------------------------------------------------------------------;
  718. init_display    PROC
  719.     push    bx
  720.     push    dx
  721.     call    init_video        ;Determine display type
  722.     cmp    is_color,00h        ;Is color supported?
  723.     je    default_colors        ;No, use default colors
  724.     mov    display_color,1Fh    ;Else use attributes suitable
  725.     mov    copyright_color,70h    ; color systems
  726.     mov    header_color,4Eh
  727.     mov    status_color,30h
  728. default_colors:
  729.     mov    dh,display_rows        ;Hide hardware cursor off screen
  730.     call    set_text_cursor
  731.     mov    bh,display_color    ;Initialize screen by clearing it
  732.     call    clear_screen
  733.     mov    bh,copyright_color    ;Write copyright bar
  734.     sub    dx,dx
  735.     call    set_cursor
  736.     call    clear_eol
  737.     add    dl,10            ;Write copyright
  738.     call    set_cursor
  739.     mov    dx,OFFSET copyright
  740.     call    write_string
  741.     mov    bh,header_color        ;Write column header bar
  742.     mov    dx,0100h
  743.     call    set_cursor
  744.     call    clear_eol
  745.     call    set_cursor        ;Write column header
  746.     mov    dx,OFFSET header
  747.     call    write_string
  748.     mov    bh,status_color        ;Write status bar
  749.     sub    dl,dl
  750.     mov    dh,display_rows
  751.     dec    dh
  752.     call    set_cursor
  753.     call    clear_eol
  754.     call    set_cursor        ;Write status
  755.     mov    dx,OFFSET status
  756.     call    write_string
  757.     call    paint_page        ;Show first page of information
  758.     pop    dx
  759.     pop    bx
  760.     ret
  761. init_display    ENDP
  762.  
  763. ;-----------------------------------------------------------------------;
  764. ; Initializes the display variables to match the current condition of    ;
  765. ; the host display.                            ;
  766. ;-----------------------------------------------------------------------;
  767. init_video    PROC
  768.     push    ax
  769.     push    bx
  770.     push    cx
  771.     push    dx
  772.     push    si
  773.     push    di
  774.     push    bp
  775.     push    es
  776.     mov    ah,0Fh            ;Get miscellaneous data
  777.     int    10h
  778.     mov    display_page,bh
  779.     mov    display_columns,ah
  780.     int    11h            ;Determine color or mono
  781.     and    ax,30h
  782.     cmp    ax,30h
  783.     je    mono
  784.     mov    is_color,01h        ;Indicate color system
  785.     mov    display_segment,0B800h
  786.     mov    snow_check,01h
  787. mono:
  788.     mov    ah,12h            ;Get number of text rows
  789.     mov    bl,10h
  790.     int    10h
  791.     cmp    bl,10h            ;Was function supported?
  792.     je    end_init_video        ;No, use default rows
  793.     cmp    is_color,bh        ;Is EGA/VGA active?
  794.     je    end_init_video        ;No, use default rows
  795.     mov    ax,1130h
  796.     int    10h
  797.     inc    dl
  798.     mov    display_rows,dl
  799.     mov    snow_check,00h
  800. end_init_video:
  801.     pop    es
  802.     pop    bp
  803.     pop    di
  804.     pop    si
  805.     pop    dx
  806.     pop    cx
  807.     pop    bx
  808.     pop    ax
  809.     ret
  810. init_video    ENDP
  811.  
  812. ;-----------------------------------------------------------------------;
  813. ; Returns the next available keystroke.                    ;
  814. ;                                    ;
  815. ;    Output:    ax    Keystroke: al = ASCII code, ah = scan code.    ;
  816. ;                                    ;
  817. ;-----------------------------------------------------------------------;
  818. get_key        PROC
  819.     sub    ah,ah
  820.     int    16h
  821.     ret
  822. get_key        ENDP
  823.  
  824. ;-----------------------------------------------------------------------;
  825. ; Removes any keystrokes waiting in the keyboard buffer.        ;
  826. ;-----------------------------------------------------------------------;
  827. flush_kbd    PROC
  828.     push    ax
  829. flush_loop:
  830.     mov    ah,01h            ;Anything in keyboard buffer?
  831.     int    16h
  832.     jz    end_flush_kbd        ;No, done
  833.     call    get_key            ;Else read keystroke
  834.     jmp    flush_loop        ;Repeat
  835. end_flush_kbd:
  836.     pop    ax
  837.     ret
  838. flush_kbd    ENDP
  839.  
  840. ;-----------------------------------------------------------------------;
  841. ; Sets the actual hardware cursor position.                ;
  842. ;                                    ;
  843. ;    Input:    dh    Row coordinate (0-based)            ;
  844. ;        dl    Column coordinate (0-based)            ;
  845. ;                                    ;
  846. ;-----------------------------------------------------------------------;
  847. set_text_cursor    PROC
  848.     push    ax
  849.     push    bx
  850.     push    si
  851.     push    di
  852.     push    bp
  853.     mov    ah,02h            ;ROM BIOS set cursor service
  854.     mov    bh,display_page
  855.     int    10h
  856.     pop    bp
  857.     pop    di
  858.     pop    si
  859.     pop    bx
  860.     pop    ax
  861.     ret
  862. set_text_cursor    ENDP
  863.  
  864. ;-----------------------------------------------------------------------;
  865. ; Sounds the computer's internal speaker.                ;
  866. ;-----------------------------------------------------------------------;
  867. beep        PROC
  868.     push    ax
  869.     push    dx
  870.     mov    ah,02h            ;DOS write character service
  871.     mov    dl,07h            ;Write 'bell' character
  872.     int    21h
  873.     pop    dx
  874.     pop    ax
  875.     ret
  876. beep        ENDP
  877.  
  878. _TEXT        ENDS
  879.  
  880.     END    start
  881.