mirror of
https://github.com/romychs/OK240.2-Firmware.git
synced 2026-04-21 10:53:18 +03:00
497 lines
9.2 KiB
NASM
497 lines
9.2 KiB
NASM
; ==================================================
|
|
; TYPE.COM
|
|
;
|
|
; Disassembled by Romych, 2026-03-01
|
|
; ==================================================
|
|
|
|
DEVICE NOSLOT64K
|
|
|
|
INCLUDE "equates.inc"
|
|
|
|
OUTPUT TYPE.COM
|
|
|
|
MODULE TYPE
|
|
|
|
ORG 0x0100
|
|
|
|
; ---------------------------------------------------
|
|
; Entry point
|
|
; ---------------------------------------------------
|
|
start:
|
|
LD HL, t_start
|
|
LD SP, HL
|
|
LD DE, 0x0
|
|
PUSH DE
|
|
JP (HL)
|
|
|
|
DB "roDOS TYPE FILE Utility(C) IRIMS, Moscow 1985"
|
|
|
|
t_start:
|
|
CALL t_check_version
|
|
; unsupported bdos call
|
|
LD C, 49
|
|
LD DE, t_scb_1
|
|
CALL jp_bdos_enter
|
|
DEC A
|
|
DEC A
|
|
LD (t_scb_mm), A
|
|
|
|
; At start command line params here
|
|
LD HL, p_cmd_line_len
|
|
LD (t_buff_addr), HL
|
|
LD A, (HL)
|
|
LD (cmd_par_len), A
|
|
|
|
; skip spaces before first parameter
|
|
.skip_sp_0:
|
|
CALL t_get_cmdl_char
|
|
JP C, t_handle_error
|
|
CP ASCII_SP
|
|
JP Z, .skip_sp_0
|
|
|
|
; get filename
|
|
.get_next_ch:
|
|
CALL t_get_cmdl_char
|
|
JP C, t_open_file
|
|
CP ASCII_SP
|
|
JP NZ, .get_next_ch
|
|
|
|
; get
|
|
.skip_sp_1:
|
|
CALL t_get_cmdl_char
|
|
JP C, t_open_file
|
|
CP ASCII_SP
|
|
JP Z, .skip_sp_1
|
|
CP 'P'
|
|
JP Z, t_param_P
|
|
CP 'D'
|
|
JP NZ, t_param_no_PD
|
|
LD A, 1
|
|
JP t_param_cmn
|
|
|
|
t_param_no_PD:
|
|
CP 'C'
|
|
JP NZ, t_param_no_D
|
|
LD A, 2
|
|
JP t_param_cmn
|
|
|
|
t_param_no_D:
|
|
CP 'F'
|
|
JP NZ, t_param_unknown
|
|
LD A, 3
|
|
|
|
t_param_cmn:
|
|
LD (cmd_switch), A
|
|
|
|
.skip_sp_2:
|
|
CALL t_get_cmdl_char
|
|
JP C, t_open_file
|
|
CP ASCII_SP
|
|
JP Z, .skip_sp_2
|
|
|
|
t_param_P:
|
|
CP 'P'
|
|
JP NZ, t_param_unknown
|
|
LD A, 0xff
|
|
LD (flag1), A
|
|
CALL get_numbr
|
|
JP C, t_open_file
|
|
LD A, L
|
|
OR A
|
|
JP Z, t_open_file
|
|
LD (t_scb_mm), A
|
|
|
|
t_open_file:
|
|
LD C, 15
|
|
LD DE, fcb1
|
|
CALL jp_bdos_enter
|
|
CP 0xff
|
|
JP Z, t_handle_error
|
|
LD HL, tpa
|
|
LD (t_buff_addr), HL
|
|
|
|
t_dump_part:
|
|
LD A, (t_scb_mm)
|
|
LD (cmd_par_len), A
|
|
|
|
print_next_byte:
|
|
; get next byte, return if error
|
|
CALL t_get_nxt_byte
|
|
RET C
|
|
; return if end of text marker
|
|
CP ASCII_SUB
|
|
RET Z
|
|
|
|
; print character
|
|
LD (t_cut_byte), A
|
|
LD E, A
|
|
CALL t_print
|
|
|
|
LD A, (t_cut_byte)
|
|
CP ASCII_LF
|
|
JP NZ, print_next_byte
|
|
; LF
|
|
LD A, (flag0)
|
|
OR A
|
|
JP Z, lo_ctr_0
|
|
|
|
; wait until keyboard key pressed
|
|
wait_for_key:
|
|
CALL t_get_key_wo_echo
|
|
OR A
|
|
JP Z, wait_for_key
|
|
|
|
; check for Ctrl+C - interrupt
|
|
CP CTRL_C
|
|
JP Z, t_is_ctrl_c
|
|
|
|
; Space - fro continue
|
|
CP ASCII_SP
|
|
JP Z, print_next_byte
|
|
|
|
CP CTRL_P
|
|
JP NZ, is_no_ctrl_p
|
|
|
|
; Access the System Control Block (Unsupported!)
|
|
; get value at offset
|
|
LD C, 49
|
|
LD DE, t_scb_2
|
|
CALL jp_bdos_enter
|
|
XOR 0xff
|
|
LD (t_scb_3+2), A
|
|
; set new value an offset
|
|
LD C, 49
|
|
LD DE, t_scb_3
|
|
CALL jp_bdos_enter
|
|
; and wait for next key
|
|
JP wait_for_key
|
|
|
|
is_no_ctrl_p:
|
|
; Return key
|
|
CP ASCII_CR
|
|
JP NZ, t_is_no_cr
|
|
; update hi counter
|
|
LD A, 0xff
|
|
LD (flag1), A
|
|
; zero to low counter
|
|
XOR A
|
|
LD (flag0), A
|
|
; and dump next part
|
|
JP t_dump_part
|
|
|
|
t_is_no_cr:
|
|
; other key - zero counters
|
|
XOR A
|
|
LD (flag0), A
|
|
LD (flag1), A
|
|
JP print_next_byte
|
|
|
|
lo_ctr_0:
|
|
CALL t_get_key_wo_echo
|
|
OR A
|
|
JP Z, no_key_pressd
|
|
|
|
lo_ctr_set_ff:
|
|
LD A, 0xff
|
|
LD (flag0), A
|
|
JP wait_for_key
|
|
|
|
no_key_pressd:
|
|
LD A, (flag1)
|
|
OR A
|
|
JP Z, print_next_byte
|
|
|
|
LD A, (cmd_par_len)
|
|
DEC A
|
|
LD (cmd_par_len), A
|
|
JP NZ, print_next_byte
|
|
JP lo_ctr_set_ff
|
|
|
|
; ---------------------------------------------------
|
|
;
|
|
; ---------------------------------------------------
|
|
t_check_version
|
|
LD C, 12
|
|
CALL jp_bdos_enter
|
|
CP 0x26
|
|
JP C, t_ver_unsupported
|
|
CP 0x30
|
|
JP NC, t_ver_unsupported
|
|
RET
|
|
|
|
t_param_unknown:
|
|
LD E, 0x0
|
|
JP t_calc_msg_offset
|
|
|
|
t_handle_error:
|
|
LD E, 0x1
|
|
JP t_calc_msg_offset
|
|
|
|
t_is_ctrl_c:
|
|
LD E, 0x2
|
|
|
|
t_calc_msg_offset:
|
|
LD HL, t_message_tab
|
|
LD D, 0x0
|
|
ADD HL, DE
|
|
ADD HL, DE
|
|
LD E, (HL)
|
|
INC HL
|
|
LD D, (HL)
|
|
; C_WRITESTR - Output string
|
|
LD C, 9
|
|
JP jp_bdos_enter
|
|
|
|
; ---------------------------------------------------
|
|
; Print character
|
|
; Inp: E - charater to print
|
|
; ---------------------------------------------------
|
|
t_print:
|
|
LD A, (cmd_switch)
|
|
OR A
|
|
JP Z, t_con_output ; D
|
|
CP 1
|
|
JP Z, t_get_key_echo ; C
|
|
|
|
LD A, E
|
|
AND 0x7f ; limit to 0..127 codes
|
|
; check for printable
|
|
CP ASCII_SP
|
|
JP NC, t_con_output
|
|
CP ASCII_CR
|
|
JP Z, t_con_output
|
|
CP ASCII_LF
|
|
JP Z, t_con_output
|
|
CP ASCII_TAB
|
|
JP Z, t_con_output
|
|
CP ASCII_SO ; ^N 0xe
|
|
JP Z, t_con_output
|
|
CP ASCII_SI ; ^O 0xf
|
|
JP Z, t_con_output
|
|
LD A, (cmd_switch)
|
|
; if param='F', and unprintable char, do not print
|
|
CP 3
|
|
RET Z
|
|
|
|
; replace unprintable with '^'
|
|
PUSH DE
|
|
LD E, '^'
|
|
CALL t_con_output
|
|
POP DE
|
|
|
|
;
|
|
LD A, E
|
|
OR 0x40
|
|
LD E, A
|
|
JP t_con_output
|
|
|
|
; --------------------------------------------------
|
|
; Return keyboard key if pressed
|
|
; Out: A - key code, 0 - no key
|
|
; --------------------------------------------------
|
|
t_get_key_wo_echo:
|
|
LD E, 0xff
|
|
|
|
t_get_key_echo:
|
|
LD C, 6
|
|
JP jp_bdos_enter
|
|
|
|
t_con_output:
|
|
LD C, 2
|
|
JP jp_bdos_enter
|
|
|
|
t_ver_unsupported:
|
|
HALT
|
|
|
|
; ---------------------------------------------------
|
|
; Get next character from command line
|
|
; Out: A - character
|
|
; CF is set if EOL
|
|
; ZF is set if A=0
|
|
; ---------------------------------------------------
|
|
t_get_cmdl_char:
|
|
; there are still characters in the cmd line?
|
|
LD A, (cmd_par_len)
|
|
OR A
|
|
JP NZ, t_get_next_cmdc ; jump if not eol
|
|
CCF
|
|
RET
|
|
|
|
t_get_next_cmdc:
|
|
; decrement characters count
|
|
DEC A
|
|
LD (cmd_par_len), A
|
|
; get next character to A
|
|
LD HL, (t_buff_addr)
|
|
INC HL
|
|
LD A, (HL)
|
|
; update pointer
|
|
LD (t_buff_addr), HL
|
|
OR A
|
|
RET
|
|
|
|
; ---------------------------------------------------
|
|
;
|
|
; ---------------------------------------------------
|
|
get_numbr:
|
|
LD C, 10
|
|
CALL t_get_cmdl_char
|
|
LD HL, 0x0
|
|
|
|
t_do_nxt_lettr:
|
|
JP NC, t_has_a_lettr
|
|
OR A
|
|
RET
|
|
|
|
t_has_a_lettr:
|
|
CP ASCII_SP
|
|
RET Z
|
|
CALL t_is_digits
|
|
RET C
|
|
CP C
|
|
CCF
|
|
RET C
|
|
LD D, H
|
|
LD E, L
|
|
LD L, A
|
|
LD H, 0
|
|
LD A, C
|
|
CALL t_next_hl_de
|
|
PUSH HL
|
|
CALL t_get_cmdl_char
|
|
POP HL
|
|
JP t_do_nxt_lettr
|
|
|
|
; ---------------------------------------------------
|
|
;
|
|
; ---------------------------------------------------
|
|
t_is_digits:
|
|
SBC A, '0'
|
|
RET C
|
|
CP 10
|
|
JP C, .digit
|
|
SBC A, 7
|
|
CP 10
|
|
RET C
|
|
.digit:
|
|
CP 16
|
|
CCF
|
|
RET
|
|
|
|
; ---------------------------------------------------
|
|
;
|
|
; ---------------------------------------------------
|
|
t_next_hl_de:
|
|
OR A
|
|
RET Z
|
|
RRA
|
|
JP NC, .a0_is_0
|
|
ADD HL, DE
|
|
.a0_is_0:
|
|
EX DE, HL
|
|
ADD HL, HL
|
|
EX DE, HL
|
|
JP t_next_hl_de
|
|
|
|
; ---------------------------------------------------
|
|
;
|
|
; ---------------------------------------------------
|
|
t_get_nxt_byte:
|
|
LD HL, (t_buff_addr)
|
|
LD DE, 0xff00
|
|
ADD HL, DE
|
|
LD A, H
|
|
OR L
|
|
CALL Z, t_read_next_128
|
|
RET C
|
|
LD HL, (t_buff_addr)
|
|
LD A, (HL)
|
|
INC HL
|
|
LD (t_buff_addr), HL
|
|
RET
|
|
|
|
; ---------------------------------------------------
|
|
;
|
|
; ---------------------------------------------------
|
|
t_read_next_128:
|
|
LD DE, dma_buffer
|
|
;(F_DMAOFF) - Set DMA address
|
|
LD C, 26
|
|
CALL jp_bdos_enter
|
|
LD DE, fcb1
|
|
;(F_READ) - read next record
|
|
LD C, 20
|
|
CALL jp_bdos_enter
|
|
RRA
|
|
LD HL, dma_buffer
|
|
LD (t_buff_addr), HL
|
|
RET
|
|
|
|
; ---------------------------------------------------
|
|
; Variables
|
|
; ---------------------------------------------------
|
|
|
|
flag0:
|
|
db 0x00
|
|
flag1:
|
|
db 0x00
|
|
|
|
; Cmd line switch D-1, C-2, F-3
|
|
cmd_switch:
|
|
db 0x00
|
|
|
|
t_scb_mm:
|
|
db 0x00
|
|
|
|
t_cut_byte:
|
|
db 0x00
|
|
|
|
cmd_par_len:
|
|
db 0x00
|
|
|
|
t_buff_addr:
|
|
dw 0x0000
|
|
|
|
t_scb_1:
|
|
db 0x1c ; offset
|
|
db 0 ; read byte at offset onto a, and word into hl
|
|
db 0, 0
|
|
|
|
t_scb_2:
|
|
db 0x38 ; offset
|
|
db 0, ; read byte at offset onto a, and word into hl
|
|
db 0 ,0
|
|
|
|
t_scb_3:
|
|
db 0x38 ; offset
|
|
db 0xff ; save next byte to SCB+offset
|
|
db 0 , 0
|
|
|
|
;t_val_scb1
|
|
; dw 0x0000
|
|
|
|
t_message_tab:
|
|
dw msg_err_cmdline
|
|
dw msg_no_file
|
|
dw msg_interrupted
|
|
|
|
msg_err_cmdline:
|
|
db "o{ibka komandnoj stroki. ispolxzujte\r\n"
|
|
db "TYPE UFN SWITCH \t ili\r\n"
|
|
db "TYPE UFN SWITCH P \t ili\r\n"
|
|
db "TYPE UFN SWITCH P#\r\n\t"
|
|
db "s perekl`~atelem SWITCH:\tNO D C F\r\n"
|
|
db "$"
|
|
|
|
msg_no_file:
|
|
db "net fajla$"
|
|
|
|
|
|
msg_interrupted:
|
|
db "\r\nTYPE prerwana$"
|
|
|
|
filler1:
|
|
ds 88, 0x1A
|
|
filler2:
|
|
ds 1024+start-filler2, 0xe5
|
|
ENDMODULE |