06-09-2014, 11:12 AM
boriel Wrote:This can be done by modifying the print routine. ZX Basic does not use the ROM print routine but its own (faster and more featured) one. If you need a print system that does not use UDG but all chars this can be achieved by patching the print.asm library with an #ifdef directive (you can specify special Defines from the command line with zxb -D TAG).
Of course. I did it four years ago. But the problem is the changes in <print.asm> are lost when ZX BASIC is updated. What I have written now is a simple library that switches on and off the new print mode, while the program is running. See the code of my proposed library:
Code:
' charset224.zxbas
' Version A-00-20140511
' An addon for ZX BASIC (http://zxbasic.net)
' Copyright (C) 2014 Marcos Cruz (programandala.net)
' This file is released under the GPL v3 License
' --------------------------------------------------------------
' Description
' This ZX BASIC file provides a sub called 'charset224'. It activates
' or deactivates a new printing mode. In the new mode, all 224 chars
' from 0x20 to 0xFF are printed as ordinary chars from the standard
' charset pointed by the CHARS system variable (no UDG, no block
' graphics, no tokens). Of course in order to use the new mode a
' proper 224-char font has to be in memory and CHARS has to be changed
' accordingly.
' The objective is to use a standard 8-bit character set (e.g. Latin
' 1) in ZX BASIC programs. This is very useful for programs in other
' languages than English, especially for programs that need a lot of
' text (text adventures or certain applications): No special notation
' or tricks are required in order to use standard non-ASCII chars into
' the texts the program will show at run-time.
' A 224-char font ocuppies 1792 bytes, and probably most of the chars
' will not be required by most programs, but the space of the unused
' chars can be used for graphics, data or even Z80 code.
' --------------------------------------------------------------
' Idea for an improved version
' A new printing mode to use the new font only for chars greater than
' 0x7E. This option would save 752 bytes. This mode would be useful
' for large programs that do not need a whole 255-bit new font design,
' but just need to add the missing standard non-ASCII chars to the
' ordinary ZX Spectrum font.
' --------------------------------------------------------------
' Change log
' 2014-05-06: First simple version. The parameter of the sub is the
' jump opcode required to hack the original <library-asm/print.asm>
' with. Two lines of code have to be previously and permanently
' modified in <library-asm/print.asm>.
' 2014-05-11: The code was rewritten and improved with a different
' approach: The original <library-asm/print.asm> has not to be
' previously modified, only a new label has to be added to it. All
' required changes are done by the sub. Its parameter is just a flag.
' The program is renamed.
' --------------------------------------------------------------
#ifndef __LIBRARY_CHARSET224__
' Avoid recursive / multiple inclusion
#define __LIBRARY_CHARSET224__
sub fastcall charset224(flag as ubyte)
' This sub modifies the Z80 code of ZX BASIC's
' <library-asm/print.asm>, in order to change its behaviour.
' If flag=0
' the legacy ZX Spectrum charset printing mode is set
' (ordinary chars, UDG and block graphics are managed differently).
' This is the original behaviour of the printing routine.
' If flag<>0
' the modern 8-bit charset printing mode is set
' (all chars 20h-FFh are ordinary).
asm
proc
ld hl,JUMP_IF_GREATER_THAN_80H ; address of the jump to be modified
and a
jr nz,MODIFY_THE_ORIGINAL_CODE
local RESTORE_THE_ORIGINAL_CODE
RESTORE_THE_ORIGINAL_CODE:
; Set the legacy ZX Spectrum charset printing mode
ld (HL),218 ; = 0xDA = Z80's 'JP C'
call READY
; original code
add a, a ; 1 byte
ld l, a ; 1 byte
ld h, 0 ; 2 bytes
local MODIFY_THE_ORIGINAL_CODE
MODIFY_THE_ORIGINAL_CODE:
; Set the modern 8-bit charset printing mode
ld (HL),195 ; = 0xC3 = Z80's 'JP'
call READY
; code to overwrite the original version with
ld l, a ; 1 byte
ld h, 0 ; 2 bytes
add hl,hl ; 1 byte
local READY
READY:
pop hl ; get the source address from the stack
ld de,__PRGRAPH0 ; destination address
ld bc,4 ; count
ldir
endp
end asm
end sub
#endif
You see, the sub changes the Z80 code of <print.asm> in two positions. That's it. All I need for this to work with any future version of ZX BASIC (as long as <print.asm> is not deeply modified) is a label in <print.asm>. I could use other current more distant label instead, but that could break the module if <print.asm> is modified in the future.
Anyway I wonder if this addon be useful enough for other people.
Marcos Cruz
http://programandala.net
http://programandala.net