; =========================================================================================
; Model 100 Specific ROM addresses include file
;
; By Kenneth D. Pettit
; March, 2009
;
;
; =========================================================================================


#define		ENTRY_ADDR	62000

; =========================================================================================
; Model 100 specific addresses (ROM, ALTLCD, etc.)
; =========================================================================================

M_EXT_DET_SIZE     equ 24H               ; Size of ROM detect routine copied to RAM

M_EXT_DETECT       equ 036FH             ; ROM Detection routine copied to RAM
M_GEN_ERROR_E      equ 045DH             ; Generate Error in E routine
M_BASIC_READY      equ 0501H             ; Vector to BASIC ready address
M_BASIC_RDYOK      equ 0502H             ; Vector to BASIC ready - print OK
M_UPD_BAS_ADDR     equ 05F0H             ; Update BASIC address pointers
M_BASIC_FIND_END   equ 05F4H             ; Find end of BASIC program
M_GEN_FC_ERR       equ 08DBH             ; Address of Generate FC Error routine in main ROM
M_GEN_FC_ERR_LSB   equ 0DBH
M_TO_UPPER         equ 0FE8H             ; Convert character at M to uppercase
M_EVAL_EXPR        equ 1113H             ; Evaluate expression at (M-1)
M_EVAL_EXPR2       equ 112EH             ; Evaluate expression at (M-1) (non BASIC entry)
M_READ_KEY         equ 12CBH             ; Read a key from keyboard with wait
M_POWER_DOWN       equ 13B5H             ; Power down the laptop
M_CHECK_KEY        equ 13DBH             ; Check keyboard for characters
M_ROM_RET          equ 1488H             ; Address of a POP PSW & RET
M_FILE_OPEN        equ 14DEH             ; File OPEN routine for RST7 Hook to return to
M_PWRDN_UPDATE     equ 14EAH             ; Routine to update powerdown timer
M_POP_ALL_RET      equ 14EDH             ; Pop all regs and ret
M_SPCL_RAM_IO      equ 161BH             ; Address of special RAM I/O routine
M_CONIG_RS232      equ 17E6H             ; Configure RS232 from settings at HL
M_EOF_FUN_RTN      equ 189AH             ; EOF Function return address for RST7
M_FEED_POWER       equ 1BB1H             ; Feed the automatic power down counter
M_LCOPY            equ 1E5EH             ; Main ROM LCOPY statement
M_CAT_KILL_DO      equ 1FBFH             ; Kill a .DO entry in the catalog
M_CAT_KILL_CO      equ 1FD9H             ; Kill a .BA entry in the catalog
M_CAT_KILL_BA      equ 2017H             ; Kill a .BA entry in the catalog
M_SRCH_CAT_BA      equ 20AFH             ; Search catalog entry for current BASIC program
M_BAS_NEW_STMT     equ 20FFH             ; BASIC NEW statement handler
M_UPDATE_PTRS      equ 2146H             ; Update system pointers to DO, BA, CO, etc.
M_SAVE_TO_CAT      equ 2239H             ; Save new entry to Catalog
M_SAVEM_ARGS       equ 2346H             ; Process SAVEM arguments
M_BASIC_EXEC       equ 23F5H             ; Routine to execute BASIC program
M_RST7_5E_RET      equ 251AH             ; Return address for RST7 5EH RUNM hook
M_CP_CO_HDR        equ 253DH             ; Copy 6-byte CO header to current program area
M_MEMCPY           equ 2542H             ; Copy B bytes from (HL) to (DE)
M_PRN_CO_INFO      equ 25A4H             ; Print CO information to LCD (start address, etc.)
M_MEMCPY_IND       equ 2905H             ; Memory copy with args following the CALL instruction
M_SGN_FUNC         equ 340AH             ; SGN function (with no last varialbe lookup)
M_SINT_MUL         equ 3725H             ; Signed Integer multiply
M_SINT_DIV         equ 377EH             ; Signed Integer divide
M_PRINT_INT_HL     equ 39D4H             ; Print integer in HL to LCD
M_PRINT_CRLF       equ 4222H             ; Send CRLF to the LCD
M_CLS              equ 4231H             ; Clear the display
M_DISABLE_SCROLL   equ 423FH             ; Disable automatic scroll
M_ENABLE_SCROLL    equ 4244H             ; Enable automatic scroll
M_CURSOR_ON        equ 4249H             ; Turn the LCD cursor on
M_CURSOR_OFF       equ 424EH             ; Turn the LCD cursor off
M_DEL_LINE         equ 4253H             ; Delete line at cursor
M_INS_LINE         equ 4258H             ; Insert line at cursor
M_ERASE_EOL        equ 425DH             ; Erase to end of line
M_START_INV        equ 4269H             ; Start Inverse video
M_CANCEL_INV       equ 426EH             ; Cancel Inverse video
M_CURSOR_POS       equ 427CH             ; Position the cursor on the LCD
M_HIDE_FKEY        equ 428AH             ; Hide Function key line
M_DISP_FKEY        equ 42A8H             ; Display Function key line
M_CHAR_PLOT_5      equ 434CH             ; Character plotting level 5
M_SCROLL_LINE      equ 44D2H             ; Scroll the screen A number of lines
M_GET_INP_NOQM     equ 4644H             ; Get input from keyboard without displaying '?'
M_PRINT_CHR_A      equ 4B55H             ; Print character in A to LCD or printer
M_GET_FD           equ 4C81H             ; Get File Descriptor for file # in A
M_FILE_CLOSE       equ 4D59H             ; File CLOSE routine for RST7 Hook to return to
M_ST_FRAM_RET      equ 4E8AH             ; Return routine to fixup the stack frame after EOF
M_PRINT_HL         equ 5791H             ; Print buffer at HL until NULL
M_SET_FKEY         equ 5A7CH             ; Set Function key line
M_GET_FILE_ADDR    equ 5AE3H             ; Get address of File at M
M_TEXT_LOOP        equ 63F4H             ; Return address in TEXT after key entry / display
M_MKHOLE           equ 6B6DH             ; Insert BC spaces at M (MKHOL routine)
M_DEL_BYTES        equ 6B9FH             ; Delete BC bytes at M 
M_MEM_MOVE_DEC     equ 6BE6H             ; Move BC bytes from M to DE with decrement
M_CHECK_RX         equ 6D6DH             ; Check RS-232 for RX byte
M_RX_BYTE          equ 6D7EH             ; Main ROM routine to receive a byte from RS-232
M_WRITE_TX         equ 6E32H             ; Write byte to TX buffer on RS-232
M_WAIT_TX_EMPTY    equ 6ECBH             ; Wait for the TX buffer to be empty
M_SCAN_BREAK       equ 7242H             ; Scan for CTRL-C, BREAK, etc.
M_CHK_BREAK        equ 7283H             ; Check for BREAK
M_CURS_BLINK       equ 73C5H             ; Blink cursor and reset cursor time
M_WAIT_LCD         equ 7548H             ; Wait for LCD to be ready
M_INT_1D           equ 765CH             ; Set interrupt 1DH
M_BOOT_SIG         equ 0F5F2H            ; Boot up signature bytes
M_RST5_5_VCTR      equ 0F5F4H            ; Addres of RST 5.5 vector
M_ROM_DETECT       equ 0F605H            ; RAM routine to detect OptROM (Set by SysROM)
M_PWROFF_SW        equ 0F656H            ; Power off switch
M_BAUD_SETTING     equ 0F65BH            ; Current BAUD rate settings
M_BAS_STR_PTR      equ 0F678H            ; Basic string pointer
M_BAS_PRG_STRT     equ 0F67CH            ; Start of BASIC program pointer
M_KBD_BUF          equ 0F685H            ; Keyboard Buffer - temp storage
M_CLK_TICK         equ 0F92FH            ; The background tick
M_PWROFF_RENEW     equ 0F932H            ; Automatic poweroff renew flag
M_ONTIME_TIME      equ 0F93DH            ; Used for RST7 Hook helper routine
M_BAS_NOTSAVE      equ 0F99AH            ; Pointer to BASIC program not saved
M_PREV_BAUD_S      equ 0F9A8H            ; Storage for previous baud rate settings (in Hayashi in Cat)
M_CAT_1ST_NTRY     equ 0F9BAH            ; Address of 1st available slot in catalog
M_FD_ARRAY         equ 0FA91H            ; Address of FD array
M_ACTIVE_FD        equ 0FAA2H            ; FD number of active BASIC File I/O operation
M_RST7_ARG         equ 0FAC9H            ; Argument of last RST7 operation
M_CO_INFO_ADDR     equ 0FACEH            ; Address of CO header info
M_TAPE_LEN         equ 0FAD0H            ; Length of last program loaded from tape
M_INPUT_PROC       equ 0FAD8H            ; Pointer for RAM input processing ???
M_MAJ_HLP_ADDR     equ 0FAE0H            ; Magic powerup helper address
M_MAJ_HLP_VAL      equ 111DH             ; Magic powerup helper value
M_LFILES_HOOK      equ 0FB2CH            ; Address of LFILES Hook address
M_DO_START         equ 0FBAEH            ; Pointer to start of DO files
M_CO_START         equ 0FBB0H            ; Start of CO files
M_VARS_START       equ 0FBB2H            ; Start of Variables pointer
M_FREE_MEM_PTR     equ 0FBB6H            ; Pointer to free memory
M_BAS_EXEC_FLG     equ 0FC92H            ; Flag to execute BASIC program
M_BASIC_FNAME      equ 0FC93H            ; Filename for current BASIC program
M_BAS_FNAM_EXT     equ 0FC99H            ; Extension location of BASIC filename
M_TAPE_NAME        equ 0FC9CH            ; Filename of last file loaded from tape
M_ALTLCD           equ 0FCC0H            ; ALTLCD address for M100
M_LCDBUF           equ 0FE00H            ; First line of LCD buffer
M_LCDBUF_LINE2     equ 0FE28H            ; Line 2 of the LCD buffer (Files page)
M_SER_BUF_CNT      equ 0FF86H            ; Number of bytes in RS-232 buffer

/*
=============================================================================================================
More defines
=============================================================================================================
*/
M_STRLEN           equ 21FAH             ; Count length of string at M (in E)
M_OPEN_DO_FILE     equ 2206H             ; Create new .DO file and insert into catalog
M_CONV_FNAME       equ 4C0BH             ; Convert "name.do" filename to Model T format
M_INS_DO_FILE      equ 608AH             ; Insert character in A to .DO file at HL
M_TEXT_CTRL_M      equ 60BEH             ; Deal with CR in TEXT
M_TEXT_RIGHT       equ 60DEH             ; Deal with right arrow in TEXT
M_TEXT_DOWN        equ 60E2H             ; Deal with down arrow in TEXT
M_TEXT_CTRL_H      equ 610BH             ; Deal with BKSP in TEXT
M_TEXT_DEL_KEY     equ 6118H             ; Deal with DEL in TEXT
M_TEXT_LEFT        equ 6151H             ; Deal with left arrow in TEXT
M_TEXT_UP          equ 6155H             ; Deal with up arrow in TEXT
M_TEXT_CTRL_F      equ 617AH             ; Next word (CTRL-F)
M_TEXT_CTRL_A      equ 618CH             ; Previous word (CTRL-A)
M_TEXT_CTRL_T      equ 61C2H             ; Top of screen / Previous Screen
M_TEXT_CTRL_B      equ 61D7H             ; Bototm os screen / Next Screen
M_EXPAND_DO_FILE   equ 634AH             ; Expand .DO file with zeros
M_COLAPSE_DO       equ 6383H             ; Remove zeroes from end of .DO file
M_GET_LCD_ROWS     equ 63CDH             ; Get LCD row count based on label protect
M_TEXT_COPY        equ 6431H             ; Copy active SEL fom .DO file
M_TEXT_CUT         equ 6445H             ; Cut active SELection from .DO file
M_GET_SEL_ADRS     equ 64ABH             ; Get SEL address in HL and DE
M_TEXT_PASTE       equ 6501H             ; Paste from PASTE buffer
M_PASTE_REDRAW     equ 6537H             ; Redraw after PASTE operation
M_GOTO_DO_AT_BC    equ 657DH             ; Jump cursor to address BC within DO file
M_DISP_DO_FILE     equ 6989H             ; Display portion of a .DO file
M_DISP_LINE_A      equ 69CBH             ; Display line 'A' of LCD from the .DO file
;M_BEZEL_LINE_ADR   equ 6A3EH             ; Get the address of the .DO file at the line below LCD
M_LINE_START_ADR   equ 6A48H             ; Get address in .DO of 1st char on line 'A'
M_DO_ADDR_CURS     equ 6AC7H             ; Get row/col on LCD for address in .DO at (DE)
M_DO_CURS_ADDR     equ 6AF9H             ; Get address in .DO of current cursor
M_FIND_DO_END      equ 6B2AH             ; Find end of .DO file

M_NEW_CONSOLE      equ 0F638H            ; New console device flag

M_CURS_ROW         equ 0F639H            ; Current Cursor ROW
M_CURS_COL         equ 0F63AH            ; Current Cursor COL
M_ACTIVE_ROWS      equ 0F63BH            ; Number of active ROWs
M_CURS_ACTV_ROWS   equ 0F63BH            ; Active ROWS count
M_COLS_COUNT       equ 0F63CH            ; Active columns count
M_LABEL_PROT       equ 0F63DH            ; Label protect line
M_SAVE_ROW         equ 0F640H            ; Cursor row save area
M_ACTIVE_ROW       equ 0F642H
M_DISP_HEIGHT      equ 0F644H            ; Height of display (8, 16 or 25)
M_DISP_WIDTH       equ 0F645H            ; Width of display (40 or 80)
M_KEYSCAN_MOD      equ 0F650H            ; Keyboard scan modifier
M_LONG_JUMP        equ 0F652H            ; Long jump address to return to on error
M_TEXT_CTRL2       equ 0F6E1H            ; Unknown Control location - set to zero
M_SEL_START        equ 0F6E2H            ; Starting address of SEL
M_SEL_END          equ 0F6E4H            ; End address of SEL
M_TEXT_CTRL1       equ 0F6E7H            ; Unknown Control location - 2 bytes
M_TEXT_LINE_START  equ 0F6EBH            ; Line starts array
M_TEXT_CTRL3       equ 0F71FH            ; Unknown Control location - set to zero
M_EDIT_DO          equ 0F767H            ; Address of beginning of .DO file being edited
M_TMP_CURS_SAVE    equ 0F88CH
M_LCD_LPT          equ 0F920H            ; LCD vs LPT output
M_WORD_WRAP        equ 0F921H            ; Word wrap enable flag
M_OUTPUT_WIDTH     equ 0F922H            ; Output width
M_PASTE_BUFFER     equ 0F9A5H            ; Paste buffer pointer storage
M_EXTRA_POP        equ 0FAC7H            ; Indicates if extra POP needed after character plotting

PORT_E8_VAL        equ 0FF45H            ; Contents of PORT E8h
BASIC_HIDEY        equ 0xF96C
RICKY_START        equ 0F9AFH            ; First address of RICKY for Catalog searches
RICKY_STORE        equ 0F9B4H            ; Temporary storage
RICKY_STORE2       equ 0F9B2H            ; Temporary storage
RET_HLPR_ADR       equ 0FAA4H            ; RAM Address of our TS-DOS ROM RETurn Helper

MAX_FILE_COUNT     equ	14H	         ; 20 Files for M100

/*
=============================================================================================================
Define the RST7 hook vectors.  The vector numbers and address are different for each model.
=============================================================================================================
*/
M_RST7_HOOK_BASE   equ 0FADAH            ; Base of RST7 vector table

M_RST7_CHGET       equ 04H               ; CHGET Hook number
M_RST7_PLOT        equ 08H               ; SAVE Hook number
M_RST7_SAVE        equ 16H               ; SAVE Hook number
M_RST7_RUN         equ 1AH               ; RUN function
M_RST7_DSKI        equ 2EH               ; DSKI function
M_RST7_OPEN_CLOSE  equ 30H               ; OPEN/CLOE?PRINT?LINE INPUT
M_RST7_WIDTH       equ 3AH               ; WIDTH hook
M_RST7_INIT_LCD    equ 3CH               ; Init back to LCD hook
M_RST7_INIT_EXT    equ 3EH               ; Initialize external monitor for output
M_RST7_LFILES      equ 52H               ; LFILES statement
M_RST7_KILL        equ 58H               ; KILL statement
M_RST7_NAME        equ 5AH               ; NAME statement
M_RST7_SAVEM       equ 5CH               ; SAVEM statement
M_RST7_LOADM       equ 5EH               ; LOADM statement

//M_RST7_0CH         equ M_RST7_HOOK_BASE + M_RST7_SAVE      ; RST 7,0Ch Hook address
M_RST7_04H         equ M_RST7_HOOK_BASE + M_RST7_CHGET          ; Get character and display hook
M_RST7_08H         equ M_RST7_HOOK_BASE + M_RST7_PLOT           ; Plot A to screen hook
M_RST7_16H         equ M_RST7_HOOK_BASE + M_RST7_SAVE           ; Save as hook for RST 7,16h - SAVE   - On KC-85, this is RST7,18H
M_RST7_1AH         equ M_RST7_HOOK_BASE + M_RST7_RUN            ; RST 7,1Ah - RUN 
M_RST7_2EH         equ M_RST7_HOOK_BASE + M_RST7_DSKI           ; RST 7,2Eh - DSKI$ function - on KC-85, this is RST7,30h
M_RST7_30H         equ M_RST7_HOOK_BASE + M_RST7_OPEN_CLOSE     ; RST 7,30h - OPEN/CLOSE/PRINT/LINE INPUT  - on KC-85, this is RST7,32h
M_RST7_3AH         equ M_RST7_HOOK_BASE + M_RST7_WIDTH          ; RST 7,3Ah - WIDTH statement hook
M_RST7_3CH         equ M_RST7_HOOK_BASE + M_RST7_INIT_LCD       ; RST 7,3Ch - Init display back to LCD
M_RST7_3EH         equ M_RST7_HOOK_BASE + M_RST7_INIT_EXT       ; RST 7,3Eh - Init display to external monitor
M_RST7_58H         equ M_RST7_HOOK_BASE + M_RST7_KILL           ; RST 7,58h - KILL
M_RST7_5AH         equ M_RST7_HOOK_BASE + M_RST7_NAME           ; RST 7,5Ah - NAME
M_RST7_5CH         equ M_RST7_HOOK_BASE + M_RST7_SAVEM          ; RST 7,5Ch - SAVEM
M_RST7_5EH         equ M_RST7_HOOK_BASE + M_RST7_LOADM          ; RST 7,5Eh - LOADM and RUNM
M_RST7_RET         equ 7FF3H             ; Address of a simple RET opcode


