Сообщение от
Shiny
Эти не подошли для программульки font.asm
Код:
;
; Title: Font - Main
; Author: Lennart Benschop
; Created: 30/12/2022
;
; Modified 09/04/2024 adapter to ez80asm
.ASSUME ADL = 1
INCLUDE "mos_api.inc"
ORG $b0000 ; Is a moslet
MACRO PROGNAME
ASCIZ "font.bin"
ENDMACRO
INCLUDE "init.inc"
; A program to load an 8x8 font from a file into the VDP. Only codes 32..126 and 128..255 will be loaded.
; Optionally show the font just loaded.
;
; The main routine
; IXU: argv - pointer to array of parameters
; C: argc - number of parameters
; Returns:
; HL: Error code, or 0 if OK
;
_main: XOR A
LD (will_show), A
LD A, C
CP #2
JR Z, main1 ; Only load font, don't show
CP #3
JR NZ, main_usage
LD A, 1
LD (will_show),A ; Additional parameter present, do not check.
JR main1
main_usage:
LD HL, s_USAGE ; Number of args != 3, print usage string and exit
CALL PRSTR
LD HL, 19
RET
main1: LD HL, (IX+3) ; source file name
LD DE, font_buf
LD BC, 4096
MOSCALL mos_load
OR A
JR Z, main2
PUSH AF
LD HL, s_ERROR_SRC ; source file not opened, error
CALL PRSTR
POP AF
LD HL, 0
LD L, A
RET
main2: ; Font file loaded, now try to get them into VDP. We will also write char 127, but it cannot be shown.
LD E, 8 ; Assume font has 8 rows, always
LD C, 32
LD HL, font_buf + $100 ; Start at space.
main_fontloop: LD A, 23
RST.LIL 10h ; VDU 23
LD A, C
RST.LIL 10h ; followed by character code.
LD B, E
@@: LD A, (HL)
RST.LIL 10h ; followd by 8/16 bitmap bytes from font.
INC HL
DJNZ @B
INC C
LD A, C
AND A
JR NZ, main_fontloop ; End loop if encremented to 0
; Font is now loaded into VDP.
LD A, (will_show)
AND A
JR Z, main_end
; Show the font in 7 rows of 32 chars each.
LD C, 32
main_showloop: LD B, 32
main_showloop2: LD A, C
CP 127
JR Z, @F ; We will skip 127 when showing.
RST.LIL 10h ; It's at the endo of the row, no need to show something else instead..
@@: INC C
DJNZ main_showloop2 ; Inner loop, print 32 chars per row
LD A, 13
RST.LIL 10h
LD A, 10
RST.LIL 10h ; print newline after row.
LD A, C
AND A
JR NZ, main_showloop
main_end: LD HL, 0
RET
; Print a zero-terminated string
; Parameters:
; HL: Address of string (24-bit pointer)
;
PRSTR: LD A,(HL)
OR A
RET Z
RST.LIL 10h
INC HL
JR PRSTR
;
; Text messages
;
s_ERROR_SRC: DB " Cannot load font file\r\n", 0
s_USAGE: DB " Usage: font <fontfile> [show]\r\n", 0
c_MORE: DB 28 ;String length
; RAM
;
will_show: DS 1
font_buf: DS 2048
Получаем ее трансляцией в /MOS
font.bin ( не забывая скопировать в /MOS mos_api.inc
Код:
;
; Title: AGON MOS - API for user projects
; Author: Dean Belfield
; Created: 03/08/2022
; Last Updated: 11/11/2023
;
; Modinfo:
; 05/08/2022: Added mos_feof
; 09/08/2022: Added system variables: cursorX, cursorY
; 18/08/2022: Added system variables: scrchar, scrpixel, audioChannel, audioSuccess, vpd_pflags
; 05/09/2022: Added mos_ren, vdp_pflag_mode
; 24/09/2022: Added mos_getError, mos_mkdir
; 13/10/2022: Added mos_oscli
; 23/02/2023: Added more sysvars, fixed typo in sysvar_audioSuccess, offsets for sysvar_scrCols, sysvar_scrRows
; 04/03/2023: Added sysvar_scrpixelIndex
; 08/03/2023: Renamed sysvar_keycode to sysvar_keyascii, added sysvar_vkeycode
; 15/03/2023: Added mos_copy, mos_getrtc, mos_setrtc, rtc, vdp_pflag_rtc
; 21/03/2023: Added mos_setintvector, sysvars for keyboard status, vdu codes for vdp
; 22/03/2023: The VDP commands are now indexed from 0x80
; 29/03/2023: Added mos_uopen, mos_uclose, mos_ugetc, mos_uputc
; 13/04/2023: Added FatFS file structures (FFOBJID, FIL, DIR, FILINFO)
; 15/04/2023: Added mos_getfil, mos_fread, mos_fwrite and mos_flseek
; 19/05/2023: Added sysvar_scrMode
; 05/06/2023: Added sysvar_rtcEnable
; 03/08/2023: Added mos_setkbvector
; 10/08/2023: Added mos_getkbmap
; 11/11/2023: Added mos_i2c_open, mos_i2c_close, mos_i2c_write and mos_i2c_read
; 09/04/2024: Adapter to ez80asm
; VDP control (VDU 23, 0, n)
;
vdp_gp: EQU 80h
vdp_keycode: EQU 81h
vdp_cursor: EQU 82h
vdp_scrchar: EQU 83h
vdp_scrpixel: EQU 84h
vdp_audio: EQU 85h
vdp_mode: EQU 86h
vdp_rtc: EQU 87h
vdp_keystate: EQU 88h
vdp_logicalcoords: EQU C0h
vdp_terminalmode: EQU FFh
; MOS high level functions
;
mos_getkey: EQU 00h
mos_load: EQU 01h
mos_save: EQU 02h
mos_cd: EQU 03h
mos_dir: EQU 04h
mos_del: EQU 05h
mos_ren: EQU 06h
mos_mkdir: EQU 07h
mos_sysvars: EQU 08h
mos_editline: EQU 09h
mos_fopen: EQU 0Ah
mos_fclose: EQU 0Bh
mos_fgetc: EQU 0Ch
mos_fputc: EQU 0Dh
mos_feof: EQU 0Eh
mos_getError: EQU 0Fh
mos_oscli: EQU 10h
mos_copy: EQU 11h
mos_getrtc: EQU 12h
mos_setrtc: EQU 13h
mos_setintvector: EQU 14h
mos_uopen: EQU 15h
mos_uclose: EQU 16h
mos_ugetc: EQU 17h
mos_uputc: EQU 18h
mos_getfil: EQU 19h
mos_fread: EQU 1Ah
mos_fwrite: EQU 1Bh
mos_flseek: EQU 1Ch
mos_setkbvector: EQU 1Dh
mos_getkbmap: EQU 1Eh
mos_i2c_open: EQU 1Fh
mos_i2c_close: EQU 20h
mos_i2c_write: EQU 21h
mos_i2c_read: EQU 22h
; FatFS file access functions
;
ffs_fopen: EQU 80h
ffs_fclose: EQU 81h
ffs_fread: EQU 82h
ffs_fwrite: EQU 83h
ffs_flseek: EQU 84h
ffs_ftruncate: EQU 85h
ffs_fsync: EQU 86h
ffs_fforward: EQU 87h
ffs_fexpand: EQU 88h
ffs_fgets: EQU 89h
ffs_fputc: EQU 8Ah
ffs_fputs: EQU 8Bh
ffs_fprintf: EQU 8Ch
ffs_ftell: EQU 8Dh
ffs_feof: EQU 8Eh
ffs_fsize: EQU 8Fh
ffs_ferror: EQU 90h
; FatFS directory access functions
;
ffs_dopen: EQU 91h
ffs_dclose: EQU 92h
ffs_dread: EQU 93h
ffs_dfindfirst: EQU 94h
ffs_dfindnext: EQU 95h
; FatFS file and directory management functions
;
ffs_stat: EQU 96h
ffs_unlink: EQU 97h
ffs_rename: EQU 98h
ffs_chmod: EQU 99h
ffs_utime: EQU 9Ah
ffs_mkdir: EQU 9Bh
ffs_chdir: EQU 9Ch
ffs_chdrive: EQU 9Dh
ffs_getcwd: EQU 9Eh
; FatFS volume management and system configuration functions
;
ffs_mount: EQU 9Fh
ffs_mkfs: EQU A0h
ffs_fdisk: EQU A1h
ffs_getfree: EQU A2h
ffs_getlabel: EQU A3h
ffs_setlabel: EQU A4h
ffs_setcp: EQU A5h
; File access modes
;
fa_read: EQU 01h
fa_write: EQU 02h
fa_open_existing: EQU 00h
fa_create_new: EQU 04h
fa_create_always: EQU 08h
fa_open_always: EQU 10h
fa_open_append: EQU 30h
; System variable indexes for api_sysvars
; Index into _sysvars in globals.asm
;
sysvar_time: EQU 00h ; 4: Clock timer in centiseconds (incremented by 2 every VBLANK)
sysvar_vpd_pflags: EQU 04h ; 1: Flags to indicate completion of VDP commands
sysvar_keyascii: EQU 05h ; 1: ASCII keycode, or 0 if no key is pressed
sysvar_keymods: EQU 06h ; 1: Keycode modifiers
sysvar_cursorX: EQU 07h ; 1: Cursor X position
sysvar_cursorY: EQU 08h ; 1: Cursor Y position
sysvar_scrchar: EQU 09h ; 1: Character read from screen
sysvar_scrpixel: EQU 0Ah ; 3: Pixel data read from screen (R,B,G)
sysvar_audioChannel: EQU 0Dh ; 1: Audio channel
sysvar_audioSuccess: EQU 0Eh ; 1: Audio channel note queued (0 = no, 1 = yes)
sysvar_scrWidth: EQU 0Fh ; 2: Screen width in pixels
sysvar_scrHeight: EQU 11h ; 2: Screen height in pixels
sysvar_scrCols: EQU 13h ; 1: Screen columns in characters
sysvar_scrRows: EQU 14h ; 1: Screen rows in characters
sysvar_scrColours: EQU 15h ; 1: Number of colours displayed
sysvar_scrpixelIndex: EQU 16h ; 1: Index of pixel data read from screen
sysvar_vkeycode: EQU 17h ; 1: Virtual key code from FabGL
sysvar_vkeydown: EQU 18h ; 1: Virtual key state from FabGL (0=up, 1=down)
sysvar_vkeycount: EQU 19h ; 1: Incremented every time a key packet is received
sysvar_rtc: EQU 1Ah ; 6: Real time clock data
sysvar_spare: EQU 20h ; 2: Spare, previously used by rtc
sysvar_keydelay: EQU 22h ; 2: Keyboard repeat delay
sysvar_keyrate: EQU 24h ; 2: Keyboard repeat reat
sysvar_keyled: EQU 26h ; 1: Keyboard LED status
sysvar_scrMode: EQU 27h ; 1: Screen mode
sysvar_rtcEnable: EQU 28h ; 1: RTC enable flag (0: disabled, 1: use ESP32 RTC)
sysvar_mouseX: EQU 29h ; 2: Mouse X position
sysvar_mouseY: EQU 2Bh ; 2: Mouse Y position
sysvar_mouseButtons: EQU 2Dh ; 1: Mouse button state
sysvar_mouseWheel: EQU 2Eh ; 1: Mouse wheel delta
sysvar_mouseXDelta: EQU 2Fh ; 2: Mouse X delta
sysvar_mouseYDelta: EQU 31h ; 2: Mouse Y delta
; Flags for the VPD protocol
;
vdp_pflag_cursor: EQU 00000001b
vdp_pflag_scrchar: EQU 00000010b
vdp_pflag_point: EQU 00000100b
vdp_pflag_audio: EQU 00001000b
vdp_pflag_mode: EQU 00010000b
vdp_pflag_rtc: EQU 00100000b
vdp_pflag_mouse: EQU 01000000b
; vdp_pflag_buffered: EQU 10000000b
;
; FatFS structures
; These mirror the structures contained in src_fatfs/ff.h in the MOS project
;
; Object ID and allocation information (FFOBJID)
;
;FFOBJID .STRUCT
; fs: DS 3 ; Pointer to the hosting volume of this object
; id: DS 2 ; Hosting volume mount ID
; attr: DS 1 ; Object attribute;
; stat: DS 1 ; Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched)
; sclust: DS 4 ; Object data start cluster (0:no cluster or root directory)
; objsize: DS 4 ; Object size (valid when sclust != 0)
;FFOBJID_SIZE .ENDSTRUCT FFOBJID
;
; File object structure (FIL)
;
;FIL .STRUCT
; obj: .TAG FFOBJID ; Object identifier
; flag: DS 1 ; File status flags
; err: DS 1 ; Abort flag (error code)
; fptr: DS 4 ; File read/write pointer (Zeroed on file open)
; clust: DS 4 ; Current cluster of fpter (invalid when fptr is 0)
; sect: DS 4 ; Sector number appearing in buf[] (0:invalid)
; dir_sect: DS 4 ; Sector number containing the directory entry
; dir_ptr: DS 3 ; Pointer to the directory entry in the win[]
;FIL_SIZE .ENDSTRUCT FIL
;
; Directory object structure (DIR)
;
;DIR .STRUCT
; obj: .TAG FFOBJID ; Object identifier;
; dptr: DS 4 ; Current read/write offset
; clust: DS 4 ; Current cluster
; sect: DS 4 ; Current sector (0:Read operation has terminated)
; dir: DS 3 ; Pointer to the directory item in the win[]
; fn: DS 12 ; SFN (in/out) {body[8],ext[3],status[1]}
; blk_ofs: DS 4 ; Offset of current entry block being processed (0xFFFFFFFF:Invalid)
;DIR_SIZE .ENDSTRUCT DIR
;
; File information structure (FILINFO)
;
;FILINFO .STRUCT
; fsize: DS 4 ; File size
; fdate: DS 2 ; Modified date;
; ftime: DS 2 ; Modified time
; fattrib: DS 1 ; File attribute
; altname: DS 13 ; Alternative file name
; fname: DS 256 ; Primary file name
;FILINFO_SIZE .ENDSTRUCT FILINFO
;
; Macro for calling the API
; Parameters:
; - function: One of the function numbers listed above
;
MACRO MOSCALL function
LD A, function
RST.L 08h
ENDMACRO
и init.inc
Код:
;
; Title: Copy - Initialisation Code
; Author: Dean Belfield, Lennart Benschop
; Created: 06/11/2022
; Last Updated: 26/12/2022
;
; Modinfo:
; 17/12/2022: Added parameter processing
; 26/12/2022: Adapted to Copy program, use LEA instead of 3x INC IX, Save/restore MB
; Changed: 08/04/2924 adapt to ez80asm
argv_ptrs_max: EQU 16 ; Maximum number of arguments allowed in argv
;
; Start in ADL mode
;
JP _start ; Jump to start
;
; The header stuff is from byte 64 onwards
;
_exec_name:
PROGNAME ; The executable name, only used in argv
ALIGN 64
DB "MOS" ; Flag for MOS - to confirm this is a valid MOS command
DB 00h ; MOS header version 0
DB 01h ; Flag for run mode (0: Z80, 1: ADL)
;
; And the code follows on immediately after the header
;
_start: PUSH AF ; Preserve the registers
PUSH BC
PUSH DE
PUSH IX
PUSH IY
LD A, MB ; Save MB
PUSH AF
XOR A
LD MB, A ; Clear to zero so MOS API calls know how to use 24-bit addresses.
LD IX, argv_ptrs ; The argv array pointer address
PUSH IX
CALL _parse_params ; Parse the parameters
POP IX ; IX: argv
LD B, 0 ; C: argc
CALL _main ; Start user code
POP AF
LD MB, A
POP IY ; Restore registers
POP IX
POP DE
POP BC
POP AF
RET
; Parse the parameter string into a C array
; Parameters
; - HL: Address of parameter string
; - IX: Address for array pointer storage
; Returns:
; - C: Number of parameters parsed
;
_parse_params: LD BC, _exec_name
LD (IX+0), BC ; ARGV[0] = the executable name
LEA IX, IX+3
CALL _skip_spaces ; Skip HL past any leading spaces
;
LD BC, 1 ; C: ARGC = 1 - also clears out top 16 bits of BCU
LD B, argv_ptrs_max - 1 ; B: Maximum number of argv_ptrs
;
_parse_params_1:
PUSH BC ; Stack ARGC
PUSH HL ; Stack start address of token
CALL _get_token ; Get the next token
LD A, C ; A: Length of the token in characters
POP DE ; Start address of token (was in HL)
POP BC ; ARGC
OR A ; Check for A=0 (no token found) OR at end of string
RET Z
;
LD (IX+0), DE ; Store the pointer to the token
PUSH HL ; DE=HL
POP DE
CALL _skip_spaces ; And skip HL past any spaces onto the next character
XOR A
LD (DE), A ; Zero-terminate the token
LEA IX, IX+3 ; Advance to next pointer position
INC C ; Increment ARGC
LD A, C ; Check for C >= A
CP B
JR C, _parse_params_1 ; And loop
RET
; Get the next token
; Parameters:
; - HL: Address of parameter string
; Returns:
; - HL: Address of first character after token
; - C: Length of token (in characters)
;
_get_token: LD C, 0 ; Initialise length
@@: LD A, (HL) ; Get the character from the parameter string
OR A ; Exit if 0 (end of parameter string in MOS)
RET Z
CP 13 ; Exit if CR (end of parameter string in BBC BASIC)
RET Z
CP ' ' ; Exit if space (end of token)
RET Z
INC HL ; Advance to next character
INC C ; Increment length
JR @B
; Skip spaces in the parameter string
; Parameters:
; - HL: Address of parameter string
; Returns:
; - HL: Address of next none-space character
; F: Z if at end of string, otherwise NZ if there are more tokens to be parsed
;
_skip_spaces: LD A, (HL) ; Get the character from the parameter string
CP ' ' ; Exit if not space
RET NZ
INC HL ; Advance to next character
JR _skip_spaces ; Increment length
; Storage for the argv array pointers
;
argv_ptrs: BLKP argv_ptrs_max, 0
Берем из agon-utilites\fonts
файлы со шрифтами: bbcasc-8.bin, bbclat-8.bin, latin1-8.bin копируем их в \mos и опробуем font.bin в действии.
Например,
*font bbcasc-8.bin show
Ну, поскольку русских букв там действительно нет, то нужен редактор фонтов, чтобы их туда добавить или вбить вместо латинских для переключения. Как будет лучше, мне пока непонятно. Также пока не знаю, как из программы запускать другую программу с диска с параметром( это если перезагружать).
- - - Добавлено - - -
Сообщение от
Oleg N. Cher
Сделал в компиляторе TinyContext опции задания адресов данных и кода
Олег, сделайте пожалуйста версию, которая запускается из \mos с входным файлом исходного текста на context в качестве параметра, ну или как-то еще с объяснением, как запускать.