Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
an additional label in <library-asm/print.asm>
#1
Mi wish is easy to satisfy: I need one label after CP 80h in <print.asm>:

Code:
ex af, af'

        cp 80h  ; Is the char an UDG, a block character or a token?
JUMP_IF_GREATER_THAN_80H:
        ; XXX label needed to hack the printing system
        jp c, __SRCADDR ; if not, jump

(That is an extract from my hacked version of <print.asm>, with additional comments of my own; the actual name of the label doesn't matter.)

The reason I need a label there is I have written a module that provides a sub to switch on an off the ZX Spectrum legacy printing mode (that treats ASCII chars, block chars and UDG chars apart). When the legacy mode is off, all chars 32-255 are taken from the same charset. This makes it possible to write source code with a modern 8-bit encoding, e.g. Latin1. This is very useful for programs that print a lot of text in other languages than English.

I tinkered with this idea four years ago, and hacked <print.asm>, but I had to redo the changes after every new version of ZX BASIC. The new approach is simpler and better: The sub modifies the code of <print.asm> in two locations, and the legacy printing mode can be restored at any time by the program. It works great. So far I have tried it with a modified version of <print.asm>. That's why I need that single label.

I will publish the module as soon as it can be used with a new version of ZX BASIC, unless someone requires it sooner.

Thank you.
Reply
#2
programandala.net Wrote:Mi wish is easy to satisfy: I need one label after CP 80h in <print.asm>:

Code:
ex af, af'

        cp 80h  ; Is the char an UDG, a block character or a token?
JUMP_IF_GREATER_THAN_80H:
        ; XXX label needed to hack the printing system
        jp c, __SRCADDR ; if not, jump

(That is an extract from my hacked version of <print.asm>, with additional comments of my own; the actual name of the label doesn't matter.)

The reason I need a label there is I have written a module that provides a sub to switch on an off the ZX Spectrum legacy printing mode (that treats ASCII chars, block chars and UDG chars apart). When the legacy mode is off, all chars 32-255 are taken from the same charset. This makes it possible to write source code with a modern 8-bit encoding, e.g. Latin1. This is very useful for programs that print a lot of text in other languages than English.

I tinkered with this idea four years ago, and hacked <print.asm>, but I had to redo the changes after every new version of ZX BASIC. The new approach is simpler and better: The sub modifies the code of <print.asm> in two locations, and the legacy printing mode can be restored at any time by the program. It works great. So far I have tried it with a modified version of <print.asm>. That's why I need that single label.

I will publish the module as soon as it can be used with a new version of ZX BASIC, unless someone requires it sooner.

Thank you.
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).
Reply
#3
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.
Reply
#4
programandala.net Wrote:Anyway I wonder if this addon be useful enough for other people.

would be useful, I meant Smile . Somehow the Edit button doesn't work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)