Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to use a standard character set
#1
Sometimes, in order to use the Spanish characters (áéíóúüñÁÉÍÓÚÜÑ¿¡) in my Spectrum programs, I put them in the place of less used Spectrum chars (#, ', @...).

In the source code of my current project there's a lot of Spanish texts to be printed by the Spectrum. It would be uncomfortable to use those fake chars all over the source. Then I had a quite brilliant Wink idea: Let's use the same standard character set both in the source code and in the Spectrum!

First, I wrote a trivial asm sub to change the character set address. Then I added the character graphics, with the Spanish chars in the right position (in the ISO-8859-1 standard). The only needed trick is to fill the gaps of the unused chars. Happily, I already had all the character definitions is assembler DEFBs, in another project of mine.

This is the first part of the sub:

Code:
sub fastcall changeCharacterSet()

    asm

systemCHARS    equ 23606

    jp actuallyChangeCharacterSet

characterSet equ $-256

;(space)
    defb %00000000
    defb %00000000
    defb %00000000
    defb %00000000
    defb %00000000
    defb %00000000
    defb %00000000
    defb %00000000
;!
    defb %00000000
    defb %00010000
    defb %00010000
    defb %00010000
    defb %00010000
    defb %00000000
    defb %00010000
    defb %00000000

And so on... This is the end:

Code:
    defs (243-241-1)*8 ; unused chars
;ó = 243
    defb %00001000
    defb %00010000
    defb %00111000
    defb %01000100
    defb %01000100
    defb %01000100
    defb %00111000
    defb %00000000

    defs (250-243-1)*8 ; unused chars
;ú = 250
    defb %00001000
    defb %00010000
    defb %01000100
    defb %01000100
    defb %01000100
    defb %01000100
    defb %00111000
    defb %00000000

    defs (252-250-1)*8 ; unused chars
;ü = 252
    defb %01000100
    defb %00000000
    defb %01000100
    defb %01000100
    defb %01000100
    defb %01000100
    defb %00111000
    defb %00000000

actuallyChangeCharacterSet:

    ld hl,characterSet
    ld (systemCHARS),hl

    end asm
end sub

Easy, isn't it?

The next task is to hack the print.asm library in order to print all characters from 32 to 255. I show the removed or added lines (they are clearly marked):

First:

Code:
; 1 LINE REMOVED:
;        LOCAL __PRINT_UDG

And then the rest:

Code:
; 8 LINES REMOVED:
;        cp 80h    ; Is it an UDG or a ?
;        jp c, __SRCADDR

;        cp 90h
;        jp nc, __PRINT_UDG

        ; Print a 8 bit pattern (80h to 8Fh)

;        ld b, a
;        call PO_GR_1 ; This ROM routine will generate the bit pattern at MEM0
;        ld hl, MEM0
;        jp __PRGRAPH

PO_GR_1 EQU 0B38h

; 4 LINES REMOVED:
;__PRINT_UDG: ;REMOVED
;        sub 90h ; Sub ASC code
;        ld bc, (UDG)
;        jp __PRGRAPH0

__SOURCEADDR EQU (__SRCADDR + 1)    ; Address of the pointer to chars source
__SRCADDR:
        ld bc, (CHARS)

__PRGRAPH0:
; 1 LINE REMOVED:
;        add a, a    ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
        ld l, a
        ld h, 0        ; HL = a * 2 (accumulator)
        add hl, hl
; 1 LINE ADDED:
        add hl, hl
        add hl, hl ; HL = a * 8
        add hl, bc ; HL = CHARS address

__PRGRAPH:

That's all. Now all characters from 32 to 255 are in the same set: no block graphics, no UDGs, no Basic tokens. Any desired graphic can be defined in any character code. Any standard 8-bit character set can be used. Now I can write the Spanish texts in the source and they show perfectly on the Spectrum's screen.

I'd like my hacked version to be an independent library, to be #included, and used with a new command (print224, printplus or whatever). But rigth now that task is beyond my current skill with ZX Basic. Any help?

Another issue is to use the gaps of the unused chars for variables, but I'm still not sure how to use asm labels in ZX Basic. I have to explore it. Any help?

Now I will tinker with the second part of the system: I have to modify my own input routine, to let it accept some key combinations (e.g. Symbol Shift (+Shift)+letter) to get the Spanish characters...
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)